diff options
author | George Hazan <ghazan@miranda.im> | 2018-06-08 12:50:51 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-06-08 12:50:51 +0300 |
commit | 123fd0d76251f073360e790eee3c8335cd8fdb31 (patch) | |
tree | 2ff2e68881753bc1832787b64caa53bbcaae07e6 /plugins/Import/src | |
parent | e3a92da4b82e687e60478c09572197e1db13012f (diff) |
Import:
- first working version of mcontacts import;
- code cleaning
Diffstat (limited to 'plugins/Import/src')
-rw-r--r-- | plugins/Import/src/import.cpp | 31 | ||||
-rw-r--r-- | plugins/Import/src/main.cpp | 61 | ||||
-rw-r--r-- | plugins/Import/src/mcontacts.cpp | 4 | ||||
-rw-r--r-- | plugins/Import/src/miranda.cpp | 30 | ||||
-rw-r--r-- | plugins/Import/src/progress.cpp | 2 | ||||
-rw-r--r-- | plugins/Import/src/stdafx.h | 14 | ||||
-rw-r--r-- | plugins/Import/src/wizard.cpp | 4 |
7 files changed, 92 insertions, 54 deletions
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index bbc55b940c..865e30cc7b 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -287,7 +287,7 @@ static INT_PTR CALLBACK AccountsMatcherProc(HWND hwndDlg, UINT uMsg, WPARAM wPar switch (uMsg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
- hwndAccMerge = hwndDlg;
+ g_hwndAccMerge = hwndDlg;
hwndList = GetDlgItem(hwndDlg, IDC_LIST);
{
LVCOLUMN col = { 0 };
@@ -338,7 +338,7 @@ static INT_PTR CALLBACK AccountsMatcherProc(HWND hwndDlg, UINT uMsg, WPARAM wPar break;
case WM_DESTROY:
- hwndAccMerge = nullptr;
+ g_hwndAccMerge = nullptr;
break;
case WM_NOTIFY:
@@ -466,7 +466,7 @@ bool ImportAccounts(OBJLIST<char> &arSkippedModules) if (DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ACCMERGE), nullptr, AccountsMatcherProc) != IDOK)
return false;
- bool bImportSysAll = (nImportOptions & IOPT_SYS_SETTINGS) != 0;
+ bool bImportSysAll = (g_iImportOptions & IOPT_SYS_SETTINGS) != 0;
LIST<AccountMap> arIndexedMap(arAccountMap.getCount(), CompareAccByIds);
for (auto &it : arAccountMap)
@@ -532,6 +532,9 @@ bool ImportAccounts(OBJLIST<char> &arSkippedModules) static MCONTACT MapContact(MCONTACT hSrc)
{
+ if (g_hImportContact != 0 && hSrc == 1)
+ return g_hImportContact;
+
ContactMap *pDestContact = arContactMap.find((ContactMap*)&hSrc);
return (pDestContact == nullptr) ? INVALID_CONTACT_ID : pDestContact->dstID;
}
@@ -945,24 +948,24 @@ static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoC bSkipThis = 1;
switch (dbei.eventType) {
case EVENTTYPE_MESSAGE:
- if ((bIsSent ? IOPT_MSGSENT : IOPT_MSGRECV) & nImportOptions)
+ if ((bIsSent ? IOPT_MSGSENT : IOPT_MSGRECV) & g_iImportOptions)
bSkipThis = false;
break;
case EVENTTYPE_FILE:
- if ((bIsSent ? IOPT_FILESENT : IOPT_FILERECV) & nImportOptions)
+ if ((bIsSent ? IOPT_FILESENT : IOPT_FILERECV) & g_iImportOptions)
bSkipThis = false;
break;
case EVENTTYPE_URL:
- if ((bIsSent ? IOPT_URLSENT : IOPT_URLRECV) & nImportOptions)
+ if ((bIsSent ? IOPT_URLSENT : IOPT_URLRECV) & g_iImportOptions)
bSkipThis = false;
break;
default:
- if ((bIsSent ? IOPT_OTHERSENT : IOPT_OTHERRECV) & nImportOptions)
+ if ((bIsSent ? IOPT_OTHERSENT : IOPT_OTHERRECV) & g_iImportOptions)
bSkipThis = false;
break;
}
}
- else if (!(nImportOptions & IOPT_SYSTEM))
+ else if (!(g_iImportOptions & IOPT_SYSTEM))
bSkipThis = true;
}
@@ -974,7 +977,7 @@ static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoC continue;
// check for duplicate entries
- if ((nImportOptions & IOPT_COMPLETE) != IOPT_COMPLETE && IsDuplicateEvent(hDst, dbei)) {
+ if ((g_iImportOptions & IOPT_COMPLETE) != IOPT_COMPLETE && IsDuplicateEvent(hDst, dbei)) {
nDupes++;
continue;
}
@@ -1064,12 +1067,12 @@ void MirandaImport(HWND hdlg) }
// copy system settings if needed
- if (nImportOptions & IOPT_SYS_SETTINGS)
+ if (g_iImportOptions & IOPT_SYS_SETTINGS)
srcDb->EnumModuleNames(CopySystemSettings, &arSkippedAccs);
arSkippedAccs.destroy();
// Import Groups
- if (nImportOptions & IOPT_GROUPS) {
+ if (g_iImportOptions & IOPT_GROUPS) {
AddMessage(LPGENW("Importing groups."));
nGroupsCount = ImportGroups();
if (nGroupsCount == -1)
@@ -1080,7 +1083,7 @@ void MirandaImport(HWND hdlg) // End of Import Groups
// Import Contacts
- if (nImportOptions & IOPT_CONTACTS) {
+ if (g_iImportOptions & IOPT_CONTACTS) {
AddMessage(LPGENW("Importing contacts."));
int i = 1;
MCONTACT hContact = srcDb->FindFirstContact();
@@ -1110,7 +1113,7 @@ void MirandaImport(HWND hdlg) // End of Import Contacts
// Import NULL contact message chain
- if (nImportOptions & IOPT_SYSTEM) {
+ if (g_iImportOptions & IOPT_SYSTEM) {
AddMessage(LPGENW("Importing system history."));
int protoCount;
@@ -1124,7 +1127,7 @@ void MirandaImport(HWND hdlg) AddMessage(L"");
// Import other contact messages
- if (nImportOptions & IOPT_HISTORY) {
+ if (g_iImportOptions & IOPT_HISTORY) {
AddMessage(LPGENW("Importing history."));
MCONTACT hContact = srcDb->FindFirstContact();
for (int i = 1; hContact != NULL; i++) {
diff --git a/plugins/Import/src/main.cpp b/plugins/Import/src/main.cpp index 5bb1a2f5f4..ecafcc9d01 100644 --- a/plugins/Import/src/main.cpp +++ b/plugins/Import/src/main.cpp @@ -22,12 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-int nImportOptions;
-
-INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam);
+int g_iImportOptions;
+MCONTACT g_hImportContact;
bool g_bServiceMode = false, g_bSendQuit = false;
-HWND hwndWizard, hwndAccMerge;
+HWND g_hwndWizard, g_hwndAccMerge;
+
CMPlugin g_plugin;
/////////////////////////////////////////////////////////////////////////////////////////
@@ -65,13 +65,17 @@ static int ModulesLoaded(WPARAM, LPARAM) mi.hIcolibItem = GetIconHandle(IDI_IMPORT);
mi.name.a = LPGEN("&Import...");
mi.position = 500050000;
- mi.pszService = IMPORT_SERVICE;
+ mi.pszService = MS_IMPORT_SERVICE;
Menu_AddMainMenuItem(&mi);
+ SET_UID(mi, 0x4D237903, 0x24F1, 0x41AD, 0x82, 0xeb, 0x8f, 0xff, 0xb7, 0x3c, 0x28, 0xcc);
+ mi.pszService = MS_IMPORT_CONTACT;
+ Menu_AddContactMenuItem(&mi);
+
if (!db_get_b(NULL, IMPORT_MODULE, IMP_KEY_FR, 0)) {
// Only autorun import wizard if at least one protocol is installed
if (Accounts().getCount() > 0) {
- CallService(IMPORT_SERVICE, 0, 0);
+ CallService(MS_IMPORT_SERVICE, 0, 0);
db_set_b(NULL, IMPORT_MODULE, IMP_KEY_FR, 1);
}
}
@@ -80,10 +84,10 @@ static int ModulesLoaded(WPARAM, LPARAM) static int OnExit(WPARAM, LPARAM)
{
- if (hwndWizard)
- SendMessage(hwndWizard, WM_CLOSE, 0, 0);
- if (hwndAccMerge)
- SendMessage(hwndAccMerge, WM_CLOSE, 0, 0);
+ if (g_hwndWizard)
+ SendMessage(g_hwndWizard, WM_CLOSE, 0, 0);
+ if (g_hwndAccMerge)
+ SendMessage(g_hwndAccMerge, WM_CLOSE, 0, 0);
return 0;
}
@@ -93,7 +97,7 @@ static INT_PTR ServiceMode(WPARAM, LPARAM) ptrW wszFullName(Utils_ReplaceVarsW(L"%miranda_userdata%\\%miranda_profilename%.dat.bak"));
if (!_waccess(wszFullName, 0)) {
- nImportOptions = IOPT_ADDUNKNOWN + IOPT_COMPLETE;
+ g_iImportOptions = IOPT_ADDUNKNOWN + IOPT_COMPLETE;
wcsncpy_s(importFile, MAX_PATH, wszFullName, _TRUNCATE);
WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
@@ -112,7 +116,31 @@ static INT_PTR CustomImport(WPARAM wParam, LPARAM) {
MImportOptions *opts = (MImportOptions*)wParam;
wcsncpy_s(importFile, MAX_PATH, opts->pwszFileName, _TRUNCATE);
- nImportOptions = opts->dwFlags;
+ g_iImportOptions = opts->dwFlags;
+ g_hImportContact = 0;
+
+ WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
+ return DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, LPARAM(¶m));
+}
+
+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;
+ return 0;
+ }
+
+ g_hImportContact = hContact;
+ g_iImportOptions = IOPT_HISTORY;
WizardDlgParam param = { IDD_PROGRESS, (LPARAM)ProgressPageProc };
return DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WIZARD), nullptr, WizardDlgProc, LPARAM(¶m));
@@ -120,9 +148,9 @@ static INT_PTR CustomImport(WPARAM wParam, LPARAM) static INT_PTR ImportCommand(WPARAM, LPARAM)
{
- if (IsWindow(hwndWizard)) {
- SetForegroundWindow(hwndWizard);
- SetFocus(hwndWizard);
+ if (IsWindow(g_hwndWizard)) {
+ SetForegroundWindow(g_hwndWizard);
+ SetFocus(g_hwndWizard);
}
else {
WizardDlgParam param = { IDD_WIZARDINTRO, (LPARAM)WizardIntroPageProc };
@@ -134,7 +162,8 @@ static INT_PTR ImportCommand(WPARAM, LPARAM) int CMPlugin::Load()
{
- CreateServiceFunction(IMPORT_SERVICE, ImportCommand);
+ CreateServiceFunction(MS_IMPORT_CONTACT, ImportContact);
+ CreateServiceFunction(MS_IMPORT_SERVICE, ImportCommand);
CreateServiceFunction(MS_SERVICEMODE_LAUNCH, ServiceMode);
CreateServiceFunction(MS_IMPORT_RUN, CustomImport);
RegisterIcons();
diff --git a/plugins/Import/src/mcontacts.cpp b/plugins/Import/src/mcontacts.cpp index a7bea6ecf1..2e33a47d9b 100644 --- a/plugins/Import/src/mcontacts.cpp +++ b/plugins/Import/src/mcontacts.cpp @@ -94,8 +94,10 @@ public: void Load() { - MC_MsgHeader hdr; + // mcontacts operates with the only contact with pseudo id=1 + m_cache->AddContactToCache(1); + MC_MsgHeader hdr; for (uint32_t pos = 0; pos < m_hdr.dataSize; pos += sizeof(hdr)) { DWORD dwPos = SetFilePointer(m_hFile, 0, 0, FILE_CURRENT), dwRead; BOOL r = ReadFile(m_hFile, &hdr, sizeof(hdr), &dwRead, 0); diff --git a/plugins/Import/src/miranda.cpp b/plugins/Import/src/miranda.cpp index 977b62652f..ade3faf5bd 100644 --- a/plugins/Import/src/miranda.cpp +++ b/plugins/Import/src/miranda.cpp @@ -182,19 +182,19 @@ INT_PTR CALLBACK MirandaOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wPara case IDOK:
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_COMPLETE)) {
- nImportOptions = INT32_MAX;
+ g_iImportOptions = INT32_MAX;
PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
break;
}
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ALL)) {
- nImportOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS;
+ g_iImportOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS;
PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
break;
}
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_CONTACTS)) {
- nImportOptions = IOPT_CONTACTS;
+ g_iImportOptions = IOPT_CONTACTS;
PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
break;
}
@@ -246,32 +246,32 @@ INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wP break;
case IDOK:
- nImportOptions = 0;
+ g_iImportOptions = 0;
if (IsDlgButtonChecked(hwndDlg, IDC_CONTACTS))
- nImportOptions |= IOPT_CONTACTS | IOPT_GROUPS;
+ g_iImportOptions |= IOPT_CONTACTS | IOPT_GROUPS;
if (IsDlgButtonChecked(hwndDlg, IDC_SYSTEM))
- nImportOptions |= IOPT_SYSTEM;
+ g_iImportOptions |= IOPT_SYSTEM;
// incoming
if (IsDlgButtonChecked(hwndDlg, IDC_IN_MSG))
- nImportOptions |= IOPT_MSGRECV;
+ g_iImportOptions |= IOPT_MSGRECV;
if (IsDlgButtonChecked(hwndDlg, IDC_IN_URL))
- nImportOptions |= IOPT_URLRECV;
+ g_iImportOptions |= IOPT_URLRECV;
if (IsDlgButtonChecked(hwndDlg, IDC_IN_FT))
- nImportOptions |= IOPT_FILERECV;
+ g_iImportOptions |= IOPT_FILERECV;
if (IsDlgButtonChecked(hwndDlg, IDC_IN_OTHER))
- nImportOptions |= IOPT_OTHERRECV;
+ g_iImportOptions |= IOPT_OTHERRECV;
// outgoing
if (IsDlgButtonChecked(hwndDlg, IDC_OUT_MSG))
- nImportOptions |= IOPT_MSGSENT;
+ g_iImportOptions |= IOPT_MSGSENT;
if (IsDlgButtonChecked(hwndDlg, IDC_OUT_URL))
- nImportOptions |= IOPT_URLSENT;
+ g_iImportOptions |= IOPT_URLSENT;
if (IsDlgButtonChecked(hwndDlg, IDC_OUT_FT))
- nImportOptions |= IOPT_FILESENT;
+ g_iImportOptions |= IOPT_FILESENT;
if (IsDlgButtonChecked(hwndDlg, IDC_OUT_OTHER))
- nImportOptions |= IOPT_OTHERSENT;
+ g_iImportOptions |= IOPT_OTHERSENT;
// since date
dwSinceDate = 0;
@@ -292,7 +292,7 @@ INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wP }
}
- if (nImportOptions)
+ if (g_iImportOptions)
PostMessage(GetParent(hwndDlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc);
break;
diff --git a/plugins/Import/src/progress.cpp b/plugins/Import/src/progress.cpp index 26708529c4..23e357b824 100644 --- a/plugins/Import/src/progress.cpp +++ b/plugins/Import/src/progress.cpp @@ -52,7 +52,7 @@ INT_PTR CALLBACK ProgressPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM case PROGM_START:
MirandaImport(hdlg);
if (g_bServiceMode && !g_bSendQuit)
- DestroyWindow(hwndWizard);
+ DestroyWindow(g_hwndWizard);
else {
SendMessage(GetParent(hdlg), WIZM_ENABLEBUTTON, 1, 0);
SendMessage(GetParent(hdlg), WIZM_ENABLEBUTTON, 2, 0);
diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h index a171890822..4ded15ce5f 100644 --- a/plugins/Import/src/stdafx.h +++ b/plugins/Import/src/stdafx.h @@ -51,8 +51,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Global constants
-#define IMPORT_MODULE "MIMImport" // Module name
-#define IMPORT_SERVICE "MIMImport/Import" // Service for menu item
+#define IMPORT_MODULE "MIMImport"
+
+#define MS_IMPORT_SERVICE "MIMImport/Import" // Service for main menu item
+#define MS_IMPORT_CONTACT "MIMImport/ImportContact" // Service for contact menu item
struct CMPlugin : public PLUGIN<CMPlugin>
{
@@ -80,6 +82,7 @@ struct WizardDlgParam LPARAM lParam;
};
+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);
@@ -91,11 +94,12 @@ bool IsDuplicateEvent(MCONTACT hContact, DBEVENTINFO dbei); int CreateGroup(const wchar_t *name, MCONTACT hContact);
-extern HWND hwndWizard, hwndAccMerge;
-extern int nImportOptions;
-extern wchar_t importFile[];
+extern HWND g_hwndWizard, g_hwndAccMerge;
+extern wchar_t importFile[MAX_PATH];
extern time_t dwSinceDate;
extern bool g_bServiceMode, g_bSendQuit;
+extern int g_iImportOptions;
+extern MCONTACT g_hImportContact;
HANDLE GetIconHandle(int iIconId);
void RegisterIcons(void);
diff --git a/plugins/Import/src/wizard.cpp b/plugins/Import/src/wizard.cpp index 7849b9292d..9f1bed8b05 100644 --- a/plugins/Import/src/wizard.cpp +++ b/plugins/Import/src/wizard.cpp @@ -97,7 +97,7 @@ INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lP case WM_INITDIALOG:
TranslateDialogDefault(hdlg);
Window_SetIcon_IcoLib(hdlg, GetIconHandle(IDI_IMPORT));
- hwndWizard = hdlg;
+ g_hwndWizard = hdlg;
{
WizardDlgParam *param = (WizardDlgParam*)lParam;
if (param)
@@ -165,7 +165,7 @@ INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lP break;
case WM_DESTROY:
- hwndWizard = hwndPage = nullptr;
+ g_hwndWizard = hwndPage = nullptr;
if (g_bSendQuit)
PostQuitMessage(0);
}
|