[Xfce4-commits] <parole:master> Added volume to control to the browser plugin and its size allocate.

Ali Abdallah noreply at xfce.org
Thu Nov 19 21:02:05 CET 2009


Updating branch refs/heads/master
         to 44395e70d30e4d6297bd69110b69575001be34a6 (commit)
       from 582b21c28600e11968e3e7c7a26f0f06e1f49505 (commit)

commit 44395e70d30e4d6297bd69110b69575001be34a6
Author: Ali Abdallah <ali at ali-xfce.org>
Date:   Thu Nov 19 20:51:45 2009 +0100

    Added volume to control to the browser plugin and
    its size allocate.

 browser-plugin/media-plugin/main.c                 |    1 -
 browser-plugin/media-plugin/parole-plugin-player.c |  267 +++++++++++++++++---
 browser-plugin/media-plugin/parole-plugin-player.h |    1 -
 browser-plugin/npp_gate.cpp                        |    1 -
 data/interfaces/Makefile.am                        |    6 +-
 data/interfaces/browser-plugin-control.ui          |   41 ---
 gst/parole-gst.c                                   |   22 +--
 7 files changed, 228 insertions(+), 111 deletions(-)

diff --git a/browser-plugin/media-plugin/main.c b/browser-plugin/media-plugin/main.c
index 3508868..6722d4f 100644
--- a/browser-plugin/media-plugin/main.c
+++ b/browser-plugin/media-plugin/main.c
@@ -96,7 +96,6 @@ int main (int argc, char **argv)
     plug = gtk_plug_new (socket_id);
 	
     player = parole_plugin_player_new (plug, url);
-	
     gtk_widget_show_all (plug);
     
     gtk_main ();
diff --git a/browser-plugin/media-plugin/parole-plugin-player.c b/browser-plugin/media-plugin/parole-plugin-player.c
index 2bde37e..851c7bc 100644
--- a/browser-plugin/media-plugin/parole-plugin-player.c
+++ b/browser-plugin/media-plugin/parole-plugin-player.c
@@ -26,11 +26,14 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <libxfce4util/libxfce4util.h>
+
 #include "parole-plugin-player.h"
 
 #include "gst/parole-gst.h"
 #include "dbus/parole-dbus.h"
