Esempio n. 1
0
static QString getStatusIconPath(BuddyOrContact buddyOrContact)
{
	Buddy buddy = buddyOrContact.buddy();
	Contact contact = buddyOrContact.contact();

	if (buddy.isBlocked())
		return webKitPath(IconsManager::instance()->iconPath("kadu_icons", "16x16", "blocked"));

	if (contact.isBlocking())
		return webKitPath(IconsManager::instance()->iconPath("kadu_icons", "16x16", "blocking"));

	if (contact.contactAccount())
	{
		Protocol *protocol = contact.contactAccount().protocolHandler();
		if (protocol)
		{
			StatusTypeManager* statustypemanager = StatusTypeManager::instance();
			if (statustypemanager)
			{
				Status status = contact.currentStatus();
				QString iconpath = statustypemanager->statusIconFullPath(protocol->statusPixmapPath(), status.type(), !status.description().isEmpty(), false);
				if (!iconpath.isEmpty())
					return webKitPath(iconpath);
			}
		}
	}

	return QString();
}
Esempio n. 2
0
bool AvatarPainter::greyOut()
{
	if (!Configuration->avatarGreyOut())
		return false;

	Contact contact = Index.data(ContactRole).value<Contact>();
	return contact.currentStatus().isDisconnected();
}
Esempio n. 3
0
void JabberChatStateService::sendState(const Contact &contact, ChatState state)
{
	if (!m_client || !m_client->isConnected())
		return;

	if (!contact || contact.currentStatus().isDisconnected())
		return;

	auto receivedChatState = static_cast<QXmppMessage::State>(contact.property("jabber:received-chat-state", QXmppMessage::State::None).toInt());
	if (receivedChatState == QXmppMessage::State::None || receivedChatState == QXmppMessage::State::Gone)
		return;

	auto jabberAccountDetails = dynamic_cast<JabberAccountDetails *>(account().details());
	if (!jabberAccountDetails || !jabberAccountDetails->sendTypingNotification())
		return;

	auto xmppState = stateToXmppState(state);
	if (!jabberAccountDetails->sendGoneNotification() && (xmppState == QXmppMessage::State::Gone || xmppState == QXmppMessage::State::Inactive))
		xmppState = QXmppMessage::State::Paused;

	auto sentChatState = static_cast<QXmppMessage::State>(contact.property("jabber:sent-chat-state", QXmppMessage::State::None).toInt());
	// invalid transition
	if (sentChatState == QXmppMessage::State::None && (xmppState != QXmppMessage::State::Active && xmppState != QXmppMessage::State::Composing && xmppState != QXmppMessage::State::Gone))
		return;

	// don't send if it is the same as last sent state
	if (xmppState == sentChatState || xmppState == QXmppMessage::State::None)
		return;

	auto jid = m_resourceService->bestContactJid(contact);

	auto xmppMessage = QXmppMessage{};
	xmppMessage.setFrom(m_client.data()->clientPresence().id());
	xmppMessage.setStamp(QDateTime::currentDateTime());
	xmppMessage.setTo(jid.full());
	xmppMessage.setType(QXmppMessage::Chat);

	if (xmppState == QXmppMessage::State::Inactive && sentChatState == QXmppMessage::State::Composing)
	{
		// send intermediate state first
		xmppMessage.setState(QXmppMessage::State::Paused);
		m_client->sendPacket(xmppMessage);
	}

	if (xmppState == QXmppMessage::State::Composing && sentChatState == QXmppMessage::State::Inactive)
	{
		// send intermediate state first
		xmppMessage.setState(QXmppMessage::State::Active);
		m_client->sendPacket(xmppMessage);
	}

	xmppMessage.setState(xmppState);
	m_client->sendPacket(xmppMessage);

	// Save last state
	// if (sentChatState != QXmppMessage::State::Gone || xmppState == QXmppMessage::State::Active) I don't know why we have this condition
	contact.addProperty("jabber:sent-chat-state", static_cast<int>(xmppState), CustomProperties::NonStorable);
}
Esempio n. 4
0
TalkableFilter::FilterResult HideOfflineWithoutDescriptionTalkableFilter::filterContact(const Contact &contact)
{
	if (!m_enabled)
		return Undecided;

	auto const &status = contact.currentStatus();
	if (status.isDisconnected() && status.description().isEmpty())
		return Rejected;
	else
		return Undecided;
}
bool OnlineAndDescriptionBuddyFilter::acceptBuddy(const Buddy &buddy)
{
    if (!Enabled)
        return true;

    Contact preferredContact = BuddyPreferredManager::instance()->preferredContact(buddy, false);
    if (preferredContact.isNull())
        return false;

    Status status = preferredContact.currentStatus();
    return !status.isDisconnected() || !status.description().isEmpty();
}
Esempio n. 6
0
bool Firewall::checkChat(const Chat &chat, const Contact &sender, const QString &message, bool &ignore)
{
    kdebugf();

    if (!CheckChats)
        return false;

    // konferencja
    if (chat.contacts().count() > 1)
    {
        kdebugf2();
        return false;
    }

    if (!sender.ownerBuddy().isAnonymous() || Passed.contains(sender))
    {
        kdebugf2();
        return false;
    }

    if (chat.chatAccount().statusContainer()->status().type() == "Invisible" && DropAnonymousWhenInvisible)
    {
        writeLog(sender, tr("Chat with anonim silently dropped.\n") + "----------------------------------------------------\n");

        kdebugf2();
        return true;
    }

    if (IgnoreInvisible)
    {
        if (sender.currentStatus().isDisconnected())
        {
            QDateTime *dateTime = chat.chatAccount().data()->moduleData<QDateTime>("firewall-account-connected");
            if (dateTime && (*dateTime < QDateTime::currentDateTime()))
            {
                Protocol *protocol = chat.chatAccount().protocolHandler();
                if (!protocol)
                {
                    kdebugf2();
                    return false;
                }

                ChatService *chatService = protocol->chatService();
                if (!chatService)
                {
                    kdebugf2();
                    return false;
                }

                chatService->sendMessage(chat, tr("This message has been generated AUTOMATICALLY!\n\nI'm a busy person and I don't have time for stupid chats with the persons hiding itself. If you want to talk with me change the status to Online or Busy first."), true);
            }

            writeLog(sender, tr("Chat with invisible anonim ignored.\n") + "----------------------------------------------------\n");

            kdebugf2();
            return true;
        }
    }

    if (pattern.exactMatch(message.simplified()))
    {
        Passed.insert(sender);

        if (Confirmation)
        {
            Protocol *protocol = chat.chatAccount().protocolHandler();
            if (!protocol)
            {
                kdebugf2();
                return false;
            }

            ChatService *chatService = protocol->chatService();
            if (!chatService)
            {
                kdebugf2();
                return false;
            }

            chatService->sendMessage(chat, ConfirmationText, true);
        }

        writeLog(sender, tr("User wrote right answer!\n") + "----------------------------------------------------\n");

        ignore = true;

        kdebugf2();
        return false;
    }
    else
    {
        if (LastContact != sender && Search)
        {
            SearchWindow *sd = new SearchWindow(Core::instance()->kaduWindow(), sender.ownerBuddy());
            sd->show();
            sd->firstSearch();

            LastContact = sender;
        }

        kdebugm(KDEBUG_INFO, "%s\n", qPrintable(message));

        QDateTime *dateTime = chat.chatAccount().data()->moduleData<QDateTime>("firewall-account-connected");

        if (dateTime && (*dateTime < QDateTime::currentDateTime()))
        {
            Protocol *protocol = chat.chatAccount().protocolHandler();
            if (!protocol)
            {
                kdebugf2();
                return false;
            }

            ChatService *chatService = protocol->chatService();
            if (!chatService)
            {
                kdebugf2();
                return false;
            }

            chatService->sendMessage(chat, ConfirmationQuestion, true);
        }

        kdebugf2();
        return true;
    }
}
Esempio n. 7
0
QString Parser::parse(const QString &s, BuddyOrContact buddyOrContact, const QObject * const object, bool escape)
{
    Buddy buddy = buddyOrContact.buddy();
    Contact contact = buddyOrContact.contact();

    kdebugmf(KDEBUG_DUMP, "%s escape=%i\n", qPrintable(s), escape);
    int index = 0, i, len = s.length();
    QList<ParserToken> parseStack;

    static QHash<QChar, bool> searchChars;

    if (!searchChars.value('%', false))
    {
        searchChars['%'] = true;
        searchChars['['] = true;
        searchChars['{'] = true;
        searchChars['\\'] = true;
        searchChars['$'] = true;
        searchChars['@'] = true;
        searchChars['#'] = true;
        searchChars['}'] = true;
        searchChars[']'] = true;
    }

    bool allowExec = config_file.readBoolEntry("General", "AllowExecutingFromParser", false);
    searchChars['`'] = allowExec;
    searchChars['\''] = allowExec;

    while (index < len)
    {
        ParserToken pe1, pe;

        for(i = index; i < len; ++i)
            if (searchChars.value(s.at(i), false))
                break;

//		this is the same, but code above is muuuuch faster
//		i=s.find(QRegExp("%|`|\\{|\\[|'|\\}|\\]"), index);

        if (i != index)
        {
            pe1.type = ParserToken::PT_STRING;
            pe1.content = s.mid(index, i - index);
            parseStack.push_back(pe1);

            if (i == len)
                break;
        }

        char c = s.at(i).toAscii();
        if (c == '%')
        {
            ++i;
            if (i == len)
                break;
            pe.type = ParserToken::PT_STRING;

            switch (s.at(i).toAscii())
            {
            case 's':
                ++i;
                if (contact)
                {
                    StatusType *type = StatusTypeManager::instance()->statusType(contact.currentStatus().type());
                    if (type)
                        pe.content = type->displayName();
                }
                break; // TODO: 't' removed
            case 'q':
                ++i;
                if (contact)
                {
                    StatusContainer *container = contact.contactAccount().statusContainer();
                    if (container)
                        pe.content = container->statusIconPath(contact.currentStatus().type());
                }
                break;
            case 'd':
                ++i;
                if (contact)
                    pe.content = contact.currentStatus().description();

                if (escape)
                    HtmlDocument::escapeText(pe.content);
                if (config_file.readBoolEntry("Look", "ShowMultilineDesc"))
                {
                    pe.content.replace('\n', QLatin1String("<br/>"));
                    pe.content.replace(QRegExp("\\s\\s"), QString(" &nbsp;"));
                }
                break;
            case 'i':
                ++i;
                if (contact)
                    pe.content = contact.address().toString();
                break;
            case 'v':
                ++i;
                if (contact)
                    pe.content = contact.dnsName();
                break;
            case 'o':
                ++i;
                if (contact && contact.port() == 2)
                    pe.content = ' ';
                break;
            case 'p':
                ++i;
                if (contact && contact.port())
                    pe.content = QString::number(contact.port());
                break;
            case 'u':
                ++i;
                if (contact)
                    pe.content = contact.id();
                else if (buddy)
                    pe.content = buddy.mobile().isEmpty() ? buddy.email() : buddy.mobile();
                break;
            case 'h':
                ++i;
                if (contact && !contact.currentStatus().isDisconnected())
                    pe.content = contact.protocolVersion();
                break;
            case 'n':
                ++i;
                pe.content = buddy.nickName();
                if (escape)
                    HtmlDocument::escapeText(pe.content);
                break;
            case 'a':
                ++i;
                pe.content = buddy.display();
                if (escape)
                    HtmlDocument::escapeText(pe.content);
                break;
            case 'f':
                ++i;
                pe.content = buddy.firstName();
                if (escape)
                    HtmlDocument::escapeText(pe.content);
                break;
            case 'r':
                ++i;
                pe.content = buddy.lastName();
                if (escape)
                    HtmlDocument::escapeText(pe.content);
                break;
            case 'm':
                ++i;
                pe.content = buddy.mobile();
                break;
            case 'g':
            {
                ++i;
                QStringList groups;
                foreach (const Group &group, buddy.groups())
                    groups << group.name();
                pe.content = groups.join(",");
                break;
            }
            case 'e':
                ++i;
                pe.content = buddy.email();
                break;
            case 'x':
                ++i;
                if (contact)
                    pe.content = contact.maximumImageSize();
                break;
            case 'z':
                ++i;
                if (buddy)
                    pe.content = QString::number(buddy.gender());
                break;
            case '%':
                ++i;
            default:
                pe.content = '%';
            }
            parseStack.push_back(pe);
        }
        else if (c == '[')