[gnome-power-manager] Port BrightnessApplet to libpanel-applet-3



commit 02c6ad8eee2d7158d5ee0d30586eae5cc03ede99
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Fri Jun 18 14:58:14 2010 +0200

    Port BrightnessApplet to libpanel-applet-3
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 .../brightness/GNOME_BrightnessApplet.server.in.in |   36 -----------
 applets/brightness/GNOME_BrightnessApplet.xml      |    8 ---
 applets/brightness/Makefile.am                     |   32 +++++++---
 applets/brightness/brightness-applet-menu.xml      |    3 +
 applets/brightness/brightness-applet.c             |   65 ++++++++++++--------
 .../org.gnome.BrightnessApplet.panel-applet.in.in  |   16 +++++
 ...panel.applet.BrightnessAppletFactory.service.in |    4 +
 7 files changed, 85 insertions(+), 79 deletions(-)
---
diff --git a/applets/brightness/Makefile.am b/applets/brightness/Makefile.am
index b8d5f77..3d798ca 100644
--- a/applets/brightness/Makefile.am
+++ b/applets/brightness/Makefile.am
@@ -14,6 +14,7 @@ INCLUDES =							\
 	-DLIBDIR=\""$(libdir)"\" 				\
 	-DVERSION="\"$(VERSION)\"" 				\
 	-DGPM_DATA=\"$(pkgdatadir)\"				\
+	-DBRIGHTNESS_MENU_UI_DIR=\""$(uidir)"\"			\
 	-DEGG_LOG_FILE=\""~/gnome-power-manager.log"\"		\
 	-DEGG_VERBOSE="\"GPM_VERBOSE\""				\
 	-DEGG_LOGGING="\"GPM_LOGGING\""				\
@@ -37,19 +38,32 @@ gnome_brightness_applet_LDADD =					\
 	$(GNOME_LIBS)						\
 	$(PANEL_LIBS)
 
-serverdir       = $(libdir)/bonobo/servers
-server_in_files = GNOME_BrightnessApplet.server.in
-server_DATA     = $(server_in_files:.server.in=.server)
 
-$(server_in_files): $(server_in_files:.server.in=.server.in.in)
-	sed -e "s|\ LIBEXECDIR\@|$(libexecdir)|" -e "s|\ VERSION\@|$(VERSION)|" $< > $@
+appletdir       = $(datadir)/gnome-panel/applets
+applet_in_files = org.gnome.BrightnessApplet.panel-applet.in
+applet_DATA     = $(applet_in_files:.panel-applet.in=.panel-applet)
 
- INTLTOOL_SERVER_RULE@
+$(applet_in_files): $(applet_in_files).in Makefile
+	$(AM_V_GEN)sed \
+            -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
+            -e "s|\ VERSION\@|$(PACKAGE_VERSION)|" \
+            $< > $@
+
+%.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.BrightnessAppletFactory.service.in
+service_DATA     = $(service_in_files:.service.in=.service)
+
+org.gnome.panel.applet.BrightnessAppletFactory.service: $(service_in_files)
+	$(AM_V_GEN)sed \
+            -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
+            $< > $@
 
 uidir   = $(datadir)/gnome-2.0/ui
-ui_DATA = GNOME_BrightnessApplet.xml
+ui_DATA = brightness-applet-menu.xml
 
-EXTRA_DIST = GNOME_BrightnessApplet.server.in.in $(ui_DATA)
+EXTRA_DIST = org.gnome.BrightnessApplet.panel-applet.in.in $(ui_DATA) $(service_in_files)
 
 DISTCLEANFILES =						\
