mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 14:09:39 +00:00
Rewriting the config code of the pages to use the new settings classes
This commit is contained in:
parent
5579df30ff
commit
25edba0887
10 changed files with 290 additions and 428 deletions
|
@ -12,7 +12,6 @@ set(LAUNCHER
|
||||||
settings/gamesettings.cpp
|
settings/gamesettings.cpp
|
||||||
settings/graphicssettings.cpp
|
settings/graphicssettings.cpp
|
||||||
|
|
||||||
utils/filedialog.cpp
|
|
||||||
utils/naturalsort.cpp
|
utils/naturalsort.cpp
|
||||||
utils/lineedit.cpp
|
utils/lineedit.cpp
|
||||||
utils/profilescombobox.cpp
|
utils/profilescombobox.cpp
|
||||||
|
@ -36,7 +35,6 @@ set(LAUNCHER_HEADER
|
||||||
settings/settingsbase.hpp
|
settings/settingsbase.hpp
|
||||||
|
|
||||||
utils/lineedit.hpp
|
utils/lineedit.hpp
|
||||||
utils/filedialog.hpp
|
|
||||||
utils/naturalsort.hpp
|
utils/naturalsort.hpp
|
||||||
utils/profilescombobox.hpp
|
utils/profilescombobox.hpp
|
||||||
utils/textinputdialog.hpp
|
utils/textinputdialog.hpp
|
||||||
|
@ -55,7 +53,6 @@ set(LAUNCHER_HEADER_MOC
|
||||||
model/esm/esmfile.hpp
|
model/esm/esmfile.hpp
|
||||||
|
|
||||||
utils/lineedit.hpp
|
utils/lineedit.hpp
|
||||||
utils/filedialog.hpp
|
|
||||||
utils/profilescombobox.hpp
|
utils/profilescombobox.hpp
|
||||||
utils/textinputdialog.hpp
|
utils/textinputdialog.hpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
#include "model/datafilesmodel.hpp"
|
#include "model/datafilesmodel.hpp"
|
||||||
#include "model/esm/esmfile.hpp"
|
#include "model/esm/esmfile.hpp"
|
||||||
|
|
||||||
|
#include "settings/gamesettings.hpp"
|
||||||
|
|
||||||
#include "utils/profilescombobox.hpp"
|
#include "utils/profilescombobox.hpp"
|
||||||
#include "utils/filedialog.hpp"
|
|
||||||
#include "utils/lineedit.hpp"
|
#include "utils/lineedit.hpp"
|
||||||
#include "utils/naturalsort.hpp"
|
#include "utils/naturalsort.hpp"
|
||||||
#include "utils/textinputdialog.hpp"
|
#include "utils/textinputdialog.hpp"
|
||||||
|
@ -46,9 +47,10 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2)
|
||||||
return index1.row() <= index2.row();
|
return index1.row() <= index2.row();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent)
|
DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, QWidget *parent)
|
||||||
: QWidget(parent)
|
: mCfgMgr(cfg)
|
||||||
, mCfgMgr(cfg)
|
, mGameSettings(gameSettings)
|
||||||
|
, QWidget(parent)
|
||||||
{
|
{
|
||||||
// Models
|
// Models
|
||||||
mMastersModel = new DataFilesModel(this);
|
mMastersModel = new DataFilesModel(this);
|
||||||
|
@ -178,6 +180,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent)
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
setupConfig();
|
setupConfig();
|
||||||
|
setupDataFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::createActions()
|
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;
|
QStringList paths = mGameSettings.getDataDirs();
|
||||||
msgBox.setWindowTitle("Error detecting Morrowind installation");
|
|
||||||
msgBox.setIcon(QMessageBox::Warning);
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Cancel);
|
|
||||||
msgBox.setText(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 =
|
foreach (const QString &path, paths) {
|
||||||
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<Files::PathContainer>()->default_value(Files::PathContainer(), "data")->multitoken())
|
|
||||||
("data-local", boost::program_options::value<std::string>()->default_value(""))
|
|
||||||
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false))
|
|
||||||
("encoding", boost::program_options::value<std::string>()->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<Files::PathContainer>());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string local = variables["data-local"].as<std::string>();
|
|
||||||
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<std::string>());
|
|
||||||
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('\"'));
|
|
||||||
mMastersModel->addMasters(path);
|
mMastersModel->addMasters(path);
|
||||||
mPluginsModel->addPlugins(path);
|
mPluginsModel->addPlugins(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same for the data-local paths
|
QString dataLocal = mGameSettings.getDataLocal();
|
||||||
for (Files::PathContainer::iterator it = mDataLocal.begin(); it != mDataLocal.end(); ++it) {
|
if (!dataLocal.isEmpty()) {
|
||||||
QString path = QString::fromStdString(it->string());
|
mMastersModel->addMasters(dataLocal);
|
||||||
path.remove(QChar('\"'));
|
mPluginsModel->addPlugins(dataLocal);
|
||||||
mMastersModel->addMasters(path);
|
|
||||||
mPluginsModel->addPlugins(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mMastersModel->sort(0);
|
|
||||||
mPluginsModel->sort(0);
|
|
||||||
// mMastersTable->sortByColumn(3, Qt::AscendingOrder);
|
|
||||||
// mPluginsTable->sortByColumn(3, Qt::AscendingOrder);
|
|
||||||
|
|
||||||
|
|
||||||
readConfig();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::writeConfig(QString profile)
|
void DataFilesPage::writeConfig(QString profile)
|
||||||
{
|
{
|
||||||
// Don't overwrite the config if no masters are found
|
// // Don't overwrite the config if no masters are found
|
||||||
if (mMastersModel->rowCount() < 1)
|
// if (mMastersModel->rowCount() < 1)
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
QString pathStr = QString::fromStdString(mCfgMgr.getUserPath().string());
|
// QString pathStr = QString::fromStdString(mCfgMgr.getUserPath().string());
|
||||||
QDir userPath(pathStr);
|
// QDir userPath(pathStr);
|
||||||
|
|
||||||
if (!userPath.exists()) {
|
// if (!userPath.exists()) {
|
||||||
if (!userPath.mkpath(pathStr)) {
|
// if (!userPath.mkpath(pathStr)) {
|
||||||
QMessageBox msgBox;
|
// QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle("Error creating OpenMW configuration directory");
|
// msgBox.setWindowTitle("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> \
|
||||||
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->quit();
|
// qApp->quit();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// Open the OpenMW config as a QFile
|
// // Open the OpenMW config as a QFile
|
||||||
QFile file(pathStr.append("openmw.cfg"));
|
// QFile file(pathStr.append("openmw.cfg"));
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
// if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||||
// 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("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</b><br><br> \
|
// msgBox.setText(tr("<br><b>Could not open or create %0</b><br><br> \
|
||||||
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->quit();
|
// qApp->quit();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
QTextStream in(&file);
|
// QTextStream in(&file);
|
||||||
QByteArray buffer;
|
// QByteArray buffer;
|
||||||
|
|
||||||
// Remove all previous entries from config
|
// // Remove all previous entries from config
|
||||||
while (!in.atEnd()) {
|
// while (!in.atEnd()) {
|
||||||
QString line = in.readLine();
|
// QString line = in.readLine();
|
||||||
if (!line.startsWith("master") &&
|
// if (!line.startsWith("master") &&
|
||||||
!line.startsWith("plugin") &&
|
// !line.startsWith("plugin") &&
|
||||||
!line.startsWith("data") &&
|
// !line.startsWith("data") &&
|
||||||
!line.startsWith("data-local"))
|
// !line.startsWith("data-local"))
|
||||||
{
|
// {
|
||||||
buffer += line += "\n";
|
// buffer += line += "\n";
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
file.close();
|
// file.close();
|
||||||
|
|
||||||
// Now we write back the other config entries
|
// // Now we write back the other config entries
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
|
// if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
|
||||||
QMessageBox msgBox;
|
// QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
// msgBox.setWindowTitle("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 write to %0</b><br><br> \
|
// msgBox.setText(tr("<br><b>Could not write to %0</b><br><br> \
|
||||||
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->quit();
|
// qApp->quit();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!buffer.isEmpty()) {
|
// if (!buffer.isEmpty()) {
|
||||||
file.write(buffer);
|
// file.write(buffer);
|
||||||
}
|
// }
|
||||||
|
|
||||||
QTextStream gameConfig(&file);
|
// QTextStream gameConfig(&file);
|
||||||
|
|
||||||
// First write the list of data dirs
|
|
||||||
mCfgMgr.processPaths(mDataDirs);
|
|
||||||
mCfgMgr.processPaths(mDataLocal);
|
|
||||||
|
|
||||||
QString path;
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 (profile.isEmpty())
|
// QString path;
|
||||||
profile = mProfilesComboBox->currentText();
|
|
||||||
|
|
||||||
if (profile.isEmpty())
|
// // data= directories
|
||||||
return;
|
// for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) {
|
||||||
|
// path = QString::fromStdString(it->string());
|
||||||
|
// path.remove(QChar('\"'));
|
||||||
|
|
||||||
// Make sure we have no groups open
|
// // Make sure the string is quoted when it contains spaces
|
||||||
while (!mLauncherConfig->group().isEmpty()) {
|
// if (path.contains(" ")) {
|
||||||
mLauncherConfig->endGroup();
|
// gameConfig << "data=\"" << path << "\"" << endl;
|
||||||
}
|
// } else {
|
||||||
|
// gameConfig << "data=" << path << endl;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
mLauncherConfig->beginGroup("Profiles");
|
// // data-local directory
|
||||||
mLauncherConfig->setValue("CurrentProfile", profile);
|
// if (!mDataLocal.empty()) {
|
||||||
|
// path = QString::fromStdString(mDataLocal.front().string());
|
||||||
|
// path.remove(QChar('\"'));
|
||||||
|
|
||||||
// Open the profile-name subgroup
|
// if (path.contains(" ")) {
|
||||||
mLauncherConfig->beginGroup(profile);
|
// gameConfig << "data-local=\"" << path << "\"" << endl;
|
||||||
mLauncherConfig->remove(""); // Clear the subgroup
|
// } else {
|
||||||
|
// gameConfig << "data-local=" << path << endl;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Now write the masters to the configs
|
|
||||||
const QStringList masters = mMastersModel->checkedItems();
|
|
||||||
|
|
||||||
// We don't use foreach because we need i
|
// if (profile.isEmpty())
|
||||||
for (int i = 0; i < masters.size(); ++i) {
|
// profile = mProfilesComboBox->currentText();
|
||||||
const QString currentMaster = masters.at(i);
|
|
||||||
|
|
||||||
mLauncherConfig->setValue(QString("Master%0").arg(i), currentMaster);
|
// if (profile.isEmpty())
|
||||||
gameConfig << "master=" << currentMaster << endl;
|
// return;
|
||||||
|
|
||||||
}
|
// // Make sure we have no groups open
|
||||||
|
// while (!mLauncherConfig->group().isEmpty()) {
|
||||||
|
// mLauncherConfig->endGroup();
|
||||||
|
// }
|
||||||
|
|
||||||
// And finally write all checked plugins
|
// mLauncherConfig->beginGroup("Profiles");
|
||||||
const QStringList plugins = mPluginsModel->checkedItems();
|
// mLauncherConfig->setValue("CurrentProfile", profile);
|
||||||
|
|
||||||
for (int i = 0; i < plugins.size(); ++i) {
|
// // Open the profile-name subgroup
|
||||||
const QString currentPlugin = plugins.at(i);
|
// mLauncherConfig->beginGroup(profile);
|
||||||
mLauncherConfig->setValue(QString("Plugin%1").arg(i), currentPlugin);
|
// mLauncherConfig->remove(""); // Clear the subgroup
|
||||||
gameConfig << "plugin=" << currentPlugin << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
// // Now write the masters to the configs
|
||||||
mLauncherConfig->endGroup();
|
// const QStringList masters = mMastersModel->checkedItems();
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
mLauncherConfig->sync();
|
// // 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;
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 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;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// file.close();
|
||||||
|
// mLauncherConfig->endGroup();
|
||||||
|
// mLauncherConfig->endGroup();
|
||||||
|
// mLauncherConfig->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include "utils/profilescombobox.hpp"
|
|
||||||
#include <components/files/collections.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
class QTableView;
|
class QTableView;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
@ -17,6 +14,8 @@ class ProfilesComboBox;
|
||||||
class DataFilesModel;
|
class DataFilesModel;
|
||||||
|
|
||||||
class TextInputDialog;
|
class TextInputDialog;
|
||||||
|
class ProfilesComboBox;
|
||||||
|
class GameSettings;
|
||||||
|
|
||||||
namespace Files { struct ConfigurationManager; }
|
namespace Files { struct ConfigurationManager; }
|
||||||
|
|
||||||
|
@ -25,13 +24,11 @@ class DataFilesPage : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent = 0);
|
DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, QWidget *parent = 0);
|
||||||
|
|
||||||
ProfilesComboBox *mProfilesComboBox;
|
ProfilesComboBox *mProfilesComboBox;
|
||||||
|
|
||||||
void writeConfig(QString profile = QString());
|
void writeConfig(QString profile = QString());
|
||||||
bool showDataFilesWarning();
|
|
||||||
bool setupDataFiles();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCheckState(QModelIndex index);
|
void setCheckState(QModelIndex index);
|
||||||
|
@ -76,10 +73,9 @@ private:
|
||||||
QAction *mUncheckAction;
|
QAction *mUncheckAction;
|
||||||
|
|
||||||
Files::ConfigurationManager &mCfgMgr;
|
Files::ConfigurationManager &mCfgMgr;
|
||||||
Files::PathContainer mDataDirs;
|
|
||||||
Files::PathContainer mDataLocal;
|
|
||||||
|
|
||||||
QSettings *mLauncherConfig;
|
QSettings *mLauncherConfig;
|
||||||
|
GameSettings &mGameSettings;
|
||||||
|
|
||||||
TextInputDialog *mNewProfileDialog;
|
TextInputDialog *mNewProfileDialog;
|
||||||
|
|
||||||
|
@ -87,6 +83,7 @@ private:
|
||||||
// const QStringList selectedMasters();
|
// const QStringList selectedMasters();
|
||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
|
void setupDataFiles();
|
||||||
void setupConfig();
|
void setupConfig();
|
||||||
void readConfig();
|
void readConfig();
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <boost/math/common_factor.hpp>
|
#include <boost/math/common_factor.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
|
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
#include <components/files/ogreplugin.hpp>
|
#include <components/files/ogreplugin.hpp>
|
||||||
#include <components/settings/settings.hpp>
|
//#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
|
#include "settings/graphicssettings.hpp"
|
||||||
#include "utils/naturalsort.hpp"
|
#include "utils/naturalsort.hpp"
|
||||||
|
|
||||||
#include "graphicspage.hpp"
|
#include "graphicspage.hpp"
|
||||||
|
@ -25,9 +25,10 @@ QString getAspect(int x, int y)
|
||||||
return QString(QString::number(xaspect) + ":" + QString::number(yaspect));
|
return QString(QString::number(xaspect) + ":" + QString::number(yaspect));
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent)
|
GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSetting, QWidget *parent)
|
||||||
: QWidget(parent)
|
: mCfgMgr(cfg)
|
||||||
, mCfgMgr(cfg)
|
, mGraphicsSettings(graphicsSetting)
|
||||||
|
, QWidget(parent)
|
||||||
{
|
{
|
||||||
QGroupBox *rendererGroup = new QGroupBox(tr("Renderer"), this);
|
QGroupBox *rendererGroup = new QGroupBox(tr("Renderer"), this);
|
||||||
|
|
||||||
|
@ -117,9 +118,8 @@ bool GraphicsPage::setupOgre()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path absPluginPath = boost::filesystem::absolute(boost::filesystem::path(pluginDir));
|
QDir dir(QString::fromStdString(pluginDir));
|
||||||
|
pluginDir = dir.absolutePath().toStdString();
|
||||||
pluginDir = absPluginPath.string();
|
|
||||||
|
|
||||||
Files::loadOgrePlugin(pluginDir, "RenderSystem_GL", *mOgre);
|
Files::loadOgrePlugin(pluginDir, "RenderSystem_GL", *mOgre);
|
||||||
Files::loadOgrePlugin(pluginDir, "RenderSystem_Direct3D9", *mOgre);
|
Files::loadOgrePlugin(pluginDir, "RenderSystem_Direct3D9", *mOgre);
|
||||||
|
@ -154,20 +154,16 @@ bool GraphicsPage::setupOgre()
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox.setText(tr("<br><b>Could not select a valid render system</b><br><br> \
|
msgBox.setText(tr("<br><b>Could not select a valid render system</b><br><br> \
|
||||||
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();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now fill the GUI elements
|
// 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) {
|
if ( index != -1) {
|
||||||
mRendererComboBox->setCurrentIndex(index);
|
mRendererComboBox->setCurrentIndex(index);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
||||||
mRendererComboBox->setCurrentIndex(mRendererComboBox->findText(direct3DName));
|
mRendererComboBox->setCurrentIndex(mRendererComboBox->findText(direct3DName));
|
||||||
#else
|
#else
|
||||||
|
@ -180,45 +176,49 @@ bool GraphicsPage::setupOgre()
|
||||||
mAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem));
|
mAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem));
|
||||||
mResolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem));
|
mResolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem));
|
||||||
|
|
||||||
readConfig();
|
// Load the rest of the values
|
||||||
|
loadSettings();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsPage::readConfig()
|
void GraphicsPage::loadSettings()
|
||||||
{
|
{
|
||||||
if (Settings::Manager::getBool("vsync", "Video"))
|
if (mGraphicsSettings.value(QString("Video/vsync")) == QLatin1String("true"))
|
||||||
mVSyncCheckBox->setCheckState(Qt::Checked);
|
mVSyncCheckBox->setCheckState(Qt::Checked);
|
||||||
|
|
||||||
if (Settings::Manager::getBool("fullscreen", "Video"))
|
if (mGraphicsSettings.value(QString("Video/fullscreen")) == QLatin1String("true"))
|
||||||
mFullScreenCheckBox->setCheckState(Qt::Checked);
|
mFullScreenCheckBox->setCheckState(Qt::Checked);
|
||||||
|
|
||||||
int aaIndex = mAntiAliasingComboBox->findText(QString::fromStdString(Settings::Manager::getString("antialiasing", "Video")));
|
int aaIndex = mAntiAliasingComboBox->findText(mGraphicsSettings.value(QString("Video/antialiasing")));
|
||||||
if (aaIndex != -1)
|
if (aaIndex != -1)
|
||||||
mAntiAliasingComboBox->setCurrentIndex(aaIndex);
|
mAntiAliasingComboBox->setCurrentIndex(aaIndex);
|
||||||
|
|
||||||
QString resolution = QString::number(Settings::Manager::getInt("resolution x", "Video"));
|
QString resolution = mGraphicsSettings.value(QString("Video/resolution x"));
|
||||||
resolution.append(" x " + QString::number(Settings::Manager::getInt("resolution y", "Video")));
|
resolution.append(QString(" x ") + mGraphicsSettings.value(QString("Video/resolution y")));
|
||||||
|
|
||||||
int resIndex = mResolutionComboBox->findText(resolution, Qt::MatchStartsWith);
|
int resIndex = mResolutionComboBox->findText(resolution, Qt::MatchStartsWith);
|
||||||
if (resIndex != -1)
|
qDebug() << "resolution from file: " << resolution;
|
||||||
mResolutionComboBox->setCurrentIndex(resIndex);
|
if (resIndex != -1)
|
||||||
|
mResolutionComboBox->setCurrentIndex(resIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsPage::writeConfig()
|
void GraphicsPage::saveSettings()
|
||||||
{
|
{
|
||||||
Settings::Manager::setBool("vsync", "Video", mVSyncCheckBox->checkState());
|
mVSyncCheckBox->checkState() ? mGraphicsSettings.setValue(QString("Video/vsync"), QString("true"))
|
||||||
Settings::Manager::setBool("fullscreen", "Video", mFullScreenCheckBox->checkState());
|
: mGraphicsSettings.setValue(QString("Video/vsync"), QString("false"));
|
||||||
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
|
mFullScreenCheckBox->checkState() ? mGraphicsSettings.setValue(QString("Video/fullscreen"), QString("true"))
|
||||||
QString resolution = mResolutionComboBox->currentText().simplified();
|
: mGraphicsSettings.setValue(QString("Video/fullscreen"), QString("false"));
|
||||||
QStringList tokens = resolution.split(" ", QString::SkipEmptyParts);
|
|
||||||
|
|
||||||
int resX = tokens.at(0).toInt();
|
mGraphicsSettings.setValue(QString("Video/antialiasing"), mAntiAliasingComboBox->currentText());
|
||||||
int resY = tokens.at(2).toInt();
|
mGraphicsSettings.setValue(QString("Video/render system"), mRendererComboBox->currentText());
|
||||||
Settings::Manager::setInt("resolution x", "Video", resX);
|
|
||||||
Settings::Manager::setInt("resolution y", "Video", resY);
|
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)
|
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;
|
Ogre::StringVector::iterator opt_it;
|
||||||
uint idx = 0;
|
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();
|
result << ((key == "FSAA") ? QString("MSAA ") : QString("")) + QString::fromStdString((*opt_it).c_str()).simplified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort ascending
|
// Sort ascending
|
||||||
|
@ -258,7 +256,7 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy
|
||||||
|
|
||||||
QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer)
|
QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer)
|
||||||
{
|
{
|
||||||
QString key ("Video Mode");
|
QString key("Video Mode");
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
uint row = 0;
|
uint row = 0;
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
#include <OgreRoot.h>
|
#include <OgreRoot.h>
|
||||||
#include <OgreRenderSystem.h>
|
#include <OgreRenderSystem.h>
|
||||||
#include <OgreConfigFile.h>
|
//#include <OgreConfigFile.h>
|
||||||
#include <OgreConfigDialog.h>
|
//#include <OgreConfigDialog.h>
|
||||||
|
|
||||||
// Static plugin headers
|
// Static plugin headers
|
||||||
#ifdef ENABLE_PLUGIN_GL
|
#ifdef ENABLE_PLUGIN_GL
|
||||||
|
@ -21,6 +21,8 @@ class QCheckBox;
|
||||||
class QStackedWidget;
|
class QStackedWidget;
|
||||||
class QSettings;
|
class QSettings;
|
||||||
|
|
||||||
|
class GraphicsSettings;
|
||||||
|
|
||||||
namespace Files { struct ConfigurationManager; }
|
namespace Files { struct ConfigurationManager; }
|
||||||
|
|
||||||
class GraphicsPage : public QWidget
|
class GraphicsPage : public QWidget
|
||||||
|
@ -28,10 +30,10 @@ class GraphicsPage : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent = 0);
|
GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSettings, QWidget *parent = 0);
|
||||||
|
|
||||||
|
void saveSettings();
|
||||||
bool setupOgre();
|
bool setupOgre();
|
||||||
void writeConfig();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void rendererChanged(const QString &renderer);
|
void rendererChanged(const QString &renderer);
|
||||||
|
@ -58,12 +60,14 @@ private:
|
||||||
QCheckBox *mFullScreenCheckBox;
|
QCheckBox *mFullScreenCheckBox;
|
||||||
|
|
||||||
Files::ConfigurationManager &mCfgMgr;
|
Files::ConfigurationManager &mCfgMgr;
|
||||||
|
GraphicsSettings &mGraphicsSettings;
|
||||||
|
|
||||||
QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer);
|
QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer);
|
||||||
QStringList getAvailableResolutions(Ogre::RenderSystem *renderer);
|
QStringList getAvailableResolutions(Ogre::RenderSystem *renderer);
|
||||||
|
|
||||||
void createPages();
|
void createPages();
|
||||||
void readConfig();
|
void loadSettings();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -138,9 +138,7 @@ int main(int argc, char *argv[])
|
||||||
paths.clear();
|
paths.clear();
|
||||||
paths.append(globalPath + QString("settings-default.cfg"));
|
paths.append(globalPath + QString("settings-default.cfg"));
|
||||||
paths.append(QString("settings-default.cfg"));
|
paths.append(QString("settings-default.cfg"));
|
||||||
|
|
||||||
paths.append(userPath + QString("settings.cfg"));
|
paths.append(userPath + QString("settings.cfg"));
|
||||||
paths.append(QString("settings.cfg"));
|
|
||||||
|
|
||||||
foreach (const QString &path, paths) {
|
foreach (const QString &path, paths) {
|
||||||
qDebug() << "Loading: " << path;
|
qDebug() << "Loading: " << path;
|
||||||
|
@ -166,14 +164,14 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MainDialog mainWin;
|
MainDialog mainWin(gameSettings, graphicsSettings);
|
||||||
mainWin.setup();
|
|
||||||
|
if (mainWin.setup()) {
|
||||||
|
mainWin.show();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
mainWin.show();
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "settings/gamesettings.hpp"
|
||||||
|
#include "settings/graphicssettings.hpp"
|
||||||
|
|
||||||
|
#include "utils/profilescombobox.hpp"
|
||||||
|
|
||||||
#include "maindialog.hpp"
|
#include "maindialog.hpp"
|
||||||
#include "playpage.hpp"
|
#include "playpage.hpp"
|
||||||
#include "graphicspage.hpp"
|
#include "graphicspage.hpp"
|
||||||
#include "datafilespage.hpp"
|
#include "datafilespage.hpp"
|
||||||
|
|
||||||
MainDialog::MainDialog()
|
MainDialog::MainDialog(GameSettings &gameSettings,
|
||||||
|
GraphicsSettings &graphicsSettings)
|
||||||
|
: mGameSettings(gameSettings)
|
||||||
|
, mGraphicsSettings(graphicsSettings)
|
||||||
|
|
||||||
{
|
{
|
||||||
QWidget *centralWidget = new QWidget(this);
|
QWidget *centralWidget = new QWidget(this);
|
||||||
setCentralWidget(centralWidget);
|
setCentralWidget(centralWidget);
|
||||||
|
@ -122,8 +131,8 @@ void MainDialog::createIcons()
|
||||||
void MainDialog::createPages()
|
void MainDialog::createPages()
|
||||||
{
|
{
|
||||||
mPlayPage = new PlayPage(this);
|
mPlayPage = new PlayPage(this);
|
||||||
mGraphicsPage = new GraphicsPage(mCfgMgr, this);
|
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
|
||||||
mDataFilesPage = new DataFilesPage(mCfgMgr, this);
|
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, this);
|
||||||
|
|
||||||
// Set the combobox of the play page to imitate the combobox on the datafilespage
|
// Set the combobox of the play page to imitate the combobox on the datafilespage
|
||||||
mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model());
|
mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model());
|
||||||
|
@ -152,46 +161,17 @@ void MainDialog::createPages()
|
||||||
|
|
||||||
bool MainDialog::setup()
|
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
|
// Setup the Graphics page
|
||||||
if (!mGraphicsPage->setupOgre()) {
|
if (!mGraphicsPage->setupOgre()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the Data Files page
|
// Setup the Data Files page
|
||||||
|
/*
|
||||||
if (!mDataFilesPage->setupDataFiles()) {
|
if (!mDataFilesPage->setupDataFiles()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -208,11 +188,67 @@ void MainDialog::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
// Now write all config files
|
// Now write all config files
|
||||||
mDataFilesPage->writeConfig();
|
mDataFilesPage->writeConfig();
|
||||||
mGraphicsPage->writeConfig();
|
mGraphicsPage->saveSettings();
|
||||||
|
|
||||||
// Save user settings
|
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
|
||||||
const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string();
|
QDir dir(userPath);
|
||||||
mSettings.saveUser(settingspath);
|
|
||||||
|
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("<br><b>Could not create %0</b><br><br> \
|
||||||
|
Please make sure you have the right permissions \
|
||||||
|
and try again.<br>").arg(userPath));
|
||||||
|
msgBox.exec();
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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("<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();
|
||||||
|
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("<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();
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.setDevice(&file);
|
||||||
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
mGraphicsSettings.writeFile(stream);
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
@ -221,7 +257,7 @@ void MainDialog::play()
|
||||||
{
|
{
|
||||||
// First do a write of all the configs, just to be sure
|
// First do a write of all the configs, just to be sure
|
||||||
mDataFilesPage->writeConfig();
|
mDataFilesPage->writeConfig();
|
||||||
mGraphicsPage->writeConfig();
|
//mGraphicsPage->writeConfig();
|
||||||
|
|
||||||
// Save user settings
|
// Save user settings
|
||||||
const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string();
|
const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string();
|
||||||
|
|
|
@ -17,12 +17,15 @@ class PlayPage;
|
||||||
class GraphicsPage;
|
class GraphicsPage;
|
||||||
class DataFilesPage;
|
class DataFilesPage;
|
||||||
|
|
||||||
|
class GameSettings;
|
||||||
|
class GraphicsSettings;
|
||||||
|
|
||||||
class MainDialog : public QMainWindow
|
class MainDialog : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainDialog();
|
MainDialog(GameSettings &gameSettings, GraphicsSettings &GraphicsSettings);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
|
@ -43,6 +46,10 @@ private:
|
||||||
|
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
Settings::Manager mSettings;
|
Settings::Manager mSettings;
|
||||||
|
|
||||||
|
GameSettings &mGameSettings;
|
||||||
|
GraphicsSettings &mGraphicsSettings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
#include "filedialog.hpp"
|
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QPushButton>
|
|
||||||
|
|
||||||
FileDialog::FileDialog(QWidget *parent)
|
|
||||||
: QFileDialog(parent)
|
|
||||||
{
|
|
||||||
// Remove the default Choose button to prevent it being updated elsewhere
|
|
||||||
QDialogButtonBox *box = qFindChild<QDialogButtonBox*>(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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
#ifndef FILEDIALOG_HPP
|
|
||||||
#define FILEDIALOG_HPP
|
|
||||||
|
|
||||||
#include <QFileDialog>
|
|
||||||
|
|
||||||
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
|
|
Loading…
Reference in a new issue