mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 04:50:30 +01:00
libnm: add NMRemoteConnection:visible property
Rather than having a private "visible" signal, have a public "visible" property.
This commit is contained in:
parent
c4a86eba52
commit
d7e99f8375
4 changed files with 68 additions and 28 deletions
|
|
@ -355,6 +355,7 @@ global:
|
|||
nm_remote_connection_get_secrets;
|
||||
nm_remote_connection_get_type;
|
||||
nm_remote_connection_get_unsaved;
|
||||
nm_remote_connection_get_visible;
|
||||
nm_remote_connection_save;
|
||||
nm_remote_settings_add_connection;
|
||||
nm_remote_settings_add_connection_unsaved;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ enum {
|
|||
PROP_DBUS_CONNECTION,
|
||||
PROP_DBUS_PATH,
|
||||
PROP_UNSAVED,
|
||||
PROP_VISIBLE,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
|
@ -57,7 +58,6 @@ enum {
|
|||
enum {
|
||||
UPDATED,
|
||||
REMOVED,
|
||||
VISIBLE,
|
||||
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
|
@ -413,6 +413,30 @@ nm_remote_connection_get_unsaved (NMRemoteConnection *connection)
|
|||
return NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->unsaved;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_remote_connection_get_visible:
|
||||
* @connection: the #NMRemoteConnection
|
||||
*
|
||||
* Checks if the connection is visible to the current user. If the
|
||||
* connection is not visible then it is essentially useless; it will
|
||||
* not contain any settings, and operations such as
|
||||
* nm_remote_connection_save() and nm_remote_connection_delete() will
|
||||
* always fail. (#NMRemoteSettings will not normally return
|
||||
* non-visible connections to callers, but it is possible for a
|
||||
* connection's visibility to change after you already have a
|
||||
* reference to it.)
|
||||
*
|
||||
* Returns: %TRUE if the remote connection is visible to the current
|
||||
* user, %FALSE if not.
|
||||
**/
|
||||
gboolean
|
||||
nm_remote_connection_get_visible (NMRemoteConnection *connection)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
|
||||
|
||||
return NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->visible;
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
static void
|
||||
|
|
@ -443,6 +467,7 @@ updated_get_settings_cb (DBusGProxy *proxy,
|
|||
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
|
||||
GHashTable *new_settings;
|
||||
GError *error = NULL;
|
||||
gboolean visible;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings,
|
||||
|
|
@ -461,17 +486,17 @@ updated_get_settings_cb (DBusGProxy *proxy,
|
|||
nm_connection_replace_settings (NM_CONNECTION (self), hash, NULL);
|
||||
g_hash_table_destroy (hash);
|
||||
|
||||
priv->visible = FALSE;
|
||||
g_signal_emit (self, signals[VISIBLE], 0, FALSE);
|
||||
visible = FALSE;
|
||||
} else {
|
||||
replace_settings (self, new_settings);
|
||||
g_hash_table_destroy (new_settings);
|
||||
|
||||
/* Settings service will handle announcing the connection to clients */
|
||||
if (priv->visible == FALSE) {
|
||||
priv->visible = TRUE;
|
||||
g_signal_emit (self, signals[VISIBLE], 0, TRUE);
|
||||
}
|
||||
visible = TRUE;
|
||||
}
|
||||
|
||||
if (visible != priv->visible) {
|
||||
priv->visible = visible;
|
||||
g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -734,6 +759,9 @@ get_property (GObject *object, guint prop_id,
|
|||
case PROP_UNSAVED:
|
||||
g_value_set_boolean (value, NM_REMOTE_CONNECTION_GET_PRIVATE (object)->unsaved);
|
||||
break;
|
||||
case PROP_VISIBLE:
|
||||
g_value_set_boolean (value, NM_REMOTE_CONNECTION_GET_PRIVATE (object)->visible);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
@ -847,6 +875,24 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
|
|||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* NMRemoteConnection:visible:
|
||||
*
|
||||
* %TRUE if the remote connection is visible to the current user, %FALSE if
|
||||
* not. If the connection is not visible then it is essentially useless; it
|
||||
* will not contain any settings, and operations such as
|
||||
* nm_remote_connection_save() and nm_remote_connection_delete() will always
|
||||
* fail. (#NMRemoteSettings will not normally return non-visible connections
|
||||
* to callers, but it is possible for a connection's visibility to change
|
||||
* after you already have a reference to it.)
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_VISIBLE,
|
||||
g_param_spec_boolean (NM_REMOTE_CONNECTION_VISIBLE, "", "",
|
||||
FALSE,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* Signals */
|
||||
/**
|
||||
* NMRemoteConnection::updated:
|
||||
|
|
@ -879,15 +925,6 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
|
|||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
/* Private signal */
|
||||
signals[VISIBLE] =
|
||||
g_signal_new ("visible",
|
||||
G_TYPE_FROM_CLASS (remote_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0, NULL, NULL,
|
||||
g_cclosure_marshal_VOID__BOOLEAN,
|
||||
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ GQuark nm_remote_connection_error_quark (void);
|
|||
/* Properties */
|
||||
#define NM_REMOTE_CONNECTION_BUS "bus"
|
||||
#define NM_REMOTE_CONNECTION_UNSAVED "unsaved"
|
||||
#define NM_REMOTE_CONNECTION_VISIBLE "visible"
|
||||
|
||||
/* Signals */
|
||||
#define NM_REMOTE_CONNECTION_UPDATED "updated"
|
||||
|
|
@ -138,6 +139,8 @@ void nm_remote_connection_get_secrets (NMRemoteConnection *connection,
|
|||
|
||||
gboolean nm_remote_connection_get_unsaved (NMRemoteConnection *connection);
|
||||
|
||||
gboolean nm_remote_connection_get_visible (NMRemoteConnection *connection);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __NM_REMOTE_CONNECTION__ */
|
||||
|
|
|
|||
|
|
@ -349,9 +349,7 @@ connection_removed_cb (NMRemoteConnection *remote, gpointer user_data)
|
|||
g_hash_table_remove (priv->pending, path);
|
||||
}
|
||||
|
||||
static void connection_visible_cb (NMRemoteConnection *remote,
|
||||
gboolean visible,
|
||||
gpointer user_data);
|
||||
static void connection_visible_changed_cb (GObject *object, GParamSpec *spec, gpointer user_data);
|
||||
|
||||
/* Takes a reference to the connection when adding to 'to' */
|
||||
static void
|
||||
|
|
@ -378,21 +376,22 @@ move_connection (NMRemoteSettings *self,
|
|||
}
|
||||
|
||||
if (!g_signal_handler_find (remote, G_SIGNAL_MATCH_FUNC,
|
||||
0, 0, NULL, connection_visible_cb, NULL)) {
|
||||
0, 0, NULL, connection_visible_changed_cb, NULL)) {
|
||||
g_signal_connect (remote,
|
||||
"visible",
|
||||
G_CALLBACK (connection_visible_cb),
|
||||
"notify::" NM_REMOTE_CONNECTION_VISIBLE,
|
||||
G_CALLBACK (connection_visible_changed_cb),
|
||||
self);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
connection_visible_cb (NMRemoteConnection *remote,
|
||||
gboolean visible,
|
||||
gpointer user_data)
|
||||
connection_visible_changed_cb (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
|
||||
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
|
||||
NMRemoteConnection *remote = NM_REMOTE_CONNECTION (object);
|
||||
const char *path;
|
||||
|
||||
path = nm_connection_get_path (NM_CONNECTION (remote));
|
||||
|
|
@ -402,7 +401,7 @@ connection_visible_cb (NMRemoteConnection *remote,
|
|||
* hash until it becomes visible again. When it does, we move it back to
|
||||
* the normal connections hash.
|
||||
*/
|
||||
if (visible) {
|
||||
if (nm_remote_connection_get_visible (remote)) {
|
||||
/* Connection visible to this user again */
|
||||
if (g_hash_table_lookup (priv->pending, path)) {
|
||||
/* Move connection from pending to visible hash; emit for clients */
|
||||
|
|
@ -1091,7 +1090,7 @@ forget_connection (gpointer user_data)
|
|||
g_signal_handlers_disconnect_matched (remote, G_SIGNAL_MATCH_FUNC,
|
||||
0, 0, NULL, connection_removed_cb, NULL);
|
||||
g_signal_handlers_disconnect_matched (remote, G_SIGNAL_MATCH_FUNC,
|
||||
0, 0, NULL, connection_visible_cb, NULL);
|
||||
0, 0, NULL, connection_visible_changed_cb, NULL);
|
||||
g_object_unref (remote);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue