diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-08-11 03:32:09 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-08-11 03:32:09 -0400 |
commit | 7ffded5b1373444cf3442d759a3bd8ae0940bd7d (patch) | |
tree | 575e6cfb5c610aa5d5271083cd769728df1885e9 /windows | |
parent | e01110c7393d5071ea271f1978b3a2ece59415ad (diff) | |
download | abaddon-portaudio-7ffded5b1373444cf3442d759a3bd8ae0940bd7d.tar.gz abaddon-portaudio-7ffded5b1373444cf3442d759a3bd8ae0940bd7d.zip |
rest of view threads window
Diffstat (limited to 'windows')
-rw-r--r-- | windows/threadswindow.cpp | 107 | ||||
-rw-r--r-- | windows/threadswindow.hpp | 60 |
2 files changed, 167 insertions, 0 deletions
diff --git a/windows/threadswindow.cpp b/windows/threadswindow.cpp new file mode 100644 index 0000000..a772eeb --- /dev/null +++ b/windows/threadswindow.cpp @@ -0,0 +1,107 @@ +#include "threadswindow.hpp" +#include "../abaddon.hpp" + +ThreadsWindow::ThreadsWindow(const ChannelData &channel) + : m_channel_id(channel.ID) + , m_box(Gtk::ORIENTATION_VERTICAL) + , m_active(channel) + , m_archived(channel) { + set_name("threads-window"); + set_default_size(450, 375); + set_title("#" + *channel.Name + " - Threads"); + set_position(Gtk::WIN_POS_CENTER); + get_style_context()->add_class("app-window"); + get_style_context()->add_class("app-popup"); + get_style_context()->add_class("threads-window"); + + const auto cb = [this](Snowflake id) { + Abaddon::Get().ActionChannelOpened(id); + hide(); + }; + m_active.signal_thread_open().connect(cb); + m_archived.signal_thread_open().connect(cb); + + m_switcher.set_halign(Gtk::ALIGN_CENTER); + m_switcher.set_stack(m_stack); + + m_stack.add(m_active, "active", "Active Threads"); + m_stack.add(m_archived, "archived", "Archived Threads"); + + m_active.show(); + m_archived.show(); + m_switcher.show(); + m_stack.show(); + m_box.show(); + + m_box.add(m_switcher); + m_box.add(m_stack); + add(m_box); +} + +ThreadListRow::ThreadListRow(const ChannelData &channel) + : ID(channel.ID) + , m_label(*channel.Name, Gtk::ALIGN_START) { + m_label.show(); + add(m_label); +} + +ActiveThreadsList::ActiveThreadsList(const ChannelData &channel) { + set_vexpand(true); + + m_list.set_selection_mode(Gtk::SELECTION_SINGLE); + m_list.set_hexpand(true); + m_list.show(); + + add(m_list); + + m_list.signal_button_press_event().connect([this](GdkEventButton *ev) -> bool { + if (ev->button == GDK_BUTTON_PRIMARY && ev->type == GDK_2BUTTON_PRESS) { + if (auto row = dynamic_cast<ThreadListRow *>(m_list.get_selected_row())) + m_signal_thread_open.emit(row->ID); + } + return false; + }); + + const auto threads = Abaddon::Get().GetDiscordClient().GetActiveThreads(channel.ID); + for (const auto &thread : threads) { + auto row = Gtk::manage(new ThreadListRow(thread)); + row->show(); + m_list.add(*row); + } +} + +ActiveThreadsList::type_signal_thread_open ActiveThreadsList::signal_thread_open() { + return m_signal_thread_open; +} + +ArchivedThreadsList::ArchivedThreadsList(const ChannelData &channel) { + set_vexpand(true); + + m_list.set_selection_mode(Gtk::SELECTION_SINGLE); + m_list.set_hexpand(true); + m_list.show(); + + add(m_list); + + m_list.signal_button_press_event().connect([this](GdkEventButton *ev) -> bool { + if (ev->button == GDK_BUTTON_PRIMARY && ev->type == GDK_2BUTTON_PRESS) { + if (auto row = dynamic_cast<ThreadListRow *>(m_list.get_selected_row())) + m_signal_thread_open.emit(row->ID); + } + return false; + }); + + Abaddon::Get().GetDiscordClient().GetArchivedPublicThreads(channel.ID, sigc::mem_fun(*this, &ArchivedThreadsList::OnPublicFetched)); +} + +void ArchivedThreadsList::OnPublicFetched(DiscordError code, const ArchivedThreadsResponseData &data) { + for (const auto &thread : data.Threads) { + auto row = Gtk::manage(new ThreadListRow(thread)); + row->show(); + m_list.add(*row); + } +} + +ArchivedThreadsList::type_signal_thread_open ArchivedThreadsList::signal_thread_open() { + return m_signal_thread_open; +} diff --git a/windows/threadswindow.hpp b/windows/threadswindow.hpp new file mode 100644 index 0000000..a0c77e8 --- /dev/null +++ b/windows/threadswindow.hpp @@ -0,0 +1,60 @@ +#pragma once +#include <gtkmm.h> +#include "../discord/objects.hpp" + +class ActiveThreadsList : public Gtk::ScrolledWindow { +public: + ActiveThreadsList(const ChannelData &channel); + +private: + Gtk::ListBox m_list; + + using type_signal_thread_open = sigc::signal<void, Snowflake>; + type_signal_thread_open m_signal_thread_open; + +public: + type_signal_thread_open signal_thread_open(); +}; + +class ArchivedThreadsList : public Gtk::ScrolledWindow { +public: + ArchivedThreadsList(const ChannelData &channel); + +private: + Gtk::ListBox m_list; + + void OnPublicFetched(DiscordError code, const ArchivedThreadsResponseData &data); + + using type_signal_thread_open = sigc::signal<void, Snowflake>; + type_signal_thread_open m_signal_thread_open; + +public: + type_signal_thread_open signal_thread_open(); +}; + +// view all threads in a channel +class ThreadsWindow : public Gtk::Window { +public: + ThreadsWindow(const ChannelData &channel); + +private: + Snowflake m_channel_id; + + Gtk::StackSwitcher m_switcher; + Gtk::Stack m_stack; + + Gtk::Box m_box; + + ActiveThreadsList m_active; + ArchivedThreadsList m_archived; +}; + +class ThreadListRow : public Gtk::ListBoxRow { +public: + ThreadListRow(const ChannelData &channel); + + Snowflake ID; + +private: + Gtk::Label m_label; +}; |