diff --git a/configdialog.cpp b/configdialog.cpp
index 7c53bdd..a21371e 100644
--- a/configdialog.cpp
+++ b/configdialog.cpp
@@ -57,13 +57,23 @@ ConfigDialog::~ConfigDialog()
delete ui;
}
+ConfigSettings ConfigDialog::getSettings() const
+{
+ return settings;
+}
+
+void ConfigDialog::setSettings(const ConfigSettings &value)
+{
+ settings = value;
+}
+
void ConfigDialog::on_browseMapper_clicked()
{
- #ifdef Q_OS_WIN
+#ifdef Q_OS_WIN
QString fileType = tr("Executable (*.exe)");
- #else
+#else
QString fileType;
- #endif
+#endif
bool selectionSeemsOK;
QString fileName;
@@ -180,18 +190,11 @@ void ConfigDialog::on_path_Minetestmapper_currentIndexChanged(int index)
-void ConfigDialog::on_CancelButton_clicked()
+void ConfigDialog::on_buttonBox_clicked(QAbstractButton *button)
{
- application->closeConfigDialog();
-}
-
-void ConfigDialog::on_ApplyButton_clicked()
-{
- application->updateConfigSettings(settings);
-}
-
-void ConfigDialog::on_OKButton_clicked()
-{
- on_ApplyButton_clicked();
- on_CancelButton_clicked();
+ QDialogButtonBox::StandardButton b = ui->buttonBox->standardButton(button);
+ if(b== QDialogButtonBox::RestoreDefaults)
+ {
+ ui->path_Minetestmapper->setCurrentIndex(0);
+ }
}
diff --git a/configdialog.h b/configdialog.h
index 61cfc36..7646485 100644
--- a/configdialog.h
+++ b/configdialog.h
@@ -37,6 +37,9 @@ public:
explicit ConfigDialog(const ConfigSettings &settings, MainWindow *app, QWidget *parent = 0);
~ConfigDialog();
+ ConfigSettings getSettings() const;
+ void setSettings(const ConfigSettings &value);
+
private:
Ui::ConfigDialog *ui;
QStringList executableList;
@@ -50,10 +53,7 @@ private slots:
void on_browseMapper_clicked();
void on_path_Minetestmapper_currentIndexChanged(int index);
-
- void on_CancelButton_clicked();
- void on_ApplyButton_clicked();
- void on_OKButton_clicked();
+ void on_buttonBox_clicked(QAbstractButton *button);
};
#endif // CONFIGDIALOG_H
diff --git a/configdialog.ui b/configdialog.ui
index ff42ea4..72cca0c 100644
--- a/configdialog.ui
+++ b/configdialog.ui
@@ -7,7 +7,7 @@
0
0
483
- 73
+ 86
@@ -31,44 +31,6 @@
- -
-
-
-
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Cancel
-
-
-
- -
-
-
- Apply
-
-
-
- -
-
-
- OK
-
-
-
-
-
-
@@ -90,12 +52,59 @@
Mapper Location:
+
+ path_Minetestmapper
+
+
+
+ -
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults
+
+
+ path_Minetestmapper
+ browseMapper
+
-
+
+
+ buttonBox
+ accepted()
+ ConfigDialog
+ accept()
+
+
+ 298
+ 60
+
+
+ 270
+ 81
+
+
+
+
+ buttonBox
+ rejected()
+ ConfigDialog
+ reject()
+
+
+ 386
+ 68
+
+
+ 422
+ 78
+
+
+
+
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 33ddb08..d585b19 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -37,8 +37,7 @@ InitStatics::InitStatics(void)
MainWindow::MainWindow(bool portable, QWidget *parent) :
QMainWindow(parent),
- ui(new Ui::MainWindow),
- configDialog(NULL)
+ ui(new Ui::MainWindow)
{
#ifndef Q_OS_WIN
if (!migrateSettingsProfiles())
@@ -284,10 +283,6 @@ void MainWindow::changeEvent(QEvent* event)
MainWindow::~MainWindow()
{
- if (configDialog) {
- delete configDialog;
- configDialog = NULL;
- }
minetestMapper->cancel();
delete ui;
}
@@ -1127,33 +1122,19 @@ void MainWindow::on_tileorigin_clicked()
void MainWindow::on_actionPreferences_triggered()
{
- if (!configDialog) {
- configDialog = new ConfigDialog(currentSettings, this, this);
- configDialog->show();
- } else {
- configDialog->show();
- configDialog->activateWindow();
- }
-}
-
-void MainWindow::closeConfigDialog(void)
-{
- if (configDialog) {
- delete configDialog;
- configDialog = NULL;
- }
-}
-
-void MainWindow::updateConfigSettings(const ConfigSettings &newSettings)
-{
- if (newSettings.mapperPath != currentSettings.mapperPath) {
+ ConfigDialog *d = new ConfigDialog(currentSettings, this, this);
+ int ret = d->exec();
+ if(ret == ConfigDialog::Accepted)
+ {
// Update all 'auto' paths (colors files, ...) ???
// (currently there are none, but in the future,
// colors files could be searched for relative to the minetestmapper path.
// If the mapper path changes, the paths of the possible colors files
// may change as well
+ currentSettings = d->getSettings();
+ minetestMapper->setExecutableFile(currentSettings.mapperPath);
+ minetestMapper->init();
}
- currentSettings = newSettings;
}
void MainWindow::startColorsTxtAssistant(void)
diff --git a/mainwindow.h b/mainwindow.h
index b324407..65aa206 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -41,10 +41,6 @@ public:
explicit MainWindow(bool portable, QWidget *parent = 0);
~MainWindow();
- // Interaction with config dialog
- void closeConfigDialog(void);
- void updateConfigSettings(const ConfigSettings &newSettings);
-
public slots:
void startColorsTxtAssistant();
protected:
@@ -131,7 +127,6 @@ private:
QWinTaskbarProgress *taskbarProgress;
#endif
ConfigSettings currentSettings;
- ConfigDialog *configDialog;
void finishUiInitialisation(void);
diff --git a/minetestmapperexe.cpp b/minetestmapperexe.cpp
index e70f24d..70eac07 100644
--- a/minetestmapperexe.cpp
+++ b/minetestmapperexe.cpp
@@ -3,11 +3,21 @@
MinetestMapperExe::MinetestMapperExe(const QString &program, QObject *parent) : QObject(parent)
{
process = new QProcess(this);
- minetestMapperExecutableFile = program;
- process->setProgram(program);
+ setExecutableFile(program);
connect(process, SIGNAL(errorOccurred(QProcess::ProcessError)),
this, SLOT(errorOccured(QProcess::ProcessError)));
-
+ connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),
+ this, SLOT(finished(int,QProcess::ExitStatus)));
+ connect(process, SIGNAL(readyReadStandardOutput()),
+ this, SLOT(readStandardOutput()));
+ connect(process, SIGNAL(readyReadStandardError()),
+ this, SLOT(readStandardError()));
+}
+void MinetestMapperExe::setExecutableFile(const QString &program)
+{
+ state = Uninitialized;
+ minetestMapperExecutableFile = program;
+ process->setProgram(program);
}
QStringList MinetestMapperExe::getSupportedBackends() const
@@ -53,8 +63,7 @@ bool MinetestMapperExe::init(){
{
emit busyStateChanged(true);
emit progressRangeChanged(0, 0);
- connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),
- this, SLOT(finished(int,QProcess::ExitStatus)));
+
state = InitVersion;
emit stateChanged("Init Version...");
process->setArguments(QStringList("--version"));
@@ -159,48 +168,47 @@ bool MinetestMapperExe::initHelp()
void MinetestMapperExe::readStandardOutput(void)
{
static const QRegularExpression re("([0-9]{1,3})(\\%)");
- QByteArray outData = process->readAllStandardOutput();
- QString out = QString(outData).trimmed();
- if(!out.isEmpty()) {
- QRegularExpressionMatch match = re.match(out);
- if(match.hasMatch()){
- if(state == MappingStart)
- {
- state = MappingProgress;
- emit progressRangeChanged(0, 100);
+ if(state == MappingStart || state == MappingProgress || state == MappingEnd) {
+ QByteArray outData = process->readAllStandardOutput();
+ QString out = QString(outData).trimmed();
+ if(!out.isEmpty()) {
+ QRegularExpressionMatch match = re.match(out);
+ if(match.hasMatch()){
+ if(state == MappingStart)
+ {
+ state = MappingProgress;
+ emit progressRangeChanged(0, 100);
+ }
+ int percent = match.captured(1).toInt(); // percent == number
+ emit progressChanged(percent);
}
- int percent = match.captured(1).toInt(); // percent == number
- emit progressChanged(percent);
- }
- else {
- if(state == MappingProgress)
- {
+ else {
+ if(state == MappingProgress)
+ {
- state = MappingEnd;
- emit progressRangeChanged(0, 0);
+ state = MappingEnd;
+ emit progressRangeChanged(0, 0);
+ }
}
+ emit stateChanged(out);
+ emit mappingStandardOutput(out);
}
- emit stateChanged(out);
- emit mappingStandardOutput(out);
}
}
void MinetestMapperExe::readStandardError()
{
- const QByteArray outData = process->readAllStandardError();
- if(outData.length() >1) {
- const QString out = QString(outData).trimmed();
- emit mappingStandardError(out);
- }
+ if(state == MappingStart || state == MappingProgress || state == MappingEnd) {
+ const QByteArray outData = process->readAllStandardError();
+ if(outData.length() >1) {
+ const QString out = QString(outData).trimmed();
+ emit mappingStandardError(out);
+ }
+ }
}
void MinetestMapperExe::finishInitialization()
{
- connect(process, SIGNAL(readyReadStandardOutput()),
- this, SLOT(readStandardOutput()));
- connect(process, SIGNAL(readyReadStandardError()),
- this, SLOT(readStandardError()));
-
emit initialisationFinished(true);
}
diff --git a/minetestmapperexe.h b/minetestmapperexe.h
index 8206aa6..c0a079f 100644
--- a/minetestmapperexe.h
+++ b/minetestmapperexe.h
@@ -52,6 +52,7 @@ public:
Tree getTree(void) const;
QString getTreeString(void) const;
+ void setExecutableFile(const QString &program);
signals:
void stateChanged(const QString &str);
/**