void CommentReadWriteTest::testSimpleReadAfterWrite() { DMetadata dmeta; CaptionsMap result; // Trick dmetadata, so it will think that we have a file path dmeta.setFilePath(QLatin1String("random.org")); dmeta.setItemComments(commentSet1); result = dmeta.getItemComments(); QString rezAuthor = result.value(QLatin1String("x-default")).author; QString rezComment = result.value(QLatin1String("x-default")).caption; QCOMPARE(rezAuthor, commentSet1.value(QLatin1String("x-default")).author); QCOMPARE(rezComment, commentSet1.value(QLatin1String("x-default")).caption); }
void CommentReadWriteTest::testReadFromDisabledNamespaces() { DMetadata dmeta; dmeta.setFilePath(QLatin1String("random.org")); CaptionsMap rez; DMetadataSettingsContainer dmsettings; NamespaceEntry commNs1; commNs1.namespaceName = QLatin1String("Xmp.dc.description"); commNs1.nsType = NamespaceEntry::COMMENT; commNs1.specialOpts = NamespaceEntry::COMMENT_ATLLANGLIST; commNs1.index = 0; commNs1.subspace = NamespaceEntry::XMP; commNs1.isDisabled = true; NamespaceEntry commNs2; commNs2.namespaceName = QLatin1String("Xmp.exif.UserComment"); commNs2.nsType = NamespaceEntry::COMMENT; commNs2.specialOpts = NamespaceEntry::COMMENT_ALTLANG; commNs2.index = 1; commNs2.subspace = NamespaceEntry::XMP; dmsettings.setUnifyReadWrite(false); dmsettings.getReadMapping(QString::fromUtf8(DM_COMMENT_CONTAINER)).clear(); dmsettings.getReadMapping(QString::fromUtf8(DM_COMMENT_CONTAINER)) << commNs1 << commNs2; dmeta.setXmpTagStringListLangAlt("Xmp.dc.description", commentSet1.toAltLangMap()); dmeta.setXmpTagStringLangAlt("Xmp.exif.UserComment", commentSet2.value(QLatin1String("x-default")).caption, QString()); rez = dmeta.getItemComments(dmsettings); QCOMPARE(rez.value(QLatin1String("x-default")).caption, commentSet2.value(QLatin1String("x-default")).caption); }
void ImagePropertiesSideBar::setImagePropertiesInformation(const QUrl& url) { if (!url.isValid()) { return; } QString str; QString unavailable(i18n("<i>unavailable</i>")); QFileInfo fileInfo(url.toLocalFile()); DMetadata metaData(url.toLocalFile()); // -- File system information ----------------------------------------- QDateTime modifiedDate = fileInfo.lastModified(); str = QLocale().toString(modifiedDate, QLocale::ShortFormat); m_propertiesTab->setFileModifiedDate(str); str = QString::fromUtf8("%1 (%2)").arg(ImagePropertiesTab::humanReadableBytesCount(fileInfo.size())) .arg(QLocale().toString(fileInfo.size())); m_propertiesTab->setFileSize(str); m_propertiesTab->setFileOwner(QString::fromUtf8("%1 - %2").arg(fileInfo.owner()).arg(fileInfo.group())); m_propertiesTab->setFilePermissions(ImagePropertiesTab::permissionsString(fileInfo)); // -- Image Properties -------------------------------------------------- QSize dims; QString bitDepth, colorMode; QString rawFilesExt = QLatin1String(RawEngine::DRawDecoder::rawFiles()); QString ext = fileInfo.suffix().toUpper(); if (!ext.isEmpty() && rawFilesExt.toUpper().contains(ext)) { m_propertiesTab->setImageMime(i18n("RAW Image")); bitDepth = QLatin1String("48"); dims = metaData.getImageDimensions(); colorMode = i18n("Uncalibrated"); } else { m_propertiesTab->setImageMime(QMimeDatabase().mimeTypeForFile(fileInfo).comment()); dims = metaData.getPixelSize(); DImg img; img.loadImageInfo(url.toLocalFile(), false, false, false, false); bitDepth.number(img.originalBitDepth()); colorMode = DImg::colorModelToString(img.originalColorModel()); } QString mpixels; mpixels.setNum(dims.width()*dims.height()/1000000.0, 'f', 2); str = (!dims.isValid()) ? i18n("Unknown") : i18n("%1x%2 (%3Mpx)", dims.width(), dims.height(), mpixels); m_propertiesTab->setImageDimensions(str); if (!dims.isValid()) str = i18n("Unknown"); else m_propertiesTab->aspectRatioToString(dims.width(), dims.height(), str); m_propertiesTab->setImageRatio(str); m_propertiesTab->setImageBitDepth(bitDepth.isEmpty() ? unavailable : i18n("%1 bpp", bitDepth)); m_propertiesTab->setImageColorMode(colorMode.isEmpty() ? unavailable : colorMode); // -- Photograph information ------------------------------------------ PhotoInfoContainer photoInfo = metaData.getPhotographInformation(); m_propertiesTab->setPhotoInfoDisable(photoInfo.isEmpty()); ImagePropertiesTab::shortenedMakeInfo(photoInfo.make); ImagePropertiesTab::shortenedModelInfo(photoInfo.model); m_propertiesTab->setPhotoMake(photoInfo.make.isEmpty() ? unavailable : photoInfo.make); m_propertiesTab->setPhotoModel(photoInfo.model.isEmpty() ? unavailable : photoInfo.model); if (photoInfo.dateTime.isValid()) { str = QLocale().toString(photoInfo.dateTime, QLocale::ShortFormat); m_propertiesTab->setPhotoDateTime(str); } else { m_propertiesTab->setPhotoDateTime(unavailable); } m_propertiesTab->setPhotoLens(photoInfo.lens.isEmpty() ? unavailable : photoInfo.lens); m_propertiesTab->setPhotoAperture(photoInfo.aperture.isEmpty() ? unavailable : photoInfo.aperture); if (photoInfo.focalLength35mm.isEmpty()) { m_propertiesTab->setPhotoFocalLength(photoInfo.focalLength.isEmpty() ? unavailable : photoInfo.focalLength); } else { str = i18n("%1 (%2)", photoInfo.focalLength, photoInfo.focalLength35mm); m_propertiesTab->setPhotoFocalLength(str); } m_propertiesTab->setPhotoExposureTime(photoInfo.exposureTime.isEmpty() ? unavailable : photoInfo.exposureTime); m_propertiesTab->setPhotoSensitivity(photoInfo.sensitivity.isEmpty() ? unavailable : i18n("%1 ISO", photoInfo.sensitivity)); if (photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty()) { m_propertiesTab->setPhotoExposureMode(unavailable); } else if (!photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty()) { m_propertiesTab->setPhotoExposureMode(photoInfo.exposureMode); } else if (photoInfo.exposureMode.isEmpty() && !photoInfo.exposureProgram.isEmpty()) { m_propertiesTab->setPhotoExposureMode(photoInfo.exposureProgram); } else { str = QString::fromUtf8("%1 / %2").arg(photoInfo.exposureMode).arg(photoInfo.exposureProgram); m_propertiesTab->setPhotoExposureMode(str); } m_propertiesTab->setPhotoFlash(photoInfo.flash.isEmpty() ? unavailable : photoInfo.flash); m_propertiesTab->setPhotoWhiteBalance(photoInfo.whiteBalance.isEmpty() ? unavailable : photoInfo.whiteBalance); // -- Video information ------------------------------------------ VideoInfoContainer videoInfo = metaData.getVideoInformation(); m_propertiesTab->setVideoInfoDisable(videoInfo.isEmpty()); m_propertiesTab->setVideoAspectRatio(videoInfo.aspectRatio.isEmpty() ? unavailable : videoInfo.aspectRatio); m_propertiesTab->setVideoDuration(videoInfo.duration.isEmpty() ? unavailable : videoInfo.duration); m_propertiesTab->setVideoFrameRate(videoInfo.frameRate.isEmpty() ? unavailable : videoInfo.frameRate); m_propertiesTab->setVideoVideoCodec(videoInfo.videoCodec.isEmpty() ? unavailable : videoInfo.videoCodec); m_propertiesTab->setVideoAudioBitRate(videoInfo.audioBitRate.isEmpty() ? unavailable : videoInfo.audioBitRate); m_propertiesTab->setVideoAudioChannelType(videoInfo.audioChannelType.isEmpty() ? unavailable : videoInfo.audioChannelType); m_propertiesTab->setVideoAudioCompressor(videoInfo.audioCompressor.isEmpty() ? unavailable : videoInfo.audioCompressor); // -- Caption, ratings, tag information --------------------- CaptionsMap captions = metaData.getImageComments(); QString caption; if (captions.contains(QLatin1String("x-default"))) caption = captions.value(QLatin1String("x-default")).caption; else if (!captions.isEmpty()) caption = captions.begin().value().caption; m_propertiesTab->setCaption(caption); m_propertiesTab->setRating(metaData.getImageRating()); QStringList tagPaths; metaData.getImageTagsPath(tagPaths); m_propertiesTab->setTags(tagPaths); m_propertiesTab->showOrHideCaptionAndTags(); }