1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#include "stdafx.h"
volatile BOOL working;
static HWND hwnd2Delete = nullptr;
int deleteModule(HWND hwndParent, MCONTACT hContact, const char *module, int confirm)
{
if (!module || db_is_module_empty(hContact, module))
return 0;
if (confirm && g_plugin.bWarnOnDelete) {
wchar_t text[MSG_SIZE];
mir_snwprintf(text, TranslateT("Are you sure you want to delete module \"%S\"?"), module);
if (MessageBoxW(hwndParent, text, modFullnameW, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
return 0;
}
ModuleSettingLL settinglist;
if (!EnumSettings(hContact, module, &settinglist))
return 0;
for (ModSetLinkLinkItem *setting = settinglist.first; setting; setting = setting->next)
db_unset(hContact, module, setting->name);
FreeModuleSettingLL(&settinglist);
return 1;
}
void __cdecl PopulateModuleDropListThreadFunc(void *param)
{
HWND hwnd = (HWND)param;
ModuleSettingLL msll;
if (!EnumModules(&msll)) {
DestroyWindow(hwnd);
return;
}
int moduleEmpty;
ModSetLinkLinkItem *module = msll.first;
while (module && working) {
moduleEmpty = 1;
// check the null
if (!db_is_module_empty(NULL, module->name)) {
SendDlgItemMessageA(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)module->name);
moduleEmpty = 0;
module = module->next;
continue;
}
for (auto &hContact : Contacts()) {
if (!db_is_module_empty(hContact, module->name)) {
SendDlgItemMessageA(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)module->name);
moduleEmpty = 0;
break;
}
}
module = module->next;
SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETCURSEL, 0, 0);
}
SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETCURSEL, 0, 0);
FreeModuleSettingLL(&msll);
SetWindowText(hwnd, TranslateT("Delete module from database"));
EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS), 1);
EnableWindow(GetDlgItem(hwnd, IDOK), 1);
EnableWindow(GetDlgItem(hwnd, IDCANCEL), 1);
if (!working)
PostMessage(hwnd, WM_COMMAND, (WPARAM)IDCANCEL, 0);
else
working = 2;
}
INT_PTR CALLBACK DeleteModuleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
{
switch (msg) {
case WM_INITDIALOG:
SetWindowText(hwnd, LPGENW("Delete module from database... Loading"));
EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS), 0);
EnableWindow(GetDlgItem(hwnd, IDOK), 0);
SetDlgItemText(hwnd, IDC_INFOTEXT, LPGENW("Delete module from database"));
SetDlgItemText(hwnd, CHK_COPY2ALL, LPGENW("Delete from all contacts (including Settings)"));
EnableWindow(GetDlgItem(hwnd, CHK_COPY2ALL), 0);
CheckDlgButton(hwnd, CHK_COPY2ALL, BST_CHECKED);
TranslateDialogDefault(hwnd);
working = 1;
mir_forkthread(PopulateModuleDropListThreadFunc, hwnd);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
char module[FLD_SIZE];
GetDlgItemTextA(hwnd, IDC_CONTACTS, module, _countof(module));
SetCursor(LoadCursor(nullptr, IDC_WAIT));
for (auto &hContact : Contacts())
deleteModule(0, hContact, module, 0);
// do the null
deleteModule(0, NULL, module, 0);
SetCursor(LoadCursor(nullptr, IDC_ARROW));
refreshTree(1);
__fallthrough;
case IDCANCEL:
if (working == 1) {
working = 0;
EnableWindow(GetDlgItem(hwnd, IDCANCEL), 0);
}
else DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
hwnd2Delete = nullptr;
break;
}
return 0;
}
void CMainDlg::deleteModuleDlg()
{
if (!hwnd2Delete)
hwnd2Delete = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_COPY_MOD), m_hwnd, DeleteModuleDlgProc);
else
::SetForegroundWindow(hwnd2Delete);
}
|