static void initialize_gio (void) { char *disable_fuse = NULL; char *use_vfs = NULL; disable_fuse = g_strdup (g_getenv ("GVFS_DISABLE_FUSE")); use_vfs = g_strdup (g_getenv ("GIO_USE_VFS")); g_setenv ("GVFS_DISABLE_FUSE", "1", TRUE); g_setenv ("GIO_USE_VFS", "local", TRUE); g_vfs_get_default (); if (use_vfs) { g_setenv ("GIO_USE_VFS", use_vfs, TRUE); g_free (use_vfs); } else { g_unsetenv ("GIO_USE_VFS"); } if (disable_fuse) { g_setenv ("GVFS_DISABLE_FUSE", use_vfs, TRUE); g_free (disable_fuse); } else { g_unsetenv ("GVFS_DISABLE_FUSE"); } }
NS_IMETHODIMP nsGIOMimeApp::GetSupportedURISchemes(nsIUTF8StringEnumerator** aSchemes) { *aSchemes = nsnull; nsRefPtr<GIOUTF8StringEnumerator> array = new GIOUTF8StringEnumerator(); NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY); GVfs *gvfs = g_vfs_get_default(); if (!gvfs) { g_warning("Cannot get GVfs object."); return NS_ERROR_OUT_OF_MEMORY; } const gchar* const * uri_schemes = g_vfs_get_supported_uri_schemes(gvfs); while (*uri_schemes != NULL) { if (!array->mStrings.AppendElement(*uri_schemes)) { return NS_ERROR_OUT_OF_MEMORY; } uri_schemes++; } NS_ADDREF(*aSchemes = array); return NS_OK; }
NS_IMETHODIMP nsGIOProtocolHandler::NewURI(const nsACString &aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **aResult) { const nsCString flatSpec(aSpec); LOG(("gio: NewURI [spec=%s]\n", flatSpec.get())); if (!aBaseURI) { // XXX Is it good to support all GIO protocols? if (!IsSupportedProtocol(flatSpec)) return NS_ERROR_UNKNOWN_PROTOCOL; int32_t colon_location = flatSpec.FindChar(':'); if (colon_location <= 0) return NS_ERROR_UNKNOWN_PROTOCOL; // Verify that GIO supports this URI scheme. bool uri_scheme_supported = false; GVfs *gvfs = g_vfs_get_default(); if (!gvfs) { g_warning("Cannot get GVfs object."); return NS_ERROR_UNKNOWN_PROTOCOL; } const gchar* const * uri_schemes = g_vfs_get_supported_uri_schemes(gvfs); while (*uri_schemes != nullptr) { // While flatSpec ends with ':' the uri_scheme does not. Therefore do not // compare last character. if (StringHead(flatSpec, colon_location).Equals(*uri_schemes)) { uri_scheme_supported = true; break; } uri_schemes++; } if (!uri_scheme_supported) { return NS_ERROR_UNKNOWN_PROTOCOL; } } nsresult rv; nsCOMPtr<nsIStandardURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, -1, flatSpec, aOriginCharset, aBaseURI); if (NS_SUCCEEDED(rv)) rv = CallQueryInterface(url, aResult); return rv; }
File::File(const QString &uri) : m_uri(uri) { m_vfs = g_vfs_get_default(); m_file = g_vfs_get_file_for_uri(m_vfs, uri.toStdString().c_str()); m_info = new FileInfo(uri); }
// check if GVFS can support this uri scheme (lower case) // NOTE: this does not work reliably due to some problems in gio/gvfs and causes bug lxde/lxqt#512 // https://github.com/lxde/lxqt/issues/512 // Use uriExists() whenever possible. bool isUriSchemeSupported(const char* uriScheme) { const gchar * const * schemes = g_vfs_get_supported_uri_schemes(g_vfs_get_default()); if(Q_UNLIKELY(schemes == NULL)) return false; for(const gchar * const * scheme = schemes; *scheme; ++scheme) if(strcmp(uriScheme, *scheme) == 0) return true; return false; }
static gboolean xmms_gvfs_plugin_setup (xmms_xform_plugin_t *xform_plugin) { GVfs *vfs; const gchar * const *schemes, * const *i; gint j; xmms_xform_methods_t methods; g_type_init (); vfs = g_vfs_get_default (); if (!g_vfs_is_active (vfs)) { xmms_log_info ("GVfs not active - disabling gvfs transport"); return FALSE; } XMMS_XFORM_METHODS_INIT (methods); methods.init = xmms_gvfs_init; methods.destroy = xmms_gvfs_destroy; methods.read = xmms_gvfs_read; methods.seek = xmms_gvfs_seek; methods.browse = xmms_gvfs_browse; xmms_xform_plugin_methods_set (xform_plugin, &methods); xmms_xform_plugin_indata_add (xform_plugin, XMMS_STREAM_TYPE_MIMETYPE, "application/x-url", XMMS_STREAM_TYPE_URL, "file://*", XMMS_STREAM_TYPE_END); schemes = g_vfs_get_supported_uri_schemes (vfs); for (i = schemes; *i; i++) { gchar *tmp = g_strconcat (*i, "://*", NULL); gint priority = XMMS_STREAM_TYPE_PRIORITY_FALLBACK; for (j = 0; j < G_N_ELEMENTS (scheme_priorities); j++) { if (g_ascii_strcasecmp (scheme_priorities[j].scheme, *i) == 0) { priority = scheme_priorities[j].priority; } } xmms_xform_plugin_indata_add (xform_plugin, XMMS_STREAM_TYPE_PRIORITY, priority, XMMS_STREAM_TYPE_MIMETYPE, "application/x-url", XMMS_STREAM_TYPE_URL, tmp, XMMS_STREAM_TYPE_END); g_free (tmp); } return TRUE; }
Dir::Dir(const QString &uri) : m_uri(uri) { m_vfs = g_vfs_get_default(); m_file = g_vfs_get_file_for_uri(m_vfs, uri.toStdString().c_str()); m_info = new FileInfo(uri); m_filters = AllEntries; m_sort_flags = NoSort; }
gchar *get_path_from_uri(const gchar *uri) { GFile *file = g_vfs_get_file_for_uri(g_vfs_get_default(), uri); gchar *path = g_file_get_path(file); if(file) { g_object_unref(file); } return path?path:g_strdup(uri); }
NS_IMETHODIMP nsGIOProtocolHandler::NewURI(const nsACString &aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **aResult) { const nsCString flatSpec(aSpec); LOG(("gio: NewURI [spec=%s]\n", flatSpec.get())); if (!aBaseURI) { // XXX Is it good to support all GIO protocols? if (!IsSupportedProtocol(flatSpec)) return NS_ERROR_UNKNOWN_PROTOCOL; int32_t colon_location = flatSpec.FindChar(':'); if (colon_location <= 0) return NS_ERROR_UNKNOWN_PROTOCOL; // Verify that GIO supports this URI scheme. bool uri_scheme_supported = false; GVfs *gvfs = g_vfs_get_default(); if (!gvfs) { g_warning("Cannot get GVfs object."); return NS_ERROR_UNKNOWN_PROTOCOL; } const gchar* const * uri_schemes = g_vfs_get_supported_uri_schemes(gvfs); while (*uri_schemes != nullptr) { // While flatSpec ends with ':' the uri_scheme does not. Therefore do not // compare last character. if (StringHead(flatSpec, colon_location).Equals(*uri_schemes)) { uri_scheme_supported = true; break; } uri_schemes++; } if (!uri_scheme_supported) { return NS_ERROR_UNKNOWN_PROTOCOL; } } return NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID) .Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init, nsIStandardURL::URLTYPE_STANDARD, -1, flatSpec, aOriginCharset, aBaseURI, nullptr) .Finalize(aResult); }
gboolean init_vfs_backend (void) { if (s_hMonitorHandleTable != NULL) g_hash_table_destroy (s_hMonitorHandleTable); s_hMonitorHandleTable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) _vfs_backend_free_monitor_data); GVfs *vfs = g_vfs_get_default (); return (vfs != NULL && g_vfs_is_active (vfs)); // utile ? }
static int ddb_gvfs_start (void) { gvfs = g_vfs_get_default (); if (!g_vfs_is_active (gvfs)) { g_warning ("GVfs not active - disabling gvfs plugin"); return 1; } return 0; }
int main (int argc, char **argv) { GError *error = NULL; g_autofree const char *old_env = NULL; int ret; setlocale (LC_ALL, ""); g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, message_handler, NULL); g_set_prgname (argv[0]); /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */ old_env = g_strdup (g_getenv ("GIO_USE_VFS")); g_setenv ("GIO_USE_VFS", "local", TRUE); g_vfs_get_default (); if (old_env) g_setenv ("GIO_USE_VFS", old_env, TRUE); else g_unsetenv ("GIO_USE_VFS"); if (argc >= 4 && strcmp (argv[1], "complete") == 0) return complete (argc, argv); flatpak_migrate_from_xdg_app (); ret = flatpak_run (argc, argv, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) flatpak_usage (commands, TRUE); if (error != NULL) { int is_tty = isatty (1); const char *prefix = ""; const char *suffix = ""; if (is_tty) { prefix = "\x1b[31m\x1b[1m"; /* red, bold */ suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */ } g_printerr ("%serror: %s%s\n", prefix, suffix, error->message); g_error_free (error); } return ret; }
static GtkWidget* make_popover_for_image_url (VteTerminal *vtterm, const gchar *uri) { g_assert (vtterm); g_assert (uri); GtkWidget *popover = gtk_popover_new (GTK_WIDGET (vtterm)); dg_lobj GVfs* gvfs = g_vfs_get_default (); dg_lobj GFile* file = g_vfs_get_file_for_uri (gvfs, uri); g_file_read_async (file, G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback) image_file_opened, popover); return popover; }
static gchar * get_protocols (void) { const gchar * const *schemes; GString *string = g_string_new (NULL); gint i; schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); for (i = 0; schemes && schemes[i]; i++) { if (string->len > 0) g_string_append_c (string, ','); g_string_append (string, schemes[i]); g_string_append_c (string, ':'); } return g_string_free (string, FALSE); }
static gboolean is_supported_scheme (const char *scheme) { GVfs *vfs; const gchar * const * schemes; guint i; if (scheme == NULL) return FALSE; vfs = g_vfs_get_default (); schemes = g_vfs_get_supported_uri_schemes (vfs); if (!schemes) { return FALSE; } for (i = 0; schemes[i] != NULL; i++) { if (g_str_equal (schemes[i], scheme)) return TRUE; } return FALSE; }
static gboolean have_burn_uri (void) { static gboolean initialized = FALSE; static gboolean res; GVfs *vfs; int i; const gchar * const * supported_uri_schemes; if (!initialized) { vfs = g_vfs_get_default (); supported_uri_schemes = g_vfs_get_supported_uri_schemes (vfs); res = FALSE; for (i = 0; supported_uri_schemes != NULL && supported_uri_schemes[i] != NULL; i++) { if (strcmp ("burn", supported_uri_schemes[i]) == 0) { res = TRUE; break; } } initialized = TRUE; } return res; }
int main (int argc, char **argv) { g_autofree const char *old_env = NULL; g_autoptr(GError) error = NULL; g_autoptr(BuilderManifest) manifest = NULL; g_autoptr(GOptionContext) context = NULL; const char *app_dir_path = NULL, *manifest_path; g_autofree gchar *json = NULL; g_autoptr(BuilderContext) build_context = NULL; g_autoptr(GFile) base_dir = NULL; g_autoptr(GFile) manifest_file = NULL; g_autoptr(GFile) app_dir = NULL; g_autoptr(BuilderCache) cache = NULL; g_autofree char *cache_branch = NULL; g_autoptr(GFileEnumerator) dir_enum = NULL; g_autoptr(GFileEnumerator) dir_enum2 = NULL; GFileInfo *next = NULL; const char *platform_id = NULL; g_autofree char **orig_argv; gboolean is_run = FALSE; gboolean is_show_deps = FALSE; gboolean app_dir_is_empty = FALSE; g_autoptr(FlatpakContext) arg_context = NULL; int i, first_non_arg, orig_argc; int argnr; setlocale (LC_ALL, ""); g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, message_handler, NULL); g_set_prgname (argv[0]); /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */ old_env = g_strdup (g_getenv ("GIO_USE_VFS")); g_setenv ("GIO_USE_VFS", "local", TRUE); g_vfs_get_default (); if (old_env) g_setenv ("GIO_USE_VFS", old_env, TRUE); else g_unsetenv ("GIO_USE_VFS"); orig_argv = g_memdup (argv, sizeof (char *) * argc); orig_argc = argc; first_non_arg = 1; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') break; first_non_arg = i + 1; if (strcmp (argv[i], "--run") == 0) is_run = TRUE; if (strcmp (argv[i], "--show-deps") == 0) is_show_deps = TRUE; } if (is_run) { context = g_option_context_new ("DIRECTORY MANIFEST COMMAND [args] - Run command in build sandbox"); g_option_context_add_main_entries (context, run_entries, NULL); arg_context = flatpak_context_new (); g_option_context_add_group (context, flatpak_context_get_options (arg_context)); /* We drop the post-command part from the args, these go with the command in the sandbox */ argc = MIN (first_non_arg + 3, argc); } else if (is_show_deps) { context = g_option_context_new ("MANIFEST - Show manifest dependencies"); g_option_context_add_main_entries (context, show_deps_entries, NULL); } else { context = g_option_context_new ("DIRECTORY MANIFEST - Build manifest"); g_option_context_add_main_entries (context, entries, NULL); } if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Option parsing failed: %s\n", error->message); return 1; } if (opt_version) { g_print ("%s\n", PACKAGE_STRING); exit (EXIT_SUCCESS); } if (opt_verbose) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL); argnr = 1; if (!is_show_deps) { if (argc == argnr) return usage (context, "DIRECTORY must be specified"); app_dir_path = argv[argnr++]; } if (argc == argnr) return usage (context, "MANIFEST must be specified"); manifest_path = argv[argnr++]; if (!g_file_get_contents (manifest_path, &json, NULL, &error)) { g_printerr ("Can't load '%s': %s\n", manifest_path, error->message); return 1; } manifest = (BuilderManifest *) json_gobject_from_data (BUILDER_TYPE_MANIFEST, json, -1, &error); if (manifest == NULL) { g_printerr ("Can't parse '%s': %s\n", manifest_path, error->message); return 1; } if (is_run && argc == 3) return usage (context, "Program to run must be specified"); if (is_show_deps) { if (!builder_manifest_show_deps (manifest, &error)) { g_printerr ("Error running %s: %s\n", argv[3], error->message); return 1; } return 0; } manifest_file = g_file_new_for_path (manifest_path); base_dir = g_file_get_parent (manifest_file); app_dir = g_file_new_for_path (app_dir_path); build_context = builder_context_new (base_dir, app_dir); builder_context_set_keep_build_dirs (build_context, opt_keep_build_dirs); builder_context_set_sandboxed (build_context, opt_sandboxed); builder_context_set_jobs (build_context, opt_jobs); if (opt_arch) builder_context_set_arch (build_context, opt_arch); if (opt_stop_at) { opt_build_only = TRUE; builder_context_set_stop_at (build_context, opt_stop_at); } if (opt_ccache && !builder_context_enable_ccache (build_context, &error)) { g_printerr ("Can't initialize ccache use: %s\n", error->message); return 1; } app_dir_is_empty = !g_file_query_exists (app_dir, NULL) || directory_is_empty (app_dir_path); if (is_run) { g_assert (opt_run); if (app_dir_is_empty) { g_printerr ("App dir '%s' is empty or doesn't exist.\n", app_dir_path); return 1; } if (!builder_manifest_run (manifest, build_context, arg_context, orig_argv + first_non_arg + 2, orig_argc - first_non_arg - 2, &error)) { g_printerr ("Error running %s: %s\n", argv[3], error->message); return 1; } return 0; } g_assert (!opt_run); g_assert (!opt_show_deps); if (!opt_finish_only && !app_dir_is_empty) { if (opt_force_clean) { g_print ("Emptying app dir '%s'\n", app_dir_path); if (!flatpak_rm_rf (app_dir, NULL, &error)) { g_printerr ("Couldn't empty app dir '%s': %s", app_dir_path, error->message); return 1; } } else { g_printerr ("App dir '%s' is not empty. Please delete " "the existing contents.\n", app_dir_path); return 1; } } if (opt_finish_only && app_dir_is_empty) { g_printerr ("App dir '%s' is empty or doesn't exist.\n", app_dir_path); return 1; } if (!builder_manifest_start (manifest, opt_allow_missing_runtimes, build_context, &error)) { g_printerr ("Failed to init: %s\n", error->message); return 1; } if (!opt_finish_only && !opt_disable_download && !builder_manifest_download (manifest, !opt_disable_updates, build_context, &error)) { g_printerr ("Failed to download sources: %s\n", error->message); return 1; } if (opt_download_only) return 0; cache_branch = g_path_get_basename (manifest_path); cache = builder_cache_new (builder_context_get_cache_dir (build_context), app_dir, cache_branch); if (!builder_cache_open (cache, &error)) { g_printerr ("Error opening cache: %s\n", error->message); return 1; } if (opt_disable_cache) /* This disables *lookups*, but we still build the cache */ builder_cache_disable_lookups (cache); builder_manifest_checksum (manifest, cache, build_context); if (!opt_finish_only) { if (!builder_cache_lookup (cache, "init")) { g_autofree char *body = g_strdup_printf ("Initialized %s\n", builder_manifest_get_id (manifest)); if (!builder_manifest_init_app_dir (manifest, build_context, &error)) { g_printerr ("Error: %s\n", error->message); return 1; } if (!builder_cache_commit (cache, body, &error)) { g_printerr ("Error: %s\n", error->message); return 1; } } if (!builder_manifest_build (manifest, cache, build_context, &error)) { g_printerr ("Error: %s\n", error->message); return 1; } } if (!opt_build_only) { if (!builder_manifest_cleanup (manifest, cache, build_context, &error)) { g_printerr ("Error: %s\n", error->message); return 1; } if (!builder_manifest_finish (manifest, cache, build_context, &error)) { g_printerr ("Error: %s\n", error->message); return 1; } if (!builder_manifest_create_platform (manifest, cache, build_context, &error)) { g_printerr ("Error: %s\n", error->message); return 1; } } if (!opt_require_changes) builder_cache_ensure_checkout (cache); if (!opt_build_only && opt_repo && builder_cache_has_checkout (cache)) { g_autoptr(GFile) debuginfo_metadata = NULL; g_print ("Exporting %s to repo\n", builder_manifest_get_id (manifest)); if (!do_export (build_context, &error, builder_context_get_build_runtime (build_context), "--exclude=/lib/debug/*", "--include=/lib/debug/app", builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg, opt_repo, app_dir_path, builder_manifest_get_branch (manifest), NULL)) { g_printerr ("Export failed: %s\n", error->message); return 1; } /* Export regular locale extensions */ dir_enum = g_file_enumerate_children (app_dir, "standard::name,standard::type", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); while (dir_enum != NULL && (next = g_file_enumerator_next_file (dir_enum, NULL, NULL))) { g_autoptr(GFileInfo) child_info = next; const char *name = g_file_info_get_name (child_info); g_autofree char *metadata_arg = NULL; g_autofree char *files_arg = NULL; g_autofree char *locale_id = builder_manifest_get_locale_id (manifest); if (strcmp (name, "metadata.locale") == 0) g_print ("Exporting %s to repo\n", locale_id); else continue; metadata_arg = g_strdup_printf ("--metadata=%s", name); files_arg = g_strconcat (builder_context_get_build_runtime (build_context) ? "--files=usr" : "--files=files", "/share/runtime/locale/", NULL); if (!do_export (build_context, &error, TRUE, metadata_arg, files_arg, opt_repo, app_dir_path, builder_manifest_get_branch (manifest), NULL)) { g_printerr ("Export failed: %s\n", error->message); return 1; } } /* Export debug extensions */ debuginfo_metadata = g_file_get_child (app_dir, "metadata.debuginfo"); if (g_file_query_exists (debuginfo_metadata, NULL)) { g_autofree char *debug_id = builder_manifest_get_debug_id (manifest); g_print ("Exporting %s to repo\n", debug_id); if (!do_export (build_context, &error, TRUE, "--metadata=metadata.debuginfo", builder_context_get_build_runtime (build_context) ? "--files=usr/lib/debug" : "--files=files/lib/debug", opt_repo, app_dir_path, builder_manifest_get_branch (manifest), NULL)) { g_printerr ("Export failed: %s\n", error->message); return 1; } } /* Export platform */ platform_id = builder_manifest_get_id_platform (manifest); if (builder_context_get_build_runtime (build_context) && platform_id != NULL) { g_print ("Exporting %s to repo\n", platform_id); if (!do_export (build_context, &error, TRUE, "--metadata=metadata.platform", "--files=platform", builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg, opt_repo, app_dir_path, builder_manifest_get_branch (manifest), NULL)) { g_printerr ("Export failed: %s\n", error->message); return 1; } } /* Export platform locales */ dir_enum2 = g_file_enumerate_children (app_dir, "standard::name,standard::type", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); while (dir_enum2 != NULL && (next = g_file_enumerator_next_file (dir_enum2, NULL, NULL))) { g_autoptr(GFileInfo) child_info = next; const char *name = g_file_info_get_name (child_info); g_autofree char *metadata_arg = NULL; g_autofree char *files_arg = NULL; g_autofree char *locale_id = builder_manifest_get_locale_id_platform (manifest); if (strcmp (name, "metadata.platform.locale") == 0) g_print ("Exporting %s to repo\n", locale_id); else continue; metadata_arg = g_strdup_printf ("--metadata=%s", name); files_arg = g_strconcat ("--files=platform/share/runtime/locale/", NULL); if (!do_export (build_context, &error, TRUE, metadata_arg, files_arg, opt_repo, app_dir_path, builder_manifest_get_branch (manifest), NULL)) { g_printerr ("Export failed: %s\n", error->message); return 1; } } } if (!builder_gc (cache, &error)) { g_warning ("Failed to GC build cache: %s\n", error->message); g_clear_error (&error); } return 0; }
static gboolean exo_open_uri (const gchar *uri, GError **error) { GFile *file; gchar *scheme; GFileInfo *file_info; gboolean succeed = FALSE; gboolean retval = FALSE; GFileType file_type; const gchar *content_type; GAppInfo *app_info; gchar *path; const gchar *executable; GList fake_list; const gchar * const *schemes; GError *err = NULL; guint i; g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); #ifndef NDEBUG schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); scheme = g_strjoinv (", ", (gchar **) schemes); g_debug ("vfs supported schemes: %s", scheme); g_free (scheme); #endif file = g_file_new_for_uri (uri); scheme = g_file_get_uri_scheme (file); /* try to launch common schemes for know preferred applications */ if (scheme != NULL && exo_open_uri_known_category (uri, scheme, &retval)) { g_free (scheme); return retval; } /* handle the uri as a file, maybe we succeed... */ file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &err); if (file_info != NULL) { file_type = g_file_info_get_file_type (file_info); if (file_type == G_FILE_TYPE_DIRECTORY) { #ifndef NDEBUG g_debug ("file is directory, use filemanager"); #endif /* directories should go fine with a file manager */ retval = exo_open_launch_category ("FileManager", uri); succeed = TRUE; } else { content_type = g_file_info_get_content_type (file_info); #ifndef NDEBUG g_debug ("content type=%s", content_type); #endif if (G_LIKELY (content_type)) { /* try to find a suitable application for this content type */ path = g_file_get_path (file); app_info = g_app_info_get_default_for_type (content_type, path == NULL); g_free (path); if (app_info != NULL) { /* make sure we don't loop somehow */ executable = g_app_info_get_executable (app_info); #ifndef NDEBUG g_debug ("default executable=%s", executable); #endif if (executable == NULL || strcmp (executable, "exo-open") != 0) { fake_list.data = (gpointer) uri; fake_list.prev = fake_list.next = NULL; /* launch it */ retval = g_app_info_launch_uris (app_info, &fake_list, NULL, &err); succeed = TRUE; } g_object_unref (G_OBJECT (app_info)); } } } g_object_unref (G_OBJECT (file_info)); } else if (err != NULL && scheme != NULL && err->code == G_IO_ERROR_NOT_MOUNTED) { /* check if the scheme is supported by gio */ schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); if (G_LIKELY (schemes != NULL)) { for (i = 0; schemes[i] != NULL; i++) { /* found scheme, open in file manager */ if (strcmp (scheme, schemes[i]) == 0) { retval = succeed = exo_open_launch_category ("FileManager", uri); break; } } } } g_object_unref (G_OBJECT (file)); /* our last try... */ if (!succeed) { #ifndef NDEBUG g_debug ("nothing worked, try ftp(s) or gtk_show_uri()"); #endif /* try ftp uris if the file manager/gio failed to recognize it */ if (scheme != NULL && (strcmp (scheme, "ftp") == 0 || strcmp (scheme, "ftps") == 0)) retval = exo_open_launch_category ("WebBrowser", uri); else retval = gtk_show_uri (NULL, uri, 0, error); } g_free (scheme); if (!retval && error != NULL) *error = err; else if (err != NULL) g_error_free (err); return retval; }
gboolean open_file (Ebook * ebook, const gchar * filename) { GtkProgressBar * progressbar; GtkStatusbar * statusbar; guint id; GtkWidget * window; PopplerRectangle * rect; GError * err; gint G_GNUC_UNUSED pages; gchar * uri, * msg; GVfs * vfs; GFileInfo * ginfo; GError * result; GConfValue *value; gboolean lines, hyphens, pagenums; vfs = g_vfs_get_default (); if (g_vfs_is_active(vfs)) ebook->gfile = g_vfs_get_file_for_path (vfs, filename); else ebook->gfile = g_file_new_for_commandline_arg (filename); ginfo = g_file_query_info (ebook->gfile, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &result); if (0 == g_file_info_get_attribute_uint64 (ginfo, G_FILE_ATTRIBUTE_STANDARD_SIZE)) { g_object_unref (ebook->gfile); g_object_unref (ginfo); g_warning ("%s", result->message); return FALSE; } uri = g_file_get_uri (ebook->gfile); err = NULL; pages = 0; rect = poppler_rectangle_new (); rect->x1 = rect->y1 = 0; window = GTK_WIDGET(gtk_builder_get_object (ebook->builder, "gpdfwindow")); progressbar = GTK_PROGRESS_BAR(gtk_builder_get_object (ebook->builder, "progressbar")); gtk_progress_bar_set_fraction (progressbar, 0.0); statusbar = GTK_STATUSBAR(gtk_builder_get_object (ebook->builder, "statusbar")); id = gtk_statusbar_get_context_id (statusbar, PACKAGE); msg = g_strconcat (_("Loading ebook:"), g_file_get_basename (ebook->gfile), NULL); gtk_statusbar_push (statusbar, id, msg); ebook->PDFDoc = poppler_document_new_from_file (uri, NULL, &err); gtk_progress_bar_set_fraction (progressbar, 0.0); /* long lines support */ value = gconf_client_get(ebook->client, ebook->long_lines.key, NULL); if (value) lines = gconf_value_get_bool(value); else lines = TRUE; /* page numbers support */ value = gconf_client_get(ebook->client, ebook->page_number.key, NULL); if (value) pagenums = gconf_value_get_bool(value); else pagenums = TRUE; /* join hyphens support */ value = gconf_client_get(ebook->client, ebook->join_hyphens.key, NULL); if (value) hyphens = gconf_value_get_bool(value); else hyphens = TRUE; if (POPPLER_IS_DOCUMENT (ebook->PDFDoc)) { #ifdef HAVE_GTKSPELL GtkSpell *spell; gchar * G_GNUC_UNUSED lang; #endif GtkWidget * G_GNUC_UNUSED spell_check; GtkTextView * text_view; GtkTextBuffer * buffer; gboolean state; static Equeue queue; spell_check = GTK_WIDGET(gtk_builder_get_object (ebook->builder, "spellcheckmenuitem")); text_view = GTK_TEXT_VIEW(gtk_builder_get_object (ebook->builder, "textview")); buffer = gtk_text_view_get_buffer (text_view); state = gconf_client_get_bool (ebook->client, ebook->spell_check.key, NULL); #ifdef HAVE_GTKSPELL spell = gtkspell_get_from_text_view (text_view); lang = gconf_client_get_string (ebook->client, ebook->language.key, NULL); /* updating the text area with spell enabled is very slow */ if (state) gtkspell_detach (spell); #endif pages = poppler_document_get_n_pages (ebook->PDFDoc); queue.ebook = ebook; queue.c = 0; queue.lines = lines; queue.hyphens = hyphens; queue.pagenums = pagenums; queue.rect = rect; /* whether to enable spell once all pages are loaded. */ queue.spell_state = state; /* loading a file is a single user action */ gtk_text_buffer_begin_user_action (buffer); g_timeout_add (30, load_pdf, &queue); } else { g_message ("err: %s", err->message); return FALSE; } msg = g_strconcat (PACKAGE, " - ", g_file_get_basename (ebook->gfile), NULL); gtk_window_set_title (GTK_WINDOW(window), msg); return TRUE; }
static VALUE vfs_get_default(G_GNUC_UNUSED VALUE self) { return GOBJ2RVAL(g_vfs_get_default()); }