mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 07:06:43 +00:00
Working on the Settings tab: start the importer/wizard
This commit is contained in:
parent
cfe66abbc5
commit
21c406316f
12 changed files with 342 additions and 109 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "datafilespage.hpp"
|
#include "datafilespage.hpp"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
@ -221,7 +223,7 @@ void Launcher::DataFilesPage::on_newProfileAction_triggered()
|
||||||
if (newDialog.exec() != QDialog::Accepted)
|
if (newDialog.exec() != QDialog::Accepted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString profile = newDialog.getText();
|
QString profile = newDialog.lineEdit()->text();
|
||||||
|
|
||||||
if (profile.isEmpty())
|
if (profile.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QProcess>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
@ -138,7 +137,7 @@ void Launcher::MainDialog::createPages()
|
||||||
mPlayPage = new PlayPage(this);
|
mPlayPage = new PlayPage(this);
|
||||||
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, mLauncherSettings, this);
|
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, mLauncherSettings, this);
|
||||||
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
|
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
|
||||||
mSettingsPage = new SettingsPage(this);
|
mSettingsPage = new SettingsPage(mGameSettings, mLauncherSettings, this);
|
||||||
|
|
||||||
// Set the combobox of the play page to imitate the combobox on the datafilespage
|
// Set the combobox of the play page to imitate the combobox on the datafilespage
|
||||||
mPlayPage->setProfilesModel(mDataFilesPage->profilesModel());
|
mPlayPage->setProfilesModel(mDataFilesPage->profilesModel());
|
||||||
|
@ -285,7 +284,9 @@ bool Launcher::MainDialog::showFirstRunDialog()
|
||||||
arguments.append(QString("--cfg"));
|
arguments.append(QString("--cfg"));
|
||||||
arguments.append(path);
|
arguments.append(path);
|
||||||
|
|
||||||
if (!ProcessInvoker::startProcess(QLatin1String("mwiniimport"), arguments, false))
|
ProcessInvoker invoker(this);
|
||||||
|
|
||||||
|
if (!invoker.startProcess(QLatin1String("mwiniimport"), arguments, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Re-read the game settings
|
// Re-read the game settings
|
||||||
|
@ -337,6 +338,26 @@ bool Launcher::MainDialog::setup()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Launcher::MainDialog::reloadSettings()
|
||||||
|
{
|
||||||
|
if (!setupLauncherSettings())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!setupGameSettings())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!setupGraphicsSettings())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// if (!mSettingsPage->loadSettings())
|
||||||
|
// return false;
|
||||||
|
|
||||||
|
if (!mGraphicsPage->loadSettings())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Launcher::MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
void Launcher::MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
||||||
{
|
{
|
||||||
if (!current)
|
if (!current)
|
||||||
|
@ -799,6 +820,7 @@ bool Launcher::MainDialog::writeSettings()
|
||||||
|
|
||||||
void Launcher::MainDialog::closeEvent(QCloseEvent *event)
|
void Launcher::MainDialog::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
|
qDebug() << "close event!";
|
||||||
writeSettings();
|
writeSettings();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
@ -822,6 +844,8 @@ void Launcher::MainDialog::play()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launch the game detached
|
// Launch the game detached
|
||||||
if (ProcessInvoker::startProcess(QLatin1String("openmw"), true))
|
ProcessInvoker invoker(this);
|
||||||
|
|
||||||
|
if (invoker.startProcess(QLatin1String("openmw"), true))
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ namespace Launcher
|
||||||
bool setup();
|
bool setup();
|
||||||
bool showFirstRunDialog();
|
bool showFirstRunDialog();
|
||||||
|
|
||||||
|
bool reloadSettings();
|
||||||
|
bool writeSettings();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
void play();
|
void play();
|
||||||
|
@ -53,7 +56,6 @@ namespace Launcher
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
bool writeSettings();
|
|
||||||
|
|
||||||
inline bool startProgram(const QString &name, bool detached = false) { return startProgram(name, QStringList(), detached); }
|
inline bool startProgram(const QString &name, bool detached = false) { return startProgram(name, QStringList(), detached); }
|
||||||
bool startProgram(const QString &name, const QStringList &arguments, bool detached = false);
|
bool startProgram(const QString &name, const QStringList &arguments, bool detached = false);
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
#include "settingspage.hpp"
|
#include "settingspage.hpp"
|
||||||
|
|
||||||
#include <components/process/processinvoker.hpp>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <components/config/gamesettings.hpp>
|
||||||
|
#include <components/config/launchersettings.hpp>
|
||||||
|
|
||||||
|
#include "utils/textinputdialog.hpp"
|
||||||
|
|
||||||
using namespace Process;
|
using namespace Process;
|
||||||
|
|
||||||
Launcher::SettingsPage::SettingsPage(QWidget *parent) : QWidget(parent)
|
Launcher::SettingsPage::SettingsPage(Config::GameSettings &gameSettings,
|
||||||
|
Config::LauncherSettings &launcherSettings, MainDialog *parent) :
|
||||||
|
mGameSettings(gameSettings),
|
||||||
|
mLauncherSettings(launcherSettings),
|
||||||
|
QWidget(parent),
|
||||||
|
mMain(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
|
@ -20,16 +29,111 @@ Launcher::SettingsPage::SettingsPage(QWidget *parent) : QWidget(parent)
|
||||||
<< "Spanish";
|
<< "Spanish";
|
||||||
|
|
||||||
languageComboBox->addItems(languages);
|
languageComboBox->addItems(languages);
|
||||||
|
|
||||||
|
mWizardInvoker = new ProcessInvoker(this);
|
||||||
|
mImporterInvoker = new ProcessInvoker(this);
|
||||||
|
|
||||||
|
connect(mWizardInvoker->getProcess(), SIGNAL(started()),
|
||||||
|
this, SLOT(wizardStarted()));
|
||||||
|
|
||||||
|
connect(mWizardInvoker->getProcess(), SIGNAL(finished(int,QProcess::ExitStatus)),
|
||||||
|
this, SLOT(wizardFinished(int,QProcess::ExitStatus)));
|
||||||
|
|
||||||
|
connect(mImporterInvoker->getProcess(), SIGNAL(started()),
|
||||||
|
this, SLOT(importerStarted()));
|
||||||
|
|
||||||
|
connect(mImporterInvoker->getProcess(), SIGNAL(finished(int,QProcess::ExitStatus)),
|
||||||
|
this, SLOT(importerFinished(int,QProcess::ExitStatus)));
|
||||||
|
|
||||||
|
mProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this);
|
||||||
|
|
||||||
|
connect(mProfileDialog->lineEdit(), SIGNAL(textChanged(QString)),
|
||||||
|
this, SLOT(updateOkButton(QString)));
|
||||||
|
|
||||||
|
// // Detect Morrowind configuration files
|
||||||
|
// 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")));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::SettingsPage::on_wizardButton_clicked()
|
void Launcher::SettingsPage::on_wizardButton_clicked()
|
||||||
{
|
{
|
||||||
if (!ProcessInvoker::startProcess(QLatin1String("openmw-wizard"), true))
|
if (!mWizardInvoker->startProcess(QLatin1String("openmw-wizard"), false))
|
||||||
qDebug() << "an error occurred";
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::SettingsPage::on_importerButton_clicked()
|
void Launcher::SettingsPage::on_importerButton_clicked()
|
||||||
{
|
{
|
||||||
|
if (!mImporterInvoker->startProcess(QLatin1String("mwiniimport"), false))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Launcher::SettingsPage::wizardStarted()
|
||||||
|
{
|
||||||
|
qDebug() << "wizard started!";
|
||||||
|
wizardButton->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Launcher::SettingsPage::wizardFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
|
{
|
||||||
|
qDebug() << "wizard finished!";
|
||||||
|
if (exitCode != 0 || exitStatus == QProcess::CrashExit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mMain->writeSettings();
|
||||||
|
mMain->reloadSettings();
|
||||||
|
wizardButton->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Launcher::SettingsPage::importerStarted()
|
||||||
|
{
|
||||||
|
qDebug() << "importer started!";
|
||||||
|
importerButton->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Launcher::SettingsPage::importerFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
|
{
|
||||||
|
qDebug() << "importer finished!";
|
||||||
|
if (exitCode != 0 || exitStatus == QProcess::CrashExit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mMain->writeSettings();
|
||||||
|
mMain->reloadSettings();
|
||||||
|
|
||||||
|
|
||||||
|
if (addonsCheckBox->isChecked()) {
|
||||||
|
|
||||||
|
if (mProfileDialog->exec() == QDialog::Accepted) {
|
||||||
|
QString profile = mProfileDialog->lineEdit()->text();
|
||||||
|
qDebug() << profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
importerButton->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Launcher::SettingsPage::updateOkButton(const QString &text)
|
||||||
|
{
|
||||||
|
// We do this here because we need the profiles combobox text
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
mProfileDialog->setOkButtonEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// (profilesComboBox->findText(text) == -1)
|
||||||
|
// ? mNewProfileDialog->setOkButtonEnabled(true)
|
||||||
|
// : mNewProfileDialog->setOkButtonEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,28 @@
|
||||||
#define SETTINGSPAGE_HPP
|
#define SETTINGSPAGE_HPP
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
#include <components/process/processinvoker.hpp>
|
||||||
|
|
||||||
#include "ui_settingspage.h"
|
#include "ui_settingspage.h"
|
||||||
|
|
||||||
|
#include "maindialog.hpp"
|
||||||
|
|
||||||
|
namespace Config { class GameSettings;
|
||||||
|
class LauncherSettings; }
|
||||||
|
|
||||||
namespace Launcher
|
namespace Launcher
|
||||||
{
|
{
|
||||||
|
class TextInputDialog;
|
||||||
|
|
||||||
class SettingsPage : public QWidget, private Ui::SettingsPage
|
class SettingsPage : public QWidget, private Ui::SettingsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SettingsPage(QWidget *parent = 0);
|
SettingsPage( Config::GameSettings &gameSettings,
|
||||||
|
Config::LauncherSettings &launcherSettings, MainDialog *parent = 0);
|
||||||
|
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
bool loadSettings();
|
bool loadSettings();
|
||||||
|
@ -21,6 +31,26 @@ namespace Launcher
|
||||||
private slots:
|
private slots:
|
||||||
void on_wizardButton_clicked();
|
void on_wizardButton_clicked();
|
||||||
void on_importerButton_clicked();
|
void on_importerButton_clicked();
|
||||||
|
|
||||||
|
void wizardStarted();
|
||||||
|
void wizardFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
|
|
||||||
|
void importerStarted();
|
||||||
|
void importerFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
|
|
||||||
|
void updateOkButton(const QString &text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Process::ProcessInvoker *mWizardInvoker;
|
||||||
|
Process::ProcessInvoker *mImporterInvoker;
|
||||||
|
|
||||||
|
Config::GameSettings &mGameSettings;
|
||||||
|
Config::LauncherSettings &mLauncherSettings;
|
||||||
|
|
||||||
|
MainDialog *mMain;
|
||||||
|
TextInputDialog *mProfileDialog;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,17 @@ Launcher::TextInputDialog::TextInputDialog(const QString& title, const QString &
|
||||||
mButtonBox = new QDialogButtonBox(this);
|
mButtonBox = new QDialogButtonBox(this);
|
||||||
mButtonBox->addButton(QDialogButtonBox::Ok);
|
mButtonBox->addButton(QDialogButtonBox::Ok);
|
||||||
mButtonBox->addButton(QDialogButtonBox::Cancel);
|
mButtonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
mButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false);
|
// mButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false);
|
||||||
|
|
||||||
|
QLabel *label = new QLabel(this);
|
||||||
|
label->setText(text);
|
||||||
|
|
||||||
// Line edit
|
// Line edit
|
||||||
QValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
QValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
||||||
mLineEdit = new DialogLineEdit(this);
|
mLineEdit = new LineEdit(this);
|
||||||
mLineEdit->setValidator(validator);
|
mLineEdit->setValidator(validator);
|
||||||
mLineEdit->setCompleter(0);
|
mLineEdit->setCompleter(0);
|
||||||
|
|
||||||
QLabel *label = new QLabel(this);
|
|
||||||
label->setText(text);
|
|
||||||
|
|
||||||
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
||||||
dialogLayout->addWidget(label);
|
dialogLayout->addWidget(label);
|
||||||
dialogLayout->addWidget(mLineEdit);
|
dialogLayout->addWidget(mLineEdit);
|
||||||
|
@ -41,8 +41,10 @@ Launcher::TextInputDialog::TextInputDialog(const QString& title, const QString &
|
||||||
|
|
||||||
connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
connect(mLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateOkButton(QString)));
|
}
|
||||||
|
|
||||||
|
Launcher::TextInputDialog::~TextInputDialog()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int Launcher::TextInputDialog::exec()
|
int Launcher::TextInputDialog::exec()
|
||||||
|
@ -52,36 +54,18 @@ int Launcher::TextInputDialog::exec()
|
||||||
return QDialog::exec();
|
return QDialog::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Launcher::TextInputDialog::getText() const
|
void Launcher::TextInputDialog::setOkButtonEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
return mLineEdit->text();
|
QPushButton *okButton = mButtonBox->button(QDialogButtonBox::Ok);
|
||||||
}
|
okButton->setEnabled(enabled);
|
||||||
|
|
||||||
void Launcher::TextInputDialog::slotUpdateOkButton(QString text)
|
QPalette *palette = new QPalette();
|
||||||
{
|
palette->setColor(QPalette::Text, Qt::red);
|
||||||
bool enabled = !(text.isEmpty());
|
|
||||||
mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled);
|
|
||||||
|
|
||||||
if (enabled)
|
if (enabled) {
|
||||||
mLineEdit->setPalette(QApplication::palette());
|
mLineEdit->setPalette(QApplication::palette());
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
// Existing profile name, make the text red
|
// Existing profile name, make the text red
|
||||||
QPalette *palette = new QPalette();
|
|
||||||
palette->setColor(QPalette::Text,Qt::red);
|
|
||||||
mLineEdit->setPalette(*palette);
|
mLineEdit->setPalette(*palette);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Launcher::TextInputDialog::DialogLineEdit::DialogLineEdit (QWidget *parent) :
|
|
||||||
LineEdit (parent)
|
|
||||||
{
|
|
||||||
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
|
||||||
|
|
||||||
setObjectName(QString("LineEdit"));
|
|
||||||
setStyleSheet(QString("LineEdit { padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1));
|
|
||||||
QSize msz = minimumSizeHint();
|
|
||||||
setMinimumSize(qMax(msz.width(), mClearButton->sizeHint().height() + frameWidth * 2 + 2),
|
|
||||||
qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,26 +13,20 @@ namespace Launcher
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
class DialogLineEdit : public LineEdit
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit DialogLineEdit (QWidget *parent = 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
DialogLineEdit *mLineEdit;
|
|
||||||
QDialogButtonBox *mButtonBox;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit TextInputDialog(const QString& title, const QString &text, QWidget *parent = 0);
|
explicit TextInputDialog(const QString& title, const QString &text, QWidget *parent = 0);
|
||||||
~TextInputDialog () {}
|
~TextInputDialog ();
|
||||||
|
|
||||||
QString getText() const;
|
inline LineEdit *lineEdit() { return mLineEdit; }
|
||||||
|
void setOkButtonEnabled(bool enabled);
|
||||||
|
|
||||||
int exec();
|
int exec();
|
||||||
|
|
||||||
private slots:
|
private:
|
||||||
void slotUpdateOkButton(QString text);
|
|
||||||
|
QDialogButtonBox *mButtonBox;
|
||||||
|
LineEdit *mLineEdit;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,8 +211,8 @@ void Wizard::MainWizard::runSettingsImporter()
|
||||||
arguments.append(QLatin1String("--cfg"));
|
arguments.append(QLatin1String("--cfg"));
|
||||||
arguments.append(userPath + QLatin1String("openmw.cfg"));
|
arguments.append(userPath + QLatin1String("openmw.cfg"));
|
||||||
|
|
||||||
if (!ProcessInvoker::startProcess(QLatin1String("mwiniimport"), arguments, false))
|
// if (!ProcessInvoker::startProcess(QLatin1String("mwiniimport"), arguments, false))
|
||||||
return qApp->quit();;
|
// return qApp->quit();;
|
||||||
|
|
||||||
// Re-read the game settings
|
// Re-read the game settings
|
||||||
setupGameSettings();
|
setupGameSettings();
|
||||||
|
|
|
@ -41,14 +41,20 @@ QStringList Config::LauncherSettings::subKeys(const QString &key)
|
||||||
QMap<QString, QString> settings = SettingsBase::getSettings();
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
||||||
QStringList keys = settings.uniqueKeys();
|
QStringList keys = settings.uniqueKeys();
|
||||||
|
|
||||||
|
qDebug() << keys;
|
||||||
|
|
||||||
QRegExp keyRe("(.+)/");
|
QRegExp keyRe("(.+)/");
|
||||||
|
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
foreach (const QString ¤tKey, keys) {
|
foreach (const QString ¤tKey, keys) {
|
||||||
if (keyRe.indexIn(currentKey) != -1) {
|
|
||||||
|
if (keyRe.indexIn(currentKey) != -1)
|
||||||
|
{
|
||||||
QString prefixedKey = keyRe.cap(1);
|
QString prefixedKey = keyRe.cap(1);
|
||||||
if(prefixedKey.startsWith(key)) {
|
|
||||||
|
if(prefixedKey.startsWith(key))
|
||||||
|
{
|
||||||
QString subKey = prefixedKey.remove(key);
|
QString subKey = prefixedKey.remove(key);
|
||||||
if (!subKey.isEmpty())
|
if (!subKey.isEmpty())
|
||||||
result.append(subKey);
|
result.append(subKey);
|
||||||
|
|
|
@ -1,23 +1,63 @@
|
||||||
#include "processinvoker.hpp"
|
#include "processinvoker.hpp"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QProcess>
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
Process::ProcessInvoker::ProcessInvoker()
|
Process::ProcessInvoker::ProcessInvoker(QWidget *parent)
|
||||||
{
|
{
|
||||||
|
mProcess = new QProcess(this);
|
||||||
|
|
||||||
|
mName = QString();
|
||||||
|
mArguments = QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Process::ProcessInvoker::~ProcessInvoker()
|
Process::ProcessInvoker::~ProcessInvoker()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void Process::ProcessInvoker::setProcessName(const QString &name)
|
||||||
|
//{
|
||||||
|
// mName = name;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void Process::ProcessInvoker::setProcessArguments(const QStringList &arguments)
|
||||||
|
//{
|
||||||
|
// mArguments = arguments;
|
||||||
|
//}
|
||||||
|
|
||||||
|
QProcess* Process::ProcessInvoker::getProcess()
|
||||||
|
{
|
||||||
|
return mProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
//QString Process::ProcessInvoker::getProcessName()
|
||||||
|
//{
|
||||||
|
// return mName;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//QStringList Process::ProcessInvoker::getProcessArguments()
|
||||||
|
//{
|
||||||
|
// return mArguments;
|
||||||
|
//}
|
||||||
|
|
||||||
bool Process::ProcessInvoker::startProcess(const QString &name, const QStringList &arguments, bool detached)
|
bool Process::ProcessInvoker::startProcess(const QString &name, const QStringList &arguments, bool detached)
|
||||||
{
|
{
|
||||||
|
// mProcess = new QProcess(this);
|
||||||
|
|
||||||
|
connect(mProcess, SIGNAL(error(QProcess::ProcessError)),
|
||||||
|
this, SLOT(processError(QProcess::ProcessError)));
|
||||||
|
|
||||||
|
connect(mProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
|
||||||
|
this, SLOT(processFinished(int,QProcess::ExitStatus)));
|
||||||
|
|
||||||
|
mName = name;
|
||||||
|
mArguments = arguments;
|
||||||
|
|
||||||
QString path(name);
|
QString path(name);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
path.append(QLatin1String(".exe"));
|
path.append(QLatin1String(".exe"));
|
||||||
|
@ -28,7 +68,6 @@ bool Process::ProcessInvoker::startProcess(const QString &name, const QStringLis
|
||||||
path.prepend(QLatin1String("./"));
|
path.prepend(QLatin1String("./"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QProcess process;
|
|
||||||
QFileInfo info(path);
|
QFileInfo info(path);
|
||||||
|
|
||||||
if (!info.exists()) {
|
if (!info.exists()) {
|
||||||
|
@ -57,7 +96,7 @@ bool Process::ProcessInvoker::startProcess(const QString &name, const QStringLis
|
||||||
|
|
||||||
// Start the executable
|
// Start the executable
|
||||||
if (detached) {
|
if (detached) {
|
||||||
if (!process.startDetached(path, arguments)) {
|
if (!mProcess->startDetached(path, arguments)) {
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle(tr("Error starting executable"));
|
msgBox.setWindowTitle(tr("Error starting executable"));
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
@ -65,45 +104,79 @@ bool Process::ProcessInvoker::startProcess(const QString &name, const QStringLis
|
||||||
msgBox.setText(tr("<html><head/><body><p><b>Could not start %1</b></p> \
|
msgBox.setText(tr("<html><head/><body><p><b>Could not start %1</b></p> \
|
||||||
<p>An error occurred while starting %1.</p> \
|
<p>An error occurred while starting %1.</p> \
|
||||||
<p>Press \"Show Details...\" for more information.</p></body></html>").arg(info.fileName()));
|
<p>Press \"Show Details...\" for more information.</p></body></html>").arg(info.fileName()));
|
||||||
msgBox.setDetailedText(process.errorString());
|
msgBox.setDetailedText(mProcess->errorString());
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
process.start(path, arguments);
|
mProcess->start(path, arguments);
|
||||||
if (!process.waitForFinished()) {
|
|
||||||
QMessageBox msgBox;
|
|
||||||
msgBox.setWindowTitle(tr("Error starting executable"));
|
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
||||||
msgBox.setText(tr("<html><head/><body><p><b>Could not start %1</b></p> \
|
|
||||||
<p>An error occurred while starting %1.</p> \
|
|
||||||
<p>Press \"Show Details...\" for more information.</p></body></html>").arg(info.fileName()));
|
|
||||||
msgBox.setDetailedText(process.errorString());
|
|
||||||
msgBox.exec();
|
|
||||||
|
|
||||||
return false;
|
// if (!mProcess->waitForFinished()) {
|
||||||
}
|
// QMessageBox msgBox;
|
||||||
|
// msgBox.setWindowTitle(tr("Error starting executable"));
|
||||||
|
// msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
// msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
// msgBox.setText(tr("<html><head/><body><p><b>Could not start %1</b></p> \
|
||||||
|
// <p>An error occurred while starting %1.</p> \
|
||||||
|
// <p>Press \"Show Details...\" for more information.</p></body></html>").arg(info.fileName()));
|
||||||
|
// msgBox.setDetailedText(mProcess->errorString());
|
||||||
|
// msgBox.exec();
|
||||||
|
|
||||||
if (process.exitCode() != 0 || process.exitStatus() == QProcess::CrashExit) {
|
// return false;
|
||||||
QString error(process.readAllStandardError());
|
// }
|
||||||
error.append(tr("\nArguments:\n"));
|
|
||||||
error.append(arguments.join(" "));
|
|
||||||
|
|
||||||
QMessageBox msgBox;
|
// if (mProcess->exitCode() != 0 || mProcess->exitStatus() == QProcess::CrashExit) {
|
||||||
msgBox.setWindowTitle(tr("Error running executable"));
|
// QString error(mProcess->readAllStandardError());
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
// error.append(tr("\nArguments:\n"));
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
// error.append(arguments.join(" "));
|
||||||
msgBox.setText(tr("<html><head/><body><p><b>Executable %1 returned an error</b></p> \
|
|
||||||
<p>An error occurred while running %1.</p> \
|
|
||||||
<p>Press \"Show Details...\" for more information.</p></body></html>").arg(info.fileName()));
|
|
||||||
msgBox.setDetailedText(error);
|
|
||||||
msgBox.exec();
|
|
||||||
|
|
||||||
return false;
|
// QMessageBox msgBox;
|
||||||
}
|
// msgBox.setWindowTitle(tr("Error running executable"));
|
||||||
|
// msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
// msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
// msgBox.setText(tr("<html><head/><body><p><b>Executable %1 returned an error</b></p> \
|
||||||
|
// <p>An error occurred while running %1.</p> \
|
||||||
|
// <p>Press \"Show Details...\" for more information.</p></body></html>").arg(info.fileName()));
|
||||||
|
// msgBox.setDetailedText(error);
|
||||||
|
// msgBox.exec();
|
||||||
|
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Process::ProcessInvoker::processError(QProcess::ProcessError error)
|
||||||
|
{
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle(tr("Error running executable"));
|
||||||
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.setText(tr("<html><head/><body><p><b>Executable %1 returned an error</b></p> \
|
||||||
|
<p>An error occurred while running %1.</p> \
|
||||||
|
<p>Press \"Show Details...\" for more information.</p></body></html>").arg(mName));
|
||||||
|
msgBox.setDetailedText(mProcess->errorString());
|
||||||
|
msgBox.exec();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Process::ProcessInvoker::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
|
{
|
||||||
|
if (exitCode != 0 || exitStatus == QProcess::CrashExit) {
|
||||||
|
QString error(mProcess->readAllStandardError());
|
||||||
|
error.append(tr("\nArguments:\n"));
|
||||||
|
error.append(mArguments.join(" "));
|
||||||
|
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle(tr("Error running executable"));
|
||||||
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.setText(tr("<html><head/><body><p><b>Executable %1 returned an error</b></p> \
|
||||||
|
<p>An error occurred while running %1.</p> \
|
||||||
|
<p>Press \"Show Details...\" for more information.</p></body></html>").arg(mName));
|
||||||
|
msgBox.setDetailedText(error);
|
||||||
|
msgBox.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
namespace Process
|
namespace Process
|
||||||
{
|
{
|
||||||
|
@ -10,13 +11,32 @@ namespace Process
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
ProcessInvoker();
|
|
||||||
~ProcessInvoker();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline static bool startProcess(const QString &name, bool detached = false) { return startProcess(name, QStringList(), detached); }
|
ProcessInvoker(QWidget *parent = 0);
|
||||||
bool static startProcess(const QString &name, const QStringList &arguments, bool detached = false);
|
~ProcessInvoker();
|
||||||
|
|
||||||
|
// void setProcessName(const QString &name);
|
||||||
|
// void setProcessArguments(const QStringList &arguments);
|
||||||
|
|
||||||
|
QProcess* getProcess();
|
||||||
|
// QString getProcessName();
|
||||||
|
// QStringList getProcessArguments();
|
||||||
|
|
||||||
|
// inline bool startProcess(bool detached = false) { return startProcess(mName, mArguments, detached); }
|
||||||
|
inline bool startProcess(const QString &name, bool detached = false) { return startProcess(name, QStringList(), detached); }
|
||||||
|
bool startProcess(const QString &name, const QStringList &arguments, bool detached = false);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QProcess *mProcess;
|
||||||
|
|
||||||
|
QString mName;
|
||||||
|
QStringList mArguments;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void processError(QProcess::ProcessError error);
|
||||||
|
void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>516</width>
|
<width>514</width>
|
||||||
<height>399</height>
|
<height>397</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -88,13 +88,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QComboBox" name="fileComboBox">
|
<widget class="QComboBox" name="settingsComboBox"/>
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>/home/user/.local/share/openmw/data/Morrowind.ini</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QPushButton" name="browseButton">
|
<widget class="QPushButton" name="browseButton">
|
||||||
|
|
Loading…
Reference in a new issue