mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
improved saving of splits and watching split
This commit is contained in:
parent
a16a2b0579
commit
5015633cc7
7 changed files with 60 additions and 21 deletions
|
@ -90,7 +90,7 @@ class IndirectChannel
|
|||
std::shared_ptr<Data> data;
|
||||
|
||||
public:
|
||||
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::None)
|
||||
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Direct)
|
||||
: data(new Data(channel, type))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void AccountManager::load()
|
|||
this->Twitch.currentUser = this->Twitch.anonymousUser;
|
||||
}
|
||||
|
||||
this->Twitch.userChanged.invoke();
|
||||
// this->Twitch.userChanged.invoke();
|
||||
}
|
||||
|
||||
} // namespace singletons
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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("<no channel>");
|
||||
return;
|
||||
QString title = channel->name;
|
||||
|
||||
if (indirectChannel.getType() == Channel::TwitchWatching) {
|
||||
title = "watching: " + (title.isEmpty() ? "none" : title);
|
||||
}
|
||||
|
||||
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||
|
@ -178,17 +179,19 @@ void SplitHeader::updateChannelText()
|
|||
" viewers"
|
||||
"</p>";
|
||||
if (streamStatus.rerun) {
|
||||
this->titleLabel->setText(channelName + " (rerun)");
|
||||
title += " (rerun)";
|
||||
} else {
|
||||
this->titleLabel->setText(channelName + " (live)");
|
||||
title += " (live)";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (title.isEmpty()) {
|
||||
title = "<empty>";
|
||||
}
|
||||
|
||||
this->isLive = false;
|
||||
this->titleLabel->setText(channelName);
|
||||
this->titleLabel->setText(title);
|
||||
this->tooltip = "";
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<TwitchChannel *>(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();
|
||||
|
|
Loading…
Reference in a new issue