From 0e1abe5ef365f5b271cb969c8df820214c56ec65 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 4 Dec 2017 16:05:26 +0100 Subject: [PATCH] settings: track visible state as regular connection flags We already need to re-emit the notify::flags signal. It's cumbersome to do this for boolean properties, so re-use the flags to also track the visibility state. --- src/nm-policy.c | 14 ++++++------ src/settings/nm-settings-connection.c | 32 +++++++-------------------- src/settings/nm-settings-connection.h | 14 +++++++----- src/settings/nm-settings.c | 25 --------------------- src/settings/nm-settings.h | 1 - 5 files changed, 24 insertions(+), 62 deletions(-) diff --git a/src/nm-policy.c b/src/nm-policy.c index 5a0b148cd5..ded84cc2e4 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -2375,9 +2375,9 @@ connection_removed (NMSettings *settings, } static void -connection_visibility_changed (NMSettings *settings, - NMSettingsConnection *connection, - gpointer user_data) +connection_flags_changed (NMSettings *settings, + NMSettingsConnection *connection, + gpointer user_data) { NMPolicyPrivate *priv = user_data; NMPolicy *self = _PRIV_TO_SELF (priv); @@ -2560,10 +2560,10 @@ constructed (GObject *object) g_signal_connect (priv->manager, NM_MANAGER_ACTIVE_CONNECTION_ADDED, (GCallback) active_connection_added, priv); g_signal_connect (priv->manager, NM_MANAGER_ACTIVE_CONNECTION_REMOVED, (GCallback) active_connection_removed, priv); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, (GCallback) connection_added, priv); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, (GCallback) connection_updated, priv); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, (GCallback) connection_removed, priv); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED, (GCallback) connection_visibility_changed, priv); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, (GCallback) connection_added, priv); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, (GCallback) connection_updated, priv); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, (GCallback) connection_removed, priv); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_FLAGS_CHANGED, (GCallback) connection_flags_changed, priv); g_signal_connect (priv->agent_mgr, NM_AGENT_MANAGER_AGENT_REGISTERED, G_CALLBACK (secret_agent_registered), self); diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 55afb4e60a..e0b4616cca 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -53,7 +53,6 @@ static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface); NM_GOBJECT_PROPERTIES_DEFINE (NMSettingsConnection, - PROP_VISIBLE, PROP_UNSAVED, PROP_READY, PROP_FLAGS, @@ -75,14 +74,11 @@ typedef struct _NMSettingsConnectionPrivate { NMSessionMonitor *session_monitor; gulong session_changed_id; - NMSettingsConnectionFlags flags; + NMSettingsConnectionFlags flags:5; bool removed:1; bool ready:1; - /* Is this connection visible by some session? */ - bool visible:1; - bool timestamp_set:1; NMSettingsAutoconnectBlockedReason autoconnect_blocked_reason:4; @@ -323,12 +319,9 @@ find_secret (NMConnection *self, static void set_visible (NMSettingsConnection *self, gboolean new_visible) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); - - if (new_visible == priv->visible) - return; - priv->visible = new_visible; - _notify (self, PROP_VISIBLE); + nm_settings_connection_set_flags (self, + NM_SETTINGS_CONNECTION_FLAGS_VISIBLE, + new_visible); } gboolean @@ -336,7 +329,7 @@ nm_settings_connection_is_visible (NMSettingsConnection *self) { g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE); - return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->visible; + return NM_FLAGS_HAS (NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->flags, NM_SETTINGS_CONNECTION_FLAGS_VISIBLE); } void @@ -404,7 +397,7 @@ nm_settings_connection_check_permission (NMSettingsConnection *self, priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); - if (priv->visible == FALSE) + if (!nm_settings_connection_is_visible (self)) return FALSE; s_con = nm_connection_get_setting_connection (NM_CONNECTION (self)); @@ -2187,6 +2180,7 @@ NM_UTILS_FLAGS2STR_DEFINE_STATIC (_settings_connection_flags_to_string, NMSettin NM_UTILS_FLAGS2STR (NM_SETTINGS_CONNECTION_FLAGS_UNSAVED, "unsaved"), NM_UTILS_FLAGS2STR (NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED, "nm-generatd"), NM_UTILS_FLAGS2STR (NM_SETTINGS_CONNECTION_FLAGS_VOLATILE, "volatile"), + NM_UTILS_FLAGS2STR (NM_SETTINGS_CONNECTION_FLAGS_VISIBLE, "visible"), ); NMSettingsConnectionFlags @@ -2231,6 +2225,7 @@ nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConn _settings_connection_flags_to_string (flags, buf1, sizeof (buf1)), _settings_connection_flags_to_string (priv->flags, buf2, sizeof (buf2))); priv->flags = flags; + nm_assert (priv->flags == flags); _notify (self, PROP_FLAGS); if (NM_FLAGS_HAS (old_flags, NM_SETTINGS_CONNECTION_FLAGS_UNSAVED) != NM_FLAGS_HAS (flags, NM_SETTINGS_CONNECTION_FLAGS_UNSAVED)) _notify (self, PROP_UNSAVED); @@ -2868,7 +2863,6 @@ nm_settings_connection_init (NMSettingsConnection *self) priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_SETTINGS_CONNECTION, NMSettingsConnectionPrivate); self->_priv = priv; - priv->visible = FALSE; priv->ready = TRUE; c_list_init (&priv->call_ids_lst_head); @@ -2946,12 +2940,8 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMSettingsConnection *self = NM_SETTINGS_CONNECTION (object); - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); switch (prop_id) { - case PROP_VISIBLE: - g_value_set_boolean (value, priv->visible); - break; case PROP_UNSAVED: g_value_set_boolean (value, nm_settings_connection_get_unsaved (self)); break; @@ -3004,12 +2994,6 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class) class->supports_secrets = supports_secrets; - obj_properties[PROP_VISIBLE] = - g_param_spec_boolean (NM_SETTINGS_CONNECTION_VISIBLE, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); - obj_properties[PROP_UNSAVED] = g_param_spec_boolean (NM_SETTINGS_CONNECTION_UNSAVED, "", "", FALSE, diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 80acf359a9..5f4d9e6aa6 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -44,8 +44,9 @@ #define NM_SETTINGS_CONNECTION_UPDATED_INTERNAL "updated-internal" /* Properties */ -#define NM_SETTINGS_CONNECTION_VISIBLE "visible" #define NM_SETTINGS_CONNECTION_UNSAVED "unsaved" + +/* Internal properties */ #define NM_SETTINGS_CONNECTION_READY "ready" #define NM_SETTINGS_CONNECTION_FLAGS "flags" #define NM_SETTINGS_CONNECTION_FILENAME "filename" @@ -61,16 +62,19 @@ * @NM_SETTINGS_CONNECTION_FLAGS_VOLATILE: The connection will be deleted * when it disconnects. That is for in-memory connections (unsaved), which are * currently active but cleanup on disconnect. + * @NM_SETTINGS_CONNECTION_FLAGS_VISIBLE: The connection is visible * @NM_SETTINGS_CONNECTION_FLAGS_ALL: special mask, for all known flags * * #NMSettingsConnection flags. **/ typedef enum { - NM_SETTINGS_CONNECTION_FLAGS_NONE = 0x00, + NM_SETTINGS_CONNECTION_FLAGS_NONE = 0, - NM_SETTINGS_CONNECTION_FLAGS_UNSAVED = 0x01, - NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED = 0x02, - NM_SETTINGS_CONNECTION_FLAGS_VOLATILE = 0x04, + NM_SETTINGS_CONNECTION_FLAGS_UNSAVED = (1LL << 0), + NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED = (1LL << 1), + NM_SETTINGS_CONNECTION_FLAGS_VOLATILE = (1LL << 2), + + NM_SETTINGS_CONNECTION_FLAGS_VISIBLE = (1LL << 3), __NM_SETTINGS_CONNECTION_FLAGS_LAST, NM_SETTINGS_CONNECTION_FLAGS_ALL = ((__NM_SETTINGS_CONNECTION_FLAGS_LAST - 1) << 1) - 1, diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index a3175d2754..21fdf9e067 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -121,7 +121,6 @@ enum { CONNECTION_ADDED, CONNECTION_UPDATED, CONNECTION_REMOVED, - CONNECTION_VISIBILITY_CHANGED, CONNECTION_FLAGS_CHANGED, NEW_CONNECTION, /* exported, not used internally */ LAST_SIGNAL @@ -820,18 +819,6 @@ connection_updated (NMSettingsConnection *connection, gboolean by_user, gpointer by_user); } -static void -connection_visibility_changed (NMSettingsConnection *connection, - GParamSpec *pspec, - gpointer user_data) -{ - /* Re-emit for listeners like NMPolicy */ - g_signal_emit (NM_SETTINGS (user_data), - signals[CONNECTION_VISIBILITY_CHANGED], - 0, - connection); -} - static void connection_flags_changed (NMSettingsConnection *connection, GParamSpec *pspec, @@ -861,7 +848,6 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data) g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_removed), self); g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_updated), self); - g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_visibility_changed), self); g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_flags_changed), self); if (!priv->startup_complete) g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_ready_changed), self); @@ -986,9 +972,6 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection) G_CALLBACK (connection_removed), self); g_signal_connect (connection, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL, G_CALLBACK (connection_updated), self); - g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_VISIBLE, - G_CALLBACK (connection_visibility_changed), - self); g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_FLAGS, G_CALLBACK (connection_flags_changed), self); @@ -2003,14 +1986,6 @@ nm_settings_class_init (NMSettingsClass *class) g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); - signals[CONNECTION_VISIBILITY_CHANGED] = - g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); - signals[CONNECTION_FLAGS_CHANGED] = g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_FLAGS_CHANGED, G_OBJECT_CLASS_TYPE (object_class), diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index cd56aa8ca0..0ecffb708a 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -46,7 +46,6 @@ #define NM_SETTINGS_SIGNAL_CONNECTION_ADDED "connection-added" #define NM_SETTINGS_SIGNAL_CONNECTION_UPDATED "connection-updated" #define NM_SETTINGS_SIGNAL_CONNECTION_REMOVED "connection-removed" -#define NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED "connection-visibility-changed" #define NM_SETTINGS_SIGNAL_CONNECTION_FLAGS_CHANGED "connection-flags-changed" /**