diff options
Diffstat (limited to 'src/application.c')
-rw-r--r-- | src/application.c | 147 |
1 files changed, 147 insertions, 0 deletions
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 | } | ||