-#include "interfaces/browser-plugin-control_ui.h"
+
+#define RESOURCE_FILE 	"xfce4/parole/browser-plugin.rc"
 
 /*
  * DBus Glib init
@@ -59,6 +62,10 @@ struct ParolePluginPlayerPrivate
     GtkWidget	 *controls;
     GtkWidget	 *play;
     GtkWidget	 *range;
+    GtkWidget    *full_screen;
+    GtkWidget    *volume;
+    
+    ParoleMediaState state;
     
     gboolean      internal_range_change;
     gboolean      user_seeking;
@@ -76,22 +83,132 @@ enum
 
 G_DEFINE_TYPE (ParolePluginPlayer, parole_plugin_player, G_TYPE_OBJECT)
 
+static gboolean
+read_entry_int (const gchar *entry, gint fallback)
+{
+    gint ret_val = fallback;
+    gchar *file;
+    XfceRc *rc;
+    
+    file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, RESOURCE_FILE, TRUE);
+    rc = xfce_rc_simple_open (file, TRUE);
+    g_free (file);
+    
+    if ( rc )
+    {
+	ret_val = xfce_rc_read_int_entry (rc, entry, fallback);
+	xfce_rc_close (rc);
+    }
+    
+    return ret_val;
+}
+
 static void
-parole_plugin_player_play_clicked_cb (ParoleGst *gst)
+write_entry_int (const gchar *entry, gint value)
 {
+    gchar *file;
+    XfceRc *rc;
+    
+    file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, RESOURCE_FILE, TRUE);
+    rc = xfce_rc_simple_open (file, FALSE);
+    g_free (file);
+    
+    xfce_rc_write_int_entry (rc, entry, value);
+    xfce_rc_close (rc);
+}
+
+static void
+parole_plugin_player_set_play_button_image (ParolePluginPlayer *player)
+{
+    GtkWidget *img;
+    
+    g_object_get (G_OBJECT (player->priv->play),
+                  "image", &img,
+                  NULL);
+
+    if ( player->priv->state == PAROLE_MEDIA_STATE_PLAYING )
+    {
+        g_object_set (G_OBJECT (img),
+                      "stock", GTK_STOCK_MEDIA_PAUSE,
+                      NULL);
+    }
+    else
+    {
+        g_object_set (G_OBJECT (img),
+                      "stock", GTK_STOCK_MEDIA_PLAY,
+                      NULL);
+                      
+    }
+    g_object_unref (img);
+}
+
+static void
+parole_plugin_player_play_clicked_cb (ParolePluginPlayer *player)
+{
+    if ( player->priv->state == PAROLE_MEDIA_STATE_PLAYING )
+	parole_gst_pause (player->priv->gst);
+    else if ( player->priv->state == PAROLE_MEDIA_STATE_PAUSED )
+	parole_gst_resume (player->priv->gst);
+}
+
+static void
+parole_plugin_player_change_range_value (ParolePluginPlayer *player, gdouble value)
+{
+    if ( !player->priv->user_seeking )
+    {
+	player->priv->internal_range_change = TRUE;
+    
+	gtk_range_set_value (GTK_RANGE (player->priv->range), value);
+
+	player->priv->internal_range_change = FALSE;
+    }
 }
 
 static void
 parole_plugin_player_media_state_cb (ParoleGst *gst, const ParoleStream *stream, 
 				     ParoleMediaState state, ParolePluginPlayer *player)
 {
+    gboolean has_video;
+    
+    
+    g_object_get (G_OBJECT (stream),
+		  "has-video", &has_video,
+		  NULL);
+    
+    g_object_set (G_OBJECT (player->priv->full_screen),
+		  "visible", has_video,
+		  NULL);
+    
+    player->priv->state = state;
+    parole_plugin_player_set_play_button_image (player);
+    
     if ( state == PAROLE_MEDIA_STATE_PLAYING )
     {
-	//parole_player_playing (player, stream);
+	gdouble duration;
+	gboolean seekable;
+	
+	g_object_get (G_OBJECT (stream),
+		      "seekable", &seekable,
+		      "duration", &duration,
+		      NULL);
+	
+	gtk_widget_set_sensitive (player->priv->range, seekable);
+	
+	if ( seekable )
+	{
+	    player->priv->internal_range_change = TRUE;
+	    gtk_range_set_range (GTK_RANGE (player->priv->range), 0, duration);
+	    player->priv->internal_range_change = FALSE;
+	}
+	else
+	{
+	    gtk_widget_set_tooltip_text (GTK_WIDGET (player->priv->range), _("Media stream is not seekable"));
+	    parole_plugin_player_change_range_value (player, 0);
+	}
     }
     else if ( state == PAROLE_MEDIA_STATE_PAUSED )
     {
-	//parole_player_paused (player);
+	parole_plugin_player_change_range_value (player, 0);
     }
     else if ( state == PAROLE_MEDIA_STATE_STOPPED )
     {
@@ -100,11 +217,11 @@ parole_plugin_player_media_state_cb (ParoleGst *gst, const ParoleStream *stream,
 	    g_object_unref (player);
 	    gtk_main_quit ();
 	}
-	//parole_player_stopped (player);
+	parole_plugin_player_change_range_value (player, 0);
     }
     else if ( state == PAROLE_MEDIA_STATE_FINISHED )
     {
-	//
+	parole_plugin_player_change_range_value (player, 0);
     }
 }
 
@@ -152,15 +269,19 @@ parole_plugin_player_range_button_press (GtkWidget *widget, GdkEventButton *ev,
 }
 
 static void
-parole_plugin_player_change_range_value (ParolePluginPlayer *player, gdouble value)
+parole_plugin_player_volume_changed_cb (GtkWidget *volume, gdouble value, ParolePluginPlayer *player)
 {
-    if ( !player->priv->user_seeking )
-    {
-	player->priv->internal_range_change = TRUE;
-    
-	gtk_range_set_value (GTK_RANGE (player->priv->range), value);
+    parole_gst_set_volume (player->priv->gst, value);
+    write_entry_int ("volume", (gint) (value * 100));
+}
 
-	player->priv->internal_range_change = FALSE;
+static void
+parole_plugin_player_media_progressed_cb (ParoleGst *gst, const ParoleStream *stream, 
+					  gdouble value, ParolePluginPlayer *player)
+{
+    if ( !player->priv->user_seeking && player->priv->state == PAROLE_MEDIA_STATE_PLAYING )
+    {
+	parole_plugin_player_change_range_value (player, value);
     }
 }
 
@@ -168,32 +289,66 @@ static void
 parole_plugin_player_construct (GObject *object)
 {
     ParolePluginPlayer *player;
-    GtkBuilder *builder;
-    GError *error = NULL;
-    GtkWidget *box;
-    
-    builder = gtk_builder_new ();
-    gtk_builder_add_from_string (builder, 
-				 browser_plugin_control_ui, 
-				 browser_plugin_control_ui_length,
-				 &error);
-				 
-    if ( error )
-    {
-	g_error ("%s", error->message);
-    }
+    GtkObject *adj;
+    GtkWidget *vbox;
+    GtkWidget *hbox;
+    GtkWidget *img;
+    GtkWidget *sep;
     
     player = PAROLE_PLUGIN_PLAYER (object);
     
-    player->priv->controls = GTK_WIDGET (gtk_builder_get_object (builder, "controls"));
+    vbox = gtk_vbox_new (FALSE, 0);
     
-    player->priv->range = GTK_WIDGET (gtk_builder_get_object (builder, "scale"));
+    /*
+     * Gst Widget
+     */
+    player->priv->gst = PAROLE_GST (parole_gst_new (TRUE, NULL));
     
