示例#1
0
QuetzalAccount::QuetzalAccount(const QString &id, QuetzalProtocol *protocol) : Account(id, protocol)
{
	Q_ASSERT(!"Shouldn't use this constructor");
	m_isLoading = false;
	Config cfg = config();
	QString purpleId = id;
	if (protocol->id() == QLatin1String("irc")) {
		purpleId = cfg.value(QLatin1String("nicks"), QStringList()).value(0);
		purpleId += QLatin1Char('@');
		int size = cfg.beginArray("servers");
		if (size == 0) {
			qCritical("Invalid irc account without server info: \"%s\"", qPrintable(id));
			deleteLater();
			return;
		}
		cfg.setArrayIndex(0);
		purpleId += cfg.value(QLatin1String("hostName"), QString());
		cfg.endArray();
	}
	m_account = purple_account_new(purpleId.toUtf8(), protocol->plugin()->info->id);
	m_account->ui_data = this;
	fillStatusActions();
	setContactsFactory(new QuetzalContactsFactory(this));
//	if (PURPLE_PLUGIN_PROTOCOL_INFO(m_account->gc->prpl)->chat_info != NULL) {
//		addAction((new ActionGenerator(QIcon(), QT_TRANSLATE_NOOP("Quetzal", "Join groupchat"), this, SLOT(showJoinGroupChat())))->setType(1));
//	}
	debug() << "created!" << this << m_account->protocol_id;
	// Hack for anti-auto-connect
	for (GList *it = purple_presence_get_statuses(m_account->presence); it; it = it->next) {
		PurpleStatus *status = reinterpret_cast<PurpleStatus *>(it->data);
//		debug() << purple_status_type_get_primitive(purple_status_get_type(status))
//				<< !!purple_status_is_online(status)
//				<< purple_status_get_id(status)
//				<< purple_status_get_name(status);
		if (!purple_status_is_online(status)) {
			purple_presence_set_status_active(m_account->presence, purple_status_get_id(status), TRUE);
			break;
		}
	}


	m_isLoading = true;
	load(cfg);
	m_isLoading = false;
//	if (protocol->id() == "jabber" && id.contains("qutim.org")) {
	if (!purple_account_get_enabled(m_account, "qutim"))
		purple_account_set_enabled(m_account, "qutim", TRUE);

//		purple_account_connect(m_account);
//	} else
//		purple_account_set_enabled(m_account, "qutim", FALSE);
}
示例#2
0
Data IMInvoker::buddyToData(PurpleBuddy *buddy) {
	Data data;
	std::string buddyName = purple_buddy_get_name(buddy);

	if (purple_buddy_get_name(buddy))          data.compound["name"] = Data(purple_buddy_get_name(buddy), Data::VERBATIM);
	if (purple_buddy_get_alias(buddy))         data.compound["alias"] = Data(purple_buddy_get_alias(buddy), Data::VERBATIM);
	if (purple_buddy_get_alias_only(buddy))    data.compound["aliasOnly"] = Data(purple_buddy_get_alias_only(buddy), Data::VERBATIM);
	if (purple_buddy_get_server_alias(buddy))  data.compound["server"] = Data(purple_buddy_get_server_alias(buddy), Data::VERBATIM);

	PurpleGroup* group = purple_buddy_get_group(buddy);
	if (group) {
		if (purple_group_get_name(group))        data.compound["group"] = Data(purple_group_get_name(group), Data::VERBATIM);
	}

	PurpleBuddyIcon* icon = purple_buddy_get_icon(buddy);
	if (icon) {
		size_t iconSize = 0;
		gconstpointer iconData = purple_buddy_icon_get_data(icon, &iconSize);
		data.compound["icon"] = Data((char*)iconData, iconSize, "application/octet-stream", false);
	}

	PurplePresence* presence = purple_buddy_get_presence(buddy);

	if (presence) {
		GList *statusElem;
		GList *statusList = purple_presence_get_statuses(presence);
		PurpleStatus* status;

		for(statusElem = statusList; statusElem; statusElem = statusElem->next) {
			status = (PurpleStatus*)statusElem->data;
			const char* statusId = purple_status_get_id(status);
			PurpleStatusPrimitive statusPrimitive = purple_primitive_get_type_from_id(statusId);

			// only include active states
			if(statusPrimitive == PURPLE_STATUS_UNSET || !purple_presence_is_status_primitive_active(presence, statusPrimitive))
				continue;
			data.compound["status"].compound[statusId] = statusToData(status);
		}
	}

	return data;
}