Re-Initialize MinetestMapperExecutable after Settings changed
parent
df2f883282
commit
00f9704b86
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>483</width>
|
||||
<height>73</height>
|
||||
<height>86</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -31,44 +31,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="CancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ApplyButton">
|
||||
<property name="text">
|
||||
<string>Apply</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="OKButton">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="path_Minetestmapper">
|
||||
<property name="sizePolicy">
|
||||
|
@ -90,12 +52,59 @@
|
|||
<property name="text">
|
||||
<string>Mapper Location: </string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>path_Minetestmapper</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>path_Minetestmapper</tabstop>
|
||||
<tabstop>browseMapper</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="minetestmappergui.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ConfigDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>298</x>
|
||||
<y>60</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>270</x>
|
||||
<y>81</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ConfigDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>386</x>
|
||||
<y>68</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>422</x>
|
||||
<y>78</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
Tree getTree(void) const;
|
||||
QString getTreeString(void) const;
|
||||
|
||||
void setExecutableFile(const QString &program);
|
||||
signals:
|
||||
void stateChanged(const QString &str);
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue