From 7f35b5c32df443cf13dbb476c641e01f30db1d6c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 13 Jan 2014 15:19:47 +0000 Subject: encrypted settings are not displayed in dbeditor git-svn-id: http://svn.miranda-ng.org/main/trunk@7631 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/DbEditorPP/src/copymodule.cpp | 9 +- plugins/DbEditorPP/src/deletemodule.cpp | 10 +- plugins/DbEditorPP/src/exportimport.cpp | 18 +- plugins/DbEditorPP/src/findwindow.cpp | 581 +++++++--------- plugins/DbEditorPP/src/headers.h | 3 + plugins/DbEditorPP/src/icons.cpp | 4 +- plugins/DbEditorPP/src/main.cpp | 224 +++--- plugins/DbEditorPP/src/modsettingenum.cpp | 67 +- plugins/DbEditorPP/src/modsettingenum.h | 18 +- plugins/DbEditorPP/src/modules.cpp | 105 ++- plugins/DbEditorPP/src/moduletree.cpp | 16 +- plugins/DbEditorPP/src/settinglist.cpp | 1065 ++++++++++++++--------------- plugins/DbEditorPP/src/watchedvars.cpp | 4 +- 13 files changed, 996 insertions(+), 1128 deletions(-) (limited to 'plugins/DbEditorPP/src') diff --git a/plugins/DbEditorPP/src/copymodule.cpp b/plugins/DbEditorPP/src/copymodule.cpp index 9a9772edb4..e3884fb123 100644 --- a/plugins/DbEditorPP/src/copymodule.cpp +++ b/plugins/DbEditorPP/src/copymodule.cpp @@ -3,12 +3,11 @@ void copyModule(char* module, HANDLE hContactFrom, HANDLE hContactTo) { ModuleSettingLL msll; - struct ModSetLinkLinkItem *setting; - EnumSettings(hContactFrom,module, &msll); + EnumSettings(hContactFrom, module, &msll); - setting = msll.first; - while(setting) { + ModSetLinkLinkItem *setting = msll.first; + while (setting) { DBVARIANT dbv; if (!GetSetting(hContactFrom, module, setting->name, &dbv)) { switch (dbv.type) { @@ -33,7 +32,7 @@ void copyModule(char* module, HANDLE hContactFrom, HANDLE hContactTo) } } db_free(&dbv); - setting = (struct ModSetLinkLinkItem *)setting->next; + setting = setting->next; } FreeModuleSettingLL(&msll); } diff --git a/plugins/DbEditorPP/src/deletemodule.cpp b/plugins/DbEditorPP/src/deletemodule.cpp index 5ceab04a3f..3026a2523c 100644 --- a/plugins/DbEditorPP/src/deletemodule.cpp +++ b/plugins/DbEditorPP/src/deletemodule.cpp @@ -7,7 +7,7 @@ int deleteModule(char* module, HANDLE hContact, int fromMenu) { char msg[1024]; ModuleSettingLL settinglist; - struct ModSetLinkLinkItem *setting; + ModSetLinkLinkItem *setting; if (!module) return 0; @@ -24,7 +24,7 @@ int deleteModule(char* module, HANDLE hContact, int fromMenu) while (setting) { db_unset(hContact, module, setting->name); - setting = (struct ModSetLinkLinkItem *)setting->next; + setting = setting->next; } FreeModuleSettingLL(&settinglist); return 1; @@ -34,7 +34,7 @@ void __cdecl PopulateModuleDropListThreadFunc(LPVOID di) { HWND hwnd = (HWND)di; ModuleSettingLL msll; - struct ModSetLinkLinkItem *module; + ModSetLinkLinkItem *module; int moduleEmpty; if (!EnumModules(&msll)) DestroyWindow(hwnd); module = msll.first; @@ -44,7 +44,7 @@ void __cdecl PopulateModuleDropListThreadFunc(LPVOID di) if (!IsModuleEmpty(NULL,module->name)) { SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_ADDSTRING,0,(LPARAM)module->name); moduleEmpty = 0; - module = (struct ModSetLinkLinkItem *)module->next; + module = module->next; continue; } for (HANDLE hContact = db_find_first();moduleEmpty && hContact;hContact = db_find_next(hContact)) { @@ -55,7 +55,7 @@ void __cdecl PopulateModuleDropListThreadFunc(LPVOID di) } } - module = (struct ModSetLinkLinkItem *)module->next; + module = module->next; SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_SETCURSEL,0,0); } SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_SETCURSEL,0,0); diff --git a/plugins/DbEditorPP/src/exportimport.cpp b/plugins/DbEditorPP/src/exportimport.cpp index af821219b5..4a438546d2 100644 --- a/plugins/DbEditorPP/src/exportimport.cpp +++ b/plugins/DbEditorPP/src/exportimport.cpp @@ -85,7 +85,7 @@ void exportModule(HANDLE hContact, char* module, FILE* file) { char tmp[32]; ModuleSettingLL settinglist; - struct ModSetLinkLinkItem *setting; + ModSetLinkLinkItem *setting; EnumSettings(hContact,module,&settinglist); @@ -147,7 +147,7 @@ void exportModule(HANDLE hContact, char* module, FILE* file) break; } } - setting = (struct ModSetLinkLinkItem *)setting->next; + setting = (ModSetLinkLinkItem *)setting->next; } FreeModuleSettingLL(&settinglist); } @@ -199,7 +199,7 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. char fileName[MAX_PATH]; int nullcontactDone = 0; ModuleSettingLL modlist; - struct ModSetLinkLinkItem *mod; + ModSetLinkLinkItem *mod; // enum all the modules if (!EnumModules(&modlist)) { msg(Translate("Error Loading Module List"),modFullname); return;} @@ -223,11 +223,11 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. { if (IsModuleEmpty(hContact, mod->name)) { - mod = (struct ModSetLinkLinkItem *)mod->next; + mod = (ModSetLinkLinkItem *)mod->next; continue; } exportModule(hContact, mod->name, file); - mod = (struct ModSetLinkLinkItem *)mod->next; + mod = (ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); } @@ -268,11 +268,11 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. { if (IsModuleEmpty(hContact, mod->name)) { - mod = (struct ModSetLinkLinkItem *)mod->next; + mod = (ModSetLinkLinkItem *)mod->next; continue; } exportModule(hContact, mod->name, file); - mod = (struct ModSetLinkLinkItem *)mod->next; + mod = (ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); } @@ -299,11 +299,11 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. { if (IsModuleEmpty(hContact, mod->name)) { - mod = (struct ModSetLinkLinkItem *)mod->next; + mod = (ModSetLinkLinkItem *)mod->next; continue; } exportModule(hContact, mod->name, file); - mod = (struct ModSetLinkLinkItem *)mod->next; + mod = (ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); } diff --git a/plugins/DbEditorPP/src/findwindow.cpp b/plugins/DbEditorPP/src/findwindow.cpp index da1b9cf673..6ac376233d 100644 --- a/plugins/DbEditorPP/src/findwindow.cpp +++ b/plugins/DbEditorPP/src/findwindow.cpp @@ -31,185 +31,164 @@ typedef struct { } FindInfo; -int FindDialogResize(HWND hwnd,LPARAM lParam,UTILRESIZECONTROL *urc) +int FindDialogResize(HWND hwnd, LPARAM lParam, UTILRESIZECONTROL *urc) { - switch(urc->wId) { + switch (urc->wId) { case IDC_LIST: - return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT; + return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; case IDC_SBAR: - return RD_ANCHORX_WIDTH|RD_ANCHORY_BOTTOM; + return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; default: - return RD_ANCHORX_LEFT|RD_ANCHORY_TOP; + return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; } } - void freeItems(HWND hwnd) { - int i; - ItemInfo *ii; - for (i=0;ihwnd = GetDlgItem(hwnd,IDC_LIST); - fi->options = (IsDlgButtonChecked(hwnd,IDC_CASESENSITIVE)?FW_CASE:0)| - (IsDlgButtonChecked(hwnd,IDC_EXACT)?FW_EXACT:0)| - (IsDlgButtonChecked(hwnd,IDC_MODNAME)?FW_MODNAME:0)| - (IsDlgButtonChecked(hwnd,IDC_SETTINGNAME)?FW_SETNAME:0)| - (IsDlgButtonChecked(hwnd,IDC_SETTINGVALUE)?FW_SETVAL:0); - - if (GetWindowLongPtr(GetDlgItem(hwnd,IDC_REPLACE),GWLP_USERDATA)) - { - if (IsDlgButtonChecked(hwnd,IDC_FOUND)) - fi->mode = RW_FOUND; - else - if (IsDlgButtonChecked(hwnd,IDC_MODNAME2)) - fi->mode = RW_MODULE; - else - if (IsDlgButtonChecked(hwnd,IDC_SETTINGNAME2)) - fi->mode = RW_SETNAME; - else - if (IsDlgButtonChecked(hwnd,IDC_SETTINGVALUE2)) - fi->mode = RW_SETVAL; - - if (IsDlgButtonChecked(hwnd,IDC_ENTIRELY)) - fi->mode |= RW_FULL; - - fi->replace = mir_tstrdup(replace); - - SetWindowText(GetDlgItem(hwnd,IDOK),Translate("Stop")); - EnableWindow(GetDlgItem(hwnd,IDC_SEARCH),0); - - if (IsDlgButtonChecked(hwnd,IDC_CASESENSITIVE)) - fi->mode |= RW_CASE; - } - else - { - SetWindowText(GetDlgItem(hwnd,IDC_SEARCH),Translate("Stop")); - EnableWindow(GetDlgItem(hwnd,IDOK),0); - } + if (GetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA) && + !GetDlgItemText(hwnd, IDC_REPLACE, replace, SIZEOF(replace)) && + !IsDlgButtonChecked(hwnd, IDC_ENTIRELY)) + break; - fi->text = mir_tstrdup(text); + if (!IsDlgButtonChecked(hwnd, IDC_MODNAME) && + !IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) && + !IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE)) + break; - SendDlgItemMessage(hwnd,IDC_LIST,LB_RESETCONTENT,0,0); - SetWindowLongPtr(GetDlgItem(hwnd,IDC_SEARCH),GWLP_USERDATA,1); + FindInfo *fi = (FindInfo*)mir_calloc(sizeof(FindInfo)); + if (!fi) + break; - EnableWindow(GetDlgItem(hwnd,IDCANCEL),0); - forkthread(FindSettings,0,fi); - } + fi->hwnd = GetDlgItem(hwnd, IDC_LIST); + fi->options = (IsDlgButtonChecked(hwnd, IDC_CASESENSITIVE) ? FW_CASE : 0) | + (IsDlgButtonChecked(hwnd, IDC_EXACT) ? FW_EXACT : 0) | + (IsDlgButtonChecked(hwnd, IDC_MODNAME) ? FW_MODNAME : 0) | + (IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) ? FW_SETNAME : 0) | + (IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE) ? FW_SETVAL : 0); + + if (GetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA)) { + if (IsDlgButtonChecked(hwnd, IDC_FOUND)) + fi->mode = RW_FOUND; + else if (IsDlgButtonChecked(hwnd, IDC_MODNAME2)) + fi->mode = RW_MODULE; + else if (IsDlgButtonChecked(hwnd, IDC_SETTINGNAME2)) + fi->mode = RW_SETNAME; + else if (IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE2)) + fi->mode = RW_SETVAL; + + if (IsDlgButtonChecked(hwnd, IDC_ENTIRELY)) + fi->mode |= RW_FULL; + + fi->replace = mir_tstrdup(replace); + + SetWindowText(GetDlgItem(hwnd, IDOK), Translate("Stop")); + EnableWindow(GetDlgItem(hwnd, IDC_SEARCH), 0); + + if (IsDlgButtonChecked(hwnd, IDC_CASESENSITIVE)) + fi->mode |= RW_CASE; } - break; - case IDCANCEL: - DestroyWindow(hwnd); - break; - case IDC_LIST: - if (HIWORD(wParam) == LBN_DBLCLK) - { - int i = SendDlgItemMessage(hwnd,IDC_LIST,LB_GETCURSEL,0,0); - ItemInfo *ii =(ItemInfo*)SendDlgItemMessage(hwnd,IDC_LIST,LB_GETITEMDATA,i,0); - if (!ii) break; - SendMessage(GetParent(hwnd),WM_FINDITEM,(WPARAM)ii,0); - } - break; + else { + SetWindowText(GetDlgItem(hwnd, IDC_SEARCH), Translate("Stop")); + EnableWindow(GetDlgItem(hwnd, IDOK), 0); + } + + fi->text = mir_tstrdup(text); + + SendDlgItemMessage(hwnd, IDC_LIST, LB_RESETCONTENT, 0, 0); + SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 1); + + EnableWindow(GetDlgItem(hwnd, IDCANCEL), 0); + forkthread(FindSettings, 0, fi); + } + break; + + case IDCANCEL: + DestroyWindow(hwnd); + break; + case IDC_LIST: + if (HIWORD(wParam) == LBN_DBLCLK) { + int i = SendDlgItemMessage(hwnd, IDC_LIST, LB_GETCURSEL, 0, 0); + ItemInfo *ii = (ItemInfo*)SendDlgItemMessage(hwnd, IDC_LIST, LB_GETITEMDATA, i, 0); + if (!ii) break; + SendMessage(GetParent(hwnd), WM_FINDITEM, (WPARAM)ii, 0); } + break; + } break; - case WM_GETMINMAXINFO: + case WM_GETMINMAXINFO: { - MINMAXINFO *mmi=(MINMAXINFO*)lParam; - mmi->ptMinTrackSize.x=520; - mmi->ptMinTrackSize.y=300; - return 0; + MINMAXINFO *mmi = (MINMAXINFO*)lParam; + mmi->ptMinTrackSize.x = 520; + mmi->ptMinTrackSize.y = 300; } - case WM_SIZE: + return 0; + case WM_SIZE: { UTILRESIZEDIALOG urd; - ZeroMemory(&urd,sizeof(urd)); - urd.cbSize=sizeof(urd); - urd.hInstance=hInst; - urd.hwndDlg=hwnd; - urd.lpTemplate=MAKEINTRESOURCE(IDD_FIND); - urd.pfnResizer=FindDialogResize; - CallService(MS_UTILS_RESIZEDIALOG,0,(LPARAM)&urd); + ZeroMemory(&urd, sizeof(urd)); + urd.cbSize = sizeof(urd); + urd.hInstance = hInst; + urd.hwndDlg = hwnd; + urd.lpTemplate = MAKEINTRESOURCE(IDD_FIND); + urd.pfnResizer = FindDialogResize; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); } break; - case WM_DESTROY: - freeItems(hwnd); + + case WM_DESTROY: + freeItems(hwnd); break; } return 0; } - void ItemFound(HWND hwnd, HANDLE hContact,const char *module,const char *setting,const char* value,int type) { ItemInfo *ii = (ItemInfo*)mir_calloc(sizeof(ItemInfo)); + if (!ii) return; + int index; char text[256] = ""; int result = 0; char szValue[256]; char *name, *mode; - if (!ii) return; - if (type & FW_REPLACED) mode = Translate("Replaced with"); else @@ -220,57 +199,52 @@ void ItemFound(HWND hwnd, HANDLE hContact,const char *module,const char *setting name = hContact?(char*)GetContactName(hContact,NULL,0):Translate("Settings"); - switch (type & 0xFF) - { - case FW_MODULE: - ii->type = FW_MODULE; - mir_snprintf(text, SIZEOF(text), Translate("%s Module \"%s\" in contact \"%s\""), mode, module, name); + switch (type & 0xFF) { + case FW_MODULE: + ii->type = FW_MODULE; + mir_snprintf(text, SIZEOF(text), Translate("%s Module \"%s\" in contact \"%s\""), mode, module, name); break; - case FW_SETTINGNAME: - mir_strncpy(ii->setting,setting,256); - ii->type = FW_SETTINGNAME; - if (GetValue(hContact,module,setting, szValue, SIZEOF(szValue))) - mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\" - \"%s\""), mode, setting, module, name, szValue); - else - mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, setting, module, name); + case FW_SETTINGNAME: + mir_strncpy(ii->setting, setting, 256); + ii->type = FW_SETTINGNAME; + if (GetValue(hContact, module, setting, szValue, SIZEOF(szValue))) + mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\" - \"%s\""), mode, setting, module, name, szValue); + else + mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, setting, module, name); break; - case FW_SETTINGVALUE: - mir_strncpy(ii->setting,setting,256); - ii->type = FW_SETTINGVALUE; - mir_snprintf(text, SIZEOF(text), Translate("%s \"%s\" in Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, value, setting, module, name); + case FW_SETTINGVALUE: + mir_strncpy(ii->setting, setting, 256); + ii->type = FW_SETTINGVALUE; + mir_snprintf(text, SIZEOF(text), Translate("%s \"%s\" in Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, value, setting, module, name); break; } index = SendMessage(hwnd,LB_ADDSTRING,0,(LPARAM)text); - if (type & FW_DELETED) - { - SendMessage(hwnd,LB_SETITEMDATA,index,0); + if (type & FW_DELETED) { + SendMessage(hwnd, LB_SETITEMDATA, index, 0); mir_free(ii); } - else - { - ii->hContact= hContact; - mir_strncpy(ii->module,module,256); - SendMessage(hwnd,LB_SETITEMDATA,index,(LPARAM)ii); + else { + ii->hContact = hContact; + mir_strncpy(ii->module, module, 256); + SendMessage(hwnd, LB_SETITEMDATA, index, (LPARAM)ii); } } - -char *multiReplace(const char* value, const char *find, const char *replace, int cs) +char* multiReplace(const char* value, const char *find, const char *replace, int cs) { char *head, *temp, *string; int len = (int)strlen(find); int replen = (int)strlen(replace); - if (head = (char*)(cs?strstr(value, find):StrStrI(value, find))) // only should be 1 '=' sign there... - { + // only should be 1 '=' sign there... + if (head = (char*)(cs ? strstr(value, find) : StrStrI(value, find))) { string = (char*)value; - temp = (char*)mir_alloc(1*sizeof(char)); + temp = (char*)mir_alloc(1 * sizeof(char)); temp[0] = '\0'; - while (head) - { + while (head) { temp = (char*)mir_realloc(temp, strlen(temp) + strlen(string) + replen + 1); if (!temp) mir_tstrdup(value); @@ -278,7 +252,7 @@ char *multiReplace(const char* value, const char *find, const char *replace, int string = head + len; strcat(temp, replace); - head = (cs?strstr(string, find):StrStrI(string, find)); + head = (cs ? strstr(string, find) : StrStrI(string, find)); } strcat(temp, string); @@ -288,7 +262,6 @@ char *multiReplace(const char* value, const char *find, const char *replace, int return mir_tstrdup(value); } - int replaceValue(HWND hwnd, HANDLE hContact, const char *module, const char *setting, DBVARIANT *dbv, const char *find, const char *replace, int mode) { int count = 0; @@ -296,7 +269,7 @@ int replaceValue(HWND hwnd, HANDLE hContact, const char *module, const char *set BOOL write = 0; int isNumeric; char *myreplace = NULL; - DBVARIANT val = {0}; + DBVARIANT val = { 0 }; if (!dbv->type || dbv->type == DBVT_BLOB) return 0; @@ -304,11 +277,11 @@ int replaceValue(HWND hwnd, HANDLE hContact, const char *module, const char *set if (!replace[0]) isNumeric = 1; else - isNumeric = sscanf(replace,"%d",&num); + isNumeric = sscanf(replace, "%d", &num); - val.type=dbv->type; + val.type = dbv->type; - switch(dbv->type) { + switch (dbv->type) { case DBVT_UTF8: case DBVT_ASCIIZ: if (mode & RW_FULL) @@ -345,15 +318,15 @@ int replaceValue(HWND hwnd, HANDLE hContact, const char *module, const char *set } if ((!val.pszVal && !replace[0]) || (val.pszVal && !val.pszVal[0])) { - ItemFound(hwnd,hContact,module,setting,NULL,FW_SETTINGNAME|FW_DELETED); - db_unset(hContact,module,setting); + ItemFound(hwnd, hContact, module, setting, NULL, FW_SETTINGNAME | FW_DELETED); + db_unset(hContact, module, setting); mir_free(myreplace); return 1; } if (!db_set(hContact, module, setting, &val)) { count++; - ItemFound(hwnd,hContact,module,setting,myreplace?myreplace:(char*)replace,FW_SETTINGVALUE|FW_REPLACED); + ItemFound(hwnd, hContact, module, setting, myreplace ? myreplace : (char*)replace, FW_SETTINGVALUE | FW_REPLACED); } mir_free(myreplace); @@ -361,7 +334,6 @@ int replaceValue(HWND hwnd, HANDLE hContact, const char *module, const char *set return count; } - int replaceSetting(HWND hwnd, HANDLE hContact, const char *module, const char *setting, DBVARIANT *dbv, const char *find, const char *replace, int mode) { char *szSetting; @@ -379,16 +351,16 @@ int replaceSetting(HWND hwnd, HANDLE hContact, const char *module, const char *s } if (szSetting[0] == 0) { - ItemFound(hwnd,hContact,module,setting,NULL,FW_SETTINGNAME|FW_DELETED); + ItemFound(hwnd, hContact, module, setting, NULL, FW_SETTINGNAME | FW_DELETED); db_unset(hContact, module, setting); return 1; } // check & write - if ( GetSetting(hContact, module, myreplace, &dbv2)) { - if ( !db_set(hContact, module, szSetting, &dbv2)) { + if (GetSetting(hContact, module, myreplace, &dbv2)) { + if (!db_set(hContact, module, szSetting, &dbv2)) { count++; - db_unset(hContact,module,setting); + db_unset(hContact, module, setting); ItemFound(hwnd, hContact, module, szSetting, NULL, FW_SETTINGNAME | FW_REPLACED); } } @@ -400,26 +372,23 @@ int replaceSetting(HWND hwnd, HANDLE hContact, const char *module, const char *s int replaceModule(HWND hwnd, HANDLE hContact, const char *module, const char *find, const char *replace, int mode) { - ModuleSettingLL msll; - struct ModSetLinkLinkItem *setting; + ModSetLinkLinkItem *setting; char *myreplace = NULL; char *newModule; int count = 0; if (mode & RW_FULL) newModule = (char*)replace; - else - { + else { myreplace = multiReplace(module, find, replace, mode & RW_CASE); newModule = myreplace; } - if (newModule[0]==0) - { - ItemFound(hwnd,hContact,module,NULL,NULL,FW_MODULE|FW_DELETED); + if (newModule[0] == 0) { + ItemFound(hwnd, hContact, module, NULL, NULL, FW_MODULE | FW_DELETED); deleteModule((char*)module, hContact, 1); - replaceTreeItem(GetDlgItem(hwnd2mainWindow,IDC_MODULES), hContact, module, NULL); + replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, NULL); mir_free(myreplace); return 1; } @@ -427,35 +396,31 @@ int replaceModule(HWND hwnd, HANDLE hContact, const char *module, const char *fi if (!IsModuleEmpty(hContact, newModule)) return 0; - if (EnumSettings(hContact,(char*)module,&msll)) - { + if (EnumSettings(hContact, (char*)module, &msll)) { setting = msll.first; - while(setting) - { + while (setting) { DBVARIANT dbv; - if (!GetSetting(hContact, module, setting->name, &dbv)) - { - switch (dbv.type) - { - case DBVT_BYTE: - db_set_b(hContact, newModule, setting->name, dbv.bVal); + if (!GetSetting(hContact, module, setting->name, &dbv)) { + switch (dbv.type) { + case DBVT_BYTE: + db_set_b(hContact, newModule, setting->name, dbv.bVal); break; - case DBVT_WORD: - db_set_w(hContact, newModule, setting->name, dbv.wVal); + case DBVT_WORD: + db_set_w(hContact, newModule, setting->name, dbv.wVal); break; - case DBVT_DWORD: - db_set_dw(hContact, newModule, setting->name, dbv.dVal); + case DBVT_DWORD: + db_set_dw(hContact, newModule, setting->name, dbv.dVal); break; - case DBVT_ASCIIZ: - db_set_s(hContact, newModule, setting->name, dbv.pszVal); + case DBVT_ASCIIZ: + db_set_s(hContact, newModule, setting->name, dbv.pszVal); break; - case DBVT_UTF8: - db_set_utf(hContact, newModule, setting->name, dbv.pszVal); + case DBVT_UTF8: + db_set_utf(hContact, newModule, setting->name, dbv.pszVal); break; - case DBVT_BLOB: - db_set_blob(hContact, newModule, setting->name, dbv.pbVal, dbv.cpbVal); + case DBVT_BLOB: + db_set_blob(hContact, newModule, setting->name, dbv.pbVal, dbv.cpbVal); break; } @@ -463,36 +428,32 @@ int replaceModule(HWND hwnd, HANDLE hContact, const char *module, const char *fi db_unset(hContact, module, setting->name); } - setting = (struct ModSetLinkLinkItem *)setting->next; + setting = setting->next; } FreeModuleSettingLL(&msll); - replaceTreeItem(GetDlgItem(hwnd2mainWindow,IDC_MODULES), hContact, module, newModule); + replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, newModule); - ItemFound(hwnd,hContact,newModule,NULL,NULL,FW_MODULE|FW_REPLACED); + ItemFound(hwnd, hContact, newModule, NULL, NULL, FW_MODULE | FW_REPLACED); count++; } mir_free(myreplace); - return count; } - char* stringToUpper(char* in, char* out, int maxlen) { - int i; int len; - - if (maxlen>0) + if (maxlen > 0) len = maxlen - 1; else len = 0x10000; - for (i=0;in[i] && i='a' && in[i]<='z')?toupper(in[i]):in[i]; + int i; + for (i = 0; in[i] && i < len; i++) + out[i] = (in[i] >= 'a' && in[i] <= 'z') ? toupper(in[i]) : in[i]; out[i] = '\0'; - return out; } @@ -506,37 +467,39 @@ void __cdecl FindSettings(LPVOID di) HWND prnthwnd = GetParent(hwnd); int options = ((FindInfo*)di)->options; ModuleSettingLL ModuleList, SettingList; - struct ModSetLinkLinkItem *module, *setting; + ModSetLinkLinkItem *module, *setting; HANDLE hContact; - DBVARIANT dbv = {0}; - int caseSensitive = options&FW_CASE; - int exactMatch = options&FW_EXACT; - int inModuleName = options&FW_MODNAME; - int inSettingName = options&FW_SETNAME; - int inSettingValue = options&FW_SETVAL; + DBVARIANT dbv = { 0 }; + int caseSensitive = options & FW_CASE; + int exactMatch = options & FW_EXACT; + int inModuleName = options & FW_MODNAME; + int inSettingName = options & FW_SETNAME; + int inSettingValue = options & FW_SETVAL; int foundCount = 0; int replaceCount = 0; char szTmp[128]; int settingValue, isNumber, NULLContactDone = 0; freeItems(hwnd); - if (!text) return; + if (!text) + return; - if (!EnumModules(&ModuleList)) { msg(Translate("Error Loading Module List"),modFullname); mir_free(di); return;} + if (!EnumModules(&ModuleList)) { + msg(Translate("Error Loading Module List"), modFullname); + mir_free(di); + return; + } - SendMessage(GetDlgItem(GetParent(hwnd),IDC_SBAR),SB_SETTEXT,0,(LPARAM)Translate("Searching...")); + SendMessage(GetDlgItem(GetParent(hwnd), IDC_SBAR), SB_SETTEXT, 0, (LPARAM)Translate("Searching...")); hContact = 0; - isNumber = sscanf(text,"%d",&settingValue); + isNumber = sscanf(text, "%d", &settingValue); - while (GetWindowLongPtr(GetDlgItem(prnthwnd,IDC_SEARCH),GWLP_USERDATA)) - { - if (!hContact) - { + while (GetWindowLongPtr(GetDlgItem(prnthwnd, IDC_SEARCH), GWLP_USERDATA)) { + if (!hContact) { if (NULLContactDone) break; - else - { + else { NULLContactDone = 1; hContact = db_find_first(); } @@ -544,17 +507,14 @@ void __cdecl FindSettings(LPVOID di) else hContact = db_find_next(hContact); module = ModuleList.first; - while (module) - { - if (IsModuleEmpty(hContact, module->name)) - { - module = (struct ModSetLinkLinkItem *)module->next; + while (module) { + if (IsModuleEmpty(hContact, module->name)) { + module = module->next; continue; } - if (!EnumSettings(hContact,module->name,&SettingList)) - { - msg(Translate("Error Loading Setting List"),modFullname); + if (!EnumSettings(hContact, module->name, &SettingList)) { + msg(Translate("Error Loading Setting List"), modFullname); mir_free(text); mir_free(di); FreeModuleSettingLL(&ModuleList); @@ -563,60 +523,52 @@ void __cdecl FindSettings(LPVOID di) setting = SettingList.first; // check in settings value - while (setting) - { - if (inSettingValue) - { + while (setting) { + if (inSettingValue) { dbv.type = 0; // check the setting value - if (!GetSetting(hContact,module->name,setting->name,&dbv)) - { - switch (dbv.type) - { - case DBVT_UTF8: // no conversion atm - case DBVT_ASCIIZ: - if ((exactMatch && !(caseSensitive?strcmp(dbv.pszVal,text):strcmpi(dbv.pszVal,text))) || (!exactMatch && (caseSensitive?strstr(dbv.pszVal,text):StrStrI(dbv.pszVal,text)))) - { - if ((mode & RW_FOUND) || (mode & RW_SETVAL)) - replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode); - else - ItemFound(hwnd,hContact,module->name,setting->name,dbv.pszVal,FW_SETTINGVALUE); - - foundCount++; - } + if (!GetSetting(hContact, module->name, setting->name, &dbv)) { + switch (dbv.type) { + case DBVT_UTF8: // no conversion atm + case DBVT_ASCIIZ: + if ((exactMatch && !(caseSensitive ? strcmp(dbv.pszVal, text) : strcmpi(dbv.pszVal, text))) || (!exactMatch && (caseSensitive ? strstr(dbv.pszVal, text) : StrStrI(dbv.pszVal, text)))) { + if ((mode & RW_FOUND) || (mode & RW_SETVAL)) + replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode); + else + ItemFound(hwnd, hContact, module->name, setting->name, dbv.pszVal, FW_SETTINGVALUE); + + foundCount++; + } break; - case DBVT_BYTE: - if (isNumber && settingValue == dbv.bVal) - { - if ((mode & RW_FOUND) || (mode & RW_SETVAL)) - replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); - else - ItemFound(hwnd,hContact,module->name,setting->name,text,FW_SETTINGVALUE); - foundCount++; - } + case DBVT_BYTE: + if (isNumber && settingValue == dbv.bVal) { + if ((mode & RW_FOUND) || (mode & RW_SETVAL)) + replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); + else + ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE); + foundCount++; + } break; - case DBVT_WORD: - if (isNumber && settingValue == dbv.wVal) - { - if ((mode & RW_FOUND) || (mode & RW_SETVAL)) - replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); - else - ItemFound(hwnd,hContact,module->name,setting->name,text,FW_SETTINGVALUE); - foundCount++; - } + case DBVT_WORD: + if (isNumber && settingValue == dbv.wVal) { + if ((mode & RW_FOUND) || (mode & RW_SETVAL)) + replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); + else + ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE); + foundCount++; + } break; - case DBVT_DWORD: - if (isNumber && settingValue == (int)dbv.dVal) - { - if ((mode & RW_FOUND) || (mode & RW_SETVAL)) - replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); - else - ItemFound(hwnd,hContact,module->name,setting->name,text,FW_SETTINGVALUE); - foundCount++; - } + case DBVT_DWORD: + if (isNumber && settingValue == (int)dbv.dVal) { + if ((mode & RW_FOUND) || (mode & RW_SETVAL)) + replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); + else + ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE); + foundCount++; + } break; } @@ -625,69 +577,59 @@ void __cdecl FindSettings(LPVOID di) } // check in setting name - if (inSettingName) - { - if ((exactMatch && !(caseSensitive?strcmp(setting->name,text):strcmpi(setting->name,text))) || (!exactMatch && (caseSensitive?StrStrI(setting->name,text):StrStrI(setting->name,text)))) - { - if ((mode & RW_FOUND) || (mode & RW_SETNAME)) - { - if (!GetSetting(hContact,module->name,setting->name,&dbv)) - { + if (inSettingName) { + if ((exactMatch && !(caseSensitive ? strcmp(setting->name, text) : strcmpi(setting->name, text))) || (!exactMatch && (caseSensitive ? StrStrI(setting->name, text) : StrStrI(setting->name, text)))) { + if ((mode & RW_FOUND) || (mode & RW_SETNAME)) { + if (!GetSetting(hContact, module->name, setting->name, &dbv)) { replaceCount += replaceSetting(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode); db_free(&dbv); } } else - ItemFound(hwnd,hContact,module->name,setting->name, NULL, FW_SETTINGNAME); + ItemFound(hwnd, hContact, module->name, setting->name, NULL, FW_SETTINGNAME); foundCount++; } } - setting = (struct ModSetLinkLinkItem *)setting->next; + setting = (ModSetLinkLinkItem *)setting->next; } // check in module name - if (inModuleName) - { - if ((exactMatch && !(caseSensitive?strcmp(module->name,text):strcmpi(module->name,text))) || (!exactMatch && (caseSensitive?strstr(module->name,text):StrStrI(module->name,text)))) - { + if (inModuleName) { + if ((exactMatch && !(caseSensitive ? strcmp(module->name, text) : strcmpi(module->name, text))) || (!exactMatch && (caseSensitive ? strstr(module->name, text) : StrStrI(module->name, text)))) { if ((mode & RW_FOUND) || (mode & RW_MODULE)) replaceCount += replaceModule(hwnd, hContact, module->name, text, replace, mode); else - ItemFound(hwnd,hContact,module->name,0, 0, FW_MODULE); + ItemFound(hwnd, hContact, module->name, 0, 0, FW_MODULE); foundCount++; } } FreeModuleSettingLL(&SettingList); - module = (struct ModSetLinkLinkItem *)module->next; + module = (ModSetLinkLinkItem *)module->next; } } - if (mode) - { + if (mode) { if (!replace[0]) mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found, %d items were deleted."), foundCount, replaceCount); else mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found, %d items were replaced."), foundCount, replaceCount); } - else - mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found."), foundCount); + else mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found."), foundCount); - SendMessage(GetDlgItem(prnthwnd,IDC_SBAR),SB_SETTEXT,0,(LPARAM)szTmp); + SendMessage(GetDlgItem(prnthwnd, IDC_SBAR), SB_SETTEXT, 0, (LPARAM)szTmp); - SetWindowLongPtr(GetDlgItem(prnthwnd,IDC_SEARCH),GWLP_USERDATA,0); + SetWindowLongPtr(GetDlgItem(prnthwnd, IDC_SEARCH), GWLP_USERDATA, 0); - if (GetWindowLongPtr(GetDlgItem(prnthwnd,IDC_REPLACE),GWLP_USERDATA)) - { - SetWindowLongPtr(GetDlgItem(prnthwnd,IDC_REPLACE),GWLP_USERDATA, 0); - EnableWindow(GetDlgItem(prnthwnd,IDC_SEARCH),1); - SetWindowText(GetDlgItem(prnthwnd,IDOK),Translate("&Replace")); + if (GetWindowLongPtr(GetDlgItem(prnthwnd, IDC_REPLACE), GWLP_USERDATA)) { + SetWindowLongPtr(GetDlgItem(prnthwnd, IDC_REPLACE), GWLP_USERDATA, 0); + EnableWindow(GetDlgItem(prnthwnd, IDC_SEARCH), 1); + SetWindowText(GetDlgItem(prnthwnd, IDOK), Translate("&Replace")); } - else - { - SetWindowText(GetDlgItem(prnthwnd,IDC_SEARCH),Translate("&Search")); - EnableWindow(GetDlgItem(prnthwnd,IDOK),1); + else { + SetWindowText(GetDlgItem(prnthwnd, IDC_SEARCH), Translate("&Search")); + EnableWindow(GetDlgItem(prnthwnd, IDOK), 1); } mir_free(replace); @@ -695,6 +637,5 @@ void __cdecl FindSettings(LPVOID di) mir_free(di); FreeModuleSettingLL(&ModuleList); - EnableWindow(GetDlgItem(prnthwnd,IDCANCEL),1); - + EnableWindow(GetDlgItem(prnthwnd, IDCANCEL), 1); } diff --git a/plugins/DbEditorPP/src/headers.h b/plugins/DbEditorPP/src/headers.h index 15735b3cf0..d5bf500565 100644 --- a/plugins/DbEditorPP/src/headers.h +++ b/plugins/DbEditorPP/src/headers.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -166,6 +167,8 @@ extern int Mode; extern int Hex; extern int Order; +extern MIDatabase *g_db; + extern BOOL usePopups; #define NAMEORDERCOUNT 8 diff --git a/plugins/DbEditorPP/src/icons.cpp b/plugins/DbEditorPP/src/icons.cpp index 7aab4906e7..83d873b5e9 100644 --- a/plugins/DbEditorPP/src/icons.cpp +++ b/plugins/DbEditorPP/src/icons.cpp @@ -47,7 +47,7 @@ void AddProtoIconsToList(HIMAGELIST hil, int newshift) for (int i = 0; i < protoCount; i++) { HICON hIcon; - if (hIcon=LoadSkinnedProtoIcon(protocols[i]->szModuleName, ID_STATUS_ONLINE)) + if (hIcon = LoadSkinnedProtoIcon(protocols[i]->szModuleName, ID_STATUS_ONLINE)) AddIconToList(hil, hIcon); else AddIconToList(himl, LoadSkinnedDBEIcon(ICO_ONLINE)); @@ -56,7 +56,7 @@ void AddProtoIconsToList(HIMAGELIST hil, int newshift) int GetProtoIcon(char *szProto) { - if ( !protoCount || !protocols || !szProto) + if (!protoCount || !protocols || !szProto) return DEF_ICON; int n = 0; diff --git a/plugins/DbEditorPP/src/main.cpp b/plugins/DbEditorPP/src/main.cpp index c74fa638cb..642f73bb4d 100644 --- a/plugins/DbEditorPP/src/main.cpp +++ b/plugins/DbEditorPP/src/main.cpp @@ -2,6 +2,7 @@ HINSTANCE hInst = NULL; +MIDatabase *g_db; HANDLE hTTBButt = NULL; BOOL bServiceMode = FALSE; BOOL usePopups; @@ -17,7 +18,9 @@ HANDLE hModulesLoadedHook = NULL, hSettingsChangedHook=NULL, hOptInitHook=NULL, //======================== // MirandaPluginInfo //======================== -PLUGININFOEX pluginInfoEx={ + +PLUGININFOEX pluginInfoEx = +{ sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -55,25 +58,20 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam) DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam; HANDLE hContact = (HANDLE)wParam; char *setting; - int i; SettingListInfo* info; - if (hwnd2mainWindow) - { + if (hwnd2mainWindow) { HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS); - if (info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings,GWLP_USERDATA)) - { - if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule)) - { + if (info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA)) { + if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule)) { setting = mir_strdup(cws->szSetting); - if (cws->value.type == DBVT_DELETED) - { + if (cws->value.type == DBVT_DELETED) { LVFINDINFO lvfi; int index; lvfi.flags = LVFI_STRING; lvfi.psz = setting; lvfi.vkDirection = VK_DOWN; - index = ListView_FindItem(hwnd2Settings,-1,&lvfi); + index = ListView_FindItem(hwnd2Settings, -1, &lvfi); if (index > -1) ListView_DeleteItem(hwnd2Settings, index); mir_free(setting); @@ -84,17 +82,15 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam) } } } + // watch list - if (!hwnd2watchedVarsWindow && !usePopups) return 0; + if (!hwnd2watchedVarsWindow && !usePopups) + return 0; - for (i=0; iszModule, WatchListArray.item[i].module)) - { - if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting)) - { + for (int i = 0; i < WatchListArray.count; i++) { + if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact)) { + if (!mir_strcmp(cws->szModule, WatchListArray.item[i].module)) { + if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting)) { if (usePopups) popupWatchedVar(hContact, cws->szModule, cws->szSetting); if (hwnd2watchedVarsWindow) @@ -109,15 +105,12 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam) INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM lParam) { - - if (!hwnd2mainWindow) // so only opens 1 at a time - { + if (!hwnd2mainWindow) { // so only opens 1 at a time hRestore = (HANDLE)wParam; SetCursor(LoadCursor(NULL,IDC_WAIT)); CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), 0, MainDlgProc); } - else - { + else { ShowWindow(hwnd2mainWindow, SW_RESTORE); SetForegroundWindow(hwnd2mainWindow); if (!hRestore && wParam) { @@ -135,7 +128,6 @@ INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM lParam) BOOL IsCP_UTF8(void) { CPINFO CPInfo; - return GetCPInfo(CP_UTF8, &CPInfo); } @@ -167,7 +159,7 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam) ZeroMemory(&mi, sizeof(mi)); mi.cbSize = sizeof(mi); mi.position = 1900000001; - mi.flags = db_get_b(NULL,modname,"UserMenuItem",0) ? 0 : CMIF_HIDDEN; + mi.flags = db_get_b(NULL, modname, "UserMenuItem", 0) ? 0 : CMIF_HIDDEN; mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGUSER)); mi.pszName = LPGEN("Open user tree in DBE++"); mi.pszService = "DBEditorpp/MenuCommand"; @@ -179,7 +171,7 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam) hkd.pszService = "DBEditorpp/MenuCommand"; hkd.ptszDescription = LPGEN("Open Database Editor"); hkd.ptszSection = modFullname; - hkd.DefHotKey = HOTKEYCODE(HOTKEYF_SHIFT|HOTKEYF_EXT, 'D'); + hkd.DefHotKey = HOTKEYCODE(HOTKEYF_SHIFT | HOTKEYF_EXT, 'D'); Hotkey_Register(&hkd); // icons @@ -189,27 +181,27 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam) UnhookEvent(hModulesLoadedHook); - usePopups = db_get_b(NULL,modname,"UsePopUps",0); + usePopups = db_get_b(NULL, modname, "UsePopUps", 0); // Load the name order - for(int i=0; i < NAMEORDERCOUNT; i++) + for (int i = 0; i < NAMEORDERCOUNT; i++) nameOrder[i] = i; DBVARIANT dbv; - if (!db_get(NULL,"Contact","NameOrder",&dbv)) { - CopyMemory(nameOrder,dbv.pbVal,dbv.cpbVal); + if (!db_get(NULL, "Contact", "NameOrder", &dbv)) { + CopyMemory(nameOrder, dbv.pbVal, dbv.cpbVal); db_free(&dbv); } HookEvent(ME_TTB_MODULELOADED, OnTTBLoaded); - if ( bServiceMode ) - CallService("DBEditorpp/MenuCommand",0,0); + if (bServiceMode) + CallService("DBEditorpp/MenuCommand", 0, 0); return 0; } -int PreShutdown(WPARAM wParam,LPARAM lParam) +int PreShutdown(WPARAM wParam, LPARAM lParam) { if (hwnd2watchedVarsWindow) DestroyWindow(hwnd2watchedVarsWindow); if (hwnd2mainWindow) DestroyWindow(hwnd2mainWindow); @@ -225,13 +217,13 @@ int PreShutdown(WPARAM wParam,LPARAM lParam) return 0; } -INT_PTR ServiceMode(WPARAM wParam,LPARAM lParam) +INT_PTR ServiceMode(WPARAM wParam, LPARAM lParam) { bServiceMode = TRUE; return SERVICE_ONLYDB; // load database and then call us } -INT_PTR ImportFromFile(WPARAM wParam,LPARAM lParam) +INT_PTR ImportFromFile(WPARAM wParam, LPARAM lParam) { ImportSettingsFromFileMenuItem((HANDLE)wParam, (char*)lParam); return 0; @@ -241,23 +233,24 @@ extern "C" __declspec(dllexport) int Load(void) { mir_getLP(&pluginInfoEx); - hwnd2mainWindow = 0; - hwnd2watchedVarsWindow = 0; - hwnd2importWindow = 0; + hwnd2mainWindow = hwnd2watchedVarsWindow = hwnd2importWindow = 0; hRestore = NULL; - hSettingsChangedHook = HookEvent(ME_DB_CONTACT_SETTINGCHANGED,DBSettingChanged); - hOptInitHook = HookEvent(ME_OPT_INITIALISE,OptInit); + g_db = GetCurrentDatabase(); + + hSettingsChangedHook = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged); + hOptInitHook = HookEvent(ME_OPT_INITIALISE, OptInit); hPreShutdownHook = HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); - hModulesLoadedHook = HookEvent(ME_SYSTEM_MODULESLOADED,ModulesLoaded); + hModulesLoadedHook = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + sMenuCommand = CreateServiceFunction("DBEditorpp/MenuCommand", DBEditorppMenuCommand); sImport = CreateServiceFunction("DBEditorpp/Import", ImportFromFile); - + sServicemodeLaunch = CreateServiceFunction(MS_SERVICEMODE_LAUNCH, ServiceMode); // Ensure that the common control DLL is loaded. INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); - icex.dwICC = ICC_LISTVIEW_CLASSES; + icex.dwICC = ICC_LISTVIEW_CLASSES; InitCommonControlsEx(&icex); ZeroMemory(&WatchListArray, sizeof(WatchListArray)); @@ -270,23 +263,19 @@ extern "C" __declspec(dllexport) int Unload(void) return 0; } - - //======================================================= -//db_get_s (prob shouldnt use this unless u know how big the string is gonna be..) +// db_get_s (prob shouldnt use this unless u know how big the string is gonna be..) //======================================================= int DBGetContactSettingStringStatic(HANDLE hContact, char* szModule, char* szSetting, char* value, int maxLength) { DBVARIANT dbv; - if (!db_get(hContact, szModule, szSetting, &dbv)) - { + if (!db_get(hContact, szModule, szSetting, &dbv)) { strncpy(value, dbv.pszVal, maxLength); db_free(&dbv); return 1; } - else - { + else { db_free(&dbv); return 0; } @@ -301,22 +290,19 @@ int WriteBlobFromString(HANDLE hContact,const char *szModule,const char *szSetti BYTE b; int tmp; - if (!(data = (BYTE *)_alloca(2+len/2))) - { + if (!(data = (BYTE *)_alloca(2 + len / 2))) { msg(Translate("Couldn't allocate enough memory!"), modFullname); return 0; } - while(j='0' && b<='9') || - (b>='A' && b<='F') || - (b>='a' && b<='f')) + if ((b >= '0' && b <= '9') || + (b >= 'A' && b <= 'F') || + (b >= 'a' && b <= 'f')) { - if (sscanf(&szValue[j], "%02X", &tmp) == 1) - { + if (sscanf(&szValue[j], "%02X", &tmp) == 1) { data[i++] = (BYTE)tmp; j++; } @@ -325,12 +311,11 @@ int WriteBlobFromString(HANDLE hContact,const char *szModule,const char *szSetti } if (i) - return db_set_blob(hContact,szModule,szSetting, data, (WORD)i); + return db_set_blob(hContact, szModule, szSetting, data, (WORD)i); return 0; } - int GetSetting(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv) { return db_get_s(hContact, szModule, szSetting, dbv, 0); @@ -341,22 +326,22 @@ int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char* DBVARIANT dbv = {0}; if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv)) { - switch(dbv.type) { + switch (dbv.type) { case DBVT_ASCIIZ: strncpy(Value, dbv.pszVal, length); break; case DBVT_DWORD: - _itoa(dbv.dVal,Value,10); + _itoa(dbv.dVal, Value, 10); break; case DBVT_BYTE: - _itoa(dbv.bVal,Value,10); + _itoa(dbv.bVal, Value, 10); break; case DBVT_WORD: - _itoa(dbv.wVal,Value,10); + _itoa(dbv.wVal, Value, 10); break; case DBVT_UTF8: - int len = (int)strlen(dbv.pszVal)+1; - char *sz = (char*)_alloca(len*3); + int len = (int)strlen(dbv.pszVal) + 1; + char *sz = (char*)_alloca(len * 3); WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); WideCharToMultiByte(CP_ACP, 0, wc, -1, sz, len, NULL, NULL); @@ -366,7 +351,7 @@ int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char* db_free(&dbv); - Value[length-1] = 0; + Value[length - 1] = 0; return 1; } @@ -376,47 +361,44 @@ int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char* return 0; } - int GetValueW(HANDLE hContact, const char* szModule, const char* szSetting, WCHAR* Value, int length) { - DBVARIANT dbv ={0}; + DBVARIANT dbv = { 0 }; + WCHAR *wc; + int len; if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv)) { - switch(dbv.type) { + switch (dbv.type) { case DBVT_UTF8: - { - int len = (int)strlen(dbv.pszVal) + 1; - WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR)); - MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); - wcsncpy((WCHAR*)Value, wc, length); - } + len = (int)strlen(dbv.pszVal) + 1; + wc = (WCHAR*)_alloca(length*sizeof(WCHAR)); + MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); + wcsncpy((WCHAR*)Value, wc, length); break; case DBVT_ASCIIZ: - { - int len = (int)strlen(dbv.pszVal) + 1; - WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len); - wcsncpy((WCHAR*)Value, wc, length); - } + len = (int)strlen(dbv.pszVal) + 1; + wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len); + wcsncpy((WCHAR*)Value, wc, length); break; case DBVT_DWORD: - _itow(dbv.dVal,Value,10); + _itow(dbv.dVal, Value, 10); break; case DBVT_BYTE: - _itow(dbv.bVal,Value,10); + _itow(dbv.bVal, Value, 10); break; case DBVT_WORD: - _itow(dbv.wVal,Value,10); + _itow(dbv.wVal, Value, 10); break; } db_free(&dbv); - Value[length-1] = 0; + Value[length - 1] = 0; return 1; } @@ -426,29 +408,29 @@ int GetValueW(HANDLE hContact, const char* szModule, const char* szSetting, WCHA return 0; } -char *u2a( wchar_t* src ) +char* u2a(wchar_t *src) { - if (!src) - return NULL; + if (!src) + return NULL; - int cbLen = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL ); - char* result = (char*)mir_calloc((cbLen+1)*sizeof(char)); - if ( result == NULL ) + int cbLen = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL); + char* result = (char*)mir_calloc((cbLen + 1)*sizeof(char)); + if (result == NULL) return NULL; - WideCharToMultiByte( CP_ACP, 0, src, -1, result, cbLen, NULL, NULL ); - result[ cbLen ] = 0; + WideCharToMultiByte(CP_ACP, 0, src, -1, result, cbLen, NULL, NULL); + result[cbLen] = 0; return result; } -wchar_t *a2u( char* src , wchar_t *buffer, int len ) +wchar_t* a2u(char* src, wchar_t *buffer, int len) { wchar_t *result = buffer; - if ( result == NULL || len < 3) + if (result == NULL || len < 3) return NULL; - MultiByteToWideChar( CP_ACP, 0, src, -1, result, len - 1 ); - result[ len - 1 ] = 0; + MultiByteToWideChar(CP_ACP, 0, src, -1, result, len - 1); + result[len - 1] = 0; return result; } @@ -461,7 +443,7 @@ int GetDatabaseString(HANDLE hContact, const char *szModule, const char* szSetti return GetValue(hContact, szModule, szSetting, (char*)Value, length); } -WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode) +WCHAR* GetContactName(HANDLE hContact, const char *szProto, int unicode) { int i, r = 0; static WCHAR res[512]; @@ -469,46 +451,45 @@ WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode) char name[256]; if (hContact && !proto) - if (GetValue(hContact,"Protocol","p",name,SIZEOF(name))) - proto = name; + if (GetValue(hContact, "Protocol", "p", name, SIZEOF(name))) + proto = name; if (proto) { - for(i=0; i < NAMEORDERCOUNT-1; i++) { - switch(nameOrder[i]) { + for (i = 0; i < NAMEORDERCOUNT - 1; i++) { + switch (nameOrder[i]) { case 0: // custom name - r = GetDatabaseString(hContact,"CList","MyHandle",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, "CList", "MyHandle", res, SIZEOF(res), unicode); break; case 1: // nick - r = GetDatabaseString(hContact,proto,"Nick",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, proto, "Nick", res, SIZEOF(res), unicode); break; case 2: // First Name - r = GetDatabaseString(hContact,proto,"FirstName",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, proto, "FirstName", res, SIZEOF(res), unicode); break; case 3: // E-mail - r = GetDatabaseString(hContact,proto,"e-mail",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, proto, "e-mail", res, SIZEOF(res), unicode); break; case 4: // Last Name - if (GetDatabaseString(hContact,proto,"LastName",res,SIZEOF(res),unicode)) + if (GetDatabaseString(hContact, proto, "LastName", res, SIZEOF(res), unicode)) break; case 5: // Unique id { // protocol must define a PFLAG_UNIQUEIDSETTING - char *uid = (char*)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0); + char *uid = (char*)CallProtoService(proto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) - r = GetDatabaseString(hContact,proto,uid,res,SIZEOF(res),unicode); - break; + r = GetDatabaseString(hContact, proto, uid, res, SIZEOF(res), unicode); } + break; case 6: // first + last name { int len = 0; - if (r = GetDatabaseString(hContact,proto,"FirstName",res,SIZEOF(res),unicode)) - { + if (r = GetDatabaseString(hContact, proto, "FirstName", res, SIZEOF(res), unicode)) { if (unicode) len = (int)wcslen(res); else @@ -519,21 +500,22 @@ WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode) if (len && len < SIZEOF(res) - 2) { if (unicode) - wcscat(res,L" "); + wcscat(res, L" "); else - strcat((char*)res," "); + strcat((char*)res, " "); len++; } - if (SIZEOF(res)-len > 1) - r |= GetDatabaseString(hContact,proto,"LastName",&res[len],SIZEOF(res)-len,unicode); + if (SIZEOF(res) - len > 1) + r |= GetDatabaseString(hContact, proto, "LastName", &res[len], SIZEOF(res) - len, unicode); break; } } - if (r) return res; + if (r) + return res; } } diff --git a/plugins/DbEditorPP/src/modsettingenum.cpp b/plugins/DbEditorPP/src/modsettingenum.cpp index 7eaecdd1a0..96d198b682 100644 --- a/plugins/DbEditorPP/src/modsettingenum.cpp +++ b/plugins/DbEditorPP/src/modsettingenum.cpp @@ -2,42 +2,42 @@ void FreeModuleSettingLL(ModuleSettingLL* msll) { - if (msll) - { + if (msll == NULL) + return; - struct ModSetLinkLinkItem *item = msll->first; - struct ModSetLinkLinkItem *temp; + ModSetLinkLinkItem *item = msll->first; + ModSetLinkLinkItem *temp; - while (item) - { - mir_free(item->name); - temp = item; - item = (struct ModSetLinkLinkItem *)item->next; - mir_free(temp); - } - - msll->first = 0; - msll->last = 0; + while (item) { + mir_free(item->name); + temp = item; + item = (ModSetLinkLinkItem *)item->next; + mir_free(temp); } + + msll->first = 0; + msll->last = 0; } int enumModulesSettingsProc( const char *szName , DWORD ofsModuleName , LPARAM lParam) { ModuleSettingLL *msll = (ModuleSettingLL *)lParam; - if (!msll->first) - { - msll->first = (struct ModSetLinkLinkItem *)mir_alloc(sizeof(struct ModSetLinkLinkItem)); - if (!msll->first) return 1; + if (!msll->first) { + msll->first = (ModSetLinkLinkItem *)mir_alloc(sizeof(ModSetLinkLinkItem)); + if (!msll->first) + return 1; + msll->first->name = mir_tstrdup(szName); msll->first->next = 0; msll->last = msll->first; } - else - { - struct ModSetLinkLinkItem *item = (struct ModSetLinkLinkItem *)mir_alloc(sizeof(struct ModSetLinkLinkItem)); - if (!item) return 1; - msll->last->next = (BYTE*)item; - msll->last = (struct ModSetLinkLinkItem *)item; + else { + ModSetLinkLinkItem *item = (ModSetLinkLinkItem *)mir_alloc(sizeof(ModSetLinkLinkItem)); + if (!item) + return 1; + + msll->last->next = item; + msll->last = item; item->name = mir_tstrdup(szName); item->next = 0; } @@ -48,16 +48,14 @@ int EnumModules(ModuleSettingLL *msll) // 1 = success, 0 = fail { msll->first = 0; msll->last = 0; - return !CallService(MS_DB_MODULES_ENUM, (WPARAM)msll,(WPARAM)enumModulesSettingsProc); + return !CallService(MS_DB_MODULES_ENUM, (WPARAM)msll, (WPARAM)enumModulesSettingsProc); } - -int enumSettingsProc(const char *szSetting,LPARAM lParam) +int enumSettingsProc(const char *szSetting, LPARAM lParam) { - return enumModulesSettingsProc(szSetting,0,lParam); + return enumModulesSettingsProc(szSetting, 0, lParam); } - int EnumSettings(HANDLE hContact, char* module, ModuleSettingLL *msll) { DBCONTACTENUMSETTINGS dbces; @@ -67,10 +65,10 @@ int EnumSettings(HANDLE hContact, char* module, ModuleSettingLL *msll) dbces.lParam = (LPARAM)msll; msll->first = 0; msll->last = 0; - return !CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact,(LPARAM)&dbces); + return !CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact, (LPARAM)&dbces); } -int CheckIfModuleIsEmptyProc(const char *szSetting,LPARAM lParam) +int CheckIfModuleIsEmptyProc(const char *szSetting, LPARAM lParam) { return 1; } @@ -78,11 +76,10 @@ int CheckIfModuleIsEmptyProc(const char *szSetting,LPARAM lParam) int IsModuleEmpty(HANDLE hContact, char* szModule) { DBCONTACTENUMSETTINGS dbces; - int retVal; dbces.pfnEnumProc = CheckIfModuleIsEmptyProc; dbces.szModule = szModule; - retVal = CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact,(LPARAM)&dbces); + int retVal = CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact, (LPARAM)&dbces); if (retVal >= 0) return 0; - else return 1; -} \ No newline at end of file + return 1; +} diff --git a/plugins/DbEditorPP/src/modsettingenum.h b/plugins/DbEditorPP/src/modsettingenum.h index 9d1e0eff47..633d2d1470 100644 --- a/plugins/DbEditorPP/src/modsettingenum.h +++ b/plugins/DbEditorPP/src/modsettingenum.h @@ -1,16 +1,18 @@ -struct ModSetLinkLinkItem { +struct ModSetLinkLinkItem +{ char *name; - BYTE *next; //struct ModSetLinkLinkItem + ModSetLinkLinkItem *next; }; -typedef struct { - struct ModSetLinkLinkItem *first; - struct ModSetLinkLinkItem *last; -} ModuleSettingLL; +struct ModuleSettingLL +{ + ModSetLinkLinkItem *first; + ModSetLinkLinkItem *last; +}; int EnumModules(ModuleSettingLL *msll); -int EnumSettings(HANDLE hContact, char* module, ModuleSettingLL *msll); +int EnumSettings(HANDLE hContact, char *module, ModuleSettingLL *msll); void FreeModuleSettingLL(ModuleSettingLL *msll); -int IsModuleEmpty(HANDLE hContact, char* szModule); \ No newline at end of file +int IsModuleEmpty(HANDLE hContact, char *szModule); diff --git a/plugins/DbEditorPP/src/modules.cpp b/plugins/DbEditorPP/src/modules.cpp index aa4b77b6e5..603b601307 100644 --- a/plugins/DbEditorPP/src/modules.cpp +++ b/plugins/DbEditorPP/src/modules.cpp @@ -1,80 +1,71 @@ #include "headers.h" - void renameModule(char* oldName, char* newName, HANDLE hContact) { DBVARIANT dbv; ModuleSettingLL settinglist; - struct ModSetLinkLinkItem *setting; + ModSetLinkLinkItem *setting; - if (!EnumSettings(hContact,oldName,&settinglist)) { msg(Translate("Error Loading Setting List"),modFullname); return;} + if (!EnumSettings(hContact, oldName, &settinglist)) { msg(Translate("Error Loading Setting List"), modFullname); return; } setting = settinglist.first; - while (setting) - { - if (!GetSetting(hContact,oldName,setting->name,&dbv)) - { - switch (dbv.type) - { - case DBVT_BYTE: - db_set_b(hContact, newName, setting->name, dbv.bVal); + while (setting) { + if (!GetSetting(hContact, oldName, setting->name, &dbv)) { + switch (dbv.type) { + case DBVT_BYTE: + db_set_b(hContact, newName, setting->name, dbv.bVal); break; - case DBVT_WORD: - db_set_w(hContact, newName, setting->name, dbv.wVal); + case DBVT_WORD: + db_set_w(hContact, newName, setting->name, dbv.wVal); break; - case DBVT_DWORD: - db_set_dw(hContact, newName, setting->name, dbv.dVal); + case DBVT_DWORD: + db_set_dw(hContact, newName, setting->name, dbv.dVal); break; - case DBVT_ASCIIZ: - db_set_s(hContact, newName, setting->name, dbv.pszVal); + case DBVT_ASCIIZ: + db_set_s(hContact, newName, setting->name, dbv.pszVal); break; - case DBVT_UTF8: - db_set_utf(hContact, newName, setting->name, dbv.pszVal); + case DBVT_UTF8: + db_set_utf(hContact, newName, setting->name, dbv.pszVal); break; - case DBVT_BLOB: - db_set_blob(hContact, newName, setting->name, dbv.pbVal, dbv.cpbVal); + case DBVT_BLOB: + db_set_blob(hContact, newName, setting->name, dbv.pbVal, dbv.cpbVal); break; } db_unset(hContact, oldName, setting->name); } db_free(&dbv); - setting = (struct ModSetLinkLinkItem *)setting->next; + setting = (ModSetLinkLinkItem *)setting->next; } FreeModuleSettingLL(&settinglist); } INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (msg == WM_INITDIALOG) - { - SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam); + if (msg == WM_INITDIALOG) { + SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); TranslateDialogDefault(hwnd); } - if (msg == WM_COMMAND) - { - switch(LOWORD(wParam)) - { - case IDOK: - { - if (GetWindowTextLength(GetDlgItem(hwnd, IDC_MODNAME))) - { - char modulename[256]; - GetDlgItemText(hwnd, IDC_MODNAME, modulename, 256); - if (IsDlgButtonChecked(hwnd,CHK_ADD2ALL)) { - // null contact - db_set_b(NULL, modulename, "(Default)", 0); - for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) - db_set_b(hContact, modulename, "(Default)", 0); - } - else db_set_b((HANDLE)GetWindowLongPtr(hwnd,GWLP_USERDATA), modulename, "(Default)", 0); - refreshTree(1); + if (msg == WM_COMMAND) { + switch (LOWORD(wParam)) { + case IDOK: + if (GetWindowTextLength(GetDlgItem(hwnd, IDC_MODNAME))) { + char modulename[256]; + GetDlgItemText(hwnd, IDC_MODNAME, modulename, 256); + if (IsDlgButtonChecked(hwnd, CHK_ADD2ALL)) { + // null contact + db_set_b(NULL, modulename, "(Default)", 0); + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + db_set_b(hContact, modulename, "(Default)", 0); } + else db_set_b((HANDLE)GetWindowLongPtr(hwnd, GWLP_USERDATA), modulename, "(Default)", 0); + + refreshTree(1); } // fall through - case IDCANCEL: - DestroyWindow(hwnd); + case IDCANCEL: + DestroyWindow(hwnd); break; } } @@ -83,20 +74,22 @@ INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam int CloneContact(HANDLE hContact) { - HANDLE newContact = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0); + HANDLE newContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); + if (!newContact) + return 0; - ModuleSettingLL modlist; - struct ModSetLinkLinkItem *mod; - if (!newContact) return 0; // enum all the modules - if (!EnumModules(&modlist)) { msg(Translate("Error Loading Module List"),modFullname); return 0;} + ModuleSettingLL modlist; + if (!EnumModules(&modlist)) { + msg(Translate("Error Loading Module List"), modFullname); + return 0; + } - mod = modlist.first; - while (mod) - { - copyModule(mod->name,hContact,newContact); - mod = (struct ModSetLinkLinkItem *)mod->next; + ModSetLinkLinkItem *mod = modlist.first; + while (mod) { + copyModule(mod->name, hContact, newContact); + mod = (ModSetLinkLinkItem *)mod->next; } FreeModuleSettingLL(&modlist); return 1; -} \ No newline at end of file +} diff --git a/plugins/DbEditorPP/src/moduletree.cpp b/plugins/DbEditorPP/src/moduletree.cpp index 992bf1733d..bcbc1ac109 100644 --- a/plugins/DbEditorPP/src/moduletree.cpp +++ b/plugins/DbEditorPP/src/moduletree.cpp @@ -11,7 +11,7 @@ int doContacts(HWND hwnd2Tree,HTREEITEM contactsRoot,ModuleSettingLL *modlist, H TVINSERTSTRUCT tvi; HTREEITEM contact; ModuleTreeInfoStruct *lParam; - struct ModSetLinkLinkItem *module; + ModSetLinkLinkItem *module; int count = CallService(MS_DB_CONTACT_GETCOUNT, 0, 0); int itemscount = 0; int loaded, i = 0, icon = 0; @@ -105,7 +105,7 @@ int doContacts(HWND hwnd2Tree,HTREEITEM contactsRoot,ModuleSettingLL *modlist, H tvi.item.lParam = (LPARAM)lParam; TreeView_InsertItem(hwnd2Tree, &tvi); } - module = (struct ModSetLinkLinkItem *)module->next; + module = (ModSetLinkLinkItem *)module->next; } hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule); @@ -127,7 +127,7 @@ void doItems(HWND hwnd2Tree,ModuleSettingLL *modlist, int count) TVITEM item ={0}; HANDLE hContact; ModuleTreeInfoStruct *lParam; - struct ModSetLinkLinkItem *module; + ModSetLinkLinkItem *module; char percent[96], title[64]; HWND hwnd = GetParent(hwnd2Tree); int i = 0; @@ -177,7 +177,7 @@ void doItems(HWND hwnd2Tree,ModuleSettingLL *modlist, int count) tvi.item.lParam = (LPARAM)lParam; TreeView_InsertItem(hwnd2Tree, &tvi); } - module = (struct ModSetLinkLinkItem *)module->next; + module = (ModSetLinkLinkItem *)module->next; } } @@ -370,7 +370,7 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) ModuleTreeInfoStruct *lParam; // module list - struct ModSetLinkLinkItem *module; + ModSetLinkLinkItem *module; ModuleSettingLL modlist; hRestore = NULL; @@ -482,7 +482,7 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) TreeView_InsertItem(hwnd2Tree, &tvi); } - module = (struct ModSetLinkLinkItem *)module->next; + module = (ModSetLinkLinkItem *)module->next; } if (db_get_b(NULL,modname,"ExpandSettingsOnOpen",0)) @@ -556,7 +556,7 @@ void moduleListWM_NOTIFY(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)// hwnd HTREEITEM item = {0}; ModuleTreeInfoStruct *_lParam; HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow,IDC_MODULES); - struct ModSetLinkLinkItem *module; + ModSetLinkLinkItem *module; ModuleSettingLL modlist; HANDLE hContact = mtis->hContact; @@ -584,7 +584,7 @@ void moduleListWM_NOTIFY(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)// hwnd tvi.item.lParam = (LPARAM)_lParam; TreeView_InsertItem(hwnd2Tree, &tvi); } - module = (struct ModSetLinkLinkItem *)module->next; + module = (ModSetLinkLinkItem *)module->next; } FreeModuleSettingLL(&modlist); diff --git a/plugins/DbEditorPP/src/settinglist.cpp b/plugins/DbEditorPP/src/settinglist.cpp index db3f939418..fee9442032 100644 --- a/plugins/DbEditorPP/src/settinglist.cpp +++ b/plugins/DbEditorPP/src/settinglist.cpp @@ -2,60 +2,53 @@ void setupSettingsList(HWND hwnd2List) { - LVCOLUMN sLC; - ListView_SetUnicodeFormat(hwnd2List, TRUE); + LVCOLUMN sLC; sLC.fmt = LVCFMT_LEFT; - ListView_SetExtendedListViewStyle(hwnd2List, 32|LVS_EX_SUBITEMIMAGES); //LVS_EX_FULLROWSELECT + ListView_SetExtendedListViewStyle(hwnd2List, 32 | LVS_EX_SUBITEMIMAGES); //LVS_EX_FULLROWSELECT sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH; sLC.pszText = Translate("Name"); sLC.cx = db_get_w(NULL, modname, "Column0width", 145); - ListView_InsertColumn(hwnd2List,0,&sLC); + ListView_InsertColumn(hwnd2List, 0, &sLC); sLC.pszText = Translate("Data"); sLC.cx = db_get_w(NULL, modname, "Column1width", 145); - ListView_InsertColumn(hwnd2List,1,&sLC); + ListView_InsertColumn(hwnd2List, 1, &sLC); sLC.pszText = Translate("Type"); sLC.cx = db_get_w(NULL, modname, "Column2width", 60); - ListView_InsertColumn(hwnd2List,2,&sLC); + ListView_InsertColumn(hwnd2List, 2, &sLC); sLC.pszText = Translate("Size"); sLC.cx = db_get_w(NULL, modname, "Column3width", 80); - ListView_InsertColumn(hwnd2List,3,&sLC); + ListView_InsertColumn(hwnd2List, 3, &sLC); } - void saveListSettings(HWND hwnd2List) { - int i; LVCOLUMN sLC = {0}; char tmp[33]; tmp[32] = 0; sLC.mask = LVCF_WIDTH; - for (i=0; i <= 3; i++) - if (ListView_GetColumn(hwnd2List,i,&sLC)) - { + for (int i=0; i <= 3; i++) + if (ListView_GetColumn(hwnd2List, i, &sLC)) { mir_snprintf(tmp, SIZEOF(tmp), "Column%dwidth", i); db_set_w(NULL, modname, tmp, (WORD)sLC.cx); } - } void ClearListview(HWND hwnd2Settings) { SettingListInfo *info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings,GWLP_USERDATA); - if (info && ListView_GetItemCount(hwnd2Settings)) - { + if (info && ListView_GetItemCount(hwnd2Settings)) { mir_free(info->module); - if (info->hwnd2Edit) - { - SendMessage(info->hwnd2Edit,WM_COMMAND,MAKEWPARAM(IDCANCEL,0),0); + if (info->hwnd2Edit) { + SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); info->hwnd2Edit = NULL; } mir_free(info); - SetWindowLongPtr(hwnd2Settings,GWLP_USERDATA, 0); + SetWindowLongPtr(hwnd2Settings, GWLP_USERDATA, 0); } ListView_DeleteAllItems(hwnd2Settings); } @@ -65,164 +58,156 @@ void DeleteSettingsFromList(HWND hSettings, HANDLE hContact, char *module, char int count = ListView_GetSelectedCount(hSettings); if (!count) return; - else + if (count == 1) - { db_unset(hContact,module,setting); - } - else - { + else { int items = ListView_GetItemCount(hSettings); int i = 0; char text[256]; - while(iIsSettingEncrypted(module, setting)) { + lvi.iImage = 5; + ListView_SetItem(hwnd2Settings, &lvi); + + ListView_SetItemTextW(hwnd2Settings, index, 1, TranslateW(L"*** encrypted ***")); + + ListView_SetItemText(hwnd2Settings, index, 2, Translate("UNICODE")); + ListView_SetItemText(hwnd2Settings, index, 3, ""); + return; + } + + DBVARIANT dbv = { 0 }; + if (!GetSetting(hContact, module, setting, &dbv)) { + switch (dbv.type) { + case DBVT_BLOB: + if (!(data = (char*)mir_realloc(data, 3 * (dbv.cpbVal + 1) + 10))) { + msg(Translate("Couldn't allocate enough memory!"), modFullname); return; } + data[0] = '\0'; + for (int j = 0; j < dbv.cpbVal; j++) { + char tmp[16]; + mir_snprintf(tmp, SIZEOF(tmp), "%02X ", (BYTE)dbv.pbVal[j]); + strcat(data, tmp); + } + lvi.iImage = 0; + ListView_SetItem(hwnd2Settings, &lvi); + ListView_SetItemText(hwnd2Settings, index, 1, data); + ListView_SetItemText(hwnd2Settings, index, 2, Translate("BLOB")); + mir_snprintf(data, 3 * (dbv.cpbVal + 1) + 10, "0x%04X (%d)", dbv.cpbVal, dbv.cpbVal); + ListView_SetItemText(hwnd2Settings, index, 3, data); break; - case DBVT_BYTE: - if (!(data = (char*)mir_realloc(data, 16))) // 0x00 (000) - return; - lvi.iImage = 1; - ListView_SetItem(hwnd2Settings,&lvi); - mir_snprintf(data, 16, "0x%02X (%d)", dbv.bVal, dbv.bVal); - ListView_SetItemText(hwnd2Settings,index,1,data); - ListView_SetItemText(hwnd2Settings,index,2,Translate("BYTE")); - ListView_SetItemText(hwnd2Settings,index,3,"0x0001 (1)"); - break; - case DBVT_WORD: - if (!(data = (char*)mir_realloc(data, 16))) // 0x0000 (00000) - return; - - lvi.iImage = 2; - ListView_SetItem(hwnd2Settings,&lvi); - mir_snprintf(data, 16, "0x%04X (%ld)", dbv.wVal,dbv.wVal); - ListView_SetItemText(hwnd2Settings,index,1,data); - ListView_SetItemText(hwnd2Settings,index,2,Translate("WORD")); - ListView_SetItemText(hwnd2Settings,index,3,"0x0002 (2)"); + + case DBVT_BYTE: + if (!(data = (char*)mir_realloc(data, 16))) // 0x00 (000) + return; + lvi.iImage = 1; + ListView_SetItem(hwnd2Settings, &lvi); + mir_snprintf(data, 16, "0x%02X (%d)", dbv.bVal, dbv.bVal); + ListView_SetItemText(hwnd2Settings, index, 1, data); + ListView_SetItemText(hwnd2Settings, index, 2, Translate("BYTE")); + ListView_SetItemText(hwnd2Settings, index, 3, "0x0001 (1)"); break; - case DBVT_DWORD: - if (!(data = (char*)mir_realloc(data, 32))) // 0x00000000 (0000000000) - return; - - lvi.iImage = 3; - ListView_SetItem(hwnd2Settings,&lvi); - mir_snprintf(data, 32, "0x%08X (%ld)", dbv.dVal, dbv.dVal); - ListView_SetItemText(hwnd2Settings,index,1,data); - ListView_SetItemText(hwnd2Settings,index,2,Translate("DWORD")); - ListView_SetItemText(hwnd2Settings,index,3,"0x0004 (4)"); + + case DBVT_WORD: + if (!(data = (char*)mir_realloc(data, 16))) // 0x0000 (00000) + return; + + lvi.iImage = 2; + ListView_SetItem(hwnd2Settings, &lvi); + mir_snprintf(data, 16, "0x%04X (%ld)", dbv.wVal, dbv.wVal); + ListView_SetItemText(hwnd2Settings, index, 1, data); + ListView_SetItemText(hwnd2Settings, index, 2, Translate("WORD")); + ListView_SetItemText(hwnd2Settings, index, 3, "0x0002 (2)"); break; - case DBVT_ASCIIZ: - { - int length = mir_strlen(dbv.pszVal)+1; - if (!(data = (char*)mir_realloc(data, 512))) - return; + + case DBVT_DWORD: + if (!(data = (char*)mir_realloc(data, 32))) // 0x00000000 (0000000000) + return; + lvi.iImage = 3; + ListView_SetItem(hwnd2Settings, &lvi); + mir_snprintf(data, 32, "0x%08X (%ld)", dbv.dVal, dbv.dVal); + ListView_SetItemText(hwnd2Settings, index, 1, data); + ListView_SetItemText(hwnd2Settings, index, 2, Translate("DWORD")); + ListView_SetItemText(hwnd2Settings, index, 3, "0x0004 (4)"); + break; + + case DBVT_ASCIIZ: + if ((data = (char*)mir_realloc(data, 512))) { lvi.iImage = 4; - ListView_SetItem(hwnd2Settings,&lvi); - ListView_SetItemText(hwnd2Settings,index,1,dbv.pszVal); - ListView_SetItemText(hwnd2Settings,index,2,Translate("STRING")); - mir_snprintf(data, 512, "0x%04X (%d)", length,length); - ListView_SetItemText(hwnd2Settings,index,3,data); + ListView_SetItem(hwnd2Settings, &lvi); + ListView_SetItemText(hwnd2Settings, index, 1, dbv.pszVal); + ListView_SetItemText(hwnd2Settings, index, 2, Translate("STRING")); + int length = mir_strlen(dbv.pszVal) + 1; + mir_snprintf(data, 512, "0x%04X (%d)", length, length); + ListView_SetItemText(hwnd2Settings, index, 3, data); } break; - case DBVT_UTF8: - { - int length = (int)strlen(dbv.pszVal) + 1; - - if (!(data = (char*)mir_realloc(data, 512))) - return; - + + case DBVT_UTF8: + if ((data = (char*)mir_realloc(data, 512))) { lvi.iImage = 5; - ListView_SetItem(hwnd2Settings,&lvi); + ListView_SetItem(hwnd2Settings, &lvi); + int length = (int)strlen(dbv.pszVal) + 1; WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, length); - ListView_SetItemTextW(hwnd2Settings,index,1,wc); + ListView_SetItemTextW(hwnd2Settings, index, 1, wc); - ListView_SetItemText(hwnd2Settings,index,2,Translate("UNICODE")); - mir_snprintf(data, 512, "0x%04X (%d)", length,length); - ListView_SetItemText(hwnd2Settings,index,3,data); + ListView_SetItemText(hwnd2Settings, index, 2, Translate("UNICODE")); + mir_snprintf(data, 512, "0x%04X (%d)", length, length); + ListView_SetItemText(hwnd2Settings, index, 3, data); } break; - case DBVT_DELETED: - return; - break; - + + case DBVT_DELETED: + return; } } - else - if (dbv.type == DBVT_UTF8) - { + else if (dbv.type == DBVT_UTF8) { lvi.iImage = 5; - ListView_SetItem(hwnd2Settings,&lvi); - ListView_SetItemText(hwnd2Settings,index,1,Translate("")); - ListView_SetItemText(hwnd2Settings,index,2,Translate("UNICODE")); - ListView_SetItemText(hwnd2Settings,index,3,Translate("")); + ListView_SetItem(hwnd2Settings, &lvi); + ListView_SetItemText(hwnd2Settings, index, 1, Translate("")); + ListView_SetItemText(hwnd2Settings, index, 2, Translate("UNICODE")); + ListView_SetItemText(hwnd2Settings, index, 3, Translate("")); } - else - ListView_DeleteItem(hwnd2Settings,index); + else ListView_DeleteItem(hwnd2Settings, index); db_free(&dbv); mir_free(data); @@ -233,9 +218,12 @@ void PopulateSettings(HWND hwnd2Settings, HANDLE hContact, char* module) SettingListInfo* info = (SettingListInfo*)mir_calloc(sizeof(SettingListInfo)); LVITEM lvItem; - struct ModSetLinkLinkItem *setting; ModuleSettingLL setlist; - if (!EnumSettings(hContact,module,&setlist)) { msg(Translate("Error Loading Setting List"),modFullname); mir_free(info); return;} + if (!EnumSettings(hContact, module, &setlist)) { + msg(Translate("Error Loading Setting List"), modFullname); + mir_free(info); + return; + } // clear any settings that may be there... ClearListview(hwnd2Settings); @@ -245,42 +233,40 @@ void PopulateSettings(HWND hwnd2Settings, HANDLE hContact, char* module) SetWindowLongPtr(hwnd2Settings,GWLP_USERDATA, (LONG)info); // icons - if (himl2) ListView_SetImageList(hwnd2Settings, himl2, LVSIL_SMALL); + if (himl2) + ListView_SetImageList(hwnd2Settings, himl2, LVSIL_SMALL); lvItem.mask = LVIF_TEXT; lvItem.iItem = 0; lvItem.iSubItem = 0; - setting = setlist.first; - while (setting) - { + ModSetLinkLinkItem *setting = setlist.first; + while (setting) { lvItem.pszText = setting->name; - additem(hwnd2Settings,hContact,module, setting->name, ListView_InsertItem(hwnd2Settings,&lvItem)); - setting = (struct ModSetLinkLinkItem *)setting->next; + additem(hwnd2Settings, hContact, module, setting->name, ListView_InsertItem(hwnd2Settings, &lvItem)); + setting = (ModSetLinkLinkItem*)setting->next; } FreeModuleSettingLL(&setlist); } - -void SelectSetting(char* setting) +void SelectSetting(char *setting) { LVITEM lvItem; LVFINDINFO lvfi; - HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow,IDC_SETTINGS); + HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS); lvfi.flags = LVFI_STRING; lvfi.psz = setting; lvfi.vkDirection = VK_DOWN; lvItem.mask = LVIF_TEXT; - lvItem.iItem = ListView_FindItem(hwnd2Settings,-1,&lvfi); - if (lvItem.iItem != -1) - { + lvItem.iItem = ListView_FindItem(hwnd2Settings, -1, &lvfi); + if (lvItem.iItem != -1) { lvItem.mask = LVIF_STATE; lvItem.state = LVIS_SELECTED | LVIS_FOCUSED; lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; - ListView_SetItem(hwnd2Settings,&lvItem); + ListView_SetItem(hwnd2Settings, &lvItem); } } @@ -293,23 +279,23 @@ void settingChanged(HWND hwnd2Settings, HANDLE hContact, char* module, char* set lvfi.psz = setting; lvfi.vkDirection = VK_DOWN; - lvItem.mask = LVIF_TEXT|LVIF_IMAGE; - lvItem.iItem = ListView_FindItem(hwnd2Settings,-1,&lvfi); + lvItem.mask = LVIF_TEXT | LVIF_IMAGE; + lvItem.iItem = ListView_FindItem(hwnd2Settings, -1, &lvfi); lvItem.iSubItem = 0; - if (lvItem.iItem == -1) - { + if (lvItem.iItem == -1) { lvItem.iItem = 0; lvItem.pszText = setting; lvItem.cchTextMax = mir_strlen(setting); - lvItem.iItem = ListView_InsertItem(hwnd2Settings,&lvItem); + lvItem.iItem = ListView_InsertItem(hwnd2Settings, &lvItem); } - additem(hwnd2Settings,hContact,module, setting,lvItem.iItem); + additem(hwnd2Settings, hContact, module, setting, lvItem.iItem); } static WNDPROC SettingLabelEditSubClass; -typedef struct { +struct EditLabelInfoStruct +{ HANDLE hContact; char module[256]; char setting[256]; @@ -317,301 +303,289 @@ typedef struct { int subitem; HWND hwnd; int unicode; -} EditLabelInfoStruct; +}; void writeStandardTextfromLabel(EditLabelInfoStruct* info, char* value, WCHAR *wc, int type) { if (type != DBVT_ASCIIZ && type != DBVT_UTF8) - db_unset(info->hContact,info->module,info->setting); - if (type == DBVT_UTF8 && wc) - { - db_set_ws(info->hContact,info->module,info->setting,wc); + db_unset(info->hContact, info->module, info->setting); + + if (type == DBVT_UTF8 && wc) { + db_set_ws(info->hContact, info->module, info->setting, wc); mir_free(wc); } - else - db_set_s(info->hContact,info->module,info->setting,value); - + else db_set_s(info->hContact, info->module, info->setting, value); } static LRESULT CALLBACK SettingLabelEditSubClassProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { EditLabelInfoStruct* info = (EditLabelInfoStruct*)GetWindowLongPtr(hwnd,GWLP_USERDATA); - switch(msg) { - case WM_KEYDOWN: - switch (wParam) - { - case VK_RETURN: - if (GetKeyState(VK_CONTROL)&0x8000) // ctrl is pressed - break; - SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDOK,0),0); - return 0; - case VK_ESCAPE: - SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDCANCEL,0),0); - return 0; - } + switch (msg) { + case WM_KEYDOWN: + switch (wParam) { + case VK_RETURN: + if (GetKeyState(VK_CONTROL) & 0x8000) // ctrl is pressed + break; + SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0); + return 0; + case VK_ESCAPE: + SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); + return 0; + } break; - case WM_USER: - SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam); - SetFocus(hwnd); - SendMessage(hwnd, WM_SETFONT, SendMessage(GetParent(hwnd), WM_GETFONT, 0, 0), 1); - info = ((EditLabelInfoStruct*)lParam); - if (info->subitem) - SendMessage(hwnd, EM_LIMITTEXT, (WPARAM)65535, 0); - else - SendMessage(hwnd, EM_LIMITTEXT, (WPARAM)255, 0); - SendMessage(hwnd, EM_SETSEL,0,-1); + case WM_USER: + SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); + SetFocus(hwnd); + SendMessage(hwnd, WM_SETFONT, SendMessage(GetParent(hwnd), WM_GETFONT, 0, 0), 1); + info = ((EditLabelInfoStruct*)lParam); + if (info->subitem) + SendMessage(hwnd, EM_LIMITTEXT, (WPARAM)65535, 0); + else + SendMessage(hwnd, EM_LIMITTEXT, (WPARAM)255, 0); + SendMessage(hwnd, EM_SETSEL, 0, -1); break; - case WM_PAINT: + case WM_PAINT: break; - case WM_COMMAND: - switch (LOWORD(wParam)) + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: { - case IDOK: - { - int len = GetWindowTextLength(hwnd)+1; - char *value = (char*)_alloca(len); - WCHAR *wc = NULL; - DBVARIANT dbv = {0}; + int len = GetWindowTextLength(hwnd) + 1; + char *value = (char*)_alloca(len); + WCHAR *wc = NULL; + DBVARIANT dbv = { 0 }; - GetWindowText(hwnd,value,len); + GetWindowText(hwnd, value, len); - if (info->unicode) - wc = mir_a2u(value); + if (info->unicode) + wc = mir_a2u(value); - if (len <= 1 || GetSetting(info->hContact,info->module,info->setting, &dbv)) { - SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDCANCEL,0),0); + if (len <= 1 || GetSetting(info->hContact, info->module, info->setting, &dbv)) { + SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); + return 0; + } + + switch (info->subitem) { + case 0: // setting name + if (!mir_strcmp(info->setting, value) || mir_strlen(value) > 255) { + db_free(&dbv); + SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); return 0; } + switch (dbv.type) { + case DBVT_UTF8: + db_set_utf(info->hContact, info->module, value, dbv.pszVal); + break; + case DBVT_ASCIIZ: + db_set_s(info->hContact, info->module, value, dbv.pszVal); + break; + case DBVT_BYTE: + db_set_b(info->hContact, info->module, value, dbv.bVal); + break; + case DBVT_WORD: + db_set_w(info->hContact, info->module, value, dbv.wVal); + break; + case DBVT_DWORD: + db_set_dw(info->hContact, info->module, value, dbv.dVal); + break; + case DBVT_BLOB: + db_set_blob(info->hContact, info->module, value, dbv.pbVal, dbv.cpbVal); + break; + } + db_unset(info->hContact, info->module, info->setting); + { + LVFINDINFO lvfi; + lvfi.flags = LVFI_STRING; + lvfi.psz = info->setting; + lvfi.vkDirection = VK_DOWN; + int item = ListView_FindItem(info->hwnd, -1, &lvfi); + ListView_DeleteItem(info->hwnd, item); + } + break; + + case 1: // value + int val; + int i = 0; + + if (dbv.type == DBVT_BLOB) { + WriteBlobFromString(info->hContact, info->module, info->setting, value, len); + break; + } - switch (info->subitem) { - case 0:// setting name - if (!mir_strcmp(info->setting,value) || mir_strlen(value)>255) { - db_free(&dbv); - SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDCANCEL,0),0); - return 0; + switch (value[0]) { + case 'b': + case 'B': + if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X')) + sscanf(&value[3], "%x", &val); + else if (value[1] >= '0' && value[1] <= '9') { + val = atoi(&value[1]); + if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) + db_unset(info->hContact, info->module, info->setting); + + db_set_b(info->hContact, info->module, info->setting, (BYTE)val); } - switch (dbv.type) { - case DBVT_UTF8: - db_set_utf(info->hContact,info->module,value,dbv.pszVal); - break; - case DBVT_ASCIIZ: - db_set_s(info->hContact,info->module,value,dbv.pszVal); - break; - case DBVT_BYTE: - db_set_b(info->hContact,info->module,value,dbv.bVal); - break; - case DBVT_WORD: - db_set_w(info->hContact,info->module,value,dbv.wVal); - break; - case DBVT_DWORD: - db_set_dw(info->hContact,info->module,value,dbv.dVal); - break; - case DBVT_BLOB: - db_set_blob(info->hContact,info->module,value,dbv.pbVal,dbv.cpbVal); - break; + else writeStandardTextfromLabel(info, value, wc, dbv.type); + break; + case 'w': + case 'W': + if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X')) + sscanf(&value[3], "%x", &val); + else if (value[1] >= '0' && value[1] <= '9') { + val = atoi(&value[1]); + if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) + db_unset(info->hContact, info->module, info->setting); + db_set_w(info->hContact, info->module, info->setting, (WORD)val); } - db_unset(info->hContact,info->module,info->setting); - { - LVFINDINFO lvfi; - int item; - - lvfi.flags = LVFI_STRING; - lvfi.psz = info->setting; - lvfi.vkDirection = VK_DOWN; - - item = ListView_FindItem(info->hwnd,-1,&lvfi); - ListView_DeleteItem(info->hwnd,item); + else writeStandardTextfromLabel(info, value, wc, dbv.type); + break; + case 'd': + case 'D': + if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X')) + sscanf(&value[3], "%x", &val); + else if (value[1] >= '0' && value[1] <= '9') { + val = atoi(&value[1]); + if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) + db_unset(info->hContact, info->module, info->setting); + db_set_dw(info->hContact, info->module, info->setting, val); } + else writeStandardTextfromLabel(info, value, wc, dbv.type); break; - case 1: // value - { - int val; - int i = 0; - - if (dbv.type == DBVT_BLOB) { - WriteBlobFromString(info->hContact,info->module,info->setting,value,len); + case '0': + i = 1; + case 'x': + case 'X': + if (value[i] == 'x' || value[i] == 'X') { + sscanf(&value[i + 1], "%x", &val); + switch (dbv.type) { + case DBVT_UTF8: + case DBVT_ASCIIZ: + writeStandardTextfromLabel(info, value, wc, dbv.type); break; - } - - switch (value[0]) { - case 'b': - case 'B': - if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X')) - sscanf(&value[3],"%x",&val); - else if (value[1] >= '0' && value[1] <= '9') { - val = atoi(&value[1]); - if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) - db_unset(info->hContact,info->module,info->setting); - - db_set_b(info->hContact,info->module,info->setting,(BYTE)val); - } - else writeStandardTextfromLabel(info, value, wc, dbv.type); + case DBVT_BYTE: + db_set_b(info->hContact, info->module, info->setting, (BYTE)val); break; - case 'w': - case 'W': - if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X')) - sscanf(&value[3],"%x",&val); - else if (value[1] >= '0' && value[1] <= '9') { - val = atoi(&value[1]); - if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) - db_unset(info->hContact,info->module,info->setting); - db_set_w(info->hContact,info->module,info->setting,(WORD)val); - } - else writeStandardTextfromLabel(info, value, wc, dbv.type); + case DBVT_WORD: + db_set_w(info->hContact, info->module, info->setting, (WORD)val); break; - case 'd': - case 'D': - if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X')) - sscanf(&value[3],"%x",&val); - else if (value[1] >= '0' && value[1] <= '9') { - val = atoi(&value[1]); - if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) - db_unset(info->hContact,info->module,info->setting); - db_set_dw(info->hContact,info->module,info->setting,val); - } - else writeStandardTextfromLabel(info, value, wc, dbv.type); + case DBVT_DWORD: + db_set_dw(info->hContact, info->module, info->setting, (DWORD)val); break; - case '0': - i=1; - case 'x': - case 'X': - if (value[i] == 'x' || value[i] == 'X') { - sscanf(&value[i+1],"%x",&val); - switch (dbv.type) { - case DBVT_UTF8: - case DBVT_ASCIIZ: - writeStandardTextfromLabel(info, value, wc, dbv.type); - break; - case DBVT_BYTE: - db_set_b(info->hContact,info->module,info->setting,(BYTE)val); - break; - case DBVT_WORD: - db_set_w(info->hContact,info->module,info->setting,(WORD)val); - break; - case DBVT_DWORD: - db_set_dw(info->hContact,info->module,info->setting,(DWORD)val); - break; - } - } - else { - val = atoi(value); - switch (dbv.type) { - case DBVT_ASCIIZ: - case DBVT_UTF8: - writeStandardTextfromLabel(info, value, wc, dbv.type); - break; - case DBVT_BYTE: - db_set_b(info->hContact,info->module,info->setting,(BYTE)val); - break; - case DBVT_WORD: - db_set_w(info->hContact,info->module,info->setting,(WORD)val); - break; - case DBVT_DWORD: - db_set_dw(info->hContact,info->module,info->setting,(DWORD)val); - break; - } - } + } + } + else { + val = atoi(value); + switch (dbv.type) { + case DBVT_ASCIIZ: + case DBVT_UTF8: + writeStandardTextfromLabel(info, value, wc, dbv.type); break; - case '\"': - case '\'': - { - int nlen = mir_strlen(value); - int sh = 0; - if (nlen > 3) - { - if (value[nlen-1] == value[0]) - { - value[nlen-1] = '\0'; - sh = 1; - } - } - writeStandardTextfromLabel(info, &value[sh], wc, dbv.type); - } + case DBVT_BYTE: + db_set_b(info->hContact, info->module, info->setting, (BYTE)val); break; - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '-': - val = atoi(value); - switch (dbv.type) { - case DBVT_ASCIIZ: - case DBVT_UTF8: - writeStandardTextfromLabel(info, value, wc, dbv.type); - break; - case DBVT_BYTE: - db_set_b(info->hContact,info->module,info->setting,(BYTE)val); - break; - case DBVT_WORD: - db_set_w(info->hContact,info->module,info->setting,(WORD)val); - break; - case DBVT_DWORD: - db_set_dw(info->hContact,info->module,info->setting,(DWORD)val); - break; - } + case DBVT_WORD: + db_set_w(info->hContact, info->module, info->setting, (WORD)val); break; - default: - writeStandardTextfromLabel(info, value, wc, dbv.type); + case DBVT_DWORD: + db_set_dw(info->hContact, info->module, info->setting, (DWORD)val); break; - } // switch (value[0]) + } } - break; // case 1: - } - db_free(&dbv); - } // fall through - case IDCANCEL: - { - SettingListInfo *sli = (SettingListInfo*)GetWindowLongPtr(info->hwnd,GWLP_USERDATA); - - if (sli && sli->hwnd2Edit==hwnd) - sli->hwnd2Edit = NULL; - - mir_free(info); - DestroyWindow(hwnd); + break; + case '\"': + case '\'': + { + int nlen = mir_strlen(value); + int sh = 0; + if (nlen > 3) { + if (value[nlen - 1] == value[0]) { + value[nlen - 1] = '\0'; + sh = 1; + } + } + writeStandardTextfromLabel(info, &value[sh], wc, dbv.type); + } + break; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + val = atoi(value); + switch (dbv.type) { + case DBVT_ASCIIZ: + case DBVT_UTF8: + writeStandardTextfromLabel(info, value, wc, dbv.type); + break; + case DBVT_BYTE: + db_set_b(info->hContact, info->module, info->setting, (BYTE)val); + break; + case DBVT_WORD: + db_set_w(info->hContact, info->module, info->setting, (WORD)val); + break; + case DBVT_DWORD: + db_set_dw(info->hContact, info->module, info->setting, (DWORD)val); + break; + } + break; + + default: + writeStandardTextfromLabel(info, value, wc, dbv.type); + break; } - return 0; - } + break; + } + db_free(&dbv); + } // fall through + case IDCANCEL: + SettingListInfo *sli = (SettingListInfo*)GetWindowLongPtr(info->hwnd, GWLP_USERDATA); + if (sli && sli->hwnd2Edit == hwnd) + sli->hwnd2Edit = NULL; + + mir_free(info); + DestroyWindow(hwnd); + return 0; + } break; // wm_command - case WM_GETDLGCODE: - return DLGC_WANTALLKEYS; + + case WM_GETDLGCODE: + return DLGC_WANTALLKEYS; } - return CallWindowProcW(SettingLabelEditSubClass,hwnd,msg,wParam,lParam); + return CallWindowProcW(SettingLabelEditSubClass, hwnd, msg, wParam, lParam); } - void EditLabel(HWND hwnd2List, int item, int subitem) { RECT rc; - LVITEM lvi; - char setting[256], value[16] = {0}; + char setting[256], value[16] = { 0 }; DBVARIANT dbv; - SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(hwnd2List,GWLP_USERDATA); + SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(hwnd2List, GWLP_USERDATA); EditLabelInfoStruct *data = (EditLabelInfoStruct*)mir_calloc(sizeof(EditLabelInfoStruct)); - if (!data || !info) return; - if (info->hwnd2Edit) - { - SendMessage(info->hwnd2Edit,WM_COMMAND,MAKEWPARAM(IDCANCEL,0),0); // ignore the new value of the last edit + if (!data || !info) + return; + + if (info->hwnd2Edit) { + SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); // ignore the new value of the last edit info->hwnd2Edit = NULL; } + + LVITEM lvi; lvi.mask = LVIF_TEXT; lvi.iItem = item; lvi.iSubItem = 0; lvi.pszText = setting; lvi.cchTextMax = 256; - if (!ListView_GetItem(hwnd2List, &lvi) || !ListView_GetSubItemRect - (hwnd2List,item,subitem,LVIR_LABEL,&rc) || - GetSetting(info->hContact,info->module,setting,&dbv)) - { - mir_free(data); - return; - } + (hwnd2List, item, subitem, LVIR_LABEL, &rc) || + GetSetting(info->hContact, info->module, setting, &dbv)) { + mir_free(data); + return; + } data->hContact = info->hContact; strcpy(data->module, info->module); @@ -622,191 +596,168 @@ void EditLabel(HWND hwnd2List, int item, int subitem) // fix size for long strings - switch (dbv.type) - { - case DBVT_UTF8: - if (subitem) - { - int len = mir_strlen(dbv.pszVal)+1; - WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); - MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); - data->unicode = 1; - info->hwnd2Edit = CreateWindowW(L"EDIT",wc,WS_BORDER|WS_VISIBLE|WS_CHILD|WS_VSCROLL|ES_MULTILINE|ES_AUTOHSCROLL, rc.left,rc.top,(int)((rc.right - rc.left)*1.5),(rc.bottom - rc.top)*3,hwnd2List, 0,hInst,0); - break; - } - // fall through - case DBVT_ASCIIZ: - if (subitem) { - // convert from UTF8 - info->hwnd2Edit = CreateWindow("EDIT",dbv.pszVal,WS_BORDER|WS_VISIBLE|WS_CHILD|WS_VSCROLL|ES_MULTILINE|ES_AUTOHSCROLL, rc.left,rc.top,(int)((rc.right - rc.left)*1.5),(rc.bottom - rc.top)*3,hwnd2List, 0,hInst,0); - } - else - info->hwnd2Edit = CreateWindow("EDIT",setting,WS_BORDER|WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL, rc.left,rc.top,(rc.right - rc.left),(rc.bottom - rc.top),hwnd2List, 0,hInst,0); + switch (dbv.type) { + case DBVT_UTF8: + if (subitem) { + int len = mir_strlen(dbv.pszVal) + 1; + WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); + MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); + data->unicode = 1; + info->hwnd2Edit = CreateWindowW(L"EDIT", wc, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL, rc.left, rc.top, (int)((rc.right - rc.left)*1.5), (rc.bottom - rc.top) * 3, hwnd2List, 0, hInst, 0); + break; + } + // fall through + case DBVT_ASCIIZ: + if (subitem) // convert from UTF8 + info->hwnd2Edit = CreateWindow("EDIT", dbv.pszVal, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL, rc.left, rc.top, (int)((rc.right - rc.left)*1.5), (rc.bottom - rc.top) * 3, hwnd2List, 0, hInst, 0); + else + info->hwnd2Edit = CreateWindow("EDIT", setting, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0); break; - case DBVT_BYTE: - if (Hex&HEX_BYTE) - mir_snprintf(value, SIZEOF(value), "0x%02X", dbv.bVal); - else - itoa(dbv.bVal,value,10); - info->hwnd2Edit = CreateWindow("EDIT",!subitem?setting:value,WS_BORDER|WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL, rc.left,rc.top,(rc.right - rc.left),(rc.bottom - rc.top),hwnd2List, 0,hInst,0); + case DBVT_BYTE: + if (Hex & HEX_BYTE) + mir_snprintf(value, SIZEOF(value), "0x%02X", dbv.bVal); + else + itoa(dbv.bVal, value, 10); + info->hwnd2Edit = CreateWindow("EDIT", !subitem ? setting : value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0); break; - case DBVT_WORD: - if (Hex&HEX_WORD) - mir_snprintf(value, SIZEOF(value), "0x%04X", dbv.wVal); - else - itoa(dbv.wVal,value,10); - info->hwnd2Edit = CreateWindow("EDIT",!subitem?setting:value,WS_BORDER|WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL, rc.left,rc.top,(rc.right - rc.left),(rc.bottom - rc.top),hwnd2List, 0,hInst,0); + case DBVT_WORD: + if (Hex & HEX_WORD) + mir_snprintf(value, SIZEOF(value), "0x%04X", dbv.wVal); + else + itoa(dbv.wVal, value, 10); + info->hwnd2Edit = CreateWindow("EDIT", !subitem ? setting : value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0); break; - case DBVT_DWORD: - if (Hex&HEX_DWORD) - mir_snprintf(value, SIZEOF(value), "0x%08X", dbv.dVal); - else - itoa(dbv.dVal,value,10); - info->hwnd2Edit = CreateWindow("EDIT",!subitem?setting:value,WS_BORDER|WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL, rc.left,rc.top,(rc.right - rc.left),(rc.bottom - rc.top),hwnd2List, 0,hInst,0); + case DBVT_DWORD: + if (Hex & HEX_DWORD) + mir_snprintf(value, SIZEOF(value), "0x%08X", dbv.dVal); + else + itoa(dbv.dVal, value, 10); + info->hwnd2Edit = CreateWindow("EDIT", !subitem ? setting : value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0); break; - case DBVT_BLOB: + case DBVT_BLOB: if (!subitem) - info->hwnd2Edit = CreateWindow("EDIT",setting,WS_BORDER|WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL, rc.left,rc.top,(rc.right - rc.left),(rc.bottom - rc.top),hwnd2List, 0,hInst,0); - else - { + info->hwnd2Edit = CreateWindow("EDIT", setting, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0); + else { int j; char tmp[16]; - char *data = (char*)_alloca(3*(dbv.cpbVal+1)+10); + char *data = (char*)_alloca(3 * (dbv.cpbVal + 1) + 10); - if (!data) {msg(Translate("Couldn't allocate enough memory!"), modFullname); return;} + if (!data) { msg(Translate("Couldn't allocate enough memory!"), modFullname); return; } data[0] = '\0'; - for(j=0; jhwnd2Edit = CreateWindow("EDIT",data,WS_BORDER|WS_VISIBLE|WS_CHILD|WS_VSCROLL|ES_MULTILINE, rc.left,rc.top,(int)((rc.right - rc.left)*1.5),(rc.bottom - rc.top)*3,hwnd2List,0,hInst,0); + info->hwnd2Edit = CreateWindow("EDIT", data, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE, rc.left, rc.top, (int)((rc.right - rc.left)*1.5), (rc.bottom - rc.top) * 3, hwnd2List, 0, hInst, 0); } break; - default: return; + default: + return; } db_free(&dbv); - SettingLabelEditSubClass=(WNDPROC)SetWindowLongPtrW(info->hwnd2Edit,GWLP_WNDPROC,(LONG)SettingLabelEditSubClassProc); + SettingLabelEditSubClass = (WNDPROC)SetWindowLongPtrW(info->hwnd2Edit, GWLP_WNDPROC, (LONG)SettingLabelEditSubClassProc); - SendMessage(info->hwnd2Edit,WM_USER,0,(LPARAM)data); + SendMessage(info->hwnd2Edit, WM_USER, 0, (LPARAM)data); } static int test; void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam); static int lastColumn = -1; -struct SettingsSortParams{ +struct SettingsSortParams +{ HWND hList; int column; }; INT_PTR CALLBACK SettingsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam) { - SettingsSortParams params = *(SettingsSortParams *) myParam; + SettingsSortParams params = *(SettingsSortParams *)myParam; const int maxSize = 1024; TCHAR text1[maxSize]; TCHAR text2[maxSize]; - ListView_GetItemText(params.hList, (int) lParam1, params.column, text1, maxSize); - ListView_GetItemText(params.hList, (int) lParam2, params.column, text2, maxSize); - + ListView_GetItemText(params.hList, (int)lParam1, params.column, text1, maxSize); + ListView_GetItemText(params.hList, (int)lParam2, params.column, text2, maxSize); + int res = _tcsicmp(text1, text2); res = (params.column == lastColumn) ? -res : res; return res; } -void SettingsListWM_NOTIFY(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) +void SettingsListWM_NOTIFY(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(((NMHDR*)lParam)->code) - { - case NM_CLICK: - { - SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(GetDlgItem(hwnd,IDC_SETTINGS),GWLP_USERDATA); - - LVHITTESTINFO hti; - hti.pt=((NMLISTVIEW*)lParam)->ptAction; - if (db_get_b(NULL,modname,"DontAllowInLineEdit",0)) - break; - if (info && ListView_SubItemHitTest(GetDlgItem(hwnd,IDC_SETTINGS),&hti) >-1) - { - if (hti.iSubItem < 2 && hti.flags != LVHT_ONITEMICON) - { - if (info->selectedItem == hti.iItem) - EditLabel(GetDlgItem(hwnd,IDC_SETTINGS),hti.iItem,hti.iSubItem); - else if (info->hwnd2Edit) - { - SendMessage(info->hwnd2Edit,WM_COMMAND,MAKEWPARAM(IDOK,0),0); - info->hwnd2Edit = NULL; - info->selectedItem = hti.iItem; - } - else info->selectedItem = hti.iItem; - } - else - { - if (info->hwnd2Edit) - { - SendMessage(info->hwnd2Edit,WM_COMMAND,MAKEWPARAM(IDOK,0),0); - info->hwnd2Edit = NULL; - } + SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(GetDlgItem(hwnd, IDC_SETTINGS), GWLP_USERDATA); + LVHITTESTINFO hti; + + switch (((NMHDR*)lParam)->code) { + case NM_CLICK: + + hti.pt = ((NMLISTVIEW*)lParam)->ptAction; + if (db_get_b(NULL, modname, "DontAllowInLineEdit", 0)) + break; + if (info && ListView_SubItemHitTest(GetDlgItem(hwnd, IDC_SETTINGS), &hti) > -1) { + if (hti.iSubItem < 2 && hti.flags != LVHT_ONITEMICON) { + if (info->selectedItem == hti.iItem) + EditLabel(GetDlgItem(hwnd, IDC_SETTINGS), hti.iItem, hti.iSubItem); + else if (info->hwnd2Edit) { + SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0); + info->hwnd2Edit = NULL; info->selectedItem = hti.iItem; } + else info->selectedItem = hti.iItem; } - else if (info && info->hwnd2Edit) - { - SendMessage(info->hwnd2Edit,WM_COMMAND,MAKEWPARAM(IDOK,0),0); - info->hwnd2Edit = NULL; - info->selectedItem = 0; - } - break; - } - - case NM_DBLCLK: - { - SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(GetDlgItem(hwnd,IDC_SETTINGS),GWLP_USERDATA); - - LVHITTESTINFO hti; - - hti.pt=((NMLISTVIEW*)lParam)->ptAction; - if (info && ListView_SubItemHitTest(GetDlgItem(hwnd,IDC_SETTINGS),&hti) >-1) - { - if ((hti.iSubItem > 1 || hti.flags == LVHT_ONITEMICON) || (db_get_b(NULL,modname,"DontAllowInLineEdit",0))) - { - char setting[256]; - SendMessage(info->hwnd2Edit,WM_COMMAND,MAKEWPARAM(IDOK,0),0); + else { + if (info->hwnd2Edit) { + SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0); info->hwnd2Edit = NULL; - ListView_GetItemText(GetDlgItem(hwnd, IDC_SETTINGS), hti.iItem, 0, setting, 256); - editSetting(info->hContact,info->module, setting); } - else EditLabel(GetDlgItem(hwnd,IDC_SETTINGS),hti.iItem,hti.iSubItem); + info->selectedItem = hti.iItem; } - break; } + else if (info && info->hwnd2Edit) { + SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0); + info->hwnd2Edit = NULL; + info->selectedItem = 0; + } + break; - case NM_RCLICK: - SettingsListRightClick(hwnd,wParam,lParam); - break; - - case LVN_COLUMNCLICK: - { - LPNMLISTVIEW lv = (LPNMLISTVIEW) lParam; - SettingsSortParams params = {0}; - params.hList = GetDlgItem(hwnd, IDC_SETTINGS); - params.column = lv->iSubItem; - ListView_SortItemsEx(params.hList, SettingsCompare, (LPARAM) ¶ms); - lastColumn = (params.column == lastColumn) ? -1 : params.column; - break; + case NM_DBLCLK: + hti.pt = ((NMLISTVIEW*)lParam)->ptAction; + if (info && ListView_SubItemHitTest(GetDlgItem(hwnd, IDC_SETTINGS), &hti) > -1) { + if ((hti.iSubItem > 1 || hti.flags == LVHT_ONITEMICON) || (db_get_b(NULL, modname, "DontAllowInLineEdit", 0))) { + char setting[256]; + SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0); + info->hwnd2Edit = NULL; + ListView_GetItemText(GetDlgItem(hwnd, IDC_SETTINGS), hti.iItem, 0, setting, 256); + editSetting(info->hContact, info->module, setting); } + else EditLabel(GetDlgItem(hwnd, IDC_SETTINGS), hti.iItem, hti.iSubItem); + } + break; + + case NM_RCLICK: + SettingsListRightClick(hwnd, wParam, lParam); + break; - } // switch(((NMHDR*)lParam)->code) + case LVN_COLUMNCLICK: + LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam; + SettingsSortParams params = { 0 }; + params.hList = GetDlgItem(hwnd, IDC_SETTINGS); + params.column = lv->iSubItem; + ListView_SortItemsEx(params.hList, SettingsCompare, (LPARAM)¶ms); + lastColumn = (params.column == lastColumn) ? -1 : params.column; + break; + } } -void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here is to the main window, NOT the listview +void SettingsListRightClick(HWND hwnd, WPARAM wParam, LPARAM lParam) // hwnd here is to the main window, NOT the listview { - HWND hSettings = GetDlgItem(hwnd,IDC_SETTINGS); - SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(hSettings,GWLP_USERDATA); + HWND hSettings = GetDlgItem(hwnd, IDC_SETTINGS); + SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(hSettings, GWLP_USERDATA); if (!info) return; @@ -816,13 +767,13 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here POINT pt; HMENU hMenu, hSubMenu; DBsetting *dbsetting; - DBVARIANT dbv = {0}; // freed in the dialog + DBVARIANT dbv = { 0 }; // freed in the dialog module = info->module; hContact = info->hContact; - hti.pt=((NMLISTVIEW*)lParam)->ptAction; - if ( ListView_SubItemHitTest(hSettings,&hti) == -1) { + hti.pt = ((NMLISTVIEW*)lParam)->ptAction; + if (ListView_SubItemHitTest(hSettings, &hti) == -1) { // nowhere.. new item menu GetCursorPos(&pt); hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXTMENU)); @@ -837,7 +788,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_WORD: @@ -847,7 +798,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_DWORD: @@ -857,7 +808,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_STRING: @@ -867,7 +818,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_UNICODE: @@ -877,7 +828,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParamW(hInst,MAKEINTRESOURCEW(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_BLOB: @@ -887,12 +838,12 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; } return; } - + // on item char type[8]; LVITEM lvi; @@ -903,16 +854,16 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here hSubMenu = GetSubMenu(hMenu, 0); TranslateMenu(hSubMenu); - lvi.mask = LVIF_IMAGE|LVIF_TEXT; + lvi.mask = LVIF_IMAGE | LVIF_TEXT; lvi.iItem = hti.iItem; lvi.iSubItem = 0; lvi.pszText = setting; lvi.cchTextMax = 256; - ListView_GetItem(hSettings,&lvi); + ListView_GetItem(hSettings, &lvi); ListView_GetItemText(hSettings, hti.iItem, 2, type, 8); - switch(lvi.iImage) { + switch (lvi.iImage) { case 4: // STRING RemoveMenu(hSubMenu, MENU_CHANGE2STRING, MF_BYCOMMAND); break; @@ -956,7 +907,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here } // check if the setting is being watched and if it is then check the menu item - for (i=0; ihContact,info->module, setting); + editSetting(info->hContact, info->module, setting); break; case MENU_ADD_BYTE: @@ -984,7 +935,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_WORD: @@ -994,7 +945,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_DWORD: @@ -1004,7 +955,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_STRING: @@ -1014,7 +965,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_UNICODE: @@ -1024,7 +975,7 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParamW(hInst,MAKEINTRESOURCEW(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; case MENU_ADD_BLOB: @@ -1034,60 +985,60 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here dbsetting->hContact = hContact; dbsetting->module = mir_tstrdup(module); dbsetting->setting = mir_tstrdup(""); - CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_EDIT_SETTING),hwnd,EditSettingDlgProc, (LPARAM)dbsetting); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting); break; ///////////////////////// convert to submenu case MENU_CHANGE2BYTE: if (convertSetting(hContact, module, setting, 0)) { lvi.iImage = 1; - ListView_SetItem(hSettings,&lvi); + ListView_SetItem(hSettings, &lvi); } break; case MENU_CHANGE2WORD: if (convertSetting(hContact, module, setting, 1)) { lvi.iImage = 2; - ListView_SetItem(hSettings,&lvi); + ListView_SetItem(hSettings, &lvi); } break; case MENU_CHANGE2DWORD: if (convertSetting(hContact, module, setting, 2)) { lvi.iImage = 3; - ListView_SetItem(hSettings,&lvi); + ListView_SetItem(hSettings, &lvi); } break; case MENU_CHANGE2STRING: if (convertSetting(hContact, module, setting, 3)) { lvi.iImage = 4; - ListView_SetItem(hSettings,&lvi); + ListView_SetItem(hSettings, &lvi); } break; case MENU_CHANGE2UNICODE: if (convertSetting(hContact, module, setting, 4)) { lvi.iImage = 5; - ListView_SetItem(hSettings,&lvi); + ListView_SetItem(hSettings, &lvi); } break; ///////////////////////// convert to submenu case MENU_VIEWDECRYPT: - if (!db_get(hContact,module,setting,&dbv) && dbv.type == DBVT_ASCIIZ) { + if (!db_get(hContact, module, setting, &dbv) && dbv.type == DBVT_ASCIIZ) { if (lstrcmpA(setting, "LoginPassword")) msg(dbv.pszVal, Translate("Decoded string..")); else { char *str = mir_strdup(dbv.pszVal); char *str1 = str; - for (;*str1; ++str1) { + for (; *str1; ++str1) { const char c = *str1 ^ 0xc3; if (c) *str1 = c; } WCHAR *res = mir_utf8decodeW(str); - MessageBoxW(0, res, TranslateW(L"Decoded string.."),MB_OK); + MessageBoxW(0, res, TranslateW(L"Decoded string.."), MB_OK); mir_free(res); mir_free(str); } @@ -1096,27 +1047,27 @@ void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam) // hwnd here break; case MENU_VIEWENCRYPT: - if (!db_get(hContact,module,setting,&dbv) && dbv.type == DBVT_ASCIIZ) + if (!db_get(hContact, module, setting, &dbv) && dbv.type == DBVT_ASCIIZ) msg(dbv.pszVal, Translate("Encoded string..")); db_free(&dbv); break; case MENU_DECRYPT: - if (!db_get_s(hContact,module,setting,&dbv)) - db_set_s(hContact,module,setting,dbv.pszVal); + if (!db_get_s(hContact, module, setting, &dbv)) + db_set_s(hContact, module, setting, dbv.pszVal); db_free(&dbv); break; case MENU_ENCRYPT: - if (!db_get_s(hContact,module,setting,&dbv)) - db_set_s(hContact,module,setting,dbv.pszVal); + if (!db_get_s(hContact, module, setting, &dbv)) + db_set_s(hContact, module, setting, dbv.pszVal); db_free(&dbv); break; ///////////////////////// divider case MENU_WATCH_ITEM: if (!watching) - addSettingToWatchList(hContact,module,setting); + addSettingToWatchList(hContact, module, setting); else freeWatchListItem(i); if (hwnd2watchedVarsWindow) diff --git a/plugins/DbEditorPP/src/watchedvars.cpp b/plugins/DbEditorPP/src/watchedvars.cpp index fd11054e49..40d5404229 100644 --- a/plugins/DbEditorPP/src/watchedvars.cpp +++ b/plugins/DbEditorPP/src/watchedvars.cpp @@ -49,7 +49,7 @@ void addwatchtolist(HWND hwnd2list, struct DBsetting *lParam) { ModuleSettingLL settinglist; struct DBsetting dummy; - struct ModSetLinkLinkItem *setting; + ModSetLinkLinkItem *setting; if (!EnumSettings(hContact,module,&settinglist)) return; dummy.hContact = hContact; dummy.module = mir_tstrdup(module); @@ -58,7 +58,7 @@ void addwatchtolist(HWND hwnd2list, struct DBsetting *lParam) { dummy.setting = setting->name; addwatchtolist(hwnd2list, &dummy); - setting = (struct ModSetLinkLinkItem *)setting->next; + setting = (ModSetLinkLinkItem *)setting->next; } mir_free(dummy.module); FreeModuleSettingLL(&settinglist); -- cgit v1.2.3