diff options
author | Lutz Mueller <lutz@users.sourceforge.net> | 2002-01-10 01:29:05 +0000 |
---|---|---|
committer | Lutz Mueller <lutz@users.sourceforge.net> | 2002-01-10 01:29:05 +0000 |
commit | fc18cbbdb5186718f284bbe31f86d3b209cb5ac2 (patch) | |
tree | 46ab8cfdc69936ec6a95eb31a9119f3969f4c2fd /frontends | |
parent | 85ded42601e03bd079b97034777c8fd2d35d82c1 (diff) | |
download | libgphoto2-fc18cbbdb5186718f284bbe31f86d3b209cb5ac2.tar.gz |
2002-01-10 Lutz M�ller <urc8@rz.uni-karlsruhe.de>
* libgphoto2/Makefile.am
* libgphoto2/gphoto2-context.[c,h]: New files
* libgphoto2/gphoto2-abilities-list.[c,h]
(gp_abilities_list_load_ctx): Sample function for showing the
benefits of above new files.
* frontends/command-line/main.c: Use gp_abilities_list_load_ctx to
make that operation cancellable.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3793 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/command-line/main.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/frontends/command-line/main.c b/frontends/command-line/main.c index c0f0cfe4a..2894cbd6e 100644 --- a/frontends/command-line/main.c +++ b/frontends/command-line/main.c @@ -55,9 +55,6 @@ #define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);} -/* Global variable for cancelling */ -static unsigned char cancelled = 0; - /* Takes the current globals, and sets up the gPhoto lib with them */ static int set_globals (void); @@ -217,7 +214,8 @@ char glob_cwd[1024]; int glob_speed; int glob_num=1; -Camera *glob_camera=NULL; +static GPContext *glob_context = NULL; +Camera *glob_camera = NULL; int glob_debug; int glob_shell=0; @@ -227,6 +225,7 @@ int glob_recurse=0; char glob_filename[128]; int glob_stdout=0; int glob_stdout_size=0; +static char glob_cancel = 0; /* 4) Finally, add your callback function. */ /* ----------------------------------------------------------------- */ @@ -741,7 +740,7 @@ download_progress_func (CameraFile *file, float percentage, void *data) const char *name; /* Check for cancellation */ - if (cancelled) + if (glob_cancel) return (GP_ERROR_CANCEL); if (glob_quiet) @@ -916,7 +915,7 @@ upload_progress_func (CameraFile *file, float percentage, void *data) const char *name; /* Check for cancellation */ - if (cancelled) + if (glob_cancel) return (GP_ERROR_CANCEL); if (glob_quiet) @@ -1111,7 +1110,7 @@ set_globals (void) CHECK_RESULT (gp_camera_new (&glob_camera)); CHECK_RESULT (gp_abilities_list_new (&al)); - CHECK_RESULT (gp_abilities_list_load (al)); + CHECK_RESULT (gp_abilities_list_load_ctx (al, glob_context)); CHECK_RESULT (gp_port_info_list_new (&il)); CHECK_RESULT (gp_port_info_list_load (il)); @@ -1215,6 +1214,41 @@ set_globals (void) return (GP_OK); } +static void +ctx_status_func (GPContext *context, const char *format, va_list args, + void *data) +{ + vfprintf (stderr, format, args); + fprintf (stderr, "\n"); + fflush (stderr); +} + +static void +ctx_error_func (GPContext *context, const char *format, va_list args, + void *data) +{ + fprintf (stderr, _("*** Error ***\n")); + vfprintf (stderr, format, args); + fflush (stderr); +} + +static void +ctx_progress_func (GPContext *context, float percentage, void *data) +{ + fprintf (stderr, "Progress: %02.01f\r", percentage * 100.); + fflush (stderr); +} + +static GPContextFeedback +ctx_cancel_func (GPContext *context, void *data) +{ + if (glob_cancel) { + return (GP_CONTEXT_FEEDBACK_CANCEL); + glob_cancel = 0; + } else + return (GP_CONTEXT_FEEDBACK_OK); +} + static int init_globals (void) { @@ -1235,6 +1269,12 @@ init_globals (void) glob_filename_override = 0; glob_recurse = 0; + glob_context = gp_context_new (); + gp_context_set_cancel_func (glob_context, ctx_cancel_func, NULL); + gp_context_set_progress_func (glob_context, ctx_progress_func, NULL); + gp_context_set_error_func (glob_context, ctx_error_func, NULL); + gp_context_set_status_func (glob_context, ctx_status_func, NULL); + return GP_OK; } @@ -1275,7 +1315,7 @@ signal_exit (int signo) if (!glob_quiet) printf(_("\nCancelling...\n")); - cancelled = 1; + glob_cancel = 1; #if 0 /* If we've got a camera, unref it */ |