GnomeVFSFileInfo *la_track_get_vfs_info(LaTrack * self) { if (!self->vfs_info) { self->vfs_info = gnome_vfs_file_info_new(); gnome_vfs_get_file_info(self->uri, self->vfs_info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FOLLOW_LINKS); } gnome_vfs_file_info_ref(self->vfs_info); return self->vfs_info; }
void file_data_update (FileData *fd) { GnomeVFSFileInfo *info; GnomeVFSResult result; g_return_if_fail (fd != NULL); fd->error = FALSE; fd->thumb_loaded = FALSE; fd->thumb_created = FALSE; info = gnome_vfs_file_info_new (); result = gnome_vfs_get_file_info (fd->path, info, (GNOME_VFS_FILE_INFO_FOLLOW_LINKS | GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE)); if (result != GNOME_VFS_OK) { fd->error = TRUE; fd->size = 0L; fd->mtime = 0; fd->ctime = 0; fd->exif_data_loaded = FALSE; fd->mime_type = NULL; return; } fd->name = file_name_from_path (fd->path); g_free (fd->display_name); fd->display_name = gnome_vfs_unescape_string_for_display (fd->name); fd->mime_type = get_static_string (info->mime_type); fd->size = info->size; fd->mtime = info->mtime; fd->ctime = info->ctime; fd->exif_data_loaded = FALSE; gnome_vfs_file_info_unref (info); }
gboolean magick_make_webimage(struct data *data, struct image *image, const gchar *uri, gint image_h) { MagickWand *wand; struct image_size *img_size = NULL; GnomeVFSResult result; GnomeVFSFileInfo *info; g_debug("in magick_make_webimage"); wand = _generate_webimage(data, image, image_h, &img_size); if (wand == NULL) return FALSE; /* save the image to a file */ if (!_save(data, wand, uri)) { DestroyMagickWand(wand); g_free(img_size); return FALSE; } DestroyMagickWand(wand); /* get file size */ info = gnome_vfs_file_info_new(); result = gnome_vfs_get_file_info(uri, info, GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS); if (result == GNOME_VFS_OK) { img_size->size = info->size / 1024; } else { img_size->size = 0; } image->sizes = g_slist_append(image->sizes, img_size); gnome_vfs_file_info_unref(info); return TRUE; }
static int tcp_transfer_dir(tcp_con_t *con,const char *path){ int rc; char *basename; GnomeVFSFileInfo *info; GnomeVFSResult res; gchar *dir_uri; if ( (!con) || (!path) ) return -EINVAL; info=gnome_vfs_file_info_new(); dir_uri=gnome_vfs_get_uri_from_local_path(path); rc=-ENOMEM; if (!dir_uri) goto free_info_out; res=gnome_vfs_get_file_info(dir_uri,info,GNOME_VFS_FILE_INFO_FOLLOW_LINKS); if (res != GNOME_VFS_OK) { rc=-res; goto free_info_out; } basename=g_path_get_basename(path); rc=-ENOMEM; if (!basename) goto free_info_out; rc=send_directory(con,path,basename,info); g_free(basename); if (!rc) rc=finalize_send_directory(con,path,info); else err_out("Send directory fail %s (%d)\n", strerror(-rc),rc); free_info_out: gnome_vfs_file_info_unref(info); return rc; }
static gboolean copy_uri (const gchar *src_uri, const gchar *dest_uri, const gchar *copying_format_str, const gchar *copied_format_str, GError **error) { GnomeVFSHandle *read_handle; GnomeVFSHandle *write_handle; GnomeVFSFileInfo *src_info; GnomeVFSFileSize file_size = 0; GnomeVFSFileSize bytes_read = 0; guchar buffer[BUFSIZE]; GnomeVFSResult result; gchar *memsize; GTimeVal last_time = { 0, 0 }; gimp_progress_init (_("Connecting to server")); src_info = gnome_vfs_file_info_new (); result = gnome_vfs_get_file_info (src_uri, src_info, 0); /* ignore errors here, they will be noticed below */ if (result == GNOME_VFS_OK && (src_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)) { file_size = src_info->size; } gnome_vfs_file_info_unref (src_info); result = gnome_vfs_open (&read_handle, src_uri, GNOME_VFS_OPEN_READ); if (result != GNOME_VFS_OK) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Could not open '%s' for reading: %s"), src_uri, gnome_vfs_result_to_string (result)); return FALSE; } result = gnome_vfs_create (&write_handle, dest_uri, GNOME_VFS_OPEN_WRITE, FALSE, 0644); if (result != GNOME_VFS_OK) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Could not open '%s' for writing: %s"), dest_uri, gnome_vfs_result_to_string (result)); gnome_vfs_close (read_handle); return FALSE; } memsize = g_format_size_for_display (file_size); gimp_progress_init_printf (file_size > 0 ? copying_format_str : copied_format_str, memsize); g_free (memsize); while (TRUE) { GnomeVFSFileSize chunk_read; GnomeVFSFileSize chunk_written; GTimeVal now; result = gnome_vfs_read (read_handle, buffer, sizeof (buffer), &chunk_read); if (chunk_read == 0) { if (result != GNOME_VFS_ERROR_EOF) { memsize = g_format_size_for_display (sizeof (buffer)); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to read %s from '%s': %s"), memsize, src_uri, gnome_vfs_result_to_string (result)); g_free (memsize); gnome_vfs_close (read_handle); gnome_vfs_close (write_handle); return FALSE; } else { gimp_progress_update (1.0); break; } } bytes_read += chunk_read; /* update the progress only up to 10 times a second */ g_get_current_time (&now); if (((now.tv_sec - last_time.tv_sec) * 1000 + (now.tv_usec - last_time.tv_usec) / 1000) > 100) { if (file_size > 0) { gimp_progress_update ((gdouble) bytes_read / (gdouble) file_size); } else { memsize = g_format_size_for_display (bytes_read); gimp_progress_set_text_printf (copied_format_str, memsize); gimp_progress_pulse (); g_free (memsize); } last_time = now; } result = gnome_vfs_write (write_handle, buffer, chunk_read, &chunk_written); if (chunk_written < chunk_read) { memsize = g_format_size_for_display (chunk_read); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to write %s to '%s': %s"), memsize, dest_uri, gnome_vfs_result_to_string (result)); g_free (memsize); gnome_vfs_close (read_handle); gnome_vfs_close (write_handle); return FALSE; } } gnome_vfs_close (read_handle); gnome_vfs_close (write_handle); return TRUE; }
/*--------------------------------------------------------------------------*/ static void download_done( DownloadCallbackData *data ) { GList *p; GnomeVFSFileInfo *info, tmp_info = {0}; gchar *hash_name; gchar *hash_path, *hash_text_uri; gchar *file_path, *file_text_uri; gchar *date_min, *date_max, *finish_msg; gchar *data_dir; gbTableModel *table_model; gb_debug (DEBUG_UPDATE, "START"); /* Rename downloaded files (undo name hash) */ data_dir = gb_util_get_home_data_dir(); for ( p=data->list; p != NULL; p=p->next ) { info = (GnomeVFSFileInfo *)p->data; hash_name = hash_filename( info->name ); hash_path = g_build_filename( data_dir, hash_name, NULL ); hash_text_uri = gnome_vfs_get_uri_from_local_path( hash_path ); file_path = g_build_filename( data_dir, info->name, NULL ); file_text_uri = gnome_vfs_get_uri_from_local_path( file_path ); gnome_vfs_get_file_info (hash_text_uri, &tmp_info, GNOME_VFS_FILE_INFO_DEFAULT); if ( info->size == tmp_info.size ) { gnome_vfs_move( hash_text_uri, file_text_uri, FALSE ); } else { g_warning ("%s: Temporary file size (%" GNOME_VFS_OFFSET_FORMAT_STR ") does not match remote size (%" GNOME_VFS_OFFSET_FORMAT_STR ").", info->name, tmp_info.size, info->size); gnome_vfs_unlink (hash_text_uri); } g_free( hash_name ); g_free( hash_path ); g_free( hash_text_uri ); g_free( file_path ); g_free( file_text_uri ); } g_free( data_dir ); /* Now reread redemption tables */ table_model = gb_table_get_model (); gb_table_model_update (table_model); /* customize finish page for this outcome */ gnome_druid_page_edge_set_title( GNOME_DRUID_PAGE_EDGE(finish_page), _( "Download done" ) ); date_min = gb_date_fmt (gb_table_model_get_rdate_min (table_model)); date_max = gb_date_fmt (gb_table_model_get_rdate_max (table_model)); finish_msg = g_strdup_printf( _( "GBonds has successfully downloaded " "%d new redemption files.\n\n" "GBonds is now configured with redemption data\n" "for %s - %s.\n" ), data->n, date_min, date_max ); gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE(finish_page), finish_msg ); g_free( date_min ); g_free( date_max ); g_free( finish_msg ); remote_dir_handle = NULL; /* Now jump to the finish page */ gnome_druid_set_page( GNOME_DRUID(update_druid), GNOME_DRUID_PAGE(finish_page) ); gb_debug (DEBUG_UPDATE, "END"); }
gboolean apply_transformation_jpeg (FileData *file, GthTransform transform, JpegMcuAction mcu_action, GError **error) { gboolean result = TRUE; char *tmp_dir = NULL; char *tmp_output_file = NULL; JXFORM_CODE transf; char *local_file; GnomeVFSFileInfo *info = NULL; if (file == NULL) return FALSE; if (transform == GTH_TRANSFORM_NONE) return TRUE; tmp_dir = get_temp_dir_name (); if (tmp_dir == NULL) { if (error != NULL) *error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not create a temporary folder")); return FALSE; } local_file = get_cache_filename_from_uri (file->path); if (local_file == NULL) { if (error != NULL) *error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not create a local temporary copy of the remote file.")); result = FALSE; goto apply_transformation_jpeg__free_and_close; } info = gnome_vfs_file_info_new (); gnome_vfs_get_file_info (file->path, info, GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS | GNOME_VFS_FILE_INFO_FOLLOW_LINKS); switch (transform) { case GTH_TRANSFORM_NONE: transf = JXFORM_NONE; break; case GTH_TRANSFORM_FLIP_H: transf = JXFORM_FLIP_H; break; case GTH_TRANSFORM_ROTATE_180: transf = JXFORM_ROT_180; break; case GTH_TRANSFORM_FLIP_V: transf = JXFORM_FLIP_V; break; case GTH_TRANSFORM_TRANSPOSE: transf = JXFORM_TRANSPOSE; break; case GTH_TRANSFORM_ROTATE_90: transf = JXFORM_ROT_90; break; case GTH_TRANSFORM_TRANSVERSE: transf = JXFORM_TRANSVERSE; break; case GTH_TRANSFORM_ROTATE_270: transf = JXFORM_ROT_270; break; default: transf = JXFORM_NONE; break; } tmp_output_file = get_temp_file_name (tmp_dir, NULL); if (! jpegtran (local_file, tmp_output_file, transf, mcu_action, error)) { result = FALSE; goto apply_transformation_jpeg__free_and_close; } if (! local_file_move (tmp_output_file, local_file)) { if (error != NULL) *error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not move temporary file to local destination. Check folder permissions.")); result = FALSE; goto apply_transformation_jpeg__free_and_close; } if (info != NULL) { char *local_uri; local_uri = get_uri_from_local_path (local_file); gnome_vfs_set_file_info (local_uri, info, GNOME_VFS_SET_FILE_INFO_PERMISSIONS | GNOME_VFS_SET_FILE_INFO_OWNER); gnome_vfs_file_info_unref (info); g_free (local_uri); } apply_transformation_jpeg__free_and_close: local_dir_remove_recursive (tmp_dir); g_free (tmp_output_file); g_free (tmp_dir); return result; }
GnomeVFSResult nsGnomeVFSInputStream::DoOpen() { GnomeVFSResult rv; NS_ASSERTION(mHandle == nsnull, "already open"); // Push a callback handler on the stack for this thread, so we can intercept // authentication requests from GnomeVFS. We'll use the channel to get a // nsIAuthPrompt instance. gnome_vfs_module_callback_push(GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION, AuthCallback, mChannel, NULL); // Query the mime type first (this could return NULL). // // XXX We need to do this up-front in order to determine how to open the URI. // Unfortunately, the error code GNOME_VFS_ERROR_IS_DIRECTORY is not // always returned by gnome_vfs_open when we pass it a URI to a directory! // Otherwise, we could have used that as a way to failover to opening the // URI as a directory. Also, it would have been ideal if // gnome_vfs_get_file_info_from_handle were actually implemented by the // smb:// module, since that would have allowed us to potentially save a // round trip to the server to discover the mime type of the document in // the case where gnome_vfs_open would have been used. (Oh well! /me // throws hands up in the air and moves on...) GnomeVFSFileInfo info = {0}; rv = gnome_vfs_get_file_info(mSpec.get(), &info, GnomeVFSFileInfoOptions( GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS)); if (rv == GNOME_VFS_OK) { if (info.type == GNOME_VFS_FILE_TYPE_DIRECTORY) { rv = gnome_vfs_directory_list_load(&mDirList, mSpec.get(), GNOME_VFS_FILE_INFO_DEFAULT); LOG(("gnomevfs: gnome_vfs_directory_list_load returned %d (%s) [spec=\"%s\"]\n", rv, gnome_vfs_result_to_string(rv), mSpec.get())); } else { rv = gnome_vfs_open(&mHandle, mSpec.get(), GNOME_VFS_OPEN_READ); LOG(("gnomevfs: gnome_vfs_open returned %d (%s) [spec=\"%s\"]\n", rv, gnome_vfs_result_to_string(rv), mSpec.get())); } } gnome_vfs_module_callback_pop(GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION); if (rv == GNOME_VFS_OK) { if (mHandle) { // Here we set the content type of the channel to the value of the mime // type determined by GnomeVFS. However, if GnomeVFS is telling us that // the document is binary, we'll ignore that and keep the channel's // content type unspecified. That will enable our content type sniffing // algorithms. This should provide more consistent mime type handling. if (info.mime_type && (strcmp(info.mime_type, APPLICATION_OCTET_STREAM) != 0)) SetContentTypeOfChannel(info.mime_type); mBytesRemaining = info.size; // Update the content length attribute on the channel. We do this // synchronously without proxying. This hack is not as bad as it looks! if (mBytesRemaining != PRUint64(-1)) mChannel->SetContentLength(mBytesRemaining); } else { mDirOpen = PR_TRUE; // Sort mDirList mDirList = g_list_sort(mDirList, FileInfoComparator); mDirListPtr = mDirList; // Write base URL (make sure it ends with a '/') mDirBuf.Append("300: "); mDirBuf.Append(mSpec); if (mSpec.get()[mSpec.Length() - 1] != '/') mDirBuf.Append('/'); mDirBuf.Append('\n'); // Write column names mDirBuf.Append("200: filename content-length last-modified file-type\n"); // Write charset (assume UTF-8) // XXX is this correct? mDirBuf.Append("301: UTF-8\n"); SetContentTypeOfChannel(APPLICATION_HTTP_INDEX_FORMAT); } } gnome_vfs_file_info_clear(&info); return rv; }
nsresult nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI) { nsresult rv; if (!gnome_program_get()) { // Get the brandShortName from the string bundle to pass to GNOME // as the application name. This may be used for things such as // the title of grouped windows in the panel. nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID); NS_ASSERTION(bundleService, "String bundle service must be present!"); nsCOMPtr<nsIStringBundle> bundle; bundleService->CreateBundle("chrome://branding/locale/brand.properties", getter_AddRefs(bundle)); nsXPIDLString appName; if (bundle) { bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(appName)); } else { NS_WARNING("brand.properties not present, using default application name"); appName.AssignLiteral("Gecko"); } char* empty[] = { "" }; gnome_init(NS_ConvertUTF16toUTF8(appName).get(), "1.0", 1, empty); } nsCAutoString iconSizeString; aIconURI->GetIconSize(iconSizeString); PRUint32 iconSize; if (iconSizeString.IsEmpty()) { rv = aIconURI->GetImageSize(&iconSize); NS_ASSERTION(NS_SUCCEEDED(rv), "GetImageSize failed"); } else { int size; GtkIconSize icon_size = moz_gtk_icon_size(iconSizeString.get()); gtk_icon_size_lookup(icon_size, &size, NULL); iconSize = size; } nsCAutoString type; aIconURI->GetContentType(type); GnomeVFSFileInfo fileInfo = {0}; fileInfo.refcount = 1; // In case some GnomeVFS function addrefs and releases it nsCAutoString spec; nsCOMPtr<nsIURI> fileURI; rv = aIconURI->GetIconFile(getter_AddRefs(fileURI)); if (fileURI) { fileURI->GetAsciiSpec(spec); // Only ask gnome-vfs for a GnomeVFSFileInfo for file: uris, to avoid a // network request PRBool isFile; if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) { gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT); } else { // We have to get a leaf name from our uri... nsCOMPtr<nsIURL> url(do_QueryInterface(fileURI)); if (url) { nsCAutoString name; // The filename we get is UTF-8-compatible, which matches gnome expectations. // See also: http://lists.gnome.org/archives/gnome-vfs-list/2004-March/msg00049.html // "Whenever we can detect the charset used for the URI type we try to // convert it to/from utf8 automatically inside gnome-vfs." // I'll interpret that as "otherwise, this field is random junk". url->GetFileName(name); fileInfo.name = g_strdup(name.get()); } // If this is no nsIURL, nothing we can do really. if (!type.IsEmpty()) { fileInfo.valid_fields = GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; fileInfo.mime_type = g_strdup(type.get()); } } } if (type.IsEmpty()) { nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1")); if (ms) { nsCAutoString fileExt; aIconURI->GetFileExtension(fileExt); ms->GetTypeFromExtension(fileExt, type); } } // Get the icon theme if (!gIconTheme) { gIconTheme = gnome_icon_theme_new(); if (!gIconTheme) { gnome_vfs_file_info_clear(&fileInfo); return NS_ERROR_NOT_AVAILABLE; } } char* name = gnome_icon_lookup(gIconTheme, NULL, spec.get(), NULL, &fileInfo, type.get(), GNOME_ICON_LOOKUP_FLAGS_NONE, NULL); gnome_vfs_file_info_clear(&fileInfo); if (!name) { return NS_ERROR_NOT_AVAILABLE; } char* file = gnome_icon_theme_lookup_icon(gIconTheme, name, iconSize, NULL, NULL); g_free(name); if (!file) return NS_ERROR_NOT_AVAILABLE; // Create a GdkPixbuf buffer and scale it GError *err = nsnull; GdkPixbuf* buf = gdk_pixbuf_new_from_file(file, &err); g_free(file); if (!buf) { if (err) g_error_free(err); return NS_ERROR_UNEXPECTED; } GdkPixbuf* scaled = buf; if (gdk_pixbuf_get_width(buf) != iconSize && gdk_pixbuf_get_height(buf) != iconSize) { // scale... scaled = gdk_pixbuf_scale_simple(buf, iconSize, iconSize, GDK_INTERP_BILINEAR); gdk_pixbuf_unref(buf); if (!scaled) return NS_ERROR_OUT_OF_MEMORY; } // XXX Respect icon state rv = moz_gdk_pixbuf_to_channel(scaled, aIconURI, getter_AddRefs(mRealChannel)); gdk_pixbuf_unref(scaled); return rv; }