[gthumb] media player: added customizable shortcuts



commit ae0b1b86fc78eb2d1e5baf00f8e561e0975f7fe7
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Nov 16 12:32:32 2019 +0100

    media player: added customizable shortcuts

 extensions/gstreamer_tools/actions.c               | 13 ++++
 extensions/gstreamer_tools/actions.h               |  1 +
 extensions/gstreamer_tools/callbacks.c             | 45 +++++++++++++
 extensions/gstreamer_tools/callbacks.h             | 29 +++++++++
 extensions/gstreamer_tools/gth-media-viewer-page.c | 75 ++++++++++++----------
 extensions/gstreamer_tools/gth-media-viewer-page.h |  1 +
 extensions/gstreamer_tools/main.c                  |  9 +++
 extensions/gstreamer_tools/meson.build             |  1 +
 extensions/gstreamer_tools/shortcuts.h             | 27 ++++++++
 9 files changed, 167 insertions(+), 34 deletions(-)
---
diff --git a/extensions/gstreamer_tools/actions.c b/extensions/gstreamer_tools/actions.c
index 8b4288e2..b03607c6 100644
--- a/extensions/gstreamer_tools/actions.c
+++ b/extensions/gstreamer_tools/actions.c
@@ -192,3 +192,16 @@ gth_browser_activate_video_screenshot (GSimpleAction       *action,
                                        screenshot_ready_cb,
                                        save_data);
 }
+
+
+void
+gth_browser_activate_toggle_play (GSimpleAction        *action,
+                                 GVariant      *parameter,
+                                 gpointer       user_data)
+{
+       GthBrowser              *browser = GTH_BROWSER (user_data);
+       GthMediaViewerPage      *page;
+
+       page = GTH_MEDIA_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
+       gth_media_viewer_page_toggle_play (page);
+}
diff --git a/extensions/gstreamer_tools/actions.h b/extensions/gstreamer_tools/actions.h
index df6c3a81..7caba7b3 100644
--- a/extensions/gstreamer_tools/actions.h
+++ b/extensions/gstreamer_tools/actions.h
@@ -25,5 +25,6 @@
 #include <gthumb.h>
 
 DEF_ACTION_CALLBACK (gth_browser_activate_video_screenshot)
+DEF_ACTION_CALLBACK (gth_browser_activate_toggle_play)
 
 #endif /* ACTIONS_H */
