aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-13 18:49:00 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-13 18:49:00 +0100
commite06b57b58d500c09986b69180ed539ef8290cda0 (patch)
tree07ea1eaa52a786acc3ac0a0af12c2968ea10295c
parent42e5473c0c1d82ffa161b928f25c1461de16c2b3 (diff)
downloadmessenger-gtk-e06b57b58d500c09986b69180ed539ef8290cda0.tar.gz
messenger-gtk-e06b57b58d500c09986b69180ed539ef8290cda0.zip
Implemented account selection
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/chat/messenger.c6
-rw-r--r--src/event.c88
-rw-r--r--src/event.h3
-rw-r--r--src/ui/messenger.c11
4 files changed, 81 insertions, 27 deletions
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
index ad05158..f1ea471 100644
--- a/src/chat/messenger.c
+++ b/src/chat/messenger.c
@@ -101,6 +101,11 @@ _chat_messenger_message(void *cls,
101 101
102 switch (kind) 102 switch (kind)
103 { 103 {
104 case GNUNET_CHAT_KIND_REFRESH:
105 {
106 application_call_event(app, event_refresh_accounts);
107 break;
108 }
104 case GNUNET_CHAT_KIND_LOGIN: 109 case GNUNET_CHAT_KIND_LOGIN:
105 { 110 {
106 application_call_event(app, event_update_profile); 111 application_call_event(app, event_update_profile);
@@ -185,7 +190,6 @@ chat_messenger_run(void *cls,
185 app->chat.messenger.handle = GNUNET_CHAT_start( 190 app->chat.messenger.handle = GNUNET_CHAT_start(
186 cfg, 191 cfg,
187 ".messenger", 192 ".messenger",
188 app->chat.identity,
189 &_chat_messenger_message, 193 &_chat_messenger_message,
190 app 194 app
191 ); 195 );
diff --git a/src/event.c b/src/event.c
index 193ecfa..5409d7b 100644
--- a/src/event.c
+++ b/src/event.c
@@ -80,6 +80,68 @@ _show_notification(MESSENGER_Application *app,
80} 80}
81 81
82static void 82static void
83_clear_each_selectable_widget(GtkWidget *widget,
84 gpointer user_data)
85{
86 GtkContainer *container = GTK_CONTAINER(user_data);
87 GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget);
88
89 if (gtk_list_box_row_get_selectable(row))
90 gtk_container_remove(container, widget);
91}
92
93static int
94_iterate_accounts(void *cls,
95 const struct GNUNET_CHAT_Handle *handle,
96 struct GNUNET_CHAT_Account *account)
97{
98 MESSENGER_Application *app = (MESSENGER_Application*) cls;
99 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
100
101 const gchar *name = GNUNET_CHAT_account_get_name(account);
102
103 UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(app);
104
105 hdy_avatar_set_text(profile->entry_avatar, name);
106 gtk_label_set_text(profile->entry_label, name);
107
108 gtk_list_box_prepend(ui->accounts_listbox, profile->entry_box);
109
110 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
111 gtk_widget_get_parent(profile->entry_box)
112 );
113
114 g_hash_table_insert(ui->bindings, row, account);
115
116 if ((account == GNUNET_CHAT_get_connected(handle)) ||
117 ((app->chat.identity) && (0 == g_strcmp0(app->chat.identity, name))))
118 gtk_list_box_select_row(ui->accounts_listbox, row);
119
120 ui_profile_entry_delete(profile);
121 return GNUNET_YES;
122}
123
124void
125event_refresh_accounts(MESSENGER_Application *app)
126{
127 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
128 CHAT_MESSENGER_Handle *chat = &(app->chat.messenger);
129
130 if (!(ui->accounts_listbox))
131 return;
132
133 gtk_list_box_unselect_all(ui->accounts_listbox);
134
135 gtk_container_foreach(
136 GTK_CONTAINER(ui->accounts_listbox),
137 _clear_each_selectable_widget,
138 ui->accounts_listbox
139 );
140
141 GNUNET_CHAT_iterate_accounts(chat->handle, _iterate_accounts, app);
142}
143
144static void
83_add_new_chat_entry(MESSENGER_Application *app, 145_add_new_chat_entry(MESSENGER_Application *app,
84 struct GNUNET_CHAT_Context *context) 146 struct GNUNET_CHAT_Context *context)
85{ 147{
@@ -156,15 +218,6 @@ _iterate_profile_groups(void *cls,
156 return GNUNET_YES; 218 return GNUNET_YES;
157} 219}
158 220
159static void
160_clear_each_widget(GtkWidget *widget,
161 gpointer user_data)
162{
163 GtkContainer *container = GTK_CONTAINER(user_data);
164
165 gtk_container_remove(container, widget);
166}
167
168void 221void
169event_update_profile(MESSENGER_Application *app) 222event_update_profile(MESSENGER_Application *app)
170{ 223{
@@ -177,21 +230,6 @@ event_update_profile(MESSENGER_Application *app)
177 { 230 {
178 hdy_avatar_set_text(ui->profile_avatar, name); 231 hdy_avatar_set_text(ui->profile_avatar, name);
179 gtk_label_set_text(ui->profile_label, name); 232 gtk_label_set_text(ui->profile_label, name);
180
181 UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(app);
182
183 hdy_avatar_set_text(profile->entry_avatar, name);
184 gtk_label_set_text(profile->entry_label, name);
185
186 gtk_list_box_prepend(ui->accounts_listbox, profile->entry_box);
187
188 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
189 gtk_widget_get_parent(profile->entry_box)
190 );
191
192 gtk_list_box_select_row(ui->accounts_listbox, row);
193
194 ui_profile_entry_delete(profile);
195 } 233 }
196 234
197 const char *key = GNUNET_CHAT_get_key(chat->handle); 235 const char *key = GNUNET_CHAT_get_key(chat->handle);
@@ -201,7 +239,7 @@ event_update_profile(MESSENGER_Application *app)
201 239
202 gtk_container_foreach( 240 gtk_container_foreach(
203 GTK_CONTAINER(ui->chats_listbox), 241 GTK_CONTAINER(ui->chats_listbox),
204 _clear_each_widget, 242 _clear_each_selectable_widget,
205 ui->chats_listbox 243 ui->chats_listbox
206 ); 244 );
207 245
diff --git a/src/event.h b/src/event.h
index 71a85ac..746e9f3 100644
--- a/src/event.h
+++ b/src/event.h
@@ -28,6 +28,9 @@
28#include "application.h" 28#include "application.h"
29 29
30void 30void
31event_refresh_accounts(MESSENGER_Application *app);
32
33void
31event_update_profile(MESSENGER_Application *app); 34event_update_profile(MESSENGER_Application *app);
32 35
33void 36void
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
index 7fdb60e..a5a64e0 100644
--- a/src/ui/messenger.c
+++ b/src/ui/messenger.c
@@ -94,7 +94,14 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
94 return; 94 return;
95 } 95 }
96 96
97 // TODO: switch to selected profile 97 struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) (
98 g_hash_table_lookup(app->ui.bindings, row)
99 );
100
101 if (!account)
102 return;
103
104 GNUNET_CHAT_connect(app->chat.messenger.handle, account);
98} 105}
99 106
100static void 107static void
@@ -497,4 +504,6 @@ ui_messenger_cleanup(UI_MESSENGER_Handle *handle)
497 504
498 if (handle->chat_entries) 505 if (handle->chat_entries)
499 g_list_free(handle->chat_entries); 506 g_list_free(handle->chat_entries);
507
508 memset(handle, 0, sizeof(*handle));
500} 509}