put singletons into their namespace

This commit is contained in:
2017-12-31 22:58:35 +01:00
parent ad001431f2
commit 5a26d5f17f
72 changed files with 357 additions and 288 deletions

View file

@ -118,7 +118,7 @@ HEADERS += \
src/precompiled_headers.hpp \
src/asyncexec.hpp \
src/channel.hpp \
src/concurrentmap.hpp \
src/util/concurrentmap.hpp \
src/emojis.hpp \
src/singletons/ircmanager.hpp \
src/messages/lazyloadedimage.hpp \
@ -194,7 +194,8 @@ HEADERS += \
src/twitch/twitchaccountmanager.hpp \
src/singletons/helper/completionmodel.hpp \
src/singletons/helper/chatterinosetting.hpp \
src/singletons/resourcemanager.hpp
src/singletons/resourcemanager.hpp \
src/util/emotemap.hpp
PRECOMPILED_HEADER =

View file

@ -6,6 +6,8 @@
#include "singletons/thememanager.hpp"
#include "singletons/windowmanager.hpp"
using namespace chatterino::singletons;
namespace chatterino {
// this class is responsible for handling the workflow of Chatterino
@ -13,41 +15,43 @@ namespace chatterino {
Application::Application()
{
logging::init();
SettingsManager::getInstance().load();
singletons::WindowManager::getInstance();
WindowManager::getInstance().initMainWindow();
logging::init();
singletons::SettingManager::getInstance().load();
singletons::WindowManager::getInstance().initMainWindow();
// Initialize everything we need
EmoteManager::getInstance().loadGlobalEmotes();
singletons::EmoteManager::getInstance().loadGlobalEmotes();
AccountManager::getInstance().load();
singletons::AccountManager::getInstance().load();
// XXX
SettingsManager::getInstance().updateWordTypeMask();
singletons::SettingManager::getInstance().updateWordTypeMask();
}
Application::~Application()
{
this->save();
chatterino::SettingsManager::getInstance().save();
chatterino::singletons::SettingManager::getInstance().save();
}
int Application::run(QApplication &qtApp)
{
// Start connecting to the IRC Servers (Twitch only for now)
IrcManager::getInstance().connect();
singletons::IrcManager::getInstance().connect();
// Show main window
WindowManager::getInstance().getMainWindow().show();
singletons::WindowManager::getInstance().getMainWindow().show();
return qtApp.exec();
}
void Application::save()
{
WindowManager::getInstance().save();
singletons::WindowManager::getInstance().save();
}
} // namespace chatterino

View file

@ -1,9 +1,9 @@
#pragma once
#include "concurrentmap.hpp"
#include "logging/loggingchannel.hpp"
#include "messages/lazyloadedimage.hpp"
#include "messages/limitedqueue.hpp"
#include "util/concurrentmap.hpp"
#include <QMap>
#include <QMutex>

View file

@ -1,7 +1,7 @@
#pragma once
#include "concurrentmap.hpp"
#include "messages/lazyloadedimage.hpp"
#include "util/concurrentmap.hpp"
#include <QObject>
#include <QString>

View file

@ -90,5 +90,6 @@ int main(int argc, char *argv[])
// Deinitialize NetworkManager (stop thread and wait for finish, should be instant)
chatterino::util::NetworkManager::deinit();
exit(0);
return ret;
}

View file

@ -79,12 +79,12 @@ void LazyLoadedImage::loadImage()
lli->animated = true;
}
EmoteManager::getInstance().incGeneration();
singletons::EmoteManager::getInstance().incGeneration();
WindowManager::getInstance().layoutVisibleChatWidgets();
singletons::WindowManager::getInstance().layoutVisibleChatWidgets();
});
EmoteManager::getInstance().getGifUpdateSignal().connect([=]() {
singletons::EmoteManager::getInstance().getGifUpdateSignal().connect([=]() {
this->gifUpdateTimout();
}); // For some reason when Boost signal is in thread scope and thread deletes the signal
// doesn't work, so this is the fix.

View file

@ -83,14 +83,14 @@ void AddCurrentTimestamp(Message *message)
strftime(timeStampBuffer, 69, "%H:%M", localtime(&t));
QString timestampNoSeconds(timeStampBuffer);
message->getWords().push_back(Word(timestampNoSeconds, Word::TimestampNoSeconds,
MessageColor(MessageColor::System), FontManager::Medium,
MessageColor(MessageColor::System), singletons::FontManager::Medium,
QString(), QString()));
// Add word for timestamp with seconds
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&t));
QString timestampWithSeconds(timeStampBuffer);
message->getWords().push_back(Word(timestampWithSeconds, Word::TimestampWithSeconds,
MessageColor(MessageColor::System), FontManager::Medium,
MessageColor(MessageColor::System), singletons::FontManager::Medium,
QString(), QString()));
}
@ -108,7 +108,7 @@ Message *Message::createSystemMessage(const QString &text)
for (QString word : words) {
message->getWords().push_back(Word(word, Word::Flags::Default,
MessageColor(MessageColor::Type::System),
FontManager::Medium, word, QString()));
singletons::FontManager::Medium, word, QString()));
}
return message;
@ -149,7 +149,7 @@ Message *Message::createTimeoutMessage(const QString &username, const QString &d
text.append(".");
Word word(text, Word::Flags::Default, MessageColor(MessageColor::Type::System),
FontManager::Medium, text, QString());
singletons::FontManager::Medium, text, QString());
message->getWords().push_back(word);

View file

@ -40,13 +40,13 @@ void MessageBuilder::appendTimestamp(QDateTime &time)
// Add word for timestamp with no seconds
QString timestampNoSeconds(time.toString("hh:mm"));
this->appendWord(Word(timestampNoSeconds, Word::TimestampNoSeconds,
MessageColor(MessageColor::System), FontManager::Medium, QString(),
MessageColor(MessageColor::System), singletons::FontManager::Medium, QString(),
QString()));
// Add word for timestamp with seconds
QString timestampWithSeconds(time.toString("hh:mm:ss"));
this->appendWord(Word(timestampWithSeconds, Word::TimestampWithSeconds,
MessageColor(MessageColor::System), FontManager::Medium, QString(),
MessageColor(MessageColor::System), singletons::FontManager::Medium, QString(),
QString()));
}

View file

