View | Details | Raw Unified | Return to bug 152846
Collapse All | Expand All

(-)a/main-menu/src/hard-drive-status-tile.c (-132 / +7 lines)
Lines 21-33 Link Here
21
#include "hard-drive-status-tile.h"
21
#include "hard-drive-status-tile.h"
22
22
23
#include <string.h>
23
#include <string.h>
24
#include <dbus/dbus.h>
24
#include <sys/statvfs.h>
25
#include <dbus/dbus-glib.h>
26
#include <dbus/dbus-glib-lowlevel.h>
27
#include <glib/gi18n.h>
25
#include <glib/gi18n.h>
28
#include <glibtop/fsusage.h>
29
#include <libhal.h>
30
#include <libhal-storage.h>
31
#include <gconf/gconf-client.h>
26
#include <gconf/gconf-client.h>
32
27
33
#include "slab-gnome-util.h"
28
#include "slab-gnome-util.h"
Lines 59-67 static void tile_show_event_cb (GtkWidget *, gpointer); Link Here
59
54
60
typedef struct
55
typedef struct
61
{
56
{
62
	LibHalContext *hal_context;
63
	DBusConnection *dbus_connection;
64
	
65
	GConfClient *gconf;
57
	GConfClient *gconf;
66
	
58
	
67
	guint64 capacity_bytes;
59
	guint64 capacity_bytes;
Lines 148-198 static void Link Here
148
hard_drive_status_tile_init (HardDriveStatusTile * tile)
140
hard_drive_status_tile_init (HardDriveStatusTile * tile)
149
{
141
{
150
	HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile);
142
	HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile);
151
	DBusError error;
152
153
	priv->hal_context = libhal_ctx_new ();
154
155
	if (!priv->hal_context)
156
		return;
157
158
	dbus_error_init (&error);
159
	priv->dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
160
161
	dbus_connection_set_exit_on_disconnect (priv->dbus_connection, FALSE);
162
163
	if (dbus_error_is_set (&error))
164
	{
165
		g_warning ("error (%s): [%s]\n", error.name, error.message);
166
167
		dbus_error_free (&error);
168
169
		priv->hal_context = NULL;
170
		priv->dbus_connection = NULL;
171
172
		return;
173
	}
174
175
	dbus_error_free (&error);
176
177
	dbus_connection_setup_with_g_main (priv->dbus_connection, g_main_context_default ());
178
179
	libhal_ctx_set_dbus_connection (priv->hal_context, priv->dbus_connection);
180
181
	dbus_error_init (&error);
182
	libhal_ctx_init (priv->hal_context, &error);
183
184
	if (dbus_error_is_set (&error))
185
	{
186
		g_warning ("error (%s): [%s]\n", error.name, error.message);
187
188
		dbus_error_free (&error);
189
190
		priv->hal_context = NULL;
191
192
		return;
193
	}
194
195
	dbus_error_free (&error);
196
143
197
	priv->gconf = gconf_client_get_default ();
144
	priv->gconf = gconf_client_get_default ();
198
	gconf_client_add_dir (priv->gconf, TIMEOUT_KEY_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL);
145
	gconf_client_add_dir (priv->gconf, TIMEOUT_KEY_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL);
Lines 201-208 hard_drive_status_tile_init (HardDriveStatusTile * tile) Link Here
201
static void
148
static void
202
hard_drive_status_tile_finalize (GObject * g_object)
149
hard_drive_status_tile_finalize (GObject * g_object)
203
{
150
{
204
/*	if (data->hal_context)
205
		libhal_ctx_free (data->hal_context); */
206
	/* FIXME */
151
	/* FIXME */
207
	(*G_OBJECT_CLASS (hard_drive_status_tile_parent_class)->finalize) (g_object);
152
	(*G_OBJECT_CLASS (hard_drive_status_tile_parent_class)->finalize) (g_object);
208
}
153
}
Lines 242-331 hard_drive_status_tile_activated (Tile * tile, TileEvent * event) Link Here
242
		tile_trigger_action_with_time (tile, tile->default_action, event->time);
187
		tile_trigger_action_with_time (tile, tile->default_action, event->time);
243
}
188
}
244
189
245
static GList *
246
get_pertinent_devices (LibHalContext * hal_context)
247
{
248
	GList *devices;
249
250
	gchar **udis;
251
	gint n_udis;
252
253
	LibHalVolume *vol;
254
	gchar *mount_point;
255
256
	DBusError error;
257
258
	gint i;
259
260
	if (!hal_context)
261
		return NULL;
262
263
	dbus_error_init (&error);
264
	udis = libhal_find_device_by_capability (hal_context, "volume", &n_udis, &error);
265
266
	if (dbus_error_is_set (&error))
267
	{
268
		g_warning ("error (%s): [%s]\n", error.name, error.message);
269
270
		dbus_error_free (&error);
271
272
		return NULL;
273
	}
274
275
	dbus_error_free (&error);
276
277
	devices = NULL;
278
279
	for (i = 0; i < n_udis; ++i)
280
	{
281
		vol = libhal_volume_from_udi (hal_context, udis[i]);
282
283
		if (libhal_volume_is_mounted (vol) && !libhal_volume_is_disc (vol))
284
		{
285
			mount_point = g_strdup (libhal_volume_get_mount_point (vol));
286
			devices = g_list_append (devices, mount_point);
287
		}
288
289
		libhal_volume_free (vol);
290
	}
291
292
	libhal_free_string_array (udis);
293
294
	return devices;
295
}
296
297
static void
190
static void
298
compute_usage (HardDriveStatusTile * tile)
191
compute_usage (HardDriveStatusTile * tile)
299
{
192
{
300
	HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile);
193
	HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile);
194
	struct statvfs s;
301
195
302
	GList *devices;
196
	if (statvfs (g_get_home_dir (), &s) != 0) {
303
	glibtop_fsusage fs_usage;
197
		priv->available_bytes = 0;
304
198
		priv->capacity_bytes = 0;
305
	GList *node;
306
307
	if (!priv->hal_context)
308
		return;
199
		return;
309
310
	devices = get_pertinent_devices (priv->hal_context);
311
312
	priv->capacity_bytes = 0;
313
	priv->available_bytes = 0;
314
315
	for (node = devices; node; node = node->next)
316
	{
317
		if (node->data)
318
		{
319
			glibtop_get_fsusage (&fs_usage, (gchar *) node->data);
320
321
			priv->available_bytes += fs_usage.bfree * fs_usage.block_size;
322
			priv->capacity_bytes += fs_usage.blocks * fs_usage.block_size;
323
324
			g_free (node->data);
325
		}
326
	}
200
	}
327
201
328
	g_list_free (devices);
202
	priv->available_bytes = (guint64) s.f_frsize * s.f_bavail;
203
	priv->capacity_bytes = (guint64) s.f_frsize * s.f_blocks;
329
}
204
}
330
205
331
static gchar *
206
static gchar *

Return to bug 152846