Commit e9bb1cff authored by Bastien Nocera's avatar Bastien Nocera Committed by Carlos Soriano

Add copy/paste of totem's properties window nautilus extension

The code is quite stable and this is basic functionality which is going to be
better in Nautilus rather than relying on extensions, given the quite bad
extension system Nautilus has.

This will also help with the port to gtk4, so we rely in yet another important
extension providing properties pages (which in turn export gtk3 widgets).
parent 80789505
Pipeline #58303 passed with stages
in 9 minutes and 5 seconds
/* bacon-video-widget-properties.c
Copyright (C) 2002 Bastien Nocera
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Author: Bastien Nocera <hadess@hadess.net>
*/
#include "config.h"
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <string.h>
#include "bacon-video-widget-properties.h"
static void bacon_video_widget_properties_dispose (GObject *object);
struct BaconVideoWidgetPropertiesPrivate {
GtkBuilder *xml;
int time;
};
#define BACON_VIDEO_WIDGET_PROPERTIES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), BACON_TYPE_VIDEO_WIDGET_PROPERTIES, BaconVideoWidgetPropertiesPrivate))
G_DEFINE_TYPE (BaconVideoWidgetProperties, bacon_video_widget_properties, GTK_TYPE_BOX)
static void
bacon_video_widget_properties_class_init (BaconVideoWidgetPropertiesClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (BaconVideoWidgetPropertiesPrivate));
object_class->dispose = bacon_video_widget_properties_dispose;
}
static void
bacon_video_widget_properties_init (BaconVideoWidgetProperties *props)
{
props->priv = G_TYPE_INSTANCE_GET_PRIVATE (props, BACON_TYPE_VIDEO_WIDGET_PROPERTIES, BaconVideoWidgetPropertiesPrivate);
gtk_orientable_set_orientation (GTK_ORIENTABLE (props), GTK_ORIENTATION_VERTICAL);
}
static void
bacon_video_widget_properties_dispose (GObject *object)
{
BaconVideoWidgetPropertiesPrivate *priv = BACON_VIDEO_WIDGET_PROPERTIES_GET_PRIVATE (object);
if (priv->xml != NULL)
g_object_unref (priv->xml);
priv->xml = NULL;
G_OBJECT_CLASS (bacon_video_widget_properties_parent_class)->dispose (object);
}
void
bacon_video_widget_properties_set_label (BaconVideoWidgetProperties *props,
const char *name,
const char *text)
{
GtkLabel *item;
g_return_if_fail (props != NULL);
g_return_if_fail (BACON_IS_VIDEO_WIDGET_PROPERTIES (props));
g_return_if_fail (name != NULL);
item = GTK_LABEL (gtk_builder_get_object (props->priv->xml, name));
g_return_if_fail (item != NULL);
gtk_label_set_text (item, text);
}
void
bacon_video_widget_properties_reset (BaconVideoWidgetProperties *props)
{
GtkWidget *item;
g_return_if_fail (props != NULL);
g_return_if_fail (BACON_IS_VIDEO_WIDGET_PROPERTIES (props));
item = GTK_WIDGET (gtk_builder_get_object (props->priv->xml, "video_vbox"));
gtk_widget_show (item);
item = GTK_WIDGET (gtk_builder_get_object (props->priv->xml, "video"));
gtk_widget_set_sensitive (item, FALSE);
item = GTK_WIDGET (gtk_builder_get_object (props->priv->xml, "audio"));
gtk_widget_set_sensitive (item, FALSE);
/* Title */
bacon_video_widget_properties_set_label (props, "title", _("Unknown"));
/* Artist */
bacon_video_widget_properties_set_label (props, "artist", _("Unknown"));
/* Album */
bacon_video_widget_properties_set_label (props, "album", _("Unknown"));
/* Year */
bacon_video_widget_properties_set_label (props, "year", _("Unknown"));
/* Duration */
bacon_video_widget_properties_set_duration (props, 0);
/* Comment */
bacon_video_widget_properties_set_label (props, "comment", "");
/* Container */
bacon_video_widget_properties_set_label (props, "container", _("Unknown"));
/* Dimensions */
bacon_video_widget_properties_set_label (props, "dimensions", C_("Dimensions", "N/A"));
/* Video Codec */
bacon_video_widget_properties_set_label (props, "vcodec", C_("Video codec", "N/A"));
/* Video Bitrate */
bacon_video_widget_properties_set_label (props, "video_bitrate",
C_("Video bit rate", "N/A"));
/* Framerate */
bacon_video_widget_properties_set_label (props, "framerate",
C_("Frame rate", "N/A"));
/* Audio Bitrate */
bacon_video_widget_properties_set_label (props, "audio_bitrate",
C_("Audio bit rate", "N/A"));
/* Audio Codec */
bacon_video_widget_properties_set_label (props, "acodec", C_("Audio codec", "N/A"));
/* Sample rate */
bacon_video_widget_properties_set_label (props, "samplerate", _("0 Hz"));
/* Channels */
bacon_video_widget_properties_set_label (props, "channels", _("0 Channels"));
}
static char *
time_to_string_text (gint64 msecs)
{
char *secs, *mins, *hours, *string;
int sec, min, hour, _time;
_time = (int) (msecs / 1000);
sec = _time % 60;
_time = _time - sec;
min = (_time % (60*60)) / 60;
_time = _time - (min * 60);
hour = _time / (60*60);
hours = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d hour", "%d hours", hour), hour);
mins = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d minute",
"%d minutes", min), min);
secs = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d second",
"%d seconds", sec), sec);
if (hour > 0)
{
/* 5 hours 2 minutes 12 seconds */
string = g_strdup_printf (C_("time", "%s %s %s"), hours, mins, secs);
} else if (min > 0) {
/* 2 minutes 12 seconds */
string = g_strdup_printf (C_("time", "%s %s"), mins, secs);
} else if (sec > 0) {
/* 10 seconds */
string = g_strdup (secs);
} else {
/* 0 seconds */
string = g_strdup (_("0 seconds"));
}
g_free (hours);
g_free (mins);
g_free (secs);
return string;
}
void
bacon_video_widget_properties_set_duration (BaconVideoWidgetProperties *props,
int _time)
{
char *string;
g_return_if_fail (props != NULL);
g_return_if_fail (BACON_IS_VIDEO_WIDGET_PROPERTIES (props));
if (_time == props->priv->time)
return;
string = time_to_string_text (_time);
bacon_video_widget_properties_set_label (props, "duration", string);
g_free (string);
props->priv->time = _time;
}
void
bacon_video_widget_properties_set_has_type (BaconVideoWidgetProperties *props,
gboolean has_video,
gboolean has_audio)
{
GtkWidget *item;
g_return_if_fail (props != NULL);
g_return_if_fail (BACON_IS_VIDEO_WIDGET_PROPERTIES (props));
/* Video */
item = GTK_WIDGET (gtk_builder_get_object (props->priv->xml, "video"));
gtk_widget_set_sensitive (item, has_video);
item = GTK_WIDGET (gtk_builder_get_object (props->priv->xml, "video_vbox"));
gtk_widget_set_visible (item, has_video);
/* Audio */
item = GTK_WIDGET (gtk_builder_get_object (props->priv->xml, "audio"));
gtk_widget_set_sensitive (item, has_audio);
}
void
bacon_video_widget_properties_set_framerate (BaconVideoWidgetProperties *props,
int framerate)
{
gchar *temp;
g_return_if_fail (props != NULL);
g_return_if_fail (BACON_IS_VIDEO_WIDGET_PROPERTIES (props));
/* The FPS has to be done differently because it's a plural string */
if (framerate != 0) {
temp = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d frame per second", "%d frames per second", framerate),
framerate);
} else {
temp = g_strdup (C_("Frame rate", "N/A"));
}
bacon_video_widget_properties_set_label (props, "framerate", temp);
g_free (temp);
}
GtkWidget*
bacon_video_widget_properties_new (void)
{
BaconVideoWidgetProperties *props;
GtkBuilder *xml;
GtkWidget *vbox;
GtkSizeGroup *group;
const char *labels[] = { "title_label", "artist_label", "album_label",
"year_label", "duration_label", "comment_label", "container_label",
"dimensions_label", "vcodec_label", "framerate_label",
"vbitrate_label", "abitrate_label", "acodec_label",
"samplerate_label", "channels_label" };
guint i;
xml = gtk_builder_new ();
gtk_builder_set_translation_domain (xml, GETTEXT_PACKAGE);
if (gtk_builder_add_from_resource (xml, "/org/gnome/nautilus/audio-video-properties/ui/properties.ui", NULL) == 0) {
g_object_unref (xml);
return NULL;
}
props = BACON_VIDEO_WIDGET_PROPERTIES (g_object_new
(BACON_TYPE_VIDEO_WIDGET_PROPERTIES, NULL));
props->priv->xml = xml;
vbox = GTK_WIDGET (gtk_builder_get_object (props->priv->xml, "vbox1"));
gtk_box_pack_start (GTK_BOX (props), vbox, FALSE, FALSE, 0);
bacon_video_widget_properties_reset (props);
group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
for (i = 0; i < G_N_ELEMENTS (labels); i++)
gtk_size_group_add_widget (group, GTK_WIDGET (gtk_builder_get_object (xml, labels[i])));
g_object_unref (group);
gtk_widget_show_all (GTK_WIDGET (props));
return GTK_WIDGET (props);
}
/* bacon-video-widget-properties.h: Properties dialog for BaconVideoWidget
Copyright (C) 2002 Bastien Nocera <hadess@hadess.net>
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Author: Bastien Nocera <hadess@hadess.net>
*/
#ifndef BACON_VIDEO_WIDGET_PROPERTIES_H
#define BACON_VIDEO_WIDGET_PROPERTIES_H
#include <gtk/gtk.h>
#define BACON_TYPE_VIDEO_WIDGET_PROPERTIES (bacon_video_widget_properties_get_type ())
#define BACON_VIDEO_WIDGET_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BACON_TYPE_VIDEO_WIDGET_PROPERTIES, BaconVideoWidgetProperties))
#define BACON_VIDEO_WIDGET_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BACON_TYPE_VIDEO_WIDGET_PROPERTIES, BaconVideoWidgetPropertiesClass))
#define BACON_IS_VIDEO_WIDGET_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BACON_TYPE_VIDEO_WIDGET_PROPERTIES))
#define BACON_IS_VIDEO_WIDGET_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BACON_TYPE_VIDEO_WIDGET_PROPERTIES))
typedef struct BaconVideoWidgetProperties BaconVideoWidgetProperties;
typedef struct BaconVideoWidgetPropertiesClass BaconVideoWidgetPropertiesClass;
typedef struct BaconVideoWidgetPropertiesPrivate BaconVideoWidgetPropertiesPrivate;
struct BaconVideoWidgetProperties {
GtkBox parent;
BaconVideoWidgetPropertiesPrivate *priv;
};
struct BaconVideoWidgetPropertiesClass {
GtkBoxClass parent_class;
};
GType bacon_video_widget_properties_get_type (void);
GtkWidget *bacon_video_widget_properties_new (void);
void bacon_video_widget_properties_reset (BaconVideoWidgetProperties *props);
void bacon_video_widget_properties_set_label (BaconVideoWidgetProperties *props,
const char *name,
const char *text);
void bacon_video_widget_properties_set_duration (BaconVideoWidgetProperties *props,
int duration);
void bacon_video_widget_properties_set_has_type (BaconVideoWidgetProperties *props,
gboolean has_video,
gboolean has_audio);
void bacon_video_widget_properties_set_framerate (BaconVideoWidgetProperties *props,
int framerate);
#endif /* BACON_VIDEO_WIDGET_PROPERTIES_H */
resources = gnome.compile_resources(
'nautilus-audio-video-properties-resources',
join_paths(
'resources', 'nautilus-audio-video-properties.gresource.xml'
),
source_dir: 'resources',
c_name: 'nautilus_audio_video_properties',
)
libtotem_properties_page_sources = files(
'totem-properties-main.c',
'totem-properties-view.c',
'bacon-video-widget-properties.c',
) + resources
libtotem_properties_page_deps = [
gst_tag_dep,
gst_pbutils_dep,
]
libtotem_properties_page = shared_module(
'totem-properties-page',
sources: libtotem_properties_page_sources,
dependencies: libtotem_properties_page_deps + [
nautilus_extension
],
c_args: [
'-DG_LOG_DOMAIN="TotemPropertiesPage"'
],
install: true,
install_dir: extensiondir
)
test_properties_page_sources = files(
'totem-properties-main.c',
'totem-properties-view.c',
'bacon-video-widget-properties.c',
'test-properties-page.c'
) + resources
executable(
'test-properties-page',
test_properties_page_sources,
dependencies: libtotem_properties_page_deps + [
nautilus_extension
],
)
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/nautilus/audio-video-properties">
<file compressed="true">ui/properties.ui</file>
</gresource>
</gresources>
This diff is collapsed.
/*
* Copyright (C) 2005 Bastien Nocera <hadess@hadess.net>
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include <string.h>
#define GST_USE_UNSTABLE_API 1
#include <gst/gst.h>
#include <glib/gi18n-lib.h>
#include "totem-properties-view.h"
static GtkWidget *window, *props, *label;
static void
create_props (const char *url)
{
label = gtk_label_new ("Audio/Video");
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_default_size (GTK_WINDOW (window), 450, 550);
props = totem_properties_view_new (url, label);
gtk_container_add (GTK_CONTAINER (window), props);
gtk_widget_show_all (window);
}
static void
destroy_props (void)
{
gtk_widget_destroy (label);
}
int main (int argc, char **argv)
{
GFile *file;
char *url;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
gst_init (&argc, &argv);
gtk_init (&argc, &argv);
if (argc != 2) {
g_print ("Usage: %s [URI]\n", argv[0]);
return 1;
}
file = g_file_new_for_commandline_arg (argv[1]);
url = g_file_get_uri (file);
g_object_unref (file);
create_props (url);
g_free (url);
gtk_main ();
destroy_props ();
return 0;
}
/* generated with mime-types-include.sh, don't edit */
G_GNUC_UNUSED static const gchar *mime_types[] = {
"application/mxf",
"application/ogg",
"application/ram",
"application/sdp",
"application/smil",
"application/smil+xml",
"application/vnd.apple.mpegurl",
"application/vnd.ms-asf",
"application/vnd.ms-wpl",
"application/vnd.rn-realmedia",
"application/vnd.rn-realmedia-vbr",
"application/x-extension-m4a",
"application/x-extension-mp4",
"application/x-flac",
"application/x-flash-video",
"application/x-matroska",
"application/x-netshow-channel",
"application/x-ogg",
"application/x-quicktime-media-link",
"application/x-quicktimeplayer",
"application/x-shorten",
"application/x-smil",
"application/xspf+xml",
"audio/3gpp",
"audio/3gpp2",
"audio/aac",
"audio/ac3",
"audio/AMR",
"audio/AMR-WB",
"audio/basic",
"audio/dv",
"audio/eac3",
"audio/flac",
"audio/m4a",
"audio/midi",
"audio/mp1",
"audio/mp2",
"audio/mp3",
"audio/mp4",
"audio/mpeg",
"audio/mpegurl",
"audio/mpg",
"audio/ogg",
"audio/opus",
"audio/prs.sid",
"audio/scpls",
"audio/vnd.rn-realaudio",
"audio/wav",
"audio/webm",
"audio/x-aac",
"audio/x-aiff",
"audio/x-ape",
"audio/x-flac",
"audio/x-gsm",
"audio/x-it",
"audio/x-m4a",
"audio/x-m4b",
"audio/x-matroska",
"audio/x-mod",
"audio/x-mp1",
"audio/x-mp2",
"audio/x-mp3",
"audio/x-mpg",
"audio/x-mpeg",
"audio/x-mpegurl",
"audio/x-ms-asf",
"audio/x-ms-asx",
"audio/x-ms-wax",
"audio/x-ms-wma",
"audio/x-musepack",
"audio/x-opus+ogg",
"audio/x-pn-aiff",
"audio/x-pn-au",
"audio/x-pn-realaudio",
"audio/x-pn-realaudio-plugin",
"audio/x-pn-wav",
"audio/x-pn-windows-acm",
"audio/x-realaudio",
"audio/x-real-audio",
"audio/x-s3m",
"audio/x-sbc",
"audio/x-scpls",
"audio/x-shorten",
"audio/x-speex",
"audio/x-stm",
"audio/x-tta",
"audio/x-wav",
"audio/x-wavpack",
"audio/x-vorbis",
"audio/x-vorbis+ogg",
"audio/x-xm",
"image/vnd.rn-realpix",
"image/x-pict",
"misc/ultravox",
"text/google-video-pointer",
"text/x-google-video-pointer",
"video/3gp",
"video/3gpp",
"video/3gpp2",
"video/dv",
"video/divx",
"video/fli",
"video/flv",
"video/mp2t",
"video/mp4",
"video/mp4v-es",
"video/mpeg",
"video/mpeg-system",
"video/msvideo",
"video/ogg",
"video/quicktime",
"video/vivo",
"video/vnd.divx",
"video/vnd.mpegurl",
"video/vnd.rn-realvideo",
"video/vnd.vivo",
"video/webm",
"video/x-anim",
"video/x-avi",
"video/x-flc",
"video/x-fli",
"video/x-flic",
"video/x-flv",
"video/x-m4v",
"video/x-matroska",
"video/x-mjpeg",
"video/x-mpeg",
"video/x-mpeg2",
"video/x-ms-asf",
"video/x-ms-asf-plugin",
"video/x-ms-asx",
"video/x-msvideo",
"video/x-ms-wm",
"video/x-ms-wmv",
"video/x-ms-wmx",
"video/x-ms-wvx",
"video/x-nsv",
"video/x-ogm+ogg",
"video/x-theora",
"video/x-theora+ogg",
"video/x-totem-stream",
NULL
};
G_GNUC_UNUSED static const gchar *audio_mime_types[] = {
"audio/3gpp",
"audio/3gpp2",
"audio/aac",
"audio/ac3",
"audio/AMR",
"audio/AMR-WB",
"audio/basic",
"audio/dv",
"audio/eac3",
"audio/flac",
"audio/m4a",
"audio/midi",
"audio/mp1",
"audio/mp2",
"audio/mp3",
"audio/mp4",
"audio/mpeg",
"audio/mpg",
"audio/ogg",
"audio/opus",
"audio/prs.sid",
"audio/scpls",
"audio/vnd.rn-realaudio",
"audio/wav",
"audio/webm",
"audio/x-aac",
"audio/x-aiff",
"audio/x-ape",
"audio/x-flac",
"audio/x-gsm",
"audio/x-it",
"audio/x-m4a",
"audio/x-m4b",
"audio/x-matroska",
"audio/x-mod",
"audio/x-mp1",
"audio/x-mp2",
"audio/x-mp3",
"audio/x-mpg",
"audio/x-mpeg",
"audio/x-ms-asf",
"audio/x-ms-asx",
"audio/x-ms-wax",
"audio/x-ms-wma",
"audio/x-musepack",
"audio/x-opus+ogg",
"audio/x-pn-aiff",
"audio/x-pn-au",
"audio/x-pn-wav",
"audio/x-pn-windows-acm",
"audio/x-realaudio",
"audio/x-real-audio",
"audio/x-s3m",
"audio/x-sbc",
"audio/x-shorten",
"audio/x-speex",
"audio/x-stm",
"audio/x-tta",
"audio/x-wav",
"audio/x-wavpack",
"audio/x-vorbis",
"audio/x-vorbis+ogg",
"audio/x-xm",
"application/x-flac",
NULL
};
G_GNUC_UNUSED static const gchar *video_mime_types[] = {
"application/mxf",
"application/ogg",
"application/ram",
"application/sdp",
"application/vnd.apple.mpegurl",
"application/vnd.ms-asf",
"application/vnd.ms-wpl",
"application/vnd.rn-realmedia",
"application/vnd.rn-realmedia-vbr",
"application/x-extension-m4a",
"application/x-extension-mp4",
"application/x-flash-video",
"application/x-matroska",
"application/x-netshow-channel",