[accounts-dialog] Use our own lock button implementation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [accounts-dialog] Use our own lock button implementation
- Date: Thu, 14 Oct 2010 22:14:38 +0000 (UTC)
commit f3ffe1019879f697e60ac3448b5f2a985488325c
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Oct 14 18:06:29 2010 -0400
Use our own lock button implementation
This is ultimatively destined to become GtkLockButton.
For now, we copy it here to try it out.
configure.ac | 2 +-
src/Makefile.am | 2 +
src/um-lockbutton.c | 637 ++++++++++++++++++++++++++++++++++++++++++++++++
src/um-lockbutton.h | 70 ++++++
src/um-login-options.c | 15 +-
src/um-user-panel.c | 61 ++++-
src/um-utils.c | 24 +-
src/um-utils.h | 2 +-
8 files changed, 781 insertions(+), 32 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 628748d..b9c2888 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,7 +37,7 @@ PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0)
PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 2.91)
PKG_CHECK_MODULES(GNOME_DESKTOP, gnome-desktop-3.0)
PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1)
-PKG_CHECK_MODULES(POLKIT, polkit-gtk-1)
+PKG_CHECK_MODULES(POLKIT, polkit-1)
PKG_CHECK_MODULES(GCONF, gconf-2.0)
PKG_CHECK_MODULES(CHEESE, gstreamer-0.10 cheese-gtk >= 2.29.90, have_cheese=yes, have_cheese=no)
diff --git a/src/Makefile.am b/src/Makefile.am
index 7477704..d5e31c8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,6 +45,8 @@ libuser_properties_la_SOURCES = \
um-account-dialog.c \
um-language-dialog.h \
um-language-dialog.c \
+ um-lockbutton.h \
+ um-lockbutton.c \
um-login-options.h \
um-login-options.c \
um-password-dialog.h \
diff --git a/src/um-lockbutton.c b/src/um-lockbutton.c
new file mode 100644
index 0000000..88da58c
--- /dev/null
+++ b/src/um-lockbutton.c
@@ -0,0 +1,637 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Author: Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "um-lockbutton.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#define P_(s) s
+
+struct _UmLockButtonPrivate
+{
+ GPermission *permission;
+
+ gchar *text_lock;
+ gchar *text_unlock;
+ gchar *text_not_authorized;
+
+ gchar *tooltip_lock;
+ gchar *tooltip_unlock;
+ gchar *tooltip_not_authorized;
+
+ GtkWidget *box;
+ GtkWidget *eventbox;
+ GtkWidget *image;
+ GtkWidget *button;
+ GtkWidget *notebook;
+
+ GtkWidget *label_lock;
+ GtkWidget *label_unlock;
+ GtkWidget *label_not_authorized;
+
+ GCancellable *cancellable;
+
+ gboolean constructed;
+};
+
+enum
+{
+ PROP_0,
+ PROP_PERMISSION,
+ PROP_TEXT_LOCK,
+ PROP_TEXT_UNLOCK,
+ PROP_TEXT_NOT_AUTHORIZED,
+ PROP_TOOLTIP_LOCK,
+ PROP_TOOLTIP_UNLOCK,
+ PROP_TOOLTIP_NOT_AUTHORIZED
+};
+
+enum
+{
+ CHANGED_SIGNAL,
+ LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = {0, };
+
+static void initiate_check (UmLockButton *button);
+static void do_sync_check (UmLockButton *button);
+static void update_state (UmLockButton *button);
+
+static void on_permission_changed (GPermission *permission,
+ GParamSpec *pspec,
+ gpointer user_data);
+
+static void on_clicked (GtkButton *button,
+ gpointer user_data);
+
+static void on_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data);
+
+G_DEFINE_TYPE (UmLockButton, um_lock_button, GTK_TYPE_BIN);
+
+static void
+um_lock_button_finalize (GObject *object)
+{
+ UmLockButton *button = UM_LOCK_BUTTON (object);
+ UmLockButtonPrivate *priv = button->priv;
+
+ g_free (priv->text_lock);
+ g_free (priv->text_unlock);
+ g_free (priv->text_not_authorized);
+
+ g_free (priv->tooltip_lock);
+ g_free (priv->tooltip_unlock);
+ g_free (priv->tooltip_not_authorized);
+
+ if (priv->cancellable != NULL)
+ {
+ g_cancellable_cancel (priv->cancellable);
+ g_object_unref (priv->cancellable);
+ }
+
+ g_signal_handlers_disconnect_by_func (priv->permission,
+ on_permission_changed,
+ button);
+
+ g_object_unref (priv->permission);
+
+ G_OBJECT_CLASS (um_lock_button_parent_class)->finalize (object);
+}
+
+static void
+um_lock_button_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ UmLockButton *button = UM_LOCK_BUTTON (object);
+ UmLockButtonPrivate *priv = button->priv;
+
+ switch (property_id)
+ {
+ case PROP_PERMISSION:
+ g_value_set_object (value, priv->permission);
+ break;
+
+ case PROP_TEXT_LOCK:
+ g_value_set_string (value, priv->text_lock);
+ break;
+
+ case PROP_TEXT_UNLOCK:
+ g_value_set_string (value, priv->text_unlock);
+ break;
+
+ case PROP_TEXT_NOT_AUTHORIZED:
+ g_value_set_string (value, priv->text_not_authorized);
+ break;
+
+ case PROP_TOOLTIP_LOCK:
+ g_value_set_string (value, priv->tooltip_lock);
+ break;
+
+ case PROP_TOOLTIP_UNLOCK:
+ g_value_set_string (value, priv->tooltip_unlock);
+ break;
+
+ case PROP_TOOLTIP_NOT_AUTHORIZED:
+ g_value_set_string (value, priv->tooltip_not_authorized);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+um_lock_button_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ UmLockButton *button = UM_LOCK_BUTTON (object);
+ UmLockButtonPrivate *priv = button->priv;
+
+ switch (property_id)
+ {
+ case PROP_PERMISSION:
+ priv->permission = g_value_get_object (value);
+ break;
+
+ case PROP_TEXT_LOCK:
+ g_free (priv->text_lock);
+ priv->text_lock = g_value_dup_string (value);
+ break;
+
+ case PROP_TEXT_UNLOCK:
+ g_free (priv->text_unlock);
+ priv->text_unlock = g_value_dup_string (value);
+ break;
+
+ case PROP_TEXT_NOT_AUTHORIZED:
+ g_free (priv->text_not_authorized);
+ priv->text_not_authorized = g_value_dup_string (value);
+ break;
+
+ case PROP_TOOLTIP_LOCK:
+ g_free (priv->tooltip_lock);
+ priv->tooltip_lock = g_value_dup_string (value);
+ break;
+
+ case PROP_TOOLTIP_UNLOCK:
+ g_free (priv->tooltip_unlock);
+ priv->tooltip_unlock = g_value_dup_string (value);
+ break;
+
+ case PROP_TOOLTIP_NOT_AUTHORIZED:
+ g_free (priv->tooltip_not_authorized);
+ priv->tooltip_not_authorized = g_value_dup_string (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+
+ if (priv->constructed)
+ update_state (button);
+}
+
+static void
+um_lock_button_init (UmLockButton *button)
+{
+ button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
+ UM_TYPE_LOCK_BUTTON,
+ UmLockButtonPrivate);
+}
+
+static void
+um_lock_button_constructed (GObject *object)
+{
+ UmLockButton *button = UM_LOCK_BUTTON (object);
+ UmLockButtonPrivate *priv = button->priv;
+
+ priv->constructed = TRUE;
+
+ g_signal_connect (priv->permission, "notify",
+ G_CALLBACK (on_permission_changed), button);
+
+ priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 6);
+ gtk_container_add (GTK_CONTAINER (button), priv->box);
+
+ priv->eventbox = gtk_event_box_new ();
+ gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->eventbox), FALSE);
+ gtk_container_add (GTK_CONTAINER (priv->box), priv->eventbox);
+ gtk_widget_show (priv->eventbox);
+
+ priv->image = gtk_image_new (); /* image is set in update_state() */
+ gtk_container_add (GTK_CONTAINER (priv->eventbox), priv->image);
+ gtk_widget_show (priv->image);
+
+ priv->notebook = gtk_notebook_new ();
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
+ gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
+ gtk_widget_show (priv->notebook);
+
+ priv->button = gtk_button_new ();
+ gtk_container_add (GTK_CONTAINER (priv->button), priv->notebook);
+ gtk_widget_show (priv->button);
+
+ priv->label_lock = gtk_label_new (""); /* text is set in update_state */
+ gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), priv->label_lock, NULL);
+ gtk_widget_show (priv->label_lock);
+
+ priv->label_unlock = gtk_label_new ("");
+ gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), priv->label_unlock, NULL);
+ gtk_widget_show (priv->label_unlock);
+
+ priv->label_not_authorized = gtk_label_new ("");
+ gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), priv->label_not_authorized, NULL);
+ gtk_widget_show (priv->label_not_authorized);
+
+ gtk_box_pack_start (GTK_BOX (priv->box), priv->button, FALSE, FALSE, 0);
+ gtk_widget_show (priv->button);
+
+ g_signal_connect (priv->eventbox, "button-press-event",
+ G_CALLBACK (on_button_press), button);
+ g_signal_connect (priv->button, "clicked",
+ G_CALLBACK (on_clicked), button);
+
+ gtk_widget_set_no_show_all (priv->box, TRUE);
+
+ update_state (button);
+
+ if (G_OBJECT_CLASS (um_lock_button_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (um_lock_button_parent_class)->constructed (object);
+}
+
+static void
+um_lock_button_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ UmLockButtonPrivate *priv = UM_LOCK_BUTTON (widget)->priv;
+
+ gtk_widget_get_preferred_size (priv->box, requisition, NULL);
+}
+
+static void
+um_lock_button_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ UmLockButtonPrivate *priv = UM_LOCK_BUTTON (widget)->priv;
+ GtkRequisition requisition;
+ GtkAllocation child_allocation;
+
+ gtk_widget_set_allocation (widget, allocation);
+ gtk_widget_get_preferred_size (priv->box, &requisition, NULL);
+ child_allocation.x = allocation->x;
+ child_allocation.y = allocation->y;
+ child_allocation.width = requisition.width;
+ child_allocation.height = requisition.height;
+ gtk_widget_size_allocate (priv->box, &child_allocation);
+}
+
+static void
+um_lock_button_class_init (UmLockButtonClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gobject_class->finalize = um_lock_button_finalize;
+ gobject_class->get_property = um_lock_button_get_property;
+ gobject_class->set_property = um_lock_button_set_property;
+ gobject_class->constructed = um_lock_button_constructed;
+
+ widget_class->size_request = um_lock_button_size_request;
+ widget_class->size_allocate = um_lock_button_size_allocate;
+
+ g_type_class_add_private (klass, sizeof (UmLockButtonPrivate));
+
+ g_object_class_install_property (gobject_class, PROP_PERMISSION,
+ g_param_spec_object ("permission",
+ P_("Permission"),
+ P_("The GPermission object controlling this button"),
+ G_TYPE_PERMISSION,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_TEXT_LOCK,
+ g_param_spec_string ("text-lock",
+ P_("Lock Text"),
+ P_("The text to display when prompting the user to lock"),
+ _("Lock"),
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_TEXT_UNLOCK,
+ g_param_spec_string ("text-unlock",
+ P_("Unlock Text"),
+ P_("The text to display when prompting the user to unlock"),
+ _("Unlock"),
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_TEXT_NOT_AUTHORIZED,
+ g_param_spec_string ("text-not-authorized",
+ P_("Not Authorized Text"),
+ P_("The text to display when prompting the user cannot obtain authorization"),
+ _("Locked"),
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_TOOLTIP_LOCK,
+ g_param_spec_string ("tooltip-lock",
+ P_("Lock Tooltip"),
+ P_("The tooltip to display when prompting the user to lock"),
+ _("Dialog is unlocked.\nClick to prevent further changes"),
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_TOOLTIP_UNLOCK,
+ g_param_spec_string ("tooltip-unlock",
+ P_("Unlock Tooltip"),
+ P_("The tooltip to display when prompting the user to unlock"),
+ _("Dialog is locked.\nClick to make changes"),
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_TOOLTIP_NOT_AUTHORIZED,
+ g_param_spec_string ("tooltip-not-authorized",
+ P_("Not Authorized Tooltip"),
+ P_("The tooltip to display when prompting the user cannot obtain authorization"),
+ _("System policy prevents changes.\nContact your system administrator"),
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ signals[CHANGED_SIGNAL] = g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (UmLockButtonClass, changed),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+}
+
+/**
+ * um_lock_button_new:
+ * @permission: a #GPermission
+ *
+ * Creates a new lock button which reflects the @permission.
+ *
+ * Returns: a new #UmLockButton
+ *
+ * Since: 3.0
+ */
+GtkWidget *
+um_lock_button_new (GPermission *permission)
+{
+ g_return_val_if_fail (permission != NULL, NULL);
+
+ return GTK_WIDGET (g_object_new (UM_TYPE_LOCK_BUTTON,
+ "permission", permission,
+ NULL));
+}
+
+static void
+update_state (UmLockButton *button)
+{
+ UmLockButtonPrivate *priv = button->priv;
+ gint page;
+ const gchar *tooltip;
+ gboolean sensitive;
+ gboolean visible;
+ GIcon *icon;
+
+ visible = TRUE;
+ sensitive = TRUE;
+
+ gtk_label_set_text (GTK_LABEL (priv->label_lock), priv->text_lock);
+ gtk_label_set_text (GTK_LABEL (priv->label_unlock), priv->text_unlock);
+ gtk_label_set_text (GTK_LABEL (priv->label_not_authorized), priv->text_not_authorized);
+
+ if (g_permission_get_allowed (priv->permission))
+ {
+ if (g_permission_get_can_release (priv->permission))
+ {
+ page = 0;
+ tooltip = priv->tooltip_lock;
+ sensitive = TRUE;
+ }
+ else
+ {
+ page = 0;
+ tooltip = "";
+ visible = FALSE;
+ }
+ }
+ else
+ {
+ if (g_permission_get_can_acquire (priv->permission))
+ {
+ page = 1;
+ tooltip = button->priv->tooltip_unlock;
+ sensitive = TRUE;
+ }
+ else
+ {
+ page = 2;
+ tooltip = button->priv->tooltip_not_authorized;
+ sensitive = FALSE;
+ }
+ }
+
+ if (g_permission_get_allowed (priv->permission))
+ {
+ gchar *names[3];
+
+ names[0] = "changes-allow-symbolic";
+ names[1] = "changes-allow";
+ names[2] = NULL;
+ icon = g_themed_icon_new_from_names (names, -1);
+ }
+ else
+ {
+ gchar *names[3];
+
+ names[0] = "changes-prevent-symbolic";
+ names[1] = "changes-prevent";
+ names[2] = NULL;
+ icon = g_themed_icon_new_from_names (names, -1);
+ }
+
+ gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_BUTTON);
+ g_object_unref (icon);
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page);
+ gtk_widget_set_tooltip_markup (priv->box, tooltip);
+
+ gtk_widget_set_sensitive (priv->box, sensitive);
+
+ if (visible)
+ gtk_widget_show (priv->box);
+ else
+ gtk_widget_hide (priv->box);
+}
+
+static void
+on_permission_changed (GPermission *permission,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ UmLockButton *button = UM_LOCK_BUTTON (user_data);
+
+ update_state (button);
+}
+
+static void
+acquire_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ UmLockButton *button = UM_LOCK_BUTTON (user_data);
+ UmLockButtonPrivate *priv = button->priv;
+ GError *error;
+ gboolean res;
+
+ error = NULL;
+ res = g_permission_acquire_finish (priv->permission, result, &error);
+
+ if (error)
+ {
+ g_warning ("Error acquiring permission: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (priv->cancellable);
+ priv->cancellable = NULL;
+
+ update_state (button);
+}
+
+static void
+release_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ UmLockButton *button = UM_LOCK_BUTTON (user_data);
+ UmLockButtonPrivate *priv = button->priv;
+ GError *error;
+ gboolean res;
+
+ error = NULL;
+ res = g_permission_release_finish (priv->permission, result, &error);
+
+ if (error)
+ {
+ g_warning ("Error releasing permission: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (priv->cancellable);
+ priv->cancellable = NULL;
+
+ update_state (button);
+}
+
+static void
+handle_click (UmLockButton *button)
+{
+ UmLockButtonPrivate *priv = button->priv;
+
+ if (!g_permission_get_allowed (priv->permission) &&
+ g_permission_get_can_acquire (priv->permission))
+ {
+ /* if we already have a pending interactive check, then do nothing */
+ if (priv->cancellable != NULL)
+ goto out;
+
+ priv->cancellable = g_cancellable_new ();
+
+ g_permission_acquire_async (priv->permission,
+ priv->cancellable,
+ acquire_cb,
+ button);
+ }
+ else if (g_permission_get_allowed (priv->permission) &&
+ g_permission_get_can_release (priv->permission))
+ {
+ /* if we already have a pending interactive check, then do nothing */
+ if (priv->cancellable != NULL)
+ goto out;
+
+ priv->cancellable = g_cancellable_new ();
+
+ g_permission_release_async (priv->permission,
+ priv->cancellable,
+ release_cb,
+ button);
+ }
+
+ out: ;
+}
+
+static void
+on_clicked (GtkButton *_button,
+ gpointer user_data)
+
+{
+ handle_click (UM_LOCK_BUTTON (user_data));
+}
+
+static void
+on_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ handle_click (UM_LOCK_BUTTON (user_data));
+}
+
+/**
+ * um_lock_button_get_permission:
+ * @button: a #UmLockButton
+ *
+ * Obtains the #GPermission object that controls @button.
+ *
+ * Returns: the #GPermission of @button
+ *
+ * Since: 3.0
+ */
+GPermission *
+um_lock_button_get_permission (UmLockButton *button)
+{
+ g_return_val_if_fail (UM_IS_LOCK_BUTTON (button), NULL);
+
+ return button->priv->permission;
+}
+
diff --git a/src/um-lockbutton.h b/src/um-lockbutton.h
new file mode 100644
index 0000000..6becfbc
--- /dev/null
+++ b/src/um-lockbutton.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Author: Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __UM_LOCK_BUTTON_H__
+#define __UM_LOCK_BUTTON_H__
+
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define UM_TYPE_LOCK_BUTTON (um_lock_button_get_type ())
+#define UM_LOCK_BUTTON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UM_TYPE_LOCK_BUTTON, UmLockButton))
+#define UM_LOCK_BUTTON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), UM_LOCK_BUTTON, UmLockButtonClass))
+#define UM_IS_LOCK_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UM_TYPE_LOCK_BUTTON))
+#define UM_IS_LOCK_BUTTON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UM_TYPE_LOCK_BUTTON))
+#define UM_LOCK_BUTTON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UM_TYPE_LOCK_BUTTON, UmLockButtonClass))
+
+typedef struct _UmLockButton UmLockButton;
+typedef struct _UmLockButtonClass UmLockButtonClass;
+typedef struct _UmLockButtonPrivate UmLockButtonPrivate;
+
+struct _UmLockButton
+{
+ GtkBin parent;
+
+ UmLockButtonPrivate *priv;
+};
+
+struct _UmLockButtonClass
+{
+ GtkBinClass parent_class;
+
+ void (*changed) (UmLockButton *button);
+
+ void (*reserved0) (void);
+ void (*reserved1) (void);
+ void (*reserved2) (void);
+ void (*reserved3) (void);
+ void (*reserved4) (void);
+ void (*reserved5) (void);
+ void (*reserved6) (void);
+ void (*reserved7) (void);
+};
+
+GType um_lock_button_get_type (void) G_GNUC_CONST;
+GtkWidget *um_lock_button_new (GPermission *permission);
+GPermission *um_lock_button_get_permission (UmLockButton *button);
+
+
+G_END_DECLS
+
+#endif /* __UM_LOCK_BUTTON_H__ */
diff --git a/src/um-login-options.c b/src/um-login-options.c
index 9fa74ed..99b57ce 100644
--- a/src/um-login-options.c
+++ b/src/um-login-options.c
@@ -32,9 +32,10 @@
#include <gtk/gtk.h>
#include <gconf/gconf-client.h>
#include <gconf/gconf-value.h>
-#include <polkitgtk/polkitgtk.h>
+#include <polkit/polkit.h>
#include "um-login-options.h"
+#include "um-lockbutton.h"
#include "um-user-manager.h"
#include "um-user.h"
@@ -45,6 +46,7 @@ struct _UmLoginOptions {
GtkWidget *hints_check;
GtkWidget *guest_check;
GtkWidget *lock_button;
+ PolkitPermission *permission;
UmUserManager *manager;
@@ -309,13 +311,13 @@ update_autologin (GtkWidget *widget,
}
static void
-lockbutton_changed (PolkitLockButton *button,
- gpointer data)
+lockbutton_changed (UmLockButton *button,
+ gpointer data)
{
UmLoginOptions *d = data;
gboolean authorized;
- authorized = polkit_lock_button_get_is_authorized (button);
+ authorized = g_permission_get_allowed (G_PERMISSION (d->permission));
gtk_widget_set_sensitive (d->autologin_combo, authorized);
gtk_widget_set_sensitive (d->userlist_check, authorized);
@@ -387,13 +389,14 @@ um_login_options_new (GtkBuilder *builder)
g_signal_connect (widget, "toggled",
G_CALLBACK (update_login_options), um);
- widget = polkit_lock_button_new ("org.freedesktop.accounts.set-login-option");
+ um->permission = polkit_permission_new_sync ("org.freedesktop.accounts.set-login-option", NULL, NULL, NULL);
+ widget = um_lock_button_new (um->permission);
gtk_widget_show (widget);
box = (GtkWidget *)gtk_builder_get_object (builder, "lockbutton-alignment");
gtk_container_add (GTK_CONTAINER (box), widget);
g_signal_connect (widget, "changed",
G_CALLBACK (lockbutton_changed), um);
- lockbutton_changed (POLKIT_LOCK_BUTTON (widget), um);
+ lockbutton_changed (UM_LOCK_BUTTON (widget), um);
um->lock_button = widget;
error = NULL;
diff --git a/src/um-user-panel.c b/src/um-user-panel.c
index db43518..8aa922c 100644
--- a/src/um-user-panel.c
+++ b/src/um-user-panel.c
@@ -32,7 +32,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <polkit/polkit.h>
-#include <polkitgtk/polkitgtk.h>
#include <dbus/dbus-glib-bindings.h>
#ifdef HAVE_CHEESE
@@ -48,6 +47,7 @@
#include "um-editable-button.h"
#include "um-editable-entry.h"
#include "um-editable-combo.h"
+#include "um-lockbutton.h"
#include "um-account-dialog.h"
#include "um-language-dialog.h"
@@ -69,6 +69,7 @@ struct _UmUserPanelPrivate {
GtkWidget *notebook;
GtkWidget *lock_button;
+ PolkitPermission *permission;
GtkWidget *language_chooser;
UmAccountDialog *account_dialog;
@@ -545,7 +546,7 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
}
}
-static void lockbutton_changed (PolkitLockButton *button, gpointer data);
+static void lockbutton_changed (UmLockButton *button, gpointer data);
static void
selected_user_changed (GtkTreeSelection *selection, UmUserPanelPrivate *d)
@@ -557,7 +558,7 @@ selected_user_changed (GtkTreeSelection *selection, UmUserPanelPrivate *d)
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
gtk_tree_model_get (model, &iter, USER_COL, &user, -1);
show_user (user, d);
- lockbutton_changed (POLKIT_LOCK_BUTTON (d->lock_button), d);
+ lockbutton_changed (UM_LOCK_BUTTON (d->lock_button), d);
g_object_unref (user);
}
}
@@ -839,10 +840,18 @@ users_loaded (UmUserManager *manager,
static void
add_unlock_tooltip (GtkWidget *button)
{
+ const gchar *names[3];
+ GIcon *icon;
+
+ names[0] = "changes-prevent-symbolic";
+ names[1] = "changes-prevent";
+ names[2] = NULL;
+ icon = g_themed_icon_new_from_names (names, -1);
setup_tooltip_with_embedded_icon (button,
_("To make changes,\nclick the * icon first"),
"*",
- "changes-prevent");
+ icon);
+ g_object_unref (icon);
g_signal_connect (button, "button-release-event",
G_CALLBACK (show_tooltip_now), NULL);
}
@@ -856,8 +865,8 @@ remove_unlock_tooltip (GtkWidget *button)
}
static void
-lockbutton_changed (PolkitLockButton *button,
- gpointer data)
+lockbutton_changed (UmLockButton *button,
+ gpointer data)
{
UmUserPanelPrivate *d = data;
gboolean is_authorized;
@@ -870,7 +879,7 @@ lockbutton_changed (PolkitLockButton *button,
return;
}
- is_authorized = polkit_lock_button_get_is_authorized (button);
+ is_authorized = g_permission_get_allowed (G_PERMISSION (d->permission));
self_selected = um_user_get_uid (user) == geteuid ();
widget = get_widget (d, "add-user-button");
@@ -879,10 +888,18 @@ lockbutton_changed (PolkitLockButton *button,
setup_tooltip_with_embedded_icon (widget, _("Create a user"), NULL, NULL);
}
else {
+ const gchar *names[3];
+ GIcon *icon;
+
+ names[0] = "changes-prevent-symbolic";
+ names[1] = "changes-prevent";
+ names[2] = NULL;
+ icon = g_themed_icon_new_from_names (names, -1);
setup_tooltip_with_embedded_icon (widget,
_("To create a user,\nclick the * icon first"),
"*",
- "changes-prevent");
+ icon);
+ g_object_unref (icon);
}
widget = get_widget (d, "delete-user-button");
@@ -891,10 +908,19 @@ lockbutton_changed (PolkitLockButton *button,
setup_tooltip_with_embedded_icon (widget, _("Delete the selected user"), NULL, NULL);
}
else {
+ const gchar *names[3];
+ GIcon *icon;
+
+ names[0] = "changes-prevent-symbolic";
+ names[1] = "changes-prevent";
+ names[2] = NULL;
+ icon = g_themed_icon_new_from_names (names, -1);
+
setup_tooltip_with_embedded_icon (widget,
_("To delete the selected user,\nclick the * icon first"),
"*",
- "changes-prevent");
+ icon);
+ g_object_unref (icon);
}
if (is_authorized) {
@@ -1030,6 +1056,8 @@ setup_main_window (UmUserPanelPrivate *d)
gint expander_size;
GtkWidget *box;
gchar *title;
+ GIcon *icon;
+ const gchar *names[3];
userlist = get_widget (d, "list-treeview");
store = gtk_list_store_new (NUM_USER_LIST_COLS,
@@ -1124,25 +1152,32 @@ setup_main_window (UmUserPanelPrivate *d)
g_signal_connect (button, "clicked",
G_CALLBACK (change_fingerprint), d);
- button = polkit_lock_button_new ("org.freedesktop.accounts.user-administration");
+ d->permission = polkit_permission_new_sync ("org.freedesktop.accounts.user-administration", NULL, NULL, NULL);
+ button = um_lock_button_new (d->permission);
+ gtk_widget_set_margin_top (button, 12);
gtk_widget_show (button);
box = get_widget (d, "userlist-vbox");
gtk_box_pack_end (GTK_BOX (box), button, FALSE, FALSE, 0);
g_signal_connect (button, "changed",
G_CALLBACK (lockbutton_changed), d);
- lockbutton_changed (POLKIT_LOCK_BUTTON (button), d);
+ lockbutton_changed (UM_LOCK_BUTTON (button), d);
d->lock_button = button;
button = get_widget (d, "add-user-button");
+ names[0] = "changes-prevent-symbolic";
+ names[1] = "changes-prevent";
+ names[2] = NULL;
+ icon = g_themed_icon_new_from_names (names, -1);
setup_tooltip_with_embedded_icon (button,
_("To create a user,\nclick the * icon first"),
"*",
- "changes-prevent");
+ icon);
button = get_widget (d, "delete-user-button");
setup_tooltip_with_embedded_icon (button,
_("To delete the selected user,\nclick the * icon first"),
"*",
- "changes-prevent");
+ icon);
+ g_object_unref (icon);
}
static void
diff --git a/src/um-utils.c b/src/um-utils.c
index 5d638fd..86a8add 100644
--- a/src/um-utils.c
+++ b/src/um-utils.c
@@ -29,7 +29,7 @@
typedef struct {
gchar *text;
gchar *placeholder_str;
- gchar *stock_id;
+ GIcon *icon;
gunichar placeholder;
gulong query_id;
} IconShapeData;
@@ -37,7 +37,7 @@ typedef struct {
static IconShapeData *
icon_shape_data_new (const gchar *text,
const gchar *placeholder,
- const gchar *stock_id)
+ GIcon *icon)
{
IconShapeData *data;
@@ -46,7 +46,7 @@ icon_shape_data_new (const gchar *text,
data->text = g_strdup (text);
data->placeholder_str = g_strdup (placeholder);
data->placeholder = g_utf8_get_char_validated (placeholder, -1);
- data->stock_id = g_strdup (stock_id);
+ data->icon = g_object_ref (icon);
return data;
}
@@ -58,7 +58,7 @@ icon_shape_data_free (gpointer user_data)
g_free (data->text);
g_free (data->placeholder_str);
- g_free (data->stock_id);
+ g_object_unref (data->icon);
g_free (data);
}
@@ -77,15 +77,17 @@ icon_shape_renderer (cairo_t *cr,
gdouble height;
gdouble width;
GdkPixbuf *pixbuf;
+ GtkIconInfo *info;
ascent = pango_units_to_double (attr->ink_rect.y);
height = pango_units_to_double (attr->ink_rect.height);
width = pango_units_to_double (attr->ink_rect.width);
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- data->stock_id,
- (gint)height,
- GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_USE_BUILTIN,
- NULL);
+ info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
+ data->icon,
+ (gint)height,
+ GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_USE_BUILTIN);
+ pixbuf = gtk_icon_info_load_icon (info, NULL);
+ gtk_icon_info_free (info);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_reset_clip (cr);
@@ -182,7 +184,7 @@ void
setup_tooltip_with_embedded_icon (GtkWidget *widget,
const gchar *text,
const gchar *placeholder,
- const gchar *stock_id)
+ GIcon *icon)
{
IconShapeData *data;
@@ -199,7 +201,7 @@ setup_tooltip_with_embedded_icon (GtkWidget *widget,
return;
}
- data = icon_shape_data_new (text, placeholder, stock_id);
+ data = icon_shape_data_new (text, placeholder, icon);
g_object_set_data_full (G_OBJECT (widget),
"icon-shape-data",
data,
diff --git a/src/um-utils.h b/src/um-utils.h
index c3b8a66..d6a227e 100644
--- a/src/um-utils.h
+++ b/src/um-utils.h
@@ -29,7 +29,7 @@ G_BEGIN_DECLS
void setup_tooltip_with_embedded_icon (GtkWidget *widget,
const gchar *text,
const gchar *placeholder,
- const gchar *stock_id);
+ GIcon *icon);
gboolean show_tooltip_now (GtkWidget *widget,
GdkEvent *event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]