Update properties-editor UI and code + minor fix in nm-l2tp-service

Code much sychronized with network-manager-pptp (master 8b5c8b6ca3d24f7b5f736b8a7a29956f0bce35f3)
Now works with beeline-moscow tp.internet.beeline.ru
parent 006b8091
...@@ -726,15 +726,15 @@ ...@@ -726,15 +726,15 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="n_rows">4</property> <property name="n_rows">4</property>
<property name="n_columns">2</property> <property name="n_columns">3</property>
<property name="column_spacing">12</property> <property name="column_spacing">12</property>
<property name="row_spacing">6</property> <property name="row_spacing">6</property>
<child> <child>
<object class="GtkEntry" id="domain_entry"> <object class="GtkEntry" id="domain_entry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_activatable">False</property> <property name="invisible_char"></property>
<property name="secondary_icon_activatable">False</property> <property name="invisible_char_set">True</property>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
...@@ -765,6 +765,7 @@ ...@@ -765,6 +765,7 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="use_action_appearance">False</property> <property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
</object> </object>
<packing> <packing>
...@@ -775,13 +776,32 @@ ...@@ -775,13 +776,32 @@
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkComboBox" id="user_pass_type_combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="model">model2</property>
<child>
<object class="GtkCellRendererText" id="renderer2"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child> <child>
<object class="GtkEntry" id="user_password_entry"> <object class="GtkEntry" id="user_password_entry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="visibility">False</property> <property name="visibility">False</property>
<property name="primary_icon_activatable">False</property> <property name="invisible_char"></property>
<property name="secondary_icon_activatable">False</property> <property name="invisible_char_set">True</property>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
...@@ -809,8 +829,8 @@ ...@@ -809,8 +829,8 @@
<object class="GtkEntry" id="user_entry"> <object class="GtkEntry" id="user_entry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_activatable">False</property> <property name="invisible_char"></property>
<property name="secondary_icon_activatable">False</property> <property name="invisible_char_set">True</property>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
...@@ -833,6 +853,15 @@ ...@@ -833,6 +853,15 @@
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object> </object>
</child> </child>
</object> </object>
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
#define L2TP_PLUGIN_DESC _("Compatible with L2TP VPN servers.") #define L2TP_PLUGIN_DESC _("Compatible with L2TP VPN servers.")
#define L2TP_PLUGIN_SERVICE NM_DBUS_SERVICE_L2TP #define L2TP_PLUGIN_SERVICE NM_DBUS_SERVICE_L2TP
#define PW_TYPE_SAVE 0
#define PW_TYPE_ASK 1
#define PW_TYPE_UNUSED 2
typedef void (*ChangedCallback) (GtkWidget *widget, gpointer user_data); typedef void (*ChangedCallback) (GtkWidget *widget, gpointer user_data);
...@@ -273,6 +276,36 @@ ipsec_button_clicked_cb (GtkWidget *button, gpointer user_data) ...@@ -273,6 +276,36 @@ ipsec_button_clicked_cb (GtkWidget *button, gpointer user_data)
gtk_widget_show_all (dialog); gtk_widget_show_all (dialog);
} }
static void
setup_password_widget (L2tpPluginUiWidget *self,
const char *entry_name,
NMSettingVPN *s_vpn,
const char *secret_name,
gboolean new_connection)
{
L2tpPluginUiWidgetPrivate *priv = L2TP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
GtkWidget *widget;
const char *value;
/* Default to agent-owned for new connections */
if (new_connection)
secret_flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED;
widget = (GtkWidget *) gtk_builder_get_object (priv->builder, entry_name);
g_assert (widget);
gtk_size_group_add_widget (priv->group, widget);
if (s_vpn) {
value = nm_setting_vpn_get_secret (s_vpn, secret_name);
gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_name, &secret_flags, NULL);
}
secret_flags &= ~(NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED);
g_object_set_data (G_OBJECT (widget), "flags", GUINT_TO_POINTER (secret_flags));
g_signal_connect (widget, "changed", G_CALLBACK (stuff_changed_cb), self);
}
static void static void
show_toggled_cb (GtkCheckButton *button, L2tpPluginUiWidget *self) show_toggled_cb (GtkCheckButton *button, L2tpPluginUiWidget *self)
...@@ -288,65 +321,89 @@ show_toggled_cb (GtkCheckButton *button, L2tpPluginUiWidget *self) ...@@ -288,65 +321,89 @@ show_toggled_cb (GtkCheckButton *button, L2tpPluginUiWidget *self)
gtk_entry_set_visibility (GTK_ENTRY (widget), visible); gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
} }
/* static GtkWidget * */ static void
/* fill_password (GtkBuilder *builder, */ pw_type_combo_changed_cb (GtkWidget *combo, gpointer user_data)
/* const char *widget_name, */ {
/* NMConnection *connection, */ L2tpPluginUiWidget *self = L2TP_PLUGIN_UI_WIDGET (user_data);
/* const char *password_type) */ L2tpPluginUiWidgetPrivate *priv = L2TP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
/* { */ GtkWidget *entry;
/* GtkWidget *widget = NULL; */
/* gchar *password = NULL; */ entry = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry"));
/* NMSettingVPN *s_vpn; */ g_assert (entry);
/* gboolean unused; */
/* If the user chose "Not required", desensitize and clear the correct
* password entry.
/* widget = GTK_WIDGET (gtk_builder_get_object (builder, widget_name)); */ */
/* g_assert (widget); */ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
case PW_TYPE_ASK:
/* if (!connection) */ case PW_TYPE_UNUSED:
/* return widget; */ gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_widget_set_sensitive (entry, FALSE);
/* /\* Try the connection first *\/ */ break;
/* s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); */ default:
/* if (s_vpn) { */ gtk_widget_set_sensitive (entry, TRUE);
/* const gchar *tmp = NULL; */ break;
}
/* tmp = nm_setting_vpn_get_secret (s_vpn, password_type); */
/* if (tmp) */ stuff_changed_cb (combo, self);
/* password = gnome_keyring_memory_strdup (tmp); */ }
/* } */
static void
/* if (!password) { */ init_one_pw_combo (L2tpPluginUiWidget *self,
/* password = keyring_helpers_lookup_secret (nm_connection_get_uuid (connection), */ NMSettingVPN *s_vpn,
/* password_type, */ const char *combo_name,
/* &unused); */ const char *secret_key,
/* } */ const char *entry_name)
{
/* if (password) { */ L2tpPluginUiWidgetPrivate *priv = L2TP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
/* gtk_entry_set_text (GTK_ENTRY (widget), password); */ int active = -1;
/* gnome_keyring_memory_free (password); */ GtkWidget *widget;
/* } */ GtkListStore *store;
GtkTreeIter iter;
/* return widget; */ const char *value = NULL;
/* } */ guint32 default_idx = 1;
NMSettingSecretFlags pw_flags = NM_SETTING_SECRET_FLAG_NONE;
/* static void */
/* fill_vpn_passwords (GtkBuilder *builder, */ /* If there's already a password and the password type can't be found in
/* GtkSizeGroup *group, */ * the VPN settings, default to saving it. Otherwise, always ask for it.
/* NMConnection *connection, */ */
/* ChangedCallback changed_cb, */ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, entry_name));
/* gpointer user_data) */ g_assert (widget);
/* { */ value = gtk_entry_get_text (GTK_ENTRY (widget));
/* GtkWidget *w = NULL; */ if (value && strlen (value))
default_idx = 0;
/* w = fill_password (builder, "user_password_entry", connection, NM_L2TP_KEY_PASSWORD); */
/* if (w) { */ store = gtk_list_store_new (1, G_TYPE_STRING);
/* gtk_size_group_add_widget (group, w); */ if (s_vpn)
/* g_signal_connect (w, "changed", G_CALLBACK (changed_cb), user_data); */ nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_key, &pw_flags, NULL);
/* } else { */
/* g_error ("No userbuilder in GtkBuilder file!"); */ gtk_list_store_append (store, &iter);
/* } */ gtk_list_store_set (store, &iter, 0, _("Saved"), -1);
/* } */ if ( (active < 0)
&& !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
&& !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
active = PW_TYPE_SAVE;
}
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Always Ask"), -1);
if ((active < 0) && (pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED))
active = PW_TYPE_ASK;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Not Required"), -1);
if ((active < 0) && (pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED))
active = PW_TYPE_UNUSED;
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, combo_name));
g_assert (widget);
gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
g_object_unref (store);
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? default_idx : active);
pw_type_combo_changed_cb (widget, self);
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (pw_type_combo_changed_cb), self);
}
static gboolean static gboolean
init_plugin_ui (L2tpPluginUiWidget *self, NMConnection *connection, GError **error) init_plugin_ui (L2tpPluginUiWidget *self, NMConnection *connection, GError **error)
...@@ -355,7 +412,6 @@ init_plugin_ui (L2tpPluginUiWidget *self, NMConnection *connection, GError **err ...@@ -355,7 +412,6 @@ init_plugin_ui (L2tpPluginUiWidget *self, NMConnection *connection, GError **err
NMSettingVPN *s_vpn; NMSettingVPN *s_vpn;
GtkWidget *widget; GtkWidget *widget;
const char *value; const char *value;
NMSettingSecretFlags pw_flags = NM_SETTING_SECRET_FLAG_NONE;
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
...@@ -406,23 +462,20 @@ init_plugin_ui (L2tpPluginUiWidget *self, NMConnection *connection, GError **err ...@@ -406,23 +462,20 @@ init_plugin_ui (L2tpPluginUiWidget *self, NMConnection *connection, GError **err
(GCallback) show_toggled_cb, (GCallback) show_toggled_cb,
self); self);
widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "user_password_entry"); /* Fill the VPN passwords *before* initializing the PW type combo, since
g_assert (widget); * knowing if there is a password when initializing the type combo is helpful.
gtk_size_group_add_widget (priv->group, widget); */
if (s_vpn) { setup_password_widget (self,
value = nm_setting_vpn_get_secret (s_vpn, NM_L2TP_KEY_PASSWORD); "user_password_entry",
if (value) s_vpn,
gtk_entry_set_text (GTK_ENTRY (widget), value); NM_L2TP_KEY_PASSWORD,
priv->new_connection);
/* Default to agent-owned for new connections */
if (priv->new_connection) init_one_pw_combo (self,
pw_flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED; s_vpn,
else "user_pass_type_combo",
nm_setting_get_secret_flags (NM_SETTING (s_vpn), NM_L2TP_KEY_PASSWORD, &pw_flags, NULL); NM_L2TP_KEY_PASSWORD,
"user_password_entry");
g_object_set_data (G_OBJECT (widget), "flags", GUINT_TO_POINTER (pw_flags));
}
g_signal_connect (widget, "changed", G_CALLBACK (stuff_changed_cb), self);
return TRUE; return TRUE;
} }
...@@ -444,6 +497,43 @@ hash_copy_pair (gpointer key, gpointer data, gpointer user_data) ...@@ -444,6 +497,43 @@ hash_copy_pair (gpointer key, gpointer data, gpointer user_data)
nm_setting_vpn_add_data_item (s_vpn, (const char *) key, (const char *) data); nm_setting_vpn_add_data_item (s_vpn, (const char *) key, (const char *) data);
} }
static void
save_password_and_flags (NMSettingVPN *s_vpn,
GtkBuilder *builder,
const char *entry_name,
const char *combo_name,
const char *secret_key)
{
NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
const char *password;
GtkWidget *entry;
GtkWidget *combo;
/* Grab original password flags */
entry = GTK_WIDGET (gtk_builder_get_object (builder, entry_name));
flags = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (entry), "flags"));
/* And set new ones based on the type combo */
combo = GTK_WIDGET (gtk_builder_get_object (builder, combo_name));
switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
case PW_TYPE_SAVE:
password = gtk_entry_get_text (GTK_ENTRY (entry));
if (password && strlen (password))
nm_setting_vpn_add_secret (s_vpn, secret_key, password);
break;
case PW_TYPE_UNUSED:
flags |= NM_SETTING_SECRET_FLAG_NOT_REQUIRED;
break;
case PW_TYPE_ASK:
default:
flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED;
break;
}
/* Set new secret flags */
nm_setting_set_secret_flags (NM_SETTING (s_vpn), secret_key, flags, NULL);
}
static gboolean static gboolean
update_connection (NMVpnPluginUiWidgetInterface *iface, update_connection (NMVpnPluginUiWidgetInterface *iface,
NMConnection *connection, NMConnection *connection,
...@@ -455,7 +545,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface, ...@@ -455,7 +545,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
GtkWidget *widget; GtkWidget *widget;
const char *str; const char *str;
gboolean valid = FALSE; gboolean valid = FALSE;
NMSettingSecretFlags pw_flags;
if (!check_validity (self, error)) if (!check_validity (self, error))
return FALSE; return FALSE;
...@@ -475,15 +564,12 @@ update_connection (NMVpnPluginUiWidgetInterface *iface, ...@@ -475,15 +564,12 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
if (str && strlen (str)) if (str && strlen (str))
nm_setting_vpn_add_data_item (s_vpn, NM_L2TP_KEY_USER, str); nm_setting_vpn_add_data_item (s_vpn, NM_L2TP_KEY_USER, str);
/* User password */ /* User password and flags */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry")); save_password_and_flags (s_vpn,
str = gtk_entry_get_text (GTK_ENTRY (widget)); priv->builder,
if (str && strlen (str)) "user_password_entry",
nm_setting_vpn_add_secret (s_vpn, NM_L2TP_KEY_PASSWORD, str); "user_pass_type_combo",
NM_L2TP_KEY_PASSWORD);
/* And password flags */
pw_flags = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget), "flags"));
nm_setting_set_secret_flags (NM_SETTING (s_vpn), NM_L2TP_KEY_PASSWORD, pw_flags, NULL);
/* Domain */ /* Domain */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "domain_entry")); widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "domain_entry"));
...@@ -502,43 +588,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface, ...@@ -502,43 +588,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
return valid; return valid;
} }
/* static gboolean */
/* save_secrets (NMVpnPluginUiWidgetInterface *iface, */
/* NMConnection *connection, */
/* GError **error) */
/* { */
/* L2tpPluginUiWidget *self = L2TP_PLUGIN_UI_WIDGET (iface); */
/* L2tpPluginUiWidgetPrivate *priv = L2TP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); */
/* GnomeKeyringResult ret; */
/* NMSettingConnection *s_con; */
/* GtkWidget *widget; */
/* const char *str, *uuid, *id; */
/* s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); */
/* if (!s_con) { */
/* g_set_error (error, */
/* L2TP_PLUGIN_UI_ERROR, */
/* L2TP_PLUGIN_UI_ERROR_INVALID_CONNECTION, */
/* "missing 'connection' setting"); */
/* return FALSE; */
/* } */
/* id = nm_setting_connection_get_id (s_con); */
/* uuid = nm_setting_connection_get_uuid (s_con); */
/* widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry")); */
/* g_assert (widget); */
/* str = gtk_entry_get_text (GTK_ENTRY (widget)); */
/* if (str && strlen (str)) { */
/* ret = keyring_helpers_save_secret (uuid, id, NULL, NM_L2TP_KEY_PASSWORD, str); */
/* if (ret != GNOME_KEYRING_RESULT_OK) */
/* g_warning ("%s: failed to save user password to keyring.", __func__); */
/* } else */
/* keyring_helpers_delete_secret (uuid, NM_L2TP_KEY_PASSWORD); */
/* return TRUE; */
/* } */
static void static void
is_new_func (const char *key, const char *value, gpointer user_data) is_new_func (const char *key, const char *value, gpointer user_data)
{ {
...@@ -667,33 +716,7 @@ l2tp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class) ...@@ -667,33 +716,7 @@ l2tp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class)
/* interface implementation */ /* interface implementation */
iface_class->get_widget = get_widget; iface_class->get_widget = get_widget;
iface_class->update_connection = update_connection; iface_class->update_connection = update_connection;
// iface_class->save_secrets = save_secrets; }
}
/* static gboolean */
/* delete_connection (NMVpnPluginUiInterface *iface, */
/* NMConnection *connection, */
/* GError **error) */
/* { */
/* NMSettingConnection *s_con = NULL; */
/* const char *uuid; */
/* /\* Remove any secrets in the keyring associated with this connection's UUID *\/ */
/* s_con = (NMSettingConnection *) nm_connection_get_setting (connection, */
/* NM_TYPE_SETTING_CONNECTION); */
/* if (!s_con) { */
/* g_set_error (error, */
/* L2TP_PLUGIN_UI_ERROR, */
/* L2TP_PLUGIN_UI_ERROR_INVALID_CONNECTION, */
/* "missing 'connection' setting"); */
/* return FALSE; */
/* } */
/* uuid = nm_setting_connection_get_uuid (s_con); */
/* keyring_helpers_delete_secret (uuid, NM_L2TP_KEY_PASSWORD); */
/* return TRUE; */
/* } */
static NMConnection * static NMConnection *
import (NMVpnPluginUiInterface *iface, const char *path, GError **error) import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
...@@ -833,7 +856,6 @@ l2tp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class) ...@@ -833,7 +856,6 @@ l2tp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class)
iface_class->import_from_file = import; iface_class->import_from_file = import;
iface_class->export_to_file = export; iface_class->export_to_file = export;
iface_class->get_suggested_name = get_suggested_name; iface_class->get_suggested_name = get_suggested_name;
/* iface_class->delete_connection = delete_connection; */
} }
......
...@@ -405,6 +405,7 @@ static ValidProperty valid_properties[] = { ...@@ -405,6 +405,7 @@ static ValidProperty valid_properties[] = {
{ NM_L2TP_KEY_USE_ACCOMP, G_TYPE_BOOLEAN, FALSE }, { NM_L2TP_KEY_USE_ACCOMP, G_TYPE_BOOLEAN, FALSE },
{ NM_L2TP_KEY_LCP_ECHO_FAILURE, G_TYPE_UINT, FALSE }, { NM_L2TP_KEY_LCP_ECHO_FAILURE, G_TYPE_UINT, FALSE },
{ NM_L2TP_KEY_LCP_ECHO_INTERVAL, G_TYPE_UINT, FALSE }, { NM_L2TP_KEY_LCP_ECHO_INTERVAL, G_TYPE_UINT, FALSE },
{ NM_L2TP_KEY_PASSWORD"-flags", G_TYPE_UINT, FALSE },
{ NM_L2TP_KEY_IPSEC_ENABLE, G_TYPE_BOOLEAN, FALSE }, { NM_L2TP_KEY_IPSEC_ENABLE, G_TYPE_BOOLEAN, FALSE },
{ NM_L2TP_KEY_IPSEC_GATEWAY_ID, G_TYPE_STRING, FALSE }, { NM_L2TP_KEY_IPSEC_GATEWAY_ID, G_TYPE_STRING, FALSE },
{ NM_L2TP_KEY_IPSEC_GROUP_NAME, G_TYPE_STRING, FALSE }, { NM_L2TP_KEY_IPSEC_GROUP_NAME, G_TYPE_STRING, FALSE },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment