diff options
Diffstat (limited to 'gio/pygio-utils.c')
-rw-r--r-- | gio/pygio-utils.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/gio/pygio-utils.c b/gio/pygio-utils.c index b3c88b9..313b147 100644 --- a/gio/pygio-utils.c +++ b/gio/pygio-utils.c @@ -1,6 +1,7 @@ /* -*- Mode: C; c-basic-offset: 4 -*- * pygtk- Python bindings for the GTK toolkit. * Copyright (C) 2008 Johan Dahlin + * Copyright (C) 2008 Gian Mario Tagliaretti * * giomodule.c: module wrapping the GIO library * @@ -45,3 +46,85 @@ pygio_check_cancellable(PyGObject *pycancellable, } return TRUE; } + +/** + * pygio_check_launch_context: + * @pycontext: + * @context: + * + * Returns: + */ +gboolean +pygio_check_launch_context(PyGObject *pycontext, + GAppLaunchContext **context) +{ + if (pycontext == NULL || (PyObject*)pycontext == Py_None) + *context = NULL; + else if (pygobject_check(pycontext, &PyGAppLaunchContext_Type)) + *context = G_APP_LAUNCH_CONTEXT(pycontext->obj); + else + { + PyErr_SetString(PyExc_TypeError, + "launch_context should be a GAppLaunchContext or None"); + return FALSE; + } + return TRUE; +} + +/** + * pygio_pylist_to_gfile_glist: + * @pyfile_list: + * + * Returns: + */ +GList * +pygio_pylist_to_gfile_glist(PyObject *pyfile_list) +{ + GList *file_list = NULL; + PyObject *item; + int len, i; + + len = PySequence_Size(pyfile_list); + for (i = 0; i < len; i++) { + item = PySequence_GetItem(pyfile_list, i); + if (!PyObject_TypeCheck(item, &PyGFile_Type)) { + PyErr_SetString(PyExc_TypeError, + "files must be a list or tuple of GFile"); + g_list_free(file_list); + return NULL; + } + file_list = g_list_prepend(file_list, ((PyGObject *)item)->obj); + } + file_list = g_list_reverse(file_list); + + return file_list; +} + +/** + * pygio_pylist_to_uri_glist: + * @pyfile_list: + * + * Returns: + */ +GList * +pygio_pylist_to_uri_glist(PyObject *pyfile_list) +{ + GList *file_list = NULL; + PyObject *item; + int len, i; + + len = PySequence_Size(pyfile_list); + for (i = 0; i < len; i++) { + item = PySequence_GetItem(pyfile_list, i); + if (!PyString_Check(item)) { + PyErr_SetString(PyExc_TypeError, + "files must be strings"); + g_list_free(file_list); + return NULL; + } + file_list = g_list_prepend(file_list, PyString_AsString(item)); + } + file_list = g_list_reverse(file_list); + + return file_list; +} |