From e1c8d00979793dd00a90d312ccdd275cf48dc4ad Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Sat, 18 Jul 2015 13:34:10 +0100 Subject: Reworked executable lists to not use 3 bools in addExecutable Think it's more readable --- src/executableslist.cpp | 61 ++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 49 deletions(-) (limited to 'src/executableslist.cpp') diff --git a/src/executableslist.cpp b/src/executableslist.cpp index 1f5fee51..ba2b5616 100644 --- a/src/executableslist.cpp +++ b/src/executableslist.cpp @@ -30,31 +30,6 @@ using namespace MOBase; using namespace MOShared; -static QDataStream &operator<<(QDataStream &out, const Executable &obj) -{ - out << obj.m_Title - << obj.m_BinaryInfo.absoluteFilePath() - << obj.m_Arguments - << static_cast::type>(obj.m_CloseMO) - << obj.m_SteamAppID - << obj.m_WorkingDirectory - << obj.m_Custom - << obj.m_Toolbar << obj.m_UseOwnIcon; - return out; -} - -static QDataStream &operator>>(QDataStream &in, Executable &obj) -{ - QString binaryTemp; - int closeStyleTemp; - in >> obj.m_Title >> binaryTemp >> obj.m_Arguments >> closeStyleTemp - >> obj.m_SteamAppID >> obj.m_WorkingDirectory >> obj.m_Custom >> obj.m_Toolbar >> obj.m_UseOwnIcon; - - obj.m_CloseMO = static_cast(closeStyleTemp); - obj.m_BinaryInfo.setFile(binaryTemp); - return in; -} - ExecutablesList::ExecutablesList() { } @@ -154,43 +129,31 @@ 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 ownicon) + Executable::Type custom, + Executable::Toolbar toolbar, + Executable::Icon ownicon) { QFileInfo file(executableName); auto existingExe = findExe(title); if (existingExe != m_Executables.end()) { existingExe->m_Title = title; - existingExe->m_Custom = custom; + existingExe->m_Type = custom; existingExe->m_CloseMO = closeMO; existingExe->m_Toolbar = toolbar; - if (custom) { + if (custom == Executable::Type::Custom) { // for pre-configured executables don't overwrite settings we didn't store existingExe->m_BinaryInfo = file; existingExe->m_Arguments = arguments; existingExe->m_WorkingDirectory = workingDirectory; existingExe->m_SteamAppID = steamAppID; - existingExe->m_UseOwnIcon = ownicon; + existingExe->m_Icon = ownicon; } } else { Executable newExe; @@ -200,9 +163,9 @@ void ExecutablesList::addExecutable(const QString &title, newExe.m_Arguments = arguments; newExe.m_WorkingDirectory = workingDirectory; newExe.m_SteamAppID = steamAppID; - newExe.m_Custom = true; + newExe.m_Type = Executable::Type::Custom; newExe.m_Toolbar = toolbar; - newExe.m_UseOwnIcon = ownicon; + newExe.m_Icon = ownicon; m_Executables.push_back(newExe); } } @@ -211,7 +174,7 @@ void ExecutablesList::addExecutable(const QString &title, void ExecutablesList::remove(const QString &title) { for (std::vector::iterator iter = m_Executables.begin(); iter != m_Executables.end(); ++iter) { - if (iter->m_Custom && iter->m_Title == title) { + if (iter->isCustom() && iter->m_Title == title) { m_Executables.erase(iter); break; } @@ -232,9 +195,9 @@ void ExecutablesList::addExecutableInternal(const QString &title, const QString newExe.m_Arguments = arguments; newExe.m_WorkingDirectory = workingDirectory; newExe.m_SteamAppID = steamAppID; - newExe.m_Custom = false; - newExe.m_Toolbar = false; - newExe.m_UseOwnIcon = false; + newExe.m_Type = Executable::Type::Game; + newExe.m_Toolbar = Executable::Toolbar::Disabled; + newExe.m_Icon = Executable::Icon::MO; m_Executables.push_back(newExe); } } -- cgit v1.3.1