mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-14 19:12:11 +01:00
Notifications - messing around with unfinished code
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
fbf6537ce6
commit
2e4478b6f6
|
@ -22,11 +22,13 @@
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "browserwindow.h"
|
#include "browserwindow.h"
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
#include "qztools.h"
|
||||||
|
|
||||||
#include <KNotification>
|
#include <KNotification>
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
|
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
|
@ -68,7 +70,7 @@ void DesktopNotificationsFactory::showNotification(const QString &heading, const
|
||||||
showNotification(QPixmap(), heading, text);
|
showNotification(QPixmap(), heading, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QString &heading, const QString &text)
|
void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QString &heading, const QString &text, const DesktopNotificationsFactory::EventType notificationType)
|
||||||
{
|
{
|
||||||
if (!m_enabled) {
|
if (!m_enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -86,16 +88,30 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS
|
||||||
m_desktopNotif.data()->move(m_position);
|
m_desktopNotif.data()->move(m_position);
|
||||||
m_desktopNotif.data()->show();
|
m_desktopNotif.data()->show();
|
||||||
break;
|
break;
|
||||||
case DesktopNative:
|
case DesktopNative: {
|
||||||
KNotification *notification = new KNotification(QSL("contactOnline"));
|
#if 1
|
||||||
|
if (!KNotificationEvents.contains(notificationType)) {
|
||||||
|
qWarning() << "Invalid notification type";
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap image = icon.copy(); /* Workaround for corrupted image */
|
||||||
|
KNotification *notification = new KNotification(KNotificationEvents[notificationType]);
|
||||||
|
notification->setPixmap(image);
|
||||||
notification->setTitle(heading);
|
notification->setTitle(heading);
|
||||||
notification->setText(text);
|
notification->setText(text);
|
||||||
notification->setPixmap(icon);
|
notification->setComponentName(QSL("falkon"));
|
||||||
// notification->setActions({tr("Open chat")});
|
|
||||||
|
|
||||||
// connect(notification, QOverload<unsigned int>::of(&KNotification::activated), contact, &Contact::slotOpenChat);
|
KNotificationAction *actionOpenFile = notification->addAction(tr("Open File"));
|
||||||
|
connect(actionOpenFile, &KNotificationAction::activated, this, [=]() {
|
||||||
|
QDesktopServices::openUrl(QUrl(QSL("file:///home/juraj")));
|
||||||
|
});
|
||||||
|
KNotificationAction *actionOpenFolder = notification->addAction(tr("Open Folder"));
|
||||||
|
connect(actionOpenFolder, &KNotificationAction::activated, this, [=]() {
|
||||||
|
QzTools::openFolder({QUrl(QSL("/home/juraj"))});
|
||||||
|
});
|
||||||
|
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
|
#else
|
||||||
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
|
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
|
||||||
QFile tmp(DataPaths::path(DataPaths::Temp) + QLatin1String("/falkon_notif.png"));
|
QFile tmp(DataPaths::path(DataPaths::Temp) + QLatin1String("/falkon_notif.png"));
|
||||||
tmp.open(QFile::WriteOnly);
|
tmp.open(QFile::WriteOnly);
|
||||||
|
@ -116,10 +132,12 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS
|
||||||
args.append(hints);
|
args.append(hints);
|
||||||
args.append(m_timeout);
|
args.append(m_timeout);
|
||||||
dbus.callWithCallback(QSL("Notify"), args, this, SLOT(updateLastId(QDBusMessage)), SLOT(error(QDBusError)));
|
dbus.callWithCallback(QSL("Notify"), args, this, SLOT(updateLastId(QDBusMessage)), SLOT(error(QDBusError)));
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DesktopNotificationsFactory::nativeNotificationPreview()
|
void DesktopNotificationsFactory::nativeNotificationPreview()
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
bool supportsNativeNotifications() const;
|
bool supportsNativeNotifications() const;
|
||||||
|
|
||||||
void showNotification(const QString &heading, const QString &text);
|
void showNotification(const QString &heading, const QString &text);
|
||||||
void showNotification(const QPixmap &icon, const QString &heading, const QString &text);
|
void showNotification(const QPixmap &icon, const QString &heading, const QString &text, const DesktopNotificationsFactory::EventType notificationType = General);
|
||||||
void nativeNotificationPreview();
|
void nativeNotificationPreview();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user