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

pull/21/head
Pieter van der Kloet 13 years ago
parent 7dad67e423
commit 6a2bcddef5

@ -140,7 +140,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent)
createActions();
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
boost::program_options::variables_map variables;
@ -245,21 +245,15 @@ void DataFilesPage::setupDataFiles()
mCfgMgr.processPaths(mDataDirs);
} else {
// Cancel from within the dir selection dialog
break;
return false;
}
} else {
// 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
Files::Collections fileCollections(mDataDirs, !variables["fs-strict"].as<bool>());
@ -362,6 +356,7 @@ void DataFilesPage::setupDataFiles()
}
readConfig();
return true;
}
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));
msgBox.exec();
qApp->exit(1);
qApp->quit();
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()));
msgBox.exec();
qApp->exit(1);
qApp->quit();
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()));
msgBox.exec();
qApp->exit(1);
qApp->quit();
return;
}

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

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

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

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

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

@ -7,28 +7,6 @@
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);
setCentralWidget(centralWidget);
@ -72,22 +50,22 @@ MainDialog::MainDialog()
// Install the stylesheet font
QFile file;
QFontDatabase fontDatabase;
const QStringList fonts = fontDatabase.families();
// Check if the font is installed
if (!fonts.contains("EB Garamond")) {
QString font = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/mygui/EBGaramond-Regular.ttf").string());
file.setFileName(font);
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);
}
// Load the stylesheet
QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/launcher.qss").string());
file.setFileName(config);
@ -101,7 +79,6 @@ MainDialog::MainDialog()
qApp->setStyleSheet(styleSheet);
file.close();
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
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)
{
// Just to be sure, should always have a selection
@ -204,7 +228,8 @@ void MainDialog::closeEvent(QCloseEvent *event)
mGraphicsPage->writeConfig();
// 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);
event->accept();
@ -248,7 +273,7 @@ void MainDialog::play()
if (!info.isExecutable()) {
QMessageBox msgBox;
msgBox.setWindowTitle("Error starting OpenMW");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<br><b>Could not start OpenMW</b><br><br> \
The OpenMW application is not executable.<br> \
@ -272,6 +297,7 @@ void MainDialog::play()
return;
} else {
close();
qApp->quit();
}
}

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

Loading…
Cancel
Save