diff --git a/NotificationList.hxx b/NotificationList.hxx
index 3bf1807..fa6c07c 100644
--- a/NotificationList.hxx
+++ b/NotificationList.hxx
@@ -1,82 +1,81 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Copyright 2017 Martin Koller, kollix@aon.at
This file is part of liquidshell.
liquidshell is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
liquidshell is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with liquidshell. If not, see .
*/
#ifndef _NotificationList_H_
#define _NotificationList_H_
#include
#include
#include
#include
#include
class QVBoxLayout;
class NotifyItem : public QFrame
{
Q_OBJECT
public:
NotifyItem(QWidget *parent, uint theid, const QString &app,
const QString &summary, const QString &body, const QIcon &icon,
const QStringList &actions);
void destroySysResources();
uint id;
QString appName, summary, body;
QStringList actions;
-
- private:
QLabel *timeLabel, *iconLabel, *textLabel;
};
//--------------------------------------------------------------------------------
class NotificationList : public QWidget
{
Q_OBJECT
public:
NotificationList(QWidget *parent);
~NotificationList() override;
void addItem(uint id, const QString &appName, const QString &summary, const QString &body,
const QIcon &icon, const QStringList &actions, const QVariantMap &hints, int timeout);
void closeItem(uint id);
int itemCount() const { return numItems; }
+ QVector getItems() const { return items; }
Q_SIGNALS:
void itemsCountChanged();
void listNowEmpty();
private:
void placeItems();
private:
QScrollArea *scrollArea;
QVBoxLayout *listVbox;
QMap appTimeouts; // appName, timeout (minutes)
int numItems = 0;
QVector items;
};
#endif
diff --git a/NotificationServer.cxx b/NotificationServer.cxx
index 133fbff..276b37b 100644
--- a/NotificationServer.cxx
+++ b/NotificationServer.cxx
@@ -1,133 +1,156 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Copyright 2017 Martin Koller, kollix@aon.at
This file is part of liquidshell.
liquidshell is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
liquidshell is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with liquidshell. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
//--------------------------------------------------------------------------------
NotificationServer::NotificationServer(QWidget *parent)
: SysTrayItem(parent, "preferences-desktop-notification")
{
new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
if ( dbus.registerService("org.freedesktop.Notifications") )
{
if ( !dbus.registerObject("/org/freedesktop/Notifications", this) )
dbus.unregisterService("org.freedesktop.Notifications");
}
notificationList = new NotificationList(this);
connect(notificationList, &NotificationList::listNowEmpty, this, &NotificationServer::hide);
connect(notificationList, &NotificationList::itemsCountChanged,
[this]()
{
show();
- setToolTip(i18np("%1 notification", "%1 notifications", notificationList->itemCount()));
+ setToolTip(makeToolTip());
}
);
hide();
}
//--------------------------------------------------------------------------------
+QString NotificationServer::makeToolTip() const
+{
+ QString tip = "";
+ tip += i18np("%1 notification", "%1 notifications", notificationList->itemCount());
+
+ if ( notificationList->itemCount() < 4 )
+ {
+ for (const NotifyItem *item : notificationList->getItems())
+ {
+ tip += "
";
+ tip += item->timeLabel->text() + " ";
+ QString title = (item->appName == item->summary) ? item->appName : (item->appName + ": " + item->summary);
+ tip += "" + title + "";
+ tip += "
" + item->body;
+ }
+ }
+
+ tip += "";
+ return tip;
+}
+
+//--------------------------------------------------------------------------------
+
QStringList NotificationServer::GetCapabilities()
{
return QStringList()
<< "body"
<< "body-hyperlinks"
<< "body-images"
<< "body-markup"
<< "icon-static"
<< "persistence"
<< "actions"
;
}
//--------------------------------------------------------------------------------
void NotificationServer::CloseNotification(uint id)
{
notificationList->closeItem(id);
}
//--------------------------------------------------------------------------------
QString NotificationServer::GetServerInformation(QString &vendor, QString &version, QString &spec_version)
{
vendor = "kollix";
version = "1.0";
spec_version = "1.2";
return vendor;
}
//--------------------------------------------------------------------------------
uint NotificationServer::Notify(const QString &app_name, uint replaces_id, const QString &app_icon,
const QString &summary, const QString &theBody, const QStringList &actions,
const QVariantMap &hints, int timeout)
{
//qDebug() << "app" << app_name << "summary" << summary << "body" << theBody << "timeout" << timeout << "replaceId" << replaces_id
// << "hints" << hints << "actions" << actions;
QString body(theBody);
body.replace("\n", "
");
QIcon icon;
if ( !app_icon.isEmpty() )
icon = QIcon::fromTheme(app_icon);
else if ( hints.contains("image-path") )
icon = QIcon(hints["image-path"].toString());
QString appName = app_name;
if ( appName.isEmpty() && hints.contains("desktop-entry") )
{
KService::Ptr service = KService::serviceByDesktopName(hints["desktop-entry"].toString().toLower());
if ( service )
appName = service->name();
}
notificationList->addItem(notifyId, appName, summary, body, icon, actions, hints, timeout);
if ( replaces_id != 0 )
notificationList->closeItem(replaces_id);
return notifyId++;
}
//--------------------------------------------------------------------------------
QWidget *NotificationServer::getDetailsList()
{
return notificationList;
}
//--------------------------------------------------------------------------------
diff --git a/NotificationServer.hxx b/NotificationServer.hxx
index 49f9802..306b5ad 100644
--- a/NotificationServer.hxx
+++ b/NotificationServer.hxx
@@ -1,58 +1,61 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Copyright 2017 Martin Koller, kollix@aon.at
This file is part of liquidshell.
liquidshell is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
liquidshell is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with liquidshell. If not, see .
*/
#ifndef _NotificationServer_H_
#define _NotificationServer_H_
// https://developer.gnome.org/notification-spec/
#include
class NotificationList;
class NotificationServer : public SysTrayItem
{
Q_OBJECT
public:
NotificationServer(QWidget *parent);
void CloseNotification(uint id);
QStringList GetCapabilities();
QString GetServerInformation(QString &vendor, QString &version, QString &spec_version);
uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon,
const QString &summary, const QString &body, const QStringList &actions,
const QVariantMap &hints, int timeout);
protected:
QWidget *getDetailsList() override;
Q_SIGNALS:
void ActionInvoked(uint id, const QString &action_key);
void NotificationClosed(uint id, uint reason);
+ private:
+ QString makeToolTip() const;
+
private:
uint notifyId = 1;
NotificationList *notificationList;
};
#endif