void init_ASMount(ASFlagType flags, const char *cmd) { memset( &AppState, 0x00, sizeof(AppState)); AppState.flags = flags ; AppState.tileWidth = DEFAULT_TILE_WIDTH; AppState.tileHeight = DEFAULT_TILE_HEIGHT; createMainWindow(); reloadButtons(); AppState.volumes = create_asbidirlist (ASVolume_destroy); g_type_init(); GVolumeMonitor * monitor = g_volume_monitor_get(); g_signal_connect_object (monitor, "mount-added", G_CALLBACK (mount_added), NULL, 0); g_signal_connect_object (monitor, "mount-changed", G_CALLBACK (mount_changed), NULL, 0); g_signal_connect_object (monitor, "mount-removed", G_CALLBACK (mount_removed), NULL, 0); g_signal_connect_object (monitor, "volume-added", G_CALLBACK (volume_added), NULL, 0); g_signal_connect_object (monitor, "volume-changed", G_CALLBACK (volume_changed), NULL, 0); g_signal_connect_object (monitor, "volume-removed", G_CALLBACK (volume_removed), NULL, 0); GList *tmp; GList *list = g_volume_monitor_get_volumes(G_VOLUME_MONITOR(monitor)); show_activity ("Adding volumes..."); for (tmp = list; tmp != NULL; tmp = tmp->next) { ASVolume *v = ASVolume_newGVolume (tmp->data); if (v) append_bidirelem (AppState.volumes, v); else g_object_unref (tmp->data); } g_list_free (list); #if 1 show_activity ("Adding mounts..."); list = g_volume_monitor_get_mounts(G_VOLUME_MONITOR(monitor)); for (tmp = list; tmp != NULL; tmp = tmp->next) { ASVolume *v = ASVolume_newGMount (tmp->data); if (v) append_bidirelem (AppState.volumes, v); else g_object_unref (tmp->data); } g_list_free (list); #endif AppState.volumeMonitor = monitor; redecorateVolumes (); }
GVolumeMonitor * _g_unix_volume_monitor_new (void) { GUnixVolumeMonitor *monitor; monitor = g_object_new (G_TYPE_UNIX_VOLUME_MONITOR, NULL); return G_VOLUME_MONITOR (monitor); }
static void update_mounts (GUnixVolumeMonitor *monitor) { GList *new_mounts; GList *removed, *added; GList *l; GUnixMount *mount; GUnixVolume *volume; const char *mount_path; new_mounts = g_unix_mounts_get (NULL); new_mounts = g_list_sort (new_mounts, (GCompareFunc) g_unix_mount_compare); diff_sorted_lists (monitor->last_mounts, new_mounts, (GCompareFunc) g_unix_mount_compare, &added, &removed); for (l = removed; l != NULL; l = l->next) { GUnixMountEntry *mount_entry = l->data; mount = find_mount_by_mountpath (monitor, g_unix_mount_get_mount_path (mount_entry)); if (mount) { _g_unix_mount_unmounted (mount); monitor->mounts = g_list_remove (monitor->mounts, mount); g_signal_emit_by_name (monitor, "mount-removed", mount); g_signal_emit_by_name (mount, "unmounted"); g_object_unref (mount); } } for (l = added; l != NULL; l = l->next) { GUnixMountEntry *mount_entry = l->data; mount_path = g_unix_mount_get_mount_path (mount_entry); volume = _g_unix_volume_monitor_lookup_volume_for_mount_path (monitor, mount_path); mount = _g_unix_mount_new (G_VOLUME_MONITOR (monitor), mount_entry, volume); if (mount) { monitor->mounts = g_list_prepend (monitor->mounts, mount); g_signal_emit_by_name (monitor, "mount-added", mount); } } g_list_free (added); g_list_free (removed); g_list_foreach (monitor->last_mounts, (GFunc)g_unix_mount_free, NULL); g_list_free (monitor->last_mounts); monitor->last_mounts = new_mounts; }
/** * g_volume_monitor_get: * * Gets the volume monitor used by gio. * * Returns: (transfer full): a reference to the #GVolumeMonitor used by gio. Call * g_object_unref() when done with it. **/ GVolumeMonitor * g_volume_monitor_get (void) { GVolumeMonitor *vm; g_rec_mutex_lock (&the_volume_monitor_mutex); if (the_volume_monitor) vm = G_VOLUME_MONITOR (g_object_ref (the_volume_monitor)); else { the_volume_monitor = g_union_volume_monitor_new (); populate_union_monitor (the_volume_monitor); vm = G_VOLUME_MONITOR (the_volume_monitor); } g_rec_mutex_unlock (&the_volume_monitor_mutex); return vm; }
static void update_volumes (GUnixVolumeMonitor *monitor) { GList *new_mountpoints; GList *removed, *added; GList *l; GUnixVolume *volume; new_mountpoints = g_unix_mount_points_get (NULL); new_mountpoints = g_list_sort (new_mountpoints, (GCompareFunc) g_unix_mount_point_compare); diff_sorted_lists (monitor->last_mountpoints, new_mountpoints, (GCompareFunc) g_unix_mount_point_compare, &added, &removed); for (l = removed; l != NULL; l = l->next) { GUnixMountPoint *mountpoint = l->data; volume = _g_unix_volume_monitor_lookup_volume_for_mount_path (monitor, g_unix_mount_point_get_mount_path (mountpoint)); if (volume) { _g_unix_volume_disconnected (volume); monitor->volumes = g_list_remove (monitor->volumes, volume); g_signal_emit_by_name (monitor, "volume-removed", volume); g_signal_emit_by_name (volume, "removed"); g_object_unref (volume); } } for (l = added; l != NULL; l = l->next) { GUnixMountPoint *mountpoint = l->data; volume = _g_unix_volume_new (G_VOLUME_MONITOR (monitor), mountpoint); if (volume) { monitor->volumes = g_list_prepend (monitor->volumes, volume); g_signal_emit_by_name (monitor, "volume-added", volume); } } g_list_free (added); g_list_free (removed); g_list_foreach (monitor->last_mountpoints, (GFunc)g_unix_mount_point_free, NULL); g_list_free (monitor->last_mountpoints); monitor->last_mountpoints = new_mountpoints; }
static GList* g_udisks_drive_get_volumes (GDrive* base) { /* FIXME: is it a better idea to save all volumes in GUDisksDrive instead? */ GUDisksDrive* drv = G_UDISKS_DRIVE(base); GList* vols = g_volume_monitor_get_volumes(G_VOLUME_MONITOR(drv->mon)); GList* l; GList* ret = NULL; for(l = vols;l;l=l->next) { GUDisksVolume* vol = G_UDISKS_VOLUME(l->data); if(vol->drive == drv) ret = g_list_prepend(ret, vol); else g_object_unref(vol); } g_list_free(vols); return ret; }