[gnome-panel] menu: don't pass GpApplet object to GpUserMenu



commit 4fd1722cc97414a323b823638f75da8b3b6fad44
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Sep 16 17:09:28 2018 +0300

    menu: don't pass GpApplet object to GpUserMenu

 modules/menu/gp-menu-button-applet.c |  17 +++-
 modules/menu/gp-user-menu-applet.c   |  17 +++-
 modules/menu/gp-user-menu.c          | 146 +++++++++++++++++++++--------------
 modules/menu/gp-user-menu.h          |   3 +-
 4 files changed, 120 insertions(+), 63 deletions(-)
---
diff --git a/modules/menu/gp-menu-button-applet.c b/modules/menu/gp-menu-button-applet.c
index 7f79bf47e..83ac604c7 100644
--- a/modules/menu/gp-menu-button-applet.c
+++ b/modules/menu/gp-menu-button-applet.c
@@ -221,9 +221,24 @@ append_user_item (GpMenuButtonApplet *menu_button,
   gp_image_menu_item_set_image (GP_IMAGE_MENU_ITEM (item), icon);
   gtk_widget_show (item);
 
-  user_menu = gp_user_menu_new (GP_APPLET (menu_button));
+  user_menu = gp_user_menu_new ();
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), user_menu);
 
+  g_object_bind_property (menu_button, "enable-tooltips",
+                          user_menu, "enable-tooltips",
+                          G_BINDING_DEFAULT |
+                          G_BINDING_SYNC_CREATE);
+
+  g_object_bind_property (menu_button, "locked-down",
+                          user_menu, "locked-down",
+                          G_BINDING_DEFAULT |
+                          G_BINDING_SYNC_CREATE);
+
+  g_object_bind_property (menu_button, "menu-icon-size",
+                          user_menu, "menu-icon-size",
+                          G_BINDING_DEFAULT |
+                          G_BINDING_SYNC_CREATE);
+
   g_object_bind_property (user_menu, "empty", item, "visible",
                           G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE |
                           G_BINDING_INVERT_BOOLEAN);
diff --git a/modules/menu/gp-user-menu-applet.c b/modules/menu/gp-user-menu-applet.c
index 57da75e81..4e69fa430 100644
--- a/modules/menu/gp-user-menu-applet.c
+++ b/modules/menu/gp-user-menu-applet.c
@@ -85,9 +85,24 @@ append_user_item (GpUserMenuApplet *applet)
   gp_image_menu_item_set_image (GP_IMAGE_MENU_ITEM (item), icon);
   gtk_widget_show (item);
 
-  menu = gp_user_menu_new (GP_APPLET (applet));
+  menu = gp_user_menu_new ();
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
 
