Skip to content

Commit

Permalink
very very rudimentary classic channels list
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Oct 25, 2023
1 parent 8b034e4 commit 1821287
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 13 deletions.
50 changes: 48 additions & 2 deletions src/components/channellist/channellist.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#include "channellist.hpp"

ChannelList::ChannelList() {
ConnectSignals();

m_guilds.set_halign(Gtk::ALIGN_START);

m_guilds_scroll.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);

m_guilds.signal_guild_selected().connect([this](Snowflake guild_id) {
m_tree.SetSelectedGuild(guild_id);
});

m_guilds.show();
m_tree.show();
add(m_tree);
m_guilds_scroll.add(m_guilds);
pack_start(m_guilds_scroll, false, false); // only take the space it needs
pack_start(m_tree, true, true); // use all the remaining space
}

void ChannelList::UpdateListing() {
m_tree.UpdateListing();
m_guilds.UpdateListing();
}

void ChannelList::SetActiveChannel(Snowflake id, bool expand_to) {
Expand All @@ -18,13 +32,45 @@ void ChannelList::UseExpansionState(const ExpansionStateRoot &state) {
}

ExpansionStateRoot ChannelList::GetExpansionState() const {
m_tree.GetExpansionState();
return m_tree.GetExpansionState();
}

void ChannelList::UsePanedHack(Gtk::Paned &paned) {
m_tree.UsePanedHack(paned);
}

void ChannelList::SetClassic(bool value) {
m_tree.SetClassic(value);
m_guilds_scroll.set_visible(value);
}

void ChannelList::ConnectSignals() {
// TODO: if these all just travel upwards to the singleton then get rid of them but mayeb they dont
m_tree.signal_action_open_new_tab().connect([this](Snowflake id) {
m_signal_action_open_new_tab.emit(id);
});

m_tree.signal_action_join_voice_channel().connect([this](Snowflake id) {
m_signal_action_join_voice_channel.emit(id);
});

m_tree.signal_action_disconnect_voice().connect([this]() {
m_signal_action_disconnect_voice.emit();
});

m_tree.signal_action_channel_item_select().connect([this](Snowflake id) {
m_signal_action_channel_item_select.emit(id);
});

m_tree.signal_action_guild_leave().connect([this](Snowflake id) {
m_signal_action_guild_leave.emit(id);
});

m_tree.signal_action_guild_settings().connect([this](Snowflake id) {
m_signal_action_guild_settings.emit(id);
});
}

ChannelList::type_signal_action_open_new_tab ChannelList::signal_action_open_new_tab() {
return m_signal_action_open_new_tab;
}
Expand Down
10 changes: 9 additions & 1 deletion src/components/channellist/channellist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#include <gtkmm/box.h>
#include <gtkmm/paned.h>
#include "channellisttree.hpp"
#include "classic/guildlist.hpp"
#include "discord/snowflake.hpp"
#include "state.hpp"

// Contains the actual ChannelListTree and the classic listing if enabled
class ChannelList : public Gtk::Box {
class ChannelList : public Gtk::HBox {
// have to proxy public and signals to underlying tree... ew!!!
public:
ChannelList();
Expand All @@ -20,9 +21,16 @@ class ChannelList : public Gtk::Box {

void UsePanedHack(Gtk::Paned &paned);

void SetClassic(bool value);

private:
void ConnectSignals();

ChannelListTree m_tree;

Gtk::ScrolledWindow m_guilds_scroll;
GuildList m_guilds;

public:
using type_signal_action_channel_item_select = sigc::signal<void, Snowflake>;
using type_signal_action_guild_leave = sigc::signal<void, Snowflake>;
Expand Down
14 changes: 13 additions & 1 deletion src/components/channellist/channellisttree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ ChannelListTree::ChannelListTree()
});

m_filter_model->set_visible_func([this](const Gtk::TreeModel::const_iterator &iter) -> bool {
if (!m_classic) return true;

if ((*iter)[m_columns.m_type] == RenderType::Guild) {
return (*iter)[m_columns.m_id] == 754921263616753776ULL;
return (*iter)[m_columns.m_id] == m_classic_selected_guild;
}
return true;
});
Expand Down Expand Up @@ -301,6 +303,16 @@ void ChannelListTree::UsePanedHack(Gtk::Paned &paned) {
paned.property_position().signal_changed().connect(sigc::mem_fun(*this, &ChannelListTree::OnPanedPositionChanged));
}

void ChannelListTree::SetClassic(bool value) {
m_classic = value;
m_filter_model->refilter();
}

void ChannelListTree::SetSelectedGuild(Snowflake guild_id) {
m_classic_selected_guild = guild_id;
m_filter_model->refilter();
}

void ChannelListTree::OnPanedPositionChanged() {
m_view.queue_draw();
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/channellist/channellisttree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class ChannelListTree : public Gtk::ScrolledWindow {

void UsePanedHack(Gtk::Paned &paned);

void SetClassic(bool value);
void SetSelectedGuild(Snowflake guild_id);

protected:
void OnPanedPositionChanged();

Expand Down Expand Up @@ -186,6 +189,9 @@ class ChannelListTree : public Gtk::ScrolledWindow {

bool m_updating_listing = false;

bool m_classic = false;
Snowflake m_classic_selected_guild;

Snowflake m_active_channel;

public:
Expand Down
24 changes: 23 additions & 1 deletion src/components/channellist/classic/guildlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,40 @@ GuildList::GuildList() {
show_all_children();
}

void GuildList::UpdateListing() {
auto &discord = Abaddon::Get().GetDiscordClient();

Clear();

// does this function still even work ??lol
const auto ids = discord.GetUserSortedGuilds();
for (const auto id : ids) {
AddGuild(id);
}
}

void GuildList::AddGuild(Snowflake id) {
const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(id);
if (!guild.has_value()) return;

auto *item = Gtk::make_managed<GuildListGuildItem>(*guild);
item->signal_button_press_event().connect([this, id](GdkEventButton *event) -> bool {
if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) {
m_signal_guild_selected.emit(id);
}
return true;
});
item->show();
add(*item);
}

void GuildList::Clear() {
const auto children = get_children();
for (auto child : children) {
for (auto *child : children) {
delete child;
}
}

GuildList::type_signal_guild_selected GuildList::signal_guild_selected() {
return m_signal_guild_selected;
}
12 changes: 11 additions & 1 deletion src/components/channellist/classic/guildlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ class GuildList : public Gtk::ListBox {
public:
GuildList();

void AddGuild(Snowflake id);
void UpdateListing();

private:
void AddGuild(Snowflake id);
void Clear();

public:
using type_signal_guild_selected = sigc::signal<void, Snowflake>;

type_signal_guild_selected signal_guild_selected();

private:
type_signal_guild_selected m_signal_guild_selected;
};
7 changes: 0 additions & 7 deletions src/components/channellist/classic/guildlistguilditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ GuildListGuildItem::GuildListGuildItem(const GuildData &guild)
add(m_image);
show_all_children();

signal_button_press_event().connect([this](GdkEventButton *event) -> bool {
if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) {
printf("Click %llu\n", (uint64_t)ID);
}
return true;
});

set_tooltip_text(guild.Name);

UpdateIcon();
Expand Down
2 changes: 2 additions & 0 deletions src/windows/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ MainWindow::MainWindow()
});
#endif

// TEMP TEMP TEMP TEMP!!!!!!!!!!!! AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
m_channel_list.SetClassic(true);
m_channel_list.set_vexpand(true);
m_channel_list.set_size_request(-1, -1);
m_channel_list.show();
Expand Down

0 comments on commit 1821287

Please sign in to comment.