static gboolean set_background_image_from_uri (PanelToplevel *toplevel, const char *uri) { GFile *file; GSettings *settings; file = g_file_new_for_uri (uri); if (!g_file_is_native (file)) { g_object_unref (file); return FALSE; } g_object_unref (file); settings = get_settings_background_for_toplevel (toplevel); if (!g_settings_is_writable (settings, PANEL_BACKGROUND_TYPE_KEY) || !g_settings_is_writable (settings, PANEL_BACKGROUND_IMAGE_URI_KEY)) { g_object_unref (settings); return FALSE; } g_settings_set_string (settings, PANEL_BACKGROUND_IMAGE_URI_KEY, uri); g_settings_set_enum (settings, PANEL_BACKGROUND_TYPE_KEY, PANEL_BACK_IMAGE); g_object_unref (settings); return FALSE; }
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; }
GFile * uri_backend_map_image (GFile *file, GimpRunMode run_mode) { gboolean success = TRUE; if (run_mode == GIMP_RUN_INTERACTIVE) { GError *error = NULL; if (! mount_enclosing_volume (file, &error)) { if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_ALREADY_MOUNTED) success = FALSE; g_error_free (error); } } if (success && g_file_is_native (file)) return g_object_ref (file); return NULL; }
NautilusMonitor * nautilus_monitor_directory (GFile *location) { GFileMonitor *dir_monitor; NautilusMonitor *ret; ret = g_slice_new0 (NautilusMonitor); dir_monitor = g_file_monitor_directory (location, G_FILE_MONITOR_WATCH_MOUNTS, NULL, NULL); if (dir_monitor != NULL) { ret->monitor = dir_monitor; } else if (!g_file_is_native (location)) { ret->location = g_object_ref (location); ret->volume_monitor = g_volume_monitor_get (); } if (ret->monitor != NULL) { g_signal_connect (ret->monitor, "changed", G_CALLBACK (dir_changed), ret); } if (ret->volume_monitor != NULL) { g_signal_connect (ret->volume_monitor, "mount-removed", G_CALLBACK (mount_removed), ret); } /* We return a monitor even on failure, so we can avoid later trying again */ return ret; }
gboolean panel_show_uri_force_mime_type (GdkScreen *screen, const gchar *uri, const gchar *mime_type, guint32 timestamp, GError **error) { GFile *file; GAppInfo *app; gboolean ret; g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (mime_type != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = g_file_new_for_uri (uri); app = g_app_info_get_default_for_type (mime_type, !g_file_is_native (file)); g_object_unref (file); if (app == NULL) { /* no application for the mime type, so let's fallback on * automatic detection */ return panel_show_uri (screen, uri, timestamp, error); } ret = panel_app_info_launch_uri (app, uri, screen, timestamp, error); g_object_unref (app); return ret; }
static void pdf_load_job_from_uri (PdfLoadJob *job) { GFile *file; const gchar *gdata_prefix = "google:drive:"; const gchar *zpj_prefix = "windows-live:skydrive:"; if (g_str_has_prefix (job->uri, gdata_prefix)) { job->resource_id = g_strdup (job->uri + strlen (gdata_prefix)); pdf_load_job_from_gdata_cache (job); return; } if (g_str_has_prefix (job->uri, zpj_prefix)) { job->resource_id = g_strdup (job->uri + strlen (zpj_prefix)); pdf_load_job_from_zpj_cache (job); return; } file = g_file_new_for_uri (job->uri); if (!g_file_is_native (file)) pdf_load_job_from_remote_file (job); else pdf_load_job_from_regular_file (job); g_object_unref (file); }
/* Returns TRUE if the file is in XDG_DATA_DIRS. This is used for deciding if a desktop file is "trusted" based on the path */ gboolean nautilus_is_in_system_dir (GFile *file) { const char * const * data_dirs; char *path; int i; gboolean res; if (!g_file_is_native (file)) { return FALSE; } path = g_file_get_path (file); res = FALSE; data_dirs = g_get_system_data_dirs (); for (i = 0; path != NULL && data_dirs[i] != NULL; i++) { if (g_str_has_prefix (path, data_dirs[i])) { res = TRUE; break; } } return res; }
static GFile * file_remote_mount_file (Gimp *gimp, GFile *file, GimpProgress *progress) { gboolean success = TRUE; if (! gimp->no_interface) { GError *error = NULL; if (! gimp_mount_enclosing_volume (gimp, file, progress, &error)) { if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_ALREADY_MOUNTED) success = FALSE; g_clear_error (&error); } } if (success && g_file_is_native (file)) return g_object_ref (file); return NULL; }
void thunar_util_load_bookmarks (GFile *bookmarks_file, ThunarBookmarksFunc foreach_func, gpointer user_data) { gchar *bookmarks_path; gchar line[1024]; const gchar *name; gchar *space; FILE *fp; gint row_num = 1; GFile *file; _thunar_return_if_fail (G_IS_FILE (bookmarks_file)); _thunar_return_if_fail (g_file_is_native (bookmarks_file)); _thunar_return_if_fail (foreach_func != NULL); /* determine the path to the GTK+ bookmarks file */ bookmarks_path = g_file_get_path (bookmarks_file); /* append the GTK+ bookmarks (if any) */ fp = fopen (bookmarks_path, "r"); if (G_LIKELY (fp != NULL)) { while (fgets (line, sizeof (line), fp) != NULL) { /* remove trailing spaces */ g_strchomp (line); /* skip over empty lines */ if (*line == '\0' || *line == ' ') continue; /* check if there is a custom name in the line */ name = NULL; space = strchr (line, ' '); if (space != NULL) { /* break line */ *space++ = '\0'; /* get the custom name */ if (G_LIKELY (*space != '\0')) name = space; } file = g_file_new_for_uri (line); /* callback */ foreach_func (file, name, row_num++, user_data); g_object_unref (G_OBJECT (file)); } fclose (fp); } g_free (bookmarks_path); }
JS_EXPORT_API gboolean dentry_is_native(Entry* e) { if (G_IS_FILE(e)) { return g_file_is_native (G_FILE(e)); } return TRUE; }
/*--------------------------------------------------------------------------*/ static void get_share_info_for_file_info (NemoFileInfo *file, ShareInfo **share_info, gboolean *is_shareable) { char *uri; char *local_path = NULL; GFile *f; *share_info = NULL; *is_shareable = FALSE; uri = nemo_file_info_get_uri (file); f = nemo_file_info_get_location(file); if (!uri) goto out; #define NETWORK_SHARE_PREFIX "network:///share-" if (g_str_has_prefix (uri, NETWORK_SHARE_PREFIX)) { const char *share_name; share_name = uri + strlen (NETWORK_SHARE_PREFIX); /* FIXME: NULL GError */ if (!shares_get_share_info_for_share_name (share_name, share_info, NULL)) { *share_info = NULL; *is_shareable = TRUE; /* it *has* the prefix, anyway... we are just unsynchronized with what gnome-vfs thinks */ } else { *is_shareable = TRUE; } goto out; } if (!nemo_file_info_is_directory(file)) goto out; local_path = g_file_get_path(f); if (!local_path || !g_file_is_native(f)) goto out; /* FIXME: NULL GError */ if (!shares_get_share_info_for_path (local_path, share_info, NULL)) goto out; *is_shareable = TRUE; out: g_object_unref(f); g_free (uri); g_free (local_path); }
static EvDocument * atril_thumbnailer_get_document (GFile *file) { EvDocument *document = NULL; gchar *uri; GFile *tmp_file = NULL; GError *error = NULL; if (!g_file_is_native (file)) { gchar *base_name, *template;
FmPath* fm_path_new_for_gfile(GFile* gf) { FmPath* path; char* str; if( g_file_is_native(gf) ) str = g_file_get_path(gf); else str = g_file_get_uri(gf); path = fm_path_new(str); g_free(str); return path; }
gboolean nautilus_directory_is_local (NautilusDirectory *directory) { g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE); if (directory->details->location == NULL) { return TRUE; } return nautilus_directory_is_in_trash (directory) || g_file_is_native (directory->details->location); }
static NautilusBookmark * new_bookmark_from_uri (const char *uri, const char *label) { NautilusBookmark *new_bookmark; NautilusFile *file; char *name; GIcon *icon; gboolean has_label; GFile *location; gboolean native; location = NULL; if (uri) { location = g_file_new_for_uri (uri); } has_label = FALSE; if (!label) { name = nautilus_compute_title_for_location (location); } else { name = g_strdup (label); has_label = TRUE; } new_bookmark = NULL; if (uri) { native = g_file_is_native (location); file = nautilus_file_get (location); icon = NULL; if (nautilus_file_check_if_ready (file, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON)) { icon = nautilus_file_get_gicon (file, 0); } nautilus_file_unref (file); if (icon == NULL) { icon = native ? g_themed_icon_new (NAUTILUS_ICON_FOLDER) : g_themed_icon_new (NAUTILUS_ICON_FOLDER_REMOTE); } new_bookmark = nautilus_bookmark_new (location, name, has_label, icon); g_object_unref (icon); } g_free (name); g_object_unref (location); return new_bookmark; }
GFileMonitor* fm_monitor_lookup_monitor(GFile* gf) { GFileMonitor* ret = NULL; if(G_UNLIKELY(!gf)) return NULL; G_LOCK(hash); ret = (GFileMonitor*)g_hash_table_lookup(hash, gf); if(!ret && !g_file_is_native(gf)) ret = (GFileMonitor*)g_hash_table_lookup(dummy_hash, gf); if(ret) g_object_ref(ret); G_UNLOCK(hash); return ret; }
/*--------------------------------------------------------------------------*/ static gchar * get_fullpath_from_fileinfo(NemoFileInfo *fileinfo) { GFile *file; gchar *fullpath; g_assert (fileinfo != NULL); file = nemo_file_info_get_location(fileinfo); fullpath = g_file_get_path(file); g_assert (fullpath != NULL && g_file_is_native(file)); /* In the beginning we checked that this was a local URI */ g_object_unref(file); return(fullpath); }
static void print_diff_item (char prefix, GFile *base, GFile *file) { if (g_file_is_native (file)) { g_autofree char *relpath = g_file_get_relative_path (base, file); g_print ("%c %s\n", prefix, relpath); } else { g_print ("%c %s\n", prefix, gs_file_get_path_cached (file)); } }
GFileMonitor* fm_monitor_directory(GFile* gf, GError** err) { GFileMonitor* ret = NULL; G_LOCK(hash); ret = (GFileMonitor*)g_hash_table_lookup(hash, gf); if(!ret && !g_file_is_native(gf)) ret = (GFileMonitor*)g_hash_table_lookup(dummy_hash, gf); if(ret) g_object_ref(ret); else { GError* e = NULL; ret = g_file_monitor_directory(gf, G_FILE_MONITOR_WATCH_MOUNTS, NULL, &e); if(ret) { g_object_weak_ref(G_OBJECT(ret), (GWeakNotify)on_monitor_destroy, gf); g_file_monitor_set_rate_limit(ret, MONITOR_RATE_LIMIT); g_hash_table_insert(hash, g_object_ref(gf), ret); } else { if(e) { if(e->domain == G_IO_ERROR && e->code == G_IO_ERROR_NOT_SUPPORTED) { /* create a fake file monitor */ ret = fm_dummy_monitor_new(); g_error_free(e); g_object_weak_ref(G_OBJECT(ret), (GWeakNotify)on_dummy_monitor_destroy, gf); g_hash_table_insert(dummy_hash, g_object_ref(gf), ret); } else { g_debug("error creating file monitor: %S", e->message); G_UNLOCK(hash); if(err) *err = e; else g_error_free(e); return NULL; } } } } G_UNLOCK(hash); return ret; }
/** * eog_util_file_is_persistent: * @file: a #GFile * * Checks whether @file is a non-removable local mount. * * Returns: %TRUE if @file is in a non-removable mount, * %FALSE otherwise or when it is remote. **/ gboolean eog_util_file_is_persistent (GFile *file) { GMount *mount; if (!g_file_is_native (file)) return FALSE; mount = g_file_find_enclosing_mount (file, NULL, NULL); if (mount) { if (g_mount_can_unmount (mount)) { return FALSE; } } return TRUE; }
static gboolean is_directory_local (CajaFileInfo *info) { gchar *str; GFile *file; gboolean is_local; str = caja_file_info_get_uri (info); file = g_file_new_for_uri (str); is_local = g_file_is_native (file); g_object_unref (file); g_free (str); return is_local; }
static gboolean should_autorun_mount (GMount *mount) { GFile *root; GVolume *enclosing_volume; gboolean ignore_autorun; ignore_autorun = TRUE; enclosing_volume = g_mount_get_volume (mount); if (enclosing_volume != NULL) { if (g_object_get_data (G_OBJECT (enclosing_volume), "caja-allow-autorun") != NULL) { ignore_autorun = FALSE; g_object_set_data (G_OBJECT (enclosing_volume), "caja-allow-autorun", NULL); } } if (ignore_autorun) { if (enclosing_volume != NULL) { g_object_unref (enclosing_volume); } return FALSE; } root = g_mount_get_root (mount); /* only do autorun on local files or files where g_volume_should_automount() returns TRUE */ ignore_autorun = TRUE; if ((g_file_is_native (root) && !should_skip_native_mount_root (root)) || (enclosing_volume != NULL && g_volume_should_automount (enclosing_volume))) { ignore_autorun = FALSE; } if (enclosing_volume != NULL) { g_object_unref (enclosing_volume); } g_object_unref (root); return !ignore_autorun; }
static void show_completed_file (GFile *hit, gboolean is_dir, const char *arg) { char *path, *cwd, *display, *t; GFile *cwd_f; GFile *home; if (g_file_is_native (hit)) { cwd = g_get_current_dir (); cwd_f = g_file_new_for_path (cwd); g_free (cwd); home = g_file_new_for_path (g_get_home_dir ()); if ((g_file_has_prefix (hit, home) || g_file_equal (hit, home)) && arg[0] == '~') { t = g_file_get_relative_path (home, hit); path = g_strconcat ("~", (t != NULL) ? "/": "", t, NULL); g_free (t); } else if (g_file_has_prefix (hit, cwd_f) && !g_path_is_absolute (arg)) path = g_file_get_relative_path (cwd_f, hit); else path = g_file_get_path (hit); g_object_unref (cwd_f); g_object_unref (home); display = shell_quote (path); g_free (path); } else display = g_file_get_uri (hit); g_print ("%s%s\n", display, (is_dir)?"/":""); g_free (display); }
static void nemo_bookmark_set_icon_to_default (NemoBookmark *bookmark) { GIcon *icon, *emblemed_icon, *folder; GEmblem *emblem; char *uri; if (g_file_is_native (bookmark->details->location)) { folder = g_themed_icon_new (NEMO_ICON_FOLDER); } else { uri = nemo_bookmark_get_uri (bookmark); if (g_str_has_prefix (uri, EEL_SEARCH_URI)) { folder = g_themed_icon_new (NEMO_ICON_FOLDER_SAVED_SEARCH); } else { folder = g_themed_icon_new (NEMO_ICON_FOLDER_REMOTE); } g_free (uri); } if (nemo_bookmark_uri_known_not_to_exist (bookmark)) { DEBUG ("%s: file does not exist, add emblem", nemo_bookmark_get_name (bookmark)); icon = g_themed_icon_new (GTK_STOCK_DIALOG_WARNING); emblem = g_emblem_new (icon); emblemed_icon = g_emblemed_icon_new (folder, emblem); g_object_unref (emblem); g_object_unref (icon); g_object_unref (folder); folder = emblemed_icon; } DEBUG ("%s: setting icon to default", nemo_bookmark_get_name (bookmark)); g_object_set (bookmark, "icon", folder, NULL); g_object_unref (folder); }
static gboolean add_single_file (BgPicturesSource *bg_source, GFile *file, GFileInfo *info, const char *source_uri) { const gchar *content_type; /* find png and jpeg files */ content_type = g_file_info_get_content_type (info); if (!content_type) return FALSE; if (g_str_equal ("image/png", content_type) || g_str_equal ("image/jpeg", content_type) || g_str_equal ("image/svg+xml", content_type)) { CcBackgroundItem *item; char *uri; /* create a new CcBackgroundItem */ uri = g_file_get_uri (file); item = cc_background_item_new (uri); g_free (uri); g_object_set (G_OBJECT (item), "flags", CC_BACKGROUND_ITEM_HAS_URI | CC_BACKGROUND_ITEM_HAS_SHADING, "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID, "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM, NULL); if (source_uri != NULL && !g_file_is_native (file)) g_object_set (G_OBJECT (item), "source-url", source_uri, NULL); g_object_set_data (G_OBJECT (file), "item", item); g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source); g_object_unref (file); return TRUE; } return FALSE; }
static gchar * get_default_folder_icon_name (NemoBookmark *bookmark) { gchar *ret = NULL; if (g_file_is_native (bookmark->details->location)) { gchar *uri = g_file_get_uri (bookmark->details->location); ret = g_strdup (NEMO_ICON_SYMBOLIC_FOLDER); } else { gchar *uri = g_file_get_uri (bookmark->details->location); if (g_str_has_prefix (uri, EEL_SEARCH_URI)) { ret = g_strdup (NEMO_ICON_SYMBOLIC_FOLDER_SAVED_SEARCH); } else { ret = g_strdup (NEMO_ICON_SYMBOLIC_FOLDER_REMOTE); } g_free (uri); } return ret; }
static gchar * ide_file_settings_repr (IdeObject *object) { IdeFileSettings *self = (IdeFileSettings *)object; IdeFileSettingsPrivate *priv = ide_file_settings_get_instance_private (self); if (priv->file != NULL) { g_autofree gchar *uri = NULL; if (g_file_is_native (priv->file)) return g_strdup_printf ("%s path=\"%s\"", G_OBJECT_TYPE_NAME (self), g_file_peek_path (priv->file)); uri = g_file_get_uri (priv->file); return g_strdup_printf ("%s uri=\"%s\"", G_OBJECT_TYPE_NAME (self), uri); } return IDE_OBJECT_CLASS (ide_file_settings_parent_class)->repr (object); }
static GtkListStore * get_list_store(const gchar *recent_group) { GtkRecentManager *manager = gtk_recent_manager_get_default(); GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); GList *ptr; int count = 0; GtkTreeIter iter; GList *list = gtk_recent_manager_get_items(manager); for (ptr = list; (ptr != NULL) && (count < 10); ptr = ptr->next) { GtkRecentInfo *info = ptr->data; if (!gtk_recent_info_has_application(info, "KCemu")) continue; if ((recent_group != NULL) && !gtk_recent_info_has_group(info, recent_group)) continue; GFile *file = g_file_new_for_uri(gtk_recent_info_get_uri(info)); if (g_file_is_native(file) /* && g_file_query_exists(file, NULL) */) { gchar *path = g_file_get_path(file); gchar *basename = g_file_get_basename(file); if ((path != NULL) && (basename != NULL)) { gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, basename, 1, path, -1); count++; } g_free(path); g_free(basename); } g_object_unref(file); } return store; }
gboolean panel_show_uri_force_mime_type (GdkScreen *screen, const gchar *uri, const gchar *mime_type, guint32 timestamp, GError **error) { GFile *file; GAppInfo *appinfo; gboolean ret; GdkDisplay *display; GdkAppLaunchContext *context; GList *uris; g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (mime_type != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = g_file_new_for_uri (uri); appinfo = g_app_info_get_default_for_type (mime_type, !g_file_is_native (file)); g_object_unref (file); if (appinfo == NULL) { /* no application for the mime type, so let's fallback on * automatic detection */ return panel_show_uri (screen, uri, timestamp, error); } uris = g_list_append (NULL, (gpointer)uri); display = gdk_screen_get_display (screen); context = gdk_display_get_app_launch_context (display); ret = g_app_info_launch_uris (appinfo, uris, G_APP_LAUNCH_CONTEXT(context), error); g_object_unref (context); g_list_free (uris); g_object_unref (appinfo); return ret; }
static void nautilus_bookmark_update_exists (NautilusBookmark *bookmark) { /* Convert to a path, returning FALSE if not local. */ if (!g_file_is_native (bookmark->details->location) && bookmark->details->exists_id == 0) { bookmark->details->exists_id = g_idle_add (exists_non_native_idle_cb, bookmark); return; } if (bookmark->details->cancellable != NULL) { return; } bookmark->details->cancellable = g_cancellable_new (); g_file_query_info_async (bookmark->details->location, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, G_PRIORITY_DEFAULT, bookmark->details->cancellable, exists_query_info_ready_cb, bookmark); }