diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-15 15:39:42 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-15 15:39:42 +0100 |
commit | 8c25c63acf839b09e10d398cfa44d5a45d3ba7c0 (patch) | |
tree | 22fa7a27414d12910c1d360b89aac1221f89ab25 /src/forms | |
parent | Updated firejail profile (diff) | |
download | smolbote-8c25c63acf839b09e10d398cfa44d5a45d3ba7c0.tar.xz |
Download manager
Diffstat (limited to 'src/forms')
-rw-r--r-- | src/forms/downloaddialog.cpp | 46 | ||||
-rw-r--r-- | src/forms/downloaddialog.h | 26 | ||||
-rw-r--r-- | src/forms/downloaddialog.ui | 67 |
3 files changed, 139 insertions, 0 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> |