source: trunk/third/gnome-vfs2/test/test-volumes.c @ 20794

Revision 20794, 3.4 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20793, which included commits to RCS files with non-trunk default branches.
Line 
1#include <libgnomevfs/gnome-vfs.h>
2#include <libgnomevfs/gnome-vfs-volume-monitor.h>
3#include <libgnomevfs/gnome-vfs-volume.h>
4
5static GMainLoop *loop;
6
7static void
8print_volume (GnomeVFSVolume *volume)
9{
10        char *path, *uri, *name, *icon;
11        GnomeVFSDrive *drive;
12
13        path = gnome_vfs_volume_get_device_path (volume);
14        uri = gnome_vfs_volume_get_activation_uri (volume);
15        icon = gnome_vfs_volume_get_icon (volume);
16        name = gnome_vfs_volume_get_display_name (volume);
17        drive = gnome_vfs_volume_get_drive (volume);
18        g_print ("vol(%p)[dev: %s, mount: %s, device type: %d, handles_trash: %d, icon: %s, name: %s, user_visible: %d, drive: %p]\n",
19                 volume,
20                 path?path:"(nil)",
21                 uri,
22                 gnome_vfs_volume_get_device_type (volume),
23                 gnome_vfs_volume_handles_trash (volume),
24                 icon,
25                 name,
26                 gnome_vfs_volume_is_user_visible (volume),
27                 drive);
28        g_free (path);
29        g_free (uri);
30        g_free (icon);
31        g_free (name);
32        gnome_vfs_drive_unref (drive);
33}
34
35static void
36print_drive (GnomeVFSDrive *drive)
37{
38        char *path, *uri, *name, *icon;
39        GnomeVFSVolume *volume;
40
41        path = gnome_vfs_drive_get_device_path (drive);
42        uri = gnome_vfs_drive_get_activation_uri (drive);
43        icon = gnome_vfs_drive_get_icon (drive);
44        name = gnome_vfs_drive_get_display_name (drive);
45        volume = gnome_vfs_drive_get_mounted_volume (drive);
46       
47        g_print ("drive(%p)[dev: %s, mount: %s, device type: %d, icon: %s, name: %s, user_visible: %d, volume: %p]\n",
48                 drive,
49                 path?path:"(nil)",
50                 uri,
51                 gnome_vfs_drive_get_device_type (drive),
52                 icon,
53                 name,
54                 gnome_vfs_drive_is_user_visible (drive),
55                 volume);
56        g_free (path);
57        g_free (uri);
58        g_free (icon);
59        g_free (name);
60        gnome_vfs_volume_unref (volume);
61}
62
63static void
64volume_mounted (GnomeVFSVolumeMonitor *volume_monitor,
65                GnomeVFSVolume         *volume)
66{
67        g_print ("Volume mounted: ");
68        print_volume (volume);
69}
70
71static void
72volume_unmounted (GnomeVFSVolumeMonitor *volume_monitor,
73                  GnomeVFSVolume               *volume)
74{
75        g_print ("Volume unmounted: ");
76        print_volume (volume);
77}
78
79static void
80drive_connected (GnomeVFSVolumeMonitor *volume_monitor,
81                 GnomeVFSDrive         *drive)
82{
83        g_print ("drive connected: ");
84        print_drive (drive);
85}
86
87static void
88drive_disconnected (GnomeVFSVolumeMonitor *volume_monitor,
89                    GnomeVFSDrive              *drive)
90{
91        g_print ("drive disconnected: ");
92        print_drive (drive);
93}
94
95int
96main (int argc, char *argv[])
97{
98  GnomeVFSVolumeMonitor *monitor;
99  GList *l, *volumes, *drives;
100 
101  gnome_vfs_init ();
102
103  monitor = gnome_vfs_get_volume_monitor ();
104
105  g_signal_connect (monitor, "volume_mounted",
106                    G_CALLBACK (volume_mounted), NULL);
107  g_signal_connect (monitor, "volume_unmounted",
108                    G_CALLBACK (volume_unmounted), NULL);
109  g_signal_connect (monitor, "drive_connected",
110                    G_CALLBACK (drive_connected), NULL);
111  g_signal_connect (monitor, "drive_disconnected",
112                    G_CALLBACK (drive_disconnected), NULL);
113 
114  volumes = gnome_vfs_volume_monitor_get_mounted_volumes (monitor);
115
116  g_print ("Mounted volumes:\n");
117  for (l = volumes; l != NULL; l = l->next) {
118          print_volume (l->data);
119          gnome_vfs_volume_unref (l->data);
120  }
121  g_list_free (volumes);
122
123  drives = gnome_vfs_volume_monitor_get_connected_drives (monitor);
124
125  g_print ("Connected drives:\n");
126  for (l = drives; l != NULL; l = l->next) {
127          print_drive (l->data);
128          gnome_vfs_drive_unref (l->data);
129  }
130  g_list_free (drives);
131
132  g_print ("Waiting for volume events:\n");
133  loop = g_main_loop_new (NULL, FALSE);
134  g_main_loop_run (loop);
135 
136  gnome_vfs_shutdown ();
137 
138  return 0;
139}
Note: See TracBrowser for help on using the repository browser.