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; }
/*! \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]"); } } }