mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-12 11:55:44 -05:00
Collect explicit URLs in one place
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
This commit is contained in:
@@ -26,13 +26,16 @@
|
||||
});
|
||||
*/
|
||||
|
||||
#include "url.h"
|
||||
|
||||
#if __has_include(<QNetworkAccessManager>)
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#endif
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QPointer>
|
||||
#endif
|
||||
|
||||
#ifdef QT_NETWORK_LIB
|
||||
|
||||
@@ -95,6 +98,7 @@ private:
|
||||
class Network
|
||||
{
|
||||
public:
|
||||
static NetworkReplyData * get(Url::ID id);
|
||||
static NetworkReplyData * get(const QString &url);
|
||||
static NetworkReplyData * get(const QUrl &url);
|
||||
};
|
||||
|
||||
33
include/core/url.h
Normal file
33
include/core/url.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#ifndef URL_H
|
||||
#define URL_H
|
||||
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
|
||||
/*
|
||||
Some basic URL functions.
|
||||
This mostly exists to collect all our explicit URLs in one place, in case they ever need to be changed.
|
||||
*/
|
||||
|
||||
namespace Url {
|
||||
enum ID {
|
||||
Manual,
|
||||
ManualProjectFiles,
|
||||
ManualProjectIdentifiers,
|
||||
ManualPlugins,
|
||||
Releases,
|
||||
};
|
||||
const QUrl& get(ID id);
|
||||
|
||||
// Open's the specified URL using the system's default browser.
|
||||
// Returns true if the request was sent (but the operation was not necessarily successful).
|
||||
bool open(const QUrl& url);
|
||||
bool open(ID id);
|
||||
|
||||
// Open's the specified local file using the system's default application.
|
||||
// Returns true if the request was sent (but the operation was not necessarily successful).
|
||||
bool openLocalFile(const QString& path);
|
||||
};
|
||||
|
||||
#endif // URL_H
|
||||
@@ -70,6 +70,7 @@ SOURCES += src/config/keyvalueconfigbase.cpp \
|
||||
src/core/parseutil.cpp \
|
||||
src/core/tile.cpp \
|
||||
src/core/tileset.cpp \
|
||||
src/core/url.cpp \
|
||||
src/core/utility.cpp \
|
||||
src/core/validator.cpp \
|
||||
src/core/version.cpp \
|
||||
@@ -194,6 +195,7 @@ HEADERS += include/config/keyvalueconfigbase.h \
|
||||
include/core/parseutil.h \
|
||||
include/core/tile.h \
|
||||
include/core/tileset.h \
|
||||
include/core/url.h \
|
||||
include/core/utility.h \
|
||||
include/core/validator.h \
|
||||
include/core/version.h \
|
||||
|
||||
@@ -23,6 +23,10 @@ QPointer<NetworkAccessManager> NetworkAccessManager::instance() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
NetworkReplyData * Network::get(Url::ID id) {
|
||||
return Network::get(Url::get(id));
|
||||
}
|
||||
|
||||
NetworkReplyData * Network::get(const QString &url) {
|
||||
return Network::get(QUrl(url));
|
||||
}
|
||||
|
||||
37
src/core/url.cpp
Normal file
37
src/core/url.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "url.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
||||
const QUrl& Url::get(Url::ID id) {
|
||||
switch (id) {
|
||||
case ID::Manual:
|
||||
{static const QUrl url("https://huderlem.github.io/porymap/"); return url;}
|
||||
case ID::ManualProjectFiles:
|
||||
{static const QUrl url("https://huderlem.github.io/porymap/manual/project-files.html#files"); return url;}
|
||||
case ID::ManualProjectIdentifiers:
|
||||
{static const QUrl url("https://huderlem.github.io/porymap/manual/project-files.html#identifiers"); return url;}
|
||||
case ID::ManualPlugins:
|
||||
{static const QUrl url("https://huderlem.github.io/porymap/manual/scripting-capabilities.html"); return url;}
|
||||
|
||||
// We could use the URL ".../releases/latest" to retrieve less data, but this would run into problems if the
|
||||
// most recent item on the releases page is not actually a new release (like the static windows build).
|
||||
// By getting all releases we can also present a multi-version changelog of all changes since the host release.
|
||||
case ID::Releases:
|
||||
{static const QUrl url("https://api.github.com/repos/huderlem/porymap/releases"); return url;}
|
||||
}
|
||||
|
||||
static const QUrl empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
bool Url::open(const QUrl& url) {
|
||||
return QDesktopServices::openUrl(url);
|
||||
}
|
||||
|
||||
bool Url::open(Url::ID id) {
|
||||
return open(get(id));
|
||||
}
|
||||
|
||||
bool Url::openLocalFile(const QString& path) {
|
||||
return open(QUrl::fromLocalFile(path));
|
||||
}
|
||||
@@ -14,9 +14,9 @@
|
||||
#include "validator.h"
|
||||
#include "message.h"
|
||||
#include "eventframes.h"
|
||||
#include "url.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
@@ -2355,7 +2355,7 @@ void Editor::openInTextEditor(const QString &path, int lineNum) {
|
||||
QString command = porymapConfig.textEditorGotoLine;
|
||||
if (command.isEmpty()) {
|
||||
// Open map scripts in the system's default editor.
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||
Url::openLocalFile(path);
|
||||
} else {
|
||||
if (command.contains("%F")) {
|
||||
if (command.contains("%L"))
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
#include "newlocationdialog.h"
|
||||
#include "loadingscreen.h"
|
||||
#include "version.h"
|
||||
#include "url.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDirIterator>
|
||||
#include <QFont>
|
||||
@@ -3026,12 +3026,11 @@ void MainWindow::on_actionOpen_Log_File_triggered() {
|
||||
}
|
||||
|
||||
void MainWindow::on_actionOpen_Config_Folder_triggered() {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)));
|
||||
Url::openLocalFile(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||
}
|
||||
|
||||
void MainWindow::on_actionOpen_Manual_triggered() {
|
||||
static const QUrl url("https://huderlem.github.io/porymap/");
|
||||
QDesktopServices::openUrl(url);
|
||||
Url::open(Url::ID::Manual);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionPreferences_triggered() {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "filterchildrenproxymodel.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDesktopServices>
|
||||
#include <QLineEdit>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "newdefinedialog.h"
|
||||
#include "utility.h"
|
||||
#include "eventfilters.h"
|
||||
#include "url.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QCloseEvent>
|
||||
#include <QDesktopServices>
|
||||
#include <QFormLayout>
|
||||
|
||||
/*
|
||||
@@ -836,13 +836,11 @@ void ProjectSettingsEditor::dialogButtonClicked(QAbstractButton *button) {
|
||||
}
|
||||
|
||||
void ProjectSettingsEditor::openFilesHelp() {
|
||||
static const QUrl url("https://huderlem.github.io/porymap/manual/project-files.html#files");
|
||||
QDesktopServices::openUrl(url);
|
||||
Url::open(Url::ID::ManualProjectFiles);
|
||||
}
|
||||
|
||||
void ProjectSettingsEditor::openIdentifiersHelp() {
|
||||
static const QUrl url("https://huderlem.github.io/porymap/manual/project-files.html#identifiers");
|
||||
QDesktopServices::openUrl(url);
|
||||
Url::open(Url::ID::ManualProjectIdentifiers);
|
||||
}
|
||||
|
||||
// Close event triggered by a project reload. User doesn't need any prompts, just close the window.
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
#include "version.h"
|
||||
#include "url.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QDesktopServices>
|
||||
#include <QTimer>
|
||||
|
||||
UpdatePromoter::UpdatePromoter(QWidget *parent)
|
||||
@@ -60,12 +60,7 @@ void UpdatePromoter::checkForUpdates() {
|
||||
this->resetDialog();
|
||||
this->button_Retry->setEnabled(false);
|
||||
ui->label_Status->setText("Checking for updates...");
|
||||
|
||||
// We could use the URL ".../releases/latest" to retrieve less data, but this would run into problems if the
|
||||
// most recent item on the releases page is not actually a new release (like the static windows build).
|
||||
// By getting all releases we can also present a multi-version changelog of all changes since the host release.
|
||||
static const QUrl url("https://api.github.com/repos/huderlem/porymap/releases");
|
||||
this->get(url);
|
||||
this->get(Url::get(Url::ID::Releases));
|
||||
}
|
||||
|
||||
void UpdatePromoter::get(const QUrl &url) {
|
||||
@@ -186,7 +181,7 @@ void UpdatePromoter::dialogButtonClicked(QAbstractButton *button) {
|
||||
} else if (button == this->button_Retry) {
|
||||
this->checkForUpdates();
|
||||
} else if (button == this->button_Downloads) {
|
||||
QDesktopServices::openUrl(this->downloadUrl);
|
||||
Url::open(this->downloadUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user