/** 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; }
/** Called when the context-menu of a contact is about to be displayed * * 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 lParam : Always set to 0; */ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) { CLISTMENUITEM mi; DBVARIANT dbv; HANDLE hContact; char *proto; char buf[512], buffer2[512]; int i, iconIndex; WORD status; mi.flags = CMIM_FLAGS; mi.cbSize = sizeof(CLISTMENUITEM); if(DBGetContactSettingDword((HANDLE)wParam,META_PROTO,META_ID,-1) != (DWORD)-1) { int num_contacts, i; // save the mouse pos in case they open a subcontact menu GetCursorPos(&menuMousePoint); // This is a MetaContact, show the edit, force default, and the delete menu, and hide the others CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); //mi.flags |= CMIM_NAME; //if(DBGetContactSettingByte((HANDLE)wParam, META_PROTO, "ForceDefault", 0)) // mi.pszName = Translate("Unforce Default"); //else // mi.pszName = Translate("Force Default"); //CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuForceDefault, (LPARAM)&mi); mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); mi.flags = CMIM_FLAGS | CMIM_NAME | CMIF_HIDDEN; // we don't need delete - already in contact menu mi.pszName = Translate("Delete MetaContact"); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); //show subcontact menu items num_contacts = DBGetContactSettingDword((HANDLE)wParam, META_PROTO, "NumContacts", 0); for(i = 0; i < MAX_CONTACTS; i++) { if(i < num_contacts) { hContact = Meta_GetContactHandle((HANDLE)wParam, i); proto = _strdup((char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); if(!proto) status = ID_STATUS_OFFLINE; else status = DBGetContactSettingWord(hContact, proto, "Status", ID_STATUS_OFFLINE); if(options.menu_contact_label == DNT_UID) { strcpy(buf, "Login"); strcat(buf, _itoa(i, buffer2, 10)); DBGetContactSetting((HANDLE)wParam,META_PROTO,buf,&dbv); switch(dbv.type) { case DBVT_ASCIIZ: mir_snprintf(buf,512,"%s",dbv.pszVal); break; case DBVT_BYTE: mir_snprintf(buf,512,"%d",dbv.bVal); break; case DBVT_WORD: mir_snprintf(buf,512,"%d",dbv.wVal); break; case DBVT_DWORD: mir_snprintf(buf,512,"%d",dbv.dVal); break; default: buf[0] = 0; } DBFreeVariant(&dbv); mi.pszName = buf; mi.flags = 0; } else { char *name = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0); char *wname = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_UNICODE); if(wname && strncmp(name, wname, strlen(name)) != 0) { mi.pszName = wname; mi.flags = CMIF_UNICODE; } else { mi.pszName = name; mi.flags = 0; } } mi.flags |= CMIM_FLAGS | CMIM_NAME | CMIM_ICON; //mi.hIcon = LoadSkinnedProtoIcon(proto, status); iconIndex = (int)CallService(MS_CLIST_GETCONTACTICON, (WPARAM)hContact, 0); mi.hIcon = ImageList_GetIcon((HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0), iconIndex, 0);; free(proto); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); DestroyIcon(mi.hIcon); //CallService(MS_SKIN2_RELEASEICON, (WPARAM)mi.hIcon, 0); } else { mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); } } // show hide nudge menu item #define MS_NUDGE_SHOWMENU "NudgeShowMenu" // wParam = char *szProto // lParam = BOOL show { char serviceFunc[256]; hContact = Meta_GetMostOnline((HANDLE)wParam); mir_snprintf(serviceFunc, 256, "%s/SendNudge", (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); CallService(MS_NUDGE_SHOWMENU, (WPARAM)META_PROTO, (LPARAM)ServiceExists(serviceFunc)); } } else {// This is a simple contact if(!Meta_IsEnabled()) { // groups disabled - all meta menu options hidden mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); for(i = 0; i < MAX_CONTACTS; i++) { mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); } } else if(DBGetContactSettingDword((HANDLE)wParam,META_PROTO,META_LINK,(DWORD)-1)!=(DWORD)-1) { // The contact is affected to a metacontact. CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); mi.flags |= CMIM_NAME; mi.pszName = (char *)Translate("Remove from MetaContact"); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); for(i = 0; i < MAX_CONTACTS; i++) { mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); } } else { // The contact is neutral CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); mi.flags |= CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); for(i = 0; i < MAX_CONTACTS; i++) { mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); } } } return 0; }
int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; char buf[512], idStr[512]; WORD status; CLISTMENUITEM mi = { sizeof(mi) }; if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID,-1) != (DWORD)-1) { // save the mouse pos in case they open a subcontact menu GetCursorPos(&menuMousePoint); // This is a MetaContact, show the edit, force default, and the delete menu, and hide the others Menu_ShowItem(hMenuEdit, true); Menu_ShowItem(hMenuAdd, false); Menu_ShowItem(hMenuConvert, false); Menu_ShowItem(hMenuDefault, false); Menu_ShowItem(hMenuDelete, false); mi.flags = CMIM_NAME | CMIF_TCHAR; mi.ptszName = (TCHAR*)TranslateT("Remove from MetaContact"); Menu_ModifyItem(hMenuDelete, &mi); //show subcontact menu items int num_contacts = db_get_dw((HANDLE)wParam, META_PROTO, "NumContacts", 0); for (int i = 0; i < MAX_CONTACTS; i++) { if (i >= num_contacts) { Menu_ShowItem(hMenuContact[i], false); continue; } HANDLE hContact = Meta_GetContactHandle((HANDLE)wParam, i); char *szProto = GetContactProto(hContact); if ( !szProto) status = ID_STATUS_OFFLINE; else status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); if (options.menu_contact_label == DNT_UID) { strcpy(buf, "Login"); strcat(buf, _itoa(i, idStr, 10)); db_get((HANDLE)wParam, META_PROTO, buf, &dbv); switch(dbv.type) { case DBVT_ASCIIZ: mir_snprintf(buf,512,"%s",dbv.pszVal); break; case DBVT_BYTE: mir_snprintf(buf,512,"%d",dbv.bVal); break; case DBVT_WORD: mir_snprintf(buf,512,"%d",dbv.wVal); break; case DBVT_DWORD: mir_snprintf(buf,512,"%d",dbv.dVal); break; default: buf[0] = 0; } db_free(&dbv); mi.pszName = buf; mi.flags = 0; } else { mi.ptszName = pcli->pfnGetContactDisplayName(hContact, GCDNF_TCHAR); mi.flags = CMIF_TCHAR; } mi.flags |= CMIM_FLAGS | CMIM_NAME | CMIM_ICON; int iconIndex = CallService(MS_CLIST_GETCONTACTICON, (WPARAM)hContact, 0); mi.hIcon = ImageList_GetIcon((HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0), iconIndex, 0); Menu_ModifyItem(hMenuContact[i], &mi); DestroyIcon(mi.hIcon); } // show hide nudge menu item #define MS_NUDGE_SHOWMENU "NudgeShowMenu" // wParam = char *szProto // lParam = BOOL show char serviceFunc[256]; mir_snprintf(serviceFunc, 256, "%s%s", GetContactProto( Meta_GetMostOnline((HANDLE)wParam)), PS_SEND_NUDGE); CallService(MS_NUDGE_SHOWMENU, (WPARAM)META_PROTO, (LPARAM)ServiceExists(serviceFunc)); } else { // This is a simple contact if ( !Meta_IsEnabled()) { // groups disabled - all meta menu options hidden Menu_ShowItem(hMenuDefault, false); Menu_ShowItem(hMenuDelete, false); Menu_ShowItem(hMenuAdd, false); Menu_ShowItem(hMenuConvert, false); Menu_ShowItem(hMenuEdit, false); } else if (db_get_dw((HANDLE)wParam, META_PROTO, META_LINK,(DWORD)-1)!=(DWORD)-1) { // The contact is affected to a metacontact. Menu_ShowItem(hMenuDefault, true); mi.flags = CMIM_NAME | CMIF_TCHAR; mi.ptszName = (TCHAR*)TranslateT("Remove from MetaContact"); Menu_ModifyItem(hMenuDelete, &mi); Menu_ShowItem(hMenuAdd, false); Menu_ShowItem(hMenuConvert, false); Menu_ShowItem(hMenuEdit, false); } else { // The contact is neutral Menu_ShowItem(hMenuAdd, true); Menu_ShowItem(hMenuConvert, true); Menu_ShowItem(hMenuEdit, false); Menu_ShowItem(hMenuDelete, false); Menu_ShowItem(hMenuDefault, false); } for (int i = 0; i < MAX_CONTACTS; i++) Menu_ShowItem(hMenuContact[i], false); } return 0; }