int Meta_ContactDeleted(WPARAM hContact, LPARAM lParam) { DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc == NULL) return 0; // is a subcontact - update meta contact if (cc->IsSub()) { DBCachedContact *ccMeta = CheckMeta(cc->parentID); if (ccMeta) { Meta_RemoveContactNumber(ccMeta, Meta_GetContactNumber(ccMeta, hContact), true); NotifyEventHooks(hSubcontactsChanged, ccMeta->contactID, 0); } return 0; } // not a subcontact - is it a metacontact? if (!cc->IsMeta()) return 0; if (cc->nSubs > 0) NotifyEventHooks(hSubcontactsChanged, hContact, 0); // remove & restore all subcontacts for (int i = 0; i < cc->nSubs; i++) { currDb->MetaDetouchSub(cc, i); // stop ignoring, if we were if (options.bSuppressStatus) CallService(MS_IGNORE_UNIGNORE, cc->pSubs[i], IGNOREEVENT_USERONLINE); } return 0; }
INT_PTR Meta_Delete(WPARAM wParam,LPARAM lParam) { DWORD metaID; // The wParam is a metacontact if ((metaID = db_get_dw((HANDLE)wParam, META_PROTO, META_ID, (DWORD)-1)) != (DWORD)-1) { if ( !lParam) { // check from recursion - see second half of this function if ( 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 (HANDLE 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,(DWORD)-1) == metaID) { db_unset(hContact, META_PROTO, "IsSubcontact"); db_unset(hContact, META_PROTO, META_LINK); db_unset(hContact, META_PROTO, "Handle"); db_unset(hContact, META_PROTO, "ContactNumber"); // unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus) Meta_RestoreGroup(hContact); db_unset(hContact, META_PROTO, "OldCListGroup"); // stop ignoring, if we were if (options.suppress_status) CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE); } } NotifyEventHooks(hSubcontactsChanged, (WPARAM)wParam, 0); CallService(MS_DB_CONTACT_DELETE,wParam,0); } else { HANDLE hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle", 0); DWORD num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", -1); if (num_contacts == 1) { if (IDYES == MessageBox(0, TranslateT(szDelMsg), TranslateT("Delete MetaContact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) Meta_Delete((WPARAM)hMeta,(LPARAM)1); return 0; } Meta_RemoveContactNumber(hMeta, db_get_dw((HANDLE)wParam, META_PROTO, "ContactNumber", -1)); } return 0; }
INT_PTR Meta_Delete(WPARAM hContact, LPARAM bSkipQuestion) { DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc == NULL) return 1; // The wParam is a metacontact if (cc->IsMeta()) { // check from recursion - see second half of this function if (!bSkipQuestion && IDYES != MessageBox(cli.hwndContactList, TranslateT("This will remove the metacontact permanently.\n\nProceed anyway?"), TranslateT("Are you sure?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2)) return 0; for (int i = cc->nSubs-1; i >= 0; i--) Meta_RemoveContactNumber(cc, i, false); NotifyEventHooks(hSubcontactsChanged, hContact, 0); CallService(MS_DB_CONTACT_DELETE, hContact, 0); } else if (cc->IsSub()) { if ((cc = currDb->m_cache->GetCachedContact(cc->parentID)) == NULL) return 2; if (cc->nSubs == 1) { if (IDYES == MessageBox(0, TranslateT(szDelMsg), TranslateT("Delete metacontact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) Meta_Delete(cc->contactID, 1); return 0; } Meta_RemoveContactNumber(cc, Meta_GetContactNumber(cc, hContact), true); } return 0; }
/** Delete a MetaContact from the database * * 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 */ INT_PTR Meta_Delete(WPARAM wParam,LPARAM lParam) { DWORD metaID; HANDLE hContact; if((metaID=DBGetContactSettingDword((HANDLE)wParam,META_PROTO,META_ID,(DWORD)-1))!=(DWORD)-1) {// The wParam is a metacontact if(!lParam) { // check from recursion - see second half of this function if(MessageBox((HWND)CallService(MS_CLUI_GETHWND,0,0),Translate("This will remove the MetaContact permanently.\n\nProceed Anyway?"), Translate("Are you sure?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2)!=IDYES) { return 0; } } hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0); while(hContact) { // Scans the database to get all the contacts that have been previously linked to this MetaContact if(DBGetContactSettingDword(hContact,META_PROTO,META_LINK,(DWORD)-1)==metaID) { // This contact is assigned to the MetaContact that will be deleted, clear the "MetaContacts" information DBDeleteContactSetting(hContact,META_PROTO,"IsSubcontact"); DBDeleteContactSetting(hContact,META_PROTO,META_LINK); DBDeleteContactSetting(hContact,META_PROTO,"Handle"); DBDeleteContactSetting(hContact,META_PROTO,"ContactNumber"); // unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus) Meta_RestoreGroup(hContact); DBDeleteContactSetting(hContact,META_PROTO,"OldCListGroup"); CallService(MS_PROTO_REMOVEFROMCONTACT,(WPARAM)hContact,(LPARAM)META_FILTER); // stop ignoring, if we were if(options.suppress_status) CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE); } hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0); } //DBDeleteContactSetting((HANDLE)wParam, META_PROTO, META_ID); //DBDeleteContactSetting((HANDLE)wParam, META_PROTO, "NumContacts"); //CallService(MS_PROTO_REMOVEFROMCONTACT,wParam,(LPARAM)META_PROTO); NotifyEventHooks(hSubcontactsChanged, (WPARAM)wParam, 0); CallService(MS_DB_CONTACT_DELETE,wParam,0); } else {// The wParam is a simple contact //if(lParam == 0) // return 1; // The function has been called by the menu of a simple contact. Should not happen. //else {// The function has been called by the edit dialog HANDLE hMeta = (HANDLE)DBGetContactSettingDword((HANDLE)wParam, META_PROTO, "Handle", 0); DWORD num_contacts = DBGetContactSettingDword(hMeta, META_PROTO, "NumContacts", -1); if(num_contacts == 1) { if(MessageBox(0,Translate("You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?"), Translate("Delete MetaContact?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)==IDYES) { // recurse - once Meta_Delete((WPARAM)hMeta,(LPARAM)1); } return 0; } Meta_RemoveContactNumber(hMeta, DBGetContactSettingDword((HANDLE)wParam,META_PROTO,"ContactNumber", -1)); CallService(MS_PROTO_REMOVEFROMCONTACT,(WPARAM)wParam,(LPARAM)META_FILTER); } } return 0; }