mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 23:32:04 +02:00
Merge pull request #530 from Rafostar/pipeline-preview-launcher
Ability to show GStreamer pipeline
This commit is contained in:
@@ -41,6 +41,7 @@ struct _ClapperAppApplication
|
||||
GtkApplication parent;
|
||||
|
||||
GSettings *settings;
|
||||
GCancellable *cancellable;
|
||||
|
||||
gboolean need_init_state;
|
||||
};
|
||||
@@ -61,6 +62,12 @@ struct ClapperPluginData
|
||||
struct ClapperPluginFeatureData features[10];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ClapperAppApplication *app;
|
||||
guint id;
|
||||
} ClapperAppWindowData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const gchar *action;
|
||||
@@ -317,6 +324,19 @@ _assemble_initial_state (GtkWindow *window)
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
_show_error_dialog (GError *error, GtkWindow *parent)
|
||||
{
|
||||
AdwDialog *dialog;
|
||||
|
||||
dialog = adw_alert_dialog_new ("Error", error->message);
|
||||
adw_alert_dialog_add_response (ADW_ALERT_DIALOG (dialog), "close", _("Close"));
|
||||
adw_alert_dialog_set_default_response (ADW_ALERT_DIALOG (dialog), "close");
|
||||
adw_alert_dialog_set_close_response (ADW_ALERT_DIALOG (dialog), "close");
|
||||
|
||||
adw_dialog_present (dialog, GTK_WIDGET (parent));
|
||||
}
|
||||
|
||||
static void
|
||||
add_files (GSimpleAction *action, GVariant *param, gpointer user_data)
|
||||
{
|
||||
@@ -395,6 +415,102 @@ show_info (GSimpleAction *action, GVariant *param, gpointer user_data)
|
||||
gtk_window_present (GTK_WINDOW (info_window));
|
||||
}
|
||||
|
||||
static void
|
||||
_launch_pipeline_cb (GtkFileLauncher *launcher,
|
||||
GAsyncResult *res, ClapperAppWindowData *win_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!gtk_file_launcher_launch_finish (launcher, res, &error)) {
|
||||
if (error->domain != GTK_DIALOG_ERROR || error->code != GTK_DIALOG_ERROR_DISMISSED) {
|
||||
GtkWindow *window;
|
||||
|
||||
GST_ERROR ("Could not launch pipeline preview, reason: %s",
|
||||
GST_STR_NULL (error->message));
|
||||
|
||||
if ((window = gtk_application_get_window_by_id (
|
||||
GTK_APPLICATION (win_data->app), win_data->id)))
|
||||
_show_error_dialog (error, window);
|
||||
}
|
||||
g_error_free (error);
|
||||
}
|
||||
g_free (win_data);
|
||||
}
|
||||
|
||||
static void
|
||||
_show_pipeline_cb (GObject *source G_GNUC_UNUSED,
|
||||
GAsyncResult *res, ClapperAppWindowData *win_data)
|
||||
{
|
||||
GTask *task = G_TASK (res);
|
||||
GtkWindow *window;
|
||||
GFile *svg_file;
|
||||
GError *error = NULL;
|
||||
|
||||
svg_file = (GFile *) g_task_propagate_pointer (task, &error);
|
||||
window = gtk_application_get_window_by_id (
|
||||
GTK_APPLICATION (win_data->app), win_data->id);
|
||||
|
||||
if (error) {
|
||||
if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_CANCELLED) {
|
||||
GST_ERROR ("Could not create pipeline graph file, reason: %s",
|
||||
GST_STR_NULL (error->message));
|
||||
if (window)
|
||||
_show_error_dialog (error, window);
|
||||
}
|
||||
g_error_free (error);
|
||||
g_free (win_data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (window) {
|
||||
GtkFileLauncher *launcher = gtk_file_launcher_new (svg_file);
|
||||
|
||||
#if GTK_CHECK_VERSION(4,12,0)
|
||||
gtk_file_launcher_set_always_ask (launcher, TRUE);
|
||||
#endif
|
||||
|
||||
gtk_file_launcher_launch (launcher, window, NULL,
|
||||
(GAsyncReadyCallback) _launch_pipeline_cb, win_data);
|
||||
g_object_unref (launcher);
|
||||
} else {
|
||||
g_free (win_data);
|
||||
}
|
||||
|
||||
g_object_unref (svg_file);
|
||||
}
|
||||
|
||||
static void
|
||||
show_pipeline (GSimpleAction *action, GVariant *param, gpointer user_data)
|
||||
{
|
||||
ClapperAppApplication *self = CLAPPER_APP_APPLICATION_CAST (user_data);
|
||||
GtkApplication *gtk_app = GTK_APPLICATION (self);
|
||||
GtkWindow *window;
|
||||
ClapperAppWindowData *win_data;
|
||||
|
||||
window = gtk_application_get_active_window (gtk_app);
|
||||
|
||||
while (window && !CLAPPER_APP_IS_WINDOW (window))
|
||||
window = gtk_window_get_transient_for (window);
|
||||
|
||||
if (G_UNLIKELY (window == NULL))
|
||||
return;
|
||||
|
||||
if (self->cancellable) {
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
g_object_unref (self->cancellable);
|
||||
}
|
||||
self->cancellable = g_cancellable_new ();
|
||||
|
||||
win_data = g_new (ClapperAppWindowData, 1);
|
||||
win_data->app = self;
|
||||
win_data->id = gtk_application_window_get_id (GTK_APPLICATION_WINDOW (window));
|
||||
|
||||
clapper_app_utils_create_pipeline_svg_file_async (
|
||||
clapper_app_window_get_player (CLAPPER_APP_WINDOW (window)),
|
||||
self->cancellable, (GAsyncReadyCallback) _show_pipeline_cb, win_data);
|
||||
}
|
||||
|
||||
static void
|
||||
show_about (GSimpleAction *action, GVariant *param, gpointer user_data)
|
||||
{
|
||||
@@ -714,6 +830,7 @@ clapper_app_application_constructed (GObject *object)
|
||||
{ "clear-queue", clear_queue, NULL, NULL, NULL },
|
||||
{ "new-window", new_window, NULL, NULL, NULL },
|
||||
{ "info", show_info, NULL, NULL, NULL },
|
||||
{ "pipeline", show_pipeline, NULL, NULL, NULL },
|
||||
{ "preferences", show_preferences, NULL, NULL, NULL },
|
||||
{ "about", show_about, NULL, NULL, NULL },
|
||||
};
|
||||
@@ -722,6 +839,7 @@ clapper_app_application_constructed (GObject *object)
|
||||
{ "app.add-uri", { "<Control>u", NULL, NULL }},
|
||||
{ "app.new-window", { "<Control>n", NULL, NULL }},
|
||||
{ "app.info", { "<Control>i", NULL, NULL }},
|
||||
{ "app.pipeline", { "<Control><Shift>p", NULL, NULL }},
|
||||
{ "app.preferences", { "<Control>comma", NULL, NULL }},
|
||||
{ "app.about", { "F1", NULL, NULL }},
|
||||
{ "win.toggle-fullscreen", { "F11", "f", NULL }},
|
||||
@@ -756,6 +874,19 @@ clapper_app_application_constructed (GObject *object)
|
||||
G_OBJECT_CLASS (parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
clapper_app_application_dispose (GObject *object)
|
||||
{
|
||||
ClapperAppApplication *self = CLAPPER_APP_APPLICATION_CAST (object);
|
||||
|
||||
if (self->cancellable) {
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
g_clear_object (&self->cancellable);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
clapper_app_application_finalize (GObject *object)
|
||||
{
|
||||
@@ -779,6 +910,7 @@ clapper_app_application_class_init (ClapperAppApplicationClass *klass)
|
||||
"Clapper App Application");
|
||||
|
||||
gobject_class->constructed = clapper_app_application_constructed;
|
||||
gobject_class->dispose = clapper_app_application_dispose;
|
||||
gobject_class->finalize = clapper_app_application_finalize;
|
||||
|
||||
gtk_application_class->window_removed = clapper_app_application_window_removed;
|
||||
|
Reference in New Issue
Block a user