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.c145
1 files changed, 5 insertions, 140 deletions
diff --git a/src/messenger_gtk.c b/src/messenger_gtk.c
index a91a35e..dc2c87a 100644
--- a/src/messenger_gtk.c
+++ b/src/messenger_gtk.c
@@ -22,148 +22,13 @@
22 * @file messenger_gtk.c 22 * @file messenger_gtk.c
23 */ 23 */
24 24
25#include "chat/messenger.h" 25#include "application.h"
26#include "ui/messenger.h"
27
28#include <pthread.h>
29
30#define UNUSED __attribute__((unused))
31
32struct main_program
33{
34 int argc;
35 char** argv;
36
37 bool exit;
38
39 struct CHAT_MESSENGER_Handle chat;
40 struct UI_MESSENGER_Handle ui;
41};
42
43gboolean gtk_set_profile_name(gpointer user_data)
44{
45 struct main_program *program = (struct main_program*) user_data;
46
47 const char *name = GNUNET_CHAT_get_name(program->chat.handle);
48
49 if (name)
50 {
51 hdy_avatar_set_text(program->ui.profile_avatar, name);
52 gtk_label_set_text(program->ui.profile_label, name);
53 }
54
55 return FALSE;
56}
57
58int gnunet_chat_message(void *cls,
59 UNUSED struct GNUNET_CHAT_Context *context,
60 const struct GNUNET_CHAT_Message *message)
61{
62 struct main_program *program = (struct main_program*) cls;
63
64 if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message))
65 g_idle_add(gtk_set_profile_name, program);
66
67 return GNUNET_YES;
68}
69
70void gnunet_idle(void *cls)
71{
72 struct main_program *program = (struct main_program*) cls;
73
74 if (program->exit)
75 {
76 GNUNET_CHAT_stop(program->chat.handle);
77 program->chat.handle = NULL;
78
79 GNUNET_SCHEDULER_shutdown();
80 return;
81 }
82
83 program->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
84 GNUNET_TIME_relative_get_second_(),
85 GNUNET_SCHEDULER_PRIORITY_IDLE,
86 gnunet_idle,
87 program
88 );
89}
90
91void gnunet_task(void *cls,
92 UNUSED char *const *args,
93 UNUSED const char *cfgfile,
94 const struct GNUNET_CONFIGURATION_Handle *cfg)
95{
96 struct main_program *program = (struct main_program*) cls;
97
98 program->chat.handle = GNUNET_CHAT_start(
99 cfg,
100 "messenger-gtk",
101 "test",
102 &gnunet_chat_message,
103 program
104 );
105
106 program->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
107 GNUNET_TIME_relative_get_zero_(),
108 GNUNET_SCHEDULER_PRIORITY_IDLE,
109 gnunet_idle,
110 program
111 );
112}
113
114void *gnunet_thread(void *args)
115{
116 struct main_program *program = (struct main_program*) args;
117
118 struct GNUNET_GETOPT_CommandLineOption options[] = {
119 GNUNET_GETOPT_OPTION_END
120 };
121
122 GNUNET_PROGRAM_run(
123 program->argc,
124 program->argv,
125 "messenger-gtk",
126 gettext_noop("A GTK based GUI for the Messenger service of GNUnet."),
127 options,
128 &gnunet_task,
129 program
130 );
131
132 return NULL;
133}
134 26
135int main(int argc, char **argv) { 27int main(int argc, char **argv) {
136 struct main_program program; 28 MESSENGER_Application app;
137 program.argc = argc;
138 program.argv = argv;
139
140 program.exit = FALSE;
141
142 pthread_t gnunet_tid;
143 gtk_init(&argc, &argv);
144
145 GdkScreen* screen = gdk_screen_get_default();
146 GtkCssProvider* provider = gtk_css_provider_new();
147 gtk_css_provider_load_from_path(
148 provider,
149 "resources/css/style.css",
150 NULL
151 );
152
153 gtk_style_context_add_provider_for_screen(
154 screen,
155 GTK_STYLE_PROVIDER(provider),
156 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
157 );
158
159 ui_messenger_init(&(program.ui));
160
161 pthread_create(&gnunet_tid, NULL, gnunet_thread, &program);
162
163 gtk_main();
164 29
165 program.exit = TRUE; 30 application_init(&app, argc, argv);
31 application_start(&app);
166 32
167 pthread_join(gnunet_tid, NULL); 33 return application_status(&app);
168 return 0;
169} 34}