/* * Copyright (c) 2013 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include #include #include #include #include #include #include #include using namespace QtUtilities; namespace Swift { QString RosterTooltip::buildDetailedTooltip(ContactRosterItem* contact, QtScaledAvatarCache* cachedImageScaler) { QString tooltipTemplate; if (QApplication::layoutDirection() == Qt::RightToLeft) { tooltipTemplate = QString( "" "" "" "" "" "
" "" "" "

%3 %2

" "
%5%4
" "%6" "%7" "%8" "%9" "
"); } else { tooltipTemplate = QString( "" "" "" "" "" "
" "" "" "

%2 %3

" "
%4%5
" "%6" "%7" "%8" "%9" "
"); } // prepare tooltip QString fullName = P2QSTRING(contact->getDisplayName()); QString vCardSummary; VCard::ref vCard = contact->getVCard(); if (vCard) { fullName = P2QSTRING(vCard->getFullName()).trimmed(); if (fullName.isEmpty()) { fullName = (P2QSTRING(vCard->getGivenName()) + " " + P2QSTRING(vCard->getFamilyName())).trimmed(); } if (fullName.isEmpty()) { fullName = P2QSTRING(contact->getDisplayName()); } vCardSummary = buildVCardSummary(vCard); } else { contact->onVCardRequested(); } QString scaledAvatarPath = cachedImageScaler->getScaledAvatarPath(P2QSTRING(contact->getAvatarPath().empty() ? ":/icons/avatar.svg" : pathToString(contact->getAvatarPath()))); QString bareJID = contact->getDisplayJID().toString().empty() ? "" : "( " + P2QSTRING(contact->getDisplayJID().toString()) + " )"; QString presenceIconTag = QString("").arg(statusShowTypeToIconPath(contact->getStatusShow())); QString statusMessage = contact->getStatusText().empty() ? QObject::tr("(No message)") : P2QSTRING(contact->getStatusText()); QString idleString = P2QSTRING(contact->getIdleText()); if (!idleString.isEmpty()) { idleString = QObject::tr("Idle since %1").arg(idleString); idleString = htmlEscape(idleString) + "
"; } QString lastSeen = P2QSTRING(contact->getOfflineSinceText()); if (!lastSeen.isEmpty()) { lastSeen = QObject::tr("Last seen %1").arg(lastSeen); lastSeen = htmlEscape(lastSeen) + "
"; } QString mucOccupant= P2QSTRING(contact->getMUCAffiliationText()); if (!mucOccupant.isEmpty()) { mucOccupant = htmlEscape(mucOccupant) + "
"; } return tooltipTemplate.arg(scaledAvatarPath, htmlEscape(fullName), htmlEscape(bareJID), presenceIconTag, htmlEscape(statusMessage), mucOccupant, idleString, lastSeen, vCardSummary); } QString RosterTooltip::buildVCardSummary(VCard::ref vcard) { QString summary; summary = ""; // star | name | content QString currentBlock; foreach (const VCard::Telephone& tel, vcard->getTelephones()) { QString type = tel.isFax ? QObject::tr("Fax") : QObject::tr("Telephone"); QString field = buildVCardField(tel.isPreferred, type, htmlEscape(P2QSTRING(tel.number))); if (tel.isPreferred) { currentBlock = field; break; } currentBlock += field; } summary += currentBlock; currentBlock = ""; foreach (const VCard::EMailAddress& mail, vcard->getEMailAddresses()) { QString field = buildVCardField(mail.isPreferred, QObject::tr("E-Mail"), htmlEscape(P2QSTRING(mail.address))); if (mail.isPreferred) { currentBlock = field; break; } currentBlock += field; } summary += currentBlock; currentBlock = ""; foreach (const VCard::Organization& org, vcard->getOrganizations()) { QString field = buildVCardField(false, QObject::tr("Organization"), htmlEscape(P2QSTRING(org.name))); currentBlock += field; } summary += currentBlock; currentBlock = ""; foreach(const std::string& title, vcard->getTitles()) { QString field = buildVCardField(false, QObject::tr("Title"), htmlEscape(P2QSTRING(title))); currentBlock += field; } summary += currentBlock; summary += "
"; return summary; } QString RosterTooltip::buildVCardField(bool preferred, const QString& name, const QString& content) { QString rowTemplate; if (QApplication::layoutDirection() == Qt::RightToLeft) { rowTemplate = QString("%3%2%1"); } else { rowTemplate = QString("%1%2%3"); } return rowTemplate.arg(preferred ? "" : "", name, content); } }