nautilus-python-object.c 20.6 KB
Newer Older
Johan Dahlin's avatar
Johan Dahlin committed
1 2
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
3
 *  Copyright (C) 2004,2005 Johan Dahlin
Johan Dahlin's avatar
Johan Dahlin committed
4
 *
5 6 7 8
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
Johan Dahlin's avatar
Johan Dahlin committed
9
 *
10
 *  This program is distributed in the hope that it will be useful,
Johan Dahlin's avatar
Johan Dahlin committed
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
Johan Dahlin's avatar
Johan Dahlin committed
14
 *
15 16 17
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
Johan Dahlin's avatar
Johan Dahlin committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 */

#include <config.h>

#include "nautilus-python-object.h"
#include "nautilus-python.h"

#include <libnautilus-extension/nautilus-extension-types.h>

#include <pygobject.h>

/* Nautilus extension headers */
#include <libnautilus-extension/nautilus-file-info.h>
#include <libnautilus-extension/nautilus-info-provider.h>
#include <libnautilus-extension/nautilus-column-provider.h>
33
#include <libnautilus-extension/nautilus-location-widget-provider.h>
Johan Dahlin's avatar
Johan Dahlin committed
34 35 36 37 38 39 40 41 42 43
#include <libnautilus-extension/nautilus-menu-item.h>
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <libnautilus-extension/nautilus-property-page-provider.h>

#include <string.h>

#define METHOD_PREFIX ""

static GObjectClass *parent_class;

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
int __PyString_Check(PyObject *obj) {
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_Check(obj);
#else
    return PyString_Check(obj);
#endif
}

char* __PyString_AsString(PyObject *obj) {
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_AsUTF8(obj);
#else
    return PyString_AsString(obj);
#endif
}

PyObject* __PyString_FromString(const char *c) {
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromString(c);
#else
    return PyString_FromString(c);
#endif
}

int __PyInt_Check(PyObject *obj) {
#if PY_MAJOR_VERSION >= 3
    return PyLong_Check(obj);
#else
    return PyInt_Check(obj);
#endif
}

Johan Dahlin's avatar
Johan Dahlin committed
76 77 78 79 80 81 82
/* These macros assumes the following things:
 *   a METHOD_NAME is defined with is a string
 *   a goto label called beach
 *   the return value is called ret
 */

#define CHECK_METHOD_NAME(self)                                        \
Adam Plumb's avatar
Adam Plumb committed
83 84
    if (!PyObject_HasAttrString(self, METHOD_NAME))                    \
        goto beach;
85

Adam Plumb's avatar
Adam Plumb committed
86 87 88 89 90 91
#define CHECK_OBJECT(object)                                           \
      if (object->instance == NULL)                                       \
      {                                                                   \
          g_object_unref (object);                                       \
          goto beach;                                                       \
      }                                                                   \
92

Johan Dahlin's avatar
Johan Dahlin committed
93
#define CONVERT_LIST(py_files, files)                                  \
Adam Plumb's avatar
Adam Plumb committed
94 95
    {                                                                  \
        GList *l;                                                      \
Johan Dahlin's avatar
Johan Dahlin committed
96
        py_files = PyList_New(0);                                      \
Adam Plumb's avatar
Adam Plumb committed
97 98 99 100 101
        for (l = files; l; l = l->next)                                \
        {                                                              \
            PyList_Append(py_files, pygobject_new((GObject*)l->data)); \
        }                                                              \
    }
Johan Dahlin's avatar
Johan Dahlin committed
102 103

#define HANDLE_RETVAL(py_ret)                                          \
104 105 106
    if (!py_ret)                                                       \
    {                                                                  \
        PyErr_Print();                                                 \
Adam Plumb's avatar
Adam Plumb committed
107 108 109 110 111 112
        goto beach;                                                    \
    }                                                                  \
    else if (py_ret == Py_None)                                        \
    {                                                                  \
        goto beach;                                                    \
    }
Johan Dahlin's avatar
Johan Dahlin committed
113 114 115

