Clean up.
This commit is contained in:
@@ -6,53 +6,59 @@ AccountListModel::AccountListModel(QObject* parent)
|
|||||||
: QAbstractListModel(parent) {}
|
: QAbstractListModel(parent) {}
|
||||||
|
|
||||||
void AccountListModel::setController(Controller* value) {
|
void AccountListModel::setController(Controller* value) {
|
||||||
if (m_controller != value) {
|
if (m_controller == value) {
|
||||||
beginResetModel();
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
QVariant AccountListModel::data(const QModelIndex& index, int role) const {
|
||||||
if (!index.isValid()) return QVariant();
|
if (!index.isValid()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if (index.row() >= m_connections.count()) {
|
if (index.row() >= m_connections.count()) {
|
||||||
qDebug() << "AccountListModel, something's wrong: index.row() >= "
|
qDebug() << "AccountListModel, something's wrong: index.row() >= "
|
||||||
"m_users.count()";
|
"m_users.count()";
|
||||||
return QVariant();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto m_connection = m_connections.at(index.row());
|
auto m_connection = m_connections.at(index.row());
|
||||||
|
|
||||||
if (role == UserRole) {
|
if (role == UserRole) {
|
||||||
return QVariant::fromValue(m_connection->user());
|
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::fromValue(m_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int AccountListModel::rowCount(const QModelIndex& parent) const {
|
int AccountListModel::rowCount(const QModelIndex& parent) const {
|
||||||
if (parent.isValid()) return 0;
|
if (parent.isValid()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return m_connections.count();
|
return m_connections.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> AccountListModel::roleNames() const {
|
QHash<int, QByteArray> AccountListModel::roleNames() const {
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
|
|
||||||
roles[UserRole] = "user";
|
roles[UserRole] = "user";
|
||||||
roles[ConnectionRole] = "connection";
|
roles[ConnectionRole] = "connection";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -343,8 +343,8 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
|||||||
if (evt.isRedacted()) {
|
if (evt.isRedacted()) {
|
||||||
auto reason = evt.redactedBecause()->reason();
|
auto reason = evt.redactedBecause()->reason();
|
||||||
return (reason.isEmpty())
|
return (reason.isEmpty())
|
||||||
? tr("Redacted")
|
? tr("[REDACTED]")
|
||||||
: tr("Redacted: %1").arg(evt.redactedBecause()->reason());
|
: tr("[REDACTED: %1]").arg(evt.redactedBecause()->reason());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto e = eventCast<const RoomMessageEvent>(&evt)) {
|
if (auto e = eventCast<const RoomMessageEvent>(&evt)) {
|
||||||
|
|||||||
@@ -4,45 +4,34 @@
|
|||||||
#include <QtMac>
|
#include <QtMac>
|
||||||
|
|
||||||
@interface NSUserNotification (CFIPrivate)
|
@interface NSUserNotification (CFIPrivate)
|
||||||
- (void)set_identityImage:(NSImage *)image;
|
- (void)set_identityImage:(NSImage*)image;
|
||||||
@end
|
@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
|
// unused
|
||||||
NotificationsManager::postNotification(
|
void NotificationsManager::actionInvoked(uint, QString) {}
|
||||||
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];
|
void NotificationsManager::notificationClosed(uint, uint) {}
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ void TrayIcon::setNotificationCount(int count) {
|
|||||||
|
|
||||||
setIcon(QIcon(tmp));
|
setIcon(QIcon(tmp));
|
||||||
|
|
||||||
icon_ = tmp;
|
icon_ = tmp
|
||||||
#endif
|
#endif
|
||||||
emit notificationCountChanged();
|
emit notificationCountChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user