From abd011f7cf8d298b8bbbe30eedb329094d43c0b9 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 23 Feb 2017 17:19:32 +0100 Subject: Download manager improvements Added shortcut for download dialog Dialog has proper title Settings replaces ~ with home location Showing download item details --- src/forms/downloaddialog.cpp | 16 +++++++++++- src/forms/downloaddialog.h | 3 +++ src/forms/downloaddialog.ui | 53 +++++++++++++++++++++++++++++++++++--- src/mainwindow.cpp | 11 ++++---- src/settings.cpp | 8 ++++++ src/webengine/downloaditemform.cpp | 7 +++++ src/webengine/downloaditemform.h | 3 +++ src/webengine/downloaditemform.ui | 2 +- test/config.ini | 6 ++++- 9 files changed, 97 insertions(+), 12 deletions(-) diff --git a/src/forms/downloaddialog.cpp b/src/forms/downloaddialog.cpp index 59756bf..7d26c4b 100644 --- a/src/forms/downloaddialog.cpp +++ b/src/forms/downloaddialog.cpp @@ -27,12 +27,15 @@ #include #include #include "webengine/downloaditemform.h" +#include "settings.h" DownloadDialog::DownloadDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DownloadDialog) { ui->setupUi(this); + + connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int))); } DownloadDialog::~DownloadDialog() @@ -42,8 +45,12 @@ DownloadDialog::~DownloadDialog() void DownloadDialog::addDownload(QWebEngineDownloadItem *item) { + Settings settings; + qDebug("download item: %s", qUtf8Printable(item->url().toString())); - QString filepath = QFileDialog::getSaveFileName(this, tr("Save")); + qDebug("download path: %s", qUtf8Printable(settings.value("downloads/path").toString())); + + QString filepath = QFileDialog::getSaveFileName(this, tr("Save"), settings.value("downloads/path").toString()); if(filepath.isEmpty()) { // user cancelled the save dialog @@ -64,3 +71,10 @@ void DownloadDialog::addDownload(QWebEngineDownloadItem *item) item->accept(); this->show(); } + +void DownloadDialog::showItemDetails(int index) +{ + DownloadItemForm *form = qobject_cast(ui->listWidget->itemWidget(ui->listWidget->item(index))); + ui->mimeType_label->setText(form->item()->mimeType()); + ui->path_label->setText(form->item()->path()); +} diff --git a/src/forms/downloaddialog.h b/src/forms/downloaddialog.h index a28dd92..9a74cf0 100644 --- a/src/forms/downloaddialog.h +++ b/src/forms/downloaddialog.h @@ -39,6 +39,9 @@ public: public slots: void addDownload(QWebEngineDownloadItem *item); +private slots: + void showItemDetails(int index); + private: Ui::DownloadDialog *ui; }; diff --git a/src/forms/downloaddialog.ui b/src/forms/downloaddialog.ui index 75a6faa..f9bc307 100644 --- a/src/forms/downloaddialog.ui +++ b/src/forms/downloaddialog.ui @@ -6,16 +6,63 @@ 0 0 - 640 + 820 480 - Dialog + Downloads - + + + + + + + + + 250 + 0 + + + + Details + + + + + + mime + + + + + + + + + + + + + + path + + + + + + + + + + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5d7c3b7..32c282d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -63,13 +63,12 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : // Tools menu QMenu *toolsMenu = new QMenu(tr("Tools"), ui->menuBar); ui->menuBar->addMenu(toolsMenu); - toolsMenu->addAction(tr("Downloads"), Browser::instance()->downloads(), SLOT(show())); + QAction *downloadsAction = toolsMenu->addAction(tr("Downloads"), Browser::instance()->downloads(), SLOT(show())); + downloadsAction->setShortcut(QKeySequence::fromString(settings.value("downloads/dialogShortcut").toString())); + QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks"), Browser::instance()->bookmarks(), SLOT(show())); + bookmarksAction->setShortcut(QKeySequence(settings.value("bookmarks/dialogShortcut").toString())); + toolsMenu->addSeparator(); toolsMenu->addAction(tr("Blocker"), blocklistManager, SLOT(show())); - QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks")); - bookmarksAction->setShortcut(QKeySequence(settings.value("shortcuts/bookmarks").toString())); - connect(bookmarksAction, &QAction::triggered, [this](){ - Browser::instance()->bookmarks()->show(this); - }); // Profile menu QMenu *profileMenu = new QMenu(tr("Profile"), ui->menuBar); diff --git a/src/settings.cpp b/src/settings.cpp index 25cc6c0..f030dfd 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -19,6 +19,7 @@ ******************************************************************************/ #include "settings.h" +#include QString Settings::_path = QString(""); @@ -41,13 +42,20 @@ QString Settings::staticFilePath() QVariant Settings::value(const QString &key, const QVariant &defaultValue) const { + // get the actual value QString value = QSettings::value(key, defaultValue).toString(); + // check if there is a reference QRegularExpressionMatch referenceMatch = referencePattern.match(value); if(referenceMatch.hasMatch()) { QString pattern = referenceMatch.capturedTexts().first(); value.replace(pattern, this->value(pattern.mid(1, pattern.length()-2)).toString()); } + // check if key is a path, in which case replace '~' with the home location + if(key.endsWith(QLatin1String("path"), Qt::CaseInsensitive)) { + value.replace('~', QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + } + return QVariant(value); } diff --git a/src/webengine/downloaditemform.cpp b/src/webengine/downloaditemform.cpp index f2928f7..599ea08 100644 --- a/src/webengine/downloaditemform.cpp +++ b/src/webengine/downloaditemform.cpp @@ -28,6 +28,8 @@ DownloadItemForm::DownloadItemForm(QWebEngineDownloadItem *item, QWidget *parent QWidget(parent), ui(new Ui::DownloadItemForm) { + m_item = item; + ui->setupUi(this); ui->url_lineEdit->setText(item->url().toString()); @@ -41,6 +43,11 @@ DownloadItemForm::~DownloadItemForm() delete ui; } +QWebEngineDownloadItem *DownloadItemForm::item() const +{ + return m_item; +} + void DownloadItemForm::updateState(QWebEngineDownloadItem::DownloadState state) { switch (state) { diff --git a/src/webengine/downloaditemform.h b/src/webengine/downloaditemform.h index 841e8bf..0b987b9 100644 --- a/src/webengine/downloaditemform.h +++ b/src/webengine/downloaditemform.h @@ -36,6 +36,8 @@ public: explicit DownloadItemForm(QWebEngineDownloadItem *item, QWidget *parent = 0); ~DownloadItemForm(); + QWebEngineDownloadItem *item() const; + private slots: void updateState(QWebEngineDownloadItem::DownloadState state); void updateProgress(qint64 value, qint64 total); @@ -43,6 +45,7 @@ private slots: private: Ui::DownloadItemForm *ui; + QWebEngineDownloadItem *m_item; }; #endif // DOWNLOADITEMFORM_H diff --git a/src/webengine/downloaditemform.ui b/src/webengine/downloaditemform.ui index 5aa46bd..d06dcf4 100644 --- a/src/webengine/downloaditemform.ui +++ b/src/webengine/downloaditemform.ui @@ -6,7 +6,7 @@ 0 0 - 600 + 500 80 diff --git a/test/config.ini b/test/config.ini index c04b942..ea5c258 100644 --- a/test/config.ini +++ b/test/config.ini @@ -11,8 +11,13 @@ profile=Default subscription= [bookmarks] +dialogShortcut=Ctrl+Shift+B path=bookmarks.xbel +[downloads] +dialogShortcut=Ctrl+Shift+D +path=~/Downloads + [window] height=720 width=1280 @@ -20,7 +25,6 @@ title=$title — smolbote [$profile] [shortcuts] focusAddress=F4 -bookmarks=Ctrl+Shift+B tabClose=Ctrl+X tabLeft=Shift+Left tabRight=Shift+Right -- cgit v1.2.1