-    player->priv->play = GTK_WIDGET (gtk_builder_get_object (builder, "play"));
+    gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (player->priv->gst), TRUE, TRUE, 0);
+    
+    g_signal_connect (G_OBJECT (player->priv->gst), "media-state",
+		      G_CALLBACK (parole_plugin_player_media_state_cb), player);
+
+    g_signal_connect (G_OBJECT (player->priv->gst), "media-progressed",
+		      G_CALLBACK (parole_plugin_player_media_progressed_cb), player);
+
+
+    hbox = gtk_hbox_new (FALSE, 0);
+    /*
+     * Play button
+     */
+    player->priv->play = gtk_button_new ();
     
     g_signal_connect_swapped (player->priv->play, "clicked",
 			      G_CALLBACK (parole_plugin_player_play_clicked_cb), player);
-
+    
+    img = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_MENU);
+    
+    g_object_set (G_OBJECT (player->priv->play),
+		  "receives-default", FALSE,
+		  "can-focus", FALSE,
+		  "relief", GTK_RELIEF_NONE,
+		  "image", img,
+		  NULL);
+		  
+    gtk_box_pack_start (GTK_BOX (hbox), player->priv->play, 
+			FALSE, FALSE, 0);
+		
+    sep = gtk_vseparator_new ();
+    gtk_box_pack_start (GTK_BOX (hbox), sep ,
+			FALSE, FALSE, 0);
+    /*
+     * Media range
+     */
+    player->priv->range = gtk_hscale_new (NULL);
+    g_object_set (G_OBJECT (player->priv->range),
+		  "draw-value", FALSE, 
+		  "show-fill-level", TRUE,
+		  NULL);
+	
+    gtk_box_pack_start (GTK_BOX (hbox), player->priv->range, 
+			TRUE, TRUE, 0);
+    
     g_signal_connect (player->priv->range, "button-press-event",
 		      G_CALLBACK (parole_plugin_player_range_button_press), player);
 
@@ -202,19 +357,48 @@ parole_plugin_player_construct (GObject *object)
 		      
     g_signal_connect (player->priv->range, "value-changed",
 		      G_CALLBACK (parole_plugin_player_range_value_changed), player);
