void gtkam_chooser_set_port_mask (GtkamChooser *chooser, GPPortType types) { GtkWidget *dialog; GPPortInfo info; int n; guint i; GList *list = NULL; g_return_if_fail (GTKAM_IS_CHOOSER (chooser)); n = gp_port_info_list_count (chooser->priv->il); if (n < 0) { dialog = gtkam_error_new (n, NULL, GTK_WIDGET (chooser), _("Could not get number of ports.")); gtk_widget_show (dialog); return; } /* Search for ports that fulfil the criteria */ for (i = 0; i < n; i++) { #ifdef HAVE_GP_PORT_INFO_GET_NAME GPPortType type; char *xname,*xpath; #endif gp_port_info_list_get_info (chooser->priv->il, i, &info); #ifdef HAVE_GP_PORT_INFO_GET_NAME gp_port_info_get_type (info, &type); gp_port_info_get_name (info, &xname); gp_port_info_get_path (info, &xpath); if (type & types) list = g_list_append (list, g_strdup_printf ("%s (%s)", xname, xpath)); #else if (info.type & types) list = g_list_append (list, g_strdup_printf ("%s (%s)", info.name, info.path)); #endif } gtkam_chooser_set_port_list (chooser, list); }
/** * \param list a CameraAbilitiesList * \param info_list the GPPortInfoList of ports to use for detection * \param l a #CameraList that contains the autodetected cameras after the call * \param context a #GPContext * * Tries to detect any camera connected to the computer using the supplied * list of supported cameras and the supplied info_list of ports. * * \return a gphoto2 error code */ int gp_abilities_list_detect (CameraAbilitiesList *list, GPPortInfoList *info_list, CameraList *l, GPContext *context) { GPPortInfo info; GPPort *port; int i, info_count; CHECK_NULL (list && info_list && l); gp_list_reset (l); CHECK_RESULT (info_count = gp_port_info_list_count (info_list)); CHECK_RESULT (gp_port_new (&port)); for (i = 0; i < info_count; i++) { int res; char *xpath; GPPortType type; CHECK_RESULT (gp_port_info_list_get_info (info_list, i, &info)); CHECK_RESULT (gp_port_set_info (port, info)); gp_port_info_get_type (info, &type); res = gp_port_info_get_path (info, &xpath); if (res <GP_OK) continue; switch (type) { case GP_PORT_USB: case GP_PORT_USB_SCSI: case GP_PORT_USB_DISK_DIRECT: { int ability; res = gp_abilities_list_detect_usb (list, &ability, port); if (res == GP_OK) { gp_list_append(l, list->abilities[ability].model, xpath); } else if (res < 0) gp_port_set_error (port, NULL); break; } case GP_PORT_DISK: { char *s, path[1024]; struct stat stbuf; s = strchr (xpath, ':'); if (!s) break; s++; snprintf (path, sizeof(path), "%s/DCIM", s); if (-1 == stat(path, &stbuf)) { snprintf (path, sizeof(path), "%s/dcim", s); if (-1 == stat(path, &stbuf)) continue; } gp_list_append (l, "Mass Storage Camera", xpath); break; } case GP_PORT_PTPIP: { char *s; s = strchr (xpath, ':'); if (!s) break; s++; if (!strlen(s)) break; gp_list_append (l, "PTP/IP Camera", xpath); break; } default: /* * We currently cannot detect any cameras on this * port */ break; } } gp_port_free (port); return (GP_OK); }
/** * Initiate a connection to the \c camera. * * @param camera a #Camera * @param context a #GPContext * @return a gphoto2 error code * * Before calling this function, the * \c camera should be set up using gp_camera_set_port_path() or * gp_camera_set_port_name() and gp_camera_set_abilities(). If that has been * omitted, gphoto2 tries to autodetect any cameras and chooses the first one * if any cameras are found. It is generally a good idea to call * gp_camera_exit() after transactions have been completed in order to give * other applications the chance to access the camera, too. * */ int gp_camera_init (Camera *camera, GPContext *context) { CameraAbilities a; const char *model, *port; CameraLibraryInitFunc init_func; int result; GP_LOG_D ("Initializing camera..."); C_PARAMS (camera); /* * Reset the exit_requested flag. If this flag is set, * gp_camera_exit will be called as soon as the camera is no * longer in use (used flag). */ camera->pc->exit_requested = 0; /* * If the model hasn't been indicated, try to * figure it out (USB only). Beware of "Directory Browse". */ if (strcasecmp (camera->pc->a.model, "Directory Browse") && !strcmp ("", camera->pc->a.model)) { CameraAbilitiesList *al; GPPortInfoList *il; int m, p; char *ppath; GPPortType ptype; GPPortInfo info; CameraList *list; result = gp_list_new (&list); if (result < GP_OK) return result; GP_LOG_D ("Neither port nor model set. Trying auto-detection..."); /* Call auto-detect and choose the first camera */ CRSL (camera, gp_abilities_list_new (&al), context, list); CRSL (camera, gp_abilities_list_load (al, context), context, list); CRSL (camera, gp_port_info_list_new (&il), context, list); CRSL (camera, gp_port_info_list_load (il), context, list); CRSL (camera, gp_abilities_list_detect (al, il, list, context), context, list); if (!gp_list_count (list)) { gp_abilities_list_free (al); gp_port_info_list_free (il); gp_context_error (context, _("Could not detect " "any camera")); gp_list_free (list); return (GP_ERROR_MODEL_NOT_FOUND); } p = 0; CRSL (camera, gp_port_get_info (camera->port, &info), context, list); CRSL (camera, gp_port_info_get_path (info, &ppath), context, list); CRSL (camera, gp_port_info_get_type (info, &ptype), context, list); /* if the port was set before, then use that entry, but not if it is "usb:" */ if ((ptype == GP_PORT_USB) && strlen(ppath) && strcmp(ppath, "usb:")) { for (p = gp_list_count (list);p--;) { const char *xp; gp_list_get_value (list, p, &xp); if (!strcmp (xp, ppath)) break; } if (p<0) { gp_abilities_list_free (al); gp_port_info_list_free (il); gp_context_error (context, _("Could not detect any camera at port %s"), ppath); gp_list_free (list); return (GP_ERROR_FILE_NOT_FOUND); } } CRSL (camera, gp_list_get_name (list, p, &model), context, list); m = gp_abilities_list_lookup_model (al, model); CRSL (camera, m, context, list); CRSL (camera, gp_abilities_list_get_abilities (al, m, &a), context, list); gp_abilities_list_free (al); CRSL (camera, gp_camera_set_abilities (camera, a), context, list); CRSL (camera, gp_list_get_value (list, p, &port), context, list); p = gp_port_info_list_lookup_path (il, port); CRSL (camera, p, context, list); CRSL (camera, gp_port_info_list_get_info (il, p, &info), context, list); CRSL (camera, gp_camera_set_port_info (camera, info), context, list); gp_port_info_list_free (il); gp_list_free (list); } if (strcasecmp (camera->pc->a.model, "Directory Browse")) { switch (camera->port->type) { case GP_PORT_NONE: gp_context_error (context, _("You have to set the " "port prior to initialization of the camera.")); return (GP_ERROR_UNKNOWN_PORT); case GP_PORT_USB: if (gp_port_usb_find_device (camera->port, camera->pc->a.usb_vendor, camera->pc->a.usb_product) != GP_OK) { CRS (camera, gp_port_usb_find_device_by_class (camera->port, camera->pc->a.usb_class, camera->pc->a.usb_subclass, camera->pc->a.usb_protocol), context); } break; default: break; } } /* Load the library. */ GP_LOG_D ("Loading '%s'...", camera->pc->a.library); lt_dlinit (); camera->pc->lh = lt_dlopenext (camera->pc->a.library); if (!camera->pc->lh) { gp_context_error (context, _("Could not load required " "camera driver '%s' (%s)."), camera->pc->a.library, lt_dlerror ()); lt_dlexit (); return (GP_ERROR_LIBRARY); } /* Initialize the camera */ init_func = lt_dlsym (camera->pc->lh, "camera_init"); if (!init_func) { lt_dlclose (camera->pc->lh); lt_dlexit (); camera->pc->lh = NULL; gp_context_error (context, _("Camera driver '%s' is " "missing the 'camera_init' function."), camera->pc->a.library); return (GP_ERROR_LIBRARY); } if (strcasecmp (camera->pc->a.model, "Directory Browse")) { result = gp_port_open (camera->port); if (result < 0) { lt_dlclose (camera->pc->lh); lt_dlexit (); camera->pc->lh = NULL; return (result); } } result = init_func (camera, context); if (result < 0) { gp_port_close (camera->port); lt_dlclose (camera->pc->lh); lt_dlexit (); camera->pc->lh = NULL; memset (camera->functions, 0, sizeof (CameraFunctions)); return (result); } /* We don't care if that goes wrong */ #ifdef HAVE_MULTI gp_port_close (camera->port); #endif return (GP_OK); }