~ubuntu-branches/ubuntu/trusty/gnome-python/trusty

« back to all changes in this revision

Viewing changes to gnomevfs/vfs-drive.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-12-02 12:30:09 UTC
  • Revision ID: james.westby@ubuntu.com-20051202123009-z00n5h4uuwfo64ev
Tags: upstream-2.12.2
ImportĀ upstreamĀ versionĀ 2.12.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-basic-offset: 4 -*- */
 
2
 
 
3
#include "pygnomevfs-private.h"
 
4
#define NO_IMPORT_PYGOBJECT
 
5
#include <pygobject.h>
 
6
 
 
7
 
 
8
static PyObject *
 
9
pygvdrive_get_id(PyGObject *self)
 
10
{
 
11
    return PyLong_FromUnsignedLong(gnome_vfs_drive_get_id(GNOME_VFS_DRIVE(self->obj)));
 
12
}
 
13
 
 
14
static PyObject *
 
15
pygvdrive_get_device_type(PyGObject *self)
 
16
{
 
17
    return PyInt_FromLong(gnome_vfs_drive_get_device_type(GNOME_VFS_DRIVE(self->obj)));
 
18
}
 
19
 
 
20
static PyObject *
 
21
pygvdrive_get_mounted_volumes(PyGObject *self)
 
22
{
 
23
    GList *volumes, *l;
 
24
    PyObject *pyvolumes = PyList_New(0);
 
25
    
 
26
    for (volumes = l = gnome_vfs_drive_get_mounted_volumes(GNOME_VFS_DRIVE(self->obj));
 
27
         l; l = l->next)
 
28
    {
 
29
        GnomeVFSVolume *volume = GNOME_VFS_VOLUME(l->data);
 
30
        PyObject *pyvol = pygobject_new((GObject *)volume);
 
31
        PyList_Append(pyvolumes, pyvol);
 
32
        Py_DECREF(pyvol);
 
33
    }
 
34
    gnome_vfs_drive_volume_list_free(volumes);
 
35
    return pyvolumes;
 
36
}
 
37
 
 
38
static PyObject *
 
39
pygvdrive_get_device_path(PyGObject *self)
 
40
{
 
41
    char *retval;
 
42
 
 
43
    retval = gnome_vfs_drive_get_device_path(GNOME_VFS_DRIVE(self->obj));
 
44
    if (retval)
 
45
        return PyString_FromString(retval);
 
46
    else {
 
47
        Py_INCREF(Py_None);
 
48
        return Py_None;
 
49
    }
 
50
}
 
51
 
 
52
static PyObject *
 
53
pygvdrive_get_activation_uri(PyGObject *self)
 
54
{
 
55
    char *retval;
 
56
 
 
57
    retval = gnome_vfs_drive_get_activation_uri(GNOME_VFS_DRIVE(self->obj));
 
58
    if (retval)
 
59
        return PyString_FromString(retval);
 
60
    else {
 
61
        Py_INCREF(Py_None);
 
62
        return Py_None;
 
63
    }
 
64
}
 
65
 
 
66
 
 
67
static PyObject *
 
68
pygvdrive_get_display_name(PyGObject *self)
 
69
{
 
70
    char *retval;
 
71
 
 
72
    retval = gnome_vfs_drive_get_display_name(GNOME_VFS_DRIVE(self->obj));
 
73
    if (retval)
 
74
        return PyString_FromString(retval);
 
75
    else {
 
76
        Py_INCREF(Py_None);
 
77
        return Py_None;
 
78
    }
 
79
}
 
80
 
 
81
static PyObject *
 
82
pygvdrive_get_icon(PyGObject *self)
 
83
{
 
84
    char *retval;
 
85
 
 
86
    retval = gnome_vfs_drive_get_icon(GNOME_VFS_DRIVE(self->obj));
 
87
    if (retval)
 
88
        return PyString_FromString(retval);
 
89
    else {
 
90
        Py_INCREF(Py_None);
 
91
        return Py_None;
 
92
    }
 
93
}
 
94
 
 
95
static PyObject *
 
96
pygvdrive_get_hal_udi(PyGObject *self)
 
