NS_IMETHODIMP nsGnomeVFSMimeApp::Launch(const nsACString &aUri) { char *uri = gnome_vfs_make_uri_from_input(PromiseFlatCString(aUri).get()); if (! uri) return NS_ERROR_FAILURE; GList *uris = g_list_append(NULL, uri); if (! uris) { g_free(uri); return NS_ERROR_FAILURE; } GnomeVFSResult result = gnome_vfs_mime_application_launch(mApp, uris); g_free(uri); g_list_free(uris); if (result != GNOME_VFS_OK) return NS_ERROR_FAILURE; return NS_OK; }
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_vfs_url_show_with_env(spec, NULL) == GNOME_VFS_OK) rv = NS_OK; g_free(spec); return rv; }
JNIEXPORT jintLong JNICALL GNOME_NATIVE(_1gnome_1vfs_1make_1uri_1from_1input) (JNIEnv *env, jclass that, jbyteArray arg0) { jbyte *lparg0=NULL; jintLong rc = 0; GNOME_NATIVE_ENTER(env, that, _1gnome_1vfs_1make_1uri_1from_1input_FUNC); if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; rc = (jintLong)gnome_vfs_make_uri_from_input((const char *)lparg0); fail: if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); GNOME_NATIVE_EXIT(env, that, _1gnome_1vfs_1make_1uri_1from_1input_FUNC); return rc; }
bool Open(const std::string& path, const std::string& args) { #if defined(HAVE_GNOME_VFS) TRACE("Using GnomeVFS\n"); std::string mimeType; std::string strURI; // first try heuristic - http link would crash in GetMimeType if (path.substr(0, 7) == "http://") mimeType = "text/html"; else if (path.substr(0, 8) == "https://") mimeType = "text/html"; else if (path.substr(0, 6) == "ftp://") mimeType = "text/html"; else if (path.substr(0, 7) == "mailto:") mimeType = "message/rfc822"; else if(std::string::npos != path.find("://")) { GnomeVFS::URI uri(path); mimeType = GnomeVFS::GetMimeType(uri); strURI = uri.ToString(); TRACE("URI:%s,host:%s\n", gnome_vfs_make_uri_from_input(path.c_str()), gnome_vfs_uri_get_host_name(uri.GetHandle())); //TRACE("mime:%s\n",gnome_vfs_mime_type_from_name(path.c_str())); } else { //assume local file (no "://" found) GnomeVFS::URI uri("file:///"); uri.AppendPath(path); mimeType = GnomeVFS::GetMimeType(uri); strURI = uri.ToString(); } if(strURI.empty()) strURI = path; TRACE("Open path:%s - URI:%s, mime type:%s\n", path.c_str(), strURI.c_str(), mimeType.c_str()); if (!mimeType.empty()) { GnomeVFS::MimeApplication app(GnomeVFS::MimeGetDefaultApplication(mimeType)); if (app) { Glib::List<std::string> uris; uris.Append(strURI); return app.Launch(uris) == GNOME_VFS_OK; } } else return g_spawn_command_line_async(path.c_str(), 0); return g_spawn_command_line_async(FileNameFromUTF8(path).c_str(), 0); #else if(!g_bMimeMapsLoaded){ LoadMimeTypes("/etc/mime.types", "/etc/mailcap"); g_bMimeMapsLoaded = true; } std::string strMime; // first try heuristic - http link would crash in GetMimeType if (path.substr(0, 7) == "http://") strMime = "text/html"; else if (path.substr(0, 8) == "https://") strMime = "text/html"; else if (path.substr(0, 6) == "ftp://") strMime = "text/html"; else if (path.substr(0, 7) == "mailto:") strMime = "message/rfc822"; else{ std::string strExt = GetFileExt(path.c_str()); if(!strExt.empty()) strExt = strExt.substr(1); // strip "." if(!strExt.empty()){ TRACE("Ext: %s\n", strExt.c_str()); strMime = g_mapExt2Mime[strExt]; } } if(!strMime.empty()){ TRACE("Mime: %s\n", strMime.c_str()); std::string strProg = g_mapMime2Prog[strMime]; if(strProg.empty()){ //last chance - try alternative mime // image/jpeg -> image/* std::string::size_type nPos = strMime.find('/'); if(nPos != std::string::npos){ strMime = strMime.substr(0, nPos+1); strMime += "*"; TRACE("Mime2: %s\n", strMime.c_str()); strProg = g_mapMime2Prog[strMime]; } } if(!strProg.empty()){ TRACE("Prog: %s\n", strProg.c_str()); char szBuffer[2048]; sprintf(szBuffer, strProg.c_str(), path.c_str()); TRACE("Exec: %s\n", szBuffer); return g_spawn_command_line_async(szBuffer, 0); // TOFIX from utf8? } } return g_spawn_command_line_async(FileNameFromUTF8(path).c_str(), 0); #endif }