diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 2895b6345..044a0a0b7 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -12,7 +12,6 @@ set(LAUNCHER settings/gamesettings.cpp settings/graphicssettings.cpp - utils/filedialog.cpp utils/naturalsort.cpp utils/lineedit.cpp utils/profilescombobox.cpp @@ -36,7 +35,6 @@ set(LAUNCHER_HEADER settings/settingsbase.hpp utils/lineedit.hpp - utils/filedialog.hpp utils/naturalsort.hpp utils/profilescombobox.hpp utils/textinputdialog.hpp @@ -55,7 +53,6 @@ set(LAUNCHER_HEADER_MOC model/esm/esmfile.hpp utils/lineedit.hpp - utils/filedialog.hpp utils/profilescombobox.hpp utils/textinputdialog.hpp ) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 6b0539c1d..e25300394 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -6,8 +6,9 @@ #include "model/datafilesmodel.hpp" #include "model/esm/esmfile.hpp" +#include "settings/gamesettings.hpp" + #include "utils/profilescombobox.hpp" -#include "utils/filedialog.hpp" #include "utils/lineedit.hpp" #include "utils/naturalsort.hpp" #include "utils/textinputdialog.hpp" @@ -46,9 +47,10 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2) return index1.row() <= index2.row(); } -DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent) - : QWidget(parent) - , mCfgMgr(cfg) +DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, QWidget *parent) + : mCfgMgr(cfg) + , mGameSettings(gameSettings) + , QWidget(parent) { // Models mMastersModel = new DataFilesModel(this); @@ -178,6 +180,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent) createActions(); setupConfig(); + setupDataFiles(); } void DataFilesPage::createActions() @@ -340,269 +343,176 @@ void DataFilesPage::readConfig() } -bool DataFilesPage::showDataFilesWarning() +void DataFilesPage::setupDataFiles() { + // Set the encoding to the one found in openmw.cfg or the default + mMastersModel->setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); + mPluginsModel->setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); - QMessageBox msgBox; - msgBox.setWindowTitle("Error detecting Morrowind installation"); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setStandardButtons(QMessageBox::Cancel); - msgBox.setText(tr("
Could not find the Data Files location

\ - The directory containing the data files was not found.

\ - Press \"Browse...\" to specify the location manually.
")); - - QAbstractButton *dirSelectButton = - msgBox.addButton(tr("B&rowse..."), QMessageBox::ActionRole); - - msgBox.exec(); - - if (msgBox.clickedButton() == dirSelectButton) { - - // Show a custom dir selection dialog which only accepts valid dirs - QString selectedDir = FileDialog::getExistingDirectory( - this, tr("Select Data Files Directory"), - QDir::currentPath(), - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - - // Add the user selected data directory - if (!selectedDir.isEmpty()) { - mDataDirs.push_back(Files::PathContainer::value_type(selectedDir.toStdString())); - mCfgMgr.processPaths(mDataDirs); - } else { - // Cancel from within the dir selection dialog - return false; - } - - } else { - // Cancel - return false; - } - - return true; -} - -bool DataFilesPage::setupDataFiles() -{ - // We use the Configuration Manager to retrieve the configuration values - boost::program_options::variables_map variables; - boost::program_options::options_description desc; - - desc.add_options() - ("data", boost::program_options::value()->default_value(Files::PathContainer(), "data")->multitoken()) - ("data-local", boost::program_options::value()->default_value("")) - ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) - ("encoding", boost::program_options::value()->default_value("win1252")); - - boost::program_options::notify(variables); - - mCfgMgr.readConfiguration(variables, desc); - - if (variables["data"].empty()) { - if (!showDataFilesWarning()) - return false; - } else { - mDataDirs = Files::PathContainer(variables["data"].as()); - } + QStringList paths = mGameSettings.getDataDirs(); - std::string local = variables["data-local"].as(); - if (!local.empty()) { - mDataLocal.push_back(Files::PathContainer::value_type(local)); - } - - mCfgMgr.processPaths(mDataDirs); - mCfgMgr.processPaths(mDataLocal); - - // Second chance to display the warning, the data= entries are invalid - while (mDataDirs.empty()) { - if (!showDataFilesWarning()) - return false; - } - - // Set the charset for reading the esm/esp files - QString encoding = QString::fromStdString(variables["encoding"].as()); - if (!encoding.isEmpty() && encoding != QLatin1String("win1252")) { - mMastersModel->setEncoding(encoding); - mPluginsModel->setEncoding(encoding); - } - - // Add the paths to the respective models - for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) { - QString path = QString::fromStdString(it->string()); - path.remove(QChar('\"')); + foreach (const QString &path, paths) { mMastersModel->addMasters(path); mPluginsModel->addPlugins(path); } - // Same for the data-local paths - for (Files::PathContainer::iterator it = mDataLocal.begin(); it != mDataLocal.end(); ++it) { - QString path = QString::fromStdString(it->string()); - path.remove(QChar('\"')); - mMastersModel->addMasters(path); - mPluginsModel->addPlugins(path); + QString dataLocal = mGameSettings.getDataLocal(); + if (!dataLocal.isEmpty()) { + mMastersModel->addMasters(dataLocal); + mPluginsModel->addPlugins(dataLocal); } - mMastersModel->sort(0); - mPluginsModel->sort(0); -// mMastersTable->sortByColumn(3, Qt::AscendingOrder); -// mPluginsTable->sortByColumn(3, Qt::AscendingOrder); - - - readConfig(); - return true; } void DataFilesPage::writeConfig(QString profile) { - // Don't overwrite the config if no masters are found - if (mMastersModel->rowCount() < 1) - return; - - QString pathStr = QString::fromStdString(mCfgMgr.getUserPath().string()); - QDir userPath(pathStr); +// // Don't overwrite the config if no masters are found +// if (mMastersModel->rowCount() < 1) +// return; + +// QString pathStr = QString::fromStdString(mCfgMgr.getUserPath().string()); +// QDir userPath(pathStr); + +// if (!userPath.exists()) { +// if (!userPath.mkpath(pathStr)) { +// QMessageBox msgBox; +// msgBox.setWindowTitle("Error creating OpenMW configuration directory"); +// msgBox.setIcon(QMessageBox::Critical); +// msgBox.setStandardButtons(QMessageBox::Ok); +// msgBox.setText(tr("
Could not create %0

\ +// Please make sure you have the right permissions and try again.
").arg(pathStr)); +// msgBox.exec(); + +// qApp->quit(); +// return; +// } +// } +// // Open the OpenMW config as a QFile +// QFile file(pathStr.append("openmw.cfg")); + +// if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { +// // File cannot be opened or created +// QMessageBox msgBox; +// msgBox.setWindowTitle("Error writing OpenMW configuration file"); +// msgBox.setIcon(QMessageBox::Critical); +// msgBox.setStandardButtons(QMessageBox::Ok); +// msgBox.setText(tr("
Could not open or create %0

\ +// Please make sure you have the right permissions and try again.
").arg(file.fileName())); +// msgBox.exec(); + +// qApp->quit(); +// return; +// } - if (!userPath.exists()) { - if (!userPath.mkpath(pathStr)) { - QMessageBox msgBox; - msgBox.setWindowTitle("Error creating OpenMW configuration directory"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not create %0

\ - Please make sure you have the right permissions and try again.
").arg(pathStr)); - msgBox.exec(); +// QTextStream in(&file); +// QByteArray buffer; - qApp->quit(); - return; - } - } - // Open the OpenMW config as a QFile - QFile file(pathStr.append("openmw.cfg")); - - if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { - // File cannot be opened or created - QMessageBox msgBox; - msgBox.setWindowTitle("Error writing OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open or create %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - - qApp->quit(); - return; - } - - QTextStream in(&file); - QByteArray buffer; - - // Remove all previous entries from config - while (!in.atEnd()) { - QString line = in.readLine(); - if (!line.startsWith("master") && - !line.startsWith("plugin") && - !line.startsWith("data") && - !line.startsWith("data-local")) - { - buffer += line += "\n"; - } - } +// // Remove all previous entries from config +// while (!in.atEnd()) { +// QString line = in.readLine(); +// if (!line.startsWith("master") && +// !line.startsWith("plugin") && +// !line.startsWith("data") && +// !line.startsWith("data-local")) +// { +// buffer += line += "\n"; +// } +// } - file.close(); +// file.close(); - // Now we write back the other config entries - if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { - QMessageBox msgBox; - msgBox.setWindowTitle("Error writing OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not write to %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); +// // Now we write back the other config entries +// if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { +// QMessageBox msgBox; +// msgBox.setWindowTitle("Error writing OpenMW configuration file"); +// msgBox.setIcon(QMessageBox::Critical); +// msgBox.setStandardButtons(QMessageBox::Ok); +// msgBox.setText(tr("
Could not write to %0

\ +// Please make sure you have the right permissions and try again.
").arg(file.fileName())); +// msgBox.exec(); - qApp->quit(); - return; - } +// qApp->quit(); +// return; +// } - if (!buffer.isEmpty()) { - file.write(buffer); - } +// if (!buffer.isEmpty()) { +// file.write(buffer); +// } - QTextStream gameConfig(&file); +// QTextStream gameConfig(&file); - // First write the list of data dirs - mCfgMgr.processPaths(mDataDirs); - mCfgMgr.processPaths(mDataLocal); - QString path; +// QString path; - // data= directories - for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) { - path = QString::fromStdString(it->string()); - path.remove(QChar('\"')); +// // data= directories +// for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) { +// path = QString::fromStdString(it->string()); +// path.remove(QChar('\"')); - // Make sure the string is quoted when it contains spaces - if (path.contains(" ")) { - gameConfig << "data=\"" << path << "\"" << endl; - } else { - gameConfig << "data=" << path << endl; - } - } +// // Make sure the string is quoted when it contains spaces +// if (path.contains(" ")) { +// gameConfig << "data=\"" << path << "\"" << endl; +// } else { +// gameConfig << "data=" << path << endl; +// } +// } - // data-local directory - if (!mDataLocal.empty()) { - path = QString::fromStdString(mDataLocal.front().string()); - path.remove(QChar('\"')); +// // data-local directory +// if (!mDataLocal.empty()) { +// path = QString::fromStdString(mDataLocal.front().string()); +// path.remove(QChar('\"')); - if (path.contains(" ")) { - gameConfig << "data-local=\"" << path << "\"" << endl; - } else { - gameConfig << "data-local=" << path << endl; - } - } +// if (path.contains(" ")) { +// gameConfig << "data-local=\"" << path << "\"" << endl; +// } else { +// gameConfig << "data-local=" << path << endl; +// } +// } - if (profile.isEmpty()) - profile = mProfilesComboBox->currentText(); +// if (profile.isEmpty()) +// profile = mProfilesComboBox->currentText(); - if (profile.isEmpty()) - return; +// if (profile.isEmpty()) +// return; - // Make sure we have no groups open - while (!mLauncherConfig->group().isEmpty()) { - mLauncherConfig->endGroup(); - } +// // Make sure we have no groups open +// while (!mLauncherConfig->group().isEmpty()) { +// mLauncherConfig->endGroup(); +// } - mLauncherConfig->beginGroup("Profiles"); - mLauncherConfig->setValue("CurrentProfile", profile); +// mLauncherConfig->beginGroup("Profiles"); +// mLauncherConfig->setValue("CurrentProfile", profile); - // Open the profile-name subgroup - mLauncherConfig->beginGroup(profile); - mLauncherConfig->remove(""); // Clear the subgroup +// // Open the profile-name subgroup +// mLauncherConfig->beginGroup(profile); +// mLauncherConfig->remove(""); // Clear the subgroup - // Now write the masters to the configs - const QStringList masters = mMastersModel->checkedItems(); +// // Now write the masters to the configs +// const QStringList masters = mMastersModel->checkedItems(); - // We don't use foreach because we need i - for (int i = 0; i < masters.size(); ++i) { - const QString currentMaster = masters.at(i); +// // We don't use foreach because we need i +// for (int i = 0; i < masters.size(); ++i) { +// const QString currentMaster = masters.at(i); - mLauncherConfig->setValue(QString("Master%0").arg(i), currentMaster); - gameConfig << "master=" << currentMaster << endl; +// mLauncherConfig->setValue(QString("Master%0").arg(i), currentMaster); +// gameConfig << "master=" << currentMaster << endl; - } +// } - // And finally write all checked plugins - const QStringList plugins = mPluginsModel->checkedItems(); +// // And finally write all checked plugins +// const QStringList plugins = mPluginsModel->checkedItems(); - for (int i = 0; i < plugins.size(); ++i) { - const QString currentPlugin = plugins.at(i); - mLauncherConfig->setValue(QString("Plugin%1").arg(i), currentPlugin); - gameConfig << "plugin=" << currentPlugin << endl; - } +// for (int i = 0; i < plugins.size(); ++i) { +// const QString currentPlugin = plugins.at(i); +// mLauncherConfig->setValue(QString("Plugin%1").arg(i), currentPlugin); +// gameConfig << "plugin=" << currentPlugin << endl; +// } - file.close(); - mLauncherConfig->endGroup(); - mLauncherConfig->endGroup(); - mLauncherConfig->sync(); +// file.close(); +// mLauncherConfig->endGroup(); +// mLauncherConfig->endGroup(); +// mLauncherConfig->sync(); } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 13668ec30..e40d29d60 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -3,9 +3,6 @@ #include #include -#include "utils/profilescombobox.hpp" -#include - class QTableView; class QSortFilterProxyModel; @@ -17,6 +14,8 @@ class ProfilesComboBox; class DataFilesModel; class TextInputDialog; +class ProfilesComboBox; +class GameSettings; namespace Files { struct ConfigurationManager; } @@ -25,13 +24,11 @@ class DataFilesPage : public QWidget Q_OBJECT public: - DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); + DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, QWidget *parent = 0); ProfilesComboBox *mProfilesComboBox; void writeConfig(QString profile = QString()); - bool showDataFilesWarning(); - bool setupDataFiles(); public slots: void setCheckState(QModelIndex index); @@ -76,10 +73,9 @@ private: QAction *mUncheckAction; Files::ConfigurationManager &mCfgMgr; - Files::PathContainer mDataDirs; - Files::PathContainer mDataLocal; QSettings *mLauncherConfig; + GameSettings &mGameSettings; TextInputDialog *mNewProfileDialog; @@ -87,6 +83,7 @@ private: // const QStringList selectedMasters(); void createActions(); + void setupDataFiles(); void setupConfig(); void readConfig(); diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 2c4f3430c..fa9d5d254 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -3,12 +3,12 @@ #include #include -#include #include #include -#include +//#include +#include "settings/graphicssettings.hpp" #include "utils/naturalsort.hpp" #include "graphicspage.hpp" @@ -25,9 +25,10 @@ QString getAspect(int x, int y) return QString(QString::number(xaspect) + ":" + QString::number(yaspect)); } -GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) - : QWidget(parent) - , mCfgMgr(cfg) +GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSetting, QWidget *parent) + : mCfgMgr(cfg) + , mGraphicsSettings(graphicsSetting) + , QWidget(parent) { QGroupBox *rendererGroup = new QGroupBox(tr("Renderer"), this); @@ -117,9 +118,8 @@ bool GraphicsPage::setupOgre() #endif } - boost::filesystem::path absPluginPath = boost::filesystem::absolute(boost::filesystem::path(pluginDir)); - - pluginDir = absPluginPath.string(); + QDir dir(QString::fromStdString(pluginDir)); + pluginDir = dir.absolutePath().toStdString(); Files::loadOgrePlugin(pluginDir, "RenderSystem_GL", *mOgre); Files::loadOgrePlugin(pluginDir, "RenderSystem_Direct3D9", *mOgre); @@ -154,20 +154,16 @@ bool GraphicsPage::setupOgre() msgBox.setIcon(QMessageBox::Critical); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setText(tr("
Could not select a valid render system

