totem r5956 - in trunk: . src/backend src/plugins/skipto



Author: pwithnall
Date: Mon Feb  9 22:06:21 2009
New Revision: 5956
URL: http://svn.gnome.org/viewvc/totem?rev=5956&view=rev

Log:
2009-02-09  Philip Withnall  <philip tecnocode co uk>

	* src/backend/video-utils.c (totem_string_to_time):
	* src/backend/video-utils.h: Utility function to convert a
	human-friendly time string to a gint64.
	* src/plugins/skipto/Makefile.am:
	* src/plugins/skipto/skipto.ui:
	* src/plugins/skipto/totem-skipto.c (totem_skipto_response_cb),
	(totem_skipto_init), (totem_skipto_update_range),
	(totem_skipto_get_range), (totem_skipto_set_current),
	(time_entry_activate_cb), (totem_skipto_new):
	* src/plugins/skipto/totem-time-entry.c
	(totem_time_entry_class_init), (totem_time_entry_init),
	(totem_time_entry_new), (output_cb), (input_cb):
	* src/plugins/skipto/totem-time-entry.h: Accept more human-friendly
	input formats in the "Skip to" dialogue using a new TotemTimeEntry
	widget. (Closes: #565988)



Added:
   trunk/src/plugins/skipto/totem-time-entry.c
   trunk/src/plugins/skipto/totem-time-entry.h
Modified:
   trunk/ChangeLog
   trunk/src/backend/video-utils.c
   trunk/src/backend/video-utils.h
   trunk/src/plugins/skipto/Makefile.am
   trunk/src/plugins/skipto/skipto.ui
   trunk/src/plugins/skipto/totem-skipto.c

Modified: trunk/src/backend/video-utils.c
==============================================================================
--- trunk/src/backend/video-utils.c	(original)
+++ trunk/src/backend/video-utils.c	Mon Feb  9 22:06:21 2009
@@ -228,6 +228,28 @@
 	return g_strdup_printf (C_("short time format", "%d:%02d"), min, sec);
 }
 
