diff options
author | George Hazan <ghazan@miranda.im> | 2019-10-30 16:54:51 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-10-30 16:54:51 +0300 |
commit | 757b64f04ea74dabb2b70a04b68e00458787b221 (patch) | |
tree | ef62f4accf5a7a0daed7a8cef828e2197c3d659e /plugins/IEHistory/src | |
parent | 9ce55e2efc6d4f5e53ef3c1bf9f1dd95e77a7b08 (diff) |
IEHistory : options code cleaning
Diffstat (limited to 'plugins/IEHistory/src')
-rw-r--r-- | plugins/IEHistory/src/IEHistory.cpp | 17 | ||||
-rw-r--r-- | plugins/IEHistory/src/dlgHandlers.cpp | 117 | ||||
-rw-r--r-- | plugins/IEHistory/src/services.cpp | 27 | ||||
-rw-r--r-- | plugins/IEHistory/src/services.h | 4 | ||||
-rw-r--r-- | plugins/IEHistory/src/stdafx.h | 22 |
5 files changed, 79 insertions, 108 deletions
diff --git a/plugins/IEHistory/src/IEHistory.cpp b/plugins/IEHistory/src/IEHistory.cpp index 442cbc95b2..344190de51 100644 --- a/plugins/IEHistory/src/IEHistory.cpp +++ b/plugins/IEHistory/src/IEHistory.cpp @@ -46,8 +46,13 @@ PLUGININFOEX pluginInfoEx = { }; CMPlugin::CMPlugin() : - PLUGIN<CMPlugin>("IEHistory", pluginInfoEx) -{} + PLUGIN<CMPlugin>("IEHistory", pluginInfoEx), + iLoadCount(m_szModuleName, "EventsToLoad", 0), + bEnableRtl(m_szModuleName, "EnableRTL", 0), + bUseWorker(m_szModuleName, "UseWorkerThread", 0), + bShowLastFirst(m_szModuleName, "ShowLastPageFirst", 0) +{ +} ///////////////////////////////////////////////////////////////////////////////////////// @@ -65,13 +70,13 @@ int CMPlugin::Load() if ((hUxTheme = LoadLibraryA("uxtheme.dll")) != nullptr) MyEnableThemeDialogTexture = (BOOL(WINAPI *)(HANDLE, DWORD))GetProcAddress(hUxTheme, "EnableThemeDialogTexture"); - /// all initialization here + // all initialization here hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HISTORYICON)); hOpenWindowsList = WindowList_Create(); - InitServices(); + CreateServiceFunction(MS_HISTORY_SHOWCONTACTHISTORY, ShowContactHistoryService); - /// menu items + // menu items CMenuItem mi(&g_plugin); SET_UID(mi, 0x28848d7a, 0x6995, 0x4799, 0x82, 0xd7, 0x18, 0x40, 0x3d, 0xe3, 0x71, 0xc4); mi.name.w = LPGENW("View &history"); @@ -81,7 +86,7 @@ int CMPlugin::Load() mi.pszService = MS_HISTORY_SHOWCONTACTHISTORY; Menu_AddContactMenuItem(&mi); - /// @todo (White-Tiger#1#08/19/14): fully implement System History someday^^ + // @todo (White-Tiger#1#08/19/14): fully implement System History someday^^ SET_UID(mi, 0xfcb4bb2a, 0xd4d8, 0x48ab, 0x94, 0xcc, 0x5b, 0xe9, 0x8d, 0x53, 0x3e, 0xf1); mi.name.w = LPGENW("&System History"); Menu_AddMainMenuItem(&mi); diff --git a/plugins/IEHistory/src/dlgHandlers.cpp b/plugins/IEHistory/src/dlgHandlers.cpp index 281232363c..6c23d19653 100644 --- a/plugins/IEHistory/src/dlgHandlers.cpp +++ b/plugins/IEHistory/src/dlgHandlers.cpp @@ -234,8 +234,8 @@ int LoadEvents(HWND hWnd) {
HistoryWindowData *data = (HistoryWindowData *)GetWindowLongPtr(hWnd, DWLP_USER);
int count = db_event_count(data->contact);
- int bLastFirst = g_plugin.getByte("ShowLastPageFirst", 0);
- int bRTL = g_plugin.getByte("EnableRTL", 0);
+ int bLastFirst = g_plugin.bShowLastFirst;
+ int bRTL = g_plugin.bEnableRtl;
bRTL = db_get_b(data->contact, "Tab_SRMsg", "RTL", bRTL);
data->bEnableRTL = bRTL;
data->count = count;
@@ -354,7 +354,7 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara TranslateDialogDefault(hWnd);
SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
{
- int bRTL = g_plugin.getByte("EnableRTL", 0);
+ int bRTL = g_plugin.bEnableRtl;
if (bRTL)
SetWindowLongPtr(hWnd, GWL_EXSTYLE, WS_EX_RTLREADING);
@@ -384,7 +384,7 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara LoadEvents(hWnd);
{
bool bAll = (data->itemsPerPage <= 0) || (data->itemsPerPage >= data->count);
- int bLastFirst = g_plugin.getByte("ShowLastPageFirst", 0);
+ int bLastFirst = g_plugin.bShowLastFirst;
if (!bLastFirst) {
EnableWindow(GetDlgItem(hWnd, IDC_PREV), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_NEXT), !bAll);
@@ -597,84 +597,57 @@ INT_PTR CALLBACK SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam /////////////////////////////////////////////////////////////////////////////////////////
// options
-static INT_PTR CALLBACK OptionsDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+class COptionsDlg : public CDlgBase
{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hWnd);
- {
- int count = g_plugin.getDword("EventsToLoad", 0);
- EnableWindow(GetDlgItem(hWnd, IDC_EVENTS_COUNT), count > 0);
- EnableWindow(GetDlgItem(hWnd, IDC_SHOW_LAST_FIRST), count > 0);
-
- CheckDlgButton(hWnd, IDC_LOAD_ALL, count <= 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hWnd, IDC_LOAD_NUMBER, count > 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hWnd, IDC_ENABLE_RTL, g_plugin.getByte("EnableRTL", 0) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hWnd, IDC_SHOW_LAST_FIRST, g_plugin.getByte("ShowLastPageFirst", 0) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hWnd, IDC_LOAD_BACKGROUND, g_plugin.getByte("UseWorkerThread", 0) ? BST_CHECKED : BST_UNCHECKED);
-
- wchar_t buffer[40];
- _itow_s(count, buffer, 10);
- SetDlgItemText(hWnd, IDC_EVENTS_COUNT, buffer);
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_LOAD_ALL:
- EnableWindow(GetDlgItem(hWnd, IDC_EVENTS_COUNT), FALSE);
- EnableWindow(GetDlgItem(hWnd, IDC_SHOW_LAST_FIRST), FALSE);
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- break;
+ CCtrlEdit edtCount;
+ CCtrlCheck chkLoadAll, chkLoadNumber, chkRtl, chkLastFirst, chkLoadBack;
+
+public:
+ COptionsDlg() :
+ CDlgBase(g_plugin, IDD_OPT_HISTORY),
+ edtCount(this, IDC_EVENTS_COUNT),
+ chkRtl(this, IDC_ENABLE_RTL),
+ chkLoadAll(this, IDC_LOAD_ALL),
+ chkLoadBack(this, IDC_LOAD_BACKGROUND),
+ chkLoadNumber(this, IDC_LOAD_NUMBER),
+ chkLastFirst(this, IDC_SHOW_LAST_FIRST)
+ {
+ CreateLink(edtCount, g_plugin.iLoadCount);
+ CreateLink(chkRtl, g_plugin.bEnableRtl);
+ CreateLink(chkLoadBack, g_plugin.bUseWorker);
+ CreateLink(chkLastFirst, g_plugin.bShowLastFirst);
+ }
- case IDC_LOAD_NUMBER:
- EnableWindow(GetDlgItem(hWnd, IDC_EVENTS_COUNT), TRUE);
- EnableWindow(GetDlgItem(hWnd, IDC_SHOW_LAST_FIRST), TRUE);
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- break;
+ bool OnInitDialog() override
+ {
+ onChange_All(0);
+ chkLoadAll.SetState(g_plugin.iLoadCount == 0);
+ chkLoadNumber.SetState(!chkLoadAll.GetState());
+ return true;
+ }
- case IDC_ENABLE_RTL:
- case IDC_SHOW_LAST_FIRST:
- case IDC_EVENTS_COUNT:
- case IDC_LOAD_BACKGROUND:
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- break;
- }
- break;
+ bool OnApply() override
+ {
+ if (chkLoadAll.GetState())
+ g_plugin.iLoadCount = 0;
+ return true;
+ }
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- long count;
- if (IsDlgButtonChecked(hWnd, IDC_LOAD_ALL))
- count = 0;
- else {
- wchar_t buffer[1024];
- GetDlgItemText(hWnd, IDC_EVENTS_COUNT, buffer, _countof(buffer));
- count = _wtol(buffer);
- count = (count < 0) ? 0 : count;
- }
- g_plugin.setByte("ShowLastPageFirst", IsDlgButtonChecked(hWnd, IDC_SHOW_LAST_FIRST));
- g_plugin.setByte("EnableRTL", IsDlgButtonChecked(hWnd, IDC_ENABLE_RTL));
- g_plugin.setByte("UseWorkerThread", IsDlgButtonChecked(hWnd, IDC_LOAD_BACKGROUND));
- g_plugin.setDword("EventsToLoad", count);
- }
- }
- break;
+ void onChange_All(CCtrlCheck *)
+ {
+ bool bEnabled = chkLoadNumber.GetState();
+ edtCount.Enable(bEnabled);
+ chkLastFirst.Enable(bEnabled);
}
- return 0;
-}
+};
int OnOptionsInitialize(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 100000000;
- odp.szTitle.w = LPGENW("History");
- odp.pfnDlgProc = OptionsDlgProc;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_HISTORY);
- odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
+ odp.szTitle.a = LPGEN("History");
+ odp.pDialog = new COptionsDlg();
+ odp.flags = ODPF_BOLDGROUPS;
g_plugin.addOptions(wParam, &odp);
return 0;
}
diff --git a/plugins/IEHistory/src/services.cpp b/plugins/IEHistory/src/services.cpp index ec5210e8df..bae78b396b 100644 --- a/plugins/IEHistory/src/services.cpp +++ b/plugins/IEHistory/src/services.cpp @@ -21,36 +21,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "services.h" -int InitServices() -{ - CreateServiceFunction(MS_HISTORY_SHOWCONTACTHISTORY, ShowContactHistoryService); - return 0; -} - -INT_PTR ShowContactHistoryService(WPARAM wParam, LPARAM) +INT_PTR ShowContactHistoryService(WPARAM hContact, LPARAM) { Log("%s", "Entering function " __FUNCTION__); HWND historyDlg; HWND parent = nullptr; - historyDlg = WindowList_Find(hOpenWindowsList, (MCONTACT)wParam); + historyDlg = WindowList_Find(hOpenWindowsList, hContact); if (historyDlg == nullptr){ - int count = g_plugin.getDword("EventsToLoad", 0); - int loadInBackground = g_plugin.getByte("UseWorkerThread", 0); - HistoryWindowData *data; - data = (HistoryWindowData *)malloc(sizeof(HistoryWindowData)); - data->contact = (MCONTACT)wParam; + HistoryWindowData *data = (HistoryWindowData *)malloc(sizeof(HistoryWindowData)); + data->contact = hContact; data->hIEView = nullptr; - data->itemsPerPage = count; + data->itemsPerPage = g_plugin.iLoadCount; data->index = 0; data->count = 0; - data->loadMethod = (loadInBackground) ? LOAD_IN_BACKGROUND : 0; + data->loadMethod = (g_plugin.bUseWorker) ? LOAD_IN_BACKGROUND : 0; historyDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_HISTORY), parent, HistoryDlgProc); SetWindowLongPtr(historyDlg, DWLP_USER, (LONG_PTR)data); - WindowList_Add(hOpenWindowsList, historyDlg, (MCONTACT)wParam); + WindowList_Add(hOpenWindowsList, historyDlg, hContact); } - else - SetForegroundWindow(historyDlg); + else SetForegroundWindow(historyDlg); + ShowWindow(historyDlg, SW_SHOWNORMAL); return 0; } diff --git a/plugins/IEHistory/src/services.h b/plugins/IEHistory/src/services.h index a1b7dfb50d..0a58dfc9c7 100644 --- a/plugins/IEHistory/src/services.h +++ b/plugins/IEHistory/src/services.h @@ -23,10 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "dlgHandlers.h" -int InitServices(); +INT_PTR ShowContactHistoryService(WPARAM, LPARAM); int OnOptionsInitialize(WPARAM, LPARAM); -INT_PTR ShowContactHistoryService(WPARAM wParam, LPARAM lParam); - #endif //M_IEHISTORY_PROVIDED_SERVICES_H diff --git a/plugins/IEHistory/src/stdafx.h b/plugins/IEHistory/src/stdafx.h index 8e69c67a8f..19aadb42a5 100644 --- a/plugins/IEHistory/src/stdafx.h +++ b/plugins/IEHistory/src/stdafx.h @@ -35,19 +35,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <uxtheme.h> #include <newpluginapi.h> -#include <m_database.h> -#include <m_utils.h> -#include <m_system.h> -#include <m_skin.h> -#include <m_options.h> #include <m_clist.h> -#include <m_langpack.h> -#include <m_history.h> #include <m_contacts.h> +#include <m_database.h> +#include <m_history.h> +#include <m_ieview.h> +#include <m_gui.h> +#include <m_langpack.h> #include <m_metacontacts.h> -#include <m_protocols.h> +#include <m_options.h> #include <m_popup.h> -#include <m_ieview.h> +#include <m_protocols.h> +#include <m_skin.h> +#include <m_system.h> +#include <m_utils.h> #include "resource.h" #include "version.h" @@ -71,6 +72,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct CMPlugin : public PLUGIN<CMPlugin> { + CMOption<BYTE> bEnableRtl, bShowLastFirst, bUseWorker; + CMOption<DWORD> iLoadCount; + CMPlugin(); int Load() override; |