[gnome-applets] [mixer] Port to new libpanel-applet API



commit 2851f906e52ab9ee3618bd2f544988ca0c68a60c
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Thu Feb 25 11:32:40 2010 +0100

    [mixer] Port to new libpanel-applet API

 mixer/GNOME_MixerApplet.server.in.in               |   35 -----
 mixer/GNOME_MixerApplet.xml                        |   12 --
 mixer/Makefile.am                                  |   46 ++++---
 mixer/applet.c                                     |  140 +++++++++++---------
 mixer/applet.h                                     |    4 +
 mixer/load.c                                       |    5 +-
 mixer/mixer-applet-menu.xml                        |    7 +
 ...rg.gnome.applets.MixerApplet.panel-applet.in.in |   16 +++
 ...nome.panel.applet.MixerAppletFactory.service.in |    3 +
 9 files changed, 139 insertions(+), 129 deletions(-)
---
diff --git a/mixer/Makefile.am b/mixer/Makefile.am
index 4a86951..06ab328 100644
--- a/mixer/Makefile.am
+++ b/mixer/Makefile.am
@@ -1,9 +1,9 @@
 SUBDIRS = docs
 
-INCLUDES = -I. -I$(srcdir) 		\
-	$(MIXER_CFLAGS)			\
-	$(GNOME_APPLETS_CFLAGS)		\
-	$(GNOME_LIBS2_CFLAGS)		\
+INCLUDES = -I. -I$(srcdir) 			\
+	-DMIXER_MENU_UI_DIR=\""$(uidir)"\"	\
+	$(MIXER_CFLAGS)				\
+	$(GNOME_APPLETS3_CFLAGS)		\
 	$(GNOMEDESKTOP_CFLAGS)
 
 libexec_PROGRAMS = mixer_applet2
@@ -22,21 +22,32 @@ noinst_HEADERS = \
 
 mixer_applet2_LDADD = 					\
 	$(MIXER_LIBS) 					\
-	$(GNOME_APPLETS_LIBS)				\
-	$(GNOME_LIBS2_LIBS)				\
+	$(GNOME_APPLETS3_LIBS)				\
 	$(GNOMEDESKTOP_LIBS)
 
-serverdir       = $(libdir)/bonobo/servers
-server_in_files = GNOME_MixerApplet.server.in
-server_DATA     = $(server_in_files:.server.in=.server)
+appletdir       = $(datadir)/gnome-panel/applets
+applet_in_files = org.gnome.applets.MixerApplet.panel-applet.in
+applet_DATA     = $(applet_in_files:.panel-applet.in=.panel-applet)
 
-$(server_in_files): $(server_in_files:.server.in=.server.in.in)
-	sed -e "s|\ LIBEXECDIR\@|$(libexecdir)|" $< > $@
+$(applet_in_files): $(applet_in_files).in Makefile
+	$(AM_V_GEN)sed \
+            -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
+            -e "s|\ VERSION\@|$(PACKAGE_VERSION)|" \
+            $< > $@
 
- INTLTOOL_SERVER_RULE@
+%.panel-applet: %.panel-applet.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+servicedir       = $(datadir)/dbus-1/services
+service_in_files = org.gnome.panel.applet.MixerAppletFactory.service.in
+service_DATA     = $(service_in_files:.service.in=.service)
+
+org.gnome.panel.applet.MixerAppletFactory.service: $(service_in_files)
+	$(AM_V_GEN)sed \
+            -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
+            $< > $@
 
 uidir   = $(datadir)/gnome-2.0/ui
-ui_DATA = GNOME_MixerApplet.xml
+ui_DATA = mixer-applet-menu.xml
 
 schemasdir   = @GCONF_SCHEMA_FILE_DIR@
 schemas_in_files = mixer.schemas.in
@@ -44,12 +55,13 @@ schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
 
 @INTLTOOL_SCHEMAS_RULE@
 
-EXTRA_DIST = 						\
-	GNOME_MixerApplet.server.in.in			\
-	$(ui_DATA) 					\
+EXTRA_DIST = 							\
+	org.gnome.applets.MixerApplet.panel-applet.in.in	\
+	$(service_in_files)					\
+	$(ui_DATA) 						\
 	$(schemas_in_files)
 
