]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtklockbutton.c
label: Fix memleak
[~andy/gtk] / gtk / gtklockbutton.c
index 70d2a4d6893ae5963a9f000e31b508ddcca2a0fb..962b4a947d4b7ac12deb7ef8e84104b725387bad 100644 (file)
 
 #include "config.h"
 
-#include "gtklockbutton.h"
+#include "gtklockbuttonprivate.h"
 #include "gtkbox.h"
 #include "gtkimage.h"
 #include "gtklabel.h"
 #include "gtksizegroup.h"
 #include "gtkintl.h"
+#include "a11y/gtklockbuttonaccessibleprivate.h"
 
 /**
  * SECTION:gtklockbutton
  * preference dialogs to allow users to obtain and revoke authorizations
  * needed to operate the controls. The required authorization is represented
  * by a #GPermission object. Concrete implementations of #GPermission may use
- * PolicyKit or some other authorization framework.
+ * PolicyKit or some other authorization framework. To obtain a PolicyKit-based
+ * #GPermission, use polkit_permission_new().
  *
- * If the user lacks the authorization but authorization can be obtained
- * through authentication, the widget looks like this
+ * If the user is not currently allowed to perform the action, but can obtain
+ * the permission, the widget looks like this
  * <informalexample><inlinegraphic fileref="lockbutton-locked.png"></inlinegraphic></informalexample>
- * and the user can click the button to obtain the authorization. Depending
+ * and the user can click the button to request the permission. Depending
  * on the platform, this may pop up an authentication dialog or ask the user
- * to authenticate in some other way. Once authorization is obtained, the
- * widget changes to this
+ * to authenticate in some other way. Once the user has obtained the permission,
+ * the widget changes to this
  * <informalexample><inlinegraphic fileref="lockbutton-unlocked.png"></inlinegraphic></informalexample>
- * and the authorization can be dropped by clicking the button. If the user
- * is not able to obtain authorization at all, the widget looks like this
+ * and the permission can be dropped again by clicking the button. If the user
+ * is not able to obtain the permission at all, the widget looks like this
  * <informalexample><inlinegraphic fileref="lockbutton-sorry.png"></inlinegraphic></informalexample>
- * If the user is authorized and cannot drop the authorization, the button
- * is hidden.
+ * If the user has the permission and cannot drop it, the button is hidden.
  *
  * The text (and tooltips) that are shown in the various cases can be adjusted
  * with the #GtkLockButton:text-lock, #GtkLockButton:text-unlock,
@@ -184,10 +185,12 @@ gtk_lock_button_set_property (GObject      *object,
 
     case PROP_TEXT_LOCK:
       gtk_label_set_text (GTK_LABEL (priv->label_lock), g_value_get_string (value));
+      _gtk_lock_button_accessible_name_changed (button);
       break;
 
     case PROP_TEXT_UNLOCK:
       gtk_label_set_text (GTK_LABEL (priv->label_unlock), g_value_get_string (value));
+      _gtk_lock_button_accessible_name_changed (button);
       break;
 
     case PROP_TOOLTIP_LOCK:
@@ -261,6 +264,7 @@ static void
 gtk_lock_button_class_init (GtkLockButtonClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
 
   gobject_class->finalize     = gtk_lock_button_finalize;
@@ -323,6 +327,8 @@ gtk_lock_button_class_init (GtkLockButtonClass *klass)
                          G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LOCK_BUTTON_ACCESSIBLE);
 }
 
 static void
@@ -384,8 +390,12 @@ update_state (GtkLockButton *button)
     }
 
   gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_MENU);
-  gtk_widget_set_visible (priv->label_lock, allowed);
-  gtk_widget_set_visible (priv->label_unlock, !allowed);
+  if (gtk_widget_get_visible (priv->label_lock) != allowed)
+    {
+      gtk_widget_set_visible (priv->label_lock, allowed);
+      gtk_widget_set_visible (priv->label_unlock, !allowed);
+      _gtk_lock_button_accessible_name_changed (button);
+    }
   gtk_widget_set_tooltip_markup (GTK_WIDGET (button), tooltip);
   gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive);
   gtk_widget_set_visible (GTK_WIDGET (button), visible);
@@ -560,3 +570,19 @@ gtk_lock_button_set_permission (GtkLockButton *button,
       g_object_notify (G_OBJECT (button), "permission");
     }
 }
+
+const char *
+_gtk_lock_button_get_current_text (GtkLockButton *button)
+{
+  GtkLockButtonPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_LOCK_BUTTON (button), NULL);
+
+  priv = button->priv;
+
+  if (gtk_widget_get_visible (priv->label_lock))
+    return gtk_label_get_text (GTK_LABEL (priv->label_lock));
+  else
+    return gtk_label_get_text (GTK_LABEL (priv->label_unlock));
+}
+