Merge branch 'master' into apa-notification-on-live

This commit is contained in:
apa420
2018-08-28 23:23:46 +02:00
committed by GitHub
214 changed files with 4368 additions and 4428 deletions
-2
View File
@@ -15,8 +15,6 @@ void Emotes::initialize(Settings &settings, Paths &paths)
[] { getApp()->accounts->twitch.getCurrent()->loadEmotes(); });
this->emojis.load();
this->bttv.loadGlobalEmotes();
this->ffz.loadGlobalEmotes();
this->gifTimer.initialize();
}
-2
View File
@@ -25,8 +25,6 @@ public:
bool isIgnoredEmote(const QString &emote);
TwitchEmotes twitch;
BttvEmotes bttv;
FfzEmotes ffz;
Emojis emojis;
GIFTimer gifTimer;
+32 -32
View File
@@ -2,22 +2,23 @@
#include "Application.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "singletons/Settings.hpp"
#include "singletons/WindowManager.hpp"
#include <QDebug>
#include <QtGlobal>
#ifdef Q_OS_WIN32
#define DEFAULT_FONT_FAMILY "Segoe UI"
#define DEFAULT_FONT_SIZE 10
# define DEFAULT_FONT_FAMILY "Segoe UI"
# define DEFAULT_FONT_SIZE 10
#else
#ifdef Q_OS_MACOS
#define DEFAULT_FONT_FAMILY "Helvetica Neue"
#define DEFAULT_FONT_SIZE 12
#else
#define DEFAULT_FONT_FAMILY "Arial"
#define DEFAULT_FONT_SIZE 11
#endif
# ifdef Q_OS_MACOS
# define DEFAULT_FONT_FAMILY "Helvetica Neue"
# define DEFAULT_FONT_SIZE 12
# else
# define DEFAULT_FONT_FAMILY "Arial"
# define DEFAULT_FONT_SIZE 11
# endif
#endif
namespace chatterino {
@@ -26,7 +27,7 @@ Fonts::Fonts()
: chatFontFamily("/appearance/currentFontFamily", DEFAULT_FONT_FAMILY)
, chatFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE)
{
this->fontsByType_.resize(size_t(EndType));
this->fontsByType_.resize(size_t(FontStyle::EndType));
}
void Fonts::initialize(Settings &, Paths &)
@@ -61,21 +62,21 @@ void Fonts::initialize(Settings &, Paths &)
});
}
QFont Fonts::getFont(Fonts::Type type, float scale)
QFont Fonts::getFont(FontStyle type, float scale)
{
return this->getOrCreateFontData(type, scale).font;
}
QFontMetrics Fonts::getFontMetrics(Fonts::Type type, float scale)
QFontMetrics Fonts::getFontMetrics(FontStyle type, float scale)
{
return this->getOrCreateFontData(type, scale).metrics;
}
Fonts::FontData &Fonts::getOrCreateFontData(Type type, float scale)
Fonts::FontData &Fonts::getOrCreateFontData(FontStyle type, float scale)
{
assertInGuiThread();
assert(type >= 0 && type < EndType);
assert(type < FontStyle::EndType);
auto &map = this->fontsByType_[size_t(type)];
@@ -94,23 +95,22 @@ Fonts::FontData &Fonts::getOrCreateFontData(Type type, float scale)
return result.first->second;
}
Fonts::FontData Fonts::createFontData(Type type, float scale)
Fonts::FontData Fonts::createFontData(FontStyle type, float scale)
{
// check if it's a chat (scale the setting)
if (type >= ChatStart && type <= ChatEnd) {
static std::unordered_map<Type, ChatFontData> sizeScale{
{ChatSmall, {0.6f, false, QFont::Normal}},
{ChatMediumSmall, {0.8f, false, QFont::Normal}},
{ChatMedium, {1, false, QFont::Normal}},
{ChatMediumBold,
{1, false,
QFont::Weight(getApp()->settings->boldScale.getValue())}},
{ChatMediumItalic, {1, true, QFont::Normal}},
{ChatLarge, {1.2f, false, QFont::Normal}},
{ChatVeryLarge, {1.4f, false, QFont::Normal}},
if (type >= FontStyle::ChatStart && type <= FontStyle::ChatEnd) {
static std::unordered_map<FontStyle, ChatFontData> sizeScale{
{FontStyle::ChatSmall, {0.6f, false, QFont::Normal}},
{FontStyle::ChatMediumSmall, {0.8f, false, QFont::Normal}},
{FontStyle::ChatMedium, {1, false, QFont::Normal}},
{FontStyle::ChatMediumBold,
{1, false, QFont::Weight(getSettings()->boldScale.getValue())}},
{FontStyle::ChatMediumItalic, {1, true, QFont::Normal}},
{FontStyle::ChatLarge, {1.2f, false, QFont::Normal}},
{FontStyle::ChatVeryLarge, {1.4f, false, QFont::Normal}},
};
sizeScale[ChatMediumBold] = {
1, false, QFont::Weight(getApp()->settings->boldScale.getValue())};
sizeScale[FontStyle::ChatMediumBold] = {
1, false, QFont::Weight(getSettings()->boldScale.getValue())};
auto data = sizeScale[type];
return FontData(
QFont(QString::fromStdString(this->chatFontFamily.getValue()),
@@ -126,11 +126,11 @@ Fonts::FontData Fonts::createFontData(Type type, float scale)
constexpr float multiplier = 1.f;
#endif
static std::unordered_map<Type, UiFontData> defaultSize{
{Tiny, {8, "Monospace", false, QFont::Normal}},
{UiMedium,
static std::unordered_map<FontStyle, UiFontData> defaultSize{
{FontStyle::Tiny, {8, "Monospace", false, QFont::Normal}},
{FontStyle::UiMedium,
{int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
{UiTabs,
{FontStyle::UiTabs,
{int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
};
+25 -26
View File
@@ -16,6 +16,27 @@ namespace chatterino {
class Settings;
class Paths;
enum class FontStyle : uint8_t {
Tiny,
ChatSmall,
ChatMediumSmall,
ChatMedium,
ChatMediumBold,
ChatMediumItalic,
ChatLarge,
ChatVeryLarge,
UiMedium,
UiTabs,
// don't remove this value
EndType,
// make sure to update these values accordingly!
ChatStart = ChatSmall,
ChatEnd = ChatVeryLarge,
};
class Fonts final : public Singleton
{
public:
@@ -24,29 +45,9 @@ public:
virtual void initialize(Settings &settings, Paths &paths) override;
// font data gets set in createFontData(...)
enum Type : uint8_t {
Tiny,
ChatSmall,
ChatMediumSmall,
ChatMedium,
ChatMediumBold,
ChatMediumItalic,
ChatLarge,
ChatVeryLarge,
UiMedium,
UiTabs,
// don't remove this value
EndType,
// make sure to update these values accordingly!
ChatStart = ChatSmall,
ChatEnd = ChatVeryLarge,
};
QFont getFont(Type type, float scale);
QFontMetrics getFontMetrics(Type type, float scale);
QFont getFont(FontStyle type, float scale);
QFontMetrics getFontMetrics(FontStyle type, float scale);
pajlada::Settings::Setting<std::string> chatFontFamily;
pajlada::Settings::Setting<int> chatFontSize;
@@ -78,12 +79,10 @@ private:
QFont::Weight weight;
};
FontData &getOrCreateFontData(Type type, float scale);
FontData createFontData(Type type, float scale);
FontData &getOrCreateFontData(FontStyle type, float scale);
FontData createFontData(FontStyle type, float scale);
std::vector<std::unordered_map<float, FontData>> fontsByType_;
};
using FontStyle = Fonts::Type;
} // namespace chatterino
+5 -5
View File
@@ -17,11 +17,11 @@
namespace ipc = boost::interprocess;
#ifdef Q_OS_WIN
#include <QProcess>
# include <QProcess>
#include <Windows.h>
#include "singletons/WindowManager.hpp"
#include "widgets/AttachedWindow.hpp"
# include <Windows.h>
# include "singletons/WindowManager.hpp"
# include "widgets/AttachedWindow.hpp"
#endif
#include <iostream>
@@ -200,7 +200,7 @@ void NativeMessagingServer::ReceiverThread::handleMessage(
if (_type == "twitch") {
postToThread([=] {
if (!name.isEmpty()) {
app->twitch.server->watchingChannel.update(
app->twitch.server->watchingChannel.reset(
app->twitch.server->getOrAddChannel(name));
}
+24 -1
View File
@@ -1,5 +1,7 @@
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDir>
@@ -33,6 +35,27 @@ bool Paths::isPortable()
return this->portable_.get();
}
QString Paths::cacheDirectory()
{
static QStringSetting cachePathSetting = [] {
QStringSetting cachePathSetting("/cache/path");
cachePathSetting.connect([](const auto &newPath, auto) {
QDir().mkpath(newPath); //
});
return cachePathSetting;
}();
auto path = cachePathSetting.getValue();
if (path == "") {
return this->cacheDirectory_;
}
return path;
}
void Paths::initAppFilePathHash()
{
this->applicationFilePathHash =
@@ -104,7 +127,7 @@ void Paths::initSubDirectories()
makePath("");
this->settingsDirectory = makePath("Settings");
this->cacheDirectory = makePath("Cache");
this->cacheDirectory_ = makePath("Cache");
this->messageLogDirectory = makePath("Logs");
this->miscDirectory = makePath("Misc");
}
+6 -4
View File
@@ -19,9 +19,6 @@ public:
// Directory for settings files. Same as <appDataDirectory>/Settings
QString settingsDirectory;
// Directory for cache files. Same as <appDataDirectory>/Misc
QString cacheDirectory;
// Directory for message log files. Same as <appDataDirectory>/Misc
QString messageLogDirectory;
@@ -34,6 +31,8 @@ public:
bool createFolder(const QString &folderPath);
bool isPortable();
QString cacheDirectory();
private:
void initAppFilePathHash();
void initCheckPortable();
@@ -41,8 +40,11 @@ private:
void initSubDirectories();
boost::optional<bool> portable_;
// Directory for cache files. Same as <appDataDirectory>/Misc
QString cacheDirectory_;
};
[[deprecated]] Paths *getPaths();
Paths *getPaths();
} // namespace chatterino
+3 -3
View File
@@ -50,7 +50,7 @@ void Settings::saveSnapshot()
this->snapshot_.reset(d);
Log("hehe: {}", pajlada::Settings::SettingManager::stringify(*d));
log("hehe: {}", pajlada::Settings::SettingManager::stringify(*d));
}
void Settings::restoreSnapshot()
@@ -64,14 +64,14 @@ void Settings::restoreSnapshot()
for (const auto &weakSetting : _settings) {
auto setting = weakSetting.lock();
if (!setting) {
Log("Error stage 1 of loading");
log("Error stage 1 of loading");
continue;
}
const char *path = setting->getPath().c_str();
if (!snapshotObject.HasMember(path)) {
Log("Error stage 2 of loading");
log("Error stage 2 of loading");
continue;
}
+5 -8
View File
@@ -5,7 +5,6 @@
#include "common/ChatterinoSetting.hpp"
#include "controllers/highlights/HighlightPhrase.hpp"
#include "controllers/moderationactions/ModerationAction.hpp"
#include "messages/MessageElement.hpp"
#include <pajlada/settings/setting.hpp>
#include <pajlada/settings/settinglistener.hpp>
@@ -26,6 +25,8 @@ public:
/// Appearance
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};
BoolSetting enableAnimationsWhenFocused = {
"/appearance/enableAnimationsWhenFocused", false};
QStringSetting timestampFormat = {"/appearance/messages/timestampFormat",
"h:mm"};
BoolSetting showBadges = {"/appearance/messages/showBadges", true};
@@ -98,12 +99,6 @@ public:
BoolSetting enableGifAnimations = {"/emotes/enableGifAnimations", true};
FloatSetting emoteScale = {"/emotes/scale", 1.f};
// 0 = No preference
// 1 = 1x
// 2 = 2x
// 3 = 3x
IntSetting preferredEmoteQuality = {"/emotes/preferredEmoteQuality", 0};
QStringSetting emojiSet = {"/emotes/emojiSet", "EmojiOne 2"};
/// Links
@@ -164,6 +159,8 @@ public:
IntSetting startUpNotification = {"/misc/startUpNotification", 0};
QStringSetting currentVersion = {"/misc/currentVersion", ""};
QStringSetting cachePath = {"/cache/path", ""};
void saveSnapshot();
void restoreSnapshot();
@@ -173,6 +170,6 @@ private:
std::unique_ptr<rapidjson::Document> snapshot_;
};
[[deprecated]] Settings *getSettings();
Settings *getSettings();
} // namespace chatterino
+12 -12
View File
@@ -10,21 +10,21 @@ namespace chatterino {
namespace detail {
double getMultiplierByTheme(const QString &themeName)
{
if (themeName == "Light") {
return 0.8;
} else if (themeName == "White") {
return 1.0;
} else if (themeName == "Black") {
return -1.0;
} else if (themeName == "Dark") {
double getMultiplierByTheme(const QString &themeName)
{
if (themeName == "Light") {
return 0.8;
} else if (themeName == "White") {
return 1.0;
} else if (themeName == "Black") {
return -1.0;
} else if (themeName == "Dark") {
return -0.8;
}
return -0.8;
}
return -0.8;
}
} // namespace detail
Theme::Theme()
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include "common/SerializeCustom.hpp"
#include "common/Singleton.hpp"
#include "util/RapidJsonSerializeQString.hpp"
#include <QBrush>
#include <QColor>
+1
View File
@@ -1,6 +1,7 @@
#include "Updates.hpp"
#include "common/NetworkRequest.hpp"
#include "common/Outcome.hpp"
#include "common/Version.hpp"
#include "singletons/Paths.hpp"
#include "util/CombinePath.hpp"
+21 -14
View File
@@ -3,13 +3,20 @@
#include "Application.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "debug/Log.hpp"
#include "messages/MessageElement.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "util/Clamp.hpp"
#include "widgets/AccountSwitchPopupWidget.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/Window.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/helper/NotebookTab.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include <QDebug>
#include <QJsonArray>
@@ -174,7 +181,7 @@ Window &WindowManager::getSelectedWindow()
return *this->selectedWindow_;
}
Window &WindowManager::createWindow(Window::Type type)
Window &WindowManager::createWindow(WindowType type)
{
assertInGuiThread();
@@ -182,7 +189,7 @@ Window &WindowManager::createWindow(Window::Type type)
this->windows_.push_back(window);
window->show();
if (type != Window::Type::Main) {
if (type != WindowType::Main) {
window->setAttribute(Qt::WA_DeleteOnClose);
QObject::connect(window, &QWidget::destroyed, [this, window] {
@@ -211,7 +218,7 @@ Window *WindowManager::windowAt(int index)
if (index < 0 || (size_t)index >= this->windows_.size()) {
return nullptr;
}
Log("getting window at bad index {}", index);
log("getting window at bad index {}", index);
return this->windows_.at(index);
}
@@ -239,16 +246,16 @@ void WindowManager::initialize(Settings &settings, Paths &paths)
// get type
QString type_val = window_obj.value("type").toString();
Window::Type type =
type_val == "main" ? Window::Type::Main : Window::Type::Popup;
WindowType type =
type_val == "main" ? WindowType::Main : WindowType::Popup;
if (type == Window::Type::Main && mainWindow_ != nullptr) {
type = Window::Type::Popup;
if (type == WindowType::Main && mainWindow_ != nullptr) {
type = WindowType::Popup;
}
Window &window = createWindow(type);
if (type == Window::Type::Main) {
if (type == WindowType::Main) {
mainWindow_ = &window;
}
@@ -308,7 +315,7 @@ void WindowManager::initialize(Settings &settings, Paths &paths)
}
if (mainWindow_ == nullptr) {
mainWindow_ = &createWindow(Window::Type::Main);
mainWindow_ = &createWindow(WindowType::Main);
mainWindow_->getNotebook().addPage(true);
}
@@ -344,15 +351,15 @@ void WindowManager::save()
// window type
switch (window->getType()) {
case Window::Type::Main:
case WindowType::Main:
window_obj.insert("type", "main");
break;
case Window::Type::Popup:
case WindowType::Popup:
window_obj.insert("type", "popup");
break;
case Window::Type::Attached:;
case WindowType::Attached:;
}
// window geometry
@@ -399,7 +406,7 @@ void WindowManager::save()
document.setObject(obj);
// save file
QString settingsPath = app->paths->settingsDirectory + SETTINGS_FILENAME;
QString settingsPath = getPaths()->settingsDirectory + SETTINGS_FILENAME;
QFile file(settingsPath);
file.open(QIODevice::WriteOnly | QIODevice::Truncate);
@@ -511,7 +518,7 @@ int WindowManager::clampUiScale(int scale)
float WindowManager::getUiScaleValue()
{
return getUiScaleValue(getApp()->settings->uiScale.getValue());
return getUiScaleValue(getSettings()->uiScale.getValue());
}
float WindowManager::getUiScaleValue(int scale)
+12 -5
View File
@@ -1,13 +1,20 @@
#pragma once
#include "common/Channel.hpp"
#include "common/FlagsEnum.hpp"
#include "common/Singleton.hpp"
#include "widgets/Window.hpp"
#include "widgets/splits/SplitContainer.hpp"
namespace chatterino {
class Settings;
class Paths;
class Window;
class SplitContainer;
enum class MessageElementFlag;
using MessageElementFlags = FlagsEnum<MessageElementFlag>;
enum class WindowType;
class WindowManager final : public Singleton
{
@@ -34,7 +41,7 @@ public:
Window &getMainWindow();
Window &getSelectedWindow();
Window &createWindow(Window::Type type);
Window &createWindow(WindowType type);
int windowCount();
Window *windowAt(int index);
@@ -63,10 +70,10 @@ private:
std::vector<Window *> windows_;
Window *mainWindow_ = nullptr;
Window *selectedWindow_ = nullptr;
Window *mainWindow_{};
Window *selectedWindow_{};
MessageElementFlags wordFlags_ = MessageElementFlag::Default;
MessageElementFlags wordFlags_{};
pajlada::Settings::SettingListener wordFlagsListener_;
};
+8 -7
View File
@@ -10,19 +10,20 @@ void GIFTimer::initialize()
{
this->timer.setInterval(30);
getApp()->settings->enableGifAnimations.connect([this](bool enabled, auto) {
if (enabled) {
getSettings()->enableGifAnimations.connect([this](bool enabled, auto) {
if (enabled)
this->timer.start();
} else {
else
this->timer.stop();
}
});
QObject::connect(&this->timer, &QTimer::timeout, [this] {
if (getSettings()->enableAnimationsWhenFocused &&
qApp->activeWindow() == nullptr)
return;
this->signal.invoke();
// fourtf:
auto app = getApp();
app->windows->repaintGifEmotes();
getApp()->windows->repaintGifEmotes();
});
}
+4 -4
View File
@@ -30,11 +30,11 @@ LoggingChannel::LoggingChannel(const QString &_channelName)
auto app = getApp();
app->settings->logPath.connect([this](const QString &logPath, auto) {
getSettings()->logPath.connect([this](const QString &logPath, auto) {
auto app = getApp();
if (logPath.isEmpty()) {
this->baseDirectory = app->paths->messageLogDirectory;
this->baseDirectory = getPaths()->messageLogDirectory;
} else {
this->baseDirectory = logPath;
}
@@ -65,13 +65,13 @@ void LoggingChannel::openLogFile()
this->baseDirectory + QDir::separator() + this->subDirectory;
if (!QDir().mkpath(directory)) {
Log("Unable to create logging path");
log("Unable to create logging path");
return;
}
// Open file handle to log file of current date
QString fileName = directory + QDir::separator() + baseFileName;
Log("Logging to {}", fileName);
log("Logging to {}", fileName);
this->fileHandle.setFileName(fileName);
this->fileHandle.open(QIODevice::Append);