Commit b9d88a5f authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 349180 - resizing attached images corrupts the images

Rename image when we change extension.

CCBUG: 349180
parent 21700000
......@@ -509,10 +509,12 @@ void Composer::addAttachmentPart( AttachmentPart::Ptr part, bool autoresizeImage
if( autoresizeImage ) {
if (MessageComposer::Utils::resizeImage(part)) {
MessageComposer::ImageScaling autoResizeJob;
autoResizeJob.setName(part->name());
if(autoResizeJob.loadImageFromData(part->data())) {
if(autoResizeJob.resizeImage()) {
part->setData(autoResizeJob.imageArray());
part->setMimeType(autoResizeJob.mimetype());
part->setName(autoResizeJob.generateNewName());
MessageComposer::Utils::changeFileName(part);
}
}
......
......@@ -70,7 +70,6 @@ bool ImageScaling::resizeImage()
newHeight = height;
newWidth = width;
}
if (MessageComposer::MessageComposerSettings::self()->enlargeImageToMinimum()) {
int minimumWidth = MessageComposer::MessageComposerSettings::self()->minimumWidth();
......@@ -114,8 +113,33 @@ QByteArray ImageScaling::mimetype() const
return QByteArray();
}
void ImageScaling::setName(const QString &name)
{
mName = name;
}
QByteArray ImageScaling::imageArray() const
{
return mBuffer.data();
}
QString ImageScaling::generateNewName()
{
const QString type = MessageComposer::MessageComposerSettings::self()->writeFormat();
if (mName.endsWith(QLatin1String(".png"))) {
if (type != QLatin1String("PNG")) {
mName.replace(QLatin1String(".png"), QLatin1String(".jpg"));
}
} else if (mName.endsWith(QLatin1String(".jpg"))) {
if (type != QLatin1String("JPG")) {
mName.replace(QLatin1String(".jpg"), QLatin1String(".png"));
}
} else {
if (type == QLatin1String("PNG")) {
mName += QLatin1String(".png");
} else {
mName += QLatin1String(".jpg");
}
}
return mName;
}
......@@ -53,9 +53,13 @@ public:
*/
QByteArray mimetype() const;
void setName(const QString &name);
QString generateNewName();
private:
QImage mImage;
QBuffer mBuffer;
QString mName;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment