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.c138
1 files changed, 137 insertions, 1 deletions
diff --git a/src/messenger_gtk.c b/src/messenger_gtk.c
index a07e6b3..7106645 100644
--- a/src/messenger_gtk.c
+++ b/src/messenger_gtk.c
@@ -22,9 +22,15 @@
22 * @file messenger_gtk.c 22 * @file messenger_gtk.c
23 */ 23 */
24 24
25#include <stdbool.h>
26#include <stdio.h>
27
28#include <pthread.h>
29
25#include <gtk-3.0/gtk/gtk.h> 30#include <gtk-3.0/gtk/gtk.h>
26#include <libhandy-1/handy.h> 31#include <libhandy-1/handy.h>
27 32
33#include <gnunet/gnunet_program_lib.h>
28#include <gnunet/gnunet_chat_lib.h> 34#include <gnunet/gnunet_chat_lib.h>
29 35
30void handle_user_details_button_click(GtkButton* button, 36void handle_user_details_button_click(GtkButton* button,
@@ -76,7 +82,123 @@ void handle_back_button_click(GtkButton* button,
76 } 82 }
77} 83}
78 84
79int main(int argc, char** argv) { 85struct main_program
86{
87 int argc;
88 char** argv;
89
90 bool exit;
91
92 struct GNUNET_CHAT_Handle *chat;
93
94 HdyAvatar *profile_avatar;
95 GtkLabel *profile_label;
96
97 struct GNUNET_SCHEDULER_Task *idle;
98};
99
100gboolean gtk_set_profile_name(gpointer user_data)
101{
102 struct main_program *program = (struct main_program*) user_data;
103
104 const char *name = GNUNET_CHAT_get_name(program->chat);
105
106 if (name)
107 {
108 hdy_avatar_set_text(program->profile_avatar, name);
109 gtk_label_set_text(program->profile_label, name);
110 }
111
112 return FALSE;
113}
114
115int gnunet_chat_message(void *cls,
116 struct GNUNET_CHAT_Context *context,
117 const struct GNUNET_CHAT_Message *message)
118{
119 struct main_program *program = (struct main_program*) cls;
120
121 printf("Hello world\n");
122
123 if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message))
124 g_idle_add(gtk_set_profile_name, program);
125
126 return GNUNET_YES;
127}
128
129void gnunet_idle(void *cls)
130{
131 struct main_program *program = (struct main_program*) cls;
132
133 if (program->exit)
134 {
135 GNUNET_CHAT_stop(program->chat);
136 program->chat = NULL;
137
138 GNUNET_SCHEDULER_shutdown();
139 return;
140 }
141
142 program->idle = GNUNET_SCHEDULER_add_delayed_with_priority(
143 GNUNET_TIME_relative_get_second_(),
144 GNUNET_SCHEDULER_PRIORITY_IDLE,
145 gnunet_idle,
146 program
147 );
148}
149
150void gnunet_task(void *cls,
151 char *const *args,
152 const char *cfgfile,
153 const struct GNUNET_CONFIGURATION_Handle *cfg)
154{
155 struct main_program *program = (struct main_program*) cls;
156
157 program->chat = GNUNET_CHAT_start(
158 cfg,
159 "messenger-gtk",
160 "test",
161 &gnunet_chat_message,
162 program
163 );
164
165 program->idle = GNUNET_SCHEDULER_add_delayed_with_priority(
166 GNUNET_TIME_relative_get_zero_(),
167 GNUNET_SCHEDULER_PRIORITY_IDLE,
168 gnunet_idle,
169 program
170 );
171}
172
173void *gnunet_thread(void *args)
174{
175 struct main_program *program = (struct main_program*) args;
176
177 struct GNUNET_GETOPT_CommandLineOption options[] = {
178 GNUNET_GETOPT_OPTION_END
179 };
180
181 GNUNET_PROGRAM_run(
182 program->argc,
183 program->argv,
184 "messenger-gtk",
185 gettext_noop("A GTK based GUI for the Messenger service of GNUnet."),
186 options,
187 &gnunet_task,
188 program
189 );
190
191 return NULL;
192}
193
194int main(int argc, char **argv) {
195 struct main_program program;
196 program.argc = argc;
197 program.argv = argv;
198
199 program.exit = FALSE;
200
201 pthread_t gnunet_tid;
80 gtk_init(&argc, &argv); 202 gtk_init(&argc, &argv);
81 203
82 GtkBuilder* builder = gtk_builder_new(); 204 GtkBuilder* builder = gtk_builder_new();
@@ -90,6 +212,14 @@ int main(int argc, char** argv) {
90 gtk_builder_get_object(builder, "main_window") 212 gtk_builder_get_object(builder, "main_window")
91 ); 213 );
92 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
93 GdkScreen* screen = gdk_screen_get_default(); 223 GdkScreen* screen = gdk_screen_get_default();
94 224
95 GtkCssProvider* provider = gtk_css_provider_new(); 225 GtkCssProvider* provider = gtk_css_provider_new();
@@ -198,6 +328,12 @@ int main(int argc, char** argv) {
198 328
199 g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); 329 g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
200 330
331 pthread_create(&gnunet_tid, NULL, gnunet_thread, &program);
332
201 gtk_main(); 333 gtk_main();
334
335 program.exit = TRUE;
336
337 pthread_join(gnunet_tid, NULL);
202 return 0; 338 return 0;
203} 339}