unread messages count now is displayed on the launcher icon

This commit is contained in:
Blue 2022-04-23 16:58:08 +03:00
parent 721d3a1a89
commit 3916aec358
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
7 changed files with 35 additions and 2 deletions

View File

@ -21,7 +21,7 @@ Application::Application(Core::Squawk* p_core):
availability(Shared::Availability::offline), availability(Shared::Availability::offline),
core(p_core), core(p_core),
squawk(nullptr), squawk(nullptr),
notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()), notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications"),
roster(), roster(),
conversations(), conversations(),
dialogueQueue(roster), dialogueQueue(roster),
@ -29,6 +29,7 @@ Application::Application(Core::Squawk* p_core):
destroyingSquawk(false) destroyingSquawk(false)
{ {
connect(&roster, &Models::Roster::unnoticedMessage, this, &Application::notify); connect(&roster, &Models::Roster::unnoticedMessage, this, &Application::notify);
connect(&roster, &Models::Roster::unreadMessagesCountChanged, this, &Application::unreadMessagesCountChanged);
//connecting myself to the backed //connecting myself to the backed
@ -100,6 +101,7 @@ void Application::quit()
emit quitting(); emit quitting();
writeSettings(); writeSettings();
unreadMessagesCountChanged(0); //this notification persist in the desktop, for now I'll zero it on quit not to confuse people
for (Conversations::const_iterator itr = conversations.begin(), end = conversations.end(); itr != end; ++itr) { for (Conversations::const_iterator itr = conversations.begin(), end = conversations.end(); itr != end; ++itr) {
disconnect(itr->second, &Conversation::destroyed, this, &Application::onConversationClosed); disconnect(itr->second, &Conversation::destroyed, this, &Application::onConversationClosed);
itr->second->close(); itr->second->close();
@ -212,7 +214,7 @@ void Application::notify(const QString& account, const Shared::Message& msg)
args << body; args << body;
args << QStringList(); args << QStringList();
args << QVariantMap({ args << QVariantMap({
{"desktop-entry", QString(QCoreApplication::applicationName())}, {"desktop-entry", qApp->desktopFileName()},
{"category", QString("message")}, {"category", QString("message")},
// {"sound-file", "/path/to/macaw/squawk"}, // {"sound-file", "/path/to/macaw/squawk"},
{"sound-name", QString("message-new-instant")} {"sound-name", QString("message-new-instant")}
@ -225,6 +227,18 @@ void Application::notify(const QString& account, const Shared::Message& msg)
} }
} }
void Application::unreadMessagesCountChanged(int count)
{
QDBusMessage signal = QDBusMessage::createSignal("/", "com.canonical.Unity.LauncherEntry", "Update");
signal << qApp->desktopFileName() + QLatin1String(".desktop");
signal << QVariantMap ({
{"count-visible", count != 0},
{"count", count}
});
QDBusConnection::sessionBus().send(signal);
}
void Application::setState(Shared::Availability p_availability) void Application::setState(Shared::Availability p_availability)
{ {
if (availability != p_availability) { if (availability != p_availability) {

View File

@ -65,6 +65,7 @@ public slots:
protected slots: protected slots:
void notify(const QString& account, const Shared::Message& msg); void notify(const QString& account, const Shared::Message& msg);
void unreadMessagesCountChanged(int count);
void setState(Shared::Availability availability); void setState(Shared::Availability availability);
void changeAccount(const QString& account, const QMap<QString, QVariant>& data); void changeAccount(const QString& account, const QMap<QString, QVariant>& data);

View File

@ -50,6 +50,7 @@ int main(int argc, char *argv[])
QApplication::setOrganizationName("macaw.me"); QApplication::setOrganizationName("macaw.me");
QApplication::setApplicationDisplayName("Squawk"); QApplication::setApplicationDisplayName("Squawk");
QApplication::setApplicationVersion("0.2.2"); QApplication::setApplicationVersion("0.2.2");
app.setDesktopFileName("squawk");
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));

View File

@ -171,6 +171,7 @@ void Models::Element::fileError(const QString& messageId, const QString& error,
void Models::Element::onFeedUnreadMessagesCountChanged() void Models::Element::onFeedUnreadMessagesCountChanged()
{ {
emit unreadMessagesCountChanged();
if (type == contact) { if (type == contact) {
changed(4); changed(4);
} else if (type == room) { } else if (type == room) {

View File

@ -52,6 +52,7 @@ signals:
void requestArchive(const QString& before); void requestArchive(const QString& before);
void fileDownloadRequest(const QString& url); void fileDownloadRequest(const QString& url);
void unnoticedMessage(const QString& account, const Shared::Message& msg); void unnoticedMessage(const QString& account, const Shared::Message& msg);
void unreadMessagesCountChanged();
void localPathInvalid(const QString& path); void localPathInvalid(const QString& path);
protected: protected:

View File

@ -463,6 +463,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
connect(contact, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest); connect(contact, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest);
connect(contact, &Contact::unnoticedMessage, this, &Roster::unnoticedMessage); connect(contact, &Contact::unnoticedMessage, this, &Roster::unnoticedMessage);
connect(contact, &Contact::localPathInvalid, this, &Roster::localPathInvalid); connect(contact, &Contact::localPathInvalid, this, &Roster::localPathInvalid);
connect(contact, &Contact::unreadMessagesCountChanged, this, &Roster::recalculateUnreadMessages);
contacts.insert(std::make_pair(id, contact)); contacts.insert(std::make_pair(id, contact));
} else { } else {
contact = itr->second; contact = itr->second;
@ -805,6 +806,7 @@ void Models::Roster::addRoom(const QString& account, const QString jid, const QM
connect(room, &Room::fileDownloadRequest, this, &Roster::fileDownloadRequest); connect(room, &Room::fileDownloadRequest, this, &Roster::fileDownloadRequest);
connect(room, &Room::unnoticedMessage, this, &Roster::unnoticedMessage); connect(room, &Room::unnoticedMessage, this, &Roster::unnoticedMessage);
connect(room, &Room::localPathInvalid, this, &Roster::localPathInvalid); connect(room, &Room::localPathInvalid, this, &Roster::localPathInvalid);
connect(room, &Room::unreadMessagesCountChanged, this, &Roster::recalculateUnreadMessages);
rooms.insert(std::make_pair(id, room)); rooms.insert(std::make_pair(id, room));
acc->appendChild(room); acc->appendChild(room);
} }
@ -1049,3 +1051,14 @@ void Models::Roster::onAccountReconnected()
} }
} }
void Models::Roster::recalculateUnreadMessages()
{
int count(0);
for (const std::pair<const ElId, Contact*>& pair : contacts) {
count += pair.second->getMessagesCount();
}
for (const std::pair<const ElId, Room*>& pair : rooms) {
count += pair.second->getMessagesCount();
}
emit unreadMessagesCountChanged(count);
}

View File

@ -99,6 +99,7 @@ public:
signals: signals:
void requestArchive(const QString& account, const QString& jid, const QString& before); void requestArchive(const QString& account, const QString& jid, const QString& before);
void fileDownloadRequest(const QString& url); void fileDownloadRequest(const QString& url);
void unreadMessagesCountChanged(int count);
void unnoticedMessage(const QString& account, const Shared::Message& msg); void unnoticedMessage(const QString& account, const Shared::Message& msg);
void localPathInvalid(const QString& path); void localPathInvalid(const QString& path);
@ -113,6 +114,7 @@ private slots:
void onChildIsAboutToBeMoved(Item* source, int first, int last, Item* destination, int newIndex); void onChildIsAboutToBeMoved(Item* source, int first, int last, Item* destination, int newIndex);
void onChildMoved(); void onChildMoved();
void onElementRequestArchive(const QString& before); void onElementRequestArchive(const QString& before);
void recalculateUnreadMessages();
private: private:
Item* root; Item* root;