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
128
129
130
131
132
133
134
135
136
137
|
/*
Import plugin for Miranda NG
Copyright (C) 2012-20 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
class CContactImportDlg : public CDlgBase
{
friend INT_PTR ImportContact(WPARAM hContact, LPARAM);
MCONTACT m_hContact;
int m_flags = 0;
CImportPattern *m_pPattern = 0;
wchar_t m_wszFileName[MAX_PATH];
CCtrlButton m_btnOpenFile, m_btnOk;
CCtrlCombo m_cmbFileType;
CCtrlEdit edtFileName;
public:
CContactImportDlg(MCONTACT hContact) :
CDlgBase(g_plugin, IDD_IMPORT_CONTACT),
m_hContact(hContact),
edtFileName(this, IDC_FILENAME),
m_cmbFileType(this, IDC_FILETYPE),
m_btnOk(this, IDOK),
m_btnOpenFile(this, IDC_OPEN_FILE)
{
m_wszFileName[0] = 0;
m_btnOk.OnClick = Callback(this, &CContactImportDlg::onClick_Ok);
m_btnOpenFile.OnClick = Callback(this, &CContactImportDlg::onClick_OpenFile);
}
bool OnInitDialog() override
{
CMStringW wszTitle(FORMAT, TranslateT("Import history for %s"), Clist_GetContactDisplayName(m_hContact));
SetWindowTextW(m_hwnd, wszTitle);
m_cmbFileType.AddString(TranslateT("Miranda NG database/mContacts"), -1);
m_cmbFileType.AddString(TranslateT("JSON file"), -2);
int iType = 1;
for (auto &it : g_plugin.m_patterns)
m_cmbFileType.AddString(it->wszName, iType++);
return true;
}
bool OnApply() override
{
edtFileName.GetText(m_wszFileName, _countof(m_wszFileName));
if (m_wszFileName[0] == 0)
return false;
if (IsDlgButtonChecked(m_hwnd, IDC_CHECK_DUPS))
m_flags = IOPT_CHECKDUPS;
return true;
}
void onClick_Ok(CCtrlButton*)
{
EndModal(1);
}
void onClick_OpenFile(CCtrlButton*)
{
int iCur = m_cmbFileType.GetCurSel();
if (iCur == -1)
return;
CMStringW text, cmbText(ptrW(m_cmbFileType.GetText()));
switch(int idx = m_cmbFileType.GetItemData(iCur)) {
case -1:
text.AppendFormat(L"%s (*.dat,*.bak)%c*.dat;*.bak%c", cmbText.c_str(), 0, 0);
m_pPattern = nullptr;
break;
case -2:
text.AppendFormat(L"%s (*.json)%c*.json%c", cmbText.c_str(), 0, 0);
m_pPattern = nullptr;
break;
default:
auto &p = g_plugin.m_patterns[idx-1];
text.AppendFormat(L"%s (*.%s)%c*.%s%c", cmbText.c_str(), p.wszExt.c_str(), 0, p.wszExt.c_str(), 0);
m_pPattern = &p;
break;
}
text.AppendFormat(L"%s (*.*)%c*.*%c%c", TranslateT("All Files"), 0, 0, 0);
OPENFILENAME ofn = { 0 };
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
ofn.lpstrFilter = text;
ofn.lpstrDefExt = L"dat";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT;
ofn.lpstrFile = m_wszFileName;
ofn.nMaxFile = _countof(m_wszFileName);
if (!GetOpenFileNameW(&ofn)) {
m_wszFileName[0] = 0;
m_pPattern = nullptr;
}
else edtFileName.SetText(m_wszFileName);
}
};
INT_PTR ImportContact(WPARAM hContact, LPARAM)
{
CContactImportDlg dlg(hContact);
if (!dlg.DoModal())
return 0;
g_pBatch = new CImportBatch();
wcsncpy_s(g_pBatch->m_wszFileName, dlg.m_wszFileName, _TRUNCATE);
g_pBatch->m_pPattern = dlg.m_pPattern;
g_pBatch->m_hContact = hContact;
g_pBatch->m_iOptions = IOPT_HISTORY + dlg.m_flags;
return RunWizard(new CProgressPageDlg(), true);
}
|