aboutsummaryrefslogtreecommitdiff
path: root/src/messenger_gtk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger_gtk.c')
-rw-r--r--src/messenger_gtk.c202
1 files changed, 17 insertions, 185 deletions
diff --git a/src/messenger_gtk.c b/src/messenger_gtk.c
index 7106645..7ec3da0 100644
--- a/src/messenger_gtk.c
+++ b/src/messenger_gtk.c
@@ -22,65 +22,12 @@
22 * @file messenger_gtk.c 22 * @file messenger_gtk.c
23 */ 23 */
24 24
25#include <stdbool.h> 25#include "chat/messenger.h"
26#include <stdio.h> 26#include "ui/messenger.h"
27 27
28#include <pthread.h> 28#include <pthread.h>
29 29
30#include <gtk-3.0/gtk/gtk.h> 30#define UNUSED __attribute__((unused))
31#include <libhandy-1/handy.h>
32
33#include <gnunet/gnunet_program_lib.h>
34#include <gnunet/gnunet_chat_lib.h>
35
36void handle_user_details_button_click(GtkButton* button,
37 gpointer user_data)
38{
39 HdyFlap* flap = HDY_FLAP(user_data);
40
41 if (TRUE == hdy_flap_get_reveal_flap(flap)) {
42 hdy_flap_set_reveal_flap(flap, FALSE);
43 } else {
44 hdy_flap_set_reveal_flap(flap, TRUE);
45 }
46}
47
48void handle_account_details_button_click(GtkButton* button,
49 gpointer user_data)
50{
51 GtkRevealer* revealer = GTK_REVEALER(user_data);
52
53 if (TRUE == gtk_revealer_get_reveal_child(revealer)) {
54 gtk_revealer_set_reveal_child(revealer, FALSE);
55 } else {
56 gtk_revealer_set_reveal_child(revealer, TRUE);
57 }
58}
59
60void handle_chats_listbox_row_activated(GtkListBox* listbox,
61 GtkListBoxRow* row,
62 gpointer user_data)
63{
64 HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
65
66 GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
67
68 if ((children) && (children->next)) {
69 hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->next->data));
70 }
71}
72
73void handle_back_button_click(GtkButton* button,
74 gpointer user_data)
75{
76 HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
77
78 GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
79
80 if (children) {
81 hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->data));
82 }
83}
84 31
85struct main_program 32struct main_program
86{ 33{
@@ -89,31 +36,27 @@ struct main_program
89 36
90 bool exit; 37 bool exit;
91 38
92 struct GNUNET_CHAT_Handle *chat; 39 struct CHAT_MESSENGER_Handle chat;
93 40 struct UI_MESSENGER_Handle ui;
94 HdyAvatar *profile_avatar;
95 GtkLabel *profile_label;
96
97 struct GNUNET_SCHEDULER_Task *idle;
98}; 41};
99 42
100gboolean gtk_set_profile_name(gpointer user_data) 43gboolean gtk_set_profile_name(gpointer user_data)
101{ 44{
102 struct main_program *program = (struct main_program*) user_data; 45 struct main_program *program = (struct main_program*) user_data;
103 46
104 const char *name = GNUNET_CHAT_get_name(program->chat); 47 const char *name = GNUNET_CHAT_get_name(program->chat.handle);
105 48
106 if (name) 49 if (name)
107 { 50 {
108 hdy_avatar_set_text(program->profile_avatar, name); 51 hdy_avatar_set_text(program->ui.profile_avatar, name);
109 gtk_label_set_text(program->profile_label, name); 52 gtk_label_set_text(program->ui.profile_label, name);
110 } 53 }
111 54
112 return FALSE; 55 return FALSE;
113} 56}
114 57
115int gnunet_chat_message(void *cls, 58int gnunet_chat_message(void *cls,
116 struct GNUNET_CHAT_Context *context, 59 UNUSED struct GNUNET_CHAT_Context *context,
117 const struct GNUNET_CHAT_Message *message) 60 const struct GNUNET_CHAT_Message *message)
118{ 61{
119 struct main_program *program = (struct main_program*) cls; 62 struct main_program *program = (struct main_program*) cls;
@@ -132,14 +75,14 @@ void gnunet_idle(void *cls)
132 75
133 if (program->exit) 76 if (program->exit)
134 { 77 {
135 GNUNET_CHAT_stop(program->chat); 78 GNUNET_CHAT_stop(program->chat.handle);
136 program->chat = NULL; 79 program->chat.handle = NULL;
137 80
138 GNUNET_SCHEDULER_shutdown(); 81 GNUNET_SCHEDULER_shutdown();
139 return; 82 return;
140 } 83 }
141 84
142 program->idle = GNUNET_SCHEDULER_add_delayed_with_priority( 85 program->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
143 GNUNET_TIME_relative_get_second_(), 86 GNUNET_TIME_relative_get_second_(),
144 GNUNET_SCHEDULER_PRIORITY_IDLE, 87 GNUNET_SCHEDULER_PRIORITY_IDLE,
145 gnunet_idle, 88 gnunet_idle,
@@ -148,13 +91,13 @@ void gnunet_idle(void *cls)
148} 91}
149 92
150void gnunet_task(void *cls, 93void gnunet_task(void *cls,
151 char *const *args, 94 UNUSED char *const *args,
152 const char *cfgfile, 95 UNUSED const char *cfgfile,
153 const struct GNUNET_CONFIGURATION_Handle *cfg) 96 const struct GNUNET_CONFIGURATION_Handle *cfg)
154{ 97{
155 struct main_program *program = (struct main_program*) cls; 98 struct main_program *program = (struct main_program*) cls;
156 99
157 program->chat = GNUNET_CHAT_start( 100 program->chat.handle = GNUNET_CHAT_start(
158 cfg, 101 cfg,
159 "messenger-gtk", 102 "messenger-gtk",
160 "test", 103 "test",
@@ -162,7 +105,7 @@ void gnunet_task(void *cls,
162 program 105 program
163 ); 106 );
164 107
165 program->idle = GNUNET_SCHEDULER_add_delayed_with_priority( 108 program->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
166 GNUNET_TIME_relative_get_zero_(), 109 GNUNET_TIME_relative_get_zero_(),
167 GNUNET_SCHEDULER_PRIORITY_IDLE, 110 GNUNET_SCHEDULER_PRIORITY_IDLE,
168 gnunet_idle, 111 gnunet_idle,
@@ -201,27 +144,7 @@ int main(int argc, char **argv) {
201 pthread_t gnunet_tid; 144 pthread_t gnunet_tid;
202 gtk_init(&argc, &argv); 145 gtk_init(&argc, &argv);
203 146
204 GtkBuilder* builder = gtk_builder_new();
205 gtk_builder_add_from_file(
206 builder,
207 "resources/ui/messenger.ui",
208 NULL
209 );
210
211 GtkApplicationWindow* window = GTK_APPLICATION_WINDOW(
212 gtk_builder_get_object(builder, "main_window")
213 );
214
215 program.profile_avatar = HDY_AVATAR(
216 gtk_builder_get_object(builder, "profile_avatar")
217 );
218
219 program.profile_label = GTK_LABEL(
220 gtk_builder_get_object(builder, "profile_label")
221 );
222
223 GdkScreen* screen = gdk_screen_get_default(); 147 GdkScreen* screen = gdk_screen_get_default();
224
225 GtkCssProvider* provider = gtk_css_provider_new(); 148 GtkCssProvider* provider = gtk_css_provider_new();
226 gtk_css_provider_load_from_path( 149 gtk_css_provider_load_from_path(
227 provider, 150 provider,
@@ -235,98 +158,7 @@ int main(int argc, char **argv) {
235 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION 158 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
236 ); 159 );
237 160
238 HdyHeaderBar* title_bar = HDY_HEADER_BAR( 161 ui_messenger_init(&(program.ui));
239 gtk_builder_get_object(builder, "title_bar")
240 );
241
242 HdyLeaflet* leaflet_chat = HDY_LEAFLET(
243 gtk_builder_get_object(builder, "leaflet_chat")
244 );
245
246 hdy_leaflet_set_homogeneous(leaflet_chat, FALSE, GTK_ORIENTATION_HORIZONTAL, FALSE);
247
248 GtkListBox* chats_listbox = GTK_LIST_BOX(
249 gtk_builder_get_object(builder, "chats_listbox")
250 );
251
252 g_signal_connect(
253 chats_listbox,
254 "row-activated",
255 G_CALLBACK(handle_chats_listbox_row_activated),
256 leaflet_chat
257 );
258
259 GtkButton* user_details_button = GTK_BUTTON(
260 gtk_builder_get_object(builder, "user_details_button")
261 );
262
263 GtkButton* hide_user_details_button = GTK_BUTTON(
264 gtk_builder_get_object(builder, "hide_user_details_button")
265 );
266
267 HdyFlap* flap_user_details = HDY_FLAP(
268 gtk_builder_get_object(builder, "flap_user_details")
269 );
270
271 g_signal_connect(
272 user_details_button,
273 "clicked",
274 G_CALLBACK(handle_user_details_button_click),
275 flap_user_details
276 );
277
278 g_signal_connect(
279 hide_user_details_button,
280 "clicked",
281 G_CALLBACK(handle_user_details_button_click),
282 flap_user_details
283 );
284
285 GtkButton* account_details_button = GTK_BUTTON(
286 gtk_builder_get_object(builder, "account_details_button")
287 );
288
289 GtkRevealer* account_details_revealer = GTK_REVEALER(
290 gtk_builder_get_object(builder, "account_details_revealer")
291 );
292
293 g_signal_connect(
294 account_details_button,
295 "clicked",
296 G_CALLBACK(handle_account_details_button_click),
297 account_details_revealer
298 );
299
300 GtkButton* back_button = GTK_BUTTON(
301 gtk_builder_get_object(builder, "back_button")
302 );
303
304 g_signal_connect(
305 back_button,
306 "clicked",
307 G_CALLBACK(handle_back_button_click),
308 leaflet_chat
309 );
310
311 g_object_bind_property(
312 leaflet_chat,
313 "folded",
314 back_button,
315 "visible",
316 G_BINDING_SYNC_CREATE
317 );
318
319 g_object_bind_property(
320 leaflet_chat,
321 "folded",
322 title_bar,
323 "show-close-button",
324 G_BINDING_INVERT_BOOLEAN
325 );
326
327 gtk_widget_show(GTK_WIDGET(window));
328
329 g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
330 162
331 pthread_create(&gnunet_tid, NULL, gnunet_thread, &program); 163 pthread_create(&gnunet_tid, NULL, gnunet_thread, &program);
332 164