diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | resources/ui/accounts.ui | 26 | ||||
-rw-r--r-- | src/application.c | 16 | ||||
-rw-r--r-- | src/ui/accounts.c | 61 | ||||
-rw-r--r-- | src/ui/accounts.h | 1 | ||||
-rw-r--r-- | src/ui/contacts.c | 14 | ||||
-rw-r--r-- | src/ui/messenger.c | 4 | ||||
-rw-r--r-- | src/ui/new_account.c | 26 | ||||
-rw-r--r-- | src/ui/new_account.h | 2 |
9 files changed, 136 insertions, 21 deletions
@@ -13,20 +13,21 @@ SOURCES = messenger_gtk.c\ | |||
13 | file.c\ | 13 | file.c\ |
14 | resources.c\ | 14 | resources.c\ |
15 | chat/messenger.c\ | 15 | chat/messenger.c\ |
16 | ui/chat.c\ | 16 | ui/account_entry.c\ |
17 | ui/accounts.c\ | ||
17 | ui/chat_entry.c\ | 18 | ui/chat_entry.c\ |
19 | ui/chat.c\ | ||
18 | ui/contact_entry.c\ | 20 | ui/contact_entry.c\ |
19 | ui/contacts.c\ | 21 | ui/contacts.c\ |
20 | ui/file_load_entry.c\ | 22 | ui/file_load_entry.c\ |
21 | ui/invite_contact.c\ | 23 | ui/invite_contact.c\ |
22 | ui/message.c\ | 24 | ui/message.c\ |
23 | ui/messenger.c\ | 25 | ui/messenger.c\ |
26 | ui/new_account.c\ | ||
24 | ui/new_contact.c\ | 27 | ui/new_contact.c\ |
25 | ui/new_group.c\ | 28 | ui/new_group.c\ |
26 | ui/new_platform.c\ | 29 | ui/new_platform.c\ |
27 | ui/new_account.c\ | ||
28 | ui/picker.c\ | 30 | ui/picker.c\ |
29 | ui/account_entry.c\ | ||
30 | ui/send_file.c\ | 31 | ui/send_file.c\ |
31 | ui/settings.c | 32 | ui/settings.c |
32 | 33 | ||
diff --git a/resources/ui/accounts.ui b/resources/ui/accounts.ui index d4ffb4e..564ef26 100644 --- a/resources/ui/accounts.ui +++ b/resources/ui/accounts.ui | |||
@@ -1,9 +1,31 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <!-- Generated with glade 3.38.2 --> | 2 | <!-- Generated with glade 3.38.2 |
3 | |||
4 | Copyright (C) 2022 GNUnet e.V. | ||
5 | |||
6 | GNUnet is free software: you can redistribute it and/or modify it | ||
7 | under the terms of the GNU Affero General Public License as published | ||
8 | by the Free Software Foundation, either version 3 of the License, | ||
9 | or (at your option) any later version. | ||
10 | |||
11 | GNUnet is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Affero General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Affero General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | |||
19 | SPDX-License-Identifier: AGPL3.0-or-later | ||
20 | Author: Tobias Frisch | ||
21 | |||
22 | --> | ||
3 | <interface> | 23 | <interface> |
4 | <requires lib="gtk+" version="3.24"/> | 24 | <requires lib="gtk+" version="3.24"/> |
5 | <object class="GtkDialog" id="accounts_dialog"> | 25 | <object class="GtkDialog" id="accounts_dialog"> |
6 | <property name="can-focus">False</property> | 26 | <property name="can-focus">False</property> |
27 | <property name="modal">True</property> | ||
28 | <property name="window-position">center-on-parent</property> | ||
7 | <property name="type-hint">dialog</property> | 29 | <property name="type-hint">dialog</property> |
8 | <child internal-child="vbox"> | 30 | <child internal-child="vbox"> |
9 | <object class="GtkBox"> | 31 | <object class="GtkBox"> |
@@ -36,6 +58,8 @@ | |||
36 | </child> | 58 | </child> |
37 | <child> | 59 | <child> |
38 | <object class="GtkScrolledWindow"> | 60 | <object class="GtkScrolledWindow"> |
61 | <property name="width-request">250</property> | ||
62 | <property name="height-request">150</property> | ||
39 | <property name="visible">True</property> | 63 | <property name="visible">True</property> |
40 | <property name="can-focus">True</property> | 64 | <property name="can-focus">True</property> |
41 | <property name="shadow-type">in</property> | 65 | <property name="shadow-type">in</property> |
diff --git a/src/application.c b/src/application.c index 4f7b024..74e8bd4 100644 --- a/src/application.c +++ b/src/application.c | |||
@@ -43,6 +43,17 @@ _load_ui_stylesheets(MESSENGER_Application *app) | |||
43 | ); | 43 | ); |
44 | } | 44 | } |
45 | 45 | ||
46 | static gboolean | ||
47 | _application_accounts(gpointer user_data) | ||
48 | { | ||
49 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
50 | |||
51 | ui_accounts_dialog_init(app, &(app->ui.accounts)); | ||
52 | |||
53 | gtk_widget_show(GTK_WIDGET(app->ui.accounts.dialog)); | ||
54 | return FALSE; | ||
55 | } | ||
56 | |||
46 | static void | 57 | static void |
47 | _application_activate(UNUSED GtkApplication* application, | 58 | _application_activate(UNUSED GtkApplication* application, |
48 | gpointer user_data) | 59 | gpointer user_data) |
@@ -50,6 +61,11 @@ _application_activate(UNUSED GtkApplication* application, | |||
50 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 61 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
51 | 62 | ||
52 | ui_messenger_init(app, &(app->ui.messenger)); | 63 | ui_messenger_init(app, &(app->ui.messenger)); |
64 | |||
65 | if (app->chat.identity) | ||
66 | gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); | ||
67 | else | ||
68 | g_idle_add(G_SOURCE_FUNC(_application_accounts), app); | ||
53 | } | 69 | } |
54 | 70 | ||
55 | void | 71 | void |
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) |
diff --git a/src/ui/accounts.h b/src/ui/accounts.h index 88cdcfa..254c861 100644 --- a/src/ui/accounts.h +++ b/src/ui/accounts.h | |||
@@ -31,6 +31,7 @@ typedef struct UI_ACCOUNTS_Handle | |||
31 | { | 31 | { |
32 | GList *account_entries; | 32 | GList *account_entries; |
33 | GHashTable *bindings; | 33 | GHashTable *bindings; |
34 | guint show_queued; | ||
34 | 35 | ||
35 | GtkBuilder *builder; | 36 | GtkBuilder *builder; |
36 | GtkDialog *dialog; | 37 | GtkDialog *dialog; |
diff --git a/src/ui/contacts.c b/src/ui/contacts.c index 63157ff..ad46773 100644 --- a/src/ui/contacts.c +++ b/src/ui/contacts.c | |||
@@ -257,9 +257,21 @@ ui_contacts_dialog_init(MESSENGER_Application *app, | |||
257 | void | 257 | void |
258 | ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) | 258 | ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) |
259 | { | 259 | { |
260 | GList *list = gtk_container_get_children( | ||
261 | GTK_CONTAINER(handle->contacts_listbox) | ||
262 | ); | ||
263 | |||
264 | while (list) | ||
265 | { | ||
266 | if (list->data) | ||
267 | g_hash_table_remove(handle->bindings, list->data); | ||
268 | |||
269 | list = list->next; | ||
270 | } | ||
271 | |||
260 | g_object_unref(handle->builder); | 272 | g_object_unref(handle->builder); |
261 | 273 | ||
262 | GList *list = handle->contact_entries; | 274 | list = handle->contact_entries; |
263 | 275 | ||
264 | while (list) { | 276 | while (list) { |
265 | if (list->data) | 277 | if (list->data) |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index d0324d0..26b1993 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -206,6 +206,8 @@ handle_chats_listbox_filter_func(GtkListBoxRow *row, | |||
206 | { | 206 | { |
207 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; | 207 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; |
208 | 208 | ||
209 | printf("-- %lu\n", (uint64_t) row); | ||
210 | |||
209 | if ((!gtk_list_box_row_get_selectable(row)) || | 211 | if ((!gtk_list_box_row_get_selectable(row)) || |
210 | (gtk_list_box_row_is_selected(row))) | 212 | (gtk_list_box_row_is_selected(row))) |
211 | return TRUE; | 213 | return TRUE; |
@@ -467,8 +469,6 @@ ui_messenger_init(MESSENGER_Application *app, | |||
467 | gtk_builder_get_object(handle->builder, "chats_stack") | 469 | gtk_builder_get_object(handle->builder, "chats_stack") |
468 | ); | 470 | ); |
469 | 471 | ||
470 | gtk_widget_show(GTK_WIDGET(handle->main_window)); | ||
471 | |||
472 | g_signal_connect( | 472 | g_signal_connect( |
473 | handle->main_window, | 473 | handle->main_window, |
474 | "destroy", | 474 | "destroy", |
diff --git a/src/ui/new_account.c b/src/ui/new_account.c index 854b2bd..f51eb4d 100644 --- a/src/ui/new_account.c +++ b/src/ui/new_account.c | |||
@@ -26,6 +26,15 @@ | |||
26 | 26 | ||
27 | #include "../application.h" | 27 | #include "../application.h" |
28 | 28 | ||
29 | static gboolean | ||
30 | _show_messenger_main_window(gpointer user_data) | ||
31 | { | ||
32 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
33 | |||
34 | gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); | ||
35 | return FALSE; | ||
36 | } | ||
37 | |||
29 | static void | 38 | static void |
30 | _open_new_account(GtkEntry *entry, MESSENGER_Application *app) | 39 | _open_new_account(GtkEntry *entry, MESSENGER_Application *app) |
31 | { | 40 | { |
@@ -40,6 +49,11 @@ _open_new_account(GtkEntry *entry, MESSENGER_Application *app) | |||
40 | GNUNET_free(app->chat.identity); | 49 | GNUNET_free(app->chat.identity); |
41 | 50 | ||
42 | app->chat.identity = GNUNET_strdup(name); | 51 | app->chat.identity = GNUNET_strdup(name); |
52 | |||
53 | if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) | ||
54 | app->ui.new_account.show_queued = g_idle_add( | ||
55 | G_SOURCE_FUNC(_show_messenger_main_window), app | ||
56 | ); | ||
43 | } | 57 | } |
44 | 58 | ||
45 | static void | 59 | static void |
@@ -86,13 +100,21 @@ static void | |||
86 | handle_dialog_destroy(UNUSED GtkWidget *window, | 100 | handle_dialog_destroy(UNUSED GtkWidget *window, |
87 | gpointer user_data) | 101 | gpointer user_data) |
88 | { | 102 | { |
89 | ui_new_account_dialog_cleanup((UI_NEW_ACCOUNT_Handle*) user_data); | 103 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
104 | |||
105 | ui_new_account_dialog_cleanup(&(app->ui.new_account)); | ||
106 | |||
107 | if ((!(app->ui.new_account.show_queued)) && | ||
108 | (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))) | ||
109 | gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); | ||
90 | } | 110 | } |
91 | 111 | ||
92 | void | 112 | void |
93 | ui_new_account_dialog_init(MESSENGER_Application *app, | 113 | ui_new_account_dialog_init(MESSENGER_Application *app, |
94 | UI_NEW_ACCOUNT_Handle *handle) | 114 | UI_NEW_ACCOUNT_Handle *handle) |
95 | { | 115 | { |
116 | handle->show_queued = 0; | ||
117 | |||
96 | handle->builder = gtk_builder_new_from_resource( | 118 | handle->builder = gtk_builder_new_from_resource( |
97 | application_get_resource_path(app, "ui/new_account.ui") | 119 | application_get_resource_path(app, "ui/new_account.ui") |
98 | ); | 120 | ); |
@@ -163,7 +185,7 @@ ui_new_account_dialog_init(MESSENGER_Application *app, | |||
163 | handle->dialog, | 185 | handle->dialog, |
164 | "destroy", | 186 | "destroy", |
165 | G_CALLBACK(handle_dialog_destroy), | 187 | G_CALLBACK(handle_dialog_destroy), |
166 | handle | 188 | app |
167 | ); | 189 | ); |
168 | } | 190 | } |
169 | 191 | ||
diff --git a/src/ui/new_account.h b/src/ui/new_account.h index c355d12..703f28d 100644 --- a/src/ui/new_account.h +++ b/src/ui/new_account.h | |||
@@ -29,6 +29,8 @@ | |||
29 | 29 | ||
30 | typedef struct UI_NEW_ACCOUNT_Handle | 30 | typedef struct UI_NEW_ACCOUNT_Handle |
31 | { | 31 | { |
32 | guint show_queued; | ||
33 | |||
32 | GtkBuilder *builder; | 34 | GtkBuilder *builder; |
33 | GtkDialog *dialog; | 35 | GtkDialog *dialog; |
34 | 36 | ||