2020-08-26 05:46:43 +00:00
|
|
|
#pragma once
|
|
|
|
#include <gtkmm.h>
|
2020-09-06 03:04:11 +00:00
|
|
|
#include <string>
|
2020-09-07 06:45:46 +00:00
|
|
|
#include <sigc++/sigc++.h>
|
2020-08-26 05:46:43 +00:00
|
|
|
#include "../discord/discord.hpp"
|
|
|
|
|
2020-08-27 22:50:47 +00:00
|
|
|
enum class ChatDisplayType {
|
|
|
|
Unknown,
|
|
|
|
Text,
|
2020-09-03 05:54:40 +00:00
|
|
|
Embed,
|
2020-09-10 03:59:40 +00:00
|
|
|
Image,
|
2020-09-22 01:01:32 +00:00
|
|
|
GuildMemberJoin,
|
2020-09-22 04:07:55 +00:00
|
|
|
ChannelPinnedMessage,
|
2020-08-27 22:50:47 +00:00
|
|
|
};
|
|
|
|
|
2020-08-30 02:45:27 +00:00
|
|
|
// contains the username and timestamp, chat items get stuck into its box
|
|
|
|
class ChatMessageContainer : public Gtk::ListBoxRow {
|
|
|
|
public:
|
|
|
|
Snowflake UserID;
|
2020-09-06 03:04:11 +00:00
|
|
|
Snowflake ChannelID;
|
2020-08-30 02:45:27 +00:00
|
|
|
|
2020-09-10 03:59:40 +00:00
|
|
|
ChatMessageContainer(const Message *data);
|
2020-08-30 02:45:27 +00:00
|
|
|
void AddNewContent(Gtk::Widget *widget, bool prepend = false);
|
2020-09-20 05:12:54 +00:00
|
|
|
void AddNewContentAtIndex(Gtk::Widget *widget, int index);
|
2020-09-12 07:17:34 +00:00
|
|
|
void SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
|
2020-09-06 03:04:11 +00:00
|
|
|
void Update();
|
2020-09-20 05:12:54 +00:00
|
|
|
int RemoveItem(Gtk::Widget *widget);
|
2020-08-30 02:45:27 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Gtk::Box *m_main_box;
|
|
|
|
Gtk::Box *m_content_box;
|
|
|
|
Gtk::Box *m_meta_box;
|
|
|
|
Gtk::Label *m_author;
|
|
|
|
Gtk::Label *m_timestamp;
|
2020-09-10 22:28:42 +00:00
|
|
|
Gtk::Image *m_avatar;
|
2020-08-30 02:45:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ChatMessageItem {
|
2020-08-26 05:46:43 +00:00
|
|
|
public:
|
2020-08-30 06:00:56 +00:00
|
|
|
ChatMessageItem();
|
|
|
|
|
|
|
|
Snowflake ChannelID;
|
2020-08-26 05:46:43 +00:00
|
|
|
Snowflake ID;
|
2020-08-30 06:00:56 +00:00
|
|
|
ChatDisplayType MessageType = ChatDisplayType::Unknown;
|
2020-08-29 05:14:07 +00:00
|
|
|
|
2020-08-30 06:00:56 +00:00
|
|
|
virtual void ShowMenu(const GdkEvent *event);
|
|
|
|
void AddMenuItem(Gtk::MenuItem *item);
|
2020-09-11 03:57:36 +00:00
|
|
|
virtual void Update() = 0;
|
2020-08-30 06:00:56 +00:00
|
|
|
|
2020-09-20 05:12:54 +00:00
|
|
|
void SetContainer(ChatMessageContainer *container);
|
|
|
|
ChatMessageContainer *GetContainer() const;
|
|
|
|
|
2020-08-30 06:00:56 +00:00
|
|
|
protected:
|
2020-09-20 05:12:54 +00:00
|
|
|
ChatMessageContainer *m_container = nullptr;
|
|
|
|
|
2020-08-30 06:00:56 +00:00
|
|
|
void AttachMenuHandler(Gtk::Widget *widget);
|
|
|
|
void on_menu_copy_id();
|
|
|
|
void on_menu_message_delete();
|
2020-08-31 02:55:36 +00:00
|
|
|
void on_menu_message_edit();
|
2020-08-30 06:00:56 +00:00
|
|
|
|
|
|
|
Gtk::Menu m_menu;
|
|
|
|
Gtk::MenuItem *m_menu_copy_id;
|
|
|
|
Gtk::MenuItem *m_menu_delete_message;
|
2020-08-31 02:55:36 +00:00
|
|
|
Gtk::MenuItem *m_menu_edit_message;
|
2020-09-07 06:45:46 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef sigc::signal<void, Snowflake, Snowflake> type_signal_action_message_delete;
|
|
|
|
typedef sigc::signal<void, Snowflake, Snowflake> type_signal_action_message_edit;
|
|
|
|
|
|
|
|
type_signal_action_message_delete signal_action_message_delete();
|
|
|
|
type_signal_action_message_edit signal_action_message_edit();
|
|
|
|
|
|
|
|
private:
|
|
|
|
type_signal_action_message_delete m_signal_action_message_delete;
|
|
|
|
type_signal_action_message_edit m_signal_action_message_edit;
|
2020-08-26 05:46:43 +00:00
|
|
|
};
|
|
|
|
|
2020-08-30 02:45:27 +00:00
|
|
|
class ChatMessageTextItem
|
|
|
|
: public Gtk::TextView // oh well
|
|
|
|
, public ChatMessageItem {
|
2020-08-26 05:46:43 +00:00
|
|
|
public:
|
2020-09-10 03:59:40 +00:00
|
|
|
ChatMessageTextItem(const Message *data);
|
2020-08-31 00:24:02 +00:00
|
|
|
|
|
|
|
void EditContent(std::string content);
|
|
|
|
|
2020-09-11 03:57:36 +00:00
|
|
|
virtual void Update();
|
2020-08-30 06:00:56 +00:00
|
|
|
|
|
|
|
protected:
|
2020-08-31 00:24:02 +00:00
|
|
|
void UpdateAttributes();
|
|
|
|
|
|
|
|
std::string m_content;
|
|
|
|
|
2020-08-30 06:00:56 +00:00
|
|
|
void on_menu_copy_content();
|
|
|
|
Gtk::MenuItem *m_menu_copy_content;
|
|
|
|
Gtk::MenuItem *m_menu_delete_message;
|
2020-08-26 05:46:43 +00:00
|
|
|
};
|
2020-09-03 05:54:40 +00:00
|
|
|
|
|
|
|
class ChatMessageEmbedItem
|
|
|
|
: public Gtk::EventBox
|
|
|
|
, public ChatMessageItem {
|
|
|
|
public:
|
2020-09-10 03:59:40 +00:00
|
|
|
ChatMessageEmbedItem(const Message *data);
|
2020-09-03 05:54:40 +00:00
|
|
|
|
2020-09-11 03:57:36 +00:00
|
|
|
virtual void Update();
|
2020-09-03 05:54:40 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void DoLayout();
|
|
|
|
void UpdateAttributes();
|
|
|
|
|
|
|
|
EmbedData m_embed;
|
|
|
|
Gtk::Box *m_main;
|
|
|
|
Gtk::Label *m_attrib_label = nullptr;
|
|
|
|
};
|
2020-09-22 01:01:32 +00:00
|
|
|
|
|
|
|
class ChatMessageUserEventItem
|
|
|
|
: public Gtk::EventBox
|
|
|
|
, public ChatMessageItem {
|
|
|
|
public:
|
|
|
|
ChatMessageUserEventItem(const Message *data);
|
|
|
|
|
|
|
|
virtual void Update();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Gtk::Label *m_label;
|
|
|
|
};
|