Beispiel #1
0
void IPTCEditWidget::apply()
{
    if (d->modified && !d->isReadOnly)
    {
        d->contentPage->applyMetadata(d->exifData, d->iptcData);
        d->originPage->applyMetadata(d->exifData, d->iptcData);
        d->creditsPage->applyMetadata(d->iptcData);
        d->subjectsPage->applyMetadata(d->iptcData);
        d->keywordsPage->applyMetadata(d->iptcData);
        d->categoriesPage->applyMetadata(d->iptcData);
        d->statusPage->applyMetadata(d->iptcData);
        d->propertiesPage->applyMetadata(d->iptcData);
        d->envelopePage->applyMetadata(d->iptcData);

        DMetadata meta;

        meta.load((*d->dlg->currentItem()).path());
        meta.setExif(d->exifData);
        meta.setIptc(d->iptcData);
        meta.save((*d->dlg->currentItem()).path());
        d->modified = false;
    }
}
Beispiel #2
0
bool GPCamera::getMetadata(const QString& folder, const QString& itemName, DMetadata& meta)
{
#ifdef HAVE_GPHOTO2
    int               errorCode;
    CameraFile*       cfile = 0;
    const char*       data  = 0;
    unsigned long int size;

    gp_file_new(&cfile);

    d->status->cancel = false;
    errorCode         = gp_camera_file_get(d->camera, QFile::encodeName(folder).constData(),
                                           QFile::encodeName(itemName).constData(),
                                           GP_FILE_TYPE_EXIF,
                                           cfile, d->status->context);

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

    errorCode = gp_file_get_data_and_size(cfile, &data, &size);

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

    QByteArray exifData(data, size);

    gp_file_unref(cfile);

    // Sometimes, GPhoto2 drivers return complete APP1 JFIF section. Exiv2 cannot
    // decode (yet) exif metadata from APP1. We will find Exif header to get data at this place
    // to please with Exiv2...

    qCDebug(DIGIKAM_IMPORTUI_LOG) << "Size of Exif metadata from camera = " << exifData.size();

    if (!exifData.isEmpty())
    {
        char exifHeader[] = { 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 };
        int i             = exifData.indexOf(*exifHeader);

        if (i != -1)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Exif header found at position " << i;
            i = i + sizeof(exifHeader);
            QByteArray data;
            data.resize(exifData.size() - i);
            memcpy(data.data(), exifData.data() + i, data.size());
            meta.setExif(data);
            return true;
        }
    }

    return false;
#else
    Q_UNUSED(folder);
    Q_UNUSED(itemName);
    Q_UNUSED(meta);
    return false;
#endif /* HAVE_GPHOTO2 */
}