#define HANDLE_LIST(py_ret, type, type_name)                           \
    {                                                                  \
116
        Py_ssize_t i = 0;                                              \
117
        if (!PySequence_Check(py_ret) || __PyString_Check(py_ret))       \
Adam Plumb's avatar
Adam Plumb committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        {                                                              \
            PyErr_SetString(PyExc_TypeError,                           \
                            METHOD_NAME " must return a sequence");    \
            goto beach;                                                \
        }                                                              \
        for (i = 0; i < PySequence_Size (py_ret); i++)                 \
        {                                                              \
            PyGObject *py_item;                                        \
            py_item = (PyGObject*)PySequence_GetItem (py_ret, i);      \
            if (!pygobject_check(py_item, &Py##type##_Type))           \
            {                                                          \
                PyErr_SetString(PyExc_TypeError,                       \
                                METHOD_NAME                            \
                                " must return a sequence of "          \
                                type_name);                            \
                goto beach;                                            \
            }                                                          \
            ret = g_list_append (ret, (type*) g_object_ref(py_item->obj));  \
136
            Py_DECREF(py_item);                                        \
Adam Plumb's avatar
Adam Plumb committed
137
        }                                                              \
Johan Dahlin's avatar
Johan Dahlin committed
138
    }
139 140 141


static void
Adam Plumb's avatar
Adam Plumb committed
142 143 144 145 146 147
free_pygobject_data(gpointer data, gpointer user_data) {
    /* Some NautilusFile objects are cached and not freed until nautilus
        itself is closed.  Since PyGObject stores data that must be freed by
        the Python interpreter, we must always free it before the interpreter
        is finalized. */
    g_object_set_data((GObject *)data, "PyGObject::instance-data", NULL);
148 149 150
}

static void
Adam Plumb's avatar
Adam Plumb committed
151 152 153 154 155
free_pygobject_data_list(GList *list) {
    if (list == NULL)
        return;
        
    g_list_foreach(list, (GFunc)free_pygobject_data, NULL);
156
}
Johan Dahlin's avatar
Johan Dahlin committed
157

158
static PyObject *
Adam Plumb's avatar
Adam Plumb committed
159 160 161 162 163 164 165
nautilus_python_boxed_new (PyTypeObject *type, gpointer boxed, gboolean free_on_dealloc) {
    PyGBoxed *self = (PyGBoxed *) type->tp_alloc (type, 0);
    self->gtype = pyg_type_from_object ( (PyObject *) type);
    self->boxed = boxed;
    self->free_on_dealloc = free_on_dealloc;
    
    return (PyObject *) self;
166 167
}

Johan Dahlin's avatar
Johan Dahlin committed
168 169 170
#define METHOD_NAME "get_property_pages"
static GList *
nautilus_python_object_get_property_pages (NautilusPropertyPageProvider *provider,
Adam Plumb's avatar
Adam Plumb committed
171 172
                                           GList                         *files) {
    NautilusPythonObject *object = (NautilusPythonObject*)provider;
173
    PyObject *py_files, *py_ret = NULL;
Johan Dahlin's avatar
Johan Dahlin committed
174
    GList *ret = NULL;
Adam Plumb's avatar
Adam Plumb committed
175 176 177
    PyGILState_STATE state = pyg_gil_state_ensure();
    
    debug_enter();
Johan Dahlin's avatar
Johan Dahlin committed
178

Adam Plumb's avatar
Adam Plumb committed
179 180
    CHECK_OBJECT(object);
    CHECK_METHOD_NAME(object->instance);
Johan Dahlin's avatar
Johan Dahlin committed
181

Adam Plumb's avatar
Adam Plumb committed
182 183
    CONVERT_LIST(py_files, files);
    
Johan Dahlin's avatar
Johan Dahlin committed
184
    py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
Adam Plumb's avatar
Adam Plumb committed
185 186 187 188 189 190 191 192
                                 "(N)", py_files);
    HANDLE_RETVAL(py_ret);

    HANDLE_LIST(py_ret, NautilusPropertyPage, "Nautilus.PropertyPage");
    
beach:
    Py_XDECREF(py_ret);
    pyg_gil_state_release(state);
Johan Dahlin's avatar
Johan Dahlin committed
193 194 195 196 197
    return ret;
}
#undef METHOD_NAME

static void
Adam Plumb's avatar
Adam Plumb committed
198 199
nautilus_python_object_property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface) {
    iface->get_pages = nautilus_python_object_get_property_pages;
Johan Dahlin's avatar
Johan Dahlin committed
200 201
}

