aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-02-23 17:19:32 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-02-23 17:19:32 +0100
commitabd011f7cf8d298b8bbbe30eedb329094d43c0b9 (patch)
tree300909ce22e5c356a4735dbedaf795a594055c9e
parentMinor features (diff)
downloadsmolbote-abd011f7cf8d298b8bbbe30eedb329094d43c0b9.tar.xz
Download manager improvements
Added shortcut for download dialog Dialog has proper title Settings replaces ~ with home location Showing download item details
-rw-r--r--src/forms/downloaddialog.cpp16
-rw-r--r--src/forms/downloaddialog.h3
-rw-r--r--src/forms/downloaddialog.ui53
-rw-r--r--src/mainwindow.cpp11
-rw-r--r--src/settings.cpp8
-rw-r--r--src/webengine/downloaditemform.cpp7
-rw-r--r--src/webengine/downloaditemform.h3
-rw-r--r--src/webengine/downloaditemform.ui2
-rw-r--r--test/config.ini6
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 <QListWidget>
#include <QLabel>
#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<DownloadItemForm *>(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 @@
<rect>
<x>0</x>
<y>0</y>
- <width>640</width>
+ <width>820</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
- <string>Dialog</string>
+ <string>Downloads</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QListWidget" name="listWidget"/>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QListWidget" name="listWidget"/>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="minimumSize">
+ <size>
+ <width>250</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Details</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>mime</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="mimeType_label">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>path</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLabel" name="path_label">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
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 <QStandardPaths>
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 @@
<rect>
<x>0</x>
<y>0</y>
- <width>600</width>
+ <width>500</width>
<height>80</height>
</rect>
</property>
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