+gint64
+totem_string_to_time (const char *time_string)
+{
+	int sec, min, hour, args;
+
+	args = sscanf (time_string, C_("long time format", "%d:%02d:%02d"), &hour, &min, &sec);
+
+	if (args == 3) {
+		/* Parsed all three arguments successfully */
+		return (hour * (60 * 60) + min * 60 + sec) * 1000;
+	} else if (args == 2) {
+		/* Only parsed the first two arguments; treat hour and min as min and sec, respectively */
+		return (hour * 60 + min) * 1000;
+	} else if (args == 1) {
+		/* Only parsed the first argument; treat hour as sec */
+		return hour * 1000;
+	} else {
+		/* Error! */
+		return -1;
+	}
+}
+
 char *
 totem_time_to_string_text (gint64 msecs)
 {

Modified: trunk/src/backend/video-utils.h
==============================================================================
--- trunk/src/backend/video-utils.h	(original)
+++ trunk/src/backend/video-utils.h	Mon Feb  9 22:06:21 2009
@@ -15,6 +15,7 @@
 gboolean totem_display_is_local (void);
 
 char *totem_time_to_string (gint64 msecs);
+gint64 totem_string_to_time (const char *time_string);
 char *totem_time_to_string_text (gint64 msecs);
 
 void totem_widget_set_preferred_size (GtkWidget *widget, gint width,

Modified: trunk/src/plugins/skipto/Makefile.am
==============================================================================
--- trunk/src/plugins/skipto/Makefile.am	(original)
+++ trunk/src/plugins/skipto/Makefile.am	Mon Feb  9 22:06:21 2009
@@ -25,6 +25,8 @@
 libskipto_la_SOURCES = \
 	totem-skipto-plugin.c	\
 	totem-skipto-plugin.h	\
+	totem-time-entry.c	\
+	totem-time-entry.h	\
 	totem-skipto.c		\
 	totem-skipto.h
 libskipto_la_LDFLAGS = $(modules_flags)

Modified: trunk/src/plugins/skipto/skipto.ui
==============================================================================
--- trunk/src/plugins/skipto/skipto.ui	(original)
+++ trunk/src/plugins/skipto/skipto.ui	Mon Feb  9 22:06:21 2009
@@ -29,7 +29,7 @@
 	  <property name="yalign">0.5</property>
 	  <property name="xpad">0</property>
 	  <property name="ypad">0</property>
-	  <property name="mnemonic_widget">tstw_skip_spinbutton</property>
+	  <property name="mnemonic_widget">tstw_skip_time_entry</property>
 	  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
 	  <property name="width_chars">-1</property>
 	  <property name="single_line_mode">False</property>
@@ -54,20 +54,14 @@
               <property name="upper">0</property>
               <property name="step-increment">1</property>
               <property name="page-increment">10</property>
-              <property name="page-size">10</property>
+              <property name="page-size">0</property>
               <property name="value">0</property>
 	    </object>
-	    <object class="GtkSpinButton" id="tstw_skip_spinbutton">
-	      <property name="visible">True</property>
-	      <property name="can_focus">True</property>
+	    <object class="TotemTimeEntry" id="tstw_skip_time_entry">
 	      <property name="climb_rate">1</property>
-	      <property name="digits">0</property>
-	      <property name="numeric">False</property>
 	      <property name="update_policy">GTK_UPDATE_ALWAYS</property>
-	      <property name="snap_to_ticks">False</property>
-	      <property name="wrap">False</property>
 	      <property name="adjustment">tstw_skip_adjustment</property>
-	      <signal name="value-changed" handler="spin_button_value_changed_cb"/>
+	      <signal name="activate" handler="time_entry_activate_cb"/>
 	    </object>
 	    <packing>
 	      <property name="padding">0</property>
@@ -114,31 +108,6 @@
       <property name="fill">True</property>
     </packing>
   </child>
-
-  <child>
-    <object class="GtkLabel" id="tstw_position_label">
-      <property name="visible">True</property>
-      <property name="label" translatable="yes">0 seconds</property>
-      <property name="use_underline">False</property>
-      <property name="use_markup">False</property>
-      <property name="justify">GTK_JUSTIFY_LEFT</property>
-      <property name="wrap">False</property>
-      <property name="selectable">False</property>
-      <property name="xalign">0.5</property>
-      <property name="yalign">0.5</property>
-      <property name="xpad">0</property>
-      <property name="ypad">0</property>
-      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-      <property name="width_chars">-1</property>
-      <property name="single_line_mode">False</property>
-      <property name="angle">0</property>
-    </object>
-    <packing>
-      <property name="padding">0</property>
-      <property name="expand">False</property>
-      <property name="fill">False</property>
-    </packing>
-  </child>
 </object>
 
 </interface>

Modified: trunk/src/plugins/skipto/totem-skipto.c
==============================================================================
--- trunk/src/plugins/skipto/totem-skipto.c	(original)
+++ trunk/src/plugins/skipto/totem-skipto.c	Mon Feb  9 22:06:21 2009
@@ -45,13 +45,11 @@
 static void totem_skipto_dispose	(GObject *object);
 
 /* Callback functions for GtkBuilder */
-void spin_button_activate_cb (GtkEntry *entry, TotemSkipto *skipto);
-void spin_button_value_changed_cb (GtkSpinButton *spinbutton, TotemSkipto *skipto);
+void time_entry_activate_cb (GtkEntry *entry, TotemSkipto *skipto);
 
 struct TotemSkiptoPrivate {
 	GtkBuilder *xml;
-	GtkWidget *label;
-	GtkWidget *spinbutton;
+	GtkWidget *time_entry;
 	gint64 time;
 	Totem *totem;
 };
@@ -75,7 +73,7 @@
 	TotemSkipto *skipto;
 
 	skipto = TOTEM_SKIPTO (dialog);
-	gtk_spin_button_update (GTK_SPIN_BUTTON (skipto->priv->spinbutton));
+	gtk_spin_button_update (GTK_SPIN_BUTTON (skipto->priv->time_entry));
 }
 
 static void
@@ -83,6 +81,7 @@
 {
 	skipto->priv = G_TYPE_INSTANCE_GET_PRIVATE (skipto, TOTEM_TYPE_SKIPTO, TotemSkiptoPrivate);
 
+	gtk_dialog_set_default_response (GTK_DIALOG (skipto), GTK_RESPONSE_OK);
 	g_signal_connect (skipto, "response",
 				G_CALLBACK (totem_skipto_response_cb), NULL);
 }
@@ -108,7 +107,7 @@
 	if (time == skipto->priv->time)
 		return;
 
-	gtk_spin_button_set_range (GTK_SPIN_BUTTON (skipto->priv->spinbutton),
+	gtk_spin_button_set_range (GTK_SPIN_BUTTON (skipto->priv->time_entry),
 			0, (gdouble) time / 1000);
 	skipto->priv->time = time;
 }
@@ -120,7 +119,7 @@
 
 	g_return_val_if_fail (TOTEM_IS_SKIPTO (skipto), 0);
 
-	time = gtk_spin_button_get_value (GTK_SPIN_BUTTON (skipto->priv->spinbutton)) * 1000;
+	time = gtk_spin_button_get_value (GTK_SPIN_BUTTON (skipto->priv->time_entry)) * 1000;
 
 	return time;
 }
