summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Tanner <thosrtanner2@users.sourceforge.net>2015-08-05 22:40:49 +0100
committerTom Tanner <thosrtanner2@users.sourceforge.net>2015-08-05 22:40:49 +0100
commitb0982148609a8a6f0d73d801ec9fcd1a22930f98 (patch)
tree4075050e1b7bc8555ddafb71259c07134cc2dff5 /src
parent9f7bec01d00ffc518ac9ec0c52e1a7184ea3cfac (diff)
More work on the executables list
Apart from an off by one in the popup list which had crept back in, reworked the underlying code even more, which now seems to get the list behaving in a predictable way.
Diffstat (limited to 'src')
-rw-r--r--src/editexecutablesdialog.cpp23
-rw-r--r--src/executableslist.cpp41
-rw-r--r--src/executableslist.h63
-rw-r--r--src/mainwindow.cpp9
-rw-r--r--src/organizercore.cpp20
5 files changed, 94 insertions, 62 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp
index 47f9262d..998a4507 100644
--- a/src/editexecutablesdialog.cpp
+++ b/src/editexecutablesdialog.cpp
@@ -60,8 +60,7 @@ void EditExecutablesDialog::refreshExecutablesWidget()
for(; current != end; ++current) {
QListWidgetItem *newItem = new QListWidgetItem(current->m_Title);
- newItem->setTextColor((current->m_Flags & Executable::CustomExecutable) ? QColor(Qt::black)
- : QColor(Qt::darkGray));
+ newItem->setTextColor(current->isCustom() ? QColor(Qt::black) : QColor(Qt::darkGray));
ui->executablesListBox->addItem(newItem);
}
@@ -92,17 +91,16 @@ void EditExecutablesDialog::resetInput()
void EditExecutablesDialog::saveExecutable()
{
+ Executable::SettableFlags flags;
+ if (ui->closeCheckBox->isChecked()) flags |= Executable::CloseOnExecution;
+ if (ui->useAppIconCheckBox->isChecked()) flags |= Executable::UseApplicationIcon;
m_ExecutablesList.addExecutable(ui->titleEdit->text(),
QDir::fromNativeSeparators(ui->binaryEdit->text()),
ui->argumentsEdit->text(),
QDir::fromNativeSeparators(ui->workingDirEdit->text()),
- (ui->closeCheckBox->checkState() == Qt::Checked) ?
- ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE
- : ExecutableInfo::CloseMOStyle::DEFAULT_STAY,
ui->overwriteAppIDBox->isChecked() ?
ui->appIDOverwriteEdit->text() : "",
- ui->useAppIconCheckBox->isChecked() ?
- Executable::UseApplicationIcon : Executable::Flags());
+ flags);
}
@@ -214,7 +212,7 @@ bool EditExecutablesDialog::executableChanged()
|| selectedExecutable.m_SteamAppID != ui->appIDOverwriteEdit->text()
|| selectedExecutable.m_WorkingDirectory != QDir::fromNativeSeparators(ui->workingDirEdit->text())
|| selectedExecutable.m_BinaryInfo.absoluteFilePath() != QDir::fromNativeSeparators(ui->binaryEdit->text())
- || (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE) != ui->closeCheckBox->isChecked()
+ || selectedExecutable.closeOnExecution() != ui->closeCheckBox->isChecked()
|| selectedExecutable.usesOwnIcon() != ui->useAppIconCheckBox->isChecked();
} else {
return false;
@@ -281,14 +279,7 @@ void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex &cur
ui->binaryEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath()));
ui->argumentsEdit->setText(selectedExecutable.m_Arguments);
ui->workingDirEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_WorkingDirectory));
- ui->closeCheckBox->setChecked(selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE);
- if (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::NEVER_CLOSE) {
- ui->closeCheckBox->setEnabled(false);
- ui->closeCheckBox->setToolTip(tr("MO must be kept running or this application will not work correctly."));
- } else {
- ui->closeCheckBox->setEnabled(true);
- ui->closeCheckBox->setToolTip(tr("If checked, MO will be closed once the specified executable is run."));
- }
+ ui->closeCheckBox->setChecked(selectedExecutable.closeOnExecution());
ui->removeButton->setEnabled(selectedExecutable.isCustom());
ui->overwriteAppIDBox->setChecked(!selectedExecutable.m_SteamAppID.isEmpty());
if (!selectedExecutable.m_SteamAppID.isEmpty()) {
diff --git a/src/executableslist.cpp b/src/executableslist.cpp
index 5a870009..ffb87703 100644
--- a/src/executableslist.cpp
+++ b/src/executableslist.cpp
@@ -48,7 +48,6 @@ void ExecutablesList::init(IPluginGame *game)
info.binary().absoluteFilePath(),
info.arguments().join(" "),
info.workingDirectory().absolutePath(),
- info.closeMO(),
info.steamAppID());
}
}
@@ -133,19 +132,22 @@ void ExecutablesList::addExecutable(const QString &title,
const QString &executableName,
const QString &arguments,
const QString &workingDirectory,
- ExecutableInfo::CloseMOStyle closeMO,
const QString &steamAppID,
- Executable::Flags flags)
+ Executable::SettableFlags settable,
+ bool set_other,
+ Executable::OtherFlags other)
{
QFileInfo file(executableName);
auto existingExe = findExe(title);
if (existingExe != m_Executables.end()) {
existingExe->m_Title = title;
- existingExe->m_CloseMO = closeMO;
- existingExe->m_Flags = flags;
- if (flags & Executable::CustomExecutable) {
- // for pre-configured executables don't overwrite settings we didn't store
+ existingExe->m_SettableFlags = settable;
+ if (set_other) {
+ existingExe->m_OtherFlags = other;
+ }
+ // for pre-configured executables don't overwrite settings we didn't store
+ if (existingExe->isCustom()) {
existingExe->m_BinaryInfo = file;
existingExe->m_Arguments = arguments;
existingExe->m_WorkingDirectory = workingDirectory;
@@ -154,12 +156,12 @@ void ExecutablesList::addExecutable(const QString &title,
} else {
Executable newExe;
newExe.m_Title = title;
- newExe.m_CloseMO = closeMO;
newExe.m_BinaryInfo = file;
newExe.m_Arguments = arguments;
newExe.m_WorkingDirectory = workingDirectory;
newExe.m_SteamAppID = steamAppID;
- newExe.m_Flags = Executable::CustomExecutable | flags;
+ newExe.m_SettableFlags = settable;
+ newExe.m_OtherFlags = Executable::CustomExecutable | other;
m_Executables.push_back(newExe);
}
}
@@ -176,20 +178,22 @@ void ExecutablesList::remove(const QString &title)
}
-void ExecutablesList::addExecutableInternal(const QString &title, const QString &executableName,
- const QString &arguments, const QString &workingDirectory,
- ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID)
+void ExecutablesList::addExecutableInternal(const QString &title,
+ const QString &executableName,
+ const QString &arguments,
+ const QString &workingDirectory,
+ const QString &steamAppID)
{
QFileInfo file(executableName);
if (file.exists()) {
Executable newExe;
- newExe.m_CloseMO = closeMO;
newExe.m_BinaryInfo = file;
newExe.m_Title = title;
newExe.m_Arguments = arguments;
newExe.m_WorkingDirectory = workingDirectory;
newExe.m_SteamAppID = steamAppID;
- newExe.m_Flags = 0;
+ newExe.m_SettableFlags = 0;
+ newExe.m_OtherFlags = 0;
m_Executables.push_back(newExe);
}
}
@@ -197,8 +201,9 @@ void ExecutablesList::addExecutableInternal(const QString &title, const QString
void Executable::showOnToolbar(bool state)
{
- if (state)
- m_Flags |= ShowInToolbar;
- else
- m_Flags ^= ShowInToolbar;
+ if (state) {
+ m_OtherFlags |= ShowInToolbar;
+ } else {
+ m_OtherFlags &= ~ShowInToolbar;
+ }
}
diff --git a/src/executableslist.h b/src/executableslist.h
index 907b37aa..4aba4ce2 100644
--- a/src/executableslist.h
+++ b/src/executableslist.h
@@ -35,27 +35,38 @@ struct Executable {
QString m_Title;
QFileInfo m_BinaryInfo;
QString m_Arguments;
- MOBase::ExecutableInfo::CloseMOStyle m_CloseMO;
QString m_SteamAppID;
QString m_WorkingDirectory;
- enum Flag {
+ //These flags are set by other parts of the system and can't be
+ //changed when modifying from the custom executable window
+ enum OtherFlag__ {
CustomExecutable = 0x01,
- ShowInToolbar = 0x02,
- UseApplicationIcon = 0x04
+ ShowInToolbar = 0x02
};
+ Q_DECLARE_FLAGS(OtherFlags, OtherFlag__)
- Q_DECLARE_FLAGS(Flags, Flag)
+ OtherFlags m_OtherFlags;
- Flags m_Flags;
+ //These flags can be changed from the Custom Executable window.
+ enum SettableFlag__ {
+ CloseOnExecution = 0x01,
+ UseApplicationIcon = 0x02
+ };
+ Q_DECLARE_FLAGS(SettableFlags, SettableFlag__)
+
+ SettableFlags m_SettableFlags;
- bool isCustom() const { return m_Flags.testFlag(CustomExecutable); }
+ bool isCustom() const { return m_OtherFlags.testFlag(CustomExecutable); }
- bool shownOnToolbar() const { return m_Flags.testFlag(ShowInToolbar); }
+ bool shownOnToolbar() const { return m_OtherFlags.testFlag(ShowInToolbar); }
void showOnToolbar(bool state);
- bool usesOwnIcon() const { return m_Flags.testFlag(UseApplicationIcon); }
+ bool usesOwnIcon() const { return m_SettableFlags.testFlag(UseApplicationIcon); }
+
+ bool closeOnExecution() const { return m_SettableFlags.testFlag(CloseOnExecution); }
+
};
@@ -138,9 +149,24 @@ public:
const QString &executableName,
const QString &arguments,
const QString &workingDirectory,
- MOBase::ExecutableInfo::CloseMOStyle closeMO,
const QString &steamAppID,
- Executable::Flags flags);
+ Executable::SettableFlags settable
+ )
+ {
+ addExecutable(title, executableName, arguments, workingDirectory, steamAppID, settable, false, 0);
+ }
+
+ void addExecutable(const QString &title,
+ const QString &executableName,
+ const QString &arguments,
+ const QString &workingDirectory,
+ const QString &steamAppID,
+ Executable::SettableFlags settable,
+ Executable::OtherFlags other
+ )
+ {
+ addExecutable(title, executableName, arguments, workingDirectory, steamAppID, settable, true, other);
+ }
/**
* @brief remove the executable with the specified file name. This needs to be an absolute file path
@@ -177,8 +203,18 @@ private:
std::vector<Executable>::iterator findExe(const QString &title);
+ void addExecutable(const QString &title,
+ const QString &executableName,
+ const QString &arguments,
+ const QString &workingDirectory,
+ const QString &steamAppID,
+ Executable::SettableFlags settable,
+ bool set_other,
+ Executable::OtherFlags other
+ );
+
void addExecutableInternal(const QString &title, const QString &executableName, const QString &arguments,
- const QString &workingDirectory, MOBase::ExecutableInfo::CloseMOStyle closeMO,
+ const QString &workingDirectory,
const QString &steamAppID);
private:
@@ -187,6 +223,7 @@ private:
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::Flags)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::OtherFlags)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::SettableFlags)
#endif // EXECUTABLESLIST_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index dda0470e..f0e576fe 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -959,7 +959,7 @@ void MainWindow::startExeAction()
selectedExecutable.m_Arguments,
selectedExecutable.m_WorkingDirectory.length() != 0 ? selectedExecutable.m_WorkingDirectory
: selectedExecutable.m_BinaryInfo.absolutePath(),
- selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE,
+ selectedExecutable.closeOnExecution(),
selectedExecutable.m_SteamAppID);
} else {
qCritical("not an action?");
@@ -1619,7 +1619,7 @@ void MainWindow::on_startButton_clicked()
selectedExecutable.m_Arguments,
selectedExecutable.m_WorkingDirectory.length() != 0 ? selectedExecutable.m_WorkingDirectory
: selectedExecutable.m_BinaryInfo.absolutePath(),
- selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE,
+ selectedExecutable.closeOnExecution(),
selectedExecutable.m_SteamAppID);
}
@@ -1731,7 +1731,7 @@ void MainWindow::on_executablesListBox_currentIndexChanged(int index)
if (executablesList->isEnabled()) {
//I think the 2nd test is impossible
- if ((index == 0) || (index >= static_cast<int>(m_OrganizerCore.executablesList()->size()))) {
+ if ((index == 0) || (index > static_cast<int>(m_OrganizerCore.executablesList()->size()))) {
if (modifyExecutablesDialog()) {
setExecutableIndex(previousIndex);
}
@@ -3545,9 +3545,8 @@ void MainWindow::addAsExecutable()
binaryInfo.absoluteFilePath(),
arguments,
targetInfo.absolutePath(),
- ExecutableInfo::CloseMOStyle::DEFAULT_STAY,
QString(),
- Executable::CustomExecutable);
+ Executable::SettableFlags());
refreshExecutablesList();
}
} break;
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 1a81d33b..a4746ddd 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -229,7 +229,7 @@ QSettings::Status OrganizerCore::storeSettings(const QString &fileName)
settings.setValue("binary", item.m_BinaryInfo.absoluteFilePath());
settings.setValue("arguments", item.m_Arguments);
settings.setValue("workingDirectory", item.m_WorkingDirectory);
- settings.setValue("closeOnStart", item.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE);
+ settings.setValue("closeOnStart", item.closeOnExecution());
settings.setValue("steamAppID", item.m_SteamAppID);
}
}
@@ -327,22 +327,22 @@ void OrganizerCore::updateExecutablesList(QSettings &settings)
int numCustomExecutables = settings.beginReadArray("customExecutables");
for (int i = 0; i < numCustomExecutables; ++i) {
settings.setArrayIndex(i);
- ExecutableInfo::CloseMOStyle closeMO =
- settings.value("closeOnStart").toBool() ? ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE
- : ExecutableInfo::CloseMOStyle::DEFAULT_STAY;
- Executable::Flags flags;
- if (settings.value("custom", true).toBool()) flags |= Executable::CustomExecutable;
- if (settings.value("toolbar", false).toBool()) flags |= Executable::ShowInToolbar;
- if (settings.value("ownicon", false).toBool()) flags |= Executable::UseApplicationIcon;
+ Executable::OtherFlags other;
+ if (settings.value("custom", true).toBool()) other |= Executable::CustomExecutable;
+ if (settings.value("toolbar", false).toBool()) other |= Executable::ShowInToolbar;
+
+ Executable::SettableFlags settable;
+ if (settings.value("closeOnStart", false).toBool()) settable |= Executable::CloseOnExecution;
+ if (settings.value("ownicon", false).toBool()) settable |= Executable::UseApplicationIcon;
m_ExecutablesList.addExecutable(settings.value("title").toString(),
settings.value("binary").toString(),
settings.value("arguments").toString(),
settings.value("workingDirectory", "").toString(),
- closeMO,
settings.value("steamAppID", "").toString(),
- flags);
+ settable,
+ other);
}
settings.endArray();