Skip to content

Commit 350c76d

Browse files
committed
Add openUrl fallback solutions
1 parent 7dfdb47 commit 350c76d

File tree

6 files changed

+56
-14
lines changed

6 files changed

+56
-14
lines changed

src/MainWindow.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
#include <eeleditor.h>
4141
#include <AeqSelector.h>
4242
#include <LiquidEqualizerWidget.h>
43+
#include <utils/DesktopServices.h>
4344
//#include <spectrograph.h>
4445

45-
#include <QDesktopServices>
4646
#include <QButtonGroup>
4747
#include <QClipboard>
4848
#include <QDebug>
@@ -388,13 +388,8 @@ MainWindow::MainWindow(bool statupInTray,
388388
installUnitData();
389389

390390
if (debuggerIsAttached() || system("which ddctoolbox > /dev/null 2>&1")) { // Workaround: do not call system() when GDB is attached
391-
connect(ui->ddctoolbox_install, &QAbstractButton::clicked, []{
392-
int ret = system("xdg-open https://github.com/thepbone/DDCToolbox"); // QDesktopServices::openUrl broken on some KDE systems with Qt 5.15
393-
if(ret > 0)
394-
{
395-
Log::error("MainWindow: xdg-open failed. Trying gio instead.");
396-
system("gio open https://github.com/thepbone/DDCToolbox");
397-
}
391+
connect(ui->ddctoolbox_install, &QAbstractButton::clicked, [this]{
392+
DesktopServices::openUrl("https://github.com/thepbone/DDCToolbox", this);
398393
});
399394
} else {
400395
ui->ddctoolbox_install->setText("Launch application");

src/interface/fragment/FirstLaunchWizard.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <QTimer>
1515
#include <QUrl>
1616

17+
#include <utils/DesktopServices.h>
18+
1719
FirstLaunchWizard::FirstLaunchWizard(QWidget *parent) :
1820
QWidget(parent),
1921
ui(new Ui::FirstLaunchWizard)
@@ -41,12 +43,12 @@ FirstLaunchWizard::FirstLaunchWizard(QWidget *parent) :
4143
connect(ui->p4_next, &QPushButton::clicked, this, [&] {
4244
emit wizardFinished();
4345
});
44-
connect(ui->p4_telegram, &QPushButton::clicked, [] {
45-
QDesktopServices::openUrl(QUrl("https://t.me/joinchat/FTKC2A2bolHkFAyO-fuPjw"));
46+
connect(ui->p4_telegram, &QPushButton::clicked, [this] {
47+
DesktopServices::openUrl("https://t.me/joinchat/FTKC2A2bolHkFAyO-fuPjw", this);
4648
});
4749

48-
connect(ui->p3b_viewReports, &QPushButton::clicked, [] {
49-
QDesktopServices::openUrl(QUrl("https://gist.github.com/ThePBone/3c757623c31400e799ab786ad3bf0709"));
50+
connect(ui->p3b_viewReports, &QPushButton::clicked, [this] {
51+
DesktopServices::openUrl("https://gist.github.com/ThePBone/3c757623c31400e799ab786ad3bf0709", this);
5052
});
5153

5254
ui->p3b_rejectReports->setChecked(!AppConfig::instance().get<bool>(AppConfig::SendCrashReports));

src/interface/fragment/SettingsFragment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#include "interface/TrayIcon.h"
1212
#include "MainWindow.h"
1313
#include "utils/AutoStartManager.h"
14+
#include "utils/DesktopServices.h"
1415

1516
#include <AeqSelector.h>
1617

1718
#include <AeqPackageManager.h>
1819
#include <QCloseEvent>
1920
#include <QDebug>
20-
#include <QDesktopServices>
2121
#include <QGraphicsOpacityEffect>
2222
#include <QMessageBox>
2323
#include <QProcess>
@@ -428,7 +428,7 @@ void SettingsFragment::onLiveprogAutoExtractToggled()
428428

429429
void SettingsFragment::onGithubLinkClicked()
430430
{
431-
QDesktopServices::openUrl(QUrl("https://github.com/Audio4Linux/JDSP4Linux"));
431+
DesktopServices::openUrl("https://github.com/Audio4Linux/JDSP4Linux", this);
432432
}
433433

434434
void SettingsFragment::onAeqDatabaseManageClicked()

src/src.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ SOURCES += \
8080
main.cpp \
8181
utils/AutoStartManager.cpp \
8282
utils/CrashReportSender.cpp \
83+
utils/DesktopServices.cpp \
8384
utils/Log.cpp \
8485
utils/SingleInstanceMonitor.cpp \
8586
utils/dbus/ClientProxy.cpp \
@@ -156,6 +157,7 @@ HEADERS += \
156157
utils/AutoStartManager.h \
157158
utils/CrashReportSender.h \
158159
utils/DebuggerUtils.h \
160+
utils/DesktopServices.h \
159161
utils/Log.h \
160162
utils/SingleInstanceMonitor.h \
161163
utils/VersionMacros.h \

src/utils/DesktopServices.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "DesktopServices.h"
2+
3+
#include "utils/Log.h"
4+
5+
#include <QMessageBox>
6+
7+
bool DesktopServices::openUrl(const QString &url, QWidget* parent)
8+
{
9+
// QDesktopServices::openUrl broken on some KDE systems with Qt 5.15
10+
if(system(QString("xdg-open %1").arg(url).toStdString().c_str()) > 0)
11+
{
12+
Log::warning("DesktopServices::openUrl: xdg-open failed. Trying gio instead.");
13+
if(system(QString("gio open %1").arg(url).toStdString().c_str()) > 0)
14+
{
15+
Log::warning("DesktopServices::openUrl: gio failed. Trying kde-open5 instead.");
16+
if(system(QString("kde-open5 %1").arg(url).toStdString().c_str()) > 0)
17+
{
18+
if(parent != nullptr)
19+
{
20+
QMessageBox::critical(parent, "Something went wrong", "Failed to open URL using 'xdg-open', 'gio open', and 'kde-open5'.\n"
21+
"Please copy this URL manually: " + url);
22+
}
23+
return false;
24+
}
25+
}
26+
}
27+
28+
return true;
29+
}

src/utils/DesktopServices.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef DESKTOPSERVICES_H
2+
#define DESKTOPSERVICES_H
3+
4+
#include <QString>
5+
6+
class QWidget;
7+
8+
class DesktopServices
9+
{
10+
public:
11+
static bool openUrl(const QString& url, QWidget *parent = nullptr);
12+
};
13+
14+
#endif // DESKTOPSERVICES_H

0 commit comments

Comments
 (0)