aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-01-15 15:39:42 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-01-15 15:39:42 +0100
commit8c25c63acf839b09e10d398cfa44d5a45d3ba7c0 (patch)
tree22fa7a27414d12910c1d360b89aac1221f89ab25 /src
parentUpdated firejail profile (diff)
downloadsmolbote-8c25c63acf839b09e10d398cfa44d5a45d3ba7c0.tar.xz
Download manager
Diffstat (limited to 'src')
-rw-r--r--src/forms/downloaddialog.cpp46
-rw-r--r--src/forms/downloaddialog.h26
-rw-r--r--src/forms/downloaddialog.ui67
-rw-r--r--src/mainwindow.cpp5
-rw-r--r--src/mainwindow.h2
-rw-r--r--src/smolbote.pro12
-rw-r--r--src/webengine/downloaditemform.cpp57
-rw-r--r--src/webengine/downloaditemform.h28
-rw-r--r--src/webengine/downloaditemform.ui57
9 files changed, 297 insertions, 3 deletions
diff --git a/src/forms/downloaddialog.cpp b/src/forms/downloaddialog.cpp
new file mode 100644
index 0000000..4943fcc
--- /dev/null
+++ b/src/forms/downloaddialog.cpp
@@ -0,0 +1,46 @@
+#include "downloaddialog.h"
+#include "ui_downloaddialog.h"
+
+#include <QWebEngineDownloadItem>
+#include <QUrl>
+#include <QFileDialog>
+#include <QListWidget>
+#include <QLabel>
+#include "webengine/downloaditemform.h"
+
+DownloadDialog::DownloadDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::DownloadDialog)
+{
+ ui->setupUi(this);
+}
+
+DownloadDialog::~DownloadDialog()
+{
+ delete ui;
+}
+
+void DownloadDialog::addDownload(QWebEngineDownloadItem *item)
+{
+ qDebug("download item: %s", qUtf8Printable(item->url().toString()));
+ QString filepath = QFileDialog::getSaveFileName(this, tr("Save"));
+
+ if(filepath.isEmpty()) {
+ // user cancelled the save dialog
+ item->cancel();
+ return;
+ }
+
+ item->setPath(filepath);
+
+ QListWidgetItem *listItem = new QListWidgetItem();
+ int rowIndex = ui->listWidget->count();
+ ui->listWidget->insertItem(rowIndex, listItem);
+
+ DownloadItemForm *form = new DownloadItemForm(item, this);
+ listItem->setSizeHint(form->size());
+ ui->listWidget->setItemWidget(listItem, form);
+
+ item->accept();
+ this->show();
+}
diff --git a/src/forms/downloaddialog.h b/src/forms/downloaddialog.h
new file mode 100644
index 0000000..bec0037
--- /dev/null
+++ b/src/forms/downloaddialog.h
@@ -0,0 +1,26 @@
+#ifndef DOWNLOADDIALOG_H
+#define DOWNLOADDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class DownloadDialog;
+}
+
+class QWebEngineDownloadItem;
+class DownloadDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit DownloadDialog(QWidget *parent = 0);
+ ~DownloadDialog();
+
+public slots:
+ void addDownload(QWebEngineDownloadItem *item);
+
+private:
+ Ui::DownloadDialog *ui;
+};
+
+#endif // DOWNLOADDIALOG_H
diff --git a/src/forms/downloaddialog.ui b/src/forms/downloaddialog.ui
new file mode 100644
index 0000000..75a6faa
--- /dev/null
+++ b/src/forms/downloaddialog.ui
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DownloadDialog</class>
+ <widget class="QDialog" name="DownloadDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>640</width>
+ <height>480</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QListWidget" name="listWidget"/>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>DownloadDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>DownloadDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 638ba7f..9e028e4 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -9,9 +9,11 @@
#include "forms/profiledialog.h"
#include <QApplication>
#include <QInputDialog>
+#include <QWebEngineDownloadItem>
MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
QMainWindow(parent),
+ downloadManager(new DownloadDialog(this)),
ui(new Ui::MainWindow),
navigationToolBar(new QToolBar(this)),
tabToolBar(new QToolBar(this)),
@@ -43,6 +45,7 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
ui->menuBar->setCornerWidget(rightBar);
profileMenu->addAction(tr("Edit profile"), this, SLOT(createProfileDialog()));
profileMenu->addAction(tr("Load profile"), this, SLOT(handleLoadProfile()));
+ profileMenu->addAction(tr("Downloads"), downloadManager, SLOT(show()));
//profileMenu->addAction(tr("Settings"));
//profileMenu->addAction(tr("Cookies"));
@@ -99,6 +102,8 @@ void MainWindow::loadProfile(const QString &name)
qDebug("Using profile: %s", qUtf8Printable(profileName));
profile = new WebEngineProfile(profileName, this);
}
+
+ connect(profile, SIGNAL(downloadRequested(QWebEngineDownloadItem*)), downloadManager, SLOT(addDownload(QWebEngineDownloadItem*)));
}
void MainWindow::handleLoadProfile()
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 2eedebf..2ad88b8 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -8,6 +8,7 @@
#include "webengine/webengineprofile.h"
#include <QUrl>
#include "widgets/webviewtabbar.h"
+#include "forms/downloaddialog.h"
namespace Ui {
class MainWindow;
@@ -42,6 +43,7 @@ private slots:
private:
Browser *browserInstance;
+ DownloadDialog *downloadManager;
QString profileName;
WebEngineProfile *profile = nullptr;
diff --git a/src/smolbote.pro b/src/smolbote.pro
index d2eaa8c..bf7a05d 100644
--- a/src/smolbote.pro
+++ b/src/smolbote.pro
@@ -17,14 +17,20 @@ SOURCES += main.cpp \
widgets/webviewtabbar.cpp \
settings.cpp \
forms/profiledialog.cpp \
- webengine/webengineprofile.cpp
+ webengine/webengineprofile.cpp \
+ forms/downloaddialog.cpp \
+ webengine/downloaditemform.cpp
HEADERS += mainwindow.h \
browser.h \
widgets/webviewtabbar.h \
settings.h \
forms/profiledialog.h \
- webengine/webengineprofile.h
+ webengine/webengineprofile.h \
+ forms/downloaddialog.h \
+ webengine/downloaditemform.h
FORMS += mainwindow.ui \
- forms/profiledialog.ui
+ forms/profiledialog.ui \
+ forms/downloaddialog.ui \
+ webengine/downloaditemform.ui
diff --git a/src/webengine/downloaditemform.cpp b/src/webengine/downloaditemform.cpp
new file mode 100644
index 0000000..717a41d
--- /dev/null
+++ b/src/webengine/downloaditemform.cpp
@@ -0,0 +1,57 @@
+#include "downloaditemform.h"
+#include "ui_downloaditemform.h"
+
+#include <QUrl>
+#include <QLabel>
+
+DownloadItemForm::DownloadItemForm(QWebEngineDownloadItem *item, QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::DownloadItemForm)
+{
+ ui->setupUi(this);
+ ui->url_lineEdit->setText(item->url().toString());
+
+ connect(item, SIGNAL(stateChanged(QWebEngineDownloadItem::DownloadState)), this, SLOT(updateState(QWebEngineDownloadItem::DownloadState)));
+ connect(item, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64)));
+ connect(item, SIGNAL(finished()), this, SLOT(updateFinished()));
+}
+
+DownloadItemForm::~DownloadItemForm()
+{
+ delete ui;
+}
+
+void DownloadItemForm::updateState(QWebEngineDownloadItem::DownloadState state)
+{
+ switch (state) {
+ case QWebEngineDownloadItem::DownloadRequested:
+ ui->status_label->setText(tr("Requested"));
+ break;
+ case QWebEngineDownloadItem::DownloadInProgress:
+ ui->status_label->setText(tr("In progress"));
+ break;
+ case QWebEngineDownloadItem::DownloadCompleted:
+ ui->status_label->setText(tr("Completed"));
+ break;
+ case QWebEngineDownloadItem::DownloadCancelled:
+ ui->status_label->setText(tr("Cancelled"));
+ break;
+ case QWebEngineDownloadItem::DownloadInterrupted:
+ ui->status_label->setText(tr("Interrupted"));
+ break;
+ default:
+ break;
+ }
+}
+
+void DownloadItemForm::updateProgress(qint64 value, qint64 total)
+{
+ ui->progressBar->setMaximum(total);
+ ui->progressBar->setValue(value);
+}
+
+void DownloadItemForm::updateFinished()
+{
+ ui->progressBar->setMaximum(100);
+ ui->progressBar->setValue(100);
+}
diff --git a/src/webengine/downloaditemform.h b/src/webengine/downloaditemform.h
new file mode 100644
index 0000000..996b876
--- /dev/null
+++ b/src/webengine/downloaditemform.h
@@ -0,0 +1,28 @@
+#ifndef DOWNLOADITEMFORM_H
+#define DOWNLOADITEMFORM_H
+
+#include <QWidget>
+#include <QWebEngineDownloadItem>
+
+namespace Ui {
+class DownloadItemForm;
+}
+
+class DownloadItemForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit DownloadItemForm(QWebEngineDownloadItem *item, QWidget *parent = 0);
+ ~DownloadItemForm();
+
+private slots:
+ void updateState(QWebEngineDownloadItem::DownloadState state);
+ void updateProgress(qint64 value, qint64 total);
+ void updateFinished();
+
+private:
+ Ui::DownloadItemForm *ui;
+};
+
+#endif // DOWNLOADITEMFORM_H
diff --git a/src/webengine/downloaditemform.ui b/src/webengine/downloaditemform.ui
new file mode 100644
index 0000000..5aa46bd
--- /dev/null
+++ b/src/webengine/downloaditemform.ui
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DownloadItemForm</class>
+ <widget class="QWidget" name="DownloadItemForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>80</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>URL</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="url_lineEdit">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="status_label">
+ <property name="text">
+ <string>Unknown</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="value">
+ <number>24</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>