static gboolean gst_gio_src_check_get_range (GstBaseSrc * base_src) { GstGioSrc *src = GST_GIO_SRC (base_src); gchar *scheme; if (src->file == NULL) goto done; scheme = g_file_get_uri_scheme (src->file); if (scheme == NULL) goto done; if (strcmp (scheme, "file") == 0) { GST_LOG_OBJECT (src, "local URI, assuming random access is possible"); g_free (scheme); return TRUE; } else if (strcmp (scheme, "http") == 0 || strcmp (scheme, "https") == 0) { GST_LOG_OBJECT (src, "blacklisted protocol '%s', " "no random access possible", scheme); g_free (scheme); return FALSE; } g_free (scheme); done: GST_DEBUG_OBJECT (src, "undecided about random access, asking base class"); return GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_SRC_CLASS, check_get_range, (base_src), FALSE); }
/* http://www.apple.com/itunes/store/podcaststechspecs.html */ IdolPlParserResult idol_pl_parser_add_itpc (IdolPlParser *parser, GFile *file, GFile *base_file, IdolPlParseData *parse_data, gpointer data) { #ifndef HAVE_GMIME WARN_NO_GMIME; #else IdolPlParserResult ret; char *uri, *new_uri, *uri_scheme; GFile *new_file; uri = g_file_get_uri (file); uri_scheme = g_file_get_uri_scheme (file); new_uri = g_strdup_printf ("http%s", uri + strlen (uri_scheme)); g_free (uri); g_free (uri_scheme); new_file = g_file_new_for_uri (new_uri); g_free (new_uri); ret = idol_pl_parser_add_rss (parser, new_file, base_file, parse_data, data); g_object_unref (new_file); return ret; #endif /* !HAVE_GMIME */ }
/* http://www.apple.com/itunes/store/podcaststechspecs.html */ TotemPlParserResult totem_pl_parser_add_itpc (TotemPlParser *parser, GFile *file, GFile *base_file, TotemPlParseData *parse_data, gpointer data) { TotemPlParserResult ret; char *uri, *new_uri, *uri_scheme; GFile *new_file; uri = g_file_get_uri (file); uri_scheme = g_file_get_uri_scheme (file); new_uri = g_strdup_printf ("http%s", uri + strlen (uri_scheme)); g_free (uri); g_free (uri_scheme); new_file = g_file_new_for_uri (new_uri); g_free (new_uri); ret = totem_pl_parser_add_rss (parser, new_file, base_file, parse_data, data); g_object_unref (new_file); return ret; }
/* nautilus_directory_get_name_for_self_as_new_file: * * Get a name to display for the file representing this * directory. This is called only when there's no VFS * directory for this NautilusDirectory. */ char * nautilus_directory_get_name_for_self_as_new_file (NautilusDirectory *directory) { GFile *file; char *directory_uri; char *scheme; char *name; char *hostname = NULL; directory_uri = nautilus_directory_get_uri (directory); file = g_file_new_for_uri (directory_uri); scheme = g_file_get_uri_scheme (file); g_object_unref (file); nautilus_uri_parse (directory_uri, &hostname, NULL, NULL); if (hostname == NULL || (strlen (hostname) == 0)) { name = g_strdup (directory_uri); } else if (scheme == NULL) { name = g_strdup (hostname); } else { /* Translators: this is of the format "hostname (uri-scheme)" */ name = g_strdup_printf (_("%s (%s)"), hostname, scheme); } g_free (directory_uri); g_free (scheme); g_free (hostname); return name; }
static gboolean unsupported_scheme (NautilusFileInfo *file) { gboolean result = FALSE; GFile *location; gchar *scheme; location = nautilus_file_info_get_location (file); scheme = g_file_get_uri_scheme (location); if (scheme != NULL) { const gchar *unsupported[] = { "trash", "computer", NULL }; gsize i; for (i = 0; unsupported[i] != NULL; i++) { if (strcmp (scheme, unsupported[i]) == 0) { result = TRUE; } } } g_free (scheme); g_object_unref (location); return result; }
GFileMonitor* fm_monitor_lookup_dummy_monitor(GFile* gf) { GFileMonitor* mon; char* scheme; if(G_LIKELY(!gf || g_file_is_native(gf))) return NULL; scheme = g_file_get_uri_scheme(gf); if(scheme) { /* those URI schemes don't need dummy monitor */ if(strcmp(scheme, "trash") == 0 || strcmp(scheme, "computer") == 0 || strcmp(scheme, "network") == 0 || strcmp(scheme, "applications") == 0) { g_free(scheme); return NULL; } g_free(scheme); } G_LOCK(hash); mon = (GFileMonitor*)g_hash_table_lookup(dummy_hash, gf); if(mon) g_object_ref(mon); else { /* create a fake file monitor */ mon = fm_dummy_monitor_new(); g_object_weak_ref(G_OBJECT(mon), (GWeakNotify)on_dummy_monitor_destroy, gf); g_hash_table_insert(dummy_hash, g_object_ref(gf), mon); } G_UNLOCK(hash); return mon; }
/* FIXME: we should check for chained URIs */ gboolean gedit_utils_uri_has_writable_scheme (const gchar *uri) { GFile *gfile; gchar *scheme; GSList *writable_schemes; gboolean res; gfile = g_file_new_for_uri (uri); scheme = g_file_get_uri_scheme (gfile); g_return_val_if_fail (scheme != NULL, FALSE); g_object_unref (gfile); writable_schemes = gedit_prefs_manager_get_writable_vfs_schemes (); /* CHECK: should we use g_ascii_strcasecmp? - Paolo (Nov 6, 2005) */ res = (g_slist_find_custom (writable_schemes, scheme, (GCompareFunc)strcmp) != NULL); g_slist_foreach (writable_schemes, (GFunc)g_free, NULL); g_slist_free (writable_schemes); g_free (scheme); return res; }
void open_file_with_application (GFile *file) { GAppInfo *application; gchar *primary; GFileInfo *info; gchar *uri_scheme; const char *content; gboolean local = FALSE; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (!info) return; uri_scheme = g_file_get_uri_scheme (file); if (g_ascii_strcasecmp(uri_scheme,"file") == 0) local = TRUE; content = g_file_info_get_content_type (info); application = g_app_info_get_default_for_type (content, TRUE); if (!application) { primary = g_strdup_printf (_("Could not open folder \"%s\""), g_file_get_basename (file)); message (primary, _("There is no installed viewer capable " "of displaying the folder."), GTK_MESSAGE_ERROR, baobab.window); g_free (primary); } else { GList *uris = NULL; gchar *uri; uri = g_file_get_uri (file); uris = g_list_append (uris, uri); g_app_info_launch_uris (application, uris, NULL, NULL); g_list_free (uris); g_free (uri); } g_free (uri_scheme); if (application) g_object_unref (application); g_object_unref (info); }
static gboolean gst_gio_src_query (GstBaseSrc * base_src, GstQuery * query) { gboolean res; GstGioSrc *src = GST_GIO_SRC (base_src); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_SCHEDULING: { gchar *scheme; GstSchedulingFlags flags; flags = 0; if (src->file == NULL) goto forward_parent; scheme = g_file_get_uri_scheme (src->file); if (scheme == NULL) goto forward_parent; if (strcmp (scheme, "file") == 0) { GST_LOG_OBJECT (src, "local URI, assuming random access is possible"); flags |= GST_SCHEDULING_FLAG_SEEKABLE; } else if (strcmp (scheme, "http") == 0 || strcmp (scheme, "https") == 0) { GST_LOG_OBJECT (src, "blacklisted protocol '%s', " "no random access possible", scheme); } else { GST_LOG_OBJECT (src, "unhandled protocol '%s', asking parent", scheme); goto forward_parent; } g_free (scheme); gst_query_set_scheduling (query, flags, 1, -1, 0); gst_query_add_scheduling_mode (query, GST_PAD_MODE_PUSH); if (flags & GST_SCHEDULING_FLAG_SEEKABLE) gst_query_add_scheduling_mode (query, GST_PAD_MODE_PULL); res = TRUE; break; } default: forward_parent: res = GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_SRC_CLASS, query, (base_src, query), FALSE); break; } return res; }
static void irc_application_open (GApplication *self, GFile **files, int n_files, const char *hint) { for (int i = 0; i < n_files; ++i) { g_autofree char *uri = g_file_get_uri_scheme (files[i]); if (!g_str_equal (uri, "irc") && !g_str_equal (uri, "ircs")) { g_warning ("Recived invalid uri to open"); continue; } g_info ("Opening"); } }
static gboolean unsupported_scheme (CajaFileInfo *file) { gboolean result = FALSE; GFile *location; char *scheme; location = caja_file_info_get_location (file); scheme = g_file_get_uri_scheme (location); if (scheme != NULL) { const char *unsupported[] = { "trash", "computer", NULL }; int i; for (i = 0; unsupported[i] != NULL; i++) if (strcmp (scheme, unsupported[i]) == 0) result = TRUE; } g_free (scheme); g_object_unref (location); return result; }
/* This is based on nautilus_compute_title_for_uri() and * nautilus_file_get_display_name_nocopy() */ char * shell_util_get_label_for_uri (const char *text_uri) { GFile *file; char *label; GFile *root; char *root_display; /* Here's what we do: * + x-nautilus-search: URI * + check if the URI is a mount * + if file: URI: * - check for known file: URI * - check for description of the GFile * - use display name of the GFile * + else: * - check for description of the GFile * - if the URI is a root: "root displayname" * - else: "root displayname: displayname" */ label = NULL; //FIXME: see nautilus_query_to_readable_string() to have a nice name if (g_str_has_prefix (text_uri, "x-nautilus-search:")) return g_strdup (_("Search")); file = g_file_new_for_uri (text_uri); label = shell_util_get_file_display_name_if_mount (file); if (label) { g_object_unref (file); return label; } if (g_str_has_prefix (text_uri, "file:")) { label = shell_util_get_file_display_for_common_files (file); if (!label) label = shell_util_get_file_description (file); if (!label) label = shell_util_get_file_display_name (file, TRUE); g_object_unref (file); return label; } label = shell_util_get_file_description (file); if (label) { g_object_unref (file); return label; } root = shell_util_get_gfile_root (file); root_display = shell_util_get_file_description (root); if (!root_display) root_display = shell_util_get_file_display_name (root, FALSE); if (!root_display) /* can happen with URI schemes non supported by gvfs */ root_display = g_file_get_uri_scheme (root); if (g_file_equal (file, root)) label = root_display; else { char *displayname; displayname = shell_util_get_file_display_name (file, TRUE); /* Translators: the first string is the name of a gvfs * method, and the second string is a path. For * example, "Trash: some-directory". It means that the * directory called "some-directory" is in the trash. */ label = g_strdup_printf (_("%1$s: %2$s"), root_display, displayname); g_free (root_display); g_free (displayname); } g_object_unref (root); g_object_unref (file); return label; }
static gchar* thunar_file_info_get_uri_scheme (ThunarxFileInfo *file_info) { return g_file_get_uri_scheme (THUNAR_PLUGGER_FILE (file_info)->gfile); }
gboolean rejilla_image_format_get_cue_size (gchar *uri, guint64 *blocks, guint64 *size_img, GCancellable *cancel, GError **error) { GFile *file; gchar *line; gint64 cue_size = 0; GFileInputStream *input; GDataInputStream *stream; file = g_file_new_for_uri (uri); input = g_file_read (file, cancel, error); if (!input) { g_object_unref (file); return FALSE; } stream = g_data_input_stream_new (G_INPUT_STREAM (input)); g_object_unref (input); while ((line = g_data_input_stream_read_line (stream, NULL, cancel, error))) { const gchar *ptr; if ((ptr = strstr (line, "FILE"))) { GFileInfo *info; gchar *file_path; GFile *file_img = NULL; ptr += 4; /* get the path (NOTE: if ptr is NULL file_path as well) */ ptr = rejilla_image_format_read_path (ptr, &file_path); if (!ptr) { g_object_unref (stream); g_object_unref (file); g_free (line); return FALSE; } /* check if the path is relative, if so then add the root path */ if (file_path && !g_path_is_absolute (file_path)) { GFile *parent; parent = g_file_get_parent (file); file_img = g_file_resolve_relative_path (parent, file_path); g_object_unref (parent); } else if (file_path) { gchar *img_uri; gchar *scheme; scheme = g_file_get_uri_scheme (file); img_uri = g_strconcat (scheme, "://", file_path, NULL); g_free (scheme); file_img = g_file_new_for_commandline_arg (img_uri); g_free (img_uri); } g_free (file_path); /* NOTE: follow symlink if any */ info = g_file_query_info (file_img, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); g_object_unref (file_img); if (!info) { g_free (line); g_object_unref (file); g_object_unref (stream); return FALSE; } cue_size += g_file_info_get_size (info); g_object_unref (info); } else if ((ptr = strstr (line, "PREGAP"))) { ptr += 6; if (isspace (*ptr)) { gint64 size_pregap; ptr ++; ptr = rejilla_image_format_get_MSF_address (ptr, &size_pregap); if (ptr) cue_size += size_pregap * 2352; } } else if ((ptr = strstr (line, "POSTGAP"))) { ptr += 7; if (isspace (*ptr)) { gint64 size_postgap; ptr ++; ptr = rejilla_image_format_get_MSF_address (ptr, &size_postgap); if (ptr) cue_size += size_postgap * 2352; } } g_free (line); } g_object_unref (stream); g_object_unref (file); if (size_img) *size_img = cue_size; if (blocks) *blocks = REJILLA_BYTES_TO_SECTORS (cue_size, 2352); return TRUE; }
static gboolean rejilla_image_format_get_FILE_info (const gchar *ptr, GFile *parent, gint64 *size_img, GError **error) { gchar *path = NULL; gint64 start = 0; GFileInfo *info; GFile *file = NULL; gchar *tmp; /* get the path and skip it */ ptr = rejilla_image_format_read_path (ptr, &path); if (!ptr) return FALSE; /* skip white spaces */ while (isspace (*ptr)) ptr++; /* skip a possible #.... (offset in bytes) */ tmp = g_utf8_strchr (ptr, -1, '#'); if (tmp) { tmp ++; while (isdigit (*tmp)) tmp ++; while (isspace (*tmp)) tmp++; ptr = tmp; } /* get the start */ ptr = rejilla_image_format_get_MSF_address (ptr, &start); if (!ptr) { g_free (path); return FALSE; } /* skip white spaces */ while (isspace (*ptr)) ptr++; if (ptr [0] == '\0' || (ptr [0] == '/' && ptr [1] == '/')) goto stat_end; /* get the size */ if (!rejilla_image_format_get_MSF_address (ptr, size_img)) { g_free (path); return FALSE; } g_free (path); return TRUE; stat_end: /* check if the path is relative, if so then add the root path */ if (path && !g_path_is_absolute (path)) file = g_file_resolve_relative_path (parent, path); else if (path) { gchar *img_uri; gchar *scheme; scheme = g_file_get_uri_scheme (parent); img_uri = g_strconcat (scheme, "://", path, NULL); g_free (scheme); file = g_file_new_for_commandline_arg (img_uri); g_free (img_uri); } else return FALSE; g_free (path); /* NOTE: follow symlink if any */ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); g_object_unref (file); if (!info) return FALSE; if (size_img) *size_img = REJILLA_BYTES_TO_SECTORS (g_file_info_get_size (info), 2352) - start; g_object_unref (info); return TRUE; }
static gboolean rejilla_image_format_get_DATAFILE_info (const gchar *ptr, GFile *parent, gint64 *size_file, GError **error) { gchar *path = NULL; GFileInfo *info; GFile *file; /* get the path. NOTE: no need to check if it's relative since that's * just to skip it. */ ptr = rejilla_image_format_read_path (ptr, &path); if (!ptr) return FALSE; /* skip white spaces */ while (isspace (*ptr)) ptr++; if (ptr [0] == '\0' || (ptr [0] == '/' && ptr [1] == '/')) goto stat_end; if (!rejilla_image_format_get_MSF_address (ptr, size_file)) { g_free (path); return FALSE; } g_free (path); return TRUE; stat_end: /* check if the path is relative, if so then add the root path */ if (path && !g_path_is_absolute (path)) file = g_file_resolve_relative_path (parent, path); else if (path) { gchar *img_uri; gchar *scheme; scheme = g_file_get_uri_scheme (parent); img_uri = g_strconcat (scheme, "://", path, NULL); g_free (scheme); file = g_file_new_for_commandline_arg (img_uri); g_free (img_uri); } g_free (path); /* NOTE: follow symlink if any */ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); g_object_unref (file); if (!info) return FALSE; if (size_file) *size_file = REJILLA_BYTES_TO_SECTORS (g_file_info_get_size (info), 2352); g_object_unref (info); return TRUE; }
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; }