summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-06-13 21:54:10 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-06-13 21:54:10 +0300
commit3c1685dff73e9c55760f8c4f1a530b06ef862039 (patch)
treebd1101e30aa025b6a8d1289740e8841152c466a0
parent3c13b970fda10419e1c3db46a244f16a7a0f27d9 (diff)
GMailNotifier: options -> UI classes
-rw-r--r--protocols/GmailNotifier/src/main.cpp32
-rw-r--r--protocols/GmailNotifier/src/notify.cpp16
-rw-r--r--protocols/GmailNotifier/src/options.cpp474
-rw-r--r--protocols/GmailNotifier/src/stdafx.h22
-rw-r--r--protocols/GmailNotifier/src/utility.cpp4
5 files changed, 250 insertions, 298 deletions
diff --git a/protocols/GmailNotifier/src/main.cpp b/protocols/GmailNotifier/src/main.cpp
index c4a4588c0b..66c1bfaa63 100644
--- a/protocols/GmailNotifier/src/main.cpp
+++ b/protocols/GmailNotifier/src/main.cpp
@@ -15,7 +15,6 @@ CMPlugin g_plugin;
UINT hTimer;
HNETLIBUSER hNetlibUser;
NOTIFYICONDATA niData;
-optionSettings opt;
OBJLIST<Account> g_accs(1);
BOOL optionWindowIsOpen = FALSE;
@@ -38,7 +37,18 @@ static PLUGININFOEX pluginInfoEx =
};
CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx)
+ PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx),
+ circleTime(MODULENAME, "circleTime", 30),
+ bNotifierOnTray(MODULENAME, "bNotifierOnTray", true),
+ bNotifierOnPop(MODULENAME, "bNotifierOnPop", true),
+ popupDuration(MODULENAME, "popupDuration", -1),
+ popupBgColor(MODULENAME, "popupBgColor", RGB(173, 206, 247)),
+ popupTxtColor(MODULENAME, "popupTxtColor", RGB(0, 0, 0)),
+ OpenUsePrg(MODULENAME, "OpenUsePrg", 0),
+ bShowCustomIcon(MODULENAME, "bShowCustomIcon", false),
+ bUseOnline(MODULENAME, "bUseOnline", false),
+ AutoLogin(MODULENAME, "AutoLogin", true),
+ bLogThreads(MODULENAME, "bLogThreads", false)
{
RegisterProtocol(PROTOTYPE_VIRTUAL);
}
@@ -47,7 +57,7 @@ CMPlugin::CMPlugin() :
INT_PTR GetCaps(WPARAM wParam, LPARAM)
{
- if (wParam == PFLAGNUM_2 && opt.ShowCustomIcon)
+ if (wParam == PFLAGNUM_2 && g_plugin.bShowCustomIcon)
return PF2_ONLINE | PF2_LIGHTDND | PF2_SHORTAWAY;
return 0;
@@ -99,18 +109,6 @@ int CMPlugin::Load()
CreateProtoServiceFunction(MODULENAME, PS_GETNAME, GetName);
CreateServiceFunction("GmailMNotifier/Notifying", Notifying);
- opt.circleTime = g_plugin.getDword("circleTime", 30);
- opt.notifierOnTray = g_plugin.getDword("notifierOnTray", TRUE);
- opt.notifierOnPop = g_plugin.getDword("notifierOnPop", TRUE);
- opt.popupDuration = g_plugin.getDword("popupDuration", -1);
- opt.popupBgColor = g_plugin.getDword("popupBgColor", RGB(173, 206, 247));
- opt.popupTxtColor = g_plugin.getDword("popupTxtColor", RGB(0, 0, 0));
- opt.OpenUsePrg = g_plugin.getDword("OpenUsePrg", 0);
- opt.ShowCustomIcon = g_plugin.getDword("ShowCustomIcon", FALSE);
- opt.UseOnline = g_plugin.getDword("UseOnline", FALSE);
- opt.AutoLogin = g_plugin.getDword("AutoLogin", TRUE);
- opt.LogThreads = g_plugin.getDword("LogThreads", FALSE);
-
DBVARIANT dbv;
if (db_get_s(0, "SkinIcons", "core_status_" MODULENAME "4", &dbv)) {
db_set_s(0, "SkinIcons", "core_status_" MODULENAME "0", "plugins\\GmailNotifier.dll,2");
@@ -121,11 +119,11 @@ int CMPlugin::Load()
else db_free(&dbv);
BuildList();
- ID_STATUS_NONEW = opt.UseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
+ ID_STATUS_NONEW = g_plugin.bUseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
for (auto &it : g_accs)
db_set_dw(it->hContact, MODULENAME, "Status", ID_STATUS_NONEW);
- hTimer = SetTimer(nullptr, 0, opt.circleTime * 60000, TimerProc);
+ hTimer = SetTimer(nullptr, 0, g_plugin.circleTime * 60000, TimerProc);
HookEvent(ME_SYSTEM_MODULESLOADED, OnMirandaStart);
HookEvent(ME_OPT_INITIALISE, OptInit);
diff --git a/protocols/GmailNotifier/src/notify.cpp b/protocols/GmailNotifier/src/notify.cpp
index 40f92b6ad9..73f744d421 100644
--- a/protocols/GmailNotifier/src/notify.cpp
+++ b/protocols/GmailNotifier/src/notify.cpp
@@ -13,7 +13,7 @@ static void __cdecl Login_ThreadFunc(Account *curAcc)
char lpPathBuffer[1024];
if (GetBrowser(lpPathBuffer)) {
- if (opt.AutoLogin == 0) {
+ if (!g_plugin.AutoLogin == 0) {
if (curAcc->hosted[0]) {
mir_strcat(lpPathBuffer, "https://mail.google.com/a/");
mir_strcat(lpPathBuffer, curAcc->hosted);
@@ -48,7 +48,7 @@ static void __cdecl Login_ThreadFunc(Account *curAcc)
else {
mir_strcat(lpPathBuffer, LINK);
mir_strcat(lpPathBuffer, mir_urlEncode(curAcc->name));
- if (opt.AutoLogin == 1)
+ if (g_plugin.AutoLogin == 1)
mir_strcat(lpPathBuffer, "&PersistentCookie=yes");
}
}
@@ -140,7 +140,7 @@ void NotifyUser(Account *curAcc)
default:
g_plugin.setWord(curAcc->hContact, "Status", ID_STATUS_OCCUPIED);
int newMails = (curAcc->oldResults_num == -1) ? (curAcc->results_num) : (curAcc->results_num - curAcc->oldResults_num);
- if (opt.LogThreads&&newMails > 0) {
+ if (g_plugin.bLogThreads && newMails > 0) {
DBEVENTINFO dbei = {};
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.flags = DBEF_READ;
@@ -155,7 +155,7 @@ void NotifyUser(Account *curAcc)
prst = prst->next;
}
}
- if (opt.notifierOnTray&&newMails > 0) {
+ if (g_plugin.bNotifierOnTray && newMails > 0) {
g_clistApi.pfnRemoveEvent(curAcc->hContact, 1);
CLISTEVENT cle = {};
@@ -168,7 +168,7 @@ void NotifyUser(Account *curAcc)
g_clistApi.pfnAddEvent(&cle);
}
- if (opt.notifierOnPop&&newMails > 0) {
+ if (g_plugin.bNotifierOnPop && newMails > 0) {
POPUPDATA ppd;
ppd.lchContact = curAcc->hContact;
ppd.lchIcon = Skin_LoadProtoIcon(MODULENAME, ID_STATUS_OCCUPIED);
@@ -179,11 +179,11 @@ void NotifyUser(Account *curAcc)
mir_strcat(ppd.lpzText, "\n");
prst = prst->next;
}
- ppd.colorBack = opt.popupBgColor;
- ppd.colorText = opt.popupTxtColor;
+ ppd.colorBack = g_plugin.popupBgColor;
+ ppd.colorText = g_plugin.popupTxtColor;
ppd.PluginWindowProc = PopupDlgProc;
ppd.PluginData = nullptr;
- ppd.iSeconds = opt.popupDuration;
+ ppd.iSeconds = g_plugin.popupDuration;
PUDeletePopup(curAcc->popUpHwnd);
PUAddPopup(&ppd);
}
diff --git a/protocols/GmailNotifier/src/options.cpp b/protocols/GmailNotifier/src/options.cpp
index 3d83fe4671..01076473e4 100644
--- a/protocols/GmailNotifier/src/options.cpp
+++ b/protocols/GmailNotifier/src/options.cpp
@@ -1,284 +1,250 @@
#include "stdafx.h"
-static void SaveButton(HWND hwndDlg, HWND hwndCombo, int curIndex)
+class COptionsDlg : public CDlgBase
{
- if (curIndex < 0 || curIndex >= g_accs.getCount())
- return;
-
- Account &acc = g_accs[curIndex];
- if (GetDlgItemTextA(hwndDlg, IDC_NAME, acc.name, _countof(acc.name))) {
- char *tail = strstr(acc.name, "@");
- if (tail && mir_strcmp(tail + 1, "gmail.com") != 0)
- mir_strcpy(acc.hosted, tail + 1);
- SendMessageA(hwndCombo, CB_DELETESTRING, curIndex, 0);
- SendMessageA(hwndCombo, CB_INSERTSTRING, curIndex, (LPARAM)acc.name);
- SendMessageA(hwndCombo, CB_SETCURSEL, curIndex, 0);
- g_plugin.setString(acc.hContact, "name", acc.name);
- g_plugin.setString(acc.hContact, "Nick", acc.name);
-
- GetDlgItemTextA(hwndDlg, IDC_PASS, acc.pass, _countof(acc.pass));
- g_plugin.setString(acc.hContact, "Password", acc.pass);
+ int curIndex = 0;
+
+ CCtrlEdit edtDuration, edtCircle;
+ CCtrlCheck chkProxy1, chkProxy2, chkProxy3, chkPopups, chkOnline, chkTray, chkPopup, chkShowIcon, chkLogThreads;
+ CCtrlColor clrText, clrBack;
+ CCtrlCombo m_combo;
+ CCtrlButton btnBrowse, btnAdd, btnDel, btnSave;
+
+public:
+ COptionsDlg() :
+ CDlgBase(g_plugin, IDD_OPT),
+ m_combo(this, IDC_NAME),
+ btnAdd(this, IDC_BTNADD),
+ btnDel(this, IDC_BTNDEL),
+ btnSave(this, IDC_BTNSAV),
+ btnBrowse(this, IDC_PRGBROWSE),
+ clrBack(this, IDC_BGCOLOR),
+ clrText(this, IDC_TEXTCOLOR),
+ chkTray(this, IDC_OPTTRAY),
+ chkPopup(this, IDC_OPTPOP),
+ chkOnline(this, IDC_ONLINE),
+ chkPopups(this, IDC_OPTPOP),
+ chkProxy1(this, IDC_SYSDEF),
+ chkProxy2(this, IDC_USEIE),
+ chkProxy3(this, IDC_STARTPRG),
+ chkShowIcon(this, IDC_SHOWICON),
+ chkLogThreads(this, IDC_LOGTHREADS),
+ edtCircle(this, IDC_CIRCLE),
+ edtDuration(this, IDC_DURATION)
+ {
+ CreateLink(clrBack, g_plugin.popupBgColor);
+ CreateLink(clrText, g_plugin.popupTxtColor);
+ CreateLink(chkTray, g_plugin.bNotifierOnTray);
+ CreateLink(chkPopup, g_plugin.bNotifierOnPop);
+ CreateLink(chkOnline, g_plugin.bUseOnline);
+ CreateLink(edtCircle, g_plugin.circleTime);
+ CreateLink(chkShowIcon, g_plugin.bShowCustomIcon);
+ CreateLink(edtDuration, g_plugin.popupDuration);
+ CreateLink(chkLogThreads, g_plugin.bLogThreads);
+
+ m_combo.OnSelChanged = Callback(this, &COptionsDlg::onSelChanged_Name);
+
+ btnAdd.OnClick = Callback(this, &COptionsDlg::onClick_Add);
+ btnDel.OnClick = Callback(this, &COptionsDlg::onClick_Del);
+ btnSave.OnClick = Callback(this, &COptionsDlg::onClick_Save);
+ btnBrowse.OnClick = Callback(this, &COptionsDlg::onClick_Browse);
+
+ chkPopups.OnChange = Callback(this, &COptionsDlg::onChange_Popups);
+ chkProxy1.OnChange = chkProxy2.OnChange = chkProxy2.OnChange = Callback(this, &COptionsDlg::onChange_Proxy);
}
-}
-static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- int ShowControl;
- char str[MAX_PATH] = { 0 };
- static int curIndex = 0;
- static bool bInit = false;
- HWND hwndCombo = GetDlgItem(hwndDlg, IDC_NAME);
-
- if (g_accs.getCount()) {
- EnableWindow(hwndCombo, TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_PASS), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTNSAV), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTNDEL), TRUE);
- }
- else {
- EnableWindow(hwndCombo, FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_PASS), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTNSAV), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTNDEL), FALSE);
+ void OnChange() override
+ {
+ bool bEnabled = g_accs.getCount();
+ btnDel.Enable(bEnabled);
+ btnSave.Enable(bEnabled);
+ m_combo.Enable(bEnabled);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_PASS), bEnabled);
}
- switch (msg) {
- case WM_INITDIALOG:
- bInit = true;
- TranslateDialogDefault(hwndDlg);
+ bool OnInitDialog() override
+ {
optionWindowIsOpen = TRUE;
BuildList();
for (auto &it : g_accs)
- SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LONG_PTR)it->name);
- SendMessage(hwndCombo, CB_SETCURSEL, curIndex, 0);
+ m_combo.AddString(_A2T(it->name));
+ m_combo.SetCurSel(curIndex);
if (curIndex < g_accs.getCount())
- SetDlgItemTextA(hwndDlg, IDC_PASS, g_accs[curIndex].pass);
-
- SetDlgItemInt(hwndDlg, IDC_CIRCLE, opt.circleTime, FALSE);
- if (opt.notifierOnTray)
- CheckDlgButton(hwndDlg, IDC_OPTTRAY, BST_CHECKED);
- if (opt.notifierOnPop) {
- CheckDlgButton(hwndDlg, IDC_OPTPOP, BST_CHECKED);
- ShowWindow(GetDlgItem(hwndDlg, IDC_DURATION), SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg, IDC_BGCOLOR), SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg, IDC_TEXTCOLOR), SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_DURATION), SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_COLOR), SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_LESS), SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_SEC), SW_SHOW);
+ SetDlgItemTextA(m_hwnd, IDC_PASS, g_accs[curIndex].pass);
+
+ if (g_plugin.bNotifierOnPop) {
+ ShowWindow(GetDlgItem(m_hwnd, IDC_DURATION), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_BGCOLOR), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_TEXTCOLOR), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_DURATION), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_COLOR), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_LESS), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_SEC), SW_SHOW);
}
- SetDlgItemInt(hwndDlg, IDC_DURATION, opt.popupDuration, TRUE);
- SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_SETCOLOUR, 0, opt.popupBgColor);
- SendDlgItemMessage(hwndDlg, IDC_TEXTCOLOR, CPM_SETCOLOUR, 0, opt.popupTxtColor);
-
- if (opt.OpenUsePrg == 0)
- CheckDlgButton(hwndDlg, IDC_SYSDEF, BST_CHECKED);
- else if (opt.OpenUsePrg == 1)
- CheckDlgButton(hwndDlg, IDC_USEIE, BST_CHECKED);
- else if (opt.OpenUsePrg == 2) {
- CheckDlgButton(hwndDlg, IDC_STARTPRG, BST_CHECKED);
- ShowWindow(GetDlgItem(hwndDlg, IDC_PRG), SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg, IDC_PRGBROWSE), SW_SHOW);
- }
- {
- DBVARIANT dbv;
- if (!g_plugin.getString("OpenUsePrgPath", &dbv)) {
- mir_strcpy(str, dbv.pszVal);
- db_free(&dbv);
- }
+ if (g_plugin.OpenUsePrg == 0)
+ chkProxy1.SetState(true);
+ else if (g_plugin.OpenUsePrg == 1)
+ chkProxy2.SetState(true);
+ else if (g_plugin.OpenUsePrg == 2) {
+ chkProxy3.SetState(true);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_PRG), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_PRGBROWSE), SW_SHOW);
}
- SetDlgItemTextA(hwndDlg, IDC_PRG, str);
-
- if (opt.UseOnline)
- CheckDlgButton(hwndDlg, IDC_ONLINE, BST_CHECKED);
- if (opt.ShowCustomIcon)
- CheckDlgButton(hwndDlg, IDC_SHOWICON, BST_CHECKED);
- if (opt.AutoLogin == 0)
- CheckDlgButton(hwndDlg, IDC_AUTOLOGIN, BST_CHECKED);
- else if (opt.AutoLogin == 1)
- CheckDlgButton(hwndDlg, IDC_AUTOLOGIN, BST_UNCHECKED);
- else if (opt.AutoLogin == 2)
- CheckDlgButton(hwndDlg, IDC_AUTOLOGIN, BST_INDETERMINATE);
- if (opt.LogThreads)
- CheckDlgButton(hwndDlg, IDC_LOGTHREADS, BST_CHECKED);
-
- bInit = false;
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_SYSDEF:
- case IDC_USEIE:
- case IDC_STARTPRG:
- ShowControl = IsDlgButtonChecked(hwndDlg, IDC_STARTPRG) ? SW_SHOW : SW_HIDE;
- ShowWindow(GetDlgItem(hwndDlg, IDC_PRG), ShowControl);
- ShowWindow(GetDlgItem(hwndDlg, IDC_PRGBROWSE), ShowControl);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_OPTPOP:
- ShowControl = IsDlgButtonChecked(hwndDlg, IDC_OPTPOP) ? SW_SHOW : SW_HIDE;
- ShowWindow(GetDlgItem(hwndDlg, IDC_DURATION), ShowControl);
- ShowWindow(GetDlgItem(hwndDlg, IDC_BGCOLOR), ShowControl);
- ShowWindow(GetDlgItem(hwndDlg, IDC_TEXTCOLOR), ShowControl);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_DURATION), ShowControl);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_COLOR), ShowControl);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_LESS), ShowControl);
- ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_SEC), ShowControl);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_PRGBROWSE:
- wchar_t szName[_MAX_PATH];
- GetDlgItemText(hwndDlg, IDC_PRG, szName, _countof(szName));
- {
- OPENFILENAME OpenFileName = {};
- OpenFileName.lStructSize = sizeof(OPENFILENAME);
- OpenFileName.hwndOwner = hwndDlg;
- OpenFileName.lpstrFilter = L"Executables (*.exe;*.com;*.bat)\0*.exe;*.com;*.bat\0\0";
- OpenFileName.lpstrFile = szName;
- OpenFileName.nMaxFile = _countof(szName);
- OpenFileName.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
- if (!GetOpenFileName(&OpenFileName))
- return 0;
- SetDlgItemText(hwndDlg, IDC_PRG, szName);
- }
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_BTNADD:
- {
- Account *p = new Account();
- p->hContact = db_add_contact();
- Proto_AddToContact(p->hContact, MODULENAME);
- g_accs.insert(p);
-
- curIndex = SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LPARAM)"");
- SendMessage(hwndCombo, CB_SETCURSEL, curIndex, 0);
- SetDlgItemTextA(hwndDlg, IDC_PASS, "");
- SetFocus(hwndCombo);
- }
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_BTNSAV:
- SaveButton(hwndDlg, hwndCombo, curIndex);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_BTNDEL:
- {
- SendMessage(hwndCombo, CB_DELETESTRING, curIndex, 0);
-
- Account &acc = g_accs[curIndex];
- DeleteResults(acc.results.next);
- db_delete_contact(acc.hContact);
- g_accs.remove(curIndex);
-
- curIndex = 0;
- SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);
- if (g_accs.getCount())
- SetDlgItemTextA(hwndDlg, IDC_PASS, g_accs[0].pass);
- }
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_NAME:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- curIndex = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
- SetDlgItemTextA(hwndDlg, IDC_PASS, g_accs[curIndex].pass);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- break;
-
- case IDC_CIRCLE:
- case IDC_DURATION:
- if (!bInit && (HIWORD(wParam) == EN_CHANGE))
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_ONLINE:
- case IDC_SHOWICON:
- case IDC_AUTOLOGIN:
- case IDC_LOGTHREADS:
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+
+ ptrW szPrg(g_plugin.getWStringA("OpenUsePrgPath"));
+ if (szPrg)
+ SetDlgItemText(m_hwnd, IDC_PRG, szPrg);
+
+ if (g_plugin.AutoLogin == 0)
+ CheckDlgButton(m_hwnd, IDC_AUTOLOGIN, BST_CHECKED);
+ else if (g_plugin.AutoLogin == 1)
+ CheckDlgButton(m_hwnd, IDC_AUTOLOGIN, BST_UNCHECKED);
+ else if (g_plugin.AutoLogin == 2)
+ CheckDlgButton(m_hwnd, IDC_AUTOLOGIN, BST_INDETERMINATE);
+
+ OnChange();
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ onClick_Save(0);
+
+ if (chkProxy1.GetState())
+ g_plugin.OpenUsePrg = 0;
+ else if (chkProxy2.GetState())
+ g_plugin.OpenUsePrg = 1;
+ else if (chkProxy3.GetState()) {
+ g_plugin.OpenUsePrg = 2;
}
- return TRUE;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- SaveButton(hwndDlg, hwndCombo, curIndex);
- opt.circleTime = GetDlgItemInt(hwndDlg, IDC_CIRCLE, nullptr, FALSE);
- if (opt.circleTime > 0) {
- KillTimer(nullptr, hTimer);
- hTimer = SetTimer(nullptr, 0, opt.circleTime * 60000, TimerProc);
- g_plugin.setDword("circleTime", opt.circleTime);
- }
- opt.notifierOnTray = IsDlgButtonChecked(hwndDlg, IDC_OPTTRAY);
- opt.notifierOnPop = IsDlgButtonChecked(hwndDlg, IDC_OPTPOP);
- g_plugin.setDword("notifierOnTray", opt.notifierOnTray);
- g_plugin.setDword("notifierOnPop", opt.notifierOnPop);
-
- opt.popupDuration = GetDlgItemInt(hwndDlg, IDC_DURATION, nullptr, TRUE);
- g_plugin.setDword("popupDuration", opt.popupDuration);
-
- opt.popupBgColor = SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, opt.popupBgColor);
- opt.popupTxtColor = SendDlgItemMessage(hwndDlg, IDC_TEXTCOLOR, CPM_GETCOLOUR, 0, opt.popupBgColor);
- g_plugin.setDword("popupBgColor", opt.popupBgColor);
- g_plugin.setDword("popupTxtColor", opt.popupTxtColor);
-
- if (IsDlgButtonChecked(hwndDlg, IDC_SYSDEF) == BST_CHECKED)
- opt.OpenUsePrg = 0;
- else if (IsDlgButtonChecked(hwndDlg, IDC_USEIE) == BST_CHECKED)
- opt.OpenUsePrg = 1;
- else if (IsDlgButtonChecked(hwndDlg, IDC_STARTPRG) == BST_CHECKED) {
- opt.OpenUsePrg = 2;
- }
- GetDlgItemTextA(hwndDlg, IDC_PRG, str, _countof(str));
-
- g_plugin.setDword("OpenUsePrg", opt.OpenUsePrg);
- g_plugin.setString("OpenUsePrgPath", str);
-
- opt.ShowCustomIcon = IsDlgButtonChecked(hwndDlg, IDC_SHOWICON);
- opt.UseOnline = IsDlgButtonChecked(hwndDlg, IDC_ONLINE);
- if (IsDlgButtonChecked(hwndDlg, IDC_AUTOLOGIN) == BST_CHECKED)
- opt.AutoLogin = 0;
- else if (IsDlgButtonChecked(hwndDlg, IDC_AUTOLOGIN) == BST_UNCHECKED)
- opt.AutoLogin = 1;
- else if (IsDlgButtonChecked(hwndDlg, IDC_AUTOLOGIN) == BST_INDETERMINATE)
- opt.AutoLogin = 2;
- opt.LogThreads = IsDlgButtonChecked(hwndDlg, IDC_LOGTHREADS);
- g_plugin.setDword("ShowCustomIcon", opt.ShowCustomIcon);
- g_plugin.setDword("UseOnline", opt.UseOnline);
- g_plugin.setDword("AutoLogin", opt.AutoLogin);
- g_plugin.setDword("LogThreads", opt.LogThreads);
-
- ID_STATUS_NONEW = opt.UseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
- for (auto &it : g_accs)
- g_plugin.setWord(it->hContact, "Status", ID_STATUS_NONEW);
+ char str[MAX_PATH] = { 0 };
+ GetDlgItemTextA(m_hwnd, IDC_PRG, str, _countof(str));
+ g_plugin.setString("OpenUsePrgPath", str);
+
+ if (IsDlgButtonChecked(m_hwnd, IDC_AUTOLOGIN) == BST_CHECKED)
+ g_plugin.AutoLogin = 0;
+ else if (IsDlgButtonChecked(m_hwnd, IDC_AUTOLOGIN) == BST_UNCHECKED)
+ g_plugin.AutoLogin = 1;
+ else if (IsDlgButtonChecked(m_hwnd, IDC_AUTOLOGIN) == BST_INDETERMINATE)
+ g_plugin.AutoLogin = 2;
+
+ ID_STATUS_NONEW = g_plugin.bUseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
+ for (auto &it : g_accs)
+ g_plugin.setWord(it->hContact, "Status", ID_STATUS_NONEW);
+
+ if (g_plugin.circleTime > 0) {
+ KillTimer(nullptr, hTimer);
+ hTimer = SetTimer(nullptr, 0, g_plugin.circleTime * 60000, TimerProc);
}
- return TRUE;
+ return true;
+ }
- case WM_CLOSE:
- optionWindowIsOpen = FALSE;
- return TRUE;
+ void onChange_Proxy(CCtrlCheck *)
+ {
+ int ShowControl = IsDlgButtonChecked(m_hwnd, IDC_STARTPRG) ? SW_SHOW : SW_HIDE;
+ ShowWindow(GetDlgItem(m_hwnd, IDC_PRG), ShowControl);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_PRGBROWSE), ShowControl);
}
- return FALSE;
-}
+
+ void onChange_Popups(CCtrlCheck *)
+ {
+ int ShowControl = IsDlgButtonChecked(m_hwnd, IDC_OPTPOP) ? SW_SHOW : SW_HIDE;
+ ShowWindow(GetDlgItem(m_hwnd, IDC_DURATION), ShowControl);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_BGCOLOR), ShowControl);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_TEXTCOLOR), ShowControl);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_DURATION), ShowControl);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_COLOR), ShowControl);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_LESS), ShowControl);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_SEC), ShowControl);
+ }
+
+ void onClick_Browse(CCtrlButton *)
+ {
+ wchar_t szName[_MAX_PATH];
+ GetDlgItemText(m_hwnd, IDC_PRG, szName, _countof(szName));
+
+ OPENFILENAME OpenFileName = {};
+ OpenFileName.lStructSize = sizeof(OPENFILENAME);
+ OpenFileName.hwndOwner = m_hwnd;
+ OpenFileName.lpstrFilter = L"Executables (*.exe;*.com;*.bat)\0*.exe;*.com;*.bat\0\0";
+ OpenFileName.lpstrFile = szName;
+ OpenFileName.nMaxFile = _countof(szName);
+ OpenFileName.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
+ if (GetOpenFileName(&OpenFileName))
+ SetDlgItemText(m_hwnd, IDC_PRG, szName);
+ }
+
+ void onClick_Add(CCtrlButton *)
+ {
+ Account *p = new Account();
+ p->hContact = db_add_contact();
+ Proto_AddToContact(p->hContact, MODULENAME);
+ g_accs.insert(p);
+
+ curIndex = m_combo.AddString(L"");
+ m_combo.SetCurSel(curIndex);
+ SetDlgItemTextA(m_hwnd, IDC_PASS, "");
+ SetFocus(m_combo.GetHwnd());
+ NotifyChange();
+ }
+
+ void onClick_Del(CCtrlButton *)
+ {
+ m_combo.DeleteString(curIndex);
+
+ Account &acc = g_accs[curIndex];
+ DeleteResults(acc.results.next);
+ db_delete_contact(acc.hContact);
+ g_accs.remove(curIndex);
+
+ m_combo.SetCurSel(curIndex = 0);
+ if (g_accs.getCount())
+ SetDlgItemTextA(m_hwnd, IDC_PASS, g_accs[0].pass);
+ NotifyChange();
+ }
+
+ void onClick_Save(CCtrlButton *)
+ {
+ if (curIndex < 0 || curIndex >= g_accs.getCount())
+ return;
+
+ Account &acc = g_accs[curIndex];
+ m_combo.GetTextA(acc.name, _countof(acc.name));
+ if (!mir_strlen(acc.name))
+ return;
+
+ char *tail = strstr(acc.name, "@");
+ if (tail && mir_strcmp(tail + 1, "gmail.com") != 0)
+ mir_strcpy(acc.hosted, tail + 1);
+ m_combo.DeleteString(curIndex);
+ m_combo.InsertString(_A2T(acc.name), curIndex);
+ m_combo.SetCurSel(curIndex);
+ g_plugin.setString(acc.hContact, "name", acc.name);
+ g_plugin.setString(acc.hContact, "Nick", acc.name);
+
+ m_combo.GetTextA(acc.pass, _countof(acc.pass));
+ g_plugin.setString(acc.hContact, "Password", acc.pass);
+ }
+
+ void onSelChanged_Name(CCtrlCombo*)
+ {
+ curIndex = m_combo.GetCurSel();
+ SetDlgItemTextA(m_hwnd, IDC_PASS, g_accs[curIndex].pass);
+ NotifyChange();
+ }
+};
int OptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
+ odp.flags = ODPF_BOLDGROUPS;
odp.position = -790000000;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT);
odp.szTitle.a = LPGEN("GmailNotifier");
odp.szGroup.a = LPGEN("Network");
- odp.flags = ODPF_BOLDGROUPS;
- odp.pfnDlgProc = DlgProcOpts;
+ odp.pDialog = new COptionsDlg();
g_plugin.addOptions(wParam, &odp);
return 0;
}
diff --git a/protocols/GmailNotifier/src/stdafx.h b/protocols/GmailNotifier/src/stdafx.h
index da6bc1039d..2140cb6aed 100644
--- a/protocols/GmailNotifier/src/stdafx.h
+++ b/protocols/GmailNotifier/src/stdafx.h
@@ -55,27 +55,11 @@ struct Account : public MZeroedObject
bool IsChecking;
};
-struct optionSettings
-{
- int circleTime;
- BOOL notifierOnTray;
- BOOL notifierOnPop;
- int popupDuration;
- COLORREF popupTxtColor;
- COLORREF popupBgColor;
- int OpenUsePrg;
- BOOL ShowCustomIcon;
- BOOL UseOnline;
- int AutoLogin;
- BOOL LogThreads;
-};
-
-extern OBJLIST<Account> g_accs;
-extern optionSettings opt;
extern HNETLIBUSER hNetlibUser;
extern UINT hTimer;
extern short ID_STATUS_NONEW;
extern BOOL optionWindowIsOpen;
+extern OBJLIST<Account> g_accs;
INT_PTR Notifying(WPARAM, LPARAM);
INT_PTR PluginMenuCommand(WPARAM, LPARAM);
@@ -93,6 +77,10 @@ Account* GetAccountByContact(MCONTACT hContact);
struct CMPlugin : public PLUGIN<CMPlugin>
{
+ CMOption<bool> bNotifierOnTray, bNotifierOnPop;
+ CMOption<bool> bShowCustomIcon, bUseOnline, bLogThreads;
+ CMOption<uint32_t> AutoLogin, OpenUsePrg, circleTime, popupDuration, popupBgColor, popupTxtColor;
+
CMPlugin();
int Load() override;
diff --git a/protocols/GmailNotifier/src/utility.cpp b/protocols/GmailNotifier/src/utility.cpp
index 7049763c55..1743b1ff05 100644
--- a/protocols/GmailNotifier/src/utility.cpp
+++ b/protocols/GmailNotifier/src/utility.cpp
@@ -35,9 +35,9 @@ BOOL GetBrowser(char *str)
char strDefault[] = "https\\shell\\open\\command";
DBVARIANT dbv;
- if (opt.OpenUsePrg == 1)
+ if (g_plugin.OpenUsePrg == 1)
strKey = strIE;
- else if (opt.OpenUsePrg == 0)
+ else if (g_plugin.OpenUsePrg == 0)
strKey = strDefault;
else {
if (!g_plugin.getString("OpenUsePrgPath", &dbv)) {