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/DbEditorPP/src | |
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/DbEditorPP/src')
-rw-r--r-- | plugins/DbEditorPP/src/copymodule.cpp | 66 | ||||
-rw-r--r-- | plugins/DbEditorPP/src/deletemodule.cpp | 99 | ||||
-rw-r--r-- | plugins/DbEditorPP/src/exportimport.cpp | 26 | ||||
-rw-r--r-- | plugins/DbEditorPP/src/modules.cpp | 15 | ||||
-rw-r--r-- | plugins/DbEditorPP/src/moduletree.cpp | 11 |
5 files changed, 73 insertions, 144 deletions
diff --git a/plugins/DbEditorPP/src/copymodule.cpp b/plugins/DbEditorPP/src/copymodule.cpp index fe3ec781d6..9a9772edb4 100644 --- a/plugins/DbEditorPP/src/copymodule.cpp +++ b/plugins/DbEditorPP/src/copymodule.cpp @@ -45,10 +45,7 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara {
int index, loaded;
char szProto[256];
- HANDLE hContact = db_find_first();
-
- while (hContact)
- {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if (GetValue(hContact,"Protocol","p",szProto,SIZEOF(szProto)))
loaded = IsProtocolLoaded(szProto);
else
@@ -56,10 +53,7 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara // filter
if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED))
- {
- hContact = db_find_next(hContact);
continue;
- }
// contacts name
DBVARIANT dbv ={0};
@@ -78,8 +72,7 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara else
mir_snwprintf(nick, SIZEOF(nick), L"%s (%s) %s", GetContactName(hContact, szProto, 1), protoW, L"(UNLOADED)");
}
- else
- wcscpy(nick, nick_unknownW);
+ else wcscpy(nick, nick_unknownW);
}
else {
if (Order)
@@ -90,8 +83,6 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara index = SendMessageW(GetDlgItem(hwnd, IDC_CONTACTS), CB_ADDSTRING, 0, (LPARAM)nick);
SendMessageW(GetDlgItem(hwnd, IDC_CONTACTS), CB_SETITEMDATA, index, (LPARAM)hContact);
-
- hContact = db_find_next(hContact);
}
index = (int)SendMessage(GetDlgItem(hwnd, IDC_CONTACTS), CB_INSERTSTRING, 0, (LPARAM)(char*)Translate("Settings"));
@@ -101,46 +92,33 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam);
TranslateDialogDefault(hwnd);
}
- else
- if (msg == WM_COMMAND)
+ else if (msg == WM_COMMAND)
{
- switch(LOWORD(wParam))
- {
- case CHK_COPY2ALL:
- EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS),!IsDlgButtonChecked(hwnd,CHK_COPY2ALL));
+ switch(LOWORD(wParam)) {
+ case CHK_COPY2ALL:
+ EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS),!IsDlgButtonChecked(hwnd,CHK_COPY2ALL));
break;
- case IDOK:
- {
- HANDLE hContact;
- if (!IsDlgButtonChecked(hwnd,CHK_COPY2ALL))
- {
- hContact = (HANDLE)SendMessage(GetDlgItem(hwnd, IDC_CONTACTS), CB_GETITEMDATA, SendMessage(GetDlgItem(hwnd, IDC_CONTACTS), CB_GETCURSEL, 0, 0), 0);
+ case IDOK:
+ if (!IsDlgButtonChecked(hwnd,CHK_COPY2ALL)) {
+ HANDLE hContact = (HANDLE)SendMessage(GetDlgItem(hwnd, IDC_CONTACTS), CB_GETITEMDATA, SendMessage(GetDlgItem(hwnd, IDC_CONTACTS), CB_GETCURSEL, 0, 0), 0);
+ copyModule(mac->module, mac->hContact, hContact);
+ }
+ else {
+ SetCursor(LoadCursor(NULL,IDC_WAIT));
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
copyModule(mac->module, mac->hContact, hContact);
- }
- else
- {
- SetCursor(LoadCursor(NULL,IDC_WAIT));
- hContact = db_find_first();
-
- while (hContact)
- {
- copyModule(mac->module, mac->hContact, hContact);
- hContact = db_find_next(hContact);
- }
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- }
- mir_free(mac);
- refreshTree(1);
- DestroyWindow(hwnd);
+ SetCursor(LoadCursor(NULL,IDC_ARROW));
}
+ mir_free(mac);
+ refreshTree(1);
+ DestroyWindow(hwnd);
break;
- case IDCANCEL:
- {
- mir_free(mac);
- DestroyWindow(hwnd);
- }
+
+ case IDCANCEL:
+ mir_free(mac);
+ DestroyWindow(hwnd);
break;
}
}
diff --git a/plugins/DbEditorPP/src/deletemodule.cpp b/plugins/DbEditorPP/src/deletemodule.cpp index 15998e74ad..5ceab04a3f 100644 --- a/plugins/DbEditorPP/src/deletemodule.cpp +++ b/plugins/DbEditorPP/src/deletemodule.cpp @@ -35,25 +35,20 @@ void __cdecl PopulateModuleDropListThreadFunc(LPVOID di) HWND hwnd = (HWND)di;
ModuleSettingLL msll;
struct ModSetLinkLinkItem *module;
- HANDLE hContact;
int moduleEmpty;
if (!EnumModules(&msll)) DestroyWindow(hwnd);
module = msll.first;
- while (module && working)
- {
+ while (module && working) {
moduleEmpty = 1;
// check the null
- if (!IsModuleEmpty(NULL,module->name))
- {
+ if (!IsModuleEmpty(NULL,module->name)) {
SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_ADDSTRING,0,(LPARAM)module->name);
moduleEmpty = 0;
module = (struct ModSetLinkLinkItem *)module->next;
continue;
}
- for (hContact = db_find_first();moduleEmpty && hContact;hContact = db_find_next(hContact))
- {
- if (!IsModuleEmpty(hContact,module->name))
- {
+ for (HANDLE hContact = db_find_first();moduleEmpty && hContact;hContact = db_find_next(hContact)) {
+ if (!IsModuleEmpty(hContact,module->name)) {
SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_ADDSTRING,0,(LPARAM)module->name);
moduleEmpty = 0;
break;
@@ -78,64 +73,52 @@ void __cdecl PopulateModuleDropListThreadFunc(LPVOID di) INT_PTR CALLBACK DeleteModuleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg)
- {
- case WM_INITDIALOG:
- {
- SetWindowText(hwnd,Translate("Delete module from Database... Loading"));
- EnableWindow(GetDlgItem(hwnd,IDC_CONTACTS),0);
- EnableWindow(GetDlgItem(hwnd,IDOK),0);
- SetDlgItemText(hwnd,IDC_INFOTEXT,"Delete module from Database");
- SetDlgItemText(hwnd,CHK_COPY2ALL,"Delete module from all contacts (Includes Setting)");
- EnableWindow(GetDlgItem(hwnd,CHK_COPY2ALL),0);
- CheckDlgButton(hwnd,CHK_COPY2ALL,1);
- TranslateDialogDefault(hwnd);
- working = 1;
- forkthread(PopulateModuleDropListThreadFunc,0,hwnd);
- }
+ switch(msg) {
+ case WM_INITDIALOG:
+ SetWindowText(hwnd,Translate("Delete module from Database... Loading"));
+ EnableWindow(GetDlgItem(hwnd,IDC_CONTACTS),0);
+ EnableWindow(GetDlgItem(hwnd,IDOK),0);
+ SetDlgItemText(hwnd,IDC_INFOTEXT,"Delete module from Database");
+ SetDlgItemText(hwnd,CHK_COPY2ALL,"Delete module from all contacts (Includes Setting)");
+ EnableWindow(GetDlgItem(hwnd,CHK_COPY2ALL),0);
+ CheckDlgButton(hwnd,CHK_COPY2ALL,1);
+ TranslateDialogDefault(hwnd);
+ working = 1;
+ forkthread(PopulateModuleDropListThreadFunc,0,hwnd);
return TRUE;
- case WM_COMMAND:
- switch(LOWORD(wParam))
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDOK:
{
- case IDOK:
- {
- char text[128];
- HANDLE hContact = db_find_first();
- GetDlgItemText(hwnd,IDC_CONTACTS,text,128);
- SetCursor(LoadCursor(NULL,IDC_WAIT));
- while (hContact)
- {
- deleteModule(text,hContact,1);
- hContact = db_find_next(hContact);
- }
- // do the null
- deleteModule(text,NULL,1);
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- refreshTree(1);
- }
- // fall through
- case IDCANCEL:
- {
- if (working == 1)
- {
- working = 0;
- EnableWindow(GetDlgItem(hwnd,IDCANCEL),0);
- }
- else
- DestroyWindow(hwnd);
- }
- break;
+ char text[128];
+ GetDlgItemText(hwnd,IDC_CONTACTS,text,128);
+ SetCursor(LoadCursor(NULL,IDC_WAIT));
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ deleteModule(text,hContact,1);
+
+ // do the null
+ deleteModule(text,NULL,1);
+ SetCursor(LoadCursor(NULL,IDC_ARROW));
+ refreshTree(1);
+ }
+ // fall through
+ case IDCANCEL:
+ if (working == 1) {
+ working = 0;
+ EnableWindow(GetDlgItem(hwnd,IDCANCEL),0);
}
+ else DestroyWindow(hwnd);
+ }
break;
- case WM_DESTROY:
- hwnd2Delete = NULL;
+
+ case WM_DESTROY:
+ hwnd2Delete = NULL;
break;
}
return 0;
}
-
-
void deleteModuleGui()
{
if (!hwnd2Delete)
diff --git a/plugins/DbEditorPP/src/exportimport.cpp b/plugins/DbEditorPP/src/exportimport.cpp index ed7aa6b371..f1e24cfc7c 100644 --- a/plugins/DbEditorPP/src/exportimport.cpp +++ b/plugins/DbEditorPP/src/exportimport.cpp @@ -329,32 +329,14 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. HANDLE CheckNewContact(char *myProto, char *uid, char *myName)
{
char szProto[256], szName[256];
- HANDLE resultHandle = INVALID_HANDLE_VALUE;
- HANDLE hContact = db_find_first();
- while (hContact)
- {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
if (DBGetContactSettingStringStatic(hContact, "Protocol", "p", szProto, 256))
- {
if (!mir_strcmp(szProto, myProto))
- {
- if (GetValue(hContact, szProto, uid, szName, SIZEOF(szName)) &&
- !mir_strcmp(szName, myName))
- {
- //char msg[1024];
- //_snprintf(msg, 1024, Translate("Do you want to overwrite it \"%s\"?"), szName);
- //if (MessageBox(0,msg, Translate("Contact already exists"), MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
- resultHandle = hContact;
- break;
- }
- }
- }
-
- hContact = db_find_next(hContact);
- }
-
- return resultHandle;
+ if (GetValue(hContact, szProto, uid, szName, SIZEOF(szName)) && !mir_strcmp(szName, myName))
+ return hContact;
+ return INVALID_HANDLE_VALUE;
}
HANDLE Clist_GroupExists(WCHAR *tszGroup)
diff --git a/plugins/DbEditorPP/src/modules.cpp b/plugins/DbEditorPP/src/modules.cpp index 898f581db3..aa4b77b6e5 100644 --- a/plugins/DbEditorPP/src/modules.cpp +++ b/plugins/DbEditorPP/src/modules.cpp @@ -61,21 +61,14 @@ INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam {
char modulename[256];
GetDlgItemText(hwnd, IDC_MODNAME, modulename, 256);
- if (IsDlgButtonChecked(hwnd,CHK_ADD2ALL))
- {
- HANDLE hContact = db_find_first();
+ if (IsDlgButtonChecked(hwnd,CHK_ADD2ALL)) {
// null contact
db_set_b(NULL, modulename, "(Default)", 0);
- while (hContact)
- {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
db_set_b(hContact, modulename, "(Default)", 0);
- hContact = db_find_next(hContact);
- }
- }
- else
- {
- db_set_b((HANDLE)GetWindowLongPtr(hwnd,GWLP_USERDATA), modulename, "(Default)", 0);
}
+ else db_set_b((HANDLE)GetWindowLongPtr(hwnd,GWLP_USERDATA), modulename, "(Default)", 0);
+
refreshTree(1);
}
}
diff --git a/plugins/DbEditorPP/src/moduletree.cpp b/plugins/DbEditorPP/src/moduletree.cpp index f1e4f348c7..6e3f8f35fd 100644 --- a/plugins/DbEditorPP/src/moduletree.cpp +++ b/plugins/DbEditorPP/src/moduletree.cpp @@ -9,7 +9,6 @@ static ModuleTreeInfoStruct settings_mtis = {CONTACT, 0}; int doContacts(HWND hwnd2Tree,HTREEITEM contactsRoot,ModuleSettingLL *modlist, HANDLE hSelectedContact, char *SelectedModule, char *SelectedSetting)
{
TVINSERTSTRUCT tvi;
- HANDLE hContact;
HTREEITEM contact;
ModuleTreeInfoStruct *lParam;
struct ModSetLinkLinkItem *module;
@@ -21,12 +20,10 @@ int doContacts(HWND hwnd2Tree,HTREEITEM contactsRoot,ModuleSettingLL *modlist, H SetWindowText(hwnd2mainWindow, Translate("Loading contacts..."));
- hContact = db_find_first();
-
tvi.hInsertAfter = TVI_SORT;
tvi.item.cChildren = 1;
- while (hContact && hwnd2mainWindow) { // break after null contact
+ for (HANDLE hContact = db_find_first(); hContact && hwnd2mainWindow; hContact = db_find_next(hContact)) {
char szProto[100];
if (DBGetContactSettingStringStatic(hContact, "Protocol", "p", szProto, SIZEOF(szProto))) {
icon = GetProtoIcon(szProto);
@@ -40,10 +37,8 @@ int doContacts(HWND hwnd2Tree,HTREEITEM contactsRoot,ModuleSettingLL *modlist, H i++;
// filter
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) {
- hContact = db_find_next(hContact);
+ if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED))
continue;
- }
// add the contact
lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
@@ -122,8 +117,6 @@ int doContacts(HWND hwnd2Tree,HTREEITEM contactsRoot,ModuleSettingLL *modlist, H hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule);
}
-
- hContact = db_find_next(hContact);
}
if (hItem != -1) {
|