aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-10-30 02:49:42 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2021-10-30 02:49:42 +0200
commita435a928f6f6280761ee8a76225333d98f96a2b2 (patch)
treea24556948c3263ac7bb43ef735c74d23bfbc0f05
parent4a223f890d2bed4a29843b15d5d5e5f91e43bc20 (diff)
downloadmessenger-gtk-a435a928f6f6280761ee8a76225333d98f96a2b2.tar.gz
messenger-gtk-a435a928f6f6280761ee8a76225333d98f96a2b2.zip
Added second thread to link the ui with gnunet
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--Makefile4
-rw-r--r--resources/ui/messenger.ui4
-rw-r--r--src/messenger_gtk.c138
3 files changed, 141 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 1e512aa..9ffcdae 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ BINARY = messenger-gtk
6SOURCES = messenger_gtk.c 6SOURCES = messenger_gtk.c
7HEADERS = 7HEADERS =
8 8
9LIBRARIES = gnunetchat 9LIBRARIES = gnunetutil gnunetchat
10PACKAGES = libhandy-1 gtk+-3.0 libnotify 10PACKAGES = libhandy-1 gtk+-3.0 libnotify
11 11
12CC ?= gcc 12CC ?= gcc
@@ -14,7 +14,7 @@ LD ?= gcc
14RM ?= rm 14RM ?= rm
15 15
16CFLAGS += -pedantic -Wall -Wextra -march=native -ggdb3 16CFLAGS += -pedantic -Wall -Wextra -march=native -ggdb3
17LDFLAGS += 17LDFLAGS += -pthread
18 18
19DEBUGFLAGS = -O0 -D _DEBUG 19DEBUGFLAGS = -O0 -D _DEBUG
20RELEASEFLAGS = -O2 -D NDEBUG -fwhole-program 20RELEASEFLAGS = -O2 -D NDEBUG -fwhole-program
diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui
index 50b68b7..d0487fa 100644
--- a/resources/ui/messenger.ui
+++ b/resources/ui/messenger.ui
@@ -254,7 +254,7 @@ Author: Tobias Frisch
254 <property name="orientation">vertical</property> 254 <property name="orientation">vertical</property>
255 <property name="spacing">16</property> 255 <property name="spacing">16</property>
256 <child> 256 <child>
257 <object class="HdyAvatar"> 257 <object class="HdyAvatar" id="profile_avatar">
258 <property name="visible">True</property> 258 <property name="visible">True</property>
259 <property name="can-focus">False</property> 259 <property name="can-focus">False</property>
260 <property name="halign">start</property> 260 <property name="halign">start</property>
@@ -267,7 +267,7 @@ Author: Tobias Frisch
267 </packing> 267 </packing>
268 </child> 268 </child>
269 <child> 269 <child>
270 <object class="GtkLabel"> 270 <object class="GtkLabel" id="profile_label">
271 <property name="visible">True</property> 271 <property name="visible">True</property>
272 <property name="can-focus">False</property> 272 <property name="can-focus">False</property>
273 <property name="label" translatable="yes">Profile name</property> 273 <property name="label" translatable="yes">Profile name</property>
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}