summaryrefslogtreecommitdiff
path: root/components/channels.hpp
blob: fce1ce98f02d5e8999122d2dd938b5b726e04f53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <gtkmm.h>
#include <string>
#include <queue>
#include <mutex>
#include <unordered_set>
#include "../discord/discord.hpp"

class Abaddon;
class ChannelList {
public:
    ChannelList();
    Gtk::Widget *GetRoot() const;
    void SetListingFromGuilds(const DiscordClient::Guilds_t &guilds);
    void ClearListing();

    void SetAbaddon(Abaddon *ptr);

protected:
    Gtk::ListBox *m_list;
    Gtk::ScrolledWindow *m_main;

    struct ListItemInfo {
        enum ListItemType {
            Guild,
            Category,
            Channel,
        };
        int GuildIndex;
        Snowflake ID;
        std::unordered_set<Gtk::ListBoxRow *> Children;
        bool IsUserCollapsed;
        bool IsHidden;
        ListItemType Type;
        // for categories
        Gtk::Arrow *CatArrow = nullptr;
    };
    std::unordered_map<Gtk::ListBoxRow *, ListItemInfo> m_infos;

    void on_row_activated(Gtk::ListBoxRow *row);

    int m_guild_count;
    Gtk::Menu m_guild_menu;
    Gtk::MenuItem *m_guild_menu_up;
    Gtk::MenuItem *m_guild_menu_down;
    Gtk::MenuItem *m_guild_menu_copyid;
    void on_menu_move_up();
    void on_menu_move_down();
    void on_menu_copyid();

    Glib::Dispatcher m_update_dispatcher;
    mutable std::mutex m_update_mutex;
    std::queue<DiscordClient::Guilds_t> m_update_queue;
    void SetListingFromGuildsInternal();
    void AttachMenuHandler(Gtk::ListBoxRow* row);

    Abaddon *m_abaddon = nullptr;
};