static void list_drives (GList *drives, int indent) { GList *volumes, *l; int c, i; GDrive *drive; char *name; char **ids; GIcon *icon; for (c = 0, l = drives; l != NULL; l = l->next, c++) { drive = (GDrive *) l->data; name = g_drive_get_name (drive); g_print ("%*sDrive(%d): %s\n", indent, "", c, name); g_free (name); if (mount_list_info) { ids = g_drive_enumerate_identifiers (drive); if (ids && ids[0] != NULL) { g_print ("%*sids:\n", indent+2, ""); for (i = 0; ids[i] != NULL; i++) { char *id = g_drive_get_identifier (drive, ids[i]); g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); g_free (id); } } g_strfreev (ids); icon = g_drive_get_icon (drive); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive)); g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive)); g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive)); g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive)); } volumes = g_drive_get_volumes (drive); list_volumes (volumes, indent + 2, FALSE); g_list_foreach (volumes, (GFunc)g_object_unref, NULL); g_list_free (volumes); } }
static void list_drives (GList *drives, int indent) { GList *volumes, *l; int c, i; GDrive *drive; char *name; char **ids; GIcon *icon; char *type_name; const gchar *sort_key; for (c = 0, l = drives; l != NULL; l = l->next, c++) { drive = (GDrive *) l->data; name = g_drive_get_name (drive); g_print ("%*sDrive(%d): %s\n", indent, "", c, name); g_free (name); type_name = get_type_name (drive); g_print ("%*sType: %s\n", indent+2, "", type_name); g_free (type_name); if (extra_detail) { GEnumValue *enum_value; gpointer klass; ids = g_drive_enumerate_identifiers (drive); if (ids && ids[0] != NULL) { g_print ("%*sids:\n", indent+2, ""); for (i = 0; ids[i] != NULL; i++) { char *id = g_drive_get_identifier (drive, ids[i]); g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); g_free (id); } } g_strfreev (ids); icon = g_drive_get_icon (drive); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive)); g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive)); g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive)); g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive)); g_print ("%*scan_start=%d\n", indent + 2, "", g_drive_can_start (drive)); g_print ("%*scan_stop=%d\n", indent + 2, "", g_drive_can_stop (drive)); enum_value = NULL; klass = g_type_class_ref (G_TYPE_DRIVE_START_STOP_TYPE); if (klass != NULL) { enum_value = g_enum_get_value (klass, g_drive_get_start_stop_type (drive)); g_print ("%*sstart_stop_type=%s\n", indent + 2, "", enum_value != NULL ? enum_value->value_nick : "UNKNOWN"); g_type_class_unref (klass); } sort_key = g_drive_get_sort_key (drive); if (sort_key != NULL) g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); } volumes = g_drive_get_volumes (drive); list_volumes (volumes, indent + 2, FALSE); g_list_foreach (volumes, (GFunc)g_object_unref, NULL); g_list_free (volumes); } }
/* this is loosely based on update_places() from caja-places-sidebar.c */ static void panel_place_menu_item_append_local_gio (PanelPlaceMenuItem *place_item, GtkWidget *menu) { GList *l; GList *ll; GList *drives; GDrive *drive; GList *volumes; GVolume *volume; GList *mounts; GMount *mount; GSList *items; GSList *sl; PanelGioItem *item; GtkWidget *add_menu; items = NULL; /* first go through all connected drives */ drives = g_volume_monitor_get_connected_drives (place_item->priv->volume_monitor); for (l = drives; l != NULL; l = l->next) { drive = l->data; volumes = g_drive_get_volumes (drive); if (volumes != NULL) { for (ll = volumes; ll != NULL; ll = ll->next) { volume = ll->data; mount = g_volume_get_mount (volume); item = g_slice_new (PanelGioItem); if (mount != NULL) { item->type = PANEL_GIO_MOUNT; item->u.mount = mount; } else { /* Do show the unmounted volumes; this * is so the user can mount it (in case * automounting is off). * * Also, even if automounting is * enabled, this gives a visual cue * that the user should remember to * yank out the media if he just * unmounted it. */ item->type = PANEL_GIO_VOLUME; item->u.volume = g_object_ref (volume); } items = g_slist_prepend (items, item); g_object_unref (volume); } g_list_free (volumes); } else { if (g_drive_is_media_removable (drive) && !g_drive_is_media_check_automatic (drive)) { /* If the drive has no mountable volumes and we * cannot detect media change.. we display the * drive so the user can manually poll the * drive by clicking on it..." * * This is mainly for drives like floppies * where media detection doesn't work.. but * it's also for human beings who like to turn * off media detection in the OS to save * battery juice. */ item = g_slice_new (PanelGioItem); item->type = PANEL_GIO_DRIVE; item->u.drive = g_object_ref (drive); items = g_slist_prepend (items, item); } } g_object_unref (drive); } g_list_free (drives); /* add all volumes that is not associated with a drive */ volumes = g_volume_monitor_get_volumes (place_item->priv->volume_monitor); for (l = volumes; l != NULL; l = l->next) { volume = l->data; drive = g_volume_get_drive (volume); if (drive != NULL) { g_object_unref (volume); g_object_unref (drive); continue; } mount = g_volume_get_mount (volume); item = g_slice_new (PanelGioItem); if (mount != NULL) { item->type = PANEL_GIO_MOUNT; item->u.mount = mount; } else { /* see comment above in why we add an icon for an * unmounted mountable volume */ item->type = PANEL_GIO_VOLUME; item->u.volume = g_object_ref (volume); } items = g_slist_prepend (items, item); g_object_unref (volume); } g_list_free (volumes); /* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */ mounts = g_volume_monitor_get_mounts (place_item->priv->volume_monitor); for (l = mounts; l != NULL; l = l->next) { GFile *root; mount = l->data; if (g_mount_is_shadowed (mount)) { g_object_unref (mount); continue; } volume = g_mount_get_volume (mount); if (volume != NULL) { g_object_unref (volume); g_object_unref (mount); continue; } root = g_mount_get_root (mount); if (!g_file_is_native (root)) { g_object_unref (root); g_object_unref (mount); continue; } g_object_unref (root); item = g_slice_new (PanelGioItem); item->type = PANEL_GIO_MOUNT; item->u.mount = mount; items = g_slist_prepend (items, item); } g_list_free (mounts); /* now that we have everything, add the items inline or in a submenu */ items = g_slist_reverse (items); if (g_slist_length (items) <= MAX_ITEMS_OR_SUBMENU) { add_menu = menu; } else { GtkWidget *item; item = gtk_image_menu_item_new (); setup_menu_item_with_icon (item, panel_menu_icon_get_size (), PANEL_ICON_REMOVABLE_MEDIA, NULL, NULL, _("Removable Media")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); add_menu = create_empty_menu (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), add_menu); } for (sl = items; sl; sl = sl->next) { item = sl->data; switch (item->type) { case PANEL_GIO_DRIVE: panel_menu_item_append_drive (add_menu, item->u.drive); g_object_unref (item->u.drive); break; case PANEL_GIO_VOLUME: panel_menu_item_append_volume (add_menu, item->u.volume); g_object_unref (item->u.volume); break; case PANEL_GIO_MOUNT: panel_menu_item_append_mount (add_menu, item->u.mount); g_object_unref (item->u.mount); break; default: g_assert_not_reached (); } g_slice_free (PanelGioItem, item); } g_slist_free (items); }