summaryrefslogtreecommitdiff
path: root/plugins/Import
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
parentee57c7fe7f30f82a2a2c637125ce3ee31d008576 (diff)
Import: ability to check duplicates during a contact import
Diffstat (limited to 'plugins/Import')
-rw-r--r--plugins/Import/res/resource.rc61
-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
7 files changed, 174 insertions, 20 deletions
diff --git a/plugins/Import/res/resource.rc b/plugins/Import/res/resource.rc
index fb7431839f..455f201930 100644
--- a/plugins/Import/res/resource.rc
+++ b/plugins/Import/res/resource.rc
@@ -232,6 +232,66 @@ END
/////////////////////////////////////////////////////////////////////////////
+// Russian (Russia) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
+LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
+#pragma code_page(1251)
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_IMPORT_CONTACT DIALOGEX 0, 0, 361, 76
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_APPWINDOW
+CAPTION "Dialog"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,247,55,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,304,55,50,14
+ EDITTEXT IDC_FILENAME,7,23,321,15,ES_AUTOHSCROLL
+ LTEXT "Enter file name for import:",IDC_STATIC,8,10,322,8
+ PUSHBUTTON "...",IDC_OPEN_FILE,332,23,21,15,0,WS_EX_STATICEDGE
+ CONTROL "Check duplicates",IDC_CHECK_DUPS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,44,316,9
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_IMPORT_CONTACT, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 354
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 69
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// AFX_DIALOG_LAYOUT
+//
+
+IDD_IMPORT_CONTACT AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
+#endif // Russian (Russia) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
// English (United Kingdom) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
@@ -272,6 +332,7 @@ END
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_IMPORT ICON "import.ico"
+
#endif // English (United Kingdom) resources
/////////////////////////////////////////////////////////////////////////////
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