Implemented a first-run dialog to import Morrowind.ini settings

This commit is contained in:
Pieter van der Kloet 2013-02-20 19:27:04 +01:00
parent 2172fb4229
commit 18d01cd65a
7 changed files with 493 additions and 256 deletions

View file

@ -1,23 +1,6 @@
#include <QApplication> #include <QApplication>
#include <QMessageBox>
#include <QTextStream>
#include <QTextCodec>
#include <QDir>
#include <QAbstractButton>
#include <QPushButton>
#include <QFileDialog>
#include <QFileInfo>
#include <QFile>
#include <QDebug>
#include <components/files/configurationmanager.hpp>
#include "maindialog.hpp" #include "maindialog.hpp"
#include "settings/gamesettings.hpp"
#include "settings/graphicssettings.hpp"
#include "settings/launchersettings.hpp"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -45,154 +28,7 @@ int main(int argc, char *argv[])
QDir::setCurrent(dir.absolutePath()); QDir::setCurrent(dir.absolutePath());
// Create setting file handlers MainDialog mainWin;
Files::ConfigurationManager cfgMgr;
QString userPath = QString::fromStdString(cfgMgr.getUserPath().string());
QString globalPath = QString::fromStdString(cfgMgr.getGlobalPath().string());
GameSettings gameSettings(cfgMgr);
GraphicsSettings graphicsSettings;
LauncherSettings launcherSettings;
QStringList paths;
paths.append(userPath + QString("openmw.cfg"));
paths.append(QString("openmw.cfg"));
paths.append(globalPath + QString("openmw.cfg"));
foreach (const QString &path, paths) {
qDebug() << "Loading: " << path;
QFile file(path);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox msgBox;
msgBox.setWindowTitle("Error opening OpenMW configuration file");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return 0;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
gameSettings.readFile(stream);
}
file.close();
}
if (gameSettings.getDataDirs().isEmpty())
{
QMessageBox msgBox;
msgBox.setWindowTitle("Error detecting Morrowind installation");
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setText(QObject::tr("<br><b>Could not find the Data Files location</b><br><br> \
The directory containing the data files was not found.<br><br> \
Press \"Browse...\" to specify the location manually.<br>"));
QAbstractButton *dirSelectButton =
msgBox.addButton(QObject::tr("B&rowse..."), QMessageBox::ActionRole);
msgBox.exec();
QString selectedFile;
if (msgBox.clickedButton() == dirSelectButton) {
selectedFile = QFileDialog::getOpenFileName(
NULL,
QObject::tr("Select master file"),
QDir::currentPath(),
QString("Morrowind master file (*.esm)"));
}
if (selectedFile.isEmpty())
return 0; // Cancel was clicked;
qDebug() << selectedFile;
QFileInfo info(selectedFile);
// Add the new dir to the settings file and to the data dir container
gameSettings.setValue(QString("data"), info.absolutePath());
gameSettings.addDataDir(info.absolutePath());
}
// On to the graphics settings
QFile localDefault(QString("settings-default.cfg"));
QFile globalDefault(globalPath + QString("settings-default.cfg"));
if (!localDefault.exists() && !globalDefault.exists()) {
QMessageBox msgBox;
msgBox.setWindowTitle("Error reading OpenMW configuration file");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not find settings-default.cfg</b><br><br> \
The problem may be due to an incomplete installation of OpenMW.<br> \
Reinstalling OpenMW may resolve the problem."));
msgBox.exec();
return 0;
}
paths.clear();
paths.append(globalPath + QString("settings-default.cfg"));
paths.append(QString("settings-default.cfg"));
paths.append(userPath + QString("settings.cfg"));
foreach (const QString &path, paths) {
qDebug() << "Loading: " << path;
QFile file(path);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox msgBox;
msgBox.setWindowTitle("Error opening OpenMW configuration file");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return 0;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
graphicsSettings.readFile(stream);
}
file.close();
}
// Now the launcher settings
paths.clear();
paths.append(QString("launcher.cfg"));
paths.append(userPath + QString("launcher.cfg"));
foreach (const QString &path, paths) {
qDebug() << "Loading: " << path;
QFile file(path);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox msgBox;
msgBox.setWindowTitle("Error opening OpenMW configuration file");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return 0;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
launcherSettings.readFile(stream);
}
file.close();
}
MainDialog mainWin(gameSettings, graphicsSettings, launcherSettings);
if (mainWin.setup()) { if (mainWin.setup()) {
mainWin.show(); mainWin.show();

View file

@ -1,9 +1,6 @@
#include <QtGui> #include <QtGui>
#include "settings/gamesettings.hpp" #include "utils/checkablemessagebox.hpp"
#include "settings/graphicssettings.hpp"
#include "settings/launchersettings.hpp"
#include "utils/profilescombobox.hpp" #include "utils/profilescombobox.hpp"
#include "maindialog.hpp" #include "maindialog.hpp"
@ -11,13 +8,8 @@
#include "graphicspage.hpp" #include "graphicspage.hpp"
#include "datafilespage.hpp" #include "datafilespage.hpp"
MainDialog::MainDialog(GameSettings &gameSettings, MainDialog::MainDialog()
GraphicsSettings &graphicsSettings, : mGameSettings(mCfgMgr)
LauncherSettings &launcherSettings)
: mGameSettings(gameSettings)
, mGraphicsSettings(graphicsSettings)
, mLauncherSettings(launcherSettings)
{ {
QWidget *centralWidget = new QWidget(this); QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget); setCentralWidget(centralWidget);
@ -95,7 +87,6 @@ MainDialog::MainDialog(GameSettings &gameSettings,
connect(buttonBox, SIGNAL(accepted()), this, SLOT(play())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(play()));
createIcons(); createIcons();
createPages();
} }
void MainDialog::createIcons() void MainDialog::createIcons()
@ -161,14 +152,148 @@ void MainDialog::createPages()
} }
bool MainDialog::showFirstRunDialog()
{
CheckableMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Morrowind installation detected"));
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion);
int size = QApplication::style()->pixelMetric(QStyle::PM_MessageBoxIconSize);
msgBox.setIconPixmap(icon.pixmap(size, size));
QAbstractButton *importerButton =
msgBox.addButton(tr("Import"), QDialogButtonBox::AcceptRole); // ActionRole doesn't work?!
QAbstractButton *skipButton =
msgBox.addButton(tr("Skip"), QDialogButtonBox::RejectRole);
Q_UNUSED(skipButton); // Surpress compiler unused warning
msgBox.setStandardButtons(QDialogButtonBox::NoButton);
msgBox.setText(tr("<br><b>An existing Morrowind installation was detected</b><br><br> \
Would you like to import settings from Morrowind.ini?<br>"));
msgBox.setCheckBoxText(tr("Include selected masters and plugins (creates a new profile)"));
msgBox.exec();
if (msgBox.clickedButton() == importerButton) {
QString iniPath;
foreach (const QString &path, mGameSettings.getDataDirs()) {
QDir dir(path);
dir.setPath(dir.canonicalPath()); // Resolve symlinks
if (!dir.cdUp())
continue; // Cannot move from Data Files
if (dir.exists(QString("Morrowind.ini")))
iniPath = dir.absoluteFilePath(QString("Morrowind.ini"));
}
if (iniPath.isEmpty()) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error reading Morrowind configuration file"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not find Morrowind.ini</b><br><br> \
The problem may be due to an incomplete installation of Morrowind.<br> \
Reinstalling Morrowind may resolve the problem."));
msgBox.exec();
return false;
}
// Create the file if it doesn't already exist, else the importer will fail
QString path = QString::fromStdString(mCfgMgr.getUserPath().string()) + QString("openmw.cfg");
QFile file(path);
if (!file.exists()) {
if (!file.open(QIODevice::ReadWrite)) {
// File cannot be created
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error writing OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return false;
}
file.close();
}
// Construct the arguments to run the importer
QStringList arguments;
if (msgBox.isChecked())
arguments.append(QString("-g"));
arguments.append(iniPath);
arguments.append(path);
if (!startProgram(QString("mwiniimport"), arguments, false))
return false;
// Re-read the game settings
mGameSettings.clear();
if (!setupGameSettings())
return false;
// Add a new profile
if (msgBox.isChecked()) {
qDebug() << "add a new profile";
mLauncherSettings.setValue(QString("Profiles/CurrentProfile"), QString("Imported"));
mLauncherSettings.remove(QString("Profiles/Imported/master"));
mLauncherSettings.remove(QString("Profiles/Imported/plugin"));
QStringList masters = mGameSettings.values(QString("master"));
QStringList plugins = mGameSettings.values(QString("plugin"));
foreach (const QString &master, masters) {
mLauncherSettings.setMultiValue(QString("Profiles/Imported/master"), master);
}
foreach (const QString &plugin, plugins) {
mLauncherSettings.setMultiValue(QString("Profiles/Imported/plugin"), plugin);
}
}
}
return true;
}
bool MainDialog::setup() bool MainDialog::setup()
{ {
// Call this so we can exit on Ogre errors before mainwindow is shown if (!setupLauncherSettings())
if (!mGraphicsPage->setupOgre()) {
return false; return false;
if (!setupGameSettings())
return false;
if (!setupGraphicsSettings())
return false;
// Check if we need to show the importer
if (mLauncherSettings.value(QString("General/firstrun"), QString("true")) == QLatin1String("true"))
{
if (!showFirstRunDialog())
return false;
} }
// Now create the pages as they need the settings
createPages();
// Call this so we can exit on Ogre errors before mainwindow is shown
if (!mGraphicsPage->setupOgre())
return false;
loadSettings(); loadSettings();
return true; return true;
} }
@ -181,6 +306,164 @@ void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
mPagesWidget->setCurrentIndex(mIconWidget->row(current)); mPagesWidget->setCurrentIndex(mIconWidget->row(current));
} }
bool MainDialog::setupLauncherSettings()
{
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
QStringList paths;
paths.append(QString("launcher.cfg"));
paths.append(userPath + QString("launcher.cfg"));
foreach (const QString &path, paths) {
qDebug() << "Loading: " << path;
QFile file(path);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error opening OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return false;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
mLauncherSettings.readFile(stream);
}
file.close();
}
return true;
}
bool MainDialog::setupGameSettings()
{
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
QString globalPath = QString::fromStdString(mCfgMgr.getGlobalPath().string());
QStringList paths;
paths.append(userPath + QString("openmw.cfg"));
paths.append(QString("openmw.cfg"));
paths.append(globalPath + QString("openmw.cfg"));
foreach (const QString &path, paths) {
qDebug() << "Loading: " << path;
QFile file(path);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error opening OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return false;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
mGameSettings.readFile(stream);
}
file.close();
}
if (mGameSettings.getDataDirs().isEmpty())
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error detecting Morrowind installation"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setText(QObject::tr("<br><b>Could not find the Data Files location</b><br><br> \
The directory containing the data files was not found.<br><br> \
Press \"Browse...\" to specify the location manually.<br>"));
QAbstractButton *dirSelectButton =
msgBox.addButton(QObject::tr("B&rowse..."), QMessageBox::ActionRole);
msgBox.exec();
QString selectedFile;
if (msgBox.clickedButton() == dirSelectButton) {
selectedFile = QFileDialog::getOpenFileName(
NULL,
QObject::tr("Select master file"),
QDir::currentPath(),
QString(tr("Morrowind master file (*.esm)")));
}
if (selectedFile.isEmpty())
return false; // Cancel was clicked;
qDebug() << selectedFile;
QFileInfo info(selectedFile);
// Add the new dir to the settings file and to the data dir container
mGameSettings.setValue(QString("data"), info.absolutePath());
mGameSettings.addDataDir(info.absolutePath());
}
return true;
}
bool MainDialog::setupGraphicsSettings()
{
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
QString globalPath = QString::fromStdString(mCfgMgr.getGlobalPath().string());
QFile localDefault(QString("settings-default.cfg"));
QFile globalDefault(globalPath + QString("settings-default.cfg"));
if (!localDefault.exists() && !globalDefault.exists()) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error reading OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not find settings-default.cfg</b><br><br> \
The problem may be due to an incomplete installation of OpenMW.<br> \
Reinstalling OpenMW may resolve the problem."));
msgBox.exec();
return false;
}
QStringList paths;
paths.append(globalPath + QString("settings-default.cfg"));
paths.append(QString("settings-default.cfg"));
paths.append(userPath + QString("settings.cfg"));
foreach (const QString &path, paths) {
qDebug() << "Loading: " << path;
QFile file(path);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error opening OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return false;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
mGraphicsSettings.readFile(stream);
}
file.close();
}
return true;
}
void MainDialog::loadSettings() void MainDialog::loadSettings()
{ {
int width = mLauncherSettings.value(QString("General/MainWindow/width")).toInt(); int width = mLauncherSettings.value(QString("General/MainWindow/width")).toInt();
@ -206,6 +489,9 @@ void MainDialog::saveSettings()
mLauncherSettings.setValue(QString("General/MainWindow/posx"), posX); mLauncherSettings.setValue(QString("General/MainWindow/posx"), posX);
mLauncherSettings.setValue(QString("General/MainWindow/posy"), posY); mLauncherSettings.setValue(QString("General/MainWindow/posy"), posY);
mLauncherSettings.setValue(QString("General/firstrun"), QString("false"));
} }
void MainDialog::writeSettings() void MainDialog::writeSettings()
@ -221,7 +507,7 @@ void MainDialog::writeSettings()
if (!dir.exists()) { if (!dir.exists()) {
if (!dir.mkpath(userPath)) { if (!dir.mkpath(userPath)) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error creating OpenMW configuration directory"); msgBox.setWindowTitle(tr("Error creating OpenMW configuration directory"));
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not create %0</b><br><br> \ msgBox.setText(tr("<br><b>Could not create %0</b><br><br> \
@ -238,7 +524,7 @@ void MainDialog::writeSettings()
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
// File cannot be opened or created // File cannot be opened or created
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error writing OpenMW configuration file"); msgBox.setWindowTitle(tr("Error writing OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \ msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \
@ -260,7 +546,7 @@ void MainDialog::writeSettings()
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
// File cannot be opened or created // File cannot be opened or created
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error writing OpenMW configuration file"); msgBox.setWindowTitle(tr("Error writing OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \ msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \
@ -282,7 +568,7 @@ void MainDialog::writeSettings()
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
// File cannot be opened or created // File cannot be opened or created
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error writing Launcher configuration file"); msgBox.setWindowTitle(tr("Error writing Launcher configuration file"));
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \ msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \
@ -308,69 +594,108 @@ void MainDialog::closeEvent(QCloseEvent *event)
void MainDialog::play() void MainDialog::play()
{ {
// First do a write of all the configs, just to be sure
//mDataFilesPage->writeConfig();
//mGraphicsPage->writeConfig();
saveSettings(); saveSettings();
writeSettings(); writeSettings();
// Launch the game detached
startProgram(QString("openmw"), true);
qApp->quit();
}
bool MainDialog::startProgram(const QString &name, const QStringList &arguments, bool detached)
{
QString path = name;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString game = "./openmw.exe"; path.append(QString(".exe"));
QFile file(game);
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
QDir dir(QCoreApplication::applicationDirPath()); QDir dir(QCoreApplication::applicationDirPath());
QString game = dir.absoluteFilePath("openmw"); path = dir.absoluteFilePath(name);
QFile file(game);
game = "\"" + game + "\"";
#else #else
QString game = "./openmw"; path.prepend(QString("./"));
QFile file(game);
#endif #endif
QFile file(path);
QProcess process; QProcess process;
QFileInfo info(file); QFileInfo info(file);
if (!file.exists()) { if (!file.exists()) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error starting OpenMW"); msgBox.setWindowTitle(tr("Error starting executable"));
msgBox.setIcon(QMessageBox::Warning); msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not find OpenMW</b><br><br> \ msgBox.setText(tr("<br><b>Could not find %1</b><br><br> \
The OpenMW application is not found.<br> \ The application is not found.<br> \
Please make sure OpenMW is installed correctly and try again.<br>")); Please make sure OpenMW is installed correctly and try again.<br>").arg(info.fileName()));
msgBox.exec(); msgBox.exec();
return; return false;
} }
if (!info.isExecutable()) { if (!info.isExecutable()) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error starting OpenMW"); msgBox.setWindowTitle(tr("Error starting executable"));
msgBox.setIcon(QMessageBox::Warning); msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not start OpenMW</b><br><br> \ msgBox.setText(tr("<br><b>Could not start %1</b><br><br> \
The OpenMW application is not executable.<br> \ The application is not executable.<br> \
Please make sure you have the right permissions and try again.<br>")); Please make sure you have the right permissions and try again.<br>").arg(info.fileName()));
msgBox.exec(); msgBox.exec();
return; return false;
} }
// Start the game // Start the executable
if (!process.startDetached(game)) { if (detached) {
QMessageBox msgBox; if (!process.startDetached(path, arguments)) {
msgBox.setWindowTitle("Error starting OpenMW"); QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical); msgBox.setWindowTitle(tr("Error starting executable"));
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText(tr("<br><b>Could not start OpenMW</b><br><br> \ msgBox.setStandardButtons(QMessageBox::Ok);
An error occurred while starting OpenMW.<br><br> \ msgBox.setText(tr("<br><b>Could not start %1</b><br><br> \
Press \"Show Details...\" for more information.<br>")); An error occurred while starting %1.<br><br> \
msgBox.setDetailedText(process.errorString()); Press \"Show Details...\" for more information.<br>").arg(info.fileName()));
msgBox.exec(); msgBox.setDetailedText(process.errorString());
msgBox.exec();
return; return false;
}
} else { } else {
qApp->quit(); process.start(path, arguments);
if (!process.waitForFinished()) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error starting executable"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not start %1</b><br><br> \
An error occurred while starting %1.<br><br> \
Press \"Show Details...\" for more information.<br>").arg(info.fileName()));
msgBox.setDetailedText(process.errorString());
msgBox.exec();
return false;
}
if (process.exitCode() != 0) {
QString error(process.readAllStandardError());
error.append(tr("\nArguments:\n"));
error.append(arguments.join(" "));
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error running executable"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Executable %1 returned an error</b><br><br> \
An error occurred while running %1.<br><br> \
Press \"Show Details...\" for more information.<br>").arg(info.fileName()));
msgBox.setDetailedText(error);
msgBox.exec();
return false;
}
} }
return true;
} }

