diff --git a/apps/wizard/existinginstallationpage.cpp b/apps/wizard/existinginstallationpage.cpp index 13dcf9941..66edc1e8a 100644 --- a/apps/wizard/existinginstallationpage.cpp +++ b/apps/wizard/existinginstallationpage.cpp @@ -14,36 +14,30 @@ Wizard::ExistingInstallationPage::ExistingInstallationPage(MainWizard *wizard) : { setupUi(this); - mEmptyItem = new QListWidgetItem(tr("No existing installations detected")); - mEmptyItem->setFlags(Qt::NoItemFlags); - installationsList->addItem(mEmptyItem); - mEmptyItem->setHidden(true); + QListWidgetItem *emptyItem = new QListWidgetItem(tr("No existing installations detected")); + emptyItem->setFlags(Qt::NoItemFlags); + installationsList->addItem(emptyItem); - connect(installationsList, SIGNAL(currentTextChanged(QString)), - this, SLOT(textChanged(QString))); - - connect(installationsList,SIGNAL(itemSelectionChanged()), - this, SIGNAL(completeChanged())); -} - -void Wizard::ExistingInstallationPage::initializePage() -{ + // Add the available installation paths QStringList paths(mWizard->mInstallations.keys()); + // Hide the default item if there are installations to choose from if (paths.isEmpty()) { - mEmptyItem->setHidden(false); - return; + installationsList->item(0)->setHidden(false); + } else { + installationsList->item(0)->setHidden(true); } - // Make to clear list before adding items - // to prevent duplicates when going back and forth between pages - installationsList->clear(); - foreach (const QString &path, paths) { QListWidgetItem *item = new QListWidgetItem(path); installationsList->addItem(item); } + connect(installationsList, SIGNAL(currentTextChanged(QString)), + this, SLOT(textChanged(QString))); + + connect(installationsList,SIGNAL(itemSelectionChanged()), + this, SIGNAL(completeChanged())); } bool Wizard::ExistingInstallationPage::validatePage() @@ -119,7 +113,7 @@ void Wizard::ExistingInstallationPage::on_browseButton_clicked() mWizard->addInstallation(path); // Hide the default item - mEmptyItem->setHidden(true); + installationsList->item(0)->setHidden(true); QListWidgetItem *item = new QListWidgetItem(path); installationsList->addItem(item); @@ -149,17 +143,5 @@ bool Wizard::ExistingInstallationPage::isComplete() const int Wizard::ExistingInstallationPage::nextId() const { - QString path(field(QLatin1String("installation.path")).toString()); - - if (path.isEmpty()) - return MainWizard::Page_LanguageSelection; - - if (mWizard->mInstallations[path]->hasMorrowind == true && - mWizard->mInstallations[path]->hasTribunal == true && - mWizard->mInstallations[path]->hasBloodmoon == true) - { - return MainWizard::Page_Import; - } else { - return MainWizard::Page_LanguageSelection; - } + return MainWizard::Page_LanguageSelection; } diff --git a/apps/wizard/existinginstallationpage.hpp b/apps/wizard/existinginstallationpage.hpp index 04385893a..54ee8d2e2 100644 --- a/apps/wizard/existinginstallationpage.hpp +++ b/apps/wizard/existinginstallationpage.hpp @@ -2,7 +2,6 @@ #define EXISTINGINSTALLATIONPAGE_HPP #include -#include #include "ui_existinginstallationpage.h" @@ -27,11 +26,7 @@ namespace Wizard private: MainWizard *mWizard; - QListWidgetItem *mEmptyItem; - - protected: - void initializePage(); }; } diff --git a/apps/wizard/languageselectionpage.cpp b/apps/wizard/languageselectionpage.cpp index 8beb106a2..7f97e6918 100644 --- a/apps/wizard/languageselectionpage.cpp +++ b/apps/wizard/languageselectionpage.cpp @@ -27,5 +27,18 @@ void Wizard::LanguageSelectionPage::initializePage() int Wizard::LanguageSelectionPage::nextId() const { - return MainWizard::Page_ComponentSelection; + // Check if we have to install something + QString path(field(QLatin1String("installation.path")).toString()); + + if (path.isEmpty()) + return MainWizard::Page_ComponentSelection; + + if (mWizard->mInstallations[path]->hasMorrowind == true && + mWizard->mInstallations[path]->hasTribunal == true && + mWizard->mInstallations[path]->hasBloodmoon == true) + { + return MainWizard::Page_Import; + } else { + return MainWizard::Page_ComponentSelection; + } } diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index 0a53e10c5..fa27b548c 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -44,6 +44,7 @@ Wizard::MainWizard::MainWizard(QWidget *parent) : setupLog(); setupGameSettings(); + setupLauncherSettings(); setupInstallations(); setupPages(); } @@ -149,6 +150,40 @@ void Wizard::MainWizard::setupGameSettings() } } +void Wizard::MainWizard::setupLauncherSettings() +{ + QString path(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str())); + path.append(QLatin1String("launcher.cfg")); + + QString message(tr("

Could not open %1 for reading

\ +

Please make sure you have the right permissions \ + and try again.

")); + + + QFile file(path); + + qDebug() << "Loading config file:" << qPrintable(path); + + if (file.exists()) { + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error opening OpenMW configuration file")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(message.arg(file.fileName())); + msgBox.exec(); + return qApp->quit(); + } + QTextStream stream(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + + mLauncherSettings.readFile(stream); + } + + file.close(); + +} + void Wizard::MainWizard::setupInstallations() { // Check if the paths actually contain a Morrowind installation @@ -211,8 +246,10 @@ void Wizard::MainWizard::runSettingsImporter() arguments.append(QLatin1String("--cfg")); arguments.append(userPath + QLatin1String("openmw.cfg")); -// if (!ProcessInvoker::startProcess(QLatin1String("mwiniimport"), arguments, false)) -// return qApp->quit();; + ProcessInvoker invoker(this); + + if (!invoker.startProcess(QLatin1String("mwiniimport"), arguments, false)) + return qApp->quit();; // Re-read the game settings setupGameSettings(); @@ -285,6 +322,19 @@ void Wizard::MainWizard::reject() void Wizard::MainWizard::writeSettings() { + // Write the encoding and language settings + QString language(field(QLatin1String("installation.language")).toString()); + mLauncherSettings.setValue(QLatin1String("Settings/language"), language); + + if (language == QLatin1String("Polish")) { + mGameSettings.setValue(QLatin1String("encoding"), QLatin1String("win1250")); + } else if (language == QLatin1String("Russian")) { + mGameSettings.setValue(QLatin1String("encoding"), QLatin1String("win1251")); + } else { + mGameSettings.setValue(QLatin1String("encoding"), QLatin1String("win1252")); + } + + // Write the installation path so that openmw can find them QString path(field(QLatin1String("installation.path")).toString()); // Make sure the installation path is the last data= entry @@ -329,6 +379,28 @@ void Wizard::MainWizard::writeSettings() mGameSettings.writeFile(stream); file.close(); + + // Launcher settings + file.setFileName(userPath + QLatin1String("launcher.cfg")); + + if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { + // File cannot be opened or created + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error writing OpenMW configuration file")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("

Could not open %1 for writing

\ +

Please make sure you have the right permissions \ + and try again.

").arg(file.fileName())); + msgBox.exec(); + return qApp->quit(); + } + + stream.setDevice(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + + mLauncherSettings.writeFile(stream); + file.close(); } bool Wizard::MainWizard::findFiles(const QString &name, const QString &path) diff --git a/apps/wizard/mainwizard.hpp b/apps/wizard/mainwizard.hpp index dcb07a8c2..63b7e62e8 100644 --- a/apps/wizard/mainwizard.hpp +++ b/apps/wizard/mainwizard.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace Wizard { @@ -53,12 +54,14 @@ namespace Wizard void setupLog(); void setupGameSettings(); + void setupLauncherSettings(); void setupInstallations(); void setupPages(); void writeSettings(); Config::GameSettings mGameSettings; + Config::LauncherSettings mLauncherSettings; QTextStream *mLog;