+  g_object_bind_property (applet, "enable-tooltips",
+                          menu, "enable-tooltips",
+                          G_BINDING_DEFAULT |
+                          G_BINDING_SYNC_CREATE);
+
+  g_object_bind_property (applet, "locked-down",
+                          menu, "locked-down",
+                          G_BINDING_DEFAULT |
+                          G_BINDING_SYNC_CREATE);
+
+  g_object_bind_property (applet, "menu-icon-size",
+                          menu, "menu-icon-size",
+                          G_BINDING_DEFAULT |
+                          G_BINDING_SYNC_CREATE);
+
   applet->lock_logout = gp_lock_logout_new ();
 
   g_object_bind_property (applet, "enable-tooltips",
diff --git a/modules/menu/gp-user-menu.c b/modules/menu/gp-user-menu.c
index 173bc8b57..be42b9dd8 100644
--- a/modules/menu/gp-user-menu.c
+++ b/modules/menu/gp-user-menu.c
@@ -25,7 +25,9 @@ struct _GpUserMenu
 {
   GtkMenu                parent;
 
-  GpApplet              *applet;
+  gboolean               enable_tooltips;
+  gboolean               locked_down;
+  guint                  menu_icon_size;
 
   gboolean               empty;
 
@@ -33,16 +35,16 @@ struct _GpUserMenu
   gpointer               append_data;
 
   guint                  reload_id;
-
-  gulong                 locked_down_id;
-  gulong                 menu_icon_size_id;
 };
 
 enum
 {
   PROP_0,
 
-  PROP_APPLET,
+  PROP_ENABLE_TOOLTIPS,
+  PROP_LOCKED_DOWN,
+  PROP_MENU_ICON_SIZE,
+
   PROP_EMPTY,
 
   LAST_PROP
@@ -114,12 +116,10 @@ append_control_center (GpUserMenu *menu)
 
   if (icon != NULL)
     {
-      guint icon_size;
       GtkWidget *image;
 
-      icon_size = gp_applet_get_menu_icon_size (menu->applet);
       image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
-      gtk_image_set_pixel_size (GTK_IMAGE (image), icon_size);
+      gtk_image_set_pixel_size (GTK_IMAGE (image), menu->menu_icon_size);
 
       gp_image_menu_item_set_image (GP_IMAGE_MENU_ITEM (item), image);
     }
@@ -128,13 +128,13 @@ append_control_center (GpUserMenu *menu)
     {
       gtk_widget_set_tooltip_text (item, description);
 
-      g_object_bind_property (menu->applet, "enable-tooltips",
+      g_object_bind_property (menu, "enable-tooltips",
                               item, "has-tooltip",
                               G_BINDING_DEFAULT |
                               G_BINDING_SYNC_CREATE);
     }
 
-  if (!gp_applet_get_locked_down (menu->applet))
+  if (!menu->locked_down)
     {
       static const GtkTargetEntry drag_targets[] =
         {
@@ -222,22 +222,6 @@ queue_reload (GpUserMenu *menu)
   g_source_set_name_by_id (menu->reload_id, "[menu] reload_cb");
 }
 
-static void
-locked_down_cb (GpApplet   *applet,
-                GParamSpec *pspec,
-                GpUserMenu *menu)
-{
-  queue_reload (menu);
-}
-
-static void
-menu_icon_size_cb (GpApplet   *applet,
-                   GParamSpec *pspec,
-                   GpUserMenu *menu)
-{
-  queue_reload (menu);
-}
-
 static void
 gp_user_menu_constructed (GObject *object)
 {
@@ -247,14 +231,6 @@ gp_user_menu_constructed (GObject *object)
 
   G_OBJECT_CLASS (gp_user_menu_parent_class)->constructed (object);
 
-  menu->locked_down_id = g_signal_connect (menu->applet, "notify::locked-down",
-                                           G_CALLBACK (locked_down_cb), menu);
-
-  menu->menu_icon_size_id = g_signal_connect (menu->applet,
-                                              "notify::menu-icon-size",
-                                              G_CALLBACK (menu_icon_size_cb),
-                                              menu);
-
   queue_reload (menu);
 }
 
@@ -271,20 +247,6 @@ gp_user_menu_dispose (GObject *object)
       menu->reload_id = 0;
     }
 
-  if (menu->locked_down_id != 0)
-    {
-      g_signal_handler_disconnect (menu->applet, menu->locked_down_id);
-      menu->locked_down_id = 0;
-    }
-
-  if (menu->menu_icon_size_id != 0)
-    {
-      g_signal_handler_disconnect (menu->applet, menu->menu_icon_size_id);
-      menu->menu_icon_size_id = 0;
-    }
-
-  menu->applet = NULL;
-
   G_OBJECT_CLASS (gp_user_menu_parent_class)->dispose (object);
 }
 
@@ -300,10 +262,15 @@ gp_user_menu_get_property (GObject    *object,
 
   switch (property_id)
     {
-      case PROP_APPLET:
+      case PROP_LOCKED_DOWN:
+      case PROP_MENU_ICON_SIZE:
         g_assert_not_reached ();
         break;
 
+      case PROP_ENABLE_TOOLTIPS:
+        g_value_set_boolean (value, menu->enable_tooltips);
+        break;
+
       case PROP_EMPTY:
         g_value_set_boolean (value, menu->empty);
         break;
@@ -314,6 +281,41 @@ gp_user_menu_get_property (GObject    *object,
     }
 }
 
+static void
+set_enable_tooltips (GpUserMenu *menu,
+                     gboolean    enable_tooltips)
+{
+  if (menu->enable_tooltips == enable_tooltips)
+    return;
+
+  menu->enable_tooltips = enable_tooltips;
+
+  g_object_notify_by_pspec (G_OBJECT (menu),
+                            menu_properties[PROP_ENABLE_TOOLTIPS]);
+}
+
+static void
+set_locked_down (GpUserMenu *menu,
+                 gboolean   locked_down)
+{
+  if (menu->locked_down == locked_down)
+    return;
+
+  menu->locked_down = locked_down;
+  queue_reload (menu);
+}
+
+static void
+set_menu_icon_size (GpUserMenu *menu,
+                    guint       menu_icon_size)
+{
+  if (menu->menu_icon_size == menu_icon_size)
+    return;
+
+  menu->menu_icon_size = menu_icon_size;
+  queue_reload (menu);
+}
+
 static void
 gp_user_menu_set_property (GObject      *object,
                            guint         property_id,
@@ -326,9 +328,21 @@ gp_user_menu_set_property (GObject      *object,
 
   switch (property_id)
     {
-      case PROP_APPLET:
-        g_assert (menu->applet == NULL);
-        menu->applet = g_value_get_object (value);
+
+      case PROP_ENABLE_TOOLTIPS:
+        set_enable_tooltips (menu, g_value_get_boolean (value));
+        break;
+
+      case PROP_LOCKED_DOWN:
+        set_locked_down (menu, g_value_get_boolean (value));
+        break;
+
+      case PROP_MENU_ICON_SIZE:
+        set_menu_icon_size (menu, g_value_get_uint (value));
+        break;
+
+      case PROP_EMPTY:
+        g_assert_not_reached ();
         break;
 
       default:
@@ -340,11 +354,26 @@ gp_user_menu_set_property (GObject      *object,
 static void
 install_properties (GObjectClass *object_class)
 {
-  menu_properties[PROP_APPLET] =
-    g_param_spec_object ("applet", "Applet", "Applet",
-                         GP_TYPE_APPLET,
-                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
-                         G_PARAM_STATIC_STRINGS);
+  menu_properties[PROP_ENABLE_TOOLTIPS] =
+    g_param_spec_boolean ("enable-tooltips", "Enable Tooltips", "Enable Tooltips",
+                          TRUE,
+                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
+                          G_PARAM_EXPLICIT_NOTIFY |
+                          G_PARAM_STATIC_STRINGS);
+
+  menu_properties[PROP_LOCKED_DOWN] =
+    g_param_spec_boolean ("locked-down", "Locked Down", "Locked Down",
+                          FALSE,
+                          G_PARAM_CONSTRUCT | G_PARAM_WRITABLE |
+                          G_PARAM_EXPLICIT_NOTIFY |
+                          G_PARAM_STATIC_STRINGS);
+
+  menu_properties[PROP_MENU_ICON_SIZE] =
+    g_param_spec_uint ("menu-icon-size", "Menu Icon Size", "Menu Icon Size",
+                       16, 24, 16,
+                       G_PARAM_CONSTRUCT | G_PARAM_WRITABLE |
+                       G_PARAM_EXPLICIT_NOTIFY |
+                       G_PARAM_STATIC_STRINGS);
 
   menu_properties[PROP_EMPTY] =
     g_param_spec_boolean ("empty", "Empty", "Empty",
@@ -376,10 +405,9 @@ gp_user_menu_init (GpUserMenu *menu)
 }
 
 GtkWidget *
-gp_user_menu_new (GpApplet *applet)
+gp_user_menu_new (void)
 {
   return g_object_new (GP_TYPE_USER_MENU,
-                       "applet", applet,
                        NULL);
 }
 
diff --git a/modules/menu/gp-user-menu.h b/modules/menu/gp-user-menu.h
index 35c977e32..9b111c1e9 100644
--- a/modules/menu/gp-user-menu.h
+++ b/modules/menu/gp-user-menu.h
@@ -19,14 +19,13 @@
 #define GP_USER_MENU_H
 
 #include "gp-menu-utils.h"
-#include <libgnome-panel/gp-applet.h>
 
 G_BEGIN_DECLS
 
 #define GP_TYPE_USER_MENU (gp_user_menu_get_type ())
 G_DECLARE_FINAL_TYPE (GpUserMenu, gp_user_menu, GP, USER_MENU, GtkMenu)
 
-GtkWidget *gp_user_menu_new             (GpApplet              *applet);
+GtkWidget *gp_user_menu_new             (void);
 
 void       gp_user_menu_set_append_func (GpUserMenu            *user_menu,
                                          GpAppendMenuItemsFunc  append_func,


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