pygobject r898 - in trunk: . gio



Author: gianmt
Date: Tue Jul 29 21:29:25 2008
New Revision: 898
URL: http://svn.gnome.org/viewvc/pygobject?rev=898&view=rev

Log:
Wrap g_app_info_launch_uris, g_app_info_launch, g_app_launch_context_get_display and g_app_launch_context_get_startup_notify_id

Added:
   trunk/gio/gapplaunchcontext.override
Modified:
   trunk/ChangeLog
   trunk/gio/Makefile.am
   trunk/gio/gappinfo.override
   trunk/gio/gio.defs
   trunk/gio/gio.override
   trunk/gio/pygio-utils.c
   trunk/gio/pygio-utils.h
   trunk/gio/unix-types.defs

Modified: trunk/gio/Makefile.am
==============================================================================
--- trunk/gio/Makefile.am	(original)
+++ trunk/gio/Makefile.am	Tue Jul 29 21:29:25 2008
@@ -31,12 +31,13 @@
 endif
 
 CLEANFILES =
-EXTRA_DIST = 
+EXTRA_DIST =
 
 # gio module
 GIO_OVERRIDES = 			\
 	gio.override			\
 	gappinfo.override		\
+	gapplaunchcontext.override 	\
 	gfile.override			\
 	gfileenumerator.override	\
 	gfileinfo.override		\
@@ -88,4 +89,3 @@
 	    --prefix py$(*F) $*.defs) > $(*D)/gen-$(*F).c \
 	&& cp $(*D)/gen-$(*F).c $(*D)/$(*F).c \
 	&& rm -f $(*D)/gen-$(*F).c
-

Modified: trunk/gio/gappinfo.override
==============================================================================
--- trunk/gio/gappinfo.override	(original)
+++ trunk/gio/gappinfo.override	Tue Jul 29 21:29:25 2008
@@ -1,6 +1,7 @@
 /* -*- Mode: C; c-basic-offset: 4 -*-
  * pygobject - Python bindings for GObject
  * Copyright (C) 2008  Johan Dahlin
+ * Copyright (C) 2008  Gian Mario Tagliaretti
  *
  *   gappinfo.override: module overrides for GInputStream
  *
@@ -48,7 +49,7 @@
     GError *error = NULL;
     GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 				     "s|zO:gio.AppInfo",
 				     kwlist,
 				     &commandline, &application_name,
@@ -57,14 +58,103 @@
     if (py_flags && pyg_flags_get_value(G_TYPE_APP_INFO_CREATE_FLAGS,
 					py_flags, (gpointer)&flags))
         return NULL;
-    
+
     ret = g_app_info_create_from_commandline(commandline,
 					     application_name, flags, &error);
-    
+
     if (pyg_error_check(&error))
         return NULL;
 
     /* pygobject_new handles NULL checking */
     return pygobject_new((GObject *)ret);
 }
-    
+%%
+override g_app_info_launch_uris kwargs
+static PyObject *
+_wrap_g_app_info_launch_uris(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "files", "launch_context", NULL };
+
+    GList *file_list = NULL;
+    PyGObject *pycontext = NULL;
+    GAppLaunchContext *ctx;
+    PyObject *pyfile_list = Py_None;
+    int ret;
+    GError *error = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+				     "|OO:gio.AppInfo.launch_uris",
+				     kwlist,
+				     &pyfile_list, &pycontext))
+        return NULL;
+
+    if (!pygio_check_launch_context(pycontext, &ctx))
+	return NULL;
+
+    if (pyfile_list == Py_None)
+        file_list = NULL;
+
+    else if (PySequence_Check (pyfile_list))
+        file_list = pygio_pylist_to_uri_glist(pyfile_list);
+
+    else {
+        PyErr_SetString(PyExc_TypeError,
+                        "file_list should be a list of strings or None");
+        return NULL;
+    }
+
+    ret = g_app_info_launch_uris(G_APP_INFO(self->obj),
+                                 file_list, ctx, &error);
+
+    g_list_free(file_list);
+
+    if (pyg_error_check(&error))
+        return NULL;
+
+    return PyBool_FromLong(ret);
+}
+%%
+override g_app_info_launch kwargs
+static PyObject *
+_wrap_g_app_info_launch(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "files", "launch_context", NULL };
+
+    GList *file_list = NULL;
+    PyGObject *pycontext = NULL;
+    GAppLaunchContext *ctx;
+    PyObject *pyfile_list = Py_None;
+    int ret;
+    GError *error = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+				     "|OO:gio.AppInfo.launch",
+				     kwlist,
+				     &pyfile_list, &pycontext))
+        return NULL;
+
+    if (!pygio_check_launch_context(pycontext, &ctx))
+	return NULL;
+
+    if (pyfile_list == Py_None)
+        file_list = NULL;
+
+    else if (PySequence_Check (pyfile_list))
+        file_list = pygio_pylist_to_gfile_glist(pyfile_list);
+
+    else {
+        PyErr_SetString(PyExc_TypeError,
+                        "file_list should be a list of strings or None");
+        return NULL;
+    }
+
+    ret = g_app_info_launch(G_APP_INFO(self->obj),
+                            file_list, ctx, &error);
+
+    g_list_free(file_list);
+
+    if (pyg_error_check(&error))
+        return NULL;
+
+    return PyBool_FromLong(ret);
+}

