QString Buddy::display() const { if (isNull()) return QString(); QString result = data()->display().isEmpty() ? data()->nickName().isEmpty() ? data()->firstName() : data()->nickName() : data()->display(); if (result.isEmpty()) { if (!data()->contacts().isEmpty()) { Contact contact = data()->contacts().at(0); if (contact) { result = contact.id(); Account account = contact.contactAccount(); if (!account.accountIdentity().name().isEmpty()) result += QString(" (%1)").arg(account.accountIdentity().name()); } } } return result; }
QVariant AccountsModel::data(const QModelIndex &index, int role) const { Account acc = account(index); if (acc.isNull()) return QVariant(); switch (role) { case Qt::DisplayRole: if (IncludeIdInDisplay) return QString("%1 (%2)").arg(acc.accountIdentity().name(), acc.id()); else return acc.accountIdentity().name(); case Qt::DecorationRole: return acc.protocolHandler() ? acc.protocolHandler()->icon() : QVariant(); case AccountRole: return QVariant::fromValue<Account>(acc); case ItemTypeRole: return AccountRole; default: return QVariant(); } }
ConnectionErrorNotification::ConnectionErrorNotification(Account account, const QString &errorServer, const QString &errorMessage) : Notification(account, Chat::null, "ConnectionError", KaduIcon("dialog-error")), ErrorServer(errorServer), ErrorMessage(errorMessage) { setTitle(tr("Connection error")); setText(Qt::escape(tr("Connection error on account: %1 (%2)").arg(account.id()).arg(account.accountIdentity().name()))); if (!ErrorMessage.isEmpty()) { if (ErrorServer.isEmpty()) setDetails(Qt::escape(ErrorMessage)); else setDetails(Qt::escape(QString("%1 (%2)").arg(ErrorMessage).arg(ErrorServer))); } addCallback("connection-ignore-errors"); }
void AccountNotificationService::notifyConnectionError(const Account &account, const QString &errorServer, const QString &errorMessage) { if (account.property(QStringLiteral("notify:ignore-connection-errors"), false).toBool()) return; auto lastConnectionError = account.property(QStringLiteral("notify:last-connection-error"), QDateTime{}).toDateTime(); if (lastConnectionError.isValid() && lastConnectionError.addSecs(60) > QDateTime::currentDateTime()) return; account.addProperty(QStringLiteral("notify:last-connection-error"), QDateTime::currentDateTime(), CustomProperties::NonStorable); auto data = QVariantMap{}; data.insert(QStringLiteral("account"), qVariantFromValue(account)); data.insert(QStringLiteral("error-server"), errorServer); data.insert(QStringLiteral("error-message"), errorMessage); auto notification = Notification{}; notification.type = m_connectionErrorEvent.name(); notification.title = tr("Connection error"); notification.text = normalizeHtml(plainToHtml(tr("Connection error on account: %1 (%2)").arg(account.id(), account.accountIdentity().name()))); notification.data = std::move(data); notification.details = normalizeHtml(plainToHtml(errorDetails(errorServer, errorMessage))); notification.callbacks.append(QStringLiteral("connection-ignore-errors")); m_notificationService->notify(notification); }