[gnome-applets/wip/gnome-3.10+: 2/5] modemlights: restore applet



commit 52f6f7f16859d420b53d175934d9b646d26671c2
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Jul 10 10:31:44 2014 +0300

    modemlights: restore applet

 configure.ac               |   20 +++----
 modemlights/Makefile.am    |    9 ++-
 modemlights/modem-applet.c |  129 ++++++++++++++++++++-----------------------
 modemlights/modem-applet.h |   18 +++---
 4 files changed, 83 insertions(+), 93 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d27b8cb..4c23454 100644
--- a/configure.ac
+++ b/configure.ac
@@ -434,20 +434,16 @@ HAVE_LIBUTIL=
 AC_PATH_PROG(SU_TOOL, su)
 AC_CHECK_LIB(util, forkpty, HAVE_LIBUTIL=true, HAVE_LIBUTIL=false)
 
-dnl ***
-dnl *** Modem lights does not currently compile. It needs to be ported to a
-dnl *** modern gnome-system-tools backend.
-dnl ***
-dnl if test "x$HAVE_LIBUTIL" = "xtrue" -a "x$HAVE_GNOME_SETTINGS_DAEMON" = "xyes"; then
-dnl   MODEMLIGHTS_LIBS=" -lutil"
-dnl   AC_SUBST(MODEMLIGHTS_LIBS)
-dnl   AC_DEFINE_UNQUOTED(STB_SCRIPTS_DIR, "$STB_SCRIPTS_DIR", [System tools backends])
-dnl   AC_DEFINE_UNQUOTED(SU_PATH, "${SU_TOOL}", [su executable path])
-dnl   BUILD_MODEM_LIGHTS=yes
-dnl else
+if test "x$HAVE_LIBUTIL" = "xtrue" -a "x$HAVE_GNOME_SETTINGS_DAEMON" = "xyes"; then
+  MODEMLIGHTS_LIBS=" -lutil"
+  AC_SUBST(MODEMLIGHTS_LIBS)
+  AC_DEFINE_UNQUOTED(STB_SCRIPTS_DIR, "$STB_SCRIPTS_DIR", [System tools backends])
+  AC_DEFINE_UNQUOTED(SU_PATH, "${SU_TOOL}", [su executable path])
+  BUILD_MODEM_LIGHTS=yes
+else
   AC_MSG_WARN([*** modemlights applet will not be built ***])
   BUILD_MODEM_LIGHTS=no
-dnl fi
+fi
 
 AM_CONDITIONAL(APPLET_MODEMLIGHTS, test "x$BUILD_MODEM_LIGHTS" = "xyes")
 
diff --git a/modemlights/Makefile.am b/modemlights/Makefile.am
index eb46bcb..71680ad 100644
--- a/modemlights/Makefile.am
+++ b/modemlights/Makefile.am
@@ -3,7 +3,8 @@
 AM_CPPFLAGS = -I. -I$(srcdir)                          \
        -DMODEM_MENU_UI_DIR=\""$(uidir)"\"              \
        $(GNOME_APPLETS_CFLAGS)                         \
-       $(WARN_CFLAGS)
+       $(WARN_CFLAGS) \
+       $(XML2_CFLAGS)
 
 libexec_PROGRAMS = modem_applet
 
@@ -13,11 +14,13 @@ modem_applet_SOURCES = \
 
 modem_applet_LDADD =           \
        $(GNOME_APPLETS_LIBS)   \
-       $(MODEMLIGHTS_LIBS)
+       $(MODEMLIGHTS_LIBS) \
+       $(XML2_LIBS)
 
-uidir  = $(datadir)/gnome-2.0/ui
+uidir  = $(pkgdatadir)/ui
 ui_DATA        = modem-applet-menu.xml
 
+
 appletdir       = $(LIBPANEL_APPLET_DIR)
 applet_in_files = org.gnome.applets.ModemApplet.panel-applet.in
 applet_DATA     = $(applet_in_files:.panel-applet.in=.panel-applet)