@@ -139,29 +138,17 @@
 {
 	g_return_if_fail (TOTEM_IS_SKIPTO (skipto));
 
-	gtk_spin_button_set_value (GTK_SPIN_BUTTON (skipto->priv->spinbutton),
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (skipto->priv->time_entry),
 			(gdouble) (time / 1000));
 }
 
 void
-spin_button_activate_cb (GtkEntry *entry, TotemSkipto *skipto)
+time_entry_activate_cb (GtkEntry *entry, TotemSkipto *skipto)
 {
 	gtk_dialog_response (GTK_DIALOG (skipto), GTK_RESPONSE_OK);
 }
 
-void
-spin_button_value_changed_cb (GtkSpinButton *spinbutton, TotemSkipto *skipto)
-{
-	int sec;
-	char *str;
-
-	sec = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinbutton));
-	str = totem_time_to_string_text (sec * 1000);
-	gtk_label_set_text (GTK_LABEL (skipto->priv->label), str);
-	g_free (str);
-}
-
-GtkWidget*
+GtkWidget *
 totem_skipto_new (TotemSkiptoPlugin *plugin)
 {
 	TotemSkipto *skipto;
@@ -178,30 +165,28 @@
 		g_object_unref (skipto);
 		return NULL;
 	}
-	skipto->priv->label = GTK_WIDGET (gtk_builder_get_object
-		(skipto->priv->xml, "tstw_position_label"));
-	skipto->priv->spinbutton = GTK_WIDGET (gtk_builder_get_object
-		(skipto->priv->xml, "tstw_skip_spinbutton"));
+	skipto->priv->time_entry = GTK_WIDGET (gtk_builder_get_object
+		(skipto->priv->xml, "tstw_skip_time_entry"));
 
 	gtk_window_set_title (GTK_WINDOW (skipto), _("Skip to"));
 	gtk_dialog_set_has_separator (GTK_DIALOG (skipto), FALSE);
 	gtk_dialog_add_buttons (GTK_DIALOG (skipto),
-			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-			GTK_STOCK_OK, GTK_RESPONSE_OK,
-			NULL);
+				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+				GTK_STOCK_OK, GTK_RESPONSE_OK,
+				NULL);
 
 	/* Skipto dialog */
 	g_signal_connect (G_OBJECT (skipto), "delete-event",
-			G_CALLBACK (gtk_widget_destroy), skipto);
+			  G_CALLBACK (gtk_widget_destroy), skipto);
 
 	container = GTK_WIDGET (gtk_builder_get_object (skipto->priv->xml,
-			"tstw_skip_vbox"));
+				"tstw_skip_vbox"));
 	gtk_container_set_border_width (GTK_CONTAINER (skipto), 5);
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (skipto)->vbox),
-			container,
-			TRUE,       /* expand */
-			TRUE,       /* fill */
-			0);         /* padding */
+			    container,
+			    TRUE,       /* expand */
+			    TRUE,       /* fill */
+			    0);         /* padding */
 
 	gtk_window_set_transient_for (GTK_WINDOW (skipto),
 				      totem_get_main_window (plugin->totem));

