mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +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)));
|
||||
}
|
||||
|
||||
#include "desktopnotification.h"
|
||||
void QupZilla::loadSettings()
|
||||
{
|
||||
QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
|
||||
@ -129,8 +128,7 @@ void QupZilla::loadSettings()
|
||||
m_actionPrivateBrowsing->setChecked( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
|
||||
m_privateBrowsing->setVisible( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
|
||||
|
||||
// DesktopNotification* notif = new DesktopNotification(QPixmap(), "bla", "ble", 10000);
|
||||
// notif->show();
|
||||
setWindowIcon(QIcon(":/icons/qupzilla.png"));
|
||||
|
||||
if (!makeTransparent)
|
||||
return;
|
||||
@ -150,7 +148,6 @@ void QupZilla::loadSettings()
|
||||
QtWin::extendFrameIntoClientArea(this);
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
setWindowIcon(QIcon(":/icons/qupzilla.png"));
|
||||
}
|
||||
|
||||
void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
||||
|
@ -70,6 +70,5 @@
|
||||
<file>icons/preferences/stock_keyring.png</file>
|
||||
<file>icons/other/list-add.png</file>
|
||||
<file>icons/other/adblock.png</file>
|
||||
<file>icons/other/notifbackground.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include "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)
|
||||
, ui(new Ui::DesktopNotification)
|
||||
, m_settingPosition(settingPosition)
|
||||
, m_timeout(6000)
|
||||
, m_timer(new QTimer(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setStyleSheet("background:transparent;");
|
||||
@ -17,11 +20,23 @@ DesktopNotification::DesktopNotification(const QPixmap &icon, const QString &hea
|
||||
setWindowFlags(flags);
|
||||
setWindowOpacity(0.9);
|
||||
|
||||
ui->icon->setPixmap(icon);
|
||||
ui->heading->setText(QString("<b>%1</b>").arg(heading));
|
||||
ui->text->setText(text);
|
||||
m_timer->setSingleShot(true);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(close()));
|
||||
}
|
||||
|
||||
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)
|
||||
@ -38,8 +53,23 @@ void DesktopNotification::leaveEvent(QEvent *e)
|
||||
|
||||
void DesktopNotification::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
close();
|
||||
if (!m_settingPosition) {
|
||||
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()
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace Ui {
|
||||
class DesktopNotification;
|
||||
@ -13,15 +14,29 @@ class DesktopNotification : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
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();
|
||||
|
||||
private:
|
||||
void enterEvent(QEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void enterEvent(QEvent* e);
|
||||
void leaveEvent(QEvent* 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
|
||||
|
@ -1,17 +1,57 @@
|
||||
#include "desktopnotificationsfactory.h"
|
||||
#include "desktopnotification.h"
|
||||
#include "mainapplication.h"
|
||||
|
||||
DesktopNotificationsFactory::DesktopNotificationsFactory(QObject *parent) :
|
||||
QObject(parent)
|
||||
DesktopNotificationsFactory::DesktopNotificationsFactory(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_uint(0)
|
||||
{
|
||||
QDBusInterface dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus());
|
||||
QVariantList args;
|
||||
args.append("qupzilla");
|
||||
args.append(QVariant::UInt);
|
||||
args.append("/home/david/a.png");
|
||||
args.append("Summary");
|
||||
args.append("Body of notification");
|
||||
args.append(QStringList());
|
||||
args.append(QVariantMap());
|
||||
args.append(-1);
|
||||
dbus.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
void DesktopNotificationsFactory::loadSettings()
|
||||
{
|
||||
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
||||
settings.beginGroup("Notifications");
|
||||
m_enabled = settings.value("Enabled", true).toBool();
|
||||
m_timeout = settings.value("Timeout", 6000).toInt();
|
||||
#ifdef Q_WS_X11
|
||||
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 <QDBusInterface>
|
||||
#include <QStringList>
|
||||
#include <QSettings>
|
||||
#include <QPoint>
|
||||
#include <QTimer>
|
||||
#include <QPointer>
|
||||
|
||||
class DesktopNotification;
|
||||
class DesktopNotificationsFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
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:
|
||||
|
||||
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
|
||||
|
@ -38,6 +38,7 @@ AboutDialog::AboutDialog(QWidget* parent) :
|
||||
connect(ui->authorsButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
||||
|
||||
showAbout();
|
||||
|
||||
}
|
||||
|
||||
void AboutDialog::buttonClicked()
|
||||
|
Loading…
Reference in New Issue
Block a user