temp stuff

This commit is contained in:
apa420 2018-08-12 15:29:40 +02:00
parent 2de99ca9f5
commit 54166ec130
8 changed files with 185 additions and 50 deletions

View file

@ -14,38 +14,68 @@ namespace chatterino {
void NotificationController::initialize(Settings &settings, Paths &paths) void NotificationController::initialize(Settings &settings, Paths &paths)
{ {
this->initialized_ = true; this->initialized_ = true;
for (const QString &channelName : this->notificationSetting_.getValue()) { for (const QString &channelName : this->twitchSetting_.getValue()) {
this->notificationVector.appendItem(channelName); this->twitchVector.appendItem(channelName);
} }
this->notificationVector.delayedItemsChanged.connect([this] { // this->twitchVector.delayedItemsChanged.connect([this] { //
this->notificationSetting_.setValue( this->twitchSetting_.setValue(this->twitchVector.getVector());
this->notificationVector.getVector()); });
for (const QString &channelName : this->mixerSetting_.getValue()) {
this->mixerVector.appendItem(channelName);
}
this->mixerVector.delayedItemsChanged.connect([this] { //
this->mixerSetting_.setValue(this->mixerVector.getVector());
}); });
} }
void NotificationController::updateChannelNotification( void NotificationController::updateChannelNotification(
const QString &channelName) const QString &channelName, int &i)
{ {
if (isChannelNotified(channelName)) { if (i == 0) {
removeChannelNotification(channelName); int j = 0;
} else { if (isChannelNotified(channelName, j)) {
addChannelNotification(channelName); removeChannelNotification(channelName, twitchVector);
} else {
addChannelNotification(channelName, twitchVector);
}
} else if (i == 1) {
int k = 1;
if (isChannelNotified(channelName, k)) {
removeChannelNotification(channelName, mixerVector);
} else {
addChannelNotification(channelName, mixerVector);
}
} }
} }
bool NotificationController::isChannelNotified(const QString &channelName) bool NotificationController::isChannelNotified(const QString &channelName,
int &i)
{ {
/*
for (std::vector<int>::size_type i = 0; for (std::vector<int>::size_type i = 0;
i != notificationVector.getVector().size(); i++) { i != notificationVector.getVector().size(); i++) {
qDebug() << notificationVector.getVector()[i] qDebug() << notificationVector.getVector()[i]
<< " vector to the left channel to the right " << channelName << " vector to the left channel to the right " << channelName
<< " vectorsize:" << notificationVector.getVector().size(); << " vectorsize:" << notificationVector.getVector().size();
} }
for (std::vector<int>::size_type i = 0; */
i != notificationVector.getVector().size(); i++) { qDebug() << channelName << " channel and now i: " << i;
if (notificationVector.getVector()[i] == channelName) { if (i == 0) {
return true; for (std::vector<int>::size_type i = 0;
i != twitchVector.getVector().size(); i++) {
if (twitchVector.getVector()[i] == channelName) {
return true;
}
}
} else if (i == 1) {
for (std::vector<int>::size_type i = 0;
i != mixerVector.getVector().size(); i++) {
if (mixerVector.getVector()[i] == channelName) {
return true;
}
} }
} }
return false; return false;
@ -92,13 +122,14 @@ public:
} }
}; };
*/ */
void NotificationController::addChannelNotification(const QString &channelName) void NotificationController::addChannelNotification(
const QString &channelName, UnsortedSignalVector<QString> &vector)
{ {
notificationVector.appendItem(channelName); vector.appendItem(channelName);
if (WinToastLib::WinToast::isCompatible()) { if (WinToastLib::WinToast::isCompatible()) {
QDir dir; // QDir dir;
qDebug() << "NaM" << dir.absolutePath(); // qDebug() << "NaM" << dir.absolutePath();
/* /*
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate( WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
@ -122,21 +153,25 @@ void NotificationController::addChannelNotification(const QString &channelName)
} }
void NotificationController::removeChannelNotification( void NotificationController::removeChannelNotification(
const QString &channelName) const QString &channelName, UnsortedSignalVector<QString> &vector)
{ {
for (std::vector<int>::size_type i = 0; for (std::vector<int>::size_type i = 0; i != vector.getVector().size();
i != notificationVector.getVector().size(); i++) { i++) {
if (notificationVector.getVector()[i] == channelName) { if (vector.getVector()[i] == channelName) {
notificationVector.removeItem(i); vector.removeItem(i);
i--; i--;
} }
} }
} }
NotificationModel *NotificationController::createModel(QObject *parent) NotificationModel *NotificationController::createModel(QObject *parent, int &i)
{ {
NotificationModel *model = new NotificationModel(parent); NotificationModel *model = new NotificationModel(parent);
model->init(&this->notificationVector); if (i == 0) {
model->init(&this->twitchVector);
} else if (i == 1) {
model->init(&this->mixerVector);
}
return model; return model;
} }

View file

@ -15,21 +15,27 @@ 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); bool isChannelNotified(const QString &channelName, int &i);
void updateChannelNotification(const QString &channelName); void updateChannelNotification(const QString &channelName, int &i);
void addChannelNotification(const QString &channelName); void addChannelNotification(const QString &channelName,
void removeChannelNotification(const QString &channelName); UnsortedSignalVector<QString> &vector);
void removeChannelNotification(const QString &channelName,
UnsortedSignalVector<QString> &vector);
UnsortedSignalVector<QString> notificationVector; UnsortedSignalVector<QString> getVector(int &i);
NotificationModel *createModel(QObject *parent); UnsortedSignalVector<QString> twitchVector;
UnsortedSignalVector<QString> mixerVector;
NotificationModel *createModel(QObject *parent, int &i);
private: private:
bool initialized_ = false; bool initialized_ = false;
ChatterinoSetting<std::vector<QString>> twitchSetting_ = {
ChatterinoSetting<std::vector<QString>> notificationSetting_ = { "/notifications/twitch"};
"/notifications/channels"}; ChatterinoSetting<std::vector<QString>> mixerSetting_ = {
"/notifications/mixer"};
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -3,6 +3,7 @@
#include "common/Common.hpp" #include "common/Common.hpp"
#include "common/NetworkRequest.hpp" #include "common/NetworkRequest.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "providers/bttv/LoadBttvChannelEmote.hpp" #include "providers/bttv/LoadBttvChannelEmote.hpp"
@ -12,6 +13,7 @@
#include "providers/twitch/TwitchParseCheerEmotes.hpp" #include "providers/twitch/TwitchParseCheerEmotes.hpp"
#include "singletons/Emotes.hpp" #include "singletons/Emotes.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/Toasts.hpp"
#include "util/PostToThread.hpp" #include "util/PostToThread.hpp"
#include <IrcConnection> #include <IrcConnection>
@ -303,6 +305,19 @@ 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;
@ -319,6 +334,40 @@ void TwitchChannel::setLive(bool newLiveStatus)
} }
} }
/*
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 (gotNewLiveStatus) {
this->liveStatusChanged.invoke();
}
}
*/
void TwitchChannel::refreshLiveStatus() void TwitchChannel::refreshLiveStatus()
{ {
auto roomID = this->getRoomId(); auto roomID = this->getRoomId();
@ -391,10 +440,17 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
{ {
auto status = this->streamStatus_.access(); auto status = this->streamStatus_.access();
if (!status->live /*&&*/) { /*
if (!status->live == false &&
getApp()->toasts->isEnabled(this->getName())) {
int i = 0;
getApp()->toasts->sendChannelNotification(this->getName(), i);
// notifcation send // notifcation send
} }
status->live = true; status->live = true;
*/
this->setLive(true);
// status->live = true;
status->viewerCount = stream["viewers"].GetUint(); status->viewerCount = stream["viewers"].GetUint();
status->game = stream["game"].GetString(); status->game = stream["game"].GetString();
status->title = streamChannel["status"].GetString(); status->title = streamChannel["status"].GetString();

View file

@ -118,6 +118,8 @@ private:
void loadRecentMessages(); void loadRecentMessages();
Outcome parseRecentMessages(const QJsonObject &jsonRoot); Outcome parseRecentMessages(const QJsonObject &jsonRoot);
bool toastIsEnabled();
void setLive(bool newLiveStatus); void setLive(bool newLiveStatus);
void loadBadges(); void loadBadges();

View file

@ -14,10 +14,12 @@
namespace chatterino { namespace chatterino {
/*
Toasts::Toasts() Toasts::Toasts()
{ {
} }
*/
/*
void Toasts::initialize(Settings &settings, Paths &paths) void Toasts::initialize(Settings &settings, Paths &paths)
{ {
getApp()->twitch2->forEachChannel([this](ChannelPtr chn) { getApp()->twitch2->forEachChannel([this](ChannelPtr chn) {
@ -67,12 +69,12 @@ bool Toasts::wasChannelLive(const QString &channelName)
} }
return false; return false;
} }
*/
void Toasts::sendChannelNotification(const QString &channelName) void Toasts::sendChannelNotification(const QString &channelName, int &platform)
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (WinToastLib::WinToast::isCompatible()) { if (WinToastLib::WinToast::isCompatible()) {
sendWindowsNotification(channelName); sendWindowsNotification(channelName, platform);
} }
#endif #endif
// OSX // OSX
@ -125,7 +127,7 @@ public:
} }
}; };
void Toasts::sendWindowsNotification(const QString &channelName) void Toasts::sendWindowsNotification(const QString &channelName, int &platform)
{ {
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate( WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
WinToastLib::WinToastTemplate::ImageAndText02); WinToastLib::WinToastTemplate::ImageAndText02);

View file

@ -3,17 +3,23 @@
#include "Application.hpp" #include "Application.hpp"
#include "common/Singleton.hpp" #include "common/Singleton.hpp"
#include <mutex> //#include <mutex>
namespace chatterino { namespace chatterino {
class Toasts final : public Singleton class Toasts final : public Singleton
{ {
public: public:
void sendChannelNotification(const QString &channelName, int &platform);
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;
*/
private: private:
void sendWindowsNotification(const QString &channelName, int &platform);
/*
void updateLiveChannels(const QString &channelName); void updateLiveChannels(const QString &channelName);
void removeFromLiveChannels(const QString &channelName); void removeFromLiveChannels(const QString &channelName);
@ -24,5 +30,6 @@ private:
void sendWindowsNotification(const QString &channelName); void sendWindowsNotification(const QString &channelName);
std::vector<QString> liveChannels; std::vector<QString> liveChannels;
std::mutex mutex_; std::mutex mutex_;
*/
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -38,14 +38,15 @@ NotificationPage::NotificationPage()
settings->addStretch(1); settings->addStretch(1);
} }
auto channels = tabs.appendTab(new QVBoxLayout, "Channels"); auto twitchChannels = tabs.appendTab(new QVBoxLayout, "Twitch");
{ {
int i = 0;
EditableModelView *view = EditableModelView *view =
channels twitchChannels
.emplace<EditableModelView>( .emplace<EditableModelView>(
getApp()->notifications->createModel(nullptr)) getApp()->notifications->createModel(nullptr, i))
.getElement(); .getElement();
view->setTitles({"Channels"}); view->setTitles({"Twitch channels"});
view->getTableView()->horizontalHeader()->setSectionResizeMode( view->getTableView()->horizontalHeader()->setSectionResizeMode(
QHeaderView::Fixed); QHeaderView::Fixed);
@ -58,8 +59,31 @@ NotificationPage::NotificationPage()
}); });
view->addButtonPressed.connect([] { view->addButtonPressed.connect([] {
getApp()->notifications->notificationVector.appendItem( getApp()->notifications->twitchVector.appendItem("channel");
"channel"); });
}
auto mixerChannels = tabs.appendTab(new QVBoxLayout, "Mixer");
{
int i = 1;
EditableModelView *view =
mixerChannels
.emplace<EditableModelView>(
getApp()->notifications->createModel(nullptr, i))
.getElement();
view->setTitles({"Mixer channels"});
view->getTableView()->horizontalHeader()->setSectionResizeMode(
QHeaderView::Fixed);
view->getTableView()->horizontalHeader()->setSectionResizeMode(
0, QHeaderView::Stretch);
QTimer::singleShot(1, [view] {
view->getTableView()->resizeColumnsToContents();
view->getTableView()->setColumnWidth(0, 200);
});
view->addButtonPressed.connect([] {
getApp()->notifications->mixerVector.appendItem("channel");
}); });
} }
} }

View file

@ -159,13 +159,16 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
auto action = new QAction(this); auto action = new QAction(this);
action->setText("Notify when live"); action->setText("Notify when live");
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())); this->split_->getChannel()->getName(), i));
}); });
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()); this->split_->getChannel()->getName(), i);
}); });
menu->addAction(action); menu->addAction(action);