stuff does compile

This commit is contained in:
apa420
2018-08-12 18:54:32 +02:00
parent 54166ec130
commit 05d5709bb9
8 changed files with 73 additions and 88 deletions
@@ -32,18 +32,16 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
} }
void NotificationController::updateChannelNotification( void NotificationController::updateChannelNotification(
const QString &channelName, int &i) const QString &channelName, Platform p)
{ {
if (i == 0) { if (p == Platform::Twitch) {
int j = 0; if (isChannelNotified(channelName, Platform::Twitch)) {
if (isChannelNotified(channelName, j)) {
removeChannelNotification(channelName, twitchVector); removeChannelNotification(channelName, twitchVector);
} else { } else {
addChannelNotification(channelName, twitchVector); addChannelNotification(channelName, twitchVector);
} }
} else if (i == 1) { } else if (p == Platform::Mixer) {
int k = 1; if (isChannelNotified(channelName, Platform::Mixer)) {
if (isChannelNotified(channelName, k)) {
removeChannelNotification(channelName, mixerVector); removeChannelNotification(channelName, mixerVector);
} else { } else {
addChannelNotification(channelName, mixerVector); addChannelNotification(channelName, mixerVector);
@@ -52,7 +50,7 @@ void NotificationController::updateChannelNotification(
} }
bool NotificationController::isChannelNotified(const QString &channelName, bool NotificationController::isChannelNotified(const QString &channelName,
int &i) Platform p)
{ {
/* /*
for (std::vector<int>::size_type i = 0; for (std::vector<int>::size_type i = 0;
@@ -62,15 +60,15 @@ bool NotificationController::isChannelNotified(const QString &channelName,
<< " vectorsize:" << notificationVector.getVector().size(); << " vectorsize:" << notificationVector.getVector().size();
} }
*/ */
qDebug() << channelName << " channel and now i: " << i; // qDebug() << channelName << " channel and now i: " << i;
if (i == 0) { if (p == Platform::Twitch) {
for (std::vector<int>::size_type i = 0; for (std::vector<int>::size_type i = 0;
i != twitchVector.getVector().size(); i++) { i != twitchVector.getVector().size(); i++) {
if (twitchVector.getVector()[i] == channelName) { if (twitchVector.getVector()[i] == channelName) {
return true; return true;
} }
} }
} else if (i == 1) { } else if (p == Platform::Mixer) {
for (std::vector<int>::size_type i = 0; for (std::vector<int>::size_type i = 0;
i != mixerVector.getVector().size(); i++) { i != mixerVector.getVector().size(); i++) {
if (mixerVector.getVector()[i] == channelName) { if (mixerVector.getVector()[i] == channelName) {
@@ -164,12 +162,13 @@ void NotificationController::removeChannelNotification(
} }
} }
NotificationModel *NotificationController::createModel(QObject *parent, int &i) NotificationModel *NotificationController::createModel(QObject *parent,
Platform p)
{ {
NotificationModel *model = new NotificationModel(parent); NotificationModel *model = new NotificationModel(parent);
if (i == 0) { if (p == Platform::Twitch) {
model->init(&this->twitchVector); model->init(&this->twitchVector);
} else if (i == 1) { } else if (p == Platform::Mixer) {
model->init(&this->mixerVector); model->init(&this->mixerVector);
} }
return model; return model;
@@ -10,25 +10,31 @@ class Paths;
class NotificationModel; class NotificationModel;
enum class Platform : uint8_t {
Twitch = 0, // 0
Mixer = 1, // 1
HitBox = 2, // 2
};
class NotificationController final : public Singleton class NotificationController final : public Singleton
{ {
public: public:
virtual void initialize(Settings &settings, Paths &paths) override; virtual void initialize(Settings &settings, Paths &paths) override;
bool isChannelNotified(const QString &channelName, int &i); bool isChannelNotified(const QString &channelName, Platform p);
void updateChannelNotification(const QString &channelName, int &i); void updateChannelNotification(const QString &channelName, Platform p);
void addChannelNotification(const QString &channelName, void addChannelNotification(const QString &channelName,
UnsortedSignalVector<QString> &vector); UnsortedSignalVector<QString> &vector);
void removeChannelNotification(const QString &channelName, void removeChannelNotification(const QString &channelName,
UnsortedSignalVector<QString> &vector); UnsortedSignalVector<QString> &vector);
UnsortedSignalVector<QString> getVector(int &i); UnsortedSignalVector<QString> getVector(Platform p);
UnsortedSignalVector<QString> twitchVector; UnsortedSignalVector<QString> twitchVector;
UnsortedSignalVector<QString> mixerVector; UnsortedSignalVector<QString> mixerVector;
NotificationModel *createModel(QObject *parent, int &i); NotificationModel *createModel(QObject *parent, Platform p);
private: private:
bool initialized_ = false; bool initialized_ = false;
+19 -54
View File
@@ -305,19 +305,6 @@ const QString &TwitchChannel::getPopoutPlayerUrl()
return this->popoutPlayerUrl_; return this->popoutPlayerUrl_;
} }
bool Toasts::isEnabled(const QString &channelName)
{
int i = 0;
return getApp()->notifications->isChannelNotified(channelName, i);
}
/*
bool toastIsEnabled()
{
QString channelName = this->getName();
return getApp()->notifications->isChannelNotified(channelName);
}
*/
void TwitchChannel::setLive(bool newLiveStatus) void TwitchChannel::setLive(bool newLiveStatus)
{ {
bool gotNewLiveStatus = false; bool gotNewLiveStatus = false;
@@ -325,41 +312,21 @@ void TwitchChannel::setLive(bool newLiveStatus)
auto guard = this->streamStatus_.access(); auto guard = this->streamStatus_.access();
if (guard->live != newLiveStatus) { if (guard->live != newLiveStatus) {
gotNewLiveStatus = true; gotNewLiveStatus = true;
guard->live = newLiveStatus; if (Toasts::isEnabled() &&
} getApp()->notifications->isChannelNotified(this->getName(),
} Platform::Twitch)) {
getApp()->toasts->sendChannelNotification(this->getName(),
if (gotNewLiveStatus) { Platform::Twitch);
this->liveStatusChanged.invoke();
}
}
/*
void TwitchChannel::setLive(bool newLiveStatus)
{
// auto guard = this->streamStatus_.access();
if (toastIsEnabled() && guard->live != newLiveStatus && guard->live !=
newLiveStatus) { Toasts::show
}
// int i = 0;
// getApp()->toasts->sendChannelNotification(this->getName(), i);
qDebug() << "setLive called here and channel: " << this->getName()
<< " status: " << newLiveStatus;
bool gotNewLiveStatus = false;
{
auto guard = this->streamStatus_.access();
if (guard->live != newLiveStatus) {
gotNewLiveStatus = true;
guard->live = newLiveStatus;
if (getApp()->toasts->isEnabled(this->getName()) &&
guard->live == true) {
int i = 0;
getApp()->toasts->sendChannelNotification(this->getName(), i);
} }
/*
if (!guard->live && Toasts::isEnabled() &&
getApp()->notifications->isChannelNotified( this->getName(),
Platform::Twitch)) {
getApp()->toasts->sendChannelNotification(this->getName(),
Platform::Twitch);
}
*/
guard->live = newLiveStatus;
} }
} }
@@ -367,7 +334,7 @@ void TwitchChannel::setLive(bool newLiveStatus)
this->liveStatusChanged.invoke(); this->liveStatusChanged.invoke();
} }
} }
*/
void TwitchChannel::refreshLiveStatus() void TwitchChannel::refreshLiveStatus()
{ {
auto roomID = this->getRoomId(); auto roomID = this->getRoomId();
@@ -441,15 +408,13 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
{ {
auto status = this->streamStatus_.access(); auto status = this->streamStatus_.access();
/* /*
if (!status->live == false && if (!(status->live) && getApp()->toasts->isEnabled(this->getName())) {
getApp()->toasts->isEnabled(this->getName())) { qDebug() << " NaM xd NaM ";
int i = 0; int i = 0;
getApp()->toasts->sendChannelNotification(this->getName(), i); getApp()->toasts->sendChannelNotification(this->getName(), i);
// notifcation send // notifcation send
} }
status->live = true; */
*/
this->setLive(true);
// status->live = true; // status->live = true;
status->viewerCount = stream["viewers"].GetUint(); status->viewerCount = stream["viewers"].GetUint();
status->game = stream["game"].GetString(); status->game = stream["game"].GetString();
@@ -479,7 +444,7 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
} }
} }
} }
setLive(true);
// Signal all listeners that the stream status has been updated // Signal all listeners that the stream status has been updated
this->liveStatusChanged.invoke(); this->liveStatusChanged.invoke();
+1
View File
@@ -144,6 +144,7 @@ public:
false}; false};
BoolSetting notificationPlaySound = {"/notifications/enablePlaySound", BoolSetting notificationPlaySound = {"/notifications/enablePlaySound",
false}; false};
BoolSetting notificationToast = {"/notifications/enableToast", false};
/// External tools /// External tools
// Streamlink // Streamlink
+16 -5
View File
@@ -5,8 +5,12 @@
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp" #include "providers/twitch/TwitchServer.hpp"
#ifdef Q_OS_WIN
#include <wintoastlib.h> #include <wintoastlib.h>
#endif
#include <QDesktopServices> #include <QDesktopServices>
#include <QUrl> #include <QUrl>
@@ -70,12 +74,19 @@ bool Toasts::wasChannelLive(const QString &channelName)
return false; return false;
} }
*/ */
void Toasts::sendChannelNotification(const QString &channelName, int &platform) bool Toasts::isEnabled()
{
return WinToastLib::WinToast::isCompatible() &&
getApp()->settings->notificationToast;
}
void Toasts::sendChannelNotification(const QString &channelName, Platform p)
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (WinToastLib::WinToast::isCompatible()) {
sendWindowsNotification(channelName, platform); sendWindowsNotification(channelName, p);
} return;
#endif #endif
// OSX // OSX
@@ -127,7 +138,7 @@ public:
} }
}; };
void Toasts::sendWindowsNotification(const QString &channelName, int &platform) void Toasts::sendWindowsNotification(const QString &channelName, Platform p)
{ {
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate( WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
WinToastLib::WinToastTemplate::ImageAndText02); WinToastLib::WinToastTemplate::ImageAndText02);
+5 -3
View File
@@ -7,18 +7,20 @@
namespace chatterino { namespace chatterino {
enum class Platform : uint8_t;
class Toasts final : public Singleton class Toasts final : public Singleton
{ {
public: public:
void sendChannelNotification(const QString &channelName, int &platform); void sendChannelNotification(const QString &channelName, Platform p);
bool isEnabled(const QString &channelName);
/* /*
Toasts(); Toasts();
virtual void initialize(Settings &settings, Paths &paths) override final; virtual void initialize(Settings &settings, Paths &paths) override final;
*/ */
static bool isEnabled();
private: private:
void sendWindowsNotification(const QString &channelName, int &platform); void sendWindowsNotification(const QString &channelName, Platform p);
/* /*
void updateLiveChannels(const QString &channelName); void updateLiveChannels(const QString &channelName);
void removeFromLiveChannels(const QString &channelName); void removeFromLiveChannels(const QString &channelName);
@@ -35,16 +35,19 @@ NotificationPage::NotificationPage()
getApp()->settings->notificationFlashTaskbar)); getApp()->settings->notificationFlashTaskbar));
settings.append(this->createCheckBox( settings.append(this->createCheckBox(
"Playsound", getApp()->settings->notificationPlaySound)); "Playsound", getApp()->settings->notificationPlaySound));
settings.append(this->createCheckBox(
"Enable toasts (currently only for windows)",
getApp()->settings->notificationToast));
settings->addStretch(1); settings->addStretch(1);
} }
auto twitchChannels = tabs.appendTab(new QVBoxLayout, "Twitch"); auto twitchChannels = tabs.appendTab(new QVBoxLayout, "Twitch");
{ {
int i = 0;
EditableModelView *view = EditableModelView *view =
twitchChannels twitchChannels
.emplace<EditableModelView>( .emplace<EditableModelView>(
getApp()->notifications->createModel(nullptr, i)) getApp()->notifications->createModel(
nullptr, Platform::Twitch))
.getElement(); .getElement();
view->setTitles({"Twitch channels"}); view->setTitles({"Twitch channels"});
@@ -64,11 +67,11 @@ NotificationPage::NotificationPage()
} }
auto mixerChannels = tabs.appendTab(new QVBoxLayout, "Mixer"); auto mixerChannels = tabs.appendTab(new QVBoxLayout, "Mixer");
{ {
int i = 1;
EditableModelView *view = EditableModelView *view =
mixerChannels mixerChannels
.emplace<EditableModelView>( .emplace<EditableModelView>(
getApp()->notifications->createModel(nullptr, i)) getApp()->notifications->createModel(
nullptr, Platform::Mixer))
.getElement(); .getElement();
view->setTitles({"Mixer channels"}); view->setTitles({"Mixer channels"});
+2 -4
View File
@@ -161,14 +161,12 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
action->setCheckable(true); action->setCheckable(true);
QObject::connect(menu.get(), &QMenu::aboutToShow, this, [action, this]() { QObject::connect(menu.get(), &QMenu::aboutToShow, this, [action, this]() {
int i = 0;
action->setChecked(getApp()->notifications->isChannelNotified( action->setChecked(getApp()->notifications->isChannelNotified(
this->split_->getChannel()->getName(), i)); this->split_->getChannel()->getName(), Platform::Twitch));
}); });
action->connect(action, &QAction::triggered, this, [this]() { action->connect(action, &QAction::triggered, this, [this]() {
int i = 0;
getApp()->notifications->updateChannelNotification( getApp()->notifications->updateChannelNotification(
this->split_->getChannel()->getName(), i); this->split_->getChannel()->getName(), Platform::Twitch);
}); });
menu->addAction(action); menu->addAction(action);