diff options
author | George Hazan <george.hazan@gmail.com> | 2013-04-09 20:03:46 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-04-09 20:03:46 +0000 |
commit | bcb27264ba737778e5d3edad36088bacf74f0236 (patch) | |
tree | fd1f57744dd380b7babe312a0ab5dc60b48854f2 /plugins/NewsAggregator | |
parent | 940231dc5a484b03a278900e1880aa083472b601 (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/NewsAggregator')
-rw-r--r-- | plugins/NewsAggregator/Src/Options.cpp | 22 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Services.cpp | 16 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Update.cpp | 4 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Utils.cpp | 4 |
4 files changed, 14 insertions, 32 deletions
diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp index eb894a776b..44a3a4a5a7 100644 --- a/plugins/NewsAggregator/Src/Options.cpp +++ b/plugins/NewsAggregator/Src/Options.cpp @@ -153,8 +153,8 @@ INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP SendDlgItemMessage(hwndDlg, IDC_CHECKTIME, EM_LIMITTEXT, 3, 0);
SendDlgItemMessage(hwndDlg, IDC_TIMEOUT_VALUE_SPIN, UDM_SETRANGE32, 0, 999);
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+ HANDLE hContact;
+ for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if (IsMyContact(hContact)) {
DBVARIANT dbNick = {0};
if (db_get_ts(hContact, MODULE, "Nick", &dbNick))
@@ -197,7 +197,6 @@ INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP }
db_free(&dbNick);
}
- hContact = db_find_next(hContact);
}
WindowList_Add(hChangeFeedDlgList, hwndDlg, hContact);
Utils_RestoreWindowPositionNoSize(hwndDlg, hContact, MODULE, "ChangeDlg");
@@ -493,8 +492,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA ListView_GetItemText(hwndList, sel, 0, nick, MAX_PATH);
ListView_GetItemText(hwndList, sel, 1, url, MAX_PATH);
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if(IsMyContact(hContact)) {
DBVARIANT dbNick = {0};
if (db_get_ts(hContact, MODULE, "Nick", &dbNick))
@@ -514,7 +512,6 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA }
db_free(&dbNick);
}
- hContact = db_find_next(hContact);
}
}
return FALSE;
@@ -716,8 +713,8 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA HXML header = xi.addChild(hXml, _T("head"), NULL);
HXML title = xi.addChild(header, _T("title"), _T("Miranda NG NewsAggregator plugin export"));
header = xi.addChild(hXml, _T("body"), NULL);
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if (IsMyContact(hContact)) {
TCHAR *title = NULL, *url = NULL, *siteurl = NULL, *group = NULL;
DBVARIANT dbv = {0};
@@ -768,7 +765,6 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA mir_free(siteurl);
mir_free(group);
}
- hContact = db_find_next(hContact);
}
xi.toFile(hXml, FileName, 1);
xi.destroyNode(hXml);
@@ -789,12 +785,9 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA case PSN_APPLY:
{
db_set_b(NULL, MODULE, "StartupRetrieve", IsDlgButtonChecked(hwndDlg, IDC_STARTUPRETRIEVE));
- HANDLE hContact = db_find_first();
int i = 0;
- while (hContact != NULL)
- {
- if(IsMyContact(hContact))
- {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ if(IsMyContact(hContact)) {
db_set_b(hContact, MODULE, "CheckState", ListView_GetCheckState(hwndList, i));
if (!ListView_GetCheckState(hwndList, i))
db_set_b(hContact, "CList", "Hidden", 1);
@@ -802,7 +795,6 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA db_unset(hContact,"CList","Hidden");
i += 1;
}
- hContact = db_find_next(hContact);
}
break;
}
diff --git a/plugins/NewsAggregator/Src/Services.cpp b/plugins/NewsAggregator/Src/Services.cpp index 238e7f1145..da1c899b86 100644 --- a/plugins/NewsAggregator/Src/Services.cpp +++ b/plugins/NewsAggregator/Src/Services.cpp @@ -32,13 +32,10 @@ void SetContactStatus(HANDLE hContact, int nNewStatus) static void __cdecl WorkingThread(void* param)
{
int nStatus = (int)param;
- HANDLE hContact= db_find_first();
- while (hContact != NULL) {
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
if(IsMyContact(hContact))
SetContactStatus(hContact, nStatus);
-
- hContact = db_find_next(hContact);
- }
}
int OnFoldersChanged(WPARAM, LPARAM)
@@ -55,15 +52,14 @@ int NewsAggrInit(WPARAM wParam, LPARAM lParam) else
lstrcpyn(tszRoot, VARST( _T("%miranda_userdata%\\Avatars\\"_T(DEFAULT_AVATARS_FOLDER))), SIZEOF(tszRoot));
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if(IsMyContact(hContact)) {
if (!db_get_b(NULL, MODULE, "StartupRetrieve", 1))
db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
SetContactStatus(hContact, ID_STATUS_ONLINE);
}
- hContact = db_find_next(hContact);
}
+
NetlibInit();
InitIcons();
InitMenu();
@@ -158,13 +154,11 @@ INT_PTR NewsAggrGetInfo(WPARAM wParam,LPARAM lParam) INT_PTR CheckAllFeeds(WPARAM wParam,LPARAM lParam)
{
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if (IsMyContact(hContact) && lParam && db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME))
UpdateListAdd(hContact);
else if (IsMyContact(hContact) && !lParam)
UpdateListAdd(hContact);
- hContact = db_find_next(hContact);
}
if (!ThreadRunning)
mir_forkthread(UpdateThreadProc, (LPVOID)FALSE);
diff --git a/plugins/NewsAggregator/Src/Update.cpp b/plugins/NewsAggregator/Src/Update.cpp index 1846b7271a..7acc0373cc 100644 --- a/plugins/NewsAggregator/Src/Update.cpp +++ b/plugins/NewsAggregator/Src/Update.cpp @@ -30,8 +30,7 @@ VOID CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) // only run if it is not current updating and the auto update option is enabled
if (!ThreadRunning && !Miranda_Terminated()) {
BOOL HaveUpdates = FALSE;
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if(IsMyContact(hContact)) {
if (db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME)) {
double diff = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
@@ -41,7 +40,6 @@ VOID CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) }
}
}
- hContact = db_find_next(hContact);
}
if (!ThreadRunning && HaveUpdates)
mir_forkthread(UpdateThreadProc, (LPVOID)FALSE);
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp index d7efc461b6..745869e27d 100644 --- a/plugins/NewsAggregator/Src/Utils.cpp +++ b/plugins/NewsAggregator/Src/Utils.cpp @@ -239,9 +239,8 @@ VOID UpdateList(HWND hwndList) // Some code to create the list-view control.
// Initialize LVITEM members that are common to all
// items.
- HANDLE hContact = db_find_first();
int i = 0;
- while (hContact != NULL) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if (IsMyContact(hContact)) {
UpdateListFlag = TRUE;
lvI.mask = LVIF_TEXT;
@@ -263,7 +262,6 @@ VOID UpdateList(HWND hwndList) db_free(&dbNick);
}
}
- hContact = db_find_next(hContact);
}
UpdateListFlag = FALSE;
}
|