View file

@ -5,6 +5,10 @@
#include <components/files/configurationmanager.hpp> #include <components/files/configurationmanager.hpp>
#include "settings/gamesettings.hpp"
#include "settings/graphicssettings.hpp"
#include "settings/launchersettings.hpp"
class QListWidget; class QListWidget;
class QListWidgetItem; class QListWidgetItem;
class QStackedWidget; class QStackedWidget;
@ -16,20 +20,20 @@ class PlayPage;
class GraphicsPage; class GraphicsPage;
class DataFilesPage; class DataFilesPage;
class GameSettings;
class GraphicsSettings;
class LauncherSettings;
class MainDialog : public QMainWindow class MainDialog : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
MainDialog(GameSettings &gameSettings, MainDialog();
GraphicsSettings &GraphicsSettings,
LauncherSettings &launcherSettings);
// GameSettings &gameSettings,
// GraphicsSettings &GraphicsSettings,
// LauncherSettings &launcherSettings);
bool setup(); bool setup();
bool showFirstRunDialog();
public slots: public slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous); void changePage(QListWidgetItem *current, QListWidgetItem *previous);
@ -39,10 +43,17 @@ private:
void createIcons(); void createIcons();
void createPages(); void createPages();
bool setupLauncherSettings();
bool setupGameSettings();
bool setupGraphicsSettings();
void loadSettings(); void loadSettings();
void saveSettings(); void saveSettings();
void writeSettings(); void writeSettings();
inline bool startProgram(const QString &name, bool detached = false) { return startProgram(name, QStringList(), detached); }
bool startProgram(const QString &name, const QStringList &arguments, bool detached = false);
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
QListWidget *mIconWidget; QListWidget *mIconWidget;
@ -54,9 +65,9 @@ private:
Files::ConfigurationManager mCfgMgr; Files::ConfigurationManager mCfgMgr;
GameSettings &mGameSettings; GameSettings mGameSettings;
GraphicsSettings &mGraphicsSettings; GraphicsSettings mGraphicsSettings;
LauncherSettings &mLauncherSettings; LauncherSettings mLauncherSettings;
}; };

