Patch to have the File Moniker extender support PersistStream components



Please review the attached patch for use with components not implementing
PersistFile.

-- 
   .--= ULLA! =----------------------------.  finger cactus cactus rulez org
   \      http://cactus.rulez.org           \   for PGP public key
    `----------= cactus cactus rulez org =--'
-*- INSERT TAGLINE HERE -*-
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/bonobo/ChangeLog,v
retrieving revision 1.866
diff -u -u -r1.866 ChangeLog
--- ChangeLog	2001/01/03 17:38:32	1.866
+++ ChangeLog	2001/01/03 20:48:45
@@ -1,3 +1,8 @@
+2001-01-03  ERDI Gergo  <cactus cactus rulez org>
+
+	* monikers/bonobo-moniker-extender-file.c: Handle components only
+	implementing Bonobo::PersistStream by building a Stream from files
+
 2001-01-03  Dietmar Maurer  <dietmar helixcode com>
 
 	* configure.in: Bump version to 0.32
Index: monikers/bonobo-moniker-extender-file.c
===================================================================
RCS file: /cvs/gnome/bonobo/monikers/bonobo-moniker-extender-file.c,v
retrieving revision 1.7
diff -u -u -r1.7 bonobo-moniker-extender-file.c
--- monikers/bonobo-moniker-extender-file.c	2000/12/22 07:55:08	1.7
+++ monikers/bonobo-moniker-extender-file.c	2001/01/03 20:48:48
@@ -17,6 +17,58 @@
 
 #include "bonobo-moniker-std.h"
 
+static gboolean persist_stream_load (const Bonobo_Unknown  object,
+				     const gchar          *filename,
+				     gchar                *mime_type)
+{
+	CORBA_Environment     ev;
+	Bonobo_PersistStream  persist_stream;
+	BonoboStream         *stream_client;
+	Bonobo_Stream         stream;
+
+	CORBA_exception_init (&ev);
+	persist_stream = Bonobo_Unknown_queryInterface
+		(object, "IDL:Bonobo/PersistStream:1.0", &ev);
+	
+	if (BONOBO_EX (&ev) || persist_stream == CORBA_OBJECT_NIL)
+		return FALSE;
+	
+	stream_client = bonobo_stream_open (BONOBO_IO_DRIVER_FS, filename,
+					    Bonobo_Storage_READ, 0);
+	stream = bonobo_object_corba_objref
+		(BONOBO_OBJECT (stream_client));
+
+	Bonobo_PersistStream_load (persist_stream,
+				   stream, mime_type,
+				   &ev);
+	CORBA_exception_free (&ev);
+	
+	bonobo_object_release_unref (persist_stream, &ev);
+	return TRUE;
+}
+
+static gboolean persist_file_load (const Bonobo_Unknown  object,
+				   const gchar          *filename,
+				   gchar                *mime_type)
+{
+	CORBA_Environment  ev;
+	Bonobo_PersistFile persist_file;
+
+	CORBA_exception_init (&ev);	
+
+	persist_file = Bonobo_Unknown_queryInterface (
+		object, "IDL:Bonobo/PersistFile:1.0", &ev);
+	CORBA_exception_free (&ev);
+	
+	if (BONOBO_EX (&ev) || persist_file == CORBA_OBJECT_NIL)
+		return persist_stream_load (object, filename, mime_type);
+	
+	Bonobo_PersistFile_load (persist_file, filename, &ev);
+	
+	bonobo_object_release_unref (persist_file, &ev);
+	return TRUE;
+}
+
 Bonobo_Unknown
 bonobo_file_extender_resolve (BonoboMonikerExtender *extender,
 			      const Bonobo_Moniker   m,
@@ -28,7 +80,6 @@
 	const char      *mime_type;
 	char            *oaf_requirements;
 	Bonobo_Unknown   object;
-	Bonobo_Persist   persist;
 	OAF_ActivationID ret_id;
 	const char      *fname;
 
@@ -43,7 +94,7 @@
 
 	oaf_requirements = g_strdup_printf (
 		"bonobo:supported_mime_types.has ('%s') AND repo_ids.has ('%s') AND "
-		"repo_ids.has ('IDL:Bonobo/PersistFile:1.0')",
+		"repo_ids.has_one ('IDL:Bonobo/PersistFile:1.0', 'IDL:Bonobo/PersistStream:1.0')",
 		mime_type, requested_interface);
 		
 	object = oaf_activate (oaf_requirements, NULL, 0, &ret_id, ev);
@@ -53,23 +104,11 @@
 
 	if (BONOBO_EX (ev) || object == CORBA_OBJECT_NIL)
 		return CORBA_OBJECT_NIL;
-
-	persist = Bonobo_Unknown_queryInterface (
-		object, "IDL:Bonobo/PersistFile:1.0", ev);
-
-	if (BONOBO_EX (ev) || persist == CORBA_OBJECT_NIL) {
-		bonobo_object_release_unref (object, ev);
-		return CORBA_OBJECT_NIL;
-	}
-
-	if (persist != CORBA_OBJECT_NIL) {
-		Bonobo_PersistFile_load (persist, fname, ev);
-
-		bonobo_object_release_unref (persist, ev);
+	
+	if (persist_file_load (object, fname, mime_type))
+		return bonobo_moniker_util_qi_return (object, requested_interface, ev);
 
-		return bonobo_moniker_util_qi_return (
-			object, requested_interface, ev);
-	}
+	bonobo_object_release_unref (object, ev);
 	
 	return CORBA_OBJECT_NIL;
 }


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