Пример #1
0
//gets the handle for the default contact
//wParam=(HANDLE)hMetaContact
//lParam=0
//returns a handle to the default contact, or null on failure
INT_PTR MetaAPI_GetDefault(WPARAM wParam, LPARAM lParam) {
	DWORD default_contact_number = db_get_dw((HANDLE)wParam, META_PROTO, "Default", -1);
	if (default_contact_number != -1) {
		return (INT_PTR)Meta_GetContactHandle((HANDLE)wParam, default_contact_number);
	}
	return 0;
}
Пример #2
0
INT_PTR Meta_ContactMenuFunc(WPARAM hMeta, LPARAM lParam)
{
	DBCachedContact *cc = CheckMeta(hMeta);
	if (cc == NULL)
		return 0;

	MCONTACT hContact = Meta_GetContactHandle(cc, (int)lParam);

	if (options.menu_function == FT_MSG) {
		// open message window if protocol supports message sending or chat, else simulate double click
		char *proto = GetContactProto(hContact);
		if (proto) {
			INT_PTR caps = CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0);
			if ((caps & PF1_IMSEND) || (caps & PF1_CHAT)) {
				// set default contact for sending/status and open message window
				Meta_SetSrmmSub(hMeta, hContact);				
				db_mc_setDefaultNum(hMeta, lParam, false);
				CallService(MS_MSG_SENDMESSAGET, hMeta, 0);
			}
			else // protocol does not support messaging - simulate double click
				CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0);
		}
		else // protocol does not support messaging - simulate double click
			CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0);
	}
	else if (options.menu_function == FT_MENU) // show contact's context menu
		CallFunctionAsync(sttMenuThread, (void*)hContact);
	else if (options.menu_function == FT_INFO) // show user info for subcontact
		CallService(MS_USERINFO_SHOWDIALOG, hContact, 0);

	return 0;
}
Пример #3
0
//returns a handle to the default contact, or null on failure
MIR_CORE_DLL(MCONTACT) db_mc_getDefault(MCONTACT hMetaContact)
{
	DBCachedContact *cc = CheckMeta(hMetaContact);
	if (cc == NULL)
		return 0;

	return (cc->nDefault != -1) ? Meta_GetContactHandle(cc, cc->nDefault) : 0;
}
Пример #4
0
static int Meta_UserInfo(WPARAM wParam, LPARAM hMeta)
{
	DBCachedContact *cc = CheckMeta(hMeta);
	if (cc == NULL || cc->nDefault == -1)
		return 0;

	CallService(MS_USERINFO_SHOWDIALOG, Meta_GetContactHandle(cc, cc->nDefault), 0);
	return 1;
}
Пример #5
0
//forces the metacontact to send using a specific subcontact, using the subcontact's contact number
//wParam=(HANDLE)hMetaContact
//lParam=(DWORD)contact number
//returns 0 on success
INT_PTR MetaAPI_ForceSendContactNum(WPARAM wParam, LPARAM lParam) {
	HANDLE hContact = Meta_GetContactHandle((HANDLE)wParam, (int)lParam);
	HANDLE hMeta = (HANDLE)db_get_dw(hContact, META_PROTO, "Handle", 0);
	if ( !hContact || !hMeta || hMeta != (HANDLE)wParam || db_get_b(hMeta, META_PROTO, "ForceDefault", 0)) 
		return 1;

	db_set_dw(hMeta, META_PROTO, "ForceSend", (DWORD)hContact);

	NotifyEventHooks(hEventForceSend, wParam, (LPARAM)hContact);
	return 0;
}
Пример #6
0
//sets the default contact, using the subcontact's contact number
//wParam=(HANDLE)hMetaContact
//lParam=(DWORD)contact number
//returns 0 on success
INT_PTR MetaAPI_SetDefaultContactNum(WPARAM wParam, LPARAM lParam) {
	DWORD num_contacts = db_get_dw((HANDLE)wParam, META_PROTO, "NumContacts", -1);
	if (num_contacts == -1)
		return 1;
	if ((DWORD)lParam >= num_contacts || (DWORD)lParam < 0)
		return 1;
	if (db_set_dw((HANDLE)wParam, META_PROTO, "Default", (DWORD)lParam))
		return 1;

	NotifyEventHooks(hEventDefaultChanged, wParam, (LPARAM)Meta_GetContactHandle((HANDLE)wParam, (int)lParam));
	return 0;
}
Пример #7
0
// we assume that it could be called only for the metacontacts
static int Meta_SrmmIconClicked(WPARAM hMeta, LPARAM lParam)
{
	StatusIconClickData *sicd = (StatusIconClickData*)lParam;
	if (lstrcmpA(sicd->szModule, META_PROTO))
		return 0;

	DBCachedContact *cc = CheckMeta(hMeta);
	if (cc == NULL)
		return 0;

	HMENU hMenu = CreatePopupMenu();
	int iDefault = Meta_GetContactNumber(cc, db_mc_getSrmmSub(cc->contactID));

	MENUITEMINFO mii = { sizeof(mii) };
	mii.fMask = MIIM_ID | MIIM_STATE | MIIM_STRING;
	for (int i = 0; i < cc->nSubs; i++)	{
		char *szProto = GetContactProto(cc->pSubs[i]);
		if (szProto == NULL) continue;

		PROTOACCOUNT *pa = ProtoGetAccount(szProto);
		if (pa == NULL)
			continue;

		CMString tszNick;
		if (options.menu_contact_label == DNT_DID)
			tszNick = cli.pfnGetContactDisplayName(cc->pSubs[i], 0);
		else
			Meta_GetSubNick(hMeta, i, tszNick);
		tszNick.AppendFormat(_T(" [%s]"), pa->tszAccountName);

		mii.wID = i + 1;
		mii.fState = (i == iDefault) ? MFS_CHECKED : MFS_ENABLED;
		mii.dwTypeData = tszNick.GetBuffer();
		mii.cch = tszNick.GetLength();
		InsertMenuItem(hMenu, i, TRUE, &mii);
	}

	UINT res = TrackPopupMenu(hMenu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_BOTTOMALIGN | TPM_LEFTALIGN, sicd->clickLocation.x, sicd->clickLocation.y, 0, cli.hwndContactTree, NULL);
	if (res > 0) {
		MCONTACT hChosen = Meta_GetContactHandle(cc, res - 1);

		MetaSrmmData tmp = { cc->contactID };
		if (MetaSrmmData *p = arMetaWindows.find(&tmp))
			p->m_hSub = hChosen;

		db_mc_setDefault(cc->contactID, hChosen, true);
	}
	return 0;
}
Пример #8
0
/** Set/unset (i.e. toggle) contact to force use of default contact
*
* 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
					(This means the function has been called via the contact menu).
*/
INT_PTR Meta_ForceDefault(WPARAM wParam,LPARAM lParam)
{
	if(DBGetContactSettingDword((HANDLE)wParam,META_PROTO, META_ID, (DWORD)-1) != (DWORD)-1)
	{ // the wParam is a MetaContact

		BOOL current = DBGetContactSettingByte((HANDLE)wParam, META_PROTO, "ForceDefault", 0);
		current = !current;
		DBWriteContactSettingByte((HANDLE)wParam, META_PROTO, "ForceDefault", (BYTE)current);

		DBWriteContactSettingDword((HANDLE)wParam, META_PROTO, "ForceSend", 0);

		if(current) NotifyEventHooks(hEventForceSend, wParam, (LPARAM)Meta_GetContactHandle((HANDLE)wParam, DBGetContactSettingDword((HANDLE)wParam, META_PROTO, "Default", -1)));
		else NotifyEventHooks(hEventUnforceSend, wParam, 0);
	}
	return 0;
}
Пример #9
0
//sets the default contact, using the subcontact's number
MIR_CORE_DLL(int) db_mc_setDefaultNum(MCONTACT hMetaContact, int iNum, BOOL bWriteDb)
{
	DBCachedContact *cc = CheckMeta(hMetaContact);
	if (cc == NULL)
		return 1;
	if (iNum >= cc->nSubs || iNum < 0)
		return 1;

	if (cc->nDefault != iNum) {
		cc->nDefault = iNum;
		if (bWriteDb)
			currDb->MetaSetDefault(cc);

		NotifyEventHooks(hEventDefaultChanged, hMetaContact, Meta_GetContactHandle(cc, iNum));
	}
	return 0;
}
Пример #10
0
INT_PTR Meta_ForceDefault(WPARAM wParam,LPARAM lParam)
{
	// the wParam is a MetaContact
	if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID, (DWORD)-1) != (DWORD)-1) {
		BOOL current = db_get_b((HANDLE)wParam, META_PROTO, "ForceDefault", 0);
		current = !current;
		db_set_b((HANDLE)wParam, META_PROTO, "ForceDefault", (BYTE)current);

		db_set_dw((HANDLE)wParam, META_PROTO, "ForceSend", 0);

		if (current)
			NotifyEventHooks(hEventForceSend, wParam, (LPARAM)Meta_GetContactHandle((HANDLE)wParam, db_get_dw((HANDLE)wParam, META_PROTO, "Default", -1)));
		else
			NotifyEventHooks(hEventUnforceSend, wParam, 0);
	}
	return 0;
}
Пример #11
0
INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hwnd;
	char *str;
	int sel, i;

	switch(msg)
	{
		case WM_INITDIALOG:
		{	
			// Font necessary for all controls created with CreateWindowsEx
			//HFONT hfDefault = GetStockObject(DEFAULT_GUI_FONT);
			//HWND combo = GetDlgItem(hwndDlg,IDC_DEFAULT);
			int nb_contacts, default_contact_number, offline_contact_number;
			LVCOLUMN LvCol;

			TranslateDialogDefault( hwndDlg );

			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_EDIT));

			// Disable the 'Apply' button.
			EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),FALSE);

			// (from http://www.codeproject.com/listctrl/listview.asp)
			// initialize list
			hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
			SendMessage(hwnd,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT); // Set style

			// Create list columns
			ZeroMemory(&LvCol, sizeof(LvCol));
			LvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;    // Type of mask

			// Inserting Couloms as much as we want
			LvCol.pszText=Translate("Contact");              // First Header Text
			LvCol.cx=100;                                   // width of column
			SendMessage(hwnd,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol); // Insert/Show the coloum

			LvCol.pszText=Translate("Id");                            // Next coloum
			LvCol.cx=130;                                   // width of column
			SendMessage(hwnd,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol); // ...
			LvCol.pszText=Translate("Protocol");                            //
			LvCol.cx=100;                                   // width of column
			SendMessage(hwnd,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol); //
			LvCol.pszText=Translate("Default");                            //
			LvCol.cx=60;                                   // width of column
			SendMessage(hwnd,LVM_INSERTCOLUMN,3,(LPARAM)&LvCol); //
			LvCol.pszText=Translate("Send Offline");                            //
			LvCol.cx=85;                                   // width of column
			SendMessage(hwnd,LVM_INSERTCOLUMN,4,(LPARAM)&LvCol); //
	
			// disable buttons until a selection is made in the list
			hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM);
			EnableWindow(hwnd, FALSE);
			hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT);
			EnableWindow(hwnd, FALSE);
			hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE);
			EnableWindow(hwnd, FALSE);
			hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
			EnableWindow(hwnd, FALSE);
			hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
			EnableWindow(hwnd, FALSE);

			nb_contacts = DBGetContactSettingDword((HANDLE)lParam, META_PROTO, "NumContacts", 0);
			default_contact_number = DBGetContactSettingDword((HANDLE)lParam, META_PROTO, "Default", (DWORD)-1);
			offline_contact_number = DBGetContactSettingDword((HANDLE)lParam, META_PROTO, "OfflineSend", (DWORD)-1);

			changes.hMeta = (HANDLE)lParam;
			changes.num_contacts = nb_contacts;
			changes.num_deleted = 0;
			changes.hDefaultContact = Meta_GetContactHandle((HANDLE)lParam, default_contact_number);
			changes.hOfflineContact = Meta_GetContactHandle((HANDLE)lParam, offline_contact_number);
			for(i = 0; i < nb_contacts; i++)
				changes.hContact[i] = Meta_GetContactHandle((HANDLE)lParam, i);
			changes.force_default = MetaAPI_GetForceState((WPARAM)lParam, 0);

			SendMessage(hwndDlg, WMU_SETTITLE, 0, lParam);

			CheckDlgButton(hwndDlg, IDC_CHK_FORCEDEFAULT, changes.force_default);

			FillContactList(hwndDlg, &changes);
			return TRUE;
		}
		case WMU_SETTITLE:
			{

				char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, 0);
				if(os_unicode_enabled) {
					wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE),
						*swzContactDisplayName;

					// detect if the clist provided unicode display name by comparing with non-unicode
					if(szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0 && wcslen(swzCDN) >= strlen(szCDN)) { 
						swzContactDisplayName = swzCDN;
					} else {
						// no? convert to unicode
						if(szCDN) {
							swzContactDisplayName = (wchar_t *) _malloca(sizeof(wchar_t) * (strlen(szCDN) + 1));
							MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1);
						} else {
							swzContactDisplayName = TranslateW(L"(Unknown Contact)");
						}
					}				

					SetWindowTextW(GetDlgItem(hwndDlg,IDC_ED_NAME), swzContactDisplayName);
				} else {
					SetWindowText(GetDlgItem(hwndDlg,IDC_ED_NAME), szCDN);
				}
			}
			return TRUE;
		case WM_NOTIFY: // the message that is being sent always
			switch(LOWORD(wParam)) // hit control
			{
				case IDC_LST_CONTACTS:      // did we hit our ListView contorl?
					if(((LPNMHDR)lParam)->code == NM_CLICK) {
						hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
						sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
						// enable buttons
						hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM);
						EnableWindow(hwnd, sel!=-1);
						hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT);
						EnableWindow(hwnd, sel!=-1 && changes.hContact[sel] != changes.hDefaultContact);
						hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE);
						EnableWindow(hwnd, sel!=-1 && changes.hContact[sel] != changes.hOfflineContact);
						hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
						EnableWindow(hwnd, (sel > 0));
						hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
						EnableWindow(hwnd, (sel != -1) && (sel < changes.num_contacts - 1));
