diff options
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 112 |
1 files changed, 84 insertions, 28 deletions
diff --git a/src/event.c b/src/event.c index 16b709e..dfc7b8e 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -117,9 +117,7 @@ _clear_each_widget(GtkWidget *widget, | |||
117 | } | 117 | } |
118 | 118 | ||
119 | void | 119 | void |
120 | event_update_profile(MESSENGER_Application *app, | 120 | event_update_profile(MESSENGER_Application *app) |
121 | UNUSED int argc, | ||
122 | UNUSED void **argv) | ||
123 | { | 121 | { |
124 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 122 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); |
125 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); | 123 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); |
@@ -164,14 +162,9 @@ event_update_profile(MESSENGER_Application *app, | |||
164 | 162 | ||
165 | void | 163 | void |
166 | event_update_chats(MESSENGER_Application *app, | 164 | event_update_chats(MESSENGER_Application *app, |
167 | int argc, | 165 | struct GNUNET_CHAT_Context *context, |
168 | void **argv) | 166 | UNUSED const struct GNUNET_CHAT_Message *msg) |
169 | { | 167 | { |
170 | if (argc < 1) | ||
171 | return; | ||
172 | |||
173 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | ||
174 | |||
175 | if (GNUNET_CHAT_context_get_user_pointer(context)) | 168 | if (GNUNET_CHAT_context_get_user_pointer(context)) |
176 | return; | 169 | return; |
177 | 170 | ||
@@ -180,46 +173,109 @@ event_update_chats(MESSENGER_Application *app, | |||
180 | 173 | ||
181 | void | 174 | void |
182 | event_joining_contact(MESSENGER_Application *app, | 175 | event_joining_contact(MESSENGER_Application *app, |
183 | int argc, | 176 | struct GNUNET_CHAT_Context *context, |
184 | void **argv) | 177 | const struct GNUNET_CHAT_Message *msg) |
185 | { | 178 | { |
186 | if (argc < 2) | 179 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); |
180 | |||
181 | if (!handle) | ||
187 | return; | 182 | return; |
188 | 183 | ||
189 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | 184 | UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); |
185 | |||
186 | const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( | ||
187 | msg | ||
188 | ); | ||
189 | |||
190 | const char *sender = GNUNET_CHAT_contact_get_name(contact); | ||
191 | |||
192 | hdy_avatar_set_text(message->sender_avatar, sender? sender : ""); | ||
193 | gtk_label_set_text(message->sender_label, sender? sender : ""); | ||
194 | |||
195 | gtk_label_set_text(message->text_label, "joined the chat"); | ||
196 | |||
197 | gtk_container_add( | ||
198 | GTK_CONTAINER(handle->chat->messages_listbox), | ||
199 | message->message_box | ||
200 | ); | ||
201 | |||
202 | ui_message_delete(message); | ||
203 | } | ||
204 | |||
205 | static void | ||
206 | _event_invitation_accept_click(UNUSED GtkButton *button, | ||
207 | gpointer user_data) | ||
208 | { | ||
209 | struct GNUNET_CHAT_Invitation *invitation = ( | ||
210 | (struct GNUNET_CHAT_Invitation*) user_data | ||
211 | ); | ||
212 | |||
213 | GNUNET_CHAT_invitation_accept(invitation); | ||
214 | } | ||
190 | 215 | ||
216 | void | ||
217 | event_invitation(MESSENGER_Application *app, | ||
218 | struct GNUNET_CHAT_Context *context, | ||
219 | const struct GNUNET_CHAT_Message *msg) | ||
220 | { | ||
191 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); | 221 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); |
192 | 222 | ||
193 | if (!handle) | 223 | if (!handle) |
194 | return; | 224 | return; |
195 | 225 | ||
196 | const struct GNUNET_CHAT_Message *msg; | 226 | struct GNUNET_CHAT_Invitation *invitation; |
197 | msg = *((const struct GNUNET_CHAT_Message**) argv[1]); | 227 | invitation = GNUNET_CHAT_message_get_invitation(msg); |
228 | |||
229 | if (!invitation) | ||
230 | return; | ||
231 | |||
232 | UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); | ||
233 | |||
234 | const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( | ||
235 | msg | ||
236 | ); | ||
237 | |||
238 | const char *sender = GNUNET_CHAT_contact_get_name(contact); | ||
239 | |||
240 | hdy_avatar_set_text(message->sender_avatar, sender? sender : ""); | ||
241 | gtk_label_set_text(message->sender_label, sender? sender : ""); | ||
242 | |||
243 | gtk_label_set_text(message->text_label, "invited you to a chat"); | ||
244 | |||
245 | g_signal_connect( | ||
246 | message->accept_button, | ||
247 | "clicked", | ||
248 | G_CALLBACK(_event_invitation_accept_click), | ||
249 | invitation | ||
250 | ); | ||
251 | |||
252 | gtk_widget_show(GTK_WIDGET(message->deny_button)); | ||
253 | gtk_widget_show(GTK_WIDGET(message->accept_button)); | ||
254 | |||
255 | gtk_container_add( | ||
256 | GTK_CONTAINER(handle->chat->messages_listbox), | ||
257 | message->message_box | ||
258 | ); | ||
198 | 259 | ||
199 | // | 260 | ui_message_delete(message); |
200 | } | 261 | } |
201 | 262 | ||
202 | void | 263 | void |
203 | event_receive_message(MESSENGER_Application *app, | 264 | event_receive_message(MESSENGER_Application *app, |
204 | int argc, | 265 | struct GNUNET_CHAT_Context *context, |
205 | void **argv) | 266 | const struct GNUNET_CHAT_Message *msg) |
206 | { | 267 | { |
207 | if (argc < 2) | ||
208 | return; | ||
209 | |||
210 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | ||
211 | |||
212 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); | 268 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); |
213 | 269 | ||
214 | if (!handle) | 270 | if (!handle) |
215 | return; | 271 | return; |
216 | 272 | ||
217 | const struct GNUNET_CHAT_Message *msg; | ||
218 | msg = *((const struct GNUNET_CHAT_Message**) argv[1]); | ||
219 | |||
220 | const int sent = GNUNET_CHAT_message_is_sent(msg); | 273 | const int sent = GNUNET_CHAT_message_is_sent(msg); |
221 | 274 | ||
222 | UI_MESSAGE_Handle *message = ui_message_new(app, GNUNET_YES == sent); | 275 | UI_MESSAGE_Handle *message = ui_message_new( |
276 | app, | ||
277 | GNUNET_YES == sent? UI_MESSAGE_SENT : UI_MESSAGE_DEFAULT | ||
278 | ); | ||
223 | 279 | ||
224 | if (GNUNET_YES != sent) | 280 | if (GNUNET_YES != sent) |
225 | { | 281 | { |