Working on importing content lists in the launcher

loadfix
pvdk 11 years ago
parent 6ed76858d9
commit 30c3c3e245

@ -34,16 +34,68 @@ Launcher::DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, Config:
setupDataFiles();
}
void Launcher::DataFilesPage::loadSettings()
void Launcher::DataFilesPage::buildView()
{
ui.verticalLayout->insertWidget (0, mSelector->uiWidget());
//tool buttons
ui.newProfileButton->setToolTip ("Create a new profile");
ui.deleteProfileButton->setToolTip ("Delete an existing profile");
//combo box
ui.profilesComboBox->addItem ("Default");
ui.profilesComboBox->setPlaceholderText (QString("Select a profile..."));
ui.profilesComboBox->setCurrentIndex(ui.profilesComboBox->findText(QLatin1String("Default")));
// Add the actions to the toolbuttons
ui.newProfileButton->setDefaultAction (ui.newProfileAction);
ui.deleteProfileButton->setDefaultAction (ui.deleteProfileAction);
//establish connections
connect (ui.profilesComboBox, SIGNAL (currentIndexChanged(int)),
this, SLOT (slotProfileChanged(int)));
connect (ui.profilesComboBox, SIGNAL (profileRenamed(QString, QString)),
this, SLOT (slotProfileRenamed(QString, QString)));
connect (ui.profilesComboBox, SIGNAL (signalProfileChanged(QString, QString)),
this, SLOT (slotProfileChangedByUser(QString, QString)));
}
void Launcher::DataFilesPage::setupDataFiles()
{
QStringList paths = mGameSettings.getDataDirs();
foreach (const QString &path, paths)
mSelector->addFiles(path);
mDataLocal = mGameSettings.getDataLocal();
if (!mDataLocal.isEmpty())
mSelector->addFiles(mDataLocal);
loadSettings();
}
bool Launcher::DataFilesPage::loadSettings()
{
QStringList paths = mGameSettings.getDataDirs();
paths.insert (0, mDataLocal);
PathIterator pathIterator (paths);
QString profileName = ui.profilesComboBox->currentText();
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
QString currentProfile = mLauncherSettings.getSettings().value("Profiles/currentprofile");
qDebug() << "current profile is: " << currentProfile;
QStringList files = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/content"), Qt::MatchExactly);
foreach (const QString &item, profiles)
addProfile (item, false);
// Hack: also add the current profile
if (!currentProfile.isEmpty())
addProfile(currentProfile, true);
QStringList files = mLauncherSettings.values(QString("Profiles/") + currentProfile + QString("/content"), Qt::MatchExactly);
QStringList filepaths;
foreach (const QString &file, files)
@ -55,6 +107,8 @@ void Launcher::DataFilesPage::loadSettings()
}
mSelector->setProfileContent (filepaths);
return true;
}
void Launcher::DataFilesPage::saveSettings(const QString &profile)
@ -81,33 +135,6 @@ void Launcher::DataFilesPage::saveSettings(const QString &profile)
}
void Launcher::DataFilesPage::buildView()
{
ui.verticalLayout->insertWidget (0, mSelector->uiWidget());
//tool buttons
ui.newProfileButton->setToolTip ("Create a new profile");
ui.deleteProfileButton->setToolTip ("Delete an existing profile");
//combo box
ui.profilesComboBox->addItem ("Default");
ui.profilesComboBox->setPlaceholderText (QString("Select a profile..."));
// Add the actions to the toolbuttons
ui.newProfileButton->setDefaultAction (ui.newProfileAction);
ui.deleteProfileButton->setDefaultAction (ui.deleteProfileAction);
//establish connections
connect (ui.profilesComboBox, SIGNAL (currentIndexChanged(int)),
this, SLOT (slotProfileChanged(int)));
connect (ui.profilesComboBox, SIGNAL (profileRenamed(QString, QString)),
this, SLOT (slotProfileRenamed(QString, QString)));
connect (ui.profilesComboBox, SIGNAL (signalProfileChanged(QString, QString)),
this, SLOT (slotProfileChangedByUser(QString, QString)));
}
void Launcher::DataFilesPage::removeProfile(const QString &profile)
{
mLauncherSettings.remove(QString("Profiles/") + profile);
@ -140,6 +167,9 @@ void Launcher::DataFilesPage::setProfile (const QString &previous, const QString
if (previous == current)
return;
if (previous.isEmpty())
return;
if (!previous.isEmpty() && savePrevious)
saveSettings (previous);
@ -180,42 +210,6 @@ void Launcher::DataFilesPage::slotProfileChanged(int index)
setProfile (index, true);
}
void Launcher::DataFilesPage::setupDataFiles()
{
QStringList paths = mGameSettings.getDataDirs();
foreach (const QString &path, paths)
mSelector->addFiles(path);
mDataLocal = mGameSettings.getDataLocal();
if (!mDataLocal.isEmpty())
mSelector->addFiles(mDataLocal);
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
QString currentProfile = mLauncherSettings.getSettings().value("Profiles/currentprofile");
// foreach (QString key, mLauncherSettings.getSettings().keys())
// {
// if (key.contains("Profiles/"))
// {
// QString profile = key.mid (9);
// if (profile != "currentprofile")
// {
// if (!profiles.contains(profile))
// profiles << profile;
// }
// }
// }
foreach (const QString &item, profiles)
addProfile (item, false);
setProfile (ui.profilesComboBox->findText(currentProfile), false);
loadSettings();
}
void Launcher::DataFilesPage::on_newProfileAction_triggered()
{
TextInputDialog newDialog (tr("New Profile"), tr("Profile name:"), this);

@ -39,7 +39,9 @@ namespace Launcher
//void writeConfig(QString profile = QString());
void saveSettings(const QString &profile = "");
void loadSettings();
bool loadSettings();
void setupDataFiles();
signals:
void signalProfileChanged (int index);
@ -70,7 +72,6 @@ namespace Launcher
void setPluginsCheckstates(Qt::CheckState state);
void buildView();
void setupDataFiles();
void setupConfig();
void readConfig();
void setProfile (int index, bool savePrevious);

@ -137,7 +137,7 @@ void Launcher::MainDialog::createPages()
mPlayPage = new PlayPage(this);
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, mLauncherSettings, this);
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
mSettingsPage = new SettingsPage(mGameSettings, mLauncherSettings, this);
mSettingsPage = new SettingsPage(mCfgMgr, mGameSettings, mLauncherSettings, this);
// Set the combobox of the play page to imitate the combobox on the datafilespage
mPlayPage->setProfilesModel(mDataFilesPage->profilesModel());
@ -161,150 +161,103 @@ void Launcher::MainDialog::createPages()
bool Launcher::MainDialog::showFirstRunDialog()
{
QStringList iniPaths;
foreach (const QString &path, mGameSettings.getDataDirs()) {
QDir dir(path);
dir.setPath(dir.canonicalPath()); // Resolve symlinks
if (dir.exists(QString("Morrowind.ini")))
iniPaths.append(dir.absoluteFilePath(QString("Morrowind.ini")));
else
{
if (!dir.cdUp())
continue; // Cannot move from Data Files
if (dir.exists(QString("Morrowind.ini")))
iniPaths.append(dir.absoluteFilePath(QString("Morrowind.ini")));
}
}
// Ask the user where the Morrowind.ini is
if (iniPaths.empty()) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error detecting Morrowind configuration"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setText(QObject::tr("<br><b>Could not find Morrowind.ini</b><br><br> \
OpenMW needs to import settings from this file.<br><br> \
Press \"Browse...\" to specify the location manually.<br>"));
QAbstractButton *dirSelectButton =
msgBox.addButton(QObject::tr("B&rowse..."), QMessageBox::ActionRole);
msgBox.exec();
QString iniFile;
if (msgBox.clickedButton() == dirSelectButton) {
iniFile = QFileDialog::getOpenFileName(
NULL,
QObject::tr("Select configuration file"),
QDir::currentPath(),
QString(tr("Morrowind configuration file (*.ini)")));
}
if (iniFile.isEmpty())
return false; // Cancel was clicked;
QFileInfo info(iniFile);
iniPaths.clear();
iniPaths.append(info.absoluteFilePath());
}
CheckableMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Morrowind installation detected"));
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion);
int size = QApplication::style()->pixelMetric(QStyle::PM_MessageBoxIconSize);
msgBox.setIconPixmap(icon.pixmap(size, size));
QAbstractButton *importerButton =
msgBox.addButton(tr("Import"), QDialogButtonBox::AcceptRole); // ActionRole doesn't work?!
QAbstractButton *skipButton =
msgBox.addButton(tr("Skip"), QDialogButtonBox::RejectRole);
Q_UNUSED(skipButton); // Surpress compiler unused warning
msgBox.setStandardButtons(QDialogButtonBox::NoButton);
msgBox.setText(tr("<br><b>An existing Morrowind configuration was detected</b><br> \
<br>Would you like to import settings from Morrowind.ini?<br> \
<br><b>Warning: In most cases OpenMW needs these settings to run properly</b><br>"));
msgBox.setCheckBoxText(tr("Include selected masters and plugins (creates a new profile)"));
msgBox.exec();
if (msgBox.clickedButton() == importerButton) {
if (iniPaths.count() > 1) {
// Multiple Morrowind.ini files found
bool ok;
QString path = QInputDialog::getItem(this, tr("Multiple configurations found"),
tr("<br><b>There are multiple Morrowind.ini files found.</b><br><br> \
Please select the one you wish to import from:"), iniPaths, 0, false, &ok);
if (ok && !path.isEmpty()) {
iniPaths.clear();
iniPaths.append(path);
} else {
// Cancel was clicked
return false;
}
}
// Create the file if it doesn't already exist, else the importer will fail
QString path = QString::fromStdString(mCfgMgr.getUserConfigPath().string()) + QString("openmw.cfg");
QFile file(path);
if (!file.exists()) {
if (!file.open(QIODevice::ReadWrite)) {
// File cannot be created
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error writing OpenMW 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 false;
}
file.close();
}
// Construct the arguments to run the importer
QStringList arguments;
if (msgBox.isChecked())
arguments.append(QString("--game-files"));
arguments.append(QString("--encoding"));
arguments.append(mGameSettings.value(QString("encoding"), QString("win1252")));
arguments.append(QString("--ini"));
arguments.append(iniPaths.first());
arguments.append(QString("--cfg"));
arguments.append(path);
ProcessInvoker invoker(this);
if (!invoker.startProcess(QLatin1String("mwiniimport"), arguments, false))
return false;
// Re-read the game settings
if (!setupGameSettings())
return false;
// Add a new profile
if (msgBox.isChecked()) {
mLauncherSettings.setValue(QString("Profiles/currentprofile"), QString("Imported"));
mLauncherSettings.remove(QString("Profiles/Imported/content"));
QStringList contents = mGameSettings.values(QString("content"));
foreach (const QString &content, contents) {
mLauncherSettings.setMultiValue(QString("Profiles/Imported/content"), content);
}
}
}
// CheckableMessageBox msgBox(this);
// msgBox.setWindowTitle(tr("Morrowind installation detected"));
// QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion);
// int size = QApplication::style()->pixelMetric(QStyle::PM_MessageBoxIconSize);
// msgBox.setIconPixmap(icon.pixmap(size, size));
// QAbstractButton *importerButton =
// msgBox.addButton(tr("Import"), QDialogButtonBox::AcceptRole); // ActionRole doesn't work?!
// QAbstractButton *skipButton =
// msgBox.addButton(tr("Skip"), QDialogButtonBox::RejectRole);
// Q_UNUSED(skipButton); // Surpress compiler unused warning
// msgBox.setStandardButtons(QDialogButtonBox::NoButton);
// msgBox.setText(tr("<br><b>An existing Morrowind configuration was detected</b><br> \
// <br>Would you like to import settings from Morrowind.ini?<br> \
// <br><b>Warning: In most cases OpenMW needs these settings to run properly</b><br>"));
// msgBox.setCheckBoxText(tr("Include selected masters and plugins (creates a new profile)"));
// msgBox.exec();
// if (msgBox.clickedButton() == importerButton) {
// if (iniPaths.count() > 1) {
// // Multiple Morrowind.ini files found
// bool ok;
// QString path = QInputDialog::getItem(this, tr("Multiple configurations found"),
// tr("<br><b>There are multiple Morrowind.ini files found.</b><br><br> \
// Please select the one you wish to import from:"), iniPaths, 0, false, &ok);
// if (ok && !path.isEmpty()) {
// iniPaths.clear();
// iniPaths.append(path);
// } else {
// // Cancel was clicked
// return false;
// }
// }
// // Create the file if it doesn't already exist, else the importer will fail
// QString path = QString::fromStdString(mCfgMgr.getUserConfigPath().string()) + QString("openmw.cfg");
// QFile file(path);
// if (!file.exists()) {
// if (!file.open(QIODevice::ReadWrite)) {
// // File cannot be created
// QMessageBox msgBox;
// msgBox.setWindowTitle(tr("Error writing OpenMW 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 false;
// }
// file.close();
// }
// // Construct the arguments to run the importer
// QStringList arguments;
// if (msgBox.isChecked())
// arguments.append(QString("--game-files"));
// arguments.append(QString("--encoding"));
// arguments.append(mGameSettings.value(QString("encoding"), QString("win1252")));
// arguments.append(QString("--ini"));
// arguments.append(iniPaths.first());
// arguments.append(QString("--cfg"));
// arguments.append(path);
// ProcessInvoker invoker(this);
// if (!invoker.startProcess(QLatin1String("mwiniimport"), arguments, false))
// return false;
// // Re-read the game settings
// if (!setupGameSettings())
// return false;
// // Add a new profile
// if (msgBox.isChecked()) {
// mLauncherSettings.setValue(QString("Profiles/currentprofile"), QString("Imported"));
// mLauncherSettings.remove(QString("Profiles/Imported/content"));
// QStringList contents = mGameSettings.values(QString("content"));
// foreach (const QString &content, contents) {
// mLauncherSettings.setMultiValue(QString("Profiles/Imported/content"), content);
// }
// }
// }
return true;
}
@ -349,8 +302,11 @@ bool Launcher::MainDialog::reloadSettings()
if (!setupGraphicsSettings())
return false;
// if (!mSettingsPage->loadSettings())
// return false;
if (!mSettingsPage->loadSettings())
return false;
if (!mDataFilesPage->loadSettings())
return false;
if (!mGraphicsPage->loadSettings())
return false;
@ -371,17 +327,17 @@ void Launcher::MainDialog::changePage(QListWidgetItem *current, QListWidgetItem
DataFilesPage *previousPage = dynamic_cast<DataFilesPage *>(pagesWidget->widget(previousIndex));
DataFilesPage *currentPage = dynamic_cast<DataFilesPage *>(pagesWidget->widget(currentIndex));
//special call to update/save data files page list view when it's displayed/hidden.
if (previousPage)
{
if (previousPage->objectName() == "DataFilesPage")
previousPage->saveSettings();
}
else if (currentPage)
{
if (currentPage->objectName() == "DataFilesPage")
currentPage->loadSettings();
}
// //special call to update/save data files page list view when it's displayed/hidden.
// if (previousPage)
// {
// if (previousPage->objectName() == "DataFilesPage")
// previousPage->saveSettings();
// }
// else if (currentPage)
// {
// if (currentPage->objectName() == "DataFilesPage")
// currentPage->loadSettings();
// }
}
bool Launcher::MainDialog::setupLauncherSettings()
@ -729,8 +685,9 @@ bool Launcher::MainDialog::writeSettings()
{
// Now write all config files
saveSettings();
mGraphicsPage->saveSettings();
mDataFilesPage->saveSettings();
mGraphicsPage->saveSettings();
mSettingsPage->saveSettings();
QString userPath = QString::fromStdString(mCfgMgr.getUserConfigPath().string());
QDir dir(userPath);

@ -5,6 +5,8 @@
#include <QDebug>
#include <QDir>
#include <components/files/configurationmanager.hpp>
#include <components/config/gamesettings.hpp>
#include <components/config/launchersettings.hpp>
@ -12,12 +14,14 @@
using namespace Process;
Launcher::SettingsPage::SettingsPage(Config::GameSettings &gameSettings,
Config::LauncherSettings &launcherSettings, MainDialog *parent) :
mGameSettings(gameSettings),
mLauncherSettings(launcherSettings),
QWidget(parent),
mMain(parent)
Launcher::SettingsPage::SettingsPage(Files::ConfigurationManager &cfg,
Config::GameSettings &gameSettings,
Config::LauncherSettings &launcherSettings, MainDialog *parent)
: mCfgMgr(cfg)
, mGameSettings(gameSettings)
, mLauncherSettings(launcherSettings)
, QWidget(parent)
, mMain(parent)
{
setupUi(this);
@ -77,17 +81,60 @@ Launcher::SettingsPage::SettingsPage(Config::GameSettings &gameSettings,
} else {
importerButton->setEnabled(false);
}
loadSettings();
}
void Launcher::SettingsPage::on_wizardButton_clicked()
{
saveSettings();
if (!mWizardInvoker->startProcess(QLatin1String("openmw-wizard"), false))
return;
}
void Launcher::SettingsPage::on_importerButton_clicked()
{
if (!mImporterInvoker->startProcess(QLatin1String("mwiniimport"), false))
saveSettings();
// Create the file if it doesn't already exist, else the importer will fail
QString path(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
path.append(QLatin1String("openmw.cfg"));
QFile file(path);
if (!file.exists()) {
if (!file.open(QIODevice::ReadWrite)) {
// File cannot be created
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error writing OpenMW configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("<html><head/><body><p><b>Could not open or create %1 for writing </b></p> \
<p>Please make sure you have the right permissions \
and try again.</p></body></html>").arg(file.fileName()));
msgBox.exec();
return;
}
file.close();
}
// Construct the arguments to run the importer
QStringList arguments;
if (addonsCheckBox->isChecked())
arguments.append(QString("--game-files"));
arguments.append(QString("--encoding"));
arguments.append(mGameSettings.value(QString("encoding"), QString("win1252")));
arguments.append(QString("--ini"));
arguments.append(settingsComboBox->currentText());
arguments.append(QString("--cfg"));
arguments.append(path);
qDebug() << "arguments " << arguments;
if (!mImporterInvoker->startProcess(QLatin1String("mwiniimport"), arguments, false))
return;
}
@ -129,7 +176,6 @@ void Launcher::SettingsPage::wizardFinished(int exitCode, QProcess::ExitStatus e
if (exitCode != 0 || exitStatus == QProcess::CrashExit)
return;
mMain->writeSettings();
mMain->reloadSettings();
wizardButton->setEnabled(true);
}
@ -146,6 +192,9 @@ void Launcher::SettingsPage::importerFinished(int exitCode, QProcess::ExitStatus
if (exitCode != 0 || exitStatus == QProcess::CrashExit)
return;
// Re-read the settings in their current state
mMain->reloadSettings();
// Import selected data files from openmw.cfg
if (addonsCheckBox->isChecked())
{
@ -154,6 +203,8 @@ void Launcher::SettingsPage::importerFinished(int exitCode, QProcess::ExitStatus
const QString profile(mProfileDialog->lineEdit()->text());
const QStringList files(mGameSettings.values(QLatin1String("content")));
qDebug() << "Profile " << profile << files;
// Doesn't quite work right now
mLauncherSettings.setValue(QLatin1String("Profiles/currentprofile"), profile);
@ -165,7 +216,6 @@ void Launcher::SettingsPage::importerFinished(int exitCode, QProcess::ExitStatus
}
}
mMain->writeSettings();
mMain->reloadSettings();
importerButton->setEnabled(true);
}
@ -184,3 +234,30 @@ void Launcher::SettingsPage::updateOkButton(const QString &text)
? mProfileDialog->setOkButtonEnabled(false)
: mProfileDialog->setOkButtonEnabled(true);
}
void Launcher::SettingsPage::saveSettings()
{
QString language(languageComboBox->currentText());
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"));
}
}
bool Launcher::SettingsPage::loadSettings()
{
QString language(mLauncherSettings.value(QLatin1String("Settings/language")));
int index = languageComboBox->findText(language);
if (index != -1)
languageComboBox->setCurrentIndex(index);
return true;
}

