mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Added initial class for supporting desktop notifications
This commit is contained in:
parent
04e0149025
commit
9d4df4aae6
|
@ -40,6 +40,7 @@ INCLUDEPATH += 3rdparty\
|
|||
sidebar\
|
||||
data\
|
||||
adblock\
|
||||
desktopnotifications\
|
||||
|
||||
SOURCES += main.cpp\
|
||||
3rdparty/squeezelabel.cpp \
|
||||
|
@ -111,7 +112,9 @@ SOURCES += main.cpp\
|
|||
tools/docktitlebarwidget.cpp \
|
||||
sidebar/bookmarkssidebar.cpp \
|
||||
bookmarks/bookmarkicon.cpp \
|
||||
sidebar/historysidebar.cpp
|
||||
sidebar/historysidebar.cpp \
|
||||
desktopnotifications/desktopnotification.cpp \
|
||||
desktopnotifications/desktopnotificationsfactory.cpp
|
||||
|
||||
HEADERS += 3rdparty/squeezelabel.h \
|
||||
3rdparty/qtwin.h \
|
||||
|
@ -182,7 +185,9 @@ HEADERS += 3rdparty/squeezelabel.h \
|
|||
tools/docktitlebarwidget.h \
|
||||
sidebar/bookmarkssidebar.h \
|
||||
bookmarks/bookmarkicon.h \
|
||||
sidebar/historysidebar.h
|
||||
sidebar/historysidebar.h \
|
||||
desktopnotifications/desktopnotification.h \
|
||||
desktopnotifications/desktopnotificationsfactory.h
|
||||
|
||||
FORMS += \
|
||||
preferences/autofillmanager.ui \
|
||||
|
@ -209,7 +214,8 @@ FORMS += \
|
|||
adblock/adblockdialog.ui \
|
||||
tools/docktitlebarwidget.ui \
|
||||
sidebar/bookmarkssidebar.ui \
|
||||
sidebar/historysidebar.ui
|
||||
sidebar/historysidebar.ui \
|
||||
desktopnotifications/desktopnotification.ui
|
||||
|
||||
RESOURCES += \
|
||||
data/icons.qrc \
|
||||
|
@ -220,6 +226,7 @@ OTHER_FILES += \
|
|||
|
||||
include(3rdparty/qtsingleapplication.pri)
|
||||
|
||||
unix:QT += dbus
|
||||
win32:RC_FILE = appicon.rc
|
||||
win32:LIBS += User32.lib
|
||||
win32:LIBS += Ole32.lib
|
||||
|
|
|
@ -83,6 +83,7 @@ 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);
|
||||
|
@ -128,6 +129,9 @@ 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();
|
||||
|
||||
if (!makeTransparent)
|
||||
return;
|
||||
//Opacity
|
||||
|
@ -162,7 +166,8 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
|||
break;
|
||||
|
||||
default:
|
||||
qWarning() << "Unresolved message sent!";
|
||||
qWarning("Unresolved message sent!");
|
||||
qDebug();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,5 +70,6 @@
|
|||
<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>
|
||||
|
|
48
src/desktopnotifications/desktopnotification.cpp
Normal file
48
src/desktopnotifications/desktopnotification.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "desktopnotification.h"
|
||||
#include "ui_desktopnotification.h"
|
||||
|
||||
DesktopNotification::DesktopNotification(const QPixmap &icon, const QString &heading, const QString &text, int timeout)
|
||||
: QWidget(0)
|
||||
, ui(new Ui::DesktopNotification)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setStyleSheet("background:transparent;");
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
|
||||
Qt::X11BypassWindowManagerHint;
|
||||
#ifdef Q_WS_WIN
|
||||
flags |= Qt::ToolTip;
|
||||
#endif
|
||||
setWindowFlags(flags);
|
||||
setWindowOpacity(0.9);
|
||||
|
||||
ui->icon->setPixmap(icon);
|
||||
ui->heading->setText(QString("<b>%1</b>").arg(heading));
|
||||
ui->text->setText(text);
|
||||
|
||||
QTimer::singleShot(timeout, this, SLOT(close()));
|
||||
}
|
||||
|
||||
void DesktopNotification::enterEvent(QEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
setWindowOpacity(0.5);
|
||||
}
|
||||
|
||||
void DesktopNotification::leaveEvent(QEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
setWindowOpacity(0.9);
|
||||
}
|
||||
|
||||
void DesktopNotification::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
close();
|
||||
}
|
||||
|
||||
DesktopNotification::~DesktopNotification()
|
||||
{
|
||||
delete ui;
|
||||
}
|
27
src/desktopnotifications/desktopnotification.h
Normal file
27
src/desktopnotifications/desktopnotification.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef DESKTOPNOTIFICATION_H
|
||||
#define DESKTOPNOTIFICATION_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Ui {
|
||||
class DesktopNotification;
|
||||
}
|
||||
|
||||
class DesktopNotification : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DesktopNotification(const QPixmap &icon, const QString &heading, const QString &text, int timeout);
|
||||
~DesktopNotification();
|
||||
|
||||
private:
|
||||
void enterEvent(QEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
Ui::DesktopNotification *ui;
|
||||
};
|
||||
|
||||
#endif // DESKTOPNOTIFICATION_H
|
82
src/desktopnotifications/desktopnotification.ui
Normal file
82
src/desktopnotifications/desktopnotification.ui
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DesktopNotification</class>
|
||||
<widget class="QWidget" name="DesktopNotification">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>356</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#frame {
|
||||
border: 2px solid darkblue;
|
||||
border-radius: 20px;
|
||||
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #e4ecf1, stop:1 #d3e5f1);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="heading">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<widget class="QLabel" name="icon">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="text">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
17
src/desktopnotifications/desktopnotificationsfactory.cpp
Normal file
17
src/desktopnotifications/desktopnotificationsfactory.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "desktopnotificationsfactory.h"
|
||||
|
||||
DesktopNotificationsFactory::DesktopNotificationsFactory(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
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);
|
||||
}
|
20
src/desktopnotifications/desktopnotificationsfactory.h
Normal file
20
src/desktopnotifications/desktopnotificationsfactory.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef DESKTOPNOTIFICATIONSFACTORY_H
|
||||
#define DESKTOPNOTIFICATIONSFACTORY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
#include <QStringList>
|
||||
|
||||
class DesktopNotificationsFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DesktopNotificationsFactory(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // DESKTOPNOTIFICATIONSFACTORY_H
|
Loading…
Reference in New Issue
Block a user