1
0
Fork 0
forked from blue/squawk

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),
core(p_core),
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(),
conversations(),
dialogueQueue(roster),
@ -29,6 +29,7 @@ Application::Application(Core::Squawk* p_core):
destroyingSquawk(false)
{
connect(&roster, &Models::Roster::unnoticedMessage, this, &Application::notify);
connect(&roster, &Models::Roster::unreadMessagesCountChanged, this, &Application::unreadMessagesCountChanged);
//connecting myself to the backed
@ -100,6 +101,7 @@ void Application::quit()
emit quitting();
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) {
disconnect(itr->second, &Conversation::destroyed, this, &Application::onConversationClosed);
itr->second->close();
@ -212,7 +214,7 @@ void Application::notify(const QString& account, const Shared::Message& msg)
args << body;
args << QStringList();
args << QVariantMap({
{"desktop-entry", QString(QCoreApplication::applicationName())},
{"desktop-entry", qApp->desktopFileName()},
{"category", QString("message")},
// {"sound-file", "/path/to/macaw/squawk"},
{"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)
{
if (availability != p_availability) {

View file

@ -65,6 +65,7 @@ public slots:
protected slots:
void notify(const QString& account, const Shared::Message& msg);
void unreadMessagesCountChanged(int count);
void setState(Shared::Availability availability);
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::setApplicationDisplayName("Squawk");
QApplication::setApplicationVersion("0.2.2");
app.setDesktopFileName("squawk");
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));