HANDLE Meta_Convert(HANDLE hSub) { HANDLE hMeta = NewMetaContact(); DBWriteContactSettingByte(hMeta, MODULE, "Default", 0); Meta_Assign(hSub, hMeta); DBVARIANT dbv; if(!DBGetContactSettingUTF8String(hSub, "CList", "Group", &dbv)) { DBWriteContactSettingUTF8String(hMeta, "CList", "Group", dbv.pszVal); DBFreeVariant(&dbv); } if(!DBGetContactSettingUTF8String(hSub, "CList", "MyHandle", &dbv)) { DBWriteContactSettingUTF8String(hMeta, "CList", "MyHandle", dbv.pszVal); DBFreeVariant(&dbv); } char *subProto = ContactProto(hSub); if(subProto) { if(!DBGetContactSettingUTF8String(hSub, subProto, "Nick", &dbv)) { DBWriteContactSettingUTF8String(hMeta, MODULE, "Nick", dbv.pszVal); DBFreeVariant(&dbv); } } Meta_CalcStatus(hMeta); return hMeta; }
INT_PTR ContactMenuAdd(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE)wParam; TCHAR buff[256]; mir_sntprintf(buff, 256, TranslateT("Adding %s..."), ContactName(hContact)); HANDLE hMeta = SelectMeta(buff); if(hMeta) Meta_Assign(hContact, hMeta); return 0; }
/** Convert the contact chosen into a MetaContact. * * 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 lParam : Allways set to 0. */ INT_PTR Meta_Convert(WPARAM wParam,LPARAM lParam) { HANDLE hMetaContact; DBVARIANT dbv; char *group = 0;//, *proto; // Get some information about the selected contact. // proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0); if(!DBGetContactSettingStringUtf((HANDLE)wParam,"CList","Group",&dbv)) { group = _strdup(dbv.pszVal); DBFreeVariant(&dbv); } // Create a new metacontact hMetaContact = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0); // Add the info for the metacontact if(hMetaContact) { DBWriteContactSettingDword(hMetaContact,META_PROTO,META_ID,nextMetaID); DBWriteContactSettingDword(hMetaContact,META_PROTO,"NumContacts",0); DBWriteContactSettingDword(NULL,META_PROTO,"NextMetaID",++nextMetaID); // Add the MetaContact protocol to the new meta contact CallService( MS_PROTO_ADDTOCONTACT, ( WPARAM )hMetaContact, ( LPARAM )META_PROTO ); if(group) { if(ServiceExists(MS_DB_CONTACT_GETSETTING_STR)) DBWriteContactSettingStringUtf(hMetaContact,"CList","Group",group); else DBWriteContactSettingString(hMetaContact,"CList","Group",group); } // Assign the contact to the MetaContact just created (and make default). if(!Meta_Assign((HANDLE)wParam,hMetaContact,TRUE)) { MessageBox(0,Translate("There was a problem in assigning the contact to the MetaContact"),Translate("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()) DBWriteContactSettingByte(hMetaContact, "CList", "Hidden", 1); } // Update the graphics CallService(MS_CLUI_SORTLIST,0,0); free(group); return (int)hMetaContact; }
INT_PTR Meta_Convert(WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; char *group = 0; // Get some information about the selected contact. if ( !db_get_utf((HANDLE)wParam, "CList", "Group", &dbv)) { group = _strdup(dbv.pszVal); db_free(&dbv); } // Create a new metacontact HANDLE hMetaContact = (HANDLE)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); // Add the MetaContact protocol to the new meta contact CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hMetaContact, (LPARAM)META_PROTO); if (group) db_set_utf(hMetaContact, "CList", "Group", group); // Assign the contact to the MetaContact just created (and make default). if ( !Meta_Assign((HANDLE)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()) db_set_b(hMetaContact, "CList", "Hidden", 1); } free(group); return (INT_PTR)hMetaContact; }
INT_PTR Meta_Convert(WPARAM wParam, LPARAM) { ptrT tszGroup(db_get_tsa(wParam, "CList", "Group")); // Create a new metacontact MCONTACT hMetaContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (hMetaContact == NULL) return NULL; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMetaContact); if (cc == NULL) return 0; db_set_dw(hMetaContact, META_PROTO, "NumContacts", 0); cc->nSubs = 0; currDb->MetaSetDefault(cc); // explicitly write default sub to a db // Add the MetaContact protocol to the new meta contact Proto_AddToContact(hMetaContact, META_PROTO); if (tszGroup) db_set_ts(hMetaContact, "CList", "Group", tszGroup); // Assign the contact to the MetaContact just created (and make default). 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, hMetaContact, 0); return 0; } // hide the contact if clist groups disabled (shouldn't create one anyway since menus disabled) if (!db_mc_isEnabled()) db_set_b(hMetaContact, "CList", "Hidden", 1); return hMetaContact; }
static INT_PTR CALLBACK Meta_SelectDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { DBCachedContact *cc = currDb->m_cache->GetCachedContact(lParam); if (cc == NULL) { DestroyWindow(hwndDlg); return TRUE; } if (cc->IsMeta()) { MessageBox(hwndDlg, TranslateT("This contact is a metacontact.\nYou can't add a metacontact to another metacontact.\n\nPlease choose another."), TranslateT("Metacontact conflict"), MB_ICONERROR); DestroyWindow(hwndDlg); return TRUE; } if (cc->IsSub()) { MessageBox(hwndDlg, TranslateT("This contact is already associated to a metacontact.\nYou cannot add a contact to multiple metacontacts."), TranslateT("Multiple metacontacts"), MB_ICONERROR); DestroyWindow(hwndDlg); return TRUE; } } SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); // user data is contact handle SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_ADD)); // Initialize the graphical part CheckDlgButton(hwndDlg, IDC_ONLYAVAIL, BST_CHECKED); // Initially checked; display all metacontacts is only an option // Besides, we can check if there is at least one metacontact to add the contact to. if (BuildList(GetDlgItem(hwndDlg, IDC_METALIST), FALSE) <= 0) { if (MessageBox(hwndDlg, TranslateT(szConvMsg), TranslateT("No suitable metacontact found"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1) == IDYES) Meta_Convert(lParam, 0); DestroyWindow(hwndDlg); return TRUE; } else { // get contact display name from clist TCHAR *ptszCDN = cli.pfnGetContactDisplayName(lParam, 0); if (!ptszCDN) ptszCDN = TranslateT("a contact"); // ... and set it to the Window title. TCHAR buf[256]; mir_sntprintf(buf, SIZEOF(buf), TranslateT("Adding %s..."), ptszCDN); SetWindowText(hwndDlg, buf); } ShowWindow(hwndDlg, SW_SHOWNORMAL); return TRUE; case WM_COMMAND: if (HIWORD(wParam) == LBN_DBLCLK) // emulate click ok Ok wParam = MAKEWPARAM(IDOK, BN_CLICKED); if (HIWORD(wParam) != BN_CLICKED) break; // Only clicks of buttons are relevant, let other COMMANDs through switch (LOWORD(wParam)) { case IDOK: { int item = SendDlgItemMessage(hwndDlg, IDC_METALIST, LB_GETCURSEL, 0, 0); // Get the index of the selected metacontact if (item == -1) return IDOK == MessageBox(hwndDlg, TranslateT("Please select a metacontact"), TranslateT("No metacontact selected"), MB_ICONHAND); MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); MCONTACT hMeta = (MCONTACT)SendMessage(GetDlgItem(hwndDlg, IDC_METALIST), LB_GETITEMDATA, item, 0); if (!Meta_Assign(hContact, hMeta, FALSE)) MessageBox(hwndDlg, TranslateT("Assignment to the metacontact failed."), TranslateT("Assignment failure"), MB_ICONERROR); } // fall through case IDCANCEL: DestroyWindow(hwndDlg); break; case IDC_CHK_SRT: SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE) ^ LBS_SORT); if (BuildList(GetDlgItem(hwndDlg, IDC_METALIST), IsDlgButtonChecked(hwndDlg, IDC_CHK_SRT) ? TRUE : FALSE) <= 0) { if (MessageBox(hwndDlg, TranslateT(szConvMsg), TranslateT("No suitable metacontact found"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1) == IDYES) Meta_Convert(lParam, 0); DestroyWindow(hwndDlg); return TRUE; } break; } break; case WM_DESTROY: // Free all allocated memory and return the focus to the CList HWND clist = GetParent(hwndDlg); Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); EndDialog(hwndDlg, TRUE); SetFocus(clist); return TRUE; } return FALSE; // All other Message are not handled }
// added 0.9.5.0 (22/3/05) // wParam=(HANDLE)hContact // lParam=(HANDLE)hMeta // add an existing contact to a metacontact INT_PTR MetaAPI_AddToMeta(WPARAM wParam, LPARAM lParam) { return Meta_Assign((HANDLE)wParam, (HANDLE)lParam, FALSE); }