@ -10,6 +10,7 @@
#include "maindialog.hpp"
namespace Files { struct ConfigurationManager; }
namespace Config { class GameSettings;
class LauncherSettings; }
@ -22,13 +23,14 @@ namespace Launcher
Q_OBJECT
public:
SettingsPage( Config::GameSettings &gameSettings,
SettingsPage(Files::ConfigurationManager &cfg, Config::GameSettings &gameSettings,
Config::LauncherSettings &launcherSettings, MainDialog *parent = 0);
void saveSettings();
bool loadSettings();
private slots:
void on_wizardButton_clicked();
void on_importerButton_clicked();
void on_browseButton_clicked();
@ -42,9 +44,12 @@ namespace Launcher
void updateOkButton(const QString &text);
private:
Process::ProcessInvoker *mWizardInvoker;
Process::ProcessInvoker *mImporterInvoker;
Files::ConfigurationManager &mCfgMgr;
Config::GameSettings &mGameSettings;
Config::LauncherSettings &mLauncherSettings;

@ -14,7 +14,7 @@ Launcher::TextInputDialog::TextInputDialog(const QString& title, const QString &
mButtonBox = new QDialogButtonBox(this);
mButtonBox->addButton(QDialogButtonBox::Ok);
mButtonBox->addButton(QDialogButtonBox::Cancel);
// mButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false);
mButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false);
QLabel *label = new QLabel(this);
label->setText(text);

Loading…
Cancel
Save