int
auto_detect_action (CameraList *list,GPContext *context)
{
	int count, result;
    GPPortInfoList *portinfo_list;
    CameraAbilitiesList *al = NULL;
	if ((result = gp_port_info_list_new (&portinfo_list)) < GP_OK)
		return result;
	result = gp_port_info_list_load (portinfo_list);
	if (result < 0) {
		gp_port_info_list_free (portinfo_list);
		return result;
	}
	count = gp_port_info_list_count (portinfo_list);
	if (count < 0) {
		gp_port_info_list_free (portinfo_list);
		return count;
	}
    gp_abilities_list_new (&al);
    gp_abilities_list_load (al, context);
    gp_abilities_list_detect (al, portinfo_list, list, context);
    gp_abilities_list_free (al);
	count = gp_list_count (list);
    return count > 0 ? GP_OK : GP_ERROR;
}
Exemple #2
0
static int
compare_lists (void)
{
  unsigned int errors = 0;
  CameraAbilitiesList *ddb = read_abilities_list(NULL);
  CameraAbilitiesList *clb;
  unsigned int i, j, n_ddb, n_clb;
  gp_abilities_list_new(&clb);
  gp_abilities_list_load(clb, NULL);
  n_ddb = gp_abilities_list_count(ddb);
  n_clb = gp_abilities_list_count(clb);
  fprintf(stderr, "## Comparing ddb with clb ##\n");
  for (i=0, j=0; (i<n_ddb) && (j<n_clb); ) {
    CameraAbilities a, b;
    gp_abilities_list_get_abilities(ddb, i, &a);
    gp_abilities_list_get_abilities(clb, j, &b);
    if ((b.port & GP_PORT_USB) && (b.usb_class == 666)) {
      /* ignore this camera */
      j++;
      continue;
    }
    if (compare_camera_abilities(&a, &b)) {
      errors++;
    }
    i++, j++;
  }
  gp_abilities_list_free(clb);
  gp_abilities_list_free(ddb);
  return (errors == 0)? 0 : 1;
}
Exemple #3
0
static GNOME_GnoCam_ModelList *
impl_GNOME_GnoCam_getModelList (PortableServer_Servant servant,
					CORBA_Environment *ev)
{
	GnoCamMain *gm;
	GNOME_GnoCam_ModelList *list;
	CameraAbilitiesList *al = NULL;
	int n, i;
	CameraAbilities a;

	gm = GNOCAM_MAIN (bonobo_object_from_servant (servant));

	gp_abilities_list_new (&al);
	gp_abilities_list_load (al, NULL);
	n = MAX (0, gp_abilities_list_count (al));
	list = GNOME_GnoCam_ModelList__alloc ();
	list->_buffer = CORBA_sequence_CORBA_string_allocbuf (n);
	for (i = 0; i < n; i++) {
		if (gp_abilities_list_get_abilities (al, i, &a) >= 0) {
			list->_buffer[list->_length] =
				CORBA_string_dup (a.model);
			list->_length++;
		}
	}
	CORBA_sequence_set_release (list, TRUE);
	gp_abilities_list_free (al);

	return (list);
}
dt_camctl_t *dt_camctl_new()
{
  dt_camctl_t *camctl=g_malloc(sizeof(dt_camctl_t));
  memset(camctl,0,sizeof(dt_camctl_t));
  dt_print(DT_DEBUG_CAMCTL,"[camera_control] creating new context %lx\n",(unsigned long int)camctl);

  // Initialize gphoto2 context and setup dispatch callbacks
  camctl->gpcontext = gp_context_new();
  gp_context_set_idle_func( camctl->gpcontext , (GPContextIdleFunc)_idle_func_dispatch, camctl );
  gp_context_set_status_func( camctl->gpcontext , (GPContextStatusFunc)_status_func_dispatch, camctl );
  gp_context_set_error_func( camctl->gpcontext , (GPContextErrorFunc)_error_func_dispatch, camctl );
  gp_context_set_message_func( camctl->gpcontext , (GPContextMessageFunc)_message_func_dispatch, camctl );

  // Load all camera drivers we know...
  gp_abilities_list_new( &camctl->gpcams );
  gp_abilities_list_load( camctl->gpcams, camctl->gpcontext );
  dt_print(DT_DEBUG_CAMCTL,"[camera_control] loaded %d camera drivers.\n", gp_abilities_list_count( camctl->gpcams ) );

  dt_pthread_mutex_init(&camctl->lock, NULL);

  // Let's detect cameras connexted
  dt_camctl_detect_cameras(camctl);


  return camctl;
}
Exemple #5
0
void GPCamera::getCameraSupportedPorts(const QString& model, QStringList& plist)
{
#ifdef HAVE_GPHOTO2
    int i                         = 0;
    plist.clear();

    CameraAbilities      abilities;
    CameraAbilitiesList* abilList = 0;
    GPContext*           context  = 0;
    context                       = gp_context_new();

    gp_abilities_list_new(&abilList);
    gp_abilities_list_load(abilList, context);
    i = gp_abilities_list_lookup_model(abilList, model.toLocal8Bit().data());
    gp_abilities_list_get_abilities(abilList, i, &abilities);
    gp_abilities_list_free(abilList);

    if (abilities.port & GP_PORT_SERIAL)
    {
        plist.append(QLatin1String("serial"));
    }

    if (abilities.port & GP_PORT_USB)
    {
        plist.append(QLatin1String("usb"));
    }

    gp_context_unref(context);
#else
    Q_UNUSED(model);
    Q_UNUSED(plist);
#endif /* HAVE_GPHOTO2 */
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    CameraAbilities a;
    int size,r;
    ui->setupUi(this);

    QStandardItemModel *model = new QStandardItemModel(this);

    model->setHorizontalHeaderItem(0, new QStandardItem(QString("Camera")));
    model->setHorizontalHeaderItem(1, new QStandardItem(QString("Comment")));
    ui->tableView->setModel(model);

    GPContext* context = gp_context_new();
    CameraAbilitiesList* list;

    gp_abilities_list_new(&list);
    gp_abilities_list_load(list, context);

    size = gp_abilities_list_count(list);
    for(int i= 0; i < size; i++)
    {
        r = gp_abilities_list_get_abilities(list, i, &a);
        if( r < 0 ) break;
        QStandardItem* cam = new QStandardItem(QString(a.model));
        model->setItem(i,0, cam);

        QStandardItem* com = new QStandardItem();
        switch (a.status)
        {
        case GP_DRIVER_STATUS_TESTING:
            com->setText(QString("TESTING"));
            break;
        case GP_DRIVER_STATUS_EXPERIMENTAL:
             com->setText(QString("EXPERIMENTAL"));
            break;
        case GP_DRIVER_STATUS_DEPRECATED:
            com->setText(QString("DEPRECATED"));
            break;
        case GP_DRIVER_STATUS_PRODUCTION:
            break;
        default:
            com->setText(QString("UNKOWN"));
            break;
        }
        model->setItem(i,1, com);
    }

    gp_abilities_list_free(list);
    list = NULL;
    gp_context_unref(context);
    context = NULL;


}
Exemple #7
0
CameraAbilitiesList *
gp_params_abilities_list (GPParams *p)
{
	/* If p == NULL, the behaviour of this function is as undefined as
	 * the expression p->abilities_list would have been. */
	if (p->_abilities_list == NULL) {
		gp_abilities_list_new (&p->_abilities_list);
		gp_abilities_list_load (p->_abilities_list, p->context);
	}
	return p->_abilities_list;
}
Exemple #8
0
/** 
 * Get list of supported cameras, walk through it, and try to see
 * if the provided USB product/vendor combination was specified.
 */
