コード例 #1
0
ファイル: gpcamera.cpp プロジェクト: Match-Yang/digikam
bool GPCamera::getFolders(const QString& folder)
{
#ifdef HAVE_GPHOTO2
    int         errorCode;
    CameraList* clist = 0;
    gp_list_new(&clist);

    d->status->cancel = false;
    errorCode         = gp_camera_folder_list_folders(d->camera, QFile::encodeName(folder).constData(), clist, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folders list from camera!";
        printGphotoErrorDescription(errorCode);
        gp_list_unref(clist);
        return false;
    }

    QStringList subFolderList;
    int count = gp_list_count(clist);

    if (count < 1)
    {
        return true;
    }

    for (int i = 0 ; i < count ; ++i)
    {
        const char* subFolder = 0;
        errorCode             = gp_list_get_name(clist, i, &subFolder);

        if (errorCode != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folder name from camera!";
            printGphotoErrorDescription(errorCode);
            gp_list_unref(clist);
            return false;
        }

        subFolderList.append(folder + QFile::decodeName(subFolder) + QLatin1Char('/'));
    }

    gp_list_unref(clist);

    emit signalFolderList(subFolderList);

    return true;
#else
    Q_UNUSED(folder);
    return false;
#endif /* HAVE_GPHOTO2 */
}
コード例 #2
0
ファイル: gpcamera.cpp プロジェクト: Match-Yang/digikam
bool GPCamera::getItemsInfoList(const QString& folder, bool useMetadata, CamItemInfoList& items)
{
#ifdef HAVE_GPHOTO2
    int         errorCode;
    CameraList* clist = 0;
    const char* cname = 0;

    gp_list_new(&clist);

    d->status->cancel = false;
    errorCode         = gp_camera_folder_list_files(d->camera, QFile::encodeName(folder).constData(), clist, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folder files list from camera!";
        printGphotoErrorDescription(errorCode);
        gp_list_unref(clist);
        return false;
    }

    int count = gp_list_count(clist);

    for (int i = 0 ; i < count ; ++i)
    {
        errorCode = gp_list_get_name(clist, i, &cname);

        if (errorCode != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get file name from camera!";
            printGphotoErrorDescription(errorCode);
            gp_list_unref(clist);
            return false;
        }

        // TODO for further speed-up, getItemInfoInternal call could be called separately when needed
        CamItemInfo info;
        getItemInfoInternal(folder, QFile::decodeName(cname), info, useMetadata);
        items.append(info);
    }

    gp_list_unref(clist);

    return true;
#else
    Q_UNUSED(folder);
    Q_UNUSED(useMetadata);
    Q_UNUSED(items);
    return false;
#endif /* HAVE_GPHOTO2 */
}
コード例 #3
0
ファイル: gpcamera.cpp プロジェクト: Match-Yang/digikam
// TODO unused, remove?
bool GPCamera::getItemsList(const QString& folder, QStringList& itemsList)
{
#ifdef HAVE_GPHOTO2
    int         errorCode;
    CameraList* clist = 0;
    const char* cname = 0;

    gp_list_new(&clist);

    d->status->cancel = false;
    errorCode         = gp_camera_folder_list_files(d->camera, QFile::encodeName(folder).constData(), clist, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folder files list from camera!";
        printGphotoErrorDescription(errorCode);
        gp_list_unref(clist);
        return false;
    }

    int count = gp_list_count(clist);

    for (int i = 0 ; i < count ; ++i)
    {
        errorCode = gp_list_get_name(clist, i, &cname);

        if (errorCode != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get file name from camera!";
            printGphotoErrorDescription(errorCode);
            gp_list_unref(clist);
            return false;
        }

        itemsList.append(QFile::decodeName(cname));
    }

    gp_list_unref(clist);

    return true;
#else
    Q_UNUSED(folder);
    Q_UNUSED(itemsList);
    return false;
#endif /* HAVE_GPHOTO2 */
}
コード例 #4
0
ファイル: cap_gphoto2.cpp プロジェクト: Aspie96/opencv
/**
 * 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);
    }
}
コード例 #5
0
ファイル: gtkam-chooser.c プロジェクト: gphoto/gtkam
static void
on_detect_clicked (GtkButton *button, GtkamChooser *chooser)
{
	GtkWidget *d, *status;
	CameraList *list;
	int result;
	const char *name;

	status = gtkam_status_new (_("Detecting cameras..."));
	gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status);
	gp_list_new (&list);
	result = gp_abilities_list_detect (chooser->priv->al,
		chooser->priv->il, list,
		GTKAM_STATUS (status)->context->context);
	switch (result) {
	case GP_OK:
		if (!gp_list_count (list)) {
			d = gtkam_close_new (_("No cameras detected."));
			gtk_window_set_transient_for (GTK_WINDOW (d),
						      GTK_WINDOW (chooser));
			gtk_widget_show (d);
		} else {
			/* FIXME: Let user choose from the list */
			gp_list_get_name (list, 0, &name);
			gtk_entry_set_text (chooser->priv->entry_model, name);
			gtk_entry_set_text (chooser->priv->entry_port,
					"Universal Serial Bus (usb:)");
		}
		break;
	case GP_ERROR_CANCEL:
		break;
	default:
		d = gtkam_error_new (result,
			GTKAM_STATUS (status)->context, GTK_WIDGET (chooser),
			_("Could not detect any cameras."));
		gtk_widget_show (d);
		break;
	}
	gp_list_unref (list);
	gtk_object_destroy (GTK_OBJECT (status));
}
コード例 #6
0
bool photoController::checkCameraDetection()
{
	START_CHRONOMETER();
	CameraList *list;
	gp_list_new (&list);
	int ret = auto_detect_action(list, context);
	DEBUG_PRINTF(V_MESSAGE, "gp_camera_autodetect return %d wanted %d\n", ret, GP_OK);
	if(ret >= GP_OK)
	{
		int cameraCount = gp_list_count(list);
		DEBUG_PRINTF(V_MESSAGE, "Camera count: %d\n", cameraCount);
		if(cameraCount > 0)
		{
			DEBUG_PRINTF(V_MESSAGE, "Got a camera\n");
			camera_detected = true;
			if(!camera && !initCamera())
			{
				camera = NULL;
			}
		}
	}
	else
	{
		if(camera)
		{
			DEBUG_PRINTF(V_MESSAGE, "Exit camera\n");
			gp_camera_exit(camera, context);
			camera = NULL;
		}
		camera_detected = false;
		DEBUG_PRINTF(V_MESSAGE, "Error while getting camera list\n");
	}
	
	gp_list_unref (list);
	STOP_CHRONOMETER("Camera detection");
	return camera_detected;
}
コード例 #7
0
ファイル: input_ptp2.c プロジェクト: 0x1abin/mjpg-streamer
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;
}
コード例 #8
0
photo_camera_list::~photo_camera_list( void )
{
  gp_list_unref( camera_list_ ); //delete camera_list_;
  gp_port_info_list_free( port_info_list_ ); //delete port_info_list_;
  gp_abilities_list_free( abilities_list_ );  //delete abilities_list_;
}