diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-10-30 21:13:51 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-10-30 21:13:51 +0200 |
commit | ee55ecb8712955fc1d982b3a271c909896eb0631 (patch) | |
tree | f7413f1a3bd1ec433f3a7aa506c012ada82812ca | |
parent | 7e0a36c3954f7a054a3a7acab1cdfb239a466917 (diff) | |
download | messenger-gtk-ee55ecb8712955fc1d982b3a271c909896eb0631.tar.gz messenger-gtk-ee55ecb8712955fc1d982b3a271c909896eb0631.zip |
Separated gtk, gnunet and events using both
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | resources/ui/messenger.ui | 1 | ||||
-rw-r--r-- | src/application.c | 147 | ||||
-rw-r--r-- | src/application.h | 83 | ||||
-rw-r--r-- | src/chat/messenger.c | 61 | ||||
-rw-r--r-- | src/chat/messenger.h | 12 | ||||
-rw-r--r-- | src/event.c | 41 | ||||
-rw-r--r-- | src/event.h | 33 | ||||
-rw-r--r-- | src/messenger_gtk.c | 145 | ||||
-rw-r--r-- | src/ui/messenger.c | 42 | ||||
-rw-r--r-- | src/ui/messenger.h | 12 | ||||
-rw-r--r-- | src/util.h | 30 |
12 files changed, 452 insertions, 157 deletions
@@ -4,6 +4,8 @@ INSTALL_DIR ?= /usr/local/ | |||
4 | 4 | ||
5 | BINARY = messenger-gtk | 5 | BINARY = messenger-gtk |
6 | SOURCES = messenger_gtk.c\ | 6 | SOURCES = messenger_gtk.c\ |
7 | application.c\ | ||
8 | event.c\ | ||
7 | chat/messenger.c\ | 9 | chat/messenger.c\ |
8 | ui/messenger.c | 10 | ui/messenger.c |
9 | 11 | ||
diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui index a776361..d6e2b1d 100644 --- a/resources/ui/messenger.ui +++ b/resources/ui/messenger.ui | |||
@@ -31,6 +31,7 @@ Author: Tobias Frisch | |||
31 | <property name="can-focus">False</property> | 31 | <property name="can-focus">False</property> |
32 | <property name="hhomogeneous-folded">False</property> | 32 | <property name="hhomogeneous-folded">False</property> |
33 | <property name="vhomogeneous-folded">False</property> | 33 | <property name="vhomogeneous-folded">False</property> |
34 | <property name="can-swipe-back">True</property> | ||
34 | <child> | 35 | <child> |
35 | <object class="GtkBox"> | 36 | <object class="GtkBox"> |
36 | <property name="visible">True</property> | 37 | <property name="visible">True</property> |
diff --git a/src/application.c b/src/application.c new file mode 100644 index 0000000..e597bfb --- /dev/null +++ b/src/application.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file application.c | ||
23 | */ | ||
24 | |||
25 | #include "application.h" | ||
26 | |||
27 | static void | ||
28 | _load_ui_stylesheets(void) | ||
29 | { | ||
30 | GdkScreen* screen = gdk_screen_get_default(); | ||
31 | GtkCssProvider* provider = gtk_css_provider_new(); | ||
32 | gtk_css_provider_load_from_path( | ||
33 | provider, | ||
34 | "resources/css/style.css", | ||
35 | NULL | ||
36 | ); | ||
37 | |||
38 | gtk_style_context_add_provider_for_screen( | ||
39 | screen, | ||
40 | GTK_STYLE_PROVIDER(provider), | ||
41 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION | ||
42 | ); | ||
43 | } | ||
44 | |||
45 | void | ||
46 | application_init(MESSENGER_Application *app, | ||
47 | int argc, | ||
48 | char **argv) | ||
49 | { | ||
50 | app->argc = argc; | ||
51 | app->argv = argv; | ||
52 | |||
53 | gtk_init(&argc, &argv); | ||
54 | |||
55 | _load_ui_stylesheets(); | ||
56 | |||
57 | app->chat.status = EXIT_FAILURE; | ||
58 | app->chat.tid = 0; | ||
59 | app->chat.signal = MESSENGER_NONE; | ||
60 | |||
61 | ui_messenger_init(app, &(app->ui.messenger)); | ||
62 | } | ||
63 | |||
64 | static void* | ||
65 | _application_chat_thread(void *args) | ||
66 | { | ||
67 | MESSENGER_Application *app = (MESSENGER_Application*) args; | ||
68 | |||
69 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
70 | GNUNET_GETOPT_OPTION_END | ||
71 | }; | ||
72 | |||
73 | app->chat.status = (GNUNET_PROGRAM_run( | ||
74 | app->argc, | ||
75 | app->argv, | ||
76 | "messenger-gtk", | ||
77 | gettext_noop("A GTK based GUI for the Messenger service of GNUnet."), | ||
78 | options, | ||
79 | &chat_messenger_run, | ||
80 | app | ||
81 | ) == GNUNET_OK? EXIT_SUCCESS : EXIT_FAILURE); | ||
82 | |||
83 | return NULL; | ||
84 | } | ||
85 | |||
86 | void | ||
87 | application_start(MESSENGER_Application *app) | ||
88 | { | ||
89 | pthread_create(&(app->chat.tid), NULL, _application_chat_thread, app); | ||
90 | |||
91 | gtk_main(); | ||
92 | |||
93 | pthread_join(app->chat.tid, NULL); | ||
94 | } | ||
95 | |||
96 | typedef struct MESSENGER_ApplicationEventCall | ||
97 | { | ||
98 | MESSENGER_Application *app; | ||
99 | MESSENGER_ApplicationEvent event; | ||
100 | } MESSENGER_ApplicationEventCall; | ||
101 | |||
102 | static gboolean | ||
103 | _application_event_call(gpointer user_data) | ||
104 | { | ||
105 | //printf("_application_event_call\n"); | ||
106 | |||
107 | MESSENGER_ApplicationEventCall *call; | ||
108 | |||
109 | call = (MESSENGER_ApplicationEventCall*) user_data; | ||
110 | call->event(call->app); | ||
111 | |||
112 | GNUNET_free(call); | ||
113 | return FALSE; | ||
114 | } | ||
115 | |||
116 | void | ||
117 | application_call_event(MESSENGER_Application *app, | ||
118 | MESSENGER_ApplicationEvent event) | ||
119 | { | ||
120 | //printf("application_call_event\n"); | ||
121 | |||
122 | MESSENGER_ApplicationEventCall *call; | ||
123 | |||
124 | call = (MESSENGER_ApplicationEventCall*) GNUNET_malloc( | ||
125 | sizeof(MESSENGER_ApplicationEventCall) | ||
126 | ); | ||
127 | |||
128 | call->app = app; | ||
129 | call->event = event; | ||
130 | |||
131 | g_idle_add(_application_event_call, call); | ||
132 | } | ||
133 | |||
134 | void | ||
135 | application_exit(MESSENGER_Application *app, | ||
136 | MESSENGER_ApplicationSignal signal) | ||
137 | { | ||
138 | app->chat.signal = signal; | ||
139 | |||
140 | gtk_main_quit(); | ||
141 | } | ||
142 | |||
143 | int | ||
144 | application_status(MESSENGER_Application *app) | ||
145 | { | ||
146 | return app->chat.status; | ||
147 | } | ||
diff --git a/src/application.h b/src/application.h new file mode 100644 index 0000000..6e35bf6 --- /dev/null +++ b/src/application.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file application.h | ||
23 | */ | ||
24 | |||
25 | #ifndef APPLICATION_H_ | ||
26 | #define APPLICATION_H_ | ||
27 | |||
28 | #include <pthread.h> | ||
29 | |||
30 | #include "chat/messenger.h" | ||
31 | |||
32 | #include "ui/messenger.h" | ||
33 | |||
34 | #include "util.h" | ||
35 | |||
36 | typedef enum MESSENGER_ApplicationSignal | ||
37 | { | ||
38 | MESSENGER_NONE = 0, | ||
39 | MESSENGER_QUIT = 1, | ||
40 | MESSENGER_FAIL = 2 | ||
41 | } MESSENGER_ApplicationSignal; | ||
42 | |||
43 | typedef struct MESSENGER_Application | ||
44 | { | ||
45 | char** argv; | ||
46 | int argc; | ||
47 | |||
48 | struct { | ||
49 | int status; | ||
50 | pthread_t tid; | ||
51 | |||
52 | MESSENGER_ApplicationSignal signal; | ||
53 | |||
54 | CHAT_MESSENGER_Handle messenger; | ||
55 | } chat; | ||
56 | |||
57 | struct { | ||
58 | UI_MESSENGER_Handle messenger; | ||
59 | } ui; | ||
60 | } MESSENGER_Application; | ||
61 | |||
62 | void | ||
63 | application_init(MESSENGER_Application *app, | ||
64 | int argc, | ||
65 | char **argv); | ||
66 | |||
67 | void | ||
68 | application_start(MESSENGER_Application *app); | ||
69 | |||
70 | typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app); | ||
71 | |||
72 | void | ||
73 | application_call_event(MESSENGER_Application *app, | ||
74 | MESSENGER_ApplicationEvent event); | ||
75 | |||
76 | void | ||
77 | application_exit(MESSENGER_Application *app, | ||
78 | MESSENGER_ApplicationSignal signal); | ||
79 | |||
80 | int | ||
81 | application_status(MESSENGER_Application *app); | ||
82 | |||
83 | #endif /* APPLICATION_H_ */ | ||
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index 56dc016..2996af3 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c | |||
@@ -24,4 +24,65 @@ | |||
24 | 24 | ||
25 | #include "messenger.h" | 25 | #include "messenger.h" |
26 | 26 | ||
27 | #include "../event.h" | ||
27 | 28 | ||
29 | static void | ||
30 | _chat_messenger_idle(void *cls) | ||
31 | { | ||
32 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | ||
33 | |||
34 | if (MESSENGER_NONE == app->chat.signal) | ||
35 | { | ||
36 | app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority( | ||
37 | GNUNET_TIME_relative_get_second_(), | ||
38 | GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
39 | &_chat_messenger_idle, | ||
40 | app | ||
41 | ); | ||
42 | |||
43 | return; | ||
44 | } | ||
45 | |||
46 | GNUNET_CHAT_stop(app->chat.messenger.handle); | ||
47 | app->chat.messenger.handle = NULL; | ||
48 | |||
49 | if (MESSENGER_QUIT != app->chat.signal) | ||
50 | GNUNET_SCHEDULER_shutdown(); | ||
51 | } | ||
52 | |||
53 | static int | ||
54 | _chat_messenger_message(void *cls, | ||
55 | UNUSED struct GNUNET_CHAT_Context *context, | ||
56 | const struct GNUNET_CHAT_Message *message) | ||
57 | { | ||
58 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | ||
59 | |||
60 | if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message)) | ||
61 | application_call_event(app, event_update_profile); | ||
62 | |||
63 | return GNUNET_YES; | ||
64 | } | ||
65 | |||
66 | void | ||
67 | chat_messenger_run(void *cls, | ||
68 | UNUSED char *const *args, | ||
69 | UNUSED const char *cfgfile, | ||
70 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
71 | { | ||
72 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | ||
73 | |||
74 | app->chat.messenger.handle = GNUNET_CHAT_start( | ||
75 | cfg, | ||
76 | "messenger-gtk", | ||
77 | "test", | ||
78 | &_chat_messenger_message, | ||
79 | app | ||
80 | ); | ||
81 | |||
82 | app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority( | ||
83 | GNUNET_TIME_relative_get_zero_(), | ||
84 | GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
85 | &_chat_messenger_idle, | ||
86 | app | ||
87 | ); | ||
88 | } | ||
diff --git a/src/chat/messenger.h b/src/chat/messenger.h index 13a427c..4e3f80a 100644 --- a/src/chat/messenger.h +++ b/src/chat/messenger.h | |||
@@ -30,10 +30,18 @@ | |||
30 | #include <gnunet/gnunet_common.h> | 30 | #include <gnunet/gnunet_common.h> |
31 | #include <gnunet/gnunet_program_lib.h> | 31 | #include <gnunet/gnunet_program_lib.h> |
32 | 32 | ||
33 | struct CHAT_MESSENGER_Handle | 33 | typedef struct MESSENGER_Application MESSENGER_Application; |
34 | |||
35 | typedef struct CHAT_MESSENGER_Handle | ||
34 | { | 36 | { |
35 | struct GNUNET_CHAT_Handle *handle; | 37 | struct GNUNET_CHAT_Handle *handle; |
36 | struct GNUNET_SCHEDULER_Task *idle; | 38 | struct GNUNET_SCHEDULER_Task *idle; |
37 | }; | 39 | } CHAT_MESSENGER_Handle; |
40 | |||
41 | void | ||
42 | chat_messenger_run(void *cls, | ||
43 | char *const *args, | ||
44 | const char *cfgfile, | ||
45 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
38 | 46 | ||
39 | #endif /* CHAT_MESSENGER_H_ */ | 47 | #endif /* CHAT_MESSENGER_H_ */ |
diff --git a/src/event.c b/src/event.c new file mode 100644 index 0000000..de009b4 --- /dev/null +++ b/src/event.c | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file event.c | ||
23 | */ | ||
24 | |||
25 | #include "event.h" | ||
26 | |||
27 | void | ||
28 | event_update_profile(MESSENGER_Application *app) | ||
29 | { | ||
30 | //printf("event_update_profile\n"); | ||
31 | |||
32 | const char *name = GNUNET_CHAT_get_name(app->chat.messenger.handle); | ||
33 | |||
34 | //printf("A: %s\n", name); | ||
35 | |||
36 | if (name) | ||
37 | { | ||
38 | hdy_avatar_set_text(app->ui.messenger.profile_avatar, name); | ||
39 | gtk_label_set_text(app->ui.messenger.profile_label, name); | ||
40 | } | ||
41 | } | ||
diff --git a/src/event.h b/src/event.h new file mode 100644 index 0000000..4beb589 --- /dev/null +++ b/src/event.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file event.h | ||
23 | */ | ||
24 | |||
25 | #ifndef EVENT_H_ | ||
26 | #define EVENT_H_ | ||
27 | |||
28 | #include "application.h" | ||
29 | |||
30 | void | ||
31 | event_update_profile(MESSENGER_Application *app); | ||
32 | |||
33 | #endif /* EVENT_H_ */ | ||
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 | |||
32 | struct 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 | |||
43 | gboolean 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 | |||
58 | int 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 | |||
70 | void 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 | |||
91 | void 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 | |||
114 | void *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 | ||
135 | int main(int argc, char **argv) { | 27 | int 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 | } |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 059927a..5a9796f 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -24,8 +24,11 @@ | |||
24 | 24 | ||
25 | #include "messenger.h" | 25 | #include "messenger.h" |
26 | 26 | ||
27 | void handle_flap_via_button_click(UI_UNUSED GtkButton* button, | 27 | #include "../application.h" |
28 | gpointer user_data) | 28 | |
29 | static void | ||
30 | handle_flap_via_button_click(UNUSED GtkButton* button, | ||
31 | gpointer user_data) | ||
29 | { | 32 | { |
30 | HdyFlap* flap = HDY_FLAP(user_data); | 33 | HdyFlap* flap = HDY_FLAP(user_data); |
31 | 34 | ||
@@ -36,8 +39,9 @@ void handle_flap_via_button_click(UI_UNUSED GtkButton* button, | |||
36 | } | 39 | } |
37 | } | 40 | } |
38 | 41 | ||
39 | void handle_account_details_button_click(UI_UNUSED GtkButton* button, | 42 | static void |
40 | gpointer user_data) | 43 | handle_account_details_button_click(UNUSED GtkButton* button, |
44 | gpointer user_data) | ||
41 | { | 45 | { |
42 | GtkRevealer* revealer = GTK_REVEALER(user_data); | 46 | GtkRevealer* revealer = GTK_REVEALER(user_data); |
43 | 47 | ||
@@ -48,9 +52,10 @@ void handle_account_details_button_click(UI_UNUSED GtkButton* button, | |||
48 | } | 52 | } |
49 | } | 53 | } |
50 | 54 | ||
51 | void handle_chats_listbox_row_activated(UI_UNUSED GtkListBox* listbox, | 55 | static void |
52 | UI_UNUSED GtkListBoxRow* row, | 56 | handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, |
53 | gpointer user_data) | 57 | UNUSED GtkListBoxRow* row, |
58 | gpointer user_data) | ||
54 | { | 59 | { |
55 | HdyLeaflet* leaflet = HDY_LEAFLET(user_data); | 60 | HdyLeaflet* leaflet = HDY_LEAFLET(user_data); |
56 | 61 | ||
@@ -61,8 +66,9 @@ void handle_chats_listbox_row_activated(UI_UNUSED GtkListBox* listbox, | |||
61 | } | 66 | } |
62 | } | 67 | } |
63 | 68 | ||
64 | void handle_back_button_click(UI_UNUSED GtkButton* button, | 69 | static void |
65 | gpointer user_data) | 70 | handle_back_button_click(UNUSED GtkButton* button, |
71 | gpointer user_data) | ||
66 | { | 72 | { |
67 | HdyLeaflet* leaflet = HDY_LEAFLET(user_data); | 73 | HdyLeaflet* leaflet = HDY_LEAFLET(user_data); |
68 | 74 | ||
@@ -73,8 +79,17 @@ void handle_back_button_click(UI_UNUSED GtkButton* button, | |||
73 | } | 79 | } |
74 | } | 80 | } |
75 | 81 | ||
82 | static void | ||
83 | handle_main_window_destroy(gpointer user_data) | ||
84 | { | ||
85 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
86 | |||
87 | application_exit(app, MESSENGER_QUIT); | ||
88 | } | ||
89 | |||
76 | void | 90 | void |
77 | ui_messenger_init(struct UI_MESSENGER_Handle *handle) | 91 | ui_messenger_init(MESSENGER_Application *app, |
92 | UI_MESSENGER_Handle *handle) | ||
78 | { | 93 | { |
79 | GtkBuilder* builder = gtk_builder_new(); | 94 | GtkBuilder* builder = gtk_builder_new(); |
80 | gtk_builder_add_from_file( | 95 | gtk_builder_add_from_file( |
@@ -220,5 +235,10 @@ ui_messenger_init(struct UI_MESSENGER_Handle *handle) | |||
220 | 235 | ||
221 | gtk_widget_show(GTK_WIDGET(handle->main_window)); | 236 | gtk_widget_show(GTK_WIDGET(handle->main_window)); |
222 | 237 | ||
223 | g_signal_connect(handle->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL); | 238 | g_signal_connect( |
239 | handle->main_window, | ||
240 | "destroy", | ||
241 | G_CALLBACK(handle_main_window_destroy), | ||
242 | app | ||
243 | ); | ||
224 | } | 244 | } |
diff --git a/src/ui/messenger.h b/src/ui/messenger.h index b309dea..ed37ad3 100644 --- a/src/ui/messenger.h +++ b/src/ui/messenger.h | |||
@@ -28,9 +28,9 @@ | |||
28 | #include <gtk-3.0/gtk/gtk.h> | 28 | #include <gtk-3.0/gtk/gtk.h> |
29 | #include <libhandy-1/handy.h> | 29 | #include <libhandy-1/handy.h> |
30 | 30 | ||
31 | #define UI_UNUSED __attribute__((unused)) | 31 | typedef struct MESSENGER_Application MESSENGER_Application; |
32 | 32 | ||
33 | struct UI_MESSENGER_Handle | 33 | typedef struct UI_MESSENGER_Handle |
34 | { | 34 | { |
35 | GtkApplicationWindow *main_window; | 35 | GtkApplicationWindow *main_window; |
36 | 36 | ||
@@ -67,9 +67,13 @@ struct UI_MESSENGER_Handle | |||
67 | GtkButton *chat_details_button; | 67 | GtkButton *chat_details_button; |
68 | 68 | ||
69 | GtkButton *hide_chat_details_button; | 69 | GtkButton *hide_chat_details_button; |
70 | }; | 70 | } UI_MESSENGER_Handle; |
71 | 71 | ||
72 | void | 72 | void |
73 | ui_messenger_init(struct UI_MESSENGER_Handle *handle); | 73 | ui_messenger_init(MESSENGER_Application *app, |
74 | UI_MESSENGER_Handle *handle); | ||
75 | |||
76 | void | ||
77 | ui_messenger_update_profile(MESSENGER_Application *app); | ||
74 | 78 | ||
75 | #endif /* UI_MESSENGER_H_ */ | 79 | #endif /* UI_MESSENGER_H_ */ |
diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..68920e2 --- /dev/null +++ b/src/util.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file util.h | ||
23 | */ | ||
24 | |||
25 | #ifndef UTIL_H_ | ||
26 | #define UTIL_H_ | ||
27 | |||
28 | #define UNUSED __attribute__((unused)) | ||
29 | |||
30 | #endif /* UTIL_H_ */ | ||