From c5a88f6af373c919571e4cef5bf3e57bd9d920a6 Mon Sep 17 00:00:00 2001 From: apa420 Date: Wed, 29 Aug 2018 19:25:37 +0200 Subject: [PATCH] fixed stuff --- .../notifications/NotificationController.cpp | 22 +++++++++------- .../notifications/NotificationController.hpp | 1 + src/providers/twitch/TwitchApi.cpp | 1 + src/providers/twitch/TwitchChannel.cpp | 5 ++-- src/providers/twitch/TwitchChannel.hpp | 2 ++ src/singletons/Toasts.cpp | 26 ++++++++++--------- .../settingspages/NotificationPage.cpp | 10 +++---- 7 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index b35dc4cdc..1e8e1b802 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -2,11 +2,14 @@ #include "Application.hpp" #include "common/NetworkRequest.hpp" +#include "common/Outcome.hpp" #include "controllers/notifications/NotificationModel.hpp" +#include "debug/Log.hpp" #include "providers/twitch/TwitchApi.hpp" #include "providers/twitch/TwitchServer.hpp" #include "singletons/Toasts.hpp" #include "singletons/WindowManager.hpp" +#include "widgets/Window.hpp" #include @@ -93,9 +96,9 @@ void NotificationController::playSound() static QUrl currentPlayerUrl; QUrl highlightSoundUrl; - if (getApp()->settings->notificationCustomSound) { + if (getSettings()->notificationCustomSound) { highlightSoundUrl = QUrl::fromLocalFile( - getApp()->settings->notificationPathSound.getValue()); + getSettings()->notificationPathSound.getValue()); } else { highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav"); } @@ -134,12 +137,12 @@ void NotificationController::getFakeTwitchChannelLiveStatus( { TwitchApi::findUserId(channelName, [channelName, this](QString roomID) { if (roomID.isEmpty()) { - Log("[TwitchChannel:{}] Refreshing live status (Missing ID)", + log("[TwitchChannel:{}] Refreshing live status (Missing ID)", channelName); removeFakeChannel(channelName); return; } - Log("[TwitchChannel:{}] Refreshing live status", channelName); + log("[TwitchChannel:{}] Refreshing live status", channelName); QString url("https://api.twitch.tv/kraken/streams/" + roomID); auto request = NetworkRequest::twitchRequest(url); @@ -148,12 +151,12 @@ void NotificationController::getFakeTwitchChannelLiveStatus( request.onSuccess([this, channelName](auto result) -> Outcome { rapidjson::Document document = result.parseRapidJson(); if (!document.IsObject()) { - Log("[TwitchChannel:refreshLiveStatus] root is not an object"); + log("[TwitchChannel:refreshLiveStatus]root is not an object"); return Failure; } if (!document.HasMember("stream")) { - Log("[TwitchChannel:refreshLiveStatus] Missing stream in root"); + log("[TwitchChannel:refreshLiveStatus] Missing stream in root"); return Failure; } @@ -161,7 +164,7 @@ void NotificationController::getFakeTwitchChannelLiveStatus( if (!stream.IsObject()) { // Stream is offline (stream is most likely null) - removeFakeChannel(channelName); + // removeFakeChannel(channelName); return Failure; } // Stream is live @@ -174,14 +177,15 @@ void NotificationController::getFakeTwitchChannelLiveStatus( getApp()->toasts->sendChannelNotification(channelName, Platform::Twitch); } - if (getApp()->settings->notificationPlaySound) { + if (getSettings()->notificationPlaySound) { getApp()->notifications->playSound(); } - if (getApp()->settings->notificationFlashTaskbar) { + if (getSettings()->notificationFlashTaskbar) { QApplication::alert( getApp()->windows->getMainWindow().window(), 2500); } } + return Success; }); request.execute(); diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp index 77e8d46b1..228348add 100644 --- a/src/controllers/notifications/NotificationController.hpp +++ b/src/controllers/notifications/NotificationController.hpp @@ -1,6 +1,7 @@ #pragma once #include "common/SignalVector.hpp" +#include "common/Singleton.hpp" #include "singletons/Settings.hpp" #include diff --git a/src/providers/twitch/TwitchApi.cpp b/src/providers/twitch/TwitchApi.cpp index 33e982191..eb4ddb0cf 100644 --- a/src/providers/twitch/TwitchApi.cpp +++ b/src/providers/twitch/TwitchApi.cpp @@ -6,6 +6,7 @@ #include "providers/twitch/TwitchCommon.hpp" #include +#include namespace chatterino { diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 674c5831a..b091ea42f 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -18,6 +18,7 @@ #include "singletons/Toasts.hpp" #include "singletons/WindowManager.hpp" #include "util/PostToThread.hpp" +#include "widgets/Window.hpp" #include #include @@ -400,10 +401,10 @@ void TwitchChannel::setLive(bool newLiveStatus) getApp()->toasts->sendChannelNotification(this->getName(), Platform::Twitch); } - if (getApp()->settings->notificationPlaySound) { + if (getSettings()->notificationPlaySound) { getApp()->notifications->playSound(); } - if (getApp()->settings->notificationFlashTaskbar) { + if (getSettings()->notificationFlashTaskbar) { QApplication::alert( getApp()->windows->getMainWindow().window(), 2500); } diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index 208a80e5b..a4a180135 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -19,6 +19,8 @@ namespace chatterino { +enum class HighlightState; + struct Emote; using EmotePtr = std::shared_ptr; class EmoteMap; diff --git a/src/singletons/Toasts.cpp b/src/singletons/Toasts.cpp index 58595e56e..6fdd65e68 100644 --- a/src/singletons/Toasts.cpp +++ b/src/singletons/Toasts.cpp @@ -10,7 +10,7 @@ #ifdef Q_OS_WIN -#include +# include #endif @@ -27,7 +27,7 @@ namespace chatterino { bool Toasts::isEnabled() { return WinToastLib::WinToast::isCompatible() && - getApp()->settings->notificationToast; + getSettings()->notificationToast; } void Toasts::sendChannelNotification(const QString &channelName, Platform p) @@ -115,13 +115,13 @@ void Toasts::sendWindowsNotification(const QString &channelName, Platform p) WinToastLib::WinToastTemplate::SecondLine); QString Path; if (p == Platform::Twitch) { - Path = getApp()->paths->cacheDirectory() + "/" + - "profileAvatars/twitch/" + channelName + ".png"; + Path = Path = getPaths()->cacheDirectory() + "/" + + "profileAvatars/twitch/" + channelName + ".png"; } std::string temp_Utf8 = Path.toUtf8().constData(); std::wstring imagePath = std::wstring(temp_Utf8.begin(), temp_Utf8.end()); templ.setImagePath(imagePath); - if (getApp()->settings->notificationPlaySound) { + if (getSettings()->notificationPlaySound) { templ.setAudioOption( WinToastLib::WinToastTemplate::AudioOption::Silent); } @@ -154,28 +154,30 @@ void Toasts::fetchChannelAvatar(const QString channelName, request.onSuccess([successCallback](auto result) mutable -> Outcome { auto root = result.parseJson(); if (!root.value("users").isArray()) { - Log("API Error while getting user id, users is not an array"); + // log("API Error while getting user id, users is not an array"); successCallback(""); return Failure; } auto users = root.value("users").toArray(); if (users.size() != 1) { - Log("API Error while getting user id, users array size is not 1"); + // log("API Error while getting user id, users array size is not + // 1"); successCallback(""); return Failure; } if (!users[0].isObject()) { - Log("API Error while getting user id, first user is not an object"); + // log("API Error while getting user id, first user is not an + // object"); successCallback(""); return Failure; } auto firstUser = users[0].toObject(); auto avatar = firstUser.value("logo"); if (!avatar.isString()) { - Log("API Error: while getting user avatar, first user object " - "`avatar` key " - "is not a " - "string"); + // log("API Error: while getting user avatar, first user object " + // "`avatar` key " + // "is not a " + // "string"); successCallback(""); return Failure; } diff --git a/src/widgets/settingspages/NotificationPage.cpp b/src/widgets/settingspages/NotificationPage.cpp index 62b9650e9..e07b6915c 100644 --- a/src/widgets/settingspages/NotificationPage.cpp +++ b/src/widgets/settingspages/NotificationPage.cpp @@ -33,21 +33,21 @@ NotificationPage::NotificationPage() settings.emplace("Enable for selected channels"); settings.append(this->createCheckBox( "Flash taskbar", - getApp()->settings->notificationFlashTaskbar)); + getSettings()->notificationFlashTaskbar)); settings.append(this->createCheckBox( "Playsound (doesn't mute the Windows 8.x sound of toasts)", - getApp()->settings->notificationPlaySound)); + getSettings()->notificationPlaySound)); #ifdef Q_OS_WIN settings.append(this->createCheckBox( "Enable toasts (currently only for windows 8.x or 10)", - getApp()->settings->notificationToast)); + getSettings()->notificationToast)); #endif auto customSound = layout.emplace().withoutMargin(); { customSound.append(this->createCheckBox( "Custom sound", - getApp()->settings->notificationCustomSound)); + getSettings()->notificationCustomSound)); auto selectFile = customSound.emplace( "Select custom sound file"); QObject::connect( @@ -56,7 +56,7 @@ NotificationPage::NotificationPage() auto fileName = QFileDialog::getOpenFileName( this, tr("Open Sound"), "", tr("Audio Files (*.mp3 *.wav)")); - getApp()->settings->notificationPathSound = + getSettings()->notificationPathSound = fileName; }); }