-CLEANFILES = $(server_in_files) $(server_DATA) $(schemas_DATA)
+CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA) $(schemas_DATA)
 
 if GCONF_SCHEMAS_INSTALL
 install-data-local:
diff --git a/mixer/applet.c b/mixer/applet.c
index 915376f..fefbb02 100644
--- a/mixer/applet.c
+++ b/mixer/applet.c
@@ -92,15 +92,9 @@ static void	cb_gconf			(GConfClient     *client,
 						 GConfEntry      *entry,
 						 gpointer         data);
 
-static void	cb_verb				(BonoboUIComponent *uic,
-						 gpointer   data,
-						 const gchar *verbname);
-
-static void	cb_ui_event			(BonoboUIComponent *comp,
-						 const gchar       *path,
-						 Bonobo_UIComponent_EventType type,
-						 const gchar       *state_string,
-						 gpointer           data);
+static void	cb_verb				(GtkAction *action,
+						 gpointer   data);
+
 static void	cb_theme_change                (GtkIconTheme *icon_theme,
 						gpointer      data);
 static void	cb_stop_scroll_events		(GtkWidget *widget,
@@ -386,18 +380,30 @@ gnome_volume_applet_setup (GnomeVolumeApplet *applet,
 			   GList *elements)
 {
   GtkObject *adj;
-  BonoboUIComponent *component;
-  static const BonoboUIVerb verbs[] = {
-    BONOBO_UI_UNSAFE_VERB ("RunMixer", cb_verb),
-    BONOBO_UI_UNSAFE_VERB ("Mute",     cb_verb),
-    BONOBO_UI_UNSAFE_VERB ("Help",     cb_verb),
-    BONOBO_UI_UNSAFE_VERB ("About",    cb_verb),
-    BONOBO_UI_UNSAFE_VERB ("Pref",     cb_verb),
-    BONOBO_UI_VERB_END
+  static const GtkActionEntry actions[] = {
+    { "RunMixer", NULL, N_("_Open Volume Control"),
+      NULL, NULL,
+      G_CALLBACK (cb_verb) },
+    { "Help", GTK_STOCK_HELP, N_("_Help"),
+      NULL, NULL,
+      G_CALLBACK (cb_verb) },
+    { "About", GTK_STOCK_ABOUT, N_("_About"),
+      NULL, NULL,
+      G_CALLBACK (cb_verb) },
+    { "Pref", GTK_STOCK_PROPERTIES, N_("_Preferences"),
+      NULL, NULL,
+      G_CALLBACK (cb_verb) }
   };
+  static const GtkToggleActionEntry toggle_actions[] = {
+    { "Mute", NULL, N_("Mu_te"),
+      NULL, NULL,
+      G_CALLBACK (cb_verb), FALSE }
+  };
+
   gchar *key;
   gchar *active_element_name;
   gchar *active_track_name;
+  gchar *ui_path;
   GstMixerTrack *first_track;
   gboolean res;
 
@@ -433,13 +439,21 @@ gnome_volume_applet_setup (GnomeVolumeApplet *applet,
   gnome_volume_applet_orientation (PANEL_APPLET (applet),
 				   panel_applet_get_orient (PANEL_APPLET (applet)));
 
-  /* menu - done here because bonobo is intialized now */
+  /* menu */
+  applet->action_group = gtk_action_group_new ("Mixer Applet Actions");
+  gtk_action_group_set_translation_domain (applet->action_group, GETTEXT_PACKAGE);
+  gtk_action_group_add_actions (applet->action_group,
+				actions,
+				G_N_ELEMENTS (actions),
+				applet);
+  gtk_action_group_add_toggle_actions (applet->action_group,
+				       toggle_actions,
+				       G_N_ELEMENTS (toggle_actions),
+				       applet);
+  ui_path = g_build_filename (MIXER_MENU_UI_DIR, "mixer-applet-menu.xml", NULL);
   panel_applet_setup_menu_from_file (PANEL_APPLET (applet),
-				     DATADIR,
-				     "GNOME_MixerApplet.xml",
-				     NULL, verbs, applet);
-  component = panel_applet_get_popup_component (PANEL_APPLET (applet));
-  g_signal_connect (component, "ui-event", G_CALLBACK (cb_ui_event), applet);
+				     ui_path, applet->action_group);
+  g_free (ui_path);
 
   gnome_volume_applet_refresh (applet, TRUE, -1, -1);
   if (res) {
@@ -471,6 +485,11 @@ gnome_volume_applet_dispose (GObject *object)
 
   gnome_volume_applet_popdown_dock (applet);
 
+  if (applet->action_group) {
+    g_object_unref (applet->action_group);
+    applet->action_group = NULL;
+  }
+
   if (applet->elements) {
     GList *item;
 
@@ -664,6 +683,24 @@ gnome_volume_applet_pop_dock (GnomeVolumeApplet *applet)
   }
 }
 
+static void
+gnome_volume_applet_update_mute_action (GnomeVolumeApplet *applet,
+					gboolean           newmute)
+{
+  GtkAction *action;
+
+  if (!applet->action_group)
+    return;
+
+  action = gtk_action_group_get_action (applet->action_group, "Mute");
+  if (newmute == gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+    return;
+
+  gtk_action_block_activate (action);
+  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), newmute);
+  gtk_action_unblock_activate (action);
+}
+
 gboolean
 mixer_is_muted (GnomeVolumeApplet *applet)
 {
@@ -677,7 +714,6 @@ mixer_is_muted (GnomeVolumeApplet *applet)
 void
 gnome_volume_applet_toggle_mute (GnomeVolumeApplet *applet)
 {
-  BonoboUIComponent *component;
   gboolean mute = mixer_is_muted (applet);
   gboolean newmute = !mute;
   GList *tracks;
@@ -690,11 +726,8 @@ gnome_volume_applet_toggle_mute (GnomeVolumeApplet *applet)
     cb_volume (applet->adjustment, applet);
   }
 
-  /* update component */
-  component = panel_applet_get_popup_component (PANEL_APPLET (applet));
-  bonobo_ui_component_set_prop (component,
-			        "/commands/Mute",
-			        "state", newmute ? "1" : "0", NULL);
+  /* update menu */
+  gnome_volume_applet_update_mute_action (applet, newmute);
 
   /* update graphic - this should happen automagically after the next
    * idle call, but apparently doesn't for some people... */
@@ -1092,7 +1125,6 @@ gnome_volume_applet_refresh (GnomeVolumeApplet *applet,
 			     gdouble            volume,
 			     gint               mute)
 {
-  BonoboUIComponent *component;
   GdkPixbuf *pixbuf;
   gint n;
   gboolean show_mute, did_change;
@@ -1188,11 +1220,9 @@ gnome_volume_applet_refresh (GnomeVolumeApplet *applet,
   }
   applet->lock = FALSE;
 
-  /* update mute status (bonobo) */
-  component = panel_applet_get_popup_component (PANEL_APPLET (applet));
-  bonobo_ui_component_set_prop (component,
-				"/commands/Mute",
-				"state", mute ? "1" : "0", NULL);
+  /* update mute status */
+  gnome_volume_applet_update_mute_action (applet, mute);
+
   return did_change;
 }
 
@@ -1380,7 +1410,7 @@ cb_gconf (GConfClient *client,
 }
 
 /*
- * bonobo verb callback.
+ * verb callback.
  */
 
 static void
@@ -1391,11 +1421,11 @@ cb_prefs_destroy (GtkWidget *widget,
 }
 
 static void
-cb_verb (BonoboUIComponent *uic,
-	 gpointer           data,
-	 const gchar       *verbname)
+cb_verb (GtkAction   *action,
+	 gpointer     data)
 {
   GnomeVolumeApplet *applet = GNOME_VOLUME_APPLET (data);
+  const gchar       *verbname = gtk_action_get_name (action);
 
   if (!strcmp (verbname, "RunMixer")) {
     gnome_volume_applet_run_mixer (applet);
@@ -1458,31 +1488,17 @@ cb_verb (BonoboUIComponent *uic,
 		        G_CALLBACK (cb_prefs_destroy), applet);
       gtk_widget_show (applet->prefs);
     }
-  } else {
-    g_warning ("Unknown bonobo command '%s'", verbname);
-  }
-}
-
-static void
-cb_ui_event (BonoboUIComponent *comp,
-	     const gchar       *verbname,
-	     Bonobo_UIComponent_EventType type,
-	     const gchar       *state_string,
-	     gpointer           data)
-{
-  GnomeVolumeApplet *applet = GNOME_VOLUME_APPLET (data);
-
-  if (!applet->mixer) {
-    show_no_mixer_dialog (applet);
   } else if (!strcmp (verbname, "Mute")) {
-    /* mute will have a value of 4 without the ? TRUE : FALSE bit... */
-    gboolean mute = applet->state & 1,
-             want_mute = !strcmp (state_string, "1") ? TRUE : FALSE;
-
-    if (mute != want_mute)
-      gnome_volume_applet_toggle_mute (applet);
+    if (!applet->mixer) {
+      show_no_mixer_dialog (applet);
+    } else {
+      gboolean mute = applet->state & 1,
+	       want_mute = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+      if (mute != want_mute)
+	gnome_volume_applet_toggle_mute (applet);
+    }
   } else {
-    g_warning ("Unknown bonobo command '%s'", verbname);
+    g_warning ("Unknown menu action '%s'", verbname);
   }
 }
 
diff --git a/mixer/applet.h b/mixer/applet.h
index cf13784..cbff8c8 100644
--- a/mixer/applet.h
+++ b/mixer/applet.h
@@ -24,6 +24,7 @@
 #define __GVA_APPLET_H__
 
 #include <glib.h>
+#include <glib/gi18n.h>
 
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
@@ -51,6 +52,9 @@ G_BEGIN_DECLS
 struct _GnomeVolumeApplet {
   PanelApplet parent;
 
+  /* menu actions */
+  GtkActionGroup *action_group;
+
   /* our main icon, which is our panel user interface */
   GtkImage *image;
 
diff --git a/mixer/load.c b/mixer/load.c
index f000256..f2ccd1c 100644
--- a/mixer/load.c
+++ b/mixer/load.c
@@ -172,11 +172,10 @@ gnome_volume_applet_factory (PanelApplet *applet,
   return TRUE;
 }
 
-PANEL_APPLET_BONOBO_FACTORY (
-  "OAFIID:GNOME_MixerApplet_Factory",
+PANEL_APPLET_OUT_PROCESS_FACTORY (
+  "MixerAppletFactory",
   GNOME_TYPE_VOLUME_APPLET,
   "mixer_applet2",
-  "0",
   gnome_volume_applet_factory,
   NULL
 )
diff --git a/mixer/mixer-applet-menu.xml b/mixer/mixer-applet-menu.xml
new file mode 100644
index 0000000..d0d2ab6
--- /dev/null
+++ b/mixer/mixer-applet-menu.xml
@@ -0,0 +1,7 @@
+<menuitem name="Mute"     action="Mute" />
+<menuitem name="RunMixer" action="RunMixer" />
+<separator/>
+<menuitem name="Pref"     action="Pref" />
+<menuitem name="Help"     action="Help" />
+<menuitem name="About"    action="About" />
+
diff --git a/mixer/org.gnome.applets.MixerApplet.panel-applet.in.in b/mixer/org.gnome.applets.MixerApplet.panel-applet.in.in
new file mode 100644
index 0000000..d286292
--- /dev/null
+++ b/mixer/org.gnome.applets.MixerApplet.panel-applet.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=MixerAppletFactory
+Location= LIBEXECDIR@/mixer_applet2
+Name=Volume Control Applet Factory
+Description=Factory for volume control applet
+
+[MixerApplet]
+_Name=Volume Control
+_Description=Adjust the sound volume
+Icon=multimedia-volume-control
+BonoboId=OAFIID:GNOME_MixerApplet
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-applets
+X-GNOME-Bugzilla-Component=mixer
+X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=mixer_applet2
diff --git a/mixer/org.gnome.panel.applet.MixerAppletFactory.service.in b/mixer/org.gnome.panel.applet.MixerAppletFactory.service.in
new file mode 100644
index 0000000..9b98e54
--- /dev/null
+++ b/mixer/org.gnome.panel.applet.MixerAppletFactory.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.panel.applet.MixerAppletFactory
+Exec= LIBEXECDIR@/mixer_applet2



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