forked from mirror/openmw-tes3mp
WIP: working on improving the config file handling
This commit is contained in:
parent
25edba0887
commit
aa25471517
15 changed files with 404 additions and 221 deletions
|
@ -11,7 +11,9 @@ set(LAUNCHER
|
||||||
|
|
||||||
settings/gamesettings.cpp
|
settings/gamesettings.cpp
|
||||||
settings/graphicssettings.cpp
|
settings/graphicssettings.cpp
|
||||||
|
settings/launchersettings.cpp
|
||||||
|
|
||||||
|
utils/comboboxlineedit.cpp
|
||||||
utils/naturalsort.cpp
|
utils/naturalsort.cpp
|
||||||
utils/lineedit.cpp
|
utils/lineedit.cpp
|
||||||
utils/profilescombobox.cpp
|
utils/profilescombobox.cpp
|
||||||
|
@ -32,8 +34,10 @@ set(LAUNCHER_HEADER
|
||||||
|
|
||||||
settings/gamesettings.hpp
|
settings/gamesettings.hpp
|
||||||
settings/graphicssettings.hpp
|
settings/graphicssettings.hpp
|
||||||
|
settings/launchersettings.hpp
|
||||||
settings/settingsbase.hpp
|
settings/settingsbase.hpp
|
||||||
|
|
||||||
|
utils/comboboxlineedit.cpp
|
||||||
utils/lineedit.hpp
|
utils/lineedit.hpp
|
||||||
utils/naturalsort.hpp
|
utils/naturalsort.hpp
|
||||||
utils/profilescombobox.hpp
|
utils/profilescombobox.hpp
|
||||||
|
@ -52,6 +56,7 @@ set(LAUNCHER_HEADER_MOC
|
||||||
model/modelitem.hpp
|
model/modelitem.hpp
|
||||||
model/esm/esmfile.hpp
|
model/esm/esmfile.hpp
|
||||||
|
|
||||||
|
utils/comboboxlineedit.hpp
|
||||||
utils/lineedit.hpp
|
utils/lineedit.hpp
|
||||||
utils/profilescombobox.hpp
|
utils/profilescombobox.hpp
|
||||||
utils/textinputdialog.hpp
|
utils/textinputdialog.hpp
|
||||||
|
@ -86,6 +91,7 @@ ENDIF(OGRE_STATIC)
|
||||||
add_executable(omwlauncher
|
add_executable(omwlauncher
|
||||||
${GUI_TYPE}
|
${GUI_TYPE}
|
||||||
${LAUNCHER}
|
${LAUNCHER}
|
||||||
|
${LAUNCHER_HEADER}
|
||||||
${RCC_SRCS}
|
${RCC_SRCS}
|
||||||
${MOC_SRCS}
|
${MOC_SRCS}
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "model/esm/esmfile.hpp"
|
#include "model/esm/esmfile.hpp"
|
||||||
|
|
||||||
#include "settings/gamesettings.hpp"
|
#include "settings/gamesettings.hpp"
|
||||||
|
#include "settings/launchersettings.hpp"
|
||||||
|
|
||||||
#include "utils/profilescombobox.hpp"
|
#include "utils/profilescombobox.hpp"
|
||||||
#include "utils/lineedit.hpp"
|
#include "utils/lineedit.hpp"
|
||||||
|
@ -47,9 +48,10 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2)
|
||||||
return index1.row() <= index2.row();
|
return index1.row() <= index2.row();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, QWidget *parent)
|
DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent)
|
||||||
: mCfgMgr(cfg)
|
: mCfgMgr(cfg)
|
||||||
, mGameSettings(gameSettings)
|
, mGameSettings(gameSettings)
|
||||||
|
, mLauncherSettings(launcherSettings)
|
||||||
, QWidget(parent)
|
, QWidget(parent)
|
||||||
{
|
{
|
||||||
// Models
|
// Models
|
||||||
|
@ -129,15 +131,19 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
|
||||||
mPluginsTable->setColumnHidden(8, true);
|
mPluginsTable->setColumnHidden(8, true);
|
||||||
|
|
||||||
// Add both tables to a splitter
|
// Add both tables to a splitter
|
||||||
QSplitter *splitter = new QSplitter(this);
|
mSplitter = new QSplitter(this);
|
||||||
splitter->setOrientation(Qt::Horizontal);
|
mSplitter->setOrientation(Qt::Horizontal);
|
||||||
splitter->addWidget(mMastersTable);
|
mSplitter->setChildrenCollapsible(false); // Don't allow the widgets to be hidden
|
||||||
splitter->addWidget(mPluginsTable);
|
mSplitter->addWidget(mMastersTable);
|
||||||
|
mSplitter->addWidget(mPluginsTable);
|
||||||
|
|
||||||
// Adjust the default widget widths inside the splitter
|
// Adjust the default widget widths inside the splitter
|
||||||
QList<int> sizeList;
|
QList<int> sizeList;
|
||||||
sizeList << 175 << 200;
|
sizeList << mLauncherSettings.value(QString("General/MastersTable/width"), QString("200")).toInt();
|
||||||
splitter->setSizes(sizeList);
|
sizeList << mLauncherSettings.value(QString("General/PluginTable/width"), QString("340")).toInt();
|
||||||
|
qDebug() << sizeList;
|
||||||
|
|
||||||
|
mSplitter->setSizes(sizeList);
|
||||||
|
|
||||||
// Bottom part with profile options
|
// Bottom part with profile options
|
||||||
QLabel *profileLabel = new QLabel(tr("Current Profile: "), this);
|
QLabel *profileLabel = new QLabel(tr("Current Profile: "), this);
|
||||||
|
@ -158,7 +164,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
|
||||||
QVBoxLayout *pageLayout = new QVBoxLayout(this);
|
QVBoxLayout *pageLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
pageLayout->addWidget(filterToolBar);
|
pageLayout->addWidget(filterToolBar);
|
||||||
pageLayout->addWidget(splitter);
|
pageLayout->addWidget(mSplitter);
|
||||||
pageLayout->addWidget(mProfileToolBar);
|
pageLayout->addWidget(mProfileToolBar);
|
||||||
|
|
||||||
// Create a dialog for the new profile name input
|
// Create a dialog for the new profile name input
|
||||||
|
@ -178,8 +184,9 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
|
||||||
connect(mProfilesComboBox, SIGNAL(profileRenamed(QString,QString)), this, SLOT(profileRenamed(QString,QString)));
|
connect(mProfilesComboBox, SIGNAL(profileRenamed(QString,QString)), this, SLOT(profileRenamed(QString,QString)));
|
||||||
connect(mProfilesComboBox, SIGNAL(profileChanged(QString,QString)), this, SLOT(profileChanged(QString,QString)));
|
connect(mProfilesComboBox, SIGNAL(profileChanged(QString,QString)), this, SLOT(profileChanged(QString,QString)));
|
||||||
|
|
||||||
|
connect(mSplitter, SIGNAL(splitterMoved(int,int)), this, SLOT(updateSplitter()));
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
setupConfig();
|
|
||||||
setupDataFiles();
|
setupDataFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,126 +228,50 @@ void DataFilesPage::createActions()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::setupConfig()
|
|
||||||
{
|
|
||||||
// Open our config file
|
|
||||||
QString config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string());
|
|
||||||
mLauncherConfig = new QSettings(config, QSettings::IniFormat);
|
|
||||||
|
|
||||||
// Make sure we have no groups open
|
|
||||||
while (!mLauncherConfig->group().isEmpty()) {
|
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
mLauncherConfig->beginGroup("Profiles");
|
|
||||||
QStringList profiles = mLauncherConfig->childGroups();
|
|
||||||
|
|
||||||
// Add the profiles to the combobox
|
|
||||||
foreach (const QString &profile, profiles) {
|
|
||||||
|
|
||||||
if (profile.contains(QRegExp("[^a-zA-Z0-9_]")))
|
|
||||||
continue; // Profile name contains garbage
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "adding " << profile;
|
|
||||||
mProfilesComboBox->addItem(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a default profile
|
|
||||||
if (mProfilesComboBox->findText(QString("Default")) == -1) {
|
|
||||||
mProfilesComboBox->addItem(QString("Default"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString currentProfile = mLauncherConfig->value("CurrentProfile").toString();
|
|
||||||
|
|
||||||
if (currentProfile.isEmpty()) {
|
|
||||||
// No current profile selected
|
|
||||||
currentProfile = "Default";
|
|
||||||
}
|
|
||||||
|
|
||||||
const int currentIndex = mProfilesComboBox->findText(currentProfile);
|
|
||||||
if (currentIndex != -1) {
|
|
||||||
// Profile is found
|
|
||||||
mProfilesComboBox->setCurrentIndex(currentIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DataFilesPage::readConfig()
|
void DataFilesPage::readConfig()
|
||||||
{
|
{
|
||||||
// Don't read the config if no masters are found
|
// // Don't read the config if no masters are found
|
||||||
if (mMastersModel->rowCount() < 1)
|
// if (mMastersModel->rowCount() < 1)
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
QString profile = mProfilesComboBox->currentText();
|
// QString profile = mProfilesComboBox->currentText();
|
||||||
|
|
||||||
// Make sure we have no groups open
|
|
||||||
while (!mLauncherConfig->group().isEmpty()) {
|
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
mLauncherConfig->beginGroup("Profiles");
|
|
||||||
mLauncherConfig->beginGroup(profile);
|
|
||||||
|
|
||||||
QStringList childKeys = mLauncherConfig->childKeys();
|
|
||||||
QStringList plugins;
|
|
||||||
|
|
||||||
// Sort the child keys numerical instead of alphabetically
|
|
||||||
// i.e. Plugin1, Plugin2 instead of Plugin1, Plugin10
|
|
||||||
qSort(childKeys.begin(), childKeys.end(), naturalSortLessThanCI);
|
|
||||||
|
|
||||||
foreach (const QString &key, childKeys) {
|
|
||||||
const QString keyValue = mLauncherConfig->value(key).toString();
|
|
||||||
|
|
||||||
if (key.startsWith("Plugin")) {
|
|
||||||
//QStringList checked = mPluginsModel->checkedItems();
|
|
||||||
EsmFile *file = mPluginsModel->findItem(keyValue);
|
|
||||||
QModelIndex index = mPluginsModel->indexFromItem(file);
|
|
||||||
|
|
||||||
mPluginsModel->setCheckState(index, Qt::Checked);
|
|
||||||
// Move the row to the top of te view
|
|
||||||
//mPluginsModel->moveRow(index.row(), checked.count());
|
|
||||||
plugins << keyValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.startsWith("Master")) {
|
|
||||||
EsmFile *file = mMastersModel->findItem(keyValue);
|
|
||||||
mMastersModel->setCheckState(mMastersModel->indexFromItem(file), Qt::Checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << plugins;
|
|
||||||
|
|
||||||
|
|
||||||
// // Set the checked item positions
|
|
||||||
// const QStringList checked = mPluginsModel->checkedItems();
|
|
||||||
// for (int i = 0; i < plugins.size(); ++i) {
|
|
||||||
// EsmFile *file = mPluginsModel->findItem(plugins.at(i));
|
|
||||||
// QModelIndex index = mPluginsModel->indexFromItem(file);
|
|
||||||
// mPluginsModel->moveRow(index.row(), i);
|
|
||||||
// qDebug() << "Moving: " << plugins.at(i) << " from: " << index.row() << " to: " << i << " count: " << checked.count();
|
|
||||||
|
|
||||||
|
// // Make sure we have no groups open
|
||||||
|
// while (!mLauncherConfig->group().isEmpty()) {
|
||||||
|
// mLauncherConfig->endGroup();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Iterate over the plugins to set their checkstate and position
|
// mLauncherConfig->beginGroup("Profiles");
|
||||||
// for (int i = 0; i < plugins.size(); ++i) {
|
// mLauncherConfig->beginGroup(profile);
|
||||||
// const QString plugin = plugins.at(i);
|
|
||||||
|
|
||||||
// const QList<QStandardItem *> pluginList = mPluginsModel->findItems(plugin);
|
// QStringList childKeys = mLauncherConfig->childKeys();
|
||||||
|
// QStringList plugins;
|
||||||
|
|
||||||
// if (!pluginList.isEmpty())
|
// // Sort the child keys numerical instead of alphabetically
|
||||||
// {
|
// // i.e. Plugin1, Plugin2 instead of Plugin1, Plugin10
|
||||||
// foreach (const QStandardItem *currentPlugin, pluginList) {
|
// qSort(childKeys.begin(), childKeys.end(), naturalSortLessThanCI);
|
||||||
// mPluginsModel->setData(currentPlugin->index(), Qt::Checked, Qt::CheckStateRole);
|
|
||||||
|
|
||||||
// // Move the plugin to the position specified in the config file
|
// foreach (const QString &key, childKeys) {
|
||||||
// mPluginsModel->insertRow(i, mPluginsModel->takeRow(currentPlugin->row()));
|
// const QString keyValue = mLauncherConfig->value(key).toString();
|
||||||
// }
|
|
||||||
|
// if (key.startsWith("Plugin")) {
|
||||||
|
// //QStringList checked = mPluginsModel->checkedItems();
|
||||||
|
// EsmFile *file = mPluginsModel->findItem(keyValue);
|
||||||
|
// QModelIndex index = mPluginsModel->indexFromItem(file);
|
||||||
|
|
||||||
|
// mPluginsModel->setCheckState(index, Qt::Checked);
|
||||||
|
// // Move the row to the top of te view
|
||||||
|
// //mPluginsModel->moveRow(index.row(), checked.count());
|
||||||
|
// plugins << keyValue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (key.startsWith("Master")) {
|
||||||
|
// EsmFile *file = mMastersModel->findItem(keyValue);
|
||||||
|
// mMastersModel->setCheckState(mMastersModel->indexFromItem(file), Qt::Checked);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// qDebug() << plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::setupDataFiles()
|
void DataFilesPage::setupDataFiles()
|
||||||
|
@ -362,10 +293,43 @@ void DataFilesPage::setupDataFiles()
|
||||||
mPluginsModel->addPlugins(dataLocal);
|
mPluginsModel->addPlugins(dataLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFilesPage::loadSettings()
|
||||||
|
{
|
||||||
|
qDebug() << "load settings";
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFilesPage::saveSettings()
|
||||||
|
{
|
||||||
|
QString profile = mLauncherSettings.value(QString("Profiles/CurrentProfile"));
|
||||||
|
qDebug() << "save settings" << profile;
|
||||||
|
|
||||||
|
QStringList items = mMastersModel->checkedItems();
|
||||||
|
|
||||||
|
foreach(const QString &master, items) {
|
||||||
|
mLauncherSettings.setMultiValue(QString("Profiles/") + profile + QString("/master"), master);
|
||||||
|
}
|
||||||
|
|
||||||
|
items.clear();
|
||||||
|
items = mPluginsModel->checkedItems();
|
||||||
|
|
||||||
|
qDebug() << items.size();
|
||||||
|
|
||||||
|
foreach(const QString &plugin, items) {
|
||||||
|
qDebug() << "setting " << plugin;
|
||||||
|
mLauncherSettings.setMultiValue(QString("Profiles/") + profile + QString("/plugin"), plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -518,21 +482,22 @@ void DataFilesPage::writeConfig(QString profile)
|
||||||
|
|
||||||
void DataFilesPage::newProfile()
|
void DataFilesPage::newProfile()
|
||||||
{
|
{
|
||||||
if (mNewProfileDialog->exec() == QDialog::Accepted) {
|
// if (mNewProfileDialog->exec() == QDialog::Accepted) {
|
||||||
|
|
||||||
const QString text = mNewProfileDialog->lineEdit()->text();
|
// const QString text = mNewProfileDialog->lineEdit()->text();
|
||||||
mProfilesComboBox->addItem(text);
|
// mProfilesComboBox->addItem(text);
|
||||||
|
// mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(text));
|
||||||
|
// }
|
||||||
|
|
||||||
// Copy the currently checked items to cfg
|
mDeleteProfileAction->setEnabled(false);
|
||||||
writeConfig(text);
|
mProfilesComboBox->setCurrentIndex(-1);
|
||||||
mLauncherConfig->sync();
|
mProfilesComboBox->setEditEnabled(true);
|
||||||
|
mProfilesComboBox->lineEdit()->setFocus();
|
||||||
mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(text));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::updateOkButton(const QString &text)
|
void DataFilesPage::updateOkButton(const QString &text)
|
||||||
{
|
{
|
||||||
|
// We do this here because we need the profiles combobox text
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
mNewProfileDialog->setOkButtonEnabled(false);
|
mNewProfileDialog->setOkButtonEnabled(false);
|
||||||
return;
|
return;
|
||||||
|
@ -543,6 +508,16 @@ void DataFilesPage::updateOkButton(const QString &text)
|
||||||
: mNewProfileDialog->setOkButtonEnabled(false);
|
: mNewProfileDialog->setOkButtonEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataFilesPage::updateSplitter()
|
||||||
|
{
|
||||||
|
// Sigh, update the saved splitter size in settings only when moved
|
||||||
|
// Since getting mSplitter->sizes() if page is hidden returns invalid values
|
||||||
|
QList<int> sizes = mSplitter->sizes();
|
||||||
|
|
||||||
|
mLauncherSettings.setValue(QString("General/MastersTable/width"), QString::number(sizes.at(0)));
|
||||||
|
mLauncherSettings.setValue(QString("General/PluginsTable/width"), QString::number(sizes.at(1)));
|
||||||
|
}
|
||||||
|
|
||||||
void DataFilesPage::deleteProfile()
|
void DataFilesPage::deleteProfile()
|
||||||
{
|
{
|
||||||
QString profile = mProfilesComboBox->currentText();
|
QString profile = mProfilesComboBox->currentText();
|
||||||
|
@ -562,18 +537,8 @@ void DataFilesPage::deleteProfile()
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
|
|
||||||
if (msgBox.clickedButton() == deleteButton) {
|
if (msgBox.clickedButton() == deleteButton) {
|
||||||
// Make sure we have no groups open
|
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/master"));
|
||||||
while (!mLauncherConfig->group().isEmpty()) {
|
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/plugin"));
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
mLauncherConfig->beginGroup("Profiles");
|
|
||||||
|
|
||||||
// Open the profile-name subgroup
|
|
||||||
mLauncherConfig->beginGroup(profile);
|
|
||||||
mLauncherConfig->remove(""); // Clear the subgroup
|
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
|
|
||||||
// Remove the profile from the combobox
|
// Remove the profile from the combobox
|
||||||
mProfilesComboBox->removeItem(mProfilesComboBox->findText(profile));
|
mProfilesComboBox->removeItem(mProfilesComboBox->findText(profile));
|
||||||
|
@ -624,11 +589,8 @@ void DataFilesPage::refresh()
|
||||||
{
|
{
|
||||||
mPluginsModel->sort(0);
|
mPluginsModel->sort(0);
|
||||||
|
|
||||||
|
|
||||||
// Refresh the plugins table
|
// Refresh the plugins table
|
||||||
mPluginsTable->scrollToTop();
|
mPluginsTable->scrollToTop();
|
||||||
writeConfig();
|
|
||||||
readConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -679,50 +641,43 @@ void DataFilesPage::profileChanged(const QString &previous, const QString &curre
|
||||||
mProfilesComboBox->setEditEnabled(true);
|
mProfilesComboBox->setEditEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!previous.isEmpty()) {
|
if (previous.isEmpty())
|
||||||
writeConfig(previous);
|
|
||||||
mLauncherConfig->sync();
|
|
||||||
|
|
||||||
if (mProfilesComboBox->currentIndex() == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
if (mProfilesComboBox->findText(previous) == -1)
|
||||||
|
return; // Profile was deleted
|
||||||
|
|
||||||
|
// Store the previous profile
|
||||||
|
mLauncherSettings.setValue(QString("Profiles/CurrentProfile"), previous);
|
||||||
|
saveSettings();
|
||||||
|
mLauncherSettings.setValue(QString("Profiles/CurrentProfile"), current);
|
||||||
|
|
||||||
|
|
||||||
mMastersModel->uncheckAll();
|
mMastersModel->uncheckAll();
|
||||||
mPluginsModel->uncheckAll();
|
mPluginsModel->uncheckAll();
|
||||||
readConfig();
|
loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::profileRenamed(const QString &previous, const QString ¤t)
|
void DataFilesPage::profileRenamed(const QString &previous, const QString ¤t)
|
||||||
{
|
{
|
||||||
|
qDebug() << "rename";
|
||||||
if (previous.isEmpty())
|
if (previous.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Save the new profile name
|
// Save the new profile name
|
||||||
writeConfig(current);
|
mLauncherSettings.setValue(QString("Profiles/CurrentProfile"), current);
|
||||||
|
saveSettings();
|
||||||
|
|
||||||
// Make sure we have no groups open
|
// Remove the old one
|
||||||
while (!mLauncherConfig->group().isEmpty()) {
|
mLauncherSettings.remove(QString("Profiles/") + previous + QString("/master"));
|
||||||
mLauncherConfig->endGroup();
|
mLauncherSettings.remove(QString("Profiles/") + previous + QString("/plugin"));
|
||||||
}
|
|
||||||
|
|
||||||
mLauncherConfig->beginGroup("Profiles");
|
// Remove the profile from the combobox
|
||||||
|
mProfilesComboBox->removeItem(mProfilesComboBox->findText(previous));
|
||||||
|
|
||||||
// Open the profile-name subgroup
|
mMastersModel->uncheckAll();
|
||||||
mLauncherConfig->beginGroup(previous);
|
mPluginsModel->uncheckAll();
|
||||||
mLauncherConfig->remove(""); // Clear the subgroup
|
loadSettings();
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
mLauncherConfig->sync();
|
|
||||||
|
|
||||||
// Remove the profile from the combobox
|
|
||||||
mProfilesComboBox->removeItem(mProfilesComboBox->findText(previous));
|
|
||||||
|
|
||||||
mMastersModel->uncheckAll();
|
|
||||||
mPluginsModel->uncheckAll();
|
|
||||||
readConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::showContextMenu(const QPoint &point)
|
void DataFilesPage::showContextMenu(const QPoint &point)
|
||||||
|
|
|
@ -6,16 +6,18 @@
|
||||||
|
|
||||||
class QTableView;
|
class QTableView;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
class QSettings;
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
|
class QSplitter;
|
||||||
class QMenu;
|
class QMenu;
|
||||||
|
|
||||||
class ProfilesComboBox;
|
class ProfilesComboBox;
|
||||||
class DataFilesModel;
|
class DataFilesModel;
|
||||||
|
|
||||||
class TextInputDialog;
|
class TextInputDialog;
|
||||||
class ProfilesComboBox;
|
class ProfilesComboBox;
|
||||||
class GameSettings;
|
class GameSettings;
|
||||||
|
class LauncherSettings;
|
||||||
|
|
||||||
namespace Files { struct ConfigurationManager; }
|
namespace Files { struct ConfigurationManager; }
|
||||||
|
|
||||||
|
@ -24,11 +26,13 @@ class DataFilesPage : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, QWidget *parent = 0);
|
DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent = 0);
|
||||||
|
|
||||||
ProfilesComboBox *mProfilesComboBox;
|
ProfilesComboBox *mProfilesComboBox;
|
||||||
|
|
||||||
void writeConfig(QString profile = QString());
|
void writeConfig(QString profile = QString());
|
||||||
|
void saveSettings();
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCheckState(QModelIndex index);
|
void setCheckState(QModelIndex index);
|
||||||
|
@ -38,6 +42,7 @@ public slots:
|
||||||
void profileChanged(const QString &previous, const QString ¤t);
|
void profileChanged(const QString &previous, const QString ¤t);
|
||||||
void profileRenamed(const QString &previous, const QString ¤t);
|
void profileRenamed(const QString &previous, const QString ¤t);
|
||||||
void updateOkButton(const QString &text);
|
void updateOkButton(const QString &text);
|
||||||
|
void updateSplitter();
|
||||||
|
|
||||||
// Action slots
|
// Action slots
|
||||||
void newProfile();
|
void newProfile();
|
||||||
|
@ -61,6 +66,7 @@ private:
|
||||||
|
|
||||||
QToolBar *mProfileToolBar;
|
QToolBar *mProfileToolBar;
|
||||||
QMenu *mContextMenu;
|
QMenu *mContextMenu;
|
||||||
|
QSplitter *mSplitter;
|
||||||
|
|
||||||
QAction *mNewProfileAction;
|
QAction *mNewProfileAction;
|
||||||
QAction *mDeleteProfileAction;
|
QAction *mDeleteProfileAction;
|
||||||
|
@ -74,8 +80,8 @@ private:
|
||||||
|
|
||||||
Files::ConfigurationManager &mCfgMgr;
|
Files::ConfigurationManager &mCfgMgr;
|
||||||
|
|
||||||
QSettings *mLauncherConfig;
|
|
||||||
GameSettings &mGameSettings;
|
GameSettings &mGameSettings;
|
||||||
|
LauncherSettings &mLauncherSettings;
|
||||||
|
|
||||||
TextInputDialog *mNewProfileDialog;
|
TextInputDialog *mNewProfileDialog;
|
||||||
|
|
||||||
|
@ -87,6 +93,8 @@ private:
|
||||||
void setupConfig();
|
void setupConfig();
|
||||||
void readConfig();
|
void readConfig();
|
||||||
|
|
||||||
|
void loadSettings();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "maindialog.hpp"
|
#include "maindialog.hpp"
|
||||||
#include "settings/gamesettings.hpp"
|
#include "settings/gamesettings.hpp"
|
||||||
#include "settings/graphicssettings.hpp"
|
#include "settings/graphicssettings.hpp"
|
||||||
|
#include "settings/launchersettings.hpp"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -52,6 +53,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
GameSettings gameSettings(cfgMgr);
|
GameSettings gameSettings(cfgMgr);
|
||||||
GraphicsSettings graphicsSettings;
|
GraphicsSettings graphicsSettings;
|
||||||
|
LauncherSettings launcherSettings;
|
||||||
|
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
paths.append(userPath + QString("openmw.cfg"));
|
paths.append(userPath + QString("openmw.cfg"));
|
||||||
|
@ -118,8 +120,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// On to the graphics settings
|
// On to the graphics settings
|
||||||
qDebug() << userPath;
|
|
||||||
|
|
||||||
QFile localDefault(QString("settings-default.cfg"));
|
QFile localDefault(QString("settings-default.cfg"));
|
||||||
QFile globalDefault(globalPath + QString("settings-default.cfg"));
|
QFile globalDefault(globalPath + QString("settings-default.cfg"));
|
||||||
|
|
||||||
|
@ -163,8 +163,36 @@ int main(int argc, char *argv[])
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now the launcher settings
|
||||||
|
paths.clear();
|
||||||
|
paths.append(QString("launcher.cfg"));
|
||||||
|
paths.append(userPath + QString("launcher.cfg"));
|
||||||
|
|
||||||
MainDialog mainWin(gameSettings, graphicsSettings);
|
foreach (const QString &path, paths) {
|
||||||
|
qDebug() << "Loading: " << path;
|
||||||
|
QFile file(path);
|
||||||
|
if (file.exists()) {
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle("Error opening OpenMW configuration file");
|
||||||
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
|
||||||
|
Please make sure you have the right permissions \
|
||||||
|
and try again.<br>").arg(file.fileName()));
|
||||||
|
msgBox.exec();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
QTextStream stream(&file);
|
||||||
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
launcherSettings.readFile(stream);
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MainDialog mainWin(gameSettings, graphicsSettings, launcherSettings);
|
||||||
|
|
||||||
if (mainWin.setup()) {
|
if (mainWin.setup()) {
|
||||||
mainWin.show();
|
mainWin.show();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "settings/gamesettings.hpp"
|
#include "settings/gamesettings.hpp"
|
||||||
#include "settings/graphicssettings.hpp"
|
#include "settings/graphicssettings.hpp"
|
||||||
|
#include "settings/launchersettings.hpp"
|
||||||
|
|
||||||
#include "utils/profilescombobox.hpp"
|
#include "utils/profilescombobox.hpp"
|
||||||
|
|
||||||
|
@ -11,9 +12,11 @@
|
||||||
#include "datafilespage.hpp"
|
#include "datafilespage.hpp"
|
||||||
|
|
||||||
MainDialog::MainDialog(GameSettings &gameSettings,
|
MainDialog::MainDialog(GameSettings &gameSettings,
|
||||||
GraphicsSettings &graphicsSettings)
|
GraphicsSettings &graphicsSettings,
|
||||||
|
LauncherSettings &launcherSettings)
|
||||||
: mGameSettings(gameSettings)
|
: mGameSettings(gameSettings)
|
||||||
, mGraphicsSettings(graphicsSettings)
|
, mGraphicsSettings(graphicsSettings)
|
||||||
|
, mLauncherSettings(launcherSettings)
|
||||||
|
|
||||||
{
|
{
|
||||||
QWidget *centralWidget = new QWidget(this);
|
QWidget *centralWidget = new QWidget(this);
|
||||||
|
@ -132,7 +135,7 @@ void MainDialog::createPages()
|
||||||
{
|
{
|
||||||
mPlayPage = new PlayPage(this);
|
mPlayPage = new PlayPage(this);
|
||||||
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
|
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
|
||||||
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, this);
|
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, mLauncherSettings, 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());
|
||||||
|
@ -161,18 +164,11 @@ void MainDialog::createPages()
|
||||||
|
|
||||||
bool MainDialog::setup()
|
bool MainDialog::setup()
|
||||||
{
|
{
|
||||||
// Setup the Graphics page
|
// Call this so we can exit on Ogre errors before mainwindow is shown
|
||||||
if (!mGraphicsPage->setupOgre()) {
|
if (!mGraphicsPage->setupOgre()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the Data Files page
|
|
||||||
/*
|
|
||||||
if (!mDataFilesPage->setupDataFiles()) {
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,11 +180,28 @@ void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
||||||
mPagesWidget->setCurrentIndex(mIconWidget->row(current));
|
mPagesWidget->setCurrentIndex(mIconWidget->row(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainDialog::closeEvent(QCloseEvent *event)
|
void MainDialog::loadSettings()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainDialog::saveSettings()
|
||||||
|
{
|
||||||
|
QString width = QString::number(this->width());
|
||||||
|
QString height = QString::number(this->height());
|
||||||
|
|
||||||
|
mLauncherSettings.setValue(QString("General/MainWindow/width"), width);
|
||||||
|
mLauncherSettings.setValue(QString("General/MainWindow/height"), height);
|
||||||
|
|
||||||
|
qDebug() << "size: " << width << height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainDialog::writeSettings()
|
||||||
{
|
{
|
||||||
// Now write all config files
|
// Now write all config files
|
||||||
mDataFilesPage->writeConfig();
|
saveSettings();
|
||||||
mGraphicsPage->saveSettings();
|
mGraphicsPage->saveSettings();
|
||||||
|
mDataFilesPage->saveSettings();
|
||||||
|
|
||||||
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
|
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
|
||||||
QDir dir(userPath);
|
QDir dir(userPath);
|
||||||
|
@ -203,7 +216,7 @@ void MainDialog::closeEvent(QCloseEvent *event)
|
||||||
Please make sure you have the right permissions \
|
Please make sure you have the right permissions \
|
||||||
and try again.<br>").arg(userPath));
|
and try again.<br>").arg(userPath));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
event->accept();
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +233,7 @@ void MainDialog::closeEvent(QCloseEvent *event)
|
||||||
Please make sure you have the right permissions \
|
Please make sure you have the right permissions \
|
||||||
and try again.<br>").arg(file.fileName()));
|
and try again.<br>").arg(file.fileName()));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
event->accept();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
|
@ -242,26 +255,52 @@ void MainDialog::closeEvent(QCloseEvent *event)
|
||||||
Please make sure you have the right permissions \
|
Please make sure you have the right permissions \
|
||||||
and try again.<br>").arg(file.fileName()));
|
and try again.<br>").arg(file.fileName()));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
event->accept();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.setDevice(&file);
|
stream.setDevice(&file);
|
||||||
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
mGraphicsSettings.writeFile(stream);
|
mGraphicsSettings.writeFile(stream);
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
// Launcher settings
|
||||||
|
file.setFileName(userPath + QString("launcher.cfg"));
|
||||||
|
|
||||||
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
||||||
|
// File cannot be opened or created
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle("Error writing Launcher 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();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.setDevice(&file);
|
||||||
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
mLauncherSettings.writeFile(stream);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainDialog::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
saveSettings();
|
||||||
|
writeSettings();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainDialog::play()
|
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();
|
||||||
|
saveSettings();
|
||||||
// Save user settings
|
writeSettings();
|
||||||
const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string();
|
|
||||||
mSettings.saveUser(settingspath);
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QString game = "./openmw.exe";
|
QString game = "./openmw.exe";
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
#include <components/settings/settings.hpp>
|
|
||||||
|
|
||||||
class QListWidget;
|
class QListWidget;
|
||||||
class QListWidgetItem;
|
class QListWidgetItem;
|
||||||
|
@ -19,22 +18,31 @@ class DataFilesPage;
|
||||||
|
|
||||||
class GameSettings;
|
class GameSettings;
|
||||||
class GraphicsSettings;
|
class GraphicsSettings;
|
||||||
|
class LauncherSettings;
|
||||||
|
|
||||||
class MainDialog : public QMainWindow
|
class MainDialog : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainDialog(GameSettings &gameSettings, GraphicsSettings &GraphicsSettings);
|
MainDialog(GameSettings &gameSettings,
|
||||||
|
GraphicsSettings &GraphicsSettings,
|
||||||
|
LauncherSettings &launcherSettings);
|
||||||
|
|
||||||
|
bool setup();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
void play();
|
void play();
|
||||||
bool setup();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createIcons();
|
void createIcons();
|
||||||
void createPages();
|
void createPages();
|
||||||
|
|
||||||
|
void loadSettings();
|
||||||
|
void saveSettings();
|
||||||
|
void writeSettings();
|
||||||
|
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
QListWidget *mIconWidget;
|
QListWidget *mIconWidget;
|
||||||
|
@ -45,10 +53,10 @@ private:
|
||||||
DataFilesPage *mDataFilesPage;
|
DataFilesPage *mDataFilesPage;
|
||||||
|
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
Settings::Manager mSettings;
|
|
||||||
|
|
||||||
GameSettings &mGameSettings;
|
GameSettings &mGameSettings;
|
||||||
GraphicsSettings &mGraphicsSettings;
|
GraphicsSettings &mGraphicsSettings;
|
||||||
|
LauncherSettings &mLauncherSettings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -334,6 +334,7 @@ void DataFilesModel::addPlugins(const QString &path)
|
||||||
QFileInfo info(dir.absoluteFilePath(path));
|
QFileInfo info(dir.absoluteFilePath(path));
|
||||||
EsmFile *file = new EsmFile(path);
|
EsmFile *file = new EsmFile(path);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ESM::ESMReader fileReader;
|
ESM::ESMReader fileReader;
|
||||||
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(mEncoding.toStdString()));
|
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(mEncoding.toStdString()));
|
||||||
|
@ -361,7 +362,8 @@ void DataFilesModel::addPlugins(const QString &path)
|
||||||
|
|
||||||
|
|
||||||
// Put the file in the table
|
// Put the file in the table
|
||||||
addFile(file);
|
if (findItem(path) == 0)
|
||||||
|
addFile(file);
|
||||||
} catch(std::runtime_error &e) {
|
} catch(std::runtime_error &e) {
|
||||||
// An error occurred while reading the .esp
|
// An error occurred while reading the .esp
|
||||||
qWarning() << "Error reading esp: " << e.what();
|
qWarning() << "Error reading esp: " << e.what();
|
||||||
|
|
|
@ -101,7 +101,14 @@ bool GameSettings::readFile(QTextStream &stream)
|
||||||
qDebug() << "key: " << key;
|
qDebug() << "key: " << key;
|
||||||
// There can be multiple data keys
|
// There can be multiple data keys
|
||||||
if (key == QLatin1String("data")) {
|
if (key == QLatin1String("data")) {
|
||||||
cache.insertMulti(key, value);
|
// Remove keys from previous config and overwrite them
|
||||||
|
mSettings.remove(key);
|
||||||
|
QStringList values = cache.values(key);
|
||||||
|
if (!values.contains(value)) {
|
||||||
|
// Do not insert duplicate values
|
||||||
|
qDebug() << "values does not contain: " << value << values;
|
||||||
|
cache.insertMulti(key, value);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
cache.insert(key, value);
|
cache.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
45
apps/launcher/settings/launchersettings.cpp
Normal file
45
apps/launcher/settings/launchersettings.cpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QString>
|
||||||
|
#include <QRegExp>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
#include "launchersettings.hpp"
|
||||||
|
|
||||||
|
LauncherSettings::LauncherSettings()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LauncherSettings::~LauncherSettings()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool LauncherSettings::writeFile(QTextStream &stream)
|
||||||
|
{
|
||||||
|
QString sectionPrefix;
|
||||||
|
QRegExp sectionRe("([^/]+)/(.+)$");
|
||||||
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
||||||
|
|
||||||
|
QMapIterator<QString, QString> i(settings);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
|
||||||
|
QString prefix;
|
||||||
|
QString key;
|
||||||
|
|
||||||
|
if (sectionRe.exactMatch(i.key())) {
|
||||||
|
prefix = sectionRe.cap(1);
|
||||||
|
key = sectionRe.cap(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sectionPrefix != prefix) {
|
||||||
|
sectionPrefix = prefix;
|
||||||
|
stream << "\n[" << prefix << "]\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << key << "=" << i.value() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
16
apps/launcher/settings/launchersettings.hpp
Normal file
16
apps/launcher/settings/launchersettings.hpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef LAUNCHERSETTINGS_HPP
|
||||||
|
#define LAUNCHERSETTINGS_HPP
|
||||||
|
|
||||||
|
#include "settingsbase.hpp"
|
||||||
|
|
||||||
|
class LauncherSettings : public SettingsBase<QMap<QString, QString>>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LauncherSettings();
|
||||||
|
~LauncherSettings();
|
||||||
|
|
||||||
|
bool writeFile(QTextStream &stream);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LAUNCHERSETTINGS_HPP
|
|
@ -2,6 +2,7 @@
|
||||||
#define SETTINGSBASE_HPP
|
#define SETTINGSBASE_HPP
|
||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QStringList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
@ -26,6 +27,17 @@ public:
|
||||||
mSettings.insert(key, value);
|
mSettings.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void setMultiValue(const QString &key, const QString &value)
|
||||||
|
{
|
||||||
|
mSettings.insertMulti(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void remove(const QString &key)
|
||||||
|
{
|
||||||
|
mSettings.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
Map getSettings() {return mSettings;}
|
Map getSettings() {return mSettings;}
|
||||||
|
|
||||||
bool readFile(QTextStream &stream)
|
bool readFile(QTextStream &stream)
|
||||||
|
@ -56,11 +68,18 @@ public:
|
||||||
if (!sectionPrefix.isEmpty())
|
if (!sectionPrefix.isEmpty())
|
||||||
key.prepend(sectionPrefix);
|
key.prepend(sectionPrefix);
|
||||||
|
|
||||||
// QMap will replace the value if key exists, QMultiMap creates a new one
|
mSettings.remove(key);
|
||||||
mCache.insert(key, value);
|
|
||||||
|
QStringList values = mCache.values(key);
|
||||||
|
if (!values.contains(value)) {
|
||||||
|
// QMap will replace the value if key exists, QMultiMap creates a new one
|
||||||
|
mCache.insert(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "HI THERE! " << mCache;
|
||||||
|
|
||||||
if (mSettings.isEmpty()) {
|
if (mSettings.isEmpty()) {
|
||||||
mSettings = mCache; // This is the first time we read a file
|
mSettings = mCache; // This is the first time we read a file
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "lineedit.hpp"
|
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
|
||||||
|
#include "lineedit.hpp"
|
||||||
|
|
||||||
LineEdit::LineEdit(QWidget *parent)
|
LineEdit::LineEdit(QWidget *parent)
|
||||||
: QLineEdit(parent)
|
: QLineEdit(parent)
|
||||||
{
|
{
|
||||||
|
@ -13,9 +14,11 @@ LineEdit::LineEdit(QWidget *parent)
|
||||||
mClearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
mClearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||||
mClearButton->hide();
|
mClearButton->hide();
|
||||||
connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear()));
|
connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear()));
|
||||||
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
|
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateClearButton(const QString&)));
|
||||||
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1));
|
|
||||||
|
setObjectName(QString("LineEdit"));
|
||||||
|
setStyleSheet(QString("LineEdit { padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1));
|
||||||
QSize msz = minimumSizeHint();
|
QSize msz = minimumSizeHint();
|
||||||
setMinimumSize(qMax(msz.width(), mClearButton->sizeHint().height() + frameWidth * 2 + 2),
|
setMinimumSize(qMax(msz.width(), mClearButton->sizeHint().height() + frameWidth * 2 + 2),
|
||||||
qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2));
|
qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2));
|
||||||
|
@ -29,9 +32,7 @@ void LineEdit::resizeEvent(QResizeEvent *)
|
||||||
(rect().bottom() + 1 - sz.height())/2);
|
(rect().bottom() + 1 - sz.height())/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEdit::updateCloseButton(const QString& text)
|
void LineEdit::updateClearButton(const QString& text)
|
||||||
{
|
{
|
||||||
mClearButton->setVisible(!text.isEmpty());
|
mClearButton->setVisible(!text.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ protected:
|
||||||
void resizeEvent(QResizeEvent *);
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateCloseButton(const QString &text);
|
void updateClearButton(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QToolButton *mClearButton;
|
QToolButton *mClearButton;
|
||||||
|
|
|
@ -1,45 +1,94 @@
|
||||||
#include <QRegExpValidator>
|
#include <QRegExpValidator>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#include "profilescombobox.hpp"
|
#include "profilescombobox.hpp"
|
||||||
|
#include "comboboxlineedit.hpp"
|
||||||
|
|
||||||
ProfilesComboBox::ProfilesComboBox(QWidget *parent) :
|
ProfilesComboBox::ProfilesComboBox(QWidget *parent) :
|
||||||
QComboBox(parent)
|
QComboBox(parent)
|
||||||
{
|
{
|
||||||
mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
||||||
|
setEditEnabled(true);
|
||||||
setEditable(true);
|
|
||||||
setValidator(mValidator);
|
setValidator(mValidator);
|
||||||
setCompleter(0);
|
setCompleter(0);
|
||||||
|
|
||||||
connect(this, SIGNAL(currentIndexChanged(int)), this,
|
connect(this, SIGNAL(currentIndexChanged(int)), this,
|
||||||
SLOT(slotIndexChanged(int)));
|
SLOT(slotIndexChanged(int)));
|
||||||
connect(lineEdit(), SIGNAL(returnPressed()), this,
|
|
||||||
SLOT(slotReturnPressed()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfilesComboBox::setEditEnabled(bool editable)
|
void ProfilesComboBox::setEditEnabled(bool editable)
|
||||||
{
|
{
|
||||||
if (!editable)
|
qDebug() << "called";
|
||||||
|
if (isEditable() == editable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!editable) {
|
||||||
|
disconnect(lineEdit(), SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
|
||||||
|
disconnect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
|
||||||
return setEditable(false);
|
return setEditable(false);
|
||||||
|
}
|
||||||
|
|
||||||
// Reset the completer and validator
|
// Reset the completer and validator
|
||||||
setEditable(true);
|
setEditable(true);
|
||||||
setValidator(mValidator);
|
setValidator(mValidator);
|
||||||
|
|
||||||
|
ComboBoxLineEdit *edit = new ComboBoxLineEdit(this);
|
||||||
|
setLineEdit(edit);
|
||||||
setCompleter(0);
|
setCompleter(0);
|
||||||
|
|
||||||
|
connect(lineEdit(), SIGNAL(editingFinished()), this,
|
||||||
|
SLOT(slotEditingFinished()));
|
||||||
|
|
||||||
|
connect(lineEdit(), SIGNAL(textChanged(QString)), this,
|
||||||
|
SLOT(slotTextChanged(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfilesComboBox::slotReturnPressed()
|
void ProfilesComboBox::slotTextChanged(const QString &text)
|
||||||
{
|
{
|
||||||
|
QString previous = itemText(currentIndex());
|
||||||
|
// lineEdit()->setPalette(QApplication::palette());
|
||||||
|
|
||||||
|
if (text.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (text == previous)
|
||||||
|
return;
|
||||||
|
|
||||||
|
qDebug() << "textChanged";
|
||||||
|
if (findText(text) != -1) {
|
||||||
|
QPalette *palette = new QPalette();
|
||||||
|
palette->setColor(QPalette::Text,Qt::red);
|
||||||
|
lineEdit()->setPalette(*palette);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProfilesComboBox::slotEditingFinished()
|
||||||
|
{
|
||||||
|
qDebug() << "returnpressed";
|
||||||
QString current = currentText();
|
QString current = currentText();
|
||||||
QString previous = itemText(currentIndex());
|
QString previous = itemText(currentIndex());
|
||||||
|
|
||||||
|
if (current.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (current == previous)
|
||||||
|
return;
|
||||||
|
|
||||||
if (findText(current) != -1)
|
if (findText(current) != -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setItemText(currentIndex(), current);
|
|
||||||
emit(profileRenamed(previous, current));
|
if (currentIndex() == -1) {
|
||||||
|
addItem(currentText());
|
||||||
|
} else {
|
||||||
|
setItemText(currentIndex(), current);
|
||||||
|
emit(profileRenamed(previous, current));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfilesComboBox::slotIndexChanged(int index)
|
void ProfilesComboBox::slotIndexChanged(int index)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
class QRegExpValidator;
|
class QRegExpValidator;
|
||||||
|
|
||||||
class ProfilesComboBox : public QComboBox
|
class ProfilesComboBox : public QComboBox
|
||||||
|
@ -19,8 +18,9 @@ signals:
|
||||||
void profileRenamed(const QString &oldName, const QString &newName);
|
void profileRenamed(const QString &oldName, const QString &newName);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotReturnPressed();
|
void slotEditingFinished();
|
||||||
void slotIndexChanged(int index);
|
void slotIndexChanged(int index);
|
||||||
|
void slotTextChanged(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mOldProfile;
|
QString mOldProfile;
|
||||||
|
|
Loading…
Reference in a new issue