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



commit d667202cdb8429ff6abf80f86e95ba8e6cf2a2c0
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Tue Feb 23 13:23:42 2010 +0100

    [battstat] Port to new libpanel-applet API

 battstat/GNOME_BattstatApplet.server.in.in         |   36 ----------
 battstat/GNOME_BattstatApplet.xml                  |   12 ---
 battstat/Makefile.am                               |   49 ++++++++-----
 battstat/battstat-applet-menu.xml                  |    4 +
 battstat/battstat.h                                |    3 +-
 battstat/battstat_applet.c                         |   74 +++++++++++--------
 ...gnome.applets.BattstatApplet.panel-applet.in.in |   16 ++++
 ...e.panel.applet.BattstatAppletFactory.service.in |    3 +
 battstat/properties.c                              |    5 +-
 9 files changed, 100 insertions(+), 102 deletions(-)
---
diff --git a/battstat/Makefile.am b/battstat/Makefile.am
index 2c107a7..a9599e3 100644
--- a/battstat/Makefile.am
+++ b/battstat/Makefile.am
@@ -24,13 +24,13 @@ SUBDIRS = docs sounds $(APMDIR)
 DIST_SUBDIRS = docs sounds apmlib
 
 INCLUDES =					\
-	$(GNOME_APPLETS_CFLAGS)			\
-	$(GNOME_LIBS2_CFLAGS)			\
+	$(GNOME_APPLETS3_CFLAGS)		\
 	$(LIBNOTIFY_CFLAGS)			\
 	$(HAL_CFLAGS)				\
 	$(APMINC)				\
 	$(ACPIINC)				\
-	-DG_LOG_DOMAIN=\"battstat_applet\"
+	-DG_LOG_DOMAIN=\"battstat_applet\"	\
+	-DBATTSTAT_MENU_UI_DIR=\""$(uidir)"\"
 
 
 libexec_PROGRAMS = battstat-applet-2
@@ -51,8 +51,7 @@ battstat_applet_2_SOURCES = \
 
 
 battstat_applet_2_LDADD = \
-		     $(GNOME_APPLETS_LIBS) \
-		     $(GNOME_LIBS2_LIBS) \
+		     $(GNOME_APPLETS3_LIBS) \
 		     $(LIBNOTIFY_LIBS) \
 		     $(HAL_LIBS) \
 		     $(APMLIB)
@@ -68,26 +67,38 @@ install-data-local:
 	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(schemas_DATA) ;
 endif
 
-serverdir       = $(libdir)/bonobo/servers
-server_in_files = GNOME_BattstatApplet.server.in
-server_DATA     = $(server_in_files:.server.in=.server)
+appletdir       = $(datadir)/gnome-panel/applets
+applet_in_files = org.gnome.applets.BattstatApplet.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)|" \
+            $< > $@
 
-CLEANFILES = $(server_in_files) $(server_DATA) $(schemas_DATA)
+%.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
 
-uidir = $(datadir)/gnome-2.0/ui
-ui_DATA = GNOME_BattstatApplet.xml
+servicedir       = $(datadir)/dbus-1/services
+service_in_files = org.gnome.panel.applet.BattstatAppletFactory.service.in
+service_DATA     = $(service_in_files:.service.in=.service)
 
-EXTRA_DIST = 			\
-	$(builder_DATA)		\
-	$(ui_DATA)		\
-	GNOME_BattstatApplet.server.in.in	\
-	$(schemas_in_files)
+org.gnome.panel.applet.BattstatAppletFactory.service: $(service_in_files)
+	$(AM_V_GEN)sed \
+            -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
+            $< > $@
 
+CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA) $(schemas_DATA)
 
- INTLTOOL_SERVER_RULE@
+uidir = $(datadir)/gnome-2.0/ui
+ui_DATA = battstat-applet-menu.xml
+
+EXTRA_DIST = 							\
+	$(builder_DATA)						\
+	$(ui_DATA)						\
+	org.gnome.applets.BattstatApplet.panel-applet.in.in	\
+	$(service_in_files)					\
+	$(schemas_in_files)
 
 
 -include $(top_srcdir)/git.mk
diff --git a/battstat/battstat-applet-menu.xml b/battstat/battstat-applet-menu.xml
new file mode 100644
index 0000000..d6eb579
--- /dev/null
+++ b/battstat/battstat-applet-menu.xml
@@ -0,0 +1,4 @@
+<menuitem name="Battstat Properties Item" action="BattstatProperties" />
+<menuitem name="Battstat Help Item" action="BattstatHelp" />
+<menuitem name="Battstat About Item" action="BattstatAbout" />
+
diff --git a/battstat/battstat.h b/battstat/battstat.h
index 6deaf43..cdcd230 100644
--- a/battstat/battstat.h
+++ b/battstat/battstat.h
@@ -22,6 +22,7 @@
 #define _battstat_h_
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 #include <panel-applet.h>
@@ -155,7 +156,7 @@ typedef struct _ProgressData {
 } ProgressData;
 
 /* properties.c */
-void prop_cb (BonoboUIComponent *, ProgressData *, const char *);
+void prop_cb (GtkAction *, ProgressData *);
 
 /* battstat_applet.c */
 void reconfigure_layout( ProgressData *battstat );
diff --git a/battstat/battstat_applet.c b/battstat/battstat_applet.c
index 2af11d2..16dbc31 100644
--- a/battstat/battstat_applet.c
+++ b/battstat/battstat_applet.c
@@ -54,14 +54,19 @@
 #define GCONF_PATH ""
 
 static gboolean check_for_updates (gpointer data);
-static void about_cb( BonoboUIComponent *, ProgressData *, const char * );
-static void help_cb( BonoboUIComponent *, ProgressData *, const char * );
-
-static const BonoboUIVerb battstat_menu_verbs [] = {
-	BONOBO_UI_UNSAFE_VERB ("BattstatProperties", prop_cb),
-	BONOBO_UI_UNSAFE_VERB ("BattstatHelp",       help_cb),
-	BONOBO_UI_UNSAFE_VERB ("BattstatAbout",      about_cb),
-        BONOBO_UI_VERB_END
+static void about_cb( GtkAction *, ProgressData * );
+static void help_cb( GtkAction *, ProgressData * );
+
+static const GtkActionEntry battstat_menu_actions [] = {
+	{ "BattstatProperties", GTK_STOCK_PROPERTIES, N_("_Preferences"),
+	  NULL, NULL,
+	  G_CALLBACK (prop_cb) },
+	{ "BattstatHelp", GTK_STOCK_HELP, N_("_Help"),
+	  NULL, NULL,
+	  G_CALLBACK (help_cb) },
+	{ "BattstatAbout", GTK_STOCK_ABOUT, N_("_About"),
+	  NULL, NULL,
+	  G_CALLBACK (about_cb) }
 };
 
 #define AC_POWER_STRING _("System is running on AC power")
@@ -1062,8 +1067,10 @@ check_for_updates( gpointer data )
       if(battstat->beep)
         gdk_beep();
     }
-    
+#if 0
+    /* FIXME: gnome-applets doesn't depend on libgnome anymore */
     gnome_triggers_do ("", NULL, "battstat_applet", "LowBattery", NULL);
+#endif
   }
 
   if( battstat->last_charging &&
@@ -1075,7 +1082,10 @@ check_for_updates( gpointer data )
       info.percent > 99)
   {
     /* Inform that battery now fully charged */
+#if 0
+    /* FIXME: gnome-applets doesn't depend on libgnome anymore */
     gnome_triggers_do ("", NULL, "battstat_applet", "BatteryFull", NULL);
+#endif
 
     if(battstat->fullbattnot)
     {
@@ -1202,7 +1212,7 @@ battstat_show_help( ProgressData *battstat, const char *section )
 /* Called when the user selects the 'help' menu item.
  */
 static void
-help_cb( BonoboUIComponent *uic, ProgressData *battstat, const char *verb )
+help_cb( GtkAction *action, ProgressData *battstat )
 {
   battstat_show_help( battstat, NULL );
 }
@@ -1210,7 +1220,7 @@ help_cb( BonoboUIComponent *uic, ProgressData *battstat, const char *verb )
 /* Called when the user selects the 'about' menu item.
  */
 static void
-about_cb( BonoboUIComponent *uic, ProgressData *battstat, const char *verb )
+about_cb( GtkAction *action, ProgressData *battstat )
 {
   const gchar *authors[] = {
     "J\xC3\xB6rgen Pehrson <jp spektr eu org>", 
@@ -1602,6 +1612,8 @@ battstat_applet_fill (PanelApplet *applet)
 {
   ProgressData *battstat;
   AtkObject *atk_widget;
+  GtkActionGroup *action_group;
+  gchar *ui_path;
   const char *err;
   int no_hal;
 
@@ -1640,23 +1652,24 @@ battstat_applet_fill (PanelApplet *applet)
   create_layout (battstat);
   setup_text_orientation( battstat );
 
-  panel_applet_setup_menu_from_file (PANEL_APPLET (battstat->applet), 
-  			             DATADIR,
-                                     "GNOME_BattstatApplet.xml",
-                                     NULL,
-                                     battstat_menu_verbs,
-                                     battstat);
+  action_group = gtk_action_group_new ("Battstat Applet Actions");
+  gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+  gtk_action_group_add_actions (action_group,
+				battstat_menu_actions,
+				G_N_ELEMENTS (battstat_menu_actions),
+				battstat);
+  ui_path = g_build_filename (BATTSTAT_MENU_UI_DIR, "battstat-applet-menu.xml", NULL);
+  panel_applet_setup_menu_from_file (PANEL_APPLET (battstat->applet),
+				     ui_path, action_group);
+  g_free (ui_path);
 
   if (panel_applet_get_locked_down (PANEL_APPLET (battstat->applet))) {
-	  BonoboUIComponent *popup_component;
-
-	  popup_component = panel_applet_get_popup_component (PANEL_APPLET (battstat->applet));
+	  GtkAction *action;
 
-	  bonobo_ui_component_set_prop (popup_component,
-					"/commands/BattstatProperties",
-					"hidden", "1",
-					NULL);
+	  action = gtk_action_group_get_action (action_group, "BattstatProperties");
+	  gtk_action_set_visible (action, FALSE);
   }
+  g_object_unref (action_group);
 
   atk_widget = gtk_widget_get_accessible (battstat->applet);
   if (GTK_IS_ACCESSIBLE (atk_widget)) {
@@ -1680,18 +1693,17 @@ battstat_applet_factory (PanelApplet *applet,
 {
   gboolean retval = FALSE;
 
-  if (!strcmp (iid, "OAFIID:GNOME_BattstatApplet"))
+  if (!strcmp (iid, "BattstatApplet"))
     retval = battstat_applet_fill (applet);
   
   return retval;
 }
 
 
-PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GNOME_BattstatApplet_Factory",
-			     PANEL_TYPE_APPLET,
-                             "battstat",
-                             "0",
-                             battstat_applet_factory,
-                             NULL)
+PANEL_APPLET_OUT_PROCESS_FACTORY ("BattstatAppletFactory",
+				  PANEL_TYPE_APPLET,
+				  "battstat",
+				  battstat_applet_factory,
+				  NULL)
       
 
diff --git a/battstat/org.gnome.applets.BattstatApplet.panel-applet.in.in b/battstat/org.gnome.applets.BattstatApplet.panel-applet.in.in
new file mode 100644
index 0000000..4887aa3
--- /dev/null
+++ b/battstat/org.gnome.applets.BattstatApplet.panel-applet.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=BattstatAppletFactory
+Location= LIBEXECDIR@/battstat-applet-2
+_Name=Battstat Factory
+_Description=Battstat Factory
+
+[BattstatApplet]
+_Name=Battery Charge Monitor
+_Description=Monitor a laptop's remaining power
+Icon=battery
+BonoboId=OAFIID:GNOME_BattstatApplet
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-applets
+X-GNOME-Bugzilla-Component=battery
+X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=battstat-applet-2
diff --git a/battstat/org.gnome.panel.applet.BattstatAppletFactory.service.in b/battstat/org.gnome.panel.applet.BattstatAppletFactory.service.in
new file mode 100644
index 0000000..33d8ced
--- /dev/null
+++ b/battstat/org.gnome.panel.applet.BattstatAppletFactory.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.panel.applet.BattstatAppletFactory
+Exec= LIBEXECDIR@/battstat-applet-2
diff --git a/battstat/properties.c b/battstat/properties.c
index f205202..83f5d21 100644
--- a/battstat/properties.c
+++ b/battstat/properties.c
@@ -243,9 +243,8 @@ response_cb (GtkDialog *dialog, gint id, gpointer data)
 }
 
 void
-prop_cb (BonoboUIComponent *uic,
-	 ProgressData      *battstat,
-	 const char        *verb)
+prop_cb (GtkAction    *action,
+				 ProgressData *battstat)
 {
   GtkBuilder *builder;
   GtkWidget *combo_ptr, *spin_ptr;



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