This commit is contained in:
fourtf
2018-04-28 13:48:49 +02:00
82 changed files with 959 additions and 794 deletions
+8 -7
View File
@@ -1,5 +1,6 @@
#include "util/completionmodel.hpp"
#include "application.hpp"
#include "common.hpp"
#include "debug/log.hpp"
#include "singletons/emotemanager.hpp"
@@ -19,11 +20,11 @@ void CompletionModel::refresh()
{
debug::Log("[CompletionModel:{}] Refreshing...]", this->channelName);
auto &emoteManager = singletons::EmoteManager::getInstance();
auto app = getApp();
// User-specific: Twitch Emotes
// TODO: Fix this so it properly updates with the proper api. oauth token needs proper scope
for (const auto &m : emoteManager.twitchAccountEmotes) {
for (const auto &m : app->emotes->twitchAccountEmotes) {
for (const auto &emoteName : m.second.emoteCodes) {
// XXX: No way to discern between a twitch global emote and sub emote right now
this->addString(emoteName, TaggedString::Type::TwitchGlobalEmote);
@@ -31,33 +32,33 @@ void CompletionModel::refresh()
}
// Global: BTTV Global Emotes
std::vector<std::string> &bttvGlobalEmoteCodes = emoteManager.bttvGlobalEmoteCodes;
std::vector<std::string> &bttvGlobalEmoteCodes = app->emotes->bttvGlobalEmoteCodes;
for (const auto &m : bttvGlobalEmoteCodes) {
this->addString(m, TaggedString::Type::BTTVGlobalEmote);
}
// Global: FFZ Global Emotes
std::vector<std::string> &ffzGlobalEmoteCodes = emoteManager.ffzGlobalEmoteCodes;
std::vector<std::string> &ffzGlobalEmoteCodes = app->emotes->ffzGlobalEmoteCodes;
for (const auto &m : ffzGlobalEmoteCodes) {
this->addString(m, TaggedString::Type::FFZGlobalEmote);
}
// Channel-specific: BTTV Channel Emotes
std::vector<std::string> &bttvChannelEmoteCodes =
emoteManager.bttvChannelEmoteCodes[this->channelName.toStdString()];
app->emotes->bttvChannelEmoteCodes[this->channelName.toStdString()];
for (const auto &m : bttvChannelEmoteCodes) {
this->addString(m, TaggedString::Type::BTTVChannelEmote);
}
// Channel-specific: FFZ Channel Emotes
std::vector<std::string> &ffzChannelEmoteCodes =
emoteManager.ffzChannelEmoteCodes[this->channelName.toStdString()];
app->emotes->ffzChannelEmoteCodes[this->channelName.toStdString()];
for (const auto &m : ffzChannelEmoteCodes) {
this->addString(m, TaggedString::Type::FFZChannelEmote);
}
// Global: Emojis
const auto &emojiShortCodes = emoteManager.emojiShortCodes;
const auto &emojiShortCodes = app->emotes->emojiShortCodes;
for (const auto &m : emojiShortCodes) {
this->addString(":" + m + ":", TaggedString::Type::Emoji);
}
+4 -2
View File
@@ -1,5 +1,7 @@
#include "util/networkrequest.hpp"
#include "application.hpp"
namespace chatterino {
namespace util {
@@ -26,9 +28,9 @@ void NetworkRequest::setUseQuickLoadCache(bool value)
void NetworkRequest::Data::writeToCache(const QByteArray &bytes)
{
if (this->useQuickLoadCache) {
auto &pathManager = singletons::PathManager::getInstance();
auto app = getApp();
QFile cachedFile(pathManager.cacheFolderPath + "/" + this->getHash());
QFile cachedFile(app->paths->cacheFolderPath + "/" + this->getHash());
if (cachedFile.open(QIODevice::WriteOnly)) {
cachedFile.write(bytes);
+3 -2
View File
@@ -1,5 +1,6 @@
#pragma once
#include "application.hpp"
#include "singletons/pathmanager.hpp"
#include "util/networkmanager.hpp"
#include "util/networkrequester.hpp"
@@ -125,9 +126,9 @@ public:
void get(FinishedCallback onFinished)
{
if (this->data.useQuickLoadCache) {
auto &pathManager = singletons::PathManager::getInstance();
auto app = getApp();
QFile cachedFile(pathManager.cacheFolderPath + "/" + this->data.getHash());
QFile cachedFile(app->paths->cacheFolderPath + "/" + this->data.getHash());
if (cachedFile.exists()) {
if (cachedFile.open(QIODevice::ReadOnly)) {
+90
View File
@@ -0,0 +1,90 @@
#pragma once
#include <QStandardItemModel>
#include <pajlada/signals/signal.hpp>
#include <vector>
#include "util/assertinguithread.hpp"
namespace chatterino {
namespace util {
template <typename TVectorItem>
class ReadOnlySignalVector
{
public:
virtual ~ReadOnlySignalVector() = default;
struct ItemInsertedArgs {
const TVectorItem &item;
int index;
};
pajlada::Signals::Signal<ItemInsertedArgs> itemInserted;
pajlada::Signals::Signal<int> itemRemoved;
pajlada::Signals::NoArgSignal delayedItemsChanged;
const std::vector<TVectorItem> &getVector() const
{
util::assertInGuiThread();
return this->vector;
}
protected:
std::vector<TVectorItem> vector;
};
template <typename TVectorItem>
class BaseSignalVector : public ReadOnlySignalVector<TVectorItem>
{
public:
void removeItem(int index)
{
util::assertInGuiThread();
assert(index >= 0 && index < this->vector.size());
this->vector.erase(this->vector.begin() + index);
this->itemRemoved.invoke(index);
}
};
template <typename TVectorItem>
class SignalVector2 : public BaseSignalVector<TVectorItem>
{
public:
void insertItem(const TVectorItem &item, int index)
{
util::assertInGuiThread();
assert(index >= 0 && index <= this->vector.size());
this->vector.insert(this->vector.begin() + index, item);
ItemInsertedArgs args{item, index};
this->itemInserted.invoke(args);
}
void appendItem(const TVectorItem &item)
{
this->insertItem(item, this->vector.size());
}
};
template <typename TVectorItem>
class SortedSignalVector : public BaseSignalVector<TVectorItem>
{
public:
void addItem(const TVectorItem &item)
{
util::assertInGuiThread();
int index = this->vector.insert(
std::lower_bound(this->vector.begin(), this->vector.end(), item), item) -
this->vector.begin();
ItemInsertedArgs args{item, index};
this->itemInserted.invoke(args);
}
};
} // namespace util
} // namespace chatterino
+10 -8
View File
@@ -1,4 +1,6 @@
#include "util/streamlink.hpp"
#include "application.hpp"
#include "helpers.hpp"
#include "singletons/settingsmanager.hpp"
#include "widgets/qualitypopup.hpp"
@@ -50,9 +52,9 @@ bool CheckStreamlinkPath(const QString &path)
// TODO: Make streamlink binary finder smarter
QString GetStreamlinkBinaryPath()
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
QString settingPath = settings.streamlinkPath;
QString settingPath = app->settings->streamlinkPath;
QStringList paths;
paths << settingPath;
@@ -111,15 +113,15 @@ void GetStreamQualities(const QString &channelURL, std::function<void(QStringLis
void OpenStreamlink(const QString &channelURL, const QString &quality, QStringList extraArguments)
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
QString path = GetStreamlinkBinaryPath();
QStringList arguments;
QString additionalOptions = settings.streamlinkOpts.getValue();
QString additionalOptions = app->settings->streamlinkOpts.getValue();
if (!additionalOptions.isEmpty()) {
arguments << settings.streamlinkOpts;
arguments << app->settings->streamlinkOpts;
}
arguments.append(extraArguments);
@@ -135,11 +137,11 @@ void OpenStreamlink(const QString &channelURL, const QString &quality, QStringLi
void Start(const QString &channel)
{
auto app = getApp();
QString channelURL = "twitch.tv/" + channel;
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
QString preferredQuality = settings.preferredQuality;
QString preferredQuality = app->settings->preferredQuality;
preferredQuality = preferredQuality.toLower();
if (preferredQuality == "choose") {
+2 -4
View File
@@ -100,8 +100,7 @@ static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
{
QNetworkRequest request(url);
auto &accountManager = singletons::AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent();
auto currentTwitchUser = getApp()->accounts->Twitch.getCurrent();
QByteArray oauthToken;
if (currentTwitchUser) {
oauthToken = currentTwitchUser->getOAuthToken().toUtf8();
@@ -131,8 +130,7 @@ static void sendDelete(QUrl url, std::function<void()> successCallback)
{
QNetworkRequest request(url);
auto &accountManager = singletons::AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent();
auto currentTwitchUser = getApp()->accounts->Twitch.getCurrent();
QByteArray oauthToken;
if (currentTwitchUser) {
oauthToken = currentTwitchUser->getOAuthToken().toUtf8();