[nautilus-python] Created a new InfoProvider.update_file_info_async() method for asynchronous use. update_file_info s



commit 35e461c83b3ea5d2dd683d575005e76def7cba42
Author: Adam Plumb <adamplumb gmail com>
Date:   Tue Apr 27 13:52:50 2010 -0400

    Created a new InfoProvider.update_file_info_async() method for asynchronous use.  update_file_info still exists and is unchanged from previous versions, and will work as in the past.  This is for backwards compatibility

 examples/documentation.py    |   15 ++++++++++++++-
 src/nautilus-python-object.c |   39 +++++++++++++++++++++++++--------------
 2 files changed, 39 insertions(+), 15 deletions(-)
---
diff --git a/examples/documentation.py b/examples/documentation.py
index 35a84a4..bad17cd 100644
--- a/examples/documentation.py
+++ b/examples/documentation.py
@@ -48,7 +48,16 @@ class PropertyPageProvider:
         """
         
 class InfoProvider:
-    def update_file_info(self, file, info):
+    def update_file_info(self, file):
+        """
+        @param file   selected file
+        @type  file   list of nautilus.FileInfo
+
+        This is used to update data for file, use the set_data method,
+        and use together with the other extensions.
+        """
+
+    def update_file_info_async(self, file, info):
         """
         @param file   selected file
         @type  file   list of nautilus.FileInfo
@@ -69,6 +78,10 @@ class InfoProvider:
         nautilus.OPERATION_IN_PROGRESS enum.  Then, when the operation has
         completed, call the self.update_complete_invoke method, passing the info variable
         as a parameter.
+        
+        Note: This method exists for backwards compatibility reasons.  If your
+        extension used the update_file_info method and you want non-blocking 
+        usage, you must switch to this method.
         """
 
     def cancel_update(self, handle):
diff --git a/src/nautilus-python-object.c b/src/nautilus-python-object.c
index 3967e75..1bb4e67 100644
--- a/src/nautilus-python-object.c
+++ b/src/nautilus-python-object.c
@@ -383,26 +383,37 @@ nautilus_python_object_update_file_info (NautilusInfoProvider 		*provider,
 {
 	NautilusPythonObject *object = (NautilusPythonObject*)provider;
     NautilusOperationResult ret = NAUTILUS_OPERATION_COMPLETE;
-
     PyObject *py_ret = NULL;
 	PyGILState_STATE state = pyg_gil_state_ensure();                                    \
-	PyObject *info = NULL;
-	
+
   	debug_enter();
 
 	CHECK_OBJECT(object);
-	CHECK_METHOD_NAME(object->instance);
 	
-	info = PyDict_New();
-	PyDict_SetItem(info, Py_BuildValue("s", "provider"), pygobject_new((GObject*)provider));
-	PyDict_SetItem(info, Py_BuildValue("s", "closure"), pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE));
-	PyDict_SetItem(info, Py_BuildValue("s", "handle"), pyg_pointer_new(G_TYPE_POINTER, *handle));
-
-    py_ret = PyObject_CallMethod(object->instance,
-								 METHOD_PREFIX METHOD_NAME, "(NN)",
-								 pygobject_new((GObject*)file),
-								 info);
-
+	if (PyObject_HasAttrString(object->instance, "update_file_info_async"))
+	{
+		PyObject *info = NULL;
+		info = PyDict_New();
+		PyDict_SetItem(info, Py_BuildValue("s", "provider"), pygobject_new((GObject*)provider));
+		PyDict_SetItem(info, Py_BuildValue("s", "closure"), pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE));
+		PyDict_SetItem(info, Py_BuildValue("s", "handle"), pyg_pointer_new(G_TYPE_POINTER, *handle));
+
+		py_ret = PyObject_CallMethod(object->instance,
+									 METHOD_PREFIX "update_file_info_async", "(NN)",
+									 pygobject_new((GObject*)file),
+									 info);
+	}
+	else if (PyObject_HasAttrString(object->instance, METHOD_NAME))
+	{
+		py_ret = PyObject_CallMethod(object->instance,
+									 METHOD_PREFIX METHOD_NAME, "(N)",
+									 pygobject_new((GObject*)file));
+	}
+	else
+	{
+		goto beach;
+	}
+	
 	HANDLE_RETVAL(py_ret);
 
 	if (!PyInt_Check(py_ret))



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