2018-07-20 16:27:43 -06:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
#include "DolphinQt/DiscordJoinRequestDialog.h"
|
|
|
|
|
2018-07-20 16:27:43 -06:00
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
#include <discord-rpc/include/discord_rpc.h>
|
|
|
|
|
|
|
|
#include "Common/HttpRequest.h"
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
DiscordJoinRequestDialog::DiscordJoinRequestDialog(QWidget* parent, const std::string& id,
|
2018-07-20 16:27:43 -06:00
|
|
|
const std::string& discord_tag,
|
2018-08-06 15:56:40 -06:00
|
|
|
const std::string& avatar)
|
2018-07-20 16:27:43 -06:00
|
|
|
: QDialog(parent), m_user_id(id), m_close_timestamp(std::time(nullptr) + s_max_lifetime_seconds)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Request to Join Your Party"));
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
QPixmap avatar_pixmap;
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
if (!avatar.empty())
|
2018-07-20 16:27:43 -06:00
|
|
|
{
|
2018-08-06 15:56:40 -06:00
|
|
|
const std::string avatar_endpoint = StringFromFormat(
|
|
|
|
"https://cdn.discordapp.com/avatars/%s/%s.png", id.c_str(), avatar.c_str());
|
2018-07-20 16:27:43 -06:00
|
|
|
|
|
|
|
Common::HttpRequest request;
|
|
|
|
Common::HttpRequest::Response response = request.Get(avatar_endpoint);
|
|
|
|
|
|
|
|
if (response.has_value())
|
|
|
|
avatar_pixmap.loadFromData(response->data(), static_cast<uint>(response->size()), "png");
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
CreateLayout(discord_tag, avatar_pixmap);
|
2018-07-20 16:27:43 -06:00
|
|
|
ConnectWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::time_t DiscordJoinRequestDialog::GetCloseTimestamp() const
|
|
|
|
{
|
|
|
|
return m_close_timestamp;
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
void DiscordJoinRequestDialog::CreateLayout(const std::string& discord_tag, const QPixmap& avatar)
|
2018-07-20 16:27:43 -06:00
|
|
|
{
|
|
|
|
m_main_layout = new QGridLayout;
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
m_invite_button = new QPushButton(tr("\u2714 Invite"));
|
|
|
|
m_decline_button = new QPushButton(tr("\u2716 Decline"));
|
2018-07-20 16:27:43 -06:00
|
|
|
m_ignore_button = new QPushButton(tr("Ignore"));
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
QLabel* text =
|
|
|
|
new QLabel(tr("%1\nwants to join your party.").arg(QString::fromStdString(discord_tag)));
|
|
|
|
text->setAlignment(Qt::AlignCenter);
|
|
|
|
|
2018-07-20 16:27:43 -06:00
|
|
|
if (!avatar.isNull())
|
|
|
|
{
|
|
|
|
QLabel* picture = new QLabel();
|
|
|
|
picture->setPixmap(avatar);
|
|
|
|
m_main_layout->addWidget(picture, 1, 0, 1, 3, Qt::AlignHCenter);
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:56:40 -06:00
|
|
|
m_main_layout->addWidget(text, 2, 0, 3, 3, Qt::AlignHCenter);
|
2018-07-20 16:27:43 -06:00
|
|
|
m_main_layout->addWidget(m_invite_button, 8, 0);
|
|
|
|
m_main_layout->addWidget(m_decline_button, 8, 1);
|
|
|
|
m_main_layout->addWidget(m_ignore_button, 8, 2);
|
|
|
|
|
|
|
|
setLayout(m_main_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscordJoinRequestDialog::ConnectWidgets()
|
|
|
|
{
|
2018-08-06 15:56:40 -06:00
|
|
|
connect(m_invite_button, &QPushButton::pressed, [this] { Reply(DISCORD_REPLY_YES); });
|
|
|
|
connect(m_decline_button, &QPushButton::pressed, [this] { Reply(DISCORD_REPLY_NO); });
|
|
|
|
connect(m_ignore_button, &QPushButton::pressed, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
2018-07-20 16:27:43 -06:00
|
|
|
connect(this, &QDialog::rejected, this, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscordJoinRequestDialog::Reply(int reply)
|
|
|
|
{
|
2018-08-06 15:56:40 -06:00
|
|
|
Discord_Respond(m_user_id.c_str(), reply);
|
2018-07-20 16:27:43 -06:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|