mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-06 20:15:19 +03:00
guild icons
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user