1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Added Notifications configuration to Preferences

This commit is contained in:
nowrep 2011-04-27 09:49:41 +02:00
parent ab9fab0801
commit 8ef4ac4a41
6 changed files with 193 additions and 16 deletions

View File

@ -552,8 +552,8 @@ void QupZilla::showDownloadManager()
void QupZilla::showPreferences() void QupZilla::showPreferences()
{ {
Preferences prefs(this, this); Preferences* prefs = new Preferences(this, this);
prefs.exec(); prefs->show();
} }
void QupZilla::showSource() void QupZilla::showSource()

View File

@ -18,10 +18,10 @@
#include "desktopnotification.h" #include "desktopnotification.h"
#include "ui_desktopnotification.h" #include "ui_desktopnotification.h"
DesktopNotification::DesktopNotification(bool settingPosition) DesktopNotification::DesktopNotification(bool setPosition)
: QWidget(0) : QWidget(0)
, ui(new Ui::DesktopNotification) , ui(new Ui::DesktopNotification)
, m_settingPosition(settingPosition) , m_settingPosition(setPosition)
, m_timeout(6000) , m_timeout(6000)
, m_timer(new QTimer(this)) , m_timer(new QTimer(this))
{ {
@ -29,8 +29,7 @@ DesktopNotification::DesktopNotification(bool settingPosition)
setStyleSheet("background:transparent;"); setStyleSheet("background:transparent;");
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint;
Qt::X11BypassWindowManagerHint;
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
flags |= Qt::ToolTip; flags |= Qt::ToolTip;
#endif #endif
@ -39,6 +38,7 @@ DesktopNotification::DesktopNotification(bool settingPosition)
m_timer->setSingleShot(true); m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), this, SLOT(close())); connect(m_timer, SIGNAL(timeout()), this, SLOT(close()));
if (m_settingPosition) if (m_settingPosition)
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
} }
@ -58,15 +58,15 @@ void DesktopNotification::show()
QWidget::show(); QWidget::show();
} }
void DesktopNotification::enterEvent(QEvent *e) void DesktopNotification::enterEvent(QEvent*)
{ {
Q_UNUSED(e) if (!m_settingPosition)
setWindowOpacity(0.5); setWindowOpacity(0.5);
} }
void DesktopNotification::leaveEvent(QEvent *e) void DesktopNotification::leaveEvent(QEvent*)
{ {
Q_UNUSED(e) if (!m_settingPosition)
setWindowOpacity(0.9); setWindowOpacity(0.9);
} }

View File

@ -31,7 +31,7 @@ class DesktopNotification : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit DesktopNotification(bool settingPosition = false); explicit DesktopNotification(bool setPosition = false);
void setPixmap(const QPixmap &icon) { m_icon = icon; } void setPixmap(const QPixmap &icon) { m_icon = icon; }
void setHeading(const QString &heading) { m_heading = heading; } void setHeading(const QString &heading) { m_heading = heading; }
void setText(const QString &text) { m_text = text; } void setText(const QString &text) { m_text = text; }

View File

