/** * Retrieves information about a file. * * @param camera a #Camera * @param folder a folder * @param file the name of the file * @param info * @param context a #GPContext * @return a gphoto2 error code * **/ int gp_camera_file_get_info (Camera *camera, const char *folder, const char *file, CameraFileInfo *info, GPContext *context) { int result = GP_OK; const char *mime_type; const char *data; /* long int size; */ CameraFile *cfile; gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Getting file info for '%s' " "in '%s'...", file, folder); CHECK_NULL (camera && folder && file && info); CHECK_INIT (camera, context); memset (info, 0, sizeof (CameraFileInfo)); /* Check first if the camera driver supports the filesystem */ CHECK_OPEN (camera, context); result = gp_filesystem_get_info (camera->fs, folder, file, info, context); CHECK_CLOSE (camera, context); if (result != GP_ERROR_NOT_SUPPORTED) { CAMERA_UNUSED (camera, context); return (result); } /* * The CameraFilesystem doesn't support file info. We simply get * the preview and the file and look for ourselves... */ /* It takes too long to get the file */ info->file.fields = GP_FILE_INFO_NONE; /* Get the preview */ info->preview.fields = GP_FILE_INFO_NONE; CRS (camera, gp_file_new (&cfile), context); if (gp_camera_file_get (camera, folder, file, GP_FILE_TYPE_PREVIEW, cfile, context) == GP_OK) { unsigned long size; info->preview.fields |= GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE; gp_file_get_data_and_size (cfile, &data, &size); info->preview.size = size; gp_file_get_mime_type (cfile, &mime_type); strncpy (info->preview.type, mime_type, sizeof (info->preview.type)); } gp_file_unref (cfile); /* We don't trust the camera libraries */ info->file.fields |= GP_FILE_INFO_NAME; strncpy (info->file.name, file, sizeof (info->file.name)); info->preview.fields &= ~GP_FILE_INFO_NAME; CAMERA_UNUSED (camera, context); return (GP_OK); }
static void on_view_as_activate (GtkMenuItem *item, ViewAsData *d) { GtkWidget *w, *c, *s; Bonobo_Control control; CORBA_Environment ev; CameraFile *f; int result; Bonobo_PersistStream pstream; BonoboObject *stream; const char *data = NULL; unsigned long int size; const char *type; g_return_if_fail (d->iid != NULL); CORBA_exception_init (&ev); control = bonobo_get_object (d->iid, "IDL:Bonobo/Control:1.0", &ev); if (BONOBO_EX (&ev) || (control == CORBA_OBJECT_NIL)) { CORBA_exception_free (&ev); g_warning ("Could not get control from '%s'.", d->iid); return; } w = bonobo_window_new (d->file, d->file); c = bonobo_widget_new_control_from_objref (control, CORBA_OBJECT_NIL); gtk_widget_show (c); bonobo_window_set_contents (BONOBO_WINDOW (w), c); gtk_widget_show (w); s = gtkam_status_new (_("Downloading '%s' from '%s'..."), d->file, d->folder); g_signal_emit (G_OBJECT (d->list), signals[NEW_STATUS], 0, s); gp_file_new (&f); result = gp_camera_file_get (d->camera->camera, d->folder, d->file, GP_FILE_TYPE_NORMAL, f, GTKAM_STATUS (s)->context->context); if (d->camera->multi) gp_camera_exit (d->camera->camera, NULL); if (result >= 0) { CORBA_exception_init (&ev); pstream = Bonobo_Unknown_queryInterface (control, "IDL:Bonobo/PersistStream:1.0", &ev); if (!BONOBO_EX (&ev) && (pstream != CORBA_OBJECT_NIL)) { gp_file_get_data_and_size (f, &data, &size); gp_file_get_mime_type (f, &type); stream = bonobo_stream_mem_create (data, size, TRUE, FALSE); Bonobo_PersistStream_load (pstream, bonobo_object_corba_objref (stream), type, &ev); g_object_unref (G_OBJECT (stream)); bonobo_object_release_unref (pstream, NULL); } CORBA_exception_free (&ev); } gp_file_unref (f); gtk_object_destroy (GTK_OBJECT (s)); }
static int save_file (GtkamSave *save, const char *filename, CameraFile *file, CameraFileType type, guint n) { gchar *full_path, *full_filename, *dirname, *msg, *number_filename; const char *mime_type; const gchar *fsel_filename, *fsel_path, *prefix, *suffix; GtkWidget *dialog; int result; gp_file_get_mime_type (file, &mime_type); fsel_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER_DIALOG (save)); if ((save->priv->toggle_filename_camera->active) || (g_slist_length (save->priv->data) == 1)) { /* Use filename provided by the CameraFile */ full_filename = create_full_filename (filename, type); if (g_slist_length (save->priv->data) == 1) full_path = g_strdup(fsel_path); else full_path = concat_dir_and_file (fsel_path, full_filename); g_free (full_filename); } else { /* Use filename in prefix */ prefix = g_locale_from_utf8 (gtk_entry_get_text (GTK_ENTRY (save->priv->prefix_entry)), -1, NULL, NULL, NULL); suffix = strrchr (mime_type, '/'); suffix++; number_filename = g_strdup_printf ("%s%04i.%s", prefix, n, suffix); full_filename = create_full_filename (number_filename, type); g_free (number_filename); full_path = concat_dir_and_file (fsel_path, full_filename); g_free (full_filename); } /* FIXME Check which is user, and prompt the user */ if (!save->priv->quiet && file_exists (full_path)) { msg = g_strdup_printf (_("The file '%s' already exists."), full_path); if (!save->priv->err_shown) { dialog = gtkam_error_new (GP_ERROR_FILE_EXISTS, NULL, GTK_WIDGET (save), msg); gtk_window_set_transient_for (GTK_WINDOW (dialog), save->priv->main_window); gtk_widget_show (dialog); g_free (msg); g_free (full_path); save->priv->err_shown = TRUE; } return -1; } /* FIXME Check for sufficient disk space for this file, or calculate total disk space required for all files before save process starts */ result = gp_file_save (file, full_path); if (result < 0) { if (!save->priv->err_shown) { dialog = gtkam_error_new (result, NULL, GTK_WIDGET (save), _("Could not save file to '%s'."), full_path); gtk_widget_show (dialog); save->priv->err_shown = TRUE; } } else { /* Add the file to the list of files to be opened with the specified external program */ if (!save->priv->filelist) save->priv->filelist = g_string_new (""); g_string_append_printf (save->priv->filelist, " %s", full_path); } g_free (full_path); return result; }