diff options
author | George Hazan <george.hazan@gmail.com> | 2014-09-29 15:02:04 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-09-29 15:02:04 +0000 |
commit | 8f994ff592a5501018ba601d33d59a558a2d9840 (patch) | |
tree | f46da86837a043aee22a3904faeae8c4f389c164 /plugins | |
parent | 425f0a62cef32018fb858f83d713be07c08fccc7 (diff) |
first version of metaimport, that seems to work
git-svn-id: http://svn.miranda-ng.org/main/trunk@10631 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Import/src/import.cpp | 174 | ||||
-rw-r--r-- | plugins/Import/src/miranda.cpp | 17 |
2 files changed, 123 insertions, 68 deletions
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index d0bb4d6a2f..3626aaacda 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -291,6 +291,12 @@ void ImportAccounts() /////////////////////////////////////////////////////////////////////////////////////////
+static MCONTACT MapContact(MCONTACT hSrc)
+{
+ ContactMap *pDestContact = arContactMap.find((ContactMap*)&hSrc);
+ return (pDestContact == NULL) ? INVALID_CONTACT_ID : pDestContact->dstID;
+}
+
static MCONTACT AddContact(HWND hdlgProgress, char* szProto, char* pszUniqueSetting, DBVARIANT* id, const TCHAR* pszUserID, TCHAR *nick, TCHAR *group)
{
MCONTACT hContact = CallService(MS_DB_CONTACT_ADD, 0, 0);
@@ -314,6 +320,58 @@ static MCONTACT AddContact(HWND hdlgProgress, char* szProto, char* pszUniqueSett return hContact;
}
+void ImportContactSettings(AccountMap *pda, MCONTACT hSrc, MCONTACT hDst)
+{
+ // Hidden?
+ DBVARIANT dbv;
+ if (!myGet(hSrc, "CList", "Hidden", &dbv)) {
+ db_set(hDst, "CList", "Hidden", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+
+ // Ignore settings
+ if (!myGet(hSrc, "Ignore", "Mask1", &dbv)) {
+ db_set(hDst, "Ignore", "Mask1", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+
+ // Apparent mode
+ if (!myGet(hSrc, pda->szSrcAcc, "ApparentMode", &dbv)) {
+ db_set(hDst, pda->szDstAcc, "ApparentMode", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+
+ // Nick
+ if (!myGet(hSrc, pda->szSrcAcc, "Nick", &dbv)) {
+ db_set(hDst, pda->szDstAcc, "Nick", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+
+ // Myhandle
+ if (!myGet(hSrc, pda->szSrcAcc, "MyHandle", &dbv)) {
+ db_set(hDst, pda->szDstAcc, "MyHandle", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+
+ // First name
+ if (!myGet(hSrc, pda->szSrcAcc, "FirstName", &dbv)) {
+ db_set(hDst, pda->szDstAcc, "FirstName", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+
+ // Last name
+ if (!myGet(hSrc, pda->szSrcAcc, "LastName", &dbv)) {
+ db_set(hDst, pda->szDstAcc, "LastName", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+
+ // About
+ if (!myGet(hSrc, pda->szSrcAcc, "About", &dbv)) {
+ db_set(hDst, pda->szDstAcc, "About", &dbv);
+ srcDb->FreeVariant(&dbv);
+ }
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
static int ImportGroup(const char* szSettingName, LPARAM lParam)
@@ -343,9 +401,59 @@ static int ImportGroups() /////////////////////////////////////////////////////////////////////////////////////////
+DBCachedContact* FindDestMeta(DBCachedContact *ccSrc)
+{
+ for (MCONTACT hMeta = dstDb->FindFirstContact(META_PROTO); hMeta != 0; hMeta = dstDb->FindNextContact(hMeta, META_PROTO)) {
+ DBCachedContact *cc = dstDb->m_cache->GetCachedContact(hMeta);
+ if (cc->nSubs != ccSrc->nSubs)
+ continue;
+
+ int i;
+ for (i = 0; i < ccSrc->nSubs; i++) {
+ MCONTACT hDest = MapContact(ccSrc->pSubs[i]);
+ if (hDest == INVALID_CONTACT_ID || ccSrc->pSubs[i] != hDest)
+ break;
+ }
+
+ if (i == ccSrc->nSubs)
+ return cc;
+ }
+
+ return NULL;
+}
+
void ImportMeta(DBCachedContact *cc)
{
+ MCONTACT hDest;
+
+ DBCachedContact *ccDst = FindDestMeta(cc);
+ if (ccDst == NULL) {
+ hDest = CallService(MS_DB_CONTACT_ADD, 0, 0);
+ CallService(MS_PROTO_ADDTOCONTACT, hDest, (LPARAM)META_PROTO);
+
+ ptrT tszGroup(myGetWs(cc->contactID, "CList", "Group")), tszNick(myGetWs(cc->contactID, "CList", "MyHandle"));
+ if (tszNick == NULL)
+ tszNick = myGetWs(cc->contactID, cc->szProto, "Nick");
+
+ CreateGroup(tszGroup, hDest);
+
+ if (tszNick && *tszNick) {
+ db_set_ws(hDest, "CList", "MyHandle", tszNick);
+ AddMessage(LPGENT("Added metacontact '%s'"), tszNick);
+ }
+ else AddMessage(LPGENT("Added metacontact"));
+ CopySettings(cc->contactID, META_PROTO, hDest, META_PROTO);
+ for (int i = 0; i < cc->nSubs; i++) {
+ char szSettingName[100];
+ mir_snprintf(szSettingName, SIZEOF(szSettingName), "Handle%d", i);
+ db_set_dw(hDest, META_PROTO, szSettingName, MapContact(cc->pSubs[i]));
+ }
+ }
+ else hDest = ccDst->contactID;
+
+ AccountMap pda(META_PROTO, META_PROTO);
+ ImportContactSettings(&pda, cc->contactID, hDest);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -385,11 +493,7 @@ static MCONTACT ImportContact(MCONTACT hSrc) }
DBVARIANT dbv;
- if (!strcmp(cc->szProto, META_PROTO)) {
- dbv.type = DBVT_DWORD;
- dbv.dVal = hSrc;
- }
- else if (myGet(hSrc, cc->szProto, pszUniqueSetting, &dbv)) {
+ if (myGet(hSrc, cc->szProto, pszUniqueSetting, &dbv)) {
AddMessage(LPGENT("Skipping %S contact, ID not found"), cc->szProto);
return NULL;
}
@@ -415,66 +519,18 @@ static MCONTACT ImportContact(MCONTACT hSrc) return NULL;
}
- TCHAR *tszGroup = myGetWs(hSrc, "CList", "Group"), *tszNick = myGetWs(hSrc, "CList", "MyHandle");
+ ptrT tszGroup(myGetWs(hSrc, "CList", "Group")), tszNick(myGetWs(hSrc, "CList", "MyHandle"));
if (tszNick == NULL)
tszNick = myGetWs(hSrc, cc->szProto, "Nick");
hDst = AddContact(hdlgProgress, pda->szDstAcc, pszUniqueSetting, &dbv, pszUniqueID, tszNick, tszGroup);
- mir_free(tszGroup), mir_free(tszNick);
-
- arContactMap.insert(new ContactMap(hSrc, hDst));
-
- if (hDst != INVALID_CONTACT_ID) {
- // Hidden?
- if (!myGet(hSrc, "CList", "Hidden", &dbv)) {
- db_set(hDst, "CList", "Hidden", &dbv);
- srcDb->FreeVariant(&dbv);
- }
-
- // Ignore settings
- if (!myGet(hSrc, "Ignore", "Mask1", &dbv)) {
- db_set(hDst, "Ignore", "Mask1", &dbv);
- srcDb->FreeVariant(&dbv);
- }
-
- // Apparent mode
- if (!myGet(hSrc, cc->szProto, "ApparentMode", &dbv)) {
- db_set(hDst, pda->szDstAcc, "ApparentMode", &dbv);
- srcDb->FreeVariant(&dbv);
- }
-
- // Nick
- if (!myGet(hSrc, cc->szProto, "Nick", &dbv)) {
- db_set(hDst, pda->szDstAcc, "Nick", &dbv);
- srcDb->FreeVariant(&dbv);
- }
-
- // Myhandle
- if (!myGet(hSrc, cc->szProto, "MyHandle", &dbv)) {
- db_set(hDst, pda->szDstAcc, "MyHandle", &dbv);
- srcDb->FreeVariant(&dbv);
- }
-
- // First name
- if (!myGet(hSrc, cc->szProto, "FirstName", &dbv)) {
- db_set(hDst, pda->szDstAcc, "FirstName", &dbv);
- srcDb->FreeVariant(&dbv);
- }
-
- // Last name
- if (!myGet(hSrc, cc->szProto, "LastName", &dbv)) {
- db_set(hDst, pda->szDstAcc, "LastName", &dbv);
- srcDb->FreeVariant(&dbv);
- }
-
- // About
- if (!myGet(hSrc, cc->szProto, "About", &dbv)) {
- db_set(hDst, pda->szDstAcc, "About", &dbv);
- srcDb->FreeVariant(&dbv);
- }
+ if (hDst == INVALID_CONTACT_ID) {
+ AddMessage(LPGENT("Unknown error while adding %S contact %s"), pda->szDstAcc, pszUniqueID);
+ return INVALID_CONTACT_ID;
}
- else AddMessage(LPGENT("Unknown error while adding %S contact %s"), pda->szDstAcc, pszUniqueID);
+ arContactMap.insert(new ContactMap(hSrc, hDst));
+ ImportContactSettings(pda, hSrc, hDst);
return hDst;
}
diff --git a/plugins/Import/src/miranda.cpp b/plugins/Import/src/miranda.cpp index 970d50b7ab..047212f816 100644 --- a/plugins/Import/src/miranda.cpp +++ b/plugins/Import/src/miranda.cpp @@ -22,19 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "import.h"
-// =====================
-// == LOCAL VARIABLES ==
-// =====================
-
time_t dwSinceDate = 0;
TCHAR importFile[MAX_PATH];
-// ====================
-// ====================
-// == IMPLEMENTATION ==
-// ====================
-// ====================
+//=======================================================================================
+// Profile selection dialog
static void SearchForLists(HWND hwndDlg, const TCHAR *mirandaPath, const TCHAR *mirandaProf)
{
@@ -149,6 +142,9 @@ INT_PTR CALLBACK MirandaPageProc(HWND hwndDlg,UINT message,WPARAM wParam,LPARAM return FALSE;
}
+//=======================================================================================
+// Import options dialog
+
INT_PTR CALLBACK MirandaOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
@@ -199,6 +195,9 @@ INT_PTR CALLBACK MirandaOptionsPageProc(HWND hwndDlg, UINT message, WPARAM wPara return FALSE;
}
+//=======================================================================================
+// Advanced options dialog
+
static const UINT InControls[] = { IDC_IN_MSG, IDC_IN_URL, IDC_IN_FT, IDC_IN_OTHER };
static const UINT OutControls[] = { IDC_OUT_MSG, IDC_OUT_URL, IDC_OUT_FT, IDC_OUT_OTHER };
static const UINT SysControls[] = { IDC_CONTACTS, IDC_SYSTEM };
|