コード例 #1
0
ファイル: status.cpp プロジェクト: partition/kadu
void Status::setType(const QString& type)
{
	Group = "Offline";
	DisplayName = "Offline";

	Type = type;

	StatusType *statusType = StatusTypeManager::instance()->statusType(Type);
	if (!statusType)
	{
		Type = "Offline";
		return;
	}
	else
		DisplayName = statusType->displayName();

	StatusGroup *statusGroup = statusType->statusGroup();
	if (statusGroup)
		Group = statusGroup->name();
}
コード例 #2
0
ファイル: parser.cpp プロジェクト: partition/kadu
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 == '[')