diff options
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 119 |
1 files changed, 106 insertions, 13 deletions
diff --git a/src/event.c b/src/event.c index 2094bdd..5330e5b 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -103,11 +103,100 @@ event_handle_warning(MESSENGER_Application *app, | |||
103 | ); | 103 | ); |
104 | } | 104 | } |
105 | 105 | ||
106 | static gboolean | ||
107 | _idle_refresh_accounts(gpointer user_data) | ||
108 | { | ||
109 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
110 | |||
111 | if (!(app->ui.messenger.main_window)) | ||
112 | goto refresh_exit; | ||
113 | |||
114 | if (gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) | ||
115 | ui_messenger_refresh(app, &(app->ui.messenger)); | ||
116 | else | ||
117 | ui_accounts_dialog_refresh(app, &(app->ui.accounts)); | ||
118 | |||
119 | refresh_exit: | ||
120 | app->ui.messenger.account_refresh = 0; | ||
121 | return FALSE; | ||
122 | } | ||
123 | |||
106 | void | 124 | void |
107 | event_refresh_accounts(MESSENGER_Application *app) | 125 | event_refresh_accounts(MESSENGER_Application *app) |
108 | { | 126 | { |
109 | ui_accounts_dialog_refresh(app, &(app->ui.accounts)); | 127 | if (app->ui.messenger.account_refresh) |
110 | ui_messenger_refresh(app, &(app->ui.messenger)); | 128 | g_source_remove(app->ui.messenger.account_refresh); |
129 | |||
130 | if (app->ui.messenger.main_window) | ||
131 | app->ui.messenger.account_refresh = g_idle_add( | ||
132 | G_SOURCE_FUNC(_idle_refresh_accounts), | ||
133 | app | ||
134 | ); | ||
135 | else | ||
136 | app->ui.messenger.account_refresh = 0; | ||
137 | } | ||
138 | |||
139 | static gboolean | ||
140 | _select_chat_to_activate(gpointer user_data) | ||
141 | { | ||
142 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) user_data; | ||
143 | |||
144 | if (!(entry->chat)) | ||
145 | return FALSE; | ||
146 | |||
147 | MESSENGER_Application *app = entry->chat->app; | ||
148 | |||
149 | if (!app) | ||
150 | return FALSE; | ||
151 | |||
152 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | ||
153 | |||
154 | GtkListBoxRow *row = GTK_LIST_BOX_ROW( | ||
155 | gtk_widget_get_parent(entry->entry_box) | ||
156 | ); | ||
157 | |||
158 | gtk_list_box_select_row(ui->chats_listbox, row); | ||
159 | gtk_list_box_invalidate_filter(ui->chats_listbox); | ||
160 | |||
161 | gtk_widget_activate(GTK_WIDGET(row)); | ||
162 | |||
163 | ui->chat_selection = 0; | ||
164 | return FALSE; | ||
165 | } | ||
166 | |||
167 | static gboolean | ||
168 | _idle_chat_entry_update(gpointer user_data) | ||
169 | { | ||
170 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) user_data; | ||
171 | |||
172 | if ((!(entry->chat)) || (!(entry->chat->app)) || | ||
173 | (!(entry->chat->send_text_view))) | ||
174 | goto update_exit; | ||
175 | |||
176 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( | ||
177 | g_object_get_qdata( | ||
178 | G_OBJECT(entry->chat->send_text_view), | ||
179 | entry->chat->app->quarks.data | ||
180 | ) | ||
181 | ); | ||
182 | |||
183 | ui_chat_entry_update(entry, entry->chat->app, context); | ||
184 | |||
185 | update_exit: | ||
186 | entry->update = 0; | ||
187 | return FALSE; | ||
188 | } | ||
189 | |||
190 | static void | ||
191 | enqueue_chat_entry_update(UI_CHAT_ENTRY_Handle *entry) | ||
192 | { | ||
193 | if (entry->update) | ||
194 | g_source_remove(entry->update); | ||
195 | |||
196 | entry->update = g_idle_add( | ||
197 | G_SOURCE_FUNC(_idle_chat_entry_update), | ||
198 | entry | ||
199 | ); | ||
111 | } | 200 | } |
112 | 201 | ||
113 | static void | 202 | static void |
@@ -117,7 +206,7 @@ _add_new_chat_entry(MESSENGER_Application *app, | |||
117 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 206 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); |
118 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); | 207 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); |
119 | 208 | ||
120 | ui_chat_entry_update(entry, app, context); | 209 | enqueue_chat_entry_update(entry); |
121 | 210 | ||
122 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); | 211 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); |
123 | GNUNET_CHAT_context_set_user_pointer(context, entry); | 212 | GNUNET_CHAT_context_set_user_pointer(context, entry); |
@@ -145,10 +234,13 @@ _add_new_chat_entry(MESSENGER_Application *app, | |||
145 | entry | 234 | entry |
146 | ); | 235 | ); |
147 | 236 | ||
148 | gtk_list_box_select_row(ui->chats_listbox, row); | 237 | if (ui->chat_selection) |
149 | gtk_list_box_invalidate_filter(ui->chats_listbox); | 238 | g_source_remove(ui->chat_selection); |
150 | 239 | ||
151 | gtk_widget_activate(GTK_WIDGET(row)); | 240 | ui->chat_selection = g_idle_add( |
241 | G_SOURCE_FUNC(_select_chat_to_activate), | ||
242 | entry | ||
243 | ); | ||
152 | } | 244 | } |
153 | 245 | ||
154 | static int | 246 | static int |
@@ -275,7 +367,7 @@ event_update_chats(MESSENGER_Application *app, | |||
275 | if (!handle) | 367 | if (!handle) |
276 | _add_new_chat_entry(app, context); | 368 | _add_new_chat_entry(app, context); |
277 | else | 369 | else |
278 | ui_chat_entry_update(handle, app, context); | 370 | enqueue_chat_entry_update(handle); |
279 | else if (handle) | 371 | else if (handle) |
280 | _clear_chat_entry(gtk_widget_get_parent(handle->entry_box), app); | 372 | _clear_chat_entry(gtk_widget_get_parent(handle->entry_box), app); |
281 | 373 | ||
@@ -298,7 +390,7 @@ _update_contact_context(MESSENGER_Application *app, | |||
298 | if (!handle) | 390 | if (!handle) |
299 | return; | 391 | return; |
300 | 392 | ||
301 | ui_chat_entry_update(handle, app, context); | 393 | enqueue_chat_entry_update(handle); |
302 | } | 394 | } |
303 | 395 | ||
304 | void | 396 | void |
@@ -365,7 +457,7 @@ event_presence_contact(MESSENGER_Application *app, | |||
365 | 457 | ||
366 | GNUNET_CHAT_member_set_user_pointer(context, contact, message); | 458 | GNUNET_CHAT_member_set_user_pointer(context, contact, message); |
367 | 459 | ||
368 | ui_chat_entry_update(handle, app, context); | 460 | enqueue_chat_entry_update(handle); |
369 | } | 461 | } |
370 | 462 | ||
371 | void | 463 | void |
@@ -388,7 +480,7 @@ event_update_contacts(MESSENGER_Application *app, | |||
388 | if (!handle) | 480 | if (!handle) |
389 | return; | 481 | return; |
390 | 482 | ||
391 | ui_chat_entry_update(handle, app, context); | 483 | enqueue_chat_entry_update(handle); |
392 | } | 484 | } |
393 | 485 | ||
394 | static void | 486 | static void |
@@ -453,7 +545,8 @@ event_invitation(MESSENGER_Application *app, | |||
453 | gtk_widget_show(GTK_WIDGET(message->accept_button)); | 545 | gtk_widget_show(GTK_WIDGET(message->accept_button)); |
454 | 546 | ||
455 | ui_chat_add_message(handle->chat, app, message); | 547 | ui_chat_add_message(handle->chat, app, message); |
456 | ui_chat_entry_update(handle, app, context); | 548 | |
549 | enqueue_chat_entry_update(handle); | ||
457 | } | 550 | } |
458 | 551 | ||
459 | void | 552 | void |
@@ -518,7 +611,7 @@ event_receive_message(MESSENGER_Application *app, | |||
518 | ui_chat_add_message(handle->chat, app, message); | 611 | ui_chat_add_message(handle->chat, app, message); |
519 | 612 | ||
520 | skip_message: | 613 | skip_message: |
521 | ui_chat_entry_update(handle, app, context); | 614 | enqueue_chat_entry_update(handle); |
522 | } | 615 | } |
523 | 616 | ||
524 | void | 617 | void |
@@ -546,5 +639,5 @@ event_delete_message(MESSENGER_Application *app, | |||
546 | messages = messages->next; | 639 | messages = messages->next; |
547 | } | 640 | } |
548 | 641 | ||
549 | ui_chat_entry_update(handle, app, context); | 642 | enqueue_chat_entry_update(handle); |
550 | } | 643 | } |