Merge branch 'master' into apa-notification-on-live

This commit is contained in:
apa420
2018-08-28 23:23:46 +02:00
committed by GitHub
214 changed files with 4368 additions and 4428 deletions
+110 -113
View File
@@ -2,139 +2,143 @@
#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "debug/Benchmark.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "singletons/Emotes.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/helper/ChannelView.hpp"
#include <QHBoxLayout>
#include <QShortcut>
#include <QTabWidget>
namespace chatterino {
EmotePopup::EmotePopup()
: BaseWindow(nullptr, BaseWindow::EnableCustomFrame)
{
this->viewEmotes_ = new ChannelView();
this->viewEmojis_ = new ChannelView();
this->viewEmotes_->setOverrideFlags(MessageElementFlags{
MessageElementFlag::Default, MessageElementFlag::AlwaysShow,
MessageElementFlag::EmoteImages});
this->viewEmojis_->setOverrideFlags(MessageElementFlags{
MessageElementFlag::Default, MessageElementFlag::AlwaysShow,
MessageElementFlag::EmoteImages});
this->viewEmotes_->setEnableScrollingToBottom(false);
this->viewEmojis_->setEnableScrollingToBottom(false);
auto *layout = new QVBoxLayout(this);
this->getLayoutContainer()->setLayout(layout);
Notebook *notebook = new Notebook(this);
layout->addWidget(notebook);
layout->setMargin(0);
notebook->addPage(this->viewEmotes_, "Emotes");
notebook->addPage(this->viewEmojis_, "Emojis");
this->loadEmojis();
this->viewEmotes_->linkClicked.connect(
[this](const Link &link) { this->linkClicked.invoke(link); });
this->viewEmojis_->linkClicked.connect(
[this](const Link &link) { this->linkClicked.invoke(link); });
}
void EmotePopup::loadChannel(ChannelPtr _channel)
{
this->setWindowTitle("Emotes from " + _channel->getName());
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(_channel.get());
if (channel == nullptr) {
return;
namespace {
auto makeTitleMessage(const QString &title)
{
MessageBuilder builder;
builder.emplace<TextElement>(title, MessageElementFlag::Text);
builder->flags.set(MessageFlag::Centered);
return builder.release();
}
auto makeEmoteMessage(const EmoteMap &map)
{
MessageBuilder builder;
builder->flags.set(MessageFlag::Centered);
builder->flags.set(MessageFlag::DisableCompactEmotes);
ChannelPtr emoteChannel(new Channel("", Channel::Type::None));
auto addEmotes = [&](const EmoteMap &map, const QString &title,
const QString &emoteDesc) {
// TITLE
MessageBuilder builder1;
builder1.emplace<TextElement>(title, MessageElementFlag::Text);
builder1->flags.set(MessageFlag::Centered);
emoteChannel->addMessage(builder1.release());
// EMOTES
MessageBuilder builder2;
builder2->flags.set(MessageFlag::Centered);
builder2->flags.set(MessageFlag::DisableCompactEmotes);
for (auto emote : map) {
builder2
for (const auto &emote : map) {
builder
.emplace<EmoteElement>(emote.second,
MessageElementFlag::AlwaysShow)
->setLink(Link(Link::InsertText, emote.first.string));
}
emoteChannel->addMessage(builder2.release());
return builder.release();
}
void addEmoteSets(
std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> sets,
Channel &globalChannel, Channel &subChannel)
{
for (const auto &set : sets) {
auto &channel = set->key == "0" ? globalChannel : subChannel;
// TITLE
auto text =
set->key == "0" || set->text.isEmpty() ? "Twitch" : set->text;
channel.addMessage(makeTitleMessage(text));
// EMOTES
MessageBuilder builder;
builder->flags.set(MessageFlag::Centered);
builder->flags.set(MessageFlag::DisableCompactEmotes);
for (const auto &emote : set->emotes) {
builder
.emplace<EmoteElement>(
getApp()->emotes->twitch.getOrCreateEmote(emote.id,
emote.name),
MessageElementFlag::AlwaysShow)
->setLink(Link(Link::InsertText, emote.name.string));
}
channel.addMessage(builder.release());
}
}
} // namespace
EmotePopup::EmotePopup()
: BaseWindow(nullptr, BaseWindow::EnableCustomFrame)
{
auto layout = new QVBoxLayout(this);
this->getLayoutContainer()->setLayout(layout);
auto notebook = new Notebook(this);
layout->addWidget(notebook);
layout->setMargin(0);
auto clicked = [this](const Link &link) { this->linkClicked.invoke(link); };
auto makeView = [&](QString tabTitle) {
auto view = new ChannelView();
view->setOverrideFlags(MessageElementFlags{
MessageElementFlag::Default, MessageElementFlag::AlwaysShow,
MessageElementFlag::EmoteImages});
view->setEnableScrollingToBottom(false);
notebook->addPage(view, tabTitle);
view->linkClicked.connect(clicked);
return view;
};
auto app = getApp();
this->subEmotesView_ = makeView("Subs");
this->channelEmotesView_ = makeView("Channel");
this->globalEmotesView_ = makeView("Global");
this->viewEmojis_ = makeView("Emojis");
// fourtf: the entire emote manager needs to be refactored so there's no
// point in trying to fix this pile of garbage
for (const auto &set :
app->accounts->twitch.getCurrent()->accessEmotes()->emoteSets) {
// TITLE
MessageBuilder builder1;
this->loadEmojis();
}
QString setText;
if (set->text.isEmpty()) {
if (set->channelName.isEmpty()) {
setText = "Twitch Account Emotes";
} else {
setText = "Twitch Account Emotes (" + set->channelName + ")";
}
} else {
setText = set->text;
}
void EmotePopup::loadChannel(ChannelPtr _channel)
{
BenchmarkGuard guard("loadChannel");
builder1.emplace<TextElement>(setText, MessageElementFlag::Text);
this->setWindowTitle("Emotes from " + _channel->getName());
builder1->flags.set(MessageFlag::Centered);
emoteChannel->addMessage(builder1.release());
auto twitchChannel = dynamic_cast<TwitchChannel *>(_channel.get());
if (twitchChannel == nullptr) return;
// EMOTES
MessageBuilder builder2;
builder2->flags.set(MessageFlag::Centered);
builder2->flags.set(MessageFlag::DisableCompactEmotes);
auto addEmotes = [&](Channel &channel, const EmoteMap &map,
const QString &title) {
channel.addMessage(makeTitleMessage(title));
channel.addMessage(makeEmoteMessage(map));
};
for (const auto &emote : set->emotes) {
builder2
.emplace<EmoteElement>(
app->emotes->twitch.getOrCreateEmote(emote.id, emote.name),
MessageElementFlag::AlwaysShow)
->setLink(Link(Link::InsertText, emote.name.string));
}
auto subChannel = std::make_shared<Channel>("", Channel::Type::None);
auto globalChannel = std::make_shared<Channel>("", Channel::Type::None);
auto channelChannel = std::make_shared<Channel>("", Channel::Type::None);
emoteChannel->addMessage(builder2.release());
}
// twitch
addEmoteSets(
getApp()->accounts->twitch.getCurrent()->accessEmotes()->emoteSets,
*globalChannel, *subChannel);
addEmotes(*app->emotes->bttv.accessGlobalEmotes(),
"BetterTTV Global Emotes", "BetterTTV Global Emote");
addEmotes(*channel->accessBttvEmotes(), "BetterTTV Channel Emotes",
"BetterTTV Channel Emote");
// addEmotes(*app->emotes->ffz.accessGlobalEmotes(), "FrankerFaceZ Global
// Emotes",
// "FrankerFaceZ Global Emote");
addEmotes(*channel->accessFfzEmotes(), "FrankerFaceZ Channel Emotes",
"FrankerFaceZ Channel Emote");
// global
addEmotes(*globalChannel, *twitchChannel->globalBttv().emotes(),
"BetterTTV");
addEmotes(*globalChannel, *twitchChannel->globalFfz().emotes(),
"FrankerFaceZ");
this->viewEmotes_->setChannel(emoteChannel);
// channel
addEmotes(*channelChannel, *twitchChannel->bttvEmotes(), "BetterTTV");
addEmotes(*channelChannel, *twitchChannel->ffzEmotes(), "FrankerFaceZ");
this->globalEmotesView_->setChannel(globalChannel);
this->subEmotesView_->setChannel(subChannel);
this->channelEmotesView_->setChannel(channelChannel);
}
void EmotePopup::loadEmojis()
@@ -143,13 +147,6 @@ void EmotePopup::loadEmojis()
ChannelPtr emojiChannel(new Channel("", Channel::Type::None));
// title
MessageBuilder builder1;
builder1.emplace<TextElement>("emojis", MessageElementFlag::Text);
builder1->flags.set(MessageFlag::Centered);
emojiChannel->addMessage(builder1.release());
// emojis
MessageBuilder builder;
builder->flags.set(MessageFlag::Centered);
+9 -4
View File
@@ -1,13 +1,16 @@
#pragma once
#include "common/Channel.hpp"
#include "widgets/BaseWindow.hpp"
#include "widgets/helper/ChannelView.hpp"
#include <pajlada/signals/signal.hpp>
namespace chatterino {
class Link;
class ChannelView;
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
class EmotePopup : public BaseWindow
{
public:
@@ -19,8 +22,10 @@ public:
pajlada::Signals::Signal<Link> linkClicked;
private:
ChannelView *viewEmotes_;
ChannelView *viewEmojis_;
ChannelView *globalEmotesView_{};
ChannelView *channelEmotesView_{};
ChannelView *subEmotesView_{};
ChannelView *viewEmojis_{};
};
} // namespace chatterino
+48 -47
View File
@@ -1,12 +1,13 @@
#include "widgets/dialogs/LoginDialog.hpp"
#include "Application.hpp"
#include "common/Common.hpp"
#include "common/NetworkRequest.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "providers/twitch/PartialTwitchUser.hpp"
#ifdef USEWINSDK
#include <Windows.h>
# include <Windows.h>
#endif
#include <QClipboard>
@@ -20,54 +21,54 @@ namespace chatterino {
namespace {
void LogInWithCredentials(const std::string &userID,
const std::string &username,
const std::string &clientID,
const std::string &oauthToken)
{
QStringList errors;
void LogInWithCredentials(const std::string &userID,
const std::string &username,
const std::string &clientID,
const std::string &oauthToken)
{
QStringList errors;
if (userID.empty()) {
errors.append("Missing user ID");
if (userID.empty()) {
errors.append("Missing user ID");
}
if (username.empty()) {
errors.append("Missing username");
}
if (clientID.empty()) {
errors.append("Missing Client ID");
}
if (oauthToken.empty()) {
errors.append("Missing OAuth Token");
}
if (errors.length() > 0) {
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Critical);
messageBox.setText(errors.join("<br />"));
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
return;
}
// QMessageBox messageBox;
// messageBox.setIcon(QMessageBox::Information);
// messageBox.setText("Successfully logged in with user <b>" +
// qS(username) + "</b>!");
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/username", username);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/userID", userID);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/clientID", clientID);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/oauthToken", oauthToken);
getApp()->accounts->twitch.reloadUsers();
// messageBox.exec();
getApp()->accounts->twitch.currentUsername = username;
}
if (username.empty()) {
errors.append("Missing username");
}
if (clientID.empty()) {
errors.append("Missing Client ID");
}
if (oauthToken.empty()) {
errors.append("Missing OAuth Token");
}
if (errors.length() > 0) {
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Critical);
messageBox.setText(errors.join("<br />"));
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
return;
}
// QMessageBox messageBox;
// messageBox.setIcon(QMessageBox::Information);
// messageBox.setText("Successfully logged in with user <b>" +
// qS(username) + "</b>!");
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/username", username);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/userID", userID);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/clientID", clientID);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/oauthToken", oauthToken);
getApp()->accounts->twitch.reloadUsers();
// messageBox.exec();
getApp()->accounts->twitch.currentUsername = username;
}
} // namespace
+2
View File
@@ -1,6 +1,7 @@
#include "LogsPopup.hpp"
#include "IrcMessage"
#include "common/Channel.hpp"
#include "common/NetworkRequest.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
@@ -14,6 +15,7 @@
namespace chatterino {
LogsPopup::LogsPopup()
: channel_(Channel::getEmpty())
{
this->initLayout();
this->resize(400, 600);
+7 -2
View File
@@ -1,6 +1,5 @@
#pragma once
#include "common/Channel.hpp"
#include "widgets/BaseWindow.hpp"
namespace chatterino {
@@ -8,6 +7,12 @@ namespace chatterino {
class Channel;
class ChannelView;
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
struct Message;
using MessagePtr = std::shared_ptr<const Message>;
class LogsPopup : public BaseWindow
{
public:
@@ -17,7 +22,7 @@ public:
private:
ChannelView *channelView_ = nullptr;
ChannelPtr channel_ = Channel::getEmpty();
ChannelPtr channel_;
QString userName_;
int roomID_;
@@ -1,5 +1,7 @@
#include "NotificationPopup.hpp"
#include "common/Channel.hpp"
#include "messages/Message.hpp"
#include "widgets/helper/ChannelView.hpp"
#include <QApplication>
+6 -2
View File
@@ -1,13 +1,17 @@
#pragma once
#include "common/Channel.hpp"
#include "messages/Message.hpp"
#include "widgets/BaseWindow.hpp"
namespace chatterino {
class ChannelView;
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
struct Message;
using MessagePtr = std::shared_ptr<const Message>;
class NotificationPopup : public BaseWindow
{
public:
+1 -1
View File
@@ -47,7 +47,7 @@ void QualityPopup::okButtonClicked()
try {
openStreamlink(channelURL, this->ui_.selector.currentText());
} catch (const Exception &ex) {
Log("Exception caught trying to open streamlink: {}", ex.what());
log("Exception caught trying to open streamlink: {}", ex.what());
}
this->close();
@@ -2,8 +2,10 @@
#include "Application.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/Theme.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/helper/NotebookTab.hpp"
#include <QDialogButtonBox>
#include <QGroupBox>
+4 -2
View File
@@ -1,8 +1,8 @@
#pragma once
#include "Application.hpp"
#include "common/Channel.hpp"
#include "widgets/BaseWindow.hpp"
#include "widgets/Notebook.hpp"
#include <pajlada/signals/signal.hpp>
@@ -11,7 +11,9 @@
namespace chatterino {
class SelectChannelDialog : public BaseWindow
class Notebook;
class SelectChannelDialog final : public BaseWindow
{
public:
SelectChannelDialog(QWidget *parent = nullptr);
+4 -2
View File
@@ -5,6 +5,7 @@
#include "widgets/helper/SettingsDialogTab.hpp"
#include "widgets/settingspages/AboutPage.hpp"
#include "widgets/settingspages/AccountsPage.hpp"
#include "widgets/settingspages/AdvancedPage.hpp"
#include "widgets/settingspages/BrowserExtensionPage.hpp"
#include "widgets/settingspages/CommandPage.hpp"
#include "widgets/settingspages/EmotesPage.hpp"
@@ -105,6 +106,7 @@ void SettingsDialog::addTabs()
// this->addTab(new SpecialChannelsPage);
this->addTab(new BrowserExtensionPage);
this->addTab(new ExternalToolsPage);
this->addTab(new AdvancedPage);
this->ui_.tabContainer->addStretch(1);
this->addTab(new AboutPage, Qt::AlignBottom);
@@ -156,7 +158,7 @@ void SettingsDialog::showDialog(PreferredTab preferredTab)
void SettingsDialog::refresh()
{
getApp()->settings->saveSnapshot();
getSettings()->saveSnapshot();
for (auto *tab : this->tabs_) {
tab->getSettingsPage()->onShow();
@@ -201,7 +203,7 @@ void SettingsDialog::onCancelClicked()
tab->getSettingsPage()->cancel();
}
getApp()->settings->restoreSnapshot();
getSettings()->restoreSnapshot();
this->close();
}
+27 -30
View File
@@ -1,6 +1,7 @@
#include "UserInfoPopup.hpp"
#include "Application.hpp"
#include "common/Channel.hpp"
#include "common/NetworkRequest.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp"
@@ -11,8 +12,8 @@
#include "util/PostToThread.hpp"
#include "widgets/Label.hpp"
#include "widgets/dialogs/LogsPopup.hpp"
#include "widgets/helper/EffectLabel.hpp"
#include "widgets/helper/Line.hpp"
#include "widgets/helper/RippleEffectLabel.hpp"
#include <QCheckBox>
#include <QDesktopServices>
@@ -46,14 +47,13 @@ UserInfoPopup::UserInfoPopup()
auto head = layout.emplace<QHBoxLayout>().withoutMargin();
{
// avatar
auto avatar = head.emplace<RippleEffectButton>(nullptr).assign(
&this->ui_.avatarButton);
auto avatar =
head.emplace<Button>(nullptr).assign(&this->ui_.avatarButton);
avatar->setScaleIndependantSize(100, 100);
QObject::connect(avatar.getElement(), &RippleEffectButton::clicked,
[this] {
QDesktopServices::openUrl(
QUrl("https://twitch.tv/" + this->userName_));
});
QObject::connect(avatar.getElement(), &Button::clicked, [this] {
QDesktopServices::openUrl(
QUrl("https://twitch.tv/" + this->userName_.toLower()));
});
// items on the right
auto vbox = head.emplace<QVBoxLayout>();
@@ -82,33 +82,31 @@ UserInfoPopup::UserInfoPopup()
user.emplace<QCheckBox>("Ignore").assign(&this->ui_.ignore);
user.emplace<QCheckBox>("Ignore highlights")
.assign(&this->ui_.ignoreHighlights);
auto viewLogs = user.emplace<RippleEffectLabel2>(this);
auto viewLogs = user.emplace<EffectLabel2>(this);
viewLogs->getLabel().setText("Online logs");
auto mod = user.emplace<RippleEffectButton>(this);
auto mod = user.emplace<Button>(this);
mod->setPixmap(app->resources->buttons.mod);
mod->setScaleIndependantSize(30, 30);
auto unmod = user.emplace<RippleEffectButton>(this);
auto unmod = user.emplace<Button>(this);
unmod->setPixmap(app->resources->buttons.unmod);
unmod->setScaleIndependantSize(30, 30);
user->addStretch(1);
QObject::connect(viewLogs.getElement(), &RippleEffectButton::clicked,
[this] {
auto logs = new LogsPopup();
logs->setInfo(this->channel_, this->userName_);
logs->setAttribute(Qt::WA_DeleteOnClose);
logs->show();
});
QObject::connect(viewLogs.getElement(), &Button::clicked, [this] {
auto logs = new LogsPopup();
logs->setInfo(this->channel_, this->userName_);
logs->setAttribute(Qt::WA_DeleteOnClose);
logs->show();
});
QObject::connect(
mod.getElement(), &RippleEffectButton::clicked,
[this] { this->channel_->sendMessage("/mod " + this->userName_); });
QObject::connect(
unmod.getElement(), &RippleEffectButton::clicked, [this] {
this->channel_->sendMessage("/unmod " + this->userName_);
});
QObject::connect(mod.getElement(), &Button::clicked, [this] {
this->channel_->sendMessage("/mod " + this->userName_);
});
QObject::connect(unmod.getElement(), &Button::clicked, [this] {
this->channel_->sendMessage("/unmod " + this->userName_);
});
// userstate
this->userStateChanged_.connect([this, mod, unmod]() mutable {
@@ -429,14 +427,13 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
hbox->setSpacing(0);
{
auto button = hbox.emplace<RippleEffectButton>(nullptr);
auto button = hbox.emplace<Button>(nullptr);
button->setPixmap(pixmap);
button->setScaleIndependantSize(buttonHeight, buttonHeight);
button->setBorderColor(QColor(255, 255, 255, 127));
QObject::connect(
button.getElement(), &RippleEffectButton::clicked,
[this, action] {
button.getElement(), &Button::clicked, [this, action] {
this->buttonClicked.invoke(std::make_pair(action, -1));
});
}
@@ -458,7 +455,7 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
hbox->setSpacing(0);
for (const auto &item : items) {
auto a = hbox.emplace<RippleEffectLabel2>();
auto a = hbox.emplace<EffectLabel2>();
a->getLabel().setText(std::get<0>(item));
if (std::get<0>(item).length() > 1) {
@@ -468,7 +465,7 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
}
a->setBorderColor(color1);
QObject::connect(a.getElement(), &RippleEffectLabel2::clicked,
QObject::connect(a.getElement(), &EffectLabel2::clicked,
[this, timeout = std::get<1>(item)] {
this->buttonClicked.invoke(std::make_pair(
Action::Timeout, timeout));
+3 -2
View File
@@ -1,6 +1,5 @@
#pragma once
#include "common/Channel.hpp"
#include "widgets/BaseWindow.hpp"
#include <pajlada/signals/signal.hpp>
@@ -9,6 +8,8 @@ class QCheckBox;
namespace chatterino {
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
class Label;
class UserInfoPopup final : public BaseWindow
@@ -40,7 +41,7 @@ private:
std::shared_ptr<bool> hack_;
struct {
RippleEffectButton *avatarButton = nullptr;
Button *avatarButton = nullptr;
// RippleEffectLabel2 *viewLogs = nullptr;
Label *nameLabel = nullptr;