Exemple #1
0
    ~GPStatus()
    {
#ifdef HAVE_GPHOTO2
        gp_context_unref(context);
        cancel = false;
#endif /* HAVE_GPHOTO2 */
    }
Exemple #2
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 */
}
Exemple #3
0
void
GPhotoContext::cleanup()
{
    if( camera_ )
    {
        gp_camera_free( camera_ );
        camera_ = NULL;
    }
    if( context_ )
    {
        gp_context_unref( context_ );
        context_ = NULL;
    }
    if( portinfoList_ )
    {
        gp_port_info_list_free( portinfoList_ );
        portinfoList_ = NULL;
    }
    if( abilitiesList_ )
    {
        gp_abilities_list_free( abilitiesList_ );
        abilitiesList_ = NULL;
    }
    if( cameras_ )
    {
        gp_list_free( cameras_ );
        cameras_ = NULL;
    }
}
Exemple #4
0
Camera::~Camera() {
    std::lock_guard<std::mutex> g(mutex);
	gp_context_unref(ctx->context);
	
	if (camera)
		gp_camera_unref(camera); // XXX: freeing also exits it, i guess
}
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 #6
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 #7
0
void cleanup(void *arg)
{
	int value = 0;

	// TODO check to see if we have already cleaned up?

	IPRINT("PTP2 capture - Cleaning up\n");
	camera_set("capture", &value);
	gp_camera_exit(camera, context);
	gp_camera_unref(camera);
	gp_context_unref(context);
	free(global->in[plugin_id].buf);
}
Exemple #8
0
/**
 * Always close connection to the device.
 */