@ -32,8 +32,10 @@
#include "sslmanager.h" #include "sslmanager.h"
#include "networkproxyfactory.h" #include "networkproxyfactory.h"
#include "networkmanager.h" #include "networkmanager.h"
#include "desktopnotificationsfactory.h"
#include "desktopnotification.h"
bool removeFile(QString fullFileName) bool removeFile(const QString &fullFileName)
{ {
QFile f(fullFileName); QFile f(fullFileName);
if (f.exists()) if (f.exists())
@ -41,7 +43,7 @@ bool removeFile(QString fullFileName)
else return false; else return false;
} }
void removeDir(const QString d) void removeDir(const QString &d)
{ {
QDir dir(d); QDir dir(d);
if (dir.exists()) if (dir.exists())
@ -67,6 +69,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) :
,p_QupZilla(mainClass) ,p_QupZilla(mainClass)
,m_pluginsList(0) ,m_pluginsList(0)
{ {
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this); ui->setupUi(this);
m_bgLabelSize = this->sizeHint(); m_bgLabelSize = this->sizeHint();
@ -235,6 +238,27 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) :
m_pluginsList = new PluginsList(this); m_pluginsList = new PluginsList(this);
ui->pluginsFrame->addWidget(m_pluginsList); ui->pluginsFrame->addWidget(m_pluginsList);
//NOTIFICATIONS
#ifdef Q_WS_X11
ui->useNativeSystemNotifications->setEnabled(true);
#endif
DesktopNotificationsFactory::Type notifyType;
settings.beginGroup("Notifications");
ui->notificationTimeout->setValue(settings.value("Timeout", 6000).toInt() / 1000);
#ifdef Q_WS_X11
notifyType = settings.value("UseNativeDesktop", true).toBool() ? DesktopNotificationsFactory::DesktopNative : DesktopNotificationsFactory::PopupWidget;
#else
notifTyype = DesktopNotificationsFactory::PopupWidget;
#endif
if (notifyType == DesktopNotificationsFactory::DesktopNative)
ui->useNativeSystemNotifications->setChecked(true);
else
ui->useOSDNotifications->setChecked(true);
ui->doNotUseNotifications->setChecked(!settings.value("Enabled", true).toBool());
m_notifPosition = settings.value("Position", QPoint(10,10)).toPoint();
settings.endGroup();
//OTHER //OTHER
//Languages //Languages
QString activeLanguage=""; QString activeLanguage="";
@ -301,6 +325,18 @@ void Preferences::showStackedPage(QListWidgetItem* item)
return; return;
ui->caption->setText("<b>"+item->text()+"</b>"); ui->caption->setText("<b>"+item->text()+"</b>");
ui->stackedWidget->setCurrentIndex(item->whatsThis().toInt()); ui->stackedWidget->setCurrentIndex(item->whatsThis().toInt());
if (ui->stackedWidget->currentIndex() == 8) {
m_notification = new DesktopNotification(true);
m_notification->setPixmap(QPixmap(":icons/preferences/stock_dialog-question.png"));
m_notification->setHeading(tr("OSD Notification"));
m_notification->setText(tr("Drag it on the screen to place it where You want."));
m_notification->move(m_notifPosition);
m_notification->show();
} else if (m_notification) {
m_notifPosition = m_notification->pos();
delete m_notification;
}
} }
void Preferences::chooseColor() void Preferences::chooseColor()
@ -606,6 +642,14 @@ void Preferences::saveSettings()
settings.setValue("filterTrackingCookie",ui->filterTracking->isChecked() ); settings.setValue("filterTrackingCookie",ui->filterTracking->isChecked() );
settings.endGroup(); settings.endGroup();
//NOTIFICATIONS
settings.beginGroup("Notifications");
settings.setValue("Timeout", ui->notificationTimeout->value() * 1000);
settings.setValue("Enabled", !ui->doNotUseNotifications->isChecked());
settings.setValue("UseNativeDesktop", ui->useNativeSystemNotifications->isChecked());
settings.setValue("Position", m_notification ? m_notification->pos() : m_notifPosition);
settings.endGroup();
//OTHER //OTHER
//AddressBar //AddressBar
settings.beginGroup("AddressBar"); settings.beginGroup("AddressBar");
@ -655,6 +699,7 @@ void Preferences::saveSettings()
mApp->plugins()->c2f_saveSettings(); mApp->plugins()->c2f_saveSettings();
mApp->networkManager()->loadSettings(); mApp->networkManager()->loadSettings();
mApp->reloadSettings(); mApp->reloadSettings();
mApp->desktopNotifications()->loadSettings();
} }
Preferences::~Preferences() Preferences::~Preferences()
@ -662,4 +707,6 @@ Preferences::~Preferences()
delete ui; delete ui;
delete m_autoFillManager; delete m_autoFillManager;
delete m_pluginsList; delete m_pluginsList;
if (m_notification)
delete m_notification;
} }

View File

@ -23,6 +23,7 @@
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QColorDialog> #include <QColorDialog>
#include <QAbstractButton> #include <QAbstractButton>
#include <QPointer>
namespace Ui { namespace Ui {
class Preferences; class Preferences;
@ -31,6 +32,7 @@ namespace Ui {
class AutoFillManager; class AutoFillManager;
class QupZilla; class QupZilla;
class PluginsList; class PluginsList;
class DesktopNotification;
class Preferences : public QDialog class Preferences : public QDialog
{ {
@ -76,6 +78,7 @@ private:
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
AutoFillManager* m_autoFillManager; AutoFillManager* m_autoFillManager;
PluginsList* m_pluginsList; PluginsList* m_pluginsList;
QPointer<DesktopNotification> m_notification;
QColor m_menuTextColor; QColor m_menuTextColor;
QString m_homepage; QString m_homepage;
@ -84,6 +87,7 @@ private:
int m_afterLaunch; int m_afterLaunch;
int m_onNewTab; int m_onNewTab;
QSize m_bgLabelSize; QSize m_bgLabelSize;
QPoint m_notifPosition;
}; };
#endif // PREFERENCES_H #endif // PREFERENCES_H

View File

@ -1586,7 +1586,133 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page_3"/> <widget class="QWidget" name="page_3">
<layout class="QGridLayout" name="gridLayout_17">
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_41">
<property name="text">
<string>&lt;b&gt;Notifications&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QRadioButton" name="useOSDNotifications">
<property name="text">
<string>Use OSD Notifications</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QRadioButton" name="useNativeSystemNotifications">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Use Native System Notifications (Linux only)</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QRadioButton" name="doNotUseNotifications">
<property name="text">
<string>Do not use Notifications</string>
</property>
</widget>
</item>
<item row="7" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="4">
<spacer name="horizontalSpacer_17">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_42">
<property name="text">
<string>Expiration timeout:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="notificationTimeout">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string> seconds</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="1" colspan="4">
<widget class="QLabel" name="label_43">
<property name="text">
<string>&lt;b&gt;Note: &lt;/b&gt;You can change position of OSD Notification by dragging it on the screen.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page"> <widget class="QWidget" name="page">
<layout class="QGridLayout" name="gridLayout_14"> <layout class="QGridLayout" name="gridLayout_14">
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">