diff --git a/src/app/mainapplication.cpp b/src/app/mainapplication.cpp index 45adf694f..25430ac10 100644 --- a/src/app/mainapplication.cpp +++ b/src/app/mainapplication.cpp @@ -34,6 +34,7 @@ #include "downloadmanager.h" #include "autofillmodel.h" #include "adblockmanager.h" +#include "desktopnotificationsfactory.h" MainApplication::MainApplication(int &argc, char **argv) : QtSingleApplication("QupZillaWebBrowser", argc, argv) @@ -50,6 +51,7 @@ MainApplication::MainApplication(int &argc, char **argv) ,m_downloadManager(0) ,m_autofill(0) ,m_networkCache(new QNetworkDiskCache) + ,m_desktopNotifications(0) ,m_isClosing(false) ,m_isChanged(false) ,m_isExited(false) @@ -420,6 +422,13 @@ AutoFillModel* MainApplication::autoFill() return m_autofill; } +DesktopNotificationsFactory* MainApplication::desktopNotifications() +{ + if (!m_desktopNotifications) + m_desktopNotifications = new DesktopNotificationsFactory(this); + return m_desktopNotifications; +} + void MainApplication::aboutToCloseWindow(QupZilla* window) { if (!window) diff --git a/src/app/mainapplication.h b/src/app/mainapplication.h index 9e993f38f..455aac896 100644 --- a/src/app/mainapplication.h +++ b/src/app/mainapplication.h @@ -41,6 +41,7 @@ class PluginProxy; class BookmarksModel; class DownloadManager; class AutoFillModel; +class DesktopNotificationsFactory; class MainApplication : public QtSingleApplication { @@ -82,6 +83,7 @@ public: DownloadManager* downManager(); AutoFillModel* autoFill(); QNetworkDiskCache* networkCache() { return m_networkCache; } + DesktopNotificationsFactory* desktopNotifications(); public slots: bool saveStateSlot(); @@ -115,6 +117,7 @@ private: DownloadManager* m_downloadManager; AutoFillModel* m_autofill; QNetworkDiskCache* m_networkCache; + DesktopNotificationsFactory* m_desktopNotifications; QList > m_mainWindows; diff --git a/src/data/icons.qrc b/src/data/icons.qrc index 3b82fb949..1976327da 100644 --- a/src/data/icons.qrc +++ b/src/data/icons.qrc @@ -70,5 +70,7 @@ icons/preferences/stock_keyring.png icons/other/list-add.png icons/other/adblock.png + icons/preferences/stock_dialog-question.png + icons/notifications/download.png diff --git a/src/data/icons/notifications/download.png b/src/data/icons/notifications/download.png new file mode 100644 index 000000000..a55e6515e Binary files /dev/null and b/src/data/icons/notifications/download.png differ diff --git a/src/data/icons/preferences/stock_dialog-question.png b/src/data/icons/preferences/stock_dialog-question.png new file mode 100644 index 000000000..1ae579e6a Binary files /dev/null and b/src/data/icons/preferences/stock_dialog-question.png differ diff --git a/src/desktopnotifications/desktopnotification.cpp b/src/desktopnotifications/desktopnotification.cpp index cd314d23e..3d1eb410b 100644 --- a/src/desktopnotifications/desktopnotification.cpp +++ b/src/desktopnotifications/desktopnotification.cpp @@ -27,7 +27,7 @@ DesktopNotification::DesktopNotification(bool settingPosition) void DesktopNotification::show() { ui->icon->setPixmap(m_icon); - ui->heading->setText(QString("%1").arg(m_heading)); + ui->heading->setText(m_heading); ui->text->setText(m_text); if (!m_settingPosition) { diff --git a/src/desktopnotifications/desktopnotification.ui b/src/desktopnotifications/desktopnotification.ui index a519a506a..13e068f64 100644 --- a/src/desktopnotifications/desktopnotification.ui +++ b/src/desktopnotifications/desktopnotification.ui @@ -7,7 +7,7 @@ 0 0 356 - 91 + 74 @@ -35,26 +35,13 @@ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #e4ecf1, stop:1 QFrame::Raised - - - - - - 0 - 0 - - - - - - - - + + - 64 - 64 + 48 + 48 @@ -62,15 +49,67 @@ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #e4ecf1, stop:1 - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + 0 - + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + QLabel { +font: bold; +font-size: 13pt; +} + + + + + + + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + diff --git a/src/desktopnotifications/desktopnotificationsfactory.cpp b/src/desktopnotifications/desktopnotificationsfactory.cpp index fd8a34bb9..2967efd76 100644 --- a/src/desktopnotifications/desktopnotificationsfactory.cpp +++ b/src/desktopnotifications/desktopnotificationsfactory.cpp @@ -15,7 +15,8 @@ void DesktopNotificationsFactory::loadSettings() settings.beginGroup("Notifications"); m_enabled = settings.value("Enabled", true).toBool(); m_timeout = settings.value("Timeout", 6000).toInt(); -#ifdef Q_WS_X11 +//#ifdef Q_WS_X11 +#if 0 m_notifType = settings.value("UseNativeDesktop", true).toBool() ? DesktopNative : PopupWidget; #else m_notifType = PopupWidget; @@ -26,6 +27,9 @@ void DesktopNotificationsFactory::loadSettings() void DesktopNotificationsFactory::notify(const QPixmap &icon, const QString &heading, const QString &text) { + if (!m_enabled) + return; + switch (m_notifType) { case PopupWidget: if (!m_desktopNotif) @@ -34,15 +38,20 @@ void DesktopNotificationsFactory::notify(const QPixmap &icon, const QString &hea m_desktopNotif->setHeading(heading); m_desktopNotif->setText(text); m_desktopNotif->setTimeout(m_timeout); + m_desktopNotif->move(m_position); m_desktopNotif->show(); break; case DesktopNative: + QFile tmp(QDir::tempPath() + "/qupzilla_notif.png"); + tmp.open(QFile::WriteOnly); + icon.save(tmp.fileName()); + 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(tmp.fileName()); args.append(heading); args.append(text); args.append(QStringList()); diff --git a/src/desktopnotifications/desktopnotificationsfactory.h b/src/desktopnotifications/desktopnotificationsfactory.h index 3d6afe796..bda9f1dea 100644 --- a/src/desktopnotifications/desktopnotificationsfactory.h +++ b/src/desktopnotifications/desktopnotificationsfactory.h @@ -8,6 +8,7 @@ #include #include #include +#include class DesktopNotification; class DesktopNotificationsFactory : public QObject diff --git a/src/downloads/downloaditem.cpp b/src/downloads/downloaditem.cpp index 7a4dd3737..0e4dfd1c5 100644 --- a/src/downloads/downloaditem.cpp +++ b/src/downloads/downloaditem.cpp @@ -128,6 +128,8 @@ void DownloadItem::finished() if (m_openAfterFinish) openFile(); + + emit downloadFinished(true); } void DownloadItem::downloadProgress(qint64 received, qint64 total) @@ -258,6 +260,8 @@ void DownloadItem::stop(bool askForDeleteFile) #endif m_downloading = false; + emit downloadFinished(false); + if (askForDeleteFile) { QMessageBox::StandardButton button = QMessageBox::question(m_item->listWidget()->parentWidget(), tr("Delete file"), tr("Do you want to also delete dowloaded file?"), QMessageBox::Yes | QMessageBox::No); if (button != QMessageBox::Yes) diff --git a/src/downloads/downloaditem.h b/src/downloads/downloaditem.h index 5d186988f..2423b11c1 100644 --- a/src/downloads/downloaditem.h +++ b/src/downloads/downloaditem.h @@ -56,6 +56,7 @@ public: signals: void deleteItem(DownloadItem*); + void downloadFinished(bool success); private slots: void finished(); diff --git a/src/downloads/downloadmanager.cpp b/src/downloads/downloadmanager.cpp index 08bae47da..57c1ce0b7 100644 --- a/src/downloads/downloadmanager.cpp +++ b/src/downloads/downloadmanager.cpp @@ -23,6 +23,7 @@ #include "ecwin7.h" #include "networkmanager.h" #include "qtwin.h" +#include "desktopnotificationsfactory.h" DownloadManager::DownloadManager(QWidget* parent) : QWidget(parent) @@ -77,25 +78,14 @@ void DownloadManager::timerEvent(QTimerEvent* event) } for (int i = 0; i < ui->list->count(); i++) { DownloadItem* downItem = qobject_cast(ui->list->itemWidget(ui->list->item(i))); - if (!downItem || (downItem && downItem->isCancelled())) + if (!downItem || (downItem && downItem->isCancelled()) || !downItem->isDownloading()) continue; - if (!downItem->isDownloading()) { - progresses.append(100); - continue; - } else - progresses.append(downItem->progress()); + progresses.append(downItem->progress()); remTimes.append(downItem->remainingTime()); speeds.append(downItem->currentSpeed()); } - if (remTimes.isEmpty()) { - ui->speedLabel->clear(); - setWindowTitle(tr("Download Manager")); -#ifdef W7API - win7.setProgressValue(0, 0); - win7.setProgressState(win7.Normal); -#endif + if (remTimes.isEmpty()) return; - } QTime remaining; foreach (QTime time, remTimes) { @@ -203,12 +193,35 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWha QListWidgetItem* item = new QListWidgetItem(ui->list); DownloadItem* downItem = new DownloadItem(item, reply, path, fileName, fileIcon, openFileOptionsChoosed, this); connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*))); + connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool))); ui->list->setItemWidget(item, downItem); item->setSizeHint(downItem->sizeHint()); show(); activateWindow(); } +void DownloadManager::downloadFinished(bool success) +{ + bool downloadingAllFilesFinished = true; + for (int i = 0; i < ui->list->count(); i++) { + DownloadItem* downItem = qobject_cast(ui->list->itemWidget(ui->list->item(i))); + if (!downItem || (downItem && downItem->isCancelled()) || !downItem->isDownloading()) + continue; + downloadingAllFilesFinished = false; + } + + if (downloadingAllFilesFinished) { + if (success) + mApp->desktopNotifications()->notify(QPixmap(":icons/notifications/download.png"), tr("Download Finished"), tr("All files has been successfuly downloaded.")); + ui->speedLabel->clear(); + setWindowTitle(tr("Download Manager")); +#ifdef W7API + win7.setProgressValue(0, 0); + win7.setProgressState(win7.Normal); +#endif + } +} + void DownloadManager::deleteItem(DownloadItem* item) { if (item && !item->isDownloading()) diff --git a/src/downloads/downloadmanager.h b/src/downloads/downloadmanager.h index fb360c06c..a7dce3f38 100644 --- a/src/downloads/downloadmanager.h +++ b/src/downloads/downloadmanager.h @@ -67,6 +67,7 @@ protected: private slots: void clearList(); void deleteItem(DownloadItem* item); + void downloadFinished(bool success); private: #ifdef W7API diff --git a/src/main.cpp b/src/main.cpp index f32cd8511..e986c38bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,5 +37,6 @@ int main(int argc, char *argv[]) std::cout << "QupZilla already running - activating existing window" << std::endl; return 1; } - return app.exec(); + int result = app.exec(); + return result; } diff --git a/src/other/aboutdialog.cpp b/src/other/aboutdialog.cpp index 95285d960..4b6ba3620 100644 --- a/src/other/aboutdialog.cpp +++ b/src/other/aboutdialog.cpp @@ -21,6 +21,7 @@ #include "webview.h" #include "webpage.h" #include "qtwin.h" +#include "desktopnotificationsfactory.h" AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent), @@ -43,6 +44,7 @@ AboutDialog::AboutDialog(QWidget* parent) : void AboutDialog::buttonClicked() { + mApp->desktopNotifications()->notify(QPixmap(":qupzilla.png"), "heading","text"); if (ui->authorsButton->text() == tr("Authors and Contributors")) showAuthors(); else if (ui->authorsButton->text() == tr("< About QupZilla")) diff --git a/src/other/updater.cpp b/src/other/updater.cpp index 1284db0ac..7cac19f93 100644 --- a/src/other/updater.cpp +++ b/src/other/updater.cpp @@ -18,15 +18,16 @@ #include "updater.h" #include "qupzilla.h" #include "tabwidget.h" +#include "desktopnotificationsfactory.h" Updater::Updater(QupZilla* mainClass, QObject* parent) : QObject(parent) ,p_QupZilla(mainClass) { - createTrayIcon(); #ifndef DEVELOPING QTimer::singleShot(60*1000, this, SLOT(start()) ); //Start checking after 1 minute #endif + QTimer::singleShot(1000, this, SLOT(start())); } void Updater::start() @@ -34,23 +35,8 @@ void Updater::start() startDownloadingUpdateInfo(QUrl(QupZilla::WWWADDRESS+"/update.php?v="+QupZilla::VERSION)); } -void Updater::createTrayIcon() -{ - m_trayIcon = new QSystemTrayIcon(this); - m_trayIconMenu = new QMenu(); - m_trayIconMenu->addAction(tr("Go to download page"), p_QupZilla, SLOT(loadActionUrl()))->setData(QUrl(QupZilla::WWWADDRESS+"/download.php")); - m_trayIconMenu->addAction(tr("Go to QupZilla website"), p_QupZilla, SLOT(loadActionUrl()))->setData(QUrl(QupZilla::WWWADDRESS)); - m_trayIconMenu->addSeparator(); - m_trayIconMenu->addAction(tr("Hide notification"), m_trayIcon, SLOT(hide())); - - - m_trayIcon->setContextMenu(m_trayIconMenu); - m_trayIcon->setIcon(QIcon(":/icons/qupzillaupdate.png")); - m_trayIcon->setToolTip(tr("QupZilla is checking for updates")); -} void Updater::startDownloadingUpdateInfo(const QUrl &url) { -// trayIcon->show(); // Disabled, it was getting focus, so mainwindow lost focus QNetworkAccessManager* manager = new QNetworkAccessManager(); QNetworkReply* reply; reply=manager->get(QNetworkRequest(QUrl(url))); @@ -60,37 +46,16 @@ void Updater::startDownloadingUpdateInfo(const QUrl &url) void Updater::downCompleted(QNetworkReply* reply) { - m_trayIcon->show(); QString html = QString(reply->readAll()); if (html.startsWith("Version:")){ html.remove("Version:"); - if (html != QupZilla::VERSION) { - connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(clicked(QSystemTrayIcon::ActivationReason))); - connect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(goUpdate())); - m_trayIcon->setToolTip(tr("QupZilla found a new version!")); - m_trayIcon->showMessage(tr("New version is available"), tr("New version of QupZilla %1 is available!").arg(html)); - } - else - m_trayIcon->hide(); - } + if (html != QupZilla::VERSION) + mApp->desktopNotifications()->notify(QPixmap(":icons/qupzillaupdate.png"), tr("Update is available"), tr("Newer version of QupZilla is ready to download.")); + } reply->manager()->deleteLater(); } -void Updater::goUpdate() -{ - p_QupZilla->tabWidget()->addView(QUrl(QupZilla::WWWADDRESS+"/download.php"), tr("QupZilla Update")); -} - -void Updater::clicked(QSystemTrayIcon::ActivationReason reason) -{ - if (reason == QSystemTrayIcon::DoubleClick) - p_QupZilla->tabWidget()->addView(QUrl(QupZilla::WWWADDRESS+"/download.php"), tr("QupZilla Update")); -} - Updater::~Updater() { - m_trayIcon->hide(); - delete m_trayIconMenu; - delete m_trayIcon; } diff --git a/src/other/updater.h b/src/other/updater.h index e6d38d1e1..0440272fb 100644 --- a/src/other/updater.h +++ b/src/other/updater.h @@ -36,16 +36,10 @@ signals: public slots: void downCompleted(QNetworkReply* reply); void start(); - void goUpdate(); - void clicked(QSystemTrayIcon::ActivationReason reason); private: - void createTrayIcon(); void startDownloadingUpdateInfo(const QUrl &url); - QSystemTrayIcon* m_trayIcon; - QMenu* m_trayIconMenu; - QupZilla* p_QupZilla; }; diff --git a/src/preferences/preferences.ui b/src/preferences/preferences.ui index 57c8b33b8..6bf7f43aa 100644 --- a/src/preferences/preferences.ui +++ b/src/preferences/preferences.ui @@ -151,11 +151,23 @@ - Plugins + Notifications 8 + + + :/icons/preferences/stock_dialog-question.png:/icons/preferences/stock_dialog-question.png + + + + + Plugins + + + 9 + :/icons/preferences/extension.png:/icons/preferences/extension.png @@ -166,7 +178,7 @@ Other - 9 + 10 @@ -1574,6 +1586,7 @@ +