static gboolean try_enumerate (GVfsBackend *backend, GVfsJobEnumerate *job, const char *filename, GFileAttributeMatcher *matcher, GFileQueryInfoFlags flags) { GFileInfo *info1, *info2; GList *l; g_print ("try_enumerate (%s)\n", filename); g_vfs_job_succeeded (G_VFS_JOB (job)); info1 = g_file_info_new (); info2 = g_file_info_new (); g_file_info_set_name (info1, "file1"); g_file_info_set_file_type (info1, G_FILE_TYPE_REGULAR); g_file_info_set_name (info2, "file2"); g_file_info_set_file_type (info2, G_FILE_TYPE_REGULAR); l = NULL; l = g_list_append (l, info1); l = g_list_append (l, info2); g_vfs_job_enumerate_add_infos (job, l); g_list_free (l); g_object_unref (info1); g_object_unref (info2); g_vfs_job_enumerate_done (job); return TRUE; }
static gboolean try_query_info (GVfsBackend *backend, GVfsJobQueryInfo *job, const char *filename, GFileQueryInfoFlags flags, GFileInfo *info, GFileAttributeMatcher *matcher) { if (is_root (filename)) { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); g_file_info_set_display_name (info, g_vfs_backend_get_display_name (backend)); g_file_info_set_content_type (info, "inode/directory"); icon = g_vfs_backend_get_icon (backend); if (icon != NULL) g_file_info_set_icon (info, icon); g_vfs_job_succeeded (G_VFS_JOB (job)); } else update_cache (G_VFS_BACKEND_AFP_BROWSE (backend), G_VFS_JOB (job)->cancellable, query_info_cb, job); return TRUE; }
static GFileInfo * create_root_file_info (GVfsBackendFtp *ftp) { GFileInfo *info; GIcon *icon; char *display_name; info = g_file_info_new (); g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); display_name = g_strdup_printf (_("/ on %s"), ftp->host_display_name); g_file_info_set_display_name (info, display_name); g_free (display_name); g_file_info_set_edit_name (info, "/"); g_file_info_set_content_type (info, "inode/directory"); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, "inode/directory"); icon = g_themed_icon_new ("folder-remote"); g_file_info_set_icon (info, icon); g_object_unref (icon); return info; }
static IdeProjectFile * create_file (IdeContext *context, GFile *file, GFileType file_type) { g_autofree gchar *path = NULL; g_autofree gchar *name = NULL; g_autoptr(GFileInfo) file_info = NULL; IdeVcs *vcs; GFile *workdir; g_assert (IDE_IS_CONTEXT (context)); g_assert (G_IS_FILE (file)); g_assert ((file_type == G_FILE_TYPE_DIRECTORY) || (file_type == G_FILE_TYPE_REGULAR)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); path = g_file_get_relative_path (workdir, file); name = g_file_get_basename (file); file_info = g_file_info_new (); g_file_info_set_file_type (file_info, file_type); g_file_info_set_name (file_info, name); g_file_info_set_display_name (file_info, name); return g_object_new (IDE_TYPE_PROJECT_FILE, "context", context, "file", file, "file-info", file_info, "path", path, "parent", NULL, NULL); }
static void fill_info (GFileInfo *info, GVfsAfpVolumeData *vol_data, GVfsBackendAfpBrowse *afp_backend) { GIcon *icon; GMountSpec *mount_spec; char *uri; g_file_info_set_name (info, vol_data->name); g_file_info_set_display_name (info, vol_data->name); g_file_info_set_edit_name (info, vol_data->name); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL, TRUE); g_file_info_set_content_type (info, "inode/directory"); g_file_info_set_file_type (info, G_FILE_TYPE_MOUNTABLE); g_file_info_set_attribute_boolean (info, "afp::volume-password-protected", (vol_data->flags & 0x01)); icon = g_themed_icon_new_with_default_fallbacks ("folder-remote-afp"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); mount_spec = g_mount_spec_new ("afp-volume"); g_mount_spec_set (mount_spec, "host", g_network_address_get_hostname (G_NETWORK_ADDRESS (afp_backend->addr))); g_mount_spec_set (mount_spec, "volume", vol_data->name); g_mount_spec_set (mount_spec, "user", afp_backend->logged_in_user); if (g_mount_tracker_has_mount_spec (afp_backend->mount_tracker, mount_spec)) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT, TRUE); } else { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT, TRUE); g_file_info_set_attribute_boolean(info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT, FALSE); } g_mount_spec_unref (mount_spec); uri = g_strdup_printf ("afp://%s/%s", g_network_address_get_hostname (G_NETWORK_ADDRESS (afp_backend->addr)), vol_data->name); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, uri); g_free (uri); }
gboolean add_file_to_mtree (GFile *file, const char *name, OstreeRepo *repo, OstreeMutableTree *mtree, GCancellable *cancellable, GError **error) { g_autoptr(GFileInfo) file_info = NULL; g_autoptr(GInputStream) raw_input = NULL; g_autoptr(GInputStream) input = NULL; guint64 length; g_autofree guchar *child_file_csum = NULL; g_autofree char *tmp_checksum = NULL; file_info = g_file_query_info (file, "standard::size", 0, cancellable, error); if (file_info == NULL) return FALSE; g_file_info_set_name (file_info, name); g_file_info_set_file_type (file_info, G_FILE_TYPE_REGULAR); g_file_info_set_attribute_uint32 (file_info, "unix::uid", 0); g_file_info_set_attribute_uint32 (file_info, "unix::gid", 0); g_file_info_set_attribute_uint32 (file_info, "unix::mode", 0100644); raw_input = (GInputStream *) g_file_read (file, cancellable, error); if (raw_input == NULL) return FALSE; if (!ostree_raw_file_to_content_stream (raw_input, file_info, NULL, &input, &length, cancellable, error)) return FALSE; if (!ostree_repo_write_content (repo, NULL, input, length, &child_file_csum, cancellable, error)) return FALSE; tmp_checksum = ostree_checksum_from_bytes (child_file_csum); if (!ostree_mutable_tree_replace_file (mtree, name, tmp_checksum, error)) return FALSE; return TRUE; }
static void list_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GError *error = NULL; GList *list; GList *scan; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _g_object_list_unref (data->photos); data->photos = flickr_service_list_photos_finish (data->service, result, &error); if (error != NULL) { if (data->service != NULL) gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the photo list"), error); g_clear_error (&error); gtk_widget_destroy (data->dialog); return; } list = NULL; for (scan = data->photos; scan; scan = scan->next) { FlickrPhoto *photo = scan->data; GthFileData *file_data; if (photo->url[FLICKR_URL_O] == NULL) continue; file_data = gth_file_data_new_for_uri (photo->url[FLICKR_URL_O], (photo->mime_type != NULL) ? photo->mime_type : "image/jpeg"); g_file_info_set_file_type (file_data->info, G_FILE_TYPE_REGULAR); g_file_info_set_size (file_data->info, FAKE_SIZE); /* set a fake size to make the progress dialog work correctly */ g_file_info_set_attribute_object (file_data->info, "flickr::object", G_OBJECT (photo)); list = g_list_prepend (list, file_data); } gth_file_list_set_files (GTH_FILE_LIST (data->file_list), list); update_selection_status (data); gtk_widget_set_sensitive (GET_WIDGET ("download_button"), list != NULL); _g_object_list_unref (list); }
static void build_context (GbProjectTreeBuilder *self, IdeTreeNode *node) { g_autoptr(GbProjectFile) item = NULL; g_autoptr(GFileInfo) file_info = NULL; g_autofree gchar *name = NULL; IdeTreeNode *child; IdeContext *context; IdeProject *project; IdeVcs *vcs; GFile *workdir; g_return_if_fail (GB_IS_PROJECT_TREE_BUILDER (self)); g_return_if_fail (IDE_IS_TREE_NODE (node)); context = IDE_CONTEXT (ide_tree_node_get_item (node)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); project = ide_context_get_project (context); file_info = g_file_info_new (); g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY); name = g_file_get_basename (workdir); g_file_info_set_name (file_info, name); g_file_info_set_display_name (file_info, name); item = g_object_new (GB_TYPE_PROJECT_FILE, "file", workdir, "file-info", file_info, NULL); child = g_object_new (IDE_TYPE_TREE_NODE, "item", item, "icon-name", "folder-symbolic", NULL); g_object_bind_property (project, "name", child, "text", G_BINDING_SYNC_CREATE); ide_tree_node_append (node, child); }
static void list_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GError *error = NULL; GList *list; GList *scan; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _g_object_list_unref (data->photos); data->photos = facebook_service_list_photos_finish (data->service, result, &error); if (error != NULL) { if (data->service != NULL) gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the photo list"), error); g_clear_error (&error); gtk_widget_destroy (data->dialog); return; } list = NULL; for (scan = data->photos; scan; scan = scan->next) { FacebookPhoto *photo = scan->data; GthFileData *file_data; file_data = gth_file_data_new_for_uri (facebook_photo_get_original_url (photo), "image/jpeg"); g_file_info_set_file_type (file_data->info, G_FILE_TYPE_REGULAR); g_file_info_set_size (file_data->info, FAKE_SIZE); /* set a fake size to make the progress dialog work correctly */ g_file_info_set_attribute_object (file_data->info, "facebook::object", G_OBJECT (photo)); list = g_list_prepend (list, file_data); } gth_file_list_set_files (GTH_FILE_LIST (data->file_list), list); update_selection_status (data); gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, list != NULL); _g_object_list_unref (list); }
static void list_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; PicasaWebService *picasaweb = PICASA_WEB_SERVICE (source_object); GError *error = NULL; GList *list; GList *scan; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _g_object_list_unref (data->photos); data->photos = picasa_web_service_list_albums_finish (picasaweb, result, &error); if (error != NULL) { gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the photo list"), error); g_clear_error (&error); gtk_widget_destroy (data->dialog); return; } list = NULL; for (scan = data->photos; scan; scan = scan->next) { PicasaWebPhoto *photo = scan->data; GthFileData *file_data; file_data = gth_file_data_new_for_uri (photo->uri, photo->mime_type); g_file_info_set_file_type (file_data->info, G_FILE_TYPE_REGULAR); g_file_info_set_size (file_data->info, photo->size); g_file_info_set_attribute_object (file_data->info, "gphoto::object", G_OBJECT (photo)); list = g_list_prepend (list, file_data); } gth_file_list_set_files (GTH_FILE_LIST (data->file_list), list); update_selection_status (data); gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, TRUE); _g_object_list_unref (list); }
static gboolean trash_backend_query_info (GVfsBackend *vfs_backend, GVfsJobQueryInfo *job, const char *filename, GFileQueryInfoFlags flags, GFileInfo *info, GFileAttributeMatcher *matcher) { GVfsBackendTrash *backend = G_VFS_BACKEND_TRASH (vfs_backend); g_assert (filename[0] == '/'); if (filename[1]) { GError *error = NULL; gboolean is_toplevel; TrashItem *item; GFile *real; real = trash_backend_get_file (backend, filename, &item, &is_toplevel, &error); if (real) { GFileInfo *real_info; real_info = g_file_query_info (real, job->attributes, flags, G_VFS_JOB (job)->cancellable, &error); g_object_unref (real); if (real_info) { g_file_info_copy_into (real_info, info); trash_backend_add_info (item, info, is_toplevel); g_vfs_job_succeeded (G_VFS_JOB (job)); trash_item_unref (item); g_object_unref (real_info); return TRUE; } trash_item_unref (item); } g_vfs_job_failed_from_error (G_VFS_JOB (job), error); g_error_free (error); } else { GIcon *icon; int n_items; n_items = trash_root_get_n_items (backend->root); g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); /* Translators: this is the display name of the backend */ g_file_info_set_display_name (info, _("Trash")); g_file_info_set_content_type (info, "inode/directory"); icon = g_themed_icon_new (n_items ? "user-trash-full" : "user-trash"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new (n_items ? "user-trash-full-symbolic" : "user-trash-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT, n_items); g_vfs_job_succeeded (G_VFS_JOB (job)); } return TRUE; }
static gboolean recent_backend_query_info (GVfsBackend *vfs_backend, GVfsJobQueryInfo *job, const char *filename, GFileQueryInfoFlags flags, GFileInfo *info, GFileAttributeMatcher *matcher) { GVfsBackendRecent *backend = G_VFS_BACKEND_RECENT (vfs_backend); g_assert (filename[0] == '/'); if (filename[1]) { GError *error = NULL; RecentItem *item = NULL; GFile *real; real = recent_backend_get_file (backend, filename, &item, &error); if (real) { GFileInfo *real_info; real_info = g_file_query_info (real, job->attributes, flags, G_VFS_JOB (job)->cancellable, &error); g_object_unref (real); if (real_info) { g_file_info_copy_into (real_info, info); recent_backend_add_info (item, info); g_vfs_job_succeeded (G_VFS_JOB (job)); g_object_unref (real_info); return TRUE; } } g_vfs_job_failed_from_error (G_VFS_JOB (job), error); g_error_free (error); } else { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); /* Translators: this is the display name of the backend */ g_file_info_set_display_name (info, _("Recent")); g_file_info_set_content_type (info, "inode/directory"); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, FALSE); icon = g_themed_icon_new ("document-open-recent"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new ("document-open-recent-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); g_vfs_job_succeeded (G_VFS_JOB (job)); } return TRUE; }
static GFileInfo * g_local_file_enumerator_next_file (GFileEnumerator *enumerator, GCancellable *cancellable, GError **error) { GLocalFileEnumerator *local = G_LOCAL_FILE_ENUMERATOR (enumerator); const char *filename; char *path; GFileInfo *info; GError *my_error; GFileType file_type; if (!local->got_parent_info) { _g_local_file_info_get_parent_info (local->filename, local->matcher, &local->parent_info); local->got_parent_info = TRUE; } next_file: #ifdef USE_GDIR filename = g_dir_read_name (local->dir); file_type = G_FILE_TYPE_UNKNOWN; #else filename = next_file_helper (local, &file_type); #endif if (filename == NULL) return NULL; my_error = NULL; path = g_build_filename (local->filename, filename, NULL); if (file_type == G_FILE_TYPE_UNKNOWN || (file_type == G_FILE_TYPE_SYMBOLIC_LINK && !(local->flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS))) { info = _g_local_file_info_get (filename, path, local->matcher, local->flags, &local->parent_info, &my_error); } else { info = _g_local_file_info_get (filename, path, local->reduced_matcher, local->flags, &local->parent_info, &my_error); if (info) { _g_local_file_info_get_nostat (info, filename, path, local->matcher); g_file_info_set_file_type (info, file_type); if (file_type == G_FILE_TYPE_SYMBOLIC_LINK) g_file_info_set_is_symlink (info, TRUE); } } g_free (path); if (info == NULL) { /* Failed to get info */ /* If the file does not exist there might have been a race where * the file was removed between the readdir and the stat, so we * ignore the file. */ if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_error_free (my_error); goto next_file; } else g_propagate_error (error, my_error); } return info; }
static gboolean fm_file_info_job_run(FmJob* fmjob) { GList* l; FmFileInfoJob* job = (FmFileInfoJob*)fmjob; GError* err = NULL; if(job->file_infos == NULL) return FALSE; for(l = fm_file_info_list_peek_head_link(job->file_infos); !fm_job_is_cancelled(fmjob) && l;) { FmFileInfo* fi = (FmFileInfo*)l->data; GList* next = l->next; FmPath* path = fm_file_info_get_path(fi); if(job->current) fm_path_unref(job->current); job->current = fm_path_ref(path); if(fm_path_is_native(path)) { char* path_str = fm_path_to_str(path); if(!_fm_file_info_job_get_info_for_native_file(fmjob, fi, path_str, &err)) { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_free(path_str); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); g_free(path_str); /* recursively set display names for path parents */ _check_native_display_names(fm_path_get_parent(path)); } else { GFile* gf; gf = fm_path_to_gfile(path); if(!_fm_file_info_job_get_info_for_gfile(fmjob, fi, gf, &err)) { if(err->domain == G_IO_ERROR && err->code == G_IO_ERROR_NOT_MOUNTED) { GFileInfo *inf; /* location by link isn't mounted; unfortunately we cannot launch a target if we don't know what kind of target we have; lets make a simplest directory-kind GFIleInfo */ /* FIXME: this may be dirty a bit */ g_error_free(err); err = NULL; inf = g_file_info_new(); g_file_info_set_file_type(inf, G_FILE_TYPE_DIRECTORY); g_file_info_set_name(inf, fm_path_get_basename(path)); g_file_info_set_display_name(inf, fm_path_get_basename(path)); fm_file_info_set_from_g_file_data(fi, gf, inf); g_object_unref(inf); } else { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_object_unref(gf); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ goto _next; } } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); /* recursively set display names for path parents */ _check_gfile_display_names(fm_path_get_parent(path), gf); _next: g_object_unref(gf); } l = next; } return TRUE; }
void ide_project_files_add_file (IdeProjectFiles *self, IdeProjectFile *file) { IdeProjectItem *item = (IdeProjectItem *)self; g_autoptr(GFile) parent = NULL; g_autofree gchar *path = NULL; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *gfile; gchar **parts; gsize i; g_return_if_fail (IDE_IS_PROJECT_FILES (self)); g_return_if_fail (IDE_IS_PROJECT_FILE (file)); context = ide_object_get_context (IDE_OBJECT (self)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); gfile = ide_project_file_get_file (file); parent = g_file_get_parent (gfile); path = g_file_get_relative_path (workdir, parent); if (path == NULL) { ide_project_item_append (IDE_PROJECT_ITEM (self), IDE_PROJECT_ITEM (file)); return; } parts = g_strsplit (path, G_DIR_SEPARATOR_S, 0); for (i = 0; parts [i]; i++) { IdeProjectItem *found; found = ide_project_files_find_child (item, parts [i]); if (found == NULL) { g_autoptr(GFileInfo) file_info = NULL; g_autofree gchar *child_path = NULL; IdeProjectItem *child; const gchar *item_path; g_autoptr(GFile) item_file = NULL; file_info = g_file_info_new (); g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY); g_file_info_set_display_name (file_info, parts [i]); g_file_info_set_name (file_info, parts [i]); item_path = ide_project_file_get_path (IDE_PROJECT_FILE (item)); child_path = g_strjoin (G_DIR_SEPARATOR_S, item_path, parts [i], NULL); item_file = g_file_get_child (workdir, child_path); child = g_object_new (IDE_TYPE_PROJECT_FILE, "context", context, "parent", item, "path", path, "file", item_file, "file-info", file_info, NULL); ide_project_item_append (item, child); item = child; } else { item = found; } } ide_project_item_append (item, IDE_PROJECT_ITEM (file)); g_strfreev (parts); }
static void file_info_from_message (SoupMessage *msg, GFileInfo *info, GFileAttributeMatcher *matcher) { const char *text; GHashTable *params; char *basename; char *ed_name; basename = ed_name = NULL; /* prefer the filename from the Content-Disposition (rfc2183) header if one if present. See bug 551298. */ if (soup_message_headers_get_content_disposition (msg->response_headers, NULL, ¶ms)) { const char *name = g_hash_table_lookup (params, "filename"); if (name) basename = g_strdup (name); g_hash_table_destroy (params); } if (basename == NULL) { const SoupURI *uri; uri = soup_message_get_uri (msg); basename = http_uri_get_basename (uri->path); } g_debug ("basename:%s\n", basename); /* read http/1.1 rfc, until then we copy the local files * behaviour */ if (basename != NULL && (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) || g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME))) ed_name = gvfs_file_info_populate_names_as_local (info, basename); g_free (basename); g_free (ed_name); if (soup_message_headers_get_encoding (msg->response_headers) == SOUP_ENCODING_CONTENT_LENGTH) { goffset start, end, length; gboolean ret; ret = soup_message_headers_get_content_range (msg->response_headers, &start, &end, &length); if (ret && length != -1) { g_file_info_set_size (info, length); } else if (!ret) { length = soup_message_headers_get_content_length (msg->response_headers); g_file_info_set_size (info, length); } } g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); text = soup_message_headers_get_content_type (msg->response_headers, NULL); if (text) { GIcon *icon; g_file_info_set_content_type (info, text); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, text); icon = g_content_type_get_icon (text); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_content_type_get_symbolic_icon (text); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } text = soup_message_headers_get_one (msg->response_headers, "Last-Modified"); if (text) { SoupDate *sd; GTimeVal tv; sd = soup_date_new_from_string(text); if (sd) { soup_date_to_timeval (sd, &tv); g_file_info_set_modification_time (info, &tv); soup_date_free (sd); } } text = soup_message_headers_get_one (msg->response_headers, "ETag"); if (text) { g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_ETAG_VALUE, text); } }
/* Function implementations */ static void fl_parser_start_node_cb (void *user_data, const char *node_name, const char **attr) { ParserData *data; GFileInfo *info; data = (ParserData *) user_data; data->depth++; d(g_print ("%d: %s\n", data->depth, node_name)); if (data->depth > 2) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Don't expect node '%s' as child of 'file', 'folder' or 'parent-folder'", node_name); return; } else if (data->depth == 1) { if (strcmp (node_name, "folder-listing") != 0) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Expected 'folder-listing', got '%s'", node_name); return; } return; } if (strcmp (node_name, "parent-folder") == 0) { /* Just ignore parent-folder items */ return; } info = g_file_info_new (); if (strcmp (node_name, "file") == 0) { g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); } else if (strcmp (node_name, "folder") == 0) { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_content_type (info, "inode/directory"); icon = g_themed_icon_new ("folder"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new ("folder-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } else { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Unknown element '%s'", node_name); return; } if (!fl_parser_fill_file_info (info, attr)) { d(g_print ("Failed to fill GnomeVFSFileInfo from node '%s'\n", node_name)); g_object_unref (info); return; } if (g_file_info_get_content_type (info) == NULL) { char *mime_type; mime_type = g_content_type_guess (g_file_info_get_name (info), NULL, 0, NULL); g_file_info_set_content_type (info, mime_type); g_free (mime_type); } if (g_file_info_get_content_type (info) == NULL) { g_file_info_set_content_type (info, "application/octet-stream"); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) { GIcon *icon; const char *content_type; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic"); g_file_info_set_icon (info, icon); g_object_unref (icon); } icon = g_content_type_get_symbolic_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } } /* Permissions on folders in OBEX has different semantics than POSIX. * In POSIX, if a folder is not writable, it means that it's content * can't be removed, whereas in OBEX, it just means that the folder * itself can't be removed. Therefore we must set all folders to RWD and * handle the error when it happens. */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE); } data->elements = g_list_prepend (data->elements, info); }
static GFileInfo * g_resource_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error) { GResourceFile *resource = G_RESOURCE_FILE (file); GError *my_error = NULL; GFileInfo *info; GFileAttributeMatcher *matcher; gboolean res; gsize size; guint32 resource_flags; char **children; gboolean is_dir; char *base; is_dir = FALSE; children = g_resources_enumerate_children (resource->path, 0, NULL); if (children != NULL) { g_strfreev (children); is_dir = TRUE; } /* root is always there */ if (strcmp ("/", resource->path) == 0) is_dir = TRUE; if (!is_dir) { res = g_resources_get_info (resource->path, 0, &size, &resource_flags, &my_error); if (!res) { if (g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("The resource at '%s' does not exist"), resource->path); } else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, my_error->message); g_clear_error (&my_error); return FALSE; } } matcher = g_file_attribute_matcher_new (attributes); info = g_file_info_new (); base = g_resource_file_get_basename (file); g_file_info_set_name (info, base); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ, TRUE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH, FALSE); if (is_dir) { g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); } else { GBytes *bytes; char *content_type; g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); g_file_info_set_size (info, size); if ((_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) || ((~resource_flags & G_RESOURCE_FLAGS_COMPRESSED) && _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE))) && (bytes = g_resources_lookup_data (resource->path, 0, NULL))) { const guchar *data; gsize data_size; data = g_bytes_get_data (bytes, &data_size); content_type = g_content_type_guess (base, data, data_size, NULL); g_bytes_unref (bytes); } else content_type = NULL; if (content_type) { _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE, content_type); _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE, content_type); g_free (content_type); } } g_free (base); g_file_attribute_matcher_unref (matcher); return info; }
static gboolean fm_dir_list_job_run_posix(FmDirListJob* job) { FmJob* fmjob = FM_JOB(job); FmFileInfo* fi; GError *err = NULL; char* path_str; GDir* dir; path_str = fm_path_to_str(job->dir_path); fi = _new_info_for_native_file(job, job->dir_path, path_str, NULL); if(fi) { if(! fm_file_info_is_dir(fi)) { err = g_error_new(G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The specified directory '%s' is not valid"), path_str); fm_file_info_unref(fi); fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); g_free(path_str); return FALSE; } job->dir_fi = fi; } else { err = g_error_new(G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The specified directory '%s' is not valid"), path_str); fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); g_free(path_str); return FALSE; } dir = g_dir_open(path_str, 0, &err); if( dir ) { const char* name; GString* fpath = g_string_sized_new(4096); int dir_len = strlen(path_str); g_string_append_len(fpath, path_str, dir_len); if(fpath->str[dir_len-1] != '/') { g_string_append_c(fpath, '/'); ++dir_len; } while( ! fm_job_is_cancelled(fmjob) && (name = g_dir_read_name(dir)) ) { FmPath* new_path; g_string_truncate(fpath, dir_len); g_string_append(fpath, name); if(job->flags & FM_DIR_LIST_JOB_DIR_ONLY) /* if we only want directories */ { struct stat st; /* FIXME: this results in an additional stat() call, which is inefficient */ if(stat(fpath->str, &st) == -1 || !S_ISDIR(st.st_mode)) continue; } new_path = fm_path_new_child(job->dir_path, name); _retry: fi = _new_info_for_native_file(job, new_path, fpath->str, &err); if (fi == NULL) /* we got a damaged file */ { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); GFile *gf; GFileInfo *inf; gchar *disp_basename; g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) goto _retry; /* bug #3615271: Damaged mountpoint isn't shown let make a simple file info then */ inf = g_file_info_new(); gf = fm_path_to_gfile(new_path); g_file_info_set_file_type(inf, G_FILE_TYPE_UNKNOWN); g_file_info_set_name(inf, name); disp_basename = g_filename_display_basename(fpath->str); g_file_info_set_display_name(inf, disp_basename); g_free(disp_basename); g_file_info_set_content_type(inf, "inode/x-corrupted"); fi = fm_file_info_new_from_g_file_data(gf, inf, new_path); g_object_unref(inf); g_object_unref(gf); } fm_dir_list_job_add_found_file(job, fi); fm_file_info_unref(fi); fm_path_unref(new_path); } g_string_free(fpath, TRUE); g_dir_close(dir); } else { fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); } g_free(path_str); return TRUE; }