summaryrefslogtreecommitdiff
path: root/plugins/Import/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-08-15 14:31:56 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-08-15 14:31:56 +0300
commit0026f0f655e1bb5a39a81f56ed40672926208290 (patch)
tree55aca31c0364b152a7b93553fdd656f4750fb9b2 /plugins/Import/src
parentee57c7fe7f30f82a2a2c637125ce3ee31d008576 (diff)
Import: ability to check duplicates during a contact import
Diffstat (limited to 'plugins/Import/src')
-rw-r--r--plugins/Import/src/import.cpp2
-rw-r--r--plugins/Import/src/main.cpp18
-rw-r--r--plugins/Import/src/miranda.cpp4
-rw-r--r--plugins/Import/src/resource.h9
-rw-r--r--plugins/Import/src/stdafx.h23
-rw-r--r--plugins/Import/src/ui.cpp77
6 files changed, 113 insertions, 20 deletions
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp
index c5392401f7..87fc1364da 100644
--- a/plugins/Import/src/import.cpp
+++ b/plugins/Import/src/import.cpp
@@ -977,7 +977,7 @@ static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoC
continue;
// check for duplicate entries
- if ((g_iImportOptions & IOPT_COMPLETE) != IOPT_COMPLETE && IsDuplicateEvent(hDst, dbei)) {
+ if ((g_iImportOptions & IOPT_CHECKDUPS) != 0 && IsDuplicateEvent(hDst, dbei)) {
nDupes++;
continue;
}
diff --git a/plugins/Import/src/main.cpp b/plugins/Import/src/main.cpp
index baeaad4e9a..0cf5f42e70 100644
--- a/plugins/Import/src/main.cpp
+++ b/plugins/Import/src/main.cpp
@@ -97,7 +97,7 @@ static INT_PTR ServiceMode(WPARAM, LPARAM)
ptrW wszFullName(Utils_ReplaceVarsW(L"%miranda_userdata%\\%miranda_profilename%.dat.bak"));
if (!_waccess(wszFullName, 0)) {
- g_iImportOptions = IOPT_ADDUNKNOWN + IOPT_COMPLETE;
+ g_iImportOptions = IOPT_ADDUNKNOWN + IOPT_COMPLETE + IOPT_CHECKDUPS;
wcsncpy_s(importFile, MAX_PATH, wszFullName, _TRUNCATE);
WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
@@ -125,22 +125,12 @@ static INT_PTR CustomImport(WPARAM wParam, LPARAM)
static INT_PTR ImportContact(WPARAM hContact, LPARAM)
{
- CMStringW text(FORMAT, 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.lpstrFilter = text;
- ofn.lpstrDefExt = L"dat";
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT;
- ofn.lpstrFile = importFile;
- ofn.nMaxFile = _countof(importFile);
- if (!GetOpenFileName(&ofn)) {
- importFile[0] = 0;
+ CContactImportDlg dlg(hContact);
+ if (!dlg.DoModal())
return 0;
- }
g_hImportContact = hContact;
- g_iImportOptions = IOPT_HISTORY;
+ g_iImportOptions = IOPT_HISTORY + dlg.getFlags();
WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
return DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, LPARAM(&param));
diff --git a/plugins/Import/src/miranda.cpp b/plugins/Import/src/miranda.cpp
index ade3faf5bd..6d646f8077 100644
--- a/plugins/Import/src/miranda.cpp
+++ b/plugins/Import/src/miranda.cpp
@@ -182,13 +182,13 @@ INT_PTR CALLBACK MirandaOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wPara
case IDOK:
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_COMPLETE)) {
- g_iImportOptions = INT32_MAX;
+ 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;
+ g_iImportOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS | IOPT_CHECKDUPS;
PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
break;
}
diff --git a/plugins/Import/src/resource.h b/plugins/Import/src/resource.h
index 1120c1a773..7857ea0834 100644
--- a/plugins/Import/src/resource.h
+++ b/plugins/Import/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by D:\miranda-ng\plugins\Import\res\resource.rc
+// Used by w:\miranda-ng\plugins\Import\res\resource.rc
//
#define IDC_BACK 3
#define IDD_WIZARD 101
@@ -10,6 +10,7 @@
#define IDD_WIZARDINTRO 107
#define IDD_FINISHED 108
#define IDD_MIRABILISDB 109
+#define IDD_IMPORT_CONTACT 109
#define IDD_MIRANDADB 110
#define IDD_PROGRESS 111
#define IDD_ADVOPTIONS 112
@@ -48,15 +49,17 @@
#define IDC_URL 1039
#define IDC_FILE 1040
#define IDC_FT 1040
+#define IDC_OPEN_FILE 1042
+#define IDC_CHECK_DUPS 1043
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 106
+#define _APS_NEXT_RESOURCE_VALUE 111
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1041
+#define _APS_NEXT_CONTROL_VALUE 1044
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h
index fd7b541507..7a19fd8cf5 100644
--- a/plugins/Import/src/stdafx.h
+++ b/plugins/Import/src/stdafx.h
@@ -43,6 +43,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_db_int.h>
#include <m_metacontacts.h>
#include <m_import.h>
+#include <m_gui.h>
#include "version.h"
#include "resource.h"
@@ -108,3 +109,25 @@ void RegisterIcons(void);
void RegisterMContacts();
void RegisterJson();
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+class CContactImportDlg : public CDlgBase
+{
+ MCONTACT m_hContact;
+ int m_flags;
+
+ CCtrlButton m_btnOpenFile, m_btnOk;
+ CCtrlEdit edtFileName;
+
+public:
+ CContactImportDlg(MCONTACT hContact);
+
+ int getFlags() const { return m_flags; }
+
+ bool OnInitDialog() override;
+ bool OnApply() override;
+
+ void onClick_Ok(CCtrlButton*);
+ void onClick_OpenFile(CCtrlButton*);
+};
diff --git a/plugins/Import/src/ui.cpp b/plugins/Import/src/ui.cpp
new file mode 100644
index 0000000000..a55fb1822d
--- /dev/null
+++ b/plugins/Import/src/ui.cpp
@@ -0,0 +1,77 @@
+/*
+
+Import plugin for Miranda NG
+
+Copyright (c) 2012-18 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"
+
+CContactImportDlg::CContactImportDlg(MCONTACT hContact) :
+ CDlgBase(g_plugin, IDD_IMPORT_CONTACT),
+ m_hContact(hContact),
+ edtFileName(this, IDC_FILENAME),
+ m_btnOk(this, IDOK),
+ m_btnOpenFile(this, IDC_OPEN_FILE)
+{
+ m_btnOk.OnClick = Callback(this, &CContactImportDlg::onClick_Ok);
+ m_btnOpenFile.OnClick = Callback(this, &CContactImportDlg::onClick_OpenFile);
+}
+
+bool CContactImportDlg::OnInitDialog()
+{
+ CMStringW wszTitle(FORMAT, L"%s %s", TranslateT("Import history for"), Clist_GetContactDisplayName(m_hContact));
+ SetWindowTextW(m_hwnd, wszTitle);
+ return true;
+}
+
+bool CContactImportDlg::OnApply()
+{
+ edtFileName.GetText(importFile, _countof(importFile));
+ if (importFile[0] == 0)
+ return false;
+
+ if (IsDlgButtonChecked(m_hwnd, IDC_CHECK_DUPS))
+ m_flags = IOPT_CHECKDUPS;
+ return true;
+}
+
+void CContactImportDlg::onClick_Ok(CCtrlButton*)
+{
+ EndModal(1);
+}
+
+void CContactImportDlg::onClick_OpenFile(CCtrlButton*)
+{
+ CMStringW text;
+ text.AppendFormat(L"%s (*.dat,*.bak)%c*.dat;*.bak%c", TranslateT("Miranda NG database"), 0, 0);
+ text.AppendFormat(L"%s (*.json)%c*.json%c", TranslateT("JSON file"), 0, 0);
+ 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 = importFile;
+ ofn.nMaxFile = _countof(importFile);
+ if (!GetOpenFileName(&ofn))
+ importFile[0] = 0;
+ else
+ edtFileName.SetText(importFile);
+} \ No newline at end of file