summaryrefslogtreecommitdiff
path: root/plugins/DbEditorPP/src/copymodule.cpp
diff options
context:
space:
mode:
authorDmitry Kuzkin <bio@ktaspb.ru>2015-06-18 12:36:07 +0000
committerDmitry Kuzkin <bio@ktaspb.ru>2015-06-18 12:36:07 +0000
commit1bb9a86b26d3a9964844d42fa25690ce0a028258 (patch)
tree6c0645ade07ec6b4d36e38a1ba77e457e8cf6ade /plugins/DbEditorPP/src/copymodule.cpp
parenta27ae3e0c1f1f17596db3abeae16ec3fc4b4ba80 (diff)
true unicode build (ansi build is possible but useless)
new search/replace dialog edit improvements (type check) resident settings support (fully resident modules are still invisible) remove obsolete things code cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@14243 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/DbEditorPP/src/copymodule.cpp')
-rw-r--r--plugins/DbEditorPP/src/copymodule.cpp146
1 files changed, 64 insertions, 82 deletions
diff --git a/plugins/DbEditorPP/src/copymodule.cpp b/plugins/DbEditorPP/src/copymodule.cpp
index ed84119b4b..cd88af3515 100644
--- a/plugins/DbEditorPP/src/copymodule.cpp
+++ b/plugins/DbEditorPP/src/copymodule.cpp
@@ -1,103 +1,63 @@
#include "headers.h"
-void copyModule(char* module, MCONTACT hContactFrom, MCONTACT hContactTo)
+void copyModule(const char *module, MCONTACT hContactFrom, MCONTACT hContactTo)
{
ModuleSettingLL msll;
- EnumSettings(hContactFrom, module, &msll);
-
- ModSetLinkLinkItem *setting = msll.first;
- while (setting) {
- DBVARIANT dbv;
- if (!GetSetting(hContactFrom, module, setting->name, &dbv)) {
- switch (dbv.type) {
- case DBVT_BYTE:
- db_set_b(hContactTo, module, setting->name, dbv.bVal);
- break;
- case DBVT_WORD:
- db_set_w(hContactTo, module, setting->name, dbv.wVal);
- break;
- case DBVT_DWORD:
- db_set_dw(hContactTo, module, setting->name, dbv.dVal);
- break;
- case DBVT_ASCIIZ:
- db_set_s(hContactTo, module, setting->name, dbv.pszVal);
- break;
- case DBVT_UTF8:
- db_set_utf(hContactTo, module, setting->name, dbv.pszVal);
- break;
- case DBVT_BLOB:
- db_set_blob(hContactTo, module, setting->name, dbv.pbVal, dbv.cpbVal);
- break;
- }
+ if (IsModuleEmpty(hContactFrom, module) || !EnumSettings(hContactFrom, module, &msll))
+ return;
+
+ DBVARIANT dbv;
+ for(ModSetLinkLinkItem *setting = msll.first; setting; setting = setting->next) {
+ if (!db_get_s(hContactFrom, module, setting->name, &dbv, 0)) {
+ db_set(hContactTo, module, setting->name, &dbv);
+ db_free(&dbv);
}
- db_free(&dbv);
- setting = setting->next;
}
FreeModuleSettingLL(&msll);
}
INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- ModuleAndContact *mac = (ModuleAndContact *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (msg == WM_INITDIALOG)
+ switch (msg) {
+ case WM_INITDIALOG:
{
- int index, loaded;
- char szProto[256];
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
- loaded = IsProtocolLoaded(szProto);
- else
- loaded = 0;
-
- // filter
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED))
- continue;
-
- // contacts name
- WCHAR nick[256];
- WCHAR protoW[256]; // unicode proto
-
- if (szProto[0])
- a2u(szProto, protoW, SIZEOF(protoW));
- else
- protoW[0] = 0;
-
- if (!szProto[0] || !loaded) {
- if (protoW) {
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s %s", protoW, GetContactName(hContact, szProto, 1), L"(UNLOADED)");
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s) %s", GetContactName(hContact, szProto, 1), protoW, L"(UNLOADED)");
- }
- else mir_wstrcpy(nick, nick_unknownW);
- }
- else {
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s", protoW, GetContactName(hContact, szProto, 1));
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s)", GetContactName(hContact, szProto, 1), protoW);
- }
+ TranslateDialogDefault(hwnd);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+ ModuleAndContact *mac = (ModuleAndContact *)lParam;
+ TCHAR name[NAME_SIZE], msg[MSG_SIZE];
- index = SendDlgItemMessageW(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)nick);
- SendDlgItemMessageW(hwnd, IDC_CONTACTS, CB_SETITEMDATA, index, hContact);
+ mir_sntprintf(msg, TranslateT("Copy module \"%s\""), _A2T(mac->module));
+ SetWindowText(hwnd, msg);
+
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ {
+ if (ApplyProtoFilter(hContact))
+ continue;
+
+ GetContactName(hContact, NULL, name, SIZEOF(name));
+
+ int index = SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)name);
+ SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETITEMDATA, index, hContact);
}
- index = (int)SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_INSERTSTRING, 0, (LPARAM)Translate("Settings"));
+ GetContactName(NULL, NULL, name, SIZEOF(name));
+ int index = (int)SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_INSERTSTRING, 0, (LPARAM)name);
SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETITEMDATA, index, 0);
SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETCURSEL, index, 0);
-
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- TranslateDialogDefault(hwnd);
+ break;
}
- else if (msg == WM_COMMAND)
+ case WM_COMMAND:
{
+ ModuleAndContact *mac = (ModuleAndContact *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
switch (LOWORD(wParam)) {
case CHK_COPY2ALL:
EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS), BST_UNCHECKED == IsDlgButtonChecked(hwnd, CHK_COPY2ALL));
break;
case IDOK:
+
if (BST_UNCHECKED == IsDlgButtonChecked(hwnd, CHK_COPY2ALL)) {
MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_GETITEMDATA, SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_GETCURSEL, 0, 0), 0);
copyModule(mac->module, mac->hContact, hContact);
@@ -109,25 +69,47 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
- mir_free(mac);
refreshTree(1);
- DestroyWindow(hwnd);
- break;
-
+ // fall through
case IDCANCEL:
mir_free(mac);
DestroyWindow(hwnd);
break;
}
+ break;
}
+ } //switch
return 0;
}
-void copyModuleMenuItem(char* module, MCONTACT hContact)
+void copyModuleMenuItem(MCONTACT hContact, const char *module)
{
ModuleAndContact *mac = (ModuleAndContact *)mir_calloc(sizeof(ModuleAndContact));
mac->hContact = hContact;
- strncpy(mac->module, module, 255);
+ mir_strncpy(mac->module, module, sizeof(mac->module));
+
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_COPY_MOD), hwnd2mainWindow, copyModDlgProc, (LPARAM)mac);
+}
+
- CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_COPY_MOD), 0, copyModDlgProc, (LPARAM)mac);
-} \ No newline at end of file
+int CloneContact(MCONTACT hContact)
+{
+ MCONTACT newContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ if (!newContact)
+ return 0;
+
+ // enum all the modules
+ ModuleSettingLL modlist;
+
+ if (!EnumModules(&modlist))
+ return 0;
+
+ ModSetLinkLinkItem *mod = modlist.first;
+ while (mod) {
+ copyModule(mod->name, hContact, newContact);
+ mod = (ModSetLinkLinkItem *)mod->next;
+ }
+
+ FreeModuleSettingLL(&modlist);
+ return 1;
+}