From bdc239d1f827308c0fc1e4c202ed0e3f5c71da0b Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 27 Dec 2017 17:06:33 +0100 Subject: Download manager fixes DownloadsWidget - Download widget now in landscape - Download widget no longer docks in the main window, but is a dialog DownloadItemWidget - Download item widget looks more compact - Download details are now a part of the item widgets instead - Download details: save path --- BUGS.md | 5 -- src/lib/downloads/downloadsform.ui | 61 +----------------------- src/lib/downloads/downloadswidget.cpp | 28 ++++++----- src/lib/downloads/downloadswidget.h | 7 +-- src/lib/downloads/widgets/downloaditemform.ui | 28 +++++++++-- src/lib/downloads/widgets/downloaditemwidget.cpp | 19 ++++++-- src/lib/downloads/widgets/downloaditemwidget.h | 3 ++ src/mainwindow.cpp | 3 -- src/mainwindow.h | 2 + src/widgets/mainwindowmenubar.cpp | 10 ++-- src/widgets/mainwindowmenubar.h | 1 - 11 files changed, 71 insertions(+), 96 deletions(-) diff --git a/BUGS.md b/BUGS.md index a3e3239..5881350 100644 --- a/BUGS.md +++ b/BUGS.md @@ -44,14 +44,9 @@ Deny 'resource://' to prevent website fingerprinting ### Downloads - review code -- possibly split off into a dialog window -- properly show download item information -- size in details is -1, but is shown correctly on item - download speed -- In DownloadItem widget: no offsets - Elapsed time, avg speed, remaining time - In details: stop, pause/resume -- flip download widget to landscape - script to run other downloader ### Rewrite documentation diff --git a/src/lib/downloads/downloadsform.ui b/src/lib/downloads/downloadsform.ui index 5ab770f..43a0d49 100644 --- a/src/lib/downloads/downloadsform.ui +++ b/src/lib/downloads/downloadsform.ui @@ -6,16 +6,10 @@ 0 0 - 420 - 600 + 600 + 420 - - - 420 - 600 - - Downloads @@ -23,57 +17,6 @@ - - - - Details - - - - - - Type - - - - - - - - - - - - - - Path - - - - - - - Size - - - - - - - - - - - - - - - - - - - - diff --git a/src/lib/downloads/downloadswidget.cpp b/src/lib/downloads/downloadswidget.cpp index af41397..dc7d5e2 100644 --- a/src/lib/downloads/downloadswidget.cpp +++ b/src/lib/downloads/downloadswidget.cpp @@ -17,7 +17,7 @@ #include "widgets/downloaditemwidget.h" DownloadsWidget::DownloadsWidget(const QString &downloadPath, QWidget *parent) : - QWidget(parent), + QDialog(parent), ui(new Ui::DownloadDialog) { // make sure this dialog does not get deleted on close @@ -25,11 +25,22 @@ DownloadsWidget::DownloadsWidget(const QString &downloadPath, QWidget *parent) : setWindowTitle(tr("Downloads")); ui->setupUi(this); - ui->filePath->setWordWrap(true); m_downloadPath = downloadPath; - connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int))); + connect(ui->listWidget, &QListWidget::currentItemChanged, this, [this](QListWidgetItem *current, QListWidgetItem *previous) { + DownloadItemWidget *currentWidget = qobject_cast(ui->listWidget->itemWidget(current)); + currentWidget->showDetails(); + currentWidget->adjustSize(); + current->setSizeHint(currentWidget->size()); + + DownloadItemWidget *previousWidget = qobject_cast(ui->listWidget->itemWidget(previous)); + if(previousWidget != nullptr) { + previousWidget->hideDetails(); + previousWidget->adjustSize(); + previous->setSizeHint(previousWidget->size()); + } + }); } DownloadsWidget::~DownloadsWidget() @@ -60,13 +71,8 @@ void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) ui->listWidget->setItemWidget(listItem, form); item->accept(); - this->show(); -} -void DownloadsWidget::showItemDetails(int index) -{ - DownloadItemWidget *form = qobject_cast(ui->listWidget->itemWidget(ui->listWidget->item(index))); - ui->mimeType_label->setText(form->item()->mimeType()); - ui->filePath_label->setText(form->item()->path()); - ui->fileSize_label->setText(QString("%1 bytes").arg(form->item()->totalBytes())); + ui->listWidget->setCurrentRow(rowIndex); + + this->show(); } diff --git a/src/lib/downloads/downloadswidget.h b/src/lib/downloads/downloadswidget.h index ffd0814..30bfa38 100644 --- a/src/lib/downloads/downloadswidget.h +++ b/src/lib/downloads/downloadswidget.h @@ -9,14 +9,14 @@ #ifndef DOWNLOADDIALOG_H #define DOWNLOADDIALOG_H -#include +#include namespace Ui { class DownloadDialog; } class QWebEngineDownloadItem; -class DownloadsWidget : public QWidget +class DownloadsWidget : public QDialog { Q_OBJECT @@ -27,9 +27,6 @@ public: public slots: void addDownload(QWebEngineDownloadItem *item); -private slots: - void showItemDetails(int index); - private: Ui::DownloadDialog *ui; QString m_downloadPath; diff --git a/src/lib/downloads/widgets/downloaditemform.ui b/src/lib/downloads/widgets/downloaditemform.ui index 8a8d148..7e63211 100644 --- a/src/lib/downloads/widgets/downloaditemform.ui +++ b/src/lib/downloads/widgets/downloaditemform.ui @@ -7,13 +7,22 @@ 0 0 500 - 70 + 100 + + + 0 + 0 + + Form + + 0 + @@ -26,14 +35,14 @@ - Unknown + Un&known - x MiB / y MiB + &x MiB / y MiB @@ -46,6 +55,19 @@ + + + + + + + TextLabel + + + + + + diff --git a/src/lib/downloads/widgets/downloaditemwidget.cpp b/src/lib/downloads/widgets/downloaditemwidget.cpp index df0b6fc..6145a6e 100644 --- a/src/lib/downloads/widgets/downloaditemwidget.cpp +++ b/src/lib/downloads/widgets/downloaditemwidget.cpp @@ -20,10 +20,13 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa ui->setupUi(this); ui->url_label->setText(item->url().toString()); + ui->detailsWidget->hide(); - 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())); + ui->path_label->setText(item->path()); + + connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState); + connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress); + connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished); } DownloadItemWidget::~DownloadItemWidget() @@ -31,6 +34,16 @@ DownloadItemWidget::~DownloadItemWidget() delete ui; } +void DownloadItemWidget::showDetails() +{ + ui->detailsWidget->show(); +} + +void DownloadItemWidget::hideDetails() +{ + ui->detailsWidget->hide(); +} + QWebEngineDownloadItem *DownloadItemWidget::item() const { return m_item; diff --git a/src/lib/downloads/widgets/downloaditemwidget.h b/src/lib/downloads/widgets/downloaditemwidget.h index cffa32a..c6246da 100644 --- a/src/lib/downloads/widgets/downloaditemwidget.h +++ b/src/lib/downloads/widgets/downloaditemwidget.h @@ -24,6 +24,9 @@ public: explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); ~DownloadItemWidget(); + void showDetails(); + void hideDetails(); + QWebEngineDownloadItem *item() const; QString sizeString(int size) const; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9c1292f..2dd7628 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -246,9 +246,6 @@ void MainWindow::setDownloadsWidget(std::shared_ptr &widget) { Q_ASSERT(widget); m_downloadsWidget = widget; - connect(menuBar->downloadsAction(), &QAction::triggered, this, [this]() { - addTabbedDock(Qt::RightDockWidgetArea, m_downloadsWidget.get()); - }); } void MainWindow::toggleFullscreen() diff --git a/src/mainwindow.h b/src/mainwindow.h index 135f8fb..6ab7f75 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -40,6 +40,8 @@ class MainWindow : public QMainWindow friend class SearchForm; friend class UrlLineEdit; + friend class MainWindowMenuBar; + public: MainWindow(std::shared_ptr config, QWidget *parent = nullptr); ~MainWindow() override; diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp index b5ce229..f8e8ecd 100644 --- a/src/widgets/mainwindowmenubar.cpp +++ b/src/widgets/mainwindowmenubar.cpp @@ -15,6 +15,7 @@ #include #include "browser.h" +#include "downloads/downloadswidget.h" MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr config, MainWindow *parent) : QMenuBar(parent) @@ -56,6 +57,9 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr config, Main m_downloadsAction = toolsMenu->addAction(tr("Downloads")); m_downloadsAction->setParent(parent); m_downloadsAction->setShortcut(QKeySequence(config->value("downloads.shortcut").value().c_str())); + connect(m_downloadsAction, &QAction::triggered, [parent]() { + parent->m_downloadsWidget->show(); + }); m_bookmarksAction = toolsMenu->addAction(tr("Bookmarks")); m_bookmarksAction->setParent(parent); @@ -82,12 +86,6 @@ QAction *MainWindowMenuBar::bookmarksAction() return m_bookmarksAction; } -QAction *MainWindowMenuBar::downloadsAction() -{ - Q_CHECK_PTR(m_downloadsAction); - return m_downloadsAction; -} - void MainWindowMenuBar::setProfileName(const QString &name) { Q_CHECK_PTR(m_profileAction); diff --git a/src/widgets/mainwindowmenubar.h b/src/widgets/mainwindowmenubar.h index 9154f67..367525b 100644 --- a/src/widgets/mainwindowmenubar.h +++ b/src/widgets/mainwindowmenubar.h @@ -21,7 +21,6 @@ public: explicit MainWindowMenuBar(std::shared_ptr config, MainWindow *parent = nullptr); QAction *bookmarksAction(); - QAction *downloadsAction(); void setProfileName(const QString &name); private slots: -- cgit v1.2.1