From 5015633cc73d862d882ab0a7c440aec26d1bffed Mon Sep 17 00:00:00 2001
From: fourtf
Date: Fri, 20 Apr 2018 22:33:28 +0200
Subject: [PATCH] improved saving of splits and watching split
---
src/channel.hpp | 2 +-
src/singletons/accountmanager.cpp | 2 +-
src/singletons/windowmanager.cpp | 45 +++++++++++++++++++++++++----
src/singletons/windowmanager.hpp | 3 ++
src/widgets/helper/splitheader.cpp | 21 ++++++++------
src/widgets/selectchanneldialog.cpp | 2 +-
src/widgets/split.cpp | 6 ++--
7 files changed, 60 insertions(+), 21 deletions(-)
diff --git a/src/channel.hpp b/src/channel.hpp
index 0342138f3..6a2433f6a 100644
--- a/src/channel.hpp
+++ b/src/channel.hpp
@@ -90,7 +90,7 @@ class IndirectChannel
std::shared_ptr data;
public:
- IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::None)
+ IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Direct)
: data(new Data(channel, type))
{
}
diff --git a/src/singletons/accountmanager.cpp b/src/singletons/accountmanager.cpp
index 93be71b42..59e41f3fc 100644
--- a/src/singletons/accountmanager.cpp
+++ b/src/singletons/accountmanager.cpp
@@ -36,7 +36,7 @@ void AccountManager::load()
this->Twitch.currentUser = this->Twitch.anonymousUser;
}
- this->Twitch.userChanged.invoke();
+ // this->Twitch.userChanged.invoke();
}
} // namespace singletons
diff --git a/src/singletons/windowmanager.cpp b/src/singletons/windowmanager.cpp
index e91d5d43b..af4e59741 100644
--- a/src/singletons/windowmanager.cpp
+++ b/src/singletons/windowmanager.cpp
@@ -198,11 +198,7 @@ void WindowManager::initialize()
widgets::Split *split = new widgets::Split(tab);
QJsonObject split_obj = split_val.toObject();
- QJsonValue channelName_val = split_obj.value("channelName");
- if (channelName_val.isString()) {
- split->setChannel(providers::twitch::TwitchServer::getInstance().addChannel(
- channelName_val.toString()));
- }
+ split->setChannel(this->decodeChannel(split_obj));
tab->addToLayout(split, std::make_pair(colNr, 10000000));
}
@@ -270,7 +266,8 @@ void WindowManager::save()
for (widgets::Split *cell : cells) {
QJsonObject cell_obj;
- cell_obj.insert("channelName", cell->getChannel().get()->name);
+
+ this->encodeChannel(cell->getIndirectChannel(), cell_obj);
cells_arr.append(cell_obj);
}
@@ -297,6 +294,42 @@ void WindowManager::save()
file.flush();
}
+void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj)
+{
+ switch (channel.getType()) {
+ case Channel::Twitch: {
+ obj.insert("type", "twitch");
+ obj.insert("name", channel.get()->name);
+ } break;
+ case Channel::TwitchMentions: {
+ obj.insert("type", "mentions");
+ } break;
+ case Channel::TwitchWatching: {
+ obj.insert("type", "watching");
+ } break;
+ case Channel::TwitchWhispers: {
+ obj.insert("type", "whispers");
+ } break;
+ }
+}
+
+IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj)
+{
+ QString type = obj.value("type").toString();
+ if (type == "twitch") {
+ return providers::twitch::TwitchServer::getInstance().addChannel(
+ obj.value("name").toString());
+ } else if (type == "mentions") {
+ return providers::twitch::TwitchServer::getInstance().mentionsChannel;
+ } else if (type == "watching") {
+ return providers::twitch::TwitchServer::getInstance().watchingChannel;
+ } else if (type == "whispers") {
+ return providers::twitch::TwitchServer::getInstance().whispersChannel;
+ }
+
+ return Channel::getEmpty();
+}
+
void WindowManager::closeAll()
{
for (widgets::Window *window : windows) {
diff --git a/src/singletons/windowmanager.hpp b/src/singletons/windowmanager.hpp
index 349de4cc6..45af41e68 100644
--- a/src/singletons/windowmanager.hpp
+++ b/src/singletons/windowmanager.hpp
@@ -45,6 +45,9 @@ private:
widgets::Window *mainWindow = nullptr;
widgets::Window *selectedWindow = nullptr;
+
+ void encodeChannel(IndirectChannel channel, QJsonObject &obj);
+ IndirectChannel decodeChannel(const QJsonObject &obj);
};
} // namespace singletons
diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp
index 677a4dbee..1d1c35d33 100644
--- a/src/widgets/helper/splitheader.cpp
+++ b/src/widgets/helper/splitheader.cpp
@@ -154,12 +154,13 @@ void SplitHeader::scaleChangedEvent(float scale)
void SplitHeader::updateChannelText()
{
+ auto indirectChannel = this->split->getIndirectChannel();
auto channel = this->split->getChannel();
- const QString channelName = channel->name;
- if (channelName.isEmpty()) {
- this->titleLabel->setText("");
- return;
+ QString title = channel->name;
+
+ if (indirectChannel.getType() == Channel::TwitchWatching) {
+ title = "watching: " + (title.isEmpty() ? "none" : title);
}
TwitchChannel *twitchChannel = dynamic_cast(channel.get());
@@ -178,17 +179,19 @@ void SplitHeader::updateChannelText()
" viewers"
"
";
if (streamStatus.rerun) {
- this->titleLabel->setText(channelName + " (rerun)");
+ title += " (rerun)";
} else {
- this->titleLabel->setText(channelName + " (live)");
+ title += " (live)";
}
-
- return;
}
}
+ if (title.isEmpty()) {
+ title = "";
+ }
+
this->isLive = false;
- this->titleLabel->setText(channelName);
+ this->titleLabel->setText(title);
this->tooltip = "";
}
diff --git a/src/widgets/selectchanneldialog.cpp b/src/widgets/selectchanneldialog.cpp
index 25517d7e6..580a02469 100644
--- a/src/widgets/selectchanneldialog.cpp
+++ b/src/widgets/selectchanneldialog.cpp
@@ -146,7 +146,7 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel)
this->selectedChannel = channel;
- switch (channel->getType()) {
+ switch (_channel.getType()) {
case Channel::Twitch: {
this->ui.notebook->selectIndex(TAB_TWITCH);
this->ui.twitch.channel->setFocus();
diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp
index e4117f673..a2c801738 100644
--- a/src/widgets/split.cpp
+++ b/src/widgets/split.cpp
@@ -134,13 +134,13 @@ ChannelPtr Split::getChannel()
void Split::setChannel(IndirectChannel newChannel)
{
+ this->channel = newChannel;
+
this->view.setChannel(newChannel.get());
this->usermodeChangedConnection.disconnect();
this->indirectChannelChangedConnection.disconnect();
- this->channel = newChannel;
-
TwitchChannel *tc = dynamic_cast(newChannel.get().get());
if (tc != nullptr) {
@@ -199,7 +199,7 @@ void Split::showChangeChannelPopup(const char *dialogTitle, bool empty,
{
SelectChannelDialog *dialog = new SelectChannelDialog();
if (!empty) {
- dialog->setSelectedChannel(this->getChannel());
+ dialog->setSelectedChannel(this->getIndirectChannel());
}
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();