202 203 204
#define METHOD_NAME "get_widget"
static GtkWidget *
nautilus_python_object_get_widget (NautilusLocationWidgetProvider *provider,
Adam Plumb's avatar
Adam Plumb committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218
                                   const char                        *uri,
                                   GtkWidget                       *window) {
    NautilusPythonObject *object = (NautilusPythonObject*)provider;
    GtkWidget *ret = NULL;
    PyObject *py_ret = NULL;
    PyGObject *py_ret_gobj;
    PyObject *py_uri = NULL;
    PyGILState_STATE state = pyg_gil_state_ensure();

    debug_enter();

    CHECK_OBJECT(object);
    CHECK_METHOD_NAME(object->instance);

219
    py_uri = __PyString_FromString(uri);
Adam Plumb's avatar
Adam Plumb committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238

    py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
                                 "(NN)", py_uri,
                                 pygobject_new((GObject *)window));
    HANDLE_RETVAL(py_ret);

    py_ret_gobj = (PyGObject *)py_ret;
    if (!pygobject_check(py_ret_gobj, &PyGtkWidget_Type)) {
        PyErr_SetString(PyExc_TypeError,
                        METHOD_NAME "should return a gtk.Widget");
        goto beach;
    }

    ret = (GtkWidget *)g_object_ref(py_ret_gobj->obj);

beach:
    Py_XDECREF(py_ret);
    pyg_gil_state_release(state);
    return ret;
239 240 241 242
}
#undef METHOD_NAME

static void
Adam Plumb's avatar
Adam Plumb committed
243 244
nautilus_python_object_location_widget_provider_iface_init (NautilusLocationWidgetProviderIface *iface) {
    iface->get_widget = nautilus_python_object_get_widget;
245 246
}

Johan Dahlin's avatar
Johan Dahlin committed
247 248 249
#define METHOD_NAME "get_file_items"
static GList *
nautilus_python_object_get_file_items (NautilusMenuProvider *provider,
Adam Plumb's avatar
Adam Plumb committed
250 251 252
                                       GtkWidget             *window,
                                       GList                 *files) {
    NautilusPythonObject *object = (NautilusPythonObject*)provider;
Johan Dahlin's avatar
Johan Dahlin committed
253
    GList *ret = NULL;
254
    PyObject *py_ret = NULL, *py_files;
Adam Plumb's avatar
Adam Plumb committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    PyGILState_STATE state = pyg_gil_state_ensure();
    
    debug_enter();

    CHECK_OBJECT(object);    

    if (PyObject_HasAttrString(object->instance, "get_file_items_full")) {
        CONVERT_LIST(py_files, files);
        py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "get_file_items_full",
                                     "(NNN)",
                                     pygobject_new((GObject *)provider), 
                                     pygobject_new((GObject *)window), 
                                     py_files);
    }
    else if (PyObject_HasAttrString(object->instance, "get_file_items")) {
        CONVERT_LIST(py_files, files);
        py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
                                     "(NN)", 
                                     pygobject_new((GObject *)window), 
                                     py_files);
    }
    else {
        goto beach;
    }

    HANDLE_RETVAL(py_ret);

    HANDLE_LIST(py_ret, NautilusMenuItem, "Nautilus.MenuItem");

beach:
	free_pygobject_data_list(files);
    Py_XDECREF(py_ret);
    pyg_gil_state_release(state);
Johan Dahlin's avatar
Johan Dahlin committed
288 289 290 291 292 293 294
    return ret;
}
#undef METHOD_NAME

#define METHOD_NAME "get_background_items"
static GList *
nautilus_python_object_get_background_items (NautilusMenuProvider *provider,
Adam Plumb's avatar
Adam Plumb committed
295 296 297
                                             GtkWidget               *window,
                                             NautilusFileInfo       *file) {
    NautilusPythonObject *object = (NautilusPythonObject*)provider;
Johan Dahlin's avatar
Johan Dahlin committed
298
    GList *ret = NULL;
299
    PyObject *py_ret = NULL;
Adam Plumb's avatar
Adam Plumb committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    PyGILState_STATE state = pyg_gil_state_ensure();
    
    debug_enter();

    CHECK_OBJECT(object);

    if (PyObject_HasAttrString(object->instance, "get_background_items_full")) {
        py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "get_background_items_full",
                                     "(NNN)",
                                     pygobject_new((GObject *)provider),
                                     pygobject_new((GObject *)window),
                                     pygobject_new((GObject *)file));
    }
    else if (PyObject_HasAttrString(object->instance, "get_background_items")) {
        py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
                                     "(NN)",
                                     pygobject_new((GObject *)window),
                                     pygobject_new((GObject *)file));
    }
    else {
        goto beach;
    }

    HANDLE_RETVAL(py_ret);

    HANDLE_LIST(py_ret, NautilusMenuItem, "Nautilus.MenuItem");
    
