Skip to content

Commit

Permalink
reimplement status indicator in member list
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Nov 17, 2023
1 parent 8e02e7c commit 3d2f5ab
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 160 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ spam filter's wrath:
| `.embed-field-value` | The value of an embed field |
| `.embed-footer` | The footer of an embed |
| `.member-list` | Container of the member list |
| `.status-indicator` | The status indicator |
| `.online` | Applied to status indicators when the associated user is online |
| `.idle` | Applied to status indicators when the associated user is away |
| `.dnd` | Applied to status indicators when the associated user is on do not disturb |
| `.offline` | Applied to status indicators when the associated user is offline |
| `.typing-indicator` | The typing indicator (also used for replies) |

Used in reorderable list implementation:
Expand Down
34 changes: 32 additions & 2 deletions src/components/cellrenderermemberlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ CellRendererMemberList::CellRendererMemberList()
, m_property_id(*this, "id")
, m_property_name(*this, "name")
, m_property_pixbuf(*this, "pixbuf")
, m_property_color(*this, "color") {
, m_property_color(*this, "color")
, m_property_status(*this, "status") {
property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
property_xpad() = 2;
property_ypad() = 2;
Expand Down Expand Up @@ -35,6 +36,10 @@ Glib::PropertyProxy<Gdk::RGBA> CellRendererMemberList::property_color() {
return m_property_color.get_proxy();
}

Glib::PropertyProxy<PresenceStatus> CellRendererMemberList::property_status() {
return m_property_status.get_proxy();
}

void CellRendererMemberList::get_preferred_width_vfunc(Gtk::Widget &widget, int &minimum_width, int &natural_width) const {
switch (m_property_type.get_value()) {
case MemberListRenderType::Role:
Expand Down Expand Up @@ -117,15 +122,40 @@ void CellRendererMemberList::get_preferred_height_for_width_vfunc_member(Gtk::Wi
}

void CellRendererMemberList::render_vfunc_member(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags) {
// Text
Gdk::Rectangle text_cell_area = cell_area;
text_cell_area.set_x(22);
text_cell_area.set_x(31);
const auto color = m_property_color.get_value();
if (color.get_alpha_u() > 0) {
m_renderer_text.property_foreground_rgba().set_value(color);
}
m_renderer_text.render(cr, widget, background_area, text_cell_area, flags);
m_renderer_text.property_foreground_set().set_value(false);

// Status indicator
// TODO: reintroduce custom status colors... somehow
cr->begin_new_path();
switch (m_property_status.get_value()) {
case PresenceStatus::Online:
cr->set_source_rgb(33.0 / 255.0, 157.0 / 255.0, 86.0 / 255.0);
break;
case PresenceStatus::Idle:
cr->set_source_rgb(230.0 / 255.0, 170.0 / 255.0, 48.0 / 255.0);
break;
case PresenceStatus::DND:
cr->set_source_rgb(233.0 / 255.0, 61.0 / 255.0, 65.0 / 255.0);
break;
case PresenceStatus::Offline:
cr->set_source_rgb(122.0 / 255.0, 126.0 / 255.0, 135.0 / 255.0);
break;
}

cr->arc(background_area.get_x() + 6.0 + 16.0 + 6.0, background_area.get_y() + background_area.get_height() / 2.0, 2.0, 0.0, 2 * (4 * std::atan(1)));
cr->close_path();
cr->fill_preserve();
cr->stroke();

// Icon
const double icon_x = background_area.get_x() + 6.0;
const double icon_y = background_area.get_y() + background_area.get_height() / 2.0 - 8.0;
Gdk::Cairo::set_source_pixbuf(cr, m_property_pixbuf.get_value(), icon_x, icon_y);
Expand Down
3 changes: 3 additions & 0 deletions src/components/cellrenderermemberlist.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <gtkmm/cellrenderer.h>
#include "discord/activity.hpp"

enum class MemberListRenderType : uint8_t {
Role,
Expand All @@ -16,6 +17,7 @@ class CellRendererMemberList : public Gtk::CellRenderer {
Glib::PropertyProxy<Glib::ustring> property_name();
Glib::PropertyProxy<Glib::RefPtr<Gdk::Pixbuf>> property_pixbuf();
Glib::PropertyProxy<Gdk::RGBA> property_color();
Glib::PropertyProxy<PresenceStatus> property_status();

protected:
void get_preferred_width_vfunc(Gtk::Widget &widget, int &minimum_width, int &natural_width) const override;
Expand Down Expand Up @@ -56,6 +58,7 @@ class CellRendererMemberList : public Gtk::CellRenderer {
Glib::Property<Glib::ustring> m_property_name;
Glib::Property<Glib::RefPtr<Gdk::Pixbuf>> m_property_pixbuf;
Glib::Property<Gdk::RGBA> m_property_color;
Glib::Property<PresenceStatus> m_property_status;

using type_signal_render = sigc::signal<void(uint64_t)>;
type_signal_render m_signal_render;
Expand Down
1 change: 0 additions & 1 deletion src/components/channels.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "channels.hpp"
#include "imgmanager.hpp"
#include "statusindicator.hpp"
#include <algorithm>
#include <map>
#include <unordered_map>
Expand Down
19 changes: 18 additions & 1 deletion src/components/memberlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ MemberList::MemberList()
column->add_attribute(renderer->property_name(), m_columns.m_name);
column->add_attribute(renderer->property_pixbuf(), m_columns.m_pixbuf);
column->add_attribute(renderer->property_color(), m_columns.m_color);
column->add_attribute(renderer->property_status(), m_columns.m_status);
m_view.append_column(*column);

m_model->set_sort_column(m_columns.m_sort, Gtk::SORT_ASCENDING);
Expand All @@ -44,6 +45,8 @@ MemberList::MemberList()
m_menu_role_copy_id.signal_activate().connect([this]() {
Gtk::Clipboard::get()->set_text(std::to_string((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]));
});

Abaddon::Get().GetDiscordClient().signal_presence_update().connect(sigc::mem_fun(*this, &MemberList::OnPresenceUpdate));
}

Gtk::Widget *MemberList::GetRoot() {
Expand Down Expand Up @@ -73,6 +76,7 @@ void MemberList::UpdateMemberList() {
row[m_columns.m_color] = color_transparent;
row[m_columns.m_av_requested] = false;
row[m_columns.m_pixbuf] = Abaddon::Get().GetImageManager().GetPlaceholder(16);
row[m_columns.m_status] = Abaddon::Get().GetDiscordClient().GetUserStatus(user.ID);
m_pending_avatars[user.ID] = row_iter;
}
}
Expand Down Expand Up @@ -126,6 +130,7 @@ void MemberList::UpdateMemberList() {
row[m_columns.m_id] = user.ID;
row[m_columns.m_name] = user.GetDisplayNameEscaped();
row[m_columns.m_pixbuf] = Abaddon::Get().GetImageManager().GetPlaceholder(16);
row[m_columns.m_status] = Abaddon::Get().GetDiscordClient().GetUserStatus(user.ID);
row[m_columns.m_av_requested] = false;
if (const auto iter = user_to_color.find(user.ID); iter != user_to_color.end()) {
row[m_columns.m_color] = IntToRGBA(iter->second);
Expand Down Expand Up @@ -241,12 +246,24 @@ int MemberList::SortFunc(const Gtk::TreeModel::iterator &a, const Gtk::TreeModel
return 0;
}

void MemberList::OnPresenceUpdate(const UserData &user, PresenceStatus status) {
for (auto &role : m_model->children()) {
for (auto &member : role.children()) {
if ((*member)[m_columns.m_id] == user.ID) {
(*member)[m_columns.m_status] = status;
return;
}
}
}
}

MemberList::ModelColumns::ModelColumns() {
add(m_type);
add(m_id);
add(m_name);
add(m_pixbuf);
add(m_av_requested);
add(m_color);
add(m_status);
add(m_sort);
add(m_av_requested);
}
3 changes: 3 additions & 0 deletions src/components/memberlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class MemberList {

int SortFunc(const Gtk::TreeModel::iterator &a, const Gtk::TreeModel::iterator &b);

void OnPresenceUpdate(const UserData &user, PresenceStatus status);

class ModelColumns : public Gtk::TreeModel::ColumnRecord {
public:
ModelColumns();
Expand All @@ -35,6 +37,7 @@ class MemberList {
Gtk::TreeModelColumn<Glib::ustring> m_name;
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> m_pixbuf;
Gtk::TreeModelColumn<Gdk::RGBA> m_color;
Gtk::TreeModelColumn<PresenceStatus> m_status;
Gtk::TreeModelColumn<int> m_sort;

Gtk::TreeModelColumn<bool> m_av_requested;
Expand Down
122 changes: 0 additions & 122 deletions src/components/statusindicator.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions src/components/statusindicator.hpp

This file was deleted.

0 comments on commit 3d2f5ab

Please sign in to comment.