bool SwWindow::prepareImageForUpload(const QString& imgPath, bool isRAW, QString& caption) { QImage image; if (isRAW) { qCDebug(KIPIPLUGINS_LOG) << "Get RAW preview " << imgPath; KDcraw::loadRawPreview(image, imgPath); } else { image.load(imgPath); } if (image.isNull()) return false; // get temporary file name m_tmpPath = m_tmpDir + QFileInfo(imgPath).baseName().trimmed() + QString(".jpg"); // rescale image if requested int maxDim = m_widget->m_dimensionSpB->value(); if (m_widget->m_resizeChB->isChecked() && (image.width() > maxDim || image.height() > maxDim)) { qCDebug(KIPIPLUGINS_LOG) << "Resizing to " << maxDim; image = image.scaled(maxDim, maxDim, Qt::KeepAspectRatio, Qt::SmoothTransformation); } qCDebug(KIPIPLUGINS_LOG) << "Saving to temp file: " << m_tmpPath; image.save(m_tmpPath, "JPEG", m_widget->m_imageQualitySpB->value()); // copy meta data to temporary image KPMetadata meta; if (meta.load(imgPath)) { caption = getImageCaption(meta); meta.setImageDimensions(image.size()); meta.setImageProgramId("Kipi-plugins", kipiplugins_version); meta.save(m_tmpPath); } else { caption.clear(); } return true; }
bool ClockPhotoDialog::setImage(const KUrl& imageFile) { bool success = false; if (d->imagePreview->load(imageFile.toLocalFile())) { // Try to read the datetime data. KPMetadata meta; if (meta.load(imageFile.toLocalFile())) { d->photoDateTime = meta.getImageDateTime(); if (d->photoDateTime.isValid()) { // Set the datetime widget to the photo datetime. d->calendar->setDateTime(d->photoDateTime); d->calendar->setEnabled(true); success = true; } else { // If datetime information couldn't be loaded, display a // warning and disable the datetime widget. QString warning = i18n("<font color=\"red\"><b>Could not " "obtain<br>date and time information<br>" "from image %1.</b></font>", imageFile.fileName()); d->imagePreview->setText(warning); } } } else { // If the image couldn't be loaded, display a warning, disable all the // GUI elements and load an empty photo into d->image. QString warning = i18n("<font color=\"red\"><b>Could not load<br>" "image %1.</b></font>", imageFile.fileName()); d->imagePreview->setText(warning); } // Disable all the GUI elements if loading failed. d->calendar->setEnabled(success); return success; }
void IPTCKeywords::applyMetadata(QByteArray& iptcData) { KPMetadata meta; meta.setIptc(iptcData); QStringList newKeywords; for (int i = 0 ; i < d->keywordsBox->count(); ++i) { QListWidgetItem* item = d->keywordsBox->item(i); newKeywords.append(item->text()); } if (d->keywordsCheck->isChecked()) meta.setIptcKeywords(d->oldKeywords, newKeywords); else meta.setIptcKeywords(d->oldKeywords, QStringList()); iptcData = meta.getIptc(); }
bool WMWindow::prepareImageForUpload(const QString& imgPath, QString& caption) { QImage image; image.load(imgPath); if (image.isNull()) { return false; } // get temporary file name m_tmpPath = m_tmpDir + QFileInfo(imgPath).baseName().trimmed() + ".jpg"; // rescale image if requested int maxDim = m_widget->dimension(); if (image.width() > maxDim || image.height() > maxDim) { kDebug() << "Resizing to " << maxDim; image = image.scaled(maxDim, maxDim, Qt::KeepAspectRatio, Qt::SmoothTransformation); } kDebug() << "Saving to temp file: " << m_tmpPath; image.save(m_tmpPath, "JPEG", m_widget->quality()); // copy meta data to temporary image KPMetadata meta; if (meta.load(imgPath)) { caption = getImageCaption(imgPath); meta.setImageDimensions(image.size()); meta.save(m_tmpPath); } else { caption.clear(); } return true; }
void IPTCKeywords::readMetadata(QByteArray& iptcData) { blockSignals(true); KPMetadata meta; meta.setIptc(iptcData); d->oldKeywords = meta.getIptcKeywords(); d->keywordsBox->clear(); d->keywordsCheck->setChecked(false); if (!d->oldKeywords.isEmpty()) { d->keywordsBox->insertItems(0, d->oldKeywords); d->keywordsCheck->setChecked(true); } d->keywordEdit->setEnabled(d->keywordsCheck->isChecked()); d->keywordsBox->setEnabled(d->keywordsCheck->isChecked()); d->addKeywordButton->setEnabled(d->keywordsCheck->isChecked()); d->delKeywordButton->setEnabled(d->keywordsCheck->isChecked()); blockSignals(false); }
void XMPEditWidget::apply() { if (d->modified && !d->isReadOnly) { KPImageInfo info(*d->dlg->currentItem()); if (d->contentPage->syncHOSTCommentIsChecked()) { info.setDescription(d->contentPage->getXMPCaption()); } d->contentPage->applyMetadata(d->exifData, d->xmpData); if (d->originPage->syncHOSTDateIsChecked()) { info.setDate(d->originPage->getXMPCreationDate()); } d->originPage->applyMetadata(d->exifData, d->xmpData); d->subjectsPage->applyMetadata(d->xmpData); d->keywordsPage->applyMetadata(d->xmpData); d->categoriesPage->applyMetadata(d->xmpData); d->creditsPage->applyMetadata(d->xmpData); d->statusPage->applyMetadata(d->xmpData); d->propertiesPage->applyMetadata(d->xmpData); KPMetadata meta; meta.load((*d->dlg->currentItem()).path()); meta.setExif(d->exifData); meta.setIptc(d->iptcData); meta.setXmp(d->xmpData); meta.save((*d->dlg->currentItem()).path()); d->modified = false; } }
void IPTCSubjects::applyMetadata(QByteArray& iptcData) { KPMetadata meta; meta.setIptc(iptcData); QStringList newSubjects = subjectsList(); if (m_subjectsCheck->isChecked()) meta.setIptcSubjects(meta.getIptcSubjects(), newSubjects); else meta.setIptcSubjects(meta.getIptcSubjects(), QStringList()); iptcData = meta.getIptc(); }
QString SwWindow::getImageCaption(const KPMetadata& meta) const { QString caption = meta.getCommentsDecoded(); if (!caption.isEmpty()) return caption; if (meta.hasExif()) { caption = meta.getExifComment(); if (!caption.isEmpty()) return caption; } if (meta.hasXmp()) { caption = meta.getXmpTagStringLangAlt("Xmp.dc.description", QString(), false); if (!caption.isEmpty()) return caption; caption = meta.getXmpTagStringLangAlt("Xmp.exif.UserComment", QString(), false); if (!caption.isEmpty()) return caption; caption = meta.getXmpTagStringLangAlt("Xmp.tiff.ImageDescription", QString(), false); if (!caption.isEmpty()) return caption; } if (meta.hasIptc()) { caption = meta.getIptcTagString("Iptc.Application2.Caption", false); if (!caption.isEmpty() && !caption.trimmed().isEmpty()) return caption; } return caption; }
void XMPContent::readMetadata(QByteArray& xmpData) { blockSignals(true); KPMetadata meta; meta.setXmp(xmpData); KPMetadata::AltLangMap map; QString data; d->headlineEdit->clear(); d->headlineCheck->setChecked(false); data = meta.getXmpTagString("Xmp.photoshop.Headline", false); if (!data.isNull()) { d->headlineEdit->setText(data); d->headlineCheck->setChecked(true); } d->headlineEdit->setEnabled(d->headlineCheck->isChecked()); d->captionEdit->setValid(false); map = meta.getXmpTagStringListLangAlt("Xmp.dc.description", false); if (!map.isEmpty()) d->captionEdit->setValues(map); data = meta.getXmpTagString("Xmp.photoshop.CaptionWriter", false); if (!data.isNull()) { d->writerEdit->setText(data); d->writerCheck->setChecked(true); } d->writerEdit->setEnabled(d->writerCheck->isChecked()); d->copyrightEdit->setValid(false); map = meta.getXmpTagStringListLangAlt("Xmp.dc.rights", false); if (!map.isEmpty()) d->copyrightEdit->setValues(map); blockSignals(false); }
void XMPEditWidget::slotItemChanged() { KPMetadata meta; meta.load((*d->dlg->currentItem()).path()); #if KEXIV2_VERSION >= 0x010000 d->exifData = meta.getExifEncoded(); #else d->exifData = meta.getExif(); #endif d->iptcData = meta.getIptc(); d->xmpData = meta.getXmp(); d->contentPage->readMetadata(d->xmpData); d->originPage->readMetadata(d->xmpData); d->subjectsPage->readMetadata(d->xmpData); d->keywordsPage->readMetadata(d->xmpData); d->categoriesPage->readMetadata(d->xmpData); d->creditsPage->readMetadata(d->xmpData); d->statusPage->readMetadata(d->xmpData); d->propertiesPage->readMetadata(d->xmpData); d->isReadOnly = !KPMetadata::canWriteXmp((*d->dlg->currentItem()).path()); emit signalSetReadOnly(d->isReadOnly); d->page_content->setEnabled(!d->isReadOnly); d->page_origin->setEnabled(!d->isReadOnly); d->page_subjects->setEnabled(!d->isReadOnly); d->page_keywords->setEnabled(!d->isReadOnly); d->page_categories->setEnabled(!d->isReadOnly); d->page_credits->setEnabled(!d->isReadOnly); d->page_status->setEnabled(!d->isReadOnly); d->page_properties->setEnabled(!d->isReadOnly); }
void XMPOrigin::readMetadata(QByteArray& xmpData) { blockSignals(true); KPMetadata meta; meta.setXmp(xmpData); QString data; QStringList code, list; QDateTime dateTime; QString dateTimeStr; dateTimeStr = meta.getXmpTagString("Xmp.photoshop.DateCreated", false); if (dateTimeStr.isEmpty()) dateTimeStr = meta.getXmpTagString("Xmp.xmp.CreateDate", false); else if (dateTimeStr.isEmpty()) dateTimeStr = meta.getXmpTagString("Xmp.xmp.ModifyDate", false); else if (dateTimeStr.isEmpty()) dateTimeStr = meta.getXmpTagString("Xmp.exif.DateTimeCreated", false); else if (dateTimeStr.isEmpty()) dateTimeStr = meta.getXmpTagString("Xmp.exif.DateTimeOriginal", false); else if (dateTimeStr.isEmpty()) dateTimeStr = meta.getXmpTagString("Xmp.tiff.DateTime", false); else if (dateTimeStr.isEmpty()) dateTimeStr = meta.getXmpTagString("Xmp.xmp.ModifyDate", false); else if (dateTimeStr.isEmpty()) dateTimeStr = meta.getXmpTagString("Xmp.xmp.MetadataDate", false); d->dateCreatedSel->setDateTime(QDateTime::currentDateTime()); d->dateCreatedCheck->setChecked(false); if (!dateTimeStr.isEmpty()) { dateTime = QDateTime::fromString(dateTimeStr, Qt::ISODate); if (dateTime.isValid()) { d->dateCreatedSel->setDateTime(dateTime); d->dateCreatedCheck->setChecked(true); } } d->dateCreatedSel->setEnabled(d->dateCreatedCheck->isChecked()); d->syncHOSTDateCheck->setEnabled(d->dateCreatedCheck->isChecked()); d->syncEXIFDateCheck->setEnabled(d->dateCreatedCheck->isChecked()); dateTimeStr = meta.getXmpTagString("Xmp.exif.DateTimeDigitized", false); d->dateDigitalizedSel->setDateTime(QDateTime::currentDateTime()); d->dateDigitalizedCheck->setChecked(false); if (!dateTimeStr.isEmpty()) { dateTime = QDateTime::fromString(dateTimeStr, Qt::ISODate); if (dateTime.isValid()) { d->dateDigitalizedSel->setDateTime(dateTime); d->dateDigitalizedCheck->setChecked(true); } } d->dateDigitalizedSel->setEnabled(d->dateDigitalizedCheck->isChecked()); d->cityEdit->clear(); d->cityCheck->setChecked(false); data = meta.getXmpTagString("Xmp.photoshop.City", false); if (!data.isNull()) { d->cityEdit->setText(data); d->cityCheck->setChecked(true); } d->cityEdit->setEnabled(d->cityCheck->isChecked()); d->sublocationEdit->clear(); d->sublocationCheck->setChecked(false); data = meta.getXmpTagString("Xmp.iptc.Location", false); if (!data.isNull()) { d->sublocationEdit->setText(data); d->sublocationCheck->setChecked(true); } d->sublocationEdit->setEnabled(d->sublocationCheck->isChecked()); d->provinceEdit->clear(); d->provinceCheck->setChecked(false); data = meta.getXmpTagString("Xmp.photoshop.State", false); if (!data.isNull()) { d->provinceEdit->setText(data); d->provinceCheck->setChecked(true); } d->provinceEdit->setEnabled(d->provinceCheck->isChecked()); d->countryCB->setCurrentIndex(0); d->countryCheck->setChecked(false); data = meta.getXmpTagString("Xmp.iptc.CountryCode", false); if (!data.isNull()) { int item = -1; for (int i = 0 ; i < d->countryCB->count() ; ++i) if (d->countryCB->itemText(i).left(3) == data) item = i; if (item != -1) { d->countryCB->setCurrentIndex(item); d->countryCheck->setChecked(true); } else d->countryCheck->setValid(false); } d->countryCB->setEnabled(d->countryCheck->isChecked()); blockSignals(false); }
void XMPContent::applyMetadata(QByteArray& exifData, QByteArray& xmpData) { KPMetadata meta; meta.setExif(exifData); meta.setXmp(xmpData); if (d->headlineCheck->isChecked()) meta.setXmpTagString("Xmp.photoshop.Headline", d->headlineEdit->text()); else meta.removeXmpTag("Xmp.photoshop.Headline"); KPMetadata::AltLangMap oldAltLangMap, newAltLangMap; if (d->captionEdit->getValues(oldAltLangMap, newAltLangMap)) { meta.setXmpTagStringListLangAlt("Xmp.dc.description", newAltLangMap, false); if (syncEXIFCommentIsChecked()) meta.setExifComment(getXMPCaption()); if (syncJFIFCommentIsChecked()) meta.setComments(getXMPCaption().toUtf8()); } else if (d->captionEdit->isValid()) meta.removeXmpTag("Xmp.dc.description"); if (d->writerCheck->isChecked()) meta.setXmpTagString("Xmp.photoshop.CaptionWriter", d->writerEdit->text()); else meta.removeXmpTag("Xmp.photoshop.CaptionWriter"); if (d->copyrightEdit->getValues(oldAltLangMap, newAltLangMap)) meta.setXmpTagStringListLangAlt("Xmp.dc.rights", newAltLangMap, false); else if (d->copyrightEdit->isValid()) meta.removeXmpTag("Xmp.dc.rights"); #if KEXIV2_VERSION >= 0x010000 exifData = meta.getExifEncoded(); #else exifData = meta.getExif(); #endif xmpData = meta.getXmp(); }
bool PiwigoTalker::addPhoto(int albumId, const QString& mediaPath, bool rescale, int maxWidth, int maxHeight, int quality) { KUrl mediaUrl = KUrl(mediaPath); m_job = 0; m_state = GE_CHECKPHOTOEXIST; m_talker_buffer.resize(0); m_path = mediaPath; // By default, m_path contains the original file m_tmpPath = ""; // By default, no temporary file (except with rescaling) m_albumId = albumId; m_md5sum = computeMD5Sum(mediaPath); kDebug() << mediaPath << " " << m_md5sum.toHex(); if (mediaPath.endsWith(".mp4") || mediaPath.endsWith(".MP4") || mediaPath.endsWith(".ogg") || mediaPath.endsWith(".OGG") || mediaPath.endsWith(".webm") || mediaPath.endsWith(".WEBM")) { // Video management // Nothing to do } else { // Image management QImage image; // Check if RAW file. if (KPMetadata::isRawFile(mediaPath)) KDcrawIface::KDcraw::loadRawPreview(image, mediaPath); else image.load(mediaPath); if (image.isNull()) { // Invalid image return false; } if (!rescale) { kDebug() << "Upload the original version: " << m_path; } else { // Rescale the image if (image.width() > maxWidth || image.height() > maxHeight) { image = image.scaled(maxWidth, maxHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); } m_path = m_tmpPath = KStandardDirs::locateLocal("tmp", KUrl(mediaPath).fileName()); image.save(m_path, "JPEG", quality); kDebug() << "Upload a resized version: " << m_path ; // Restore all metadata with EXIF // in the resized version KPMetadata meta; if (meta.load(mediaPath)) { meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); meta.setImageDimensions(image.size()); meta.save(m_path); } else { kDebug() << "Image " << mediaPath << " has no exif data"; } } } // Metadata management // Complete name and comment for summary sending QFileInfo fi(mediaPath); m_title = fi.completeBaseName(); m_comment = ""; m_author = ""; m_date = fi.created(); // Look in the Digikam database KPImageInfo info(mediaUrl); if (info.hasTitle() && !info.title().isEmpty()) m_title = info.title(); if (info.hasDescription() && !info.description().isEmpty()) m_comment = info.description(); if (info.hasCreators() && !info.creators().isEmpty()) m_author = info.creators().join(" / "); if (info.hasDate()) m_date = info.date(); kDebug() << "Title: " << m_title; kDebug() << "Comment: " << m_comment; kDebug() << "Author: " << m_author; kDebug() << "Date: " << m_date; QStringList qsl; qsl.append("method=pwg.images.exist"); qsl.append("md5sum_list=" + m_md5sum.toHex()); QString dataParameters = qsl.join("&"); QByteArray buffer; buffer.append(dataParameters.toUtf8()); m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo); m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" ); m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken ); emit signalProgressInfo( i18n("Check if %1 already exists", KUrl(mediaPath).fileName()) ); connect(m_job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(slotTalkerData(KIO::Job*,QByteArray))); connect(m_job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); emit signalBusy(true); return true; }
void SaveImgThread::run() { // Perform saving --------------------------------------------------------------- QImage prev = d->img.scaled(1280, 1024, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage thumb = d->img.scaled(160, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation); QByteArray prof = KPWriteImage::getICCProfilFromFile(RawDecodingSettings::SRGB); KPMetadata meta; meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); meta.setImageDimensions(d->img.size()); if (d->format != QString("JPEG")) meta.setImagePreview(prev); meta.setExifThumbnail(thumb); meta.setExifTagString("Exif.Image.DocumentName", QString("Scanned Image")); // not i18n meta.setExifTagString("Exif.Image.Make", d->make); meta.setXmpTagString("Xmp.tiff.Make", d->make); meta.setExifTagString("Exif.Image.Model", d->model); meta.setXmpTagString("Xmp.tiff.Model", d->model); meta.setImageDateTime(QDateTime::currentDateTime()); meta.setImageOrientation(KPMetadata::ORIENTATION_NORMAL); meta.setImageColorWorkSpace(KPMetadata::WORKSPACE_SRGB); KPWriteImage wImageIface; if (d->frmt != KSaneIface::KSaneWidget::FormatRGB_16_C) { QByteArray data((const char*)d->img.bits(), d->img.numBytes()); wImageIface.setImageData(data, d->img.width(), d->img.height(), false, true, prof, meta); } else { // 16 bits color depth image. wImageIface.setImageData(d->ksaneData, d->width, d->height, true, false, prof, meta); } bool ret = false; QString path; if(d->newUrl.isLocalFile()) path = d->newUrl.toLocalFile(); else path = d->newUrl.path(); if (d->format == QString("JPEG")) { ret = wImageIface.write2JPEG(path); } else if (d->format == QString("PNG")) { ret = wImageIface.write2PNG(path); } else if (d->format == QString("TIFF")) { ret = wImageIface.write2TIFF(path); } else { ret = d->img.save(path, d->format.toAscii().data()); } emit signalComplete(d->newUrl, ret); }
void IPTCEnvelope::readMetadata(QByteArray& iptcData) { blockSignals(true); KPMetadata meta; meta.setIptc(iptcData); QString data, format, version; QStringList list; QDate date; QTime time; QString dateStr, timeStr; d->destinationEdit->clear(); d->destinationCheck->setChecked(false); data = meta.getIptcTagString("Iptc.Envelope.Destination", false); if (!data.isNull()) { d->destinationEdit->setText(data); d->destinationCheck->setChecked(true); } d->destinationEdit->setEnabled(d->destinationCheck->isChecked()); d->envelopeIDEdit->clear(); d->envelopeIDCheck->setChecked(false); data = meta.getIptcTagString("Iptc.Envelope.EnvelopeNumber", false); if (!data.isNull()) { d->envelopeIDEdit->setText(data); d->envelopeIDCheck->setChecked(true); } d->envelopeIDEdit->setEnabled(d->envelopeIDCheck->isChecked()); d->serviceIDEdit->clear(); d->serviceIDCheck->setChecked(false); data = meta.getIptcTagString("Iptc.Envelope.ServiceId", false); if (!data.isNull()) { d->serviceIDEdit->setText(data); d->serviceIDCheck->setChecked(true); } d->serviceIDEdit->setEnabled(d->serviceIDCheck->isChecked()); d->unoIDEdit->clear(); d->unoIDCheck->setChecked(false); data = meta.getIptcTagString("Iptc.Envelope.UNO", false); if (!data.isNull()) { d->unoIDEdit->setText(data); d->unoIDCheck->setChecked(true); } d->unoIDEdit->setEnabled(d->unoIDCheck->isChecked()); d->productIDEdit->clear(); d->productIDCheck->setChecked(false); data = meta.getIptcTagString("Iptc.Envelope.ProductId", false); if (!data.isNull()) { d->productIDEdit->setText(data); d->productIDCheck->setChecked(true); } d->productIDEdit->setEnabled(d->productIDCheck->isChecked()); d->priorityCB->setCurrentIndex(0); d->priorityCheck->setChecked(false); data = meta.getIptcTagString("Iptc.Envelope.EnvelopePriority", false); if (!data.isNull()) { const int val = data.toInt(); if (val >= 0 && val <= 9) { d->priorityCB->setCurrentIndex(val); d->priorityCheck->setChecked(true); } else d->priorityCheck->setValid(false); } d->priorityCB->setEnabled(d->priorityCheck->isChecked()); d->formatCB->setCurrentIndex(0); d->formatCheck->setChecked(false); format = meta.getIptcTagString("Iptc.Envelope.FileFormat", false); version = meta.getIptcTagString("Iptc.Envelope.FileVersion", false); if (!format.isNull()) { if (!version.isNull()) { if (format.size() == 1) format.prepend("0"); if (version.size() == 1) version.prepend("0"); QString key = QString("%1-%2").arg(format).arg(version); int index = -1, i = 0; for (IPTCEnvelopePriv::FileFormatMap::Iterator it = d->fileFormatMap.begin(); it != d->fileFormatMap.end(); ++it) { if (it.key() == key) index = i; i++; } if (index != -1) { d->formatCB->setCurrentIndex(index); d->formatCheck->setChecked(true); } else d->formatCheck->setValid(false); } else d->formatCheck->setValid(false); } d->formatCB->setEnabled(d->formatCheck->isChecked()); dateStr = meta.getIptcTagString("Iptc.Envelope.DateSent", false); timeStr = meta.getIptcTagString("Iptc.Envelope.TimeSent", false); d->dateSentSel->setDate(QDate::currentDate()); d->dateSentCheck->setChecked(false); if (!dateStr.isEmpty()) { date = QDate::fromString(dateStr, Qt::ISODate); if (date.isValid()) { d->dateSentSel->setDate(date); d->dateSentCheck->setChecked(true); } } d->dateSentSel->setEnabled(d->dateSentCheck->isChecked()); d->timeSentSel->setTime(QTime::currentTime()); d->timeSentCheck->setChecked(false); d->zoneSentSel->setToUTC(); if (!timeStr.isEmpty()) { time = QTime::fromString(timeStr, Qt::ISODate); if (time.isValid()) { d->timeSentSel->setTime(time); d->timeSentCheck->setChecked(true); d->zoneSentSel->setTimeZone(timeStr); } } d->timeSentSel->setEnabled(d->timeSentCheck->isChecked()); d->zoneSentSel->setEnabled(d->timeSentCheck->isChecked()); blockSignals(false); }
bool PiwigoTalker::addPhoto(int albumId, const QString& photoPath, bool rescale, int maxWidth, int maxHeight, int thumbDim) { KUrl photoUrl = KUrl(photoPath); m_job = 0; m_state = GE_CHECKPHOTOEXIST; m_talker_buffer.resize(0); m_path = photoPath; m_albumId = albumId; m_md5sum = computeMD5Sum(photoPath); if (!rescale) { m_hqpath = photoPath; kDebug() << "Download HQ version: " << m_hqpath; } else { m_hqpath = ""; } kDebug() << photoPath << " " << m_md5sum.toHex(); QImage image; // Check if RAW file. if (KPMetadata::isRawFile(photoPath)) KDcrawIface::KDcraw::loadDcrawPreview(image, photoPath); else image.load(photoPath); if (!image.isNull()) { QFileInfo fi(photoPath); QImage thumbnail = image.scaled(thumbDim, thumbDim, Qt::KeepAspectRatio, Qt::SmoothTransformation); m_thumbpath = KStandardDirs::locateLocal("tmp", "thumb-" + KUrl(photoPath).fileName()); thumbnail.save(m_thumbpath, "JPEG", 95); kDebug() << "Thumbnail to temp file: " << m_thumbpath ; // image file - see if we need to rescale it if (image.width() > maxWidth || image.height() > maxHeight) { image = image.scaled(maxWidth, maxHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); } m_path = KStandardDirs::locateLocal("tmp", KUrl(photoPath).fileName()); image.save(m_path, "JPEG", 95); kDebug() << "Resizing and saving to temp file: " << m_path ; // Complete name and comment for summary sending m_title = fi.completeBaseName(); m_comment = ""; m_author = ""; m_date = fi.created(); // Look in the Digikam database KPImageInfo info(photoUrl); if (info.hasTitle() && !info.title().isEmpty()) m_title = info.title(); if (info.hasDescription() && !info.description().isEmpty()) m_comment = info.description(); if (info.hasCreators() && !info.creators().isEmpty()) m_author = info.creators().join(" / "); if (info.hasDate()) m_date = info.date(); kDebug() << "Title: " << m_title; kDebug() << "Comment: " << m_comment; kDebug() << "Author: " << m_author; kDebug() << "Date: " << m_date; // Restore all metadata with EXIF // in the resized version KPMetadata meta; if (meta.load(photoPath)) { meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); meta.setImageDimensions(image.size()); meta.save(m_path); } else { kDebug() << "Image " << photoPath << " has no exif data"; } } else { // Invalid image return false; } QStringList qsl; qsl.append("method=pwg.images.exist"); qsl.append("md5sum_list=" + m_md5sum.toHex()); QString dataParameters = qsl.join("&"); QByteArray buffer; buffer.append(dataParameters.toUtf8()); m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo); m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" ); m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken ); emit signalProgressInfo( i18n("Check if %1 already exists", KUrl(m_path).fileName()) ); connect(m_job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(slotTalkerData(KIO::Job*,QByteArray))); connect(m_job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); emit signalBusy(true); return true; }
void Task::run() { if (d->cancel) return; QDateTime dt = d->itemsMap.value(d->url); if (!dt.isValid()) return; emit signalProcessStarted(d->url); bool metadataChanged = d->settings.updEXIFModDate || d->settings.updEXIFOriDate || d->settings.updEXIFDigDate || d->settings.updEXIFThmDate || d->settings.updIPTCDate || d->settings.updXMPDate; int status = MyImageList::NOPROCESS_ERROR; if (metadataChanged) { bool ret = true; KPMetadata meta; ret &= meta.load(d->url.path()); if (ret) { if (meta.canWriteExif(d->url.path())) { if (d->settings.updEXIFModDate) { ret &= meta.setExifTagString("Exif.Image.DateTime", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } if (d->settings.updEXIFOriDate) { ret &= meta.setExifTagString("Exif.Photo.DateTimeOriginal", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } if (d->settings.updEXIFDigDate) { ret &= meta.setExifTagString("Exif.Photo.DateTimeDigitized", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } if (d->settings.updEXIFThmDate) { ret &= meta.setExifTagString("Exif.Image.PreviewDateTime", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } } else if (d->settings.updEXIFModDate || d->settings.updEXIFOriDate || d->settings.updEXIFDigDate || d->settings.updEXIFThmDate) { ret = false; } if (d->settings.updIPTCDate) { if (meta.canWriteIptc(d->url.path())) { ret &= meta.setIptcTagString("Iptc.Application2.DateCreated", dt.date().toString(Qt::ISODate)); ret &= meta.setIptcTagString("Iptc.Application2.TimeCreated", dt.time().toString(Qt::ISODate)); } else { ret = false; } } if (d->settings.updXMPDate) { if (meta.supportXmp() && meta.canWriteXmp(d->url.path())) { ret &= meta.setXmpTagString("Xmp.exif.DateTimeOriginal", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.photoshop.DateCreated", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.tiff.DateTime", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.xmp.CreateDate", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.xmp.MetadataDate", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.xmp.ModifyDate", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } else { ret = false; } } ret &= meta.save(d->url.path()); if (!ret) { kDebug() << "Failed to update metadata in file " << d->url.fileName(); } } else { kDebug() << "Failed to load metadata from file " << d->url.fileName(); } if (!ret) { status |= MyImageList::META_TIME_ERROR; } } if (d->settings.updFileModDate) { // Since QFileInfo does not support timestamp updates, see Qt suggestion #79427 at // http://www.qtsoftware.com/developer/task-tracker/index_html?id=79427&method=entry // we have to use the utime() system call. utimbuf times; times.actime = QDateTime::currentDateTime().toTime_t(); times.modtime = dt.toTime_t(); if (utime(QFile::encodeName(d->url.toLocalFile()).constData(), ×) != 0) { status |= MyImageList::FILE_TIME_ERROR; } } if (d->settings.updFileName) { bool ret = true; KUrl newUrl = ActionThread::newUrl(d->url, dt); if (KDE_rename(QFile::encodeName(d->url.toLocalFile()), QFile::encodeName(newUrl.toLocalFile())) != 0) ret = false; ret &= KPMetadata::moveSidecar(d->url, newUrl); if (!ret) status |= MyImageList::FILE_NAME_ERROR; } if (d->settings.updAppDate) { KPImageInfo info(d->url); QDateTime dt = d->itemsMap.value(d->url); if (dt.isValid()) info.setDate(dt); } emit signalProcessEnded(d->url, status); }
void PicasawebWindow::slotListPhotosDoneForUpload(int errCode, const QString &errMsg, const QList <PicasaWebPhoto>& photosList) { disconnect(m_talker, SIGNAL(signalListPhotosDone(int,QString,QList<PicasaWebPhoto>)), this, SLOT(slotListPhotosDoneForUpload(int,QString,QList<PicasaWebPhoto>))); if (errCode != 0) { KMessageBox::error(this, i18n("Picasaweb Call Failed: %1\n", errMsg)); return; } typedef QPair<KUrl,PicasaWebPhoto> Pair; m_transferQueue.clear(); KUrl::List urlList = m_widget->m_imgList->imageUrls(true); if (urlList.isEmpty()) return; for (KUrl::List::ConstIterator it = urlList.constBegin(); it != urlList.constEnd(); ++it) { KPImageInfo info(*it); PicasaWebPhoto temp; temp.title = info.name(); // Picasa doesn't support image titles. Include it in descriptions if needed. QStringList descriptions = QStringList() << info.title() << info.description(); descriptions.removeAll(""); temp.description = descriptions.join("\n\n"); // check for existing items QString localId; KPMetadata meta; if (meta.load((*it).toLocalFile())) { localId = meta.getXmpTagString("Xmp.kipi.picasawebGPhotoId"); } QList<PicasaWebPhoto>::const_iterator itPWP; for (itPWP = photosList.begin(); itPWP != photosList.end(); ++itPWP) { if ((*itPWP).id == localId) { temp.id = localId; temp.editUrl = (*itPWP).editUrl; temp.thumbURL = (*itPWP).thumbURL; break; } } //Tags from the database temp.gpsLat.setNum(info.latitude()); temp.gpsLon.setNum(info.longitude()); temp.tags = info.tagsPath(); m_transferQueue.append( Pair( (*it), temp) ); } if (m_transferQueue.isEmpty()) return; m_currentAlbumID = m_widget->m_albumsCoB->itemData( m_widget->m_albumsCoB->currentIndex()).toString(); m_imagesTotal = m_transferQueue.count(); m_imagesCount = 0; m_widget->progressBar()->setFormat(i18n("%v / %m")); m_widget->progressBar()->setMaximum(m_imagesTotal); m_widget->progressBar()->setValue(0); m_widget->progressBar()->show(); m_widget->progressBar()->progressScheduled(i18n("Picasa Export"), true, true); m_widget->progressBar()->progressThumbnailChanged(KIcon("kipi").pixmap(22, 22)); m_renamingOpt = 0; uploadNextPhoto(); }
/*! \fn KmlExport::generate() */ void KmlExport::generate() { //! @todo perform a test here before continuing. createDir(QString(m_tempDestDir + m_imageDir)); m_progressDialog->show(); ImageCollection selection = m_interface->currentSelection(); ImageCollection album = m_interface->currentAlbum(); // create the document, and it's root m_kmlDocument = new QDomDocument(""); QDomImplementation impl; QDomProcessingInstruction instr = m_kmlDocument->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); m_kmlDocument->appendChild(instr); QDomElement kmlRoot = m_kmlDocument->createElementNS("http://www.opengis.net/kml/2.2", "kml"); m_kmlDocument->appendChild( kmlRoot ); QDomElement kmlAlbum = addKmlElement(kmlRoot, "Document"); QDomElement kmlName = addKmlTextElement(kmlAlbum, "name", album.name()); QDomElement kmlDescription = addKmlHtmlElement(kmlAlbum, "description", "Created with kmlexport <a href=\"http://www.digikam.org/\">kipi-plugin</a>"); if (m_GPXtracks) { addTrack(kmlAlbum); } KPMetadata meta; KUrl::List images = selection.images(); int defectImage = 0; int pos = 1; int count = images.count(); KUrl::List::ConstIterator imagesEnd (images.constEnd()); for( KUrl::List::ConstIterator selIt = images.constBegin(); selIt != imagesEnd; ++selIt, ++pos) { double alt, lat, lng; KUrl url = *selIt; KPImageInfo info(url); bool hasGPSInfo = info.hasGeolocationInfo(); if (hasGPSInfo) { lat = info.latitude(); lng = info.longitude(); alt = info.altitude(); } else { meta.load(url.path()); hasGPSInfo = meta.getGPSInfo(alt, lat, lng); } if ( hasGPSInfo ) { // generation de l'image et de l'icone generateImagesthumb(url, kmlAlbum); } else { logWarning(i18n("No position data for '%1'", info.name())); defectImage++; } m_progressDialog->progressWidget()->setProgress(pos, count); kapp->processEvents(); } if (defectImage) { /** @todo if defectImage==count there are no pictures exported, does is it worth to continue? */ KMessageBox::information(kapp->activeWindow(), i18np("No position data for 1 picture", "No position data for %1 pictures", defectImage)); } /** @todo change to kml or kmz if compressed */ QFile file( m_tempDestDir + m_KMLFileName + ".kml"); /** @todo handle file opening problems */ file.open( QIODevice::WriteOnly ); QTextStream stream( &file ); // we will serialize the data into the file stream << m_kmlDocument->toString(); file.close(); delete m_kmlDocument; m_kmlDocument = 0; KIO::moveAs(m_tempDestDir, m_baseDestDir, KIO::HideProgressInfo | KIO::Overwrite); logInfo(i18n("Move to final directory")); m_progressDialog->close(); }
/*! \fn KmlExport::generateImagesthumb(const KUrl& imageURL, QDomElement& kmlAlbum ) */ void KmlExport::generateImagesthumb(const KUrl& imageURL, QDomElement& kmlAlbum ) { KPImageInfo info(imageURL); // Load image QString path = imageURL.path(); QFile imageFile(path); if (!imageFile.open(QIODevice::ReadOnly)) { logWarning(i18n("Could not read image '%1'",path)); return; } QImageReader reader(&imageFile); QString imageFormat = reader.format(); if (imageFormat.isEmpty()) { logWarning(i18n("Format of image '%1' is unknown",path)); return; } imageFile.close(); imageFile.open(QIODevice::ReadOnly); QByteArray imageData = imageFile.readAll(); QImage image; if (!image.loadFromData(imageData) ) { logWarning(i18n("Error loading image '%1'",path)); return; } // Process images if ( info.orientation() != KPMetadata::ORIENTATION_UNSPECIFIED ) { QMatrix matrix = RotationMatrix::toMatrix(info.orientation()); image = image.transformed( matrix ); } image = image.scaled(m_size, m_size, Qt::KeepAspectRatioByExpanding); QImage icon; if (m_optimize_googlemap) { icon = generateSquareThumbnail(image,m_googlemapSize); } else { // icon = image.smoothScale(m_iconSize, m_iconSize, QImage::ScaleMax); icon = generateBorderedThumbnail(image, m_iconSize); } // Save images /** @todo remove the extension of the file * it's appear with digikam but not with gwenview * which already seems to strip the extension */ QString baseFileName = webifyFileName(info.name()); //baseFileName = mUniqueNameHelper.makeNameUnique(baseFileName); QString fullFileName; fullFileName = baseFileName + '.' + imageFormat.toLower(); QString destPath = m_tempDestDir + m_imageDir + fullFileName; if (!image.save(destPath, imageFormat.toAscii(), 85)) { // if not able to save the image, it's pointless to create a placemark logWarning(i18n("Could not save image '%1' to '%2'",path,destPath)); } else { //logInfo(i18n("Creation of picture '%1'").arg(fullFileName)); double alt, lat, lng; KPMetadata meta; if (info.hasGeolocationInfo()) { lat = info.latitude(); lng = info.longitude(); alt = info.altitude(); } else { meta.load(imageURL.path()); meta.getGPSInfo(alt, lat, lng); } QDomElement kmlPlacemark = addKmlElement(kmlAlbum, "Placemark"); addKmlTextElement(kmlPlacemark,"name",fullFileName); // location and altitude QDomElement kmlGeometry = addKmlElement(kmlPlacemark, "Point"); if (alt) { addKmlTextElement(kmlGeometry, "coordinates", QString("%1,%2,%3 ") .arg(lng, 0, 'f', 8) .arg(lat, 0, 'f', 8) .arg(alt, 0, 'f', 8)); } else { addKmlTextElement(kmlGeometry, "coordinates", QString("%1,%2 ") .arg(lng, 0, 'f', 8) .arg(lat, 0, 'f', 8)); } if (m_altitudeMode == 2 ) { addKmlTextElement(kmlGeometry, "altitudeMode", "absolute"); } else if (m_altitudeMode == 1 ) { addKmlTextElement(kmlGeometry, "altitudeMode", "relativeToGround"); } else { addKmlTextElement(kmlGeometry, "altitudeMode", "clampToGround"); } addKmlTextElement(kmlGeometry, "extrude", "1"); // we try to load exif value if any otherwise, try the application db /** we need to take the DateTimeOriginal * if we refer to http://www.exif.org/Exif2-2.PDF * (standard)DateTime: is The date and time of image creation. In this standard it is the date and time the file was changed * DateTimeOriginal: The date and time when the original image data was generated. * For a DSC the date and time the picture was taken are recorded. * DateTimeDigitized: The date and time when the image was stored as digital data. * So for: * - a DSC: the right time is the DateTimeDigitized which is also DateTimeOriginal * if the picture has been modified the (standard)DateTime should change. * - a scanned picture, the right time is the DateTimeOriginal which should also be the DateTime * the (standard)DateTime should be the same except if the picture is modified * - a panorama created from several pictures, the right time is the DateTimeOriginal (average of DateTimeOriginal actually) * The (standard)DateTime is the creation date of the panorama. * it's seems the time to take into acccount is the DateTimeOriginal. * but the KPMetadata::getImageDateTime() return the (standard)DateTime first * KPMetadata seems to take Original dateTime first so it shoul be alright now. */ QDateTime datetime = meta.getImageDateTime(); if (datetime.isValid()) { QDomElement kmlTimeStamp = addKmlElement(kmlPlacemark, "TimeStamp"); addKmlTextElement(kmlTimeStamp, "when", datetime.toString("yyyy-MM-ddThh:mm:ssZ")); } else if (m_interface->hasFeature(ImagesHasTime)) { QDomElement kmlTimeStamp = addKmlElement(kmlPlacemark, "TimeStamp"); addKmlTextElement(kmlTimeStamp, "when", (info.date()).toString("yyyy-MM-ddThh:mm:ssZ")); } QString my_description; if (m_optimize_googlemap) { my_description = "<img src=\"" + m_UrlDestDir + m_imageDir + fullFileName + "\">"; } else { my_description = "<img src=\"" + m_imageDir + fullFileName + "\">"; } if ( m_interface->hasFeature( ImagesHasComments ) ) { my_description += "<br/>" + info.description() ; } addKmlTextElement(kmlPlacemark, "description", my_description); logInfo(i18n("Creation of placemark '%1'", fullFileName)); // Save icon QString iconFileName = "thumb_" + baseFileName + '.' + imageFormat.toLower(); QString destPath = m_tempDestDir + m_imageDir + iconFileName; if (!icon.save(destPath, imageFormat.toAscii(), 85)) { logWarning(i18n("Could not save icon for image '%1' to '%2'",path,destPath)); } else { //logInfo(i18n("Creation of icon '%1'").arg(iconFileName)); // style et icon QDomElement kmlStyle = addKmlElement(kmlPlacemark, "Style"); QDomElement kmlIconStyle = addKmlElement(kmlStyle, "IconStyle"); QDomElement kmlIcon = addKmlElement(kmlIconStyle, "Icon"); if (m_optimize_googlemap) { addKmlTextElement(kmlIcon, "href", m_UrlDestDir + m_imageDir + iconFileName); } else { addKmlTextElement(kmlIcon, "href", m_imageDir + iconFileName); } QDomElement kmlBallonStyle = addKmlElement(kmlStyle, "BalloonStyle"); addKmlTextElement(kmlBallonStyle, "text", "$[description]"); } } }
bool Utils::updateMetadataImageMagick(const QString& src, QString& err) { QFileInfo finfo(src); if (src.isEmpty() || !finfo.isReadable()) { err = i18n("unable to open source file"); return false; } QImage img(src); QImage iptcPreview = img.scaled(1280, 1024, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage exifThumbnail = iptcPreview.scaled(160, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation); KPMetadata meta; meta.load(src); meta.setImageOrientation(KPMetadata::ORIENTATION_NORMAL); meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); meta.setImageDimensions(img.size()); meta.setExifThumbnail(exifThumbnail); meta.setImagePreview(iptcPreview); #if KEXIV2_VERSION >= 0x010000 QByteArray exifData = meta.getExifEncoded(true); #else QByteArray exifData = meta.getExif(true); #endif QByteArray iptcData = meta.getIptc(true); QByteArray xmpData = meta.getXmp(); KTemporaryFile exifTemp; exifTemp.setSuffix(QString("kipipluginsexif.app1")); exifTemp.setAutoRemove(true); if ( !exifTemp.open() ) { err = i18n("unable to open temp file"); return false; } QString exifFile = exifTemp.fileName(); QDataStream streamExif( &exifTemp ); streamExif.writeRawData(exifData.data(), exifData.size()); exifTemp.close(); KTemporaryFile iptcTemp; iptcTemp.setSuffix(QString("kipipluginsiptc.8bim")); iptcTemp.setAutoRemove(true); iptcTemp.open(); if ( !iptcTemp.open() ) { err = i18n("Cannot rotate: unable to open temp file"); return false; } QString iptcFile = iptcTemp.fileName(); QDataStream streamIptc( &iptcTemp ); streamIptc.writeRawData(iptcData.data(), iptcData.size()); iptcTemp.close(); KTemporaryFile xmpTemp; xmpTemp.setSuffix(QString("kipipluginsxmp.xmp")); xmpTemp.setAutoRemove(true); if ( !xmpTemp.open() ) { err = i18n("unable to open temp file"); return false; } QString xmpFile = xmpTemp.fileName(); QDataStream streamXmp( &xmpTemp ); streamXmp.writeRawData(xmpData.data(), xmpData.size()); xmpTemp.close(); KProcess process; process.clearProgram(); process << "mogrify"; process << "-profile"; process << exifFile; process << "-profile"; process << iptcFile; process << "-profile"; process << xmpFile; process << src + QString("[0]"); kDebug() << "ImageMagick Command line: " << process.program(); process.start(); if (!process.waitForFinished()) return false; if (process.exitStatus() != QProcess::NormalExit) return false; switch (process.exitCode()) { case 0: // Process finished successfully ! { return true; break; } case 15: // process aborted ! { return false; break; } } // Processing error ! m_stdErr = process.readAllStandardError(); err = i18n("Cannot update metadata: %1", m_stdErr.replace('\n', ' ')); return false; }
void XMPOrigin::applyMetadata(QByteArray& exifData, QByteArray& xmpData) { KPMetadata meta; meta.setExif(exifData); meta.setXmp(xmpData); if (d->dateCreatedCheck->isChecked()) { meta.setXmpTagString("Xmp.photoshop.DateCreated", getXMPCreationDate().toString("yyyy:MM:dd hh:mm:ss")); meta.setXmpTagString("Xmp.xmp.CreateDate", getXMPCreationDate().toString("yyyy:MM:dd hh:mm:ss")); meta.setXmpTagString("Xmp.exif.DateTimeCreated", getXMPCreationDate().toString("yyyy:MM:dd hh:mm:ss")); meta.setXmpTagString("Xmp.exif.DateTimeOriginal", getXMPCreationDate().toString("yyyy:MM:dd hh:mm:ss")); meta.setXmpTagString("Xmp.tiff.DateTime", getXMPCreationDate().toString("yyyy:MM:dd hh:mm:ss")); meta.setXmpTagString("Xmp.xmp.ModifyDate", getXMPCreationDate().toString("yyyy:MM:dd hh:mm:ss")); meta.setXmpTagString("Xmp.xmp.MetadataDate", getXMPCreationDate().toString("yyyy:MM:dd hh:mm:ss")); if (syncEXIFDateIsChecked()) { meta.setExifTagString("Exif.Image.DateTime", getXMPCreationDate().toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } } else { meta.removeXmpTag("Xmp.photoshop.DateCreated"); meta.removeXmpTag("Xmp.xmp.CreateDate"); meta.removeXmpTag("Xmp.exif.DateTimeCreated"); meta.removeXmpTag("Xmp.exif.DateTimeOriginal"); meta.removeXmpTag("Xmp.tiff.DateTime"); meta.removeXmpTag("Xmp.xmp.ModifyDate"); meta.removeXmpTag("Xmp.xmp.MetadataDate"); } if (d->dateDigitalizedCheck->isChecked()) meta.setXmpTagString("Xmp.exif.DateTimeDigitized", d->dateDigitalizedSel->dateTime().toString("yyyy:MM:dd hh:mm:ss")); else meta.removeXmpTag("Xmp.exif.DateTimeDigitized"); if (d->cityCheck->isChecked()) meta.setXmpTagString("Xmp.photoshop.City", d->cityEdit->text()); else meta.removeXmpTag("Xmp.photoshop.City"); if (d->sublocationCheck->isChecked()) meta.setXmpTagString("Xmp.iptc.Location", d->sublocationEdit->text()); else meta.removeXmpTag("Xmp.iptc.Location"); if (d->provinceCheck->isChecked()) meta.setXmpTagString("Xmp.photoshop.State", d->provinceEdit->text()); else meta.removeXmpTag("Xmp.photoshop.State"); if (d->countryCheck->isChecked()) { QString countryName = d->countryCB->currentText().mid(6); QString countryCode = d->countryCB->currentText().left(3); meta.setXmpTagString("Xmp.iptc.CountryCode", countryCode); meta.setXmpTagString("Xmp.photoshop.Country", countryName); } else if (d->countryCheck->isValid()) { meta.removeXmpTag("Xmp.iptc.CountryCode"); meta.removeXmpTag("Xmp.photoshop.Country"); } #if KEXIV2_VERSION >= 0x010000 exifData = meta.getExifEncoded(); #else exifData = meta.getExif(); #endif xmpData = meta.getXmp(); }
void SwWindow::uploadNextPhoto() { if (m_transferQueue.isEmpty()) { // done! m_progressDlg->hide(); if (m_imagesTotal > 0) { SwAlbum album = m_albumsList.at( m_widget->m_albumsCoB->currentIndex() ); KMessageBox::information(this, i18n("Upload complete. Visit \"<a href=\"%1\">%2</a>\" to view the album online and invite people.", album.albumUrl, album.title), i18n("Upload complete"), QString(), KMessageBox::AllowLink ); } return; } m_progressDlg->progressBar()->setMaximum(m_imagesTotal); m_progressDlg->progressBar()->setValue(m_imagesCount); QString imgPath = m_transferQueue.first().path(); QString caption; bool res; // check if we have to RAW file -> use preview image then bool isRAW = KPMetadata::isRawFile(QUrl::fromLocalFile(imgPath)); if (isRAW || m_widget->m_resizeChB->isChecked()) { if (!prepareImageForUpload(imgPath, isRAW, caption)) { slotAddPhotoDone(666, i18n("Cannot open file")); return; } res = m_connector->addPhoto(m_tmpPath, m_currentAlbumID, caption); } else { KPMetadata meta; if (meta.load(imgPath)) caption = getImageCaption(meta); else caption.clear(); m_tmpPath.clear(); res = m_connector->addPhoto(imgPath, m_currentAlbumID, caption); } if (!res) { slotAddPhotoDone(666, i18n("Cannot open file")); return; } m_progressDlg->setLabelText(i18n("Uploading file %1", m_transferQueue.first().path())); }
bool DBTalker::addPhoto(const QString& imgPath, const QString& uploadFolder, bool rescale, int maxDim, int imageQuality) { if(m_job) { m_job->kill(); m_job = 0; } emit signalBusy(true); MPForm form; QString path = imgPath; QImage image; if(KPMetadata::isRawFile(imgPath)) { KDcrawIface::KDcraw::loadRawPreview(image,imgPath); } else { image.load(imgPath); } if(image.isNull()) { return false; } path = KStandardDirs::locateLocal("tmp",QFileInfo(imgPath).baseName().trimmed()+".jpg"); if(rescale && (image.width() > maxDim || image.height() > maxDim)) { image = image.scaled(maxDim,maxDim,Qt::KeepAspectRatio,Qt::SmoothTransformation); } image.save(path,"JPEG",imageQuality); KPMetadata meta; if(meta.load(imgPath)) { meta.setImageDimensions(image.size()); meta.setImageProgramId("Kipi-plugins",kipiplugins_version); meta.save(path); } if(!form.addFile(path)) { emit signalBusy(false); return false; } QString uploadPath = uploadFolder + KUrl(imgPath).fileName(); QString m_url = QString("https://api-content.dropbox.com/1/files_put/dropbox/") + "/" +uploadPath; KUrl url(m_url); url.addQueryItem("oauth_consumer_key",m_oauth_consumer_key); url.addQueryItem("oauth_nonce", nonce); url.addQueryItem("oauth_signature",m_access_oauth_signature); url.addQueryItem("oauth_signature_method",m_oauth_signature_method); url.addQueryItem("oauth_timestamp", QString::number(timestamp)); url.addQueryItem("oauth_version",m_oauth_version); url.addQueryItem("oauth_token",m_oauthToken); url.addQueryItem("overwrite","false"); KIO::TransferJob* const job = KIO::http_post(url,form.formData(),KIO::HideProgressInfo); job->addMetaData("content-type","Content-Type : application/x-www-form-urlencoded"); connect(job,SIGNAL(data(KIO::Job*,QByteArray)), this,SLOT(data(KIO::Job*,QByteArray))); connect(job,SIGNAL(result(KJob*)), this,SLOT(slotResult(KJob*))); m_state = DB_ADDPHOTO; m_job = job; m_buffer.resize(0); emit signalBusy(true); return true; }
void IPTCSubjects::readMetadata(QByteArray& iptcData) { KPMetadata meta; meta.setIptc(iptcData); setSubjectsList(meta.getIptcSubjects()); }
void EXIFAdjust::applyMetadata(QByteArray& exifData) { KPMetadata meta; meta.setExif(exifData); long int num=1, den=1; if (d->brightnessCheck->isChecked()) { meta.convertToRational(d->brightnessEdit->value(), &num, &den, 1); meta.setExifTagRational("Exif.Photo.BrightnessValue", num, den); } else meta.removeExifTag("Exif.Photo.BrightnessValue"); if (d->gainControlCheck->isChecked()) meta.setExifTagLong("Exif.Photo.GainControl", d->gainControlCB->currentIndex()); else if (d->gainControlCheck->isValid()) meta.removeExifTag("Exif.Photo.GainControl"); if (d->contrastCheck->isChecked()) meta.setExifTagLong("Exif.Photo.Contrast", d->contrastCB->currentIndex()); else if (d->contrastCheck->isValid()) meta.removeExifTag("Exif.Photo.Contrast"); if (d->saturationCheck->isChecked()) meta.setExifTagLong("Exif.Photo.Saturation", d->saturationCB->currentIndex()); else if (d->saturationCheck->isValid()) meta.removeExifTag("Exif.Photo.Saturation"); if (d->sharpnessCheck->isChecked()) meta.setExifTagLong("Exif.Photo.Sharpness", d->sharpnessCB->currentIndex()); else if (d->sharpnessCheck->isValid()) meta.removeExifTag("Exif.Photo.Sharpness"); if (d->customRenderedCheck->isChecked()) meta.setExifTagLong("Exif.Photo.CustomRendered", d->customRenderedCB->currentIndex()); else if (d->customRenderedCheck->isValid()) meta.removeExifTag("Exif.Photo.CustomRendered"); #if KEXIV2_VERSION >= 0x010000 exifData = meta.getExifEncoded(); #else exifData = meta.getExif(); #endif }
bool FlickrTalker::addPhoto(const QString& photoPath, const FPhotoInfo& info, bool sendOriginal, bool rescale, int maxDim, int imageQuality) { if (m_job) { m_job->kill(); m_job = 0; } KUrl url(m_uploadUrl); // We dont' want to modify url as such, we just used the KURL object for storing the query items. KUrl url2(""); QString path = photoPath; MPForm form; form.addPair("auth_token", m_token, "text/plain"); url2.addQueryItem("auth_token", m_token); form.addPair("api_key", m_apikey, "text/plain"); url2.addQueryItem("api_key", m_apikey); QString ispublic = (info.is_public == 1) ? "1" : "0"; form.addPair("is_public", ispublic, "text/plain"); url2.addQueryItem("is_public", ispublic); QString isfamily = (info.is_family == 1) ? "1" : "0"; form.addPair("is_family", isfamily, "text/plain"); url2.addQueryItem("is_family", isfamily); QString isfriend = (info.is_friend == 1) ? "1" : "0"; form.addPair("is_friend", isfriend, "text/plain"); url2.addQueryItem("is_friend", isfriend); QString safetyLevel = QString::number(static_cast<int>(info.safety_level)); form.addPair("safety_level", safetyLevel, "text/plain"); url2.addQueryItem("safety_level", safetyLevel); QString contentType = QString::number(static_cast<int>(info.content_type)); form.addPair("content_type", contentType, "text/plain"); url2.addQueryItem("content_type", contentType); QString tags = "\"" + info.tags.join("\" \"") + "\""; if (tags.length() > 0) { form.addPair("tags", tags, "text/plain"); url2.addQueryItem("tags", tags); } if (!info.title.isEmpty()) { form.addPair("title", info.title, "text/plain"); url2.addQueryItem("title", info.title); } if (!info.description.isEmpty()) { form.addPair("description", info.description, "text/plain"); url2.addQueryItem("description", info.description); } QString md5 = getApiSig(m_secret, url2); form.addPair("api_sig", md5, "text/plain"); QImage image; // Check if RAW file. if (KPMetadata::isRawFile(photoPath)) { KDcrawIface::KDcraw::loadDcrawPreview(image, photoPath); } else { image.load(photoPath); } if (!image.isNull()) { path = KStandardDirs::locateLocal("tmp", QFileInfo(photoPath).baseName().trimmed() + ".jpg"); if (sendOriginal) { QFile imgFile(photoPath); imgFile.copy(path); } else { if (rescale && (image.width() > maxDim || image.height() > maxDim)) image = image.scaled(maxDim, maxDim, Qt::KeepAspectRatio, Qt::SmoothTransformation); image.save(path, "JPEG", imageQuality); } // Restore all metadata. KPMetadata meta; if (meta.load(photoPath)) { meta.setImageDimensions(image.size()); // NOTE: see B.K.O #153207: Flickr use IPTC keywords to create Tags in web interface // As IPTC do not support UTF-8, we need to remove it. meta.removeIptcTag("Iptc.Application2.Keywords", false); meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); meta.save(path); } else { kWarning() << "(flickrExport::Image doesn't have metadata)"; } kDebug() << "Resizing and saving to temp file: " << path; } if (!form.addFile("photo", path)) { return false; } form.finish(); KIO::TransferJob* job = KIO::http_post(url, form.formData(), KIO::HideProgressInfo); job->addMetaData("content-type", form.contentType()); connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(data(KIO::Job*,QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_state = FE_ADDPHOTO; m_job = job; m_buffer.resize(0); emit signalBusy(true); return true; }
void IPTCEnvelope::applyMetadata(QByteArray& iptcData) { KPMetadata meta; meta.setIptc(iptcData); if (d->destinationCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.Destination", d->destinationEdit->toPlainText()); } else { meta.removeIptcTag("Iptc.Envelope.Destination"); } if (d->envelopeIDCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.EnvelopeNumber", d->envelopeIDEdit->text()); } else { meta.removeIptcTag("Iptc.Envelope.EnvelopeNumber"); } if (d->serviceIDCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.ServiceId", d->serviceIDEdit->text()); } else { meta.removeIptcTag("Iptc.Envelope.ServiceId"); } if (d->unoIDCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.UNO", d->unoIDEdit->text()); } else { meta.removeIptcTag("Iptc.Envelope.UNO"); } if (d->productIDCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.ProductId", d->productIDEdit->text()); } else { meta.removeIptcTag("Iptc.Envelope.ProductId"); } if (d->priorityCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.EnvelopePriority", QString::number(d->priorityCB->currentIndex())); } else if (d->priorityCheck->isValid()) { meta.removeIptcTag("Iptc.Envelope.EnvelopePriority"); } if (d->formatCheck->isChecked()) { QString key; int i = 0; for (IPTCEnvelopePriv::FileFormatMap::Iterator it = d->fileFormatMap.begin(); it != d->fileFormatMap.end(); ++it) { if (i == d->formatCB->currentIndex()) key = it.key(); i++; } QString format = key.section('-', 0, 0); QString version = key.section('-', -1); meta.setIptcTagString("Iptc.Envelope.FileFormat", format); meta.setIptcTagString("Iptc.Envelope.FileVersion", version); } else if (d->priorityCheck->isValid()) { meta.removeIptcTag("Iptc.Envelope.FileFormat"); meta.removeIptcTag("Iptc.Envelope.FileVersion"); } if (d->dateSentCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.DateSent", d->dateSentSel->date().toString(Qt::ISODate)); } else { meta.removeIptcTag("Iptc.Envelope.DateSent"); } if (d->timeSentCheck->isChecked()) { meta.setIptcTagString("Iptc.Envelope.TimeSent", d->timeSentSel->time().toString(Qt::ISODate) + d->zoneSentSel->getTimeZone()); } else { meta.removeIptcTag("Iptc.Envelope.TimeSent"); } meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); iptcData = meta.getIptc(); }
void EXIFDevice::applyMetadata(QByteArray& exifData) { KPMetadata meta; meta.setExif(exifData); long int num=1, den=1; if (d->makeCheck->isChecked()) meta.setExifTagString("Exif.Image.Make", d->makeEdit->text()); else meta.removeExifTag("Exif.Image.Make"); if (d->modelCheck->isChecked()) meta.setExifTagString("Exif.Image.Model", d->modelEdit->text()); else meta.removeExifTag("Exif.Image.Model"); if (d->deviceTypeCheck->isChecked()) meta.setExifTagLong("Exif.Photo.FileSource", d->deviceTypeCB->currentIndex()+1); else if (d->deviceTypeCheck->isValid()) meta.removeExifTag("Exif.Photo.FileSource"); if (d->exposureTimeCheck->isChecked()) { meta.setExifTagRational("Exif.Photo.ExposureTime", d->exposureTimeNumEdit->value(), d->exposureTimeDenEdit->value()); double exposureTime = (double)(d->exposureTimeNumEdit->value())/ (double)(d->exposureTimeDenEdit->value()); double shutterSpeed = (-1.0)*(std::log(exposureTime)/std::log(2.0)); meta.convertToRational(shutterSpeed, &num, &den, 8); meta.setExifTagRational("Exif.Photo.ShutterSpeedValue", num, den); } else { meta.removeExifTag("Exif.Photo.ExposureTime"); meta.removeExifTag("Exif.Photo.ShutterSpeedValue"); } if (d->exposureProgramCheck->isChecked()) meta.setExifTagLong("Exif.Photo.ExposureProgram", d->exposureProgramCB->currentIndex()); else if (d->exposureProgramCheck->isValid()) meta.removeExifTag("Exif.Photo.ExposureProgram"); if (d->exposureModeCheck->isChecked()) meta.setExifTagLong("Exif.Photo.ExposureMode", d->exposureModeCB->currentIndex()); else if (d->exposureModeCheck->isValid()) meta.removeExifTag("Exif.Photo.ExposureMode"); if (d->exposureBiasCheck->isChecked()) { meta.convertToRational(d->exposureBiasEdit->value(), &num, &den, 1); meta.setExifTagRational("Exif.Photo.ExposureBiasValue", num, den); } else { meta.removeExifTag("Exif.Photo.ExposureBiasValue"); } if (d->meteringModeCheck->isChecked()) { long met = d->meteringModeCB->currentIndex(); meta.setExifTagLong("Exif.Photo.MeteringMode", met > 6 ? 255 : met); } else if (d->meteringModeCheck->isValid()) meta.removeExifTag("Exif.Photo.MeteringMode"); if (d->ISOSpeedCheck->isChecked()) { meta.setExifTagLong("Exif.Photo.ISOSpeedRatings", d->ISOSpeedCB->currentText().toLong()); meta.convertToRational(d->ISOSpeedCB->currentText().toDouble(), &num, &den, 1); meta.setExifTagRational("Exif.Photo.ExposureIndex", num, den); } else if (d->ISOSpeedCheck->isValid()) { meta.removeExifTag("Exif.Photo.ISOSpeedRatings"); meta.removeExifTag("Exif.Photo.ExposureIndex"); } if (d->sensingMethodCheck->isChecked()) { long sem = d->sensingMethodCB->currentIndex(); meta.setExifTagLong("Exif.Photo.SensingMethod", sem > 4 ? sem+2 : sem+1); } else if (d->sensingMethodCheck->isValid()) { meta.removeExifTag("Exif.Photo.SensingMethod"); } if (d->sceneTypeCheck->isChecked()) meta.setExifTagLong("Exif.Photo.SceneCaptureType", d->sceneTypeCB->currentIndex()); else if (d->sceneTypeCheck->isValid()) meta.removeExifTag("Exif.Photo.SceneCaptureType"); if (d->subjectDistanceTypeCheck->isChecked()) meta.setExifTagLong("Exif.Photo.SubjectDistanceRange", d->subjectDistanceTypeCB->currentIndex()); else if (d->subjectDistanceTypeCheck->isValid()) meta.removeExifTag("Exif.Photo.SubjectDistanceRange"); #if KEXIV2_VERSION >= 0x010000 exifData = meta.getExifEncoded(); #else exifData = meta.getExif(); #endif }