diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-19 18:58:47 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-19 18:58:47 -0400 |
commit | 83b480742b46f120b73042791e2f91c70ce3fe84 (patch) | |
tree | 31165ded8fc274cfa6de12b2dcc51066c98e389b | |
parent | 72d0a0d2a098d9f75291bdad73d02d3601c82945 (diff) | |
download | abaddon-portaudio-83b480742b46f120b73042791e2f91c70ce3fe84.tar.gz abaddon-portaudio-83b480742b46f120b73042791e2f91c70ce3fe84.zip |
guild icons
-rw-r--r-- | components/channels.cpp | 16 | ||||
-rw-r--r-- | components/channels.hpp | 1 | ||||
-rw-r--r-- | discord/guild.cpp | 4 | ||||
-rw-r--r-- | discord/guild.hpp | 2 |
4 files changed, 23 insertions, 0 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 227d791..db6beb1 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -3,6 +3,7 @@ #include <map> #include <unordered_map> #include "../abaddon.hpp" +#include "../imgmanager.hpp" ChannelListRow::type_signal_list_collapse ChannelListRow::signal_list_collapse() { return m_signal_list_collapse; @@ -57,12 +58,27 @@ ChannelListRowGuild::ChannelListRowGuild(const Guild *data) { m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); m_lbl = Gtk::manage(new Gtk::Label); + auto buf = Abaddon::Get().GetImageManager().GetFromURLIfCached(data->GetIconURL("png", "32")); + if (buf) + m_icon = Gtk::manage(new Gtk::Image(buf)); + else { + m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24))); + Abaddon::Get().GetImageManager().LoadFromURL(data->GetIconURL("png", "32"), [this](Glib::RefPtr<Gdk::Pixbuf> ldbuf) { + Glib::signal_idle().connect([this, ldbuf]() -> bool { + m_icon->property_pixbuf() = ldbuf->scale_simple(24, 24, Gdk::INTERP_BILINEAR); + + return false; + }); + }); + } + get_style_context()->add_class("channel-row"); get_style_context()->add_class("channel-row-guild"); m_lbl->get_style_context()->add_class("channel-row-label"); m_lbl->set_markup("<b>" + Glib::Markup::escape_text(data->Name) + "</b>"); m_box->set_halign(Gtk::ALIGN_START); + m_box->pack_start(*m_icon); m_box->pack_start(*m_lbl); m_ev->add(*m_box); add(*m_ev); diff --git a/components/channels.hpp b/components/channels.hpp index a771933..f898df7 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -55,6 +55,7 @@ protected: Gtk::EventBox *m_ev; Gtk::Box *m_box; Gtk::Label *m_lbl; + Gtk::Image *m_icon; }; class ChannelListRowCategory : public ChannelListRow { diff --git a/discord/guild.cpp b/discord/guild.cpp index fae30f1..35db47c 100644 --- a/discord/guild.cpp +++ b/discord/guild.cpp @@ -54,3 +54,7 @@ void from_json(const nlohmann::json &j, Guild &m) { JS_O("approximate_member_count", m.ApproximateMemberCount); JS_O("approximate_presence_count", m.ApproximatePresenceCount); } + +std::string Guild::GetIconURL(std::string ext, std::string size) const { + return "https://cdn.discordapp.com/icons/" + std::to_string(ID) + "/" + Icon + "." + ext + "?size=" + size; +} diff --git a/discord/guild.hpp b/discord/guild.hpp index d90c3e8..4966b34 100644 --- a/discord/guild.hpp +++ b/discord/guild.hpp @@ -64,4 +64,6 @@ struct Guild { // * - documentation says only sent in GUILD_CREATE, but these can be sent anyways in the READY event friend void from_json(const nlohmann::json &j, Guild &m); + + std::string GetIconURL(std::string ext = "png", std::string size = "32") const; }; |