107
99
image = gtk_image_new ();
108
slab_load_image (GTK_IMAGE (image), GTK_ICON_SIZE_BUTTON, "gnome-dev-harddisk");
100
slab_load_image (GTK_IMAGE (image), GTK_ICON_SIZE_BUTTON, "utilities-system-monitor");
110
name = g_strdup (_("Hard _Drive"));
102
name = g_strdup (_("_System Monitor"));
112
104
header = gtk_label_new (name);
113
105
gtk_label_set_use_underline (GTK_LABEL (header), TRUE);
148
140
hard_drive_status_tile_init (HardDriveStatusTile * tile)
150
142
HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile);
153
priv->hal_context = libhal_ctx_new ();
155
if (!priv->hal_context)
158
dbus_error_init (&error);
159
priv->dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
161
dbus_connection_set_exit_on_disconnect (priv->dbus_connection, FALSE);
163
if (dbus_error_is_set (&error))
165
g_warning ("error (%s): [%s]\n", error.name, error.message);
167
dbus_error_free (&error);
169
priv->hal_context = NULL;
170
priv->dbus_connection = NULL;
175
dbus_error_free (&error);
177
dbus_connection_setup_with_g_main (priv->dbus_connection, g_main_context_default ());
179
libhal_ctx_set_dbus_connection (priv->hal_context, priv->dbus_connection);
181
dbus_error_init (&error);
182
libhal_ctx_init (priv->hal_context, &error);
184
if (dbus_error_is_set (&error))
186
g_warning ("error (%s): [%s]\n", error.name, error.message);
188
dbus_error_free (&error);
190
priv->hal_context = NULL;
195
dbus_error_free (&error);
197
144
priv->gconf = gconf_client_get_default ();
198
145
gconf_client_add_dir (priv->gconf, TIMEOUT_KEY_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL);
242
187
tile_trigger_action_with_time (tile, tile->default_action, event->time);
246
get_pertinent_devices (LibHalContext * hal_context)
263
dbus_error_init (&error);
264
udis = libhal_find_device_by_capability (hal_context, "volume", &n_udis, &error);
266
if (dbus_error_is_set (&error))
268
g_warning ("error (%s): [%s]\n", error.name, error.message);
270
dbus_error_free (&error);
275
dbus_error_free (&error);
279
for (i = 0; i < n_udis; ++i)
281
vol = libhal_volume_from_udi (hal_context, udis[i]);
283
if (libhal_volume_is_mounted (vol) && !libhal_volume_is_disc (vol))
285
mount_point = g_strdup (libhal_volume_get_mount_point (vol));
286
devices = g_list_append (devices, mount_point);
289
libhal_volume_free (vol);
292
libhal_free_string_array (udis);
298
191
compute_usage (HardDriveStatusTile * tile)
300
193
HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile);
303
glibtop_fsusage fs_usage;
307
if (!priv->hal_context)
196
if (statvfs (g_get_home_dir (), &s) != 0) {
197
priv->available_bytes = 0;
198
priv->capacity_bytes = 0;
310
devices = get_pertinent_devices (priv->hal_context);
312
priv->capacity_bytes = 0;
313
priv->available_bytes = 0;
315
for (node = devices; node; node = node->next)
319
glibtop_get_fsusage (&fs_usage, (gchar *) node->data);
321
priv->available_bytes += fs_usage.bfree * fs_usage.block_size;
322
priv->capacity_bytes += fs_usage.blocks * fs_usage.block_size;
328
g_list_free (devices);
202
priv->available_bytes = (gdouble)s.f_frsize * s.f_bavail;
203
priv->capacity_bytes = (gdouble)s.f_frsize * s.f_blocks;
332
size_bytes_to_string (guint64 size)
207
size_bytes_to_string (gdouble size)
334
209
gchar *size_string;
335
unsigned long long size_bytes;
337
/* FIXME: this is just a work around for gcc warnings about %lu not big enough
338
* to hold guint64 on 32bit machines. on 64bit machines, however, gcc warns
339
* that %llu is too big for guint64. ho-hum.
342
size_bytes = (unsigned long long) size;
344
if (size_bytes > GIGA)
345
size_string = g_strdup_printf (_("%lluG"), size_bytes / GIGA);
346
else if (size_bytes > MEGA)
347
size_string = g_strdup_printf (_("%lluM"), size_bytes / MEGA);
348
else if (size_bytes > KILO)
349
size_string = g_strdup_printf (_("%lluK"), size_bytes / KILO);
212
size_string = g_strdup_printf (_("%.1fG"), size / GIGA);
213
else if (size > MEGA)
214
size_string = g_strdup_printf (_("%.1fM"), size / MEGA);
215
else if (size > KILO)
216
size_string = g_strdup_printf (_("%.1fK"), size / KILO);
351
size_string = g_strdup_printf (_("%llub"), size_bytes);
218
size_string = g_strdup_printf (_("%.1fb"), size);
353
220
return size_string;