diff options
author | Thomas Haller <thaller@redhat.com> | 2016-12-16 15:04:56 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-12-16 15:04:56 +0100 |
commit | 56033f802d7bfdb91d3c0f60e5973979228f159e (patch) | |
tree | bfa4c49d70ea02b41de8697ba2c70f052f9c57b4 | |
parent | 5018f91499f0bae365c9b69f5be5435e46a92627 (diff) | |
parent | 90b9f92d42a491521d463925543ba4c8b0d94066 (diff) | |
download | network-manager-applet-56033f802d7bfdb91d3c0f60e5973979228f159e.tar.gz |
proxy: merge branch 'th/proxy-bgo621767'
https://bugzilla.gnome.org/show_bug.cgi?id=621767
-rw-r--r-- | shared/Makefile.am | 1 | ||||
-rw-r--r-- | shared/nm-default.h | 2 | ||||
-rw-r--r-- | shared/nm-libnm-compat.h | 41 | ||||
-rw-r--r-- | src/connection-editor/Makefile.am | 3 | ||||
-rw-r--r-- | src/connection-editor/ce-page-proxy.ui | 174 | ||||
-rw-r--r-- | src/connection-editor/connection-helpers.c | 15 | ||||
-rw-r--r-- | src/connection-editor/connection-helpers.h | 1 | ||||
-rw-r--r-- | src/connection-editor/nm-connection-editor.c | 8 | ||||
-rw-r--r-- | src/connection-editor/nm-connection-list.c | 6 | ||||
-rw-r--r-- | src/connection-editor/page-proxy.c | 321 | ||||
-rw-r--r-- | src/connection-editor/page-proxy.h | 54 |
11 files changed, 626 insertions, 0 deletions
diff --git a/shared/Makefile.am b/shared/Makefile.am index 6cc2ad80..2e45201f 100644 --- a/shared/Makefile.am +++ b/shared/Makefile.am @@ -7,4 +7,5 @@ EXTRA_DIST = \ nm-utils/nm-test-utils.h \ nm-utils/nm-vpn-editor-plugin-call.h \ nm-default.h \ + nm-libnm-compat.h \ $(NULL) diff --git a/shared/nm-default.h b/shared/nm-default.h index 5b3a8d3c..56c03dcb 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -75,6 +75,8 @@ #include <NetworkManager.h> #endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ +#include "nm-libnm-compat.h" + /*****************************************************************************/ #endif /* __NM_DEFAULT_H__ */ diff --git a/shared/nm-libnm-compat.h b/shared/nm-libnm-compat.h new file mode 100644 index 00000000..dd6b48c6 --- /dev/null +++ b/shared/nm-libnm-compat.h @@ -0,0 +1,41 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * (C) Copyright 2016 Red Hat, Inc. + */ + +#ifndef __NM_LIBNM_COMPAT_H__ +#define __NM_LIBNM_COMPAT_H__ + +#define NM_LIBNM_COMPAT_UNDEPRECATE(cmd) \ + ({ \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + (cmd); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ + }) + +#define NM_LIBNM_COMPAT_PROXY_SUPPORTED (NM_CHECK_VERSION (1, 5, 0)) + +#define nm_setting_proxy_new(setting) NM_LIBNM_COMPAT_UNDEPRECATE (nm_setting_proxy_new (setting)) +#define nm_setting_proxy_get_method(setting) NM_LIBNM_COMPAT_UNDEPRECATE (nm_setting_proxy_get_method (setting)) +#define nm_setting_proxy_get_pac_url(setting) NM_LIBNM_COMPAT_UNDEPRECATE (nm_setting_proxy_get_pac_url (setting)) +#define nm_setting_proxy_get_pac_script(setting) NM_LIBNM_COMPAT_UNDEPRECATE (nm_setting_proxy_get_pac_script (setting)) +#define nm_setting_proxy_get_browser_only(setting) NM_LIBNM_COMPAT_UNDEPRECATE (nm_setting_proxy_get_browser_only (setting)) +#define nm_connection_get_setting_proxy(connection) NM_LIBNM_COMPAT_UNDEPRECATE (nm_connection_get_setting_proxy (connection)) + +#endif /* __NM_LIBNM_COMPAT_H__ */ diff --git a/src/connection-editor/Makefile.am b/src/connection-editor/Makefile.am index 69b012f1..091c1dc3 100644 --- a/src/connection-editor/Makefile.am +++ b/src/connection-editor/Makefile.am @@ -52,6 +52,8 @@ nm_connection_editor_SOURCES = \ page-bluetooth.c \ page-ppp.h \ page-ppp.c \ + page-proxy.h \ + page-proxy.c \ page-vpn.h \ page-vpn.c \ page-master.h \ @@ -106,6 +108,7 @@ ui_DATA = \ ce-page-team-port.ui \ ce-page-bridge.ui \ ce-page-bridge-port.ui \ + ce-page-proxy.ui \ ce-page-ip4.ui \ ce-ip4-routes.ui \ ce-page-ip6.ui \ diff --git a/src/connection-editor/ce-page-proxy.ui b/src/connection-editor/ce-page-proxy.ui new file mode 100644 index 00000000..02e2a957 --- /dev/null +++ b/src/connection-editor/ce-page-proxy.ui @@ -0,0 +1,174 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.19.0 --> +<interface> + <requires lib="gtk+" version="3.4"/> + <object class="GtkBox" id="ProxyPage"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="border_width">12</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> + <child> + <object class="GtkBox" id="box1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">12</property> + <child> + <object class="GtkLabel" id="proxy_method_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Method: </property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="proxy_method"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="active_id">0</property> + <items> + <item id="0" translatable="yes">None</item> + <item id="1" translatable="yes">Automatic</item> + </items> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="proxy_browser_only_checkbutton"> + <property name="label" translatable="yes">For Browser Only</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="tooltip_text" translatable="yes">Use this Proxy Configuration for Only Browser Clients/schemes.</property> + <property name="halign">start</property> + <property name="xalign">0.5</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">10</property> + <child> + <object class="GtkLabel" id="proxy_pac_url_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">PAC URL: </property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="proxy_pac_url_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="tooltip_text" translatable="yes">URL from where PAC Script is to be obtained.</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">4</property> + <child> + <object class="GtkLabel" id="proxy_pac_script_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">PAC Script: </property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="proxy_pac_script_import_button"> + <property name="label" translatable="yes">Import script from a file...</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="vexpand">True</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="shadow_type">in</property> + <property name="min_content_height">100</property> + <child> + <object class="GtkTextView" id="proxy_pac_script_window"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">4</property> + </packing> + </child> + </object> +</interface> diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c index be9dd22f..4ad014a9 100644 --- a/src/connection-editor/connection-helpers.c +++ b/src/connection-editor/connection-helpers.c @@ -789,6 +789,21 @@ delete_connection (GtkWindow *parent_window, } gboolean +connection_supports_proxy (NMConnection *connection) +{ + NMSettingConnection *s_con; + + g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); + +#if NM_LIBNM_COMPAT_PROXY_SUPPORTED + s_con = nm_connection_get_setting_connection (connection); + return (nm_setting_connection_get_slave_type (s_con) == NULL); +#else + return FALSE; +#endif +} + +gboolean connection_supports_ip4 (NMConnection *connection) { NMSettingConnection *s_con; diff --git a/src/connection-editor/connection-helpers.h b/src/connection-editor/connection-helpers.h index 08fe5834..17de5699 100644 --- a/src/connection-editor/connection-helpers.h +++ b/src/connection-editor/connection-helpers.h @@ -83,6 +83,7 @@ void delete_connection (GtkWindow *parent_window, DeleteConnectionResultFunc result_func, gpointer user_data); +gboolean connection_supports_proxy (NMConnection *connection); gboolean connection_supports_ip4 (NMConnection *connection); gboolean connection_supports_ip6 (NMConnection *connection); diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c index 9d23390b..6032a98a 100644 --- a/src/connection-editor/nm-connection-editor.c +++ b/src/connection-editor/nm-connection-editor.c @@ -38,6 +38,7 @@ #include "page-8021x-security.h" #include "page-wifi.h" #include "page-wifi-security.h" +#include "page-proxy.h" #include "page-ip4.h" #include "page-ip6.h" #include "page-ip-tunnel.h" @@ -812,6 +813,13 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor, goto out; } +#if NM_LIBNM_COMPAT_PROXY_SUPPORTED + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + if ( nm_connection_get_setting_proxy (editor->connection) + && !add_page (editor, ce_page_proxy_new, editor->connection, error)) + goto out; + G_GNUC_END_IGNORE_DEPRECATIONS +#endif if ( nm_connection_get_setting_ip4_config (editor->connection) && !add_page (editor, ce_page_ip4_new, editor->connection, error)) goto out; diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c index 37c7eb5a..7fc482af 100644 --- a/src/connection-editor/nm-connection-list.c +++ b/src/connection-editor/nm-connection-list.c @@ -278,6 +278,12 @@ really_add_connection (FUNC_TAG_NEW_CONNECTION_RESULT_IMPL, return; } +#if NM_LIBNM_COMPAT_PROXY_SUPPORTED + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + if (connection_supports_proxy (connection) && !nm_connection_get_setting_proxy (connection)) + nm_connection_add_setting (connection, nm_setting_proxy_new ()); + G_GNUC_END_IGNORE_DEPRECATIONS +#endif if (connection_supports_ip4 (connection) && !nm_connection_get_setting_ip4_config (connection)) nm_connection_add_setting (connection, nm_setting_ip4_config_new ()); if (connection_supports_ip6 (connection) && !nm_connection_get_setting_ip6_config (connection)) diff --git a/src/connection-editor/page-proxy.c b/src/connection-editor/page-proxy.c new file mode 100644 index 00000000..45436e28 --- /dev/null +++ b/src/connection-editor/page-proxy.c @@ -0,0 +1,321 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager Connection editor -- Connection editor for NetworkManager + * + * 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. + * + * (C) Copyright 2016 Atul Anand <atulhjp@gmail.com>. + */ + +#include "nm-default.h" + +#if NM_LIBNM_COMPAT_PROXY_SUPPORTED + +#include "page-proxy.h" + +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +#include "nm-connection-editor.h" + +G_DEFINE_TYPE (CEPageProxy, ce_page_proxy, CE_TYPE_PAGE) + +#define CE_PAGE_PROXY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_PROXY, CEPageProxyPrivate)) + +typedef struct { + NMSettingProxy *setting; + + /* Method */ + GtkComboBox *method; + + /* Browser Only */ + GtkCheckButton *browser_only; + + /* PAC URL */ + GtkWidget *pac_url_label; + GtkEntry *pac_url; + + /* PAC Script */ + GtkWidget *pac_script_label; + GtkButton *pac_script_import_button; + GtkTextView *pac_script_window; +} CEPageProxyPrivate; + +#define PROXY_METHOD_NONE 0 +#define PROXY_METHOD_AUTO 1 + +static void +proxy_private_init (CEPageProxy *self) +{ + CEPageProxyPrivate *priv = CE_PAGE_PROXY_GET_PRIVATE (self); + GtkBuilder *builder; + + builder = CE_PAGE (self)->builder; + + priv->method = GTK_COMBO_BOX (gtk_builder_get_object (builder, "proxy_method")); + + priv->browser_only = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "proxy_browser_only_checkbutton")); + + priv->pac_url_label = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_pac_url_label")); + priv->pac_url = GTK_ENTRY (gtk_builder_get_object (builder, "proxy_pac_url_entry")); + + priv->pac_script_label = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_pac_script_label")); + priv->pac_script_import_button = GTK_BUTTON (gtk_builder_get_object (builder, "proxy_pac_script_import_button")); + priv->pac_script_window = GTK_TEXT_VIEW (gtk_builder_get_object (builder, "proxy_pac_script_window")); +} + +static void +stuff_changed (GtkWidget *w, gpointer user_data) +{ + ce_page_changed (CE_PAGE (user_data)); +} + +static void +method_changed (GtkComboBox *combo, gpointer user_data) +{ + CEPageProxy *self = user_data; + CEPageProxyPrivate *priv = CE_PAGE_PROXY_GET_PRIVATE (self); + int method = gtk_combo_box_get_active (combo); + + if (method == PROXY_METHOD_NONE) { + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_url_label), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_url), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_script_label), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_script_import_button), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_script_window), FALSE); + } else { + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_url_label), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_url), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_script_label), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_script_import_button), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (priv->pac_script_window), TRUE); + } +} + +static void +import_button_clicked_cb (GtkWidget *widget, CEPageProxy *self) +{ + CEPageProxyPrivate *priv = CE_PAGE_PROXY_GET_PRIVATE (self); + GtkWidget *dialog, *toplevel; + GtkTextBuffer *buffer; + char *filename, *script = NULL; + gsize len; + + toplevel = gtk_widget_get_toplevel (CE_PAGE (self)->page); + g_return_if_fail (toplevel); + g_return_if_fail (gtk_widget_is_toplevel (toplevel)); + + dialog = gtk_file_chooser_dialog_new (_("Select file to import"), + GTK_WINDOW (toplevel), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + if (!filename) + goto out; + + g_file_get_contents (filename, &script, &len, NULL); + buffer = gtk_text_view_get_buffer (priv->pac_script_window); + gtk_text_buffer_set_text (buffer, script ?: "", -1); + + g_free (filename); + g_free (script); + } + +out: + gtk_widget_destroy (dialog); +} + +static void +populate_ui (CEPageProxy *self) +{ + CEPageProxyPrivate *priv = CE_PAGE_PROXY_GET_PRIVATE (self); + NMSettingProxy *setting = priv->setting; + NMSettingProxyMethod s_method; + GtkTextBuffer *buffer; + const char *tmp = NULL; + + /* Method */ + s_method = nm_setting_proxy_get_method (setting); + switch (s_method) { + case NM_SETTING_PROXY_METHOD_AUTO: + gtk_combo_box_set_active (priv->method, PROXY_METHOD_AUTO); + + /* Pac Url */ + tmp = nm_setting_proxy_get_pac_url (setting); + gtk_entry_set_text (priv->pac_url, tmp ? tmp : ""); + + /* Pac Script */ + tmp = nm_setting_proxy_get_pac_script (setting); + buffer = gtk_text_view_get_buffer (priv->pac_script_window); + gtk_text_buffer_set_text (buffer, tmp ?: "", -1); + break; + case NM_SETTING_PROXY_METHOD_NONE: + gtk_combo_box_set_active (priv->method, PROXY_METHOD_NONE); + /* Nothing to Show */ + } + + g_signal_connect (priv->method, "changed", G_CALLBACK (stuff_changed), self); + g_signal_connect (priv->browser_only, "toggled", G_CALLBACK (stuff_changed), self); + g_signal_connect (priv->pac_url, "changed", G_CALLBACK (stuff_changed), self); + g_signal_connect (gtk_text_view_get_buffer (priv->pac_script_window), "changed", G_CALLBACK (stuff_changed), self); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->browser_only), + nm_setting_proxy_get_browser_only (setting)); +} + +static void +finish_setup (CEPageProxy *self, gpointer unused, GError *error, gpointer user_data) +{ + CEPageProxyPrivate *priv = CE_PAGE_PROXY_GET_PRIVATE (self); + + if (error) + return; + + populate_ui (self); + + method_changed (priv->method, self); + g_signal_connect (priv->method, "changed", G_CALLBACK (method_changed), self); + g_signal_connect (priv->pac_script_import_button, "clicked", G_CALLBACK (import_button_clicked_cb), self); +} + +CEPage * +ce_page_proxy_new (NMConnectionEditor *editor, + NMConnection *connection, + GtkWindow *parent_window, + NMClient *client, + const char **out_secrets_setting_name, + GError **error) +{ + CEPageProxy *self; + CEPageProxyPrivate *priv; + NMSettingConnection *s_con; + + self = CE_PAGE_PROXY (ce_page_new (CE_TYPE_PAGE_PROXY, + editor, + connection, + parent_window, + client, + UIDIR "/ce-page-proxy.ui", + "ProxyPage", + _("Proxy"))); + if (!self) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load Proxy user interface.")); + return NULL; + } + + proxy_private_init (self); + priv = CE_PAGE_PROXY_GET_PRIVATE (self); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + + priv->setting = nm_connection_get_setting_proxy (connection); + g_assert (priv->setting); + + g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL); + + return CE_PAGE (self); +} + +static void +ui_to_setting (CEPageProxy *self) +{ + CEPageProxyPrivate *priv = CE_PAGE_PROXY_GET_PRIVATE (self); + NMSettingConnection *s_con; + int method; + gboolean browser_only; + const char *pac_url; + GtkTextBuffer *buffer; + GtkTextIter start, end; + char *script = NULL; + + s_con = nm_connection_get_setting_connection (CE_PAGE (self)->connection); + g_return_if_fail (s_con != NULL); + + /* Method */ + method = gtk_combo_box_get_active (priv->method); + + /* Browser Only */ + browser_only = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->browser_only)); + + if (method == PROXY_METHOD_NONE) { + g_object_set (priv->setting, + NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_NONE, + NM_SETTING_PROXY_BROWSER_ONLY, browser_only, + NM_SETTING_PROXY_PAC_URL, NULL, + NM_SETTING_PROXY_PAC_SCRIPT, NULL, + NULL); + return; + } + + /* PAC Url */ + pac_url = gtk_entry_get_text (priv->pac_url); + if (pac_url && strlen (pac_url) < 1) + pac_url = NULL; + + /* PAC Script */ + buffer = gtk_text_view_get_buffer (priv->pac_script_window); + gtk_text_buffer_get_iter_at_offset (buffer, &start, 0); + gtk_text_buffer_get_iter_at_offset (buffer, &end, -1); + script = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); + + /* Update NMSetting */ + g_object_set (priv->setting, + NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_AUTO, + NM_SETTING_PROXY_BROWSER_ONLY, browser_only, + NM_SETTING_PROXY_PAC_URL, pac_url, + NM_SETTING_PROXY_PAC_SCRIPT, nm_str_not_empty (script), + NULL); + g_free (script); +} + +static gboolean +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) +{ + CEPageProxy *self = CE_PAGE_PROXY (page); + CEPageProxyPrivate *priv = CE_PAGE_PROXY_GET_PRIVATE (self); + + if (!priv->setting) { + priv->setting = (NMSettingProxy *) nm_setting_proxy_new (); + nm_connection_add_setting (connection, NM_SETTING (priv->setting)); + } + ui_to_setting (self); + + return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); +} + +static void +ce_page_proxy_init (CEPageProxy *self) +{ +} + +static void +ce_page_proxy_class_init (CEPageProxyClass *proxy_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (proxy_class); + CEPageClass *parent_class = CE_PAGE_CLASS (proxy_class); + + g_type_class_add_private (object_class, sizeof (CEPageProxyPrivate)); + + /* virtual methods */ + parent_class->ce_page_validate_v = ce_page_validate_v; +} + +#endif /* NM_LIBNM_COMPAT_PROXY_SUPPORTED */ diff --git a/src/connection-editor/page-proxy.h b/src/connection-editor/page-proxy.h new file mode 100644 index 00000000..9e5afb32 --- /dev/null +++ b/src/connection-editor/page-proxy.h @@ -0,0 +1,54 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager Connection editor -- Connection editor for NetworkManager + * + * 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. + * + * (C) Copyright 2016 Atul Anand <atulhjp@gmail.com>. + */ + +#ifndef __PAGE_PROXY_H__ +#define __PAGE_PROXY_H__ + +#include "ce-page.h" + +#if NM_LIBNM_COMPAT_PROXY_SUPPORTED + +#define CE_TYPE_PAGE_PROXY (ce_page_proxy_get_type ()) +#define CE_PAGE_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_PROXY, CEPageProxy)) +#define CE_PAGE_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_PROXY, CEPageProxyClass)) +#define CE_IS_PAGE_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_PROXY)) +#define CE_IS_PAGE_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CE_TYPE_PAGE_PROXY)) +#define CE_PAGE_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_PROXY, CEPageProxyClass)) + +typedef struct { + CEPage parent; +} CEPageProxy; + +typedef struct { + CEPageClass parent; +} CEPageProxyClass; + +GType ce_page_proxy_get_type (void); + +CEPage *ce_page_proxy_new (NMConnectionEditor *editor, + NMConnection *connection, + GtkWindow *parent, + NMClient *client, + const char **out_secrets_setting_name, + GError **error); + +#endif /* NM_LIBNM_COMPAT_PROXY_SUPPORTED */ + +#endif /* __PAGE_PROXY_H__ */ |