diff options
| -rw-r--r-- | src/settings.cpp | 439 | ||||
| -rw-r--r-- | src/settings.h | 85 | ||||
| -rw-r--r-- | src/settingsdialog.ui | 80 |
3 files changed, 406 insertions, 198 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index 88d97006..98e367fe 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -36,6 +36,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QMessageBox> #include <QDesktopServices> +#include <memory> + using namespace MOBase; using namespace MOShared; @@ -140,7 +142,7 @@ void Settings::registerPlugin(IPlugin *plugin) } } -QString Settings::obfuscate(const QString &password) const +QString Settings::obfuscate(const QString &password) { QByteArray temp = password.toUtf8(); @@ -151,7 +153,7 @@ QString Settings::obfuscate(const QString &password) const return buffer.toBase64(); } -QString Settings::deObfuscate(const QString &password) const +QString Settings::deObfuscate(const QString &password) { QByteArray temp(QByteArray::fromBase64(password.toUtf8())); @@ -539,30 +541,13 @@ void Settings::query(QWidget *parent) connect(&dialog, SIGNAL(resetDialogs()), this, SLOT(resetDialogs())); - // General Page - QComboBox *languageBox = dialog.findChild<QComboBox*>("languageBox"); - QComboBox *styleBox = dialog.findChild<QComboBox*>("styleBox"); - QComboBox *logLevelBox = dialog.findChild<QComboBox*>("logLevelBox"); - QCheckBox *compactBox = dialog.findChild<QCheckBox*>("compactBox"); - QCheckBox *showMetaBox = dialog.findChild<QCheckBox*>("showMetaBox"); - - QLineEdit *downloadDirEdit = dialog.findChild<QLineEdit*>("downloadDirEdit"); - QLineEdit *modDirEdit = dialog.findChild<QLineEdit*>("modDirEdit"); - QLineEdit *cacheDirEdit = dialog.findChild<QLineEdit*>("cacheDirEdit"); - - // nexus page - QCheckBox *loginCheckBox = dialog.findChild<QCheckBox*>("loginCheckBox"); - QLineEdit *usernameEdit = dialog.findChild<QLineEdit*>("usernameEdit"); - QLineEdit *passwordEdit = dialog.findChild<QLineEdit*>("passwordEdit"); - QCheckBox *offlineBox = dialog.findChild<QCheckBox*>("offlineBox"); - QCheckBox *proxyBox = dialog.findChild<QCheckBox*>("proxyBox"); - - QListWidget *knownServersList = dialog.findChild<QListWidget*>("knownServersList"); - QListWidget *preferredServersList = dialog.findChild<QListWidget*>("preferredServersList"); - - // plugis page - QListWidget *pluginsList = dialog.findChild<QListWidget*>("pluginsList"); - QListWidget *pluginBlacklistList = dialog.findChild<QListWidget*>("pluginBlacklist"); + std::vector<std::unique_ptr<SettingsTab>> tabs; + //Don't you love C++? + //tabs.push_back(new GeneralTab(this, dialog)); + tabs.push_back(std::unique_ptr<SettingsTab>(new GeneralTab(this, dialog))); + tabs.push_back(std::unique_ptr<SettingsTab>(new NexusTab(this, dialog))); + tabs.push_back(std::unique_ptr<SettingsTab>(new SteamTab(this, dialog))); + tabs.push_back(std::unique_ptr<SettingsTab>(new PluginsTab(this, dialog))); // workarounds page QCheckBox *forceEnableBox = dialog.findChild<QCheckBox*>("forceEnableBox"); @@ -571,11 +556,6 @@ void Settings::query(QWidget *parent) QLineEdit *nmmVersionEdit = dialog.findChild<QLineEdit*>("nmmVersionEdit"); QCheckBox *hideUncheckedBox = dialog.findChild<QCheckBox*>("hideUncheckedBox"); QCheckBox *displayForeignBox = dialog.findChild<QCheckBox*>("displayForeignBox"); - - // steam login page - QLineEdit *steamUserEdit = dialog.findChild<QLineEdit*>("steamUserEdit"); - QLineEdit *steamPassEdit = dialog.findChild<QLineEdit*>("steamPassEdit"); - // // set up current settings // @@ -605,75 +585,174 @@ void Settings::query(QWidget *parent) mechanismBox->setCurrentIndex(index); - { - addLanguages(languageBox); - QString languageCode = language(); - int currentID = languageBox->findData(languageCode); - // I made a mess. :( Most languages are stored with only the iso country code (2 characters like "de") but chinese - // with the exact language variant (zh_TW) so I have to search for both variants - if (currentID == -1) { - currentID = languageBox->findData(languageCode.mid(0, 2)); + hideUncheckedBox->setChecked(hideUncheckedPlugins()); + displayForeignBox->setChecked(displayForeign()); + forceEnableBox->setChecked(forceEnableCoreFiles()); + + appIDEdit->setText(getSteamAppID()); + nmmVersionEdit->setText(getNMMVersion()); + + if (dialog.exec() == QDialog::Accepted) { + for (std::unique_ptr<SettingsTab> const &tab: tabs) { + tab->update(); } - if (currentID != -1) { - languageBox->setCurrentIndex(currentID); + // + // transfer modified settings to configuration file + // + + m_Settings.setValue("Settings/hide_unchecked_plugins", hideUncheckedBox->checkState() ? true : false); + m_Settings.setValue("Settings/force_enable_core_files", forceEnableBox->checkState() ? true : false); + m_Settings.setValue("Settings/load_mechanism", mechanismBox->itemData(mechanismBox->currentIndex()).toInt()); + + if (appIDEdit->text() != m_GamePlugin->steamAPPId()) { + m_Settings.setValue("Settings/app_id", appIDEdit->text()); + } else { + m_Settings.remove("Settings/app_id"); } + m_Settings.setValue("Settings/display_foreign", displayForeignBox->isChecked()); + + m_Settings.setValue("Settings/nmm_version", nmmVersionEdit->text()); + } +} +Settings::SettingsTab::SettingsTab(Settings *m_parent, SettingsDialog &m_dialog) : + m_parent(m_parent), + m_Settings(m_parent->m_Settings), + m_dialog(m_dialog) +{ +} + +Settings::SettingsTab::~SettingsTab() +{} + +Settings::GeneralTab::GeneralTab(Settings *m_parent, SettingsDialog &m_dialog) : + Settings::SettingsTab(m_parent, m_dialog), + m_languageBox(m_dialog.findChild<QComboBox*>("languageBox")), + m_styleBox(m_dialog.findChild<QComboBox*>("styleBox")), + m_logLevelBox(m_dialog.findChild<QComboBox*>("logLevelBox")), + m_downloadDirEdit(m_dialog.findChild<QLineEdit*>("downloadDirEdit")), + m_modDirEdit(m_dialog.findChild<QLineEdit*>("modDirEdit")), + m_cacheDirEdit(m_dialog.findChild<QLineEdit*>("cacheDirEdit")), + m_compactBox(m_dialog.findChild<QCheckBox*>("compactBox")), + m_showMetaBox(m_dialog.findChild<QCheckBox*>("showMetaBox")) { - addStyles(styleBox); - int currentID = styleBox->findData(m_Settings.value("Settings/style", "").toString()); - if (currentID != -1) { - styleBox->setCurrentIndex(currentID); + //FIXME I think 'addLanguages' lives in here not in parent + m_parent->addLanguages(m_languageBox); + { + QString languageCode = m_parent->language(); + int currentID = m_languageBox->findData(languageCode); + // I made a mess. :( Most languages are stored with only the iso country code (2 characters like "de") but chinese + // with the exact language variant (zh_TW) so I have to search for both variants + if (currentID == -1) { + currentID = m_languageBox->findData(languageCode.mid(0, 2)); + } + if (currentID != -1) { + m_languageBox->setCurrentIndex(currentID); + } } - } - compactBox->setChecked(compactDownloads()); - showMetaBox->setChecked(metaDownloads()); + //FIXME I think addStyles lives in here not in parent + m_parent->addStyles(m_styleBox); + { + int currentID = m_styleBox->findData(m_Settings.value("Settings/style", "").toString()); + if (currentID != -1) { + m_styleBox->setCurrentIndex(currentID); + } + } - hideUncheckedBox->setChecked(hideUncheckedPlugins()); - displayForeignBox->setChecked(displayForeign()); - forceEnableBox->setChecked(forceEnableCoreFiles()); + m_logLevelBox->setCurrentIndex(m_parent->logLevel()); + m_downloadDirEdit->setText(m_parent->getDownloadDirectory()); + m_modDirEdit->setText(m_parent->getModDirectory()); + m_cacheDirEdit->setText(m_parent->getCacheDirectory()); + m_compactBox->setChecked(m_parent->compactDownloads()); + m_showMetaBox->setChecked(m_parent->metaDownloads()); +} - appIDEdit->setText(getSteamAppID()); +void Settings::GeneralTab::update() +{ + QString oldLanguage = m_Settings.value("Settings/language", "en_US").toString(); + QString newLanguage = m_languageBox->itemData(m_languageBox->currentIndex()).toString(); + if (newLanguage != oldLanguage) { + m_Settings.setValue("Settings/language", newLanguage); + emit m_parent->languageChanged(newLanguage); + } - if (automaticLoginEnabled()) { - loginCheckBox->setChecked(true); - usernameEdit->setText(m_Settings.value("Settings/nexus_username", "").toString()); - passwordEdit->setText(deObfuscate(m_Settings.value("Settings/nexus_password", "").toString())); + QString oldStyle = m_Settings.value("Settings/style", "").toString(); + QString newStyle = m_styleBox->itemData(m_styleBox->currentIndex()).toString(); + if (oldStyle != newStyle) { + m_Settings.setValue("Settings/style", newStyle); + emit m_parent->styleChanged(newStyle); } - if (m_Settings.contains("Settings/steam_username")) { - steamUserEdit->setText(m_Settings.value("Settings/steam_username", "").toString()); - if (m_Settings.contains("Settings/steam_password")) { - steamPassEdit->setText(deObfuscate(m_Settings.value("Settings/steam_password", "").toString())); + m_Settings.setValue("Settings/log_level", m_logLevelBox->currentIndex()); + + { // advanced settings + if ((QDir::fromNativeSeparators(m_modDirEdit->text()) != QDir::fromNativeSeparators(m_parent->getModDirectory())) && + (QMessageBox::question(nullptr, tr("Confirm"), tr("Changing the mod directory affects all your profiles! " + "Mods not present (or named differently) in the new location will be disabled in all profiles. " + "There is no way to undo this unless you backed up your profiles manually. Proceed?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) { + m_modDirEdit->setText(m_parent->getModDirectory()); } - } - downloadDirEdit->setText(getDownloadDirectory()); - modDirEdit->setText(getModDirectory()); - cacheDirEdit->setText(getCacheDirectory()); - offlineBox->setChecked(offlineMode()); - proxyBox->setChecked(useProxy()); - nmmVersionEdit->setText(getNMMVersion()); - logLevelBox->setCurrentIndex(logLevel()); + if (!QDir(m_downloadDirEdit->text()).exists()) { + QDir().mkpath(m_downloadDirEdit->text()); + } + if (QFileInfo(m_downloadDirEdit->text()) != + QFileInfo(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::downloadPath()))) { + m_Settings.setValue("Settings/download_directory", QDir::toNativeSeparators(m_downloadDirEdit->text())); + } else { + m_Settings.remove("Settings/download_directory"); + } - // display plugin settings - foreach (IPlugin *plugin, m_Plugins) { - QListWidgetItem *listItem = new QListWidgetItem(plugin->name(), pluginsList); - listItem->setData(Qt::UserRole, QVariant::fromValue((void*)plugin)); - listItem->setData(Qt::UserRole + 1, m_PluginSettings[plugin->name()]); - listItem->setData(Qt::UserRole + 2, m_PluginDescriptions[plugin->name()]); - pluginsList->addItem(listItem); + if (!QDir(m_modDirEdit->text()).exists()) { + QDir().mkpath(m_modDirEdit->text()); + } + if (QFileInfo(m_modDirEdit->text()) != + QFileInfo(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::modsPath()))) { + m_Settings.setValue("Settings/mod_directory", QDir::toNativeSeparators(m_modDirEdit->text())); + } else { + m_Settings.remove("Settings/mod_directory"); + } + + if (!QDir(m_cacheDirEdit->text()).exists()) { + QDir().mkpath(m_cacheDirEdit->text()); + } + if (QFileInfo(m_cacheDirEdit->text()) != + QFileInfo(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::cachePath()))) { + m_Settings.setValue("Settings/cache_directory", QDir::toNativeSeparators(m_cacheDirEdit->text())); + } else { + m_Settings.remove("Settings/cache_directory"); + } } - // display plugin blacklist - foreach (const QString &pluginName, m_PluginBlacklist) { - pluginBlacklistList->addItem(pluginName); + m_Settings.setValue("Settings/compact_downloads", m_compactBox->isChecked()); + m_Settings.setValue("Settings/meta_downloads", m_showMetaBox->isChecked()); +} + +Settings::NexusTab::NexusTab(Settings *m_parent, SettingsDialog &m_dialog) : + Settings::SettingsTab(m_parent, m_dialog), + m_loginCheckBox(m_dialog.findChild<QCheckBox*>("loginCheckBox")), + m_usernameEdit(m_dialog.findChild<QLineEdit*>("usernameEdit")), + m_passwordEdit(m_dialog.findChild<QLineEdit*>("passwordEdit")), + m_offlineBox(m_dialog.findChild<QCheckBox*>("offlineBox")), + m_proxyBox(m_dialog.findChild<QCheckBox*>("proxyBox")), + m_knownServersList(m_dialog.findChild<QListWidget*>("knownServersList")), + m_preferredServersList(m_dialog.findChild<QListWidget*>("preferredServersList")) +{ + if (m_parent->automaticLoginEnabled()) { + m_loginCheckBox->setChecked(true); + m_usernameEdit->setText(m_Settings.value("Settings/nexus_username", "").toString()); + m_passwordEdit->setText(deObfuscate(m_Settings.value("Settings/nexus_password", "").toString())); } + m_offlineBox->setChecked(m_parent->offlineMode()); + m_proxyBox->setChecked(m_parent->useProxy()); + // display server preferences m_Settings.beginGroup("Servers"); - foreach (const QString &key, m_Settings.childKeys()) { + for (const QString &key : m_Settings.childKeys()) { QVariantMap val = m_Settings.value(key).toMap(); QString type = val["premium"].toBool() ? "(premium)" : "(free)"; @@ -688,137 +767,105 @@ void Settings::query(QWidget *parent) newItem->setData(Qt::UserRole, key); newItem->setData(Qt::UserRole + 1, val["preferred"].toInt()); if (val["preferred"].toInt() > 0) { - preferredServersList->addItem(newItem); + m_preferredServersList->addItem(newItem); } else { - knownServersList->addItem(newItem); + m_knownServersList->addItem(newItem); } - preferredServersList->sortItems(Qt::DescendingOrder); + m_preferredServersList->sortItems(Qt::DescendingOrder); } m_Settings.endGroup(); +} - if (dialog.exec() == QDialog::Accepted) { - // - // transfer modified settings to configuration file - // - - m_Settings.setValue("Settings/hide_unchecked_plugins", hideUncheckedBox->checkState() ? true : false); - m_Settings.setValue("Settings/force_enable_core_files", forceEnableBox->checkState() ? true : false); - m_Settings.setValue("Settings/compact_downloads", compactBox->isChecked()); - m_Settings.setValue("Settings/meta_downloads", showMetaBox->isChecked()); - m_Settings.setValue("Settings/load_mechanism", mechanismBox->itemData(mechanismBox->currentIndex()).toInt()); - - - { // advanced settings - if ((QDir::fromNativeSeparators(modDirEdit->text()) != QDir::fromNativeSeparators(getModDirectory())) && - (QMessageBox::question(nullptr, tr("Confirm"), tr("Changing the mod directory affects all your profiles! " - "Mods not present (or named differently) in the new location will be disabled in all profiles. " - "There is no way to undo this unless you backed up your profiles manually. Proceed?"), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) { - modDirEdit->setText(getModDirectory()); - } - - if (!QDir(downloadDirEdit->text()).exists()) { - QDir().mkpath(downloadDirEdit->text()); - } - if (!QDir(cacheDirEdit->text()).exists()) { - QDir().mkpath(cacheDirEdit->text()); - } - if (!QDir(modDirEdit->text()).exists()) { - QDir().mkpath(modDirEdit->text()); - } - - if (QFileInfo(downloadDirEdit->text()) != - QFileInfo(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::downloadPath()))) { - m_Settings.setValue("Settings/download_directory", QDir::toNativeSeparators(downloadDirEdit->text())); - } else { - m_Settings.remove("Settings/download_directory"); - } - if (QFileInfo(cacheDirEdit->text()) != - QFileInfo(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::cachePath()))) { - m_Settings.setValue("Settings/cache_directory", QDir::toNativeSeparators(cacheDirEdit->text())); - } else { - m_Settings.remove("Settings/cache_directory"); - } - if (QFileInfo(modDirEdit->text()) != - QFileInfo(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::modsPath()))) { - m_Settings.setValue("Settings/mod_directory", QDir::toNativeSeparators(modDirEdit->text())); - } else { - m_Settings.remove("Settings/mod_directory"); - } - } +void Settings::NexusTab::update() +{ + if (m_loginCheckBox->isChecked()) { + m_Settings.setValue("Settings/nexus_login", true); + m_Settings.setValue("Settings/nexus_username", m_usernameEdit->text()); + m_Settings.setValue("Settings/nexus_password", obfuscate(m_passwordEdit->text())); + } else { + m_Settings.setValue("Settings/nexus_login", false); + m_Settings.remove("Settings/nexus_username"); + m_Settings.remove("Settings/nexus_password"); + } + m_Settings.setValue("Settings/offline_mode", m_offlineBox->isChecked()); + m_Settings.setValue("Settings/use_proxy", m_proxyBox->isChecked()); + // store server preference + m_Settings.beginGroup("Servers"); + for (int i = 0; i < m_knownServersList->count(); ++i) { + QString key = m_knownServersList->item(i)->data(Qt::UserRole).toString(); + QVariantMap val = m_Settings.value(key).toMap(); + val["preferred"] = 0; + m_Settings.setValue(key, val); + } + int count = m_preferredServersList->count(); + for (int i = 0; i < count; ++i) { + QString key = m_preferredServersList->item(i)->data(Qt::UserRole).toString(); + QVariantMap val = m_Settings.value(key).toMap(); + val["preferred"] = count - i; + m_Settings.setValue(key, val); + } + m_Settings.endGroup(); +} - QString oldLanguage = m_Settings.value("Settings/language", "en_US").toString(); - QString newLanguage = languageBox->itemData(languageBox->currentIndex()).toString(); - if (newLanguage != oldLanguage) { - m_Settings.setValue("Settings/language", newLanguage); - emit languageChanged(newLanguage); - } - QString oldStyle = m_Settings.value("Settings/style", "").toString(); - QString newStyle = styleBox->itemData(styleBox->currentIndex()).toString(); - if (oldStyle != newStyle) { - m_Settings.setValue("Settings/style", newStyle); - emit styleChanged(newStyle); +Settings::SteamTab::SteamTab(Settings *m_parent, SettingsDialog &m_dialog) : + Settings::SettingsTab(m_parent, m_dialog), + m_steamUserEdit(m_dialog.findChild<QLineEdit*>("steamUserEdit")), + m_steamPassEdit(m_dialog.findChild<QLineEdit*>("steamPassEdit")) +{ + if (m_Settings.contains("Settings/steam_username")) { + m_steamUserEdit->setText(m_Settings.value("Settings/steam_username", "").toString()); + if (m_Settings.contains("Settings/steam_password")) { + m_steamPassEdit->setText(deObfuscate(m_Settings.value("Settings/steam_password", "").toString())); } + } +} - m_Settings.setValue("Settings/log_level", logLevelBox->currentIndex()); - - if (appIDEdit->text() != m_GamePlugin->steamAPPId()) { - m_Settings.setValue("Settings/app_id", appIDEdit->text()); - } else { - m_Settings.remove("Settings/app_id"); - } - if (loginCheckBox->isChecked()) { - m_Settings.setValue("Settings/nexus_login", true); - m_Settings.setValue("Settings/nexus_username", usernameEdit->text()); - m_Settings.setValue("Settings/nexus_password", obfuscate(passwordEdit->text())); - } else { - m_Settings.setValue("Settings/nexus_login", false); - m_Settings.remove("Settings/nexus_username"); - m_Settings.remove("Settings/nexus_password"); - } - setSteamLogin(steamUserEdit->text(), steamPassEdit->text()); - m_Settings.setValue("Settings/offline_mode", offlineBox->isChecked()); - m_Settings.setValue("Settings/use_proxy", proxyBox->isChecked()); - m_Settings.setValue("Settings/display_foreign", displayForeignBox->isChecked()); +void Settings::SteamTab::update() +{ + //FIXME this should be inlined here? + m_parent->setSteamLogin(m_steamUserEdit->text(), m_steamPassEdit->text()); +} - m_Settings.setValue("Settings/nmm_version", nmmVersionEdit->text()); +Settings::PluginsTab::PluginsTab(Settings *m_parent, SettingsDialog &m_dialog) : + Settings::SettingsTab(m_parent, m_dialog), + m_pluginsList(m_dialog.findChild<QListWidget*>("pluginsList")), + m_pluginBlacklistList(m_dialog.findChild<QListWidget*>("pluginBlacklist")) +{ + // display plugin settings + for (IPlugin *plugin : m_parent->m_Plugins) { + QListWidgetItem *listItem = new QListWidgetItem(plugin->name(), m_pluginsList); + listItem->setData(Qt::UserRole, QVariant::fromValue((void*)plugin)); + listItem->setData(Qt::UserRole + 1, m_parent->m_PluginSettings[plugin->name()]); + listItem->setData(Qt::UserRole + 2, m_parent->m_PluginDescriptions[plugin->name()]); + m_pluginsList->addItem(listItem); + } - // transfer plugin settings to in-memory structure - for (int i = 0; i < pluginsList->count(); ++i) { - QListWidgetItem *item = pluginsList->item(i); - m_PluginSettings[item->text()] = item->data(Qt::UserRole + 1).toMap(); - } - // store plugin settings on disc - for (auto iterPlugins = m_PluginSettings.begin(); iterPlugins != m_PluginSettings.end(); ++iterPlugins) { - for (auto iterSettings = iterPlugins->begin(); iterSettings != iterPlugins->end(); ++iterSettings) { - m_Settings.setValue("Plugins/" + iterPlugins.key() + "/" + iterSettings.key(), iterSettings.value()); - } - } + // display plugin blacklist + for (const QString &pluginName : m_parent->m_PluginBlacklist) { + m_pluginBlacklistList->addItem(pluginName); + } +} - // store plugin blacklist - m_PluginBlacklist.clear(); - foreach (QListWidgetItem *item, pluginBlacklistList->findItems("*", Qt::MatchWildcard)) { - m_PluginBlacklist.insert(item->text()); +void Settings::PluginsTab::update() +{ + // transfer plugin settings to in-memory structure + for (int i = 0; i < m_pluginsList->count(); ++i) { + QListWidgetItem *item = m_pluginsList->item(i); + m_parent->m_PluginSettings[item->text()] = item->data(Qt::UserRole + 1).toMap(); + } + // store plugin settings on disc + for (auto iterPlugins = m_parent->m_PluginSettings.begin(); iterPlugins != m_parent->m_PluginSettings.end(); ++iterPlugins) { + for (auto iterSettings = iterPlugins->begin(); iterSettings != iterPlugins->end(); ++iterSettings) { + m_Settings.setValue("Plugins/" + iterPlugins.key() + "/" + iterSettings.key(), iterSettings.value()); } - writePluginBlacklist(); + } - // store server preference - m_Settings.beginGroup("Servers"); - for (int i = 0; i < knownServersList->count(); ++i) { - QString key = knownServersList->item(i)->data(Qt::UserRole).toString(); - QVariantMap val = m_Settings.value(key).toMap(); - val["preferred"] = 0; - m_Settings.setValue(key, val); - } - int count = preferredServersList->count(); - for (int i = 0; i < count; ++i) { - QString key = preferredServersList->item(i)->data(Qt::UserRole).toString(); - QVariantMap val = m_Settings.value(key).toMap(); - val["preferred"] = count - i; - m_Settings.setValue(key, val); - } - m_Settings.endGroup(); + // store plugin blacklist + m_parent->m_PluginBlacklist.clear(); + foreach (QListWidgetItem *item, m_pluginBlacklistList->findItems("*", Qt::MatchWildcard)) { + m_parent->m_PluginBlacklist.insert(item->text()); } + m_parent->writePluginBlacklist(); } diff --git a/src/settings.h b/src/settings.h index 7e784a99..bc21ca5b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -33,6 +33,8 @@ namespace MOBase { class IPluginGame; } +class SettingsDialog; +class QCheckBox; /** * manages the settings for Mod Organizer. The settings are not cached @@ -301,8 +303,8 @@ public slots: private: - QString obfuscate(const QString &password) const; - QString deObfuscate(const QString &password) const; + static QString obfuscate(const QString &password); + static QString deObfuscate(const QString &password); void addLanguages(QComboBox *languageBox); void addStyles(QComboBox *styleBox); @@ -310,6 +312,85 @@ private: void writePluginBlacklist(); QString getConfigurablePath(const QString &key, const QString &def) const; + class SettingsTab + { + public: + SettingsTab(Settings *m_parent, SettingsDialog &m_dialog); + virtual ~SettingsTab(); + + virtual void update() = 0; + + protected: + Settings *m_parent; + QSettings &m_Settings; + SettingsDialog &m_dialog; + + }; + + /** Display/store the configuration in the 'general' tab of the settings dialogue */ + class GeneralTab : SettingsTab + { + public: + GeneralTab(Settings *m_parent, SettingsDialog &m_dialog); + + void update(); + + private: + QComboBox *m_languageBox; + QComboBox *m_styleBox; + QComboBox *m_logLevelBox; + QLineEdit *m_downloadDirEdit; + QLineEdit *m_modDirEdit; + QLineEdit *m_cacheDirEdit; + QCheckBox *m_compactBox; + QCheckBox *m_showMetaBox; + }; + + /** Display/store the configuration in the 'nexus' tab of the settings dialogue */ + class NexusTab : SettingsTab + { + public: + NexusTab(Settings *m_parent, SettingsDialog &m_dialog); + + void update(); + + private: + QCheckBox *m_loginCheckBox; + QLineEdit *m_usernameEdit; + QLineEdit *m_passwordEdit; + QCheckBox *m_offlineBox; + QCheckBox *m_proxyBox; + QListWidget *m_knownServersList; + QListWidget *m_preferredServersList; + }; + + /** Display/store the configuration in the 'steam' tab of the settings dialogue */ + class SteamTab : SettingsTab + { + public: + SteamTab(Settings *m_parent, SettingsDialog &m_dialog); + + void update(); + + private: + QLineEdit *m_steamUserEdit; + QLineEdit *m_steamPassEdit; + }; + + /** Display/store the configuration in the 'plugins' tab of the settings dialogue */ + class PluginsTab : SettingsTab + { + public: + PluginsTab(Settings *m_parent, SettingsDialog &m_dialog); + + void update(); + + private: + QListWidget *m_pluginsList; + QListWidget *m_pluginBlacklistList; + }; + + private slots: void resetDialogs(); diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index b88885dc..a7543a00 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -884,6 +884,86 @@ For the other games this is not a sufficient replacement for AI!</string> </item>
</layout>
</widget>
+ <widget class="QWidget" name="overwriteTab">
+ <attribute name="title">
+ <string>Overwrite</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="4" column="0">
+ <widget class="QCheckBox" name="ignoreLogFileBox">
+ <property name="statusTip">
+ <string/>
+ </property>
+ <property name="text">
+ <string>Ignore .log files (implies ignore empty directories)</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <spacer name="verticalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="0">
+ <spacer name="verticalSpacer_8">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="5" column="0">
+ <spacer name="verticalSpacer_9">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_23">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_22">
+ <property name="text">
+ <string>The tab controls various customisations of the overwrite directory</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QCheckBox" name="ignoreEmptyDirBox">
+ <property name="toolTip">
+ <string/>
+ </property>
+ <property name="text">
+ <string>Ignore empty directories</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
</widget>
</item>
<item>
|
