mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
DesktopNotificationsFactory class now supports native notifications (on
Linux) and popupWidget notification
This commit is contained in:
parent
9d4df4aae6
commit
a8add4a5b3
|
@ -83,7 +83,6 @@ QupZilla::QupZilla(bool tryRestore, QUrl startUrl) :
|
||||||
connect(mApp, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(receiveMessage(MainApplication::MessageType,bool)));
|
connect(mApp, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(receiveMessage(MainApplication::MessageType,bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "desktopnotification.h"
|
|
||||||
void QupZilla::loadSettings()
|
void QupZilla::loadSettings()
|
||||||
{
|
{
|
||||||
QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
|
QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
|
||||||
|
@ -129,8 +128,7 @@ void QupZilla::loadSettings()
|
||||||
m_actionPrivateBrowsing->setChecked( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
|
m_actionPrivateBrowsing->setChecked( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
|
||||||
m_privateBrowsing->setVisible( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
|
m_privateBrowsing->setVisible( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
|
||||||
|
|
||||||
// DesktopNotification* notif = new DesktopNotification(QPixmap(), "bla", "ble", 10000);
|
setWindowIcon(QIcon(":/icons/qupzilla.png"));
|
||||||
// notif->show();
|
|
||||||
|
|
||||||
if (!makeTransparent)
|
if (!makeTransparent)
|
||||||
return;
|
return;
|
||||||
|
@ -150,7 +148,6 @@ void QupZilla::loadSettings()
|
||||||
QtWin::extendFrameIntoClientArea(this);
|
QtWin::extendFrameIntoClientArea(this);
|
||||||
setContentsMargins(0, 0, 0, 0);
|
setContentsMargins(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
setWindowIcon(QIcon(":/icons/qupzilla.png"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
||||||
|
|
|
@ -70,6 +70,5 @@
|
||||||
<file>icons/preferences/stock_keyring.png</file>
|
<file>icons/preferences/stock_keyring.png</file>
|
||||||
<file>icons/other/list-add.png</file>
|
<file>icons/other/list-add.png</file>
|
||||||
<file>icons/other/adblock.png</file>
|
<file>icons/other/adblock.png</file>
|
||||||
<file>icons/other/notifbackground.png</file>
|
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#include "desktopnotification.h"
|
#include "desktopnotification.h"
|
||||||
#include "ui_desktopnotification.h"
|
#include "ui_desktopnotification.h"
|
||||||
|
|
||||||
DesktopNotification::DesktopNotification(const QPixmap &icon, const QString &heading, const QString &text, int timeout)
|
DesktopNotification::DesktopNotification(bool settingPosition)
|
||||||
: QWidget(0)
|
: QWidget(0)
|
||||||
, ui(new Ui::DesktopNotification)
|
, ui(new Ui::DesktopNotification)
|
||||||
|
, m_settingPosition(settingPosition)
|
||||||
|
, m_timeout(6000)
|
||||||
|
, m_timer(new QTimer(this))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setStyleSheet("background:transparent;");
|
setStyleSheet("background:transparent;");
|
||||||
|
@ -17,11 +20,23 @@ DesktopNotification::DesktopNotification(const QPixmap &icon, const QString &hea
|
||||||
setWindowFlags(flags);
|
setWindowFlags(flags);
|
||||||
setWindowOpacity(0.9);
|
setWindowOpacity(0.9);
|
||||||
|
|
||||||
ui->icon->setPixmap(icon);
|
m_timer->setSingleShot(true);
|
||||||
ui->heading->setText(QString("<b>%1</b>").arg(heading));
|
connect(m_timer, SIGNAL(timeout()), this, SLOT(close()));
|
||||||
ui->text->setText(text);
|
}
|
||||||
|
|
||||||
QTimer::singleShot(timeout, this, SLOT(close()));
|
void DesktopNotification::show()
|
||||||
|
{
|
||||||
|
ui->icon->setPixmap(m_icon);
|
||||||
|
ui->heading->setText(QString("<b>%1</b>").arg(m_heading));
|
||||||
|
ui->text->setText(m_text);
|
||||||
|
|
||||||
|
if (!m_settingPosition) {
|
||||||
|
m_timer->stop();
|
||||||
|
m_timer->setInterval(m_timeout);
|
||||||
|
m_timer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget::show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotification::enterEvent(QEvent *e)
|
void DesktopNotification::enterEvent(QEvent *e)
|
||||||
|
@ -38,8 +53,23 @@ void DesktopNotification::leaveEvent(QEvent *e)
|
||||||
|
|
||||||
void DesktopNotification::mousePressEvent(QMouseEvent *e)
|
void DesktopNotification::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e)
|
if (!m_settingPosition) {
|
||||||
close();
|
close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e->button() == Qt::LeftButton) {
|
||||||
|
m_dragPosition = e->globalPos() - frameGeometry().topLeft();
|
||||||
|
e->accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopNotification::mouseMoveEvent(QMouseEvent *e)
|
||||||
|
{
|
||||||
|
if (e->buttons() & Qt::LeftButton) {
|
||||||
|
move(e->globalPos() - m_dragPosition);
|
||||||
|
e->accept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopNotification::~DesktopNotification()
|
DesktopNotification::~DesktopNotification()
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DesktopNotification;
|
class DesktopNotification;
|
||||||
|
@ -13,15 +14,29 @@ class DesktopNotification : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DesktopNotification(const QPixmap &icon, const QString &heading, const QString &text, int timeout);
|
explicit DesktopNotification(bool settingPosition = false);
|
||||||
|
void setPixmap(const QPixmap &icon) { m_icon = icon; }
|
||||||
|
void setHeading(const QString &heading) { m_heading = heading; }
|
||||||
|
void setText(const QString &text) { m_text = text; }
|
||||||
|
void setTimeout(int timeout) { m_timeout = timeout; }
|
||||||
|
void show();
|
||||||
~DesktopNotification();
|
~DesktopNotification();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void enterEvent(QEvent *e);
|
void enterEvent(QEvent* e);
|
||||||
void leaveEvent(QEvent *e);
|
void leaveEvent(QEvent* e);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent* e);
|
||||||
|
void mouseMoveEvent(QMouseEvent* e);
|
||||||
|
|
||||||
Ui::DesktopNotification *ui;
|
Ui::DesktopNotification* ui;
|
||||||
|
bool m_settingPosition;
|
||||||
|
QPoint m_dragPosition;
|
||||||
|
|
||||||
|
QPixmap m_icon;
|
||||||
|
QString m_heading;
|
||||||
|
QString m_text;
|
||||||
|
int m_timeout;
|
||||||
|
QTimer* m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DESKTOPNOTIFICATION_H
|
#endif // DESKTOPNOTIFICATION_H
|
||||||
|
|
|
@ -1,17 +1,57 @@
|
||||||
#include "desktopnotificationsfactory.h"
|
#include "desktopnotificationsfactory.h"
|
||||||
|
#include "desktopnotification.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
|
||||||
DesktopNotificationsFactory::DesktopNotificationsFactory(QObject *parent) :
|
DesktopNotificationsFactory::DesktopNotificationsFactory(QObject* parent)
|
||||||
QObject(parent)
|
: QObject(parent)
|
||||||
|
, m_uint(0)
|
||||||
{
|
{
|
||||||
QDBusInterface dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus());
|
loadSettings();
|
||||||
QVariantList args;
|
}
|
||||||
args.append("qupzilla");
|
|
||||||
args.append(QVariant::UInt);
|
void DesktopNotificationsFactory::loadSettings()
|
||||||
args.append("/home/david/a.png");
|
{
|
||||||
args.append("Summary");
|
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
||||||
args.append("Body of notification");
|
settings.beginGroup("Notifications");
|
||||||
args.append(QStringList());
|
m_enabled = settings.value("Enabled", true).toBool();
|
||||||
args.append(QVariantMap());
|
m_timeout = settings.value("Timeout", 6000).toInt();
|
||||||
args.append(-1);
|
#ifdef Q_WS_X11
|
||||||
dbus.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
m_notifType = settings.value("UseNativeDesktop", true).toBool() ? DesktopNative : PopupWidget;
|
||||||
|
#else
|
||||||
|
m_notifType = PopupWidget;
|
||||||
|
#endif
|
||||||
|
m_position = settings.value("Position", QPoint(10, 10)).toPoint();
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopNotificationsFactory::notify(const QPixmap &icon, const QString &heading, const QString &text)
|
||||||
|
{
|
||||||
|
switch (m_notifType) {
|
||||||
|
case PopupWidget:
|
||||||
|
if (!m_desktopNotif)
|
||||||
|
m_desktopNotif = new DesktopNotification();
|
||||||
|
m_desktopNotif->setPixmap(icon);
|
||||||
|
m_desktopNotif->setHeading(heading);
|
||||||
|
m_desktopNotif->setText(text);
|
||||||
|
m_desktopNotif->setTimeout(m_timeout);
|
||||||
|
m_desktopNotif->show();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DesktopNative:
|
||||||
|
QDBusInterface dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus());
|
||||||
|
QVariantList args;
|
||||||
|
args.append("qupzilla");
|
||||||
|
args.append(m_uint);
|
||||||
|
args.append(""); //FIXME:store pixmap in temp folder and provide full path to it
|
||||||
|
args.append(heading);
|
||||||
|
args.append(text);
|
||||||
|
args.append(QStringList());
|
||||||
|
args.append(QVariantMap());
|
||||||
|
args.append(m_timeout);
|
||||||
|
QDBusMessage message = dbus.callWithArgumentList(QDBus::Block, "Notify", args);
|
||||||
|
QVariantList list = message.arguments();
|
||||||
|
if (list.count() > 0)
|
||||||
|
m_uint = list.at(0).toInt();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,33 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QPoint>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
class DesktopNotification;
|
||||||
class DesktopNotificationsFactory : public QObject
|
class DesktopNotificationsFactory : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DesktopNotificationsFactory(QObject *parent = 0);
|
enum Type { DesktopNative, PopupWidget };
|
||||||
|
explicit DesktopNotificationsFactory(QObject* parent = 0);
|
||||||
|
void notify(const QPixmap &icon, const QString &heading, const QString &text);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void loadSettings();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_enabled;
|
||||||
|
int m_timeout;
|
||||||
|
Type m_notifType;
|
||||||
|
QPoint m_position;
|
||||||
|
|
||||||
|
QPointer<DesktopNotification> m_desktopNotif;
|
||||||
|
unsigned int m_uint;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DESKTOPNOTIFICATIONSFACTORY_H
|
#endif // DESKTOPNOTIFICATIONSFACTORY_H
|
||||||
|
|
|
@ -38,6 +38,7 @@ AboutDialog::AboutDialog(QWidget* parent) :
|
||||||
connect(ui->authorsButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
connect(ui->authorsButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
||||||
|
|
||||||
showAbout();
|
showAbout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AboutDialog::buttonClicked()
|
void AboutDialog::buttonClicked()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user