aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-12-05 22:20:29 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-12-05 22:20:29 +0100
commitd3c77142308567e16af38beb704c3436464c0cff (patch)
tree8f931627d61f960f51111e07e9ddd96479a6412b
parentaefac32b50c41a2a6f137b84b80753cd26333aa5 (diff)
downloadmessenger-gtk-d3c77142308567e16af38beb704c3436464c0cff.tar.gz
messenger-gtk-d3c77142308567e16af38beb704c3436464c0cff.zip
Support ogg playback via internal media player
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--resources/ui/message_content.ui106
-rw-r--r--src/ui/message.c137
-rw-r--r--src/ui/message.h7
3 files changed, 230 insertions, 20 deletions
diff --git a/resources/ui/message_content.ui b/resources/ui/message_content.ui
index 1d32e93..a4b01d6 100644
--- a/resources/ui/message_content.ui
+++ b/resources/ui/message_content.ui
@@ -219,6 +219,112 @@ Author: Tobias Frisch
219 <property name="position">3</property> 219 <property name="position">3</property>
220 </packing> 220 </packing>
221 </child> 221 </child>
222 <child>
223 <object class="GtkRevealer" id="media_revealer">
224 <property name="visible">True</property>
225 <property name="can-focus">False</property>
226 <property name="transition-type">none</property>
227 <child>
228 <object class="GtkBox">
229 <property name="visible">True</property>
230 <property name="can-focus">False</property>
231 <property name="orientation">vertical</property>
232 <property name="spacing">4</property>
233 <child>
234 <object class="GtkImage" id="media_type_image">
235 <property name="visible">True</property>
236 <property name="can-focus">False</property>
237 <property name="xpad">24</property>
238 <property name="ypad">24</property>
239 <property name="icon-name">video-x-generic-symbolic</property>
240 <property name="icon_size">5</property>
241 </object>
242 <packing>
243 <property name="expand">True</property>
244 <property name="fill">True</property>
245 <property name="position">0</property>
246 </packing>
247 </child>
248 <child>
249 <object class="GtkBox">
250 <property name="visible">True</property>
251 <property name="can-focus">False</property>
252 <property name="spacing">4</property>
253 <child>
254 <object class="GtkBox">
255 <property name="visible">True</property>
256 <property name="can-focus">False</property>
257 <property name="orientation">vertical</property>
258 <property name="spacing">4</property>
259 <child>
260 <object class="GtkLabel" id="media_label">
261 <property name="visible">True</property>
262 <property name="can-focus">False</property>
263 <property name="xalign">0</property>
264 <property name="yalign">1</property>
265 </object>
266 <packing>
267 <property name="expand">True</property>
268 <property name="fill">True</property>
269 <property name="position">0</property>
270 </packing>
271 </child>
272 <child>
273 <object class="GtkProgressBar" id="media_progress_bar">
274 <property name="visible">True</property>
275 <property name="can-focus">False</property>
276 </object>
277 <packing>
278 <property name="expand">False</property>
279 <property name="fill">True</property>
280 <property name="pack-type">end</property>
281 <property name="position">1</property>
282 </packing>
283 </child>
284 </object>
285 <packing>
286 <property name="expand">True</property>
287 <property name="fill">True</property>
288 <property name="position">0</property>
289 </packing>
290 </child>
291 <child>
292 <object class="GtkButton" id="media_button">
293 <property name="visible">True</property>
294 <property name="can-focus">True</property>
295 <property name="receives-default">True</property>
296 <property name="relief">none</property>
297 <child>
298 <object class="GtkImage">
299 <property name="visible">True</property>
300 <property name="can-focus">False</property>
301 <property name="icon-name">media-playback-start-symbolic</property>
302 </object>
303 </child>
304 </object>
305 <packing>
306 <property name="expand">False</property>
307 <property name="fill">True</property>
308 <property name="pack-type">end</property>
309 <property name="position">1</property>
310 </packing>
311 </child>
312 </object>
313 <packing>
314 <property name="expand">False</property>
315 <property name="fill">True</property>
316 <property name="position">1</property>
317 </packing>
318 </child>
319 </object>
320 </child>
321 </object>
322 <packing>
323 <property name="name">page0</property>
324 <property name="title" translatable="yes">page0</property>
325 <property name="position">4</property>
326 </packing>
327 </child>
222 </object> 328 </object>
223 <packing> 329 <packing>
224 <property name="expand">True</property> 330 <property name="expand">True</property>
diff --git a/src/ui/message.c b/src/ui/message.c
index b375215..30b17d9 100644
--- a/src/ui/message.c
+++ b/src/ui/message.c
@@ -101,25 +101,53 @@ handle_file_button_click(GtkButton *button,
101 GString* uri = g_string_new("file://"); 101 GString* uri = g_string_new("file://");
102 g_string_append(uri, preview); 102 g_string_append(uri, preview);
103 103
104 if (handle->media) 104 if (!g_app_info_launch_default_for_uri(uri->str, NULL, NULL))
105 {
106 ui_play_media_window_init(app, &(app->ui.play_media));
107
108 ui_play_media_window_update(
109 &(app->ui.play_media),
110 uri->str,
111 file
112 );
113
114 gtk_widget_show(GTK_WIDGET(app->ui.play_media.window));
115 }
116 else if (!g_app_info_launch_default_for_uri(uri->str, NULL, NULL))
117 GNUNET_CHAT_file_close_preview(file); 105 GNUNET_CHAT_file_close_preview(file);
118 106
119 g_string_free(uri, TRUE); 107 g_string_free(uri, TRUE);
120 } 108 }
121} 109}
122 110
111static void
112handle_media_button_click(GtkButton *button,
113 gpointer user_data)
114{
115 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
116
117 UI_MESSAGE_Handle* handle = (UI_MESSAGE_Handle*) (
118 g_object_get_qdata(G_OBJECT(button), app->quarks.ui)
119 );
120
121 if (!handle)
122 return;
123
124 struct GNUNET_CHAT_File *file = (struct GNUNET_CHAT_File*) (
125 g_object_get_qdata(G_OBJECT(handle->media_progress_bar), app->quarks.data)
126 );
127
128 if (!file)
129 return;
130
131 const gchar *preview = GNUNET_CHAT_file_open_preview(file);
132
133 if (!preview)
134 return;
135
136 ui_play_media_window_init(app, &(app->ui.play_media));
137
138 GString* uri = g_string_new("file://");
139 g_string_append(uri, preview);
140
141 ui_play_media_window_update(
142 &(app->ui.play_media),
143 uri->str,
144 file
145 );
146
147 gtk_widget_show(GTK_WIDGET(app->ui.play_media.window));
148 g_string_free(uri, TRUE);
149}
150
123static int 151static int
124handle_message_redraw_animation(gpointer user_data) 152handle_message_redraw_animation(gpointer user_data)
125{ 153{
@@ -260,7 +288,6 @@ ui_message_new(MESSENGER_Application *app,
260 UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle)); 288 UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle));
261 289
262 handle->type = type; 290 handle->type = type;
263 handle->media = FALSE;
264 291
265 handle->timestamp = GNUNET_TIME_absolute_get_zero_(); 292 handle->timestamp = GNUNET_TIME_absolute_get_zero_();
266 handle->msg = NULL; 293 handle->msg = NULL;
@@ -391,6 +418,35 @@ ui_message_new(MESSENGER_Application *app,
391 gtk_builder_get_object(handle->builder[1], "whisper_box") 418 gtk_builder_get_object(handle->builder[1], "whisper_box")
392 ); 419 );
393 420
421 handle->media_revealer = GTK_REVEALER(
422 gtk_builder_get_object(handle->builder[1], "media_revealer")
423 );
424
425 handle->media_type_image = GTK_IMAGE(
426 gtk_builder_get_object(handle->builder[1], "media_type_image")
427 );
428
429 handle->media_label = GTK_LABEL(
430 gtk_builder_get_object(handle->builder[1], "media_label")
431 );
432
433 handle->media_progress_bar = GTK_PROGRESS_BAR(
434 gtk_builder_get_object(handle->builder[1], "media_progress_bar")
435 );
436
437 handle->media_button = GTK_BUTTON(
438 gtk_builder_get_object(handle->builder[1], "media_button")
439 );
440
441 g_signal_connect(
442 handle->media_button,
443 "clicked",
444 G_CALLBACK(handle_media_button_click),
445 app
446 );
447
448 g_object_set_qdata(G_OBJECT(handle->media_button), app->quarks.ui, handle);
449
394 switch (handle->type) 450 switch (handle->type)
395 { 451 {
396 case UI_MESSAGE_STATUS: 452 case UI_MESSAGE_STATUS:
@@ -443,6 +499,23 @@ ui_message_refresh(UI_MESSAGE_Handle *handle)
443 gtk_widget_hide(GTK_WIDGET(handle->read_receipt_image)); 499 gtk_widget_hide(GTK_WIDGET(handle->read_receipt_image));
444} 500}
445 501
502gboolean
503_message_media_supports_file_extension(const gchar *filename)
504{
505 if (!filename)
506 return FALSE;
507
508 const char* extension = strrchr(filename, '.');
509
510 if (!extension)
511 return FALSE;
512
513 if (0 == g_strcmp0(extension, ".ogg"))
514 return TRUE;
515
516 return FALSE;
517}
518
446static void 519static void
447_update_file_message(UI_MESSAGE_Handle *handle, 520_update_file_message(UI_MESSAGE_Handle *handle,
448 MESSENGER_Application *app, 521 MESSENGER_Application *app,
@@ -502,20 +575,46 @@ _update_file_message(UI_MESSAGE_Handle *handle,
502 return; 575 return;
503 } 576 }
504 577
505 if (ui_play_media_window_supports_file_extension(filename)) 578 GNUNET_CHAT_file_close_preview(file);
579
580 if (_message_media_supports_file_extension(filename))
506 { 581 {
507 handle->media = TRUE; 582 gtk_image_set_from_icon_name(
508 goto file_progress; 583 handle->media_type_image,
584 "audio-x-generic-symbolic",
585 GTK_ICON_SIZE_DND
586 );
587
588 goto media_content;
509 } 589 }
510 590
511 GNUNET_CHAT_file_close_preview(file); 591 if (!ui_play_media_window_supports_file_extension(filename))
592 goto file_progress;
593
594media_content:
595 ui_label_set_text(handle->media_label, filename);
596
597 gtk_stack_set_visible_child(
598 handle->content_stack,
599 GTK_WIDGET(handle->media_revealer)
600 );
601
602 gtk_revealer_set_reveal_child(handle->media_revealer, TRUE);
603
604 g_object_set_qdata(
605 G_OBJECT(handle->media_progress_bar),
606 app->quarks.data,
607 file
608 );
609
610 return;
512 611
513file_progress: 612file_progress:
514 gtk_progress_bar_set_fraction(handle->file_progress_bar, 1.0); 613 gtk_progress_bar_set_fraction(handle->file_progress_bar, 1.0);
515 614
516 gtk_image_set_from_icon_name( 615 gtk_image_set_from_icon_name(
517 handle->file_status_image, 616 handle->file_status_image,
518 (handle->media? "video-x-generic-symbolic" : "document-open-symbolic"), 617 "document-open-symbolic",
519 GTK_ICON_SIZE_BUTTON 618 GTK_ICON_SIZE_BUTTON
520 ); 619 );
521 620
diff --git a/src/ui/message.h b/src/ui/message.h
index 1205881..97efe07 100644
--- a/src/ui/message.h
+++ b/src/ui/message.h
@@ -44,7 +44,6 @@ typedef enum UI_MESSAGE_Type
44typedef struct UI_MESSAGE_Handle 44typedef struct UI_MESSAGE_Handle
45{ 45{
46 UI_MESSAGE_Type type; 46 UI_MESSAGE_Type type;
47 gboolean media;
48 47
49 struct GNUNET_TIME_Absolute timestamp; 48 struct GNUNET_TIME_Absolute timestamp;
50 const struct GNUNET_CHAT_Message *msg; 49 const struct GNUNET_CHAT_Message *msg;
@@ -78,6 +77,12 @@ typedef struct UI_MESSAGE_Handle
78 77
79 GtkWidget *whisper_box; 78 GtkWidget *whisper_box;
80 79
80 GtkRevealer *media_revealer;
81 GtkImage *media_type_image;
82 GtkLabel *media_label;
83 GtkProgressBar *media_progress_bar;
84 GtkButton *media_button;
85
81 GdkPixbuf *preview_image; 86 GdkPixbuf *preview_image;
82 GdkPixbufAnimation *preview_animation; 87 GdkPixbufAnimation *preview_animation;
83 GdkPixbufAnimationIter *preview_animation_iter; 88 GdkPixbufAnimationIter *preview_animation_iter;