-	$(server_DATA) $(server_DATA).in
+	$(applet_DATA) $(applet_DATA).in $(service_DATA)
diff --git a/applets/brightness/brightness-applet-menu.xml b/applets/brightness/brightness-applet-menu.xml
new file mode 100644
index 0000000..efc2659
--- /dev/null
+++ b/applets/brightness/brightness-applet-menu.xml
@@ -0,0 +1,3 @@
+<menuitem name="Help" action="Help" />
+<menuitem name="About" action="About" />
+
diff --git a/applets/brightness/brightness-applet.c b/applets/brightness/brightness-applet.c
index f8cd00c..b7cff0a 100644
--- a/applets/brightness/brightness-applet.c
+++ b/applets/brightness/brightness-applet.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <panel-applet.h>
 #include <gtk/gtk.h>
+#include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
 #include <glib-object.h>
 #include <dbus/dbus-glib.h>
@@ -93,12 +94,12 @@ static gboolean  gpm_applet_scroll_cb             (GpmBrightnessApplet *applet,
 static gboolean  gpm_applet_slide_cb              (GtkWidget *w, GpmBrightnessApplet *applet);
 static void      gpm_applet_create_popup          (GpmBrightnessApplet *applet);
 static gboolean  gpm_applet_popup_cb              (GpmBrightnessApplet *applet, GdkEventButton *event);
-static void      gpm_applet_dialog_about_cb       (BonoboUIComponent *uic, gpointer data, const gchar *verbname);
+static void      gpm_applet_dialog_about_cb       (GtkAction *action, gpointer data);
 static gboolean  gpm_applet_bonobo_cb             (PanelApplet *_applet, const gchar *iid, gpointer data);
 static void      gpm_applet_destroy_cb            (GtkObject *object);
 
-#define GPM_BRIGHTNESS_APPLET_OAFID		"OAFIID:GNOME_BrightnessApplet"
-#define GPM_BRIGHTNESS_APPLET_FACTORY_OAFID	"OAFIID:GNOME_BrightnessApplet_Factory"
+#define GPM_BRIGHTNESS_APPLET_ID		"BrightnessApplet"
+#define GPM_BRIGHTNESS_APPLET_FACTORY_ID	"BrightnessAppletFactory"
 #define GPM_BRIGHTNESS_APPLET_ICON		"gnome-brightness-applet"
 #define GPM_BRIGHTNESS_APPLET_ICON_DISABLED	"gpm-brightness-lcd-disabled"
 #define GPM_BRIGHTNESS_APPLET_ICON_INVALID	"gpm-brightness-lcd-invalid"
@@ -727,7 +728,7 @@ gpm_applet_stop_scroll_events_cb (GtkWidget *widget, GdkEvent  *event)
  * displays about dialog
  **/
 static void
-gpm_applet_dialog_about_cb (BonoboUIComponent *uic, gpointer data, const gchar *verbname)
+gpm_applet_dialog_about_cb (GtkAction *action, gpointer data)
 {
 	GtkAboutDialog *about;
 
@@ -792,7 +793,7 @@ gpm_applet_dialog_about_cb (BonoboUIComponent *uic, gpointer data, const gchar *
  * open gpm help
  **/
 static void
-gpm_applet_help_cb (BonoboUIComponent *uic, gpointer data, const gchar *verbname)
+gpm_applet_help_cb (GtkAction *action, gpointer data)
 {
 	gpm_help_display ("applets-brightness");
 }
@@ -991,44 +992,56 @@ gpm_brightness_applet_init (GpmBrightnessApplet *applet)
 }
 
 /**
- * gpm_applet_bonobo_cb:
- * @_applet: GpmBrightnessApplet instance created by the bonobo factory
- * @iid: Bonobo id
+ * gpm_applet_cb:
+ * @_applet: GpmBrightnessApplet instance created by the applet factory
+ * @iid: Applet id
  *
- * the function called by bonobo factory after creation
+ * the function called by libpanel-applet factory after creation
  **/
 static gboolean
-gpm_applet_bonobo_cb (PanelApplet *_applet, const gchar *iid, gpointer data)
+gpm_applet_cb (PanelApplet *_applet, const gchar *iid, gpointer data)
 {
 	GpmBrightnessApplet *applet = GPM_BRIGHTNESS_APPLET(_applet);
-
-	static BonoboUIVerb verbs [] = {
-		BONOBO_UI_VERB ("About", gpm_applet_dialog_about_cb),
-		BONOBO_UI_VERB ("Help", gpm_applet_help_cb),
-		BONOBO_UI_VERB_END
+	GtkActionGroup *action_group;
+	gchar *ui_path;
+
+	static const GtkActionEntry menu_actions [] = {
+		{ "About", GTK_STOCK_ABOUT, N_("_About"),
+		  NULL, NULL,
+		  G_CALLBACK (gpm_applet_dialog_about_cb) },
+		{ "Help", GTK_STOCK_HELP, N_("_Help"),
+		  NULL, NULL,
+		  G_CALLBACK (gpm_applet_help_cb) }
 	};
 
-	if (strcmp (iid, GPM_BRIGHTNESS_APPLET_OAFID) != 0) {
+	if (strcmp (iid, GPM_BRIGHTNESS_APPLET_ID) != 0) {
 		return FALSE;
 	}
 
-	panel_applet_setup_menu_from_file (PANEL_APPLET (applet),
-					   DATADIR,
-					   "GNOME_BrightnessApplet.xml",
-					   NULL, verbs, applet);
+	action_group = gtk_action_group_new ("Brightness Applet Actions");
+	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+	gtk_action_group_add_actions (action_group,
+				      menu_actions,
+				      G_N_ELEMENTS (menu_actions),
+				      applet);
+	ui_path = g_build_filename (BRIGHTNESS_MENU_UI_DIR, "brightness-applet-menu.xml", NULL);
+	panel_applet_setup_menu_from_file (PANEL_APPLET (applet), ui_path, action_group);
+	g_free (ui_path);
+	g_object_unref (action_group);
+
 	gpm_applet_draw_cb (applet);
 	return TRUE;
 }
 
 /**
- * this generates a main with a bonobo factory
+ * this generates a main with a applet factory
  **/
-PANEL_APPLET_BONOBO_FACTORY
+PANEL_APPLET_OUT_PROCESS_FACTORY
  (/* the factory iid */
- GPM_BRIGHTNESS_APPLET_FACTORY_OAFID,
+ GPM_BRIGHTNESS_APPLET_FACTORY_ID,
  /* generates brighness applets instead of regular gnome applets  */
  GPM_TYPE_BRIGHTNESS_APPLET,
- /* the applet name and version */
- "BrightnessApplet", VERSION,
+ /* the applet name */
+ "BrightnessApplet",
  /* our callback (with no user data) */
- gpm_applet_bonobo_cb, NULL);
+ gpm_applet_cb, NULL);
diff --git a/applets/brightness/org.gnome.BrightnessApplet.panel-applet.in.in b/applets/brightness/org.gnome.BrightnessApplet.panel-applet.in.in
new file mode 100644
index 0000000..bcbf22a
--- /dev/null
+++ b/applets/brightness/org.gnome.BrightnessApplet.panel-applet.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=BrightnessAppletFactory
+Location= LIBEXECDIR@/gnome-brightness-applet
+_Name=Brightness Applet Factory
+_Description=Factory for Brightness Applet
+
+[BrightnessApplet]
+_Name=Brightness Applet
+_Description=Adjusts Laptop panel brightness
+Icon=gnome-brightness-applet
+BonoboId=OAFIID:GNOME_BrightnessApplet
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-power-manager
+X-GNOME-Bugzilla-Component=applets
+X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=gnome-brightness-applet
diff --git a/applets/brightness/org.gnome.panel.applet.BrightnessAppletFactory.service.in b/applets/brightness/org.gnome.panel.applet.BrightnessAppletFactory.service.in
new file mode 100644
index 0000000..6c9fec4
--- /dev/null
+++ b/applets/brightness/org.gnome.panel.applet.BrightnessAppletFactory.service.in
@@ -0,0 +1,4 @@
+[D-BUS Service]
+Name=org.gnome.panel.applet.BrightnessAppletFactory
+Exec= LIBEXECDIR@/gnome-brightness-applet
+



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