View file

@ -25,6 +25,7 @@ void GameSettings::validatePaths()
return; return;
QStringList paths = mSettings.values(QString("data")); QStringList paths = mSettings.values(QString("data"));
qDebug() << "paths " << paths;
Files::PathContainer dataDirs; Files::PathContainer dataDirs;
foreach (const QString &path, paths) { foreach (const QString &path, paths) {
@ -63,9 +64,6 @@ void GameSettings::validatePaths()
if (dir.exists()) if (dir.exists())
mDataLocal = path; mDataLocal = path;
} }
qDebug() << mSettings;
} }
QStringList GameSettings::values(const QString &key, const QStringList &defaultValues) QStringList GameSettings::values(const QString &key, const QStringList &defaultValues)
@ -91,18 +89,24 @@ bool GameSettings::readFile(QTextStream &stream)
QString key = keyRe.cap(1).simplified(); QString key = keyRe.cap(1).simplified();
QString value = keyRe.cap(2).simplified(); QString value = keyRe.cap(2).simplified();
// There can be multiple keys // // There can be multiple keys
if (key == QLatin1String("data") || // if (key == QLatin1String("data") ||
key == QLatin1String("master") || // key == QLatin1String("master") ||
key == QLatin1String("plugin")) // key == QLatin1String("plugin"))
{ // {
// Remove keys from previous config and overwrite them // // Remove keys from previous config and overwrite them
mSettings.remove(key); // mSettings.remove(key);
QStringList values = cache.values(key); // QStringList values = cache.values(key);
if (!values.contains(value)) // Do not insert duplicate values // if (!values.contains(value)) // Do not insert duplicate values
cache.insertMulti(key, value); // cache.insertMulti(key, value);
} else { // } else {
cache.insert(key, value); // cache.insert(key, value);
// }
mSettings.remove(key);
QStringList values = cache.values(key);
if (!values.contains(value)) {
cache.insertMulti(key, value);
} }
} }
} }

