mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
temp stuff
This commit is contained in:
parent
2de99ca9f5
commit
54166ec130
|
@ -14,40 +14,70 @@ namespace chatterino {
|
|||
void NotificationController::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->initialized_ = true;
|
||||
for (const QString &channelName : this->notificationSetting_.getValue()) {
|
||||
this->notificationVector.appendItem(channelName);
|
||||
for (const QString &channelName : this->twitchSetting_.getValue()) {
|
||||
this->twitchVector.appendItem(channelName);
|
||||
}
|
||||
|
||||
this->notificationVector.delayedItemsChanged.connect([this] { //
|
||||
this->notificationSetting_.setValue(
|
||||
this->notificationVector.getVector());
|
||||
this->twitchVector.delayedItemsChanged.connect([this] { //
|
||||
this->twitchSetting_.setValue(this->twitchVector.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(
|
||||
const QString &channelName)
|
||||
const QString &channelName, int &i)
|
||||
{
|
||||
if (isChannelNotified(channelName)) {
|
||||
removeChannelNotification(channelName);
|
||||
if (i == 0) {
|
||||
int j = 0;
|
||||
if (isChannelNotified(channelName, j)) {
|
||||
removeChannelNotification(channelName, twitchVector);
|
||||
} else {
|
||||
addChannelNotification(channelName);
|
||||
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;
|
||||
i != notificationVector.getVector().size(); i++) {
|
||||
qDebug() << notificationVector.getVector()[i]
|
||||
<< " vector to the left channel to the right " << channelName
|
||||
<< " vectorsize:" << notificationVector.getVector().size();
|
||||
}
|
||||
*/
|
||||
qDebug() << channelName << " channel and now i: " << i;
|
||||
if (i == 0) {
|
||||
for (std::vector<int>::size_type i = 0;
|
||||
i != notificationVector.getVector().size(); i++) {
|
||||
if (notificationVector.getVector()[i] == channelName) {
|
||||
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;
|
||||
}
|
||||
/*
|
||||
|
@ -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()) {
|
||||
QDir dir;
|
||||
qDebug() << "NaM" << dir.absolutePath();
|
||||
// QDir dir;
|
||||
// qDebug() << "NaM" << dir.absolutePath();
|
||||
/*
|
||||
|
||||
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
|
||||
|
@ -122,21 +153,25 @@ void NotificationController::addChannelNotification(const QString &channelName)
|
|||
}
|
||||
|
||||
void NotificationController::removeChannelNotification(
|
||||
const QString &channelName)
|
||||
const QString &channelName, UnsortedSignalVector<QString> &vector)
|
||||
{
|
||||
for (std::vector<int>::size_type i = 0;
|
||||
i != notificationVector.getVector().size(); i++) {
|
||||
if (notificationVector.getVector()[i] == channelName) {
|
||||
notificationVector.removeItem(i);
|
||||
for (std::vector<int>::size_type i = 0; i != vector.getVector().size();
|
||||
i++) {
|
||||
if (vector.getVector()[i] == channelName) {
|
||||
vector.removeItem(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationModel *NotificationController::createModel(QObject *parent)
|
||||
NotificationModel *NotificationController::createModel(QObject *parent, int &i)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,21 +15,27 @@ class NotificationController final : public Singleton
|
|||
public:
|
||||
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 addChannelNotification(const QString &channelName);
|
||||
void removeChannelNotification(const QString &channelName);
|
||||
void updateChannelNotification(const QString &channelName, int &i);
|
||||
void addChannelNotification(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:
|
||||
bool initialized_ = false;
|
||||
|
||||
ChatterinoSetting<std::vector<QString>> notificationSetting_ = {
|
||||
"/notifications/channels"};
|
||||
ChatterinoSetting<std::vector<QString>> twitchSetting_ = {
|
||||
"/notifications/twitch"};
|
||||
ChatterinoSetting<std::vector<QString>> mixerSetting_ = {
|
||||
"/notifications/mixer"};
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/notifications/NotificationController.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/bttv/LoadBttvChannelEmote.hpp"
|
||||
|
@ -12,6 +13,7 @@
|
|||
#include "providers/twitch/TwitchParseCheerEmotes.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Toasts.hpp"
|
||||
#include "util/PostToThread.hpp"
|
||||
|
||||
#include <IrcConnection>
|
||||
|
@ -303,6 +305,19 @@ const QString &TwitchChannel::getPopoutPlayerUrl()
|
|||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
auto roomID = this->getRoomId();
|
||||
|
@ -391,10 +440,17 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
|
|||
|
||||
{
|
||||
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
|
||||
}
|
||||
status->live = true;
|
||||
*/
|
||||
this->setLive(true);
|
||||
// status->live = true;
|
||||
status->viewerCount = stream["viewers"].GetUint();
|
||||
status->game = stream["game"].GetString();
|
||||
status->title = streamChannel["status"].GetString();
|
||||
|
|
|
@ -118,6 +118,8 @@ private:
|
|||
void loadRecentMessages();
|
||||
Outcome parseRecentMessages(const QJsonObject &jsonRoot);
|
||||
|
||||
bool toastIsEnabled();
|
||||
|
||||
void setLive(bool newLiveStatus);
|
||||
|
||||
void loadBadges();
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
/*
|
||||
Toasts::Toasts()
|
||||
{
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
void Toasts::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
getApp()->twitch2->forEachChannel([this](ChannelPtr chn) {
|
||||
|
@ -67,12 +69,12 @@ bool Toasts::wasChannelLive(const QString &channelName)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Toasts::sendChannelNotification(const QString &channelName)
|
||||
*/
|
||||
void Toasts::sendChannelNotification(const QString &channelName, int &platform)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if (WinToastLib::WinToast::isCompatible()) {
|
||||
sendWindowsNotification(channelName);
|
||||
sendWindowsNotification(channelName, platform);
|
||||
}
|
||||
#endif
|
||||
// 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::ImageAndText02);
|
||||
|
|
|
@ -3,17 +3,23 @@
|
|||
#include "Application.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
#include <mutex>
|
||||
//#include <mutex>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Toasts final : public Singleton
|
||||
{
|
||||
public:
|
||||
void sendChannelNotification(const QString &channelName, int &platform);
|
||||
bool isEnabled(const QString &channelName);
|
||||
/*
|
||||
Toasts();
|
||||
virtual void initialize(Settings &settings, Paths &paths) override final;
|
||||
*/
|
||||
|
||||
private:
|
||||
void sendWindowsNotification(const QString &channelName, int &platform);
|
||||
/*
|
||||
void updateLiveChannels(const QString &channelName);
|
||||
void removeFromLiveChannels(const QString &channelName);
|
||||
|
||||
|
@ -24,5 +30,6 @@ private:
|
|||
void sendWindowsNotification(const QString &channelName);
|
||||
std::vector<QString> liveChannels;
|
||||
std::mutex mutex_;
|
||||
*/
|
||||
};
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -38,14 +38,15 @@ NotificationPage::NotificationPage()
|
|||
|
||||
settings->addStretch(1);
|
||||
}
|
||||
auto channels = tabs.appendTab(new QVBoxLayout, "Channels");
|
||||
auto twitchChannels = tabs.appendTab(new QVBoxLayout, "Twitch");
|
||||
{
|
||||
int i = 0;
|
||||
EditableModelView *view =
|
||||
channels
|
||||
twitchChannels
|
||||
.emplace<EditableModelView>(
|
||||
getApp()->notifications->createModel(nullptr))
|
||||
getApp()->notifications->createModel(nullptr, i))
|
||||
.getElement();
|
||||
view->setTitles({"Channels"});
|
||||
view->setTitles({"Twitch channels"});
|
||||
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
QHeaderView::Fixed);
|
||||
|
@ -58,8 +59,31 @@ NotificationPage::NotificationPage()
|
|||
});
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
getApp()->notifications->notificationVector.appendItem(
|
||||
"channel");
|
||||
getApp()->notifications->twitchVector.appendItem("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");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,13 +159,16 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
|
|||
auto action = new QAction(this);
|
||||
action->setText("Notify when live");
|
||||
action->setCheckable(true);
|
||||
|
||||
QObject::connect(menu.get(), &QMenu::aboutToShow, this, [action, this]() {
|
||||
int i = 0;
|
||||
action->setChecked(getApp()->notifications->isChannelNotified(
|
||||
this->split_->getChannel()->getName()));
|
||||
this->split_->getChannel()->getName(), i));
|
||||
});
|
||||
action->connect(action, &QAction::triggered, this, [this]() {
|
||||
int i = 0;
|
||||
getApp()->notifications->updateChannelNotification(
|
||||
this->split_->getChannel()->getName());
|
||||
this->split_->getChannel()->getName(), i);
|
||||
});
|
||||
menu->addAction(action);
|
||||
|
||||
|
|
Loading…
Reference in a new issue