summaryrefslogtreecommitdiff
path: root/plugins/Import/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-10-18 20:39:20 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-10-18 20:39:20 +0300
commitfba89acdf4814afe7547fd3c24b428ab42aa0a81 (patch)
treeae36ebdd0c362ff7890281f6b26fa0508e9119b8 /plugins/Import/src
parent3bf5f14f6f970e4be61a3b4f2c073a113937efc5 (diff)
Import moved to UI classes
Diffstat (limited to 'plugins/Import/src')
-rw-r--r--plugins/Import/src/main.cpp20
-rw-r--r--plugins/Import/src/miranda.cpp533
-rw-r--r--plugins/Import/src/progress.cpp58
-rw-r--r--plugins/Import/src/stdafx.h108
-rw-r--r--plugins/Import/src/version.h2
-rw-r--r--plugins/Import/src/wizard.cpp272
6 files changed, 548 insertions, 445 deletions
diff --git a/plugins/Import/src/main.cpp b/plugins/Import/src/main.cpp
index 108ce1cee8..c390e51304 100644
--- a/plugins/Import/src/main.cpp
+++ b/plugins/Import/src/main.cpp
@@ -100,17 +100,14 @@ static INT_PTR ServiceMode(WPARAM wParam, LPARAM)
if (!_waccess(wszFullName, 0)) {
g_iImportOptions = IOPT_ADDUNKNOWN + IOPT_COMPLETE + IOPT_CHECKDUPS;
wcsncpy_s(importFile, MAX_PATH, wszFullName, _TRUNCATE);
-
- WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
- DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, LPARAM(&param));
+ RunWizard(new CProgressPageDlg(), true);
}
return SERVICE_CONTINUE;
}
g_bSendQuit = true;
- WizardDlgParam param = { IDD_WIZARDINTRO, (LPARAM)WizardIntroPageProc };
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, (LPARAM)&param);
+ RunWizard(new CIntroPageDlg(), false);
return SERVICE_ONLYDB;
}
@@ -120,9 +117,7 @@ static INT_PTR CustomImport(WPARAM wParam, LPARAM)
wcsncpy_s(importFile, MAX_PATH, opts->pwszFileName, _TRUNCATE);
g_iImportOptions = opts->dwFlags;
g_hImportContact = 0;
-
- WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
- return DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, LPARAM(&param));
+ return RunWizard(new CProgressPageDlg(), true);
}
static INT_PTR ImportContact(WPARAM hContact, LPARAM)
@@ -133,9 +128,7 @@ static INT_PTR ImportContact(WPARAM hContact, LPARAM)
g_hImportContact = hContact;
g_iImportOptions = IOPT_HISTORY + dlg.getFlags();
-
- WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
- return DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, LPARAM(&param));
+ return RunWizard(new CProgressPageDlg(), true);
}
static INT_PTR ImportCommand(WPARAM, LPARAM)
@@ -144,10 +137,7 @@ static INT_PTR ImportCommand(WPARAM, LPARAM)
SetForegroundWindow(g_hwndWizard);
SetFocus(g_hwndWizard);
}
- else {
- WizardDlgParam param = { IDD_WIZARDINTRO, (LPARAM)WizardIntroPageProc };
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, (LPARAM)&param);
- }
+ else RunWizard(new CIntroPageDlg(), false);
return 0;
}
diff --git a/plugins/Import/src/miranda.cpp b/plugins/Import/src/miranda.cpp
index 6d646f8077..b8de3a69a8 100644
--- a/plugins/Import/src/miranda.cpp
+++ b/plugins/Import/src/miranda.cpp
@@ -29,7 +29,102 @@ wchar_t importFile[MAX_PATH];
//=======================================================================================
// Profile selection dialog
-static void SearchForLists(HWND hwndDlg, const wchar_t *mirandaPath, const wchar_t *mirandaProf)
+CMirandaPageDlg::CMirandaPageDlg() :
+ CWizardPageDlg(IDD_MIRANDADB),
+ list(this, IDC_LIST),
+ btnBack(this, IDC_BACK),
+ btnOther(this, IDC_OTHER)
+{
+ list.OnSelChange = Callback(this, &CMirandaPageDlg::onSelChanged_list);
+
+ btnBack.OnClick = Callback(this, &CMirandaPageDlg::onClick_Back);
+ btnOther.OnClick = Callback(this, &CMirandaPageDlg::onClick_Other);
+}
+
+bool CMirandaPageDlg::OnInitDialog()
+{
+ VARSW pfd(L"%miranda_path%\\Profiles");
+ VARSW pfd1(L"%miranda_path%");
+ VARSW pfd2(L"%miranda_profilesdir%");
+ VARSW pfn(L"%miranda_profilename%");
+
+ SearchForLists(pfd2, pfn);
+ SearchForLists(pfd1, nullptr);
+ if (mir_wstrcmpi(pfd, pfd2))
+ SearchForLists(pfd, nullptr);
+
+ SendDlgItemMessage(m_hwnd, IDC_LIST, LB_SETCURSEL, 0, 0);
+ SendMessage(m_hwnd, WM_COMMAND, MAKELONG(IDC_LIST, LBN_SELCHANGE), 0);
+
+ wchar_t filename[MAX_PATH];
+ GetDlgItemText(m_hwnd, IDC_FILENAME, filename, _countof(filename));
+ if (_waccess(filename, 4))
+ SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 1, 0);
+ return true;
+}
+
+void CMirandaPageDlg::OnDestroy()
+{
+ for (int i = SendDlgItemMessage(m_hwnd, IDC_LIST, LB_GETCOUNT, 0, 0) - 1; i >= 0; i--)
+ mir_free((char*)SendDlgItemMessage(m_hwnd, IDC_LIST, LB_GETITEMDATA, i, 0));
+}
+
+void CMirandaPageDlg::OnNext()
+{
+ wchar_t filename[MAX_PATH];
+ GetDlgItemText(m_hwnd, IDC_FILENAME, filename, _countof(filename));
+ if (_waccess(filename, 4)) {
+ MessageBox(m_hwnd, TranslateT("The given file does not exist. Please check that you have entered the name correctly."), TranslateT("Miranda Import"), MB_OK);
+ return;
+ }
+ mir_wstrcpy(importFile, filename);
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaOptionsPageDlg());
+}
+
+void CMirandaPageDlg::onClick_Back(CCtrlButton*)
+{
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CIntroPageDlg());
+}
+
+void CMirandaPageDlg::onClick_Other(CCtrlButton*)
+{
+ ptrW pfd(Utils_ReplaceVarsW(L"%miranda_profilesdir%"));
+
+ wchar_t str[MAX_PATH], text[256];
+ GetDlgItemText(m_hwnd, IDC_FILENAME, str, _countof(str));
+ mir_snwprintf(text, L"%s (*.dat, *.bak)%c*.dat;*.bak%c%s (*.*)%c*.*%c%c", TranslateT("Miranda NG database"), 0, 0, TranslateT("All Files"), 0, 0, 0);
+
+ OPENFILENAME ofn = {};
+ ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ ofn.hwndOwner = m_hwnd;
+ ofn.lpstrFilter = text;
+ ofn.lpstrDefExt = L"dat";
+ ofn.lpstrFile = str;
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT;
+ ofn.nMaxFile = _countof(str);
+ ofn.lpstrInitialDir = pfd;
+ if (GetOpenFileName(&ofn)) {
+ if (!mir_wstrcmpi(str, VARSW(L"%miranda_userdata%\\%miranda_profilename%.dat"))) {
+ MessageBoxW(nullptr, TranslateT("You cannot import your current profile into itself"), L"Miranda NG", MB_OK | MB_ICONERROR);
+ return;
+ }
+
+ SetDlgItemText(m_hwnd, IDC_FILENAME, str);
+ list.SetCurSel(-1);
+ SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
+ }
+}
+
+void CMirandaPageDlg::onSelChanged_list(CCtrlListBox*)
+{
+ int sel = list.GetCurSel();
+ if (sel != -1) {
+ SetDlgItemText(m_hwnd, IDC_FILENAME, (wchar_t*)list.GetItemData(sel));
+ SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
+ }
+}
+
+void CMirandaPageDlg::SearchForLists(const wchar_t *mirandaPath, const wchar_t *mirandaProf)
{
// find in Miranda profile subfolders
wchar_t searchspec[MAX_PATH];
@@ -53,165 +148,57 @@ static void SearchForLists(HWND hwndDlg, const wchar_t *mirandaPath, const wchar
mir_snwprintf(buf, L"%s\\%s\\%s.dat", mirandaPath, fd.cFileName, fd.cFileName);
if (_waccess(buf, 0) == 0) {
mir_snwprintf(profile, L"%s.dat", fd.cFileName);
-
- int i = SendDlgItemMessage(hwndDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)profile);
- SendDlgItemMessage(hwndDlg, IDC_LIST, LB_SETITEMDATA, i, (LPARAM)mir_wstrdup(buf));
+ list.AddString(profile, (LPARAM)mir_wstrdup(buf));
}
- }
- while (FindNextFile(hFind, &fd));
+ } while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
-INT_PTR CALLBACK MirandaPageProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM)
-{
- wchar_t filename[MAX_PATH];
-
- switch(message) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- {
- VARSW pfd(L"%miranda_path%\\Profiles");
- VARSW pfd1(L"%miranda_path%");
- VARSW pfd2(L"%miranda_profilesdir%");
- VARSW pfn(L"%miranda_profilename%");
-
- SearchForLists(hwndDlg, pfd2, pfn);
- SearchForLists(hwndDlg, pfd1, nullptr);
- if (mir_wstrcmpi(pfd, pfd2))
- SearchForLists(hwndDlg, pfd, nullptr);
- }
- SendDlgItemMessage(hwndDlg, IDC_LIST, LB_SETCURSEL, 0, 0);
- SendMessage(hwndDlg, WM_COMMAND, MAKELONG(IDC_LIST, LBN_SELCHANGE), 0);
- GetDlgItemText(hwndDlg, IDC_FILENAME, filename, _countof(filename));
- if (_waccess(filename, 4))
- SendMessage(GetParent(hwndDlg), WIZM_DISABLEBUTTON, 1, 0);
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_BACK:
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_WIZARDINTRO, (LPARAM)WizardIntroPageProc);
- break;
-
- case IDOK:
- GetDlgItemText(hwndDlg, IDC_FILENAME, filename, _countof(filename));
- if (_waccess(filename, 4)) {
- MessageBox(hwndDlg, TranslateT("The given file does not exist. Please check that you have entered the name correctly."), TranslateT("Miranda Import"), MB_OK);
- break;
- }
- mir_wstrcpy(importFile, filename);
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_OPTIONS, (LPARAM)MirandaOptionsPageProc);
- break;
-
- case IDCANCEL:
- PostMessage(GetParent(hwndDlg), WM_CLOSE, 0, 0);
- break;
-
- case IDC_LIST:
- if (HIWORD(wParam) == LBN_SELCHANGE) {
- int sel = SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETCURSEL, 0, 0);
- if (sel != LB_ERR) {
- SetDlgItemText(hwndDlg, IDC_FILENAME, (wchar_t*)SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETITEMDATA, sel, 0));
- SendMessage(GetParent(hwndDlg), WIZM_ENABLEBUTTON, 1, 0);
- }
- }
- break;
-
- case IDC_OTHER:
- ptrW pfd(Utils_ReplaceVarsW(L"%miranda_profilesdir%"));
-
- wchar_t str[MAX_PATH], text[256];
- GetDlgItemText(hwndDlg, IDC_FILENAME, str, _countof(str));
- mir_snwprintf(text, L"%s (*.dat, *.bak)%c*.dat;*.bak%c%s (*.*)%c*.*%c%c", TranslateT("Miranda NG database"), 0, 0, TranslateT("All Files"), 0, 0, 0);
-
- OPENFILENAME ofn = { 0 };
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.hwndOwner = hwndDlg;
- ofn.lpstrFilter = text;
- ofn.lpstrDefExt = L"dat";
- ofn.lpstrFile = str;
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT;
- ofn.nMaxFile = _countof(str);
- ofn.lpstrInitialDir = pfd;
- if (GetOpenFileName(&ofn)) {
- if (!mir_wstrcmpi(str, VARSW(L"%miranda_userdata%\\%miranda_profilename%.dat"))) {
- MessageBoxW(nullptr, TranslateT("You cannot import your current profile into itself"), L"Miranda NG", MB_OK | MB_ICONERROR);
- break;
- }
-
- SetDlgItemText(hwndDlg, IDC_FILENAME, str);
- SendDlgItemMessage(hwndDlg, IDC_LIST, LB_SETCURSEL, -1, 0);
- SendMessage(GetParent(hwndDlg), WIZM_ENABLEBUTTON, 1, 0);
- }
- }
- break;
+//=======================================================================================
+// Import options dialog
- case WM_DESTROY:
- for (int i = SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETCOUNT, 0, 0) - 1; i >= 0; i--)
- mir_free((char*)SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETITEMDATA, i, 0));
- break;
- }
+CMirandaOptionsPageDlg::CMirandaOptionsPageDlg() :
+ CWizardPageDlg(IDD_OPTIONS),
+ btnBack(this, IDC_BACK)
+{
+ btnBack.OnClick = Callback(this, &CMirandaOptionsPageDlg::onClick_Back);
+}
- return FALSE;
+bool CMirandaOptionsPageDlg::OnInitDialog()
+{
+ EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_COMPLETE), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_ALL), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_STATIC_ALL), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_CONTACTS), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_STATIC_CONTACTS), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_CUSTOM), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_STATIC_CUSTOM), TRUE);
+ CheckDlgButton(m_hwnd, IDC_RADIO_ALL, BST_CHECKED);
+ return true;
}
-//=======================================================================================
-// Import options dialog
+void CMirandaOptionsPageDlg::onClick_Back(CCtrlButton*)
+{
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaPageDlg());
+}
-INT_PTR CALLBACK MirandaOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM)
+void CMirandaOptionsPageDlg::OnNext()
{
- switch (message) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_COMPLETE), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_ALL), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_ALL), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_CONTACTS), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_CONTACTS), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_CUSTOM), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_CUSTOM), TRUE);
- CheckDlgButton(hwndDlg, IDC_RADIO_ALL, BST_CHECKED);
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_BACK:
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_MIRANDADB, (LPARAM)MirandaPageProc);
- break;
-
- case IDOK:
- if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_COMPLETE)) {
- g_iImportOptions = IOPT_ADDUNKNOWN | IOPT_COMPLETE | IOPT_CHECKDUPS;
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
- break;
- }
-
- if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ALL)) {
- g_iImportOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS | IOPT_CHECKDUPS;
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
- break;
- }
-
- if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_CONTACTS)) {
- g_iImportOptions = IOPT_CONTACTS;
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
- break;
- }
-
- if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_CUSTOM)) {
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_ADVOPTIONS, (LPARAM)MirandaAdvOptionsPageProc);
- break;
- }
- break;
-
- case IDCANCEL:
- PostMessage(GetParent(hwndDlg), WM_CLOSE, 0, 0);
- break;
- }
- break;
+ if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_COMPLETE)) {
+ g_iImportOptions = IOPT_ADDUNKNOWN | IOPT_COMPLETE | IOPT_CHECKDUPS;
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
+ }
+ else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_ALL)) {
+ g_iImportOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS | IOPT_CHECKDUPS;
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
}
- return FALSE;
+ else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_CONTACTS)) {
+ g_iImportOptions = IOPT_CONTACTS;
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
+ }
+ else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_CUSTOM))
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_ADVOPTIONS, (LPARAM)new CMirandaAdvOptionsPageDlg());
}
//=======================================================================================
@@ -221,126 +208,138 @@ static const UINT InControls[] = { IDC_IN_MSG, IDC_IN_URL, IDC_IN_FT, IDC_IN_OTH
static const UINT OutControls[] = { IDC_OUT_MSG, IDC_OUT_URL, IDC_OUT_FT, IDC_OUT_OTHER };
static const UINT SysControls[] = { IDC_CONTACTS, IDC_SYSTEM };
-INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM)
+CMirandaAdvOptionsPageDlg::CMirandaAdvOptionsPageDlg() :
+ CWizardPageDlg(IDD_ADVOPTIONS),
+ btnBack(this, IDC_BACK),
+ chkFT(this, IDC_FT),
+ chkAll(this, IDC_ALL),
+ chkMsg(this, IDC_MSG),
+ chkUrl(this, IDC_URL),
+ chkOther(this, IDC_OTHER),
+ chkSince(this, IDC_SINCE),
+ chkOutgoing(this, IDC_OUTGOING),
+ chkIncoming(this, IDC_INCOMING)
{
- switch (message) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- {
- dwSinceDate = db_get_dw(NULL, IMPORT_MODULE, "ImportSinceTS", time(0));
- struct tm *TM = localtime(&dwSinceDate);
-
- struct _SYSTEMTIME ST = { 0 };
- ST.wYear = TM->tm_year + 1900;
- ST.wMonth = TM->tm_mon + 1;
- ST.wDay = TM->tm_mday;
-
- DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER), GDT_VALID, &ST);
- }
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_BACK:
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_OPTIONS, (LPARAM)MirandaOptionsPageProc);
- break;
-
- case IDOK:
- g_iImportOptions = 0;
-
- if (IsDlgButtonChecked(hwndDlg, IDC_CONTACTS))
- g_iImportOptions |= IOPT_CONTACTS | IOPT_GROUPS;
- if (IsDlgButtonChecked(hwndDlg, IDC_SYSTEM))
- g_iImportOptions |= IOPT_SYSTEM;
-
- // incoming
- if (IsDlgButtonChecked(hwndDlg, IDC_IN_MSG))
- g_iImportOptions |= IOPT_MSGRECV;
- if (IsDlgButtonChecked(hwndDlg, IDC_IN_URL))
- g_iImportOptions |= IOPT_URLRECV;
- if (IsDlgButtonChecked(hwndDlg, IDC_IN_FT))
- g_iImportOptions |= IOPT_FILERECV;
- if (IsDlgButtonChecked(hwndDlg, IDC_IN_OTHER))
- g_iImportOptions |= IOPT_OTHERRECV;
-
- // outgoing
- if (IsDlgButtonChecked(hwndDlg, IDC_OUT_MSG))
- g_iImportOptions |= IOPT_MSGSENT;
- if (IsDlgButtonChecked(hwndDlg, IDC_OUT_URL))
- g_iImportOptions |= IOPT_URLSENT;
- if (IsDlgButtonChecked(hwndDlg, IDC_OUT_FT))
- g_iImportOptions |= IOPT_FILESENT;
- if (IsDlgButtonChecked(hwndDlg, IDC_OUT_OTHER))
- g_iImportOptions |= IOPT_OTHERSENT;
-
- // since date
- dwSinceDate = 0;
-
- if (IsDlgButtonChecked(hwndDlg, IDC_SINCE)) {
- struct _SYSTEMTIME ST = { 0 };
-
- if (DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER), &ST) == GDT_VALID) {
- struct tm TM = { 0 };
-
- TM.tm_mday = ST.wDay;
- TM.tm_mon = ST.wMonth - 1;
- TM.tm_year = ST.wYear - 1900;
-
- dwSinceDate = mktime(&TM);
-
- db_set_dw(NULL, IMPORT_MODULE, "ImportSinceTS", dwSinceDate);
- }
- }
-
- if (g_iImportOptions)
- PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
- break;
-
- case IDCANCEL:
- PostMessage(GetParent(hwndDlg), WM_CLOSE, 0, 0);
- break;
-
- case IDC_SINCE:
- EnableWindow(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER), IsDlgButtonChecked(hwndDlg, IDC_SINCE));
- break;
-
- case IDC_ALL:
- case IDC_INCOMING:
- case IDC_OUTGOING:
- if (LOWORD(wParam) == IDC_ALL)
- for (auto &it : SysControls)
- CheckDlgButton(hwndDlg, it, IsDlgButtonChecked(hwndDlg, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
-
- if (LOWORD(wParam) != IDC_OUTGOING)
- for (auto &it : InControls)
- CheckDlgButton(hwndDlg, it, IsDlgButtonChecked(hwndDlg, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
-
- if (LOWORD(wParam) != IDC_INCOMING)
- for (auto &it : OutControls)
- CheckDlgButton(hwndDlg, it, IsDlgButtonChecked(hwndDlg, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- break;
-
- case IDC_MSG:
- CheckDlgButton(hwndDlg, IDC_IN_MSG, IsDlgButtonChecked(hwndDlg, IDC_IN_MSG) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_OUT_MSG, IsDlgButtonChecked(hwndDlg, IDC_OUT_MSG) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- break;
-
- case IDC_URL:
- CheckDlgButton(hwndDlg, IDC_IN_URL, IsDlgButtonChecked(hwndDlg, IDC_IN_URL) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_OUT_URL, IsDlgButtonChecked(hwndDlg, IDC_OUT_URL) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- break;
-
- case IDC_FT:
- CheckDlgButton(hwndDlg, IDC_IN_FT, IsDlgButtonChecked(hwndDlg, IDC_IN_FT) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_OUT_FT, IsDlgButtonChecked(hwndDlg, IDC_OUT_FT) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- break;
-
- case IDC_OTHER:
- CheckDlgButton(hwndDlg, IDC_IN_OTHER, IsDlgButtonChecked(hwndDlg, IDC_IN_OTHER) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_OUT_OTHER, IsDlgButtonChecked(hwndDlg, IDC_OUT_OTHER) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
- break;
+ btnBack.OnClick = Callback(this, &CMirandaAdvOptionsPageDlg::onClick_Back);
+
+ chkSince.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_Since);
+ chkAll.OnChange = chkOutgoing.OnChange = chkIncoming.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_All);
+ chkMsg.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_Msg);
+ chkUrl.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_Url);
+ chkFT.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_FT);
+ chkOther.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_Other);
+}
+
+bool CMirandaAdvOptionsPageDlg::OnInitDialog()
+{
+ dwSinceDate = db_get_dw(NULL, IMPORT_MODULE, "ImportSinceTS", time(0));
+ struct tm *TM = localtime(&dwSinceDate);
+
+ struct _SYSTEMTIME ST = { 0 };
+ ST.wYear = TM->tm_year + 1900;
+ ST.wMonth = TM->tm_mon + 1;
+ ST.wDay = TM->tm_mday;
+ DateTime_SetSystemtime(GetDlgItem(m_hwnd, IDC_DATETIMEPICKER), GDT_VALID, &ST);
+ return true;
+}
+
+void CMirandaAdvOptionsPageDlg::onClick_Back(CCtrlButton*)
+{
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaOptionsPageDlg());
+}
+
+void CMirandaAdvOptionsPageDlg::OnNext()
+{
+ g_iImportOptions = 0;
+
+ if (IsDlgButtonChecked(m_hwnd, IDC_CONTACTS))
+ g_iImportOptions |= IOPT_CONTACTS | IOPT_GROUPS;
+ if (IsDlgButtonChecked(m_hwnd, IDC_SYSTEM))
+ g_iImportOptions |= IOPT_SYSTEM;
+
+ // incoming
+ if (IsDlgButtonChecked(m_hwnd, IDC_IN_MSG))
+ g_iImportOptions |= IOPT_MSGRECV;
+ if (IsDlgButtonChecked(m_hwnd, IDC_IN_URL))
+ g_iImportOptions |= IOPT_URLRECV;
+ if (IsDlgButtonChecked(m_hwnd, IDC_IN_FT))
+ g_iImportOptions |= IOPT_FILERECV;
+ if (IsDlgButtonChecked(m_hwnd, IDC_IN_OTHER))
+ g_iImportOptions |= IOPT_OTHERRECV;
+
+ // outgoing
+ if (IsDlgButtonChecked(m_hwnd, IDC_OUT_MSG))
+ g_iImportOptions |= IOPT_MSGSENT;
+ if (IsDlgButtonChecked(m_hwnd, IDC_OUT_URL))
+ g_iImportOptions |= IOPT_URLSENT;
+ if (IsDlgButtonChecked(m_hwnd, IDC_OUT_FT))
+ g_iImportOptions |= IOPT_FILESENT;
+ if (IsDlgButtonChecked(m_hwnd, IDC_OUT_OTHER))
+ g_iImportOptions |= IOPT_OTHERSENT;
+
+ // since date
+ dwSinceDate = 0;
+
+ if (chkSince.IsChecked()) {
+ struct _SYSTEMTIME ST = { 0 };
+
+ if (DateTime_GetSystemtime(GetDlgItem(m_hwnd, IDC_DATETIMEPICKER), &ST) == GDT_VALID) {
+ struct tm TM = { 0 };
+
+ TM.tm_mday = ST.wDay;
+ TM.tm_mon = ST.wMonth - 1;
+ TM.tm_year = ST.wYear - 1900;
+
+ dwSinceDate = mktime(&TM);
+
+ db_set_dw(NULL, IMPORT_MODULE, "ImportSinceTS", dwSinceDate);
}
- break;
}
- return FALSE;
+
+ if (g_iImportOptions)
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CProgressPageDlg());
+}
+
+void CMirandaAdvOptionsPageDlg::onChange_Since(CCtrlCheck*)
+{
+ EnableWindow(GetDlgItem(m_hwnd, IDC_DATETIMEPICKER), chkSince.IsChecked());
+}
+
+void CMirandaAdvOptionsPageDlg::onChange_All(CCtrlCheck *pCheck)
+{
+ if (pCheck->GetCtrlId() == IDC_ALL)
+ for (auto &it : SysControls)
+ CheckDlgButton(m_hwnd, it, IsDlgButtonChecked(m_hwnd, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+
+ if (pCheck->GetCtrlId() != IDC_OUTGOING)
+ for (auto &it : InControls)
+ CheckDlgButton(m_hwnd, it, IsDlgButtonChecked(m_hwnd, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+
+ if (pCheck->GetCtrlId() != IDC_INCOMING)
+ for (auto &it : OutControls)
+ CheckDlgButton(m_hwnd, it, IsDlgButtonChecked(m_hwnd, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+}
+
+void CMirandaAdvOptionsPageDlg::onChange_Msg(CCtrlCheck*)
+{
+ CheckDlgButton(m_hwnd, IDC_IN_MSG, IsDlgButtonChecked(m_hwnd, IDC_IN_MSG) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_OUT_MSG, IsDlgButtonChecked(m_hwnd, IDC_OUT_MSG) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+}
+
+void CMirandaAdvOptionsPageDlg::onChange_Url(CCtrlCheck*)
+{
+ CheckDlgButton(m_hwnd, IDC_IN_URL, IsDlgButtonChecked(m_hwnd, IDC_IN_URL) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_OUT_URL, IsDlgButtonChecked(m_hwnd, IDC_OUT_URL) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+}
+
+void CMirandaAdvOptionsPageDlg::onChange_FT(CCtrlCheck*)
+{
+ CheckDlgButton(m_hwnd, IDC_IN_FT, IsDlgButtonChecked(m_hwnd, IDC_IN_FT) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_OUT_FT, IsDlgButtonChecked(m_hwnd, IDC_OUT_FT) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+}
+
+void CMirandaAdvOptionsPageDlg::onChange_Other(CCtrlCheck*)
+{
+ CheckDlgButton(m_hwnd, IDC_IN_OTHER, IsDlgButtonChecked(m_hwnd, IDC_IN_OTHER) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_OUT_OTHER, IsDlgButtonChecked(m_hwnd, IDC_OUT_OTHER) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
}
diff --git a/plugins/Import/src/progress.cpp b/plugins/Import/src/progress.cpp
index 23e357b824..be559756b3 100644
--- a/plugins/Import/src/progress.cpp
+++ b/plugins/Import/src/progress.cpp
@@ -22,53 +22,51 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-#define PROGM_START (WM_USER+100)
-
void MirandaImport(HWND);
-INT_PTR CALLBACK ProgressPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+CProgressPageDlg::CProgressPageDlg() :
+ CWizardPageDlg(IDD_PROGRESS)
+{}
+
+bool CProgressPageDlg::OnInitDialog()
+{
+ SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 0, 0);
+ SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 1, 0);
+ SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 2, 0);
+ SendDlgItemMessage(m_hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
+ PostMessage(m_hwnd, PROGM_START, 0, 0);
+ return true;
+}
+
+void CProgressPageDlg::OnNext()
{
- switch (message) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hdlg);
- SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 0, 0);
- SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 1, 0);
- SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 2, 0);
- SendDlgItemMessage(hdlg, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
- PostMessage(hdlg, PROGM_START, 0, 0);
- return TRUE;
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CFinishedPageDlg());
+}
+INT_PTR CProgressPageDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
case PROGM_SETPROGRESS:
- SendDlgItemMessage(hdlg, IDC_PROGRESS, PBM_SETPOS, wParam, 0);
+ SendDlgItemMessage(m_hwnd, IDC_PROGRESS, PBM_SETPOS, wParam, 0);
break;
case PROGM_ADDMESSAGE:
{
- int i = SendDlgItemMessage(hdlg, IDC_STATUS, LB_ADDSTRING, 0, lParam);
- SendDlgItemMessage(hdlg, IDC_STATUS, LB_SETTOPINDEX, i, 0);
+ int i = SendDlgItemMessage(m_hwnd, IDC_STATUS, LB_ADDSTRING, 0, lParam);
+ SendDlgItemMessage(m_hwnd, IDC_STATUS, LB_SETTOPINDEX, i, 0);
}
break;
case PROGM_START:
- MirandaImport(hdlg);
+ MirandaImport(m_hwnd);
if (g_bServiceMode && !g_bSendQuit)
DestroyWindow(g_hwndWizard);
else {
- SendMessage(GetParent(hdlg), WIZM_ENABLEBUTTON, 1, 0);
- SendMessage(GetParent(hdlg), WIZM_ENABLEBUTTON, 2, 0);
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_FINISHED, (LPARAM)FinishedPageProc);
- break;
- case IDCANCEL:
- PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0);
- break;
+ SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
+ SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 2, 0);
}
break;
}
- return FALSE;
+
+ return CWizardPageDlg::DlgProc(uMsg, wParam, lParam);
}
diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h
index 3fa8d721fc..4aed993c33 100644
--- a/plugins/Import/src/stdafx.h
+++ b/plugins/Import/src/stdafx.h
@@ -69,29 +69,115 @@ struct CMPlugin : public PLUGIN<CMPlugin>
// Keys
#define IMP_KEY_FR "FirstRun" // First run
-#define WIZM_GOTOPAGE (WM_USER+10) // wParam=resource id, lParam=dlgproc
+#define WIZM_GOTOPAGE (WM_USER+10) // wParam=0, lParam=page class
#define WIZM_DISABLEBUTTON (WM_USER+11) // wParam=0:back, 1:next, 2:cancel
#define WIZM_SETCANCELTEXT (WM_USER+12) // lParam=(char*)newText
#define WIZM_ENABLEBUTTON (WM_USER+13) // wParam=0:back, 1:next, 2:cancel
#define PROGM_SETPROGRESS (WM_USER+10) // wParam=0..100
#define PROGM_ADDMESSAGE (WM_USER+11) // lParam=(char*)szText
+#define PROGM_START (WM_USER+100)
+
+class CWizardPageDlg : public CDlgBase
+{
+ CCtrlButton btnOk, btnCancel;
+
+protected:
+ virtual void OnNext() PURE;
+ virtual void OnCancel();
+
+public:
+ CWizardPageDlg(int dlgId);
+
+ void onClick_Ok(CCtrlButton*) { OnNext(); }
+ void onClick_Cancel(CCtrlButton*) { OnCancel(); }
+};
void AddMessage(const wchar_t* fmt, ...);
+LRESULT RunWizard(CWizardPageDlg*, bool bModal);
+
+class CIntroPageDlg : public CWizardPageDlg
+{
+public:
+ CIntroPageDlg();
+
+ bool OnInitDialog() override;
+ void OnNext() override;
+};
-struct WizardDlgParam
+class CProgressPageDlg : public CWizardPageDlg
{
- WPARAM wParam;
- LPARAM lParam;
+public:
+ CProgressPageDlg();
+
+ bool OnInitDialog() override;
+ void OnNext() override;
+ INT_PTR DlgProc(UINT, WPARAM, LPARAM) override;
};
-INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK WizardIntroPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK ProgressPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK MirandaPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK MirandaOptionsPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK FinishedPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
+class CMirandaPageDlg : public CWizardPageDlg
+{
+ void SearchForLists(const wchar_t *mirandaPath, const wchar_t *mirandaProf);
+
+ CCtrlButton btnBack, btnOther;
+ CCtrlListBox list;
+
+public:
+ CMirandaPageDlg();
+
+ bool OnInitDialog() override;
+ void OnDestroy() override;
+ void OnNext() override;
+
+ void onClick_Back(CCtrlButton*);
+ void onClick_Other(CCtrlButton*);
+
+ void onSelChanged_list(CCtrlListBox*);
+};
+
+class CMirandaOptionsPageDlg : public CWizardPageDlg
+{
+ CCtrlButton btnBack;
+
+public:
+ CMirandaOptionsPageDlg();
+
+ bool OnInitDialog() override;
+ void OnNext() override;
+
+ void onClick_Back(CCtrlButton*);
+};
+
+class CMirandaAdvOptionsPageDlg : public CWizardPageDlg
+{
+ CCtrlButton btnBack;
+ CCtrlCheck chkSince, chkAll, chkOutgoing, chkIncoming, chkMsg, chkUrl, chkFT, chkOther;
+
+public:
+ CMirandaAdvOptionsPageDlg();
+
+ bool OnInitDialog() override;
+ void OnNext() override;
+
+ void onClick_Back(CCtrlButton*);
+
+ void onChange_Since(CCtrlCheck*);
+ void onChange_All(CCtrlCheck*);
+ void onChange_Msg(CCtrlCheck*);
+ void onChange_Url(CCtrlCheck*);
+ void onChange_FT(CCtrlCheck*);
+ void onChange_Other(CCtrlCheck*);
+};
+
+class CFinishedPageDlg : public CWizardPageDlg
+{
+public:
+ CFinishedPageDlg();
+
+ bool OnInitDialog() override;
+ void OnNext() override;
+ void OnCancel() override;
+};
bool IsDuplicateEvent(MCONTACT hContact, DBEVENTINFO dbei);
diff --git a/plugins/Import/src/version.h b/plugins/Import/src/version.h
index 4d1b1af376..5e66319a8e 100644
--- a/plugins/Import/src/version.h
+++ b/plugins/Import/src/version.h
@@ -1,6 +1,6 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
-#define __RELEASE_NUM 9
+#define __RELEASE_NUM 10
#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/plugins/Import/src/wizard.cpp b/plugins/Import/src/wizard.cpp
index 9f1bed8b05..ed1fd7432a 100644
--- a/plugins/Import/src/wizard.cpp
+++ b/plugins/Import/src/wizard.cpp
@@ -22,153 +22,183 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-INT_PTR CALLBACK WizardIntroPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM)
+/////////////////////////////////////////////////////////////////////////////////////////
+// Intro wizard page
+
+CIntroPageDlg::CIntroPageDlg() :
+ CWizardPageDlg(IDD_WIZARDINTRO)
+{}
+
+bool CIntroPageDlg::OnInitDialog()
{
- switch (message) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hdlg);
- SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 0, 0);
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRANDADB, (LPARAM)MirandaPageProc);
- break;
+ SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 0, 0);
+ return true;
+}
- case IDCANCEL:
- PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0);
- break;
- }
- }
+void CIntroPageDlg::OnNext()
+{
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaPageDlg());
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Final wizard page
+
+CFinishedPageDlg::CFinishedPageDlg() :
+ CWizardPageDlg(IDD_FINISHED)
+{}
- return FALSE;
+bool CFinishedPageDlg::OnInitDialog()
+{
+ SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 0, 0);
+ SendMessage(m_hwndParent, WIZM_SETCANCELTEXT, 0, (LPARAM)TranslateT("Finish"));
+ CheckDlgButton(m_hwnd, IDC_DONTLOADPLUGIN, BST_UNCHECKED);
+ return true;
}
-INT_PTR CALLBACK FinishedPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM)
+void CFinishedPageDlg::OnNext()
{
- switch (message) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hdlg);
- SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 0, 0);
- SendMessage(GetParent(hdlg), WIZM_SETCANCELTEXT, 0, (LPARAM)TranslateT("Finish"));
- CheckDlgButton(hdlg, IDC_DONTLOADPLUGIN, BST_UNCHECKED);
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRANDADB, (LPARAM)MirandaPageProc);
- break;
+ PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaPageDlg());
+}
- case IDCANCEL:
- if (IsDlgButtonChecked(hdlg, IDC_DONTLOADPLUGIN)) {
- char sModuleFileName[MAX_PATH];
- GetModuleFileNameA(g_plugin.getInst(), sModuleFileName, sizeof(sModuleFileName));
- char *pszFileName = strrchr(sModuleFileName, '\\');
- if (pszFileName == nullptr)
- pszFileName = sModuleFileName;
- else
- pszFileName++;
-
- // We must lower case here because if a DLL is loaded in two
- // processes, its file name from GetModuleFileName in one process may
- // differ in case from its file name in the other process. This will
- // prevent the plugin from disabling/enabling correctly (this fix relies
- // on the plugin loader to ignore case)
- CharLowerA(pszFileName);
- db_set_b(NULL, "PluginDisable", pszFileName, 1);
- }
- PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0);
- break;
- }
- break;
- }
+void CFinishedPageDlg::OnCancel()
+{
+ if (IsDlgButtonChecked(m_hwnd, IDC_DONTLOADPLUGIN))
+ db_set_b(NULL, "PluginDisable", "import", 1);
- return FALSE;
+ CWizardPageDlg::OnCancel();
}
-INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CWizardPageDlg::CWizardPageDlg(int iDlgId) :
+ CDlgBase(g_plugin, iDlgId),
+ btnOk(this, IDOK),
+ btnCancel(this, IDCANCEL)
{
- static HWND hwndPage = nullptr;
- bool bFirstLaunch = hwndPage == nullptr;
-
- switch (message) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hdlg);
- Window_SetIcon_IcoLib(hdlg, GetIconHandle(IDI_IMPORT));
- g_hwndWizard = hdlg;
- {
- WizardDlgParam *param = (WizardDlgParam*)lParam;
- if (param)
- PostMessage(hdlg, WIZM_GOTOPAGE, param->wParam, param->lParam);
- }
- return TRUE;
+ m_autoClose = 0; // disable built-in IDOK & IDCANCEL handlers;
+
+ btnOk.OnClick = Callback(this, &CWizardPageDlg::onClick_Ok);
+ btnCancel.OnClick = Callback(this, &CWizardPageDlg::onClick_Cancel);
+}
+
+void CWizardPageDlg::OnCancel()
+{
+ PostMessage(m_hwndParent, WM_CLOSE, 0, 0);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
- case WIZM_GOTOPAGE:
+class CWizardDlg : public CDlgBase
+{
+ CWizardPageDlg *m_pFirstPage;
+ HWND hwndPage = nullptr;
+
+public:
+ CWizardDlg(CWizardPageDlg *pPage) :
+ CDlgBase(g_plugin, IDD_WIZARD),
+ m_pFirstPage(pPage)
+ {
+ m_autoClose = CLOSE_ON_CANCEL;
+ }
+
+ bool OnInitDialog() override
+ {
+ Window_SetIcon_IcoLib(m_hwnd, GetIconHandle(IDI_IMPORT));
+ g_hwndWizard = m_hwnd;
+
+ if (m_pFirstPage)
+ PostMessage(m_hwnd, WIZM_GOTOPAGE, 0, (LPARAM)m_pFirstPage);
+ return true;
+ }
+
+ bool OnClose() override
+ {
if (hwndPage)
DestroyWindow(hwndPage);
- EnableWindow(GetDlgItem(hdlg, IDC_BACK), TRUE);
- EnableWindow(GetDlgItem(hdlg, IDOK), TRUE);
- EnableWindow(GetDlgItem(hdlg, IDCANCEL), TRUE);
- SetDlgItemText(hdlg, IDCANCEL, TranslateT("Cancel"));
- hwndPage = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(wParam), hdlg, (DLGPROC)lParam);
- SetWindowPos(hwndPage, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
- ShowWindow(hwndPage, SW_SHOW);
- if (bFirstLaunch)
- ShowWindow(hdlg, SW_SHOW);
- break;
-
- case WIZM_DISABLEBUTTON:
- switch (wParam) {
- case 0:
- EnableWindow(GetDlgItem(hdlg, IDC_BACK), FALSE);
- break;
+ return true;
+ }
- case 1:
- EnableWindow(GetDlgItem(hdlg, IDOK), FALSE);
+ void OnDestroy() override
+ {
+ g_hwndWizard = nullptr;
+ if (g_bSendQuit)
+ PostQuitMessage(0);
+ }
+
+ INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override
+ {
+ bool bFirstLaunch = hwndPage == nullptr;
+
+ switch (uMsg) {
+ case WIZM_GOTOPAGE:
+ if (hwndPage)
+ DestroyWindow(hwndPage);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_BACK), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDOK), TRUE);
+ EnableWindow(GetDlgItem(m_hwnd, IDCANCEL), TRUE);
+ SetDlgItemText(m_hwnd, IDCANCEL, TranslateT("Cancel"));
+ {
+ CWizardPageDlg *pPage = (CWizardPageDlg*)lParam;
+ pPage->SetParent(m_hwnd);
+ pPage->Show();
+ hwndPage = pPage->GetHwnd();
+ }
+ SetWindowPos(hwndPage, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
+ if (bFirstLaunch)
+ ShowWindow(m_hwnd, SW_SHOW);
break;
- case 2:
- EnableWindow(GetDlgItem(hdlg, IDCANCEL), FALSE);
+ case WIZM_DISABLEBUTTON:
+ switch (wParam) {
+ case 0:
+ EnableWindow(GetDlgItem(m_hwnd, IDC_BACK), FALSE);
+ break;
+
+ case 1:
+ EnableWindow(GetDlgItem(m_hwnd, IDOK), FALSE);
+ break;
+
+ case 2:
+ EnableWindow(GetDlgItem(m_hwnd, IDCANCEL), FALSE);
+ break;
+ }
break;
- }
- break;
- case WIZM_ENABLEBUTTON:
- switch (wParam) {
- case 0:
- EnableWindow(GetDlgItem(hdlg, IDC_BACK), TRUE);
+ case WIZM_ENABLEBUTTON:
+ switch (wParam) {
+ case 0:
+ EnableWindow(GetDlgItem(m_hwnd, IDC_BACK), TRUE);
+ break;
+
+ case 1:
+ EnableWindow(GetDlgItem(m_hwnd, IDOK), TRUE);
+ break;
+
+ case 2:
+ EnableWindow(GetDlgItem(m_hwnd, IDCANCEL), TRUE);
+ break;
+ }
break;
- case 1:
- EnableWindow(GetDlgItem(hdlg, IDOK), TRUE);
+ case WIZM_SETCANCELTEXT:
+ SetDlgItemText(m_hwnd, IDCANCEL, (wchar_t*)lParam);
break;
- case 2:
- EnableWindow(GetDlgItem(hdlg, IDCANCEL), TRUE);
+ case WM_COMMAND:
+ SendMessage(hwndPage, WM_COMMAND, wParam, lParam);
break;
}
- break;
-
- case WIZM_SETCANCELTEXT:
- SetDlgItemText(hdlg, IDCANCEL, (wchar_t*)lParam);
- break;
- case WM_COMMAND:
- SendMessage(hwndPage, WM_COMMAND, wParam, lParam);
- break;
-
- case WM_CLOSE:
- DestroyWindow(hwndPage);
- DestroyWindow(hdlg);
- break;
-
- case WM_DESTROY:
- g_hwndWizard = hwndPage = nullptr;
- if (g_bSendQuit)
- PostQuitMessage(0);
+ return CDlgBase::DlgProc(uMsg, wParam, lParam);
}
+};
+
+LRESULT RunWizard(CWizardPageDlg *pPage, bool bModal)
+{
+ if (bModal)
+ return CWizardDlg(pPage).DoModal();
- return FALSE;
+ CWizardDlg *pDlg = new CWizardDlg(pPage);
+ pDlg->Show();
+ return 0;
}