summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-06-16 07:44:59 +0200
committerMontel Laurent <[email protected]>2015-06-16 07:44:59 +0200
commit7b928f3b5f76520960357616e737a9b2f9777d78 (patch)
treed7560957fdf4c13926e82b37f260b2b884e61388
parentb9d88a5f1b2d2a814572437c32b456cceb22fa23 (diff)
Fix Bug 349180 - resizing attached images corrupts the images
BUG: 349180 FIXED-IN: 4.14.10 Now we don't change image format if not necessary
-rw-r--r--messagecomposer/composer/composer.cpp1
-rw-r--r--messagecomposer/imagescaling/imagescaling.cpp36
-rw-r--r--messagecomposer/imagescaling/imagescaling.h2
-rw-r--r--messagecomposer/imagescaling/ui/imagescalingwidget.ui2
4 files changed, 33 insertions, 8 deletions
diff --git a/messagecomposer/composer/composer.cpp b/messagecomposer/composer/composer.cpp
index e07502c..1671561 100644
--- a/messagecomposer/composer/composer.cpp
+++ b/messagecomposer/composer/composer.cpp
@@ -510,6 +510,7 @@ void Composer::addAttachmentPart( AttachmentPart::Ptr part, bool autoresizeImage
if (MessageComposer::Utils::resizeImage(part)) {
MessageComposer::ImageScaling autoResizeJob;
autoResizeJob.setName(part->name());
+ autoResizeJob.setMimetype(part->mimeType());
if(autoResizeJob.loadImageFromData(part->data())) {
if(autoResizeJob.resizeImage()) {
part->setData(autoResizeJob.imageArray());
diff --git a/messagecomposer/imagescaling/imagescaling.cpp b/messagecomposer/imagescaling/imagescaling.cpp
index f2b0005..0a39ec9 100644
--- a/messagecomposer/imagescaling/imagescaling.cpp
+++ b/messagecomposer/imagescaling/imagescaling.cpp
@@ -91,7 +91,16 @@ bool ImageScaling::resizeImage()
if ((newHeight != height) || (newWidth != width)) {
mBuffer.open(QIODevice::WriteOnly);
mImage = mImage.scaled(newWidth,newHeight, MessageComposer::MessageComposerSettings::self()->keepImageRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio);
- const bool result = mImage.save(&mBuffer,MessageComposer::MessageComposerSettings::self()->writeFormat().toLocal8Bit());
+
+ QByteArray format;
+ if (mMimeType == "image/jpeg") {
+ format = "JPG";
+ } else if (mMimeType == "image/png") {
+ format = "PNG";
+ } else {
+ format = MessageComposer::MessageComposerSettings::self()->writeFormat().toLocal8Bit();
+ }
+ const bool result = mImage.save(&mBuffer, format);
mBuffer.close();
return result;
} else {
@@ -103,16 +112,25 @@ bool ImageScaling::resizeImage()
QByteArray ImageScaling::mimetype() const
{
- //Add more mimetype if a day we add more saving format.
- const QString type = MessageComposer::MessageComposerSettings::self()->writeFormat();
- if (type == QLatin1String("JPG")) {
- return "image/jpeg";
- } else if (type == QLatin1String("PNG")) {
- return "image/png";
+ if ((mMimeType == "image/jpeg") || (mMimeType == "image/png")) {
+ return mMimeType;
+ } else {
+ //Add more mimetype if a day we add more saving format.
+ const QString type = MessageComposer::MessageComposerSettings::self()->writeFormat();
+ if (type == QLatin1String("JPG")) {
+ return "image/jpeg";
+ } else if (type == QLatin1String("PNG")) {
+ return "image/png";
+ }
}
return QByteArray();
}
+void ImageScaling::setMimetype(const QByteArray &mimetype)
+{
+ mMimeType = mimetype;
+}
+
void ImageScaling::setName(const QString &name)
{
mName = name;
@@ -125,6 +143,10 @@ QByteArray ImageScaling::imageArray() const
QString ImageScaling::generateNewName()
{
+ // Don't rename it.
+ if ((mMimeType == "image/jpeg") || (mMimeType == "image/png")) {
+ return mName;
+ }
const QString type = MessageComposer::MessageComposerSettings::self()->writeFormat();
if (mName.endsWith(QLatin1String(".png"))) {
if (type != QLatin1String("PNG")) {
diff --git a/messagecomposer/imagescaling/imagescaling.h b/messagecomposer/imagescaling/imagescaling.h
index 3b3bcbd..fa1bf97 100644
--- a/messagecomposer/imagescaling/imagescaling.h
+++ b/messagecomposer/imagescaling/imagescaling.h
@@ -52,6 +52,7 @@ public:
* @return new image mimetype after saving.
*/
QByteArray mimetype() const;
+ void setMimetype(const QByteArray &mimetype);
void setName(const QString &name);
@@ -60,6 +61,7 @@ private:
QImage mImage;
QBuffer mBuffer;
QString mName;
+ QByteArray mMimeType;
};
}
diff --git a/messagecomposer/imagescaling/ui/imagescalingwidget.ui b/messagecomposer/imagescaling/ui/imagescalingwidget.ui
index d2052b9..5e1dde2 100644
--- a/messagecomposer/imagescaling/ui/imagescalingwidget.ui
+++ b/messagecomposer/imagescaling/ui/imagescalingwidget.ui
@@ -47,7 +47,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
- <string>Write to format</string>
+ <string>Fallback to format:</string>
</property>
</widget>
</item>