beach:
   free_pygobject_data(file, NULL);
    Py_XDECREF(py_ret);
    pyg_gil_state_release(state);
Johan Dahlin's avatar
Johan Dahlin committed
331 332 333 334 335
    return ret;
}
#undef METHOD_NAME

static void
Adam Plumb's avatar
Adam Plumb committed
336 337 338
nautilus_python_object_menu_provider_iface_init (NautilusMenuProviderIface *iface) {
    iface->get_background_items = nautilus_python_object_get_background_items;
    iface->get_file_items = nautilus_python_object_get_file_items;
Johan Dahlin's avatar
Johan Dahlin committed
339 340 341 342
}

#define METHOD_NAME "get_columns"
static GList *
Adam Plumb's avatar
Adam Plumb committed
343 344
nautilus_python_object_get_columns (NautilusColumnProvider *provider) {
    NautilusPythonObject *object = (NautilusPythonObject*)provider;
Johan Dahlin's avatar
Johan Dahlin committed
345
    GList *ret = NULL;
346
    PyObject *py_ret = NULL;
Adam Plumb's avatar
Adam Plumb committed
347
    PyGILState_STATE state = pyg_gil_state_ensure();                                    \
Johan Dahlin's avatar
Johan Dahlin committed
348

Adam Plumb's avatar
Adam Plumb committed
349 350 351 352
    debug_enter();
        
    CHECK_OBJECT(object);
    CHECK_METHOD_NAME(object->instance);
Johan Dahlin's avatar
Johan Dahlin committed
353 354

    py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
Adam Plumb's avatar
Adam Plumb committed
355
                                 NULL);
Johan Dahlin's avatar
Johan Dahlin committed
356

Adam Plumb's avatar
Adam Plumb committed
357
    HANDLE_RETVAL(py_ret);
Johan Dahlin's avatar
Johan Dahlin committed
358

Adam Plumb's avatar
Adam Plumb committed
359 360 361 362 363 364
    HANDLE_LIST(py_ret, NautilusColumn, "Nautilus.Column");
    
beach:
    if (py_ret != NULL)
        Py_XDECREF(py_ret);
    pyg_gil_state_release(state);
Johan Dahlin's avatar
Johan Dahlin committed
365 366 367 368 369
    return ret;
}
#undef METHOD_NAME

static void
Adam Plumb's avatar
Adam Plumb committed
370 371
nautilus_python_object_column_provider_iface_init (NautilusColumnProviderIface *iface) {
    iface->get_columns = nautilus_python_object_get_columns;
Johan Dahlin's avatar
Johan Dahlin committed
372 373 374 375 376
}


#define METHOD_NAME "cancel_update"
static void
Adam Plumb's avatar
Adam Plumb committed
377 378 379 380 381
nautilus_python_object_cancel_update (NautilusInfoProvider         *provider,
                                      NautilusOperationHandle     *handle) {
    NautilusPythonObject *object = (NautilusPythonObject*)provider;
    PyGILState_STATE state = pyg_gil_state_ensure();
    PyObject *py_handle = nautilus_python_boxed_new (_PyNautilusOperationHandle_Type, handle, FALSE);
382

Adam Plumb's avatar
Adam Plumb committed
383
    debug_enter();
384

Adam Plumb's avatar
Adam Plumb committed
385 386
    CHECK_OBJECT(object);
    CHECK_METHOD_NAME(object->instance);
387 388

    PyObject_CallMethod(object->instance,
Adam Plumb's avatar
Adam Plumb committed
389 390 391
                                 METHOD_PREFIX METHOD_NAME, "(NN)",
                                 pygobject_new((GObject*)provider),
                                 py_handle);
392

Adam Plumb's avatar
Adam Plumb committed
393 394
beach:
    pyg_gil_state_release(state);
Johan Dahlin's avatar
Johan Dahlin committed
395 396 397 398 399
}
#undef METHOD_NAME

#define METHOD_NAME "update_file_info"
static NautilusOperationResult
Adam Plumb's avatar
Adam Plumb committed
400 401 402 403 404
nautilus_python_object_update_file_info (NautilusInfoProvider         *provider,
                                         NautilusFile                 *file,
                                         GClosure                     *update_complete,
                                         NautilusOperationHandle   **handle) {
    NautilusPythonObject *object = (NautilusPythonObject*)provider;
Johan Dahlin's avatar
Johan Dahlin committed
405
    NautilusOperationResult ret = NAUTILUS_OPERATION_COMPLETE;
406
    PyObject *py_ret = NULL;
Adam Plumb's avatar
Adam Plumb committed
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    PyGILState_STATE state = pyg_gil_state_ensure();
    PyObject *py_handle = nautilus_python_boxed_new (_PyNautilusOperationHandle_Type, *handle, FALSE);

    debug_enter();

    CHECK_OBJECT(object);

    if (PyObject_HasAttrString(object->instance, "update_file_info_full")) {
        py_ret = PyObject_CallMethod(object->instance,
                                     METHOD_PREFIX "update_file_info_full", "(NNNN)",
                                     pygobject_new((GObject*)provider),
                                     py_handle,
                                     pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE),
                                     pygobject_new((GObject*)file));
    }
    else if (PyObject_HasAttrString(object->instance, "update_file_info")) {
        py_ret = PyObject_CallMethod(object->instance,
                                     METHOD_PREFIX METHOD_NAME, "(N)",
                                     pygobject_new((GObject*)file));
    }
    else {
        goto beach;
    }
    
    HANDLE_RETVAL(py_ret);

433
    if (!__PyInt_Check(py_ret)) {
Adam Plumb's avatar
Adam Plumb committed
434 435 436 437 438
        PyErr_SetString(PyExc_TypeError,
                        METHOD_NAME " must return None or a int");
        goto beach;
    }

439 440 441
#if PY_MAJOR_VERSION >= 3
    ret = PyLong_AsLong(py_ret);
#else
Adam Plumb's avatar
Adam Plumb committed
442
    ret = PyInt_AsLong(py_ret);
443 444
#endif

Adam Plumb's avatar
Adam Plumb committed
445 446 447 448
beach:
    free_pygobject_data(file, NULL);
    Py_XDECREF(py_ret);
    pyg_gil_state_release(state);
Johan Dahlin's avatar
Johan Dahlin committed
449 450 451 452 453
    return ret;
}
#undef METHOD_NAME

static void
Adam Plumb's avatar
Adam Plumb committed
454 455 456
nautilus_python_object_info_provider_iface_init (NautilusInfoProviderIface *iface) {
    iface->cancel_update = nautilus_python_object_cancel_update;
    iface->update_file_info = nautilus_python_object_update_file_info;
Johan Dahlin's avatar
Johan Dahlin committed
457 458 459
}

static void 
Adam Plumb's avatar
Adam Plumb committed
460 461 462
nautilus_python_object_instance_init (NautilusPythonObject *object) {
    NautilusPythonObjectClass *class;
    debug_enter();
Johan Dahlin's avatar
Johan Dahlin committed
463

Adam Plumb's avatar
Adam Plumb committed
464
    class = (NautilusPythonObjectClass*)(((GTypeInstance*)object)->g_class);
Johan Dahlin's avatar
Johan Dahlin committed
465

Adam Plumb's avatar
Adam Plumb committed
466 467 468
    object->instance = PyObject_CallObject(class->type, NULL);
    if (object->instance == NULL)
        PyErr_Print();
Johan Dahlin's avatar
Johan Dahlin committed
469 470 471
}

static void
Adam Plumb's avatar
Adam Plumb committed
472 473
nautilus_python_object_finalize (GObject *object) {
    debug_enter();
Johan Dahlin's avatar
Johan Dahlin committed
474

Adam Plumb's avatar
Adam Plumb committed
475 476
    if (((NautilusPythonObject *)object)->instance != NULL)
        Py_DECREF(((NautilusPythonObject *)object)->instance);
Johan Dahlin's avatar
Johan Dahlin committed
477 478 479 480
}

