Added. Added. Added. Added.
[platform/upstream/glib.git] / gio / gvolumemonitor.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include <config.h>
24 #include "gvolumemonitor.h"
25 #include "glibintl.h"
26
27 #include "gioalias.h"
28
29 /**
30  * SECTION:gvolumemonitor
31  * @short_description: Volume Monitor
32  * @see_also: #GDirectoryMonitor, #GFileMonitor
33  * 
34  * Monitors a mounted volume for changes.
35  *
36  **/
37
38 G_DEFINE_TYPE (GVolumeMonitor, g_volume_monitor, G_TYPE_OBJECT);
39
40 enum {
41   VOLUME_MOUNTED,
42   VOLUME_PRE_UNMOUNT,
43   VOLUME_UNMOUNTED,
44   DRIVE_CONNECTED,
45   DRIVE_DISCONNECTED,
46   LAST_SIGNAL
47 };
48
49 static guint signals[LAST_SIGNAL] = { 0 };
50
51
52 static void
53 g_volume_monitor_finalize (GObject *object)
54 {
55   GVolumeMonitor *monitor;
56
57   monitor = G_VOLUME_MONITOR (object);
58
59   if (G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize)
60     (*G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize) (object);
61 }
62
63 static void
64 g_volume_monitor_class_init (GVolumeMonitorClass *klass)
65 {
66   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
67   
68   gobject_class->finalize = g_volume_monitor_finalize;
69
70   /**
71    * GVolumeMonitor::volume-mounted:   
72    * @volume_monitor: The volume monitor emitting the signal.
73    * @volume: the volume that was mounted.
74    *
75    * Emitted when a volume is mounted.
76    **/
77   signals[VOLUME_MOUNTED] = g_signal_new (I_("volume_mounted"),
78                                           G_TYPE_VOLUME_MONITOR,
79                                           G_SIGNAL_RUN_LAST,
80                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_mounted),
81                                           NULL, NULL,
82                                           g_cclosure_marshal_VOID__OBJECT,
83                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
84   /**
85    * GVolumeMonitor::volume-pre-unmount:
86    * @volume_monitor: The volume monitor emitting the signal.
87    * @volume: the volume that is being unmounted.
88    *
89    * Emitted when a volume is about to be unmounted.
90    **/ 
91   signals[VOLUME_PRE_UNMOUNT] = g_signal_new (I_("volume_pre_unmount"),
92                                               G_TYPE_VOLUME_MONITOR,
93                                               G_SIGNAL_RUN_LAST,
94                                               G_STRUCT_OFFSET (GVolumeMonitorClass, volume_pre_unmount),
95                                               NULL, NULL,
96                                               g_cclosure_marshal_VOID__OBJECT,
97                                               G_TYPE_NONE, 1, G_TYPE_VOLUME);
98   /**
99    * GVolumeMonitor::volume-unmounted:
100    * @volume_monitor: The volume monitor emitting the signal.
101    * @volume: the volume that was unmounted.
102    * 
103    * Emitted when a volume is unmounted.
104    **/  
105   signals[VOLUME_UNMOUNTED] = g_signal_new (I_("volume_unmounted"),
106                                             G_TYPE_VOLUME_MONITOR,
107                                             G_SIGNAL_RUN_LAST,
108                                             G_STRUCT_OFFSET (GVolumeMonitorClass, volume_unmounted),
109                                             NULL, NULL,
110                                             g_cclosure_marshal_VOID__OBJECT,
111                                             G_TYPE_NONE, 1, G_TYPE_VOLUME);
112   /**
113    * GVolumeMonitor::drive-connected:
114    * @volume_monitor: The volume monitor emitting the signal.
115    * @drive: a #GDrive that was connected.
116    * 
117    * Emitted when a drive is connected to the system.
118    **/
119   signals[DRIVE_CONNECTED] = g_signal_new (I_("drive_connected"),
120                                            G_TYPE_VOLUME_MONITOR,
121                                            G_SIGNAL_RUN_LAST,
122                                            G_STRUCT_OFFSET (GVolumeMonitorClass, drive_connected),
123                                            NULL, NULL,
124                                            g_cclosure_marshal_VOID__OBJECT,
125                                            G_TYPE_NONE, 1, G_TYPE_DRIVE);
126   
127   /**
128    * GVolumeMonitor::drive-disconnected:
129    * @volume_monitor: The volume monitor emitting the signal.
130    * @drive: a #GDrive that was disconnected.
131    * 
132    * Emitted when a drive is disconnected from the system.
133    **/  
134   signals[DRIVE_DISCONNECTED] = g_signal_new (I_("drive_disconnected"),
135                                               G_TYPE_VOLUME_MONITOR,
136                                               G_SIGNAL_RUN_LAST,
137                                               G_STRUCT_OFFSET (GVolumeMonitorClass, drive_disconnected),
138                                               NULL, NULL,
139                                               g_cclosure_marshal_VOID__OBJECT,
140                                               G_TYPE_NONE, 1, G_TYPE_DRIVE);
141 }
142
143 static void
144 g_volume_monitor_init (GVolumeMonitor *monitor)
145 {
146 }
147
148 /**
149  * g_volume_monitor_get_mounted_volumes:
150  * @volume_monitor: a #GVolumeMonitor.
151  * 
152  * Gets a list of volumes mounted on the computer.
153  * 
154  * Returns: a #GList of mounted #GVolumes.
155  **/
156 GList *
157 g_volume_monitor_get_mounted_volumes  (GVolumeMonitor *volume_monitor)
158 {
159   GVolumeMonitorClass *class;
160
161   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
162
163   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
164
165   return class->get_mounted_volumes (volume_monitor);
166 }
167
168 /**
169  * g_volume_monitor_get_connected_drives:
170  * @volume_monitor: a #GVolumeMonitor.
171  * 
172  * Gets a list of drives connected to the computer.
173  * 
174  * Returns: a #GList of connected #GDrives. 
175  **/
176 GList *
177 g_volume_monitor_get_connected_drives (GVolumeMonitor *volume_monitor)
178 {
179   GVolumeMonitorClass *class;
180
181   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
182
183   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
184
185   return class->get_connected_drives (volume_monitor);
186 }
187
188 #define __G_VOLUME_MONITOR_C__
189 #include "gioaliasdef.c"