public/private filter in threads window

This commit is contained in:
ouwou 2021-08-22 01:21:06 -04:00
parent 962cda957d
commit 69e03bbfb7
2 changed files with 67 additions and 6 deletions

View File

@ -4,8 +4,10 @@
ThreadsWindow::ThreadsWindow(const ChannelData &channel)
: m_channel_id(channel.ID)
, m_box(Gtk::ORIENTATION_VERTICAL)
, m_active(channel)
, m_archived(channel) {
, m_active(channel, sigc::mem_fun(*this, &ThreadsWindow::ListFilterFunc))
, m_archived(channel, sigc::mem_fun(*this, &ThreadsWindow::ListFilterFunc))
, m_filter_public(m_group, "Public")
, m_filter_private(m_group, "Private") {
set_name("threads-window");
set_default_size(450, 375);
set_title("#" + *channel.Name + " - Threads");
@ -27,27 +29,58 @@ ThreadsWindow::ThreadsWindow(const ChannelData &channel)
m_stack.add(m_active, "active", "Active Threads");
m_stack.add(m_archived, "archived", "Archived Threads");
m_filter_buttons.set_homogeneous(true);
m_filter_buttons.set_halign(Gtk::ALIGN_CENTER);
m_filter_buttons.add(m_filter_public);
m_filter_buttons.add(m_filter_private);
// a little strange
const auto btncb = [this](Gtk::RadioButton *btn) {
if (btn->get_active()) {
if (btn == &m_filter_public)
m_filter_mode = FILTER_PUBLIC;
else if (btn == &m_filter_private)
m_filter_mode = FILTER_PRIVATE;
m_active.InvalidateFilter();
m_archived.InvalidateFilter();
}
};
m_filter_public.signal_toggled().connect(sigc::bind(btncb, &m_filter_public));
m_filter_private.signal_toggled().connect(sigc::bind(btncb, &m_filter_private));
m_active.show();
m_archived.show();
m_switcher.show();
m_filter_buttons.show_all();
m_stack.show();
m_box.show();
m_box.add(m_switcher);
m_box.add(m_filter_buttons);
m_box.add(m_stack);
add(m_box);
}
bool ThreadsWindow::ListFilterFunc(Gtk::ListBoxRow *row_) {
if (auto *row = dynamic_cast<ThreadListRow *>(row_))
return (m_filter_mode == FILTER_PUBLIC && (row->Type == ChannelType::GUILD_PUBLIC_THREAD || row->Type == ChannelType::GUILD_NEWS_THREAD)) ||
(m_filter_mode == FILTER_PRIVATE && row->Type == ChannelType::GUILD_PRIVATE_THREAD);
return false;
}
ThreadListRow::ThreadListRow(const ChannelData &channel)
: ID(channel.ID)
, Type(channel.Type)
, m_label(*channel.Name, Gtk::ALIGN_START) {
m_label.show();
add(m_label);
}
ActiveThreadsList::ActiveThreadsList(const ChannelData &channel) {
ActiveThreadsList::ActiveThreadsList(const ChannelData &channel, const Gtk::ListBox::SlotFilter &filter) {
set_vexpand(true);
m_list.set_filter_func(filter);
m_list.set_selection_mode(Gtk::SELECTION_SINGLE);
m_list.set_hexpand(true);
m_list.show();
@ -70,13 +103,18 @@ ActiveThreadsList::ActiveThreadsList(const ChannelData &channel) {
}
}
void ActiveThreadsList::InvalidateFilter() {
m_list.invalidate_filter();
}
ActiveThreadsList::type_signal_thread_open ActiveThreadsList::signal_thread_open() {
return m_signal_thread_open;
}
ArchivedThreadsList::ArchivedThreadsList(const ChannelData &channel) {
ArchivedThreadsList::ArchivedThreadsList(const ChannelData &channel, const Gtk::ListBox::SlotFilter &filter) {
set_vexpand(true);
m_list.set_filter_func(filter);
m_list.set_selection_mode(Gtk::SELECTION_SINGLE);
m_list.set_hexpand(true);
m_list.show();
@ -94,6 +132,10 @@ ArchivedThreadsList::ArchivedThreadsList(const ChannelData &channel) {
Abaddon::Get().GetDiscordClient().GetArchivedPublicThreads(channel.ID, sigc::mem_fun(*this, &ArchivedThreadsList::OnPublicFetched));
}
void ArchivedThreadsList::InvalidateFilter() {
m_list.invalidate_filter();
}
void ArchivedThreadsList::OnPublicFetched(DiscordError code, const ArchivedThreadsResponseData &data) {
for (const auto &thread : data.Threads) {
auto row = Gtk::manage(new ThreadListRow(thread));

View File

@ -4,7 +4,9 @@
class ActiveThreadsList : public Gtk::ScrolledWindow {
public:
ActiveThreadsList(const ChannelData &channel);
ActiveThreadsList(const ChannelData &channel, const Gtk::ListBox::SlotFilter &filter);
void InvalidateFilter();
private:
Gtk::ListBox m_list;
@ -18,7 +20,9 @@ public:
class ArchivedThreadsList : public Gtk::ScrolledWindow {
public:
ArchivedThreadsList(const ChannelData &channel);
ArchivedThreadsList(const ChannelData &channel, const Gtk::ListBox::SlotFilter &filter);
void InvalidateFilter();
private:
Gtk::ListBox m_list;
@ -38,11 +42,25 @@ public:
ThreadsWindow(const ChannelData &channel);
private:
// this filtering is rather cringe but idk what a better alternative would be
bool ListFilterFunc(Gtk::ListBoxRow *row_);
enum FilterMode {
FILTER_PUBLIC = 0,
FILTER_PRIVATE = 1,
};
bool m_filter_mode = FILTER_PUBLIC;
Snowflake m_channel_id;
Gtk::StackSwitcher m_switcher;
Gtk::Stack m_stack;
Gtk::RadioButtonGroup m_group;
Gtk::ButtonBox m_filter_buttons;
Gtk::RadioButton m_filter_public;
Gtk::RadioButton m_filter_private;
Gtk::Box m_box;
ActiveThreadsList m_active;
@ -54,6 +72,7 @@ public:
ThreadListRow(const ChannelData &channel);
Snowflake ID;
ChannelType Type;
private:
Gtk::Label m_label;