int
main (int argc, char *argv[])
{
    CameraAbilitiesList *al;
    int         i;
    int         count;
    const char *fmt_str = NULL;


    CHECK (gp_abilities_list_new  (&al));
    CHECK (gp_abilities_list_load (al, NULL));

    count = gp_abilities_list_count (al);
    if (count < 0) {
        printf("gp_abilities_list_count error: %d\n", count);
        return(1);
    }
    else if (count == 0) {
        /* Copied from gphoto2-abilities-list.c gp_abilities_list_load() */
        const char *camlib_env = getenv(CAMLIBDIR_ENV);
        const char *camlibs = (camlib_env != NULL)?camlib_env:CAMLIBS;

        printf("no camera drivers (camlibs) found in camlib dir:\n"
               "    CAMLIBS='%s', default='%s', used=%s\n",
               camlib_env?camlib_env:"(null)", CAMLIBS,
               (camlib_env!=NULL)?"CAMLIBS":"default");
        return(1);
    }


    /* For each camera in the list, add a text snippet to the 
     * output file. */
    for (i = 0; i < count; i++) {
        CameraAbilities abilities;
        const char *camlib_basename;
        CHECK (gp_abilities_list_get_abilities (al, i, &abilities));
        camlib_basename = basename(abilities.library);

        /* Don't print out empty vendor IDs.  Empty product IDs might be
         * okay, though. */
        if( !abilities.usb_vendor )
            continue;

        printf("%04x:%04x\t# %s\n",
               abilities.usb_vendor,
               abilities.usb_product,
               abilities.model
               );
    }

    CHECK (gp_abilities_list_free (al));
    return (0);
}
Exemple #9
0
/**
 * Autodetect all detectable camera
 *
 * @param list a #CameraList that receives the autodetected cameras
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * This camera will autodetected all cameras that can be autodetected.
 * This will for instance detect all USB cameras.
 *
 *   CameraList *list;
 *   gp_list_new (&list);
 *   gp_camera_autodetect (list, context);
 *   ... done! ...
 */
int
gp_camera_autodetect (CameraList *list, GPContext *context)
{
	CameraAbilitiesList	*al = NULL;
	GPPortInfoList		*il = NULL;
	int			ret, i;
	CameraList		*xlist = NULL;

	ret = gp_list_new (&xlist);
	if (ret < GP_OK) goto out;
	if (!il) {
		/* Load all the port drivers we have... */
		ret = gp_port_info_list_new (&il);
		if (ret < GP_OK) goto out;
		ret = gp_port_info_list_load (il);
		if (ret < 0) goto out;
		ret = gp_port_info_list_count (il);
		if (ret < 0) goto out;
	}
	/* Load all the camera drivers we have... */
	ret = gp_abilities_list_new (&al);
	if (ret < GP_OK) goto out;
	ret = gp_abilities_list_load (al, context);
	if (ret < GP_OK) goto out;

	/* ... and autodetect the currently attached cameras. */
        ret = gp_abilities_list_detect (al, il, xlist, context);
	if (ret < GP_OK) goto out;

	/* Filter out the "usb:" entry */
        ret = gp_list_count (xlist);
	if (ret < GP_OK) goto out;
	for (i=0;i<ret;i++) {
		const char *name, *value;

		gp_list_get_name (xlist, i, &name);
		gp_list_get_value (xlist, i, &value);
		if (!strcmp ("usb:",value)) continue;
		gp_list_append (list, name, value);
	}
out:
	if (il) gp_port_info_list_free (il);
	if (al) gp_abilities_list_free (al);
	gp_list_free (xlist);
	if (ret < GP_OK)
		return ret;
	return gp_list_count(list);
}
bool photo_camera_list::loadAbilities( GPContext* context )
{
  // Create a new abilities list
  if( gp_abilities_list_new( &abilities_list_ ) != GP_OK )
  {
    photo_reporter::error( "gp_abilities_list_new()" );
    return false;
  }

  // Populate the abilities list
  if( gp_abilities_list_load( abilities_list_, context ) != GP_OK )
  {
    photo_reporter::error( "gp_abilities_list_load()" );
    return false;
  }

  return true;
}
void Image_GPhoto::init()
{
    _type = "image_gphoto";
    registerAttributes();

    // This is used for getting documentation "offline"
    if (!_root)
        return;

    lock_guard<recursive_mutex> lock(_gpMutex);

    _gpContext = gp_context_new();
    gp_abilities_list_new(&_gpCams);
    gp_abilities_list_load(_gpCams, _gpContext);

    Log::get() << Log::MESSAGE << "Image_GPhoto::" << __FUNCTION__ << " - Loaded " << gp_abilities_list_count(_gpCams) << " camera drivers" << Log::endl;

    detectCameras();
}
Exemple #12
0
void GPCamera::getSupportedCameras(int& count, QStringList& clist)
{
#ifdef HAVE_GPHOTO2
    clist.clear();
    count                         = 0;

    CameraAbilities      abil;
    CameraAbilitiesList* abilList = 0;
    GPContext*           context  = 0;
    context                       = gp_context_new();

    gp_abilities_list_new(&abilList);
    gp_abilities_list_load(abilList, context);

    count                         = gp_abilities_list_count(abilList);

    if (count < 0)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get list of cameras!";
        printGphotoErrorDescription(count);
        gp_context_unref(context);
        return;
    }
    else
    {
        for (int i = 0 ; i < count ; i++)
        {
            gp_abilities_list_get_abilities(abilList, i, &abil);
            const char* cname = abil.model;
            clist.append(QString::fromLocal8Bit(cname));
        }
    }

    gp_abilities_list_free(abilList);
    gp_context_unref(context);