\ - Please make sure the plugins.cfg file exists and contains a valid rendering plugin.
")); + Please make sure the plugins.cfg file exists and contains a valid rendering plugin.
")); msgBox.exec(); - return false; } // Now fill the GUI elements - int index = mRendererComboBox->findText(QString::fromStdString(Settings::Manager::getString("render system", "Video"))); - + int index = mRendererComboBox->findText(mGraphicsSettings.value(QString("Video/render system"))); if ( index != -1) { mRendererComboBox->setCurrentIndex(index); - } - else - { + } else { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 mRendererComboBox->setCurrentIndex(mRendererComboBox->findText(direct3DName)); #else @@ -180,45 +176,49 @@ bool GraphicsPage::setupOgre() mAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); mResolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem)); - readConfig(); + // Load the rest of the values + loadSettings(); return true; } -void GraphicsPage::readConfig() +void GraphicsPage::loadSettings() { - if (Settings::Manager::getBool("vsync", "Video")) - mVSyncCheckBox->setCheckState(Qt::Checked); + if (mGraphicsSettings.value(QString("Video/vsync")) == QLatin1String("true")) + mVSyncCheckBox->setCheckState(Qt::Checked); - if (Settings::Manager::getBool("fullscreen", "Video")) - mFullScreenCheckBox->setCheckState(Qt::Checked); + if (mGraphicsSettings.value(QString("Video/fullscreen")) == QLatin1String("true")) + mFullScreenCheckBox->setCheckState(Qt::Checked); - int aaIndex = mAntiAliasingComboBox->findText(QString::fromStdString(Settings::Manager::getString("antialiasing", "Video"))); - if (aaIndex != -1) - mAntiAliasingComboBox->setCurrentIndex(aaIndex); + int aaIndex = mAntiAliasingComboBox->findText(mGraphicsSettings.value(QString("Video/antialiasing"))); + if (aaIndex != -1) + mAntiAliasingComboBox->setCurrentIndex(aaIndex); - QString resolution = QString::number(Settings::Manager::getInt("resolution x", "Video")); - resolution.append(" x " + QString::number(Settings::Manager::getInt("resolution y", "Video"))); + QString resolution = mGraphicsSettings.value(QString("Video/resolution x")); + resolution.append(QString(" x ") + mGraphicsSettings.value(QString("Video/resolution y"))); - int resIndex = mResolutionComboBox->findText(resolution, Qt::MatchStartsWith); - if (resIndex != -1) - mResolutionComboBox->setCurrentIndex(resIndex); + int resIndex = mResolutionComboBox->findText(resolution, Qt::MatchStartsWith); + qDebug() << "resolution from file: " << resolution; + if (resIndex != -1) + mResolutionComboBox->setCurrentIndex(resIndex); } -void GraphicsPage::writeConfig() +void GraphicsPage::saveSettings() { - Settings::Manager::setBool("vsync", "Video", mVSyncCheckBox->checkState()); - Settings::Manager::setBool("fullscreen", "Video", mFullScreenCheckBox->checkState()); - Settings::Manager::setString("antialiasing", "Video", mAntiAliasingComboBox->currentText().toStdString()); - Settings::Manager::setString("render system", "Video", mRendererComboBox->currentText().toStdString()); - - // Get the current resolution, but with the tabs replaced with a single space - QString resolution = mResolutionComboBox->currentText().simplified(); - QStringList tokens = resolution.split(" ", QString::SkipEmptyParts); - - int resX = tokens.at(0).toInt(); - int resY = tokens.at(2).toInt(); - Settings::Manager::setInt("resolution x", "Video", resX); - Settings::Manager::setInt("resolution y", "Video", resY); + mVSyncCheckBox->checkState() ? mGraphicsSettings.setValue(QString("Video/vsync"), QString("true")) + : mGraphicsSettings.setValue(QString("Video/vsync"), QString("false")); + + mFullScreenCheckBox->checkState() ? mGraphicsSettings.setValue(QString("Video/fullscreen"), QString("true")) + : mGraphicsSettings.setValue(QString("Video/fullscreen"), QString("false")); + + mGraphicsSettings.setValue(QString("Video/antialiasing"), mAntiAliasingComboBox->currentText()); + mGraphicsSettings.setValue(QString("Video/render system"), mRendererComboBox->currentText()); + + QRegExp resolutionRe(QString("(\\d+) x (\\d+).*")); + + if (resolutionRe.exactMatch(mResolutionComboBox->currentText().simplified())) { + mGraphicsSettings.setValue(QString("Video/resolution x"), resolutionRe.cap(1)); + mGraphicsSettings.setValue(QString("Video/resolution y"), resolutionRe.cap(2)); + } } QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer) @@ -232,16 +232,14 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy { Ogre::StringVector::iterator opt_it; uint idx = 0; - for (opt_it = i->second.possibleValues.begin (); - opt_it != i->second.possibleValues.end (); opt_it++, idx++) - { - if (strcmp (key.toStdString().c_str(), i->first.c_str()) == 0) - { + for (opt_it = i->second.possibleValues.begin(); + opt_it != i->second.possibleValues.end(); opt_it++, idx++) + { + if (strcmp (key.toStdString().c_str(), i->first.c_str()) == 0) { result << ((key == "FSAA") ? QString("MSAA ") : QString("")) + QString::fromStdString((*opt_it).c_str()).simplified(); } } - } // Sort ascending @@ -258,7 +256,7 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) { - QString key ("Video Mode"); + QString key("Video Mode"); QStringList result; uint row = 0; diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index b8166f672..48b9ff785 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -5,8 +5,8 @@ #include #include -#include -#include +//#include +//#include // Static plugin headers #ifdef ENABLE_PLUGIN_GL @@ -21,6 +21,8 @@ class QCheckBox; class QStackedWidget; class QSettings; +class GraphicsSettings; + namespace Files { struct ConfigurationManager; } class GraphicsPage : public QWidget @@ -28,10 +30,10 @@ class GraphicsPage : public QWidget Q_OBJECT public: - GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent = 0); + GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSettings, QWidget *parent = 0); + void saveSettings(); bool setupOgre(); - void writeConfig(); public slots: void rendererChanged(const QString &renderer); @@ -58,12 +60,14 @@ private: QCheckBox *mFullScreenCheckBox; Files::ConfigurationManager &mCfgMgr; + GraphicsSettings &mGraphicsSettings; QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer); QStringList getAvailableResolutions(Ogre::RenderSystem *renderer); void createPages(); - void readConfig(); + void loadSettings(); + }; #endif diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 3fef62bc6..43bf50fbc 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -138,9 +138,7 @@ int main(int argc, char *argv[]) paths.clear(); paths.append(globalPath + QString("settings-default.cfg")); paths.append(QString("settings-default.cfg")); - paths.append(userPath + QString("settings.cfg")); - paths.append(QString("settings.cfg")); foreach (const QString &path, paths) { qDebug() << "Loading: " << path; @@ -166,14 +164,14 @@ int main(int argc, char *argv[]) } - MainDialog mainWin; - mainWin.setup(); - - mainWin.show(); - QCoreApplication::processEvents(); - return app.exec(); + MainDialog mainWin(gameSettings, graphicsSettings); + if (mainWin.setup()) { + mainWin.show(); + } else { + return 0; + } - return 0; + return app.exec(); } diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 674ccdf67..4d3d24bd9 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -1,11 +1,20 @@ #include +#include "settings/gamesettings.hpp" +#include "settings/graphicssettings.hpp" + +#include "utils/profilescombobox.hpp" + #include "maindialog.hpp" #include "playpage.hpp" #include "graphicspage.hpp" #include "datafilespage.hpp" -MainDialog::MainDialog() +MainDialog::MainDialog(GameSettings &gameSettings, + GraphicsSettings &graphicsSettings) + : mGameSettings(gameSettings) + , mGraphicsSettings(graphicsSettings) + { QWidget *centralWidget = new QWidget(this); setCentralWidget(centralWidget); @@ -122,8 +131,8 @@ void MainDialog::createIcons() void MainDialog::createPages() { mPlayPage = new PlayPage(this); - mGraphicsPage = new GraphicsPage(mCfgMgr, this); - mDataFilesPage = new DataFilesPage(mCfgMgr, this); + mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this); + mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, this); // Set the combobox of the play page to imitate the combobox on the datafilespage mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model()); @@ -152,46 +161,17 @@ 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; } @@ -208,11 +188,67 @@ void MainDialog::closeEvent(QCloseEvent *event) { // Now write all config files mDataFilesPage->writeConfig(); - mGraphicsPage->writeConfig(); + mGraphicsPage->saveSettings(); + + QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string()); + QDir dir(userPath); + + if (!dir.exists()) { + if (!dir.mkpath(userPath)) { + QMessageBox msgBox; + msgBox.setWindowTitle("Error creating OpenMW configuration directory"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
Could not create %0

