[rhythmbox] prefs: allow plugins to add widgets to the general and playback pages



commit 0ea0854cb9376fffc8ad7572f7020db6be07c231
Author: Jonathan Matthew <jonathan d14n org>
Date:   Mon Aug 23 11:19:32 2010 +1000

    prefs: allow plugins to add widgets to the general and playback pages

 bindings/python/Makefile.am  |    1 +
 bindings/python/rb.defs      |   56 +++++++++++++++++++++++++++++++++++
 data/ui/general-prefs.ui     |   12 +++++++
 data/ui/playback-prefs.ui    |   13 ++++++++
 shell/rb-shell-preferences.c |   66 ++++++++++++++++++++++++++++++++++++++++++
 shell/rb-shell-preferences.h |   17 +++++++++++
 shell/rb-shell.c             |   22 +++++++++----
 7 files changed, 180 insertions(+), 7 deletions(-)
---
diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am
index 280397f..cd20a7a 100644
--- a/bindings/python/Makefile.am
+++ b/bindings/python/Makefile.am
@@ -69,6 +69,7 @@ RB_BINDING_HEADERS_SRCDIR_IN = \
 	shell/rb-removable-media-manager.h	\
 	shell/rb-shell.h			\
 	shell/rb-shell-player.h			\
+	shell/rb-shell-preferences.h		\
 	shell/rb-track-transfer-batch.h		\
 	shell/rb-track-transfer-queue.h		\
 	sources/rb-source.h			\
diff --git a/bindings/python/rb.defs b/bindings/python/rb.defs
index 103e91e..8c20dca 100644
--- a/bindings/python/rb.defs
+++ b/bindings/python/rb.defs
@@ -200,6 +200,13 @@
   (gtype-id "RB_TYPE_RATING")
 )
 
+(define-object ShellPreferences
+  (in-module "RB")
+  (parent "GtkDialog")
+  (c-name "RBShellPreferences")
+  (gtype-id "RB_TYPE_SHELL_PREFERENCES")
+)
+
 ;; Enumerations and flags ...
 
 (define-enum ShellPlayerError
@@ -321,6 +328,16 @@
   )
 )
 
+(define-enum ShellPrefsUILocation
+  (in-module "RB")
+  (c-name "RBShellPrefsUILocation")
+  (gtype-id "RB_TYPE_SHELL_PREFS_UI_LOCATION")
+  (values
+    '("general" "RB_SHELL_PREFS_UI_LOCATION_GENERAL")
+    '("playback" "RB_SHELL_PREFS_UI_LOCATION_PLAYBACK")
+  )
+)
+
 (define-enum MetaDataField
   (in-module "RB")
   (c-name "RBMetaDataField")
@@ -3057,3 +3074,42 @@
   (is-constructor-of "RBRating")
   (return-type "RBRating*")
 )
+
+;; From rb-shell-preferences.h
+
+(define-function shell_preferences_get_type
+  (c-name "rb_shell_preferences_get_type")
+  (return-type "GType")
+)
+
+(define-method append_page
+  (of-object "RBShellPreferences")
+  (c-name "rb_shell_preferences_append_page")
+  (return-type "none")
+  (parameters
+    '("const-char*" "name")
+    '("GtkWidget*" "widget")
+  )
+)
+
+(define-method add_widget
+  (of-object "RBShellPreferences")
+  (c-name "rb_shell_preferences_add_widget")
+  (return-type "none")
+  (parameters
+    '("GtkWidget*" "widget")
+    '("RBShellPrefsUILocation" "location")
+    '("gboolean" "expand")
+    '("gboolean" "fill")
+  )
+)
+
+(define-method remove_widget
+  (of-object "RBShellPreferences")
+  (c-name "rb_shell_preferences_remove_widget")
+  (return-type "none")
+  (parameters
+    '("GtkWidget*" "widget")
+    '("RBShellPrefsUILocation" "location")
+  )
+)
diff --git a/data/ui/general-prefs.ui b/data/ui/general-prefs.ui
index 295ff2c..aa3575d 100644
--- a/data/ui/general-prefs.ui
+++ b/data/ui/general-prefs.ui
@@ -586,5 +586,17 @@
         <property name="position">2</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkVBox" id="plugin_box">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="position">3</property>
