From 5c2f5a27a78d50b6814a89c974214e7d294f5981 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 3 Mar 2014 12:34:53 +0000 Subject: - MIDatabase::MetaDetouchSub = new method for the mc support virtualization - further cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@8376 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/m_db_int.h | 64 ++++++++------- plugins/Db3x_mmap/src/dbcontacts.cpp | 9 +++ plugins/Db3x_mmap/src/dbintf.h | 2 + src/modules/metacontacts/meta_addto.cpp | 33 ++++---- src/modules/metacontacts/meta_edit.cpp | 10 +-- src/modules/metacontacts/meta_menu.cpp | 120 ++++++++++++--------------- src/modules/metacontacts/meta_services.cpp | 86 +++++++++----------- src/modules/metacontacts/meta_utils.cpp | 125 +++++++++++++---------------- src/modules/metacontacts/metacontacts.h | 8 +- 9 files changed, 220 insertions(+), 237 deletions(-) diff --git a/include/m_db_int.h b/include/m_db_int.h index 9733d0ddf5..95cd993878 100644 --- a/include/m_db_int.h +++ b/include/m_db_int.h @@ -76,41 +76,43 @@ interface MIDatabase { MIDatabaseCache* m_cache; - STDMETHOD_(void,SetCacheSafetyMode)(BOOL) PURE; + STDMETHOD_(void, SetCacheSafetyMode)(BOOL) PURE; - STDMETHOD_(LONG,GetContactCount)(void) PURE; + STDMETHOD_(LONG, GetContactCount)(void) PURE; STDMETHOD_(MCONTACT,FindFirstContact)(const char *szProto = NULL) PURE; STDMETHOD_(MCONTACT, FindNextContact)(MCONTACT contactID, const char *szProto = NULL) PURE; - STDMETHOD_(LONG,DeleteContact)(MCONTACT contactID) PURE; - STDMETHOD_(HANDLE,AddContact)(void) PURE; - STDMETHOD_(BOOL,IsDbContact)(MCONTACT contactID) PURE; - - STDMETHOD_(LONG,GetEventCount)(MCONTACT contactID) PURE; - STDMETHOD_(HANDLE,AddEvent)(MCONTACT contactID, DBEVENTINFO *dbe) PURE; - STDMETHOD_(BOOL,DeleteEvent)(MCONTACT contactID, HANDLE hDbEvent) PURE; - STDMETHOD_(LONG,GetBlobSize)(HANDLE hDbEvent) PURE; - STDMETHOD_(BOOL,GetEvent)(HANDLE hDbEvent, DBEVENTINFO *dbe) PURE; - STDMETHOD_(BOOL,MarkEventRead)(MCONTACT contactID, HANDLE hDbEvent) PURE; - STDMETHOD_(MCONTACT,GetEventContact)(HANDLE hDbEvent) PURE; - STDMETHOD_(HANDLE,FindFirstEvent)(MCONTACT contactID) PURE; - STDMETHOD_(HANDLE,FindFirstUnreadEvent)(MCONTACT contactID) PURE; - STDMETHOD_(HANDLE,FindLastEvent)(MCONTACT contactID) PURE; - STDMETHOD_(HANDLE,FindNextEvent)(HANDLE hDbEvent) PURE; - STDMETHOD_(HANDLE,FindPrevEvent)(HANDLE hDbEvent) PURE; - - STDMETHOD_(BOOL,EnumModuleNames)(DBMODULEENUMPROC pFunc, void *pParam) PURE; - - STDMETHOD_(BOOL,GetContactSetting)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; - STDMETHOD_(BOOL,GetContactSettingStr)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; - STDMETHOD_(BOOL,GetContactSettingStatic)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; - STDMETHOD_(BOOL,FreeVariant)(DBVARIANT *dbv) PURE; - STDMETHOD_(BOOL,WriteContactSetting)(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) PURE; - STDMETHOD_(BOOL,DeleteContactSetting)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) PURE; - STDMETHOD_(BOOL,EnumContactSettings)(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces) PURE; - STDMETHOD_(BOOL,SetSettingResident)(BOOL bIsResident, const char *pszSettingName) PURE; - STDMETHOD_(BOOL,EnumResidentSettings)(DBMODULEENUMPROC pFunc, void *pParam) PURE; - STDMETHOD_(BOOL,IsSettingEncrypted)(LPCSTR szModule, LPCSTR szSetting) PURE; + STDMETHOD_(LONG, DeleteContact)(MCONTACT contactID) PURE; + STDMETHOD_(HANDLE, AddContact)(void) PURE; + STDMETHOD_(BOOL, IsDbContact)(MCONTACT contactID) PURE; + + STDMETHOD_(LONG, GetEventCount)(MCONTACT contactID) PURE; + STDMETHOD_(HANDLE, AddEvent)(MCONTACT contactID, DBEVENTINFO *dbe) PURE; + STDMETHOD_(BOOL, DeleteEvent)(MCONTACT contactID, HANDLE hDbEvent) PURE; + STDMETHOD_(LONG, GetBlobSize)(HANDLE hDbEvent) PURE; + STDMETHOD_(BOOL, GetEvent)(HANDLE hDbEvent, DBEVENTINFO *dbe) PURE; + STDMETHOD_(BOOL, MarkEventRead)(MCONTACT contactID, HANDLE hDbEvent) PURE; + STDMETHOD_(MCONTACT, GetEventContact)(HANDLE hDbEvent) PURE; + STDMETHOD_(HANDLE, FindFirstEvent)(MCONTACT contactID) PURE; + STDMETHOD_(HANDLE, FindFirstUnreadEvent)(MCONTACT contactID) PURE; + STDMETHOD_(HANDLE, FindLastEvent)(MCONTACT contactID) PURE; + STDMETHOD_(HANDLE, FindNextEvent)(HANDLE hDbEvent) PURE; + STDMETHOD_(HANDLE, FindPrevEvent)(HANDLE hDbEvent) PURE; + + STDMETHOD_(BOOL, EnumModuleNames)(DBMODULEENUMPROC pFunc, void *pParam) PURE; + + STDMETHOD_(BOOL, GetContactSetting)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; + STDMETHOD_(BOOL, GetContactSettingStr)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; + STDMETHOD_(BOOL, GetContactSettingStatic)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; + STDMETHOD_(BOOL, FreeVariant)(DBVARIANT *dbv) PURE; + STDMETHOD_(BOOL, WriteContactSetting)(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) PURE; + STDMETHOD_(BOOL, DeleteContactSetting)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) PURE; + STDMETHOD_(BOOL, EnumContactSettings)(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces) PURE; + STDMETHOD_(BOOL, SetSettingResident)(BOOL bIsResident, const char *pszSettingName) PURE; + STDMETHOD_(BOOL, EnumResidentSettings)(DBMODULEENUMPROC pFunc, void *pParam) PURE; + STDMETHOD_(BOOL, IsSettingEncrypted)(LPCSTR szModule, LPCSTR szSetting) PURE; + + STDMETHOD_(BOOL, MetaDetouchSub)(DBCachedContact*, int nSub) PURE; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index fcfd56afb9..5420037b90 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -199,6 +199,15 @@ STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(MCONTACT contactID) return FALSE; } +///////////////////////////////////////////////////////////////////////////////////////// +// metacontacts support + +BOOL CDb3Mmap::MetaDetouchSub(DBCachedContact *cc, int nSub) +{ + CallService(MS_DB_MODULE_DELETE, cc->pSubs[nSub], (LPARAM)META_PROTO); + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// // contacts convertor diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index 6be58c9634..986ac700d0 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -234,6 +234,8 @@ public: STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam); STDMETHODIMP_(BOOL) IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting); + STDMETHODIMP_(BOOL) MetaDetouchSub(DBCachedContact *cc, int nSub); + protected: STDMETHODIMP_(BOOL) Start(DBCHeckCallback *callback); STDMETHODIMP_(BOOL) CheckDb(int phase, int firstTime); diff --git a/src/modules/metacontacts/meta_addto.cpp b/src/modules/metacontacts/meta_addto.cpp index dfef8291b5..54b5cf62ae 100644 --- a/src/modules/metacontacts/meta_addto.cpp +++ b/src/modules/metacontacts/meta_addto.cpp @@ -41,15 +41,16 @@ typedef struct { * * Adds all the metacontacts present in the database in the list, * -* @param list : \c HANDLE to the list which will contain the columns. -* @param nb_contacts : Number of loaded contacts. -* @param contacts : A list of the contacts' identifiers +* @param list : HANDLE to the list which will contain the columns. +* @param nb_contacts : Number of loaded contacts. +* @param contacts : A list of the contacts' identifiers * -* @param id : Reference to a list of the MetaContacts IDs loaded in the listview. -* Since this list is resized, its address must be passed. +* @param id : Reference to a list of the MetaContacts IDs loaded in the listview. +* Since this list is resized, its address must be passed. * -* @return An integer specifying the number of rows added in the list. +* @return An integer specifying the number of rows added in the list. */ + int FillList(HWND list, BOOL sort) { int i=0; @@ -87,12 +88,12 @@ int FillList(HWND list, BOOL sort) /** Build or update the list. * -* @param list : \c HANDLE to the list which will contain the columns -* @param id : Reference to a list that will contain all the MetaContacts IDs loaded in the listview -* otherwise the list is only refilled \n (Warning : this value must be -* set to \c TRUE only once per Dialog display, otherwise all columns will be doubled) +* @param list : HANDLE to the list which will contain the columns +* @param id : Reference to a list that will contain all the MetaContacts IDs loaded in the listview +* otherwise the list is only refilled \n (Warning : this value must be +* set to TRUE only once per Dialog display, otherwise all columns will be doubled) * -* @returns An integer specifying the number of rows inserted or \c -1 if there was a problem +* @returns An integer specifying the number of rows inserted or -1 if there was a problem */ int BuildList(HWND list, BOOL sort) @@ -105,12 +106,12 @@ int BuildList(HWND list, BOOL sort) * * All the UI is controlled here, from display to functionnalities. * -* @param hwndDlg : \c HANDLE to the 'Add To' \c Dialog. -* @param uMsg : Specifies the message received by this dialog. -* @param wParam : Specifies additional message-specific information. -* @param lParam : Specifies additional message-specific information. +* @param hwndDlg : HANDLE to the 'Add To' Dialog. +* @param uMsg : Specifies the message received by this dialog. +* @param wParam : Specifies additional message-specific information. +* @param lParam : Specifies additional message-specific information. * -* @return \c TRUE if the dialog processed the message, \c FALSE if it did not. +* @return TRUE if the dialog processed the message, FALSE if it did not. */ #define szConvMsg LPGEN("Either there is no MetaContact in the database (in this case you should first convert a contact into one)\n\ diff --git a/src/modules/metacontacts/meta_edit.cpp b/src/modules/metacontacts/meta_edit.cpp index bb9aa2eec3..56277d8bd1 100644 --- a/src/modules/metacontacts/meta_edit.cpp +++ b/src/modules/metacontacts/meta_edit.cpp @@ -211,12 +211,12 @@ LRESULT ProcessCustomDraw (LPARAM lParam) * * All the UI is controlled here, from display to functionnalities. * -* @param hwndDlg : \c HANDLE to the 'Edit' \c Dialog. -* @param uMsg : Specifies the message received by this dialog. -* @param wParam : Specifies additional message-specific information. -* @param lParam : Specifies additional message-specific information (handle of MetaContact to edit) +* @param hwndDlg : HANDLE to the 'Edit' Dialog. +* @param uMsg : Specifies the message received by this dialog. +* @param wParam : Specifies additional message-specific information. +* @param lParam : Specifies additional message-specific information (handle of MetaContact to edit) * -* @return \c TRUE if the dialog processed the message, \c FALSE if it did not. +* @return TRUE if the dialog processed the message, FALSE if it did not. */ #define WMU_SETTITLE (WM_USER + 1) diff --git a/src/modules/metacontacts/meta_menu.cpp b/src/modules/metacontacts/meta_menu.cpp index aeed077a18..2b712bd731 100644 --- a/src/modules/metacontacts/meta_menu.cpp +++ b/src/modules/metacontacts/meta_menu.cpp @@ -42,7 +42,7 @@ static HGENMENU * Create a new MetaContact, remove the selected contact from the \c CList * and attach it to the MetaContact. * -* @param wParam : \c HANDLE to the contact that has been chosen. +* @param wParam : HANDLE to the contact that has been chosen. * @param lParam : Allways set to 0. */ @@ -52,17 +52,15 @@ INT_PTR Meta_Convert(WPARAM wParam, LPARAM lParam) char *group = 0; // Get some information about the selected contact. - if ( !db_get_utf(wParam, "CList", "Group", &dbv)) { + if (!db_get_utf(wParam, "CList", "Group", &dbv)) { group = _strdup(dbv.pszVal); db_free(&dbv); } // Create a new metacontact - MCONTACT hMetaContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD,0,0); + MCONTACT hMetaContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (hMetaContact) { - db_set_dw(hMetaContact, META_PROTO, META_ID,nextMetaID); - db_set_dw(hMetaContact, META_PROTO, "NumContacts",0); - db_set_dw(NULL, META_PROTO, "NextMetaID", ++nextMetaID); + db_set_dw(hMetaContact, META_PROTO, "NumContacts", 0); // Add the MetaContact protocol to the new meta contact CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hMetaContact, (LPARAM)META_PROTO); @@ -71,14 +69,14 @@ INT_PTR Meta_Convert(WPARAM wParam, LPARAM lParam) db_set_utf(hMetaContact, "CList", "Group", group); // Assign the contact to the MetaContact just created (and make default). - if ( !Meta_Assign(wParam, hMetaContact, TRUE)) { + if (!Meta_Assign(wParam, hMetaContact, TRUE)) { MessageBox(0, TranslateT("There was a problem in assigning the contact to the MetaContact"), TranslateT("Error"), MB_ICONEXCLAMATION); CallService(MS_DB_CONTACT_DELETE, (WPARAM)hMetaContact, 0); return 0; } // hide the contact if clist groups disabled (shouldn't create one anyway since menus disabled) - if ( !Meta_IsEnabled()) + if (!Meta_IsEnabled()) db_set_b(hMetaContact, "CList", "Hidden", 1); } @@ -91,7 +89,7 @@ INT_PTR Meta_Convert(WPARAM wParam, LPARAM lParam) * Present a dialog in which the user can choose to which MetaContact this * contact will be added * -* @param wParam : \c HANDLE to the contact that has been chosen. +* @param wParam : HANDLE to the contact that has been chosen. * @param lParam : Allways set to 0. */ @@ -106,19 +104,19 @@ INT_PTR Meta_AddTo(WPARAM wParam, LPARAM lParam) * * Present a dialog in which the user can edit some properties of the MetaContact. * -* @param wParam : \c HANDLE to the MetaContact to be edited. +* @param wParam : HANDLE to the MetaContact to be edited. * @param lParam : Allways set to 0. */ -INT_PTR Meta_Edit(WPARAM wParam,LPARAM lParam) + +INT_PTR Meta_Edit(WPARAM wParam, LPARAM lParam) { HWND clui = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_METAEDIT), clui, Meta_EditDialogProc, (LPARAM)wParam); return 0; } -void Meta_RemoveContactNumber(MCONTACT hMeta, int number) +void Meta_RemoveContactNumber(DBCachedContact *cc, int number) { - DBCachedContact *cc = CheckMeta(hMeta); if (cc == NULL) return; @@ -127,49 +125,47 @@ void Meta_RemoveContactNumber(MCONTACT hMeta, int number) // get the handle MCONTACT hContact = Meta_GetContactHandle(cc, number); - int default_contact = db_get_dw(hMeta, META_PROTO, "Default", -1); + int default_contact = db_get_dw(cc->contactID, META_PROTO, "Default", -1); // make sure this contact thinks it's part of this metacontact - if (db_get_dw(hContact, META_PROTO, "Handle", 0) == hMeta) { + if (hContact == cc->contactID) { // remove link to meta contact db_unset(hContact, META_PROTO, META_LINK); db_unset(hContact, META_PROTO, "Handle"); - // unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus) - db_unset(hContact, META_PROTO, "OldCListGroup"); // stop ignoring, if we were if (options.suppress_status) - CallService(MS_IGNORE_UNIGNORE, hContact, (WPARAM)IGNOREEVENT_USERONLINE); + CallService(MS_IGNORE_UNIGNORE, hContact, IGNOREEVENT_USERONLINE); } // each contact from 'number' upwards will be moved down one // and the last one will be deleted for (int i = number + 1; i < cc->nSubs; i++) - Meta_SwapContacts(cc, i, i-1); + Meta_SwapContacts(cc, i, i - 1); // remove the last one char buffer[512], idStr[20]; _itoa(cc->nSubs - 1, idStr, 10); strcpy(buffer, "Protocol"); strcat(buffer, idStr); - db_unset(hMeta, META_PROTO, buffer); + db_unset(cc->contactID, META_PROTO, buffer); strcpy(buffer, "Status"); strcat(buffer, idStr); - db_unset(hMeta, META_PROTO, buffer); + db_unset(cc->contactID, META_PROTO, buffer); strcpy(buffer, "Handle"); strcat(buffer, idStr); - db_unset(hMeta, META_PROTO, buffer); + db_unset(cc->contactID, META_PROTO, buffer); strcpy(buffer, "StatusString"); strcat(buffer, idStr); - db_unset(hMeta, META_PROTO, buffer); + db_unset(cc->contactID, META_PROTO, buffer); strcpy(buffer, "Login"); strcat(buffer, idStr); - db_unset(hMeta, META_PROTO, buffer); + db_unset(cc->contactID, META_PROTO, buffer); strcpy(buffer, "Nick"); strcat(buffer, idStr); - db_unset(hMeta, META_PROTO, buffer); + db_unset(cc->contactID, META_PROTO, buffer); strcpy(buffer, "CListName"); strcat(buffer, idStr); - db_unset(hMeta, META_PROTO, buffer); + db_unset(cc->contactID, META_PROTO, buffer); // if the default contact was equal to or greater than 'number', decrement it (and deal with ends) if (default_contact >= number) { @@ -177,11 +173,11 @@ void Meta_RemoveContactNumber(MCONTACT hMeta, int number) if (default_contact < 0) default_contact = 0; - db_set_dw(hMeta, META_PROTO, "Default", default_contact); - NotifyEventHooks(hEventDefaultChanged, hMeta, Meta_GetContactHandle(cc, default_contact)); + db_set_dw(cc->contactID, META_PROTO, "Default", default_contact); + NotifyEventHooks(hEventDefaultChanged, cc->contactID, Meta_GetContactHandle(cc, default_contact)); } cc->nSubs--; - db_set_dw(hMeta, META_PROTO, "NumContacts", cc->nSubs); + db_set_dw(cc->contactID, META_PROTO, "NumContacts", cc->nSubs); // fix nick hContact = Meta_GetMostOnline(cc); @@ -194,12 +190,12 @@ void Meta_RemoveContactNumber(MCONTACT hMeta, int number) hContact = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS); if (hContact) { PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) }; - AI.hContact = hMeta; + AI.hContact = cc->contactID; AI.format = PA_FORMAT_UNKNOWN; _tcscpy(AI.filename, _T("X")); if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) - db_set_ts(hMeta, "ContactPhoto", "File",AI.filename); + db_set_ts(cc->contactID, "ContactPhoto", "File", AI.filename); } } @@ -208,53 +204,45 @@ void Meta_RemoveContactNumber(MCONTACT hMeta, int number) * Delete a MetaContact and remove all the information * concerning this MetaContact in the contact linked to it. * -* @param wParam : \c HANDLE to the MetaContact to be deleted, or to the subcontact to be removed from the MetaContact -* @param lParam : \c BOOL flag indicating whether to ask 'are you sure' when deleting a MetaContact +* @param wParam : HANDLE to the MetaContact to be deleted, or to the subcontact to be removed from the MetaContact +* @param lParam : BOOL flag indicating whether to ask 'are you sure' when deleting a MetaContact */ -INT_PTR Meta_Delete(WPARAM wParam, LPARAM lParam) +INT_PTR Meta_Delete(WPARAM hContact, LPARAM bSkipQuestion) { - DWORD metaID; + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); + if (cc == NULL) + return 0; // The wParam is a metacontact - if ((metaID = db_get_dw(wParam, META_PROTO, META_ID, INVALID_CONTACT_ID)) != INVALID_CONTACT_ID) { - if (!lParam) { // check from recursion - see second half of this function - if (MessageBox((HWND)CallService(MS_CLUI_GETHWND, 0, 0), + if (cc->nSubs != -1) { + // check from recursion - see second half of this function + if (!bSkipQuestion && IDYES != + MessageBox((HWND)CallService(MS_CLUI_GETHWND, 0, 0), TranslateT("This will remove the MetaContact permanently.\n\nProceed Anyway?"), - TranslateT("Are you sure?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES) - return 0; - } - - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - // This contact is assigned to the MetaContact that will be deleted, clear the "MetaContacts" information - if (db_get_dw(hContact, META_PROTO, META_LINK, INVALID_CONTACT_ID) == metaID) { - db_unset(hContact, META_PROTO, META_LINK); - db_unset(hContact, META_PROTO, "Handle"); + TranslateT("Are you sure?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2)) + return 0; - // unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus) - db_unset(hContact, META_PROTO, "OldCListGroup"); + for (int i = 0; i < cc->nSubs; i++) { + currDb->MetaDetouchSub(cc, i); - // stop ignoring, if we were - if (options.suppress_status) - CallService(MS_IGNORE_UNIGNORE, hContact, (WPARAM)IGNOREEVENT_USERONLINE); - } + // stop ignoring, if we were + if (options.suppress_status) + CallService(MS_IGNORE_UNIGNORE, hContact, IGNOREEVENT_USERONLINE); } - NotifyEventHooks(hSubcontactsChanged, (WPARAM)wParam, 0); - CallService(MS_DB_CONTACT_DELETE, wParam, 0); + NotifyEventHooks(hSubcontactsChanged, hContact, 0); + CallService(MS_DB_CONTACT_DELETE, hContact, 0); } else { - MCONTACT hMeta = (MCONTACT)db_get_dw(wParam, META_PROTO, "Handle", 0); - DWORD num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", -1); - - if (num_contacts == 1) { + if (cc->nSubs == 1) { if (IDYES == MessageBox(0, TranslateT(szDelMsg), TranslateT("Delete MetaContact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) - Meta_Delete((WPARAM)hMeta, (LPARAM)1); + Meta_Delete(hContact, 1); return 0; } - Meta_RemoveContactNumber(hMeta, wParam); // !!!!!!!!!!!!!!!!!!!!!!!!! + Meta_RemoveContactNumber(cc, Meta_GetContactNumber(cc, hContact)); } return 0; } @@ -263,7 +251,7 @@ INT_PTR Meta_Delete(WPARAM wParam, LPARAM lParam) * * Set the given contact to be the default one for the metacontact to which it is linked. * -* @param wParam : HANDLE to the MetaContact to be set as default +* @param wParam : HANDLE to the MetaContact to be set as default * @param lParam : HWND to the clist window (This means the function has been called via the contact menu). */ @@ -281,8 +269,8 @@ INT_PTR Meta_Default(WPARAM hMeta, LPARAM wParam) * * Set the given contact to be the default one for the metacontact to which it is linked. * -* @param wParam : \c HANDLE to the MetaContact to be set as default -* @param lParam : \c HWND to the clist window +* @param wParam : HANDLE to the MetaContact to be set as default +* @param lParam :HWND to the clist window (This means the function has been called via the contact menu). */ @@ -310,7 +298,7 @@ INT_PTR Meta_ForceDefault(WPARAM hMeta, LPARAM) * This will test which of the 4 menu item should be displayed, depending * on which contact triggered the event * -* @param wParam : \c HANDLE to the contact that triggered the event +* @param wParam : HANDLE to the contact that triggered the event * @param lParam : Always set to 0; */ @@ -517,8 +505,6 @@ void InitMenus() hMenuContact[i] = Menu_AddContactMenuItem(&mi); } - nextMetaID = db_get_dw(NULL, META_PROTO, "NextMetaID", 0); - // loop and copy data from subcontacts if (options.copydata) { int meta_id; diff --git a/src/modules/metacontacts/meta_services.cpp b/src/modules/metacontacts/meta_services.cpp index 01817d525e..f189059f36 100644 --- a/src/modules/metacontacts/meta_services.cpp +++ b/src/modules/metacontacts/meta_services.cpp @@ -53,7 +53,7 @@ BOOL firstSetOnline = TRUE; // see Meta_SetStatus function /** Get the capabilities of the "MetaContacts" protocol. * -* @param wParam : equals to one of the following values :\n +* @param wParam : equals to one of the following values :\n PFLAGNUM_1 | PFLAGNUM_2 | PFLAGNUM_3 | PFLAGNUM_4 | PFLAG_UNIQUEIDTEXT | PFLAG_MAXLENOFMESSAGE | PFLAG_UNIQUEIDSETTING . * @param lParam : Allways set to 0. * @@ -90,7 +90,7 @@ INT_PTR Meta_GetCaps(WPARAM wParam,LPARAM lParam) } /** Copy the name of the protocole into lParam -* @param wParam : max size of the name +* @param wParam : max size of the name * @param lParam : reference to a char *, which will hold the name */ @@ -106,7 +106,7 @@ INT_PTR Meta_GetName(WPARAM wParam,LPARAM lParam) /** Loads the icon corresponding to the status * Called by the CList when the status changes. -* @param wParam : one of the following values : \n +* @param wParam : one of the following values : \n PLI_PROTOCOL | PLI_ONLINE | PLI_OFFLINE * @return an \c HICON in which the icon has been loaded. */ @@ -144,7 +144,7 @@ void CALLBACK SetStatusThread(HWND hWnd, UINT msg, UINT_PTR id, DWORD dw) } /** Changes the status and notifies everybody -* @param wParam : The new mode +* @param wParam : The new mode * @param lParam : Allways set to 0. */ @@ -201,10 +201,10 @@ static DWORD CALLBACK sttFakeAckFail( LPVOID param ) * * When groups are disabled, add an event to the DB for the metacontact to maintain history * -* @param wParam : index of the protocol in the protocol chain. -* @param lParam : \c CCSDATA structure holding all the information about the message. +* @param wParam : index of the protocol in the protocol chain. +* @param lParam : CCSDATA structure holding all the information about the message. * -* @return 0 on success, 1 otherwise. +* @return 0 on success, 1 otherwise. */ INT_PTR MetaFilter_SendMessage(WPARAM wParam,LPARAM lParam) @@ -264,10 +264,10 @@ INT_PTR Meta_SendNudge(WPARAM wParam,LPARAM lParam) * Call the function specific to the protocol that belongs * to the contact chosen to send the message. * -* @param wParam : index of the protocol in the protocol chain. -* @param lParam : \c CCSDATA structure holding all the information abour rhe message. +* @param wParam : index of the protocol in the protocol chain. +* @param lParam : CCSDATA structure holding all the information abour rhe message. * -* @return 0 on success, 1 otherwise. +* @return 0 on success, 1 otherwise. */ INT_PTR Meta_SendMessage(WPARAM wParam,LPARAM lParam) { @@ -339,10 +339,10 @@ INT_PTR Meta_SendMessage(WPARAM wParam,LPARAM lParam) * to that MetaContact and inhibit the further reception of this message * by the standard protocol of the contact. * -* @param wParam : index of the protocol in the protocol chain. -* @param lParam : \c CCSDATA structure holding all the information about the message. +* @param wParam : index of the protocol in the protocol chain. +* @param lParam : CCSDATA structure holding all the information about the message. * -* @return 0 on success, 1 otherwise. +* @return 0 on success, 1 otherwise. */ INT_PTR MetaFilter_RecvMessage(WPARAM wParam,LPARAM lParam) @@ -487,7 +487,7 @@ INT_PTR Meta_RecvMessage(WPARAM wParam, LPARAM lParam) * Retransmit the ACK sent by a simple contact so that it * looks like it was the MetaContact that sends the ACK. * -* @param wParam : Allways set to 0. +* @param wParam : Allways set to 0. * @param lParam : Reference to a ACKDATA that contains information about the ACK. * @return 0 on success, 1 otherwise. @@ -557,7 +557,6 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam) DBCONTACTWRITESETTING *dcws = (DBCONTACTWRITESETTING *)lParam; char buffer[512], szId[40]; int contact_number; - MCONTACT most_online; // hide metacontacts when groups disabled if (wParam == 0 @@ -664,7 +663,6 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam) // copy nick to metacontact, if it's the most online MCONTACT most_online = Meta_GetMostOnline(cc); Meta_CopyContactNick(cc, most_online); - return 0; } else if (!strcmp(dcws->szSetting, "Status") && !dcws->value.type == DBVT_DELETED) { @@ -684,24 +682,20 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam) MetaAPI_UnforceSendContact((WPARAM)cc->contactID, 0); else { // set status to that of most online contact - most_online = Meta_GetMostOnline(cc); - Meta_CopyContactNick(cc, most_online); + Meta_CopyContactNick(cc, Meta_GetMostOnline(cc)); Meta_FixStatus(cc); Meta_CopyData(cc); } // most online contact with avatar support might have changed - update avatar - most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS); + MCONTACT most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS); if (most_online) { - PROTO_AVATAR_INFORMATIONT AI; - - AI.cbSize = sizeof(AI); + PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) }; AI.hContact = cc->contactID; AI.format = PA_FORMAT_UNKNOWN; _tcscpy(AI.filename, _T("X")); - - if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) + if (CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) db_set_ts(cc->contactID, "ContactPhoto", "File", AI.filename); } } @@ -716,35 +710,31 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam) int Meta_ContactDeleted(WPARAM hContact, LPARAM lParam) { - DBCachedContact *cc = CheckMeta(hContact); + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc == NULL) return 0; // is a subcontact - update meta contact - MCONTACT hMeta = db_get_dw(hContact, META_PROTO, "Handle", 0); - if (hMeta) { - Meta_RemoveContactNumber(hMeta, hContact); - NotifyEventHooks(hSubcontactsChanged, (WPARAM)hMeta, 0); + if (IsSub(cc)) { + Meta_RemoveContactNumber(cc, Meta_GetContactNumber(cc, hContact)); + NotifyEventHooks(hSubcontactsChanged, cc->parentID, 0); return 0; } // not a subcontact - is it a metacontact? - int num_contacts = db_get_dw(hContact, META_PROTO, "NumContacts", 0); - if (num_contacts) + if (!IsMeta(cc)) + return 0; + + if (cc->nSubs > 0) NotifyEventHooks(hSubcontactsChanged, hContact, 0); // remove & restore all subcontacts - for (int i = 0; i < num_contacts; i++) { - MCONTACT hContact = Meta_GetContactHandle(cc, i); - if (hContact && db_get_dw(hContact, META_PROTO, "Handle", 0) == hContact) { - db_unset(hContact, META_PROTO, META_LINK); - db_unset(hContact, META_PROTO, "Handle"); - db_unset(hContact, META_PROTO, "OldCListGroup"); - - // stop ignoring, if we were - if (options.suppress_status) - CallService(MS_IGNORE_UNIGNORE, hContact, (WPARAM)IGNOREEVENT_USERONLINE); - } + for (int i = 0; i < cc->nSubs; i++) { + currDb->MetaDetouchSub(cc, i); + + // stop ignoring, if we were + if (options.suppress_status) + CallService(MS_IGNORE_UNIGNORE, cc->pSubs[i], IGNOREEVENT_USERONLINE); } return 0; } @@ -779,15 +769,16 @@ INT_PTR Meta_UserIsTyping(WPARAM hMeta, LPARAM lParam) * @param wParam \c HANDLE to the contact that is typing or not * @param lParam either PROTOTYPE_SELFTYPING_ON or PROTOTYPE_SELFTYPING_OFF */ -int Meta_ContactIsTyping(WPARAM wParam, LPARAM lParam) + +int Meta_ContactIsTyping(WPARAM hMeta, LPARAM lParam) { - MCONTACT hMeta; - if ((hMeta = (MCONTACT)db_get_dw(wParam, META_PROTO, "Handle", 0)) != 0 && Meta_IsEnabled()) { + DBCachedContact *cc = CheckMeta(hMeta); + if (cc != NULL && Meta_IsEnabled()) { // This contact is attached to a MetaContact. if (!options.subcontact_windows) { // we don't want clicking on the clist notification icon to open the metacontact message window // try to remove any clist events we added for subcontact - CallServiceSync(MS_CLIST_REMOVEEVENT, wParam, (LPARAM)1); - CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hMeta, lParam); + CallServiceSync(MS_CLIST_REMOVEEVENT, hMeta, 1); + CallService(MS_PROTO_CONTACTISTYPING, hMeta, lParam); // stop processing of event return 1; } @@ -1136,7 +1127,6 @@ int Meta_CallMostOnline(WPARAM hContact, LPARAM lParam) int Meta_PreShutdown(WPARAM wParam, LPARAM lParam) { Meta_SetStatus((WPARAM)ID_STATUS_OFFLINE, 0); - Meta_UnhideLinkedContacts(); Meta_SuppressStatus(FALSE); if (setStatusTimerId) KillTimer(0, setStatusTimerId); diff --git a/src/modules/metacontacts/meta_utils.cpp b/src/modules/metacontacts/meta_utils.cpp index 07297afdc8..9295aca525 100644 --- a/src/modules/metacontacts/meta_utils.cpp +++ b/src/modules/metacontacts/meta_utils.cpp @@ -200,11 +200,11 @@ int Meta_SetNick(char *szProto) /** Assign a contact (src) to a metacontact (dest) * -* @param src \c HANDLE to a contact that should be assigned -* @param dest \c HANDLE to a metacontact that will host the contact -* @param set_as_default \c bool flag to indicate whether the new contact becomes the default +* @param src : HANDLE to a contact that should be assigned +* @param dest : HANDLE to a metacontact that will host the contact +* @param set_as_default : bool flag to indicate whether the new contact becomes the default * -* @return TRUE on success, FALSE otherwise +* @return TRUE on success, FALSE otherwise */ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default) { @@ -373,9 +373,9 @@ MCONTACT Meta_GetMostOnline(DBCachedContact *cc) /** Get the 'most online' contact for a meta contact (according to above order) which supports the specified * protocol service, and copies nick from that contact * -* @param hMeta \c HANDLE to a metacontact +* @param hMetaHANDLE to a metacontact * -* @return \c HANDLE to a contact +* @return HANDLE to a contact */ MCONTACT Meta_GetMostOnlineSupporting(DBCachedContact *cc, int pflagnum, unsigned long capability) @@ -709,63 +709,62 @@ MetaContacts continues to function correctly, you should:\n\ int Meta_HideLinkedContacts(void) { DBVARIANT dbv, dbv2; - DWORD meta_id, num_contacts, contact_number; char buffer[512], buffer2[512]; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - if ((meta_id = db_get_dw(hContact, META_PROTO, META_LINK, INVALID_CONTACT_ID)) != INVALID_CONTACT_ID) { - // get contact number - contact_number = db_get_dw(hContact, META_PROTO, "ContactNumber", INVALID_CONTACT_ID); - - // prepare to update metacontact record of subcontat status - char *szProto = GetContactProto(hContact); + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); + if (cc == NULL || cc->parentID == 0) + continue; - // find metacontact - for (MCONTACT hContact2 = db_find_first(); hContact2; hContact2 = db_find_next(hContact2)) { - if (db_get_dw(hContact2, META_PROTO, META_ID, INVALID_CONTACT_ID) != meta_id) - continue; + DBCachedContact *ccMeta = CheckMeta(cc->parentID); + if (ccMeta == NULL) + continue; - num_contacts = db_get_dw(hContact2, META_PROTO, "NumContacts", INVALID_CONTACT_ID); - if (contact_number < 0 || contact_number >= num_contacts) - continue; + // get contact number + int contact_number = Meta_GetContactNumber(cc, hContact); - // update metacontact's record of status for this contact - strcpy(buffer, "Status"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); + // prepare to update metacontact record of subcontat status + char *szProto = GetContactProto(hContact); - WORD status = (!szProto) ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); - db_set_w(hContact2, META_PROTO, buffer, status); - - // update metacontact's record of nick for this contact - if (szProto && !db_get(hContact, szProto, "Nick", &dbv)) { - strcpy(buffer, "Nick"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - db_set(hContact2, META_PROTO, buffer, &dbv); - - strcpy(buffer, "CListName"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - if (db_get(hContact, "CList", "MyHandle", &dbv2)) - db_set(hContact2, META_PROTO, buffer, &dbv); - else { - db_set(hContact2, META_PROTO, buffer, &dbv2); - db_free(&dbv2); - } + // find metacontact + if (contact_number < 0 || contact_number >= ccMeta->nSubs) + continue; - db_free(&dbv); - } - else { - if (!db_get(hContact, "CList", "MyHandle", &dbv)) { - strcpy(buffer, "CListName"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - db_set(hContact2, META_PROTO, buffer, &dbv); - db_free(&dbv); - } - } + // update metacontact's record of status for this contact + strcpy(buffer, "Status"); + strcat(buffer, _itoa(contact_number, buffer2, 10)); + + WORD status = (!szProto) ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); + db_set_w(ccMeta->contactID, META_PROTO, buffer, status); + + // update metacontact's record of nick for this contact + if (szProto && !db_get(hContact, szProto, "Nick", &dbv)) { + strcpy(buffer, "Nick"); + strcat(buffer, _itoa(contact_number, buffer2, 10)); + db_set(ccMeta->contactID, META_PROTO, buffer, &dbv); + + strcpy(buffer, "CListName"); + strcat(buffer, _itoa(contact_number, buffer2, 10)); + if (db_get(hContact, "CList", "MyHandle", &dbv2)) + db_set(ccMeta->contactID, META_PROTO, buffer, &dbv); + else { + db_set(ccMeta->contactID, META_PROTO, buffer, &dbv2); + db_free(&dbv2); } - if (options.suppress_status) - CallService(MS_IGNORE_IGNORE, hContact, (WPARAM)IGNOREEVENT_USERONLINE); + db_free(&dbv); } + else { + if (!db_get(hContact, "CList", "MyHandle", &dbv)) { + strcpy(buffer, "CListName"); + strcat(buffer, _itoa(contact_number, buffer2, 10)); + db_set(ccMeta->contactID, META_PROTO, buffer, &dbv); + db_free(&dbv); + } + } + + if (options.suppress_status) + CallService(MS_IGNORE_IGNORE, hContact, (WPARAM)IGNOREEVENT_USERONLINE); } // do metacontacts after handles set properly above @@ -782,14 +781,6 @@ int Meta_HideLinkedContacts(void) return 0; } -/** Unhide all contacts linked to any meta contact -* -*/ -int Meta_UnhideLinkedContacts(void) -{ - return 0; -} - int Meta_HideMetaContacts(int hide) { // set status suppression @@ -799,13 +790,13 @@ int Meta_HideMetaContacts(int hide) Meta_SuppressStatus(options.suppress_status); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - if (db_get_dw(hContact, META_PROTO, META_ID, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) { - // is a meta contact - if (hide) - db_set_b(hContact, "CList", "Hidden", 1); - else - db_unset(hContact, "CList", "Hidden"); - } + if (CheckMeta(hContact) == NULL) + continue; + + if (hide) + db_set_b(hContact, "CList", "Hidden", 1); + else + db_unset(hContact, "CList", "Hidden"); } return 0; diff --git a/src/modules/metacontacts/metacontacts.h b/src/modules/metacontacts/metacontacts.h index bf314ca577..ecc28c7cca 100644 --- a/src/modules/metacontacts/metacontacts.h +++ b/src/modules/metacontacts/metacontacts.h @@ -33,17 +33,20 @@ INT_PTR TranslateMenuFunc(MCONTACT hContact, int i); // contact menu items void InitMenus(); -extern DWORD nextMetaID; extern int mcStatus; +__forceinline bool IsMeta(DBCachedContact *cc) { return cc->nSubs != -1; } +__forceinline bool IsSub(DBCachedContact *cc) { return cc->parentID != 0; } + INT_PTR Meta_Convert(WPARAM wParam,LPARAM lParam); INT_PTR Meta_AddTo(WPARAM wParam,LPARAM lParam); INT_PTR Meta_Edit(WPARAM wParam,LPARAM lParam); -void Meta_RemoveContactNumber(MCONTACT hMeta, int number); INT_PTR Meta_Delete(WPARAM wParam,LPARAM lParam); INT_PTR Meta_Default(WPARAM wParam,LPARAM lParam); INT_PTR Meta_ForceDefault(WPARAM wParam,LPARAM lParam); +void Meta_RemoveContactNumber(DBCachedContact *cc, int number); + INT_PTR Meta_IsEnabled(); INT_PTR Meta_OnOff(WPARAM wParam, LPARAM lParam); @@ -52,7 +55,6 @@ int Meta_ModifyMenu(WPARAM wParam,LPARAM lParam); BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default); int Meta_SetNick(char *proto); int Meta_HideLinkedContacts(void); -int Meta_UnhideLinkedContacts(void); int Meta_GetContactNumber(DBCachedContact *cc, MCONTACT hContact); int Meta_HideMetaContacts(int hide); int Meta_SuppressStatus(int suppress); -- cgit v1.2.3