1/* -*- Mode: C; c-basic-offset: 4 -*-
2 * pygobject - Python bindings for GObject
3 * Copyright (C) 2008  Johan Dahlin
4 * Copyright (C) 2009  Gian Mario Tagliaretti
5 *
6 *   gdrive.override: module overrides for GDrive and related types
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
22 */
23
24%%
25override g_drive_get_volumes noargs
26static PyObject *
27_wrap_g_drive_get_volumes (PyGObject *self)
28{
29  GList *list, *l;
30  PyObject *ret;
31
32  pyg_begin_allow_threads;
33
34  list = g_drive_get_volumes (G_DRIVE (self->obj));
35
36  pyg_end_allow_threads;
37
38  ret = PyList_New(0);
39  for (l = list; l; l = l->next) {
40    GVolume *volume = l->data;
41    PyObject *item = pygobject_new((GObject *)volume);
42    PyList_Append(ret, item);
43    Py_DECREF(item);
44    g_object_unref(volume);
45  }
46  g_list_free(list);
47
48  return ret;
49}
50%%
51override g_drive_eject kwargs
52static PyObject *
53_wrap_g_drive_eject(PyGObject *self, PyObject *args, PyObject *kwargs)
54{
55    static char *kwlist[] = { "callback", "flags", "cancellable", "user_data", NULL };
56    PyGIONotify *notify;
57    PyObject *py_flags = NULL;
58    GMountUnmountFlags flags = G_MOUNT_UNMOUNT_NONE;
59    PyGObject *py_cancellable = NULL;
60    GCancellable *cancellable;
61
62    notify = pygio_notify_new();
63
64    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
65                                     "O|OOO:gio.Drive.eject",
66				     kwlist,
67				     &notify->callback,
68				     &py_flags,
69				     &py_cancellable,
70				     &notify->data))
71        goto error;
72
73    if (PyErr_Warn(PyExc_DeprecationWarning,
74                   "gio.Drive.ejectis deprecated, \
75                   use gtk.Drive.eject_with_operation instead") < 0)
76        return NULL;
77
78    if (!pygio_notify_callback_is_valid(notify))
79        goto error;
80
81    if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_UNMOUNT_FLAGS,
82					py_flags, (gpointer) &flags))
83        goto error;
84
85    if (!pygio_check_cancellable(py_cancellable, &cancellable))
86        goto error;
87
88    pygio_notify_reference_callback(notify);
89
90    g_drive_eject(G_DRIVE(self->obj),
91		  flags,
92		  cancellable,
93		  (GAsyncReadyCallback) async_result_callback_marshal,
94		  notify);
95
96    Py_INCREF(Py_None);
97    return Py_None;
98
99 error:
100    pygio_notify_free(notify);
101    return NULL;
102}
103%%
104override g_drive_poll_for_media kwargs
105static PyObject *
106_wrap_g_drive_poll_for_media(PyGObject *self, PyObject *args, PyObject *kwargs)
107{
108    static char *kwlist[] = { "callback", "cancellable", "user_data", NULL };
109    PyGIONotify *notify;
110    PyGObject *py_cancellable = NULL;
111    GCancellable *cancellable;
112
113    notify = pygio_notify_new();
114
115    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
116                                     "O|OO:gio.Drive.eject",
117				     kwlist,
118				     &notify->callback,
119				     &py_cancellable,
120				     &notify->data))
121        goto error;
122
123    if (!pygio_notify_callback_is_valid(notify))
124        goto error;
125
126    if (!pygio_check_cancellable(py_cancellable, &cancellable))
127        goto error;
128
129    pygio_notify_reference_callback(notify);
130
131    pyg_begin_allow_threads;
132
133    g_drive_poll_for_media(G_DRIVE(self->obj),
134			   cancellable,
135			   (GAsyncReadyCallback) async_result_callback_marshal,
136			   notify);
137
138    pyg_end_allow_threads;
139
140    Py_INCREF(Py_None);
141    return Py_None;
142
143 error:
144    pygio_notify_free(notify);
145    return NULL;
146}
147%%
148override-slot GDrive.tp_repr
149static PyObject *
150_wrap_g_drive_tp_repr(PyGObject *self)
151{
152    char *name = g_drive_get_name(G_DRIVE(self->obj));
153    gchar *representation;
154    PyObject *result;
155
156    if (name) {
157	representation = g_strdup_printf("<%s at %p: %s>", self->ob_type->tp_name, self, name);
158	g_free(name);
159    }
160    else
161	representation = g_strdup_printf("<%s at %p: UNKNOWN NAME>", self->ob_type->tp_name, self);
162
163    result = PyString_FromString(representation);
164    g_free(representation);
165    return result;
166}
167%%
168override g_drive_enumerate_identifiers noargs
169static PyObject *
170_wrap_g_drive_enumerate_identifiers (PyGObject *self)
171{
172    char **ids;
173    PyObject *ret;
174
175    pyg_begin_allow_threads;
176
177    ids = g_drive_enumerate_identifiers(G_DRIVE (self->obj));
178
179    pyg_end_allow_threads;
180
181    if (ids && ids[0] != NULL) {
182	ret = strv_to_pylist(ids);
183	g_strfreev (ids);
184    } else {
185	ret = Py_None;
186	Py_INCREF(ret);
187    }
188    return ret;
189}
190%%
191override g_drive_eject_with_operation kwargs
192static PyObject *
193_wrap_g_drive_eject_with_operation(PyGObject *self,
194                                   PyObject *args,
195                                   PyObject *kwargs)
196{
197    static char *kwlist[] = { "callback", "flags", "mount_operation",
198                              "cancellable", "user_data", NULL };
199    PyGIONotify *notify;
200    PyObject *py_flags = NULL;
201    PyGObject *mount_operation;
202    GMountUnmountFlags flags = G_MOUNT_UNMOUNT_NONE;
203    PyGObject *py_cancellable = NULL;
204    GCancellable *cancellable;
205
206    notify = pygio_notify_new();
207
208    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
209                                     "O|OOOO:gio.Drive.eject_with_operation",
210                                     kwlist,
211                                     &notify->callback,
212                                     &py_flags,
213                                     &mount_operation,
214                                     &py_cancellable,
215                                     &notify->data))
216        goto error;
217
218    if (!pygio_notify_callback_is_valid(notify))
219        goto error;
220
221    if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_UNMOUNT_FLAGS,
222                                        py_flags, (gpointer) &flags))
223        goto error;
224
225    if (!pygio_check_cancellable(py_cancellable, &cancellable))
226        goto error;
227
228    pygio_notify_reference_callback(notify);
229
230    g_drive_eject_with_operation(G_DRIVE(self->obj),
231                          flags,
232                          G_MOUNT_OPERATION(mount_operation->obj),
233                          cancellable,
234                          (GAsyncReadyCallback) async_result_callback_marshal,
235                          notify);
236
237    Py_INCREF(Py_None);
238    return Py_None;
239
240 error:
241    pygio_notify_free(notify);
242    return NULL;
243}
244%%
245override g_drive_start kwargs
246static PyObject *
247_wrap_g_drive_start(PyGObject *self, PyObject *args, PyObject *kwargs)
248{
249    static char *kwlist[] = { "callback", "flags", "mount_operation",
250                              "cancellable", "user_data", NULL };
251    PyGIONotify *notify;
252    PyObject *py_flags = NULL;
253    PyGObject *mount_operation;
254    GDriveStartFlags flags = G_DRIVE_START_NONE;
255    PyGObject *py_cancellable = NULL;
256    GCancellable *cancellable;
257
258    notify = pygio_notify_new();
259
260    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
261                                     "O|OOOO:gio.Drive.start",
262                                     kwlist,
263                                     &notify->callback,
264                                     &py_flags,
265                                     &mount_operation,
266                                     &py_cancellable,
267                                     &notify->data))
268        goto error;
269
270    if (!pygio_notify_callback_is_valid(notify))
271        goto error;
272
273    if (py_flags && pyg_flags_get_value(G_TYPE_DRIVE_START_FLAGS,
274                                        py_flags, (gpointer) &flags))
275        goto error;
276
277    if (!pygio_check_cancellable(py_cancellable, &cancellable))
278        goto error;
279
280    pygio_notify_reference_callback(notify);
281
282    g_drive_start(G_DRIVE(self->obj),
283                  flags,
284                  G_MOUNT_OPERATION(mount_operation->obj),
285                  cancellable,
286                  (GAsyncReadyCallback) async_result_callback_marshal,
287                  notify);
288
289    Py_INCREF(Py_None);
290    return Py_None;
291
292 error:
293    pygio_notify_free(notify);
294    return NULL;
295}
296%%
297override g_drive_stop kwargs
298static PyObject *
299_wrap_g_drive_stop(PyGObject *self, PyObject *args, PyObject *kwargs)
300{
301    static char *kwlist[] = { "callback", "flags", "mount_operation",
302                              "cancellable", "user_data", NULL };
303    PyGIONotify *notify;
304    PyObject *py_flags = NULL;
305    PyGObject *mount_operation;
306    GMountUnmountFlags flags = G_MOUNT_UNMOUNT_NONE;
307    PyGObject *py_cancellable = NULL;
308    GCancellable *cancellable;
309
310    notify = pygio_notify_new();
311
312    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
313                                     "O|OOOO:gio.Drive.stop",
314                                     kwlist,
315                                     &notify->callback,
316                                     &py_flags,
317                                     &mount_operation,
318                                     &py_cancellable,
319                                     &notify->data))
320        goto error;
321
322    if (!pygio_notify_callback_is_valid(notify))
323        goto error;
324
325    if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_UNMOUNT_FLAGS,
326                                        py_flags, (gpointer) &flags))
327        goto error;
328
329    if (!pygio_check_cancellable(py_cancellable, &cancellable))
330        goto error;
331
332    pygio_notify_reference_callback(notify);
333
334    g_drive_stop(G_DRIVE(self->obj),
335                 flags,
336                 G_MOUNT_OPERATION(mount_operation->obj),
337                 cancellable,
338                 (GAsyncReadyCallback) async_result_callback_marshal,
339                 notify);
340
341    Py_INCREF(Py_None);
342    return Py_None;
343
344 error:
345    pygio_notify_free(notify);
346    return NULL;
347}
348