diff --git a/extensions/gstreamer_tools/callbacks.c b/extensions/gstreamer_tools/callbacks.c
new file mode 100644
index 00000000..d7d4742e
--- /dev/null
+++ b/extensions/gstreamer_tools/callbacks.c
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+#include <gthumb.h>
+#include "callbacks.h"
+#include "shortcuts.h"
+
+
+static const GthShortcut shortcuts[] = {
+       { "video-screenshot", N_("Screenshot"), GTH_SHORTCUT_CONTEXT_VIEWER, 
GTH_SHORTCUT_CATEGORY_MEDIA_VIEWER, "<Alt>s" },
+       { "toggle-play", N_("Play/Pause"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_MEDIA_VIEWER, 
"p" },
+};
+
+
+void
+media_viewer__gth_browser_construct_cb (GthBrowser *browser)
+{
+       g_return_if_fail (GTH_IS_BROWSER (browser));
+
+       gth_window_add_shortcuts (GTH_WINDOW (browser),
+                                 shortcuts,
+                                 G_N_ELEMENTS (shortcuts));
+}
diff --git a/extensions/gstreamer_tools/callbacks.h b/extensions/gstreamer_tools/callbacks.h
new file mode 100644
index 00000000..52da2fa7
--- /dev/null
+++ b/extensions/gstreamer_tools/callbacks.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CALLBACKS_H
+#define CALLBACKS_H
+
+#include <gthumb.h>
+
+void media_viewer__gth_browser_construct_cb (GthBrowser *browser);
+
+#endif /* CALLBACKS_H */
diff --git a/extensions/gstreamer_tools/gth-media-viewer-page.c 
b/extensions/gstreamer_tools/gth-media-viewer-page.c
index 4f2accaf..68aba19d 100644
--- a/extensions/gstreamer_tools/gth-media-viewer-page.c
+++ b/extensions/gstreamer_tools/gth-media-viewer-page.c
@@ -84,7 +84,8 @@ static double default_rates[] = { 0.03, 0.06, 0.12, 0.25, 0.33, 0.50, 0.66, 1.0,
 
 
 static const GActionEntry actions[] = {
-       { "video-screenshot", gth_browser_activate_video_screenshot }
+       { "video-screenshot", gth_browser_activate_video_screenshot },
+       { "toggle-play", gth_browser_activate_toggle_play }
 };
 
 
@@ -415,39 +416,7 @@ static void
 play_button_clicked_cb (GtkButton *button,
                        gpointer   user_data)
 {
-       GthMediaViewerPage *self = user_data;
-
-       if (self->priv->playbin == NULL)
-               return;
-       if (! self->priv->playing) {
-               if (! self->priv->paused) {
-                       gst_element_set_state (self->priv->playbin, GST_STATE_PAUSED);
-                       gst_element_seek (self->priv->playbin,
-                                         self->priv->rate,
-                                         GST_FORMAT_TIME,
-                                         GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
-                                         GST_SEEK_TYPE_SET,
-                                         0.0,
-                                         GST_SEEK_TYPE_NONE,
-                                         0.0);
-               }
-               else {
-                       gint64 current_value;
-
-                       current_value = (gint64) (gtk_adjustment_get_value (GTK_ADJUSTMENT (GET_WIDGET 
("position_adjustment"))) / 100.0 * self->priv->duration);
-                       gst_element_seek (self->priv->playbin,
-                                         self->priv->rate,
-                                         GST_FORMAT_TIME,
-                                         GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
-                                         GST_SEEK_TYPE_SET,
-                                         current_value,
-                                         GST_SEEK_TYPE_NONE,
-                                         0.0);
-               }
-               gst_element_set_state (self->priv->playbin, GST_STATE_PLAYING);
-       }
-       else
-               gst_element_set_state (self->priv->playbin, GST_STATE_PAUSED);
+       gth_media_viewer_page_toggle_play (GTH_MEDIA_VIEWER_PAGE (user_data));
 }
 
 
@@ -1418,3 +1387,41 @@ gth_media_viewer_page_get_file_data (GthMediaViewerPage *self)
 {
        return self->priv->file_data;
 }
+
+
+void
+gth_media_viewer_page_toggle_play (GthMediaViewerPage *self)
+{
+       if (self->priv->playbin == NULL)
+               return;
+
+       if (! self->priv->playing) {
+               if (! self->priv->paused) {
+                       gst_element_set_state (self->priv->playbin, GST_STATE_PAUSED);
+                       gst_element_seek (self->priv->playbin,
+                                         self->priv->rate,
+                                         GST_FORMAT_TIME,
+                                         GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
+                                         GST_SEEK_TYPE_SET,
+                                         0.0,
+                                         GST_SEEK_TYPE_NONE,
+                                         0.0);
+               }
+               else {
+                       gint64 current_value;
+
+                       current_value = (gint64) (gtk_adjustment_get_value (GTK_ADJUSTMENT (GET_WIDGET 
("position_adjustment"))) / 100.0 * self->priv->duration);
+                       gst_element_seek (self->priv->playbin,
+                                         self->priv->rate,
+                                         GST_FORMAT_TIME,
+                                         GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
+                                         GST_SEEK_TYPE_SET,
+                                         current_value,
+                                         GST_SEEK_TYPE_NONE,
+                                         0.0);
+               }
+               gst_element_set_state (self->priv->playbin, GST_STATE_PLAYING);
+       }
+       else
+               gst_element_set_state (self->priv->playbin, GST_STATE_PAUSED);
+}
diff --git a/extensions/gstreamer_tools/gth-media-viewer-page.h 
b/extensions/gstreamer_tools/gth-media-viewer-page.h
index 482c588c..ab42c27f 100644
--- a/extensions/gstreamer_tools/gth-media-viewer-page.h
+++ b/extensions/gstreamer_tools/gth-media-viewer-page.h
@@ -55,6 +55,7 @@ void           gth_media_viewer_page_get_video_fps  (GthMediaViewerPage *self,
                                                     int                *video_fps_n,
                                                     int                *video_fps_d);
 GthFileData * gth_media_viewer_page_get_file_data   (GthMediaViewerPage *self);
+void           gth_media_viewer_page_toggle_play    (GthMediaViewerPage *self);
 
 G_END_DECLS
 
diff --git a/extensions/gstreamer_tools/main.c b/extensions/gstreamer_tools/main.c
index f8077f61..9b085c70 100644
--- a/extensions/gstreamer_tools/main.c
+++ b/extensions/gstreamer_tools/main.c
@@ -23,9 +23,16 @@
 #include <config.h>
 #include <gtk/gtk.h>
 #include <gthumb.h>
+#include "callbacks.h"
 #include "dlg-media-viewer-preferences.h"
 #include "gth-metadata-provider-gstreamer.h"
 #include "gth-media-viewer-page.h"
+#include "shortcuts.h"
+
+
+static GthShortcutCategory shortcut_categories[] = {
+       { GTH_SHORTCUT_CATEGORY_MEDIA_VIEWER, N_("Audio/Video Player"), 21 },
+};
 
 
 GthMetadataCategory gstreamer_metadata_category[] = {
@@ -59,9 +66,11 @@ G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
        gth_main_register_object (GTH_TYPE_VIEWER_PAGE, NULL, GTH_TYPE_MEDIA_VIEWER_PAGE, NULL);
+       gth_main_register_shortcut_category (shortcut_categories, G_N_ELEMENTS (shortcut_categories));
        gth_main_register_metadata_category (gstreamer_metadata_category);
        gth_main_register_metadata_info_v (gstreamer_metadata_info);
        gth_main_register_metadata_provider (GTH_TYPE_METADATA_PROVIDER_GSTREAMER);
+       gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK 
(media_viewer__gth_browser_construct_cb), NULL);
 }
 
 
diff --git a/extensions/gstreamer_tools/meson.build b/extensions/gstreamer_tools/meson.build
index 94e035c4..fb60864b 100644
--- a/extensions/gstreamer_tools/meson.build
+++ b/extensions/gstreamer_tools/meson.build
@@ -1,5 +1,6 @@
 source_files = files(
   'actions.c',
+  'callbacks.c',
   'dlg-media-viewer-preferences.c',
   'gth-media-viewer-page.c',
   'gth-metadata-provider-gstreamer.c',
diff --git a/extensions/gstreamer_tools/shortcuts.h b/extensions/gstreamer_tools/shortcuts.h
new file mode 100644
index 00000000..2e0215c8
--- /dev/null
+++ b/extensions/gstreamer_tools/shortcuts.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IMAGE_VIEWER_SHORTCUTS_H
+#define IMAGE_VIEWER_SHORTCUTS_H
+
+#define GTH_SHORTCUT_CATEGORY_MEDIA_VIEWER "media-viewer"
+
+#endif /* IMAGE_VIEWER_SHORTCUTS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]