\ + Please make sure you have the right permissions \ + and try again.
").arg(userPath)); + msgBox.exec(); + event->accept(); + } + } - // Save user settings - const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string(); - mSettings.saveUser(settingspath); + // Game settings + QFile file(userPath + QString("openmw.cfg")); + + if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { + // File cannot be opened or created + QMessageBox msgBox; + msgBox.setWindowTitle("Error writing OpenMW configuration file"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
Could not open or create %0 for writing

\ + Please make sure you have the right permissions \ + and try again.
").arg(file.fileName())); + msgBox.exec(); + event->accept(); + } + + QTextStream stream(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + + mGameSettings.writeFile(stream); + file.close(); + + // Graphics settings + file.setFileName(userPath + QString("settings.cfg")); + + if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { + // File cannot be opened or created + QMessageBox msgBox; + msgBox.setWindowTitle("Error writing OpenMW configuration file"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
Could not open or create %0 for writing

\ + Please make sure you have the right permissions \ + and try again.
").arg(file.fileName())); + msgBox.exec(); + event->accept(); + } + + stream.setDevice(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + + mGraphicsSettings.writeFile(stream); event->accept(); } @@ -221,7 +257,7 @@ void MainDialog::play() { // First do a write of all the configs, just to be sure mDataFilesPage->writeConfig(); - mGraphicsPage->writeConfig(); + //mGraphicsPage->writeConfig(); // Save user settings const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string(); diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index bf98011cc..c9654b874 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -17,12 +17,15 @@ class PlayPage; class GraphicsPage; class DataFilesPage; +class GameSettings; +class GraphicsSettings; + class MainDialog : public QMainWindow { Q_OBJECT public: - MainDialog(); + MainDialog(GameSettings &gameSettings, GraphicsSettings &GraphicsSettings); public slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); @@ -43,6 +46,10 @@ private: Files::ConfigurationManager mCfgMgr; Settings::Manager mSettings; + + GameSettings &mGameSettings; + GraphicsSettings &mGraphicsSettings; + }; #endif diff --git a/apps/launcher/utils/filedialog.cpp b/apps/launcher/utils/filedialog.cpp deleted file mode 100644 index 16d677533..000000000 --- a/apps/launcher/utils/filedialog.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "filedialog.hpp" -#include -#include - -FileDialog::FileDialog(QWidget *parent) - : QFileDialog(parent) -{ - // Remove the default Choose button to prevent it being updated elsewhere - QDialogButtonBox *box = qFindChild(this); - Q_ASSERT(box); - box->removeButton(box->button(QDialogButtonBox::Open)); - - // Add our own button so we can disable/enable it - mChooseButton = new QPushButton(tr("&Choose")); - mChooseButton->setIcon(QIcon::fromTheme("document-open")); - mChooseButton->setEnabled(false); - box->addButton(mChooseButton, QDialogButtonBox::AcceptRole); - - connect(this, SIGNAL(directoryEntered(const QString&)), this, SLOT(updateChooseButton(const QString&))); - emit directoryEntered(QDir::currentPath()); -} - -QString FileDialog::getExistingDirectory(QWidget *parent, - const QString &caption, - const QString &dir, - Options options) -{ - // create a non-native file dialog - FileDialog dialog; - dialog.setFileMode(DirectoryOnly); - dialog.setOptions(options |= QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly); - - if (!caption.isEmpty()) - dialog.setWindowTitle(caption); - - if (!dir.isEmpty()) - dialog.setDirectory(dir); - - if (dialog.exec() == QDialog::Accepted) { - return dialog.selectedFiles().value(0); - } - return QString(); -} - -void FileDialog::updateChooseButton(const QString &directory) -{ - QDir currentDir = QDir(directory); - currentDir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); - currentDir.setNameFilters(QStringList() << "*.esm" << "*.esp"); - - if (!currentDir.entryList().isEmpty()) { - // There are data files in the current dir - mChooseButton->setEnabled(true); - } else { - mChooseButton->setEnabled(false); - } -} diff --git a/apps/launcher/utils/filedialog.hpp b/apps/launcher/utils/filedialog.hpp deleted file mode 100644 index 7a161ecb9..000000000 --- a/apps/launcher/utils/filedialog.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef FILEDIALOG_HPP -#define FILEDIALOG_HPP - -#include - -class QPushButton; - -class FileDialog : public QFileDialog -{ - Q_OBJECT - -public: - FileDialog(QWidget *parent = 0); - - static QString getExistingDirectory(QWidget *parent = 0, - const QString &caption = QString(), - const QString &dir = QString(), - Options options = ShowDirsOnly); - -private slots: - void updateChooseButton(const QString &directory); - -private: - QPushButton *mChooseButton; -}; - - -#endif // FILEDIALOG_HPP