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/utils.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/utils.cpp') 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(); + }); +} -- cgit v1.2.3