show status, error when captcha required
This commit is contained in:
@@ -23,21 +23,40 @@ RemoteAuthDialog::RemoteAuthDialog(Gtk::Window &parent)
|
||||
m_bbox.pack_start(m_cancel, Gtk::PACK_SHRINK);
|
||||
m_bbox.set_layout(Gtk::BUTTONBOX_END);
|
||||
|
||||
m_ra.signal_hello().connect(sigc::mem_fun(*this, &RemoteAuthDialog::OnHello));
|
||||
m_ra.signal_fingerprint().connect(sigc::mem_fun(*this, &RemoteAuthDialog::OnFingerprint));
|
||||
m_ra.signal_pending_ticket().connect(sigc::mem_fun(*this, &RemoteAuthDialog::OnPendingTicket));
|
||||
m_ra.signal_pending_login().connect(sigc::mem_fun(*this, &RemoteAuthDialog::OnPendingLogin));
|
||||
m_ra.signal_token().connect(sigc::mem_fun(*this, &RemoteAuthDialog::OnToken));
|
||||
m_ra.signal_error().connect(sigc::mem_fun(*this, &RemoteAuthDialog::OnError));
|
||||
|
||||
m_ra.Start();
|
||||
|
||||
m_image.set_size_request(256, 256);
|
||||
|
||||
m_status.set_text("Connecting...");
|
||||
m_status.set_hexpand(true);
|
||||
m_status.set_halign(Gtk::ALIGN_CENTER);
|
||||
|
||||
m_layout.add(m_image);
|
||||
m_layout.add(m_status);
|
||||
m_layout.add(m_bbox);
|
||||
get_content_area()->add(m_layout);
|
||||
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
std::string RemoteAuthDialog::GetToken() {
|
||||
return m_token;
|
||||
}
|
||||
|
||||
void RemoteAuthDialog::OnHello() {
|
||||
m_status.set_text("Handshaking...");
|
||||
}
|
||||
|
||||
void RemoteAuthDialog::OnFingerprint(const std::string &fingerprint) {
|
||||
m_status.set_text("Waiting for mobile device...");
|
||||
|
||||
const auto url = "https://discord.com/ra/" + fingerprint;
|
||||
|
||||
const auto level = qrcodegen::QrCode::Ecc::QUARTILE;
|
||||
@@ -75,8 +94,24 @@ void RemoteAuthDialog::OnFingerprint(const std::string &fingerprint) {
|
||||
m_image.property_pixbuf() = pb;
|
||||
}
|
||||
|
||||
std::string RemoteAuthDialog::GetToken() {
|
||||
return m_token;
|
||||
void RemoteAuthDialog::OnPendingTicket(Snowflake user_id, std::string discriminator, std::string avatar_hash, std::string username) {
|
||||
Glib::ustring name = username;
|
||||
if (discriminator != "0") {
|
||||
name += "#" + discriminator;
|
||||
}
|
||||
m_status.set_text("Waiting for confirmation... (" + name + ")");
|
||||
|
||||
if (!avatar_hash.empty()) {
|
||||
const auto url = "https://cdn.discordapp.com/avatars/" + std::to_string(user_id) + "/" + avatar_hash + ".png?size=256";
|
||||
const auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
|
||||
m_image.property_pixbuf() = pb->scale_simple(256, 256, Gdk::INTERP_BILINEAR);
|
||||
};
|
||||
Abaddon::Get().GetImageManager().LoadFromURL(url, sigc::track_obj(cb, *this));
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteAuthDialog::OnPendingLogin() {
|
||||
m_status.set_text("Logging in!");
|
||||
}
|
||||
|
||||
void RemoteAuthDialog::OnToken(const std::string &token) {
|
||||
@@ -84,3 +119,9 @@ void RemoteAuthDialog::OnToken(const std::string &token) {
|
||||
m_ra.Stop();
|
||||
response(Gtk::RESPONSE_OK);
|
||||
}
|
||||
|
||||
void RemoteAuthDialog::OnError(const std::string &error) {
|
||||
m_ra.Stop();
|
||||
Abaddon::Get().ShowConfirm(error, dynamic_cast<Gtk::Window*>(get_toplevel()));
|
||||
response(Gtk::RESPONSE_CANCEL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user