summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-12-09 20:02:28 +0100
committerTannin <devnull@localhost>2014-12-09 20:02:28 +0100
commit8634b97bea67744d2ac147f2c8b94b8e52c37acd (patch)
tree84f8f9557a4c7fb95f312252b9f08aa27a1b7811 /src
parent116a36b9439b27fe3ea7a5bed1f462792634d50d (diff)
all executables can now be repositioned, including auto-detected ones
Diffstat (limited to 'src')
-rw-r--r--src/executableslist.cpp40
-rw-r--r--src/executableslist.h14
-rw-r--r--src/main.cpp22
-rw-r--r--src/mainwindow.cpp10
4 files changed, 62 insertions, 24 deletions
diff --git a/src/executableslist.cpp b/src/executableslist.cpp
index 2c6754d7..210737a0 100644
--- a/src/executableslist.cpp
+++ b/src/executableslist.cpp
@@ -113,14 +113,14 @@ Executable &ExecutablesList::find(const QString &title)
}
-Executable *ExecutablesList::findExe(const QString &title)
+std::vector<Executable>::iterator ExecutablesList::findExe(const QString &title)
{
for (std::vector<Executable>::iterator iter = m_Executables.begin(); iter != m_Executables.end(); ++iter) {
if (iter->m_Title == title) {
- return &*iter;
+ return iter;
}
}
- return NULL;
+ return m_Executables.end();
}
@@ -133,8 +133,8 @@ bool ExecutablesList::titleExists(const QString &title) const
void ExecutablesList::addExecutable(const Executable &executable)
{
- Executable *existingExe = findExe(executable.m_Title);
- if (existingExe != NULL) {
+ auto existingExe = findExe(executable.m_Title);
+ if (existingExe != m_Executables.end()) {
*existingExe = executable;
} else {
m_Executables.push_back(executable);
@@ -142,13 +142,26 @@ void ExecutablesList::addExecutable(const Executable &executable)
}
+void ExecutablesList::position(const QString &title, bool toolbar, int pos)
+{
+ auto existingExe = findExe(title);
+ if (existingExe != m_Executables.end()) {
+ Executable temp = *existingExe;
+ temp.m_Toolbar = toolbar;
+ m_Executables.erase(existingExe);
+ m_Executables.insert(m_Executables.begin() + pos, temp);
+ }
+}
+
+
void ExecutablesList::addExecutable(const QString &title, const QString &executableName, const QString &arguments,
const QString &workingDirectory, CloseMOStyle closeMO, const QString &steamAppID,
- bool custom, bool toolbar)
+ bool custom, bool toolbar, int pos)
{
QFileInfo file(executableName);
- Executable *existingExe = findExe(title);
- if (existingExe != NULL) {
+ auto existingExe = findExe(title);
+
+ if (existingExe != m_Executables.end()) {
existingExe->m_Title = title;
existingExe->m_CloseMO = closeMO;
existingExe->m_BinaryInfo = file;
@@ -157,6 +170,11 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa
existingExe->m_SteamAppID = steamAppID;
existingExe->m_Custom = custom;
existingExe->m_Toolbar = toolbar;
+ if (pos >= 0) {
+ Executable temp = *existingExe;
+ m_Executables.erase(existingExe);
+ m_Executables.insert(m_Executables.begin() + pos, temp);
+ }
} else {
Executable newExe;
newExe.m_Title = title;
@@ -167,7 +185,11 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa
newExe.m_SteamAppID = steamAppID;
newExe.m_Custom = true;
newExe.m_Toolbar = toolbar;
- m_Executables.push_back(newExe);
+ if ((pos < 0) || (pos >= m_Executables.size())) {
+ m_Executables.push_back(newExe);
+ } else {
+ m_Executables.insert(m_Executables.begin() + pos, newExe);
+ }
}
}
diff --git a/src/executableslist.h b/src/executableslist.h
index 6f7771e5..09023a04 100644
--- a/src/executableslist.h
+++ b/src/executableslist.h
@@ -114,7 +114,17 @@ public:
* @param arguments arguments to pass to the executable
* @param closeMO if true, MO will be closed when the binary is started
**/
- void addExecutable(const QString &title, const QString &executableName, const QString &arguments, const QString &workingDirectory, MOShared::CloseMOStyle closeMO, const QString &steamAppID, bool custom, bool toolbar);
+ void addExecutable(const QString &title, const QString &executableName, const QString &arguments,
+ const QString &workingDirectory, MOShared::CloseMOStyle closeMO, const QString &steamAppID,
+ bool custom, bool toolbar, int pos = -1);
+
+ /**
+ * @brief change position of an executable which is expected to exist
+ * @param title title of the executable
+ * @param toolbar enable/disable placement on the toolbar
+ * @param pos new position for the executable
+ */
+ void position(const QString &title, bool toolbar, int pos);
/**
* @brief remove the executable with the specified file name. This needs to be an absolute file path
@@ -142,7 +152,7 @@ public:
private:
- Executable *findExe(const QString &title);
+ std::vector<Executable>::iterator findExe(const QString &title);
void addExecutableInternal(const QString &title, const QString &executableName, const QString &arguments, const QString &workingDirectory, MOShared::CloseMOStyle closeMO, const QString &steamAppID);
diff --git a/src/main.cpp b/src/main.cpp
index d645f2aa..e0e91c40 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -464,14 +464,20 @@ int main(int argc, char *argv[])
for (int i = 0; i < numCustomExecutables; ++i) {
settings.setArrayIndex(i);
CloseMOStyle closeMO = settings.value("closeOnStart").toBool() ? DEFAULT_CLOSE : DEFAULT_STAY;
- executablesList.addExecutable(settings.value("title").toString(),
- settings.value("binary").toString(),
- settings.value("arguments").toString(),
- settings.value("workingDirectory", "").toString(),
- closeMO,
- settings.value("steamAppID", "").toString(),
- settings.value("custom", true).toBool(),
- settings.value("toolbar", false).toBool());
+ bool custom = settings.value("custom", true).toBool();
+ if (custom) {
+ executablesList.addExecutable(settings.value("title").toString(),
+ settings.value("binary").toString(),
+ settings.value("arguments").toString(),
+ settings.value("workingDirectory", "").toString(),
+ closeMO,
+ settings.value("steamAppID", "").toString(),
+ custom,
+ settings.value("toolbar", false).toBool(),
+ i);
+ } else {
+ executablesList.position(settings.value("title").toString(), settings.value("toolbar", false).toBool(), i);
+ }
}
settings.endArray();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 630184c9..8f23c0fa 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2248,16 +2248,16 @@ void MainWindow::storeSettings()
int count = 0;
for (; current != end; ++current) {
const Executable &item = *current;
- if (item.m_Custom || item.m_Toolbar) {
- settings.setArrayIndex(count++);
+ settings.setArrayIndex(count++);
+ settings.setValue("title", item.m_Title);
+ settings.setValue("custom", item.m_Custom);
+ settings.setValue("toolbar", item.m_Toolbar);
+ if (item.m_Custom) {
settings.setValue("binary", item.m_BinaryInfo.absoluteFilePath());
- settings.setValue("title", item.m_Title);
settings.setValue("arguments", item.m_Arguments);
settings.setValue("workingDirectory", item.m_WorkingDirectory);
settings.setValue("closeOnStart", item.m_CloseMO == DEFAULT_CLOSE);
settings.setValue("steamAppID", item.m_SteamAppID);
- settings.setValue("custom", item.m_Custom);
- settings.setValue("toolbar", item.m_Toolbar);
}
}
settings.endArray();