diff --git a/modemlights/modem-applet.c b/modemlights/modem-applet.c
index dc29671..6aec345 100644
--- a/modemlights/modem-applet.c
+++ b/modemlights/modem-applet.c
@@ -50,7 +50,6 @@
 
 typedef void (*DirectiveCallback) (ModemApplet*, xmlDoc*);
 typedef struct _BackendDirective   BackendDirective;
-typedef struct _ModemAppletPrivate ModemAppletPrivate;
 
 struct _ModemAppletPrivate
 {
@@ -87,6 +86,8 @@ struct _ModemAppletPrivate
   GSList *directives;
   gboolean directive_running;
 
+  gint size;
+
   /* interface data */
   gboolean configured;  /* is configured? */
   gboolean enabled;     /* is enabled? */
@@ -112,12 +113,9 @@ static gboolean update_tooltip      (ModemApplet *applet);
 static gboolean dispatch_directives (ModemApplet *applet);
 static gboolean update_info         (ModemApplet *applet);
 
-static void modem_applet_change_size (PanelApplet *applet, guint size);
-
-static void modem_applet_change_background (PanelApplet *app,
-                                           PanelAppletBackgroundType type,
-                                           GdkColor  *colour,
-                                           GdkPixmap *pixmap);
+static void modem_applet_size_allocate (GtkWidget     *widget,
+                                        GtkAllocation *allocation,
+                                        gpointer       user_data);
 
 static void on_modem_applet_about_clicked (GSimpleAction *action,
                                            GVariant      *parameter,
@@ -141,8 +139,6 @@ static void shutdown_backend              (ModemApplet *applet,
                                           gboolean     backend_alive,
                                           gboolean     already_waiting);
 
-static gpointer parent_class;
-
 static const GActionEntry menu_actions [] = {
   { "activate", on_modem_applet_activate, NULL, NULL, NULL },
   { "deactivate", on_modem_applet_deactivate, NULL, NULL, NULL },
@@ -151,23 +147,15 @@ static const GActionEntry menu_actions [] = {
   { "about", on_modem_applet_about_clicked, NULL, NULL, NULL }
 };
 
-G_DEFINE_TYPE (ModemApplet, modem_applet, PANEL_TYPE_APPLET)
+G_DEFINE_TYPE_WITH_PRIVATE (ModemApplet, modem_applet, PANEL_TYPE_APPLET)
 
 static void
 modem_applet_class_init (ModemAppletClass *class)
 {
-  GObjectClass     *object_class;
-  PanelAppletClass *applet_class;
+  GObjectClass *object_class;
 
   object_class = G_OBJECT_CLASS (class);
-  applet_class = PANEL_APPLET_CLASS (class);
-  parent_class = g_type_class_peek_parent (class);
-
-  object_class->finalize    = modem_applet_finalize;
-  applet_class->change_size = modem_applet_change_size;
-  applet_class->change_background = modem_applet_change_background;
-
-  g_type_class_add_private (object_class, sizeof (ModemAppletPrivate));
+  object_class->finalize = modem_applet_finalize;
 }
 
 static void
@@ -185,6 +173,7 @@ modem_applet_init (ModemApplet *applet)
   priv->icon = NULL;
   priv->icon_theme = gtk_icon_theme_get_default ();
   priv->image = gtk_image_new ();
+  priv->size = 48;
 
   priv->auth_dialog       = GTK_WIDGET (gtk_builder_get_object (priv->builder, "auth_dialog"));
   priv->auth_dialog_label = GTK_WIDGET (gtk_builder_get_object (priv->builder, "auth_dialog_label"));
@@ -197,7 +186,7 @@ modem_applet_init (ModemApplet *applet)
   g_signal_connect (G_OBJECT (priv->report_window), "delete-event",
                    G_CALLBACK (gtk_widget_hide), NULL);
 
-  pixbuf = gtk_icon_theme_load_icon (priv->icon_theme, "gnome-modem-monitor-applet", 48, 0, NULL);
+  pixbuf = gtk_icon_theme_load_icon (priv->icon_theme, "gnome-modem-monitor-applet", priv->size, 0, NULL);
   gtk_image_set_from_pixbuf (GTK_IMAGE (priv->report_window_image), pixbuf);
   g_object_unref (pixbuf);
 
@@ -235,62 +224,38 @@ modem_applet_finalize (GObject *object)
       g_free (priv->lock_file);
     }
 
-  if (G_OBJECT_CLASS (parent_class)->finalize)
-    (* G_OBJECT_CLASS (parent_class)->finalize) (object);
+  if (G_OBJECT_CLASS (modem_applet_parent_class)->finalize)
+    G_OBJECT_CLASS (modem_applet_parent_class)->finalize (object);
 }
 
 static void
-modem_applet_change_size (PanelApplet *applet,
-                         guint        size)
+modem_applet_size_allocate (GtkWidget     *widget,
+                            GtkAllocation *allocation,
+                            gpointer       user_data)
 {
+  ModemApplet *applet = MODEM_APPLET (user_data);
   ModemAppletPrivate *priv = MODEM_APPLET_GET_PRIVATE (applet);
+  PanelAppletOrient orient = panel_applet_get_orient (PANEL_APPLET (applet));
+  gint old_size = priv->size;
+
+  if (orient == PANEL_APPLET_ORIENT_UP || orient == PANEL_APPLET_ORIENT_DOWN) {
+    priv->size = allocation->height;
+  } else {
+    priv->size = allocation->width;
+  }
+
+  if (old_size == priv->size)
+    return;
 
   if (priv->icon)
     g_object_unref (priv->icon);
 
   /* this might be too much overload, maybe should we get just one icon size and scale? */
   priv->icon = gtk_icon_theme_load_icon (priv->icon_theme,
-                                        "gnome-modem", size, 0, NULL);
+                                        "gnome-modem", priv->size, 0, NULL);
   gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), priv->icon);
 }
 
