Skip to content

Commit

Permalink
Prefer Qt macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-Beirao committed Jun 6, 2024
1 parent a296a73 commit b488b56
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const QChar FOLDER_SEPARATOR = '\\';
const QChar FOLDER_SEPARATOR = '/';
#endif

#if defined Q_OS_MAC || defined Q_OS_LINUX
#if defined Q_OS_MACOS || defined Q_OS_LINUX
const QString dotfolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.dsda-doom";
#endif

Expand Down
14 changes: 7 additions & 7 deletions src/funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

void openIWADsFolder() // CTRL+O runs this function to open the folder where the IWADs should be placed in
{
#ifdef __APPLE__
#ifdef Q_OS_MACOS
QProcess::startDetached("open", {dotfolder});
#elif __linux__
#elif Q_OS_LINUX
QProcess::startDetached("xdg-open", {dotfolder});
#else
QProcess::startDetached("explorer.exe", {execPath});
Expand All @@ -13,7 +13,7 @@ void openIWADsFolder() // CTRL+O runs this function to open the folder where the

QString getFileName(QString filePath)
{
#ifdef _WIN32
#ifdef Q_OS_WIN
return filePath.section(FOLDER_SEPARATOR, -1, -1);
#else
return filePath.section(FOLDER_SEPARATOR, -1, -1);
Expand All @@ -38,7 +38,7 @@ QFileInfoList getFilePath_possibleFiles()

// Find file in DOOMWADPATH
QString doomwadpath = QString(qgetenv("DOOMWADPATH"));
#ifdef _WIN32
#ifdef Q_OS_WIN
QChar token = ';';
#else
QChar token = ':';
Expand Down Expand Up @@ -79,7 +79,7 @@ QString getFilePath(QString fileName)

// Find file in dsda folder
QString dsda_folder;
#ifdef _WIN32
#ifdef Q_OS_WIN
dsda_folder = execPath;
#else
dsda_folder = dotfolder;
Expand All @@ -97,7 +97,7 @@ QString getFilePath(QString fileName)

// Find file in DOOMWADPATH
QString doomwadpath = QString(qgetenv("DOOMWADPATH"));
#ifdef _WIN32
#ifdef Q_OS_WIN
QChar token = ';';
#else
QChar token = ':';
Expand Down Expand Up @@ -163,7 +163,7 @@ QFileInfoList findIwads_possibleFiles()
QString doomwaddirstr = QString(qgetenv("DOOMWADDIR"));

// Find the IWADs in the correct folder depending on the OS
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
#if defined(Q_OS_MACOS) || defined(Q_OS_LINUX)
if (!QDir(dotfolder).exists()) QDir().mkdir(dotfolder);

QDir directory(dotfolder);
Expand Down
11 changes: 5 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "mainwindow.h"
#include <QFile>
#include <QApplication>
#include <QStyleFactory>
#include <QSplashScreen>
#include <QTimer>
#include <QDebug>
#include <QSettings>
#include <QFile>
#include <QMessageBox>
#include <QDebug>
#include <QSettings>
#include <QSplashScreen>
#include <QStyleFactory>
#include <QTimer>

extern QSettings *settings;

Expand Down
18 changes: 9 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void MainWindow::showSSLDialog()

void MainWindow::changeButtonColor(bool isDark)
{
#ifdef __APPLE__
#ifdef Q_OS_MACOS
if (isDark)
{
ui->showCommandLine_pushButton->setStyleSheet("QPushButton{border: 1px solid rgb(120, 120, 120); border-radius:7px; background-color: rgb(50, 50, 50); color: rgb(150, 150, 150)}"
Expand Down Expand Up @@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi

ui->stackedWidget->setAttribute(Qt::WA_TranslucentBackground);

#ifdef _WIN32
#ifdef Q_OS_WIN
ui->tooltip_textBrowser->setHtml(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"><html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">p, li { white-space: pre-wrap; }</style></head><body style=\" font-family:'.AppleSystemUIFont'; font-size:8pt; font-weight:400; font-style:normal;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" "
"font-size:8pt;\">Don't see any IWAD? ^</span></p><p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"><br /></p><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Go to the settings and add the folder you have your IWADs in, to the </span><span style=\" font-size:9pt; "
Expand Down Expand Up @@ -487,7 +487,7 @@ QStringList MainWindow::getArguments()
for (int i = 0; i < ui->wads_listWidget->count(); i++)
{
/*
#ifdef _WIN32
#ifdef Q_OS_WIN
for (int i = 0; i < file.length(); i++)
{
if (file[i] == '/') file[i] = '\\';
Expand Down Expand Up @@ -588,9 +588,9 @@ void MainWindow::on_launchGame_pushButton_clicked(bool returnTooltip, QString ex
}
QTextStream out(&file);

#ifdef __APPLE__
#ifdef Q_OS_MACOS
out << "\"" + launcherFolderPath + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
#elif __linux__
#elif Q_OS_LINUX
out << "\"" + execPath + "/" + exeName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
#else
std::replace(execPath.begin(), execPath.end(), '/', '\\');
Expand All @@ -611,9 +611,9 @@ void MainWindow::on_launchGame_pushButton_clicked(bool returnTooltip, QString ex
if (msgBox.clickedButton() != pButtonYes)
{
QClipboard *clip = QApplication::clipboard();
#ifdef __APPLE__
#ifdef Q_OS_MACOS
clip->setText("\"" + launcherFolderPath + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
#elif __linux__
#elif Q_OS_LINUX
clip->setText("\"" + execPath + "/" + exeName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
#else
std::replace(execPath.begin(), execPath.end(), '/', '\\');
Expand Down Expand Up @@ -647,7 +647,7 @@ void MainWindow::Launch(QStringList arguments)
arguments.append({"-assign", "ansi_endoom=2"});
}

#ifdef __APPLE__
#ifdef Q_OS_MACOS
QFile port = QFile(launcherFolderPath + "/../Resources/" + gameName + "");
if (port.exists())
{
Expand All @@ -664,7 +664,7 @@ void MainWindow::Launch(QStringList arguments)
{
QMessageBox::warning(this, "dsda-launcher", gameName + " was not found in dsda-launcher.app/Contents/Resources/" + gameName);
}
#elif __LINUX__
#elif Q_OS_LINUX
QFile port = QFile(execPath + "/" + exeName);
QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
// Run "which" command to check if dsda-doom exists. if it does then no need to specify a path, just run a process with exeName.
Expand Down
7 changes: 4 additions & 3 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGlobal>

#ifdef _WIN32
#include <windows.h>
#if defined Q_OS_WIN
#include <stdio.h>
#include <tchar.h>
#elif __APPLE__
#include <windows.h>
#elif defined Q_OS_MACOS
#include "Mac.h"
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void MainWindow::on_actionCheckForUpdatesDsdadoom_triggered()

QString path;

#ifdef __APPLE__
#ifdef Q_OS_MACOS
path = launcherFolderPath + "/../Resources/" + gameName;
#elif __linux__
#elif Q_OS_LINUX
path = execPath + "/" + gameName;
#else
path = execPath + "\\" + gameName + ".exe";
Expand Down
6 changes: 3 additions & 3 deletions src/mainwindow_bottom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void MainWindow::on_additionalArguments_pushButton_clicked()

QString path;

#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
path = launcherFolderPath + "/../Resources/" + gameName;
#elif Q_OS_LINUX
path = execPath + "/" + gameName;
Expand All @@ -25,11 +25,11 @@ void MainWindow::on_additionalArguments_pushButton_clicked()
QFile port = QFile(path);
if (port.exists())
{
#ifdef __APPLE__
#ifdef Q_OS_MACOS
QProcess *process = new QProcess;
process->startDetached("sh", {"-c", "echo \"" + path + " --help ; rm /tmp/dsda-doom-params.sh\" > /tmp/dsda-doom-params.sh ; chmod +x /tmp/dsda-doom-params.sh ; open -a Terminal /tmp/dsda-doom-params.sh"});
process->deleteLater();
#elif _WIN32
#elif Q_OS_WIN
system(("start cmd.exe /k \"" + path.toStdString() + "\" --help").c_str());
#else
// xterm is the most reliable terminal to use, but it seems a few distros do not have it
Expand Down
Loading

0 comments on commit b488b56

Please sign in to comment.