diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/application.h | 2 | ||||
-rw-r--r-- | src/ui/Makefile.am | 1 | ||||
-rw-r--r-- | src/ui/picker.c | 18 | ||||
-rw-r--r-- | src/ui/play_media.c | 287 | ||||
-rw-r--r-- | src/ui/play_media.h | 79 |
5 files changed, 386 insertions, 1 deletions
diff --git a/src/application.h b/src/application.h index f3b4407..2dc4696 100644 --- a/src/application.h +++ b/src/application.h | |||
@@ -42,6 +42,7 @@ | |||
42 | #include "ui/new_group.h" | 42 | #include "ui/new_group.h" |
43 | #include "ui/new_lobby.h" | 43 | #include "ui/new_lobby.h" |
44 | #include "ui/new_platform.h" | 44 | #include "ui/new_platform.h" |
45 | #include "ui/play_media.h" | ||
45 | #include "ui/send_file.h" | 46 | #include "ui/send_file.h" |
46 | #include "ui/settings.h" | 47 | #include "ui/settings.h" |
47 | 48 | ||
@@ -100,6 +101,7 @@ typedef struct MESSENGER_Application | |||
100 | UI_DELETE_MESSAGES_Handle delete_messages; | 101 | UI_DELETE_MESSAGES_Handle delete_messages; |
101 | UI_INVITE_CONTACT_Handle invite_contact; | 102 | UI_INVITE_CONTACT_Handle invite_contact; |
102 | UI_SEND_FILE_Handle send_file; | 103 | UI_SEND_FILE_Handle send_file; |
104 | UI_PLAY_MEDIA_Handle play_media; | ||
103 | 105 | ||
104 | UI_NEW_CONTACT_Handle new_contact; | 106 | UI_NEW_CONTACT_Handle new_contact; |
105 | UI_NEW_GROUP_Handle new_group; | 107 | UI_NEW_GROUP_Handle new_group; |
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index b30f8ee..3e6cbf7 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am | |||
@@ -32,6 +32,7 @@ libui_a_SOURCES = \ | |||
32 | new_lobby.c new_lobby.h \ | 32 | new_lobby.c new_lobby.h \ |
33 | new_platform.c new_platform.h \ | 33 | new_platform.c new_platform.h \ |
34 | picker.c picker.h \ | 34 | picker.c picker.h \ |
35 | play_media.c play_media.h \ | ||
35 | send_file.c send_file.h \ | 36 | send_file.c send_file.h \ |
36 | settings.c settings.h | 37 | settings.c settings.h |
37 | 38 | ||
diff --git a/src/ui/picker.c b/src/ui/picker.c index 09ccf09..ca8423e 100644 --- a/src/ui/picker.c +++ b/src/ui/picker.c | |||
@@ -95,8 +95,17 @@ handle_search_button_click(UNUSED GtkButton *button, | |||
95 | ); | 95 | ); |
96 | } | 96 | } |
97 | 97 | ||
98 | static void | ||
99 | handle_settings_button_click(UNUSED GtkButton *button, | ||
100 | gpointer user_data) | ||
101 | { | ||
102 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
103 | ui_play_media_window_init(app, &(app->ui.play_media)); | ||
104 | gtk_widget_show(GTK_WIDGET(app->ui.play_media.window)); | ||
105 | } | ||
106 | |||
98 | UI_PICKER_Handle* | 107 | UI_PICKER_Handle* |
99 | ui_picker_new(UNUSED MESSENGER_Application *app, | 108 | ui_picker_new(MESSENGER_Application *app, |
100 | UI_CHAT_Handle *chat) | 109 | UI_CHAT_Handle *chat) |
101 | { | 110 | { |
102 | UI_PICKER_Handle *handle = g_malloc(sizeof(UI_PICKER_Handle)); | 111 | UI_PICKER_Handle *handle = g_malloc(sizeof(UI_PICKER_Handle)); |
@@ -244,6 +253,13 @@ ui_picker_new(UNUSED MESSENGER_Application *app, | |||
244 | gtk_builder_get_object(handle->builder, "settings_button") | 253 | gtk_builder_get_object(handle->builder, "settings_button") |
245 | ); | 254 | ); |
246 | 255 | ||
256 | g_signal_connect( | ||
257 | handle->settings_button, | ||
258 | "clicked", | ||
259 | G_CALLBACK(handle_settings_button_click), | ||
260 | app | ||
261 | ); | ||
262 | |||
247 | return handle; | 263 | return handle; |
248 | } | 264 | } |
249 | 265 | ||
diff --git a/src/ui/play_media.c b/src/ui/play_media.c new file mode 100644 index 0000000..dc41a3e --- /dev/null +++ b/src/ui/play_media.c | |||
@@ -0,0 +1,287 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 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 ui/play_media.c | ||
23 | */ | ||
24 | |||
25 | #include "play_media.h" | ||
26 | |||
27 | #include "../application.h" | ||
28 | #include "../ui.h" | ||
29 | |||
30 | static void | ||
31 | handle_back_button_click(GtkButton *button, | ||
32 | gpointer user_data) | ||
33 | { | ||
34 | GtkWindow *window = GTK_WINDOW(user_data); | ||
35 | gtk_window_close(window); | ||
36 | } | ||
37 | |||
38 | static void | ||
39 | _pause_playing_media(UI_PLAY_MEDIA_Handle *handle) | ||
40 | { | ||
41 | // | ||
42 | |||
43 | handle->playing = FALSE; | ||
44 | } | ||
45 | |||
46 | static void | ||
47 | _continue_playing_media(UI_PLAY_MEDIA_Handle *handle) | ||
48 | { | ||
49 | // | ||
50 | |||
51 | handle->playing = TRUE; | ||
52 | } | ||
53 | |||
54 | static void | ||
55 | handle_play_pause_button_click(GtkButton *button, | ||
56 | gpointer user_data) | ||
57 | { | ||
58 | UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) user_data; | ||
59 | |||
60 | if (handle->playing) | ||
61 | _pause_playing_media(handle); | ||
62 | else | ||
63 | _continue_playing_media(handle); | ||
64 | |||
65 | gtk_stack_set_visible_child_name( | ||
66 | handle->play_symbol_stack, | ||
67 | handle->playing? "pause_page" : "play_page" | ||
68 | ); | ||
69 | } | ||
70 | |||
71 | static void | ||
72 | handle_fullscreen_button_click(GtkButton *button, | ||
73 | gpointer user_data) | ||
74 | { | ||
75 | UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) user_data; | ||
76 | |||
77 | gtk_revealer_set_reveal_child(handle->header_revealer, handle->fullscreen); | ||
78 | hdy_flap_set_reveal_flap(handle->controls_flap, handle->fullscreen); | ||
79 | |||
80 | handle->fullscreen = !(handle->fullscreen); | ||
81 | |||
82 | if (!(handle->fullscreen)) | ||
83 | gtk_window_unfullscreen(GTK_WINDOW(handle->window)); | ||
84 | |||
85 | gtk_widget_hide(GTK_WIDGET(handle->window)); | ||
86 | |||
87 | gtk_window_set_type_hint( | ||
88 | GTK_WINDOW(handle->window), | ||
89 | handle->fullscreen? | ||
90 | GDK_WINDOW_TYPE_HINT_NORMAL : | ||
91 | GDK_WINDOW_TYPE_HINT_DIALOG | ||
92 | ); | ||
93 | |||
94 | gtk_window_set_modal(GTK_WINDOW(handle->window), !(handle->fullscreen)); | ||
95 | |||
96 | gtk_window_set_position( | ||
97 | GTK_WINDOW(handle->window), | ||
98 | handle->fullscreen? GTK_WIN_POS_NONE : GTK_WIN_POS_CENTER_ON_PARENT | ||
99 | ); | ||
100 | |||
101 | gtk_window_set_transient_for( | ||
102 | GTK_WINDOW(handle->window), | ||
103 | handle->fullscreen? NULL : handle->parent | ||
104 | ); | ||
105 | |||
106 | gtk_widget_show_all(GTK_WIDGET(handle->window)); | ||
107 | |||
108 | if (handle->fullscreen) | ||
109 | gtk_window_fullscreen(GTK_WINDOW(handle->window)); | ||
110 | |||
111 | gtk_stack_set_visible_child_name( | ||
112 | handle->fullscreen_symbol_stack, | ||
113 | handle->fullscreen? "scale_down_page" : "scale_up_page" | ||
114 | ); | ||
115 | } | ||
116 | |||
117 | static gboolean | ||
118 | handle_media_motion_lost(gpointer user_data) | ||
119 | { | ||
120 | UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) user_data; | ||
121 | |||
122 | if (!(hdy_flap_get_reveal_flap(handle->controls_flap))) | ||
123 | return FALSE; | ||
124 | |||
125 | hdy_flap_set_reveal_flap(handle->controls_flap, FALSE); | ||
126 | handle->motion_lost = 0; | ||
127 | return FALSE; | ||
128 | } | ||
129 | |||
130 | static gboolean | ||
131 | handle_media_motion_notify(GtkWidget *widget, | ||
132 | GdkEvent *event, | ||
133 | gpointer user_data) | ||
134 | { | ||
135 | UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) user_data; | ||
136 | |||
137 | if (hdy_flap_get_reveal_flap(handle->controls_flap)) | ||
138 | return FALSE; | ||
139 | |||
140 | if (handle->motion_lost) | ||
141 | g_source_remove(handle->motion_lost); | ||
142 | |||
143 | hdy_flap_set_reveal_flap(handle->controls_flap, TRUE); | ||
144 | handle->motion_lost = g_timeout_add_seconds( | ||
145 | 3, | ||
146 | G_SOURCE_FUNC(handle_media_motion_lost), | ||
147 | handle | ||
148 | ); | ||
149 | |||
150 | return FALSE; | ||
151 | } | ||
152 | |||
153 | static void | ||
154 | handle_window_destroy(UNUSED GtkWidget *window, | ||
155 | gpointer user_data) | ||
156 | { | ||
157 | ui_play_media_window_cleanup((UI_PLAY_MEDIA_Handle*) user_data); | ||
158 | } | ||
159 | |||
160 | void | ||
161 | ui_play_media_window_init(MESSENGER_Application *app, | ||
162 | UI_PLAY_MEDIA_Handle *handle) | ||
163 | { | ||
164 | GNUNET_assert((app) && (handle)); | ||
165 | |||
166 | handle->parent = GTK_WINDOW(app->ui.messenger.main_window); | ||
167 | |||
168 | handle->builder = gtk_builder_new_from_resource( | ||
169 | application_get_resource_path(app, "ui/play_media.ui") | ||
170 | ); | ||
171 | |||
172 | handle->window = HDY_WINDOW( | ||
173 | gtk_builder_get_object(handle->builder, "play_media_window") | ||
174 | ); | ||
175 | |||
176 | gtk_window_set_position( | ||
177 | GTK_WINDOW(handle->window), | ||
178 | GTK_WIN_POS_CENTER_ON_PARENT | ||
179 | ); | ||
180 | |||
181 | gtk_window_set_transient_for( | ||
182 | GTK_WINDOW(handle->window), | ||
183 | handle->parent | ||
184 | ); | ||
185 | |||
186 | handle->header_revealer = GTK_REVEALER( | ||
187 | gtk_builder_get_object(handle->builder, "header_revealer") | ||
188 | ); | ||
189 | |||
190 | handle->title_bar = HDY_HEADER_BAR( | ||
191 | gtk_builder_get_object(handle->builder, "title_bar") | ||
192 | ); | ||
193 | |||
194 | hdy_header_bar_set_title(handle->title_bar, _("Play Media")); | ||
195 | |||
196 | handle->back_button = GTK_BUTTON( | ||
197 | gtk_builder_get_object(handle->builder, "back_button") | ||
198 | ); | ||
199 | |||
200 | g_signal_connect( | ||
201 | handle->back_button, | ||
202 | "clicked", | ||
203 | G_CALLBACK(handle_back_button_click), | ||
204 | handle->window | ||
205 | ); | ||
206 | |||
207 | handle->controls_flap = HDY_FLAP( | ||
208 | gtk_builder_get_object(handle->builder, "controls_flap") | ||
209 | ); | ||
210 | |||
211 | handle->play_pause_button = GTK_BUTTON( | ||
212 | gtk_builder_get_object(handle->builder, "play_pause_button") | ||
213 | ); | ||
214 | |||
215 | handle->play_symbol_stack = GTK_STACK( | ||
216 | gtk_builder_get_object(handle->builder, "play_symbol_stack") | ||
217 | ); | ||
218 | |||
219 | g_signal_connect( | ||
220 | handle->play_pause_button, | ||
221 | "clicked", | ||
222 | G_CALLBACK(handle_play_pause_button_click), | ||
223 | handle | ||
224 | ); | ||
225 | |||
226 | handle->volume_button = GTK_VOLUME_BUTTON( | ||
227 | gtk_builder_get_object(handle->builder, "volume_button") | ||
228 | ); | ||
229 | |||
230 | handle->timeline_label = GTK_LABEL( | ||
231 | gtk_builder_get_object(handle->builder, "timeline_label") | ||
232 | ); | ||
233 | |||
234 | handle->settings_button = GTK_BUTTON( | ||
235 | gtk_builder_get_object(handle->builder, "settings_button") | ||
236 | ); | ||
237 | |||
238 | handle->fullscreen_button = GTK_BUTTON( | ||
239 | gtk_builder_get_object(handle->builder, "fullscreen_button") | ||
240 | ); | ||
241 | |||
242 | handle->fullscreen_symbol_stack = GTK_STACK( | ||
243 | gtk_builder_get_object(handle->builder, "fullscreen_symbol_stack") | ||
244 | ); | ||
245 | |||
246 | g_signal_connect( | ||
247 | handle->fullscreen_button, | ||
248 | "clicked", | ||
249 | G_CALLBACK(handle_fullscreen_button_click), | ||
250 | handle | ||
251 | ); | ||
252 | |||
253 | g_signal_connect( | ||
254 | handle->window, | ||
255 | "motion-notify-event", | ||
256 | G_CALLBACK(handle_media_motion_notify), | ||
257 | handle | ||
258 | ); | ||
259 | |||
260 | gtk_widget_add_events( | ||
261 | GTK_WIDGET(handle->window), | ||
262 | GDK_POINTER_MOTION_HINT_MASK | | ||
263 | GDK_POINTER_MOTION_MASK | ||
264 | ); | ||
265 | |||
266 | g_signal_connect( | ||
267 | handle->window, | ||
268 | "destroy", | ||
269 | G_CALLBACK(handle_window_destroy), | ||
270 | handle | ||
271 | ); | ||
272 | |||
273 | gtk_widget_show_all(GTK_WIDGET(handle->window)); | ||
274 | } | ||
275 | |||
276 | void | ||
277 | ui_play_media_window_cleanup(UI_PLAY_MEDIA_Handle *handle) | ||
278 | { | ||
279 | GNUNET_assert(handle); | ||
280 | |||
281 | g_object_unref(handle->builder); | ||
282 | |||
283 | if (handle->motion_lost) | ||
284 | g_source_remove(handle->motion_lost); | ||
285 | |||
286 | memset(handle, 0, sizeof(*handle)); | ||
287 | } | ||
diff --git a/src/ui/play_media.h b/src/ui/play_media.h new file mode 100644 index 0000000..29f8d1a --- /dev/null +++ b/src/ui/play_media.h | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 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 ui/play_media.h | ||
23 | */ | ||
24 | |||
25 | #ifndef UI_PLAY_MEDIA_H_ | ||
26 | #define UI_PLAY_MEDIA_H_ | ||
27 | |||
28 | #include "messenger.h" | ||
29 | |||
30 | typedef struct UI_PLAY_MEDIA_Handle | ||
31 | { | ||
32 | gboolean playing; | ||
33 | gboolean fullscreen; | ||
34 | |||
35 | GtkWindow *parent; | ||
36 | |||
37 | GtkBuilder *builder; | ||
38 | HdyWindow *window; | ||
39 | |||
40 | GtkRevealer *header_revealer; | ||
41 | HdyHeaderBar *title_bar; | ||
42 | GtkButton *back_button; | ||
43 | |||
44 | HdyFlap *controls_flap; | ||
45 | GtkButton *play_pause_button; | ||
46 | GtkStack *play_symbol_stack; | ||
47 | |||
48 | GtkVolumeButton *volume_button; | ||
49 | GtkLabel *timeline_label; | ||
50 | |||
51 | GtkButton *settings_button; | ||
52 | |||
53 | GtkButton *fullscreen_button; | ||
54 | GtkStack *fullscreen_symbol_stack; | ||
55 | |||
56 | guint motion_lost; | ||
57 | } UI_PLAY_MEDIA_Handle; | ||
58 | |||
59 | /** | ||
60 | * Initializes a handle for the play media window | ||
61 | * of a given messenger application. | ||
62 | * | ||
63 | * @param app Messenger application | ||
64 | * @param handle Play media window handle | ||
65 | */ | ||
66 | void | ||
67 | ui_play_media_window_init(MESSENGER_Application *app, | ||
68 | UI_PLAY_MEDIA_Handle *handle); | ||
69 | |||
70 | /** | ||
71 | * Cleans up the allocated resources and resets the | ||
72 | * state of a given play media window handle. | ||
73 | * | ||
74 | * @param handle Play media window handle | ||
75 | */ | ||
76 | void | ||
77 | ui_play_media_window_cleanup(UI_PLAY_MEDIA_Handle *handle); | ||
78 | |||
79 | #endif /* UI_PLAY_MEDIA_H_ */ | ||