97
{
 
98
    char *retval;
 
99
 
 
100
    retval = gnome_vfs_drive_get_hal_udi(GNOME_VFS_DRIVE(self->obj));
 
101
    if (retval)
 
102
        return PyString_FromString(retval);
 
103
    else {
 
104
        Py_INCREF(Py_None);
 
105
        return Py_None;
 
106
    }
 
107
}
 
108
 
 
109
static PyObject *
 
110
pygvdrive_is_user_visible(PyGObject *self)
 
111
{
 
112
    gboolean retval;
 
113
 
 
114
    retval = gnome_vfs_drive_is_user_visible(GNOME_VFS_DRIVE(self->obj));
 
115
    if (retval) {
 
116
        Py_INCREF(Py_True);
 
117
        return Py_True;
 
118
    } else {
 
119
        Py_INCREF(Py_False);
 
120
        return Py_False;
 
121
    }
 
122
}
 
123
 
 
124
static PyObject *
 
125
pygvdrive_is_connected(PyGObject *self)
 
126
{
 
127
    gboolean retval;
 
128
 
 
129
    retval = gnome_vfs_drive_is_connected(GNOME_VFS_DRIVE(self->obj));
 
130
    if (retval) {
 
131
        Py_INCREF(Py_True);
 
132
        return Py_True;
 
133
    } else {
 
134
        Py_INCREF(Py_False);
 
135
        return Py_False;
 
136
    }
 
137
}
 
138
 
 
139
static PyObject *
 
140
pygvdrive_is_mounted(PyGObject *self)
 
141
{
 
142
    gboolean retval;
 
143
 
 
144
    retval = gnome_vfs_drive_is_mounted(GNOME_VFS_DRIVE(self->obj));
 
145
    if (retval) {
 
146
        Py_INCREF(Py_True);
 
147
        return Py_True;
 
148
    } else {
 
149
        Py_INCREF(Py_False);
 
150
        return Py_False;
 
151
    }
 
152
}
 
153
 
 
154
void
 
155
wrap_gnomevfs_volume_op_callback(gboolean succeeded,
 
156
                                 char *error,
 
157
                                 char *detailed_error,
 
158
                                 gpointer data)
 
159
{
 
160
    PyGnomeVFSVolumeOpCallback *context;
 
161
    PyObject *retval;
 
162
    PyGILState_STATE gil;
 
163
 
 
164
    context = (PyGnomeVFSVolumeOpCallback *) data;
 
165
    gil = pyg_gil_state_ensure();
 
166
    
 
167
    if (context->user_data)
 
168
        retval = PyEval_CallFunction(context->callback, "(OssO)",
 
169
                                     error, detailed_error,
 
170
                                     context->user_data);
 
171
    else
 
172
        retval = PyEval_CallFunction(context->callback, "(Oss)",
 
173
                                     error, detailed_error);
 
174
    if (!retval) {
 
175
        PyErr_Print();
 
176
        PyErr_Clear();
 
177
    }
 
178
    Py_XDECREF(retval);
 
179
 
 
180
    Py_DECREF(context->callback);
 
181
    Py_XDECREF(context->user_data);
 
182
    g_free(data);
 
183
 
 
184
    pyg_gil_state_release(gil);
 
185
}
 
186
 
 
187
 
 
188
static PyObject *
 
189
pygvdrive_mount(PyGObject *self, PyObject *args, PyObject *kwargs)
 
190
{
 
191
    static char *kwlist[] = { "callback", "user_data", NULL };
 
192
    PyObject *py_callback, *py_user_data = NULL;
 
193
    PyGnomeVFSVolumeOpCallback *callback_context;
 
194
 
 
195
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
196
                                     "O|O:gnomevfs.Drive.mount",
 
197
                                     kwlist, &py_callback, py_user_data))
 
198
        return NULL;
 
199
 
 
200
    if (!PyCallable_Check(py_callback)) {
 
201
        PyErr_SetString(PyExc_TypeError, "first argument must be callable");
 
202
        return NULL;
 
203
    }
 
