2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/split.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "channelmanager.hpp"
|
|
|
|
#include "colorscheme.hpp"
|
|
|
|
#include "settingsmanager.hpp"
|
2017-09-17 04:36:48 +02:00
|
|
|
#include "twitch/twitchmessagebuilder.hpp"
|
2017-09-11 22:37:39 +02:00
|
|
|
#include "util/urlfetch.hpp"
|
2017-09-16 16:20:10 +02:00
|
|
|
#include "widgets/qualitypopup.hpp"
|
2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/splitcontainer.hpp"
|
2017-09-15 17:23:49 +02:00
|
|
|
#include "widgets/textinputdialog.hpp"
|
2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/window.hpp"
|
|
|
|
#include "windowmanager.hpp"
|
2017-01-17 00:15:44 +01:00
|
|
|
|
2017-09-12 19:06:16 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2017-02-02 23:51:02 +01:00
|
|
|
#include <QDebug>
|
2017-09-11 22:37:39 +02:00
|
|
|
#include <QDockWidget>
|
2017-08-12 15:58:46 +02:00
|
|
|
#include <QFileInfo>
|
2017-01-17 00:15:44 +01:00
|
|
|
#include <QFont>
|
|
|
|
#include <QFontDatabase>
|
2017-09-11 22:37:39 +02:00
|
|
|
#include <QListWidget>
|
2017-01-17 00:15:44 +01:00
|
|
|
#include <QPainter>
|
2017-08-12 15:58:46 +02:00
|
|
|
#include <QProcess>
|
2017-06-10 23:53:39 +02:00
|
|
|
#include <QShortcut>
|
2017-09-16 00:05:06 +02:00
|
|
|
#include <QTimer>
|
2017-01-17 00:15:44 +01:00
|
|
|
#include <QVBoxLayout>
|
2017-02-02 22:15:09 +01:00
|
|
|
#include <boost/signals2.hpp>
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-07-09 17:49:02 +02:00
|
|
|
#include <functional>
|
2017-09-17 04:36:48 +02:00
|
|
|
#include <random>
|
2017-07-09 17:49:02 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
using namespace chatterino::messages;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
template <typename T>
|
2017-11-12 17:21:50 +01:00
|
|
|
inline void ezShortcut(Split *w, const char *key, T t)
|
2017-06-11 11:36:42 +02:00
|
|
|
{
|
|
|
|
auto s = new QShortcut(QKeySequence(key), w);
|
|
|
|
s->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
QObject::connect(s, &QShortcut::activated, w, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-12-22 14:44:31 +01:00
|
|
|
Split::Split(ChannelManager &_channelManager, SplitContainer *parent, const std::string &_uuid)
|
2017-06-26 16:41:20 +02:00
|
|
|
: BaseWidget(parent)
|
2017-12-22 14:44:31 +01:00
|
|
|
, uuid(_uuid)
|
|
|
|
, settingRoot(fS("/splits/{}", this->uuid))
|
|
|
|
, channelName(fS("{}/channelName", this->settingRoot))
|
2017-08-17 22:25:41 +02:00
|
|
|
, parentPage(*parent)
|
2017-06-13 21:13:58 +02:00
|
|
|
, channelManager(_channelManager)
|
2017-07-23 09:53:50 +02:00
|
|
|
, channel(_channelManager.emptyChannel)
|
2017-06-11 11:36:42 +02:00
|
|
|
, vbox(this)
|
|
|
|
, header(this)
|
2017-12-17 02:18:13 +01:00
|
|
|
, view(this)
|
|
|
|
, input(this)
|
2017-11-12 17:21:50 +01:00
|
|
|
, flexSizeX(1)
|
|
|
|
, flexSizeY(1)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2017-06-11 11:36:42 +02:00
|
|
|
this->vbox.setSpacing(0);
|
|
|
|
this->vbox.setMargin(1);
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
this->vbox.addWidget(&this->header);
|
|
|
|
this->vbox.addWidget(&this->view, 1);
|
|
|
|
this->vbox.addWidget(&this->input);
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
// Initialize chat widget-wide hotkeys
|
2017-06-10 23:53:39 +02:00
|
|
|
// CTRL+T: Create new split (Add page)
|
2017-11-12 17:21:50 +01:00
|
|
|
ezShortcut(this, "CTRL+T", &Split::doAddSplit);
|
2017-06-10 23:53:39 +02:00
|
|
|
|
|
|
|
// CTRL+W: Close Split
|
2017-11-12 17:21:50 +01:00
|
|
|
ezShortcut(this, "CTRL+W", &Split::doCloseSplit);
|
2017-06-10 23:53:39 +02:00
|
|
|
|
|
|
|
// CTRL+R: Change Channel
|
2017-11-12 17:21:50 +01:00
|
|
|
ezShortcut(this, "CTRL+R", &Split::doChangeChannel);
|
|
|
|
|
|
|
|
// xd
|
2017-12-16 16:33:46 +01:00
|
|
|
// ezShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX);
|
|
|
|
// ezShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX);
|
|
|
|
// ezShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY);
|
|
|
|
// ezShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY);
|
2017-09-17 04:36:48 +02:00
|
|
|
|
2017-07-09 17:49:02 +02:00
|
|
|
this->channelName.getValueChangedSignal().connect(
|
2017-11-12 17:21:50 +01:00
|
|
|
std::bind(&Split::channelNameUpdated, this, std::placeholders::_1));
|
2017-07-09 17:49:02 +02:00
|
|
|
|
|
|
|
this->channelNameUpdated(this->channelName.getValue());
|
2017-08-12 15:41:14 +02:00
|
|
|
|
|
|
|
this->input.textInput.installEventFilter(parent);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-09-16 16:49:52 +02:00
|
|
|
this->view.mouseDown.connect([this](QMouseEvent *) { this->giveFocus(Qt::MouseFocusReason); });
|
2017-09-21 02:20:02 +02:00
|
|
|
this->view.selectionChanged.connect([this]() {
|
|
|
|
if (view.hasSelection()) {
|
|
|
|
this->input.clearSelection();
|
2017-12-17 16:19:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this->input.textChanged.connect([this](const QString &newText) {
|
|
|
|
if (!SettingsManager::getInstance().hideEmptyInput) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newText.length() == 0) {
|
|
|
|
this->input.hide();
|
|
|
|
} else if (this->input.isHidden()) {
|
|
|
|
this->input.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
SettingsManager::getInstance().hideEmptyInput.connect([this](const bool &hideEmptyInput, auto) {
|
|
|
|
if (hideEmptyInput && this->input.getInputText().length() == 0) {
|
|
|
|
this->input.hide();
|
|
|
|
} else {
|
|
|
|
this->input.show();
|
2017-09-21 02:20:02 +02:00
|
|
|
}
|
|
|
|
});
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
Split::~Split()
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-09-17 02:13:57 +02:00
|
|
|
this->channelNameUpdated("");
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2017-12-22 14:44:31 +01:00
|
|
|
const std::string &Split::getUUID() const
|
|
|
|
{
|
|
|
|
return this->uuid;
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
std::shared_ptr<Channel> Split::getChannel() const
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-06-11 11:36:42 +02:00
|
|
|
return this->channel;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
std::shared_ptr<Channel> &Split::getChannelRef()
|
2017-05-27 17:45:40 +02:00
|
|
|
{
|
2017-06-11 11:36:42 +02:00
|
|
|
return this->channel;
|
2017-05-27 17:45:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::setChannel(std::shared_ptr<Channel> _newChannel)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
this->view.setChannel(_newChannel);
|
2017-02-02 22:15:09 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
this->channel = _newChannel;
|
2017-02-02 23:51:02 +01:00
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
this->channelChanged();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::setFlexSizeX(double x)
|
|
|
|
{
|
|
|
|
this->flexSizeX = x;
|
|
|
|
this->parentPage.updateFlexValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
double Split::getFlexSizeX()
|
|
|
|
{
|
|
|
|
return this->flexSizeX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::setFlexSizeY(double y)
|
|
|
|
{
|
|
|
|
this->flexSizeY = y;
|
|
|
|
this->parentPage.updateFlexValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
double Split::getFlexSizeY()
|
|
|
|
{
|
|
|
|
return this->flexSizeY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::channelNameUpdated(const std::string &newChannelName)
|
2017-07-09 17:49:02 +02:00
|
|
|
{
|
|
|
|
// remove current channel
|
|
|
|
if (!this->channel->isEmpty()) {
|
2017-09-16 00:05:06 +02:00
|
|
|
this->channelManager.removeTwitchChannel(this->channel->name);
|
2017-07-09 17:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// update messages
|
|
|
|
if (newChannelName.empty()) {
|
2017-09-16 00:05:06 +02:00
|
|
|
this->setChannel(this->channelManager.emptyChannel);
|
2017-07-09 17:49:02 +02:00
|
|
|
} else {
|
2017-09-16 00:05:06 +02:00
|
|
|
this->setChannel(
|
|
|
|
this->channelManager.addTwitchChannel(QString::fromStdString(newChannelName)));
|
2017-07-09 17:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// update header
|
|
|
|
this->header.updateChannelText();
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
bool Split::showChangeChannelPopup(const char *dialogTitle, bool empty)
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
// create new input dialog and execute it
|
2017-01-17 00:15:44 +01:00
|
|
|
TextInputDialog dialog(this);
|
|
|
|
|
2017-07-31 01:36:42 +02:00
|
|
|
dialog.setWindowTitle(dialogTitle);
|
|
|
|
|
|
|
|
if (!empty) {
|
|
|
|
dialog.setText(QString::fromStdString(this->channelName));
|
|
|
|
}
|
2017-01-17 00:15:44 +01:00
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
2017-07-09 17:49:02 +02:00
|
|
|
QString newChannelName = dialog.getText().trimmed();
|
|
|
|
|
|
|
|
this->channelName = newChannelName.toStdString();
|
2017-08-17 22:25:41 +02:00
|
|
|
this->parentPage.refreshTitle();
|
2017-07-31 01:36:42 +02:00
|
|
|
|
|
|
|
return true;
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
2017-07-31 01:36:42 +02:00
|
|
|
|
|
|
|
return false;
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::layoutMessages()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
this->view.layoutMessages();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::updateGifEmotes()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-06-11 11:36:42 +02:00
|
|
|
this->view.updateGifEmotes();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::giveFocus(Qt::FocusReason reason)
|
2017-08-12 15:41:14 +02:00
|
|
|
{
|
|
|
|
this->input.textInput.setFocus(reason);
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
bool Split::hasFocus() const
|
2017-06-11 20:53:43 +02:00
|
|
|
{
|
2017-08-12 15:41:14 +02:00
|
|
|
return this->input.textInput.hasFocus();
|
2017-06-11 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::paintEvent(QPaintEvent *)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
// color the background of the chat
|
2017-01-11 18:52:09 +01:00
|
|
|
QPainter painter(this);
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
painter.fillRect(this->rect(), this->colorScheme.ChatBackground);
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
2017-01-29 11:38:00 +01:00
|
|
|
|
2017-06-10 23:53:39 +02:00
|
|
|
/// Slots
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doAddSplit()
|
2017-06-10 23:53:39 +02:00
|
|
|
{
|
2017-11-12 17:21:50 +01:00
|
|
|
SplitContainer *page = static_cast<SplitContainer *>(this->parentWidget());
|
2017-06-29 14:13:00 +02:00
|
|
|
page->addChat(true);
|
2017-06-10 23:53:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doCloseSplit()
|
2017-06-10 23:53:39 +02:00
|
|
|
{
|
2017-11-12 17:21:50 +01:00
|
|
|
SplitContainer *page = static_cast<SplitContainer *>(this->parentWidget());
|
2017-06-11 12:03:47 +02:00
|
|
|
page->removeFromLayout(this);
|
2017-06-10 23:53:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doChangeChannel()
|
2017-06-10 23:53:39 +02:00
|
|
|
{
|
2017-07-31 01:36:42 +02:00
|
|
|
this->showChangeChannelPopup("Change channel");
|
2017-09-15 17:23:49 +02:00
|
|
|
auto popup = this->findChildren<QDockWidget *>();
|
2017-09-23 19:23:10 +02:00
|
|
|
if (popup.size() && popup.at(0)->isVisible() && !popup.at(0)->isFloating()) {
|
2017-09-12 22:10:30 +02:00
|
|
|
popup.at(0)->hide();
|
|
|
|
doOpenViewerList();
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doPopup()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2017-11-12 17:21:50 +01:00
|
|
|
Window &window = WindowManager::instance->createWindow();
|
|
|
|
|
|
|
|
Split *split = new Split(this->channelManager,
|
2017-12-22 14:44:31 +01:00
|
|
|
static_cast<SplitContainer *>(window.getNotebook().getSelectedPage()),
|
|
|
|
this->uuid);
|
2017-11-12 17:21:50 +01:00
|
|
|
|
|
|
|
window.getNotebook().getSelectedPage()->addToLayout(split);
|
|
|
|
|
|
|
|
window.show();
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doClearChat()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
view.clearMessages();
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenChannel()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2017-07-09 17:49:02 +02:00
|
|
|
qDebug() << "[UNIMPLEMENTED] Open twitch.tv/"
|
|
|
|
<< QString::fromStdString(this->channelName.getValue());
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenPopupPlayer()
|
2017-06-11 09:11:55 +02:00
|
|
|
{
|
2017-07-09 17:49:02 +02:00
|
|
|
qDebug() << "[UNIMPLEMENTED] Open twitch.tv/"
|
|
|
|
<< QString::fromStdString(this->channelName.getValue()) << "/popout";
|
2017-06-11 09:11:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenStreamlink()
|
2017-08-12 14:44:27 +02:00
|
|
|
{
|
|
|
|
SettingsManager &settings = SettingsManager::getInstance();
|
2017-09-15 17:23:49 +02:00
|
|
|
QString preferredQuality =
|
|
|
|
QString::fromStdString(settings.preferredQuality.getValue()).toLower();
|
2017-09-11 23:35:59 +02:00
|
|
|
// TODO(Confuseh): Default streamlink paths
|
2017-08-12 14:44:27 +02:00
|
|
|
QString path = QString::fromStdString(settings.streamlinkPath.getValue());
|
2017-09-11 23:35:59 +02:00
|
|
|
QString channel = QString::fromStdString(this->channelName.getValue());
|
2017-08-12 14:44:27 +02:00
|
|
|
QFileInfo fileinfo = QFileInfo(path);
|
2017-12-17 15:46:22 +01:00
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
debug::Log("[Split:doOpenStreamlink] No streamlink path selected in Settings");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fileinfo.exists()) {
|
|
|
|
debug::Log("[Split:doOpenStreamlink] Streamlink path ({}) is invalid, file does not exist",
|
|
|
|
path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileinfo.isDir() || !fileinfo.isExecutable()) {
|
|
|
|
debug::Log("[Split:doOpenStreamlink] Streamlink path ({}) is invalid, it needs to point to "
|
|
|
|
"the streamlink executable",
|
|
|
|
path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preferredQuality != "choose") {
|
|
|
|
QStringList args = {"twitch.tv/" + channel};
|
|
|
|
QString quality = "";
|
|
|
|
QString exclude = "";
|
|
|
|
if (preferredQuality == "high") {
|
|
|
|
exclude = ">720p30";
|
|
|
|
quality = "high,best";
|
|
|
|
} else if (preferredQuality == "medium") {
|
|
|
|
exclude = ">540p30";
|
|
|
|
quality = "medium,best";
|
|
|
|
} else if (preferredQuality == "low") {
|
|
|
|
exclude = ">360p30";
|
|
|
|
quality = "low,best";
|
|
|
|
} else if (preferredQuality == "audio only") {
|
|
|
|
quality = "audio,audio_only";
|
2017-09-11 23:35:59 +02:00
|
|
|
} else {
|
2017-12-17 15:46:22 +01:00
|
|
|
quality = "best";
|
|
|
|
}
|
|
|
|
if (quality != "")
|
|
|
|
args << quality;
|
|
|
|
if (exclude != "")
|
|
|
|
args << "--stream-sorting-excludes" << exclude;
|
|
|
|
QProcess::startDetached(path, args);
|
|
|
|
} else {
|
|
|
|
QProcess *p = new QProcess();
|
|
|
|
// my god that signal though
|
|
|
|
QObject::connect(p, static_cast<void (QProcess::*)(int)>(&QProcess::finished), this,
|
2017-12-17 16:34:01 +01:00
|
|
|
[path, channel, p](int) {
|
2017-12-17 15:46:22 +01:00
|
|
|
QString lastLine = QString(p->readAllStandardOutput());
|
2017-12-17 16:34:01 +01:00
|
|
|
lastLine = lastLine.trimmed().split('\n').last().trimmed();
|
2017-12-17 15:46:22 +01:00
|
|
|
if (lastLine.startsWith("Available streams: ")) {
|
|
|
|
QStringList options;
|
|
|
|
QStringList split =
|
|
|
|
lastLine.right(lastLine.length() - 19).split(", ");
|
|
|
|
|
|
|
|
for (int i = split.length() - 1; i >= 0; i--) {
|
|
|
|
QString option = split.at(i);
|
|
|
|
if (option.endsWith(" (worst)")) {
|
|
|
|
options << option.left(option.length() - 8);
|
|
|
|
} else if (option.endsWith(" (best)")) {
|
|
|
|
options << option.left(option.length() - 7);
|
|
|
|
} else {
|
|
|
|
options << option;
|
2017-09-15 17:23:49 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-17 15:46:22 +01:00
|
|
|
|
|
|
|
QualityPopup::showDialog(channel, path, options);
|
|
|
|
}
|
|
|
|
});
|
2017-12-17 16:34:01 +01:00
|
|
|
p->start(path, {"twitch.tv/" + channel, "--default-stream=KKona"});
|
2017-08-12 14:44:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenViewerList()
|
2017-09-11 22:37:39 +02:00
|
|
|
{
|
2017-09-15 17:23:49 +02:00
|
|
|
auto viewerDock = new QDockWidget("Viewer List", this);
|
2017-09-11 22:37:39 +02:00
|
|
|
viewerDock->setAllowedAreas(Qt::LeftDockWidgetArea);
|
|
|
|
viewerDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar |
|
2017-09-15 17:23:49 +02:00
|
|
|
QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable);
|
|
|
|
viewerDock->resize(0.5 * this->width(),
|
|
|
|
this->height() - this->header.height() - this->input.height());
|
|
|
|
viewerDock->move(0, this->header.height());
|
2017-09-11 22:37:39 +02:00
|
|
|
|
2017-09-12 22:10:30 +02:00
|
|
|
auto accountPopup = new AccountPopupWidget(this->channel);
|
2017-09-11 22:37:39 +02:00
|
|
|
auto multiWidget = new QWidget(viewerDock);
|
|
|
|
auto dockVbox = new QVBoxLayout(viewerDock);
|
|
|
|
auto searchBar = new QLineEdit(viewerDock);
|
|
|
|
|
|
|
|
auto chattersList = new QListWidget();
|
|
|
|
auto resultList = new QListWidget();
|
|
|
|
|
|
|
|
static QStringList labels = {"Moderators", "Staff", "Admins", "Global Moderators", "Viewers"};
|
|
|
|
static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"};
|
2017-09-15 17:23:49 +02:00
|
|
|
QList<QListWidgetItem *> labelList;
|
|
|
|
for (auto &x : labels) {
|
2017-09-11 22:37:39 +02:00
|
|
|
auto label = new QListWidgetItem(x);
|
|
|
|
label->setBackgroundColor(this->colorScheme.ChatHeaderBackground);
|
|
|
|
labelList.append(label);
|
2017-08-12 14:44:27 +02:00
|
|
|
}
|
2017-09-11 22:37:39 +02:00
|
|
|
auto loadingLabel = new QLabel("Loading...");
|
|
|
|
|
2017-10-27 20:09:02 +02:00
|
|
|
util::twitch::get("https://tmi.twitch.tv/group/user/" + channel->name + "/chatters", this,
|
|
|
|
[=](QJsonObject obj) {
|
|
|
|
QJsonObject chattersObj = obj.value("chatters").toObject();
|
|
|
|
|
|
|
|
loadingLabel->hide();
|
|
|
|
for (int i = 0; i < jsonLabels.size(); i++) {
|
|
|
|
chattersList->addItem(labelList.at(i));
|
|
|
|
foreach (const QJsonValue &v,
|
|
|
|
chattersObj.value(jsonLabels.at(i)).toArray())
|
|
|
|
chattersList->addItem(v.toString());
|
|
|
|
}
|
|
|
|
});
|
2017-09-11 22:37:39 +02:00
|
|
|
|
|
|
|
searchBar->setPlaceholderText("Search User...");
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
|
2017-09-11 22:37:39 +02:00
|
|
|
auto query = searchBar->text();
|
2017-09-15 17:23:49 +02:00
|
|
|
if (!query.isEmpty()) {
|
|
|
|
auto results = chattersList->findItems(query, Qt::MatchStartsWith);
|
2017-09-11 22:37:39 +02:00
|
|
|
chattersList->hide();
|
|
|
|
resultList->clear();
|
2017-09-15 17:23:49 +02:00
|
|
|
for (auto &item : results) {
|
|
|
|
if (!labels.contains(item->text()))
|
2017-09-11 22:37:39 +02:00
|
|
|
resultList->addItem(item->text());
|
|
|
|
}
|
|
|
|
resultList->show();
|
2017-09-15 17:23:49 +02:00
|
|
|
} else {
|
2017-09-11 22:37:39 +02:00
|
|
|
resultList->hide();
|
|
|
|
chattersList->show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(viewerDock, &QDockWidget::topLevelChanged, this,
|
|
|
|
[=]() { viewerDock->setMinimumWidth(300); });
|
2017-09-11 22:37:39 +02:00
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(chattersList, &QListWidget::doubleClicked, this, [=]() {
|
|
|
|
if (!labels.contains(chattersList->currentItem()->text())) {
|
|
|
|
doOpenAccountPopupWidget(accountPopup, chattersList->currentItem()->text());
|
2017-09-12 22:10:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
QObject::connect(resultList, &QListWidget::doubleClicked, this, [=]() {
|
|
|
|
if (!labels.contains(resultList->currentItem()->text())) {
|
|
|
|
doOpenAccountPopupWidget(accountPopup, resultList->currentItem()->text());
|
2017-09-12 22:10:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-11 22:37:39 +02:00
|
|
|
dockVbox->addWidget(searchBar);
|
|
|
|
dockVbox->addWidget(loadingLabel);
|
|
|
|
dockVbox->addWidget(chattersList);
|
|
|
|
dockVbox->addWidget(resultList);
|
|
|
|
resultList->hide();
|
|
|
|
|
|
|
|
multiWidget->setStyleSheet(this->colorScheme.InputStyleSheet);
|
|
|
|
multiWidget->setLayout(dockVbox);
|
|
|
|
viewerDock->setWidget(multiWidget);
|
|
|
|
viewerDock->show();
|
2017-08-12 14:44:27 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user)
|
2017-09-12 22:10:30 +02:00
|
|
|
{
|
|
|
|
widget->setName(user);
|
|
|
|
widget->move(QCursor::pos());
|
2017-09-23 19:23:10 +02:00
|
|
|
widget->updatePermissions();
|
2017-09-12 22:10:30 +02:00
|
|
|
widget->show();
|
|
|
|
widget->setFocus();
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doCopy()
|
2017-09-12 19:06:16 +02:00
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(this->view.getSelectedText());
|
|
|
|
}
|
|
|
|
|
2017-09-17 04:36:48 +02:00
|
|
|
template <typename Iter, typename RandomGenerator>
|
|
|
|
static Iter select_randomly(Iter start, Iter end, RandomGenerator &g)
|
|
|
|
{
|
|
|
|
std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
|
|
|
|
std::advance(start, dis(g));
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Iter>
|
|
|
|
static Iter select_randomly(Iter start, Iter end)
|
|
|
|
{
|
|
|
|
static std::random_device rd;
|
|
|
|
static std::mt19937 gen(rd());
|
|
|
|
return select_randomly(start, end, gen);
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Split::doIncFlexX()
|
|
|
|
{
|
|
|
|
this->setFlexSizeX(this->getFlexSizeX() * 1.2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::doDecFlexX()
|
|
|
|
{
|
|
|
|
this->setFlexSizeX(this->getFlexSizeX() * (1 / 1.2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::doIncFlexY()
|
|
|
|
{
|
|
|
|
this->setFlexSizeY(this->getFlexSizeY() * 1.2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Split::doDecFlexY()
|
|
|
|
{
|
|
|
|
this->setFlexSizeY(this->getFlexSizeY() * (1 / 1.2));
|
|
|
|
}
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|