+		
+    sep = gtk_vseparator_new ();
+    gtk_box_pack_start (GTK_BOX (hbox), sep,
+			FALSE, FALSE, 0);
+			
+    /*
+     * Full screen button
+     */
+    player->priv->full_screen = gtk_button_new ();
+    img = gtk_image_new_from_stock (GTK_STOCK_FULLSCREEN, GTK_ICON_SIZE_MENU);
+    g_object_set (G_OBJECT (player->priv->full_screen),
+		  "receives-default", FALSE,
+		  "can-focus", FALSE,
+		  "relief", GTK_RELIEF_NONE,
+		  "image", img,
+		  NULL);
+		  
+    gtk_box_pack_start (GTK_BOX (hbox), player->priv->full_screen, 
+			FALSE, FALSE, 0);
+    sep = gtk_vseparator_new ();
+    gtk_box_pack_start (GTK_BOX (hbox), sep, 
+			FALSE, FALSE, 0);
+
+    /*
+     * Volume button
+     */
+    adj = gtk_adjustment_new (0.,
+			      0., 1., 1., 0., 0.);
+    player->priv->volume = g_object_new (GTK_TYPE_VOLUME_BUTTON,
+					 "adjustment", adj,
+					 NULL);
+    gtk_adjustment_set_value (GTK_ADJUSTMENT (adj), (gdouble) (read_entry_int ("volume", 100)/100.) );
+    gtk_box_pack_start (GTK_BOX (hbox), player->priv->volume, 
+			FALSE, FALSE,  0);
+	
+    g_signal_connect (player->priv->volume, "value-changed",
+		      G_CALLBACK (parole_plugin_player_volume_changed_cb), player);
     
-    box = gtk_vbox_new (FALSE, 0);
-    
-    player->priv->gst = PAROLE_GST (parole_gst_new (TRUE, NULL));
-    
-    g_signal_connect (G_OBJECT (player->priv->gst), "media-state",
-		      G_CALLBACK (parole_plugin_player_media_state_cb), player);
     
-    gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (player->priv->gst), TRUE, TRUE, 0);
-    gtk_box_pack_start (GTK_BOX (box), player->priv->controls, 
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, 
 			FALSE, FALSE, 0);
-    
-    gtk_container_add (GTK_CONTAINER (player->priv->plug), box);
+    gtk_container_add (GTK_CONTAINER (player->priv->plug), vbox);
     
     player->priv->sig = g_signal_connect (player->priv->plug, "delete-event",
 					  G_CALLBACK (parole_plugin_player_terminate), player);
@@ -270,6 +454,7 @@ parole_plugin_player_init (ParolePluginPlayer *player)
     player->priv->terminate = FALSE;
     player->priv->user_seeking = FALSE;
     player->priv->internal_range_change = FALSE;
+    player->priv->state = PAROLE_MEDIA_STATE_STOPPED;
     
     parole_plugin_player_dbus_init (player);
 }
diff --git a/browser-plugin/media-plugin/parole-plugin-player.h b/browser-plugin/media-plugin/parole-plugin-player.h
index aa5e050..ec354c3 100644
--- a/browser-plugin/media-plugin/parole-plugin-player.h
+++ b/browser-plugin/media-plugin/parole-plugin-player.h
@@ -49,7 +49,6 @@ GType        				 parole_plugin_player_get_type        (void) G_GNUC_CONST;
 
 ParolePluginPlayer       		*parole_plugin_player_new             (GtkWidget *plug,
 									       gchar *url);
-
 G_END_DECLS
 
 #endif /* __PAROLE_PLUGIN_PLAYER_H */
diff --git a/browser-plugin/npp_gate.cpp b/browser-plugin/npp_gate.cpp
index 869f90d..e4ce7ad 100644
--- a/browser-plugin/npp_gate.cpp
+++ b/browser-plugin/npp_gate.cpp
@@ -132,7 +132,6 @@ NPError NPP_SetWindow(NPP instance, NPWindow * pNPWindow)
 
     // window resized
     if (pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
-        printf("Window resized\n");
         pPlugin->SetWindow(pNPWindow);
         return NPERR_NO_ERROR;
     }
