1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-04-21 13:42:05 +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>
AccountAdapter::AccountAdapter(AppSettingsManager* settingsManager,
SystemTray* systemTray,
LRCInstance* instance,
QObject* parent)
: QmlAdapterBase(instance, parent)
, settingsManager_(settingsManager)
, systemTray_(systemTray)
, accountListModel_(new AccountListModel(instance))
, deviceItemListModel_(new DeviceItemListModel(instance))
{
@ -46,6 +48,11 @@ AccountAdapter::AccountAdapter(AppSettingsManager* settingsManager,
&AccountModel::profileUpdated,
this,
&AccountAdapter::accountStatusChanged);
connect(systemTray_,
&SystemTray::countChanged,
accountListModel_.get(),
&AccountListModel::updateNotifications);
}
AccountModel*
@ -354,4 +361,4 @@ AccountAdapter::setArchivePasswordAsync(const QString& accountID, const QString&
config.archivePassword = password;
lrcInstance_->accountModel().setAccountConfig(accountID, config);
});
}
}

View file

@ -22,6 +22,7 @@
#include "accountlistmodel.h"
#include "deviceitemlistmodel.h"
#include "systemtray.h"
#include "lrcinstance.h"
#include "utils.h"
@ -44,6 +45,7 @@ Q_SIGNALS:
public:
explicit AccountAdapter(AppSettingsManager* settingsManager,
SystemTray* systemTray,
LRCInstance* instance,
QObject* parent = nullptr);
~AccountAdapter() = default;
@ -102,6 +104,7 @@ private:
QMetaObject::Connection registeredNameSavedConnection_;
AppSettingsManager* settingsManager_;
SystemTray* systemTray_;
QScopedPointer<AccountListModel> accountListModel_;
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));
case Role::Status:
return QVariant(static_cast<int>(accountInfo.status));
case Role::NotificationCount:
return QVariant(static_cast<int>(accountInfo.conversationModel->notificationsCount()));
case Role::ID:
return QVariant(accountInfo.id);
}
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>
AccountListModel::roleNames() const
{

View file

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

View file

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

View file

@ -91,5 +91,17 @@ ItemDelegate {
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 avAdapter = new AvAdapter(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 pluginAdapter = new PluginAdapter(lrcInstance, parent);
auto currentConversation = new CurrentConversation(lrcInstance, parent);

View file

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

View file

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

View file

@ -59,7 +59,10 @@ public:
lrcInstance->subscribeToDebugReceived();
// 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()