From 45e0d9b22b0592bf46e3aec2148770eba9882e46 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 9 Mar 2018 21:10:41 +0300 Subject: more cleaning --- protocols/JabberG/src/jabber_xstatus.cpp | 73 +++++++++++++++++--------------- src/mir_app/src/clc.cpp | 16 ++++--- src/mir_app/src/clistmod.cpp | 8 ++-- src/mir_app/src/extraicons.cpp | 8 ++-- src/mir_app/src/hotkey_opts.cpp | 49 ++++++++++----------- src/mir_app/src/proto_order.cpp | 3 +- 6 files changed, 82 insertions(+), 75 deletions(-) diff --git a/protocols/JabberG/src/jabber_xstatus.cpp b/protocols/JabberG/src/jabber_xstatus.cpp index 43072a3749..4f6c768a05 100644 --- a/protocols/JabberG/src/jabber_xstatus.cpp +++ b/protocols/JabberG/src/jabber_xstatus.cpp @@ -31,7 +31,7 @@ static CIconPool g_MoodIcons, g_ActivityIcons; /////////////////////////////////////////////////////////////////////////////// // Simple dialog with timer and ok/cancel buttons -class CJabberDlgPepBase: public CJabberDlgBase +class CJabberDlgPepBase : public CJabberDlgBase { typedef CJabberDlgBase CSuper; public: @@ -53,7 +53,7 @@ private: int m_time; }; -CJabberDlgPepBase::CJabberDlgPepBase(CJabberProto *proto, int id): +CJabberDlgPepBase::CJabberDlgPepBase(CJabberProto *proto, int id) : CJabberDlgBase(proto, id, nullptr), m_btnOk(this, IDOK), m_btnCancel(this, IDCANCEL), @@ -77,7 +77,7 @@ int CJabberDlgPepBase::Resizer(UTILRESIZECONTROL *urc) switch (urc->wId) { case IDOK: case IDCANCEL: - return RD_ANCHORX_RIGHT|RD_ANCHORY_BOTTOM; + return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM; } return CSuper::Resizer(urc); @@ -115,7 +115,7 @@ void CJabberDlgPepBase::StopTimer() /////////////////////////////////////////////////////////////////////////////// // Simple PEP status -class CJabberDlgPepSimple: public CJabberDlgPepBase +class CJabberDlgPepSimple : public CJabberDlgPepBase { typedef CJabberDlgPepBase CSuper; public: @@ -154,7 +154,7 @@ private: wchar_t *m_title; bool m_subitem; - CStatusMode(LPARAM id, char *name, HICON hIcon, wchar_t *title, bool subitem): m_id(id), m_name(name), m_hIcon(hIcon), m_title(title), m_subitem(subitem) {} + CStatusMode(LPARAM id, char *name, HICON hIcon, wchar_t *title, bool subitem) : m_id(id), m_name(name), m_hIcon(hIcon), m_title(title), m_subitem(subitem) {} ~CStatusMode() { IcoLib_ReleaseIcon(m_hIcon); } }; @@ -174,7 +174,7 @@ private: void cbModes_OnChange(CCtrlData *); }; -CJabberDlgPepSimple::CJabberDlgPepSimple(CJabberProto *proto, wchar_t *title): +CJabberDlgPepSimple::CJabberDlgPepSimple(CJabberProto *proto, wchar_t *title) : CJabberDlgPepBase(proto, IDD_PEP_SIMPLE), m_cbModes(this, IDC_CB_MODES), m_txtDescription(this, IDC_TXT_DESCRIPTION), @@ -189,7 +189,7 @@ CJabberDlgPepSimple::CJabberDlgPepSimple(CJabberProto *proto, wchar_t *title): m_btnOk.OnClick = Callback(this, &CJabberDlgPepSimple::btnOk_OnClick); m_cbModes.OnChange = Callback(this, &CJabberDlgPepSimple::cbModes_OnChange); m_cbModes.OnDropdown = - m_txtDescription.OnChange = Callback(this, &CJabberDlgPepSimple::global_OnChange); + m_txtDescription.OnChange = Callback(this, &CJabberDlgPepSimple::global_OnChange); m_modes.insert(new CStatusMode(-1, "", Skin_LoadIcon(SKINICON_OTHER_SMALLDOT), TranslateT("None"), false)); } @@ -215,7 +215,7 @@ LPARAM CJabberDlgPepSimple::GetStatusMode() return m_modes[m_selected].m_id; } -wchar_t *CJabberDlgPepSimple::GetStatusText() +wchar_t* CJabberDlgPepSimple::GetStatusText() { return m_text; } @@ -228,12 +228,13 @@ void CJabberDlgPepSimple::OnInitDialog() SetWindowText(m_hwnd, m_title); m_txtDescription.Enable(false); - for (int i=0; i < m_modes.getCount(); i++) { - int idx = m_cbModes.AddString(m_modes[i].m_title, i); - if ((m_modes[i].m_id == m_active) || !idx) { + for (auto &it : m_modes) { + int idx = m_cbModes.AddString(it->m_title, (LPARAM)it); + if (it->m_id == m_active || !idx) { m_prevSelected = idx; m_cbModes.SetCurSel(idx); - if (idx) m_txtDescription.Enable(); + if (idx) + m_txtDescription.Enable(); } } @@ -245,9 +246,9 @@ int CJabberDlgPepSimple::Resizer(UTILRESIZECONTROL *urc) { switch (urc->wId) { case IDC_CB_MODES: - return RD_ANCHORX_WIDTH|RD_ANCHORY_TOP; + return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; case IDC_TXT_DESCRIPTION: - return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT; + return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; } return CSuper::Resizer(urc); @@ -274,18 +275,20 @@ void CJabberDlgPepSimple::cbModes_OnChange(CCtrlData *) char szSetting[128]; - if ((m_prevSelected >= 0) && (m_modes[m_cbModes.GetItemData(m_prevSelected)].m_id >= 0)) { + CStatusMode *pMode = (CStatusMode*)m_cbModes.GetItemData(m_prevSelected); + if (m_prevSelected >= 0 && pMode->m_id >= 0) { wchar_t *txt = m_txtDescription.GetText(); - mir_snprintf(szSetting, "PepMsg_%s", m_modes[m_cbModes.GetItemData(m_prevSelected)].m_name); + mir_snprintf(szSetting, "PepMsg_%s", pMode->m_name); m_proto->setWString(szSetting, txt); mir_free(txt); } m_prevSelected = m_cbModes.GetCurSel(); - if ((m_prevSelected >= 0) && (m_modes[m_cbModes.GetItemData(m_prevSelected)].m_id >= 0)) { - mir_snprintf(szSetting, "PepMsg_%s", m_modes[m_cbModes.GetItemData(m_prevSelected)].m_name); + pMode = (CStatusMode*)m_cbModes.GetItemData(m_prevSelected); + if (m_prevSelected >= 0 && pMode->m_id >= 0) { + mir_snprintf(szSetting, "PepMsg_%s", pMode->m_name); - ptrW szDescr( m_proto->getWStringA(szSetting)); + ptrW szDescr(m_proto->getWStringA(szSetting)); m_txtDescription.SetText((szDescr != nullptr) ? szDescr : L""); m_txtDescription.Enable(true); } @@ -301,8 +304,8 @@ BOOL CJabberDlgPepSimple::OnWmMeasureItem(UINT, WPARAM, LPARAM lParam) if (lpmis->CtlID != IDC_CB_MODES) return FALSE; - TEXTMETRIC tm = {0}; HDC hdc = GetDC(m_cbModes.GetHwnd()); + TEXTMETRIC tm = {}; GetTextMetrics(hdc, &tm); ReleaseDC(m_cbModes.GetHwnd(), hdc); @@ -371,7 +374,7 @@ BOOL CJabberDlgPepSimple::OnWmGetMinMaxInfo(UINT, WPARAM, LPARAM lParam) /////////////////////////////////////////////////////////////////////////////// // CPepService base class -CPepService::CPepService(CJabberProto *proto, char *name, wchar_t *node): +CPepService::CPepService(CJabberProto *proto, char *name, wchar_t *node) : m_proto(proto), m_name(name), m_node(node), @@ -389,8 +392,8 @@ void CPepService::Publish() XmlNodeIq iq(L"set", m_proto->SerialNext()); CreateData( iq << XCHILDNS(L"pubsub", JABBER_FEAT_PUBSUB) - << XCHILD(L"publish") << XATTR(L"node", m_node) - << XCHILD(L"item") << XATTR(L"id", L"current")); + << XCHILD(L"publish") << XATTR(L"node", m_node) + << XCHILD(L"item") << XATTR(L"id", L"current")); m_proto->m_ThreadInfo->send(iq); m_wasPublished = true; @@ -403,10 +406,10 @@ void CPepService::Retract() m_proto->m_ThreadInfo->send( XmlNodeIq(L"set", m_proto->SerialNext()) - << XCHILDNS(L"pubsub", JABBER_FEAT_PUBSUB) - << XCHILD(L"publish") << XATTR(L"node", m_node) - << XCHILD(L"item") - << XCHILDNS(tempName, m_node)); + << XCHILDNS(L"pubsub", JABBER_FEAT_PUBSUB) + << XCHILD(L"publish") << XATTR(L"node", m_node) + << XCHILD(L"item") + << XCHILDNS(tempName, m_node)); mir_free(tempName); } @@ -425,7 +428,7 @@ void CPepService::ForceRepublishOnLogin() /////////////////////////////////////////////////////////////////////////////// // CPepGuiService base class -CPepGuiService::CPepGuiService(CJabberProto *proto, char *name, wchar_t *node): +CPepGuiService::CPepGuiService(CJabberProto *proto, char *name, wchar_t *node) : CPepService(proto, name, node), m_bGuiOpen(false), m_hIcolibItem(nullptr), @@ -631,7 +634,7 @@ void CPepMood::ProcessItems(const wchar_t *from, HXML itemsNode) if (!moodNode) return; const wchar_t *moodType = nullptr, *moodText = nullptr; - for (int i=0; n = XmlGetChild(moodNode, i); i++) { + for (int i = 0; n = XmlGetChild(moodNode, i); i++) { if (!mir_wstrcmp(XmlGetName(n), L"text")) moodText = XmlGetText(n); else @@ -978,7 +981,7 @@ void ActivityBuildTitle(int id, wchar_t *buf, int size) else *buf = 0; } -CPepActivity::CPepActivity(CJabberProto *proto): +CPepActivity::CPepActivity(CJabberProto *proto) : CPepGuiService(proto, "Activity", JABBER_FEAT_USER_ACTIVITY), m_text(nullptr), m_mode(-1) @@ -1015,7 +1018,7 @@ void CPepActivity::ProcessItems(const wchar_t *from, HXML itemsNode) const wchar_t *szFirstNode = nullptr, *szSecondNode = nullptr; HXML n; - for (int i=0; n = XmlGetChild(actNode, i); i++) { + for (int i = 0; n = XmlGetChild(actNode, i); i++) { if (mir_wstrcmp(XmlGetName(n), L"text")) { szFirstNode = XmlGetName(n); HXML secondNode = XmlGetChild(n, 0); @@ -1089,7 +1092,7 @@ void CPepActivity::SetActivity(MCONTACT hContact, const wchar_t *szFirst, const mir_wstrcpy(title, TranslateT("Set activity...")); hIcon = Skin_GetIconHandle(SKINICON_OTHER_SMALLDOT); } - + UpdateMenuItem(hIcon, title); if (m_proto->m_pInfoFrame) m_proto->m_pInfoFrame->UpdateInfoItem("$/PEP/activity", hIcon, title); @@ -1107,7 +1110,7 @@ void CPepActivity::SetActivity(MCONTACT hContact, const wchar_t *szFirst, const void CPepActivity::ShowSetDialog(BYTE) { CJabberDlgPepSimple dlg(m_proto, TranslateT("Set Activity")); - for (int i=0; i < _countof(g_arrActivities); i++) + for (int i = 0; i < _countof(g_arrActivities); i++) if (g_arrActivities[i].szFirst || g_arrActivities[i].szSecond) dlg.AddStatusMode(i, ActivityGetId(i), g_ActivityIcons.GetIcon(returnActivity(i)), TranslateW(g_arrActivities[i].szTitle), (g_arrActivities[i].szSecond != nullptr)); @@ -1267,8 +1270,8 @@ INT_PTR __cdecl CJabberProto::OnSetListeningTo(WPARAM, LPARAM lParam) overrideStr(szTrack, cm->ptszTrack, unicode); overrideStr(szLength, cm->ptszLength, unicode); - wchar_t szLengthInSec[ 32 ]; - szLengthInSec[ 0 ] = 0; + wchar_t szLengthInSec[32]; + szLengthInSec[0] = 0; if (szLength) { unsigned int multiplier = 1, result = 0; for (wchar_t *p = szLength; *p; p++) diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index 382150ff65..a7c8b06698 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -384,18 +384,19 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam DBCONTACTWRITESETTING *dbcws = (DBCONTACTWRITESETTING *)lParam; if (dbcws->value.type == DBVT_ASCIIZ || dbcws->value.type == DBVT_UTF8) { int groupId = atoi(dbcws->szSetting) + 1; - int i, eq; - //check name of group and ignore message if just being expanded/collapsed + + // check name of group and ignore message if just being expanded/collapsed if (Clist_FindItem(hwnd, dat, groupId | HCONTACT_ISGROUP, &contact, &group, nullptr)) { CMStringW szFullName(contact->szText); while (group->parent) { ClcContact *cc = nullptr; - for (i = 0; i < group->parent->cl.getCount(); i++) { - cc = group->parent->cl[i]; - if (cc->group == group) + for (auto &it : group->parent->cl) + if (it->group == group) { + cc = it; break; - } - if (i == group->parent->cl.getCount()) { + } + + if (cc == nullptr) { szFullName.Empty(); break; } @@ -403,6 +404,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam group = group->parent; } + int eq; if (dbcws->value.type == DBVT_ASCIIZ) eq = !mir_wstrcmp(szFullName, _A2T(dbcws->value.pszVal+1)); else diff --git a/src/mir_app/src/clistmod.cpp b/src/mir_app/src/clistmod.cpp index 8362bf71f9..87c616de47 100644 --- a/src/mir_app/src/clistmod.cpp +++ b/src/mir_app/src/clistmod.cpp @@ -52,7 +52,7 @@ struct ProtoIconIndex int iIconBase; }; -OBJLIST protoIconIndex(5); +OBJLIST protoIconIndex(5, PtrKeySortT); wchar_t* fnGetStatusModeDescription(int mode, int flags) { @@ -180,9 +180,9 @@ static void AddProtoIconIndex(PROTOACCOUNT *pa) static void RemoveProtoIconIndex(PROTOACCOUNT *pa) { - for (int i = 0; i < protoIconIndex.getCount(); i++) - if (mir_strcmp(protoIconIndex[i].szProto, pa->szModuleName) == 0) { - protoIconIndex.remove(i); + for (auto &it : protoIconIndex) + if (mir_strcmp(it->szProto, pa->szModuleName) == 0) { + protoIconIndex.remove(it); break; } } diff --git a/src/mir_app/src/extraicons.cpp b/src/mir_app/src/extraicons.cpp index 90cac83a2b..937b5e61a8 100644 --- a/src/mir_app/src/extraicons.cpp +++ b/src/mir_app/src/extraicons.cpp @@ -159,8 +159,8 @@ static void LoadGroups(LIST &groups) static ExtraIconGroup* IsInGroup(LIST &groups, BaseExtraIcon *extra) { for (auto &group : groups) - for (int j = 0; j < group->m_items.getCount(); j++) - if (extra == group->m_items[j]) + for (auto &it : group->m_items) + if (extra == it) return group; return nullptr; @@ -179,8 +179,8 @@ void RebuildListsBasedOnGroups(LIST &groups) extraIconsBySlot.destroy(); for (auto &group : groups) { - for (int j = 0; j < group->m_items.getCount(); j++) - extraIconsByHandle.put(group->m_items[j]->getID() - 1, group); + for (auto &it : group->m_items) + extraIconsByHandle.put(it->getID()-1, group); extraIconsBySlot.insert(group); } diff --git a/src/mir_app/src/hotkey_opts.cpp b/src/mir_app/src/hotkey_opts.cpp index 1de4e22f38..e86751c501 100644 --- a/src/mir_app/src/hotkey_opts.cpp +++ b/src/mir_app/src/hotkey_opts.cpp @@ -381,39 +381,40 @@ static void sttOptionsSaveItem(THotkeyItem *item) static void sttBuildHotkeyList(HWND hwndList) { - int i, nItems = 0; ListView_DeleteAllItems(hwndList); - for (i = 0; i < hotkeys.getCount(); i++) { + int nItems = 0; + THotkeyItem *prevItem = nullptr; + for (auto &item : hotkeys) { LVITEM lvi = { 0 }; - THotkeyItem *item = hotkeys[i]; - if (item->OptDeleted) - continue; + if (!item->OptDeleted) { + if (!prevItem || mir_wstrcmp(item->pwszSection, prevItem->pwszSection)) { + lvi.mask = LVIF_TEXT | LVIF_PARAM; + lvi.iItem = nItems++; + lvi.iSubItem = 0; + lvi.lParam = 0; + lvi.pszText = item->getSection(); + ListView_InsertItem(hwndList, &lvi); + ListView_SetCheckState(hwndList, lvi.iItem, TRUE); - if (!i || mir_wstrcmp(item->pwszSection, hotkeys[i - 1]->pwszSection)) { - lvi.mask = LVIF_TEXT | LVIF_PARAM; - lvi.iItem = nItems++; - lvi.iSubItem = 0; - lvi.lParam = 0; - lvi.pszText = item->getSection(); - ListView_InsertItem(hwndList, &lvi); - ListView_SetCheckState(hwndList, lvi.iItem, TRUE); + lvi.mask = LVIF_TEXT; + lvi.iSubItem = 1; + lvi.pszText = item->pwszSection; + ListView_SetItem(hwndList, &lvi); - lvi.mask = LVIF_TEXT; - lvi.iSubItem = 1; - lvi.pszText = item->pwszSection; - ListView_SetItem(hwndList, &lvi); + lvi.iSubItem = 0; + } - lvi.iSubItem = 0; + lvi.mask = LVIF_PARAM | LVIF_INDENT; + lvi.iIndent = 1; + lvi.iItem = nItems++; + lvi.lParam = (LPARAM)item; + ListView_InsertItem(hwndList, &lvi); + sttOptionsSetupItem(hwndList, nItems - 1, item); } - lvi.mask = LVIF_PARAM | LVIF_INDENT; - lvi.iIndent = 1; - lvi.iItem = nItems++; - lvi.lParam = (LPARAM)item; - ListView_InsertItem(hwndList, &lvi); - sttOptionsSetupItem(hwndList, nItems - 1, item); + prevItem = item; } ListView_SortItemsEx(hwndList, sttOptionsSortList, (LPARAM)hwndList); diff --git a/src/mir_app/src/proto_order.cpp b/src/mir_app/src/proto_order.cpp index 7456218447..b35c115385 100644 --- a/src/mir_app/src/proto_order.cpp +++ b/src/mir_app/src/proto_order.cpp @@ -47,7 +47,8 @@ bool CheckProtocolOrder(void) for (;;) { // Find account with this id for (i = 0; i < accounts.getCount(); i++) - if (accounts[i]->iOrder == id) break; + if (accounts[i]->iOrder == id) + break; // Account with id not found if (i == accounts.getCount()) { -- cgit v1.2.3