Added: trunk/src/plugins/skipto/totem-time-entry.c
==============================================================================
--- (empty file)
+++ trunk/src/plugins/skipto/totem-time-entry.c	Mon Feb  9 22:06:21 2009
@@ -0,0 +1,89 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Copyright (C) 2008 Philip Withnall <philip tecnocode co uk>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ * The Totem project hereby grant permission for non-gpl compatible GStreamer
+ * plugins to be used and distributed together with GStreamer and Totem. This
+ * permission are above and beyond the permissions granted by the GPL license
+ * Totem is covered by.
+ *
+ * Monday 7th February 2005: Christian Schaller: Add excemption clause.
+ * See license_change file for details.
+ *
+ * Author: Philip Withnall <philip tecnocode co uk>
+ */
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "video-utils.h"
+#include "totem-time-entry.h"
+
+static gboolean output_cb (GtkSpinButton *self, gpointer user_data);
+static gint input_cb (GtkSpinButton *self, gdouble *new_value, gpointer user_data);
+
+G_DEFINE_TYPE (TotemTimeEntry, totem_time_entry, GTK_TYPE_SPIN_BUTTON)
+
+static void
+totem_time_entry_class_init (TotemTimeEntryClass *klass)
+{
+	/* Nothing to see here; please move along */
+}
+
+static void
+totem_time_entry_init (TotemTimeEntry *self)
+{
+	/* Connect to signals */
+	g_signal_connect (self, "output", G_CALLBACK (output_cb), NULL);
+	g_signal_connect (self, "input", G_CALLBACK (input_cb), NULL);
+}
+
+GtkWidget *
+totem_time_entry_new (GtkAdjustment *adjustment, gdouble climb_rate)
+{
+	return g_object_new (TOTEM_TYPE_TIME_ENTRY,
+			     "adjustment", adjustment,
+			     "climb-rate", climb_rate,
+			     "digits", 0,
+			     "numeric", FALSE,
+			     NULL);
+}
+
+static gboolean
+output_cb (GtkSpinButton *self, gpointer user_data)
+{
+	gchar *text;
+
+	text = totem_time_to_string ((gint64) gtk_spin_button_get_value (self) * 1000);
+	gtk_entry_set_text (GTK_ENTRY (self), text);
+	g_free (text);
+
+	return TRUE;
+}
+
+static gint
+input_cb (GtkSpinButton *self, gdouble *new_value, gpointer user_data)
+{
+	gint64 val;
+
+	val = totem_string_to_time (gtk_entry_get_text (GTK_ENTRY (self)));
+	if (val == -1)
+		return GTK_INPUT_ERROR;
+
+	*new_value = val / 1000;
+	return TRUE;
+}

Added: trunk/src/plugins/skipto/totem-time-entry.h
==============================================================================
--- (empty file)
+++ trunk/src/plugins/skipto/totem-time-entry.h	Mon Feb  9 22:06:21 2009
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Copyright (C) 2008 Philip Withnall <philip tecnocode co uk>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ * The Totem project hereby grant permission for non-gpl compatible GStreamer
+ * plugins to be used and distributed together with GStreamer and Totem. This
+ * permission are above and beyond the permissions granted by the GPL license
+ * Totem is covered by.
+ *
+ * Monday 7th February 2005: Christian Schaller: Add excemption clause.
+ * See license_change file for details.
+ *
+ * Author: Philip Withnall <philip tecnocode co uk>
+ */
+
+#ifndef TOTEM_TIME_ENTRY_H
+#define TOTEM_TIME_ENTRY_H
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define TOTEM_TYPE_TIME_ENTRY		(totem_time_entry_get_type ())
+#define TOTEM_TIME_ENTRY(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_TIME_ENTRY, TotemTimeEntry))
+#define TOTEM_TIME_ENTRY_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_TIME_ENTRY, TotemTimeEntryClass))
+#define TOTEM_IS_TIME_ENTRY(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_TIME_ENTRY))
+#define TOTEM_IS_TIME_ENTRY_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_TIME_ENTRY))
+#define TOTEM_TIME_ENTRY_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_TIME_ENTRY, TotemTimeEntryClass))
+
+typedef struct {
+	GtkSpinButton parent;
+} TotemTimeEntry;
+
+typedef struct {
+	GtkSpinButtonClass parent;
+} TotemTimeEntryClass;
+
+GType totem_time_entry_get_type (void);
+GtkWidget *totem_time_entry_new (GtkAdjustment *adjustment, gdouble climb_rate);
+
+G_END_DECLS
+
+#endif /* !TOTEM_TIME_ENTRY_H */



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