aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Keshav <keshavnrj@gmail.com>2022-05-07 21:08:01 +0530
committerLibravatar Keshav <keshavnrj@gmail.com>2022-05-07 21:08:01 +0530
commit419ffb29d24e50c2d0a222ec8003fa35050cf1ac (patch)
treece91ddcc00021af5acd949a215bba0142b75aa14 /src
parentdfb5b9ca7c8d234fc7ac19b0c354c1228b0270e4 (diff)
downloadwhatsie-419ffb29d24e50c2d0a222ec8003fa35050cf1ac.tar.gz
whatsie-419ffb29d24e50c2d0a222ec8003fa35050cf1ac.zip
feat: add open downloads directory button in download widget
Diffstat (limited to 'src')
-rw-r--r--src/downloadmanagerwidget.cpp10
-rw-r--r--src/downloadmanagerwidget.h4
-rw-r--r--src/downloadmanagerwidget.ui11
-rw-r--r--src/utils.cpp27
-rw-r--r--src/utils.h9
5 files changed, 53 insertions, 8 deletions
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 <QWidget>
#include <QSettings>
+#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 @@
<rect>
<x>0</x>
<y>0</y>
- <width>452</width>
+ <width>450</width>
<height>250</height>
</rect>
</property>
@@ -57,7 +57,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>450</width>
+ <width>448</width>
<height>248</height>
</rect>
</property>
@@ -109,6 +109,13 @@
</property>
</spacer>
</item>
+ <item>
+ <widget class="QPushButton" name="open_download_dir">
+ <property name="text">
+ <string>Open Download directory</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</widget>
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 <QApplication>
-#include <QDateTime>
-#include <QMessageBox>
-#include <QProcessEnvironment>
-#include <QRandomGenerator>
-#include <QRegularExpression>
#include <time.h>
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<void (QProcess::*)(int, QProcess::ExitStatus)>(
+ &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 <QDir>
#include <QTextDocument>
#include <QUuid>
+#include <QApplication>
+#include <QDateTime>
+#include <QDesktopServices>
+#include <QMessageBox>
+#include <QProcessEnvironment>
+#include <QRandomGenerator>
+#include <QRegularExpression>
+#include <QProcess>
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