aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-14 21:39:58 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-14 21:39:58 +0100
commit0fb7c2434bf60bf2650a11f0df866123dd064c10 (patch)
tree44d6603b06a6a4629927e4572a0914ffb3923100 /src/ui
parent1de05a83d54cb363199c2767e56267533cc11f0d (diff)
downloadmessenger-gtk-0fb7c2434bf60bf2650a11f0df866123dd064c10.tar.gz
messenger-gtk-0fb7c2434bf60bf2650a11f0df866123dd064c10.zip
Implemented account overview to open main window with selection
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/accounts.c61
-rw-r--r--src/ui/accounts.h1
-rw-r--r--src/ui/contacts.c14
-rw-r--r--src/ui/messenger.c4
-rw-r--r--src/ui/new_account.c26
-rw-r--r--src/ui/new_account.h2
6 files changed, 91 insertions, 17 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
49static 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
49static void 58static void
50handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, 59handle_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
71close_dialog: 88close_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
76handle_dialog_destroy(UNUSED GtkWidget *window, 93handle_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
82static int 105static 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
174void 199void
175ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) 200ui_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,
257void 257void
258ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) 258ui_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
29static 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
29static void 38static 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
45static void 59static void
@@ -86,13 +100,21 @@ static void
86handle_dialog_destroy(UNUSED GtkWidget *window, 100handle_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
92void 112void
93ui_new_account_dialog_init(MESSENGER_Application *app, 113ui_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
30typedef struct UI_NEW_ACCOUNT_Handle 30typedef 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