started to refactor Application
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void Emotes::initialize()
|
||||
void Emotes::initialize(Application &app)
|
||||
{
|
||||
getApp()->accounts->twitch.currentUserChanged.connect([this] {
|
||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
||||
app.accounts->twitch.currentUserChanged.connect([this, &app] {
|
||||
auto currentUser = app.accounts->twitch.getCurrent();
|
||||
assert(currentUser);
|
||||
this->twitch.refresh(currentUser);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#define GIF_FRAME_LENGTH 33
|
||||
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
@@ -10,12 +12,10 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Emotes
|
||||
class Emotes final : public Singleton
|
||||
{
|
||||
public:
|
||||
~Emotes() = delete;
|
||||
|
||||
void initialize();
|
||||
virtual void initialize(Application &app) override;
|
||||
|
||||
bool isIgnoredEmote(const QString &emote);
|
||||
|
||||
|
||||
+29
-28
@@ -26,37 +26,38 @@ Fonts::Fonts()
|
||||
: chatFontFamily("/appearance/currentFontFamily", DEFAULT_FONT_FAMILY)
|
||||
, chatFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE)
|
||||
{
|
||||
qDebug() << "init FontManager";
|
||||
|
||||
this->chatFontFamily.connect([this](const std::string &, auto) {
|
||||
assertInGuiThread();
|
||||
|
||||
if (getApp()->windows) {
|
||||
getApp()->windows->incGeneration();
|
||||
}
|
||||
|
||||
for (auto &map : this->fontsByType_) {
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
|
||||
this->chatFontSize.connect([this](const int &, auto) {
|
||||
assertInGuiThread();
|
||||
|
||||
if (getApp()->windows) {
|
||||
getApp()->windows->incGeneration();
|
||||
}
|
||||
|
||||
for (auto &map : this->fontsByType_) {
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
|
||||
this->fontsByType_.resize(size_t(EndType));
|
||||
}
|
||||
|
||||
void Fonts::initialize(Application &app)
|
||||
{
|
||||
this->chatFontFamily.connect([this, &app](const std::string &, auto) {
|
||||
assertInGuiThread();
|
||||
|
||||
if (app.windows) {
|
||||
app.windows->incGeneration();
|
||||
}
|
||||
|
||||
for (auto &map : this->fontsByType_) {
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
|
||||
this->chatFontSize.connect([this, &app](const int &, auto) {
|
||||
assertInGuiThread();
|
||||
|
||||
if (app.windows) {
|
||||
app.windows->incGeneration();
|
||||
}
|
||||
|
||||
for (auto &map : this->fontsByType_) {
|
||||
map.clear();
|
||||
}
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
}
|
||||
|
||||
QFont Fonts::getFont(Fonts::Type type, float scale)
|
||||
{
|
||||
return this->getOrCreateFontData(type, scale).font;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QFontMetrics>
|
||||
@@ -11,11 +13,13 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Fonts : boost::noncopyable
|
||||
class Fonts final : public Singleton
|
||||
{
|
||||
public:
|
||||
Fonts();
|
||||
|
||||
virtual void initialize(Application &app) override;
|
||||
|
||||
// font data gets set in createFontData(...)
|
||||
enum Type : uint8_t {
|
||||
Tiny,
|
||||
|
||||
@@ -12,16 +12,13 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void Logging::initialize()
|
||||
void Logging::initialize(Application &app)
|
||||
{
|
||||
this->pathManager = getApp()->paths;
|
||||
}
|
||||
|
||||
void Logging::addMessage(const QString &channelName, MessagePtr message)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (!app->settings->enableLogging) {
|
||||
if (!getSettings()->enableLogging) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +27,7 @@ void Logging::addMessage(const QString &channelName, MessagePtr message)
|
||||
auto channel = new LoggingChannel(channelName);
|
||||
channel->addMessage(message);
|
||||
this->loggingChannels_.emplace(channelName,
|
||||
std::unique_ptr<LoggingChannel>(std::move(channel)));
|
||||
std::unique_ptr<LoggingChannel>(std::move(channel)));
|
||||
} else {
|
||||
it->second->addMessage(message);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#include "messages/Message.hpp"
|
||||
#include "singletons/helper/LoggingChannel.hpp"
|
||||
|
||||
@@ -9,16 +11,14 @@ namespace chatterino {
|
||||
|
||||
class Paths;
|
||||
|
||||
class Logging
|
||||
class Logging : public Singleton
|
||||
{
|
||||
Paths *pathManager = nullptr;
|
||||
|
||||
public:
|
||||
Logging() = default;
|
||||
|
||||
~Logging() = delete;
|
||||
|
||||
void initialize();
|
||||
virtual void initialize(Application &app) override;
|
||||
|
||||
void addMessage(const QString &channelName, MessagePtr message);
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#include <QThread>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class NativeMessaging
|
||||
class NativeMessaging final
|
||||
{
|
||||
public:
|
||||
// fourtf: don't add this class to the application class
|
||||
NativeMessaging();
|
||||
|
||||
~NativeMessaging() = delete;
|
||||
|
||||
class ReceiverThread : public QThread
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -114,4 +114,9 @@ void Paths::initSubDirectories()
|
||||
this->miscDirectory = makePath("Misc");
|
||||
}
|
||||
|
||||
Paths *getPaths()
|
||||
{
|
||||
return Paths::getInstance();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -45,4 +45,6 @@ private:
|
||||
boost::optional<bool> portable_;
|
||||
};
|
||||
|
||||
Paths *getPaths();
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -302,7 +302,7 @@ Resources::Resources()
|
||||
qDebug() << "init ResourceManager";
|
||||
}
|
||||
|
||||
void Resources::initialize()
|
||||
void Resources::initialize(Application &app)
|
||||
{
|
||||
this->loadDynamicTwitchBadges();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
|
||||
#include <QIcon>
|
||||
@@ -11,14 +13,14 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Resources
|
||||
class Resources : public Singleton
|
||||
{
|
||||
public:
|
||||
Resources();
|
||||
|
||||
~Resources() = delete;
|
||||
|
||||
void initialize();
|
||||
virtual void initialize(Application &app) override;
|
||||
|
||||
struct {
|
||||
QIcon left;
|
||||
|
||||
@@ -29,26 +29,11 @@ Settings &Settings::getInstance()
|
||||
|
||||
void Settings::initialize()
|
||||
{
|
||||
this->timestampFormat.connect([](auto, auto) {
|
||||
auto app = getApp();
|
||||
app->windows->layoutChannelViews();
|
||||
});
|
||||
|
||||
this->emoteScale.connect([](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
||||
|
||||
this->timestampFormat.connect([](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
||||
this->alternateMessageBackground.connect(
|
||||
[](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
||||
this->separateMessages.connect(
|
||||
[](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
||||
this->collpseMessagesMinLines.connect(
|
||||
[](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
||||
}
|
||||
|
||||
void Settings::load()
|
||||
{
|
||||
auto app = getApp();
|
||||
QString settingsPath = app->paths->settingsDirectory + "/settings.json";
|
||||
QString settingsPath = getPaths()->settingsDirectory + "/settings.json";
|
||||
|
||||
pajlada::Settings::SettingManager::load(qPrintable(settingsPath));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/SerializeCustom.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
@@ -10,13 +11,11 @@ namespace chatterino {
|
||||
|
||||
class WindowManager;
|
||||
|
||||
class Theme
|
||||
class Theme final : public Singleton
|
||||
{
|
||||
public:
|
||||
Theme();
|
||||
|
||||
~Theme() = delete;
|
||||
|
||||
inline bool isLightTheme() const
|
||||
{
|
||||
return this->isLight_;
|
||||
|
||||
@@ -206,17 +206,16 @@ Window *WindowManager::windowAt(int index)
|
||||
return this->windows_.at(index);
|
||||
}
|
||||
|
||||
void WindowManager::initialize()
|
||||
void WindowManager::initialize(Application &app)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
auto app = getApp();
|
||||
app->themes->repaintVisibleChatWidgets_.connect([this] { this->repaintVisibleChatWidgets(); });
|
||||
app.themes->repaintVisibleChatWidgets_.connect([this] { this->repaintVisibleChatWidgets(); });
|
||||
|
||||
assert(!this->initialized_);
|
||||
|
||||
// load file
|
||||
QString settingsPath = app->paths->settingsDirectory + SETTINGS_FILENAME;
|
||||
QString settingsPath = getPaths()->settingsDirectory + SETTINGS_FILENAME;
|
||||
QFile file(settingsPath);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
@@ -301,6 +300,22 @@ void WindowManager::initialize()
|
||||
mainWindow_->getNotebook().addPage(true);
|
||||
}
|
||||
|
||||
auto settings = getSettings();
|
||||
|
||||
settings->timestampFormat.connect([this](auto, auto) {
|
||||
auto app = getApp();
|
||||
this->layoutChannelViews();
|
||||
});
|
||||
|
||||
settings->emoteScale.connect([this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||
|
||||
settings->timestampFormat.connect([this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||
settings->alternateMessageBackground.connect(
|
||||
[this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||
settings->separateMessages.connect([this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||
settings->collpseMessagesMinLines.connect(
|
||||
[this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||
|
||||
this->initialized_ = true;
|
||||
}
|
||||
|
||||
@@ -321,9 +336,12 @@ void WindowManager::save()
|
||||
case Window::Type::Main:
|
||||
window_obj.insert("type", "main");
|
||||
break;
|
||||
|
||||
case Window::Type::Popup:
|
||||
window_obj.insert("type", "popup");
|
||||
break;
|
||||
|
||||
case Window::Type::Attached:;
|
||||
}
|
||||
|
||||
// window geometry
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/Singleton.hpp>
|
||||
|
||||
#include "widgets/Window.hpp"
|
||||
#include "widgets/splits/SplitContainer.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class WindowManager
|
||||
class WindowManager : public Singleton
|
||||
{
|
||||
public:
|
||||
WindowManager();
|
||||
~WindowManager() = delete;
|
||||
|
||||
static void encodeChannel(IndirectChannel channel, QJsonObject &obj);
|
||||
static IndirectChannel decodeChannel(const QJsonObject &obj);
|
||||
@@ -36,8 +37,8 @@ public:
|
||||
int windowCount();
|
||||
Window *windowAt(int index);
|
||||
|
||||
void save();
|
||||
void initialize();
|
||||
virtual void initialize(Application &app) override;
|
||||
virtual void save() override;
|
||||
void closeAll();
|
||||
|
||||
int getGeneration() const;
|
||||
|
||||
Reference in New Issue
Block a user