#else
    Q_UNUSED(count);
    Q_UNUSED(clist);
#endif /* HAVE_GPHOTO2 */
}
Exemple #13
0
static TW_UINT16
gphoto2_auto_detect(void) {
    int result, count;

    if (detected_cameras && (gp_list_count (detected_cameras) == 0)) {
	/* Reload if previously no cameras, we might detect new ones. */
	TRACE("Reloading portlist trying to detect cameras.\n");
	if (port_list) {
	    gp_port_info_list_free (port_list);
	    port_list = NULL;
	}
    }
    if (!port_list) {
	TRACE("Auto detecting gphoto cameras.\n");
	TRACE("Loading ports...\n");
	if (gp_port_info_list_new (&port_list) < GP_OK)
	    return TWRC_FAILURE;
	result = gp_port_info_list_load (port_list);
	if (result < 0) {
	    gp_port_info_list_free (port_list);
	    return TWRC_FAILURE;
	}
	count = gp_port_info_list_count (port_list);
	if (count <= 0)
	    return TWRC_FAILURE;
	if (gp_list_new (&detected_cameras) < GP_OK)
	    return TWRC_FAILURE;
	if (!abilities_list) { /* Load only once per program start */
	    gp_abilities_list_new (&abilities_list);
	    TRACE("Loading cameras...\n");
	    gp_abilities_list_load (abilities_list, NULL);
	}
	TRACE("Detecting cameras...\n");
	gp_abilities_list_detect (abilities_list, port_list, detected_cameras, NULL);
        curcamera = 0;
        TRACE("%d cameras detected\n", gp_list_count(detected_cameras));
    }
    return TWRC_SUCCESS;
}
Exemple #14
0
static GnoCamCamera *
gnocam_main_get_camera (GnoCamMain *gm, const gchar *model, const gchar *port,
		        CORBA_Environment *ev)
{
	Camera *camera;
	GnoCamCamera *gc = NULL;

	g_message ("Trying to get a camera for model '%s' (port '%s')...",
		   model, port);

	g_return_val_if_fail (GNOCAM_IS_MAIN (gm), NULL);

	gc = gnocam_cache_lookup (gm->priv->cache, model, port);
	if (gc) {
		bonobo_object_ref (gc);
		return gc;
	}

	CR (gp_camera_new (&camera), ev);
	if (BONOBO_EX (ev))
		return (CORBA_OBJECT_NIL);

	if (model && strlen (model)) {
		CameraAbilities a;
		CameraAbilitiesList *al = NULL;
		int m;

	        memset (&a, 0, sizeof (CameraAbilities));
	        gp_abilities_list_new (&al);
	        gp_abilities_list_load (al, NULL);
	        m = gp_abilities_list_lookup_model (al, model);
	        gp_abilities_list_get_abilities (al, m, &a);
	        gp_abilities_list_free (al);
		CR (gp_camera_set_abilities (camera, a), ev);
		if (BONOBO_EX (ev)) {
			gp_camera_unref (camera);
			return NULL;
		}
	}

	if (port && strlen (port)) {
		GPPortInfo info;
		GPPortInfoList *il = NULL;
		int p;

		memset (&info, 0, sizeof (GPPortInfo));
		gp_port_info_list_new (&il);
		gp_port_info_list_load (il);
		p = gp_port_info_list_lookup_name (il, port);
		if (p < 0)
			p = gp_port_info_list_lookup_path (il, port);
		gp_port_info_list_get_info (il, p, &info);
		gp_port_info_list_free (il);
		CR (gp_camera_set_port_info (camera, info), ev); 
		if (BONOBO_EX (ev)) { 
			gp_camera_unref (camera);
			return (CORBA_OBJECT_NIL);
		}
	}

        CR (gp_camera_init (camera, NULL), ev);
        if (BONOBO_EX (ev)) {
                gp_camera_unref (camera); 
                return NULL;
        }

        gc = gnocam_camera_new (camera, ev);
        gp_camera_unref (camera);
        if (BONOBO_EX (ev))
                return NULL;

	gnocam_cache_add (gm->priv->cache, gc);

        g_message ("Successfully created a camera.");

	return gc;
}
Exemple #15
0
int
main (int argc, char **argv)
{
    fd_set rs;
    struct timeval tv;
    int n, cmd_len;
    char cmd[PATH_MAX + 32];
    const char *arg;
    GFParams params;

    memset (&params, 0, sizeof (GFParams));
    if (gp_camera_new (&(params.camera)) < 0)
        goto ExitError;
    if (gp_abilities_list_new (&(params.al)) < 0)
        goto ExitError;
    if (gp_abilities_list_load (params.al, NULL) < 0)
        goto ExitError;
    if (gp_port_info_list_new (&params.il) < 0)
        goto ExitError;
    if (gp_port_info_list_load (params.il) < 0)
        goto ExitError;
    params.folder = malloc (strlen ("/") + 1);
    if (!params.folder)
        goto ExitError;
    strcpy (params.folder, "/");
    params.idletime = 1800;

    n = sizeof (struct sockaddr_in);
    if (getsockname (0, (struct sockaddr *) &params.sai_sock, &n)) {
        fprintf (stdout, "421 Can not get name of sock.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = sizeof (struct sockaddr_in);
    if (getpeername (0, (struct sockaddr *) &params.sai_peer, &n)) {
        fprintf (stdout, "421 Can not get name of peer.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = IPTOS_LOWDELAY;
    setsockopt (0, IPPROTO_IP, IP_TOS, (char *) &n, sizeof (int));

    fprintf (stdout, "220-Hello and welcome to the wonderful world\r\n");
    fprintf (stdout, "220-of gphoto!\r\n");
    fprintf (stdout, "220-\r\n");
    fprintf (stdout, "220-Use this server like a standard FTP-Server.\r\n");
    fprintf (stdout, "220-List files in virtual directory\r\n");
    fflush (stdout);
    fprintf (stdout, "220-'/capture-image' in order to capture\r\n");
    fflush (stdout);
    fprintf (stdout, "220-an image, in '/capture-preview' in order\r\n");
    fflush (stdout);
    fprintf (stdout, "220-to capture a preview.\r\n");
    fflush (stdout);
    fprintf (stdout, "220 FTP server ready.\r\n");
    fflush (stdout);

    while (1) {

        /* Read something. */
        syslog (LOG_INFO, "Reading...");
        FD_ZERO (&rs);
        tv.tv_sec = 1800;
        tv.tv_usec = 0;
        memset (cmd, 0, sizeof (cmd));
        cmd_len = n = 0;
        while (1) {
            if (!n) {
                FD_SET (0, &rs);
                select (1, &rs, NULL, NULL, &tv);
                if (ioctl (0, FIONREAD, &n) < 0)
                    n = 0;
            }
            if (FD_ISSET (0, &rs)) {
                if (read (0, cmd + cmd_len, 1) <= 0)
                    goto ExitError;
                if (n)
                    n--;
                if (cmd[cmd_len] == '\n') {
                    cmd[cmd_len + 1] = '\0';
                    break;
                }
                if (cmd_len < sizeof (cmd) - 2)
                    cmd_len++;
            } else
                goto ExitError;
        }

        syslog (LOG_INFO, "Got '%s'...", cmd);
        for (n = 0; isalpha (cmd[n]) && n < sizeof (cmd); n++)
            cmd[n] = tolower (cmd[n]);
        if (!n) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            goto ExitOk;
        }
        while (isspace (cmd[n]) && n < sizeof (cmd))
            cmd[n++] = '\0';
        arg = cmd + n;
        while (cmd[n] && n < sizeof (cmd))
            n++;
        n--;
        while (isspace (cmd[n]))
            cmd[n--] = '\0';
        syslog (LOG_INFO, "Processing '%s' - '%s'...", cmd, arg);
        if (!strcasecmp (cmd, "cwd")) {
            gf_cwd (&params, arg);
        } else if (!strcasecmp (cmd, "list")) {
            if (gf_list (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "noop")) {
            fprintf (stdout, "200 NOOP command successful.\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "pass")) {
            if (gf_pass (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pasv")) {
            gf_pasv (&params);
        } else if (!strcasecmp (cmd, "port")) {
            if (gf_port (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pwd") ||
                   !strcasecmp (cmd, "xpwd")) {
            fprintf (stdout, "257 \"%s\"\r\n", params.folder);
            fflush (stdout);
        } else if (!strcasecmp (cmd, "quit")) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            syslog (LOG_INFO, "Quit.");
            return (0);
        } else if (!strcasecmp (cmd, "retr")) {
            if (gf_retr (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "syst")) {
            printf ("215 UNIX Type: L8\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "type")) {
            if (!arg)
                goto ExitError;
            gf_type (&params, *arg);
        } else if (!strcasecmp (cmd, "user")) {
            if (gf_user (&params, arg) < 0)
                goto ExitError;
        } else {
            syslog (LOG_INFO, "Command '%s'...", cmd);
            printf ("%3d %s\r\n", 550, "Unknown command.");
            fflush (stdout);
        }
    }

ExitError:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    syslog (LOG_INFO, "Error: 1");
    return (1);

ExitOk:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    return (0);
}
Exemple #16
0
void KKameraConfig::load(bool useDefaults )
{
	m_config->setReadDefaults( useDefaults );
	QStringList groupList = m_config->groupList();
	QStringList::Iterator it;
        int i, count;
        CameraList *list;
        CameraAbilitiesList *al;
        GPPortInfoList *il;
        const char *model, *value;
	KCamera *kcamera;
	
	for (it = groupList.begin(); it != groupList.end(); it++) {
		if (*it != "<default>")	{
			m_config->setGroup(*it);
			if (m_config->readEntry("Path").contains("usb:"))
				continue;

			kcamera = new KCamera(*it,m_config->readEntry("Path"));
			connect(kcamera, SIGNAL(error(const QString &)), SLOT(slot_error(const QString &)));
			connect(kcamera, SIGNAL(error(const QString &, const QString &)), SLOT(slot_error(const QString &, const QString &)));
			kcamera->load(m_config);
			m_devices[*it] = kcamera;
		}
	}
	m_cancelPending = false;

	gp_list_new (&list);

        gp_abilities_list_new (&al);
        gp_abilities_list_load (al, m_context);
        gp_port_info_list_new (&il);
        gp_port_info_list_load (il);
        gp_abilities_list_detect (al, il, list, m_context);
        gp_abilities_list_free (al);
        gp_port_info_list_free (il);

        count = gp_list_count (list);

	QMap<QString,QString>	ports, names;
	
	for (i = 0 ; i<count ; i++) {
		gp_list_get_name  (list, i, &model);
		gp_list_get_value (list, i, &value);

		ports[value] = model;
		if (!strcmp(value,"usb:"))
			names[model] = value;
	}
	if (ports.contains("usb:") && names[ports["usb:"]]!="usb:")
		ports.remove("usb:");

	QMap<QString,QString>::iterator portit;

	for (portit = ports.begin() ; portit != ports.end(); portit++) {
		/* kdDebug() << "Adding USB camera: " << portit.data() << " at " << portit.key() << endl; */

		kcamera = new KCamera(portit.data(),portit.key());
		connect(kcamera, SIGNAL(error(const QString &)), SLOT(slot_error(const QString &)));
		connect(kcamera, SIGNAL(error(const QString &, const QString &)), SLOT(slot_error(const QString &, const QString &)));
		m_devices[portit.data()] = kcamera;
	}
	populateDeviceListView();

	gp_list_free (list);

	emit changed( useDefaults );
}
Exemple #17
0
/**
 * 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 (GP_LOG_DEBUG, "gphoto2-camera", "Initializing camera...");

	CHECK_NULL (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;
		GPPortInfo	pinfo;
		GPPortInfoList	*il;
		int		m, p;
		GPPortInfo	info;
        	CameraList	*list;

		result = gp_list_new (&list);
		if (result < GP_OK)
			return result;

		result = gp_port_get_info (camera->port, &pinfo);
		if (result < GP_OK)
			return result;

		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.type %d", pinfo.type);
		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.path %s", pinfo.path);
		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.name %s", pinfo.name);
		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Neither "
			"port nor model set. Trying auto-detection...");

		/* Call auto-detect and choose the first camera */
		gp_abilities_list_new (&al);
		gp_abilities_list_load (al, context);
		gp_port_info_list_new (&il);
		gp_port_info_list_load (il);
		gp_abilities_list_detect (al, il, list, context);
		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;
		/* if the port was set before, then use that entry. but not if it is "usb:" */
		if (	(pinfo.type == GP_PORT_USB) &&
			strlen(pinfo.path) &&
			strcmp(pinfo.path,"usb:")
		) {
			for (p = gp_list_count (list);p--;) {
				const char *xp;

				gp_list_get_value (list, p, &xp);
				if (!strcmp (xp, pinfo.path))
					break;
			}
			if (p<0) {
				gp_context_error (context, _("Could not detect any camera at port %s"), pinfo.path);
				return (GP_ERROR_FILE_NOT_FOUND);
			}
		}

		gp_list_get_name  (list, p, &model);
		m = gp_abilities_list_lookup_model (al, model);
		gp_abilities_list_get_abilities (al, m, &a);
		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);
		gp_port_info_list_get_info (il, p, &info);
		gp_port_info_list_free (il);
		CRSL (camera, gp_camera_set_port_info (camera, info), context, list);
		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 (GP_LOG_DEBUG, "gphoto2-camera", "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);
}
Exemple #18
0
bool GPCamera::doConnect()
{
#ifdef HAVE_GPHOTO2
    int errorCode;

    // -- first step - setup the camera --------------------

    if (d->camera)
    {
        gp_camera_unref(d->camera);
        d->camera = 0;
    }

    CameraAbilitiesList* abilList = 0;
    GPPortInfoList*      infoList = 0;
    GPPortInfo           info;

    gp_camera_new(&d->camera);

    delete d->status;
    d->status = 0;
    d->status = new GPStatus();

    gp_abilities_list_new(&abilList);
    gp_abilities_list_load(abilList, d->status->context);
    gp_port_info_list_new(&infoList);
    gp_port_info_list_load(infoList);

    int modelNum     = gp_abilities_list_lookup_model(abilList, m_model.toLatin1().constData());
    int portNum      = gp_port_info_list_lookup_path(infoList, m_port.toLatin1().constData());

    gp_abilities_list_get_abilities(abilList, modelNum, &d->cameraAbilities);

    errorCode    = gp_camera_set_abilities(d->camera, d->cameraAbilities);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera Abilities!";
        printGphotoErrorDescription(errorCode);
        gp_camera_unref(d->camera);
        d->camera = 0;
        gp_abilities_list_free(abilList);
        gp_port_info_list_free(infoList);
        return false;
    }

    if (m_model != QLatin1String("Directory Browse"))
    {
        gp_port_info_list_get_info(infoList, portNum, &info);
        errorCode = gp_camera_set_port_info(d->camera, info);

        if (errorCode != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera port!";
            printGphotoErrorDescription(errorCode);
            gp_camera_unref(d->camera);
            d->camera = 0;
            gp_abilities_list_free(abilList);
            gp_port_info_list_free(infoList);
            return false;
        }
    }

    gp_abilities_list_free(abilList);
    gp_port_info_list_free(infoList);

    if (d->cameraAbilities.file_operations &
        GP_FILE_OPERATION_PREVIEW)
    {
        m_thumbnailSupport = true;
    }

    if (d->cameraAbilities.file_operations &
        GP_FILE_OPERATION_DELETE)
    {
        m_deleteSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_PUT_FILE)
    {
        m_uploadSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_MAKE_DIR)
    {
        m_mkDirSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_REMOVE_DIR)
    {
        m_delDirSupport = true;
    }

    if (d->cameraAbilities.operations &
        GP_OPERATION_CAPTURE_IMAGE)
    {
        m_captureImageSupport = true;
    }

    if (d->cameraAbilities.operations &
        GP_OPERATION_CAPTURE_PREVIEW)
    {
        m_captureImagePreviewSupport = true;
    }

    // -- Try and initialize the camera to see if its connected -----------------

    errorCode = gp_camera_init(d->camera, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to initialize camera!";
        printGphotoErrorDescription(errorCode);
        gp_camera_unref(d->camera);
        d->camera = 0;
        return false;
    }

    d->cameraInitialized = true;

    return true;
#else
    return false;
#endif /* HAVE_GPHOTO2 */
}
Exemple #19
0
bool GPCamera::findConnectedUsbCamera(int vendorId, int productId, QString& model, QString& port)
{
#ifdef HAVE_GPHOTO2
    CameraAbilitiesList* abilList = 0;
    GPPortInfoList*      list     = 0;
    GPContext*           context  = 0;
    CameraList*          camList  = 0;
    bool                 success  = false;
    // get name and port of detected camera
    const char* model_str         = 0;
    const char* port_str          = 0;
    context                       = gp_context_new();

    // get list of all ports
    gp_port_info_list_new(&list);
    gp_port_info_list_load(list);

    gp_abilities_list_new(&abilList);
    // get list of all supported cameras
    gp_abilities_list_load(abilList, context);

    // autodetect all cameras, then match the list to the passed in USB ids
    gp_list_new (&camList);
    gp_abilities_list_detect(abilList, list, camList, context);
    gp_context_unref(context);

    int count = gp_list_count(camList);
    int cnt   = 0;

    for (int i = 0 ; i < count ; i++)
    {
        const char* xmodel = 0;
        gp_list_get_name(camList, i, &xmodel);
        int model          = gp_abilities_list_lookup_model (abilList, xmodel);
        CameraAbilities ab;
        gp_abilities_list_get_abilities(abilList, model, &ab);

        if (ab.port != GP_PORT_USB)
            continue;

        /* KDE provides us USB Vendor and Product, but we might just
         * have covered this via a class match. Check class matched
         * cameras also for matchingo USB vendor/product id
         */
        if (ab.usb_vendor == 0)
        {
            int ret;
            GPPortInfo info;
            const char* xport = 0;
            GPPort* gpport    = 0;

            /* get the port path so we only look at this bus position */
            gp_list_get_value(camList, i, &xport);
            ret = gp_port_info_list_lookup_path (list, xport);

            if (ret < GP_OK) /* should not happen */
                continue;

            /* get the lowlevel port info  for the path
             */
            gp_port_info_list_get_info(list, ret, &info);

            /* open lowlevel driver interface briefly to search */
            gp_port_new(&gpport);
            gp_port_set_info(gpport, info);

            /* And now call into the lowlevel usb driver to see if the bus position
             * has that specific vendor/product id
             */
            if (gp_port_usb_find_device(gpport, vendorId, productId) == GP_OK)
            {
                ab.usb_vendor  = vendorId;
                ab.usb_product = productId;
            }

            gp_port_free (gpport);
        }

        if (ab.usb_vendor != vendorId)
            continue;

        if (ab.usb_product != productId)
            continue;

        /* keep it, and continue iterating, in case we find another one
         */
        gp_list_get_name (camList, i, &model_str);
        gp_list_get_value(camList, i, &port_str);

        cnt++;
    }

    gp_port_info_list_free(list);
    gp_abilities_list_free(abilList);

    if (cnt > 0)
    {
       if (cnt > 1)
       {
          qCWarning(DIGIKAM_IMPORTUI_LOG) << "More than one camera detected on port " << port
                                  << ". Due to restrictions in the GPhoto2 API, "
                                  << "only the first camera is used.";
       }

       model   = QString::fromLatin1(model_str);
       port    = QString::fromLatin1(port_str);
       success = true;
    }
    else
    {
       qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get information for the listed camera";
    }

    gp_list_free(camList);
    return success;
#else
    Q_UNUSED(vendorId);
    Q_UNUSED(productId);
    Q_UNUSED(model);
    Q_UNUSED(port);
    return false;
#endif /* HAVE_GPHOTO2 */
}
Exemple #20
0
GtkWidget *
gtkam_chooser_new (void)
{
	GtkamChooser *chooser;
	GtkWidget *table, *label, *button, *combo, *vbox, *hbox, *check, *expander;

	chooser = g_object_new (GTKAM_TYPE_CHOOSER, NULL);

	chooser->priv->tooltips = gtk_tooltips_new ();
	g_object_ref (G_OBJECT (chooser->priv->tooltips));
	gtk_object_sink (GTK_OBJECT (chooser->priv->tooltips));

	gp_abilities_list_new (&(chooser->priv->al));
	gp_abilities_list_load (chooser->priv->al, NULL);

	gp_port_info_list_new (&(chooser->priv->il));
	gp_port_info_list_load (chooser->priv->il);

	gtk_window_set_title (GTK_WINDOW (chooser), _("Add Camera"));
	gtk_container_set_border_width (GTK_CONTAINER (chooser), 5);

	vbox = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox);
	gtk_box_pack_start (GTK_BOX (GTKAM_DIALOG (chooser)->vbox),
			    vbox, FALSE, FALSE, 0);

	table = gtk_table_new (3, 3, FALSE);
	gtk_table_set_row_spacings (GTK_TABLE (table), 5);
	gtk_table_set_col_spacings (GTK_TABLE (table), 5);
	gtk_widget_show (table);
	gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
	chooser->priv->table = table;

	label = gtk_label_new (_("Model:"));
	gtk_widget_show (label);
	gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);

	combo = gtk_combo_new ();
	gtk_widget_show (combo);
	gtk_table_attach_defaults (GTK_TABLE (table), combo, 1, 2, 0, 1);
	chooser->priv->combo_model = GTK_COMBO (combo);
	chooser->priv->entry_model = GTK_ENTRY (GTK_COMBO (combo)->entry);
#if 0
	gtk_entry_set_editable (chooser->priv->entry_model, FALSE);
#endif
	button = gtk_button_new_with_label (_("Detect"));
	gtk_widget_show (button);
	gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 0, 1);
	g_signal_connect (GTK_OBJECT (button), "clicked",
			    GTK_SIGNAL_FUNC (on_detect_clicked), chooser);
	gtk_tooltips_set_tip (chooser->priv->tooltips, button,
			      _("Detect USB camera"), NULL);

	label = gtk_label_new (_("Port:"));
	gtk_widget_show (label);
	gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);

	combo = gtk_combo_new ();
	gtk_widget_show (combo);
	gtk_table_attach_defaults (GTK_TABLE (table), combo, 1, 3, 1, 2);
	gtk_widget_set_sensitive (combo, FALSE);
	chooser->priv->entry_port = GTK_ENTRY (GTK_COMBO (combo)->entry);
	chooser->priv->combo_port = GTK_COMBO (combo);
#if 0
	gtk_entry_set_editable (chooser->priv->entry_port, FALSE);
#endif

	button = gtk_button_new_from_stock (GTK_STOCK_ADD);
	gtk_widget_set_sensitive (button, FALSE);
	gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 1, 2);
	g_signal_connect (GTK_OBJECT (button), "clicked",
			    GTK_SIGNAL_FUNC (on_add_clicked), chooser);
	chooser->priv->button_add = button;

	label = gtk_label_new (_("Speed:"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
	chooser->priv->label_speed = label;

	combo = gtk_combo_new ();
	gtk_table_attach_defaults (GTK_TABLE (table), combo, 1, 3, 2, 3);
	gtk_widget_set_sensitive (combo, FALSE);
	chooser->priv->entry_speed = GTK_ENTRY (GTK_COMBO (combo)->entry);
	gtk_entry_set_text (chooser->priv->entry_speed, _("Best"));
	chooser->priv->combo_speed = GTK_COMBO (combo);
#if 0
	gtk_entry_set_editable (chooser->priv->entry_speed, FALSE);
#endif
	check = gtk_check_button_new_with_label (_("Allow multiple frontends"));
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), FALSE);
	gtk_table_attach_defaults (GTK_TABLE (table), check, 0, 2, 3, 4);
	g_signal_connect (GTK_OBJECT (check), "toggled",
			    GTK_SIGNAL_FUNC (on_multi_toggled), chooser);
	chooser->priv->check_multi = check;

	expander = gtk_expander_new (_("Enhanced"));
	gtk_widget_show (expander);
	gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 0);

	vbox = gtk_vbox_new (TRUE, 6);
	gtk_widget_show (vbox);
	gtk_container_add (GTK_CONTAINER (expander), vbox);

	hbox = gtk_hbox_new (FALSE, 6);
	gtk_widget_show (hbox);
	gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 6);

	label = gtk_label_new (_("Speed:"));
	gtk_widget_show (label);
	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 6);
	chooser->priv->label_speed = label;

	combo = gtk_combo_new ();
	gtk_widget_show (combo);
	gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 6);
	gtk_widget_set_sensitive (combo, FALSE);
	chooser->priv->entry_speed = GTK_ENTRY (GTK_COMBO (combo)->entry);
	gtk_entry_set_text (chooser->priv->entry_speed, _("Best"));
	chooser->priv->combo_speed = GTK_COMBO (combo);
