Exemplo n.º 1
0
static void
get_permissions_cb (BMSettingsSystemInterface *settings,
                    BMSettingsSystemPermissions permissions,
                    GError *error,
                    gpointer user_data)
{
	PermInfo *info = user_data;
	CEPolkitButton *self = info->self;
	CEPolkitButtonPrivate *priv;
	gboolean old_actionable, old_authorized;

	/* Response might come when button is already disposed */
	if (info->disposed)
		goto out;

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (info->self);

	priv->perm_calls = g_slist_remove (priv->perm_calls, info);

	old_actionable = ce_polkit_button_get_actionable (self);
	old_authorized = priv->authorized;

	priv->authorized = (permissions & priv->permission);
	if (priv->use_polkit)
		update_and_emit (self, old_actionable);

	if (priv->authorized != old_authorized)
		g_signal_emit (self, signals[AUTHORIZED], 0, priv->authorized);

out:
	g_free (info);
}
Exemplo n.º 2
0
static void
dispose (GObject *object)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (object);
	GSList *iter;

	if (priv->disposed) {
		g_warning ("%s: CEPolkitButton object %p disposed twice", __func__, object);
		G_OBJECT_CLASS (ce_polkit_button_parent_class)->dispose (object);
		return;
	}

	priv->disposed = TRUE;

	/* Mark any ongoing permissions calls as disposed */
	for (iter = priv->perm_calls; iter; iter = g_slist_next (iter))
		((PermInfo *) iter->data)->disposed = TRUE;

	if (priv->check_id)
		g_signal_handler_disconnect (priv->settings, priv->check_id);

	g_object_unref (priv->settings);
	g_object_unref (priv->auth);
	g_object_unref (priv->stock);

	G_OBJECT_CLASS (ce_polkit_button_parent_class)->dispose (object);
}
Exemplo n.º 3
0
gboolean
ce_polkit_button_get_authorized (CEPolkitButton *self)
{
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (CE_IS_POLKIT_BUTTON (self), FALSE);

	return CE_POLKIT_BUTTON_GET_PRIVATE (self)->authorized;
}
Exemplo n.º 4
0
static void
finalize (GObject *object)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (object);

	g_free (priv->tooltip);
	g_free (priv->auth_tooltip);

	G_OBJECT_CLASS (ce_polkit_button_parent_class)->finalize (object);
}
Exemplo n.º 5
0
void
ce_polkit_button_set_use_polkit (CEPolkitButton *self, gboolean use_polkit)
{
	gboolean old_actionable;

	g_return_if_fail (self != NULL);
	g_return_if_fail (CE_IS_POLKIT_BUTTON (self));

	old_actionable = ce_polkit_button_get_actionable (self);
	CE_POLKIT_BUTTON_GET_PRIVATE (self)->use_polkit = use_polkit;
	update_and_emit (self, old_actionable);
}
Exemplo n.º 6
0
gboolean
ce_polkit_button_get_actionable (CEPolkitButton *self)
{
	CEPolkitButtonPrivate *priv;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (CE_IS_POLKIT_BUTTON (self), FALSE);

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);

	return priv->master_sensitive && priv->authorized;
}
Exemplo n.º 7
0
void
ce_polkit_button_set_master_sensitive (CEPolkitButton *self, gboolean sensitive)
{
	gboolean old_actionable;

	g_return_if_fail (self != NULL);
	g_return_if_fail (CE_IS_POLKIT_BUTTON (self));

	old_actionable = ce_polkit_button_get_actionable (self);
	CE_POLKIT_BUTTON_GET_PRIVATE (self)->master_sensitive = sensitive;
	update_and_emit (self, old_actionable);
}
gboolean
ce_polkit_button_get_authorized (CEPolkitButton *self)
{
	CEPolkitButtonPrivate *priv;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (CE_IS_POLKIT_BUTTON (self), FALSE);

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);

	return    priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES
	       || priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH;
}
gboolean
ce_polkit_button_get_actionable (CEPolkitButton *self)
{
	CEPolkitButtonPrivate *priv;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (CE_IS_POLKIT_BUTTON (self), FALSE);

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);

	return    !priv->validation_error
	       && ce_polkit_button_get_authorized (self);
}
Exemplo n.º 10
0
static void
update_button (CEPolkitButton *self, gboolean actionable)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);

	gtk_widget_set_sensitive (GTK_WIDGET (self), actionable);

	if (priv->authorized) {
		gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->auth_tooltip);
		gtk_button_set_image (GTK_BUTTON (self), priv->auth);
	} else {
		gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->tooltip);
		gtk_button_set_image (GTK_BUTTON (self), priv->stock);
	}
}
Exemplo n.º 11
0
static void
dispose (GObject *object)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (object);

	if (priv->perm_id) {
		g_signal_handler_disconnect (priv->client, priv->perm_id);
		priv->perm_id = 0;
	}

	g_clear_object (&priv->client);
	g_clear_object (&priv->auth);
	g_clear_object (&priv->stock);

	G_OBJECT_CLASS (ce_polkit_button_parent_class)->dispose (object);
}
Exemplo n.º 12
0
static void
check_permissions_cb (BMRemoteSettingsSystem *settings, CEPolkitButton *self)
{
	PermInfo *info;
	CEPolkitButtonPrivate *priv;

	info = g_malloc0 (sizeof (PermInfo));
	info->self = self;

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (info->self);
	priv->perm_calls = g_slist_append (priv->perm_calls, info);

	/* recheck permissions */
	bm_settings_system_interface_get_permissions (BM_SETTINGS_SYSTEM_INTERFACE (settings),
	                                              get_permissions_cb,
	                                              info);
}
static void
permission_changed_cb (NMClient *client,
                       NMClientPermission permission,
                       NMClientPermissionResult result,
                       CEPolkitButton *self)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
	gboolean old_actionable;

	if (priv->permission_result == result)
		return;

	old_actionable = ce_polkit_button_get_actionable (self);
	priv->permission_result = result;
	update_and_emit (self, old_actionable);

	g_signal_emit (self, signals[AUTHORIZED], 0, ce_polkit_button_get_authorized (self));
}
Exemplo n.º 14
0
static void
permission_changed_cb (NMClient *client,
                       NMClientPermission permission,
                       NMClientPermissionResult result,
                       CEPolkitButton *self)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
	gboolean old_actionable, old_authorized;

	old_actionable = ce_polkit_button_get_actionable (self);
	old_authorized = priv->authorized;

	priv->authorized = (result == NM_CLIENT_PERMISSION_RESULT_YES || result == NM_CLIENT_PERMISSION_RESULT_AUTH);
	update_and_emit (self, old_actionable);

	if (priv->authorized != old_authorized)
		g_signal_emit (self, signals[AUTHORIZED], 0, priv->authorized);
}
Exemplo n.º 15
0
gboolean
ce_polkit_button_get_actionable (CEPolkitButton *self)
{
	CEPolkitButtonPrivate *priv;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (CE_IS_POLKIT_BUTTON (self), FALSE);

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);

	if (!priv->master_sensitive)
		return FALSE;

	/* If polkit is in-use, the button is only actionable if the operation is
	 * authorized or able to be authorized via user authentication.  If polkit
	 * isn't in-use, the button will always be actionable unless insensitive.
	 */
	return priv->use_polkit ? priv->authorized : TRUE;
}
Exemplo n.º 16
0
GtkWidget *
ce_polkit_button_new (const char *label,
                      const char *tooltip,
                      const char *auth_label,
                      const char *auth_tooltip,
                      const char *stock_icon,
                      BMRemoteSettingsSystem *settings,
                      BMSettingsSystemPermissions permission)
{
	GObject *object;
	CEPolkitButtonPrivate *priv;

	object = g_object_new (CE_TYPE_POLKIT_BUTTON, NULL);
	if (!object)
		return NULL;

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (object);

	priv->label = g_strdup (label);
	priv->tooltip = g_strdup (tooltip);
	priv->auth_label = g_strdup (auth_label);
	priv->auth_tooltip = g_strdup (auth_tooltip);
	priv->permission = permission;
	priv->use_polkit = FALSE;

	priv->settings = g_object_ref (settings);
	priv->check_id = g_signal_connect (settings,
	                                   BM_SETTINGS_SYSTEM_INTERFACE_CHECK_PERMISSIONS,
	                                   G_CALLBACK (check_permissions_cb),
	                                   object);

	priv->stock = gtk_image_new_from_stock (stock_icon, GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (priv->stock);
	priv->auth = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (priv->auth);

	update_button (CE_POLKIT_BUTTON (object),
	               ce_polkit_button_get_actionable (CE_POLKIT_BUTTON (object)));

	check_permissions_cb (settings, CE_POLKIT_BUTTON (object));

	return GTK_WIDGET (object);
}
Exemplo n.º 17
0
GtkWidget *
ce_polkit_button_new (const char *label,
                      const char *tooltip,
                      const char *auth_tooltip,
                      const char *stock_icon,
                      NMClient *client,
                      NMClientPermission permission)
{
	GObject *object;
	CEPolkitButtonPrivate *priv;

	object = g_object_new (CE_TYPE_POLKIT_BUTTON, NULL);
	if (!object)
		return NULL;

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (object);

	priv->tooltip = g_strdup (tooltip);
	priv->auth_tooltip = g_strdup (auth_tooltip);
	priv->permission = permission;

	priv->client = g_object_ref (client);
	priv->perm_id = g_signal_connect (client,
	                                  "permission-changed",
	                                  G_CALLBACK (permission_changed_cb),
	                                  object);

	priv->stock = gtk_image_new_from_stock (stock_icon, GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (priv->stock);
	priv->auth = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (priv->auth);

	gtk_button_set_label (GTK_BUTTON (object), label);
	update_button (CE_POLKIT_BUTTON (object),
	               ce_polkit_button_get_actionable (CE_POLKIT_BUTTON (object)));

	permission_changed_cb (client,
	                       permission,
	                       nm_client_get_permission_result (client, permission),
	                       CE_POLKIT_BUTTON (object));

	return GTK_WIDGET (object);
}
Exemplo n.º 18
0
static void
get_permissions_cb (NMSettingsSystemInterface *settings,
                    NMSettingsSystemPermissions permissions,
                    GError *error,
                    gpointer user_data)
{
	CEPolkitButton *self = CE_POLKIT_BUTTON (user_data);
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
	gboolean old_actionable, old_authorized;

	old_actionable = ce_polkit_button_get_actionable (self);
	old_authorized = priv->authorized;

	priv->authorized = (permissions & priv->permission);
	if (priv->use_polkit)
		update_and_emit (self, old_actionable);

	if (priv->authorized != old_authorized)
		g_signal_emit (self, signals[AUTHORIZED], 0, priv->authorized);
}
void
ce_polkit_button_set_validation_error (CEPolkitButton *self, const char *validation_error)
{
	CEPolkitButtonPrivate *priv;
	gboolean old_actionable;

	g_return_if_fail (self != NULL);
	g_return_if_fail (CE_IS_POLKIT_BUTTON (self));

	priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);

	if (g_strcmp0 (validation_error, priv->validation_error) != 0) {
		old_actionable = ce_polkit_button_get_actionable (self);

		g_free (priv->validation_error);
		priv->validation_error = g_strdup (validation_error);

		update_and_emit (self, old_actionable);
	}
}
Exemplo n.º 20
0
static void
dispose (GObject *object)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (object);

	if (priv->disposed) {
		g_warning ("%s: CEPolkitButton object %p disposed twice", __func__, object);
		G_OBJECT_CLASS (ce_polkit_button_parent_class)->dispose (object);
		return;
	}

	priv->disposed = TRUE;

	if (priv->check_id)
		g_signal_handler_disconnect (priv->settings, priv->check_id);

	g_object_unref (priv->settings);
	g_object_unref (priv->auth);
	g_object_unref (priv->stock);

	G_OBJECT_CLASS (ce_polkit_button_parent_class)->dispose (object);
}
static void
update_button (CEPolkitButton *self)
{
	CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
	gboolean actionable;

	actionable = ce_polkit_button_get_actionable (self);

	gtk_widget_set_sensitive (GTK_WIDGET (self), actionable);

	if (priv->validation_error)
		gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->validation_error);
	else if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH)
		gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->auth_tooltip);
	else if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES)
		gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->tooltip);
	else
		gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("No polkit authorization to perform the action"));

	if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES)
		gtk_button_set_image (GTK_BUTTON (self), priv->stock);
	else
		gtk_button_set_image (GTK_BUTTON (self), priv->auth);
}