Changed the way the launcher exits and polished the error handling code

This commit is contained in:
Pieter van der Kloet 2012-06-20 20:43:51 +02:00
parent 7dad67e423
commit 6a2bcddef5
8 changed files with 84 additions and 68 deletions

View file

@ -140,7 +140,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent)
createActions(); createActions();
setupConfig(); setupConfig();
setupDataFiles(); //setupDataFiles();
} }
@ -189,7 +189,7 @@ void DataFilesPage::setupConfig()
} }
void DataFilesPage::setupDataFiles() bool DataFilesPage::setupDataFiles()
{ {
// We use the Configuration Manager to retrieve the configuration values // We use the Configuration Manager to retrieve the configuration values
boost::program_options::variables_map variables; boost::program_options::variables_map variables;
@ -245,21 +245,15 @@ void DataFilesPage::setupDataFiles()
mCfgMgr.processPaths(mDataDirs); mCfgMgr.processPaths(mDataDirs);
} else { } else {
// Cancel from within the dir selection dialog // Cancel from within the dir selection dialog
break; return false;
} }
} else { } else {
// Cancel // Cancel
break; return false;
} }
} }
// Check if cancel was clicked because we can't exit from while loop
if (mDataDirs.empty()) {
QApplication::exit(1);
return;
}
// Create a file collection for the data dirs // Create a file collection for the data dirs
Files::Collections fileCollections(mDataDirs, !variables["fs-strict"].as<bool>()); Files::Collections fileCollections(mDataDirs, !variables["fs-strict"].as<bool>());
@ -362,6 +356,7 @@ void DataFilesPage::setupDataFiles()
} }
readConfig(); readConfig();
return true;
} }
void DataFilesPage::createActions() void DataFilesPage::createActions()
@ -1076,7 +1071,7 @@ void DataFilesPage::writeConfig(QString profile)
Please make sure you have the right permissions and try again.<br>").arg(pathStr)); Please make sure you have the right permissions and try again.<br>").arg(pathStr));
msgBox.exec(); msgBox.exec();
qApp->exit(1); qApp->quit();
return; return;
} }
} }
@ -1093,7 +1088,7 @@ void DataFilesPage::writeConfig(QString profile)
Please make sure you have the right permissions and try again.<br>").arg(file.fileName())); Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
msgBox.exec(); msgBox.exec();
qApp->exit(1); qApp->quit();
return; return;
} }
@ -1124,7 +1119,7 @@ void DataFilesPage::writeConfig(QString profile)
Please make sure you have the right permissions and try again.<br>").arg(file.fileName())); Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
msgBox.exec(); msgBox.exec();
qApp->exit(1); qApp->quit();
return; return;
} }

View file

@ -34,6 +34,7 @@ public:
ComboBox *mProfilesComboBox; ComboBox *mProfilesComboBox;
void writeConfig(QString profile = QString()); void writeConfig(QString profile = QString());
bool setupDataFiles();
public slots: public slots:
void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
@ -92,7 +93,6 @@ private:
void removePlugins(const QModelIndex &index); void removePlugins(const QModelIndex &index);
void uncheckPlugins(); void uncheckPlugins();
void createActions(); void createActions();
void setupDataFiles();
void setupConfig(); void setupConfig();
void readConfig(); void readConfig();
void scrollToSelection(); void scrollToSelection();

View file

