1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-04-21 21:52:03 +02:00

accountcombobox: show unread count

Change-Id: Ia6d7ba0ee9e32d5830b35b863b3981e2487df183
GitLab: #821
This commit is contained in:
Sébastien Blin 2022-09-09 10:32:15 -04:00 committed by Andreas Traczyk
parent 730b00bd5d
commit bad7cff316
10 changed files with 49 additions and 6 deletions

View file

@ -27,10 +27,12 @@
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
AccountAdapter::AccountAdapter(AppSettingsManager* settingsManager, AccountAdapter::AccountAdapter(AppSettingsManager* settingsManager,
SystemTray* systemTray,
LRCInstance* instance, LRCInstance* instance,
QObject* parent) QObject* parent)
: QmlAdapterBase(instance, parent) : QmlAdapterBase(instance, parent)
, settingsManager_(settingsManager) , settingsManager_(settingsManager)
, systemTray_(systemTray)
, accountListModel_(new AccountListModel(instance)) , accountListModel_(new AccountListModel(instance))
, deviceItemListModel_(new DeviceItemListModel(instance)) , deviceItemListModel_(new DeviceItemListModel(instance))
{ {
@ -46,6 +48,11 @@ AccountAdapter::AccountAdapter(AppSettingsManager* settingsManager,
&AccountModel::profileUpdated, &AccountModel::profileUpdated,
this, this,
&AccountAdapter::accountStatusChanged); &AccountAdapter::accountStatusChanged);
connect(systemTray_,
&SystemTray::countChanged,
accountListModel_.get(),
&AccountListModel::updateNotifications);
} }
AccountModel* AccountModel*
@ -354,4 +361,4 @@ AccountAdapter::setArchivePasswordAsync(const QString& accountID, const QString&
config.archivePassword = password; config.archivePassword = password;
lrcInstance_->accountModel().setAccountConfig(accountID, config); lrcInstance_->accountModel().setAccountConfig(accountID, config);
}); });
} }

View file

@ -22,6 +22,7 @@
#include "accountlistmodel.h" #include "accountlistmodel.h"
#include "deviceitemlistmodel.h" #include "deviceitemlistmodel.h"
#include "systemtray.h"
#include "lrcinstance.h" #include "lrcinstance.h"
#include "utils.h" #include "utils.h"
@ -44,6 +45,7 @@ Q_SIGNALS:
public: public:
explicit AccountAdapter(AppSettingsManager* settingsManager, explicit AccountAdapter(AppSettingsManager* settingsManager,
SystemTray* systemTray,
LRCInstance* instance, LRCInstance* instance,
QObject* parent = nullptr); QObject* parent = nullptr);
~AccountAdapter() = default; ~AccountAdapter() = default;
@ -102,6 +104,7 @@ private:
QMetaObject::Connection registeredNameSavedConnection_; QMetaObject::Connection registeredNameSavedConnection_;
AppSettingsManager* settingsManager_; AppSettingsManager* settingsManager_;
SystemTray* systemTray_;
QScopedPointer<AccountListModel> accountListModel_; QScopedPointer<AccountListModel> accountListModel_;
QScopedPointer<DeviceItemListModel> deviceItemListModel_; QScopedPointer<DeviceItemListModel> deviceItemListModel_;

View file

@ -63,12 +63,23 @@ AccountListModel::data(const QModelIndex& index, int role) const
return QVariant(static_cast<int>(accountInfo.profileInfo.type)); return QVariant(static_cast<int>(accountInfo.profileInfo.type));
case Role::Status: case Role::Status:
return QVariant(static_cast<int>(accountInfo.status)); return QVariant(static_cast<int>(accountInfo.status));
case Role::NotificationCount:
return QVariant(static_cast<int>(accountInfo.conversationModel->notificationsCount()));
case Role::ID: case Role::ID:
return QVariant(accountInfo.id); return QVariant(accountInfo.id);
} }
return QVariant(); return QVariant();
} }
void
AccountListModel::updateNotifications()
{
for (int i = 0; i < lrcInstance_->accountModel().getAccountList().size(); ++i) {
QModelIndex modelIndex = QAbstractListModel::index(i, 0);
Q_EMIT dataChanged(modelIndex, modelIndex, {Role::NotificationCount});
}
}
QHash<int, QByteArray> QHash<int, QByteArray>
AccountListModel::roleNames() const AccountListModel::roleNames() const
{ {

View file

@ -26,6 +26,7 @@
X(Username) \ X(Username) \
X(Type) \ X(Type) \
X(Status) \ X(Status) \
X(NotificationCount) \
X(ID) X(ID)
namespace AccountList { namespace AccountList {
@ -53,6 +54,8 @@ public:
// reset the model when there's new account added // reset the model when there's new account added
Q_INVOKABLE void reset(); Q_INVOKABLE void reset();
void updateNotifications();
protected: protected:
using Role = AccountList::Role; using Role = AccountList::Role;
}; };

View file

@ -379,7 +379,7 @@ ConversationsAdapter::updateConversationFilterData()
} }
set_totalUnreadMessageCount(totalUnreadMessages); set_totalUnreadMessageCount(totalUnreadMessages);
set_pendingRequestCount(accountInfo.conversationModel->pendingRequestCount()); set_pendingRequestCount(accountInfo.conversationModel->pendingRequestCount());
systemTray_->setCount(lrcInstance_->notificationsCount()); systemTray_->onNotificationCountChanged(lrcInstance_->notificationsCount());
if (get_pendingRequestCount() == 0 && get_filterRequests()) if (get_pendingRequestCount() == 0 && get_filterRequests())
set_filterRequests(false); set_filterRequests(false);