DigitalCameraCapture::~DigitalCameraCapture()
{
    close();
    try
    {
        CR(gp_abilities_list_free(abilitiesList));
        abilitiesList = NULL;
        CR(gp_port_info_list_free(capablePorts));
        capablePorts = NULL;
        CR(gp_list_unref(allDevices));
        allDevices = NULL;
        gp_context_unref(context);
        context = NULL;
    }
    catch (GPhoto2Exception & e)
    {
        message(ERROR, "destruction error", e);
    }
}
Exemple #9
0
GPCamera::~GPCamera()
{
#ifdef HAVE_GPHOTO2
    if (d->status)
    {
        gp_context_unref(d->status->context);
        d->status = 0;
    }

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

#endif /* HAVE_GPHOTO2 */

    delete d;
}
int main(int argc, char **argv) {
	Camera		*camera;
	int		ret;
	char		*owner;
	GPContext	*context;
	CameraText	text;

	context = sample_create_context (); /* see context.c */
	gp_camera_new (&camera);

	/* This call will autodetect cameras, take the
	 * first one from the list and use it. It will ignore
	 * any others... See the *multi* examples on how to
	 * detect and use more than the first one.
	 */
	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		printf("No camera auto detected.\n");
		gp_camera_free (camera);
		return 0;
	}

	/* Simple query the camera summary text */
	ret = gp_camera_get_summary (camera, &text, context);
	if (ret < GP_OK) {
		printf("Camera failed retrieving summary.\n");
		gp_camera_free (camera);
		return 0;
	}
	printf("Summary:\n%s\n", text.text);

	/* Simple query of a string configuration variable. */
	ret = get_config_value_string (camera, "owner", &owner, context);
	if (ret >= GP_OK) {
		printf("Owner: %s\n", owner);
		free (owner);
	}
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	gp_context_unref (context);
	return 0;
}
Exemple #11
0
void
gp_params_exit (GPParams *p)
{
	if (!p)
		return;

	if (p->_abilities_list)
		gp_abilities_list_free (p->_abilities_list);
	if (p->camera)
		gp_camera_unref (p->camera);
	if (p->folder)
		free (p->folder);
	if (p->filename)
		free (p->filename);
	if (p->context)
		gp_context_unref (p->context);
	if (p->hook_script)
		free (p->hook_script);
	if (p->portinfo_list)
		gp_port_info_list_free (p->portinfo_list);
	memset (p, 0, sizeof (GPParams));
}
Exemple #12
0
int
main ()
{
	CameraFilesystem *fs;
	CameraFileInfo info;
	CameraList *list;
	int x, count;
	const char *name;
	char *foldername;
	GPContext *context;

#ifdef HAVE_MCHECK_H
	mtrace();
#endif

	CHECK (gp_list_new(&list));

	gp_log_add_func (GP_LOG_DEBUG, log_func, NULL);
	context = gp_context_new ();
	gp_context_set_error_func (context, error_func, NULL);

	printf ("*** Creating file system...\n");
	CHECK (gp_filesystem_new (&fs));

	printf ("*** Setting the callbacks...\n");
	CHECK (gp_filesystem_set_funcs (fs, &fsfuncs, NULL));

	printf ("*** Adding a file...\n");
	CHECK (gp_filesystem_append (fs, "/", "my.file", context));

	gp_filesystem_dump (fs);

	printf ("*** Removing this file...\n");
	CHECK (gp_filesystem_delete_file (fs, "/", "my.file", context));

	gp_filesystem_dump (fs);

	printf ("*** Resetting...\n");
	CHECK (gp_filesystem_reset (fs));

	gp_filesystem_dump (fs);

	printf ("*** Adding /...\n");
	CHECK (gp_filesystem_append (fs, "/", NULL, context));

	printf ("*** Adding /whatever ...\n");
	CHECK (gp_filesystem_append (fs, "/whatever", NULL, context));

	printf ("*** Adding /whatever/dir...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/dir", NULL, context));

	printf ("*** Adding /whatever/dir/file1...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file1", context));

	gp_filesystem_dump (fs);

	printf ("*** Adding /whatever/dir/file2...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file2", context));
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file3", context));
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file4", context));
	CHECK (gp_filesystem_append (fs, "/whatever/dir", "file5", context));

	gp_filesystem_dump (fs);

	printf ("*** Deleting everything below root...\n");
	CHECK (gp_filesystem_delete_all (fs, "/", context));

	gp_filesystem_dump (fs);

	printf ("*** Appending root directory...\n");
	CHECK (gp_filesystem_append (fs, "/", NULL, context));

	printf ("*** Appending some directories...\n");
	CHECK (gp_filesystem_append (fs, "/whatever", NULL, context));
	CHECK (gp_filesystem_append (fs, "/whatever/directory", NULL, context));

	printf ("*** Adding some files...\n");
	CHECK (gp_filesystem_append (fs, "/whatever/directory",
				     "some.file", context));
	CHECK (gp_filesystem_append (fs, "/whatever/directory",
				     "some.file2", context));
	CHECK (gp_filesystem_append (fs, "/another/directory",
				     "another.file", context));

	gp_filesystem_dump (fs);

	printf ("*** Getting info about a file...\n");
	CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file",
				       &info, context));

	printf ("*** Getting info again (cache!)...\n");
	CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file",
				       &info, context));

	printf ("*** Set info about another file...\n");
	CHECK (gp_filesystem_set_info (fs, "/whatever/directory", "some.file2",
				       info, context));

	printf ("*** Getting info about this file (cache!)...\n");
	CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file2",
				       &info, context));

	printf ("*** Deleting a file...\n");
	CHECK (gp_filesystem_delete_file (fs, "/whatever/directory",
					  "some.file2", context));

	gp_filesystem_dump (fs);

	printf ("*** Resetting the filesystem...\n");
	CHECK (gp_filesystem_reset (fs));

	gp_filesystem_dump (fs);

	printf ("*** Getting file list for folder '/whatever/directory'...\n");
	CHECK (gp_filesystem_list_folders (fs, "/whatever/directory",
					   list, context));

	printf ("*** Getting file list for folder '/whatever/directory' "
		"again (cached!)...\n");
	CHECK (gp_filesystem_list_folders (fs, "/whatever/directory",
					   list, context));

	printf ("*** Counting the contents...\n");
	CHECK (count = gp_list_count (list));

	printf ("*** Listing the contents...\n");
	for (x = 0; x < count; x++) {
		CHECK (gp_list_get_name (list, x, &name));
		printf (" %i: '%s'\n", x, name);
	}

	printf ("*** Getting folder of 'file1'...\n");
	CHECK (gp_filesystem_get_folder (fs, "file1", &foldername, context));
	printf ("... found in '%s'.\n", foldername);
	free(foldername);

	printf ("*** Deleting a couple of files...\n");
	CHECK (gp_filesystem_delete_file (fs, "/whatever", "file5", context));
	CHECK (gp_filesystem_delete_file (fs, "/whatever", "file4", context));
	CHECK (gp_filesystem_delete_file (fs, "/whatever", "file3", context));

	gp_filesystem_dump (fs);

	printf ("*** Freeing file system...\n");
	CHECK (gp_filesystem_free (fs));

	gp_context_unref (context);

	CHECK (gp_list_free(list));

#ifdef HAVE_MCHECK_H
	muntrace();
#endif

	return (0);
}
Exemple #13
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 #14
0
Context::~Context() {
	gp_context_unref(context);
}
Exemple #15
0
photo_camera::~photo_camera( void )
{
  gp_camera_unref( camera_ ); //delete camera_;
  gp_context_unref( context_ ); //delete context_;
}
GPhotoCameraWorker::~GPhotoCameraWorker()
{
    closeCamera();
    gp_port_info_list_free(m_portInfo.portInfoList);
    gp_context_unref(m_context);
}
Exemple #17
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;
}