info: Make free space checking async

https://bugzilla.gnome.org/show_bug.cgi?id=647125
This commit is contained in:
Bastien Nocera 2011-04-08 13:27:50 +01:00
parent adb74f26d3
commit c22a98dcb7
2 changed files with 80 additions and 24 deletions

View file

@ -62,6 +62,11 @@ struct _CcInfoPanelPrivate
gboolean updates_available; gboolean updates_available;
gboolean is_fallback; gboolean is_fallback;
/* Free space */
GList *primary_mounts;
guint64 total_bytes;
GCancellable *cancellable;
GDBusConnection *session_bus; GDBusConnection *session_bus;
GDBusProxy *pk_proxy; GDBusProxy *pk_proxy;
GDBusProxy *pk_transaction_proxy; GDBusProxy *pk_transaction_proxy;
@ -70,6 +75,8 @@ struct _CcInfoPanelPrivate
GraphicsData *graphics_data; GraphicsData *graphics_data;
}; };
static void get_primary_disc_info_start (CcInfoPanel *self);
typedef struct typedef struct
{ {
char *major; char *major;
@ -488,6 +495,11 @@ cc_info_panel_finalize (GObject *object)
{ {
CcInfoPanelPrivate *priv = CC_INFO_PANEL (object)->priv; CcInfoPanelPrivate *priv = CC_INFO_PANEL (object)->priv;
if (priv->cancellable != NULL)
{
g_cancellable_cancel (priv->cancellable);
priv->cancellable = NULL;
}
g_free (priv->gnome_version); g_free (priv->gnome_version);
g_free (priv->gnome_date); g_free (priv->gnome_date);
g_free (priv->gnome_distributor); g_free (priv->gnome_distributor);
@ -577,21 +589,79 @@ format_size_for_display (goffset size)
} }
} }
static char * static void
get_primary_disc_info (void) query_done (GFile *file,
GAsyncResult *res,
CcInfoPanel *self)
{
GFileInfo *info;
GError *error = NULL;
self->priv->cancellable = NULL;
info = g_file_query_filesystem_info_finish (file, res, &error);
if (info == NULL)
{
char *path;
path = g_file_get_path (file);
g_warning ("Failed to get filesystem free space for '%s': %s", path, error->message);
g_free (path);
g_error_free (error);
return;
}
self->priv->total_bytes += g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
g_object_unref (info);
/* And onto the next element */
get_primary_disc_info_start (self);
}
static void
get_primary_disc_info_start (CcInfoPanel *self)
{
GUnixMountEntry *mount;
GFile *file;
if (self->priv->primary_mounts == NULL)
{
char *size;
GtkWidget *widget;
size = format_size_for_display (self->priv->total_bytes);
widget = WID (self->priv->builder, "disk_label");
gtk_label_set_text (GTK_LABEL (widget), size);
g_free (size);
return;
}
mount = self->priv->primary_mounts->data;
self->priv->primary_mounts = g_list_remove (self->priv->primary_mounts, mount);
file = g_file_new_for_path (g_unix_mount_get_mount_path (mount));
g_unix_mount_free (mount);
self->priv->cancellable = g_cancellable_new ();
g_file_query_filesystem_info_async (file,
G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
0,
self->priv->cancellable,
(GAsyncReadyCallback) query_done,
self);
g_object_unref (file);
}
static void
get_primary_disc_info (CcInfoPanel *self)
{ {
guint64 total_bytes;
GList *points; GList *points;
GList *p; GList *p;
total_bytes = 0;
points = g_unix_mount_points_get (NULL); points = g_unix_mount_points_get (NULL);
for (p = points; p != NULL; p = p->next) for (p = points; p != NULL; p = p->next)
{ {
GUnixMountEntry *mount = p->data; GUnixMountEntry *mount = p->data;
const char *mount_path; const char *mount_path;
struct statfs buf;
mount_path = g_unix_mount_get_mount_path (mount); mount_path = g_unix_mount_get_mount_path (mount);
@ -602,22 +672,11 @@ get_primary_disc_info (void)
continue; continue;
} }
if (statfs (mount_path, &buf) < 0) self->priv->primary_mounts = g_list_prepend (self->priv->primary_mounts, mount);
{
g_warning ("Unable to stat / filesystem: %s", g_strerror (errno));
g_unix_mount_free (mount);
continue;
}
else
{
total_bytes += (guint64) buf.f_blocks * buf.f_bsize;
}
g_unix_mount_free (mount);
} }
g_list_free (points); g_list_free (points);
return format_size_for_display (total_bytes); get_primary_disc_info_start (self);
} }
static char * static char *
@ -1016,10 +1075,7 @@ info_panel_setup_overview (CcInfoPanel *self)
gtk_label_set_text (GTK_LABEL (widget), text ? text : ""); gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
g_free (text); g_free (text);
widget = WID (self->priv->builder, "disk_label"); get_primary_disc_info (self);
text = get_primary_disc_info ();
gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
g_free (text);
widget = WID (self->priv->builder, "graphics_label"); widget = WID (self->priv->builder, "graphics_label");
gtk_label_set_markup (GTK_LABEL (widget), self->priv->graphics_data->hardware_string); gtk_label_set_markup (GTK_LABEL (widget), self->priv->graphics_data->hardware_string);

View file

@ -228,7 +228,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label">Unknown</property> <property name="label" translatable="yes">Calculating...</property>
<property name="selectable">True</property> <property name="selectable">True</property>
</object> </object>
<packing> <packing>