/*
					// custom draw stuff - change colour of listview things - doesn't affect selection :(
					} else if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW) {
						SetWindowLong(hwndDlg, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam));
						return TRUE;					
*/
					}					
					break;
			}
			break;
		case WM_COMMAND:
			switch(HIWORD(wParam))
			{
				case BN_CLICKED:	// A button ('Remove', 'Ok', 'Cancel' or 'Apply', normally) has been clicked
					switch(LOWORD(wParam))
					{
						case IDC_VALIDATE:			// Apply changes, if there is still one contact attached to the metacontact.
							if(changes.num_contacts == 0)	// Otherwise, delete the metacontact.
							{
								if(MessageBox(hwndDlg,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)
									return TRUE;
								else
								{
									Meta_Delete((WPARAM)changes.hMeta,(LPARAM)NULL);
									DestroyWindow(hwndDlg);
									return TRUE;
								}
							}
							ApplyChanges(&changes);

							// Disable the 'Apply' button.
							EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),FALSE);
							break;
						case IDOK:
							if(IsWindowEnabled(GetDlgItem(hwndDlg,IDC_VALIDATE)))
							{							// If there are changes that could be made,
								if(changes.num_contacts == 0)	// do the work that would have be done if
								{						// the button 'Apply' has been clicked.
									if(MessageBox(hwndDlg,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)
									{
										return TRUE;
									} else {
										Meta_Delete((WPARAM)changes.hMeta,(LPARAM)NULL);
										DestroyWindow(hwndDlg);
										return TRUE;
									}
								}
								ApplyChanges(&changes);
							}
							EndDialog(hwndDlg, IDOK);
							return TRUE;
						case IDCANCEL:	// Simply close the dialog
							EndDialog(hwndDlg, IDCANCEL);
							return TRUE;
						case IDC_BTN_SETDEFAULT:
							hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
							sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
							InvalidateRect(hwnd, 0, TRUE);
							changes.hDefaultContact = changes.hContact[sel];
							SendMessage(hwndDlg, WMU_SETTITLE, 0, (LPARAM)changes.hContact[sel]);

							FillContactList(hwndDlg, &changes);
							SetListSelection(hwnd, sel);
							// Disable set default button
							EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETDEFAULT),FALSE);
							// Enable the 'Apply' button.
							EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);

							// repaint list
							return TRUE;
						case IDC_BTN_SETOFFLINE:
							hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
							sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
							InvalidateRect(hwnd, 0, TRUE);
							changes.hOfflineContact = changes.hContact[sel];

							FillContactList(hwndDlg, &changes);
							SetListSelection(hwnd, sel);
							// Disable set offline button
							EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETOFFLINE),FALSE);
							// Enable the 'Apply' button.
							EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);

							// repaint list
							return TRUE;
						case IDC_BTN_REM:
							hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
							sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
							changes.num_contacts--;
							changes.hDeletedContacts[changes.num_deleted++] = changes.hContact[sel];
							if(changes.hDefaultContact == changes.hContact[sel]) {
								if(changes.num_contacts > 0) {
									changes.hDefaultContact = changes.hContact[0];
									str = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)changes.hDefaultContact, 0);
									SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),str);
								} else {
									changes.hDefaultContact = 0;
									SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),"None");
								}

							}

							for(i = sel; i < changes.num_contacts; i++)
								changes.hContact[i] = changes.hContact[i + 1];
							FillContactList(hwndDlg, &changes);
							// disable buttons
							hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM);
							EnableWindow(hwnd, FALSE);
							hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT);
							EnableWindow(hwnd, FALSE);
							hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE);
							EnableWindow(hwnd, FALSE);
							hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
							EnableWindow(hwnd, FALSE);
							hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
							EnableWindow(hwnd, FALSE);
							// Enable the 'Apply' button.
							EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
							return TRUE;
						case IDC_BTN_UP:
							hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
							sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected

							{
								HANDLE temp = changes.hContact[sel];
								changes.hContact[sel] = changes.hContact[sel - 1];
								changes.hContact[sel - 1] = temp;
							}
							FillContactList(hwndDlg, &changes);
							sel--;
							SetListSelection(hwnd, sel);

							hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
							EnableWindow(hwnd, (sel > 0));
							hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
							EnableWindow(hwnd, (sel < changes.num_contacts - 1));
							// Enable the 'Apply' button.
							EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
							return TRUE;
						case IDC_BTN_DOWN:
							hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
							sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected

							{
								HANDLE temp = changes.hContact[sel];
								changes.hContact[sel] = changes.hContact[sel + 1];
								changes.hContact[sel + 1] = temp;
							}
							FillContactList(hwndDlg, &changes);
							sel++;
							SetListSelection(hwnd, sel);

							hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
							EnableWindow(hwnd, (sel > 0));
							hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
							EnableWindow(hwnd, (sel < changes.num_contacts - 1));
							// Enable the 'Apply' button.
							EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
							return TRUE;
						case IDC_CHK_FORCEDEFAULT:
							changes.force_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_FORCEDEFAULT);
							// Enable the 'Apply' button.
							EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
							return TRUE;
					}
			}
			break;
		case WM_CLOSE:
			DestroyWindow(hwndDlg);
			return TRUE;

		case WM_DESTROY:
			ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
			EndDialog(hwndDlg, IDCANCEL);
			break;
	}

	return FALSE;
}
Пример #12
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;
}
Пример #13
0
// returns a subcontact with the given index
MIR_CORE_DLL(MCONTACT) db_mc_getSub(MCONTACT hMetaContact, int iNum)
{
	DBCachedContact *cc = CheckMeta(hMetaContact);
	return (cc == NULL) ? 0 : Meta_GetContactHandle(cc, iNum);
}
Пример #14
0
/** 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;
}
Пример #15
0
//gets the handle of a subcontact, using the subcontact's number
//wParam=(HANDLE)hMetaContact
//lParam=(DWORD)contact number
//returns a handle to the specified subcontact
INT_PTR MetaAPI_GetContact(WPARAM wParam, LPARAM lParam) {
	return (INT_PTR)Meta_GetContactHandle((HANDLE)wParam, (DWORD)lParam);
}
Пример #16
0
int Meta_ModifyMenu(WPARAM hMeta, LPARAM)
{
	DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMeta);
	if (cc == NULL)
		return 0;
		
	Menu_ShowItem(hMenuRoot, false);

	if (cc->IsMeta()) {
		// 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);
		Menu_ModifyItem(hMenuDelete, LPGENT("Remove from metacontact"));

		// show subcontact menu items
		CMString tszNick;
		for (int i = 0; i < MAX_CONTACTS; i++) {
			if (i >= cc->nSubs) {
				Menu_ShowItem(hMenuContact[i], false);
				continue;
			}

			MCONTACT hContact = Meta_GetContactHandle(cc, i);
			LPCTSTR ptszName;

			if (options.menu_contact_label == DNT_UID) {
				Meta_GetSubNick(hMeta, i, tszNick);
				ptszName = tszNick.GetBuffer();
			}
			else ptszName = cli.pfnGetContactDisplayName(hContact, 0);

			int iconIndex = CallService(MS_CLIST_GETCONTACTICON, hContact, 0);
			HICON hIcon = ImageList_GetIcon((HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0), iconIndex, 0);
			Menu_ModifyItem(hMenuContact[i], ptszName, hIcon, 0);
			DestroyIcon(hIcon);
			
			Menu_ShowItem(hMenuRoot, true);
		}

		// show hide nudge menu item
		char serviceFunc[256];
		mir_snprintf(serviceFunc, _countof(serviceFunc), "%s%s", GetContactProto(Meta_GetMostOnline(cc)), PS_SEND_NUDGE);
		CallService(MS_NUDGE_SHOWMENU, (WPARAM)META_PROTO, ServiceExists(serviceFunc));
		return 0;
	}

	PROTOACCOUNT *pa = Proto_GetAccount(cc->szProto);
	if (!db_mc_isEnabled() || !pa || pa->bIsVirtual) {
		// 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);
		return 0;
	}
	
	// the contact is affected to a metacontact
	if (cc->IsSub()) {
		Menu_ShowItem(hMenuDefault, true);

		Menu_ModifyItem(hMenuDelete, LPGENT("Remove from metacontact"));
		Menu_ShowItem(hMenuDelete, true);

		Menu_ShowItem(hMenuAdd, false);
		Menu_ShowItem(hMenuConvert, false);
		Menu_ShowItem(hMenuEdit, false);
	}
	else {
		// The contact is neutral
		bool bHideChat = db_get_b(hMeta, cc->szProto, "ChatRoom", 0) == 0;
		Menu_ShowItem(hMenuAdd, bHideChat);
		Menu_ShowItem(hMenuConvert, bHideChat);
		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;
}
Пример #17
0
void Meta_RemoveContactNumber(DBCachedContact *ccMeta, int number, bool bUpdateInfo)
{
	if (ccMeta == NULL)
		return;

	// make sure this contact thinks it's part of this metacontact
	DBCachedContact *ccSub = currDb->m_cache->GetCachedContact(Meta_GetContactHandle(ccMeta, number));
	if (ccSub != NULL) {
		if (ccSub->parentID == ccMeta->contactID) {
			db_unset(ccSub->contactID, "CList", "Hidden");

			// stop ignoring, if we were
			if (options.bSuppressStatus)
				CallService(MS_IGNORE_UNIGNORE, ccSub->contactID, 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 < ccMeta->nSubs; i++)
		Meta_SwapContacts(ccMeta, i, i - 1);

	// remove the last one
	int id = ccMeta->nSubs - 1;
	char buffer[512];
	mir_snprintf(buffer, "Handle%d", id);
	db_unset(ccMeta->contactID, META_PROTO, buffer);

	mir_snprintf(buffer, "Protocol%d", id);
	db_unset(ccMeta->contactID, META_PROTO, buffer);

	mir_snprintf(buffer, "Status%d", id);
	db_unset(ccMeta->contactID, META_PROTO, buffer);

	mir_snprintf(buffer, "StatusString%d", id);
	db_unset(ccMeta->contactID, META_PROTO, buffer);

	mir_snprintf(buffer, "Login%d", id);
	db_unset(ccMeta->contactID, META_PROTO, buffer);

	mir_snprintf(buffer, "Nick%d", id);
	db_unset(ccMeta->contactID, META_PROTO, buffer);

	mir_snprintf(buffer, "CListName%d", id);
	db_unset(ccMeta->contactID, META_PROTO, buffer);

	if (ccSub != NULL) {
		ccSub->parentID = 0;
		currDb->MetaDetouchSub(ccMeta, ccMeta->nSubs - 1);

		currDb->MetaSplitHistory(ccMeta, ccSub);
	}

	// if the default contact was equal to or greater than 'number', decrement it (and deal with ends)
	if (ccMeta->nDefault >= number) {
		int iNumber = ccMeta->nDefault-1;
		if (iNumber < 0)
			iNumber = 0;
		db_mc_setDefaultNum(ccMeta->contactID, iNumber, true);
	}
	
	ccMeta->nSubs--;
	db_set_dw(ccMeta->contactID, META_PROTO, "NumContacts", ccMeta->nSubs);

	if (bUpdateInfo) {
		// fix nick
		Meta_CopyContactNick(ccMeta, Meta_GetMostOnline(ccMeta));

		// fix status
		Meta_FixStatus(ccMeta);

		// fix avatar
		MCONTACT hContact = Meta_GetMostOnlineSupporting(ccMeta, PFLAGNUM_4, PF4_AVATARS);
		if (hContact) {
			PROTO_AVATAR_INFORMATION ai = { 0 };
			ai.hContact = ccMeta->contactID;
			ai.format = PA_FORMAT_UNKNOWN;
			_tcsncpy_s(ai.filename, _T("X"), _TRUNCATE);

			if (CallProtoService(META_PROTO, PS_GETAVATARINFO, 0, (LPARAM)&ai) == GAIR_SUCCESS)
				db_set_ts(ccMeta->contactID, "ContactPhoto", "File", ai.filename);
		}
	}
}
Пример #18
0
void Meta_RemoveContactNumber(HANDLE hMeta, int number) {
	int i, num_contacts, default_contact;
	HANDLE hContact;//, handle;

	char buffer[512], buffer2[512];

	num_contacts = DBGetContactSettingDword(hMeta, META_PROTO, "NumContacts", 0);
	default_contact = DBGetContactSettingDword(hMeta, META_PROTO, "Default", -1);
	if(number >= 0 && number < num_contacts) {

		// get the handle
		hContact = Meta_GetContactHandle(hMeta, number);

		// make sure this contact thinks it's part of this metacontact
		if((HANDLE)DBGetContactSettingDword(hContact,META_PROTO,"Handle", 0) == hMeta) {

			// remove link to meta contact
			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_PROTO);
			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);
		}

		// remove history from metacontact
		//Meta_RemoveHistory(hMeta, hContact);

		// each contact from 'number' upwards will be moved down one
		// and the last one will be deleted
		for(i = number + 1; i < num_contacts; i++) {
			Meta_SwapContacts(hMeta, i, i-1);
		}

		// remove the last one
		strcpy(buffer, "Protocol");
		strcat(buffer, _itoa((num_contacts - 1), buffer2, 10));
		DBDeleteContactSetting(hMeta, META_PROTO, buffer);
		strcpy(buffer, "Status");
		strcat(buffer, _itoa((num_contacts - 1), buffer2, 10));
		DBDeleteContactSetting(hMeta, META_PROTO, buffer);
		strcpy(buffer, "Handle");
		strcat(buffer, _itoa((num_contacts - 1), buffer2, 10));
		DBDeleteContactSetting(hMeta, META_PROTO, buffer);
		strcpy(buffer, "StatusString");
		strcat(buffer, _itoa((num_contacts - 1), buffer2, 10));
		DBDeleteContactSetting(hMeta, META_PROTO, buffer);
		strcpy(buffer, "Login");
		strcat(buffer, _itoa((num_contacts - 1), buffer2, 10));
		DBDeleteContactSetting(hMeta, META_PROTO, buffer);
		strcpy(buffer, "Nick");
		strcat(buffer, _itoa((num_contacts - 1), buffer2, 10));
		DBDeleteContactSetting(hMeta, META_PROTO, buffer);
		strcpy(buffer, "CListName");
		strcat(buffer, _itoa((num_contacts - 1), buffer2, 10));
		DBDeleteContactSetting(hMeta, META_PROTO, buffer);

		// if the default contact was equal to or greater than 'number', decrement it (and deal with ends)
		if(default_contact >= number) {
			default_contact--;
			if(default_contact < 0) 
				default_contact = 0;

			DBWriteContactSettingDword(hMeta, META_PROTO, "Default", (DWORD)default_contact);
			NotifyEventHooks(hEventDefaultChanged, (WPARAM)hMeta, (LPARAM)Meta_GetContactHandle(hMeta, default_contact));
		}
		num_contacts--;
		DBWriteContactSettingDword(hMeta, META_PROTO, "NumContacts", (DWORD)num_contacts);

		// fix nick
		hContact = Meta_GetMostOnline(hMeta);
		Meta_CopyContactNick(hMeta, hContact);

		// fix status
		Meta_FixStatus(hMeta);

		// fix avatar
		hContact = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS);
		if(hContact) {
			PROTO_AVATAR_INFORMATION AI;

			AI.cbSize = sizeof(AI);
			AI.hContact = hMeta;
			AI.format = PA_FORMAT_UNKNOWN;
			strcpy(AI.filename, "X");

			if((int)CallProtoService(META_PROTO, PS_GETAVATARINFO, 0, (LPARAM)&AI) == GAIR_SUCCESS)
				DBWriteContactSettingString(hMeta, "ContactPhoto", "File",AI.filename);
		}
	}
}
Пример #19
0
void Meta_RemoveContactNumber(HANDLE hMeta, int number)
{
	int num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", 0);
	int default_contact = db_get_dw(hMeta, META_PROTO, "Default", -1);
	if (number < 0 && number >= num_contacts)
		return;

	// get the handle
	HANDLE hContact = Meta_GetContactHandle(hMeta, number);

	// make sure this contact thinks it's part of this metacontact
	if ((HANDLE)db_get_dw(hContact, META_PROTO, "Handle", 0) == hMeta) {
		// remove link to meta contact
		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);
	}

	// each contact from 'number' upwards will be moved down one
	// and the last one will be deleted
	for (int i = number + 1; i < num_contacts; i++)
		Meta_SwapContacts(hMeta, i, i-1);

	// remove the last one
	char buffer[512], idStr[20];
	_itoa(num_contacts-1, idStr, 10);
	strcpy(buffer, "Protocol"); strcat(buffer, idStr);
	db_unset(hMeta, META_PROTO, buffer);

	strcpy(buffer, "Status"); strcat(buffer, idStr);
	db_unset(hMeta, META_PROTO, buffer);

	strcpy(buffer, "Handle"); strcat(buffer, idStr);
	db_unset(hMeta, META_PROTO, buffer);

	strcpy(buffer, "StatusString"); strcat(buffer, idStr);
	db_unset(hMeta, META_PROTO, buffer);

	strcpy(buffer, "Login"); strcat(buffer, idStr);
	db_unset(hMeta, META_PROTO, buffer);

	strcpy(buffer, "Nick"); strcat(buffer, idStr);
	db_unset(hMeta, META_PROTO, buffer);

	strcpy(buffer, "CListName"); strcat(buffer, idStr);
	db_unset(hMeta, META_PROTO, buffer);

	// if the default contact was equal to or greater than 'number', decrement it (and deal with ends)
	if (default_contact >= number) {
		default_contact--;
		if (default_contact < 0)
			default_contact = 0;

		db_set_dw(hMeta, META_PROTO, "Default", (DWORD)default_contact);
		NotifyEventHooks(hEventDefaultChanged, (WPARAM)hMeta, (LPARAM)Meta_GetContactHandle(hMeta, default_contact));
	}
	num_contacts--;
	db_set_dw(hMeta, META_PROTO, "NumContacts", (DWORD)num_contacts);

	// fix nick
	hContact = Meta_GetMostOnline(hMeta);
	Meta_CopyContactNick(hMeta, hContact);

	// fix status
	Meta_FixStatus(hMeta);

	// fix avatar
	hContact = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS);
	if (hContact) {
		PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) };
		AI.hContact = hMeta;
		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);
	}
}