Example #1
0
ContactListModelSelection::ContactListModelSelection(QList<ContactListItemProxy*> items)
	: QMimeData()
	, mimeData_(0)
{
	QDomDocument doc;
	QDomElement root = doc.createElement("items");
	root.setAttribute("version", "2.0");
	doc.appendChild(root);

	// TODO: maybe also embed a random instance-specific token to
	// prevent drag'n'drop with other running Psi instances?

	QStringList jids;

	foreach(ContactListItemProxy* itemProxy, items) {
		Q_ASSERT(itemProxy);

		PsiContact* contact = 0;
		ContactListNestedGroup* group = 0;
		ContactListAccountGroup* account = 0;
		if ((contact = dynamic_cast<PsiContact*>(itemProxy->item()))) {
			QDomElement tag = textTag(&doc, "contact", contact->jid().full());
			tag.setAttribute("account", contact->account()->id());
			tag.setAttribute("group", itemProxy->parent() ? itemProxy->parent()->fullName() : "");
			root.appendChild(tag);

			jids << contact->jid().full();
		}
		else if ((account = dynamic_cast<ContactListAccountGroup*>(itemProxy->item()))) {
			QDomElement tag = doc.createElement("account");
			tag.setAttribute("id", account->account()->id());
			root.appendChild(tag);

			jids << account->displayName();
		}
		else if ((group = dynamic_cast<ContactListNestedGroup*>(itemProxy->item()))) {
			// if group->fullName() consists only of whitespace when we'll try
			// to read it back we'll get an empty string, so we're using CDATA
			// QDomElement tag = textTag(&doc, "group", group->fullName());
			QDomElement tag = doc.createElement("group");
			QDomText text = doc.createCDATASection(TextUtil::escape(group->fullName()));
			tag.appendChild(text);

			root.appendChild(tag);

			jids << group->fullName();
		}
		else {
			qWarning("ContactListModelSelection::ContactListModelSelection(): Unable to serialize %d, unsupported type", itemProxy->item()->type());
		}
	}
bool YaPopupNotification::notify(int id, PsiEvent* event, int soundType)
{
	Q_ASSERT(event);

#ifndef YAPSI_ACTIVEX_SERVER
	// FIXME: should use PsiAccount::Private::noPopup()
	if (!event->account() || event->account()->status().type() != XMPP::Status::Online)
		return false;
#endif

	if (event->type() == PsiEvent::Message || event->type() == PsiEvent::Mood) {
		ChatDlg* chatDlg = event->account()->findChatDialog(event->from());
		if (!chatDlg)
			chatDlg = event->account()->findChatDialog(event->jid());

		if (chatDlg && chatDlg->isActiveTab())
			return false;
	}

	if (event->type() == PsiEvent::Message) {
#ifndef YAPSI_ACTIVEX_SERVER
		if (!PsiOptions::instance()->getOption("options.ya.popups.message.enable").toBool()) {
			return false;
		}
#endif
	}

	if (event->type() == PsiEvent::Mood) {
		MoodEvent* moodEvent = static_cast<MoodEvent*>(event);
		if (!event->account()->psi()->yaToasterCentral()->showToaster(YaToasterCentral::MoodChange, event->from(), moodEvent->mood())) {
			// qWarning("YaToasterCentral blocked mood change: %s %s", qPrintable(contact->jid().full()), qPrintable(mood));
			return false;
		}

		// qWarning("%s Changed mood to: %s", qPrintable(contact->jid().full()), qPrintable(mood));

#ifndef YAPSI_ACTIVEX_SERVER
		if (!PsiOptions::instance()->getOption("options.ya.popups.moods.enable").toBool()) {
			return false;
		}
#endif

#if defined(Q_WS_MAC) && defined(HAVE_GROWL)
		PsiContact* contact = event->account()->findContact(event->from());
		if (contact) {
			QString contactName = Ya::contactName(contact->name(), contact->jid().bare());
			PsiGrowlNotifier::instance()->moodChanged(event->account(), contact->jid(), contactName, moodEvent->mood());
		}
		return true;
#endif
	}

#ifdef YAPSI_ACTIVEX_SERVER
	if (event->account()->psi()->yaOnline()) {
		event->account()->psi()->yaOnline()->notify(id, event, soundType);
		return true;
	}
#endif

#if defined(Q_WS_MAC) && defined(HAVE_GROWL)
	// nasty-nasty YaToster steals focus on Mac OS X
	return true;
#endif

	YaPopupNotification* notification = new YaPopupNotification(id, event);
	int height = notification->sizeHint().height();
	notification->setMinimumSize(QSize(16, height));
	YaToster* toster = new YaToster(notification);
	toster->setStayForever(Ya::isSubscriptionRequest(event));
	toster->setTimes(1000, 5000, 500);
	toster->setSize(QSize(280, height));
	toster->start();
	return true;
}