diff --git a/src/accountlistmodel.cpp b/src/accountlistmodel.cpp index 198ac4fb8..58b9058d9 100644 --- a/src/accountlistmodel.cpp +++ b/src/accountlistmodel.cpp @@ -6,53 +6,59 @@ AccountListModel::AccountListModel(QObject* parent) : QAbstractListModel(parent) {} void AccountListModel::setController(Controller* value) { - if (m_controller != value) { - beginResetModel(); - m_connections.clear(); - - m_controller = value; - - for (auto c : m_controller->connections()) m_connections.append(c); - - connect(m_controller, &Controller::connectionAdded, this, - [=](Connection* conn) { - if (!conn) { - } - beginInsertRows(QModelIndex(), m_connections.count(), - m_connections.count()); - m_connections.append(conn); - endInsertRows(); - }); - connect(m_controller, &Controller::connectionDropped, this, - [=](Connection* conn) { - qDebug() << "Dropping connection" << conn->userId(); - if (!conn) { - qDebug() << "Trying to remove null connection"; - return; - } - conn->disconnect(this); - const auto it = - std::find(m_connections.begin(), m_connections.end(), conn); - if (it == m_connections.end()) - return; // Already deleted, nothing to do - const int row = it - m_connections.begin(); - beginRemoveRows(QModelIndex(), row, row); - m_connections.erase(it); - endRemoveRows(); - }); - emit controllerChanged(); + if (m_controller == value) { + return; } + + beginResetModel(); + + m_connections.clear(); + m_controller = value; + m_connections += m_controller->connections(); + + connect(m_controller, &Controller::connectionAdded, this, + [=](Connection* conn) { + if (!conn) { + return; + } + beginInsertRows(QModelIndex(), m_connections.count(), + m_connections.count()); + m_connections.append(conn); + endInsertRows(); + }); + connect(m_controller, &Controller::connectionDropped, this, + [=](Connection* conn) { + qDebug() << "Dropping connection" << conn->userId(); + if (!conn) { + qDebug() << "Trying to remove null connection"; + return; + } + conn->disconnect(this); + const auto it = + std::find(m_connections.begin(), m_connections.end(), conn); + if (it == m_connections.end()) + return; // Already deleted, nothing to do + const int row = it - m_connections.begin(); + beginRemoveRows(QModelIndex(), row, row); + m_connections.erase(it); + endRemoveRows(); + }); + emit controllerChanged(); } QVariant AccountListModel::data(const QModelIndex& index, int role) const { - if (!index.isValid()) return QVariant(); + if (!index.isValid()) { + return {}; + } if (index.row() >= m_connections.count()) { qDebug() << "AccountListModel, something's wrong: index.row() >= " "m_users.count()"; - return QVariant(); + return {}; } + auto m_connection = m_connections.at(index.row()); + if (role == UserRole) { return QVariant::fromValue(m_connection->user()); } @@ -60,18 +66,22 @@ QVariant AccountListModel::data(const QModelIndex& index, int role) const { return QVariant::fromValue(m_connection); } - return QVariant(); + return {}; } int AccountListModel::rowCount(const QModelIndex& parent) const { - if (parent.isValid()) return 0; + if (parent.isValid()) { + return 0; + } return m_connections.count(); } QHash AccountListModel::roleNames() const { QHash roles; + roles[UserRole] = "user"; roles[ConnectionRole] = "connection"; + return roles; } diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index f1e7a8a7c..d3de9af34 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -343,8 +343,8 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { if (evt.isRedacted()) { auto reason = evt.redactedBecause()->reason(); return (reason.isEmpty()) - ? tr("Redacted") - : tr("Redacted: %1").arg(evt.redactedBecause()->reason()); + ? tr("[REDACTED]") + : tr("[REDACTED: %1]").arg(evt.redactedBecause()->reason()); } if (auto e = eventCast(&evt)) { diff --git a/src/notifications/managermac.mm b/src/notifications/managermac.mm index 782be1f29..bcd8c776d 100644 --- a/src/notifications/managermac.mm +++ b/src/notifications/managermac.mm @@ -4,45 +4,34 @@ #include @interface NSUserNotification (CFIPrivate) -- (void)set_identityImage:(NSImage *)image; +- (void)set_identityImage:(NSImage*)image; @end -NotificationsManager::NotificationsManager(QObject *parent): QObject(parent) -{ +NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {} +void NotificationsManager::postNotification(const QString& roomId, + const QString& eventId, + const QString& roomName, + const QString& senderName, + const QString& text, + const QImage& icon) { + Q_UNUSED(roomId); + Q_UNUSED(eventId); + Q_UNUSED(icon); + + NSUserNotification* notif = [[NSUserNotification alloc] init]; + + notif.title = roomName.toNSString(); + notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString(); + notif.informativeText = text.toNSString(); + notif.soundName = NSUserNotificationDefaultSoundName; + + [[NSUserNotificationCenter defaultUserNotificationCenter] + deliverNotification:notif]; + [notif autorelease]; } -void -NotificationsManager::postNotification( - const QString &roomId, - const QString &eventId, - const QString &roomName, - const QString &senderName, - const QString &text, - const QImage &icon) -{ - Q_UNUSED(roomId); - Q_UNUSED(eventId); - Q_UNUSED(icon); +// unused +void NotificationsManager::actionInvoked(uint, QString) {} - NSUserNotification * notif = [[NSUserNotification alloc] init]; - - notif.title = roomName.toNSString(); - notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString(); - notif.informativeText = text.toNSString(); - notif.soundName = NSUserNotificationDefaultSoundName; - - [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif]; - [notif autorelease]; -} - -//unused -void -NotificationsManager::actionInvoked(uint, QString) -{ -} - -void -NotificationsManager::notificationClosed(uint, uint) -{ -} +void NotificationsManager::notificationClosed(uint, uint) {} diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 33576f1f6..45fb51674 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -123,7 +123,7 @@ void TrayIcon::setNotificationCount(int count) { setIcon(QIcon(tmp)); - icon_ = tmp; + icon_ = tmp #endif emit notificationCountChanged(); }