@ -28,13 +28,13 @@ QString FileDialog::getExistingDirectory(QWidget *parent,
// create a non-native file dialog // create a non-native file dialog
FileDialog dialog; FileDialog dialog;
dialog.setFileMode(DirectoryOnly); dialog.setFileMode(DirectoryOnly);
dialog.setOptions(options & (DontUseNativeDialog | ShowDirsOnly)); dialog.setOptions(options |= QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly);
if (!caption.isEmpty()) if (!caption.isEmpty())
dialog.setWindowTitle(caption); dialog.setWindowTitle(caption);
if (!dir.isEmpty()) if (!dir.isEmpty())
dialog.setDirectory(dir); dialog.setDirectory(dir);
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
return dialog.selectedFiles().value(0); return dialog.selectedFiles().value(0);

View file

@ -45,10 +45,6 @@ GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent)
connect(mRendererComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged(const QString&))); connect(mRendererComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged(const QString&)));
createPages(); createPages();
setupConfig();
setupOgre();
readConfig();
} }
void GraphicsPage::createPages() void GraphicsPage::createPages()
@ -78,11 +74,7 @@ void GraphicsPage::createPages()
mDisplayStackedWidget->addWidget(main); mDisplayStackedWidget->addWidget(main);
} }
void GraphicsPage::setupConfig() bool GraphicsPage::setupOgre()
{
}
void GraphicsPage::setupOgre()
{ {
QString pluginCfg = mCfgMgr.getPluginsConfigPath().string().c_str(); QString pluginCfg = mCfgMgr.getPluginsConfigPath().string().c_str();
QFile file(pluginCfg); QFile file(pluginCfg);
@ -113,9 +105,7 @@ void GraphicsPage::setupOgre()
msgBox.exec(); msgBox.exec();
qCritical("Error creating Ogre::Root, the error reported was:\n %s", qPrintable(ogreError)); qCritical("Error creating Ogre::Root, the error reported was:\n %s", qPrintable(ogreError));
return false;
qApp->exit(1);
return;
} }
#ifdef ENABLE_PLUGIN_GL #ifdef ENABLE_PLUGIN_GL
@ -165,8 +155,7 @@ void GraphicsPage::setupOgre()
Please make sure the plugins.cfg file exists and contains a valid rendering plugin.<br>")); Please make sure the plugins.cfg file exists and contains a valid rendering plugin.<br>"));
msgBox.exec(); msgBox.exec();
qApp->exit(1); return false;
return;
} }
// Now fill the GUI elements // Now fill the GUI elements
@ -174,6 +163,9 @@ void GraphicsPage::setupOgre()
mResolutionComboBox->clear(); mResolutionComboBox->clear();
mAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); mAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem));
mResolutionComboBox->addItems(getAvailableOptions(QString("Video Mode"), mSelectedRenderSystem)); mResolutionComboBox->addItems(getAvailableOptions(QString("Video Mode"), mSelectedRenderSystem));
readConfig();
return true;
} }
void GraphicsPage::readConfig() void GraphicsPage::readConfig()

View file

@ -30,6 +30,7 @@ class GraphicsPage : public QWidget
public: public:
GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent = 0); GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent = 0);
bool setupOgre();
void writeConfig(); void writeConfig();
public slots: public slots:
@ -62,8 +63,6 @@ private:
QStringList getAvailableResolutions(Ogre::RenderSystem *renderer); QStringList getAvailableResolutions(Ogre::RenderSystem *renderer);
void createPages(); void createPages();
void setupConfig();
void setupOgre();
void readConfig(); void readConfig();
}; };

View file

@ -1,7 +1,6 @@
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QtDebug>
#include "maindialog.hpp" #include "maindialog.hpp"
@ -32,9 +31,13 @@ int main(int argc, char *argv[])
QDir::setCurrent(dir.absolutePath()); QDir::setCurrent(dir.absolutePath());
MainDialog mainWin; MainDialog mainWin;
mainWin.show();
return app.exec(); if (mainWin.setup()) {
mainWin.show();
return app.exec();
}
return 0;
} }

View file

