From e7778ea86e2d5c6544dd35068dd347fee8582868 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 20 May 2020 23:25:16 +1000 Subject: [PATCH] Qt: Move OpenURL to QtUtils namespace --- src/duckstation-qt/mainwindow.cpp | 24 +++++------------------- src/duckstation-qt/qtutils.cpp | 16 ++++++++++++++++ src/duckstation-qt/qtutils.h | 9 ++++++++- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 2aafb3e29..056209418 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -13,11 +13,11 @@ #include "scmversion/scmversion.h" #include "settingsdialog.h" #include "settingwidgetbinder.h" +#include "qtutils.h" #include #include #include #include -#include #include #include #include @@ -277,33 +277,19 @@ void MainWindow::onRemoveDiscActionTriggered() m_host_interface->changeDisc(QString()); } -static void OpenURL(QWidget* parent, const QUrl& qurl) -{ - if (!QDesktopServices::openUrl(qurl)) - { - QMessageBox::critical(parent, QObject::tr("Failed to open URL"), - QObject::tr("Failed to open URL.\n\nThe URL was: %1").arg(qurl.toString())); - } -} - -static void OpenURL(QWidget* parent, const char* url) -{ - return OpenURL(parent, QUrl::fromEncoded(QByteArray(url, static_cast(std::strlen(url))))); -} - void MainWindow::onGitHubRepositoryActionTriggered() { - OpenURL(this, "https://github.com/stenzek/duckstation/"); + QtUtils::OpenURL(this, "https://github.com/stenzek/duckstation/"); } void MainWindow::onIssueTrackerActionTriggered() { - OpenURL(this, "https://github.com/stenzek/duckstation/issues"); + QtUtils::OpenURL(this, "https://github.com/stenzek/duckstation/issues"); } void MainWindow::onDiscordServerActionTriggered() { - OpenURL(this, "https://discord.gg/Buktv3t"); + QtUtils::OpenURL(this, "https://discord.gg/Buktv3t"); } void MainWindow::onAboutActionTriggered() {} @@ -358,7 +344,7 @@ void MainWindow::onGameListContextMenuRequested(const QPoint& point, const GameL connect(menu.addAction(tr("Open Containing Directory...")), &QAction::triggered, [this, entry]() { const QFileInfo fi(QString::fromStdString(entry->path)); - OpenURL(this, QUrl::fromLocalFile(fi.absolutePath())); + QtUtils::OpenURL(this, QUrl::fromLocalFile(fi.absolutePath())); }); menu.addSeparator(); diff --git a/src/duckstation-qt/qtutils.cpp b/src/duckstation-qt/qtutils.cpp index ab81745b8..f86d98af0 100644 --- a/src/duckstation-qt/qtutils.cpp +++ b/src/duckstation-qt/qtutils.cpp @@ -1,9 +1,11 @@ #include "qtutils.h" #include "common/byte_stream.h" #include +#include #include #include #include +#include #include #include #include @@ -615,4 +617,18 @@ bool WriteQByteArrayToStream(QByteArray& arr, ByteStream* stream) return arr.isEmpty() || stream->Write2(arr.data(), static_cast(arr.size())); } +void OpenURL(QWidget* parent, const QUrl& qurl) +{ + if (!QDesktopServices::openUrl(qurl)) + { + QMessageBox::critical(parent, QObject::tr("Failed to open URL"), + QObject::tr("Failed to open URL.\n\nThe URL was: %1").arg(qurl.toString())); + } +} + +void OpenURL(QWidget* parent, const char* url) +{ + return OpenURL(parent, QUrl::fromEncoded(QByteArray(url, static_cast(std::strlen(url))))); +} + } // namespace QtUtils \ No newline at end of file diff --git a/src/duckstation-qt/qtutils.h b/src/duckstation-qt/qtutils.h index 376b1fee5..6ca193fde 100644 --- a/src/duckstation-qt/qtutils.h +++ b/src/duckstation-qt/qtutils.h @@ -1,6 +1,6 @@ #pragma once -#include #include +#include #include #include @@ -10,6 +10,7 @@ class QFrame; class QKeyEvent; class QTableView; class QWidget; +class QUrl; namespace QtUtils { @@ -44,4 +45,10 @@ QByteArray ReadStreamToQByteArray(ByteStream* stream, bool rewind = false); /// Creates a stream from a Qt byte array. bool WriteQByteArrayToStream(QByteArray& arr, ByteStream* stream); +/// Opens a URL with the default handler. +void OpenURL(QWidget* parent, const QUrl& qurl); + +/// Opens a URL string with the default handler. +void OpenURL(QWidget* parent, const char* url); + } // namespace QtUtils \ No newline at end of file