diff options
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/src/event.c b/src/event.c index 5ad3016..d11b8cf 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -74,7 +74,8 @@ _clear_each_widget(GtkWidget *widget, | |||
74 | 74 | ||
75 | void | 75 | void |
76 | event_update_profile(MESSENGER_Application *app, | 76 | event_update_profile(MESSENGER_Application *app, |
77 | UNUSED void *cls) | 77 | UNUSED int argc, |
78 | UNUSED void **argv) | ||
78 | { | 79 | { |
79 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 80 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); |
80 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); | 81 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); |
@@ -105,9 +106,13 @@ event_update_profile(MESSENGER_Application *app, | |||
105 | 106 | ||
106 | void | 107 | void |
107 | event_update_chats(MESSENGER_Application *app, | 108 | event_update_chats(MESSENGER_Application *app, |
108 | void *cls) | 109 | int argc, |
110 | void **argv) | ||
109 | { | 111 | { |
110 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) cls; | 112 | if (argc < 1) |
113 | return; | ||
114 | |||
115 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | ||
111 | 116 | ||
112 | if (GNUNET_CHAT_context_get_user_pointer(context)) | 117 | if (GNUNET_CHAT_context_get_user_pointer(context)) |
113 | return; | 118 | return; |
@@ -120,4 +125,69 @@ event_update_chats(MESSENGER_Application *app, | |||
120 | 125 | ||
121 | // TODO: put something better here to attach it! | 126 | // TODO: put something better here to attach it! |
122 | GNUNET_CHAT_context_set_user_pointer(context, ui); | 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 | } | ||
141 | |||
142 | void | ||
143 | event_receive_message(MESSENGER_Application *app, | ||
144 | int argc, | ||
145 | void **argv) | ||
146 | { | ||
147 | if (argc < 2) | ||
148 | return; | ||
149 | |||
150 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | ||
151 | |||
152 | if (!GNUNET_CHAT_context_get_user_pointer(context)) | ||
153 | return; | ||
154 | |||
155 | const struct GNUNET_CHAT_Message *msg; | ||
156 | msg = *((const struct GNUNET_CHAT_Message**) argv[1]); | ||
157 | |||
158 | const int sent = GNUNET_CHAT_message_is_sent(msg); | ||
159 | |||
160 | UI_MESSAGE_Handle *message = ui_message_new(app, GNUNET_YES == sent); | ||
161 | |||
162 | if (GNUNET_YES != sent) | ||
163 | { | ||
164 | const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( | ||
165 | msg | ||
166 | ); | ||
167 | |||
168 | const char *sender = GNUNET_CHAT_contact_get_name(contact); | ||
169 | |||
170 | hdy_avatar_set_text(message->sender_avatar, sender? sender : ""); | ||
171 | gtk_label_set_text(message->sender_label, sender? sender : ""); | ||
172 | } | ||
173 | |||
174 | struct GNUNET_TIME_Absolute timestamp = GNUNET_CHAT_message_get_timestamp( | ||
175 | msg | ||
176 | ); | ||
177 | |||
178 | const char *text = GNUNET_CHAT_message_get_text(msg); | ||
179 | const char *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); | ||
180 | |||
181 | gtk_label_set_text(message->text_label, text? text : ""); | ||
182 | gtk_label_set_text(message->timestamp_label, time? time : ""); | ||
183 | |||
184 | if (message->read_receipt_image) | ||
185 | // TODO: check read receipt | ||
186 | |||
187 | gtk_container_add( | ||
188 | GTK_CONTAINER(app->ui.messenger.messages_listbox), | ||
189 | message->message_box | ||
190 | ); | ||
191 | |||
192 | g_free(message); // TODO: this is just a test! | ||
123 | } | 193 | } |