diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-02-18 21:06:04 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-02-18 21:06:04 +0100 |
commit | 65a85c59ca226fbf65ada003c57f0d77e61ef073 (patch) | |
tree | 21295f5486ee2e2d6be72d34088703b46d122bcb | |
parent | 1bdb0791ee56fa081f8af1c18b457a1cf1c471fd (diff) | |
download | messenger-gtk-65a85c59ca226fbf65ada003c57f0d77e61ef073.tar.gz messenger-gtk-65a85c59ca226fbf65ada003c57f0d77e61ef073.zip |
Update accounts in dialog as well as main window
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/application.c | 1 | ||||
-rw-r--r-- | src/event.c | 2 | ||||
-rw-r--r-- | src/ui/accounts.c | 73 | ||||
-rw-r--r-- | src/ui/accounts.h | 4 |
4 files changed, 65 insertions, 15 deletions
diff --git a/src/application.c b/src/application.c index f8a1274..46456b9 100644 --- a/src/application.c +++ b/src/application.c | |||
@@ -49,6 +49,7 @@ _application_accounts(gpointer user_data) | |||
49 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 49 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
50 | 50 | ||
51 | ui_accounts_dialog_init(app, &(app->ui.accounts)); | 51 | ui_accounts_dialog_init(app, &(app->ui.accounts)); |
52 | ui_accounts_dialog_refresh(app, &(app->ui.accounts)); | ||
52 | 53 | ||
53 | gtk_widget_show(GTK_WIDGET(app->ui.accounts.dialog)); | 54 | gtk_widget_show(GTK_WIDGET(app->ui.accounts.dialog)); |
54 | return FALSE; | 55 | return FALSE; |
diff --git a/src/event.c b/src/event.c index 459f910..f081e2f 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -127,6 +127,8 @@ event_refresh_accounts(MESSENGER_Application *app) | |||
127 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 127 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); |
128 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); | 128 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); |
129 | 129 | ||
130 | ui_accounts_dialog_refresh(app, &(app->ui.accounts)); | ||
131 | |||
130 | if (!(ui->accounts_listbox)) | 132 | if (!(ui->accounts_listbox)) |
131 | return; | 133 | return; |
132 | 134 | ||
diff --git a/src/ui/accounts.c b/src/ui/accounts.c index 1817180..fcd4ad9 100644 --- a/src/ui/accounts.c +++ b/src/ui/accounts.c | |||
@@ -181,18 +181,11 @@ ui_accounts_dialog_init(MESSENGER_Application *app, | |||
181 | G_CALLBACK(handle_dialog_destroy), | 181 | G_CALLBACK(handle_dialog_destroy), |
182 | app | 182 | app |
183 | ); | 183 | ); |
184 | |||
185 | GNUNET_CHAT_iterate_accounts( | ||
186 | app->chat.messenger.handle, | ||
187 | _iterate_accounts, | ||
188 | app | ||
189 | ); | ||
190 | |||
191 | gtk_list_box_unselect_all(handle->accounts_listbox); | ||
192 | } | 184 | } |
193 | 185 | ||
194 | void | 186 | static void |
195 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) | 187 | _clear_accounts_listbox_rows(UI_ACCOUNTS_Handle *handle, |
188 | gboolean bindings_only) | ||
196 | { | 189 | { |
197 | GList *list = gtk_container_get_children( | 190 | GList *list = gtk_container_get_children( |
198 | GTK_CONTAINER(handle->accounts_listbox) | 191 | GTK_CONTAINER(handle->accounts_listbox) |
@@ -200,15 +193,28 @@ ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) | |||
200 | 193 | ||
201 | while (list) | 194 | while (list) |
202 | { | 195 | { |
203 | if (list->data) | 196 | GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data); |
204 | g_hash_table_remove(handle->bindings, list->data); | ||
205 | 197 | ||
198 | if ((!row) || (!gtk_list_box_row_get_selectable(row))) | ||
199 | goto skip_row; | ||
200 | |||
201 | g_hash_table_remove(handle->bindings, row); | ||
202 | |||
203 | if (!bindings_only) | ||
204 | gtk_container_remove( | ||
205 | GTK_CONTAINER(handle->accounts_listbox), | ||
206 | GTK_WIDGET(row) | ||
207 | ); | ||
208 | |||
209 | skip_row: | ||
206 | list = list->next; | 210 | list = list->next; |
207 | } | 211 | } |
212 | } | ||
208 | 213 | ||
209 | g_object_unref(handle->builder); | 214 | static void |
210 | 215 | _clear_accounts_entries(UI_ACCOUNTS_Handle *handle) | |
211 | list = handle->account_entries; | 216 | { |
217 | GList *list = handle->account_entries; | ||
212 | 218 | ||
213 | while (list) { | 219 | while (list) { |
214 | if (list->data) | 220 | if (list->data) |
@@ -219,4 +225,41 @@ ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) | |||
219 | 225 | ||
220 | if (handle->account_entries) | 226 | if (handle->account_entries) |
221 | g_list_free(handle->account_entries); | 227 | g_list_free(handle->account_entries); |
228 | |||
229 | handle->account_entries = NULL; | ||
230 | } | ||
231 | |||
232 | void | ||
233 | ui_accounts_dialog_refresh(MESSENGER_Application *app, | ||
234 | UI_ACCOUNTS_Handle *handle) | ||
235 | { | ||
236 | if (!(handle->accounts_listbox)) | ||
237 | return; | ||
238 | |||
239 | if (!(handle->account_entries)) | ||
240 | goto add_account_entries; | ||
241 | |||
242 | _clear_accounts_listbox_rows(handle, FALSE); | ||
243 | _clear_accounts_entries(handle); | ||
244 | |||
245 | add_account_entries: | ||
246 | GNUNET_CHAT_iterate_accounts( | ||
247 | app->chat.messenger.handle, | ||
248 | _iterate_accounts, | ||
249 | app | ||
250 | ); | ||
251 | |||
252 | gtk_list_box_unselect_all(handle->accounts_listbox); | ||
253 | } | ||
254 | |||
255 | void | ||
256 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) | ||
257 | { | ||
258 | _clear_accounts_listbox_rows(handle, TRUE); | ||
259 | |||
260 | g_object_unref(handle->builder); | ||
261 | |||
262 | _clear_accounts_entries(handle); | ||
263 | |||
264 | handle->accounts_listbox = NULL; | ||
222 | } | 265 | } |
diff --git a/src/ui/accounts.h b/src/ui/accounts.h index 254c861..6a098d8 100644 --- a/src/ui/accounts.h +++ b/src/ui/accounts.h | |||
@@ -46,6 +46,10 @@ ui_accounts_dialog_init(MESSENGER_Application *app, | |||
46 | UI_ACCOUNTS_Handle *handle); | 46 | UI_ACCOUNTS_Handle *handle); |
47 | 47 | ||
48 | void | 48 | void |
49 | ui_accounts_dialog_refresh(MESSENGER_Application *app, | ||
50 | UI_ACCOUNTS_Handle *handle); | ||
51 | |||
52 | void | ||
49 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle); | 53 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle); |
50 | 54 | ||
51 | #endif /* UI_ACCOUNTS_H_ */ | 55 | #endif /* UI_ACCOUNTS_H_ */ |