file moniker patch



Here's a patch to bonobo-moniker-file.c that sets the correct
mime type for directories, and allows you to query for a storage
interface from directories. Note that the stat() for directories
isn't very pretty. The alternative is to try to open the file
as a stream and see if it fails; however, this would require the
stream to be created unnecessarily if the PersistFile interface
was supported. Any other suggestions? Could always get a BonoboStorage
for the parent directory and then do a getInfo on the file, but again,
possibly unnecessary...

The other thing that I noticed is that the file moniker doesn't
have the desired effect if a relative path is used. Why this happens
makes sense -- however, perhaps it should explicitly enforce this policy
by requiring all filenames to start with a /, to avoid possible trouble?

	- Vlad


Index: bonobo-moniker-file.c
===================================================================
RCS file: /cvs/gnome/bonobo/monikers/bonobo-moniker-file.c,v
retrieving revision 1.4
diff -u -r1.4 bonobo-moniker-file.c
--- bonobo-moniker-file.c	2000/11/02 06:41:16	1.4
+++ bonobo-moniker-file.c	2000/11/29 19:37:58
@@ -9,8 +9,10 @@
 #include <config.h>
 #include <bonobo/bonobo-moniker.h>
 #include <bonobo/bonobo-moniker-util.h>
+#include <bonobo/bonobo-storage.h>
 #include <libgnome/gnome-mime.h>
 #include <liboaf/liboaf.h>
+#include <sys/stat.h>
 
 #include "bonobo-moniker-file.h"
 
@@ -70,14 +72,37 @@
 
 		return CORBA_Object_duplicate (
 			bonobo_object_corba_objref (BONOBO_OBJECT (stream)), ev);
-	} else {
+	}
+
+        if (!strcmp (requested_interface, "IDL:Bonobo/Storage:1.0")) {
+            BonoboStorage *storage;
+
+            storage = bonobo_storage_open ("fs", fname,
+                                           Bonobo_Storage_READ |
+                                           Bonobo_Storage_WRITE,
+                                           0);
+            if (storage) {
+                /* We can present this thing as a Storage directly from the filesystem. */
+                return CORBA_Object_duplicate (
+                    bonobo_object_corba_objref (BONOBO_OBJECT (storage)), ev);
+            }
+        }
+
+        /* Always fall through, if the above two cases didn't catch it. */
+        if (1) {
 		const char    *mime_type;
 		char          *oaf_requirements;
 		Bonobo_Unknown object;
 		Bonobo_Persist persist;
 		OAF_ActivationID ret_id;
+                struct stat statbuf;
 
 		mime_type = gnome_mime_type (fname);
+
+                /* UGLY hack for directories. */
+                if (stat (fname, &statbuf) == 0)
+                    if (S_ISDIR(statbuf.st_mode))
+                        mime_type = "x-directory/normal";
 
 		oaf_requirements = g_strdup_printf (
 			"bonobo:supported_mime_types.has ('%s') AND repo_ids.has ('%s') AND "




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