mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Some edits in desktopnotificationsfactory + use it when newer version is
available and after all downloads are completed
This commit is contained in:
parent
cd4763d2d9
commit
cfb889df8a
|
@ -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)
|
||||
|
|
|
@ -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<QPointer<QupZilla> > m_mainWindows;
|
||||
|
||||
|
|
|
@ -70,5 +70,7 @@
|
|||
<file>icons/preferences/stock_keyring.png</file>
|
||||
<file>icons/other/list-add.png</file>
|
||||
<file>icons/other/adblock.png</file>
|
||||
<file>icons/preferences/stock_dialog-question.png</file>
|
||||
<file>icons/notifications/download.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
BIN
src/data/icons/notifications/download.png
Normal file
BIN
src/data/icons/notifications/download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
src/data/icons/preferences/stock_dialog-question.png
Normal file
BIN
src/data/icons/preferences/stock_dialog-question.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
|
@ -27,7 +27,7 @@ DesktopNotification::DesktopNotification(bool settingPosition)
|
|||
void DesktopNotification::show()
|
||||
{
|
||||
ui->icon->setPixmap(m_icon);
|
||||
ui->heading->setText(QString("<b>%1</b>").arg(m_heading));
|
||||
ui->heading->setText(m_heading);
|
||||
ui->text->setText(m_text);
|
||||
|
||||
if (!m_settingPosition) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>356</width>
|
||||
<height>91</height>
|
||||
<height>74</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -35,26 +35,13 @@ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #e4ecf1, stop:1
|
|||
<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">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="icon">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
<width>48</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -62,15 +49,67 @@ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #e4ecf1, stop:1
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="text">
|
||||
<property name="text">
|
||||
<string/>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<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>
|
||||
<widget class="QLabel" name="heading">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel {
|
||||
font: bold;
|
||||
font-size: 13pt;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="text">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <QPoint>
|
||||
#include <QTimer>
|
||||
#include <QPointer>
|
||||
#include <QDir>
|
||||
|
||||
class DesktopNotification;
|
||||
class DesktopNotificationsFactory : public QObject
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
|
||||
signals:
|
||||
void deleteItem(DownloadItem*);
|
||||
void downloadFinished(bool success);
|
||||
|
||||
private slots:
|
||||
void finished();
|
||||
|
|
|
@ -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<DownloadItem*>(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<DownloadItem*>(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())
|
||||
|
|
|
@ -67,6 +67,7 @@ protected:
|
|||
private slots:
|
||||
void clearList();
|
||||
void deleteItem(DownloadItem* item);
|
||||
void downloadFinished(bool success);
|
||||
|
||||
private:
|
||||
#ifdef W7API
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
|
|
@ -151,11 +151,23 @@
|
|||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Plugins</string>
|
||||
<string>Notifications</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string notr="true">8</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/icons.qrc">
|
||||
<normaloff>:/icons/preferences/stock_dialog-question.png</normaloff>:/icons/preferences/stock_dialog-question.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Plugins</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string notr="true">9</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/icons.qrc">
|
||||
<normaloff>:/icons/preferences/extension.png</normaloff>:/icons/preferences/extension.png</iconset>
|
||||
|
@ -166,7 +178,7 @@
|
|||
<string>Other</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string notr="true">9</string>
|
||||
<string notr="true">10</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/icons.qrc">
|
||||
|
@ -1574,6 +1586,7 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_3"/>
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QGridLayout" name="gridLayout_14">
|
||||
<item row="0" column="0" colspan="2">
|
||||
|
|
Loading…
Reference in New Issue
Block a user