summaryrefslogtreecommitdiff
path: root/components/channels.hpp
blob: ad0879bc6ab03edfc013534b19ba9a035db8f7ec (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
#pragma once
#include <gtkmm.h>
#include <string>
#include <queue>
#include <mutex>
#include <unordered_set>
#include "../discord/discord.hpp"

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

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_type> m_update_queue;
    void AddPrivateChannels(); // retard moment
    void SetListingFromGuildsInternal();
    void AttachMenuHandler(Gtk::ListBoxRow *row);
};