mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
Qt: Move OpenURL to QtUtils namespace
This commit is contained in:
parent
d41bf86eaa
commit
e7778ea86e
|
@ -13,11 +13,11 @@
|
|||
#include "scmversion/scmversion.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "settingwidgetbinder.h"
|
||||
#include "qtutils.h"
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtGui/QCursor>
|
||||
#include <QtGui/QDesktopServices>
|
||||
#include <QtGui/QWindowStateChangeEvent>
|
||||
#include <QtWidgets/QFileDialog>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
|
@ -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<int>(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();
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "qtutils.h"
|
||||
#include "common/byte_stream.h"
|
||||
#include <QtCore/QMetaObject>
|
||||
#include <QtGui/QDesktopServices>
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QtWidgets/QScrollBar>
|
||||
#include <QtWidgets/QStyle>
|
||||
#include <QtWidgets/QTableView>
|
||||
|
@ -615,4 +617,18 @@ bool WriteQByteArrayToStream(QByteArray& arr, ByteStream* stream)
|
|||
return arr.isEmpty() || stream->Write2(arr.data(), static_cast<u32>(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<int>(std::strlen(url)))));
|
||||
}
|
||||
|
||||
} // namespace QtUtils
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QString>
|
||||
#include <initializer_list>
|
||||
#include <optional>
|
||||
|
||||
|
@ -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
|
Loading…
Reference in a new issue