Example #1
0
/** Scans the \c CHANGES and call the appropriate function for each change.
*
* @param chg : Structure holding all the change info (See CHANGES).
*/
void ApplyChanges(CHANGES *chg)
{
	HANDLE most_online;
	int i;

	// remove removed contacts
	for(i = 0; i < chg->num_deleted; i++) {
		Meta_Delete((WPARAM)chg->hDeletedContacts[i], 0);
		if(chg->hDeletedContacts[i] == chg->hDefaultContact)
			chg->hDefaultContact = 0;
		if(chg->hDeletedContacts[i] == chg->hOfflineContact)
			chg->hOfflineContact = 0;
	}

	// set contact positions
	for(i = 0; i < chg->num_contacts; i++) {
		if(Meta_GetContactNumber(chg->hContact[i]) != i)
			Meta_SwapContacts(chg->hMeta, Meta_GetContactNumber(chg->hContact[i]), i);
	}

	NotifyEventHooks(hSubcontactsChanged, (WPARAM)chg->hMeta, (LPARAM)chg->hDefaultContact);

	// set default
	if(chg->hDefaultContact)
		DBWriteContactSettingDword(chg->hMeta, META_PROTO, "Default", Meta_GetContactNumber(chg->hDefaultContact));
	else
		DBWriteContactSettingDword(chg->hMeta, META_PROTO, "Default", 0);
	NotifyEventHooks(hEventDefaultChanged, (WPARAM)chg->hMeta, (LPARAM)chg->hDefaultContact);

	// set offline
	if(chg->hOfflineContact)
		DBWriteContactSettingDword(chg->hMeta, META_PROTO, "OfflineSend", Meta_GetContactNumber(chg->hOfflineContact));
	else
		DBWriteContactSettingDword(chg->hMeta, META_PROTO, "OfflineSend", (DWORD)-1);

	// fix nick
	most_online = Meta_GetMostOnline(chg->hMeta);
	Meta_CopyContactNick(chg->hMeta, most_online);

	// fix status
	Meta_FixStatus(chg->hMeta);

	// fix avatar
	most_online = Meta_GetMostOnlineSupporting(chg->hMeta, PFLAGNUM_4, PF4_AVATARS);
	if(most_online) {
		PROTO_AVATAR_INFORMATION AI;

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

		if((int)CallProtoService(META_PROTO, PS_GETAVATARINFO, 0, (LPARAM)&AI) == GAIR_SUCCESS)
	        DBWriteContactSettingString(chg->hMeta, "ContactPhoto", "File",AI.filename);
	}

	if(MetaAPI_GetForceState((WPARAM)chg->hMeta, 0) != chg->force_default)
		MetaAPI_ForceDefault((WPARAM)chg->hMeta, 0);
}
Example #2
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);
		}
	}
}
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);
		}
	}
}
Example #4
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);
	}
}