Ejemplo n.º 1
0
static int
camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
{
	int r;

	r = gp_file_open (file, "/usr/share/pixmaps/gnome-logo-large.png");
	if (r < 0)
		return (r);
	
	return (GP_OK);
}
Ejemplo n.º 2
0
bool GPCamera::uploadItem(const QString& folder, const QString& itemName, const QString& localFile, CamItemInfo& itemInfo)
{
#ifdef HAVE_GPHOTO2
    int         errorCode;
    CameraFile* cfile = 0;
    errorCode         = gp_file_new(&cfile);
    d->status->cancel = false;

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to init new camera file instance!";
        printGphotoErrorDescription(errorCode);
        return false;
    }

    errorCode = gp_file_open(cfile, QFile::encodeName(localFile).constData());

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to open file!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    errorCode = gp_file_set_name(cfile, QFile::encodeName(itemName).constData());

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to rename item from camera!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

#ifdef HAVE_GPHOTO25
    errorCode = gp_camera_folder_put_file(d->camera,
                                          QFile::encodeName(folder).constData(),
                                          QFile::encodeName(itemName).constData(),
                                          GP_FILE_TYPE_NORMAL,
                                          cfile,
                                          d->status->context);
#else
    errorCode = gp_camera_folder_put_file(d->camera,
                                          QFile::encodeName(folder).constData(),
                                          cfile,
                                          d->status->context);
#endif

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to upload item to camera!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    // Get new camera item information.

    itemInfo.name   = itemName;
    itemInfo.folder = folder;

    CameraFileInfo info;
    errorCode       = gp_camera_file_get_info(d->camera, QFile::encodeName(folder).constData(),
                                              QFile::encodeName(itemName).constData(), &info, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get camera item information!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    itemInfo.ctime            = QDateTime();
    itemInfo.mime             = QString();
    itemInfo.size             = -1;
    itemInfo.width            = -1;
    itemInfo.height           = -1;
    itemInfo.downloaded       = CamItemInfo::DownloadUnknown;
    itemInfo.readPermissions  = -1;
    itemInfo.writePermissions = -1;

    /* The mime type returned by Gphoto2 is dummy with all RAW files.
    if (info.file.fields & GP_FILE_INFO_TYPE)
        itemInfo.mime = info.file.type;
    */

    itemInfo.mime = mimeType(itemInfo.name.section(QLatin1Char('.'), -1).toLower());

    if (info.file.fields & GP_FILE_INFO_MTIME)
    {
        itemInfo.ctime = QDateTime::fromTime_t(info.file.mtime);
    }

    if (info.file.fields & GP_FILE_INFO_SIZE)
    {
        itemInfo.size = info.file.size;
    }

    if (info.file.fields & GP_FILE_INFO_WIDTH)
    {
        itemInfo.width = info.file.width;
    }

    if (info.file.fields & GP_FILE_INFO_HEIGHT)
    {
        itemInfo.height = info.file.height;
    }

    if (info.file.fields & GP_FILE_INFO_STATUS)
    {
        if (info.file.status == GP_FILE_STATUS_DOWNLOADED)
        {
            itemInfo.downloaded = CamItemInfo::DownloadedYes;
        }
        else
        {
            itemInfo.downloaded = CamItemInfo::DownloadedNo;
        }
    }

    if (info.file.fields & GP_FILE_INFO_PERMISSIONS)
    {
        if (info.file.permissions & GP_FILE_PERM_READ)
        {
            itemInfo.readPermissions = 1;
        }
        else
        {
            itemInfo.readPermissions = 0;
        }

        if (info.file.permissions & GP_FILE_PERM_DELETE)
        {
            itemInfo.writePermissions = 1;
        }
        else
        {
            itemInfo.writePermissions = 0;
        }
    }

    gp_file_unref(cfile);
    return true;
#else
    Q_UNUSED(folder);
    Q_UNUSED(itemName);
    Q_UNUSED(localFile);
    Q_UNUSED(itemInfo);
    return false;
#endif /* HAVE_GPHOTO2 */
}