more stuff done, does compile, changed vector for map
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QMediaPlayer>
|
||||
#include <QUrl>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -15,162 +16,113 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->initialized_ = true;
|
||||
for (const QString &channelName : this->twitchSetting_.getValue()) {
|
||||
this->twitchVector.appendItem(channelName);
|
||||
this->channelMap[Platform::Twitch].appendItem(channelName);
|
||||
}
|
||||
|
||||
this->twitchVector.delayedItemsChanged.connect([this] { //
|
||||
this->twitchSetting_.setValue(this->twitchVector.getVector());
|
||||
this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] { //
|
||||
this->twitchSetting_.setValue(
|
||||
this->channelMap[Platform::Twitch].getVector());
|
||||
});
|
||||
|
||||
for (const QString &channelName : this->mixerSetting_.getValue()) {
|
||||
this->mixerVector.appendItem(channelName);
|
||||
this->channelMap[Platform::Mixer].appendItem(channelName);
|
||||
}
|
||||
|
||||
this->mixerVector.delayedItemsChanged.connect([this] { //
|
||||
this->mixerSetting_.setValue(this->mixerVector.getVector());
|
||||
this->channelMap[Platform::Mixer].delayedItemsChanged.connect([this] { //
|
||||
this->mixerSetting_.setValue(
|
||||
this->channelMap[Platform::Mixer].getVector());
|
||||
});
|
||||
}
|
||||
|
||||
void NotificationController::updateChannelNotification(
|
||||
const QString &channelName, Platform p)
|
||||
{
|
||||
if (p == Platform::Twitch) {
|
||||
if (isChannelNotified(channelName, Platform::Twitch)) {
|
||||
removeChannelNotification(channelName, twitchVector);
|
||||
} else {
|
||||
addChannelNotification(channelName, twitchVector);
|
||||
}
|
||||
} else if (p == Platform::Mixer) {
|
||||
if (isChannelNotified(channelName, Platform::Mixer)) {
|
||||
removeChannelNotification(channelName, mixerVector);
|
||||
} else {
|
||||
addChannelNotification(channelName, mixerVector);
|
||||
}
|
||||
if (isChannelNotified(channelName, p)) {
|
||||
removeChannelNotification(channelName, p);
|
||||
} else {
|
||||
addChannelNotification(channelName, p);
|
||||
}
|
||||
}
|
||||
|
||||
bool NotificationController::isChannelNotified(const QString &channelName,
|
||||
Platform p)
|
||||
{
|
||||
/*
|
||||
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();
|
||||
for (const auto &channel : this->channelMap[p].getVector()) {
|
||||
if (channelName.toLower() == channel.toLower()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
// qDebug() << channelName << " channel and now i: " << i;
|
||||
// for (std::vector<int>::size_type i = 0; i != channelMap[p])
|
||||
/*
|
||||
if (p == Platform::Twitch) {
|
||||
for (std::vector<int>::size_type i = 0;
|
||||
i != twitchVector.getVector().size(); i++) {
|
||||
if (twitchVector.getVector()[i] == channelName) {
|
||||
return true;
|
||||
if (twitchVector.getVector()[i].toLower() ==
|
||||
channelName.toLowercase()) { return true;
|
||||
}
|
||||
}
|
||||
} else if (p == Platform::Mixer) {
|
||||
for (std::vector<int>::size_type i = 0;
|
||||
i != mixerVector.getVector().size(); i++) {
|
||||
if (mixerVector.getVector()[i] == channelName) {
|
||||
return true;
|
||||
if (mixerVector.getVector()[i].toLower() ==
|
||||
channelName.toLowercase()) { return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
class CustomHandler : public WinToastLib::IWinToastHandler
|
||||
|
||||
void NotificationController::addChannelNotification(const QString &channelName,
|
||||
Platform p)
|
||||
{
|
||||
public:
|
||||
void toastActivated() const
|
||||
{
|
||||
std::wcout << L"The user clicked in this toast" << std::endl;
|
||||
}
|
||||
|
||||
void toastActivated(int actionIndex) const
|
||||
{
|
||||
std::wcout << L"The user clicked on button #" << actionIndex
|
||||
<< L" in this toast" << std::endl;
|
||||
QDesktopServices::openUrl(
|
||||
QUrl("http://www.google.com", QUrl::TolerantMode));
|
||||
}
|
||||
|
||||
void toastFailed() const
|
||||
{
|
||||
std::wcout << L"Error showing current toast" << std::endl;
|
||||
}
|
||||
void toastDismissed(WinToastDismissalReason state) const
|
||||
{
|
||||
switch (state) {
|
||||
case UserCanceled:
|
||||
std::wcout << L"The user dismissed this toast" << std::endl;
|
||||
break;
|
||||
case ApplicationHidden:
|
||||
std::wcout << L"The application hid the toast using "
|
||||
L"ToastNotifier.hide()"
|
||||
<< std::endl;
|
||||
break;
|
||||
case TimedOut:
|
||||
std::wcout << L"The toast has timed out" << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::wcout << L"Toast not activated" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
*/
|
||||
void NotificationController::addChannelNotification(
|
||||
const QString &channelName, UnsortedSignalVector<QString> &vector)
|
||||
{
|
||||
vector.appendItem(channelName);
|
||||
|
||||
if (WinToastLib::WinToast::isCompatible()) {
|
||||
// QDir dir;
|
||||
// qDebug() << "NaM" << dir.absolutePath();
|
||||
/*
|
||||
|
||||
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
|
||||
WinToastLib::WinToastTemplate::ImageAndText02);
|
||||
templ.setTextField(L"Your favorite streamer has gone live!",
|
||||
WinToastLib::WinToastTemplate::FirstLine);
|
||||
templ.setTextField(L"NaM!", WinToastLib::WinToastTemplate::SecondLine);
|
||||
// templ.setExpiration(10);
|
||||
// templ.setImagePath();
|
||||
// templ.setAudioOption(WinToastLib::WinToastTemplate::Silent);
|
||||
// templ.setAudioPath(L"C:/ping2.wav");
|
||||
WinToastLib::WinToast::instance()->setAppName(L"Chatterino2");
|
||||
WinToastLib::WinToast::instance()->setAppUserModelId(
|
||||
WinToastLib::WinToast::configureAUMI(
|
||||
L"mohabouje", L"wintoast", L"wintoastexample", L"20161006"));
|
||||
WinToastLib::WinToast::instance()->initialize();
|
||||
WinToastLib::WinToast::instance()->showToast(templ,
|
||||
new CustomHandler());
|
||||
*/
|
||||
}
|
||||
channelMap[p].appendItem(channelName);
|
||||
}
|
||||
|
||||
void NotificationController::removeChannelNotification(
|
||||
const QString &channelName, UnsortedSignalVector<QString> &vector)
|
||||
const QString &channelName, Platform p)
|
||||
{
|
||||
for (std::vector<int>::size_type i = 0; i != vector.getVector().size();
|
||||
i++) {
|
||||
if (vector.getVector()[i] == channelName) {
|
||||
vector.removeItem(i);
|
||||
for (std::vector<int>::size_type i = 0;
|
||||
i != channelMap[p].getVector().size(); i++) {
|
||||
if (channelMap[p].getVector()[i].toLower() == channelName) {
|
||||
channelMap[p].removeItem(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationController::playSound()
|
||||
{
|
||||
static auto player = new QMediaPlayer;
|
||||
static QUrl currentPlayerUrl;
|
||||
|
||||
QUrl highlightSoundUrl;
|
||||
if (getApp()->settings->customHighlightSound) {
|
||||
highlightSoundUrl = QUrl::fromLocalFile(
|
||||
getApp()->settings->pathHighlightSound.getValue());
|
||||
} else {
|
||||
highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav");
|
||||
}
|
||||
if (currentPlayerUrl != highlightSoundUrl) {
|
||||
player->setMedia(highlightSoundUrl);
|
||||
|
||||
currentPlayerUrl = highlightSoundUrl;
|
||||
}
|
||||
player->play();
|
||||
}
|
||||
|
||||
NotificationModel *NotificationController::createModel(QObject *parent,
|
||||
Platform p)
|
||||
{
|
||||
NotificationModel *model = new NotificationModel(parent);
|
||||
model->init(&this->channelMap[p]);
|
||||
/*
|
||||
if (p == Platform::Twitch) {
|
||||
model->init(&this->twitchVector);
|
||||
} else if (p == Platform::Mixer) {
|
||||
model->init(&this->mixerVector);
|
||||
}
|
||||
*/
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user