places-view: monitor network

GtkPlacesView exposes local access points and network
shares transparently by using the 'network:///' URI,
which is handled by GIO.

Currently, however, it doesn't monitor the network
for new available points, such as computers that just
join the network. It may happen too that the backend
won't find all the networks before the network enumeration
finishes.

Fix that by keeping a file monitor inspecting the network
uri, and update the places list when that happens.

https://bugzilla.gnome.org/show_bug.cgi?id=781162
This commit is contained in:
Georges Basile Stavracas Neto
2017-04-10 18:59:33 -03:00
parent 6e87915b05
commit dfb5d11a53

View File

@@ -56,6 +56,7 @@ struct _GtkPlacesViewPrivate
GFile *server_list_file;
GFileMonitor *server_list_monitor;
GFileMonitor *network_monitor;
GCancellable *cancellable;
@@ -397,6 +398,7 @@ gtk_places_view_destroy (GtkWidget *widget)
priv->destroyed = 1;
g_signal_handlers_disconnect_by_func (priv->volume_monitor, update_places, widget);
g_signal_handlers_disconnect_by_func (priv->network_monitor, update_places, widget);
g_cancellable_cancel (priv->cancellable);
g_cancellable_cancel (priv->networks_fetching_cancellable);
@@ -417,6 +419,7 @@ gtk_places_view_finalize (GObject *object)
g_clear_object (&priv->server_list_file);
g_clear_object (&priv->server_list_monitor);
g_clear_object (&priv->volume_monitor);
g_clear_object (&priv->network_monitor);
g_clear_object (&priv->cancellable);
g_clear_object (&priv->networks_fetching_cancellable);
g_clear_object (&priv->path_size_group);
@@ -901,6 +904,40 @@ update_network_state (GtkPlacesView *view)
}
}
static void
monitor_network (GtkPlacesView *self)
{
GtkPlacesViewPrivate *priv;
GFile *network_file;
GError *error;
priv = gtk_places_view_get_instance_private (self);
if (priv->network_monitor)
return;
error = NULL;
network_file = g_file_new_for_uri ("network:///");
priv->network_monitor = g_file_monitor (network_file,
G_FILE_MONITOR_NONE,
NULL,
&error);
g_clear_object (&network_file);
if (error)
{
g_warning ("Error monitoring network: %s", error->message);
g_clear_error (&error);
return;
}
g_signal_connect_swapped (priv->network_monitor,
"changed",
G_CALLBACK (update_places),
self);
}
static void
populate_networks (GtkPlacesView *view,
GFileEnumerator *enumerator,
@@ -974,6 +1011,7 @@ network_enumeration_next_files_finished (GObject *source_object,
if (!priv->destroyed)
{
update_network_state (view);
monitor_network (view);
update_loading (view);
}
}