+      </packing>
+    </child>
   </object>
 </interface>
diff --git a/data/ui/playback-prefs.ui b/data/ui/playback-prefs.ui
index 93ac506..fa8a536 100644
--- a/data/ui/playback-prefs.ui
+++ b/data/ui/playback-prefs.ui
@@ -181,6 +181,19 @@
         </child>
       </object>
       <packing>
+        <property name="expand">False</property>
+        <property name="position">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkVBox" id="plugin_box">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
         <property name="position">3</property>
       </packing>
     </child>
diff --git a/shell/rb-shell-preferences.c b/shell/rb-shell-preferences.c
index b057312..c7f45d9 100644
--- a/shell/rb-shell-preferences.c
+++ b/shell/rb-shell-preferences.c
@@ -61,6 +61,7 @@
 #include "rb-debug.h"
 #include "eel-gconf-extensions.h"
 #include "rb-preferences.h"
+#include "rb-shell.h"
 
 static void rb_shell_preferences_class_init (RBShellPreferencesClass *klass);
 static void rb_shell_preferences_init (RBShellPreferences *shell_preferences);
@@ -117,10 +118,12 @@ struct RBShellPreferencesPrivate
 	GtkWidget *quality_check;
 	GtkWidget *year_check;
 	GtkWidget *location_check;
+	GtkWidget *general_prefs_plugin_box;
 
 	GtkWidget *xfade_backend_check;
 	GtkWidget *transition_duration;
 	GtkWidget *network_buffer_size;
+	GtkWidget *playback_prefs_plugin_box;
 
 	GSList *browser_views_group;
 
@@ -267,6 +270,11 @@ rb_shell_preferences_init (RBShellPreferences *shell_preferences)
 	eel_gconf_notification_add (CONF_UI_DIR,
 				    (GConfClientNotifyFunc) rb_shell_preferences_ui_pref_changed,
 				    shell_preferences);
+
+	/* box for stuff added by plugins */
+	shell_preferences->priv->general_prefs_plugin_box =
+		GTK_WIDGET (gtk_builder_get_object (builder, "plugin_box"));
+
 	g_object_unref (builder);
 
 	/* playback preferences */
@@ -282,6 +290,8 @@ rb_shell_preferences_init (RBShellPreferences *shell_preferences)
 		GTK_WIDGET (gtk_builder_get_object (builder, "duration"));
 	shell_preferences->priv->network_buffer_size =
 		GTK_WIDGET (gtk_builder_get_object (builder, "network_buffer_size"));
