Bug 391980 - "New Download manager automatically associates all types of files including folders with one file type" [p=ventnor.bugzilla@yahoo.com.au (Michael Ventnor) r=bsmedberg a=blocking-firefox3+]
authorreed@reedloden.com
Mon, 26 Nov 2007 15:55:34 -0800
changeset 8346 fe37d6eb08b3cebc407701136fa6d86e3a2cbf25
parent 8345 f66cf2f0a17f5fc1d38798284c656495085ff344
child 8347 5e5395678002c9e6b6d8920bf06ee8d78c3dbba7
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, blocking-firefox3
bugs391980
milestone1.9b2pre
Bug 391980 - "New Download manager automatically associates all types of files including folders with one file type" [p=ventnor.bugzilla@yahoo.com.au (Michael Ventnor) r=bsmedberg a=blocking-firefox3+]
toolkit/system/gnome/nsGnomeVFSService.cpp
xpcom/io/nsLocalFileUnix.cpp
xpcom/system/nsIGnomeVFSService.idl
--- a/toolkit/system/gnome/nsGnomeVFSService.cpp
+++ b/toolkit/system/gnome/nsGnomeVFSService.cpp
@@ -45,16 +45,17 @@
 #include "nsAutoPtr.h"
 
 extern "C" {
 #include <libgnomevfs/gnome-vfs-application-registry.h>
 #include <libgnomevfs/gnome-vfs-init.h>
 #include <libgnomevfs/gnome-vfs-mime.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
 #include <libgnomevfs/gnome-vfs-mime-info.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
 #include <libgnome/gnome-url.h>
 }
 
 class nsGnomeVFSMimeApp : public nsIGnomeVFSMimeApp
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIGNOMEVFSMIMEAPP
@@ -241,16 +242,30 @@ nsGnomeVFSService::ShowURI(nsIURI *aURI)
 
   if (gnome_url_show(spec.get(), NULL))
     return NS_OK;
 
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
+nsGnomeVFSService::ShowURIForInput(const nsACString &aUri)
+{
+  char* spec = gnome_vfs_make_uri_from_input(PromiseFlatCString(aUri).get());
+  nsresult rv = NS_ERROR_FAILURE;
+
+  if (gnome_url_show(spec, NULL))
+    rv = NS_OK;
+
+  if (spec)
+    g_free(spec);
+  return rv;
+}
+
+NS_IMETHODIMP
 nsGnomeVFSService::SetAppStringKey(const nsACString &aID,
                                    PRInt32           aKey,
                                    const nsACString &aValue)
 {
   const char *key;
 
   if (aKey == APP_KEY_COMMAND)
     key = GNOME_VFS_APPLICATION_REGISTRY_COMMAND;
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -78,16 +78,20 @@
 #include "nsIComponentManager.h"
 #include "nsXPIDLString.h"
 #include "prproces.h"
 #include "nsIDirectoryEnumerator.h"
 #include "nsISimpleEnumerator.h"
 #include "nsITimelineService.h"
 #include "nsIProgrammingLanguage.h"
 
+#ifdef MOZ_WIDGET_GTK2
+#include "nsIGnomeVFSService.h"
+#endif
+
 #include "nsNativeCharsetUtils.h"
 #include "nsTraceRefcntImpl.h"
 
 // On some platforms file/directory name comparisons need to
 // be case-blind.
 #if defined(VMS)
     #define FILE_STRCMP strcasecmp
     #define FILE_STRNCMP strncasecmp
@@ -1658,23 +1662,54 @@ nsLocalFile::Launch()
     be_roster->Launch (&ref);
 
     return NS_OK;
 }
 #else
 NS_IMETHODIMP
 nsLocalFile::Reveal()
 {
+#ifdef MOZ_WIDGET_GTK2
+    nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
+    if (!vfs)
+        return NS_ERROR_FAILURE;
+
+    PRBool isDirectory;
+    if (NS_FAILED(IsDirectory(&isDirectory)))
+        return NS_ERROR_FAILURE;
+
+    if (isDirectory) {
+        return vfs->ShowURIForInput(mPath);
+    } else {
+        nsCOMPtr<nsIFile> parentDir;
+        nsCAutoString dirPath;
+        if (NS_FAILED(GetParent(getter_AddRefs(parentDir))))
+            return NS_ERROR_FAILURE;
+        if (NS_FAILED(parentDir->GetNativePath(dirPath)))
+            return NS_ERROR_FAILURE;
+
+        return vfs->ShowURIForInput(dirPath);
+    }
+#else
     return NS_ERROR_FAILURE;
+#endif
 }
 
 NS_IMETHODIMP
 nsLocalFile::Launch()
 {
+#ifdef MOZ_WIDGET_GTK2
+    nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
+    if (!vfs)
+        return NS_ERROR_FAILURE;
+
+    return vfs->ShowURIForInput(mPath);
+#else
     return NS_ERROR_FAILURE;
+#endif
 }
 #endif
 
 nsresult
 NS_NewNativeLocalFile(const nsACString &path, PRBool followSymlinks, nsILocalFile **result)
 {
     nsLocalFile *file = new nsLocalFile();
     if (!file)
--- a/xpcom/system/nsIGnomeVFSService.idl
+++ b/xpcom/system/nsIGnomeVFSService.idl
@@ -39,17 +39,17 @@
 #include "nsISupports.idl"
 
 interface nsIUTF8StringEnumerator;
 interface nsIURI;
 
 /* nsIGnomeVFSMimeApp holds information about an application that is looked up
    with nsIGnomeVFSService::GetAppForMimeType. */
 
-[scriptable, uuid(99ae024f-e869-4973-958b-54768a84295a)]
+[scriptable, uuid(57b1ef41-35cd-48e9-a248-2030c8365067)]
 interface nsIGnomeVFSMimeApp : nsISupports
 {
   const long EXPECTS_URIS  = 0;
   const long EXPECTS_PATHS = 1;
   const long EXPECTS_URIS_FOR_NON_FILES = 2;
 
   readonly attribute AUTF8String         id;
   readonly attribute AUTF8String         name;
@@ -138,13 +138,14 @@ interface nsIGnomeVFSService : nsISuppor
   void setMimeExtensions(in AUTF8String mimeType,
                          in AUTF8String extensionsList);
 
 
   /*** Misc. methods ***/
 
   /* Open the given URI in the default application */
   void               showURI(in nsIURI uri);
+  [noscript] void    showURIForInput(in ACString uri);
 };
 
 %{C++
 #define NS_GNOMEVFSSERVICE_CONTRACTID "@mozilla.org/gnome-vfs-service;1"
 %}