summaryrefslogtreecommitdiff
path: root/camlibs/jamcam
diff options
context:
space:
mode:
authorLutz Mueller <lutz@users.sourceforge.net>2002-01-12 23:31:45 +0000
committerLutz Mueller <lutz@users.sourceforge.net>2002-01-12 23:31:45 +0000
commitcd437aae95664443dbac48dd6e0f893d808e3c02 (patch)
tree59ad67833c2d2243c665bedb4a33b258c74f77ca /camlibs/jamcam
parent6aabebdc005abd6a46cb1a86aabd7d0a2663c5f7 (diff)
downloadlibgphoto2-cd437aae95664443dbac48dd6e0f893d808e3c02.tar.gz
2002-01-13 Lutz M�ller <urc8@rz.uni-karlsruhe.de>
Finished the GPContext stuff - changes all over the place. Basically, gp_[file,camera]_progress has been replaced by gp_context_progress_*. Well, we haven't release a gphoto2-2.0 yet, therefore I hope you don't mind the API change... * libgphoto2/gphoto2-camera.[c,h]: Added a GPContext parameter to any function that can possibly communicate with the camera. That makes every function cancellable (which is good), makes it possible to report multiple errors during execution of a command, offers several (nested) progress reports, and many other goodies. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3841 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'camlibs/jamcam')
-rw-r--r--camlibs/jamcam/jamcam.c31
-rw-r--r--camlibs/jamcam/library.c53
-rw-r--r--camlibs/jamcam/library.h6
3 files changed, 54 insertions, 36 deletions
diff --git a/camlibs/jamcam/jamcam.c b/camlibs/jamcam/jamcam.c
index a02f0729f..663b816c1 100644
--- a/camlibs/jamcam/jamcam.c
+++ b/camlibs/jamcam/jamcam.c
@@ -154,7 +154,7 @@ static int get_info_func (CameraFilesystem *fs, const char *folder,
return (GP_OK);
}
-static int camera_exit (Camera *camera)
+static int camera_exit (Camera *camera, GPContext *context)
{
gp_debug_printf (GP_DEBUG_LOW, "jamcam", "* camera_exit");
@@ -173,7 +173,6 @@ static int get_file_func (CameraFilesystem *fs, const char *folder,
unsigned char gtable[256];
char *ptr;
int size = 0, n = 0;
- int res;
int width, height;
struct jamcam_file *jc_file;
@@ -185,14 +184,12 @@ static int get_file_func (CameraFilesystem *fs, const char *folder,
CHECK (n = gp_filesystem_number (camera->fs, folder,
filename, context));
- res = gp_file_progress( file, 0 );
- if ( res < 0 ) {
- return( res );
- }
+ if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL)
+ return (GP_ERROR_CANCEL);
switch (type) {
case GP_FILE_TYPE_PREVIEW:
- CHECK (jamcam_request_thumbnail (camera, file, raw, &size, n));
+ CHECK (jamcam_request_thumbnail (camera, file, raw, &size, n, context));
width = 80;
height = 60;
@@ -217,7 +214,7 @@ static int get_file_func (CameraFilesystem *fs, const char *folder,
break;
case GP_FILE_TYPE_NORMAL:
- CHECK (jamcam_request_image (camera, file, raw, &size, n));
+ CHECK (jamcam_request_image (camera, file, raw, &size, n, context));
jc_file = jamcam_file_info (camera, n);
@@ -242,7 +239,7 @@ static int get_file_func (CameraFilesystem *fs, const char *folder,
break;
case GP_FILE_TYPE_RAW:
- CHECK (jamcam_request_image (camera, file, raw, &size, n));
+ CHECK (jamcam_request_image (camera, file, raw, &size, n, context));
CHECK (gp_file_set_mime_type (file, GP_MIME_RAW));
strcpy( tmp_filename, filename );
tmp_filename[strlen(tmp_filename)-3] = 'r';
@@ -258,7 +255,7 @@ static int get_file_func (CameraFilesystem *fs, const char *folder,
return (GP_OK);
}
-static int camera_summary (Camera *camera, CameraText *summary)
+static int camera_summary (Camera *camera, CameraText *summary, GPContext *context)
{
int count;
char tmp[1024];
@@ -274,16 +271,7 @@ static int camera_summary (Camera *camera, CameraText *summary)
return (GP_OK);
}
-static int camera_manual (Camera *camera, CameraText *manual)
-{
- gp_debug_printf (GP_DEBUG_LOW, "jamcam", "* camera_manual");
-
- strcpy (manual->text, _("Some notes:\n"
- " No notes here yet.\n"));
- return (GP_OK);
-}
-
-static int camera_about (Camera *camera, CameraText *about)
+static int camera_about (Camera *camera, CameraText *about, GPContext *context)
{
gp_debug_printf (GP_DEBUG_LOW, "jamcam", "* camera_about");
@@ -298,7 +286,7 @@ static int camera_about (Camera *camera, CameraText *about)
return (GP_OK);
}
-int camera_init (Camera *camera)
+int camera_init (Camera *camera, GPContext *context)
{
int count;
GPPortSettings settings;
@@ -312,7 +300,6 @@ int camera_init (Camera *camera)
/* First, set up all the function pointers */
camera->functions->exit = camera_exit;
camera->functions->summary = camera_summary;
- camera->functions->manual = camera_manual;
camera->functions->about = camera_about;
CHECK (gp_port_get_settings (camera->port, &settings));
diff --git a/camlibs/jamcam/library.c b/camlibs/jamcam/library.c
index c8e7e4836..f769b04c0 100644
--- a/camlibs/jamcam/library.c
+++ b/camlibs/jamcam/library.c
@@ -22,6 +22,7 @@
/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/****************************************************************/
+#include <config.h>
#include <stdio.h>
#include <string.h>
@@ -32,6 +33,25 @@
#include "library.h"
+#ifdef ENABLE_NLS
+# include <libintl.h>
+# undef _
+# define _(String) dgettext (PACKAGE, String)
+# ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+# else
+# define N_(String) (String)
+# endif
+#else
+# define textdomain(String) (String)
+# define gettext(String) (String)
+# define dgettext(Domain,Message) (Message)
+# define dcgettext(Domain,Message,Type) (Message)
+# define bindtextdomain(Domain,Directory) (Domain)
+# define _(String) (String)
+# define N_(String) (String)
+#endif
+
struct jamcam_file jamcam_files[1024];
static int jamcam_count = 0;
static int jamcam_mmc_card_size = 0;
@@ -294,7 +314,7 @@ int jamcam_file_count (Camera *camera) {
}
int jamcam_fetch_memory( Camera *camera, CameraFile *file,
- char *data, int start, int length ) {
+ char *data, int start, int length, GPContext *context) {
char tmp_buf[16];
char packet[16];
int new_start;
@@ -303,6 +323,7 @@ int jamcam_fetch_memory( Camera *camera, CameraFile *file,
int bytes_to_read;
int bytes_left = length;
int res = GP_OK;
+ unsigned int id = 0;
gp_debug_printf (GP_DEBUG_LOW, "jamcam", "* jamcam_fetch_memory");
gp_debug_printf (GP_DEBUG_LOW, "jamcam", " * start: %d (0x%x)",
@@ -310,6 +331,10 @@ int jamcam_fetch_memory( Camera *camera, CameraFile *file,
gp_debug_printf (GP_DEBUG_LOW, "jamcam", " * length: %d (0x%x)",
length, length);
+ if ( length > 1000 )
+ id = gp_context_progress_start (context, length,
+ _("Downloading data..."));
+
while( bytes_left ) {
switch( camera->port->type ) {
default:
@@ -355,15 +380,17 @@ int jamcam_fetch_memory( Camera *camera, CameraFile *file,
/* hate this hardcoded, but don't want to update here */
/* when downloading parts of a thumbnail */
if ( length > 1000 ) {
- res = gp_file_progress( file,
- (float)(bytes_read)/(float)(length) );
- if ( res < 0 ) {
+ gp_context_progress_update (context, id, bytes_read);
+ if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) {
gp_debug_printf (GP_DEBUG_LOW, "jamcam", " * CANCELED");
break;
}
}
}
+ if ( length > 1000 )
+ gp_context_progress_stop (context, id);
+
if ( res == GP_OK ) {
gp_debug_printf (GP_DEBUG_LOW, "jamcam", " * returning OK");
}
@@ -371,7 +398,7 @@ int jamcam_fetch_memory( Camera *camera, CameraFile *file,
}
int jamcam_request_image( Camera *camera, CameraFile *file,
- char *buf, int *len, int number ) {
+ char *buf, int *len, int number, GPContext *context ) {
int position;
int result;
char tmp_buf[300000];
@@ -394,7 +421,7 @@ int jamcam_request_image( Camera *camera, CameraFile *file,
}
result = jamcam_fetch_memory( camera, file, tmp_buf, position,
- jamcam_files[number].data_incr );
+ jamcam_files[number].data_incr, context );
/* this seems to reset the camera to a sane status */
if ( camera->port->type == GP_PORT_USB ) {
@@ -419,7 +446,7 @@ struct jamcam_file *jamcam_file_info(Camera *camera, int number)
}
int jamcam_request_thumbnail( Camera *camera, CameraFile *file,
- char *buf, int *len, int number ) {
+ char *buf, int *len, int number, GPContext *context ) {
char line[2048];
char packet[16];
int position;
@@ -427,6 +454,7 @@ int jamcam_request_thumbnail( Camera *camera, CameraFile *file,
int res = GP_OK;
char *ptr;
int bytes_to_read;
+ unsigned int id;
gp_debug_printf (GP_DEBUG_LOW, "jamcam", "* jamcam_request_thumbnail");
@@ -462,12 +490,14 @@ int jamcam_request_thumbnail( Camera *camera, CameraFile *file,
/* fetch thumbnail lines and build the thumbnail */
position += 10 * jamcam_files[number].width;
+ id = gp_context_progress_start (context, 60.,
+ _("Downloading thumbnail..."));
for( y = 0 ; y < 60 ; y++ ) {
- jamcam_fetch_memory( camera, file, line, position, bytes_to_read );
+ jamcam_fetch_memory( camera, file, line, position, bytes_to_read, context );
- res = gp_file_progress( file, (float)(y)/60.0 );
- gp_debug_printf (GP_DEBUG_LOW, "jamcam", " * progress: %.2f", (float)(y)/60.0);
- if ( res < 0 ) {
+ gp_context_progress_update (context, id, y);
+ if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) {
+ res = GP_ERROR_CANCEL;
break;
}
@@ -491,6 +521,7 @@ int jamcam_request_thumbnail( Camera *camera, CameraFile *file,
}
}
}
+ gp_context_progress_stop (context, id);
/* this seems to reset the camera to a sane status */
if ( camera->port->type == GP_PORT_USB ) {
diff --git a/camlibs/jamcam/library.h b/camlibs/jamcam/library.h
index 9e824dee1..6922545c5 100644
--- a/camlibs/jamcam/library.h
+++ b/camlibs/jamcam/library.h
@@ -46,8 +46,8 @@ int jamcam_write_packet(Camera *camera, char *packet, int length);
int jamcam_read_packet(Camera *camera, char *packet, int length);
int jamcam_file_count(Camera *camera);
struct jamcam_file *jamcam_file_info(Camera *camera, int number);
-int jamcam_fetch_memory(Camera *camera, CameraFile *file, char *data, int start, int length );
-int jamcam_request_image(Camera *camera, CameraFile *file, char *buf, int *len, int number);
-int jamcam_request_thumbnail(Camera *camera, CameraFile *file, char *buf, int *len, int number );
+int jamcam_fetch_memory(Camera *camera, CameraFile *file, char *data, int start, int length, GPContext *context );
+int jamcam_request_image(Camera *camera, CameraFile *file, char *buf, int *len, int number, GPContext *context );
+int jamcam_request_thumbnail(Camera *camera, CameraFile *file, char *buf, int *len, int number, GPContext *context );
#endif /* __LIBRARY_H__ */