diff options
author | Thomas Haller <thaller@redhat.com> | 2014-07-29 00:46:52 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-09-24 16:32:11 +0200 |
commit | e5c719c0c02f96d4e2cccd4328b1a15b1d967010 (patch) | |
tree | aa0c9857547511859eb7fb9ae30c3d31a64d4c81 | |
parent | ec6d8385d3811bc565ca0d232f289e05855b91a5 (diff) | |
download | NetworkManager-e5c719c0c02f96d4e2cccd4328b1a15b1d967010.tar.gz |
settings: implement 'unsaved' and 'nm-generated' as #NMSettingsConnectionFlags
Before, NMSettingsConnection had two internal properties 'unsaved' and
'nm-generated'. Now, implement these properties as #NMSettingsConnectionFlags.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/nm-manager.c | 2 | ||||
-rw-r--r-- | src/settings/nm-settings-connection.c | 59 | ||||
-rw-r--r-- | src/settings/nm-settings-connection.h | 7 |
3 files changed, 25 insertions, 43 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c index e08e595877..4698247f0b 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1562,7 +1562,7 @@ get_existing_connection (NMManager *manager, NMDevice *device) added = nm_settings_add_connection (priv->settings, connection, FALSE, &error); if (added) - nm_settings_connection_set_nm_generated (added); + nm_settings_connection_set_flags (NM_SETTINGS_CONNECTION (added), NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED, TRUE); else { nm_log_warn (LOGD_SETTINGS, "(%s) Couldn't save generated connection '%s': %s", nm_device_get_iface (device), diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 1eaf713f71..a36f5ecbda 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -100,16 +100,6 @@ typedef struct { NMSettingsConnectionFlags flags; - /* TRUE if the connection has not yet been saved to disk, - * or if it contains changes that have not been saved to disk. - */ - gboolean unsaved; - - /* TRUE if the connection was generated by NetworkManager and has - * not been saved or modified by the user. - */ - gboolean nm_generated; - guint updated_idle_id; GSList *pending_auths; /* List of pending authentication requests */ @@ -408,14 +398,16 @@ emit_updated (NMSettingsConnection *self) static void set_unsaved (NMSettingsConnection *self, gboolean now_unsaved) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + NMSettingsConnectionFlags flags = nm_settings_connection_get_flags (self); - if (priv->unsaved != now_unsaved) { - priv->unsaved = now_unsaved; - if (!priv->unsaved) - priv->nm_generated = FALSE; - - g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTION_UNSAVED); + if (NM_FLAGS_HAS (flags, NM_SETTINGS_CONNECTION_FLAGS_UNSAVED) != !!now_unsaved) { + if (now_unsaved) + flags |= NM_SETTINGS_CONNECTION_FLAGS_UNSAVED; + else { + flags &= ~(NM_SETTINGS_CONNECTION_FLAGS_UNSAVED | + NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED); + } + nm_settings_connection_set_flags_all (self, flags); } } @@ -465,7 +457,7 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self, g_signal_handlers_block_by_func (self, G_CALLBACK (changed_cb), GUINT_TO_POINTER (TRUE)); nm_connection_replace_settings_from_connection (NM_CONNECTION (self), new_connection); - priv->nm_generated = FALSE; + nm_settings_connection_set_flags (self, NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED, FALSE); /* Cache the just-updated system secrets in case something calls * nm_connection_clear_secrets() and clears them. @@ -1414,7 +1406,7 @@ impl_settings_connection_save (NMSettingsConnection *self, DBusGMethodInvocation *context) { /* Do nothing if the connection is already synced with disk */ - if (NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->unsaved == TRUE) + if (nm_settings_connection_get_unsaved (self)) impl_settings_connection_update_helper (self, NULL, context, TRUE); else dbus_g_method_return (context); @@ -1600,7 +1592,7 @@ nm_settings_connection_signal_remove (NMSettingsConnection *self) gboolean nm_settings_connection_get_unsaved (NMSettingsConnection *self) { - return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->unsaved; + return NM_FLAGS_HAS (nm_settings_connection_get_flags (self), NM_SETTINGS_CONNECTION_FLAGS_UNSAVED); } /**************************************************************/ @@ -1643,6 +1635,8 @@ nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConn if (old_flags != flags) { priv->flags = flags; g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTION_FLAGS); + if (NM_FLAGS_HAS (old_flags, NM_SETTINGS_CONNECTION_FLAGS_UNSAVED) != NM_FLAGS_HAS (flags, NM_SETTINGS_CONNECTION_FLAGS_UNSAVED)) + g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTION_UNSAVED); } return old_flags; } @@ -2009,30 +2003,13 @@ nm_settings_connection_can_autoconnect (NMSettingsConnection *connection) * Gets the "nm-generated" flag on @connection. * * A connection is "nm-generated" if it was generated by - * nm_device_generate_connection() and then assumed by #NMManager, and - * it has not been modified or saved by the user since then. In other - * words, an "nm-generated" connection reflects state that is entirely - * external to NetworkManager. + * nm_device_generate_connection() and has not been modified or + * saved by the user since then. */ gboolean nm_settings_connection_get_nm_generated (NMSettingsConnection *connection) { - return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->nm_generated; -} - -/** - * nm_settings_connection_set_nm_generated: - * @connection: an #NMSettingsConnection - * - * Sets the "nm-generated" flag on @connection; see - * nm_settings_connection_get_nm_generated(). - */ -void -nm_settings_connection_set_nm_generated (NMSettingsConnection *connection) -{ - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); - - priv->nm_generated = TRUE; + return NM_FLAGS_HAS (nm_settings_connection_get_flags (connection), NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED); } /**************************************************************/ @@ -2119,7 +2096,7 @@ get_property (GObject *object, guint prop_id, g_value_set_boolean (value, priv->visible); break; case PROP_UNSAVED: - g_value_set_boolean (value, priv->unsaved); + g_value_set_boolean (value, nm_settings_connection_get_unsaved (self)); break; case PROP_FLAGS: g_value_set_uint (value, nm_settings_connection_get_flags (self)); diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 3e3f202b3f..3191e7aad8 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -54,6 +54,10 @@ G_BEGIN_DECLS /** * NMSettingsConnectionFlags: * @NM_SETTINGS_CONNECTION_FLAGS_NONE: no flag set + * @NM_SETTINGS_CONNECTION_FLAGS_UNSAVED: the connection is not saved to disk + * @NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED: A connection is "nm-generated" if + * it was generated by NetworkManger. If the connection gets modified or saved + * by the user, the flag gets cleared. A nm-generated is implicitly unsaved. * @NM_SETTINGS_CONNECTION_FLAGS_ALL: special mask, for all known flags * * #NMSettingsConnection flags. @@ -61,6 +65,8 @@ G_BEGIN_DECLS typedef enum { NM_SETTINGS_CONNECTION_FLAGS_NONE = 0x00, + NM_SETTINGS_CONNECTION_FLAGS_UNSAVED = 0x01, + NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED = 0x02, __NM_SETTINGS_CONNECTION_FLAGS_LAST, NM_SETTINGS_CONNECTION_FLAGS_ALL = ((__NM_SETTINGS_CONNECTION_FLAGS_LAST - 1) << 1) - 1, @@ -183,7 +189,6 @@ void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection gboolean nm_settings_connection_can_autoconnect (NMSettingsConnection *connection); -void nm_settings_connection_set_nm_generated (NMSettingsConnection *connection); gboolean nm_settings_connection_get_nm_generated (NMSettingsConnection *connection); G_END_DECLS |