static void
nautilus_python_object_class_init (NautilusPythonObjectClass *class,
Adam Plumb's avatar
Adam Plumb committed
481 482 483 484 485 486 487 488
                                   gpointer                   class_data) {
    debug_enter();

    parent_class = g_type_class_peek_parent (class);
    
    class->type = (PyObject*)class_data;
    
    G_OBJECT_CLASS (class)->finalize = nautilus_python_object_finalize;
Johan Dahlin's avatar
Johan Dahlin committed
489 490 491 492
}

GType 
nautilus_python_object_get_type (GTypeModule *module, 
Adam Plumb's avatar
Adam Plumb committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
                                 PyObject     *type) {
    GTypeInfo *info;
    const char *type_name;
    GType gtype;
      
    static const GInterfaceInfo property_page_provider_iface_info = {
        (GInterfaceInitFunc) nautilus_python_object_property_page_provider_iface_init,
        NULL,
        NULL
    };

    static const GInterfaceInfo location_widget_provider_iface_info = {
        (GInterfaceInitFunc) nautilus_python_object_location_widget_provider_iface_init,
        NULL,
        NULL
    };

    static const GInterfaceInfo menu_provider_iface_info = {
        (GInterfaceInitFunc) nautilus_python_object_menu_provider_iface_init,
        NULL,
        NULL
    };

    static const GInterfaceInfo column_provider_iface_info = {
        (GInterfaceInitFunc) nautilus_python_object_column_provider_iface_init,
        NULL,
        NULL
    };

    static const GInterfaceInfo info_provider_iface_info = {
        (GInterfaceInitFunc) nautilus_python_object_info_provider_iface_init,
        NULL,
        NULL
    };

528
    debug_enter_args("type=%s", __PyString_AsString(PyObject_GetAttrString(type, "__name__")));
Adam Plumb's avatar
Adam Plumb committed
529 530 531 532 533 534 535 536 537 538 539
    info = g_new0 (GTypeInfo, 1);
    
    info->class_size = sizeof (NautilusPythonObjectClass);
    info->class_init = (GClassInitFunc)nautilus_python_object_class_init;
    info->instance_size = sizeof (NautilusPythonObject);
    info->instance_init = (GInstanceInitFunc)nautilus_python_object_instance_init;

    info->class_data = type;
    Py_INCREF(type);

    type_name = g_strdup_printf("%s+NautilusPython",
540
                                __PyString_AsString(PyObject_GetAttrString(type, "__name__")));
Adam Plumb's avatar
Adam Plumb committed
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
        
    gtype = g_type_module_register_type (module, 
                                         G_TYPE_OBJECT,
                                         type_name,
                                         info, 0);

    if (PyObject_IsSubclass(type, (PyObject*)&PyNautilusPropertyPageProvider_Type)) {
        g_type_module_add_interface (module, gtype, 
                                     NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER,
                                     &property_page_provider_iface_info);
    }

    if (PyObject_IsSubclass(type, (PyObject*)&PyNautilusLocationWidgetProvider_Type)) {
        g_type_module_add_interface (module, gtype,
                                     NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,
                                     &location_widget_provider_iface_info);
    }
    
    if (PyObject_IsSubclass(type, (PyObject*)&PyNautilusMenuProvider_Type)) {
        g_type_module_add_interface (module, gtype, 
                                     NAUTILUS_TYPE_MENU_PROVIDER,
                                     &menu_provider_iface_info);
    }

    if (PyObject_IsSubclass(type, (PyObject*)&PyNautilusColumnProvider_Type)) {
        g_type_module_add_interface (module, gtype, 
                                     NAUTILUS_TYPE_COLUMN_PROVIDER,
                                     &column_provider_iface_info);
    }
    
    if (PyObject_IsSubclass(type, (PyObject*)&PyNautilusInfoProvider_Type)) {
        g_type_module_add_interface (module, gtype, 
                                     NAUTILUS_TYPE_INFO_PROVIDER,
                                     &info_provider_iface_info);
    }
    
    return gtype;
Johan Dahlin's avatar
Johan Dahlin committed
578
}