Skip to content

Commit

Permalink
Merge pull request #12698 from fwcd/desktophelper-openurl
Browse files Browse the repository at this point in the history
DesktopHelper: Add openUrl abstraction to support iOS
  • Loading branch information
Swiftb0y authored Feb 1, 2024
2 parents 034eb6c + 0bd5833 commit ae53865
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "controllers/dlgprefcontroller.h"

#include <QDesktopServices>
#include <QDir>
#include <QFileDialog>
#include <QFileInfo>
Expand All @@ -21,6 +20,7 @@
#include "defs_urls.h"
#include "moc_dlgprefcontroller.cpp"
#include "preferences/usersettings.h"
#include "util/desktophelper.h"
#include "util/string.h"

namespace {
Expand Down Expand Up @@ -113,7 +113,7 @@ DlgPrefController::DlgPrefController(
connect(m_ui.labelLoadedMappingScriptFileLinks,
&QLabel::linkActivated,
[](const QString& path) {
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
mixxx::DesktopHelper::openUrl(QUrl::fromLocalFile(path));
});

// Input mappings
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/dlgprefcontrollers.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "controllers/dlgprefcontrollers.h"

#include <QDesktopServices>

#include "controllers/controller.h"
#include "controllers/controllermanager.h"
#include "controllers/defs_controllers.h"
#include "controllers/dlgprefcontroller.h"
#include "defs_urls.h"
#include "moc_dlgprefcontrollers.cpp"
#include "preferences/dialog/dlgpreferences.h"
#include "util/desktophelper.h"
#include "util/string.h"

DlgPrefControllers::DlgPrefControllers(DlgPreferences* pPreferences,
Expand Down Expand Up @@ -78,7 +77,7 @@ DlgPrefControllers::~DlgPrefControllers() {
}

void DlgPrefControllers::openLocalFile(const QString& file) {
QDesktopServices::openUrl(QUrl::fromLocalFile(file));
mixxx::DesktopHelper::openUrl(QUrl::fromLocalFile(file));
}

void DlgPrefControllers::slotUpdate() {
Expand Down
4 changes: 2 additions & 2 deletions src/dialog/dlgabout.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "dialog/dlgabout.h"

#include <QDebug>
#include <QDesktopServices>
#include <QFile>
#include <QLocale>

#include "defs_urls.h"
#include "moc_dlgabout.cpp"
#include "util/color/color.h"
#include "util/desktophelper.h"
#include "util/versionstore.h"

DlgAbout::DlgAbout()
Expand Down Expand Up @@ -411,7 +411,7 @@ DlgAbout::DlgAbout()
}
btnDonate->setText(tr("Donate"));
connect(btnDonate, &QPushButton::clicked, this, [] {
QDesktopServices::openUrl(QUrl(MIXXX_DONATE_URL));
mixxx::DesktopHelper::openUrl(QUrl(MIXXX_DONATE_URL));
});

connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgAbout::accept);
Expand Down
4 changes: 2 additions & 2 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <QCloseEvent>
#include <QDebug>
#include <QDesktopServices>
#include <QFileDialog>
#include <QOpenGLContext>
#include <QUrl>
Expand Down Expand Up @@ -48,6 +47,7 @@
#include "sources/soundsourceproxy.h"
#include "track/track.h"
#include "util/debug.h"
#include "util/desktophelper.h"
#include "util/sandbox.h"
#include "util/timer.h"
#include "util/versionstore.h"
Expand Down Expand Up @@ -554,7 +554,7 @@ QDialog::DialogCode MixxxMainWindow::soundDeviceErrorDlg(
*retryClicked = true;
return QDialog::Accepted;
} else if (msgBox.clickedButton() == wikiButton) {
QDesktopServices::openUrl(QUrl(MIXXX_WIKI_TROUBLESHOOTING_SOUND_URL));
mixxx::DesktopHelper::openUrl(QUrl(MIXXX_WIKI_TROUBLESHOOTING_SOUND_URL));
wikiButton->setEnabled(false);
} else if (msgBox.clickedButton() == reconfigureButton) {
msgBox.hide();
Expand Down
4 changes: 2 additions & 2 deletions src/preferences/dialog/dlgpreferences.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "preferences/dialog/dlgpreferences.h"

#include <QDesktopServices>
#include <QDialog>
#include <QEvent>
#include <QMoveEvent>
Expand All @@ -16,6 +15,7 @@
#include "preferences/dialog/dlgpreflibrary.h"
#include "preferences/dialog/dlgprefsound.h"
#include "util/color/color.h"
#include "util/desktophelper.h"
#include "util/widgethelper.h"

#ifdef __VINYLCONTROL__
Expand Down Expand Up @@ -436,7 +436,7 @@ void DlgPreferences::slotButtonPressed(QAbstractButton* pButton) {
if (pCurrentPage) {
QUrl helpUrl = pCurrentPage->helpUrl();
DEBUG_ASSERT(helpUrl.isValid());
QDesktopServices::openUrl(helpUrl);
mixxx::DesktopHelper::openUrl(helpUrl);
}
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions src/preferences/dialog/dlgpreflibrary.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "preferences/dialog/dlgpreflibrary.h"

#include <QApplication>
#include <QDesktopServices>
#include <QDir>
#include <QFileDialog>
#include <QFontDialog>
Expand All @@ -18,6 +17,7 @@
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "moc_dlgpreflibrary.cpp"
#include "util/desktophelper.h"
#include "widget/wsearchlineedit.h"

using namespace mixxx::library::prefs;
Expand Down Expand Up @@ -66,7 +66,7 @@ DlgPrefLibrary::DlgPrefLibrary(
connect(PushButtonOpenSettingsDir,
&QPushButton::clicked,
[settingsDir] {
QDesktopServices::openUrl(QUrl::fromLocalFile(settingsDir));
mixxx::DesktopHelper::openUrl(QUrl::fromLocalFile(settingsDir));
});

// Set default direction as stored in config file
Expand Down Expand Up @@ -124,7 +124,7 @@ DlgPrefLibrary::DlgPrefLibrary(
connect(label_settingsManualLink,
&QLabel::linkActivated,
[](const QString& url) {
QDesktopServices::openUrl(url);
mixxx::DesktopHelper::openUrl(url);
});

connect(checkBox_SyncTrackMetadata,
Expand Down
1 change: 0 additions & 1 deletion src/util/cmdlineargs.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <QCoreApplication>
#include <QDesktopServices>
#include <QDir>
#include <QList>
#include <QString>
Expand Down
18 changes: 16 additions & 2 deletions src/util/desktophelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const QString kSelectInXfce = "xf";
QString sSelectInFileBrowserCommand;

QString getSelectInFileBrowserCommand() {
#if defined(Q_OS_MAC)
#if defined(Q_OS_MACOS)
return "open -R";
#elif defined(Q_OS_WIN)
return "explorer.exe /select,";
Expand Down Expand Up @@ -169,10 +169,24 @@ void DesktopHelper::openInFileBrowser(const QStringList& paths) {
dirPath = dir.absolutePath();
qDebug() << "opening:" << dirPath;
if (!openedDirs.contains(dirPath)) {
QDesktopServices::openUrl(QUrl::fromLocalFile(dirPath));
openUrl(QUrl::fromLocalFile(dirPath));
openedDirs.insert(dirPath);
}
}
}

bool DesktopHelper::openUrl(const QUrl& url) {
#ifdef Q_OS_IOS
QUrl urlToOpen = url;
// Open files and folders in the iOS Files app
// See https://stackoverflow.com/q/46499842
if (urlToOpen.scheme() == "file") {
urlToOpen.setScheme("shareddocuments");
}
return QDesktopServices::openUrl(urlToOpen);
#else
return QDesktopServices::openUrl(url);
#endif
}

} // namespace mixxx
3 changes: 3 additions & 0 deletions src/util/desktophelper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <QUrl>
#include <QtGlobal>

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -11,6 +12,8 @@ namespace mixxx {
class DesktopHelper {
public:
static void openInFileBrowser(const QStringList& paths);

static bool openUrl(const QUrl& url);
};

} // namespace mixxx
6 changes: 3 additions & 3 deletions src/widget/wfindonwebmenu.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "wfindonwebmenu.h"

#include <QDesktopServices>
#include <QMenu>
#include <QtDebug>

#include "moc_wfindonwebmenu.cpp"
#include "track/track.h"
#include "util/desktophelper.h"

WFindOnWebMenu::WFindOnWebMenu(QWidget* parent)
: QMenu(tr("Find on Web"), parent) {
Expand Down Expand Up @@ -36,8 +36,8 @@ QString WFindOnWebMenu::composeSearchQuery(
}

void WFindOnWebMenu::openInBrowser(const QUrl& url) {
if (!QDesktopServices::openUrl(url)) {
qWarning() << "QDesktopServices::openUrl() failed for " << url;
if (!mixxx::DesktopHelper::openUrl(url)) {
qWarning() << "DesktopHelper::openUrl() failed for " << url;
DEBUG_ASSERT(false);
}
}
3 changes: 2 additions & 1 deletion src/widget/wmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "defs_urls.h"
#include "moc_wmainmenubar.cpp"
#include "util/cmdlineargs.h"
#include "util/desktophelper.h"
#include "util/experiment.h"
#include "vinylcontrol/defs_vinylcontrol.h"

Expand Down Expand Up @@ -733,7 +734,7 @@ void WMainMenuBar::slotDeveloperDebugger(bool toggle) {
}

void WMainMenuBar::slotVisitUrl(const QUrl& url) {
QDesktopServices::openUrl(url);
mixxx::DesktopHelper::openUrl(url);
}

void WMainMenuBar::createVisibilityControl(QAction* pAction,
Expand Down

0 comments on commit ae53865

Please sign in to comment.