View file

@ -41,6 +41,11 @@ public:
mSettings.remove(key); mSettings.remove(key);
} }
inline void clear()
{
mSettings.clear();
}
inline QStringList getDataDirs() { return mDataDirs; } inline QStringList getDataDirs() { return mDataDirs; }
inline void addDataDir(const QString &dir) { if(!dir.isEmpty()) mDataDirs.append(dir); } inline void addDataDir(const QString &dir) { if(!dir.isEmpty()) mDataDirs.append(dir); }
inline QString getDataLocal() {return mDataLocal; } inline QString getDataLocal() {return mDataLocal; }

View file

@ -1,3 +1,34 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "checkablemessagebox.hpp"
#include <QDebug> #include <QDebug>
#include <QVariant> #include <QVariant>
@ -14,21 +45,17 @@
#include <QSpacerItem> #include <QSpacerItem>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "checkablemessagebox.hpp"
/*!
\class Utils::CheckableMessageBox
/* \brief A messagebox suitable for questions with a
class CheckableMessageBox "Do not ask me again" checkbox.
Modified from the one used in Qt Creator
A messagebox suitable for questions with a
"Do not ask me again" checkbox.
Emulates the QMessageBox API with Emulates the QMessageBox API with
static conveniences. The message label can open external URLs. static conveniences. The message label can open external URLs.
*/ */
class CheckableMessageBoxPrivate class CheckableMessageBoxPrivate
{ {
public: public:

View file

@ -1,3 +1,32 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CHECKABLEMESSAGEBOX_HPP #ifndef CHECKABLEMESSAGEBOX_HPP
#define CHECKABLEMESSAGEBOX_HPP #define CHECKABLEMESSAGEBOX_HPP
@ -22,13 +51,13 @@ public:
virtual ~CheckableMessageBox(); virtual ~CheckableMessageBox();
static QDialogButtonBox::StandardButton static QDialogButtonBox::StandardButton
question(QWidget *parent, question(QWidget *parent,
const QString &title, const QString &title,
const QString &question, const QString &question,
const QString &checkBoxText, const QString &checkBoxText,
bool *checkBoxSetting, bool *checkBoxSetting,
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No); QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No);
QString text() const; QString text() const;
void setText(const QString &); void setText(const QString &);