summaryrefslogtreecommitdiff
path: root/plugins/Import
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-10-18 21:20:04 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-10-18 21:20:04 +0300
commit589b7562b76ade5afb5e50e7eacf74782205c498 (patch)
treef59387de40a137f2de00bb6a39fac3913c19ee51 /plugins/Import
parentfba89acdf4814afe7547fd3c24b428ab42aa0a81 (diff)
the less WinAPI, the better
Diffstat (limited to 'plugins/Import')
-rw-r--r--plugins/Import/src/import.cpp19
-rw-r--r--plugins/Import/src/miranda.cpp12
-rw-r--r--plugins/Import/src/progress.cpp83
-rw-r--r--plugins/Import/src/stdafx.h19
4 files changed, 75 insertions, 58 deletions
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp
index 4b4d1e10d2..14f803d84f 100644
--- a/plugins/Import/src/import.cpp
+++ b/plugins/Import/src/import.cpp
@@ -22,8 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-#define SetProgress(n) SendMessage(hdlgProgress,PROGM_SETPROGRESS,n,0)
-
struct AccountMap
{
AccountMap(const char *_src, int _origIdx, const wchar_t *_srcName) :
@@ -73,24 +71,11 @@ static LIST<DBCachedContact> arMetas(10);
/////////////////////////////////////////////////////////////////////////////////////////
// local data
-static HWND hdlgProgress;
static DWORD nDupes, nContactsCount, nMessagesCount, nGroupsCount, nSkippedEvents, nSkippedContacts;
static MDatabaseCommon *srcDb, *dstDb;
/////////////////////////////////////////////////////////////////////////////////////////
-void AddMessage(const wchar_t* fmt, ...)
-{
- va_list args;
- wchar_t msgBuf[4096];
- va_start(args, fmt);
- mir_vsnwprintf(msgBuf, TranslateW(fmt), args);
-
- SendMessage(hdlgProgress, PROGM_ADDMESSAGE, 0, (LPARAM)msgBuf);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
static bool CompareDb(DBVARIANT &dbv1, DBVARIANT &dbv2)
{
if (dbv1.type == dbv2.type) {
@@ -1035,10 +1020,8 @@ static int CompareModules(const char *p1, const char *p2)
return mir_strcmpi(p1, p2);
}
-void MirandaImport(HWND hdlg)
+void MirandaImport()
{
- hdlgProgress = hdlg;
-
if ((dstDb = (MDatabaseCommon*)db_get_current()) == nullptr) {
AddMessage(LPGENW("Error retrieving current profile, exiting."));
return;
diff --git a/plugins/Import/src/miranda.cpp b/plugins/Import/src/miranda.cpp
index b8de3a69a8..0abfac62c4 100644
--- a/plugins/Import/src/miranda.cpp
+++ b/plugins/Import/src/miranda.cpp
@@ -31,11 +31,11 @@ wchar_t importFile[MAX_PATH];
CMirandaPageDlg::CMirandaPageDlg() :
CWizardPageDlg(IDD_MIRANDADB),
- list(this, IDC_LIST),
+ m_list(this, IDC_LIST),
btnBack(this, IDC_BACK),
btnOther(this, IDC_OTHER)
{
- list.OnSelChange = Callback(this, &CMirandaPageDlg::onSelChanged_list);
+ m_list.OnSelChange = Callback(this, &CMirandaPageDlg::onSelChanged_list);
btnBack.OnClick = Callback(this, &CMirandaPageDlg::onClick_Back);
btnOther.OnClick = Callback(this, &CMirandaPageDlg::onClick_Other);
@@ -110,16 +110,16 @@ void CMirandaPageDlg::onClick_Other(CCtrlButton*)
}
SetDlgItemText(m_hwnd, IDC_FILENAME, str);
- list.SetCurSel(-1);
+ m_list.SetCurSel(-1);
SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
}
}
void CMirandaPageDlg::onSelChanged_list(CCtrlListBox*)
{
- int sel = list.GetCurSel();
+ int sel = m_list.GetCurSel();
if (sel != -1) {
- SetDlgItemText(m_hwnd, IDC_FILENAME, (wchar_t*)list.GetItemData(sel));
+ SetDlgItemText(m_hwnd, IDC_FILENAME, (wchar_t*)m_list.GetItemData(sel));
SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
}
}
@@ -148,7 +148,7 @@ void CMirandaPageDlg::SearchForLists(const wchar_t *mirandaPath, const wchar_t *
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);
- list.AddString(profile, (LPARAM)mir_wstrdup(buf));
+ m_list.AddString(profile, (LPARAM)mir_wstrdup(buf));
}
} while (FindNextFile(hFind, &fd));
diff --git a/plugins/Import/src/progress.cpp b/plugins/Import/src/progress.cpp
index be559756b3..87b89a76ea 100644
--- a/plugins/Import/src/progress.cpp
+++ b/plugins/Import/src/progress.cpp
@@ -22,51 +22,80 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-void MirandaImport(HWND);
+#define PROGM_START (WM_USER+100)
+
+static CProgressPageDlg *pDlg;
+
+void MirandaImport(void);
CProgressPageDlg::CProgressPageDlg() :
- CWizardPageDlg(IDD_PROGRESS)
-{}
+ CWizardPageDlg(IDD_PROGRESS),
+ m_list(this, IDC_STATUS),
+ m_timer(this, 1)
+{
+ m_timer.OnEvent = Callback(this, &CProgressPageDlg::OnTimer);
+}
bool CProgressPageDlg::OnInitDialog()
{
+ pDlg = this;
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);
+ m_timer.Start(50);
return true;
}
+void CProgressPageDlg::OnDestroy()
+{
+ pDlg = nullptr;
+}
+
void CProgressPageDlg::OnNext()
{
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CFinishedPageDlg());
}
-INT_PTR CProgressPageDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
+void CProgressPageDlg::OnTimer(CTimer*)
{
- switch (uMsg) {
- case PROGM_SETPROGRESS:
- SendDlgItemMessage(m_hwnd, IDC_PROGRESS, PBM_SETPOS, wParam, 0);
- break;
-
- case PROGM_ADDMESSAGE:
- {
- 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(m_hwnd);
- if (g_bServiceMode && !g_bSendQuit)
- DestroyWindow(g_hwndWizard);
- else {
- SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
- SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 2, 0);
- }
- break;
+ m_timer.Stop();
+
+ MirandaImport();
+ if (g_bServiceMode && !g_bSendQuit)
+ DestroyWindow(g_hwndWizard);
+ else {
+ SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
+ SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 2, 0);
}
+}
+
+void CProgressPageDlg::AddMessage(const wchar_t *pMsg)
+{
+ m_list.SendMsg(LB_SETTOPINDEX, m_list.AddString(pMsg, 0), 0);
+}
- return CWizardPageDlg::DlgProc(uMsg, wParam, lParam);
+void CProgressPageDlg::SetProgress(int n)
+{
+ SendDlgItemMessage(m_hwnd, IDC_PROGRESS, PBM_SETPOS, n, 0);
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void AddMessage(const wchar_t *fmt, ...)
+{
+ va_list args;
+ wchar_t msgBuf[4096];
+ va_start(args, fmt);
+ mir_vsnwprintf(msgBuf, TranslateW(fmt), args);
+
+ if (pDlg)
+ pDlg->AddMessage(msgBuf);
+}
+
+void SetProgress(int n)
+{
+ if (pDlg)
+ pDlg->SetProgress(n);
+}
+
diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h
index 4aed993c33..06c0454843 100644
--- a/plugins/Import/src/stdafx.h
+++ b/plugins/Import/src/stdafx.h
@@ -74,10 +74,6 @@ struct CMPlugin : public PLUGIN<CMPlugin>
#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;
@@ -93,8 +89,9 @@ public:
void onClick_Cancel(CCtrlButton*) { OnCancel(); }
};
-void AddMessage(const wchar_t* fmt, ...);
+void AddMessage(const wchar_t* fmt, ...);
LRESULT RunWizard(CWizardPageDlg*, bool bModal);
+void SetProgress(int);
class CIntroPageDlg : public CWizardPageDlg
{
@@ -107,12 +104,20 @@ public:
class CProgressPageDlg : public CWizardPageDlg
{
+ CCtrlListBox m_list;
+ CTimer m_timer;
+
public:
CProgressPageDlg();
bool OnInitDialog() override;
+ void OnDestroy() override;
void OnNext() override;
- INT_PTR DlgProc(UINT, WPARAM, LPARAM) override;
+
+ void OnTimer(CTimer*);
+
+ void AddMessage(const wchar_t *pMsg);
+ void SetProgress(int);
};
class CMirandaPageDlg : public CWizardPageDlg
@@ -120,7 +125,7 @@ class CMirandaPageDlg : public CWizardPageDlg
void SearchForLists(const wchar_t *mirandaPath, const wchar_t *mirandaProf);
CCtrlButton btnBack, btnOther;
- CCtrlListBox list;
+ CCtrlListBox m_list;
public:
CMirandaPageDlg();