mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
public/private filter in threads window
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user