static void
on_permission_changed (GPermission *permission,
                       GParamSpec  *pspec,
                       gpointer     data)
{
  CcDateTimePanelPrivate *priv = CC_DATE_TIME_PANEL (data)->priv;
  gboolean allowed, auto_timezone, using_ntp;

  allowed = (priv->permission != NULL && g_permission_get_allowed (priv->permission));
  using_ntp = gtk_switch_get_active (GTK_SWITCH (W("network_time_switch")));
  auto_timezone = gtk_switch_get_active (GTK_SWITCH (W("auto_timezone_switch")));

  /* All the widgets but the lock button and the 24h setting */
  gtk_widget_set_sensitive (W("auto-datetime-row"), allowed);
  gtk_widget_set_sensitive (W("auto-timezone-row"), allowed);
  gtk_widget_set_sensitive (W("datetime-button"), allowed && !using_ntp);
  gtk_widget_set_sensitive (W("timezone-button"), allowed && !auto_timezone);

  /* Hide the subdialogs if we no longer have permissions */
  if (!allowed)
    {
      gtk_widget_hide (GTK_WIDGET (W ("datetime-dialog")));
      gtk_widget_hide (GTK_WIDGET (W ("timezone-dialog")));
    }
}
static void
reload_proxy_settings (GsPlugin *plugin, GCancellable *cancellable)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	g_autofree gchar *proxy_http = NULL;
	g_autofree gchar *proxy_ftp = NULL;
	g_autoptr(GPermission) permission = NULL;

	/* only if we can achieve the action *without* an auth dialog */
	permission = gs_utils_get_permission ("org.freedesktop.packagekit."
					      "system-network-proxy-configure");
	if (permission == NULL) {
		g_debug ("not setting proxy as no permission");
		return;
	}
	if (!g_permission_get_allowed (permission)) {
		g_debug ("not setting proxy as no auth requested");
		return;
	}

	proxy_http = get_proxy_http (plugin);
	proxy_ftp = get_proxy_ftp (plugin);

	g_debug ("Setting proxies (http: %s, ftp: %s)", proxy_http, proxy_ftp);

	pk_control_set_proxy_async (priv->control,
				    proxy_http,
				    proxy_ftp,
				    cancellable,
				    set_proxy_cb,
				    plugin);
}
static void
gs_plugin_systemd_updates_permission_cb (GPermission *permission,
					 GParamSpec *pspec,
					 gpointer data)
{
	GsPlugin *plugin = GS_PLUGIN (data);
	gboolean ret = g_permission_get_allowed (permission) ||
			g_permission_get_can_acquire (permission);
	gs_plugin_set_allow_updates (plugin, ret);
}
static void
language_changed (CcLanguageChooser  *chooser,
                  GParamSpec         *pspec,
                  GisLanguagePage    *page)
{
  GisLanguagePagePrivate *priv = gis_language_page_get_instance_private (page);
  ActUser *user;
  GisDriver *driver;

  if (priv->selection_done_source > 0)
    {
      g_source_remove (priv->selection_done_source);
      priv->selection_done_source = 0;
    }

  priv->new_locale_id = cc_language_chooser_get_language (chooser);
  driver = GIS_PAGE (page)->driver;

  setlocale (LC_MESSAGES, priv->new_locale_id);
  gis_driver_locale_changed (driver);

  if (gis_driver_get_mode (driver) == GIS_DRIVER_MODE_NEW_USER) {
      if (g_permission_get_allowed (priv->permission)) {
          set_localed_locale (page);
      }
      else if (g_permission_get_can_acquire (priv->permission)) {
          g_permission_acquire_async (priv->permission,
                                      NULL,
                                      change_locale_permission_acquired,
                                      page);
      }
  }
  user = act_user_manager_get_user (act_user_manager_get_default (),
                                    g_get_user_name ());
  if (act_user_is_loaded (user))
    act_user_set_language (user, priv->new_locale_id);
  else
    g_signal_connect (user,
                      "notify::is-loaded",
                      G_CALLBACK (user_loaded),
                      g_strdup (priv->new_locale_id));

  gis_driver_set_user_language (driver, priv->new_locale_id);

  priv->selection_done_source = g_timeout_add (500, _selection_done,
                                               (gpointer)driver);
}
static void
on_permission_changed (GPermission *permission,
                       GParamSpec  *pspec,
                       gpointer     data)
{
  CcDateTimePanelPrivate *priv = CC_DATE_TIME_PANEL (data)->priv;
  gboolean allowed, using_ntp;

  allowed = g_permission_get_allowed (permission);
  using_ntp = gtk_switch_get_active (GTK_SWITCH (W("network_time_switch")));

  /* All the widgets but the lock button and the 24h setting */
  gtk_widget_set_sensitive (W("map-vbox"), allowed);
  gtk_widget_set_sensitive (W("hbox2"), allowed);
  gtk_widget_set_sensitive (W("alignment2"), allowed);
  gtk_widget_set_sensitive (W("table1"), allowed && !using_ntp);
}
static gboolean
switch_to_row_transform_func (GBinding        *binding,
                              const GValue    *source_value,
                              GValue          *target_value,
                              CcDateTimePanel *self)
{
  CcDateTimePanelPrivate *priv = self->priv;
  gboolean active;
  gboolean allowed;

  active = g_value_get_boolean (source_value);
  allowed = (priv->permission != NULL && g_permission_get_allowed (priv->permission));

  g_value_set_boolean (target_value, !active && allowed);

  return TRUE;
}
static void
on_permission_changed (GPermission *permission,
                       GParamSpec  *pspec,
                       GtkBuilder  *dialog)
{
        GtkWidget *button;
        GtkWidget *label;
        gboolean can_acquire;
        gboolean allowed;

        if (permission) {
                can_acquire = g_permission_get_can_acquire (permission);
                allowed = g_permission_get_allowed (permission);
        }
        else {
                can_acquire = FALSE;
                allowed = FALSE;
        }

        button = WID ("copy_settings_button");
        label = WID ("system-title");

        if (!allowed && !can_acquire) {
                gtk_label_set_text (GTK_LABEL (label),
                                    _("The login screen, system accounts and new user accounts use the system-wide Region and Language settings."));
                gtk_widget_hide (button);
        }
        else {
                gtk_label_set_text (GTK_LABEL (label),
                                    _("The login screen, system accounts and new user accounts use the system-wide Region and Language settings. You may change the system settings to match yours."));
                gtk_widget_show (button);
                if (allowed) {
                        gtk_button_set_label (GTK_BUTTON (button), _("Copy Settings"));
                }
                else {
                        gtk_button_set_label (GTK_BUTTON (button), _("Copy Settings..."));
                }
        }
}
static void
system_poweroff (gpointer data)
{
  GDBusConnection *bus;
  GError *error = NULL;
  GPermission *permission;

  permission = polkit_permission_new_sync ("org.freedesktop.login1.power-off", NULL, NULL, &error);
  if (error) {
    g_warning ("Failed getting permission to power off: %s", error->message);
    g_error_free (error);
    return;
  }

  if (!g_permission_get_allowed (permission)) {
    g_warning ("Not allowed to power off");
    g_object_unref (permission);
    return;
  }

  g_object_unref (permission);

  bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
  if (error) {
    g_warning ("Failed to get system bus: %s", error->message);
    g_error_free (error);
    return;
  }

  g_dbus_connection_call (bus,
                          "org.freedesktop.login1",
                          "/org/freedesktop/login1",
                          "org.freedesktop.login1.Manager",
                          "PowerOff",
                          g_variant_new ("(b)", FALSE),
                          NULL, 0, G_MAXINT, NULL, NULL, NULL);

  g_object_unref (bus);
}
static void
on_permission_changed (GPermission *permission,
                       GParamSpec  *pspec,
                       gpointer     data)
{
    UmUserPanelPrivate *d = data;
    gboolean is_authorized;
    gboolean self_selected;
    UmUser *user;
    GtkWidget *widget;

    user = get_selected_user (d);
    if (!user) {
        return;
    }

    is_authorized = g_permission_get_allowed (G_PERMISSION (d->permission));
    self_selected = um_user_get_uid (user) == geteuid ();

    widget = get_widget (d, "add-user-toolbutton");
    gtk_widget_set_sensitive (widget, is_authorized);
    if (is_authorized) {
        setup_tooltip_with_embedded_icon (widget, _("Create a user account"), NULL, NULL);
    }
    else {
        gchar *names[3];
        GIcon *icon;

        names[0] = "changes-allow-symbolic";
        names[1] = "changes-allow";
        names[2] = NULL;
        icon = (GIcon *)g_themed_icon_new_from_names (names, -1);
        setup_tooltip_with_embedded_icon (widget,
                                          _("To create a user account,\nclick the * icon first"),
                                          "*",
                                          icon);
        g_object_unref (icon);
    }

    widget = get_widget (d, "remove-user-toolbutton");
    gtk_widget_set_sensitive (widget, is_authorized && !self_selected);
    if (is_authorized) {
        setup_tooltip_with_embedded_icon (widget, _("Delete the selected user account"), NULL, NULL);
    }
    else {
        gchar *names[3];
        GIcon *icon;

        names[0] = "changes-allow-symbolic";
        names[1] = "changes-allow";
        names[2] = NULL;
        icon = (GIcon *)g_themed_icon_new_from_names (names, -1);

        setup_tooltip_with_embedded_icon (widget,
                                          _("To delete the selected user account,\nclick the * icon first"),
                                          "*",
                                          icon);
        g_object_unref (icon);
    }

    if (!um_user_is_local_account (user)) {
        um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-type-combo")), FALSE);
        remove_unlock_tooltip (get_widget (d, "account-type-combo"));

    } else if (is_authorized && um_user_is_local_account (user)) {
        um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-type-combo")), TRUE);
        remove_unlock_tooltip (get_widget (d, "account-type-combo"));
    }
    else {
        um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-type-combo")), FALSE);
        add_unlock_tooltip (get_widget (d, "account-type-combo"));
    }

    /* The full name entry: insensitive if remote or not authorized and not self */
    widget = get_widget (d, "full-name-entry");
    if (!um_user_is_local_account (user)) {
        cc_editable_entry_set_editable (CC_EDITABLE_ENTRY (widget), FALSE);
        remove_unlock_tooltip (widget);

    } else if (is_authorized || self_selected) {
        cc_editable_entry_set_editable (CC_EDITABLE_ENTRY (widget), TRUE);
        remove_unlock_tooltip (widget);

    } else {
        cc_editable_entry_set_editable (CC_EDITABLE_ENTRY (widget), FALSE);
        add_unlock_tooltip (widget);
    }

    if (is_authorized || self_selected) {
        gtk_widget_show (get_widget (d, "user-icon-button"));
        gtk_widget_hide (get_widget (d, "user-icon-nonbutton"));

        um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-language-combo")), TRUE);
        remove_unlock_tooltip (get_widget (d, "account-language-combo"));

        um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-password-button")), TRUE);
        remove_unlock_tooltip (get_widget (d, "account-password-button"));

        gtk_notebook_set_current_page (GTK_NOTEBOOK (get_widget (d, "account-fingerprint-notebook")), 1);
    }
    else {
        gtk_widget_hide (get_widget (d, "user-icon-button"));
        gtk_widget_show (get_widget (d, "user-icon-nonbutton"));

        um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-language-combo")), FALSE);
        add_unlock_tooltip (get_widget (d, "account-language-combo"));

        um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-password-button")), FALSE);
        add_unlock_tooltip (get_widget (d, "account-password-button"));

        gtk_notebook_set_current_page (GTK_NOTEBOOK (get_widget (d, "account-fingerprint-notebook")), 0);
    }

    um_password_dialog_set_privileged (d->password_dialog, is_authorized);

    g_object_unref (user);
}