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/BasicHistory | |
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/BasicHistory')
-rw-r--r-- | plugins/BasicHistory/src/HistoryWindow.cpp | 52 | ||||
-rw-r--r-- | plugins/BasicHistory/src/Options.cpp | 41 |
2 files changed, 29 insertions, 64 deletions
diff --git a/plugins/BasicHistory/src/HistoryWindow.cpp b/plugins/BasicHistory/src/HistoryWindow.cpp index e5cd9c7384..5902dc3de8 100644 --- a/plugins/BasicHistory/src/HistoryWindow.cpp +++ b/plugins/BasicHistory/src/HistoryWindow.cpp @@ -1773,27 +1773,19 @@ void HistoryWindow::ReloadContacts() }
}
- HANDLE _hContact = db_find_first();
- while(_hContact)
- {
- if(EventList::GetContactMessageNumber(_hContact) && (metaContactProto == NULL || db_get_b(_hContact, metaContactProto, "IsSubcontact", 0) == 0))
+ HANDLE hContact;
+ for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ if(EventList::GetContactMessageNumber(hContact) && (metaContactProto == NULL || db_get_b(hContact, metaContactProto, "IsSubcontact", 0) == 0))
{
- HANDLE hItem = (HANDLE)SendMessage(contactList, CLM_FINDCONTACT, (WPARAM)_hContact, 0);
+ HANDLE hItem = (HANDLE)SendMessage(contactList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if(hItem == NULL)
- {
- SendMessage(contactList, CLM_ADDCONTACT, (WPARAM)_hContact, 0);
- }
+ SendMessage(contactList, CLM_ADDCONTACT, (WPARAM)hContact, 0);
}
- else
- {
- HANDLE hItem = (HANDLE)SendMessage(contactList, CLM_FINDCONTACT, (WPARAM)_hContact, 0);
+ else {
+ HANDLE hItem = (HANDLE)SendMessage(contactList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if(hItem != NULL)
- {
- SendMessage(contactList, CLM_DELETEITEM, (WPARAM)_hContact, 0);
- }
+ SendMessage(contactList, CLM_DELETEITEM, (WPARAM)hContact, 0);
}
-
- _hContact = db_find_next(_hContact);
}
if(hContact != NULL)
@@ -1944,17 +1936,14 @@ void HistoryWindow::SavePos(bool all) HANDLE contactToSave = hContact;
if(all)
{
- HANDLE _hContact = db_find_first();
- while(_hContact)
- {
- db_unset(_hContact, MODULE, "history_x");
- db_unset(_hContact, MODULE, "history_y");
- db_unset(_hContact, MODULE, "history_width");
- db_unset(_hContact, MODULE, "history_height");
- db_unset(_hContact, MODULE, "history_ismax");
- db_unset(_hContact, MODULE, "history_splitterv");
- db_unset(_hContact, MODULE, "history_splitter");
- _hContact = db_find_next(_hContact);
+ for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ db_unset(hContact, MODULE, "history_x");
+ db_unset(hContact, MODULE, "history_y");
+ db_unset(hContact, MODULE, "history_width");
+ db_unset(hContact, MODULE, "history_height");
+ db_unset(hContact, MODULE, "history_ismax");
+ db_unset(hContact, MODULE, "history_splitterv");
+ db_unset(hContact, MODULE, "history_splitter");
}
contactToSave = NULL;
@@ -2170,12 +2159,9 @@ void HistoryWindow::DoImport(IImport::ImportType type) std::vector<IImport::ExternalMessage> messages;
std::wstring err;
std::vector<HANDLE> contacts;
- HANDLE _hContact = db_find_first();
- while(_hContact)
- {
- contacts.push_back(_hContact);
- _hContact = db_find_next(_hContact);
- }
+
+ for(hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ contacts.push_back(hContact);
bool changeContact = false;
HANDLE lastContact = hContact;
diff --git a/plugins/BasicHistory/src/Options.cpp b/plugins/BasicHistory/src/Options.cpp index 3e9283df10..8e3d159289 100644 --- a/plugins/BasicHistory/src/Options.cpp +++ b/plugins/BasicHistory/src/Options.cpp @@ -598,18 +598,12 @@ void Options::SaveTasks(std::list<TaskOptions>* tasks) sprintf_s(buf, "Task_zipPassword_%d", i);
db_set_s(0, MODULE, buf, it->zipPassword.c_str());
- HANDLE _hContact = db_find_first();
sprintf_s(buf, "IsInTask_%d", i);
- while(_hContact)
- {
- db_unset(_hContact, MODULE, buf);
- _hContact = db_find_next(_hContact);
- }
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ db_unset(hContact, MODULE, buf);
for(size_t j = 0; j < it->contacts.size(); ++j)
- {
db_set_b(it->contacts[j], MODULE, buf, 1);
- }
it->orderNr = i++;
taskOptions.push_back(*it);
@@ -660,13 +654,9 @@ void Options::SaveTasks(std::list<TaskOptions>* tasks) sprintf_s(buf, "Task_taskName_%d", i);
db_unset(NULL, MODULE, buf);
- HANDLE _hContact = db_find_first();
sprintf_s(buf, "IsInTask_%d", i);
- while(_hContact)
- {
- db_unset(_hContact, MODULE, buf);
- _hContact = db_find_next(_hContact);
- }
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ db_unset(hContact, MODULE, buf);
}
LeaveCriticalSection(&criticalSection);
@@ -758,17 +748,10 @@ void Options::LoadTasks() db_free(&var);
}
- HANDLE _hContact = db_find_first();
sprintf_s(buf, "IsInTask_%d", i);
- while(_hContact)
- {
- if(db_get_b(_hContact, MODULE, buf, 0) == 1)
- {
- to.contacts.push_back(_hContact);
- }
-
- _hContact = db_find_next(_hContact);
- }
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ if(db_get_b(hContact, MODULE, buf, 0) == 1)
+ to.contacts.push_back(hContact);
to.orderNr = i;
taskOptions.push_back(to);
@@ -1765,19 +1748,15 @@ void RebuildList(HWND hwnd, HANDLE hSystem, TaskOptions* to) void SaveList(HWND hwnd, HANDLE hSystem, TaskOptions* to)
{
- HANDLE hContact, hItem;
-
to->contacts.clear();
if (hSystem)
to->isSystem = SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM) hSystem, 0) != 0;
- hContact = db_find_first();
- do
- {
- hItem = (HANDLE) SendMessage(hwnd, CLM_FINDCONTACT, (WPARAM) hContact, 0);
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE) SendMessage(hwnd, CLM_FINDCONTACT, (WPARAM) hContact, 0);
if (hItem && SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM) hItem, 0))
to->contacts.push_back(hContact);
}
- while (hContact = db_find_next(hContact));
}
bool IsValidTask(TaskOptions& to, std::list<TaskOptions>* top = NULL, std::wstring* err = NULL, std::wstring* errDescr = NULL);
|