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;
|
std::shared_ptr<Data> data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::None)
|
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Direct)
|
||||||
: data(new Data(channel, type))
|
: data(new Data(channel, type))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ void AccountManager::load()
|
||||||
this->Twitch.currentUser = this->Twitch.anonymousUser;
|
this->Twitch.currentUser = this->Twitch.anonymousUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->Twitch.userChanged.invoke();
|
// this->Twitch.userChanged.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace singletons
|
} // namespace singletons
|
||||||
|
|
|
@ -198,11 +198,7 @@ void WindowManager::initialize()
|
||||||
widgets::Split *split = new widgets::Split(tab);
|
widgets::Split *split = new widgets::Split(tab);
|
||||||
|
|
||||||
QJsonObject split_obj = split_val.toObject();
|
QJsonObject split_obj = split_val.toObject();
|
||||||
QJsonValue channelName_val = split_obj.value("channelName");
|
split->setChannel(this->decodeChannel(split_obj));
|
||||||
if (channelName_val.isString()) {
|
|
||||||
split->setChannel(providers::twitch::TwitchServer::getInstance().addChannel(
|
|
||||||
channelName_val.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
tab->addToLayout(split, std::make_pair(colNr, 10000000));
|
tab->addToLayout(split, std::make_pair(colNr, 10000000));
|
||||||
}
|
}
|
||||||
|
@ -270,7 +266,8 @@ void WindowManager::save()
|
||||||
|
|
||||||
for (widgets::Split *cell : cells) {
|
for (widgets::Split *cell : cells) {
|
||||||
QJsonObject cell_obj;
|
QJsonObject cell_obj;
|
||||||
cell_obj.insert("channelName", cell->getChannel().get()->name);
|
|
||||||
|
this->encodeChannel(cell->getIndirectChannel(), cell_obj);
|
||||||
|
|
||||||
cells_arr.append(cell_obj);
|
cells_arr.append(cell_obj);
|
||||||
}
|
}
|
||||||
|
@ -297,6 +294,42 @@ void WindowManager::save()
|
||||||
file.flush();
|
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()
|
void WindowManager::closeAll()
|
||||||
{
|
{
|
||||||
for (widgets::Window *window : windows) {
|
for (widgets::Window *window : windows) {
|
||||||
|
|
|
@ -45,6 +45,9 @@ private:
|
||||||
|
|
||||||
widgets::Window *mainWindow = nullptr;
|
widgets::Window *mainWindow = nullptr;
|
||||||
widgets::Window *selectedWindow = nullptr;
|
widgets::Window *selectedWindow = nullptr;
|
||||||
|
|
||||||
|
void encodeChannel(IndirectChannel channel, QJsonObject &obj);
|
||||||
|
IndirectChannel decodeChannel(const QJsonObject &obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace singletons
|
} // namespace singletons
|
||||||
|
|
|
@ -154,12 +154,13 @@ void SplitHeader::scaleChangedEvent(float scale)
|
||||||
|
|
||||||
void SplitHeader::updateChannelText()
|
void SplitHeader::updateChannelText()
|
||||||
{
|
{
|
||||||
|
auto indirectChannel = this->split->getIndirectChannel();
|
||||||
auto channel = this->split->getChannel();
|
auto channel = this->split->getChannel();
|
||||||
|
|
||||||
const QString channelName = channel->name;
|
QString title = channel->name;
|
||||||
if (channelName.isEmpty()) {
|
|
||||||
this->titleLabel->setText("<no channel>");
|
if (indirectChannel.getType() == Channel::TwitchWatching) {
|
||||||
return;
|
title = "watching: " + (title.isEmpty() ? "none" : title);
|
||||||
}
|
}
|
||||||
|
|
||||||
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||||
|
@ -178,17 +179,19 @@ void SplitHeader::updateChannelText()
|
||||||
" viewers"
|
" viewers"
|
||||||
"</p>";
|
"</p>";
|
||||||
if (streamStatus.rerun) {
|
if (streamStatus.rerun) {
|
||||||
this->titleLabel->setText(channelName + " (rerun)");
|
title += " (rerun)";
|
||||||
} else {
|
} else {
|
||||||
this->titleLabel->setText(channelName + " (live)");
|
title += " (live)";
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (title.isEmpty()) {
|
||||||
|
title = "<empty>";
|
||||||
|
}
|
||||||
|
|
||||||
this->isLive = false;
|
this->isLive = false;
|
||||||
this->titleLabel->setText(channelName);
|
this->titleLabel->setText(title);
|
||||||
this->tooltip = "";
|
this->tooltip = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel)
|
||||||
|
|
||||||
this->selectedChannel = channel;
|
this->selectedChannel = channel;
|
||||||
|
|
||||||
switch (channel->getType()) {
|
switch (_channel.getType()) {
|
||||||
case Channel::Twitch: {
|
case Channel::Twitch: {
|
||||||
this->ui.notebook->selectIndex(TAB_TWITCH);
|
this->ui.notebook->selectIndex(TAB_TWITCH);
|
||||||
this->ui.twitch.channel->setFocus();
|
this->ui.twitch.channel->setFocus();
|
||||||
|
|
|
@ -134,13 +134,13 @@ ChannelPtr Split::getChannel()
|
||||||
|
|
||||||
void Split::setChannel(IndirectChannel newChannel)
|
void Split::setChannel(IndirectChannel newChannel)
|
||||||
{
|
{
|
||||||
|
this->channel = newChannel;
|
||||||
|
|
||||||
this->view.setChannel(newChannel.get());
|
this->view.setChannel(newChannel.get());
|
||||||
|
|
||||||
this->usermodeChangedConnection.disconnect();
|
this->usermodeChangedConnection.disconnect();
|
||||||
this->indirectChannelChangedConnection.disconnect();
|
this->indirectChannelChangedConnection.disconnect();
|
||||||
|
|
||||||
this->channel = newChannel;
|
|
||||||
|
|
||||||
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get());
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(newChannel.get().get());
|
||||||
|
|
||||||
if (tc != nullptr) {
|
if (tc != nullptr) {
|
||||||
|
@ -199,7 +199,7 @@ void Split::showChangeChannelPopup(const char *dialogTitle, bool empty,
|
||||||
{
|
{
|
||||||
SelectChannelDialog *dialog = new SelectChannelDialog();
|
SelectChannelDialog *dialog = new SelectChannelDialog();
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
dialog->setSelectedChannel(this->getChannel());
|
dialog->setSelectedChannel(this->getIndirectChannel());
|
||||||
}
|
}
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
dialog->show();
|
dialog->show();
|
||||||
|
|
Loading…
Reference in a new issue