-static void
-modem_applet_change_background (PanelApplet *app,
-                               PanelAppletBackgroundType type,
-                               GdkColor  *colour,
-                               GdkPixmap *pixmap)
-{
-  ModemApplet *applet = MODEM_APPLET (app);
-  GtkRcStyle *rc_style;
-  GtkStyle *style;
-
-  /* reset style */
-  gtk_widget_set_style (GTK_WIDGET (applet), NULL);
-  rc_style = gtk_rc_style_new ();
-  gtk_widget_modify_style (GTK_WIDGET (applet), rc_style);
-  g_object_unref (rc_style);
-
-  switch (type)
-    {
-    case PANEL_NO_BACKGROUND:
-      break;
-    case PANEL_COLOR_BACKGROUND:
-      gtk_widget_modify_bg (GTK_WIDGET (applet),
-                           GTK_STATE_NORMAL, colour);
-      break;
-    case PANEL_PIXMAP_BACKGROUND:
-      style = gtk_style_copy (GTK_WIDGET (applet)->style);
-
-      if (style->bg_pixmap[GTK_STATE_NORMAL])
-        g_object_unref (style->bg_pixmap[GTK_STATE_NORMAL]);
-
-      style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref (pixmap);
-      gtk_widget_set_style (GTK_WIDGET (applet), style);
-      g_object_unref (style);
-      break;
-    }
-}
-
 static gboolean
 pulse_progressbar (GtkWidget *progressbar)
 {
@@ -625,7 +590,9 @@ static void
 update_popup_buttons (ModemApplet *applet)
 {
   GSimpleAction *action;
-  ModemAppletPrivate *priv = MODEM_APPLET_GET_PRIVATE (applet);
+  ModemAppletPrivate *priv;
+
+  priv = MODEM_APPLET_GET_PRIVATE (applet);
 
   action = (GSimpleAction *) g_action_map_lookup_action (G_ACTION_MAP (priv->action_group), "activate");
   g_simple_action_set_enabled (action, priv->configured && !priv->enabled);
@@ -887,11 +854,18 @@ launch_backend (ModemApplet *applet, gboolean root_auth)
     }
 }
 