204
 
 
205
    callback_context = g_new(PyGnomeVFSVolumeOpCallback, 1);
 
206
    callback_context->callback = py_callback;
 
207
    Py_INCREF(py_callback);
 
208
    callback_context->user_data = py_user_data;
 
209
    Py_XINCREF(py_user_data);
 
210
 
 
211
    gnome_vfs_drive_mount(GNOME_VFS_DRIVE(self->obj),
 
212
                          wrap_gnomevfs_volume_op_callback,
 
213
                          callback_context);
 
214
    Py_INCREF(Py_None);
 
215
    return Py_None;
 
216
}
 
217
 
 
218
 
 
219
static PyObject *
 
220
pygvdrive_unmount(PyGObject *self, PyObject *args, PyObject *kwargs)
 
221
{
 
222
    static char *kwlist[] = { "callback", "user_data", NULL };
 
223
    PyObject *py_callback, *py_user_data = NULL;
 
224
    PyGnomeVFSVolumeOpCallback *callback_context;
 
225
 
 
226
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
227
                                     "O|O:gnomevfs.Drive.unmount",
 
228
                                     kwlist, &py_callback, py_user_data))
 
229
        return NULL;
 
230
 
 
231
    if (!PyCallable_Check(py_callback)) {
 
232
        PyErr_SetString(PyExc_TypeError, "first argument must be callable");
 
233
        return NULL;
 
234
    }
 
235
 
 
236
    callback_context = g_new(PyGnomeVFSVolumeOpCallback, 1);
 
237
    callback_context->callback = py_callback;
 
238
    Py_INCREF(py_callback);
 
239
    callback_context->user_data = py_user_data;
 
240
    Py_XINCREF(py_user_data);
 
241
 
 
242
    gnome_vfs_drive_unmount(GNOME_VFS_DRIVE(self->obj),
 
243
                            wrap_gnomevfs_volume_op_callback,
 
244
                            callback_context);
 
245
    Py_INCREF(Py_None);
 
246
    return Py_None;
 
247
}
 
248
 
 
249
 
 
250
static PyObject *
 
251
pygvdrive_eject(PyGObject *self, PyObject *args, PyObject *kwargs)
 
252
{
 
253
    static char *kwlist[] = { "callback", "user_data", NULL };
 
254
    PyObject *py_callback, *py_user_data = NULL;
 
255
    PyGnomeVFSVolumeOpCallback *callback_context;
 
256
 
 
257
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
258
                                     "O|O:gnomevfs.Drive.eject",
 
259
                                     kwlist, &py_callback, py_user_data))
 
260
        return NULL;
 
261
 
 
262
    if (!PyCallable_Check(py_callback)) {
 
263
        PyErr_SetString(PyExc_TypeError, "first argument must be callable");
 
264
        return NULL;
 
265
    }
 
266
 
 
267
    callback_context = g_new(PyGnomeVFSVolumeOpCallback, 1);
 
268
    callback_context->callback = py_callback;
 
269
    Py_INCREF(py_callback);
 
270
    callback_context->user_data = py_user_data;
 
271
    Py_XINCREF(py_user_data);
 
272
 
 
273
    gnome_vfs_drive_eject(GNOME_VFS_DRIVE(self->obj),
 
274
                          wrap_gnomevfs_volume_op_callback,
 
275
                          callback_context);
 
276
    Py_INCREF(Py_None);
 
277
    return Py_None;
 
278
}
 
