diff options
Diffstat (limited to 'src/ui/accounts.c')
-rw-r--r-- | src/ui/accounts.c | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/src/ui/accounts.c b/src/ui/accounts.c index c55c009..f89244f 100644 --- a/src/ui/accounts.c +++ b/src/ui/accounts.c | |||
@@ -46,6 +46,15 @@ _open_new_account_dialog(gpointer user_data) | |||
46 | return FALSE; | 46 | return FALSE; |
47 | } | 47 | } |
48 | 48 | ||
49 | static gboolean | ||
50 | _show_messenger_main_window(gpointer user_data) | ||
51 | { | ||
52 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
53 | |||
54 | gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); | ||
55 | return FALSE; | ||
56 | } | ||
57 | |||
49 | static void | 58 | static void |
50 | handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, | 59 | handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, |
51 | GtkListBoxRow* row, | 60 | GtkListBoxRow* row, |
@@ -55,7 +64,10 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, | |||
55 | 64 | ||
56 | if (!gtk_list_box_row_get_selectable(row)) | 65 | if (!gtk_list_box_row_get_selectable(row)) |
57 | { | 66 | { |
58 | g_idle_add(G_SOURCE_FUNC(_open_new_account_dialog), app); | 67 | app->ui.accounts.show_queued = g_idle_add( |
68 | G_SOURCE_FUNC(_open_new_account_dialog), app | ||
69 | ); | ||
70 | |||
59 | goto close_dialog; | 71 | goto close_dialog; |
60 | } | 72 | } |
61 | 73 | ||
@@ -66,7 +78,12 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, | |||
66 | if (!account) | 78 | if (!account) |
67 | goto close_dialog; | 79 | goto close_dialog; |
68 | 80 | ||
69 | // TODO | 81 | if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) |
82 | app->ui.accounts.show_queued = g_idle_add( | ||
83 | G_SOURCE_FUNC(_show_messenger_main_window), app | ||
84 | ); | ||
85 | |||
86 | GNUNET_CHAT_connect(app->chat.messenger.handle, account); | ||
70 | 87 | ||
71 | close_dialog: | 88 | close_dialog: |
72 | gtk_window_close(GTK_WINDOW(app->ui.accounts.dialog)); | 89 | gtk_window_close(GTK_WINDOW(app->ui.accounts.dialog)); |
@@ -76,16 +93,21 @@ static void | |||
76 | handle_dialog_destroy(UNUSED GtkWidget *window, | 93 | handle_dialog_destroy(UNUSED GtkWidget *window, |
77 | gpointer user_data) | 94 | gpointer user_data) |
78 | { | 95 | { |
79 | ui_accounts_dialog_cleanup((UI_ACCOUNTS_Handle*) user_data); | 96 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
97 | |||
98 | ui_accounts_dialog_cleanup(&(app->ui.accounts)); | ||
99 | |||
100 | if ((!(app->ui.accounts.show_queued)) && | ||
101 | (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))) | ||
102 | gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); | ||
80 | } | 103 | } |
81 | 104 | ||
82 | static int | 105 | static int |
83 | _iterate_accounts(void *cls, | 106 | _iterate_accounts(void *cls, |
84 | const struct GNUNET_CHAT_Handle *handle, | 107 | UNUSED const struct GNUNET_CHAT_Handle *handle, |
85 | struct GNUNET_CHAT_Account *account) | 108 | struct GNUNET_CHAT_Account *account) |
86 | { | 109 | { |
87 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | 110 | MESSENGER_Application *app = (MESSENGER_Application*) cls; |
88 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | ||
89 | 111 | ||
90 | const gchar *name = GNUNET_CHAT_account_get_name(account); | 112 | const gchar *name = GNUNET_CHAT_account_get_name(account); |
91 | 113 | ||
@@ -94,16 +116,16 @@ _iterate_accounts(void *cls, | |||
94 | hdy_avatar_set_text(entry->entry_avatar, name); | 116 | hdy_avatar_set_text(entry->entry_avatar, name); |
95 | gtk_label_set_text(entry->entry_label, name); | 117 | gtk_label_set_text(entry->entry_label, name); |
96 | 118 | ||
97 | gtk_list_box_prepend(ui->accounts_listbox, entry->entry_box); | 119 | gtk_list_box_prepend(app->ui.accounts.accounts_listbox, entry->entry_box); |
98 | 120 | ||
99 | GtkListBoxRow *row = GTK_LIST_BOX_ROW( | 121 | GtkListBoxRow *row = GTK_LIST_BOX_ROW( |
100 | gtk_widget_get_parent(entry->entry_box) | 122 | gtk_widget_get_parent(entry->entry_box) |
101 | ); | 123 | ); |
102 | 124 | ||
103 | g_hash_table_insert(ui->bindings, row, account); | 125 | g_hash_table_insert(app->ui.bindings, row, account); |
104 | 126 | ||
105 | ui.accounts.account_entries = g_list_append( | 127 | app->ui.accounts.account_entries = g_list_append( |
106 | ui.accounts.account_entries, | 128 | app->ui.accounts.account_entries, |
107 | entry | 129 | entry |
108 | ); | 130 | ); |
109 | 131 | ||
@@ -116,6 +138,7 @@ ui_accounts_dialog_init(MESSENGER_Application *app, | |||
116 | { | 138 | { |
117 | handle->account_entries = NULL; | 139 | handle->account_entries = NULL; |
118 | handle->bindings = app->ui.bindings; | 140 | handle->bindings = app->ui.bindings; |
141 | handle->show_queued = 0; | ||
119 | 142 | ||
120 | handle->builder = gtk_builder_new_from_resource( | 143 | handle->builder = gtk_builder_new_from_resource( |
121 | application_get_resource_path(app, "ui/accounts.ui") | 144 | application_get_resource_path(app, "ui/accounts.ui") |
@@ -127,7 +150,7 @@ ui_accounts_dialog_init(MESSENGER_Application *app, | |||
127 | 150 | ||
128 | gtk_window_set_title( | 151 | gtk_window_set_title( |
129 | GTK_WINDOW(handle->dialog), | 152 | GTK_WINDOW(handle->dialog), |
130 | _("Contacts") | 153 | _("Accounts") |
131 | ); | 154 | ); |
132 | 155 | ||
133 | gtk_window_set_transient_for( | 156 | gtk_window_set_transient_for( |
@@ -161,7 +184,7 @@ ui_accounts_dialog_init(MESSENGER_Application *app, | |||
161 | handle->dialog, | 184 | handle->dialog, |
162 | "destroy", | 185 | "destroy", |
163 | G_CALLBACK(handle_dialog_destroy), | 186 | G_CALLBACK(handle_dialog_destroy), |
164 | handle | 187 | app |
165 | ); | 188 | ); |
166 | 189 | ||
167 | GNUNET_CHAT_iterate_accounts( | 190 | GNUNET_CHAT_iterate_accounts( |
@@ -169,14 +192,28 @@ ui_accounts_dialog_init(MESSENGER_Application *app, | |||
169 | _iterate_accounts, | 192 | _iterate_accounts, |
170 | app | 193 | app |
171 | ); | 194 | ); |
195 | |||
196 | gtk_list_box_unselect_all(handle->accounts_listbox); | ||
172 | } | 197 | } |
173 | 198 | ||
174 | void | 199 | void |
175 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) | 200 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) |
176 | { | 201 | { |
202 | GList *list = gtk_container_get_children( | ||
203 | GTK_CONTAINER(handle->accounts_listbox) | ||
204 | ); | ||
205 | |||
206 | while (list) | ||
207 | { | ||
208 | if (list->data) | ||
209 | g_hash_table_remove(handle->bindings, list->data); | ||
210 | |||
211 | list = list->next; | ||
212 | } | ||
213 | |||
177 | g_object_unref(handle->builder); | 214 | g_object_unref(handle->builder); |
178 | 215 | ||
179 | GList *list = handle->account_entries; | 216 | list = handle->account_entries; |
180 | 217 | ||
181 | while (list) { | 218 | while (list) { |
182 | if (list->data) | 219 | if (list->data) |