1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 #include <gphoto2/gphoto2-camera.h>
6
7 #include "samples.h"
8
9 /* Set the owner of the first camera.
10 *
11 * This program can autodetect a single camera and then sets its
12 * owner to the string passed on the cmdline.
13 *
14 * Same as:
15 * gphoto2 --get-config ownername
16 * gphoto2 --set-config ownername="Owner Name"
17 */
18
main(int argc,char ** argv)19 int main(int argc, char **argv) {
20 Camera *camera;
21 int ret;
22 char *owner;
23 GPContext *context;
24
25 context = sample_create_context (); /* see context.c */
26 gp_camera_new (&camera);
27
28 /* This call will autodetect cameras, take the
29 * first one from the list and use it. It will ignore
30 * any others... See the *multi* examples on how to
31 * detect and use more than the first one.
32 */
33 ret = gp_camera_init (camera, context);
34 if (ret < GP_OK) {
35 printf("No camera auto detected.\n");
36 gp_camera_free (camera);
37 return 0;
38 }
39
40 ret = get_config_value_string (camera, "artist", &owner, context);
41 if (ret < GP_OK) {
42 printf ("Could not query owner.\n");
43 goto out;
44 }
45 printf("Current owner: %s\n", owner);
46 if (argc > 1) {
47 ret = set_config_value_string (camera, "artist", argv[1], context);
48 if (ret < GP_OK) {
49 fprintf (stderr, "Failed to set camera owner to %s; %d\n", argv[1], ret);
50 } else
51 printf("New owner: %s\n", argv[1]);
52 }
53 out:
54 gp_camera_exit (camera, context);
55 gp_camera_free (camera);
56 return 0;
57 }
58