mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
Fixed config loading problem
This commit is contained in:
parent
64d636574e
commit
e4129ce26e
1 changed files with 63 additions and 63 deletions
|
@ -85,9 +85,6 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
||||||
pageLayout->addLayout(bottomLayout);
|
pageLayout->addLayout(bottomLayout);
|
||||||
pageLayout->addItem(vSpacer3);
|
pageLayout->addItem(vSpacer3);
|
||||||
|
|
||||||
setupDataFiles();
|
|
||||||
setupConfig();
|
|
||||||
|
|
||||||
connect(mMastersWidget->selectionModel(),
|
connect(mMastersWidget->selectionModel(),
|
||||||
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
|
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
|
||||||
this, SLOT(masterSelectionChanged(const QItemSelection&, const QItemSelection&)));
|
this, SLOT(masterSelectionChanged(const QItemSelection&, const QItemSelection&)));
|
||||||
|
@ -98,6 +95,9 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
||||||
//connect(mProfileComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(profileChanged(const QString&)));
|
//connect(mProfileComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(profileChanged(const QString&)));
|
||||||
connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&)));
|
connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&)));
|
||||||
|
|
||||||
|
|
||||||
|
setupDataFiles();
|
||||||
|
setupConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::setupDataFiles()
|
void DataFilesPage::setupDataFiles()
|
||||||
|
@ -174,7 +174,6 @@ void DataFilesPage::setupDataFiles()
|
||||||
|
|
||||||
QList<QStandardItem*> masterList = mDataFilesModel->findItems(availableMasters.join(","));
|
QList<QStandardItem*> masterList = mDataFilesModel->findItems(availableMasters.join(","));
|
||||||
|
|
||||||
|
|
||||||
if (masterList.isEmpty()) { // Masters node not yet in the mDataFilesModel
|
if (masterList.isEmpty()) { // Masters node not yet in the mDataFilesModel
|
||||||
parent->appendRow(child);
|
parent->appendRow(child);
|
||||||
mDataFilesModel->appendRow(parent);
|
mDataFilesModel->appendRow(parent);
|
||||||
|
@ -187,8 +186,48 @@ void DataFilesPage::setupDataFiles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataFilesPage::setupConfig()
|
||||||
|
{
|
||||||
|
QFile config("launcher.cfg");
|
||||||
|
|
||||||
|
if (config.exists())
|
||||||
|
{
|
||||||
|
qDebug() << "Using config file from current directory";
|
||||||
|
mLauncherConfig = new QSettings("launcher.cfg", QSettings::IniFormat);
|
||||||
|
} else {
|
||||||
|
QString path = QString::fromStdString(OMW::Path::getPath(OMW::Path::GLOBAL_CFG_PATH,
|
||||||
|
"openmw",
|
||||||
|
"launcher.cfg"));
|
||||||
|
qDebug() << "Using global config file from " << path;
|
||||||
|
mLauncherConfig = new QSettings(path, QSettings::IniFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.close();
|
||||||
|
|
||||||
|
mLauncherConfig->beginGroup("Profiles");
|
||||||
|
QStringList profiles = mLauncherConfig->childGroups();
|
||||||
|
|
||||||
|
if (profiles.isEmpty()) {
|
||||||
|
// Add a default profile
|
||||||
|
profiles.append("Default");
|
||||||
|
}
|
||||||
|
|
||||||
|
mProfilesModel->setStringList(profiles);
|
||||||
|
|
||||||
|
QString currentProfile = mLauncherConfig->value("CurrentProfile").toString();
|
||||||
|
if (currentProfile.isEmpty()) {
|
||||||
|
currentProfile = "Default";
|
||||||
|
}
|
||||||
|
mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile));
|
||||||
|
|
||||||
|
mLauncherConfig->endGroup();
|
||||||
|
|
||||||
|
readConfig();
|
||||||
|
}
|
||||||
|
|
||||||
void DataFilesPage::masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
void DataFilesPage::masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
{
|
{
|
||||||
|
// TODO: Use mMasterWidget->selectedItems
|
||||||
if (mMastersWidget->selectionModel()->hasSelection()) {
|
if (mMastersWidget->selectionModel()->hasSelection()) {
|
||||||
const QModelIndexList selectedIndexes = mMastersWidget->selectionModel()->selectedIndexes();
|
const QModelIndexList selectedIndexes = mMastersWidget->selectionModel()->selectedIndexes();
|
||||||
|
|
||||||
|
@ -246,8 +285,6 @@ void DataFilesPage::masterSelectionChanged(const QItemSelection &selected, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readConfig();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::addPlugins(const QModelIndex &index)
|
void DataFilesPage::addPlugins(const QModelIndex &index)
|
||||||
|
@ -347,11 +384,9 @@ void DataFilesPage::uncheckPlugins()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DataFilesPage::resizeRows()
|
void DataFilesPage::resizeRows()
|
||||||
{
|
{
|
||||||
// Contents changed
|
// Contents changed
|
||||||
qDebug() << "test";
|
|
||||||
mPluginsTable->resizeRowsToContents();
|
mPluginsTable->resizeRowsToContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,51 +406,16 @@ void DataFilesPage::profileChanged(const QString &previous, const QString &curre
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesPage::setupConfig()
|
|
||||||
{
|
|
||||||
QFile config("launcher.cfg");
|
|
||||||
|
|
||||||
if (config.exists())
|
|
||||||
{
|
|
||||||
qDebug() << "Using config file from current directory";
|
|
||||||
mLauncherConfig = new QSettings("launcher.cfg", QSettings::IniFormat);
|
|
||||||
} else {
|
|
||||||
QString path = QString::fromStdString(OMW::Path::getPath(OMW::Path::GLOBAL_CFG_PATH,
|
|
||||||
"openmw",
|
|
||||||
"launcher.cfg"));
|
|
||||||
qDebug() << "Using global config file from " << path;
|
|
||||||
mLauncherConfig = new QSettings(path, QSettings::IniFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
config.close();
|
|
||||||
|
|
||||||
|
|
||||||
mLauncherConfig->beginGroup("Profiles");
|
|
||||||
QStringList profiles = mLauncherConfig->childGroups();
|
|
||||||
|
|
||||||
if (profiles.isEmpty()) {
|
|
||||||
// Add a default profile
|
|
||||||
profiles.append("Default");
|
|
||||||
}
|
|
||||||
|
|
||||||
mProfilesModel->setStringList(profiles);
|
|
||||||
|
|
||||||
QString currentProfile = mLauncherConfig->value("CurrentProfile").toString();
|
|
||||||
if (currentProfile.isEmpty()) {
|
|
||||||
currentProfile = "Default";
|
|
||||||
}
|
|
||||||
mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile));
|
|
||||||
|
|
||||||
mLauncherConfig->endGroup();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DataFilesPage::readConfig()
|
void DataFilesPage::readConfig()
|
||||||
{
|
{
|
||||||
QString profile = mProfilesComboBox->currentText();
|
QString profile = mProfilesComboBox->currentText();
|
||||||
qDebug() << "read from: " << profile;
|
qDebug() << "read from: " << profile;
|
||||||
|
|
||||||
|
// Make sure we have no groups open
|
||||||
|
while (!mLauncherConfig->group().isEmpty()) {
|
||||||
|
mLauncherConfig->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
mLauncherConfig->beginGroup("Profiles");
|
mLauncherConfig->beginGroup("Profiles");
|
||||||
mLauncherConfig->beginGroup(profile);
|
mLauncherConfig->beginGroup(profile);
|
||||||
|
|
||||||
|
@ -423,20 +423,28 @@ void DataFilesPage::readConfig()
|
||||||
qDebug() << childKeys << "SJILDKIEJS";
|
qDebug() << childKeys << "SJILDKIEJS";
|
||||||
|
|
||||||
foreach (const QString &key, childKeys) {
|
foreach (const QString &key, childKeys) {
|
||||||
qDebug() << "Key is " << key << mLauncherConfig->value(key).toString();
|
const QString keyValue = mLauncherConfig->value(key).toString();
|
||||||
if (key.startsWith("Plugin")) {
|
|
||||||
QList<QStandardItem *> itemList = mPluginsModel->findItems(mLauncherConfig->value(key).toString());
|
|
||||||
|
|
||||||
if (!itemList.isEmpty())
|
if (key.startsWith("Plugin")) {
|
||||||
|
QList<QStandardItem *> pluginList = mPluginsModel->findItems(keyValue);
|
||||||
|
|
||||||
|
if (!pluginList.isEmpty())
|
||||||
{
|
{
|
||||||
foreach (const QStandardItem *currentItem, itemList) {
|
foreach (const QStandardItem *currentPlugin, pluginList) {
|
||||||
mPluginsModel->setData(currentItem->index(), Qt::Checked, Qt::CheckStateRole);
|
mPluginsModel->setData(currentPlugin->index(), Qt::Checked, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.startsWith("Master")) {
|
if (key.startsWith("Master")) {
|
||||||
qDebug() << mLauncherConfig->value(key).toString();
|
qDebug() << "Read master: " << keyValue;
|
||||||
|
QList<QTableWidgetItem*> masterList = mMastersWidget->findItems(keyValue, Qt::MatchExactly);
|
||||||
|
|
||||||
|
if (!masterList.isEmpty()) {
|
||||||
|
foreach (QTableWidgetItem *currentMaster, masterList) {
|
||||||
|
mMastersWidget->selectionModel()->select(mMastersWidget->model()->index(currentMaster->row(), 0), QItemSelectionModel::Select);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,14 +473,6 @@ void DataFilesPage::writeConfig(QString profile)
|
||||||
// First write the masters to the config
|
// First write the masters to the config
|
||||||
QList<QTableWidgetItem *> selectedMasters = mMastersWidget->selectedItems();
|
QList<QTableWidgetItem *> selectedMasters = mMastersWidget->selectedItems();
|
||||||
|
|
||||||
/*mLauncherConfig->beginWriteArray("Masters");
|
|
||||||
for (int i = 0; i < selectedMasters.size(); ++i) {
|
|
||||||
mLauncherConfig->setArrayIndex(i);
|
|
||||||
const QTableWidgetItem *item = selectedMasters.at(i);
|
|
||||||
mLauncherConfig->setValue("Master", item->data(Qt::DisplayRole).toString());
|
|
||||||
}
|
|
||||||
mLauncherConfig->endArray();
|
|
||||||
*/
|
|
||||||
for (int i = 0; i < selectedMasters.size(); ++i) {
|
for (int i = 0; i < selectedMasters.size(); ++i) {
|
||||||
const QTableWidgetItem *item = selectedMasters.at(i);
|
const QTableWidgetItem *item = selectedMasters.at(i);
|
||||||
mLauncherConfig->setValue(QString("Master%0").arg(i), item->data(Qt::DisplayRole).toString());
|
mLauncherConfig->setValue(QString("Master%0").arg(i), item->data(Qt::DisplayRole).toString());
|
||||||
|
|
Loading…
Reference in a new issue