int SiteDeleted(WPARAM wParam, LPARAM)
{
	MCONTACT hContact = wParam;
	if (mir_strcmp(GetContactProto(hContact), MODULENAME))
		return 0;

	ptrT contactName( db_get_tsa(hContact, MODULENAME, PRESERVE_NAME_KEY));

	// TEST GET NAME FOR CACHE
	TCHAR cachepath[MAX_PATH], cachedirectorypath[MAX_PATH], newcachepath[MAX_PATH + 50];
	GetModuleFileName(hInst, cachepath, _countof(cachepath));
	TCHAR *cacheend = _tcsrchr(cachepath, '\\');
	cacheend++;
	*cacheend = '\0';

	mir_sntprintf(cachedirectorypath, _T("%s")_T(MODULENAME)_T("cache\\"), cachepath);
	CreateDirectory(cachedirectorypath, NULL);
	mir_sntprintf(newcachepath, _T("%s")_T(MODULENAME)_T("cache\\%s.txt"), cachepath,  contactName);
	// file exists?
	if ( _taccess(newcachepath, 0) != -1) {
		FILE *pcachefile = _tfopen(newcachepath, _T("r"));
		if (pcachefile != NULL) {
			fclose(pcachefile);
			DeleteFile(newcachepath);
			db_set_s(hContact, MODULENAME, CACHE_FILE_KEY, "");
		}
	}
	return 0;
}
void ExchangeApproveDialog::appendRequestItems(const QList<IRosterExchangeItem> &AItems)
{
	for (QList<IRosterExchangeItem>::const_iterator it=AItems.constBegin(); it!=AItems.constEnd(); ++it)
	{
		QString actionText;
		IRosterItem ritem = FRoster->findItem(it->itemJid);
		if (it->action == ROSTEREXCHANGE_ACTION_ADD)
		{
			if (ritem.isNull())
			{
				if (it->groups.isEmpty())
					actionText = tr("Add new contact '%1 <%2>'").arg(it->name,it->itemJid.uBare());
				else
					actionText = tr("Add new contact '%1 <%2>' to the group: %3").arg(it->name,it->itemJid.uBare(),groupSetToString(it->groups));
				ui.chbSubscribe->setVisible(true);
			}
			else if (!it->groups.isEmpty())
			{
				actionText = tr("Copy contact '%1' to the group: %2").arg(contactName(it->itemJid),groupSetToString(it->groups-ritem.groups));
			}
		}
		else if (!ritem.isNull() && it->action == ROSTEREXCHANGE_ACTION_DELETE)
		{
			QSet<QString> oldGroups = it->groups;
			oldGroups.intersect(ritem.groups);
			if (it->groups.isEmpty())
				actionText = tr("Remove contact '%1' from contact list").arg(contactName(it->itemJid));
			else
				actionText = tr("Remove contact '%1' from the group: %2").arg(contactName(it->itemJid),groupSetToString(oldGroups));
		}
		else if (!ritem.isNull() && it->action == ROSTEREXCHANGE_ACTION_MODIFY)
		{
			QSet<QString> newGroups = it->groups - ritem.groups;
			QSet<QString> oldGroups = ritem.groups - it->groups;
			if (it->name != ritem.name)
			{
				actionText = tr("Rename contact '%1' to '%2'").arg(contactName(it->itemJid),it->name);
			}
			if (!newGroups.isEmpty())
			{
				if (!actionText.isEmpty())
					actionText += "; ";
				actionText += tr("Copy contact '%1' to the group: %2").arg(contactName(it->itemJid),groupSetToString(newGroups));
			}
			if (!oldGroups.isEmpty())
			{
				if (!actionText.isEmpty())
					actionText += "; ";
				actionText += tr("Remove contact '%1' from the group: %2").arg(contactName(it->itemJid),groupSetToString(oldGroups));
			}
		}

		if (!actionText.isEmpty())
		{
			QTableWidgetItem *actionItem = new QTableWidgetItem;
			actionItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);
			actionItem->setCheckState(Qt::Checked);
			actionItem->setText(actionText);

			ui.tbwItems->setRowCount(ui.tbwItems->rowCount()+1);
			ui.tbwItems->setItem(ui.tbwItems->rowCount()-1,COL_ACTION,actionItem);
			ui.tbwItems->verticalHeader()->SETRESIZEMODE(actionItem->row(),QHeaderView::ResizeToContents);

			FItems.insert(actionItem,*it);
		}
	}
}
ExchangeApproveDialog::ExchangeApproveDialog(IRoster *ARoster, const IRosterExchangeRequest &ARequest, QWidget *AParent) : QDialog(AParent)
{
	REPORT_VIEW;
	ui.setupUi(this);
	setAttribute(Qt::WA_DeleteOnClose,true);

	FRoster = ARoster;
	FRequest = ARequest;

	setWindowTitle(tr("Roster Modification - %1").arg(ARoster->streamJid().uBare()));
	setWindowIcon(IconStorage::staticStorage(RSR_STORAGE_MENUICONS)->getIcon(MNI_ROSTEREXCHANGE_REQUEST));

	ui.lblNotice->setText(tr("Contact '%1' offers you to make the following changes in your contact list:").arg(contactName(ARequest.contactJid)));

	ui.tbwItems->setWordWrap(true);
	ui.tbwItems->setTextElideMode(Qt::ElideNone);
	ui.tbwItems->setColumnCount(COL_COUNT);
	ui.tbwItems->setHorizontalHeaderLabels(QStringList()<<tr("Modification"));
	ui.tbwItems->horizontalHeader()->SETRESIZEMODE(COL_ACTION,QHeaderView::Stretch);

	ui.chbSubscribe->setChecked(true);
	ui.chbSubscribe->setVisible(false);

	connect(ui.btbButtons,SIGNAL(accepted()),SLOT(accept()));
	connect(ui.btbButtons,SIGNAL(rejected()),SLOT(reject()));

	connect(FRoster->xmppStream()->instance(),SIGNAL(aboutToClose()),SLOT(reject()));

	appendRequestItems(ARequest.items);
}