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>
This commit is contained in:
Thomas Haller 2014-07-29 00:46:52 +02:00
parent ec6d8385d3
commit e5c719c0c0
3 changed files with 25 additions and 43 deletions

View file

@ -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),

View file

@ -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));

View file

@ -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