Save Quake 3 path to settings on Windows. QSettings is wrapped to keep error-prone stringly typed code in one place (QSettings uses string keys).

This commit is contained in:
Jonathan Young 2014-05-09 12:21:42 +10:00
parent 633e2fbd6c
commit 8a231f0b0b
5 changed files with 117 additions and 8 deletions

View file

@ -13,9 +13,11 @@ TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
mainwindow.cpp \
settings.cpp
HEADERS += mainwindow.h
HEADERS += mainwindow.h \
settings.h
FORMS += mainwindow.ui

View file

@ -20,14 +20,35 @@ ioLaunch::~ioLaunch()
void ioLaunch::on_btnLaunch_clicked()
{
QString ioq3;
#ifdef Q_OS_WIN32
if(ioq3 == NULL)
// Prompt the user to set the ioq3 path if the settings value either doesn't exist or is invalid.
bool promptForPath = true;
if (settings.containsQuakePath())
{
const QString path = settings.getQuakePath();
const QDir dir(path);
if (!path.isEmpty() && dir.exists())
promptForPath = false;
}
if(promptForPath)
{
msg.setText("Please select your Quake3 directory");
msg.exec();
QString path = QFileDialog::getExistingDirectory (this, tr("Directory"), directory.path());
ioq3 = QString("\"") + path + QDir::separator() + "ioquake3.x86.exe\" +set r_mode -1";
const QString path = QFileDialog::getExistingDirectory (this, tr("Directory"));
if (path.isEmpty())
return;
settings.setQuakePath(path);
}
ioq3 = QString("\"") + settings.getQuakePath() + QDir::separator() + "ioquake3.x86.exe\" +set r_mode -1";
#elif defined Q_OS_MAC
ioq3 = "open -a ioquake3 --args +set r_mode -1";
#elif defined Q_OS_UNIX

View file

@ -8,6 +8,7 @@
#include <QtGlobal>
#include <QFileDialog>
#include <QDir>
#include "settings.h"
namespace Ui {
class ioLaunch;
@ -41,17 +42,15 @@ private slots:
private:
Ui::ioLaunch *ui;
QString ioq3;
QString resOption;
QString screenOption;
QMessageBox msg;
QMessageBox ioq3Failed;
QDir directory;
int ioWidth;
int ioHeight;
bool ioWedited;
bool ioHedited;
Settings settings;
};
#endif // MAINWINDOW_H

44
settings.cpp Normal file
View file

@ -0,0 +1,44 @@
/*
The MIT License (MIT)
Copyright (c) 2013 The ioquake Group
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <QString>
#include "settings.h"
Settings::Settings() :
settings("ioquake", "launch")
{
}
QString Settings::getQuakePath() const
{
return settings.value("quakePath").toString();
}
bool Settings::containsQuakePath() const
{
return settings.contains("quakePath");
}
void Settings::setQuakePath(const QString &path)
{
settings.setValue("quakePath", path);
}

43
settings.h Normal file
View file

@ -0,0 +1,43 @@
/*
The MIT License (MIT)
Copyright (c) 2013 The ioquake Group
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QSettings>
class QString;
class Settings
{
public:
Settings();
QString getQuakePath() const;
bool containsQuakePath() const;
void setQuakePath(const QString &path);
private:
QSettings settings;
};
#endif // SETTINGS_H