@ -7,28 +7,6 @@
MainDialog::MainDialog() MainDialog::MainDialog()
{ {
// Create the settings manager and load default settings file
const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg";
const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg";
// prefer local
if (boost::filesystem::exists(localdefault))
mSettings.loadDefault(localdefault);
else if (boost::filesystem::exists(globaldefault))
mSettings.loadDefault(globaldefault);
else
throw std::runtime_error ("No default settings file found! Make sure the file \"settings-default.cfg\" was properly installed.");
// load user settings if they exist, otherwise just load the default settings as user settings
const std::string settingspath = mCfgMgr.getUserPath().string() + "/settings.cfg";
if (boost::filesystem::exists(settingspath))
mSettings.loadUser(settingspath);
else if (boost::filesystem::exists(localdefault))
mSettings.loadUser(localdefault);
else if (boost::filesystem::exists(globaldefault))
mSettings.loadUser(globaldefault);
QWidget *centralWidget = new QWidget(this); QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget); setCentralWidget(centralWidget);
@ -72,22 +50,22 @@ MainDialog::MainDialog()
// Install the stylesheet font // Install the stylesheet font
QFile file; QFile file;
QFontDatabase fontDatabase; QFontDatabase fontDatabase;
const QStringList fonts = fontDatabase.families(); const QStringList fonts = fontDatabase.families();
// Check if the font is installed // Check if the font is installed
if (!fonts.contains("EB Garamond")) { if (!fonts.contains("EB Garamond")) {
QString font = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/mygui/EBGaramond-Regular.ttf").string()); QString font = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/mygui/EBGaramond-Regular.ttf").string());
file.setFileName(font); file.setFileName(font);
if (!file.exists()) { if (!file.exists()) {
font = QString::fromStdString((mCfgMgr.getLocalPath() / "resources/mygui/EBGaramond-Regular.ttf").string()); font = QString::fromStdString((mCfgMgr.getLocalPath() / "resources/mygui/EBGaramond-Regular.ttf").string());
} }
fontDatabase.addApplicationFont(font); fontDatabase.addApplicationFont(font);
} }
// Load the stylesheet // Load the stylesheet
QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/launcher.qss").string()); QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/launcher.qss").string());
file.setFileName(config); file.setFileName(config);
@ -101,7 +79,6 @@ MainDialog::MainDialog()
qApp->setStyleSheet(styleSheet); qApp->setStyleSheet(styleSheet);
file.close(); file.close();
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(play())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(play()));
@ -172,6 +149,53 @@ void MainDialog::createPages()
} }
bool MainDialog::setup()
{
// Create the settings manager and load default settings file
const std::string localdefault = (mCfgMgr.getLocalPath() / "settings-default.cfg").string();
const std::string globaldefault = (mCfgMgr.getGlobalPath() / "settings-default.cfg").string();
// prefer local
if (boost::filesystem::exists(localdefault)) {
mSettings.loadDefault(localdefault);
} else if (boost::filesystem::exists(globaldefault)) {
mSettings.loadDefault(globaldefault);
} else {
QMessageBox msgBox;
msgBox.setWindowTitle("Error reading OpenMW configuration file");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not find %0</b><br><br> \
The problem may be due to an incomplete installation of OpenMW.<br> \
Reinstalling OpenMW may resolve the problem.").arg(QString::fromStdString(globaldefault)));
msgBox.exec();
return false;
}
// load user settings if they exist, otherwise just load the default settings as user settings
const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string();
if (boost::filesystem::exists(settingspath))
mSettings.loadUser(settingspath);
else if (boost::filesystem::exists(localdefault))
mSettings.loadUser(localdefault);
else if (boost::filesystem::exists(globaldefault))
mSettings.loadUser(globaldefault);
// Setup the Graphics page
if (!mGraphicsPage->setupOgre()) {
return false;
}
// Setup the Data Files page
if (!mDataFilesPage->setupDataFiles()) {
return false;
}
return true;
}
void MainDialog::profileChanged(int index) void MainDialog::profileChanged(int index)
{ {
// Just to be sure, should always have a selection // Just to be sure, should always have a selection
@ -204,7 +228,8 @@ void MainDialog::closeEvent(QCloseEvent *event)
mGraphicsPage->writeConfig(); mGraphicsPage->writeConfig();
// Save user settings // Save user settings
const std::string settingspath = mCfgMgr.getUserPath().string() + "/settings.cfg"; const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string();
qDebug() << QString::fromStdString(settingspath);
mSettings.saveUser(settingspath); mSettings.saveUser(settingspath);
event->accept(); event->accept();
@ -248,7 +273,7 @@ void MainDialog::play()
if (!info.isExecutable()) { if (!info.isExecutable()) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error starting OpenMW"); msgBox.setWindowTitle("Error starting OpenMW");
msgBox.setIcon(QMessageBox::Critical); 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 OpenMW</b><br><br> \
The OpenMW application is not executable.<br> \ The OpenMW application is not executable.<br> \
@ -272,6 +297,7 @@ void MainDialog::play()
return; return;
} else { } else {
close(); qApp->quit();
} }
} }

View file

@ -28,6 +28,7 @@ public slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous); void changePage(QListWidgetItem *current, QListWidgetItem *previous);
void play(); void play();
void profileChanged(int index); void profileChanged(int index);
bool setup();
private: private:
void createIcons(); void createIcons();