From 755c99df3ccd14db12a550f5e38e429f48909935 Mon Sep 17 00:00:00 2001 From: pvdk Date: Tue, 18 Feb 2014 12:44:27 +0100 Subject: [PATCH] Some minor fixes --- apps/wizard/componentselectionpage.cpp | 14 +++++------ apps/wizard/conclusionpage.cpp | 8 ++++++- apps/wizard/existinginstallationpage.cpp | 4 ++-- apps/wizard/inisettings.cpp | 30 ++++++++---------------- apps/wizard/installationpage.cpp | 14 +++++------ apps/wizard/installationtargetpage.cpp | 2 +- apps/wizard/methodselectionpage.cpp | 4 ++-- 7 files changed, 36 insertions(+), 40 deletions(-) diff --git a/apps/wizard/componentselectionpage.cpp b/apps/wizard/componentselectionpage.cpp index 87779e93dd..19a07438db 100644 --- a/apps/wizard/componentselectionpage.cpp +++ b/apps/wizard/componentselectionpage.cpp @@ -16,7 +16,7 @@ Wizard::ComponentSelectionPage::ComponentSelectionPage(MainWizard *wizard) : setCommitPage(true); setButtonText(QWizard::CommitButton, tr("&Install")); - registerField("installation.components", componentsList); + registerField(QLatin1String("installation.components"), componentsList); connect(componentsList, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(updateButton(QListWidgetItem *))); @@ -25,7 +25,7 @@ Wizard::ComponentSelectionPage::ComponentSelectionPage(MainWizard *wizard) : void Wizard::ComponentSelectionPage::updateButton(QListWidgetItem *item) { - if (field("installation.new").toBool() == true) + if (field(QLatin1String("installation.new")).toBool() == true) return; // Morrowind is always checked here bool unchecked = true; @@ -53,13 +53,13 @@ void Wizard::ComponentSelectionPage::initializePage() { componentsList->clear(); - QString path(field("installation.path").toString()); + QString path(field(QLatin1String("installation.path")).toString()); QListWidgetItem *morrowindItem = new QListWidgetItem(QLatin1String("Morrowind")); QListWidgetItem *tribunalItem = new QListWidgetItem(QLatin1String("Tribunal")); QListWidgetItem *bloodmoonItem = new QListWidgetItem(QLatin1String("Bloodmoon")); - if (field("installation.new").toBool() == true) + if (field(QLatin1String("installation.new")).toBool() == true) { morrowindItem->setFlags(morrowindItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); morrowindItem->setData(Qt::CheckStateRole, Qt::Checked); @@ -111,12 +111,12 @@ void Wizard::ComponentSelectionPage::initializePage() bool Wizard::ComponentSelectionPage::validatePage() { - QStringList components(field("installation.components").toStringList()); - QString path(field("installation.path").toString()); + QStringList components(field(QLatin1String("installation.components")).toStringList()); + QString path(field(QLatin1String("installation.path")).toString()); qDebug() << components << path << mWizard->mInstallations[path]; - if (field("installation.new").toBool() == false) { + if (field(QLatin1String("installation.new")).toBool() == false) { if (components.contains(QLatin1String("Tribunal")) && !components.contains(QLatin1String("Bloodmoon"))) { if (mWizard->mInstallations[path]->hasBloodmoon) diff --git a/apps/wizard/conclusionpage.cpp b/apps/wizard/conclusionpage.cpp index 61d58eaba1..d734d39ab8 100644 --- a/apps/wizard/conclusionpage.cpp +++ b/apps/wizard/conclusionpage.cpp @@ -13,9 +13,15 @@ Wizard::ConclusionPage::ConclusionPage(MainWizard *wizard) : void Wizard::ConclusionPage::initializePage() { + // Write the path to openmw.cfg + if (field(QLatin1String("installation.new")).toBool() == true) { + QString path(field(QLatin1String("installation.path")).toString()); + mWizard->addInstallation(path); + } + if (!mWizard->mError) { - if (field("installation.new").toBool() == true) + if (field(QLatin1String("installation.new")).toBool() == true) { textLabel->setText(tr("

The OpenMW Wizard successfully installed Morrowind on your computer.

\

Click Finish to close the Wizard.

")); diff --git a/apps/wizard/existinginstallationpage.cpp b/apps/wizard/existinginstallationpage.cpp index 34e771e3d7..f0f5c8573e 100644 --- a/apps/wizard/existinginstallationpage.cpp +++ b/apps/wizard/existinginstallationpage.cpp @@ -82,7 +82,7 @@ bool Wizard::ExistingInstallationPage::validatePage() // It can be missing entirely // Or failed to be detected due to the target being a symlink - QString path(field("installation.path").toString()); + QString path(field(QLatin1String("installation.path")).toString()); QFile file(mWizard->mInstallations[path]->iniPath); if (!file.exists()) { @@ -131,7 +131,7 @@ bool Wizard::ExistingInstallationPage::isComplete() const int Wizard::ExistingInstallationPage::nextId() const { - QString path(field("installation.path").toString()); + QString path(field(QLatin1String("installation.path")).toString()); if (path.isEmpty()) return MainWizard::Page_LanguageSelection; diff --git a/apps/wizard/inisettings.cpp b/apps/wizard/inisettings.cpp index f34699742b..a2c2556844 100644 --- a/apps/wizard/inisettings.cpp +++ b/apps/wizard/inisettings.cpp @@ -131,30 +131,20 @@ bool Wizard::IniSettings::writeFile(const QString &path, QTextStream &stream) int index = buffer.lastIndexOf(section); if (index != -1) { - // Append the new keys to the bottom of the section + // Look for the next section index = buffer.indexOf(QLatin1Char('['), index + 1); - if (index == -1 ) - { - // Beginning of next section not found, we are at the last section - if (buffer.lastIndexOf(QLatin1String("\n")) > (buffer.lastIndexOf(section) + section.length())) { - // There is a newline after the section - index = buffer.lastIndexOf(QLatin1String("\n")) - 1; - buffer.insert(index - 2, QString("\n%1=%2").arg(key, i.value().toString())); - mSettings.remove(i.key()); - continue; - } else { - // No newline found, or the last newline is before the last section - // Append the key to the bottom of the file - buffer.append(QString("\n%1=%2").arg(key, i.value().toString())); - mSettings.remove(i.key()); - continue; - } + if (index == -1 ) { + // We are at the last section, append it to the bottom of the file + buffer.append(QString("\n%1=%2").arg(key, i.value().toString())); + mSettings.remove(i.key()); + continue; + } else { + // Not at last section, add the key at the index + buffer.insert(index - 1, QString("\n%1=%2").arg(key, i.value().toString())); + mSettings.remove(i.key()); } - // Add the key at the index - buffer.insert(index - 1, QString("\n%1=%2").arg(key, i.value().toString())); - mSettings.remove(i.key()); } else { // Add the section to the end of the file, because it's not found buffer.append(QString("\n%1\n").arg(section)); diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index 05d1b4af84..774e02f3c5 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -20,8 +20,8 @@ Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : void Wizard::InstallationPage::initializePage() { - QString path(field("installation.path").toString()); - QStringList components(field("installation.components").toStringList()); + QString path(field(QLatin1String("installation.path")).toString()); + QStringList components(field(QLatin1String("installation.components")).toStringList()); logTextEdit->appendPlainText(QString("Installing to %1").arg(path)); logTextEdit->appendPlainText(QString("Installing %1.").arg(components.join(", "))); @@ -32,7 +32,7 @@ void Wizard::InstallationPage::initializePage() // That way installing all three components would yield 300% // When one component is done the bar will be filled by 33% - if (field("installation.new").toBool() == true) { + if (field(QLatin1String("installation.new")).toBool() == true) { installProgressBar->setMaximum((components.count() * 100)); } else { if (components.contains(QLatin1String("Tribunal")) @@ -49,8 +49,8 @@ void Wizard::InstallationPage::initializePage() void Wizard::InstallationPage::startInstallation() { - QStringList components(field("installation.components").toStringList()); - QString path(field("installation.path").toString()); + QStringList components(field(QLatin1String("installation.components")).toStringList()); + QString path(field(QLatin1String("installation.path")).toString()); QThread *thread = new QThread(); mUnshield = new UnshieldWorker(); @@ -86,7 +86,7 @@ void Wizard::InstallationPage::startInstallation() connect(mUnshield, SIGNAL(requestFileDialog(Wizard::Component)), this, SLOT(showFileDialog(Wizard::Component)), Qt::QueuedConnection); - if (field("installation.new").toBool() == true) + if (field(QLatin1String("installation.new")).toBool() == true) { // Always install Morrowind mUnshield->setInstallComponent(Wizard::Component_Morrowind, true); @@ -117,7 +117,7 @@ void Wizard::InstallationPage::startInstallation() mUnshield->setPath(path); // Set the right codec to use for Morrowind.ini - QString language(field("installation.language").toString()); + QString language(field(QLatin1String("installation.language")).toString()); if (language == QLatin1String("Polish")) { mUnshield->setIniCodec(QTextCodec::codecForName("windows-1250")); diff --git a/apps/wizard/installationtargetpage.cpp b/apps/wizard/installationtargetpage.cpp index daf2c08467..521dc2ceaa 100644 --- a/apps/wizard/installationtargetpage.cpp +++ b/apps/wizard/installationtargetpage.cpp @@ -27,7 +27,7 @@ void Wizard::InstallationTargetPage::initializePage() bool Wizard::InstallationTargetPage::validatePage() { - QString path(field("installation.path").toString()); + QString path(field(QLatin1String("installation.path")).toString()); qDebug() << "Validating path: " << path; diff --git a/apps/wizard/methodselectionpage.cpp b/apps/wizard/methodselectionpage.cpp index 6db0779a6a..b1483ac3a5 100644 --- a/apps/wizard/methodselectionpage.cpp +++ b/apps/wizard/methodselectionpage.cpp @@ -8,12 +8,12 @@ Wizard::MethodSelectionPage::MethodSelectionPage(MainWizard *wizard) : { setupUi(this); - registerField("installation.new", newLocationRadioButton); + registerField(QLatin1String("installation.new"), newLocationRadioButton); } int Wizard::MethodSelectionPage::nextId() const { - if (field("installation.new").toBool() == true) { + if (field(QLatin1String("installation.new")).toBool() == true) { return MainWizard::Page_InstallationTarget; } else { return MainWizard::Page_ExistingInstallation;