mirror-chatterino2/src/Application.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

244 lines
6.1 KiB
C++
Raw Normal View History

#pragma once
2019-09-22 10:53:39 +02:00
#include "common/Singleton.hpp"
#include "singletons/NativeMessaging.hpp"
#include <pajlada/signals.hpp>
#include <pajlada/signals/signal.hpp>
#include <QApplication>
#include <memory>
namespace chatterino {
class Args;
class TwitchIrcServer;
class ITwitchIrcServer;
class PubSub;
class CommandController;
class AccountController;
class NotificationController;
class HighlightController;
class HotkeyController;
class IUserDataController;
class UserDataController;
class ISoundController;
class SoundController;
class ITwitchLiveController;
class TwitchLiveController;
#ifdef CHATTERINO_HAVE_PLUGINS
class PluginController;
#endif
2018-06-28 20:03:04 +02:00
class Theme;
class WindowManager;
2018-06-28 19:51:07 +02:00
class Logging;
class Paths;
class Emotes;
2022-11-05 11:04:35 +01:00
class IEmotes;
2018-06-28 19:51:07 +02:00
class Settings;
class Fonts;
2018-08-11 12:47:03 +02:00
class Toasts;
class ChatterinoBadges;
class FfzBadges;
class SeventvBadges;
class ImageUploader;
class SeventvAPI;
class CrashHandler;
2022-05-22 15:00:18 +02:00
class IApplication
{
public:
IApplication();
virtual ~IApplication() = default;
static IApplication *instance;
virtual const Args &getArgs() = 0;
2022-05-22 15:00:18 +02:00
virtual Theme *getThemes() = 0;
virtual Fonts *getFonts() = 0;
2022-11-05 11:04:35 +01:00
virtual IEmotes *getEmotes() = 0;
2022-05-22 15:00:18 +02:00
virtual AccountController *getAccounts() = 0;
virtual HotkeyController *getHotkeys() = 0;
virtual WindowManager *getWindows() = 0;
virtual Toasts *getToasts() = 0;
virtual CrashHandler *getCrashHandler() = 0;
2022-05-22 15:00:18 +02:00
virtual CommandController *getCommands() = 0;
virtual HighlightController *getHighlights() = 0;
2022-05-22 15:00:18 +02:00
virtual NotificationController *getNotifications() = 0;
virtual ITwitchIrcServer *getTwitch() = 0;
virtual Logging *getChatLogger() = 0;
2022-05-22 15:00:18 +02:00
virtual ChatterinoBadges *getChatterinoBadges() = 0;
virtual FfzBadges *getFfzBadges() = 0;
virtual SeventvBadges *getSeventvBadges() = 0;
virtual IUserDataController *getUserData() = 0;
virtual ISoundController *getSound() = 0;
virtual ITwitchLiveController *getTwitchLiveController() = 0;
virtual ImageUploader *getImageUploader() = 0;
virtual SeventvAPI *getSeventvAPI() = 0;
2022-05-22 15:00:18 +02:00
};
class Application : public IApplication
{
const Args &args_;
2018-08-02 14:23:27 +02:00
std::vector<std::unique_ptr<Singleton>> singletons_;
int argc_{};
char **argv_{};
public:
2018-08-02 14:23:27 +02:00
static Application *instance;
Application(Settings &_settings, Paths &_paths, const Args &_args);
~Application() override;
Application(const Application &) = delete;
Application(Application &&) = delete;
Application &operator=(const Application &) = delete;
Application &operator=(Application &&) = delete;
2018-08-02 14:23:27 +02:00
void initialize(Settings &settings, Paths &paths);
void load();
2018-08-02 14:23:27 +02:00
void save();
int run(QApplication &qtApp);
friend void test();
2018-08-07 01:35:24 +02:00
Theme *const themes{};
Fonts *const fonts{};
Emotes *const emotes{};
AccountController *const accounts{};
HotkeyController *const hotkeys{};
2018-08-07 01:35:24 +02:00
WindowManager *const windows{};
2018-08-11 12:47:03 +02:00
Toasts *const toasts{};
ImageUploader *const imageUploader{};
SeventvAPI *const seventvAPI{};
CrashHandler *const crashHandler{};
2018-08-02 14:23:27 +02:00
2018-08-07 01:35:24 +02:00
CommandController *const commands{};
NotificationController *const notifications{};
HighlightController *const highlights{};
TwitchIrcServer *const twitch{};
ChatterinoBadges *const chatterinoBadges{};
FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{};
UserDataController *const userData{};
ISoundController *const sound{};
2018-08-02 14:23:27 +02:00
private:
TwitchLiveController *const twitchLiveController{};
const std::unique_ptr<Logging> logging;
public:
#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *const plugins{};
#endif
const Args &getArgs() override
{
return this->args_;
}
2022-05-22 15:00:18 +02:00
Theme *getThemes() override
{
return this->themes;
}
Fonts *getFonts() override
{
return this->fonts;
}
2022-11-05 11:04:35 +01:00
IEmotes *getEmotes() override;
2022-05-22 15:00:18 +02:00
AccountController *getAccounts() override
{
return this->accounts;
}
HotkeyController *getHotkeys() override
{
return this->hotkeys;
}
WindowManager *getWindows() override
{
return this->windows;
}
Toasts *getToasts() override
{
return this->toasts;
}
CrashHandler *getCrashHandler() override
{
return this->crashHandler;
}
2022-05-22 15:00:18 +02:00
CommandController *getCommands() override
{
return this->commands;
}
NotificationController *getNotifications() override
{
return this->notifications;
}
HighlightController *getHighlights() override
{
return this->highlights;
}
ITwitchIrcServer *getTwitch() override;
Logging *getChatLogger() override;
2022-05-22 15:00:18 +02:00
ChatterinoBadges *getChatterinoBadges() override
{
return this->chatterinoBadges;
}
FfzBadges *getFfzBadges() override
{
return this->ffzBadges;
}
SeventvBadges *getSeventvBadges() override
{
return this->seventvBadges;
}
IUserDataController *getUserData() override;
ISoundController *getSound() override;
ITwitchLiveController *getTwitchLiveController() override;
ImageUploader *getImageUploader() override
{
return this->imageUploader;
}
SeventvAPI *getSeventvAPI() override
{
return this->seventvAPI;
}
2022-05-22 15:00:18 +02:00
pajlada::Signals::NoArgSignal streamerModeChanged;
private:
2018-07-07 11:41:01 +02:00
void addSingleton(Singleton *singleton);
void initPubSub();
void initBttvLiveUpdates();
void initSeventvEventAPI();
2018-09-17 12:51:16 +02:00
void initNm(Paths &paths);
2018-08-02 14:23:27 +02:00
template <typename T,
typename = std::enable_if_t<std::is_base_of<Singleton, T>::value>>
T &emplace()
{
auto t = new T;
this->singletons_.push_back(std::unique_ptr<T>(t));
return *t;
}
2018-09-17 12:51:16 +02:00
template <typename T,
typename = std::enable_if_t<std::is_base_of<Singleton, T>::value>>
T &emplace(T *t)
{
this->singletons_.push_back(std::unique_ptr<T>(t));
return *t;
}
2018-09-17 12:51:16 +02:00
NativeMessagingServer nmServer{};
};
Application *getApp();
2022-05-22 15:00:18 +02:00
// Get an interface version of the Application class - should be preferred when possible for new code
IApplication *getIApp();
} // namespace chatterino