diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index f3c5962cab..8545be835f 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -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()); @@ -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.
").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.
").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.
").arg(file.fileName())); msgBox.exec(); - qApp->exit(1); + qApp->quit(); return; } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index ad5e90511c..5078f64288 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -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(); diff --git a/apps/launcher/filedialog.cpp b/apps/launcher/filedialog.cpp index 595501b919..16d6775331 100644 --- a/apps/launcher/filedialog.cpp +++ b/apps/launcher/filedialog.cpp @@ -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); diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 22a9ca5bec..0af127edc5 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -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.
")); 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() diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index c2701f3625..b8166f672a 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -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(); }; diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index cbc1c4da36..4ae09f8447 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #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; } diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 63ea96b6f7..ab6eb0b73e 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -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("
Could not find %0

\ + The problem may be due to an incomplete installation of OpenMW.
\ + 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("
Could not start OpenMW

\ The OpenMW application is not executable.
\ @@ -272,6 +297,7 @@ void MainDialog::play() return; } else { - close(); + qApp->quit(); } } + diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index 59c6cbd2d4..683cd58c26 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -28,6 +28,7 @@ public slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); void play(); void profileChanged(int index); + bool setup(); private: void createIcons();