Skip to content

Commit a394f02

Browse files
Add executables list to plugin API (#2327)
1 parent aa44561 commit a394f02

6 files changed

Lines changed: 132 additions & 6 deletions

File tree

src/executableslist.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ void ExecutablesList::dump() const
364364
flags.push_back("hide");
365365
}
366366

367+
if (e.flags() & Executable::MinimizeToSystemTray) {
368+
flags.push_back("minimizeToSystemTray");
369+
}
370+
367371
log::debug(" . executable '{}'\n"
368372
" binary: {}\n"
369373
" arguments: {}\n"

src/executableslist.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
2828
#include <QFileInfo>
2929
#include <QMetaType>
3030

31+
#include <uibase/iexecutable.h>
32+
3133
namespace MOBase
3234
{
3335
class IPluginGame;
@@ -38,7 +40,7 @@ class Settings;
3840
/*!
3941
* @brief Information about an executable
4042
**/
41-
class Executable
43+
class Executable : public MOBase::IExecutable
4244
{
4345
public:
4446
enum Flag
@@ -58,11 +60,11 @@ class Executable
5860
*/
5961
Executable(const MOBase::ExecutableInfo& info, Flags flags);
6062

61-
const QString& title() const;
62-
const QFileInfo& binaryInfo() const;
63-
const QString& arguments() const;
64-
const QString& steamAppID() const;
65-
const QString& workingDirectory() const;
63+
const QString& title() const override;
64+
const QFileInfo& binaryInfo() const override;
65+
const QString& arguments() const override;
66+
const QString& steamAppID() const override;
67+
const QString& workingDirectory() const override;
6668
Flags flags() const;
6769

6870
Executable& title(const QString& s);

src/executableslistproxy.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright (C) 2012 Sebastian Herbord. All rights reserved.
3+
4+
This file is part of Mod Organizer.
5+
6+
Mod Organizer is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Mod Organizer is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "executableslistproxy.h"
21+
22+
#include "executableslist.h"
23+
24+
#include <generator>
25+
#include <stdexcept>
26+
27+
#include <QFileInfo>
28+
#include <QString>
29+
30+
ExecutablesListProxy::ExecutablesListProxy(ExecutablesList* executablesList)
31+
: m_Proxied(executablesList)
32+
{}
33+
34+
std::generator<const MOBase::IExecutable&> ExecutablesListProxy::executables() const
35+
{
36+
for (const auto& exe : *m_Proxied) {
37+
co_yield exe;
38+
}
39+
}
40+
41+
const MOBase::IExecutable* ExecutablesListProxy::getByTitle(const QString& title) const
42+
{
43+
try {
44+
return &m_Proxied->get(title);
45+
} catch (const std::runtime_error&) {
46+
return nullptr;
47+
}
48+
}
49+
50+
const MOBase::IExecutable*
51+
ExecutablesListProxy::getByBinary(const QFileInfo& info) const
52+
{
53+
try {
54+
return &m_Proxied->getByBinary(info);
55+
} catch (const std::runtime_error&) {
56+
return nullptr;
57+
}
58+
}
59+
60+
bool ExecutablesListProxy::contains(const QString& title) const
61+
{
62+
return m_Proxied->titleExists(title);
63+
}

src/executableslistproxy.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright (C) 2012 Sebastian Herbord. All rights reserved.
3+
4+
This file is part of Mod Organizer.
5+
6+
Mod Organizer is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Mod Organizer is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef EXECUTABLESLISTPROXY_H
21+
#define EXECUTABLESLISTPROXY_H
22+
23+
#include "executableslist.h"
24+
25+
#include <generator>
26+
27+
#include <QFileInfo>
28+
#include <QString>
29+
30+
#include <uibase/iexecutable.h>
31+
#include <uibase/iexecutableslist.h>
32+
33+
class ExecutablesListProxy : public MOBase::IExecutablesList
34+
{
35+
public:
36+
ExecutablesListProxy(ExecutablesList* executablesList);
37+
std::generator<const MOBase::IExecutable&> executables() const override;
38+
const MOBase::IExecutable* getByTitle(const QString& title) const override;
39+
const MOBase::IExecutable* getByBinary(const QFileInfo& info) const override;
40+
bool contains(const QString& title) const override;
41+
42+
private:
43+
ExecutablesList* m_Proxied;
44+
};
45+
46+
#endif // EXECUTABLESLISTPROXY_H

src/organizerproxy.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "organizerproxy.h"
22

33
#include "downloadmanagerproxy.h"
4+
#include "executableslistproxy.h"
45
#include "gamefeaturesproxy.h"
56
#include "glob_matching.h"
67
#include "instancemanager.h"
@@ -28,6 +29,8 @@ OrganizerProxy::OrganizerProxy(OrganizerCore* organizer,
2829
m_DownloadManagerProxy(
2930
std::make_unique<DownloadManagerProxy>(this, organizer->downloadManager())),
3031
m_ModListProxy(std::make_unique<ModListProxy>(this, organizer->modList())),
32+
m_ExecutablesListProxy(
33+
std::make_unique<ExecutablesListProxy>(organizer->executablesList())),
3134
m_PluginListProxy(
3235
std::make_unique<PluginListProxy>(this, organizer->pluginList())),
3336
m_GameFeaturesProxy(
@@ -365,6 +368,11 @@ MOBase::IModList* OrganizerProxy::modList() const
365368
return m_ModListProxy.get();
366369
}
367370

371+
MOBase::IExecutablesList* OrganizerProxy::executablesList() const
372+
{
373+
return m_ExecutablesListProxy.get();
374+
}
375+
368376
MOBase::IGameFeatures* OrganizerProxy::gameFeatures() const
369377
{
370378
return m_GameFeaturesProxy.get();

src/organizerproxy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class GameFeaturesProxy;
1212
class PluginContainer;
1313
class DownloadManagerProxy;
14+
class ExecutablesListProxy;
1415
class ModListProxy;
1516
class PluginListProxy;
1617

@@ -65,6 +66,7 @@ class OrganizerProxy : public MOBase::IOrganizer
6566
MOBase::IDownloadManager* downloadManager() const override;
6667
MOBase::IPluginList* pluginList() const override;
6768
MOBase::IModList* modList() const override;
69+
MOBase::IExecutablesList* executablesList() const override;
6870
std::shared_ptr<MOBase::IProfile> profile() const override;
6971
QStringList profileNames() const override;
7072
std::shared_ptr<const MOBase::IProfile>
@@ -157,6 +159,7 @@ class OrganizerProxy : public MOBase::IOrganizer
157159
std::unique_ptr<DownloadManagerProxy> m_DownloadManagerProxy;
158160
std::unique_ptr<ModListProxy> m_ModListProxy;
159161
std::unique_ptr<PluginListProxy> m_PluginListProxy;
162+
std::unique_ptr<ExecutablesListProxy> m_ExecutablesListProxy;
160163
std::unique_ptr<GameFeaturesProxy> m_GameFeaturesProxy;
161164
};
162165

0 commit comments

Comments
 (0)