#if 0
	gtk_entry_set_editable (chooser->priv->entry_speed, FALSE);
#endif

	check = gtk_check_button_new_with_label (_("Allow multiple frontends"));
	gtk_widget_show (check);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), FALSE);
	gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 6);
	g_signal_connect (GTK_OBJECT (check), "toggled",
			    GTK_SIGNAL_FUNC (on_multi_toggled), chooser);
	chooser->priv->check_multi = check;

	button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
	gtk_widget_show (button);
	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (chooser)->action_area),
			   button);
	g_signal_connect (GTK_OBJECT (button), "clicked",
			    GTK_SIGNAL_FUNC (on_cancel_clicked), chooser);

	chooser->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
	gtk_widget_show (chooser->apply_button);
	gtk_widget_set_sensitive (chooser->apply_button, FALSE);
	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (chooser)->action_area),
			   chooser->apply_button);
	g_signal_connect (GTK_OBJECT (chooser->apply_button), "clicked",
			    GTK_SIGNAL_FUNC (on_apply_clicked), chooser);

	button = gtk_button_new_from_stock (GTK_STOCK_OK);
	gtk_widget_show (button);
	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (chooser)->action_area),
			   button);
	g_signal_connect (GTK_OBJECT (button), "clicked",
			    GTK_SIGNAL_FUNC (on_ok_clicked), chooser);
	gtk_widget_grab_focus (button);
	chooser->priv->ok = button;

	/* Fill the model combo with all models */
	gtkam_chooser_set_camera_mask (chooser, GP_OPERATION_NONE);

	g_signal_connect (G_OBJECT (chooser->priv->entry_model), "changed",
			  G_CALLBACK (on_model_changed), chooser);
	g_signal_connect (G_OBJECT (chooser->priv->entry_port), "changed",
			  G_CALLBACK (on_port_changed), chooser);
	g_signal_connect (G_OBJECT (chooser->priv->entry_speed), "changed",
			  G_CALLBACK (on_speed_changed), chooser);

	gtkam_chooser_update_for_model (chooser);

	chooser->priv->needs_update = TRUE;
	gtk_widget_set_sensitive (chooser->apply_button, TRUE);

	return (GTK_WIDGET (chooser));
}
Exemple #21
0
/** 
 * Get list of supported cameras, walk through it, and try to see
 * if the provided USB product/vendor combination was specified.
 */
