Commit ae0b1b86 authored by Paolo Bacchilega's avatar Paolo Bacchilega

media player: added customizable shortcuts

parent 61c1fdc4
......@@ -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);
}
......@@ -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 */
/* -*- 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));
}
/* -*- 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 */
......@@ -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);
}
......@@ -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
......
......@@ -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);
}
......
source_files = files(
'actions.c',
'callbacks.c',
'dlg-media-viewer-preferences.c',
'gth-media-viewer-page.c',
'gth-metadata-provider-gstreamer.c',
......
/* -*- 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 */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment