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



commit 57bc3f79ee5610ff4251854be35b030ece77f7d8
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Tue Feb 23 10:35:57 2010 +0100

    [modemlights] Port to new libpanel-applet API

 modemlights/GNOME_ModemLights.server.in.in         |   36 ------
 modemlights/GNOME_ModemLights.xml                  |   20 ---
 modemlights/Makefile.am                            |   42 ++++--
 modemlights/modem-applet-menu.xml                  |    7 +
 modemlights/modem-applet.c                         |  131 ++++++++++----------
 ...rg.gnome.applets.ModemApplet.panel-applet.in.in |   16 +++
 ...nome.panel.applet.ModemAppletFactory.service.in |    3 +
 7 files changed, 122 insertions(+), 133 deletions(-)
---
diff --git a/modemlights/Makefile.am b/modemlights/Makefile.am
index 29b02ce..cb692ee 100644
--- a/modemlights/Makefile.am
+++ b/modemlights/Makefile.am
@@ -1,7 +1,8 @@
 #SUBDIRS = docs
 
 INCLUDES = -I. -I$(srcdir) 				\
-	$(GNOME_APPLETS_CFLAGS)	
+	-DMODEM_MENU_UI_DIR=\""$(uidir)"\"		\
+	$(GNOME_APPLETS3_CFLAGS)
 
 libexec_PROGRAMS = modem_applet
 
@@ -10,23 +11,35 @@ modem_applet_SOURCES = \
 	modem-applet.h
 
 modem_applet_LDADD = 		\
-	$(GNOME_APPLETS_LIBS)	\
+	$(GNOME_APPLETS3_LIBS)	\
 	$(MODEMLIGHTS_LIBS)
 
 uidir	= $(datadir)/gnome-2.0/ui
-ui_DATA	= GNOME_ModemLights.xml
+ui_DATA	= modem-applet-menu.xml
 
 
-serverdir       = $(libdir)/bonobo/servers
-server_in_files = GNOME_ModemLights.server.in
-server_DATA     = $(server_in_files:.server.in=.server)
+appletdir       = $(datadir)/gnome-panel/applets
+applet_in_files = org.gnome.applets.ModemApplet.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)
+%.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
 
- INTLTOOL_SERVER_RULE@
+servicedir       = $(datadir)/dbus-1/services
+service_in_files = org.gnome.panel.applet.ModemAppletFactory.service.in
+service_DATA     = $(service_in_files:.service.in=.service)
+
+org.gnome.panel.applet.ModemAppletFactory.service: $(service_in_files)
+	$(AM_V_GEN)sed \
+            -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
+            $< > $@
+
+CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA)
 
 builder_DATA = modemlights.ui
 
@@ -37,10 +50,11 @@ icons = \
 	gnome-modem-monitor-applet.22.png \
 	gnome-modem-monitor-applet.24.png
 
-EXTRA_DIST =				\
-	GNOME_ModemLights.server.in.in	\
-	$(icons)			\
-	$(builder_DATA)			\
+EXTRA_DIST =							\
+	org.gnome.applets.ModemApplet.panel-applet.in.in	\
+	$(service_in_files)					\
+	$(icons)						\
+	$(builder_DATA)						\
 	$(ui_DATA)
 
 gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
diff --git a/modemlights/modem-applet-menu.xml b/modemlights/modem-applet-menu.xml
new file mode 100644
index 0000000..7e1d0e0
--- /dev/null
+++ b/modemlights/modem-applet-menu.xml
@@ -0,0 +1,7 @@
+<menuitem name="Activate"   action="Activate" />
+<menuitem name="Deactivate" action="Deactivate" />
+<separator/>
+<menuitem name="Properties" action="Properties" />
+<menuitem name="Help"       action="Help" />
+<menuitem name="About"      action="About" />
+
diff --git a/modemlights/modem-applet.c b/modemlights/modem-applet.c
index 4acf203..50a22ac 100644
--- a/modemlights/modem-applet.c
+++ b/modemlights/modem-applet.c
@@ -22,6 +22,7 @@
 #include "config.h"
 #endif
 
+#include <glib/gi18n.h>
 #include <panel-applet.h>
 #include <fcntl.h>
 #ifdef HAVE_PTY_H
