summaryrefslogtreecommitdiff
path: root/src/executableslist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/executableslist.cpp')
-rw-r--r--src/executableslist.cpp51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/executableslist.cpp b/src/executableslist.cpp
index 03f2b7c9..25b6bb0f 100644
--- a/src/executableslist.cpp
+++ b/src/executableslist.cpp
@@ -123,14 +123,25 @@ Executable &ExecutablesList::find(const QString &title)
}
-Executable *ExecutablesList::findExe(const QString &title)
+Executable &ExecutablesList::findByBinary(const QFileInfo &info)
+{
+ for (std::vector<Executable>::iterator iter = m_Executables.begin(); iter != m_Executables.end(); ++iter) {
+ if (info == iter->m_BinaryInfo) {
+ return *iter;
+ }
+ }
+ throw std::runtime_error("invalid info");
+}
+
+
+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 nullptr;
+ return m_Executables.end();
}
@@ -143,8 +154,8 @@ bool ExecutablesList::titleExists(const QString &title) const
void ExecutablesList::addExecutable(const Executable &executable)
{
- Executable *existingExe = findExe(executable.m_Title);
- if (existingExe != nullptr) {
+ auto existingExe = findExe(executable.m_Title);
+ if (existingExe != m_Executables.end()) {
*existingExe = executable;
} else {
m_Executables.push_back(executable);
@@ -152,13 +163,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, ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID,
- bool custom, bool toolbar)
+ bool custom, bool toolbar, int pos)
{
QFileInfo file(executableName);
- Executable *existingExe = findExe(title);
- if (existingExe != nullptr) {
+ auto existingExe = findExe(title);
+
+ if (existingExe != m_Executables.end()) {
existingExe->m_Title = title;
existingExe->m_CloseMO = closeMO;
existingExe->m_BinaryInfo = file;
@@ -167,6 +191,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;
@@ -177,7 +206,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 >= static_cast<int>(m_Executables.size()))) {
+ m_Executables.push_back(newExe);
+ } else {
+ m_Executables.insert(m_Executables.begin() + pos, newExe);
+ }
}
}