summaryrefslogtreecommitdiff
path: root/plugins/TabSRMM
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-04-09 20:03:46 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-04-09 20:03:46 +0000
commitbcb27264ba737778e5d3edad36088bacf74f0236 (patch)
treefd1f57744dd380b7babe312a0ab5dc60b48854f2 /plugins/TabSRMM
parent940231dc5a484b03a278900e1880aa083472b601 (diff)
- short function names allows to write database loops in one string;
- 'continue' operator can be used then; - multiple bugs fixed in clists; - code becomes much more compact; git-svn-id: http://svn.miranda-ng.org/main/trunk@4403 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TabSRMM')
-rw-r--r--plugins/TabSRMM/src/chat/clist.cpp17
-rw-r--r--plugins/TabSRMM/src/container.cpp23
-rw-r--r--plugins/TabSRMM/src/globals.cpp10
-rw-r--r--plugins/TabSRMM/src/msgoptions.cpp40
-rw-r--r--plugins/TabSRMM/src/sendqueue.cpp26
-rw-r--r--plugins/TabSRMM/src/trayicon.cpp56
-rw-r--r--plugins/TabSRMM/src/typingnotify.cpp4
7 files changed, 69 insertions, 107 deletions
diff --git a/plugins/TabSRMM/src/chat/clist.cpp b/plugins/TabSRMM/src/chat/clist.cpp
index fd0f232573..483603b24d 100644
--- a/plugins/TabSRMM/src/chat/clist.cpp
+++ b/plugins/TabSRMM/src/chat/clist.cpp
@@ -115,12 +115,8 @@ BOOL CList_SetOffline(HANDLE hContact, BOOL bHide)
BOOL CList_SetAllOffline(BOOL bHide, const char *pszModule)
{
- HANDLE hContact;
- char* szProto;
-
- hContact = db_find_first();
- while (hContact) {
- szProto = GetContactProto(hContact);
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ char *szProto = GetContactProto(hContact);
if (MM_FindModule(szProto)) {
if (!pszModule || (pszModule && !strcmp(pszModule, szProto))) {
int i = M->GetByte(hContact, szProto, "ChatRoom", 0);
@@ -130,8 +126,6 @@ BOOL CList_SetAllOffline(BOOL bHide, const char *pszModule)
}
}
}
-
- hContact = db_find_next(hContact);
}
return TRUE;
}
@@ -297,9 +291,8 @@ BOOL CList_AddEvent(HANDLE hContact, HICON Icon, HANDLE event, int type, const T
HANDLE CList_FindRoom(const char* pszModule, const TCHAR* pszRoom)
{
- HANDLE hContact = db_find_first();
- while (hContact) {
- char* szProto = GetContactProto(hContact);
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ char *szProto = GetContactProto(hContact);
if (szProto && !lstrcmpiA(szProto, pszModule)) {
if (M->GetByte(hContact, szProto, "ChatRoom", 0) != 0) {
DBVARIANT dbv;
@@ -312,8 +305,6 @@ HANDLE CList_FindRoom(const char* pszModule, const TCHAR* pszRoom)
}
}
}
-
- hContact = db_find_next(hContact);
}
return 0;
}
diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp
index e5e98c9a44..c37642d345 100644
--- a/plugins/TabSRMM/src/container.cpp
+++ b/plugins/TabSRMM/src/container.cpp
@@ -2389,25 +2389,21 @@ void TSAPI DeleteContainer(int iIndex)
char *szKey = "TAB_ContainersW";
char *szSettingP = "CNTW_";
char *szSubKey = "containerW";
- HANDLE hhContact;
_snprintf(szIndex, 8, "%d", iIndex);
-
if (!M->GetTString(NULL, szKey, szIndex, &dbv)) {
if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_WCHAR) {
TCHAR *wszContainerName = dbv.ptszVal;
M->WriteTString(NULL, szKey, szIndex, _T("**free**"));
- hhContact = db_find_first();
- while (hhContact) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
DBVARIANT dbv_c;
- if (!M->GetTString(hhContact, SRMSGMOD_T, szSubKey, &dbv_c)) {
+ if (!M->GetTString(hContact, SRMSGMOD_T, szSubKey, &dbv_c)) {
TCHAR *wszString = dbv_c.ptszVal;
if (_tcscmp(wszString, wszContainerName) && lstrlen(wszString) == lstrlen(wszContainerName))
- db_unset(hhContact, SRMSGMOD_T, "containerW");
+ db_unset(hContact, SRMSGMOD_T, "containerW");
db_free(&dbv_c);
}
- hhContact = db_find_next(hhContact);
}
_snprintf(szSetting, CONTAINER_NAMELEN + 15, "%s%d_Flags", szSettingP, iIndex);
db_unset(NULL, SRMSGMOD_T, szSetting);
@@ -2433,27 +2429,24 @@ void TSAPI RenameContainer(int iIndex, const TCHAR *szNew)
char *szSettingP = "CNTW_";
char *szSubKey = "containerW";
char szIndex[10];
- HANDLE hhContact;
_snprintf(szIndex, 8, "%d", iIndex);
if (!M->GetTString(NULL, szKey, szIndex, &dbv)) {
- if (szNew != NULL) {
+ if (szNew != NULL)
if (lstrlen(szNew) != 0)
M->WriteTString(NULL, szKey, szIndex, szNew);
- }
- hhContact = db_find_first();
- while (hhContact) {
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
DBVARIANT dbv_c;
- if (!M->GetTString(hhContact, SRMSGMOD_T, szSubKey, &dbv_c)) {
+ if (!M->GetTString(hContact, SRMSGMOD_T, szSubKey, &dbv_c)) {
if (!_tcscmp(dbv.ptszVal, dbv_c.ptszVal) && lstrlen(dbv_c.ptszVal) == lstrlen(dbv.ptszVal)) {
if (szNew != NULL) {
if (lstrlen(szNew) != 0)
- M->WriteTString(hhContact, SRMSGMOD_T, szSubKey, szNew);
+ M->WriteTString(hContact, SRMSGMOD_T, szSubKey, szNew);
}
}
db_free(&dbv_c);
}
- hhContact = db_find_next(hhContact);
}
db_free(&dbv);
}
diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp
index 67c4333121..76f44eefe7 100644
--- a/plugins/TabSRMM/src/globals.cpp
+++ b/plugins/TabSRMM/src/globals.cpp
@@ -562,7 +562,6 @@ int CGlobals::MetaContactEvent(WPARAM wParam, LPARAM lParam)
int CGlobals::PreshutdownSendRecv(WPARAM wParam, LPARAM lParam)
{
- HANDLE hContact;
int i;
#if defined(__USE_EX_HANDLERS)
@@ -579,11 +578,8 @@ int CGlobals::PreshutdownSendRecv(WPARAM wParam, LPARAM lParam)
::SendMessage(pFirstContainer->hwnd, WM_CLOSE, 0, 1);
}
- hContact = db_find_first();
- while (hContact) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
M->WriteDword(hContact, SRMSGMOD_T, "messagecount", 0);
- hContact = db_find_next(hContact);
- }
for (i=0; i < SERVICE_LAST; i++) {
if (PluginConfig.hSvc[i])
@@ -651,8 +647,7 @@ void CGlobals::RestoreUnreadMessageAlerts(void)
cle.pszService = "SRMsg/ReadMessage";
cle.flags = CLEF_TCHAR;
- HANDLE hContact = db_find_first();
- while (hContact) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if (M->GetDword(hContact, "SendLater", "count", 0))
sendLater->addContact(hContact);
@@ -675,7 +670,6 @@ void CGlobals::RestoreUnreadMessageAlerts(void)
}
hDbEvent = db_event_next(hDbEvent);
}
- hContact = db_find_next(hContact);
}
}
diff --git a/plugins/TabSRMM/src/msgoptions.cpp b/plugins/TabSRMM/src/msgoptions.cpp
index 419863cb75..868e59513b 100644
--- a/plugins/TabSRMM/src/msgoptions.cpp
+++ b/plugins/TabSRMM/src/msgoptions.cpp
@@ -853,41 +853,33 @@ static void ResetCList(HWND hwndDlg)
static void RebuildList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown)
{
- HANDLE hContact, hItem;
BYTE defType = M->GetByte(SRMSGMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW);
-
- if (hItemNew && defType) {
+ if (hItemNew && defType)
SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItemNew, 1);
- }
- if (hItemUnknown && M->GetByte(SRMSGMOD, SRMSGSET_TYPINGUNKNOWN, SRMSGDEFSET_TYPINGUNKNOWN)) {
+
+ if (hItemUnknown && M->GetByte(SRMSGMOD, SRMSGSET_TYPINGUNKNOWN, SRMSGDEFSET_TYPINGUNKNOWN))
SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItemUnknown, 1);
- }
- hContact = db_find_first();
- do {
- hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
- if (hItem && M->GetByte(hContact, SRMSGMOD, SRMSGSET_TYPING, defType)) {
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ if (hItem && M->GetByte(hContact, SRMSGMOD, SRMSGSET_TYPING, defType))
SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 1);
- }
- } while (hContact = db_find_next(hContact));
+ }
}
static void SaveList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown)
{
- HANDLE hContact, hItem;
-
- if (hItemNew) {
+ if (hItemNew)
M->WriteByte(SRMSGMOD, SRMSGSET_TYPINGNEW, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItemNew, 0) ? 1 : 0));
- }
- if (hItemUnknown) {
+
+ if (hItemUnknown)
M->WriteByte(SRMSGMOD, SRMSGSET_TYPINGUNKNOWN, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItemUnknown, 0) ? 1 : 0));
- }
- hContact = db_find_first();
- do {
- hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
- if (hItem) {
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ if (hItem)
db_set_b(hContact, SRMSGMOD, SRMSGSET_TYPING, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0) ? 1 : 0));
- }
- } while (hContact = db_find_next(hContact));
+ }
}
static INT_PTR CALLBACK DlgProcTypeOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp
index fdfda626b7..3f78cf8c32 100644
--- a/plugins/TabSRMM/src/sendqueue.cpp
+++ b/plugins/TabSRMM/src/sendqueue.cpp
@@ -375,45 +375,39 @@ int SendQueue::sendQueued(TWindowData *dat, const int iEntry)
HWND hwndDlg = dat->hwnd;
if (dat->sendMode & SMODE_MULTIPLE) {
- HANDLE hContact, hItem;
- int iJobs = 0;
- int iMinLength = 0;
- CContactCache* c = 0;
-
- hContact = db_find_first();
+ int iJobs = 0;
+ int iMinLength = 0;
m_jobs[iEntry].hOwner = dat->hContact;
m_jobs[iEntry].iStatus = SQ_INPROGRESS;
m_jobs[iEntry].hwndOwner = hwndDlg;
- int iSendLength = getSendLength(iEntry, dat->sendMode);
+ int iSendLength = getSendLength(iEntry, dat->sendMode);
- do {
- hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if (hItem && SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
- c = CContactCache::getContactCache(hContact);
+ CContactCache *c = CContactCache::getContactCache(hContact);
if (c)
iMinLength = (iMinLength == 0 ? c->getMaxMessageLength() : min(c->getMaxMessageLength(), iMinLength));
}
- } while (hContact = db_find_next(hContact));
+ }
if (iSendLength >= iMinLength) {
TCHAR tszError[256];
-
mir_sntprintf(tszError, 256, TranslateT("The message cannot be sent delayed or to multiple contacts, because it exceeds the maximum allowed message length of %d bytes"), iMinLength);
::SendMessage(dat->hwnd, DM_ACTIVATETOOLTIP, IDC_MESSAGE, reinterpret_cast<LPARAM>(tszError));
sendQueue->clearJob(iEntry);
return 0;
}
- hContact = db_find_first();
- do {
- hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if (hItem && SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
doSendLater(iEntry, 0, hContact, false);
iJobs++;
}
- } while (hContact = db_find_next(hContact));
+ }
sendQueue->clearJob(iEntry);
if (iJobs)
diff --git a/plugins/TabSRMM/src/trayicon.cpp b/plugins/TabSRMM/src/trayicon.cpp
index 212ba2d8b4..5739275cbb 100644
--- a/plugins/TabSRMM/src/trayicon.cpp
+++ b/plugins/TabSRMM/src/trayicon.cpp
@@ -330,39 +330,39 @@ typedef struct _recentEntry {
void TSAPI LoadFavoritesAndRecent()
{
- RCENTRY *recentEntries, rceTemp;
DWORD dwRecent;
- int iIndex = 0, i, j;
- HANDLE hContact = db_find_first();
- recentEntries = new RCENTRY[nen_options.wMaxRecent + 1];
- if (recentEntries != NULL) {
- while (hContact != 0) {
- if (M->GetByte(hContact, SRMSGMOD_T, "isFavorite", 0))
- AddContactToFavorites(hContact, NULL, NULL, NULL, 0, 0, 1, PluginConfig.g_hMenuFavorites);
- if ((dwRecent = M->GetDword(hContact, "isRecent", 0)) != 0 && iIndex < nen_options.wMaxRecent) {
- recentEntries[iIndex].dwTimestamp = dwRecent;
- recentEntries[iIndex++].hContact = hContact;
- }
- hContact = db_find_next(hContact);
- }
- if (iIndex == 0) {
- free(recentEntries);
- return;
+ int iIndex = 0, i, j;
+
+ RCENTRY *recentEntries = new RCENTRY[nen_options.wMaxRecent + 1];
+ if (recentEntries == NULL)
+ return;
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ if (M->GetByte(hContact, SRMSGMOD_T, "isFavorite", 0))
+ AddContactToFavorites(hContact, NULL, NULL, NULL, 0, 0, 1, PluginConfig.g_hMenuFavorites);
+ if ((dwRecent = M->GetDword(hContact, "isRecent", 0)) != 0 && iIndex < nen_options.wMaxRecent) {
+ recentEntries[iIndex].dwTimestamp = dwRecent;
+ recentEntries[iIndex++].hContact = hContact;
}
+ }
- for (i=0; i < iIndex - 1; i++) {
- for (j = 0; j < iIndex - 1; j++) {
- if (recentEntries[j].dwTimestamp > recentEntries[j+1].dwTimestamp) {
- rceTemp = recentEntries[j];
- recentEntries[j] = recentEntries[j+1];
- recentEntries[j+1] = rceTemp;
- }
+ if (iIndex == 0) {
+ free(recentEntries);
+ return;
+ }
+
+ for (i=0; i < iIndex - 1; i++) {
+ for (j = 0; j < iIndex - 1; j++) {
+ if (recentEntries[j].dwTimestamp > recentEntries[j+1].dwTimestamp) {
+ RCENTRY rceTemp = recentEntries[j];
+ recentEntries[j] = recentEntries[j+1];
+ recentEntries[j+1] = rceTemp;
}
}
- for (i=0; i < iIndex; i++)
- AddContactToFavorites(recentEntries[i].hContact, NULL, NULL, NULL, 0, 0, 1, PluginConfig.g_hMenuRecent);
-
- delete[] recentEntries;
}
+ for (i=0; i < iIndex; i++)
+ AddContactToFavorites(recentEntries[i].hContact, NULL, NULL, NULL, 0, 0, 1, PluginConfig.g_hMenuRecent);
+
+ delete[] recentEntries;
}
diff --git a/plugins/TabSRMM/src/typingnotify.cpp b/plugins/TabSRMM/src/typingnotify.cpp
index 15a52ef814..3bef236dce 100644
--- a/plugins/TabSRMM/src/typingnotify.cpp
+++ b/plugins/TabSRMM/src/typingnotify.cpp
@@ -303,12 +303,10 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
case IDC_PREVIEW:
if (PluginConfig.g_PopupAvail) {
- HANDLE hContact = db_find_first();
- while (hContact) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
char *szProto = GetContactProto(hContact);
if (szProto != NULL)
break;
- hContact = db_find_next(hContact);
}
POPUPDATAT ppd = { 0 };