static int file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context) { CameraFile *file; CameraFileInfo info; KncStatus status; unsigned int i, id; Camera *camera = data; int result; KncCamRes cr; /* * We can't get the filename from the camera. * But we decide to call the images %6i.jpeg', with the image id as * parameter. Therefore, let's get the image ids. */ CR (knc_get_status (camera->pl->c, &cr, &status), context); CCR (cr, context); id = gp_context_progress_start (context, status.pictures, _("Getting file list...")); for (i = 0; i < status.pictures; i++) { /* Get information */ gp_file_new (&file); result = get_info (camera, i + 1, &info, file, context); if (result < 0) { gp_file_unref (file); return (result); } /* * Append directly to the filesystem instead of to the list, * because we have additional information. */ gp_filesystem_append (camera->fs, folder, info.file.name, context); gp_filesystem_set_info_noop (camera->fs, folder, info, context); gp_filesystem_set_file_noop (camera->fs, folder, file, context); gp_file_unref (file); gp_context_idle (context); gp_context_progress_update (context, id, i + 1); if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) return (GP_ERROR_CANCEL); } gp_context_progress_stop (context, id); return (GP_OK); }
static int put_file_func (CameraFilesystem *fs, const char *folder, CameraFile *file, void *data, GPContext *context) { char path[2048]; const char *name; int result; #ifdef DEBUG unsigned int i, id; #endif Camera *camera = (Camera*)data; gp_file_get_name (file, &name); result = _get_path (camera->port, folder, name, path, sizeof(path)); if (result < GP_OK) return result; result = gp_file_save (file, path); if (result < 0) return (result); #ifdef DEBUG id = gp_context_progress_start (context, 500., "Uploading file..."); for (i = 0; i < 500; i++) { gp_context_progress_update (context, id, i + 1); gp_context_idle (context); if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) return (result); usleep (10); } gp_context_progress_stop (context, id); #endif return (GP_OK); }
static void on_ok_clicked (GtkButton *button, GtkamSave *save) { guint i, count, j = 1; int result = -1; GtkWidget *s, *dialog; unsigned int id = 0; GtkamSaveData *data; gchar *progname, *command; GError *error = NULL; if (count_items (save) == 0) { if (!save->priv->err_shown) { dialog = gtkam_error_new (result, NULL, GTK_WIDGET (save), _("There is nothing to be saved.")); gtk_widget_show (dialog); } return; } store_save_settings(save); gtk_widget_hide (GTK_WIDGET (save)); count = g_slist_length (save->priv->data); if (count == 1) s = gtkam_cancel_new (_("Downloading file")); else s = gtkam_cancel_new (_("Downloading %i files"), count); gtk_window_set_transient_for (GTK_WINDOW (s), save->priv->main_window); gtk_widget_show (s); if (count > 1) id = gp_context_progress_start ( GTKAM_CANCEL (s)->context->context, count, _("Downloading %i files..."), count); if (!save->priv->toggle_filename_camera->active) j = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON (save->priv->spin_entry)); for (i = 0; i < count; i++) { data = g_slist_nth_data (save->priv->data, i); /* Check for shutdown */ if (!GTKAM_IS_SAVE (save)) return; if (save->priv->toggle_normal && save->priv->toggle_normal->active) result = get_file (save, data->camera, data->folder, data->name, GP_FILE_TYPE_NORMAL, i + j, GTKAM_CANCEL (s)->context); if (save->priv->toggle_preview && save->priv->toggle_preview->active && (!result < 0)) result = get_file (save, data->camera, data->folder, data->name, GP_FILE_TYPE_PREVIEW, i + j, GTKAM_CANCEL (s)->context); if (save->priv->toggle_raw && save->priv->toggle_raw->active && (!result < 0)) result = get_file (save, data->camera, data->folder, data->name, GP_FILE_TYPE_RAW, i + j, GTKAM_CANCEL (s)->context); if (save->priv->toggle_audio && save->priv->toggle_audio->active && (!result < 0)) result = get_file (save, data->camera, data->folder, data->name, GP_FILE_TYPE_AUDIO, i + j, GTKAM_CANCEL (s)->context); if (save->priv->toggle_exif && save->priv->toggle_exif->active && (!result < 0)) result = get_file (save, data->camera, data->folder, data->name, GP_FILE_TYPE_EXIF, i + j, GTKAM_CANCEL (s)->context); if (result < 0) { if (count > 1) gp_context_progress_stop (GTKAM_CANCEL (s)->context->context, id); if (!save->priv->err_shown) { dialog = gtkam_error_new (result, GTKAM_CANCEL (s)->context, GTK_WIDGET (save), _("Problem getting '%s' " "from folder '%s'."), data->name, data->folder); gtk_widget_show (dialog); save->priv->err_shown = TRUE; } gtk_object_destroy (GTK_OBJECT (s)); gtk_object_destroy (GTK_OBJECT (save)); return; } if (count > 1) gp_context_progress_update ( GTKAM_CANCEL (s)->context->context, id, i + 1); gp_context_idle (GTKAM_CANCEL (s)->context->context); if (gp_context_cancel (GTKAM_CANCEL (s)->context->context) == GP_CONTEXT_FEEDBACK_CANCEL) break; } if (count > 1) gp_context_progress_stop ( GTKAM_CANCEL (s)->context->context, id); gtk_object_destroy (GTK_OBJECT (s)); /* If file(s) were saved and a program specified, load the program passing the filenames */ if (result >= 0) { progname = gtk_entry_get_text (save->priv->program); if (progname && progname[0] != '\0') { command = g_strdup_printf ("%s%s", progname, save->priv->filelist->str); /* FIXME Report any arising errors */ if (!g_spawn_command_line_async (command, &error)) { g_warning ("Error running command\n"); g_error_free (error); } g_free (command); g_string_free (save->priv->filelist, TRUE); } } gtk_object_destroy (GTK_OBJECT (save)); }
static int file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context) { Camera *camera = data; unsigned int i, filecount, id, size, type; CameraFile *file; CameraFileInfo info; unsigned char *buffer = NULL; int ret, n_img=0, n_avi=0, n_wav=0; char fn[100]; CHECK (pccam300_get_filecount (camera->port, &filecount)); id = gp_context_progress_start (context, filecount, _("Getting file list...")); for (i = 0; i < filecount; i++) { /* Get information */ gp_file_new (&file); ret = pccam300_get_file (camera->port, context, i, &buffer, &size, &type); if (ret < GP_OK) { gp_file_free (file); return ret; } info.audio.fields = GP_FILE_INFO_NONE; info.preview.fields = GP_FILE_INFO_NONE; info.file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE; info.file.size = size; switch (type) { case PCCAM300_MIME_JPEG: strcpy (info.file.type, GP_MIME_JPEG); sprintf (fn, "Image%03i.jpeg", n_img++); break; case PCCAM300_MIME_AVI: strcpy (info.file.type, GP_MIME_AVI); sprintf (fn, "Movie%03i.UNUSABLE", n_avi++); break; case PCCAM300_MIME_WAV: strcpy (info.file.type, GP_MIME_WAV); sprintf (fn, "Audio%03i.UNUSABLE", n_wav++); break; default: break; } if (file) gp_file_set_data_and_size (file, buffer, size); else free (buffer); /* * Append directly to the filesystem instead of to the list, * because we have additional information. * */ gp_filesystem_append (camera->fs, folder, fn, context); gp_filesystem_set_info_noop (camera->fs, folder, fn, info, context); gp_filesystem_set_file_noop (camera->fs, folder, fn, GP_FILE_TYPE_NORMAL, file, context); gp_file_unref (file); gp_context_idle (context); gp_context_progress_update (context, id, i + 1); if (gp_context_cancel(context) == GP_CONTEXT_FEEDBACK_CANCEL) return (GP_ERROR_CANCEL); } gp_context_progress_stop (context, id); return GP_OK; }
static int get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileType type, CameraFile *file, void *user_data, GPContext *context) { char path[1024]; int result = GP_OK; struct stat stbuf; int fd, id; unsigned int curread, toread; unsigned char *buf; #ifdef HAVE_LIBEXIF ExifData *data; unsigned int buf_len; #endif /* HAVE_LIBEXIF */ Camera *camera = (Camera*)user_data; result = _get_path (camera->port, folder, filename, path, sizeof(path)); gp_log (GP_LOG_DEBUG, "directory/get_file_func", "%s %s",folder,filename); if (result < GP_OK) return result; gp_log (GP_LOG_DEBUG, "directory/get_file_func", "->%s",path); switch (type) { case GP_FILE_TYPE_NORMAL: #ifdef DEBUG case GP_FILE_TYPE_PREVIEW: #endif fd = open (path,O_RDONLY); if (fd == -1) return GP_ERROR_IO_READ; break; #ifdef HAVE_LIBEXIF case GP_FILE_TYPE_EXIF: data = exif_data_new_from_file (path); if (!data) { gp_context_error (context, _("Could not open '%s'."), path); return (GP_ERROR); } exif_data_save_data (data, &buf, &buf_len); exif_data_unref (data); gp_file_set_data_and_size (file, buf, buf_len); return (GP_OK); #endif /* HAVE_LIBEXIF */ default: return (GP_ERROR_NOT_SUPPORTED); } if (-1 == fstat(fd,&stbuf)) { close (fd); return GP_ERROR_IO_READ; } #define BLOCKSIZE 65536 /* do it in 64kb blocks */ buf = malloc(BLOCKSIZE); if (!buf) { close (fd); return GP_ERROR_NO_MEMORY; } curread = 0; id = gp_context_progress_start (context, (1.0*stbuf.st_size/BLOCKSIZE), _("Getting file...")); GP_DEBUG ("Progress id: %i", id); result = GP_OK; while (curread < stbuf.st_size) { int ret; toread = stbuf.st_size-curread; if (toread>BLOCKSIZE) toread = BLOCKSIZE; ret = read(fd,buf,toread); if (ret == -1) { result = GP_ERROR_IO_READ; break; } curread += ret; gp_file_append (file, buf, ret); gp_context_progress_update (context, id, (1.0*curread/BLOCKSIZE)); gp_context_idle (context); if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) { result = GP_ERROR_CANCEL; break; } #if 0 /* We could take 2 seconds to download this image. everytime. */ /* But actually this driver is used in production by some frontends, * so do not delay at all */ usleep(2000000/(stbuf.st_size/BLOCKSIZE)); #endif } gp_context_progress_stop (context, id); free (buf); close (fd); return (GP_OK); }
static int folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context) { gp_system_dir dir; gp_system_dirent de; char buf[1024], f[1024]; unsigned int id, n; struct stat st; Camera *camera = (Camera*)data; if (camera->port->type == GP_PORT_DISK) { char *path; GPPortInfo info; int ret; ret = gp_port_get_info (camera->port, &info); if (ret < GP_OK) return ret; path = strchr (info.path,':'); if (!path) path = info.path; else path++; snprintf (f, sizeof(f), "%s/%s/", path, folder); gp_log (GP_LOG_DEBUG, "directory/folder_list_func", "%s", f); /* UNIX / is empty, or we recurse through the whole fs */ if ( (!strcmp(path, "") || !strcmp(path, "/")) && !strcmp(folder,"/") ) return GP_OK; } else { /* old style access */ /* Make sure we have 1 delimiter */ if (folder[strlen(folder)-1] != '/') { snprintf (f, sizeof(f), "%s%c", folder, '/'); } else { strncpy (f, folder, sizeof(f)); } } dir = gp_system_opendir ((char*) f); if (!dir) return GP_ERROR; /* Count the files */ n = 0; while (gp_system_readdir (dir)) n++; gp_system_closedir (dir); dir = gp_system_opendir (f); if (!dir) return GP_ERROR; id = gp_context_progress_start (context, n, _("Listing folders in '%s'..."), folder); n = 0; while ((de = gp_system_readdir (dir))) { const char * filename = NULL; /* Give some feedback */ gp_context_progress_update (context, id, n + 1); gp_context_idle (context); if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) { gp_system_closedir (dir); return GP_ERROR_CANCEL; } filename = gp_system_filename (de); if (*filename != '.') { snprintf (buf, sizeof(buf), "%s%s", f, filename); /* lstat ... do not follow symlinks */ if (lstat (buf, &st) != 0) { gp_context_error (context, _("Could not get information about '%s' (%m)."), buf); return GP_ERROR; } if (S_ISDIR (st.st_mode)) { gp_list_append(list, filename, NULL); } } n++; } gp_system_closedir (dir); gp_context_progress_stop (context, id); return (GP_OK); }