diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2017-06-26 16:42:01 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-07-11 17:51:04 +0200 |
commit | 3f198516c39e8f11183d844fcd429e5d63a165ff (patch) | |
tree | 1b36b246397b486bfb309a847b0e8493bb5199c0 | |
parent | a1f4d4d6aee37bc68884d856428d65b4e9832c5a (diff) | |
download | network-manager-applet-3f198516c39e8f11183d844fcd429e5d63a165ff.tar.gz |
editor: allow registering any widget with polkit
CePolkitButton only works for GtkButtons. We'd like to use this for
GtkToolButtons too.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/connection-editor/ce-polkit.c | 117 | ||||
-rw-r--r-- | src/connection-editor/ce-polkit.h | 39 |
4 files changed, 159 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index af338167..58c536f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -672,6 +672,8 @@ connection_editor_hc_real = \ src/connection-editor/ppp-auth-methods-dialog.h \ src/connection-editor/ce-polkit-button.c \ src/connection-editor/ce-polkit-button.h \ + src/connection-editor/ce-polkit.c \ + src/connection-editor/ce-polkit.h \ src/connection-editor/connection-helpers.c \ src/connection-editor/connection-helpers.h diff --git a/po/POTFILES.in b/po/POTFILES.in index eb1dae0c..989dafc1 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -41,6 +41,7 @@ src/connection-editor/ce-page.h [type: gettext/glade]src/connection-editor/ce-page-vlan.ui [type: gettext/glade]src/connection-editor/ce-page-wifi-security.ui [type: gettext/glade]src/connection-editor/ce-page-wifi.ui +src/connection-editor/ce-polkit.c src/connection-editor/ce-polkit-button.c [type: gettext/glade]src/connection-editor/ce-ppp-auth-methods.ui src/connection-editor/connection-helpers.c diff --git a/src/connection-editor/ce-polkit.c b/src/connection-editor/ce-polkit.c new file mode 100644 index 00000000..c59a9f5c --- /dev/null +++ b/src/connection-editor/ce-polkit.c @@ -0,0 +1,117 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager Connection editor -- Connection editor for NetworkManager + * + * Dan Williams <dcbw@redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2009 - 2017 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include <string.h> + +#include "ce-polkit.h" + +typedef struct { + char *tooltip; + char *auth_tooltip; + char *validation_error; + + NMClientPermission permission; + NMClientPermissionResult permission_result; +} CePolkitData; + +static void +ce_polkit_data_free (CePolkitData *data) +{ + g_free (data->tooltip); + g_free (data->auth_tooltip); + g_free (data->validation_error); + g_slice_free (CePolkitData, data); +} + +static void +update_widget (GtkWidget *widget) +{ + CePolkitData *data = g_object_get_data (G_OBJECT (widget), "ce-polkit-data"); + + if (data->validation_error) { + gtk_widget_set_sensitive (widget, FALSE); + gtk_widget_set_tooltip_text (widget, data->validation_error); + } else if (data->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH) { + gtk_widget_set_sensitive (widget, TRUE); + gtk_widget_set_tooltip_text (widget, data->auth_tooltip); + } else if (data->permission_result == NM_CLIENT_PERMISSION_RESULT_YES) { + gtk_widget_set_sensitive (widget, TRUE); + gtk_widget_set_tooltip_text (widget, data->tooltip); + } else { + gtk_widget_set_sensitive (widget, FALSE); + gtk_widget_set_tooltip_text (widget, _("No polkit authorization to perform the action")); + } +} + +static void +permission_changed_cb (NMClient *client, + NMClientPermission permission, + NMClientPermissionResult result, + GtkWidget *widget) +{ + CePolkitData *data = g_object_get_data (G_OBJECT (widget), "ce-polkit-data"); + + data->permission_result = result; + update_widget (widget); +} + +void ce_polkit_set_widget_validation_error (GtkWidget *widget, + const char *validation_error) +{ + CePolkitData *data = g_object_get_data (G_OBJECT (widget), "ce-polkit-data"); + + g_free (data->validation_error); + data->validation_error = g_strdup (validation_error); + update_widget (widget); +} + +void +ce_polkit_connect_widget (GtkWidget *widget, + const char *tooltip, + const char *auth_tooltip, + NMClient *client, + NMClientPermission permission) +{ + CePolkitData *data; + + data = g_slice_new0 (CePolkitData); + data->tooltip = g_strdup (tooltip); + data->auth_tooltip = g_strdup (auth_tooltip); + data->permission = permission; + g_object_set_data_full (G_OBJECT (widget), + "ce-polkit-data", + data, + (GDestroyNotify) ce_polkit_data_free); + + g_signal_connect_object (client, + "permission-changed", + G_CALLBACK (permission_changed_cb), + G_OBJECT (widget), + 0); + + permission_changed_cb (client, + permission, + nm_client_get_permission_result (client, permission), + widget); +} diff --git a/src/connection-editor/ce-polkit.h b/src/connection-editor/ce-polkit.h new file mode 100644 index 00000000..ec260c77 --- /dev/null +++ b/src/connection-editor/ce-polkit.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager Connection editor -- Connection editor for NetworkManager + * + * Dan Williams <dcbw@redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2009 - 2017 Red Hat, Inc. + */ + +#ifndef __CE_POLKIT_H__ +#define __CE_POLKIT_H__ + +#include <gtk/gtk.h> + +#include <NetworkManager.h> + +void ce_polkit_connect_widget (GtkWidget *widget, + const char *tooltip, + const char *auth_tooltip, + NMClient *client, + NMClientPermission permission); + +void ce_polkit_set_widget_validation_error (GtkWidget *widget, + const char *validation_error); + +#endif /* __CE_POLKIT_H__ */ |