2018-07-20 22:27:43 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-07-20 22:27:43 +00:00
|
|
|
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
|
2018-08-06 21:56:40 +00:00
|
|
|
#include "DolphinQt/DiscordJoinRequestDialog.h"
|
|
|
|
|
2018-07-20 22:27:43 +00:00
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
2020-04-29 09:45:59 +00:00
|
|
|
#include <discord_rpc.h>
|
2022-10-12 02:21:51 +00:00
|
|
|
#include <fmt/format.h>
|
2018-07-20 22:27:43 +00:00
|
|
|
|
|
|
|
#include "Common/HttpRequest.h"
|
|
|
|
|
2018-08-06 21:56:40 +00:00
|
|
|
DiscordJoinRequestDialog::DiscordJoinRequestDialog(QWidget* parent, const std::string& id,
|
2018-07-20 22:27:43 +00:00
|
|
|
const std::string& discord_tag,
|
2018-08-06 21:56:40 +00:00
|
|
|
const std::string& avatar)
|
2018-07-20 22:27:43 +00: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 21:56:40 +00:00
|
|
|
if (!avatar.empty())
|
2018-07-20 22:27:43 +00:00
|
|
|
{
|
2022-10-12 02:21:51 +00:00
|
|
|
const std::string avatar_endpoint =
|
|
|
|
fmt::format("https://cdn.discordapp.com/avatars/{}/{}.png", id, avatar);
|
2018-07-20 22:27:43 +00: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 21:56:40 +00:00
|
|
|
CreateLayout(discord_tag, avatar_pixmap);
|
2018-07-20 22:27:43 +00:00
|
|
|
ConnectWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::time_t DiscordJoinRequestDialog::GetCloseTimestamp() const
|
|
|
|
{
|
|
|
|
return m_close_timestamp;
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:56:40 +00:00
|
|
|
void DiscordJoinRequestDialog::CreateLayout(const std::string& discord_tag, const QPixmap& avatar)
|
2018-07-20 22:27:43 +00:00
|
|
|
{
|
|
|
|
m_main_layout = new QGridLayout;
|
|
|
|
|
2018-08-06 21:56:40 +00:00
|
|
|
m_invite_button = new QPushButton(tr("\u2714 Invite"));
|
|
|
|
m_decline_button = new QPushButton(tr("\u2716 Decline"));
|
2018-07-20 22:27:43 +00:00
|
|
|
m_ignore_button = new QPushButton(tr("Ignore"));
|
|
|
|
|
2018-08-06 21:56:40 +00:00
|
|
|
QLabel* text =
|
|
|
|
new QLabel(tr("%1\nwants to join your party.").arg(QString::fromStdString(discord_tag)));
|
|
|
|
text->setAlignment(Qt::AlignCenter);
|
|
|
|
|
2018-07-20 22:27:43 +00: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 21:56:40 +00:00
|
|
|
m_main_layout->addWidget(text, 2, 0, 3, 3, Qt::AlignHCenter);
|
2018-07-20 22:27:43 +00: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()
|
|
|
|
{
|
2019-07-23 22:18:58 +00:00
|
|
|
connect(m_invite_button, &QPushButton::clicked, [this] { Reply(DISCORD_REPLY_YES); });
|
|
|
|
connect(m_decline_button, &QPushButton::clicked, [this] { Reply(DISCORD_REPLY_NO); });
|
|
|
|
connect(m_ignore_button, &QPushButton::clicked, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
|
|
|
connect(this, &QDialog::rejected, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
2018-07-20 22:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiscordJoinRequestDialog::Reply(int reply)
|
|
|
|
{
|
2018-08-06 21:56:40 +00:00
|
|
|
Discord_Respond(m_user_id.c_str(), reply);
|
2018-07-20 22:27:43 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|