View file

@ -91,5 +91,17 @@ ItemDelegate {
elide: Text.ElideRight elide: Text.ElideRight
} }
} }
// unread message count
Item {
Layout.preferredWidth: childrenRect.width
Layout.preferredHeight: childrenRect.height
Layout.alignment: Qt.AlignRight
BadgeNotifier {
size: 20
count: NotificationCount
animate: index === 0
}
}
} }
} }

View file

@ -113,7 +113,7 @@ registerTypes(QQmlEngine* engine,
auto conversationsAdapter = new ConversationsAdapter(systemTray, lrcInstance, parent); auto conversationsAdapter = new ConversationsAdapter(systemTray, lrcInstance, parent);
auto avAdapter = new AvAdapter(lrcInstance, parent); auto avAdapter = new AvAdapter(lrcInstance, parent);
auto contactAdapter = new ContactAdapter(lrcInstance, parent); auto contactAdapter = new ContactAdapter(lrcInstance, parent);
auto accountAdapter = new AccountAdapter(settingsManager, lrcInstance, parent); auto accountAdapter = new AccountAdapter(settingsManager, systemTray, lrcInstance, parent);
auto utilsAdapter = new UtilsAdapter(settingsManager, systemTray, lrcInstance, parent); auto utilsAdapter = new UtilsAdapter(settingsManager, systemTray, lrcInstance, parent);
auto pluginAdapter = new PluginAdapter(lrcInstance, parent); auto pluginAdapter = new PluginAdapter(lrcInstance, parent);
auto currentConversation = new CurrentConversation(lrcInstance, parent); auto currentConversation = new CurrentConversation(lrcInstance, parent);

View file

@ -138,13 +138,14 @@ SystemTray::~SystemTray()
} }
void void
SystemTray::setCount(int count) SystemTray::onNotificationCountChanged(int count)
{ {
if (count == 0) { if (count == 0) {
setIcon(QIcon(":/images/jami.svg")); setIcon(QIcon(":/images/jami.svg"));
} else { } else {
setIcon(QIcon(":/images/jami-new.svg")); setIcon(QIcon(":/images/jami-new.svg"));
} }
Q_EMIT countChanged();
} }
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX

View file

@ -37,7 +37,7 @@ public:
explicit SystemTray(AppSettingsManager* settingsManager, QObject* parent = nullptr); explicit SystemTray(AppSettingsManager* settingsManager, QObject* parent = nullptr);
~SystemTray(); ~SystemTray();
void setCount(int count); void onNotificationCountChanged(int count);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
bool hideNotification(const QString& id); bool hideNotification(const QString& id);
void showNotification(const QString& id, void showNotification(const QString& id,
@ -61,6 +61,9 @@ Q_SIGNALS:
void setOnClickedCallback(Func&& onClickedCb); void setOnClickedCallback(Func&& onClickedCb);
#endif // Q_OS_LINUX #endif // Q_OS_LINUX
Q_SIGNALS:
void countChanged();
private: private:
QMetaObject::Connection messageClicked_; QMetaObject::Connection messageClicked_;
AppSettingsManager* settingsManager_; AppSettingsManager* settingsManager_;

View file

@ -59,7 +59,10 @@ public:
lrcInstance->subscribeToDebugReceived(); lrcInstance->subscribeToDebugReceived();
// setup the adapters (their lifetimes are that of MainApplication) // setup the adapters (their lifetimes are that of MainApplication)
accountAdapter.reset(new AccountAdapter(settingsManager.get(), lrcInstance.data(), nullptr)); accountAdapter.reset(new AccountAdapter(settingsManager.get(),
systemTray.get(),
lrcInstance.data(),
nullptr));
} }
void TearDown() void TearDown()