示例#1
0
void Channel::appendText(QString sender, QString inText, MessageType type) {
    // Postpend post with images in image tags
    QString postpendedImageTags = "";
    QStringList foundLinks;
    QRegExp imageRegex(".*(href=\"(([^>]+)\\.*)\").*");
    int pos = 0;
    while ((pos = imageRegex.indexIn(inText, pos)) != -1) {
        // Undoing previous html encoding for ampersands
        QString imageUrl = imageRegex.cap(2).replace("&","&");
        if(!imageUrl.startsWith("http", Qt::CaseInsensitive)) {
            imageUrl = "http://" + imageUrl;
        }
        postpendedImageTags += QString("<br /><a href=\"%1\"><img src=\"%1\" /></a>").arg(imageUrl);
        foundLinks.append(imageUrl);
        pos += imageRegex.matchedLength();
    }
    inText += postpendedImageTags;

    // Build HTML wrapper for message
    Server *server = this->getServer();
    QRegExp usernameRX = server->getNicknameRegex();
    bool textContainsUser = inText.contains(usernameRX);

    QDateTime currentTime = QDateTime::currentDateTime();
    QString currentTimeStr = currentTime.toString("h:mmap");

    QString tableRow = "";
    if (type == Channel::MessageTypeEmote)
    {
        tableRow = "<table class=\"msg-emote\" width=\"100%\"><tr>";
    }
    else if (type == Channel::MessageTypeTopic)
    {
        tableRow = "<table class=\"msg-topic\" width=\"100%\"><tr>";
    }
    else if (type == Channel::MessageTypeInfo)
    {
        tableRow = "<table class=\"msg-info\" width=\"100%\"><tr>";
    }
    else if (textContainsUser)
    {
        tableRow = "<table class=\"msg-mentioned\" width=\"100%\"><tr>";
    }
    else
    {
        tableRow = "<table width=\"100%\"><tr>";
    }
        tableRow += "<th class=\"col-name\" width=\"115\" align=\"right\">" + getStyledUserString(sender) + "</th>";
        tableRow += "<td class=\"col-message\"><p class=\"message\">" + inText + "</p></td>";
        tableRow += "<td class=\"col-meta\" width=\"50\"><h6 class=\"metainfo\">" + currentTimeStr +"</h6></td>";
        tableRow += "</tr></table>";
    text.append(tableRow);
    Session *session = server->getSession();
    session->emitMessageReceived(server, this, tableRow, foundLinks, type);
}
示例#2
0
void VNTRSSItem::setDescription(const QString &description) {
    VNTRSSCommon::setDescription(description);

    if (mImageUrl.isEmpty()) {
        QRegExp imageRegex("src=\"?(http://|https://)(www)?[a-zA-Z0-9~\\+\\$\\=\\%\\^\\&\\!\\-\\#\\_\\?./]+(\\.jpg|\\.JPG|\\.png|\\.PNG|\\.jpeg|\\.JPEG)\"?");

        if (imageRegex.indexIn(description) != -1) {
            this->setImageUrl(imageRegex.cap().remove("src=").remove('"'));
        }
    }
}