mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Merge branch 'master' of github.com:fourtf/chatterino2
This commit is contained in:
commit
3010e6303a
5 changed files with 156 additions and 33 deletions
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>317</width>
|
||||||
<height>131</height>
|
<height>145</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -19,60 +19,72 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>AccountPopup</string>
|
<string>AccountPopup</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QPushButton" name="btnPurge">
|
|
||||||
<property name="text">
|
|
||||||
<string>Purge</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" rowspan="2" colspan="2">
|
<item row="1" column="1" rowspan="2" colspan="2">
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Views</string>
|
<string>Views:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="lblViews">
|
<widget class="QLabel" name="lblViews">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>420</string>
|
<string>Loading...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Followers</string>
|
<string>Followers:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLabel" name="lblFollowers">
|
<widget class="QLabel" name="lblFollowers">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>69</string>
|
<string>Loading...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Account Age</string>
|
<string>Created at:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QLabel" name="lblAccountAge">
|
<widget class="QLabel" name="lblAccountAge">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>6 years</string>
|
<string>Loading...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0" rowspan="3">
|
||||||
|
<widget class="QLabel" name="lblAvatar">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>100</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Loading...</string>
|
||||||
|
</property>
|
||||||
|
<property name="scaledContents">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="1" colspan="2">
|
<item row="0" column="1" colspan="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
|
@ -91,7 +103,7 @@
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>USERNAME</string>
|
<string>Loading...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -110,13 +122,6 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" rowspan="3">
|
|
||||||
<widget class="QLabel" name="lblAvatar">
|
|
||||||
<property name="text">
|
|
||||||
<string>AVATAR</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
@ -10,7 +10,7 @@ MessageBuilder::MessageBuilder()
|
||||||
: _words()
|
: _words()
|
||||||
{
|
{
|
||||||
_parseTime = std::chrono::system_clock::now();
|
_parseTime = std::chrono::system_clock::now();
|
||||||
regex.setPattern("[[:ascii:]]*\\.[A-Z]+");
|
regex.setPattern("[[:ascii:]]*\\.[A-Z]+\/[[:ascii:]]+");
|
||||||
regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
#include "ui_accountpopupform.h"
|
#include "ui_accountpopupform.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace widgets {
|
namespace widgets {
|
||||||
|
@ -22,20 +28,119 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> &channel)
|
||||||
connect(_ui->btnClose, &QPushButton::clicked, [=]() {
|
connect(_ui->btnClose, &QPushButton::clicked, [=]() {
|
||||||
hide(); //
|
hide(); //
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(_ui->btnPurge, &QPushButton::clicked, [=]() {
|
|
||||||
qDebug() << "xD: " << _channel->name;
|
|
||||||
printf("Channel pointer in dialog: %p\n", _channel.get());
|
|
||||||
|
|
||||||
//_channel->sendMessage(QString(".timeout %1 0").arg(_ui->lblUsername->text()));
|
|
||||||
_channel->sendMessage("xD");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPopupWidget::setName(const QString &name)
|
void AccountPopupWidget::setName(const QString &name)
|
||||||
{
|
{
|
||||||
_ui->lblUsername->setText(name);
|
_ui->lblUsername->setText(name);
|
||||||
|
getUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AccountPopupWidget::getUserId()
|
||||||
|
{
|
||||||
|
QUrl nameUrl("https://api.twitch.tv/kraken/users?login=" + _ui->lblUsername->text());
|
||||||
|
|
||||||
|
QNetworkRequest req(nameUrl);
|
||||||
|
req.setRawHeader(QByteArray("Accept"),QByteArray("application/vnd.twitchtv.v5+json"));
|
||||||
|
req.setRawHeader(QByteArray("Client-ID"),QByteArray("7ue61iz46fz11y3cugd0l3tawb4taal"));
|
||||||
|
|
||||||
|
static auto manager = new QNetworkAccessManager();
|
||||||
|
auto *reply = manager->get(req);
|
||||||
|
|
||||||
|
QObject::connect(reply,&QNetworkReply::finished,this,[=]
|
||||||
|
{
|
||||||
|
if(reply->error() == QNetworkReply::NoError){
|
||||||
|
auto doc = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
auto obj = doc.object();
|
||||||
|
auto array = obj.value("users").toArray();
|
||||||
|
|
||||||
|
userID = array.at(0).toObject().value("_id").toString();
|
||||||
|
|
||||||
|
getUserData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccountPopupWidget::getUserData()
|
||||||
|
{
|
||||||
|
QUrl idUrl("https://api.twitch.tv/kraken/channels/" + userID);
|
||||||
|
|
||||||
|
QNetworkRequest req(idUrl);
|
||||||
|
req.setRawHeader(QByteArray("Accept"),QByteArray("application/vnd.twitchtv.v5+json"));
|
||||||
|
req.setRawHeader(QByteArray("Client-ID"),QByteArray("7ue61iz46fz11y3cugd0l3tawb4taal"));
|
||||||
|
|
||||||
|
static auto manager = new QNetworkAccessManager();
|
||||||
|
auto *reply = manager->get(req);
|
||||||
|
|
||||||
|
QObject::connect(reply,&QNetworkReply::finished,this,[=]
|
||||||
|
{
|
||||||
|
if(reply->error() == QNetworkReply::NoError){
|
||||||
|
auto doc = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
auto obj = doc.object();
|
||||||
|
|
||||||
|
_ui->lblFollowers->setText(QString::number(obj.value("followers").toInt()));
|
||||||
|
_ui->lblViews->setText(QString::number(obj.value("views").toInt()));
|
||||||
|
_ui->lblAccountAge->setText(obj.value("created_at").toString().section("T",0,0));
|
||||||
|
|
||||||
|
loadAvatar(QUrl(obj.value("logo").toString()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ui->lblFollowers->setText("ERROR");
|
||||||
|
_ui->lblViews->setText("ERROR");
|
||||||
|
_ui->lblAccountAge->setText("ERROR");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl)
|
||||||
|
{
|
||||||
|
if(!avatarMap.tryGet(userID,this->avatar))
|
||||||
|
{
|
||||||
|
if(!avatarUrl.isEmpty())
|
||||||
|
{
|
||||||
|
QNetworkRequest req(avatarUrl);
|
||||||
|
static auto manager = new QNetworkAccessManager();
|
||||||
|
auto *reply = manager->get(req);
|
||||||
|
|
||||||
|
QObject::connect(reply,&QNetworkReply::finished,this,[=]
|
||||||
|
{
|
||||||
|
if(reply->error() == QNetworkReply::NoError)
|
||||||
|
{
|
||||||
|
const auto data = reply->readAll();
|
||||||
|
this->avatar.loadFromData(data);
|
||||||
|
this->avatarMap.insert(userID,avatar);
|
||||||
|
_ui->lblAvatar->setPixmap(avatar);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ui->lblAvatar->setText("ERROR");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ui->lblAvatar->setText("No Avatar");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ui->lblAvatar->setPixmap(this->avatar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccountPopupWidget::focusOutEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
hide();
|
||||||
|
|
||||||
|
_ui->lblFollowers->setText("Loading...");
|
||||||
|
_ui->lblViews->setText("Loading...");
|
||||||
|
_ui->lblAccountAge->setText("Loading...");
|
||||||
|
_ui->lblUsername->setText("Loading...");
|
||||||
|
_ui->lblAvatar->setText("Loading...");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace widgets
|
} // namespace widgets
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "concurrentmap.hpp"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
@ -25,7 +26,19 @@ public:
|
||||||
private:
|
private:
|
||||||
Ui::AccountPopup *_ui;
|
Ui::AccountPopup *_ui;
|
||||||
|
|
||||||
|
void getUserId();
|
||||||
|
void getUserData();
|
||||||
|
void loadAvatar(const QUrl &avatarUrl);
|
||||||
|
|
||||||
std::shared_ptr<Channel> &_channel;
|
std::shared_ptr<Channel> &_channel;
|
||||||
|
|
||||||
|
QString userID;
|
||||||
|
QPixmap avatar;
|
||||||
|
|
||||||
|
ConcurrentMap<QString,QPixmap> avatarMap;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void focusOutEvent(QFocusEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace widgets
|
} // namespace widgets
|
||||||
|
|
|
@ -383,7 +383,7 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
|
||||||
switch (link.getType()) {
|
switch (link.getType()) {
|
||||||
case messages::Link::UserInfo: {
|
case messages::Link::UserInfo: {
|
||||||
auto user = message->getMessage()->getUserName();
|
auto user = link.getValue();
|
||||||
this->userPopupWidget.setName(user);
|
this->userPopupWidget.setName(user);
|
||||||
this->userPopupWidget.move(event->screenPos().toPoint());
|
this->userPopupWidget.move(event->screenPos().toPoint());
|
||||||
this->userPopupWidget.show();
|
this->userPopupWidget.show();
|
||||||
|
|
Loading…
Reference in a new issue