+	shell_preferences->priv->playback_prefs_plugin_box =
+		GTK_WIDGET (gtk_builder_get_object (builder, "plugin_box"));
 
 	g_signal_connect_object (shell_preferences->priv->xfade_backend_check,
 				 "toggled",
@@ -693,3 +703,59 @@ rb_shell_preferences_network_buffer_size_cb (GtkRange *range,
 	eel_gconf_set_integer (CONF_PLAYER_NETWORK_BUFFER_SIZE, (int)v);
 }
 
+static GtkWidget *
+get_box_for_location (RBShellPreferences *prefs, RBShellPrefsUILocation location)
+{
+	switch (location) {
+	case RB_SHELL_PREFS_UI_LOCATION_GENERAL:
+		return prefs->priv->general_prefs_plugin_box;
+	case RB_SHELL_PREFS_UI_LOCATION_PLAYBACK:
+		return prefs->priv->playback_prefs_plugin_box;
+	default:
+		g_assert_not_reached();
+	}
+}
+
+void
+rb_shell_preferences_add_widget (RBShellPreferences *prefs,
+				 GtkWidget *widget,
+				 RBShellPrefsUILocation location,
+				 gboolean expand,
+				 gboolean fill)
+{
+	GtkWidget *box;
+
+	box = get_box_for_location (prefs, location);
+	gtk_box_pack_start (GTK_BOX (box), widget, expand, fill, 0);
+}
+
+void
+rb_shell_preferences_remove_widget (RBShellPreferences *prefs,
+				    GtkWidget *widget,
+				    RBShellPrefsUILocation location)
+{
+	GtkWidget *box;
+
+	box = get_box_for_location (prefs, location);
+	gtk_container_remove (GTK_CONTAINER (box), widget);
+}
+
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+
+GType
+rb_shell_prefs_ui_location_get_type (void)
+{
+	static GType etype = 0;
+
+	if (etype == 0)	{
+		static const GEnumValue values[] = {
+			ENUM_ENTRY (RB_SHELL_PREFS_UI_LOCATION_GENERAL, "general"),
+			ENUM_ENTRY (RB_SHELL_PREFS_UI_LOCATION_PLAYBACK, "playback"),
+			{ 0, 0, 0 }
+		};
+
+		etype = g_enum_register_static ("RBShellPrefsUILocation", values);
+	}
+
+	return etype;
+}
diff --git a/shell/rb-shell-preferences.h b/shell/rb-shell-preferences.h
index 36b8017..2377097 100644
--- a/shell/rb-shell-preferences.h
+++ b/shell/rb-shell-preferences.h
@@ -33,6 +33,15 @@
 
 G_BEGIN_DECLS
 
+typedef enum
+{
+	RB_SHELL_PREFS_UI_LOCATION_GENERAL,
+	RB_SHELL_PREFS_UI_LOCATION_PLAYBACK
+} RBShellPrefsUILocation;
+
+GType rb_shell_prefs_ui_location_get_type (void);
+#define RB_TYPE_SHELL_PREFS_UI_LOCATION	(rb_shell_prefs_ui_location_get_type())
+
 #define RB_TYPE_SHELL_PREFERENCES         (rb_shell_preferences_get_type ())
 #define RB_SHELL_PREFERENCES(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_SHELL_PREFERENCES, RBShellPreferences))
 #define RB_SHELL_PREFERENCES_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), RB_TYPE_SHELL_PREFERENCES, RBShellPreferencesClass))
@@ -62,6 +71,14 @@ GtkWidget	*rb_shell_preferences_new		(GList *views);
 void		rb_shell_preferences_append_page	(RBShellPreferences *prefs,
 							 const char *name,
 							 GtkWidget *widget);
+void		rb_shell_preferences_add_widget		(RBShellPreferences *prefs,
+							 GtkWidget *widget,
+							 RBShellPrefsUILocation location,
+							 gboolean expand,
+							 gboolean fill);
+void		rb_shell_preferences_remove_widget	(RBShellPreferences *prefs,
+							 GtkWidget *widget,
+							 RBShellPrefsUILocation location);
 
 G_END_DECLS
 
diff --git a/shell/rb-shell.c b/shell/rb-shell.c
index 7438d94..d73b323 100644
--- a/shell/rb-shell.c
+++ b/shell/rb-shell.c
@@ -976,6 +976,17 @@ rb_shell_get_property (GObject *object,
 		g_value_set_object (value, shell->priv->window);
 		break;
 	case PROP_PREFS:
+		/* create the preferences window the first time we need it */
+		if (shell->priv->prefs == NULL) {
+			GtkWidget *content;
+
+			shell->priv->prefs = rb_shell_preferences_new (shell->priv->sources);
+
+			gtk_window_set_transient_for (GTK_WINDOW (shell->priv->prefs),
+						      GTK_WINDOW (shell->priv->window));
+			content = gtk_dialog_get_content_area (GTK_DIALOG (shell->priv->prefs));
+			gtk_widget_show_all (content);
+		}
 		g_value_set_object (value, shell->priv->prefs);
 		break;
 	case PROP_QUEUE_SOURCE:
@@ -2424,15 +2435,12 @@ static void
 rb_shell_cmd_preferences (GtkAction *action,
 		          RBShell *shell)
 {
-	if (shell->priv->prefs == NULL) {
-		shell->priv->prefs = rb_shell_preferences_new (shell->priv->sources);
+	RBShellPreferences *prefs;
 
-		gtk_window_set_transient_for (GTK_WINDOW (shell->priv->prefs),
-					      GTK_WINDOW (shell->priv->window));
-		gtk_widget_show_all (shell->priv->prefs);
-	}
+	g_object_get (shell, "prefs", &prefs, NULL);
 
-	gtk_window_present (GTK_WINDOW (shell->priv->prefs));
+	gtk_window_present (GTK_WINDOW (prefs));
+	g_object_unref (prefs);
 }
 
 static gboolean



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