diff --git a/data/interfaces/Makefile.am b/data/interfaces/Makefile.am
index e8851b7..dbb3922 100644
--- a/data/interfaces/Makefile.am
+++ b/data/interfaces/Makefile.am
@@ -4,8 +4,7 @@ interfaces =					\
 	playlist.ui				\
 	mediachooser.ui				\
 	save-playlist.ui			\
-	plugins.ui				\
-	browser-plugin-control.ui
+	plugins.ui
 
 interfaces_h = 					\
 	$(interfaces:.ui=_ui.h)
@@ -31,9 +30,6 @@ save-playlist_ui.h: save-playlist.ui
 plugins_ui.h: plugins.ui
 	exo-csource --static --strip-comments --strip-content --name=plugins_ui $< > $@
 
-browser-plugin-control_ui.h: browser-plugin-control.ui
-	exo-csource --static --strip-comments --strip-content --name=browser_plugin_control_ui $< > $@
-
 endif
 
 CLEANFILES =					\
diff --git a/data/interfaces/browser-plugin-control.ui b/data/interfaces/browser-plugin-control.ui
deleted file mode 100644
index 3aa9a9b..0000000
--- a/data/interfaces/browser-plugin-control.ui
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0"?>
-<interface>
-  <requires lib="gtk+" version="2.16"/>
-  <!-- interface-naming-policy project-wide -->
-  <object class="GtkHBox" id="controls">
-    <property name="visible">True</property>
-    <property name="spacing">2</property>
-    <child>
-      <object class="GtkButton" id="play">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="receives_default">False</property>
-        <property name="image">image1</property>
-        <property name="relief">none</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="fill">False</property>
-        <property name="position">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkHScale" id="scale">
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="draw_value">False</property>
-      </object>
-      <packing>
-        <property name="position">1</property>
-      </packing>
-    </child>
-    <child>
-      <placeholder/>
-    </child>
-  </object>
-  <object class="GtkImage" id="image1">
-    <property name="visible">True</property>
-    <property name="stock">gtk-media-play</property>
-    <property name="icon-size">1</property>
-  </object>
-</interface>
diff --git a/gst/parole-gst.c b/gst/parole-gst.c
index 5b15b0a..04e94b2 100644
--- a/gst/parole-gst.c
+++ b/gst/parole-gst.c
@@ -164,23 +164,6 @@ parole_gst_configure_event_cb (GtkWidget *widget, GdkEventConfigure *ev, ParoleG
     return FALSE;
 }
 
-static gboolean
-parole_gst_parent_expose_event (GtkWidget *w, GdkEventExpose *ev, ParoleGst *gst)
-{
-    cairo_t *cr;
-    
-    cr = gdk_cairo_create (w->window);
-    
-    cairo_set_source_rgb (cr, 0.0f, 0.0f, 0.0f);
-    
-    cairo_rectangle (cr, w->allocation.x, w->allocation.y, w->allocation.width, w->allocation.height);
-    
-    cairo_fill (cr);
-    cairo_destroy (cr);
-    
-    return FALSE;
-}
-
 static void
 parole_gst_realize (GtkWidget *widget)
 {
@@ -222,9 +205,6 @@ parole_gst_realize (GtkWidget *widget)
     
     g_signal_connect (gtk_widget_get_toplevel (widget), "configure_event",
 		      G_CALLBACK (parole_gst_configure_event_cb), gst);
-		      
-    g_signal_connect (gtk_widget_get_parent (widget), "expose_event",
-		      G_CALLBACK (parole_gst_parent_expose_event), gst);
 }
 
 static void
@@ -330,7 +310,7 @@ parole_gst_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
     
     widget->allocation = *allocation;
 
-    if ( GTK_WIDGET_REALIZED (widget) && !PAROLE_GST (widget)->priv->embedded )
+    if ( GTK_WIDGET_REALIZED (widget) )
     {
 	gint w, h;
 	gdouble ratio, width, height;



More information about the Xfce4-commits mailing list