diff options
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 86 |
1 files changed, 40 insertions, 46 deletions
diff --git a/src/event.c b/src/event.c index d11b8cf..6683e63 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -27,21 +27,43 @@ | |||
27 | #include "ui/chat_entry.h" | 27 | #include "ui/chat_entry.h" |
28 | #include "ui/message.h" | 28 | #include "ui/message.h" |
29 | 29 | ||
30 | static int | 30 | static void |
31 | _iterate_profile_contacts(void *cls, | 31 | _add_new_chat_entry(MESSENGER_Application *app, |
32 | UNUSED struct GNUNET_CHAT_Handle *handle, | 32 | struct GNUNET_CHAT_Context *context) |
33 | UNUSED struct GNUNET_CHAT_Contact *contact) | ||
34 | { | 33 | { |
35 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | ||
36 | |||
37 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 34 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); |
38 | 35 | ||
39 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(); | 36 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); |
40 | |||
41 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); | 37 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); |
38 | GNUNET_CHAT_context_set_user_pointer(context, entry); | ||
39 | |||
40 | char context_id [9]; | ||
41 | g_snprintf(context_id, sizeof(context_id), "%08lx", (gulong) context); | ||
42 | |||
43 | gtk_widget_set_name(entry->entry_box, context_id); | ||
42 | 44 | ||
43 | g_free(entry); //TODO: add to a list or similar? | 45 | gtk_stack_add_named( |
46 | ui->chats_stack, | ||
47 | entry->chat->chat_box, | ||
48 | context_id | ||
49 | ); | ||
44 | 50 | ||
51 | g_hash_table_insert( | ||
52 | app->ui.bindings, | ||
53 | entry->chat->send_text_view, | ||
54 | context | ||
55 | ); | ||
56 | |||
57 | ui->chat_entries = g_list_append(ui->chat_entries, entry); | ||
58 | } | ||
59 | |||
60 | static int | ||
61 | _iterate_profile_contacts(void *cls, | ||
62 | UNUSED struct GNUNET_CHAT_Handle *handle, | ||
63 | UNUSED struct GNUNET_CHAT_Contact *contact) | ||
64 | { | ||
65 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | ||
66 | _add_new_chat_entry(app, GNUNET_CHAT_contact_get_context(contact)); | ||
45 | return GNUNET_YES; | 67 | return GNUNET_YES; |
46 | } | 68 | } |
47 | 69 | ||
@@ -51,15 +73,7 @@ _iterate_profile_groups(void *cls, | |||
51 | UNUSED struct GNUNET_CHAT_Group *group) | 73 | UNUSED struct GNUNET_CHAT_Group *group) |
52 | { | 74 | { |
53 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | 75 | MESSENGER_Application *app = (MESSENGER_Application*) cls; |
54 | 76 | _add_new_chat_entry(app, GNUNET_CHAT_group_get_context(group)); | |
55 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | ||
56 | |||
57 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(); | ||
58 | |||
59 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); | ||
60 | |||
61 | g_free(entry); //TODO: add to a list or similar? | ||
62 | |||
63 | return GNUNET_YES; | 77 | return GNUNET_YES; |
64 | } | 78 | } |
65 | 79 | ||
@@ -96,12 +110,6 @@ event_update_profile(MESSENGER_Application *app, | |||
96 | 110 | ||
97 | GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); | 111 | GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); |
98 | GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); | 112 | GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); |
99 | |||
100 | for (int i = 0; i < 8; i++) { | ||
101 | UI_MESSAGE_Handle *message = ui_message_new(app, i % 2 == 0); | ||
102 | gtk_container_add(GTK_CONTAINER(ui->messages_listbox), message->message_box); | ||
103 | g_free(message); // TODO: this is just a test! | ||
104 | } | ||
105 | } | 113 | } |
106 | 114 | ||
107 | void | 115 | void |
@@ -117,26 +125,7 @@ event_update_chats(MESSENGER_Application *app, | |||
117 | if (GNUNET_CHAT_context_get_user_pointer(context)) | 125 | if (GNUNET_CHAT_context_get_user_pointer(context)) |
118 | return; | 126 | return; |
119 | 127 | ||
120 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 128 | _add_new_chat_entry(app, context); |
121 | |||
122 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(); | ||
123 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); | ||
124 | g_free(entry); // TODO: free already? | ||
125 | |||
126 | // TODO: put something better here to attach it! | ||
127 | GNUNET_CHAT_context_set_user_pointer(context, ui); | ||
128 | |||
129 | g_hash_table_insert( | ||
130 | app->ui.bindings, | ||
131 | app->ui.messenger.send_record_button, | ||
132 | context | ||
133 | ); | ||
134 | |||
135 | g_hash_table_insert( | ||
136 | app->ui.bindings, | ||
137 | app->ui.messenger.send_text_view, | ||
138 | context | ||
139 | ); | ||
140 | } | 129 | } |
141 | 130 | ||
142 | void | 131 | void |
@@ -149,7 +138,9 @@ event_receive_message(MESSENGER_Application *app, | |||
149 | 138 | ||
150 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | 139 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; |
151 | 140 | ||
152 | if (!GNUNET_CHAT_context_get_user_pointer(context)) | 141 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); |
142 | |||
143 | if (!handle) | ||
153 | return; | 144 | return; |
154 | 145 | ||
155 | const struct GNUNET_CHAT_Message *msg; | 146 | const struct GNUNET_CHAT_Message *msg; |
@@ -185,9 +176,12 @@ event_receive_message(MESSENGER_Application *app, | |||
185 | // TODO: check read receipt | 176 | // TODO: check read receipt |
186 | 177 | ||
187 | gtk_container_add( | 178 | gtk_container_add( |
188 | GTK_CONTAINER(app->ui.messenger.messages_listbox), | 179 | GTK_CONTAINER(handle->chat->messages_listbox), |
189 | message->message_box | 180 | message->message_box |
190 | ); | 181 | ); |
191 | 182 | ||
192 | g_free(message); // TODO: this is just a test! | 183 | g_free(message); // TODO: this is just a test! |
184 | |||
185 | gtk_label_set_text(handle->text_label, text? text : ""); | ||
186 | gtk_label_set_text(handle->timestamp_label, time? time : ""); | ||
193 | } | 187 | } |