Added: trunk/gio/gapplaunchcontext.override
==============================================================================
--- (empty file)
+++ trunk/gio/gapplaunchcontext.override	Tue Jul 29 21:29:25 2008
@@ -0,0 +1,99 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygobject - Python bindings for GObject
+ * Copyright (C) 2008 Gian Mario Tagliaretti
+ *
+ *   gapplaunchcontext.override: module overrides for GAppLaunchContext
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+%%
+override g_app_launch_context_get_display kwargs
+static PyObject *
+_wrap_g_app_launch_context_get_display(PyGObject *self,
+                                       PyObject *args,
+                                       PyObject *kwargs)
+{
+    static char *kwlist[] = { "info", "files", NULL };
+
+    GList *file_list = NULL;
+    PyGObject *py_info;
+    PyObject *pyfile_list;
+    gchar *ret;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+			    "O!O:gio.AppLaunchContext.get_display",
+			    kwlist,
+			    &PyGAppInfo_Type, &py_info, &pyfile_list))
+        return NULL;
+
+    if (!PySequence_Check (pyfile_list)) {
+        PyErr_Format (PyExc_TypeError,
+                      "argument must be a list or tuple of GFile objects");
+        return NULL;
+    }
+
+    file_list = pygio_pylist_to_gfile_glist(pyfile_list);
+
+    ret = g_app_launch_context_get_display(G_APP_LAUNCH_CONTEXT(self->obj),
+                                           G_APP_INFO(py_info->obj), file_list);
+    g_list_free(file_list);
+
+    if (ret)
+        return PyString_FromString(ret);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+%%
+override g_app_launch_context_get_startup_notify_id kwargs
+static PyObject *
+_wrap_g_app_launch_context_get_startup_notify_id(PyGObject *self,
+                                                 PyObject *args,
+                                                 PyObject *kwargs)
+{
+    static char *kwlist[] = { "info", "files", NULL };
+
+    GList       *file_list = NULL;
+    PyGObject   *py_info;
+    PyObject    *pyfile_list;
+    gchar       *ret;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+			    "O!O:gio.AppLaunchContext.get_startup_notify_id",
+			    kwlist,
+			    &PyGAppInfo_Type, &py_info, &pyfile_list))
+        return NULL;
+
+    if (!PySequence_Check (pyfile_list)) {
+        PyErr_Format (PyExc_TypeError,
+                      "argument must be a list or tuple of GFile objects");
+        return NULL;
+    }
+
+    file_list = pygio_pylist_to_gfile_glist(pyfile_list);
+
+    ret = g_app_launch_context_get_startup_notify_id(
+                                        G_APP_LAUNCH_CONTEXT(self->obj),
+                                        G_APP_INFO(py_info->obj), file_list);
+    g_list_free(file_list);
+
+    if (ret)
+        return PyString_FromString(ret);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}

Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs	(original)
+++ trunk/gio/gio.defs	Tue Jul 29 21:29:25 2008
@@ -71,6 +71,21 @@
 )
 
 (define-method launch
+  (docstring
+  "launch (files=None, launch_context=None) -> gboolean\n"
+  "\n"
+  "Launches the application. Passes files to the launched application\n"
+  "as arguments, using the optional launch_context to get information\n"
+  "about the details of the launcher (like what screen it is on).\n"
+  "On error, error will be set accordingly.\n\n"
+  "Note that even if the launch is successful the application launched\n"
+  "can fail to start if it runs into problems during startup.\n"
+  "There is no way to detect this.\n\n"
+  "Some URIs can be changed when passed through a gio.File\n"
+  "(for instance unsupported uris with strange formats like mailto:),\n"
+  "so if you have a textual uri you want to pass in as argument,\n"
+  "consider using gio.AppInfo.launch_uris() instead."
+  )
   (of-object "GAppInfo")
   (c-name "g_app_info_launch")
   (return-type "gboolean")
@@ -94,6 +109,17 @@
 )
 
 (define-method launch_uris
+  (docstring
+  "launch_uris (files=None, launch_context=None) -> gboolean\n"
+  "\n"
+  "Launches the application. Passes files to the launched application\n"
+  "as arguments, using the optional launch_context to get information\n"
+  "about the details of the launcher (like what screen it is on).\n"
+  "On error, error will be set accordingly.\n\n"
+  "Note that even if the launch is successful the application launched\n"
+  "can fail to start if it runs into problems during startup.\n"
+  "There is no way to detect this.\n\n"
+  )
   (of-object "GAppInfo")
   (c-name "g_app_info_launch_uris")
   (return-type "gboolean")
@@ -1021,7 +1047,7 @@
 )
 
 (define-method next_files_async
-  (docstring 
+  (docstring
 "FE.next_files_async(num_files, callback, [io_priority, cancellable, user_data])\n"
 "Request information for a number of files from the enumerator asynchronously.\n"
 "When all i/o for the operation is finished the callback will be called with\n"
@@ -1298,7 +1324,7 @@
 
 (define-method read_async
   (of-object "GFile")
-  (docstring 
+  (docstring
   "F.read_async(callback [,io_priority [,cancellable [,user_data]]]) -> start read\n"
   "\n"
   "For more details, see gio.File.read() which is the synchronous\n"
@@ -1522,9 +1548,9 @@
 )
 
 (define-method enumerate_children
-  (docstring 
+  (docstring
 "F.enumerate_children(attributes, [flags, cancellable]) -> enumerator\n"
-"Gets the requested information about the files in a directory.\n" 
+"Gets the requested information about the files in a directory.\n"
 "The result is a gio.FileEnumerator object that will give out gio.FileInfo\n"
 "objects for all the files in the directory.\n"
 "The attribute value is a string that specifies the file attributes that\n"
@@ -1555,7 +1581,7 @@
 )
 
 (define-method enumerate_children_async
-  (docstring 
+  (docstring
 "F.enumerate_children_async(attributes, callback,\n"
 "                           [flags, io_priority, cancellable, user_data])\n"
 "Asynchronously gets the requested information about the files in a directory.\n"
@@ -1916,8 +1942,8 @@
 )
 
 (define-method mount_mountable
-  (docstring 
-"F.mount_mountable(mount_operation, callback, [flags, cancellable, user_data])\n" 
+  (docstring
+"F.mount_mountable(mount_operation, callback, [flags, cancellable, user_data])\n"
 "Mounts a file of type gio.FILE_TYPE_MOUNTABLE. Using mount_operation,\n"
 "you can request callbacks when, for instance, passwords are needed\n"
 "during authentication.\n"
@@ -4436,5 +4462,3 @@
     '("GMount*" "mount")
   )
 )
-
-

Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override	(original)
+++ trunk/gio/gio.override	Tue Jul 29 21:29:25 2008
@@ -44,23 +44,23 @@
 }
 
 static void
-async_result_callback_marshal(GObject *source_object, 
-			      GAsyncResult *result, 
+async_result_callback_marshal(GObject *source_object,
+			      GAsyncResult *result,
 			      PyGIONotify *notify)
 {
     PyObject *ret;
     PyGILState_STATE state;
-    
+
     state = pyg_gil_state_ensure();
 
     if (notify->data)
-	ret = PyEval_CallFunction(notify->callback, "(OOO)", 
-				  pygobject_new(source_object), 
+	ret = PyEval_CallFunction(notify->callback, "(OOO)",
+				  pygobject_new(source_object),
 				  pygobject_new((GObject *)result),
 				  notify->data);
     else
-	ret = PyObject_CallFunction(notify->callback, "(OO)", 
-				    pygobject_new(source_object), 
+	ret = PyObject_CallFunction(notify->callback, "(OO)",
+				    pygobject_new(source_object),
 				    pygobject_new((GObject *)result));
 
     if (ret == NULL)
@@ -80,6 +80,7 @@
 %%
 include
   gappinfo.override
+  gapplaunchcontext.override
   gfile.override
   gfileenumerator.override
   gfileinfo.override
@@ -114,7 +115,7 @@
 {
   GList *list, *l;
   PyObject *ret;
-  
+
   list = g_drive_get_volumes (G_DRIVE (self->obj));
 
   ret = PyList_New(0);
@@ -125,7 +126,7 @@
     Py_DECREF(item);
   }
   g_list_free(list);
-  
+
   return ret;
 }
 %%
@@ -135,7 +136,7 @@
 {
   GList *list, *l;
   PyObject *ret;
-  
+
   list = g_app_info_get_all ();
 
   ret = PyList_New(0);
@@ -146,7 +147,7 @@
     Py_DECREF(item);
   }
   g_list_free(list);
-  
+
   return ret;
 }
 %%
@@ -157,10 +158,10 @@
   GList *list, *l;
   PyObject *ret;
   gchar *type;
-  
+
   if (!PyArg_ParseTuple (args, "s:app_info_get_all_for_type", &type))
     return NULL;
-  
+
   list = g_app_info_get_all_for_type (type);
 
   ret = PyList_New(0);
@@ -171,7 +172,7 @@
     Py_DECREF(item);
   }
   g_list_free(list);
-  
+
   return ret;
 }
 %%
@@ -204,7 +205,7 @@
     char *filename = NULL, *data = NULL, *type;
     int data_size = 0;
     gboolean result_uncertain, want_uncertain = FALSE;
-    
+
     if (!PyArg_ParseTupleAndKeywords (args, kwargs,
 				      "|zz#i:g_content_type_guess",
 				      kwlist,
@@ -239,9 +240,9 @@
     PyGObject *py_cancellable = NULL;
     GMountUnmountFlags flags = G_MOUNT_UNMOUNT_NONE;
     GCancellable *cancellable;
-  
+
     notify = g_slice_new0(PyGIONotify);
-    
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                      "O|OOO:GMount.unmount",
 				     kwlist,
@@ -249,7 +250,7 @@
 				     &py_flags,
 				     &py_cancellable,
 				     &notify->data))
-            
+
     {
       g_slice_free(PyGIONotify, notify);
       return NULL;
@@ -263,7 +264,7 @@
     }
     Py_INCREF(notify->callback);
     Py_XINCREF(notify->data);
-  
+
     if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_UNMOUNT_FLAGS,
 					py_flags, (gpointer)&flags))
         return NULL;

Modified: trunk/gio/pygio-utils.c
==============================================================================
--- trunk/gio/pygio-utils.c	(original)
+++ trunk/gio/pygio-utils.c	Tue Jul 29 21:29:25 2008
@@ -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 @@
     }
   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;
+}

Modified: trunk/gio/pygio-utils.h
==============================================================================
--- trunk/gio/pygio-utils.h	(original)
+++ trunk/gio/pygio-utils.h	Tue Jul 29 21:29:25 2008
@@ -29,8 +29,17 @@
 #include <gio/gio.h>
 
 extern PyTypeObject PyGCancellable_Type;
+extern PyTypeObject PyGAppLaunchContext_Type;
+extern PyTypeObject PyGFile_Type;
 
 gboolean pygio_check_cancellable(PyGObject *pycancellable,
 				 GCancellable **cancellable);
 
+gboolean pygio_check_launch_context(PyGObject *pycontext,
+				    GAppLaunchContext **context);
+
+GList* pygio_pylist_to_gfile_glist(PyObject *pycontext);
+
+GList* pygio_pylist_to_uri_glist(PyObject *pycontext);
+
 #endif /* __PYGIO_UTILS_H__ */

Modified: trunk/gio/unix-types.defs
==============================================================================
--- trunk/gio/unix-types.defs	(original)
+++ trunk/gio/unix-types.defs	Tue Jul 29 21:29:25 2008
@@ -1,5 +1,17 @@
 ;; -*- scheme -*-
 
+(define-object DesktopAppInfo
+  (docstring
+  "DesktopAppInfo(desktop_id) -> gio.unix.DesktopAppInfo\n\n"
+  "gio.Unix.DesktopAppInfo is an implementation of gio.AppInfo\n"
+  "based on desktop files."
+  )
+  (in-module "giounix")
+  (parent "GObject")
+  (c-name "GDesktopAppInfo")
+  (gtype-id "G_TYPE_DESKTOP_APP_INFO")
+)
+
 (define-object InputStream
   (in-module "giounix")
   (parent "GInputStream")
@@ -19,5 +31,3 @@
   (c-name "GUnixMountEntry")
   (gtype-id "GIO_UNIX_MOUNT_ENTRY_TYPE")
 )
-
-



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]