@ -19,7 +19,7 @@ MessageColor::Type MessageColor::getType() const
return this->type;
}
const QColor &MessageColor::getColor(ThemeManager &themeManager) const
const QColor &MessageColor::getColor(singletons::ThemeManager &themeManager) const
{
switch (this->type) {
case Type::Custom:

View file

@ -16,7 +16,7 @@ public:
explicit MessageColor(Type type = Text);
Type getType() const;
const QColor &getColor(ThemeManager &themeManager) const;
const QColor &getColor(singletons::ThemeManager &themeManager) const;
private:
Type type;

View file

@ -35,7 +35,7 @@ int MessageRef::getHeight() const
// return true if redraw is required
bool MessageRef::layout(int width, float scale)
{
auto &emoteManager = EmoteManager::getInstance();
auto &emoteManager = singletons::EmoteManager::getInstance();
bool rebuildRequired = false, layoutRequired = false;
@ -50,15 +50,15 @@ bool MessageRef::layout(int width, float scale)
this->emoteGeneration = emoteManager.getGeneration();
// check if text changed
bool textChanged = this->fontGeneration != FontManager::getInstance().getGeneration();
bool textChanged = this->fontGeneration != singletons::FontManager::getInstance().getGeneration();
layoutRequired |= textChanged;
this->fontGeneration = FontManager::getInstance().getGeneration();
this->fontGeneration = singletons::FontManager::getInstance().getGeneration();
// check if work mask changed
bool wordMaskChanged =
this->currentWordTypes != SettingsManager::getInstance().getWordTypeMask();
this->currentWordTypes != singletons::SettingManager::getInstance().getWordTypeMask();
layoutRequired |= wordMaskChanged;
this->currentWordTypes = SettingsManager::getInstance().getWordTypeMask();
this->currentWordTypes = singletons::SettingManager::getInstance().getWordTypeMask();
// check if dpi changed
bool scaleChanged = this->scale != scale;
@ -92,7 +92,7 @@ bool MessageRef::layout(int width, float scale)
void MessageRef::actuallyLayout(int width)
{
auto &settings = SettingsManager::getInstance();
auto &settings = singletons::SettingManager::getInstance();
const int spaceWidth = 4;
const int right = width - MARGIN_RIGHT;

View file

@ -18,8 +18,9 @@ Word::Word(LazyLoadedImage *image, Flags type, const QString &copytext, const QS
}
// Text word
Word::Word(const QString &text, Flags type, const MessageColor &color, FontManager::Type font,
const QString &copytext, const QString &tooltip, const Link &link)
Word::Word(const QString &text, Flags type, const MessageColor &color,
singletons::FontManager::Type font, const QString &copytext, const QString &tooltip,
const Link &link)
: image(nullptr)
, text(text)
, color(color)
@ -64,10 +65,11 @@ QSize Word::getSize(float scale) const
data.size.setHeight((int)(metrics.height()));
} else {
const int mediumTextLineHeight =
FontManager::getInstance().getFontMetrics(this->font, scale).height();
const qreal emoteScale = SettingsManager::getInstance().emoteScale.get() * scale;
singletons::FontManager::getInstance().getFontMetrics(this->font, scale).height();
const qreal emoteScale =
singletons::SettingManager::getInstance().emoteScale.get() * scale;
const bool scaleEmotesByLineHeight =
SettingsManager::getInstance().scaleEmotesByLineHeight;
singletons::SettingManager::getInstance().scaleEmotesByLineHeight;
auto &image = this->getImage();
@ -114,12 +116,12 @@ bool Word::hasTrailingSpace() const
QFont &Word::getFont(float scale) const
{
return FontManager::getInstance().getFont(this->font, scale);
return singletons::FontManager::getInstance().getFont(this->font, scale);
}
QFontMetrics &Word::getFontMetrics(float scale) const
{
return FontManager::getInstance().getFontMetrics(this->font, scale);
return singletons::FontManager::getInstance().getFontMetrics(this->font, scale);
}
Word::Flags Word::getFlags() const

View file

@ -96,7 +96,7 @@ public:
explicit Word(LazyLoadedImage *_image, Flags getFlags, const QString &copytext,
const QString &tooltip, const Link &getLink = Link());
explicit Word(const QString &_text, Flags getFlags, const MessageColor &textColor,
FontManager::Type font, const QString &copytext, const QString &tooltip,
singletons::FontManager::Type font, const QString &copytext, const QString &tooltip,
const Link &getLink = Link());
bool isImage() const;
@ -138,7 +138,7 @@ private:
int yOffset = 0;
bool _hasTrailingSpace = true;
FontManager::Type font = FontManager::Medium;
singletons::FontManager::Type font = singletons::FontManager::Medium;
Link link;
struct ScaleDependantData {

View file

@ -1,6 +1,7 @@
#include "singletons/accountmanager.hpp"
namespace chatterino {
namespace singletons {
namespace {
@ -43,3 +44,4 @@ void AccountManager::load()
}
} // namespace chatterino
}

View file

@ -3,6 +3,7 @@
#include "twitch/twitchaccountmanager.hpp"
namespace chatterino {
namespace singletons {
class AccountManager
{
@ -17,3 +18,4 @@ public:
};
} // namespace chatterino
}

View file

@ -4,6 +4,7 @@
using namespace chatterino::twitch;
namespace chatterino {
namespace singletons {
ChannelManager &ChannelManager::getInstance()
{
@ -138,3 +139,4 @@ void ChannelManager::doOnAll(std::function<void(std::shared_ptr<Channel>)> func)
}
} // namespace chatterino
}

View file

@ -7,8 +7,7 @@
#include <map>
namespace chatterino {
class WindowManager;
namespace singletons {
class IrcManager;
class ChannelManager
@ -43,7 +42,8 @@ private:
pajlada::Signals::Signal<const QString &> ircJoin;
pajlada::Signals::Signal<const QString &> ircPart;
friend class IrcManager;
friend class singletons::IrcManager;
};
} // namespace chatterino
}

View file

@ -3,6 +3,7 @@
#include <QRegularExpression>
namespace chatterino {
namespace singletons {
CommandManager &CommandManager::getInstance()
{
static CommandManager instance;
@ -81,3 +82,4 @@ CommandManager &CommandManager::getInstance()
// this->text = _text.mid(index + 1);
//}
}
}

View file

@ -4,6 +4,7 @@
#include <vector>
namespace chatterino {
namespace singletons {
class CommandManager
{
@ -36,3 +37,4 @@ public:
// std::vector<Command> commands;
};
}
}

View file

@ -5,6 +5,7 @@
#include "singletons/emotemanager.hpp"
namespace chatterino {
namespace singletons {
CompletionManager &CompletionManager::getInstance()
{
@ -26,3 +27,4 @@ CompletionModel *CompletionManager::createModel(const std::string &channelName)
}
} // namespace chatterino
}

View file

@ -8,6 +8,7 @@
#include "helper/completionmodel.hpp"
namespace chatterino {
namespace singletons {
class CompletionManager
{
CompletionManager() = default;
@ -22,3 +23,4 @@ private:
};
} // namespace chatterino
}

View file

@ -21,8 +21,9 @@
using namespace chatterino::messages;
namespace chatterino {
namespace singletons {
EmoteManager::EmoteManager(SettingsManager &_settingsManager, WindowManager &_windowManager)
EmoteManager::EmoteManager(SettingManager &_settingsManager, WindowManager &_windowManager)
: settingsManager(_settingsManager)
, windowManager(_windowManager)
, findShortCodesRegex(":([-+\\w]+):")
@ -38,7 +39,7 @@ EmoteManager::EmoteManager(SettingsManager &_settingsManager, WindowManager &_wi
EmoteManager &EmoteManager::getInstance()
{
static EmoteManager instance(SettingsManager::getInstance(), WindowManager::getInstance());
static EmoteManager instance(SettingManager::getInstance(), WindowManager::getInstance());
return instance;
}
@ -49,7 +50,8 @@ void EmoteManager::loadGlobalEmotes()
this->loadFFZEmotes();
}
void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName, std::weak_ptr<EmoteMap> _map)
void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName,
std::weak_ptr<util::EmoteMap> _map)
{
printf("[EmoteManager] Reload BTTV Channel Emotes for channel %s\n", qPrintable(channelName));
@ -88,7 +90,7 @@ void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName, std::weak
link = link.replace("{{id}}", id).replace("{{image}}", "1x");
auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [this, &code, &link] {
return EmoteData(
return util::EmoteData(
new LazyLoadedImage(link, 1, code, code + "<br/>Channel BTTV Emote"));
});
@ -101,7 +103,8 @@ void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName, std::weak
});
}
void EmoteManager::reloadFFZChannelEmotes(const QString &channelName, std::weak_ptr<EmoteMap> _map)
void EmoteManager::reloadFFZChannelEmotes(const QString &channelName,
std::weak_ptr<util::EmoteMap> _map)
{
printf("[EmoteManager] Reload FFZ Channel Emotes for channel %s\n", qPrintable(channelName));
@ -137,7 +140,7 @@ void EmoteManager::reloadFFZChannelEmotes(const QString &channelName, std::weak_
auto emote =
this->getFFZChannelEmoteFromCaches().getOrAdd(id, [this, &code, &url1] {
return EmoteData(
return util::EmoteData(
new LazyLoadedImage(url1, 1, code, code + "<br/>Channel FFZ Emote"));
});
@ -151,37 +154,37 @@ void EmoteManager::reloadFFZChannelEmotes(const QString &channelName, std::weak_
});
}
ConcurrentMap<QString, twitch::EmoteValue *> &EmoteManager::getTwitchEmotes()
util::ConcurrentMap<QString, twitch::EmoteValue *> &EmoteManager::getTwitchEmotes()
{
return _twitchEmotes;
}
EmoteMap &EmoteManager::getFFZEmotes()
util::EmoteMap &EmoteManager::getFFZEmotes()
{
return ffzGlobalEmotes;
}
EmoteMap &EmoteManager::getChatterinoEmotes()
util::EmoteMap &EmoteManager::getChatterinoEmotes()
{
return _chatterinoEmotes;
}
EmoteMap &EmoteManager::getBTTVChannelEmoteFromCaches()
util::EmoteMap &EmoteManager::getBTTVChannelEmoteFromCaches()
{
return _bttvChannelEmoteFromCaches;
}
EmoteMap &EmoteManager::getEmojis()
util::EmoteMap &EmoteManager::getEmojis()
{
return this->emojis;
}
ConcurrentMap<int, EmoteData> &EmoteManager::getFFZChannelEmoteFromCaches()
util::ConcurrentMap<int, util::EmoteData> &EmoteManager::getFFZChannelEmoteFromCaches()
{
return _ffzChannelEmoteFromCaches;
}
ConcurrentMap<long, EmoteData> &EmoteManager::getTwitchEmoteFromCache()
util::ConcurrentMap<long, util::EmoteData> &EmoteManager::getTwitchEmoteFromCache()
{
return _twitchEmoteFromCache;
}
@ -237,7 +240,8 @@ void EmoteManager::loadEmojis()
"emojione/2.2.6/assets/png/" +
code + ".png";
this->emojis.insert(code, EmoteData(new LazyLoadedImage(url, 0.35, ":" + shortCode + ":",
this->emojis.insert(code,
util::EmoteData(new LazyLoadedImage(url, 0.35, ":" + shortCode + ":",
":" + shortCode + ":<br/>Emoji")));
// TODO(pajlada): The vectors in emojiFirstByte need to be sorted by
@ -245,7 +249,7 @@ void EmoteManager::loadEmojis()
}
}
void EmoteManager::parseEmojis(std::vector<std::tuple<EmoteData, QString>> &parsedWords,
void EmoteManager::parseEmojis(std::vector<std::tuple<util::EmoteData, QString>> &parsedWords,
const QString &text)
{
int lastParsedEmojiEndIndex = 0;
@ -316,11 +320,12 @@ void EmoteManager::parseEmojis(std::vector<std::tuple<EmoteData, QString>> &pars
// Create or fetch cached emoji image
auto emojiImage = this->emojis.getOrAdd(matchedEmoji.code, [this, &url] {
return EmoteData(new LazyLoadedImage(url, 0.35, "?????????", "???????????????")); //
return util::EmoteData(
new LazyLoadedImage(url, 0.35, "?????????", "???????????????")); //
});
// Push the emoji as a word to parsedWords
parsedWords.push_back(std::tuple<EmoteData, QString>(emojiImage, QString()));
parsedWords.push_back(std::tuple<util::EmoteData, QString>(emojiImage, QString()));
lastParsedEmojiEndIndex = currentParsedEmojiEndIndex;
@ -482,7 +487,7 @@ void EmoteManager::loadFFZEmotes()
// id is used for lookup
// emoteName is used for giving a name to the emote in case it doesn't exist
EmoteData EmoteManager::getTwitchEmoteById(long id, const QString &emoteName)
util::EmoteData EmoteManager::getTwitchEmoteById(long id, const QString &emoteName)
{
return _twitchEmoteFromCache.getOrAdd(id, [this, &emoteName, &id] {
qreal scale;
@ -502,10 +507,10 @@ QString EmoteManager::getTwitchEmoteLink(long id, qreal &scale)
return value.replace("{id}", QString::number(id)).replace("{scale}", "2");
}
EmoteData EmoteManager::getCheerImage(long long amount, bool animated)
util::EmoteData EmoteManager::getCheerImage(long long amount, bool animated)
{
// TODO: fix this xD
return EmoteData();
return util::EmoteData();
}
boost::signals2::signal<void()> &EmoteManager::getGifUpdateSignal()
@ -535,3 +540,4 @@ boost::signals2::signal<void()> &EmoteManager::getGifUpdateSignal()
}
} // namespace chatterino
}

View file

@ -2,12 +2,13 @@
#define GIF_FRAME_LENGTH 33
#include "concurrentmap.hpp"
#include "emojis.hpp"
#include "messages/lazyloadedimage.hpp"
#include "signalvector.hpp"
#include "twitch/emotevalue.hpp"
#include "twitch/twitchuser.hpp"
#include "util/concurrentmap.hpp"
#include "util/emotemap.hpp"
#include <QMap>
#include <QMutex>
@ -17,28 +18,15 @@
#include <boost/signals2.hpp>
namespace chatterino {
namespace singletons {
class SettingsManager;
class SettingManager;
class WindowManager;
struct EmoteData {
EmoteData()
{
}
EmoteData(messages::LazyLoadedImage *_image)
: image(_image)
{
}
messages::LazyLoadedImage *image = nullptr;
};
typedef ConcurrentMap<QString, EmoteData> EmoteMap;
class EmoteManager
{
explicit EmoteManager(SettingsManager &manager, WindowManager &windowManager);
explicit EmoteManager(singletons::SettingManager &manager,
singletons::WindowManager &windowManager);
public:
static EmoteManager &getInstance();
@ -46,21 +34,21 @@ public:
void loadGlobalEmotes();
void reloadBTTVChannelEmotes(const QString &channelName,
std::weak_ptr<EmoteMap> channelEmoteMap);
std::weak_ptr<util::EmoteMap> channelEmoteMap);
void reloadFFZChannelEmotes(const QString &channelName,
std::weak_ptr<EmoteMap> channelEmoteMap);
std::weak_ptr<util::EmoteMap> channelEmoteMap);
ConcurrentMap<QString, twitch::EmoteValue *> &getTwitchEmotes();
EmoteMap &getFFZEmotes();
EmoteMap &getChatterinoEmotes();
EmoteMap &getBTTVChannelEmoteFromCaches();
EmoteMap &getEmojis();
ConcurrentMap<int, EmoteData> &getFFZChannelEmoteFromCaches();
ConcurrentMap<long, EmoteData> &getTwitchEmoteFromCache();
util::ConcurrentMap<QString, twitch::EmoteValue *> &getTwitchEmotes();
util::EmoteMap &getFFZEmotes();
util::EmoteMap &getChatterinoEmotes();
util::EmoteMap &getBTTVChannelEmoteFromCaches();
util::EmoteMap &getEmojis();
util::ConcurrentMap<int, util::EmoteData> &getFFZChannelEmoteFromCaches();
util::ConcurrentMap<long, util::EmoteData> &getTwitchEmoteFromCache();
EmoteData getCheerImage(long long int amount, bool animated);
util::EmoteData getCheerImage(long long int amount, bool animated);
EmoteData getTwitchEmoteById(long int id, const QString &emoteName);
util::EmoteData getTwitchEmoteById(long int id, const QString &emoteName);
int getGeneration()
{
@ -75,10 +63,10 @@ public:
boost::signals2::signal<void()> &getGifUpdateSignal();
// Bit badge/emotes?
ConcurrentMap<QString, messages::LazyLoadedImage *> miscImageCache;
util::ConcurrentMap<QString, messages::LazyLoadedImage *> miscImageCache;
private:
SettingsManager &settingsManager;
SettingManager &settingsManager;
WindowManager &windowManager;
/// Emojis
@ -91,12 +79,13 @@ private:
QMap<QChar, QVector<EmojiData>> emojiFirstByte;
// url Emoji-one image
EmoteMap emojis;
util::EmoteMap emojis;
void loadEmojis();
public:
void parseEmojis(std::vector<std::tuple<EmoteData, QString>> &parsedWords, const QString &text);
void parseEmojis(std::vector<std::tuple<util::EmoteData, QString>> &parsedWords,
const QString &text);
QString replaceShortCodes(const QString &text);
@ -123,41 +112,41 @@ public:
private:
// emote code
ConcurrentMap<QString, twitch::EmoteValue *> _twitchEmotes;
util::ConcurrentMap<QString, twitch::EmoteValue *> _twitchEmotes;
// emote id
ConcurrentMap<long, EmoteData> _twitchEmoteFromCache;
util::ConcurrentMap<long, util::EmoteData> _twitchEmoteFromCache;
/// BTTV emotes
EmoteMap bttvChannelEmotes;
util::EmoteMap bttvChannelEmotes;
public:
ConcurrentMap<QString, EmoteMap> bttvChannels;
EmoteMap bttvGlobalEmotes;
util::ConcurrentMap<QString, util::EmoteMap> bttvChannels;
util::EmoteMap bttvGlobalEmotes;
SignalVector<std::string> bttvGlobalEmoteCodes;
// roomID
std::map<std::string, SignalVector<std::string>> bttvChannelEmoteCodes;
EmoteMap _bttvChannelEmoteFromCaches;
util::EmoteMap _bttvChannelEmoteFromCaches;
private:
void loadBTTVEmotes();
/// FFZ emotes
EmoteMap ffzChannelEmotes;
util::EmoteMap ffzChannelEmotes;
public:
ConcurrentMap<QString, EmoteMap> ffzChannels;
EmoteMap ffzGlobalEmotes;
util::ConcurrentMap<QString, util::EmoteMap> ffzChannels;
util::EmoteMap ffzGlobalEmotes;
SignalVector<std::string> ffzGlobalEmoteCodes;
std::map<std::string, SignalVector<std::string>> ffzChannelEmoteCodes;
private:
ConcurrentMap<int, EmoteData> _ffzChannelEmoteFromCaches;
util::ConcurrentMap<int, util::EmoteData> _ffzChannelEmoteFromCaches;
void loadFFZEmotes();
/// Chatterino emotes
EmoteMap _chatterinoEmotes;
util::EmoteMap _chatterinoEmotes;
boost::signals2::signal<void()> gifUpdateTimerSignal;
QTimer gifUpdateTimer;
@ -170,3 +159,4 @@ private:
};
} // namespace chatterino
}

View file

@ -3,6 +3,7 @@
#include <QDebug>
namespace chatterino {
namespace singletons {
FontManager::FontManager()
: currentFontFamily("/appearance/currentFontFamily", "Arial")
@ -89,3 +90,4 @@ FontManager::Font &FontManager::getCurrentFont(float dpi)
return this->currentFontByDpi.back().second;
}
} // namespace chatterino
}

View file

@ -6,6 +6,7 @@
#include <pajlada/signals/signal.hpp>
namespace chatterino {
namespace singletons {
class FontManager
{
@ -133,3 +134,4 @@ private:
};
} // namespace chatterino
}

View file

@ -1,6 +1,7 @@
#pragma once
namespace chatterino {
namespace singletons {
static void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting);
template <typename Type>
@ -65,3 +66,4 @@ public:
}
};
}
}

View file

@ -7,6 +7,7 @@
#include "singletons/emotemanager.hpp"
namespace chatterino {
namespace singletons {
CompletionModel::CompletionModel(const QString &_channelName)
: channelName(_channelName)
{
@ -16,7 +17,7 @@ void CompletionModel::refresh()
{
// debug::Log("[CompletionModel:{}] Refreshing...]", this->channelName);
auto &emoteManager = EmoteManager::getInstance();
auto &emoteManager = singletons::EmoteManager::getInstance();
this->emotes.clear();
// User-specific: Twitch Emotes
@ -60,7 +61,7 @@ void CompletionModel::refresh()
}
// Channel-specific: Usernames
auto c = ChannelManager::getInstance().getTwitchChannel(this->channelName);
auto c = singletons::ChannelManager::getInstance().getTwitchChannel(this->channelName);
auto usernames = c->getUsernamesForCompletions();
for (const auto &name : usernames) {
assert(!name.displayName.isEmpty());
@ -86,3 +87,4 @@ void CompletionModel::addString(const QString &str)
this->emotes.push_back(str + " ");
}
}
}

View file

@ -7,6 +7,7 @@
#include <string>
namespace chatterino {
namespace singletons {
class CompletionModel : public QAbstractListModel
{
public:
@ -39,3 +40,4 @@ private:
QString channelName;
};
}
}

View file

@ -26,6 +26,7 @@
using namespace chatterino::messages;
namespace chatterino {
namespace singletons {
IrcManager::IrcManager(ChannelManager &_channelManager, ResourceManager &_resources,
AccountManager &_accountManager)
@ -70,7 +71,8 @@ IrcManager::IrcManager(ChannelManager &_channelManager, ResourceManager &_resour
IrcManager &IrcManager::getInstance()
{
static IrcManager instance(ChannelManager::getInstance(), ResourceManager::getInstance(),
static IrcManager instance(ChannelManager::getInstance(),
singletons::ResourceManager::getInstance(),
AccountManager::getInstance());
return instance;
}
@ -196,7 +198,7 @@ void IrcManager::sendMessage(const QString &channelName, QString message)
static int i = 0;
if (this->writeConnection) {
if (SettingsManager::getInstance().allowDuplicateMessages && (++i % 2) == 0) {
if (singletons::SettingManager::getInstance().allowDuplicateMessages && (++i % 2) == 0) {
message.append(this->messageSuffix);
}
this->writeConnection->sendRaw("PRIVMSG #" + channelName + " :" + message);
@ -528,3 +530,4 @@ Communi::IrcConnection *IrcManager::getReadConnection()
}
} // namespace chatterino
}

View file

@ -17,10 +17,12 @@
#include <mutex>
namespace chatterino {
namespace singletons {
class ChannelManager;
class ResourceManager;
class AccountManager;
class WindowManager;
class IrcManager : public QObject
{
@ -100,3 +102,4 @@ private:
};
} // namespace chatterino
}

View file

@ -6,6 +6,7 @@
#include <QPixmap>
namespace chatterino {
namespace singletons {
namespace {
@ -153,3 +154,4 @@ void ResourceManager::loadChatterinoBadges()
}
} // namespace chatterino
}

View file

@ -7,6 +7,7 @@
#include <mutex>
namespace chatterino {
namespace singletons {
class ResourceManager
{
@ -90,3 +91,4 @@ public:
};
} // namespace chatterino
}

View file

@ -8,6 +8,7 @@
using namespace chatterino::messages;
namespace chatterino {
namespace singletons {
std::vector<std::weak_ptr<pajlada::Settings::ISettingData>> _settings;
@ -16,7 +17,7 @@ void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting)
_settings.push_back(setting);
}
SettingsManager::SettingsManager()
SettingManager::SettingManager()
: streamlinkPath("/behaviour/streamlink/path", "")
, preferredQuality("/behaviour/streamlink/quality", "Choose")
, emoteScale(this->settingsItems, "emoteScale", 1.0)
@ -39,7 +40,7 @@ SettingsManager::SettingsManager()
};
}
void SettingsManager::save()
void SettingManager::save()
{
for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") {
@ -62,7 +63,7 @@ void SettingsManager::save()
}
}
void SettingsManager::load()
void SettingManager::load()
{
for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") {
@ -82,22 +83,22 @@ void SettingsManager::load()
}
}
Word::Flags SettingsManager::getWordTypeMask()
Word::Flags SettingManager::getWordTypeMask()
{
return this->wordTypeMask;
}
bool SettingsManager::isIgnoredEmote(const QString &)
bool SettingManager::isIgnoredEmote(const QString &)
{
return false;
}
QSettings &SettingsManager::getQSettings()
QSettings &SettingManager::getQSettings()
{
return this->settings;
}
void SettingsManager::updateWordTypeMask()
void SettingManager::updateWordTypeMask()
{
uint32_t newMaskUint = Word::Text;
@ -136,7 +137,7 @@ void SettingsManager::updateWordTypeMask()
}
}
void SettingsManager::saveSnapshot()
void SettingManager::saveSnapshot()
{
rapidjson::Document *d = new rapidjson::Document(rapidjson::kObjectType);
rapidjson::Document::AllocatorType &a = d->GetAllocator();
@ -157,7 +158,7 @@ void SettingsManager::saveSnapshot()
debug::Log("hehe: {}", pajlada::Settings::SettingManager::stringify(*d));
}
void SettingsManager::recallSnapshot()
void SettingManager::recallSnapshot()
{
if (!this->snapshot) {
return;
@ -184,3 +185,4 @@ void SettingsManager::recallSnapshot()
}
} // namespace chatterino
}