279
 
 
280
 
 
281
static PyMethodDef pygvdrive_methods[] = {
 
282
    { "get_id", (PyCFunction)pygvdrive_get_id, METH_NOARGS },
 
283
    { "get_device_type", (PyCFunction)pygvdrive_get_device_type, METH_NOARGS },
 
284
    { "get_mounted_volumes", (PyCFunction)pygvdrive_get_mounted_volumes, METH_NOARGS },
 
285
    { "get_device_path", (PyCFunction)pygvdrive_get_device_path, METH_NOARGS },
 
286
    { "get_activation_uri", (PyCFunction)pygvdrive_get_activation_uri, METH_NOARGS },
 
287
    { "get_display_name", (PyCFunction)pygvdrive_get_display_name, METH_NOARGS },
 
288
    { "get_icon", (PyCFunction)pygvdrive_get_icon, METH_NOARGS },
 
289
    { "get_hal_udi", (PyCFunction)pygvdrive_get_hal_udi, METH_NOARGS },
 
290
    { "is_user_visible", (PyCFunction)pygvdrive_is_user_visible, METH_NOARGS },
 
291
    { "is_connected", (PyCFunction)pygvdrive_is_connected, METH_NOARGS },
 
292
    { "is_mounted", (PyCFunction)pygvdrive_is_mounted, METH_NOARGS },
 
293
    { "mount", (PyCFunction)pygvdrive_mount, METH_VARARGS|METH_KEYWORDS },
 
294
    { "unmount", (PyCFunction)pygvdrive_unmount, METH_VARARGS|METH_KEYWORDS },
 
295
    { "eject", (PyCFunction)pygvdrive_eject, METH_VARARGS|METH_KEYWORDS },
 
296
    { NULL, NULL, 0 }
 
297
};
 
298
 
 
299
 
 
300
static int
 
301
pygvdrive_compare(PyGObject *self, PyGObject *other)
 
302
{
 
303
    return gnome_vfs_drive_compare(GNOME_VFS_DRIVE(self->obj),
 
304
                                   GNOME_VFS_DRIVE(other->obj));
 
305
}
 
306
 
 
307
 
 
308
PyTypeObject PyGnomeVFSDrive_Type = {
 
309
    PyObject_HEAD_INIT(NULL)
 
310
    0,                                  /* ob_size */
 
311
    "gnomevfs.Drive",                   /* tp_name */
 
312
    sizeof(PyGObject),                  /* tp_basicsize */
 
313
    0,                                  /* tp_itemsize */
 
314
    /* methods */
 
315
    (destructor)0,                      /* tp_dealloc */
 
316
    (printfunc)0,                       /* tp_print */
 
317
    (getattrfunc)0,                     /* tp_getattr */
 
318
    (setattrfunc)0,                     /* tp_setattr */
 
319
    (cmpfunc)pygvdrive_compare,         /* tp_compare */
 
320
    (reprfunc)0,                        /* tp_repr */
 
321
    0,                                  /* tp_as_number */
 
322
    0,                                  /* tp_as_sequence */
 
323
    0,                                  /* tp_as_mapping */
 
324
    (hashfunc)0,                        /* tp_hash */
 
325
    (ternaryfunc)0,                     /* tp_call */
 
326
    (reprfunc)0,                        /* tp_str */
 
327
    (getattrofunc)0,                    /* tp_getattro */
 
328
    (setattrofunc)0,                    /* tp_setattro */
 
329
    0,                                  /* tp_as_buffer */
 
330
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   /* tp_flags */
 
331
    NULL, /* Documentation string */
 
332
    (traverseproc)0,                    /* tp_traverse */
 
333
    (inquiry)0,                         /* tp_clear */
 
334
    (richcmpfunc)0,                     /* tp_richcompare */
 
335
    0,                                  /* tp_weaklistoffset */
 
336
    (getiterfunc)0,                     /* tp_iter */
 
337
    (iternextfunc)0,                    /* tp_iternext */
 
338
    pygvdrive_methods,                  /* tp_methods */
 
339
    0,                                  /* tp_members */
 
340
    0,                                  /* tp_getset */
 
341
    (PyTypeObject *)0,                  /* tp_base */
 
342
    (PyObject *)0,                      /* tp_dict */
 
343
    0,                                  /* tp_descr_get */
 
344
    0,                                  /* tp_descr_set */
 
345
    0,                                  /* tp_dictoffset */
 
346
    (initproc)0,                        /* tp_init */
 
347
    PyType_GenericAlloc,                /* tp_alloc */
 
348
    PyType_GenericNew,                  /* tp_new */
 
349
    0,                                  /* tp_free */
 
350
    (inquiry)0,                         /* tp_is_gc */
 
351
    (PyObject *)0,                      /* tp_bases */
 
352
};
 
353
 
 
354