[Goodies-commits] r7607 - in parole/trunk: . data/interfaces src
Ali Abdallah
aliov at xfce.org
Thu Jun 18 13:01:05 CEST 2009
Author: aliov
Date: 2009-06-18 11:01:05 +0000 (Thu, 18 Jun 2009)
New Revision: 7607
Modified:
parole/trunk/ChangeLog
parole/trunk/data/interfaces/parole-settings.ui
parole/trunk/data/interfaces/parole.ui
parole/trunk/src/conf-dialog.c
parole/trunk/src/conf.c
parole/trunk/src/filters.c
parole/trunk/src/gst.c
parole/trunk/src/main.c
parole/trunk/src/mediafile.c
parole/trunk/src/medialist.c
parole/trunk/src/player.c
parole/trunk/src/rc-utils.c
parole/trunk/src/utils.c
parole/trunk/src/utils.h
Log:
* Fix uri command line handling.
* Automatically load subtitle.
* Add options for subtitles font.
Modified: parole/trunk/ChangeLog
===================================================================
--- parole/trunk/ChangeLog 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/ChangeLog 2009-06-18 11:01:05 UTC (rev 7607)
@@ -1,3 +1,8 @@
+2009-06-18: 12:00 Ali aliov at xfce.org
+ * Fix uri command line handling.
+ * Automatically load subtitle.
+ * Add options for subtitles font.
+
2009-06-16: 11:30 Ali aliov at xfce.org
* Show busy cursor when dropping files in the media list view.
* Fix the date in previous commit (2009 instead of 2008).
Modified: parole/trunk/data/interfaces/parole-settings.ui
===================================================================
--- parole/trunk/data/interfaces/parole-settings.ui 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/data/interfaces/parole-settings.ui 2009-06-18 11:01:05 UTC (rev 7607)
@@ -133,7 +133,82 @@
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
- <placeholder/>
+ <object class="GtkVBox" id="vbox3">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkCheckButton" id="enable-subtitle">
+ <property name="label" translatable="yes">Automatically load subtitle when playing movie file</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="parole_conf_dialog_enable_subtitle_changed_cb"/>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Font:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFontButton" id="fontbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="font_set" handler="parole_conf_dialog_font_set_cb"/>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox3">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Encoding: </property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="encoding-combo">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
</child>
</object>
</child>
Modified: parole/trunk/data/interfaces/parole.ui
===================================================================
--- parole/trunk/data/interfaces/parole.ui 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/data/interfaces/parole.ui 2009-06-18 11:01:05 UTC (rev 7607)
@@ -8,6 +8,7 @@
<property name="default_height">440</property>
<signal name="destroy" handler="parole_player_destroy_cb"/>
<signal name="key_press_event" handler="parole_player_key_press"/>
+ <signal name="delete_event" handler="parole_player_delete_event_cb"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
Modified: parole/trunk/src/conf-dialog.c
===================================================================
--- parole/trunk/src/conf-dialog.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/conf-dialog.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -35,15 +35,22 @@
* GtkBuilder Callbacks
*/
-void parole_conf_dialog_response_cb (GtkDialog *dialog,
- gint response_id,
- ParoleConfDialog *self);
+void parole_conf_dialog_response_cb (GtkDialog *dialog,
+ gint response_id,
+ ParoleConfDialog *self);
-void parole_conf_dialog_enable_vis_changed_cb (GtkToggleButton *widget,
- ParoleConfDialog *self);
+void parole_conf_dialog_enable_vis_changed_cb (GtkToggleButton *widget,
+ ParoleConfDialog *self);
-void parole_conf_dialog_vis_plugin_changed_cb (GtkComboBox *widget,
- ParoleConfDialog *self);
+void parole_conf_dialog_vis_plugin_changed_cb (GtkComboBox *widget,
+ ParoleConfDialog *self);
+
+void parole_conf_dialog_font_set_cb (GtkFontButton *button,
+ ParoleConfDialog *self);
+
+void parole_conf_dialog_enable_subtitle_changed_cb (GtkToggleButton *widget,
+ ParoleConfDialog *self);
+
/*
* End of GtkBuilder callbacks
*/
@@ -60,6 +67,8 @@
GtkWidget *vis_combox;
GtkWidget *toggle_vis;
+ GtkWidget *toggle_subtitle;
+ GtkWidget *font_button;
};
G_DEFINE_TYPE (ParoleConfDialog, parole_conf_dialog, G_TYPE_OBJECT)
@@ -115,6 +124,27 @@
g_free (active);
}
+void parole_conf_dialog_font_set_cb (GtkFontButton *button, ParoleConfDialog *self)
+{
+ g_object_set (G_OBJECT (self->priv->conf),
+ "subtitle-font", gtk_font_button_get_font_name (button),
+ NULL);
+}
+
+void parole_conf_dialog_enable_subtitle_changed_cb (GtkToggleButton *widget, ParoleConfDialog *self)
+{
+ gboolean active;
+
+ active = gtk_toggle_button_get_active (widget);
+
+ g_object_set (G_OBJECT (self->priv->conf),
+ "enable-subtitle", active,
+ NULL);
+
+ gtk_widget_set_sensitive (self->priv->font_button, active);
+
+}
+
static void
parole_conf_dialog_finalize (GObject *object)
{
@@ -193,19 +223,29 @@
{
GtkTreeModel *model;
gboolean vis_enabled;
-
+ gboolean subtitle;
+ gchar *subtitle_font;
+
g_object_get (G_OBJECT (self->priv->conf),
"vis-enabled", &vis_enabled,
+ "enable-subtitle", &subtitle,
+ "subtitle-font", &subtitle_font,
NULL);
gtk_widget_set_sensitive (self->priv->vis_combox, vis_enabled);
+ gtk_widget_set_sensitive (self->priv->font_button, subtitle);
+
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->toggle_vis), vis_enabled);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->toggle_subtitle), subtitle);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (self->priv->vis_combox));
gtk_tree_model_foreach (model,
(GtkTreeModelForeachFunc) parole_conf_dialog_set_default_vis_plugin,
self);
+
+ gtk_font_button_set_font_name (GTK_FONT_BUTTON (self->priv->font_button), subtitle_font);
+ g_free (subtitle_font);
}
ParoleConfDialog *
@@ -226,7 +266,10 @@
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "settings-dialog"));
combox = GTK_WIDGET (gtk_builder_get_object (builder, "vis-combobox"));
+
self->priv->toggle_vis = GTK_WIDGET (gtk_builder_get_object (builder, "enable-vis"));
+ self->priv->toggle_subtitle = GTK_WIDGET (gtk_builder_get_object (builder, "enable-subtitle"));
+ self->priv->font_button = GTK_WIDGET (gtk_builder_get_object (builder, "fontbutton"));
g_hash_table_foreach (self->priv->vis_plugins, (GHFunc) parole_conf_dialog_add_vis_plugins, combox);
Modified: parole/trunk/src/conf.c
===================================================================
--- parole/trunk/src/conf.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/conf.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -38,6 +38,8 @@
{
gchar *vis_sink;
gboolean enable_vis;
+ gboolean enable_subtitle;
+ gchar *subtitle_font;
};
static gpointer parole_conf_object = NULL;
@@ -48,7 +50,9 @@
{
PROP_0,
PROP_VIS_ENABLED,
- PROP_VIS_NAME
+ PROP_VIS_NAME,
+ PROP_SUBTITLE_ENABLED,
+ PROP_SUBTITLE_FONT,
};
static void parole_conf_set_property (GObject *object,
@@ -67,10 +71,24 @@
parole_rc_write_entry_bool ("VIS_ENABLED", conf->priv->enable_vis);
break;
case PROP_VIS_NAME:
+ if ( conf->priv->vis_sink )
+ g_free (conf->priv->vis_sink);
conf->priv->vis_sink = g_strdup (g_value_get_string (value));
g_object_notify (G_OBJECT (conf), "vis-name");
parole_rc_write_entry_string ("VIS_NAME", conf->priv->vis_sink);
break;
+ case PROP_SUBTITLE_ENABLED:
+ conf->priv->enable_subtitle = g_value_get_boolean (value);
+ g_object_notify (G_OBJECT (conf), "enable-subtitle");
+ parole_rc_write_entry_bool ("ENABLE_SUBTITLE", conf->priv->enable_subtitle);
+ break;
+ case PROP_SUBTITLE_FONT:
+ if ( conf->priv->subtitle_font )
+ g_free (conf->priv->subtitle_font);
+ conf->priv->subtitle_font = g_strdup (g_value_get_string (value));
+ g_object_notify (G_OBJECT (conf), "subtitle-font");
+ parole_rc_write_entry_string ("SUBTITLE_FONT", conf->priv->subtitle_font);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -93,6 +111,12 @@
case PROP_VIS_NAME:
g_value_set_string (value, conf->priv->vis_sink);
break;
+ case PROP_SUBTITLE_ENABLED:
+ g_value_set_boolean (value, conf->priv->enable_subtitle);
+ break;
+ case PROP_SUBTITLE_FONT:
+ g_value_set_string (value, conf->priv->subtitle_font);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -107,6 +131,7 @@
conf = PAROLE_CONF (object);
g_free (conf->priv->vis_sink);
+ g_free (conf->priv->subtitle_font);
G_OBJECT_CLASS (parole_conf_parent_class)->finalize (object);
}
@@ -135,6 +160,20 @@
NULL,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_SUBTITLE_ENABLED,
+ g_param_spec_boolean ("enable-subtitle",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_SUBTITLE_FONT,
+ g_param_spec_string ("subtitle-font",
+ NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE));
+
g_type_class_add_private (klass, sizeof (ParoleConfPrivate));
}
@@ -145,6 +184,8 @@
conf->priv->enable_vis = parole_rc_read_entry_bool ("VIS_ENABLED", FALSE);
conf->priv->vis_sink = g_strdup (parole_rc_read_entry_string ("VIS_NAME", "none"));
+ conf->priv->enable_subtitle = parole_rc_read_entry_bool ("ENABLE_SUBTITLE", TRUE);
+ conf->priv->subtitle_font = g_strdup (parole_rc_read_entry_string ("SUBTITLE_FONT", "Sans 12"));
}
ParoleConf *
Modified: parole/trunk/src/filters.c
===================================================================
--- parole/trunk/src/filters.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/filters.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -129,11 +129,11 @@
while ( (name = g_dir_read_name (dir)) )
{
gchar *path_internal = g_strdup_printf ("%s/%s", path, name);
- if ( g_file_test (path, G_FILE_TEST_IS_DIR) )
+ if ( g_file_test (path_internal, G_FILE_TEST_IS_DIR) )
{
parole_get_media_files (filter, path_internal, list);
}
- else if ( g_file_test (path, G_FILE_TEST_IS_REGULAR) )
+ else if ( g_file_test (path_internal, G_FILE_TEST_IS_REGULAR) )
{
file = parole_media_file_new (path_internal);
if ( parole_file_filter (filter, file) )
Modified: parole/trunk/src/gst.c
===================================================================
--- parole/trunk/src/gst.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/gst.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -39,6 +39,7 @@
#include "gst.h"
#include "utils.h"
#include "conf.h"
+#include "utils.h"
#include "enum-gtypes.h"
#include "gmarshal.h"
@@ -397,6 +398,67 @@
}
static void
+parole_gst_set_subtitle_font (ParoleGst *gst)
+{
+ gchar *font;
+
+ g_object_get (G_OBJECT (gst->priv->conf),
+ "subtitle-font", &font,
+ NULL);
+
+ TRACE ("Setting subtitle font %s\n", font);
+
+ g_object_set (G_OBJECT (gst->priv->playbin),
+ "subtitle-font-desc", font,
+ NULL);
+ g_free (font);
+}
+
+static void
+parole_gst_set_subtitle_encoding (ParoleGst *gst)
+{
+ g_object_set (G_OBJECT (gst->priv->playbin),
+ "subtitle-encoding", "UTF-8",
+ NULL);
+}
+
+static void
+parole_gst_load_subtitle (ParoleGst *gst)
+{
+ ParoleMediaFile *file;
+ const gchar *uri;
+ gchar *sub;
+ gchar *sub_uri;
+ gboolean sub_enabled;
+
+ g_object_get (G_OBJECT (gst->priv->conf),
+ "enable-subtitle", &sub_enabled,
+ NULL);
+
+ if ( !sub_enabled )
+ return;
+
+ g_object_get (G_OBJECT (gst->priv->stream),
+ "media-file", &file,
+ NULL);
+
+ uri = parole_media_file_get_uri (file);
+ sub = parole_get_subtitle_path (uri);
+
+ if ( sub )
+ {
+ TRACE ("Found subtitle with path %s", sub);
+ sub_uri = g_filename_to_uri (sub, NULL, NULL);
+ g_object_set (G_OBJECT (gst->priv->playbin),
+ "suburi", sub_uri,
+ NULL);
+ g_free (sub);
+ g_free (sub_uri);
+ }
+ g_object_unref (file);
+}
+
+static void
parole_gst_query_info (ParoleGst *gst)
{
const GList *info = NULL;
@@ -404,8 +466,8 @@
GParamSpec *pspec;
GEnumValue *val;
gint type;
+ gboolean has_video = FALSE;
-
g_object_get (G_OBJECT (gst->priv->playbin),
"stream-info", &info,
NULL);
@@ -428,6 +490,7 @@
g_object_set (G_OBJECT (gst->priv->stream),
"has-video", TRUE,
NULL);
+ has_video = TRUE;
}
if ( g_ascii_strcasecmp (val->value_name, "audio") == 0 ||
g_ascii_strcasecmp (val->value_nick, "audio") == 0)
@@ -438,6 +501,9 @@
NULL);
}
}
+
+ if ( !has_video )
+ gtk_widget_queue_draw (GTK_WIDGET (gst));
}
static void
@@ -489,9 +555,10 @@
switch (gst->priv->state)
{
case GST_STATE_PLAYING:
+ parole_gst_query_duration (gst);
parole_gst_query_capabilities (gst);
- parole_gst_query_duration (gst);
parole_gst_query_info (gst);
+
g_signal_emit (G_OBJECT (gst), signals [MEDIA_STATE], 0,
gst->priv->stream, PAROLE_MEDIA_STATE_PLAYING);
break;
@@ -675,10 +742,12 @@
g_object_set (G_OBJECT (gst->priv->playbin),
"uri", parole_media_file_get_uri (file),
+ "suburi", NULL,
NULL);
-
+
+ parole_gst_load_subtitle (gst);
+
parole_gst_change_state (gst, GST_STATE_PLAYING);
-
g_object_unref (file);
}
@@ -729,6 +798,9 @@
g_object_unref (bus);
parole_gst_load_logo (gst);
+
+ parole_gst_set_subtitle_encoding (gst);
+ parole_gst_set_subtitle_font (gst);
}
static gboolean
@@ -755,6 +827,8 @@
{
gst->priv->update = TRUE;
}
+ else if ( !g_strcmp0 ("subtitle-font", spec->name ) && gst->priv->state >= GST_STATE_PAUSED )
+ parole_gst_set_subtitle_font (gst);
}
static void
Modified: parole/trunk/src/main.c
===================================================================
--- parole/trunk/src/main.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/main.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -31,6 +31,7 @@
#include <gtk/gtk.h>
#include <glib.h>
+#include <gio/gio.h>
#include <gst/gst.h>
@@ -46,19 +47,31 @@
static void
parole_send_files (gchar **filenames)
{
+ GFile *file;
DBusGConnection *bus;
DBusGProxy *proxy;
+ gchar **out_uris;
GError *error = NULL;
+ guint i;
bus = parole_g_session_bus_get ();
+ out_uris = g_new (gchar *, g_strv_length (filenames));
+
+ for ( i = 0; filenames && filenames[i]; i++)
+ {
+ file = g_file_new_for_commandline_arg (filenames[i]);
+ out_uris[i] = g_file_get_uri (file);
+ g_object_unref (file);
+ }
+
proxy = dbus_g_proxy_new_for_name (bus,
PAROLE_DBUS_NAME,
PAROLE_DBUS_PATH,
PAROLE_DBUS_INTERFACE);
dbus_g_proxy_call (proxy, "AddFiles", &error,
- G_TYPE_STRV, filenames,
+ G_TYPE_STRV, out_uris,
G_TYPE_INVALID,
G_TYPE_INVALID);
@@ -70,6 +83,7 @@
g_object_unref (proxy);
dbus_g_connection_unref (bus);
+ g_strfreev (out_uris);
}
int main (int argc, char **argv)
Modified: parole/trunk/src/mediafile.c
===================================================================
--- parole/trunk/src/mediafile.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/mediafile.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -60,7 +60,7 @@
file = PAROLE_MEDIA_FILE (object);
- TRACE ("Media file finalized %s", file->priv->display_name);
+ TRACE ("file finalized %s", file->priv->display_name);
if ( file->priv->path )
g_free (file->priv->path);
@@ -131,7 +131,7 @@
0,
NULL,
&error);
-
+
if ( error )
{
#ifdef DEBUG
@@ -141,7 +141,7 @@
file->priv->display_name = g_file_get_basename (gfile);
goto out;
}
-
+
file->priv->display_name = g_strdup (g_file_info_get_display_name (info));
file->priv->mime_type = g_strdup (g_file_info_get_content_type (info));
Modified: parole/trunk/src/medialist.c
===================================================================
--- parole/trunk/src/medialist.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/medialist.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -28,6 +28,7 @@
#include <gtk/gtk.h>
#include <glib.h>
+#include <gio/gio.h>
#include <libxfce4util/libxfce4util.h>
#include <libxfcegui4/libxfcegui4.h>
@@ -129,6 +130,7 @@
NAME_COL, parole_media_file_get_display_name (file),
DATA_COL, file,
-1);
+
if ( emit )
{
path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_store), &iter);
Modified: parole/trunk/src/player.c
===================================================================
--- parole/trunk/src/player.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/player.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -71,6 +71,10 @@
void parole_player_destroy_cb (GtkObject *window,
ParolePlayer *player);
+gboolean parole_player_delete_event_cb (GtkWidget *widget,
+ GdkEvent *ev,
+ ParolePlayer *player);
+
void parole_player_show_hide_playlist (GtkButton *button,
ParolePlayer *player);
@@ -525,20 +529,27 @@
{
player->priv->buffering = TRUE;
parole_statusbar_set_buffering (player->priv->status, percentage);
+
if ( player->priv->state == PAROLE_MEDIA_STATE_PLAYING )
parole_gst_pause (PAROLE_GST (player->priv->gst));
}
}
-void
-parole_player_destroy_cb (GtkObject *window, ParolePlayer *player)
+gboolean parole_player_delete_event_cb (GtkWidget *widget, GdkEvent *ev, ParolePlayer *player)
{
- parole_window_busy_cursor (GTK_WIDGET (window)->window);
+ parole_window_busy_cursor (GTK_WIDGET (player->priv->window)->window);
player->priv->exit = TRUE;
parole_gst_null_state (PAROLE_GST (player->priv->gst));
+
+ return TRUE;
}
+void
+parole_player_destroy_cb (GtkObject *window, ParolePlayer *player)
+{
+}
+
static void
parole_player_play_menu_item_activate (ParolePlayer *player)
{
@@ -731,7 +742,7 @@
void
parole_player_menu_exit_cb (GtkWidget *widget, ParolePlayer *player)
{
- parole_player_destroy_cb (NULL, player);
+ parole_player_delete_event_cb (NULL, NULL, player);
}
static const gchar *
Modified: parole/trunk/src/rc-utils.c
===================================================================
--- parole/trunk/src/rc-utils.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/rc-utils.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -75,7 +75,7 @@
XfceRc *rc = open_resource_file (TRUE);
if ( rc )
- return xfce_rc_read_bool_entry (rc, property, TRUE);
+ return xfce_rc_read_bool_entry (rc, property, fallback);
return fallback;
}
@@ -95,7 +95,7 @@
XfceRc *rc = open_resource_file (TRUE);
if ( rc )
- return xfce_rc_read_entry (rc, property, NULL);
+ return xfce_rc_read_entry (rc, property, fallback);
return fallback;
}
Modified: parole/trunk/src/utils.c
===================================================================
--- parole/trunk/src/utils.c 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/utils.c 2009-06-18 11:01:05 UTC (rev 7607)
@@ -29,8 +29,21 @@
#include <gst/gst.h>
#include <glib.h>
+#include <libxfce4util/libxfce4util.h>
+
#include "utils.h"
+/* List from xine-lib's demux_sputext.c */
+static const char subtitle_ext[][4] = {
+ "asc",
+ "txt",
+ "sub",
+ "srt",
+ "smi",
+ "ssa",
+ "ass"
+};
+
void parole_window_busy_cursor (GdkWindow *window)
{
GdkCursor *cursor;
@@ -244,3 +257,92 @@
else
return (ac > bc) ? 1 : -1;
}
+
+static gchar *
+parole_get_name_without_extension (const gchar *name)
+{
+ guint len, suffix;
+ gchar *ret;
+
+ len = strlen (name);
+
+ for ( suffix = len -1; suffix > 0; suffix--)
+ {
+ if ( name [suffix] == '.' )
+ break;
+ }
+
+ ret = g_strndup (name, sizeof (char) * (suffix));
+ return ret;
+}
+
+static gchar *
+parole_get_subtitle_in_dir (const gchar *dir_path, const gchar *file)
+{
+ gchar *sub_path = NULL;
+ gchar *file_no_ext;
+ guint i;
+
+ file_no_ext = parole_get_name_without_extension (file);
+
+ for ( i = 0; i < G_N_ELEMENTS (subtitle_ext); i++)
+ {
+ sub_path = g_strdup_printf ("%s/%s.%s", dir_path, file_no_ext, subtitle_ext[i]);
+
+ if ( g_file_test (sub_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) )
+ break;
+
+ g_free (sub_path);
+ sub_path = NULL;
+ }
+ g_free (file_no_ext);
+
+ return sub_path;
+}
+
+gchar *parole_get_subtitle_path (const gchar *uri)
+{
+ GFile *file, *parent;
+ GFileInfo *info;
+ GError *error = NULL;
+ gchar *path;
+ gchar *file_name;
+ gchar *ret = NULL;
+
+ file = g_file_new_for_commandline_arg (uri);
+ parent = g_file_get_parent (file);
+
+ if ( !parent )
+ {
+ g_object_unref (file);
+ return NULL;
+ }
+
+ info = g_file_query_info (file,
+ "standard::*,",
+ 0,
+ NULL,
+ &error);
+
+ if ( error )
+ {
+ g_warning ("%s: \n", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ file_name = g_strdup (g_file_info_get_display_name (info));
+
+ path = g_file_get_path (parent);
+
+ ret = parole_get_subtitle_in_dir (path, file_name);
+
+ g_object_unref (file);
+ g_object_unref (parent);
+ g_object_unref (info);
+
+ g_free (file_name);
+ g_free (path);
+
+ return ret;
+}
Modified: parole/trunk/src/utils.h
===================================================================
--- parole/trunk/src/utils.h 2009-06-17 22:06:33 UTC (rev 7606)
+++ parole/trunk/src/utils.h 2009-06-18 11:01:05 UTC (rev 7607)
@@ -33,4 +33,7 @@
gint thunar_file_compare_by_name (ParoleMediaFile *file_a,
ParoleMediaFile *file_b,
gboolean case_sensitive);
+
+gchar *parole_get_subtitle_path (const gchar *uri);
+
#endif /* __PAROLE_UTILS_ */
More information about the Goodies-commits
mailing list