From 419ffb29d24e50c2d0a222ec8003fa35050cf1ac Mon Sep 17 00:00:00 2001 From: Keshav Date: Sat, 7 May 2022 21:08:01 +0530 Subject: feat: add open downloads directory button in download widget --- src/downloadmanagerwidget.cpp | 10 ++++++++++ src/downloadmanagerwidget.h | 4 ++++ src/downloadmanagerwidget.ui | 11 +++++++++-- src/utils.cpp | 27 +++++++++++++++++++++------ src/utils.h | 9 +++++++++ 5 files changed, 53 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/downloadmanagerwidget.cpp b/src/downloadmanagerwidget.cpp index 7f5b300..2d75287 100644 --- a/src/downloadmanagerwidget.cpp +++ b/src/downloadmanagerwidget.cpp @@ -46,3 +46,13 @@ void DownloadManagerWidget::remove(DownloadWidget *downloadWidget) { if (--m_numDownloads == 0) m_zeroItemsLabel->show(); } + +void DownloadManagerWidget::on_open_download_dir_clicked() { + utils::desktopOpenUrl(settings + .value("defaultDownloadLocation", + QStandardPaths::writableLocation( + QStandardPaths::DownloadLocation) + + QDir::separator() + + QApplication::applicationName()) + .toString()); +} diff --git a/src/downloadmanagerwidget.h b/src/downloadmanagerwidget.h index bded369..7fa0950 100644 --- a/src/downloadmanagerwidget.h +++ b/src/downloadmanagerwidget.h @@ -55,6 +55,7 @@ #include #include +#include "utils.h" QT_BEGIN_NAMESPACE class QWebEngineDownloadItem; @@ -74,6 +75,9 @@ public: // will be shown on the screen. void downloadRequested(QWebEngineDownloadItem *webItem); +private slots: + void on_open_download_dir_clicked(); + private: void add(DownloadWidget *downloadWidget); void remove(DownloadWidget *downloadWidget); diff --git a/src/downloadmanagerwidget.ui b/src/downloadmanagerwidget.ui index 2a9e675..c87286b 100644 --- a/src/downloadmanagerwidget.ui +++ b/src/downloadmanagerwidget.ui @@ -6,7 +6,7 @@ 0 0 - 452 + 450 250 @@ -57,7 +57,7 @@ 0 0 - 450 + 448 248 @@ -109,6 +109,13 @@ + + + + Open Download directory + + + diff --git a/src/utils.cpp b/src/utils.cpp index 0c70ef9..f8e5dda 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,10 +1,4 @@ #include "utils.h" -#include -#include -#include -#include -#include -#include #include utils::utils(QObject *parent) : QObject(parent) { setParent(parent); } @@ -268,3 +262,24 @@ QString utils::GetEnvironmentVar(const QString &variable_name) { .trimmed(); #endif } + +void utils::desktopOpenUrl(const QString str) { + QProcess *xdg_open = new QProcess(0); + xdg_open->start("xdg-open", QStringList() << str); + if (xdg_open->waitForStarted(1000) == false) { + // try using QdesktopServices + bool opened = QDesktopServices::openUrl(QUrl(str)); + if (opened == false) { + qWarning() << "failed to open url" << str; + } + } + connect(xdg_open, + static_cast( + &QProcess::finished), + [xdg_open](int exitCode, QProcess::ExitStatus exitStatus) { + Q_UNUSED(exitCode); + Q_UNUSED(exitStatus); + xdg_open->close(); + xdg_open->deleteLater(); + }); +} diff --git a/src/utils.h b/src/utils.h index 93cbaca..3eb697f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -8,6 +8,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include class utils : public QObject { @@ -31,6 +39,7 @@ public slots: static float RoundToOneDecimal(float number); void DisplayExceptionErrorDialog(const QString &error_info); static QString appDebugInfo(); + static void desktopOpenUrl(const QString str); private slots: //use refreshCacheSize -- cgit v1.2.3