aboutsummaryrefslogtreecommitdiff
path: root/src/ui/contacts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/contacts.c')
-rw-r--r--src/ui/contacts.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
index 34ceaed..21a7932 100644
--- a/src/ui/contacts.c
+++ b/src/ui/contacts.c
@@ -24,6 +24,7 @@
24 24
25#include "contacts.h" 25#include "contacts.h"
26 26
27#include "chat_entry.h"
27#include "contact_entry.h" 28#include "contact_entry.h"
28#include "../application.h" 29#include "../application.h"
29 30
@@ -38,6 +39,73 @@ handle_close_button_click(UNUSED GtkButton *button,
38} 39}
39 40
40static void 41static void
42handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox,
43 GtkListBoxRow* row,
44 gpointer user_data)
45{
46 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
47
48 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) (
49 g_hash_table_lookup(app->ui.bindings, row)
50 );
51
52 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)))
53 goto close_dialog;
54
55 struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context(
56 contact
57 );
58
59 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
60
61 char context_id [9];
62 g_snprintf(context_id, sizeof(context_id), "%08lx", (gulong) context);
63
64 if (gtk_stack_get_child_by_name(ui->chats_stack, context_id))
65 goto close_dialog;
66
67 const char *title = GNUNET_CHAT_contact_get_name(contact);
68
69 UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app);
70 gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box);
71 GNUNET_CHAT_context_set_user_pointer(context, entry);
72
73 if (title)
74 {
75 gtk_label_set_text(entry->title_label, title);
76 hdy_avatar_set_text(entry->entry_avatar, title);
77
78 gtk_label_set_text(entry->chat->chat_title, title);
79 }
80
81 gtk_widget_set_name(entry->entry_box, context_id);
82
83 gtk_stack_add_named(
84 ui->chats_stack,
85 entry->chat->chat_box,
86 context_id
87 );
88
89 g_hash_table_insert(
90 app->ui.bindings,
91 entry->chat->send_text_view,
92 context
93 );
94
95 ui->chat_entries = g_list_append(ui->chat_entries, entry);
96
97 GtkListBoxRow *entry_row = GTK_LIST_BOX_ROW(
98 gtk_widget_get_parent(entry->entry_box)
99 );
100
101 gtk_list_box_select_row(ui->chats_listbox, entry_row);
102 gtk_widget_activate(GTK_WIDGET(entry_row));
103
104close_dialog:
105 gtk_window_close(GTK_WINDOW(app->ui.contacts.dialog));
106}
107
108static void
41handle_dialog_destroy(UNUSED GtkWidget *window, 109handle_dialog_destroy(UNUSED GtkWidget *window,
42 gpointer user_data) 110 gpointer user_data)
43{ 111{
@@ -90,6 +158,12 @@ _iterate_contacts(void *cls,
90 GNUNET_free(key_string); 158 GNUNET_free(key_string);
91 } 159 }
92 160
161 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
162 gtk_widget_get_parent(entry->entry_box)
163 );
164
165 g_hash_table_insert(app->ui.bindings, row, contact);
166
93 app->ui.contacts.contact_entries = g_list_append( 167 app->ui.contacts.contact_entries = g_list_append(
94 app->ui.contacts.contact_entries, 168 app->ui.contacts.contact_entries,
95 entry 169 entry
@@ -128,6 +202,13 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
128 gtk_builder_get_object(handle->builder, "contacts_listbox") 202 gtk_builder_get_object(handle->builder, "contacts_listbox")
129 ); 203 );
130 204
205 g_signal_connect(
206 handle->contacts_listbox,
207 "row-activated",
208 G_CALLBACK(handle_contacts_listbox_row_activated),
209 app
210 );
211
131 handle->close_button = GTK_BUTTON( 212 handle->close_button = GTK_BUTTON(
132 gtk_builder_get_object(handle->builder, "close_button") 213 gtk_builder_get_object(handle->builder, "close_button")
133 ); 214 );