Skip to content

Commit 419ffb2

Browse files
committed
feat: add open downloads directory button in download widget
1 parent dfb5b9c commit 419ffb2

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

src/downloadmanagerwidget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,13 @@ void DownloadManagerWidget::remove(DownloadWidget *downloadWidget) {
4646
if (--m_numDownloads == 0)
4747
m_zeroItemsLabel->show();
4848
}
49+
50+
void DownloadManagerWidget::on_open_download_dir_clicked() {
51+
utils::desktopOpenUrl(settings
52+
.value("defaultDownloadLocation",
53+
QStandardPaths::writableLocation(
54+
QStandardPaths::DownloadLocation) +
55+
QDir::separator() +
56+
QApplication::applicationName())
57+
.toString());
58+
}

src/downloadmanagerwidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
#include <QWidget>
5757
#include <QSettings>
58+
#include "utils.h"
5859

5960
QT_BEGIN_NAMESPACE
6061
class QWebEngineDownloadItem;
@@ -74,6 +75,9 @@ class DownloadManagerWidget final : public QWidget, public Ui::DownloadManagerWi
7475
// will be shown on the screen.
7576
void downloadRequested(QWebEngineDownloadItem *webItem);
7677

78+
private slots:
79+
void on_open_download_dir_clicked();
80+
7781
private:
7882
void add(DownloadWidget *downloadWidget);
7983
void remove(DownloadWidget *downloadWidget);

src/downloadmanagerwidget.ui

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>452</width>
9+
<width>450</width>
1010
<height>250</height>
1111
</rect>
1212
</property>
@@ -57,7 +57,7 @@
5757
<rect>
5858
<x>0</x>
5959
<y>0</y>
60-
<width>450</width>
60+
<width>448</width>
6161
<height>248</height>
6262
</rect>
6363
</property>
@@ -109,6 +109,13 @@
109109
</property>
110110
</spacer>
111111
</item>
112+
<item>
113+
<widget class="QPushButton" name="open_download_dir">
114+
<property name="text">
115+
<string>Open Download directory</string>
116+
</property>
117+
</widget>
118+
</item>
112119
</layout>
113120
</widget>
114121
</widget>

src/utils.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#include "utils.h"
2-
#include <QApplication>
3-
#include <QDateTime>
4-
#include <QMessageBox>
5-
#include <QProcessEnvironment>
6-
#include <QRandomGenerator>
7-
#include <QRegularExpression>
82
#include <time.h>
93

104
utils::utils(QObject *parent) : QObject(parent) { setParent(parent); }
@@ -268,3 +262,24 @@ QString utils::GetEnvironmentVar(const QString &variable_name) {
268262
.trimmed();
269263
#endif
270264
}
265+
266+
void utils::desktopOpenUrl(const QString str) {
267+
QProcess *xdg_open = new QProcess(0);
268+
xdg_open->start("xdg-open", QStringList() << str);
269+
if (xdg_open->waitForStarted(1000) == false) {
270+
// try using QdesktopServices
271+
bool opened = QDesktopServices::openUrl(QUrl(str));
272+
if (opened == false) {
273+
qWarning() << "failed to open url" << str;
274+
}
275+
}
276+
connect(xdg_open,
277+
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
278+
&QProcess::finished),
279+
[xdg_open](int exitCode, QProcess::ExitStatus exitStatus) {
280+
Q_UNUSED(exitCode);
281+
Q_UNUSED(exitStatus);
282+
xdg_open->close();
283+
xdg_open->deleteLater();
284+
});
285+
}

src/utils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
#include <QDir>
99
#include <QTextDocument>
1010
#include <QUuid>
11+
#include <QApplication>
12+
#include <QDateTime>
13+
#include <QDesktopServices>
14+
#include <QMessageBox>
15+
#include <QProcessEnvironment>
16+
#include <QRandomGenerator>
17+
#include <QRegularExpression>
18+
#include <QProcess>
1119

1220
class utils : public QObject
1321
{
@@ -31,6 +39,7 @@ public slots:
3139
static float RoundToOneDecimal(float number);
3240
void DisplayExceptionErrorDialog(const QString &error_info);
3341
static QString appDebugInfo();
42+
static void desktopOpenUrl(const QString str);
3443

3544
private slots:
3645
//use refreshCacheSize

0 commit comments

Comments
 (0)