int
main (int argc, char *argv[])
{
    CameraAbilitiesList *al;
    int         i;
    int         count;
    const char *fmt_str = NULL;
    long        vendor_id, product_id;

    /* Parse the command line, looking for the USB ids */
    if( argc != 3 ) {
        fprintf(stderr, "Usage: %s [vendor_id] [product_id]\n", argv[0]);
        return 0;
    }

    vendor_id  = strtol(argv[1], NULL, 0);
    product_id = strtol(argv[2], NULL, 0);

    fprintf(stderr, "Read vendor 0x%04x product 0x%04x\n", vendor_id,
            product_id);

    if( !vendor_id || !product_id ) {
        fprintf(stderr, "Missing either the vendor or product id\n");
        return 0;
    }

    /*
    if (do_debug) {
        gettimeofday (&glob_tv_zero, NULL);
        CHECK (gp_log_add_func (GP_LOG_ALL, debug_func, NULL));
        
        gp_log (GP_LOG_DEBUG, "main", "test-camera-list start");
    }
    */


    CHECK (gp_abilities_list_new (&al));
    CHECK (gp_abilities_list_load (al, NULL));

    count = gp_abilities_list_count (al);
    if (count < 0) {
        printf("gp_abilities_list_count error: %d\n", count);
        return(0);
    }
    else if (count == 0) {
        /* Copied from gphoto2-abilities-list.c gp_abilities_list_load() */
        const char *camlib_env = getenv(CAMLIBDIR_ENV);
        const char *camlibs = (camlib_env != NULL)?camlib_env:CAMLIBS;

        printf("no camera drivers (camlibs) found in camlib dir:\n"
               "    CAMLIBS='%s', default='%s', used=%s\n",
               camlib_env?camlib_env:"(null)", CAMLIBS,
               (camlib_env!=NULL)?"CAMLIBS":"default");
        return(0);
    }


    /* For each camera in the list, add a text snippet to the 
     * output file. */
    fprintf(stderr, "Examining %d entries for 0x%04x:0x%04x\n",
            count, vendor_id, product_id);
    for (i = 0; i < count; i++) {
        CameraAbilities abilities;
        const char *camlib_basename;
        CHECK (gp_abilities_list_get_abilities (al, i, &abilities));
        camlib_basename = basename(abilities.library);

        if( abilities.usb_vendor  == vendor_id
         && abilities.usb_product == product_id ) {
            fprintf(stderr, "Found camera model \"%s\"\n", abilities.model);
            return 1;
        }
        /*
        printf(fmt_str,
               i+1, 
               camlib_basename,
               abilities.id,
               abilities.usb_vendor,
               abilities.usb_product,
               abilities.model
               );
        */
    }

    CHECK (gp_abilities_list_free (al));
    return (0);
}
Exemple #22
0
int input_run(int id)
{
	int res, i;

	global->in[id].buf = malloc(256 * 1024);
	if(global->in[id].buf == NULL)
	{
		IPRINT(INPUT_PLUGIN_NAME " - could not allocate memory\n");
		exit(EXIT_FAILURE);
	}
	plugin_id = id;

	// auto-detect algorithm
	CameraAbilitiesList* al;
	GPPortInfoList* il;
	CameraList* list;
	const char* model;
	const char* port;
	context = gp_context_new();
	gp_abilities_list_new(&al);
	gp_abilities_list_load(al, context);
	gp_port_info_list_new(&il);
	gp_port_info_list_load(il);
	gp_list_new(&list);
	gp_abilities_list_detect(al, il, list, context);
	int count = gp_list_count(list);
	IPRINT(INPUT_PLUGIN_NAME " - Detected %d camera(s)\n", count);
	if(count == 0)
	{
		IPRINT(INPUT_PLUGIN_NAME " - No cameras detected.\n");
		return 0;
	}
	GPPortInfo info;
	CameraAbilities a;
	int m, p;
	camera = NULL;
	for(i = 0; i < count; i++)
	{
		res = gp_list_get_name(list, i, &model);
		CAMERA_CHECK_GP(res, "gp_list_get_name");
		m = gp_abilities_list_lookup_model(al, model);
		if(m < 0)
		{
			IPRINT(INPUT_PLUGIN_NAME " - Gphoto abilities_list_lookup_model Code: %d - %s\n", m, gp_result_as_string(m));
			return 0;
		}
		res = gp_abilities_list_get_abilities(al, m, &a);
		CAMERA_CHECK_GP(res, "gp_abilities_list_get_abilities");
		res = gp_list_get_value(list, i, &port);
		CAMERA_CHECK_GP(res, "gp_list_get_value"); DBG("Model: %s; port: %s.\n", model, port);
		if(selected_port != NULL && strcmp(selected_port, port) != 0)
			continue;
		p = gp_port_info_list_lookup_path(il, port);
		if(p < 0)
		{
			IPRINT(INPUT_PLUGIN_NAME " - Gphoto port_info_list_lookup_path Code: %d - %s\n", m, gp_result_as_string(m));
			return 0;
		}
		res = gp_port_info_list_get_info(il, p, &info);
		CAMERA_CHECK_GP(res, "gp_port_info_list_get_info");

		res = gp_camera_new(&camera);
		CAMERA_CHECK_GP(res, "gp_camera_new");
		res = gp_camera_set_abilities(camera, a);
		CAMERA_CHECK_GP(res, "gp_camera_set_abilities");
		res = gp_camera_set_port_info(camera, info);
		CAMERA_CHECK_GP(res, "gp_camera_set_port_info");
	}
	if(camera == NULL)
	{
		IPRINT("Camera %s not found, exiting.\n", selected_port);
		exit(EXIT_FAILURE);
	}
	// cleanup
	gp_list_unref(list);
	gp_port_info_list_free(il);
	gp_abilities_list_free(al);

	// open camera and set capture on
	int value = 1;
	res = gp_camera_init(camera, context);
	CAMERA_CHECK_GP(res, "gp_camera_init");
	camera_set("capture", &value);

	// starting thread
	if(pthread_create(&thread, 0, capture, NULL) != 0)
	{
		free(global->in[id].buf);
		IPRINT("could not start worker thread\n");
		exit(EXIT_FAILURE);
	}
	pthread_detach(thread);

	return 0;
}
Exemple #23
0
int GPCamera::autoDetect(QString& model, QString& port)
{
#ifdef HAVE_GPHOTO2
    CameraList*          camList   = 0;
    CameraAbilitiesList* abilList  = 0;
    GPPortInfoList*      infoList  = 0;
    const char*          camModel_ = 0, *camPort_ = 0;
    GPContext*           context   = 0;
    context                        = gp_context_new();

    gp_list_new(&camList);

    gp_abilities_list_new(&abilList);
    gp_abilities_list_load(abilList, context);
    gp_port_info_list_new(&infoList);
    gp_port_info_list_load(infoList);
    gp_abilities_list_detect(abilList, infoList, camList, context);
    gp_abilities_list_free(abilList);
    gp_port_info_list_free(infoList);

    gp_context_unref(context);

    int count = gp_list_count(camList);

    if (count <= 0)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
        printGphotoErrorDescription(count);
        gp_list_free(camList);
        return -1;
    }

    camModel_ = 0;
    camPort_  = 0;

    for (int i = 0; i < count; i++)
    {
        if (gp_list_get_name(camList, i, &camModel_) != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
            gp_list_free(camList);
            return -1;
        }

        if (gp_list_get_value(camList, i, &camPort_) != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
            gp_list_free(camList);
            return -1;
        }

        if (camModel_ && camPort_)
        {
            model = QString::fromLatin1(camModel_);
            port  = QString::fromLatin1(camPort_);
            gp_list_free(camList);
            return 0;
        }
    }

    qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
    gp_list_free(camList);