+static void
+set_environment (gpointer display)
+{
+  g_setenv ("DISPLA", display, TRUE);
+}
+
 static gboolean
 launch_config_tool (GdkScreen *screen, gboolean is_isdn)
 {
-  gchar    *argv[4], *application;
+  gchar    *argv[4], *application, *display;
   gboolean  ret;
+  GError   *error;
 
   application = g_find_program_in_path (NETWORK_TOOL);
 
@@ -903,9 +877,20 @@ launch_config_tool (GdkScreen *screen, gboolean is_isdn)
   argv[2] = (is_isdn) ? "isdn" : "modem";
   argv[3] = NULL;
 
-  ret = gdk_spawn_on_screen (screen, NULL, argv, NULL, 0,
-                            NULL, NULL, NULL, NULL);
+  display = gdk_screen_make_display_name (screen);
+  error = NULL;
+
+  ret = g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
+                       set_environment, &display, NULL, &error);
+
+  if (!ret) {
+    g_warning ("launch_config_tool: %s", error->message);
+    g_error_free (error);
+  }
+
+  g_free (display);
   g_free (application);
+
   return ret;
 }
 
@@ -931,9 +916,9 @@ toggle_interface_root (ModemApplet *applet, gboolean enable)
                                   GTK_DIALOG_MODAL,
                                   GTK_MESSAGE_QUESTION,
                                   GTK_BUTTONS_NONE,
-                                  text);
+                                  "%s", text);
   gtk_dialog_add_buttons (GTK_DIALOG (dialog),
-                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                         _("_Cancel"), GTK_RESPONSE_CANCEL,
                          (enable) ? _("C_onnect") : _("_Disconnect"),
                          GTK_RESPONSE_OK, NULL);
   gtk_window_set_screen (GTK_WINDOW (dialog),
@@ -1063,6 +1048,12 @@ modem_applet_fill (ModemApplet *applet)
   gtk_widget_insert_action_group (GTK_WIDGET (applet), "modem",
                                   G_ACTION_GROUP (priv->action_group));
 
+  panel_applet_set_background_widget (PANEL_APPLET (applet),
+                                      GTK_WIDGET (applet));
+
+  g_signal_connect (GTK_WIDGET (applet), "size-allocate",
+                    G_CALLBACK (modem_applet_size_allocate), applet);
+
   return TRUE;
 }
 
diff --git a/modemlights/modem-applet.h b/modemlights/modem-applet.h
index 49d9701..67425f0 100644
--- a/modemlights/modem-applet.h
+++ b/modemlights/modem-applet.h
@@ -21,9 +21,7 @@
 #ifndef __MODEM_APPLET_H
 #define __MODEM_APPLET_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+G_BEGIN_DECLS
 
 #include <panel-applet.h>
 
@@ -34,19 +32,21 @@ extern "C" {
 #define IS_MODEM_APPLET_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE    ((obj), TYPE_MODEM_APPLET))
 #define MODEM_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS  ((obj), TYPE_MODEM_APPLET, ModemAppletClass))
 
-typedef struct _ModemApplet      ModemApplet;
-typedef struct _ModemAppletClass ModemAppletClass;
+typedef struct _ModemApplet        ModemApplet;
+typedef struct _ModemAppletClass   ModemAppletClass;
+typedef struct _ModemAppletPrivate ModemAppletPrivate;
 
 struct _ModemApplet {
-  PanelApplet parent;
+  PanelApplet         parent;
+  ModemAppletPrivate *priv;
 };
 
 struct _ModemAppletClass {
   PanelAppletClass parent_class;
 };
 
-#ifdef __cplusplus
-}
-#endif
+GType modem_applet_get_type (void);
+
+G_END_DECLS
 
 #endif /* __MODEM_APPLET_H */


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