diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index 94990808e..414f9fb6c 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -552,8 +552,8 @@ void QupZilla::showDownloadManager() void QupZilla::showPreferences() { - Preferences prefs(this, this); - prefs.exec(); + Preferences* prefs = new Preferences(this, this); + prefs->show(); } void QupZilla::showSource() diff --git a/src/desktopnotifications/desktopnotification.cpp b/src/desktopnotifications/desktopnotification.cpp index 4e0066ad6..1316c0c03 100644 --- a/src/desktopnotifications/desktopnotification.cpp +++ b/src/desktopnotifications/desktopnotification.cpp @@ -18,10 +18,10 @@ #include "desktopnotification.h" #include "ui_desktopnotification.h" -DesktopNotification::DesktopNotification(bool settingPosition) +DesktopNotification::DesktopNotification(bool setPosition) : QWidget(0) , ui(new Ui::DesktopNotification) - , m_settingPosition(settingPosition) + , m_settingPosition(setPosition) , m_timeout(6000) , m_timer(new QTimer(this)) { @@ -29,8 +29,7 @@ DesktopNotification::DesktopNotification(bool settingPosition) setStyleSheet("background:transparent;"); setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); - Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | - Qt::X11BypassWindowManagerHint; + Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint; #ifdef Q_WS_WIN flags |= Qt::ToolTip; #endif @@ -39,6 +38,7 @@ DesktopNotification::DesktopNotification(bool settingPosition) m_timer->setSingleShot(true); connect(m_timer, SIGNAL(timeout()), this, SLOT(close())); + if (m_settingPosition) setCursor(Qt::OpenHandCursor); } @@ -58,16 +58,16 @@ void DesktopNotification::show() QWidget::show(); } -void DesktopNotification::enterEvent(QEvent *e) +void DesktopNotification::enterEvent(QEvent*) { - Q_UNUSED(e) - setWindowOpacity(0.5); + if (!m_settingPosition) + setWindowOpacity(0.5); } -void DesktopNotification::leaveEvent(QEvent *e) +void DesktopNotification::leaveEvent(QEvent*) { - Q_UNUSED(e) - setWindowOpacity(0.9); + if (!m_settingPosition) + setWindowOpacity(0.9); } void DesktopNotification::mousePressEvent(QMouseEvent *e) diff --git a/src/desktopnotifications/desktopnotification.h b/src/desktopnotifications/desktopnotification.h index 018288c2f..c15b22807 100644 --- a/src/desktopnotifications/desktopnotification.h +++ b/src/desktopnotifications/desktopnotification.h @@ -31,7 +31,7 @@ class DesktopNotification : public QWidget Q_OBJECT public: - explicit DesktopNotification(bool settingPosition = false); + explicit DesktopNotification(bool setPosition = 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; } diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 9ecce5d9d..9fb8c8fb4 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -32,8 +32,10 @@ #include "sslmanager.h" #include "networkproxyfactory.h" #include "networkmanager.h" +#include "desktopnotificationsfactory.h" +#include "desktopnotification.h" -bool removeFile(QString fullFileName) +bool removeFile(const QString &fullFileName) { QFile f(fullFileName); if (f.exists()) @@ -41,7 +43,7 @@ bool removeFile(QString fullFileName) else return false; } -void removeDir(const QString d) +void removeDir(const QString &d) { QDir dir(d); if (dir.exists()) @@ -67,6 +69,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) : ,p_QupZilla(mainClass) ,m_pluginsList(0) { + setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(this); m_bgLabelSize = this->sizeHint(); @@ -235,6 +238,27 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) : m_pluginsList = new PluginsList(this); 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 //Languages QString activeLanguage=""; @@ -301,6 +325,18 @@ void Preferences::showStackedPage(QListWidgetItem* item) return; ui->caption->setText(""+item->text()+""); 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() @@ -606,6 +642,14 @@ void Preferences::saveSettings() settings.setValue("filterTrackingCookie",ui->filterTracking->isChecked() ); 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 //AddressBar settings.beginGroup("AddressBar"); @@ -655,6 +699,7 @@ void Preferences::saveSettings() mApp->plugins()->c2f_saveSettings(); mApp->networkManager()->loadSettings(); mApp->reloadSettings(); + mApp->desktopNotifications()->loadSettings(); } Preferences::~Preferences() @@ -662,4 +707,6 @@ Preferences::~Preferences() delete ui; delete m_autoFillManager; delete m_pluginsList; + if (m_notification) + delete m_notification; } diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index f01dbe196..fde4935e3 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace Ui { class Preferences; @@ -31,6 +32,7 @@ namespace Ui { class AutoFillManager; class QupZilla; class PluginsList; +class DesktopNotification; class Preferences : public QDialog { @@ -76,6 +78,7 @@ private: QupZilla* p_QupZilla; AutoFillManager* m_autoFillManager; PluginsList* m_pluginsList; + QPointer m_notification; QColor m_menuTextColor; QString m_homepage; @@ -84,6 +87,7 @@ private: int m_afterLaunch; int m_onNewTab; QSize m_bgLabelSize; + QPoint m_notifPosition; }; #endif // PREFERENCES_H diff --git a/src/preferences/preferences.ui b/src/preferences/preferences.ui index 3f553c883..1daeb9af9 100644 --- a/src/preferences/preferences.ui +++ b/src/preferences/preferences.ui @@ -1586,7 +1586,133 @@ - + + + + + + <b>Notifications</b> + + + + + + + Use OSD Notifications + + + + + + + false + + + Use Native System Notifications (Linux only) + + + + + + + Do not use Notifications + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Expiration timeout: + + + + + + + + 0 + 0 + + + + seconds + + + + + + + + + <b>Note: </b>You can change position of OSD Notification by dragging it on the screen. + + + true + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 0 + 20 + + + + + +