commit 36058f083af2fccf616b72df5fa387a14db3b657
parent e67d27e74d0a2b0281256402ea79adea8ae91373
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Mon, 5 Dec 2022 21:19:06 +0100
Allow opening internal video player with received mp4 files
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
6 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/resources/ui/message_content.ui b/resources/ui/message_content.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2
+<!-- Generated with glade 3.40.0
Copyright (C) 2021‑‑2022 GNUnet e.V.
@@ -81,6 +81,7 @@ Author: Tobias Frisch
<property name="wrap">True</property>
<property name="max-width-chars">64</property>
<property name="xalign">0</property>
+ <property name="yalign">1</property>
</object>
<packing>
<property name="name">text_page</property>
@@ -100,16 +101,19 @@ Author: Tobias Frisch
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="valign">center</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel" id="filename_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
+ <property name="label" translatable="yes">
+</property>
+ <property name="xalign">0</property>
+ <property name="yalign">1</property>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@@ -122,6 +126,7 @@ Author: Tobias Frisch
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
+ <property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
@@ -137,8 +142,7 @@ Author: Tobias Frisch
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
+ <property name="valign">end</property>
<property name="relief">none</property>
<child>
<object class="GtkImage" id="file_status_image">
@@ -182,6 +186,7 @@ Author: Tobias Frisch
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
+ <property name="valign">end</property>
<property name="icon-name">face-shutmouth-symbolic</property>
</object>
<packing>
@@ -196,6 +201,7 @@ Author: Tobias Frisch
<property name="can-focus">False</property>
<property name="label" translatable="yes">whispering...</property>
<property name="xalign">0</property>
+ <property name="yalign">1</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
diff --git a/src/ui/message.c b/src/ui/message.c
@@ -101,7 +101,19 @@ handle_file_button_click(GtkButton *button,
GString* uri = g_string_new("file://");
g_string_append(uri, preview);
- if (!g_app_info_launch_default_for_uri(uri->str, NULL, NULL))
+ if (handle->media)
+ {
+ ui_play_media_window_init(app, &(app->ui.play_media));
+
+ ui_play_media_window_update(
+ &(app->ui.play_media),
+ uri->str,
+ file
+ );
+
+ gtk_widget_show(GTK_WIDGET(app->ui.play_media.window));
+ }
+ else if (!g_app_info_launch_default_for_uri(uri->str, NULL, NULL))
GNUNET_CHAT_file_close_preview(file);
g_string_free(uri, TRUE);
@@ -248,6 +260,7 @@ ui_message_new(MESSENGER_Application *app,
UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle));
handle->type = type;
+ handle->media = FALSE;
handle->timestamp = GNUNET_TIME_absolute_get_zero_();
handle->msg = NULL;
@@ -472,7 +485,7 @@ _update_file_message(UI_MESSAGE_Handle *handle,
if (!(handle->preview_animation))
handle->preview_image = gdk_pixbuf_new_from_file(preview, NULL);
- if ((handle->preview_animation) || (handle->preview_animation))
+ if ((handle->preview_animation) || (handle->preview_image))
{
gtk_widget_set_size_request(
GTK_WIDGET(handle->preview_drawing_area),
@@ -489,6 +502,14 @@ _update_file_message(UI_MESSAGE_Handle *handle,
return;
}
+ const char* extension = strrchr(filename, '.');
+
+ if (0 == g_strcmp0(extension, ".mp4"))
+ {
+ handle->media = TRUE;
+ goto file_progress;
+ }
+
GNUNET_CHAT_file_close_preview(file);
file_progress:
@@ -496,7 +517,7 @@ file_progress:
gtk_image_set_from_icon_name(
handle->file_status_image,
- "document-open-symbolic",
+ (handle->media? "video-x-generic-symbolic" : "document-open-symbolic"),
GTK_ICON_SIZE_BUTTON
);
diff --git a/src/ui/message.h b/src/ui/message.h
@@ -44,6 +44,7 @@ typedef enum UI_MESSAGE_Type
typedef struct UI_MESSAGE_Handle
{
UI_MESSAGE_Type type;
+ gboolean media;
struct GNUNET_TIME_Absolute timestamp;
const struct GNUNET_CHAT_Message *msg;
diff --git a/src/ui/picker.c b/src/ui/picker.c
@@ -100,14 +100,8 @@ handle_settings_button_click(UNUSED GtkButton *button,
gpointer user_data)
{
MESSENGER_Application *app = (MESSENGER_Application*) user_data;
- ui_play_media_window_init(app, &(app->ui.play_media));
- ui_play_media_window_update(
- &(app->ui.play_media),
- "TODO" // uri path to video file
- );
-
- gtk_widget_show(GTK_WIDGET(app->ui.play_media.window));
+ // TODO
}
UI_PICKER_Handle*
diff --git a/src/ui/play_media.c b/src/ui/play_media.c
@@ -746,8 +746,11 @@ ui_play_media_window_init(MESSENGER_Application *app,
void
ui_play_media_window_update(UI_PLAY_MEDIA_Handle *handle,
- const gchar *uri)
+ const gchar *uri,
+ const struct GNUNET_CHAT_File *file)
{
+ GNUNET_assert((handle) && (uri));
+
if (handle->video_tid)
pthread_join(handle->video_tid, NULL);
@@ -757,6 +760,18 @@ ui_play_media_window_update(UI_PLAY_MEDIA_Handle *handle,
_disable_video_processing(handle, TRUE);
g_object_set(G_OBJECT(handle->pipeline), "uri", uri, NULL);
+ const gchar *filename;
+
+ if (file)
+ filename = GNUNET_CHAT_file_get_name(file);
+ else
+ filename = uri;
+
+ hdy_header_bar_set_subtitle(
+ handle->title_bar,
+ filename? filename : ""
+ );
+
pthread_create(
&(handle->video_tid),
NULL,
diff --git a/src/ui/play_media.h b/src/ui/play_media.h
@@ -91,10 +91,12 @@ ui_play_media_window_init(MESSENGER_Application *app,
*
* @param handle Play media window handle
* @param uri URI of media file
+ * @param file Media file handle or NULL
*/
void
ui_play_media_window_update(UI_PLAY_MEDIA_Handle *handle,
- const gchar *uri);
+ const gchar *uri,
+ const struct GNUNET_CHAT_File *file);
/**
* Cleans up the allocated resources and resets the