diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/message.c | 88 | ||||
-rw-r--r-- | src/ui/message.h | 27 |
2 files changed, 115 insertions, 0 deletions
diff --git a/src/ui/message.c b/src/ui/message.c index 4d7ec8f..a6ce818 100644 --- a/src/ui/message.c +++ b/src/ui/message.c | |||
@@ -375,6 +375,10 @@ ui_message_new(MESSENGER_Application *app, | |||
375 | gtk_builder_get_object(handle->builder[0], "content_box") | 375 | gtk_builder_get_object(handle->builder[0], "content_box") |
376 | ); | 376 | ); |
377 | 377 | ||
378 | handle->tag_flow_box = GTK_FLOW_BOX( | ||
379 | gtk_builder_get_object(handle->builder[0], "tag_flow_box") | ||
380 | ); | ||
381 | |||
378 | handle->builder[1] = gtk_builder_new_from_resource( | 382 | handle->builder[1] = gtk_builder_new_from_resource( |
379 | application_get_resource_path(app, "ui/message_content.ui") | 383 | application_get_resource_path(app, "ui/message_content.ui") |
380 | ); | 384 | ); |
@@ -780,6 +784,90 @@ ui_message_set_contact(UI_MESSAGE_Handle *handle, | |||
780 | } | 784 | } |
781 | 785 | ||
782 | void | 786 | void |
787 | ui_message_add_tag(UI_MESSAGE_Handle *handle, | ||
788 | MESSENGER_Application *app, | ||
789 | const struct GNUNET_CHAT_Message *tag_message) | ||
790 | { | ||
791 | g_assert((handle) && (app) && (tag_message)); | ||
792 | |||
793 | if ((GNUNET_CHAT_KIND_TAG != GNUNET_CHAT_message_get_kind(tag_message)) || | ||
794 | (GNUNET_CHAT_message_get_target(tag_message) != handle->msg)) | ||
795 | return; | ||
796 | |||
797 | const char *tag_value = GNUNET_CHAT_message_get_text(tag_message); | ||
798 | |||
799 | if ((!tag_value) || (!tag_value[0])) | ||
800 | return; | ||
801 | |||
802 | GtkLabel *tag_label = GTK_LABEL(gtk_label_new(NULL)); | ||
803 | |||
804 | if (!tag_label) | ||
805 | return; | ||
806 | |||
807 | ui_label_set_text(tag_label, tag_value); | ||
808 | gtk_label_set_ellipsize(tag_label, PANGO_ELLIPSIZE_END); | ||
809 | |||
810 | g_object_set_qdata(G_OBJECT(tag_label), app->quarks.data, (gpointer) tag_message); | ||
811 | |||
812 | gtk_container_add(GTK_CONTAINER(handle->tag_flow_box), GTK_WIDGET(tag_label)); | ||
813 | gtk_widget_show_all(GTK_WIDGET(tag_label)); | ||
814 | } | ||
815 | |||
816 | void | ||
817 | ui_message_remove_tag(UI_MESSAGE_Handle *handle, | ||
818 | MESSENGER_Application *app, | ||
819 | const struct GNUNET_CHAT_Message *tag_message) | ||
820 | { | ||
821 | g_assert((handle) && (app) && (tag_message)); | ||
822 | |||
823 | if ((GNUNET_CHAT_KIND_TAG != GNUNET_CHAT_message_get_kind(tag_message)) || | ||
824 | (GNUNET_CHAT_message_get_target(tag_message) != handle->msg)) | ||
825 | return; | ||
826 | |||
827 | GList *children = gtk_container_get_children(GTK_CONTAINER(handle->tag_flow_box)); | ||
828 | |||
829 | if (!children) | ||
830 | return; | ||
831 | |||
832 | GtkWidget *removable = NULL; | ||
833 | |||
834 | GList *list = children; | ||
835 | while (list) | ||
836 | { | ||
837 | GtkFlowBoxChild *child = GTK_FLOW_BOX_CHILD(list->data); | ||
838 | GList *items = gtk_container_get_children(GTK_CONTAINER(child)); | ||
839 | |||
840 | if (items) | ||
841 | { | ||
842 | GtkLabel *tag_label = GTK_LABEL(items->data); | ||
843 | |||
844 | const struct GNUNET_CHAT_Message *msg = g_object_get_qdata( | ||
845 | G_OBJECT(tag_label), | ||
846 | app->quarks.data | ||
847 | ); | ||
848 | |||
849 | if (tag_message == msg) | ||
850 | removable = GTK_WIDGET(child); | ||
851 | |||
852 | g_list_free(items); | ||
853 | } | ||
854 | |||
855 | list = list->next; | ||
856 | |||
857 | if (removable) | ||
858 | break; | ||
859 | } | ||
860 | |||
861 | g_list_free(children); | ||
862 | |||
863 | if (!removable) | ||
864 | return; | ||
865 | |||
866 | gtk_container_remove(GTK_CONTAINER(handle->tag_flow_box), removable); | ||
867 | gtk_widget_destroy(removable); | ||
868 | } | ||
869 | |||
870 | void | ||
783 | ui_message_delete(UI_MESSAGE_Handle *handle) | 871 | ui_message_delete(UI_MESSAGE_Handle *handle) |
784 | { | 872 | { |
785 | g_assert(handle); | 873 | g_assert(handle); |
diff --git a/src/ui/message.h b/src/ui/message.h index 60ee203..47aa847 100644 --- a/src/ui/message.h +++ b/src/ui/message.h | |||
@@ -51,6 +51,7 @@ typedef struct UI_MESSAGE_Handle | |||
51 | 51 | ||
52 | GtkBuilder *builder [2]; | 52 | GtkBuilder *builder [2]; |
53 | GtkWidget *message_box; | 53 | GtkWidget *message_box; |
54 | GtkFlowBox *tag_flow_box; | ||
54 | 55 | ||
55 | HdyAvatar *sender_avatar; | 56 | HdyAvatar *sender_avatar; |
56 | GtkLabel *sender_label; | 57 | GtkLabel *sender_label; |
@@ -138,6 +139,32 @@ ui_message_set_contact(UI_MESSAGE_Handle *handle, | |||
138 | const struct GNUNET_CHAT_Contact *contact); | 139 | const struct GNUNET_CHAT_Contact *contact); |
139 | 140 | ||
140 | /** | 141 | /** |
142 | * Adds a widget to represent a given tag message | ||
143 | * to another message handle. | ||
144 | * | ||
145 | * @param handle Message handle | ||
146 | * @param app Messenger application | ||
147 | * @param tag_message Chat tag message | ||
148 | */ | ||
149 | void | ||
150 | ui_message_add_tag(UI_MESSAGE_Handle *handle, | ||
151 | MESSENGER_Application *app, | ||
152 | const struct GNUNET_CHAT_Message *tag_message); | ||
153 | |||
154 | /** | ||
155 | * Remove a widget representing a given tag message | ||
156 | * from another message handle. | ||
157 | * | ||
158 | * @param handle Message handle | ||
159 | * @param app Messenger application | ||
160 | * @param tag_message Chat tag message | ||
161 | */ | ||
162 | void | ||
163 | ui_message_remove_tag(UI_MESSAGE_Handle *handle, | ||
164 | MESSENGER_Application *app, | ||
165 | const struct GNUNET_CHAT_Message *tag_message); | ||
166 | |||
167 | /** | ||
141 | * Frees its resources and destroys a given | 168 | * Frees its resources and destroys a given |
142 | * message handle. | 169 | * message handle. |
143 | * | 170 | * |