Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions app/imageutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "coreutils.h"

#include <QFile>
#include <QFileInfo>
#include <QImage>

Expand All @@ -24,28 +23,33 @@ bool ImageUtils::copyExifMetadata( const QString &sourceImage, const QString &ta

try
{
std::unique_ptr< Exiv2::Image > srcImage( Exiv2::ImageFactory::open( sourceImage.toStdString() ) );
const std::unique_ptr srcImage( Exiv2::ImageFactory::open( sourceImage.toStdString() ) );
if ( !srcImage )
return false;

std::unique_ptr< Exiv2::Image > dstImage( Exiv2::ImageFactory::open( targetImage.toStdString() ) );
if ( !dstImage )
return false;

srcImage->readMetadata();
Exiv2::ExifData &exifData = srcImage->exifData();
const Exiv2::ExifData &exifData = srcImage->exifData();
if ( exifData.empty() )
{
return true;
}

const std::unique_ptr dstImage( Exiv2::ImageFactory::open( targetImage.toStdString() ) );
if ( !dstImage )
return false;

dstImage->setExifData( exifData );
dstImage->writeMetadata();
return true;
}
catch ( Exiv2::Error &error )
{
CoreUtils::log( "Copying EXIF", error.what() );
return false;
}
catch ( ... )
{
CoreUtils::log( "copying EXIF", QStringLiteral( "Failed to copy EXIF metadata" ) );
CoreUtils::log( "Copying EXIF", QStringLiteral( "Failed to copy EXIF metadata" ) );
return false;
}
}
Expand Down Expand Up @@ -153,19 +157,17 @@ bool ImageUtils::clearOrientationMetadata( const QString &sourceImage )
}

const auto iterator = exifData.findKey( Exiv2::ExifKey( "Exif.Image.Orientation" ) );
if ( iterator == exifData.end() )
if ( iterator != exifData.end() )
{
return true;
exifData.erase( iterator );
}
exifData.erase( iterator );

srcImage->setExifData( exifData );
srcImage->writeMetadata();
return true;
}
catch ( ... )
{
CoreUtils::log( "copying EXIF", QStringLiteral( "Failed to copy EXIF metadata" ) );
CoreUtils::log( "Editing EXIF", QStringLiteral( "Failed to clear orientation EXIF metadata" ) );
return false;
}
}
1 change: 1 addition & 0 deletions app/imageutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ImageUtils

/**
* Copies EXIF metadata from sourceImage to targetImage.
* \note Developers need to make sure the paths don't reference the same file, it will cause empty metadata
*/
static bool copyExifMetadata( const QString &sourceImage, const QString &targetImage );

Expand Down
16 changes: 15 additions & 1 deletion app/photosketchingcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,35 @@ void PhotoSketchingController::backupSketches()
}
else
{
if ( ImageUtils::copyExifMetadata( QUrl( mPhotoSource ).toLocalFile(), photoPath ) && ImageUtils::clearOrientationMetadata( photoPath ) )
if ( ImageUtils::copyExifMetadata( mOriginalPhotoSource, photoPath ) && ImageUtils::clearOrientationMetadata( photoPath ) )
{
CoreUtils::log( "Photo sketching", "Temporary image saved to: " + photoPath );
emit tempPhotoSourceChanged( photoPath );
}
else
{
CoreUtils::log( "Photo sketching", "Failed to copy metadata to: " + photoPath );
InputUtils::removeFile( photoPath );
clear();
emit sketchesSavingError();
}
}

mActivePaths.clear();
mCanUndo = false;
}

void PhotoSketchingController::removeBackupSketches()
{
const QString photoFileName = QUrl( mPhotoSource ).fileName();
const QString photoPath = QString( "%1/%2/%3" ).arg( QDir::tempPath(), mProjectName, photoFileName );
if ( QFile::exists( photoPath ) )
{
InputUtils::removeFile( photoPath );
CoreUtils::log( "Photo sketching", "Removed temporary image from: " + photoPath );
}
}

void PhotoSketchingController::redrawPaths()
{
for ( int i = 0 ; i < mPaths.size(); ++i )
Expand Down
5 changes: 5 additions & 0 deletions app/photosketchingcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class PhotoSketchingController: public QObject
// saves the drawings into temporary image
Q_INVOKABLE void backupSketches();

// removes sketched file from temporary folder
Q_INVOKABLE void removeBackupSketches();

// redraws all paths in mPaths (used after user comes back to drawing screen)
Q_INVOKABLE void redrawPaths();

Expand Down Expand Up @@ -102,6 +105,8 @@ class PhotoSketchingController: public QObject
void lastPathRemoved();
void pathsReset();

void sketchesSavingError();

private:
double mPhotoScale = 1.0;
QString mPhotoSource;
Expand Down
6 changes: 6 additions & 0 deletions app/qml/form/editors/MMFormPhotoEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ MMFormPhotoViewer {
onDeleteImage: {
// schedule the image for deletion
internal.imageSourceToDelete = imageDeleteDialog.imagePath
root.sketchingController.removeBackupSketches()
root.sketchingController.clear()
resetValueAndClose()
}

Expand Down Expand Up @@ -176,6 +178,10 @@ MMFormPhotoViewer {
}
internal.tempSketchedImageSource = "file://" + newPath
}

function onSketchesSavingError(){
__notificationModel.addError( qsTr("Photo sketches could not be saved, please contact support.") )
}
}

Connections {
Expand Down
Loading