View file

@ -9,10 +9,11 @@
#include <pajlada/settings/settinglistener.hpp>
namespace chatterino {
namespace singletons {
static void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting);
class SettingsManager : public QObject
class SettingManager : public QObject
{
Q_OBJECT
@ -81,9 +82,9 @@ public:
BoolSetting inlineWhispers = {"/whispers/enableInlineWhispers", true};
static SettingsManager &getInstance()
static SettingManager &getInstance()
{
static SettingsManager instance;
static SettingManager instance;
return instance;
}
void updateWordTypeMask();
@ -97,7 +98,7 @@ signals:
private:
std::unique_ptr<rapidjson::Document> snapshot;
SettingsManager();
SettingManager();
QSettings settings;
std::vector<std::reference_wrapper<BaseSetting>> settingsItems;
@ -107,3 +108,4 @@ private:
};
} // namespace chatterino
}

View file

@ -7,6 +7,7 @@
#include <math.h>
namespace chatterino {
namespace singletons {
namespace detail {
@ -160,3 +161,4 @@ void ThemeManager::normalizeColor(QColor &color)
}
} // namespace chatterino
}

View file

@ -6,6 +6,7 @@
#include <pajlada/settings/setting.hpp>
namespace chatterino {
namespace singletons {
class WindowManager;
@ -107,3 +108,4 @@ private:
};
} // namespace chatterino
}