@@ -54,10 +55,11 @@ typedef struct _ModemAppletPrivate ModemAppletPrivate;
 struct _ModemAppletPrivate
 {
   /* applet UI stuff */
-  GtkBuilder   *builder;
-  GtkIconTheme *icon_theme;
-  GdkPixbuf    *icon;
-  GtkWidget    *image;
+  GtkBuilder     *builder;
+  GtkIconTheme   *icon_theme;
+  GdkPixbuf      *icon;
+  GtkWidget      *image;
+  GtkActionGroup *action_group;
 
   /* auth dialog */
   GtkWidget    *auth_dialog;
@@ -117,21 +119,16 @@ static void modem_applet_change_background (PanelApplet *app,
 					    GdkColor  *colour,
 					    GdkPixmap *pixmap);
 
-static void on_modem_applet_about_clicked (BonoboUIComponent *uic,
-					   ModemApplet       *applet,
-					   const gchar       *verb);
-static void on_modem_applet_activate      (BonoboUIComponent *uic,
-					   ModemApplet       *applet,
-					   const gchar       *verb);
-static void on_modem_applet_deactivate    (BonoboUIComponent *uic,
-					   ModemApplet       *applet,
-					   const gchar       *verb);
-static void on_modem_applet_properties_clicked (BonoboUIComponent *uic,
-						ModemApplet       *applet,
-						const gchar       *verb);
-static void on_modem_applet_help_clicked  (BonoboUIComponent *uic,
-					   ModemApplet       *applet,
-					   const char        *verb);
+static void on_modem_applet_about_clicked (GtkAction   *action,
+					   ModemApplet *applet);
+static void on_modem_applet_activate      (GtkAction   *action,
+					   ModemApplet *applet);
+static void on_modem_applet_deactivate    (GtkAction   *action,
+					   ModemApplet *applet);
+static void on_modem_applet_properties_clicked (GtkAction   *action,
+						ModemApplet *applet);
+static void on_modem_applet_help_clicked  (GtkAction   *action,
+					   ModemApplet *applet);
 
 static void launch_backend                (ModemApplet      *applet,
 					   gboolean          root_auth);
@@ -141,13 +138,22 @@ static void shutdown_backend              (ModemApplet *applet,
 
 static gpointer parent_class;
 
-static const BonoboUIVerb menu_verbs[] = {
-  BONOBO_UI_UNSAFE_VERB ("Activate",   on_modem_applet_activate),
-  BONOBO_UI_UNSAFE_VERB ("Deactivate", on_modem_applet_deactivate),
-  BONOBO_UI_UNSAFE_VERB ("Properties", on_modem_applet_properties_clicked),
-  BONOBO_UI_UNSAFE_VERB ("Help",       on_modem_applet_help_clicked),
-  BONOBO_UI_UNSAFE_VERB ("About",      on_modem_applet_about_clicked),
-  BONOBO_UI_VERB_END
+static const GtkActionEntry menu_actions[] = {
+  { "Activate", GTK_STOCK_EXECUTE, N_("_Activate"),
+    NULL, NULL,
+    G_CALLBACK (on_modem_applet_activate) },
+  { "Deactivate", GTK_STOCK_STOP, N_("_Deactivate"),
+    NULL, NULL,
+    G_CALLBACK (on_modem_applet_deactivate) },
+  { "Properties", GTK_STOCK_PROPERTIES, N_("_Properties"),
+    NULL, NULL,
+    G_CALLBACK (on_modem_applet_properties_clicked) },
+  { "Help", GTK_STOCK_HELP, N_("_Help"),
+    NULL, NULL,
+    G_CALLBACK (on_modem_applet_help_clicked) },
+  { "About", GTK_STOCK_ABOUT, N_("_About"),
+    NULL, NULL,
+    G_CALLBACK (on_modem_applet_about_clicked) }
 };
 
 G_DEFINE_TYPE (ModemApplet, modem_applet, PANEL_TYPE_APPLET)
@@ -228,6 +234,7 @@ modem_applet_finalize (GObject *object)
       gtk_widget_destroy (priv->auth_dialog);
       gtk_widget_destroy (priv->report_window);
       g_object_unref (priv->icon);
+      g_object_unref (priv->action_group);
 
       g_free (priv->dev);
       g_free (priv->lock_file);
@@ -622,19 +629,14 @@ shutdown_backend (ModemApplet *applet, gboolean backend_alive, gboolean already_
 static void
 update_popup_buttons (ModemApplet *applet)
 {
-  BonoboUIComponent  *component;
+  GtkAction *action;
   ModemAppletPrivate *priv = MODEM_APPLET_GET_PRIVATE (applet);
 
-  component = panel_applet_get_popup_component (PANEL_APPLET (applet));
+  action = gtk_action_group_get_action (priv->action_group, "Activate");
+  gtk_action_set_sensitive (action, priv->configured && !priv->enabled);
 
-  bonobo_ui_component_set_prop (component,
-			        "/commands/Activate",
-				"sensitive", (priv->configured && !priv->enabled) ? "1" : "0",
-				NULL);
-  bonobo_ui_component_set_prop (component,
-			        "/commands/Deactivate",
-				"sensitive", (priv->configured && priv->enabled) ? "1" : "0",
-				NULL);
+  action = gtk_action_group_get_action (priv->action_group, "Deactivate");
+  gtk_action_set_sensitive (action, priv->configured && priv->enabled);
 }
 
 static void
@@ -961,25 +963,22 @@ toggle_interface (ModemApplet *applet, gboolean enable)
 }
 
 static void
-on_modem_applet_activate (BonoboUIComponent *uic,
-			  ModemApplet       *applet,
-			  const gchar       *verb)
+on_modem_applet_activate (GtkAction   *action,
+			  ModemApplet *applet)
 {
   toggle_interface (applet, TRUE);
 }
 
 static void
-on_modem_applet_deactivate (BonoboUIComponent *uic,
-			    ModemApplet       *applet,
-			    const gchar       *verb)
+on_modem_applet_deactivate (GtkAction   *action,
+			    ModemApplet *applet)
 {
   toggle_interface (applet, FALSE);
 }
 
 static void
-on_modem_applet_properties_clicked (BonoboUIComponent *uic,
-				    ModemApplet       *applet,
-				    const gchar       *verb)
+on_modem_applet_properties_clicked (GtkAction   *action,
+				    ModemApplet *applet)
 {
   ModemAppletPrivate *priv = MODEM_APPLET_GET_PRIVATE (applet);
   GdkScreen *screen;
@@ -1003,9 +1002,8 @@ on_modem_applet_properties_clicked (BonoboUIComponent *uic,
 }
 
 static void
-on_modem_applet_about_clicked (BonoboUIComponent *uic,
-			       ModemApplet       *applet,
-			       const gchar       *verb)
+on_modem_applet_about_clicked (GtkAction   *action,
+			       ModemApplet *applet)
 {
   const gchar *authors[] = {
     "Carlos Garnacho Parro <carlosg gnome org>",
@@ -1028,9 +1026,8 @@ on_modem_applet_about_clicked (BonoboUIComponent *uic,
 }
 
 static void
-on_modem_applet_help_clicked (BonoboUIComponent *uic,
-			      ModemApplet       *applet,
-			      const char        *verb)
+on_modem_applet_help_clicked (GtkAction   *action,
+			      ModemApplet *applet)
 {
   gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (applet)),
 		"ghelp:modemlights",
@@ -1041,16 +1038,25 @@ on_modem_applet_help_clicked (BonoboUIComponent *uic,
 static gboolean
 modem_applet_fill (ModemApplet *applet)
 {
+  ModemAppletPrivate *priv = MODEM_APPLET_GET_PRIVATE (applet);
+  gchar *ui_path;
+
   g_return_val_if_fail (PANEL_IS_APPLET (applet), FALSE);
 
   gtk_widget_show_all (GTK_WIDGET (applet));
 
+  priv->action_group = gtk_action_group_new ("ModemLights Applet Actions");
+  gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE);
+  gtk_action_group_add_actions (priv->action_group,
+				menu_actions,
+				G_N_ELEMENTS (menu_actions),
+				applet);
+  update_popup_buttons (applet);
+  ui_path = g_build_filename (MODEM_MENU_UI_DIR, "modem-applet-menu.xml", NULL);
   panel_applet_setup_menu_from_file (PANEL_APPLET (applet),
-				     DATADIR,
-				     "GNOME_ModemLights.xml",
-				     NULL,
-				     menu_verbs,
-				     applet);
+				     ui_path, priv->action_group);
+  g_free (ui_path);
+
   return TRUE;
 }
 
@@ -1061,15 +1067,14 @@ modem_applet_factory (PanelApplet *applet,
 {
   gboolean retval = FALSE;
     
-  if (!strcmp (iid, "OAFIID:GNOME_ModemLightsApplet"))
+  if (!strcmp (iid, "ModemLightsApplet"))
     retval = modem_applet_fill (MODEM_APPLET (applet)); 
   
   return retval;
 }
 
-PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GNOME_ModemApplet_Factory",
-			     TYPE_MODEM_APPLET,
-			     "modem",
-			     "0",
-			     modem_applet_factory,
-			     NULL)
+PANEL_APPLET_OUT_PROCESS_FACTORY ("ModemAppletFactory",
+				  TYPE_MODEM_APPLET,
+				  "modem",
+				  modem_applet_factory,
+				  NULL)
diff --git a/modemlights/org.gnome.applets.ModemApplet.panel-applet.in.in b/modemlights/org.gnome.applets.ModemApplet.panel-applet.in.in
new file mode 100644
index 0000000..a64785c
--- /dev/null
+++ b/modemlights/org.gnome.applets.ModemApplet.panel-applet.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=ModemAppletFactory
+Location= LIBEXECDIR@/modem_applet
+Name=Modem Factory
+Description=Modem Applet Factory
+
+[ModemLightsApplet]
+_Name=Modem Monitor
+_Description=Activate and monitor a dial-up network connection
+Icon=gnome-modem-monitor-applet
+BonoboId=OAFIID:GNOME_ModemLightsApplet
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-applets
+X-GNOME-Bugzilla-Component=modemlights
+X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=modem_applet
diff --git a/modemlights/org.gnome.panel.applet.ModemAppletFactory.service.in b/modemlights/org.gnome.panel.applet.ModemAppletFactory.service.in
new file mode 100644
index 0000000..a508a72
--- /dev/null
+++ b/modemlights/org.gnome.panel.applet.ModemAppletFactory.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.panel.applet.ModemAppletFactory
+Exec= LIBEXECDIR@/modem_applet



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