#else
    Q_UNUSED(model);
    Q_UNUSED(port);
#endif /* HAVE_GPHOTO2 */
    return -1;
}
/** 
 * Get list of supported cameras, walk through it and create some output.
 */
int
main (int argc, char *argv[])
{
	CameraAbilitiesList *al;
	int i;
	int count;
	const char *fmt_str = NULL;

	parse_command_line (argc, argv);

	if (do_debug) {
		gettimeofday (&glob_tv_zero, NULL);
		CHECK (gp_log_add_func (GP_LOG_ALL, debug_func, NULL));
		
		gp_log (GP_LOG_DEBUG, "main", "test-camera-list start");
	}


	CHECK (gp_abilities_list_new (&al));
	CHECK (gp_abilities_list_load (al, NULL));

	count = gp_abilities_list_count (al);
	if (count < 0) {
		printf("gp_abilities_list_count error: %d\n", count);
		return(1);
	} else if (count == 0) {
		/* Copied from gphoto2-abilities-list.c gp_abilities_list_load() */
		const char *camlib_env = getenv(CAMLIBDIR_ENV);
		const char *camlibs = (camlib_env != NULL)?camlib_env:CAMLIBS;

		printf("no camera drivers (camlibs) found in camlib dir:\n"
		       "    CAMLIBS='%s', default='%s', used=%s\n",
		       camlib_env?camlib_env:"(null)", CAMLIBS,
		       (camlib_env!=NULL)?"CAMLIBS":"default");
		return(1);
	}


	/* Set output format for file body, 
	 * and print opening part of output file. */
	switch (format) {
	case FMT_CSV:
		fmt_str = "%d,%s,%s,%s\n";
		break;
	case FMT_FLAT_TEXT:
		fmt_str = "%3d|%-20s|%-20s|%s\n";
		break;
	case FMT_HEADED_TEXT:
		fmt_str = "%3d|%-20s|%-20s|%s\n";
		break;
	case FMT_XML:
		fmt_str = "  <camera name=\"%4$s\" entry_number=\"%1$d\">\n"
			"    <camlib-name value=\"%2$s\"/>\n"
			"    <driver-name value=\"%3$s\"/>\n"
			"  </camera>\n";
		printf("<?xml version=\"%s\" encoding=\"%s\"?>\n"
		       "<camera-list camera-count=\"%d\">\n", 
		       "1.0", "us-ascii", count);
		break;
	case FMT_FLAT_CAMLIBS:
		fmt_str = "%2$-28s  %3$s\n";
		break;
	case FMT_COUNT:
		printf("%d\n", count);
		return(0);
		break;
	}

	/* For each camera in the list, add a text snippet to the 
	 * output file. */
	for (i = 0; i < count; i++) {
		CameraAbilities abilities;
		const char *camlib_basename;
		CHECK (gp_abilities_list_get_abilities (al, i, &abilities));
		camlib_basename = path_basename(abilities.library);

		switch (format) {
		case FMT_HEADED_TEXT:
			if ( ((i%25)== 0) && 
			     ( (i==0) || ((count-i) > 5) ) ) {
				print_hline();
				print_headline();
				print_hline();
			}
			break;
		case FMT_FLAT_CAMLIBS:
			break;
		case FMT_XML:
			break;
		case FMT_CSV:
			break;
		case FMT_FLAT_TEXT:
			break;
		case FMT_COUNT:
			break;
		}

		printf(fmt_str,
		       i+1, 
		       camlib_basename,
		       abilities.id,
		       abilities.model);
	}

	/* Print closing part of output file. */
	switch (format) {
	case FMT_HEADED_TEXT:
		print_hline();
		print_headline();
		print_hline();
		break;
	case FMT_FLAT_CAMLIBS:
		break;
	case FMT_XML:
		printf("</camera-list>\n");
		break;
	case FMT_CSV:
		break;
	case FMT_FLAT_TEXT:
		break;
	case FMT_COUNT:
		break;
	}
	
	CHECK (gp_abilities_list_free (al));
	return (0);
}