View file

@ -1,5 +1,6 @@
#include "windowmanager.hpp"
#include "appdatapath.hpp"
#include "singletons/fontmanager.hpp"
#include "singletons/thememanager.hpp"
#include <QDebug>
@ -7,6 +8,7 @@
#include <boost/foreach.hpp>
namespace chatterino {
namespace singletons {
WindowManager &WindowManager::getInstance()
{
static WindowManager instance(ThemeManager::getInstance());
@ -102,3 +104,4 @@ void WindowManager::save()
}
} // namespace chatterino
}

View file

@ -3,6 +3,7 @@
#include "widgets/window.hpp"
namespace chatterino {
namespace singletons {
class ThemeManager;
@ -41,3 +42,4 @@ private:
};
} // namespace chatterino
}

View file

@ -13,7 +13,9 @@
//
namespace chatterino {
namespace singletons {
class AccountManager;
}
namespace twitch {
@ -59,7 +61,7 @@ private:
std::vector<std::shared_ptr<twitch::TwitchUser>> users;
mutable std::mutex mutex;
friend class chatterino::AccountManager;
friend class chatterino::singletons::AccountManager;
};
}
}

View file

@ -11,8 +11,8 @@ namespace twitch {
TwitchChannel::TwitchChannel(const QString &channelName)
: Channel(channelName)
, bttvChannelEmotes(new EmoteMap)
, ffzChannelEmotes(new EmoteMap)
, bttvChannelEmotes(new util::EmoteMap)
, ffzChannelEmotes(new util::EmoteMap)
, subscriptionURL("https://www.twitch.tv/subs/" + name)
, channelURL("https://twitch.tv/" + name)
, popoutPlayerURL("https://player.twitch.tv/?channel=" + name)
@ -64,7 +64,7 @@ void TwitchChannel::setRoomID(const QString &_roomID)
void TwitchChannel::reloadChannelEmotes()
{
auto &emoteManager = EmoteManager::getInstance();
auto &emoteManager = singletons::EmoteManager::getInstance();
debug::Log("[TwitchChannel:{}] Reloading channel emotes", this->name);
@ -74,14 +74,14 @@ void TwitchChannel::reloadChannelEmotes()
void TwitchChannel::sendMessage(const QString &message)
{
auto &emoteManager = EmoteManager::getInstance();
auto &emoteManager = singletons::EmoteManager::getInstance();
debug::Log("[TwitchChannel:{}] Send message: {}", this->name, message);
// Do last message processing
QString parsedMessage = emoteManager.replaceShortCodes(message);
IrcManager::getInstance().sendMessage(this->name, parsedMessage);
singletons::IrcManager::getInstance().sendMessage(this->name, parsedMessage);
}
void TwitchChannel::setLive(bool newLiveStatus)
@ -155,7 +155,7 @@ void TwitchChannel::fetchRecentMessages()
{
static QString genericURL =
"https://tmi.twitch.tv/api/rooms/%1/recent_messages?client_id=" + getDefaultClientID();
static auto readConnection = IrcManager::getInstance().getReadConnection();
static auto readConnection = singletons::IrcManager::getInstance().getReadConnection();
util::twitch::get(genericURL.arg(roomID), QThread::currentThread(), [=](QJsonObject obj) {
this->dontAddMessages = false;
@ -165,7 +165,7 @@ void TwitchChannel::fetchRecentMessages()
QByteArray content = msgArray[i].toString().toUtf8();
auto msg = Communi::IrcMessage::fromData(content, readConnection);
auto privMsg = static_cast<Communi::IrcPrivateMessage *>(msg);
IrcManager::getInstance().privateMessageReceived(privMsg);
singletons::IrcManager::getInstance().privateMessageReceived(privMsg);
}
});
}

View file

@ -1,9 +1,9 @@
#pragma once
#include "channel.hpp"
#include "concurrentmap.hpp"
#include "singletons/emotemanager.hpp"
#include "singletons/ircmanager.hpp"
#include "util/concurrentmap.hpp"
namespace chatterino {
namespace twitch {
@ -22,8 +22,8 @@ public:
bool canSendMessage() const override;
void sendMessage(const QString &message) override;
const std::shared_ptr<chatterino::EmoteMap> bttvChannelEmotes;
const std::shared_ptr<chatterino::EmoteMap> ffzChannelEmotes;
const std::shared_ptr<chatterino::util::EmoteMap> bttvChannelEmotes;
const std::shared_ptr<chatterino::util::EmoteMap> ffzChannelEmotes;
const QString subscriptionURL;
const QString channelURL;

View file

@ -25,14 +25,14 @@ TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
, ircMessage(_ircMessage)
, args(_args)
, tags(this->ircMessage->tags())
, usernameColor(ThemeManager::getInstance().SystemMessageColor)
, usernameColor(singletons::ThemeManager::getInstance().SystemMessageColor)
{
}
SharedMessage TwitchMessageBuilder::parse()
{
SettingsManager &settings = SettingsManager::getInstance();
EmoteManager &emoteManager = EmoteManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
this->originalMessage = this->ircMessage->content();
@ -86,7 +86,7 @@ SharedMessage TwitchMessageBuilder::parse()
}
// twitch emotes
std::vector<std::pair<long, EmoteData>> twitchEmotes;
std::vector<std::pair<long, util::EmoteData>> twitchEmotes;
iterator = this->tags.find("emotes");
if (iterator != this->tags.end()) {
@ -97,8 +97,8 @@ SharedMessage TwitchMessageBuilder::parse()
}
struct {
bool operator()(const std::pair<long, EmoteData> &lhs,
const std::pair<long, EmoteData> &rhs)
bool operator()(const std::pair<long, util::EmoteData> &lhs,
const std::pair<long, util::EmoteData> &rhs)
{
return lhs.first < rhs.first;
}
@ -127,7 +127,7 @@ SharedMessage TwitchMessageBuilder::parse()
currentTwitchEmote->second.image->getName() + QString("\nTwitch Emote")));
this->appendWord(
Word(currentTwitchEmote->second.image->getName(), Word::TwitchEmoteText, textColor,
FontManager::Medium, currentTwitchEmote->second.image->getName(),
singletons::FontManager::Medium, currentTwitchEmote->second.image->getName(),
currentTwitchEmote->second.image->getName() + QString("\nTwitch Emote")));
i += split.length() + 1;
@ -137,13 +137,13 @@ SharedMessage TwitchMessageBuilder::parse()
}
// split words
std::vector<std::tuple<EmoteData, QString>> parsed;
std::vector<std::tuple<util::EmoteData, QString>> parsed;
// Parse emojis and take all non-emojis and put them in parsed as full text-words
emoteManager.parseEmojis(parsed, split);
for (const auto &tuple : parsed) {
const EmoteData &emoteData = std::get<0>(tuple);
const util::EmoteData &emoteData = std::get<0>(tuple);
if (emoteData.image == nullptr) { // is text
QString string = std::get<1>(tuple);
@ -200,7 +200,7 @@ SharedMessage TwitchMessageBuilder::parse()
this->appendWord(Word(
QString("x" + string.mid(5)), Word::BitsAmount, MessageColor(bitsColor),
FontManager::Medium, QString(string.mid(5)), QString("Twitch Cheer"),
singletons::FontManager::Medium, QString(string.mid(5)), QString("Twitch Cheer"),
Link(Link::Url,
QString("https://blog.twitch.tv/"
"introducing-cheering-celebrate-together-da62af41fac6"))));
@ -230,12 +230,12 @@ SharedMessage TwitchMessageBuilder::parse()
textColor = MessageColor(MessageColor::Link);
}
this->appendWord(Word(string, Word::Text, textColor, FontManager::Medium, string,
this->appendWord(Word(string, Word::Text, textColor, singletons::FontManager::Medium, string,
QString(), link));
} else { // is emoji
this->appendWord(Word(emoteData.image, Word::EmojiImage, emoteData.image->getName(),
emoteData.image->getTooltip()));
Word(emoteData.image->getName(), Word::EmojiText, textColor, FontManager::Medium,
Word(emoteData.image->getName(), Word::EmojiText, textColor, singletons::FontManager::Medium,
emoteData.image->getName(), emoteData.image->getTooltip());
}
}
@ -284,7 +284,7 @@ void TwitchMessageBuilder::parseChannelName()
{
QString channelName("#" + this->channel->name);
this->appendWord(Word(channelName, Word::Misc, MessageColor(MessageColor::System),
FontManager::Medium, QString(channelName), QString(),
singletons::FontManager::Medium, QString(channelName), QString(),
Link(Link::Url, this->channel->name + "\n" + this->messageID)));
}
@ -372,7 +372,7 @@ void TwitchMessageBuilder::appendUsername()
}
this->appendWord(Word(usernameString, Word::Username, MessageColor(this->usernameColor),
FontManager::MediumBold, usernameString, QString(),
singletons::FontManager::MediumBold, usernameString, QString(),
Link(Link::UserInfo, this->userName)));
}
@ -380,7 +380,7 @@ void TwitchMessageBuilder::parseHighlights()
{
static auto player = new QMediaPlayer;
static QUrl currentPlayerUrl;
SettingsManager &settings = SettingsManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
static pajlada::Settings::Setting<std::string> currentUser("/accounts/current");
QString currentUsername = QString::fromStdString(currentUser.getValue());
@ -471,7 +471,7 @@ void TwitchMessageBuilder::parseHighlights()
}
if (doAlert) {
QApplication::alert(WindowManager::getInstance().getMainWindow().window(), 2500);
QApplication::alert(singletons::WindowManager::getInstance().getMainWindow().window(), 2500);
}
}
}
@ -482,17 +482,17 @@ void TwitchMessageBuilder::appendModerationButtons()
static QString buttonBanTooltip("Ban user");
static QString buttonTimeoutTooltip("Timeout user");
this->appendWord(Word(ResourceManager::getInstance().buttonBan, Word::ButtonBan, QString(),
this->appendWord(Word(singletons::ResourceManager::getInstance().buttonBan, Word::ButtonBan, QString(),
buttonBanTooltip, Link(Link::UserBan, ircMessage->account())));
this->appendWord(Word(ResourceManager::getInstance().buttonTimeout, Word::ButtonTimeout, QString(),
this->appendWord(Word(singletons::ResourceManager::getInstance().buttonTimeout, Word::ButtonTimeout, QString(),
buttonTimeoutTooltip, Link(Link::UserTimeout, ircMessage->account())));
}
void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcPrivateMessage *ircMessage,
const QString &emote,
std::vector<std::pair<long int, EmoteData>> &vec)
std::vector<std::pair<long int, util::EmoteData>> &vec)
{
EmoteManager &emoteManager = EmoteManager::getInstance();
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
if (!emote.contains(':')) {
return;
}
@ -524,14 +524,14 @@ void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcPrivateMessage *i
QString name = ircMessage->content().mid(start, end - start + 1);
vec.push_back(
std::pair<long int, EmoteData>(start, emoteManager.getTwitchEmoteById(id, name)));
std::pair<long int, util::EmoteData>(start, emoteManager.getTwitchEmoteById(id, name)));
}
}
bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString)
{
EmoteManager &emoteManager = EmoteManager::getInstance();
EmoteData emoteData;
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
util::EmoteData emoteData;
if (emoteManager.bttvGlobalEmotes.tryGet(emoteString, emoteData)) {
// BTTV Global Emote
@ -555,7 +555,7 @@ bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString)
return false;
}
bool TwitchMessageBuilder::appendEmote(EmoteData &emoteData)
bool TwitchMessageBuilder::appendEmote(util::EmoteData &emoteData)
{
this->appendWord(Word(emoteData.image, Word::BttvEmoteImage, emoteData.image->getName(),
emoteData.image->getTooltip(),
@ -567,7 +567,7 @@ bool TwitchMessageBuilder::appendEmote(EmoteData &emoteData)
void TwitchMessageBuilder::parseTwitchBadges()
{
const auto &channelResources = ResourceManager::getInstance().channels[this->roomID];
const auto &channelResources = singletons::ResourceManager::getInstance().channels[this->roomID];
auto iterator = this->tags.find("badges");
@ -584,7 +584,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
}
if (badge.startsWith("bits/")) {
if (!ResourceManager::getInstance().dynamicBadgesLoaded) {
if (!singletons::ResourceManager::getInstance().dynamicBadgesLoaded) {
// Do nothing
continue;
}
@ -593,7 +593,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
std::string versionKey = cheerAmountQS.toStdString();
try {
auto &badgeSet = ResourceManager::getInstance().badgeSets.at("bits");
auto &badgeSet = singletons::ResourceManager::getInstance().badgeSets.at("bits");
try {
auto &badgeVersion = badgeSet.versions.at(versionKey);
@ -609,34 +609,34 @@ void TwitchMessageBuilder::parseTwitchBadges()
debug::Log("No badge set with key bits. Exception: {}", e.what());
}
} else if (badge == "staff/1") {
appendWord(Word(ResourceManager::getInstance().badgeStaff, Word::BadgeGlobalAuthority,
appendWord(Word(singletons::ResourceManager::getInstance().badgeStaff, Word::BadgeGlobalAuthority,
QString(), QString("Twitch Staff")));
} else if (badge == "admin/1") {
appendWord(Word(ResourceManager::getInstance().badgeAdmin, Word::BadgeGlobalAuthority,
appendWord(Word(singletons::ResourceManager::getInstance().badgeAdmin, Word::BadgeGlobalAuthority,
QString(), QString("Twitch Admin")));
} else if (badge == "global_mod/1") {
appendWord(Word(ResourceManager::getInstance().badgeGlobalModerator,
appendWord(Word(singletons::ResourceManager::getInstance().badgeGlobalModerator,
Word::BadgeGlobalAuthority, QString(), QString("Global Moderator")));
} else if (badge == "moderator/1") {
// TODO: Implement custom FFZ moderator badge
appendWord(Word(ResourceManager::getInstance().badgeModerator, Word::BadgeChannelAuthority,
appendWord(Word(singletons::ResourceManager::getInstance().badgeModerator, Word::BadgeChannelAuthority,
QString(),
QString("Channel Moderator"))); // custom badge
} else if (badge == "turbo/1") {
appendWord(Word(ResourceManager::getInstance().badgeTurbo, Word::BadgeVanity, QString(),
appendWord(Word(singletons::ResourceManager::getInstance().badgeTurbo, Word::BadgeVanity, QString(),
QString("Turbo Subscriber")));
} else if (badge == "broadcaster/1") {
appendWord(Word(ResourceManager::getInstance().badgeBroadcaster, Word::BadgeChannelAuthority,
appendWord(Word(singletons::ResourceManager::getInstance().badgeBroadcaster, Word::BadgeChannelAuthority,
QString(), QString("Channel Broadcaster")));
} else if (badge == "premium/1") {
appendWord(Word(ResourceManager::getInstance().badgePremium, Word::BadgeVanity, QString(),
appendWord(Word(singletons::ResourceManager::getInstance().badgePremium, Word::BadgeVanity, QString(),
QString("Twitch Prime")));
} else if (badge.startsWith("partner/")) {
int index = badge.midRef(8).toInt();
switch (index) {
case 1: {
appendWord(Word(ResourceManager::getInstance().badgeVerified, Word::BadgeVanity,
appendWord(Word(singletons::ResourceManager::getInstance().badgeVerified, Word::BadgeVanity,
QString(), "Twitch Verified"));
} break;
default: {
@ -652,7 +652,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
auto badgeSetIt = channelResources.badgeSets.find("subscriber");
if (badgeSetIt == channelResources.badgeSets.end()) {
// Fall back to default badge
appendWord(Word(ResourceManager::getInstance().badgeSubscriber,
appendWord(Word(singletons::ResourceManager::getInstance().badgeSubscriber,
Word::Flags::BadgeSubscription, QString(),
QString("Twitch Subscriber")));
continue;
@ -666,7 +666,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
if (badgeVersionIt == badgeSet.versions.end()) {
// Fall back to default badge
appendWord(Word(ResourceManager::getInstance().badgeSubscriber,
appendWord(Word(singletons::ResourceManager::getInstance().badgeSubscriber,
Word::Flags::BadgeSubscription, QString(),
QString("Twitch Subscriber")));
continue;
@ -677,7 +677,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
appendWord(Word(badgeVersion.badgeImage1x, Word::Flags::BadgeSubscription, QString(),
QString("Twitch " + QString::fromStdString(badgeVersion.title))));
} else {
if (!ResourceManager::getInstance().dynamicBadgesLoaded) {
if (!singletons::ResourceManager::getInstance().dynamicBadgesLoaded) {
// Do nothing
continue;
}
@ -695,7 +695,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
std::string versionKey = parts[1].toStdString();
try {
auto &badgeSet = ResourceManager::getInstance().badgeSets.at(badgeSetKey);
auto &badgeSet = singletons::ResourceManager::getInstance().badgeSets.at(badgeSetKey);
try {
auto &badgeVersion = badgeSet.versions.at(versionKey);
@ -717,7 +717,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
void TwitchMessageBuilder::parseChatterinoBadges()
{
auto &badges = ResourceManager::getInstance().chatterinoBadges;
auto &badges = singletons::ResourceManager::getInstance().chatterinoBadges;
auto it = badges.find(this->userName.toStdString());
if (it == badges.end()) {

View file

@ -10,10 +10,7 @@
#include <QVariant>
namespace chatterino {
class WindowManager;
class Channel;
class ThemeManager;
namespace twitch {
class TwitchChannel;
@ -61,9 +58,9 @@ private:
void appendModerationButtons();
void appendTwitchEmote(const Communi::IrcPrivateMessage *ircMessage, const QString &emote,
std::vector<std::pair<long, EmoteData>> &vec);
std::vector<std::pair<long, util::EmoteData>> &vec);
bool tryAppendEmote(QString &emoteString);
bool appendEmote(EmoteData &emoteData);
bool appendEmote(util::EmoteData &emoteData);
void parseTwitchBadges();
void parseChatterinoBadges();

View file

@ -9,6 +9,7 @@
#include <memory>
namespace chatterino {
namespace util {
template <typename TKey, typename TValue>
class ConcurrentMap
@ -84,3 +85,4 @@ private:
QMap<TKey, TValue> data;
};
} // namespace chatterino
}

24
src/util/emotemap.hpp Normal file
View file

@ -0,0 +1,24 @@
#pragma once
#include "messages/lazyloadedimage.hpp"
#include "util/concurrentmap.hpp"
namespace chatterino {
namespace util {
struct EmoteData {
EmoteData()
{
}
EmoteData(messages::LazyLoadedImage *_image)
: image(_image)
{
}
messages::LazyLoadedImage *image = nullptr;
};
typedef ConcurrentMap<QString, EmoteData> EmoteMap;
}
}

View file

@ -133,7 +133,7 @@ static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
{
QNetworkRequest request(url);
auto &accountManager = AccountManager::getInstance();
auto &accountManager = singletons::AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent();
QByteArray oauthToken;
if (currentTwitchUser) {

View file

@ -1,7 +1,7 @@
#include "widgets/accountpopup.hpp"
#include "singletons/accountmanager.hpp"
#include "channel.hpp"
#include "credentials.hpp"
#include "singletons/accountmanager.hpp"
#include "singletons/settingsmanager.hpp"
#include "ui_accountpopupform.h"
#include "util/urlfetch.hpp"
@ -32,7 +32,7 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> _channel)
this->resize(0, 0);
SettingsManager &settings = SettingsManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
this->permission = permissions::User;
for (auto button : this->ui->profileLayout->findChildren<QPushButton *>()) {
@ -59,7 +59,7 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> _channel)
this->sendCommand(this->ui->mod, "/mod ");
this->sendCommand(this->ui->unMod, "/unmod ");
auto &accountManager = AccountManager::getInstance();
auto &accountManager = singletons::AccountManager::getInstance();
QString userId;
QString userNickname;
auto currentTwitchUser = accountManager.Twitch.getCurrent();
@ -185,7 +185,8 @@ void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl)
void AccountPopupWidget::updatePermissions()
{
AccountManager &accountManager = AccountManager::getInstance();
singletons::AccountManager &accountManager = singletons::AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent();
if (!currentTwitchUser) {
// No twitch user set (should never happen)
@ -242,7 +243,7 @@ void AccountPopupWidget::focusOutEvent(QFocusEvent *)
void AccountPopupWidget::showEvent(QShowEvent *)
{
AccountManager &accountManager = AccountManager::getInstance();
singletons::AccountManager &accountManager = singletons::AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent();
if (!currentTwitchUser) {
// No twitch user set (should never happen)
@ -266,7 +267,8 @@ void AccountPopupWidget::showEvent(QShowEvent *)
this->updateButtons(this->ui->ownerLayout, false);
}
QString blacklisted = SettingsManager::getInstance().highlightUserBlacklist.getnonConst();
QString blacklisted =
singletons::SettingManager::getInstance().highlightUserBlacklist.getnonConst();
QStringList list = blacklisted.split("\n", QString::SkipEmptyParts);
if (list.contains(this->ui->lblUsername->text(), Qt::CaseInsensitive)) {
this->ui->disableHighlights->hide();

View file

@ -1,7 +1,7 @@
#pragma once
#include "basewidget.hpp"
#include "concurrentmap.hpp"
#include "util/concurrentmap.hpp"
#include "twitch/twitchchannel.hpp"
#include <QPushButton>
@ -52,7 +52,7 @@ private:
QString userID;
QPixmap avatar;
ConcurrentMap<QString, QPixmap> avatarMap;
util::ConcurrentMap<QString, QPixmap> avatarMap;
protected:
virtual void focusOutEvent(QFocusEvent *event) override;

View file

@ -1,6 +1,6 @@
#include "accountswitchwidget.hpp"
#include "singletons/accountmanager.hpp"
#include "const.hpp"
#include "singletons/accountmanager.hpp"
namespace chatterino {
namespace widgets {
@ -8,20 +8,22 @@ namespace widgets {
AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
: QListWidget(parent)
{
singletons::AccountManager &accountManager = singletons::AccountManager::getInstance();
this->addItem(ANONYMOUS_USERNAME_LABEL);
for (const auto &userName : AccountManager::getInstance().Twitch.getUsernames()) {
for (const auto &userName : accountManager.Twitch.getUsernames()) {
this->addItem(userName);
}
AccountManager::getInstance().Twitch.userListUpdated.connect([this]() {
accountManager.Twitch.userListUpdated.connect([this, &accountManager]() {
this->blockSignals(true);
this->clear();
this->addItem(ANONYMOUS_USERNAME_LABEL);
for (const auto &userName : AccountManager::getInstance().Twitch.getUsernames()) {
for (const auto &userName : accountManager.Twitch.getUsernames()) {
this->addItem(userName);
}
@ -32,13 +34,13 @@ AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
this->refreshSelection();
QObject::connect(this, &QListWidget::clicked, [this] {
QObject::connect(this, &QListWidget::clicked, [this, &accountManager] {
if (!this->selectedItems().isEmpty()) {
QString newUsername = this->currentItem()->text();
if (newUsername.compare(ANONYMOUS_USERNAME_LABEL, Qt::CaseInsensitive) == 0) {
AccountManager::getInstance().Twitch.currentUsername = "";
accountManager.Twitch.currentUsername = "";
} else {
AccountManager::getInstance().Twitch.currentUsername = newUsername.toStdString();
accountManager.Twitch.currentUsername = newUsername.toStdString();
}
}
});
@ -55,7 +57,7 @@ void AccountSwitchWidget::refreshSelection()
// Select the currently logged in user
if (this->count() > 0) {
auto currentUser = AccountManager::getInstance().Twitch.getCurrent();
auto currentUser = singletons::AccountManager::getInstance().Twitch.getCurrent();
if (currentUser->isAnon()) {
this->setCurrentRow(0);

View file

@ -12,7 +12,7 @@
namespace chatterino {
namespace widgets {
BaseWidget::BaseWidget(ThemeManager &_themeManager, QWidget *parent)
BaseWidget::BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent)
: QWidget(parent)
, themeManager(_themeManager)
{
@ -21,14 +21,14 @@ BaseWidget::BaseWidget(ThemeManager &_themeManager, QWidget *parent)
BaseWidget::BaseWidget(BaseWidget *parent)
: QWidget(parent)
, themeManager(ThemeManager::getInstance())
, themeManager(singletons::ThemeManager::getInstance())
{
this->init();
}
BaseWidget::BaseWidget(QWidget *parent)
: QWidget(parent)
, themeManager(ThemeManager::getInstance())
, themeManager(singletons::ThemeManager::getInstance())
{
}
@ -72,7 +72,7 @@ void BaseWidget::initAsWindow()
}
#endif
if (SettingsManager::getInstance().windowTopMost.getValue()) {
if (singletons::SettingManager::getInstance().windowTopMost.getValue()) {
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
}
}

View file

@ -3,8 +3,9 @@
#include <QWidget>
namespace chatterino {
namespace singletons {
class ThemeManager;
}
namespace widgets {
@ -13,13 +14,13 @@ class BaseWidget : public QWidget
Q_OBJECT
public:
explicit BaseWidget(ThemeManager &_themeManager, QWidget *parent);
explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent);
explicit BaseWidget(BaseWidget *parent);
explicit BaseWidget(QWidget *parent = nullptr);
ThemeManager &themeManager;
singletons::ThemeManager &themeManager;
float getDpiMultiplier();

View file

@ -12,7 +12,7 @@ using namespace chatterino::messages;
namespace chatterino {
namespace widgets {
EmotePopup::EmotePopup(ThemeManager &themeManager)
EmotePopup::EmotePopup(singletons::ThemeManager &themeManager)
: BaseWidget(themeManager, 0)
{
this->initAsWindow();
@ -44,12 +44,12 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
std::shared_ptr<Channel> emoteChannel(new Channel(""));
auto addEmotes = [&](EmoteMap &map, const QString &title, const QString &emoteDesc) {
auto addEmotes = [&](util::EmoteMap &map, const QString &title, const QString &emoteDesc) {
// TITLE
messages::MessageBuilder builder1;
builder1.appendWord(Word(title, Word::Flags::Text, MessageColor(MessageColor::Text),
FontManager::Medium, QString(), QString()));
singletons::FontManager::Medium, QString(), QString()));
builder1.getMessage()->centered = true;
emoteChannel->addMessage(builder1.getMessage());
@ -58,7 +58,7 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
messages::MessageBuilder builder2;
builder2.getMessage()->centered = true;
map.each([&](const QString &key, const EmoteData &value) {
map.each([&](const QString &key, const util::EmoteData &value) {
builder2.appendWord(Word(value.image, Word::Flags::AlwaysShow, key, emoteDesc,
Link(Link::Type::InsertText, key)));
});
@ -66,7 +66,7 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
emoteChannel->addMessage(builder2.getMessage());
};
EmoteManager &emoteManager = EmoteManager::getInstance();
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
addEmotes(emoteManager.bttvGlobalEmotes, "BetterTTV Global Emotes", "BetterTTV Global Emote");
addEmotes(*channel->bttvChannelEmotes.get(), "BetterTTV Channel Emotes",
@ -81,7 +81,7 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
void EmotePopup::loadEmojis()
{
EmoteMap &emojis = EmoteManager::getInstance().getEmojis();
util::EmoteMap &emojis = singletons::EmoteManager::getInstance().getEmojis();
std::shared_ptr<Channel> emojiChannel(new Channel(""));
@ -89,7 +89,7 @@ void EmotePopup::loadEmojis()
messages::MessageBuilder builder1;
builder1.appendWord(Word("emojis", Word::Flags::Text, MessageColor(MessageColor::Text),
FontManager::Medium, QString(), QString()));
singletons::FontManager::Medium, QString(), QString()));
builder1.getMessage()->centered = true;
emojiChannel->addMessage(builder1.getMessage());
@ -97,7 +97,7 @@ void EmotePopup::loadEmojis()
// emojis
messages::MessageBuilder builder;
builder.getMessage()->centered = true;
emojis.each([this, &builder](const QString &key, const EmoteData &value) {
emojis.each([this, &builder](const QString &key, const util::EmoteData &value) {
builder.appendWord(Word(value.image, Word::Flags::AlwaysShow, key, "emoji",
Link(Link::Type::InsertText, key)));
});

View file

@ -10,7 +10,7 @@ namespace widgets {
class EmotePopup : public BaseWidget
{
public:
explicit EmotePopup(ThemeManager &);
explicit EmotePopup(singletons::ThemeManager &);
void loadChannel(std::shared_ptr<Channel> channel);
void loadEmojis();

View file

@ -39,7 +39,8 @@ ChannelView::ChannelView(BaseWidget *parent)
#endif
this->setMouseTracking(true);
QObject::connect(&SettingsManager::getInstance(), &SettingsManager::wordTypeMaskChanged, this,
QObject::connect(&singletons::SettingManager::getInstance(),
&singletons::SettingManager::wordTypeMaskChanged, this,
&ChannelView::wordTypeMaskChanged);
this->scrollBar.getCurrentValueChanged().connect([this] {
@ -51,7 +52,7 @@ ChannelView::ChannelView(BaseWidget *parent)
this->queueUpdate();
});
WindowManager &windowManager = WindowManager::getInstance();
singletons::WindowManager &windowManager = singletons::WindowManager::getInstance();
this->repaintGifsConnection =
windowManager.repaintGifs.connect([&] { this->updateGifEmotes(); });
@ -62,7 +63,8 @@ ChannelView::ChannelView(BaseWidget *parent)
this->goToBottom->getLabel().setText("Jump to bottom");
this->goToBottom->setVisible(false);
this->managedConnections.emplace_back(FontManager::getInstance().fontChanged.connect([this] {
this->managedConnections.emplace_back(
singletons::FontManager::getInstance().fontChanged.connect([this] {
this->layoutMessages(); //
}));
@ -82,8 +84,9 @@ ChannelView::ChannelView(BaseWidget *parent)
ChannelView::~ChannelView()
{
QObject::disconnect(&SettingsManager::getInstance(), &SettingsManager::wordTypeMaskChanged,
this, &ChannelView::wordTypeMaskChanged);
QObject::disconnect(&singletons::SettingManager::getInstance(),
&singletons::SettingManager::wordTypeMaskChanged, this,
&ChannelView::wordTypeMaskChanged);
this->messageAppendedConnection.disconnect();
this->messageRemovedConnection.disconnect();
this->repaintGifsConnection.disconnect();
@ -776,7 +779,7 @@ void ChannelView::drawMessageSelection(QPainter &painter, messages::MessageRef *
void ChannelView::wheelEvent(QWheelEvent *event)
{
if (this->scrollBar.isVisible()) {
float mouseMultiplier = SettingsManager::getInstance().mouseScrollMultiplier;
float mouseMultiplier = singletons::SettingManager::getInstance().mouseScrollMultiplier;
this->scrollBar.setDesiredValue(
this->scrollBar.getDesiredValue() - event->delta() / 10.0 * mouseMultiplier, true);

View file

@ -29,7 +29,7 @@ NotebookTab::NotebookTab(Notebook *_notebook, const std::string &_uuid)
this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
SettingsManager::getInstance().hideTabX.connect(
singletons::SettingManager::getInstance().hideTabX.connect(
boost::bind(&NotebookTab::hideTabXChanged, this, _1), this->managedConnections);
this->setMouseTracking(true);
@ -74,7 +74,7 @@ void NotebookTab::calcSize()
float scale = getDpiMultiplier();
QString qTitle(qS(this->title));
if (SettingsManager::getInstance().hideTabX) {
if (singletons::SettingManager::getInstance().hideTabX) {
this->resize(static_cast<int>((fontMetrics().width(qTitle) + 16) * scale),
static_cast<int>(24 * scale));
} else {
@ -190,12 +190,12 @@ void NotebookTab::paintEvent(QPaintEvent *)
painter.setPen(fg);
float scale = this->getDpiMultiplier();
int rectW = (SettingsManager::getInstance().hideTabX ? 0 : static_cast<int>(16) * scale);
int rectW = (singletons::SettingManager::getInstance().hideTabX ? 0 : static_cast<int>(16) * scale);
QRect rect(0, 0, this->width() - rectW, this->height());
painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter));
if (!SettingsManager::getInstance().hideTabX && (mouseOver || selected)) {
if (!singletons::SettingManager::getInstance().hideTabX && (mouseOver || selected)) {
QRect xRect = this->getXRect();
if (mouseOverX) {
painter.fillRect(xRect, QColor(0, 0, 0, 64));
@ -237,7 +237,7 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
this->notebook->removePage(this->page);
}
} else {
if (!SettingsManager::getInstance().hideTabX && this->mouseDownX &&
if (!singletons::SettingManager::getInstance().hideTabX && this->mouseDownX &&
this->getXRect().contains(event->pos())) {
this->mouseDownX = false;
@ -270,7 +270,7 @@ void NotebookTab::dragEnterEvent(QDragEnterEvent *)
void NotebookTab::mouseMoveEvent(QMouseEvent *event)
{
if (!SettingsManager::getInstance().hideTabX) {
if (!singletons::SettingManager::getInstance().hideTabX) {
bool overX = this->getXRect().contains(event->pos());
if (overX != this->mouseOverX) {

View file

@ -10,8 +10,6 @@
namespace chatterino {
class ThemeManager;
namespace widgets {
class Notebook;

View file

@ -88,7 +88,7 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
}
auto *completionModel =
static_cast<chatterino::CompletionModel *>(this->completer->model());
static_cast<chatterino::singletons::CompletionModel *>(this->completer->model());
if (!this->nextCompletion) {
completionModel->refresh();

View file

@ -10,9 +10,6 @@
#include <QWidget>
namespace chatterino {
class ThemeManager;
namespace widgets {
class RippleEffectLabel : public RippleEffectButton

View file

@ -3,8 +3,9 @@
#include "QString"
namespace chatterino {
namespace singletons {
class ThemeManager;
}
namespace widgets {
@ -18,7 +19,7 @@ public:
ScrollBarHighlight(double _position, int _colorIndex, ScrollBar *parent, Style _style = Default,
QString _tag = "");
ThemeManager &themeManager;
singletons::ThemeManager &themeManager;
double getPosition()
{

View file

@ -16,8 +16,6 @@
namespace chatterino {
class ThemeManager;
namespace widgets {
class Split;

View file

@ -27,13 +27,13 @@ SplitInput::SplitInput(Split *_chatWidget)
this->hbox.addLayout(&this->editContainer);
this->hbox.addLayout(&this->vbox);
auto &fontManager = FontManager::getInstance();
auto &fontManager = singletons::FontManager::getInstance();
this->textInput.setFont(
fontManager.getFont(FontManager::Type::Medium, this->getDpiMultiplier()));
fontManager.getFont(singletons::FontManager::Type::Medium, this->getDpiMultiplier()));
this->managedConnections.emplace_back(fontManager.fontChanged.connect([this, &fontManager]() {
this->textInput.setFont(
fontManager.getFont(FontManager::Type::Medium, this->getDpiMultiplier()));
fontManager.getFont(singletons::FontManager::Type::Medium, this->getDpiMultiplier()));
}));
this->editContainer.addWidget(&this->textInput);
@ -67,10 +67,10 @@ SplitInput::SplitInput(Split *_chatWidget)
connect(&textInput, &ResizingTextEdit::textChanged, this, &SplitInput::editTextChanged);
this->refreshTheme();
textLengthLabel.setHidden(!SettingsManager::getInstance().showMessageLength);
textLengthLabel.setHidden(!singletons::SettingManager::getInstance().showMessageLength);
auto completer =
new QCompleter(CompletionManager::getInstance().createModel(this->chatWidget->channelName));
auto completer = new QCompleter(
singletons::CompletionManager::getInstance().createModel(this->chatWidget->channelName));
this->textInput.setCompleter(completer);
@ -180,7 +180,7 @@ SplitInput::SplitInput(Split *_chatWidget)
}
});
SettingsManager::getInstance().showMessageLength.connect(
singletons::SettingManager::getInstance().showMessageLength.connect(
[this](const bool &value, auto) { this->textLengthLabel.setHidden(!value); },
this->managedConnections);

View file

@ -50,7 +50,7 @@ void LogInWithCredentials(const std::string &userID, const std::string &username
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/oauthToken",
oauthToken);
AccountManager::getInstance().Twitch.reloadUsers();
singletons::AccountManager::getInstance().Twitch.reloadUsers();
messageBox.exec();
}

View file

@ -40,7 +40,7 @@ Notebook::Notebook(Window *parent, bool _showButtons, const std::string &setting
this->userButton.move(24, 0);
this->userButton.icon = NotebookButton::IconUser;
auto &settingsManager = SettingsManager::getInstance();
auto &settingsManager = singletons::SettingManager::getInstance();
settingsManager.hidePreferencesButton.connectSimple([this](auto) { this->performLayout(); });
settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); });
@ -177,13 +177,13 @@ void Notebook::performLayout(bool animated)
int x = 0, y = 0;
float scale = this->getDpiMultiplier();
if (!showButtons || SettingsManager::getInstance().hidePreferencesButton) {
if (!showButtons || singletons::SettingManager::getInstance().hidePreferencesButton) {
this->settingsButton.hide();
} else {
this->settingsButton.show();
x += settingsButton.width();
}
if (!showButtons || SettingsManager::getInstance().hideUserButton) {
if (!showButtons || singletons::SettingManager::getInstance().hideUserButton) {
this->userButton.hide();
} else {
this->userButton.move(x, 0);

View file

@ -9,9 +9,6 @@
#include <QWidget>
namespace chatterino {
class ChannelManager;
namespace widgets {
class Window;

View file

@ -17,7 +17,7 @@ ScrollBar::ScrollBar(ChannelView *parent)
: BaseWidget(parent)
, currentValueAnimation(this, "currentValue")
, highlights(nullptr)
, smoothScrollingSetting(SettingsManager::getInstance().enableSmoothScrolling)
, smoothScrollingSetting(singletons::SettingManager::getInstance().enableSmoothScrolling)
{
resize((int)(16 * this->getDpiMultiplier()), 100);
this->currentValueAnimation.setDuration(250);

View file

@ -11,8 +11,6 @@
namespace chatterino {
class ThemeManager;
namespace widgets {
class ChannelView;

View file

@ -106,7 +106,7 @@ void SettingsDialog::addTabs()
QVBoxLayout *SettingsDialog::createAccountsTab()
{
auto layout = new QVBoxLayout();
SettingsManager &settings = SettingsManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
// add remove buttons
auto buttonBox = new QDialogButtonBox(this);
@ -136,7 +136,7 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
return;
}
AccountManager::getInstance().Twitch.removeUser(selectedUser);
singletons::AccountManager::getInstance().Twitch.removeUser(selectedUser);
});
layout->addWidget(this->ui.accountSwitchWidget);
@ -146,7 +146,7 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
QVBoxLayout *SettingsDialog::createAppearanceTab()
{
auto &settings = SettingsManager::getInstance();
auto &settings = singletons::SettingManager::getInstance();
auto layout = this->createTabLayout();
{
@ -163,7 +163,7 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
fontLayout->addWidget(fontFamilyLabel);
{
auto &fontManager = FontManager::getInstance();
auto &fontManager = singletons::FontManager::getInstance();
auto UpdateFontFamilyLabel = [fontFamilyLabel, &fontManager](auto) {
fontFamilyLabel->setText(
@ -178,11 +178,11 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
}
fontButton->connect(fontButton, &QPushButton::clicked, []() {
auto &fontManager = FontManager::getInstance();
QFontDialog dialog(fontManager.getFont(FontManager::Medium, 1.));
auto &fontManager = singletons::FontManager::getInstance();
QFontDialog dialog(fontManager.getFont(singletons::FontManager::Medium, 1.));
dialog.connect(&dialog, &QFontDialog::fontSelected, [](const QFont &font) {
auto &fontManager = FontManager::getInstance();
auto &fontManager = singletons::FontManager::getInstance();
fontManager.currentFontFamily = font.family().toStdString();
fontManager.currentFontSize = font.pointSize();
});
@ -263,7 +263,7 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
QObject::connect(combo, &QComboBox::currentTextChanged, this, [](const QString &value) {
// dirty hack
EmoteManager::getInstance().incGeneration();
singletons::EmoteManager::getInstance().incGeneration();
pajlada::Settings::Setting<std::string>::set("/appearance/theme/name",
value.toStdString());
});
@ -312,7 +312,7 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
QVBoxLayout *SettingsDialog::createBehaviourTab()
{
SettingsManager &settings = SettingsManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto layout = this->createTabLayout();
auto form = new QFormLayout();
@ -329,14 +329,14 @@ QVBoxLayout *SettingsDialog::createBehaviourTab()
auto scroll = new QSlider(Qt::Horizontal);
form->addRow("Mouse scroll speed:", scroll);
float currentValue = SettingsManager::getInstance().mouseScrollMultiplier;
float currentValue = singletons::SettingManager::getInstance().mouseScrollMultiplier;
int scrollValue = ((currentValue - 0.1f) / 2.f) * 99.f;
scroll->setValue(scrollValue);
connect(scroll, &QSlider::valueChanged, [](int newValue) {
float mul = static_cast<float>(newValue) / 99.f;
float newScrollValue = (mul * 2.1f) + 0.1f;
SettingsManager::getInstance().mouseScrollMultiplier = newScrollValue;
singletons::SettingManager::getInstance().mouseScrollMultiplier = newScrollValue;
});
form->addRow("Streamlink path:", createLineEdit(settings.streamlinkPath));
@ -361,7 +361,7 @@ QVBoxLayout *SettingsDialog::createCommandsTab()
QVBoxLayout *SettingsDialog::createEmotesTab()
{
SettingsManager &settings = SettingsManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto layout = this->createTabLayout();
layout->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
@ -405,7 +405,7 @@ QVBoxLayout *SettingsDialog::createLogsTab()
QVBoxLayout *SettingsDialog::createHighlightingTab()
{
SettingsManager &settings = SettingsManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto layout = this->createTabLayout();
auto highlights = new QListWidget();
@ -615,7 +615,7 @@ void SettingsDialog::refresh()
{
this->ui.accountSwitchWidget->refresh();
SettingsManager::getInstance().saveSnapshot();
singletons::SettingManager::getInstance().saveSnapshot();
}
void SettingsDialog::dpiMultiplierChanged(float oldDpi, float newDpi)
@ -754,7 +754,7 @@ void SettingsDialog::okButtonClicked()
void SettingsDialog::cancelButtonClicked()
{
auto &settings = SettingsManager::getInstance();
auto &settings = singletons::SettingManager::getInstance();
settings.recallSnapshot();

View file

@ -51,7 +51,7 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
, settingRoot(fS("/splits/{}", this->uuid))
, channelName(fS("{}/channelName", this->settingRoot))
, parentPage(*parent)
, channel(ChannelManager::getInstance().emptyChannel)
, channel(singletons::ChannelManager::getInstance().emptyChannel)
, vbox(this)
, header(this)
, view(this)
@ -97,7 +97,7 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
});
this->input.textChanged.connect([this](const QString &newText) {
if (!SettingsManager::getInstance().hideEmptyInput) {
if (!singletons::SettingManager::getInstance().hideEmptyInput) {
return;
}
@ -108,7 +108,7 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
}
});
SettingsManager::getInstance().hideEmptyInput.connect([this](const bool &hideEmptyInput, auto) {
singletons::SettingManager::getInstance().hideEmptyInput.connect([this](const bool &hideEmptyInput, auto) {
if (hideEmptyInput && this->input.getInputText().length() == 0) {
this->input.hide();
} else {
@ -170,7 +170,7 @@ double Split::getFlexSizeY()
void Split::channelNameUpdated(const std::string &newChannelName)
{
auto &cman = ChannelManager::getInstance();
auto &cman = singletons::ChannelManager::getInstance();
// remove current channel
if (!this->channel->isEmpty()) {
@ -264,7 +264,7 @@ void Split::doChangeChannel()
void Split::doPopup()
{
Window &window = WindowManager::getInstance().createWindow();
Window &window = singletons::WindowManager::getInstance().createWindow();
Split *split = new Split(static_cast<SplitContainer *>(window.getNotebook().getSelectedPage()),
this->uuid);
@ -293,7 +293,7 @@ void Split::doOpenPopupPlayer()
void Split::doOpenStreamlink()
{
SettingsManager &settings = SettingsManager::getInstance();
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
QString preferredQuality =
QString::fromStdString(settings.preferredQuality.getValue()).toLower();
// TODO(Confuseh): Default streamlink paths

View file

@ -13,9 +13,6 @@
#include <QWidget>
namespace chatterino {
class ChannelManager;
namespace widgets {
class SplitContainer : public BaseWidget

View file

@ -20,7 +20,7 @@ TooltipWidget::TooltipWidget(BaseWidget *parent)
palette.setColor(QPalette::Background, black);
this->setPalette(palette);
this->setWindowOpacity(0.8);
this->setFont(FontManager::getInstance().getFont(FontManager::Type::MediumSmall,
this->setFont(singletons::FontManager::getInstance().getFont(singletons::FontManager::Type::MediumSmall,
this->getDpiMultiplier()));
this->setAttribute(Qt::WA_ShowWithoutActivating);
@ -32,8 +32,8 @@ TooltipWidget::TooltipWidget(BaseWidget *parent)
layout->addWidget(displayText);
this->setLayout(layout);
FontManager::getInstance().fontChanged.connect([this] {
this->setFont(FontManager::getInstance().getFont(FontManager::Type::MediumSmall,
singletons::FontManager::getInstance().fontChanged.connect([this] {
this->setFont(singletons::FontManager::getInstance().getFont(singletons::FontManager::Type::MediumSmall,
this->getDpiMultiplier()));
});
}

View file

@ -14,7 +14,7 @@
namespace chatterino {
namespace widgets {
Window::Window(const QString &windowName, ThemeManager &_themeManager, bool _isMainWindow)
Window::Window(const QString &windowName, singletons::ThemeManager &_themeManager, bool _isMainWindow)
: BaseWidget(_themeManager, nullptr)
, settingRoot(fS("/windows/{}", windowName))
, windowGeometry(this->settingRoot)
@ -24,7 +24,7 @@ Window::Window(const QString &windowName, ThemeManager &_themeManager, bool _isM
{
this->initAsWindow();
AccountManager::getInstance().Twitch.currentUsername.connect(
singletons::AccountManager::getInstance().Twitch.currentUsername.connect(
[this](const std::string &newUsername, auto) {
if (newUsername.empty()) {
this->refreshWindowTitle("Not logged in");

View file

@ -14,10 +14,9 @@
#include <pajlada/signals/signal.hpp>
namespace chatterino {
class ChannelManager;
namespace singletons {
class ThemeManager;
class CompletionManager;
}
namespace widgets {
@ -45,7 +44,7 @@ class Window : public BaseWidget
WindowGeometry windowGeometry;
public:
explicit Window(const QString &windowName, ThemeManager &_themeManager, bool isMainWindow);
explicit Window(const QString &windowName, singletons::ThemeManager &_themeManager, bool isMainWindow);
void repaintVisibleChatWidgets(Channel *channel = nullptr);
@ -59,7 +58,7 @@ protected:
virtual void closeEvent(QCloseEvent *event) override;
private:
ThemeManager &themeManager;
singletons::ThemeManager &themeManager;
float dpi;