Merge lp:~tiagosh/telephony-service/fix-attachment-size into lp:telephony-service

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 840
Merged at revision: 845
Proposed branch: lp:~tiagosh/telephony-service/fix-attachment-size
Merge into: lp:telephony-service
Diff against target: 48 lines (+16/-1)
1 file modified
handler/texthandler.cpp (+16/-1)
To merge this branch: bzr merge lp:~tiagosh/telephony-service/fix-attachment-size
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+225562@code.launchpad.net

Commit message

Reduce image sizes before sending them to telepathy. MMS's have a limit of 300k

Description of the change

Reduce image sizes before sending them to telepathy. MMS's have a limit of 300k.

--Checklist--

Are there any related MPs required for this MP to build/function as expected? Please list.
No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/telephony-service) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Can you please fix the two inline diff comments and also merge latest changes from trunk in your MR?

review: Needs Fixing
840. By Tiago Salem Herrmann

improve the width and height check

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
No, but not related to this MR.

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

Code looks good now and works as expected!

review: Approve
841. By Tiago Salem Herrmann

merge trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'handler/texthandler.cpp'
2--- handler/texthandler.cpp 2014-06-25 12:19:20 +0000
3+++ handler/texthandler.cpp 2014-07-09 13:50:35 +0000
4@@ -25,6 +25,7 @@
5 #include "config.h"
6 #include "dbustypes.h"
7
8+#include <QImage>
9 #include <TelepathyQt/ContactManager>
10 #include <TelepathyQt/PendingContacts>
11
12@@ -130,6 +131,7 @@
13 header["message-type"] = QDBusVariant(0);
14 message << header;
15 Q_FOREACH(const AttachmentStruct &attachment, attachments) {
16+ QByteArray fileData;
17 QString newFilePath = QString(attachment.filePath).replace("file://", "");
18 QFile attachmentFile(newFilePath);
19 if (!attachmentFile.open(QIODevice::ReadOnly)) {
20@@ -139,14 +141,27 @@
21 if (attachment.contentType.startsWith("image/")) {
22 regions += QString(SMIL_IMAGE_REGION).arg(attachment.id);
23 parts += QString(SMIL_IMAGE_PART).arg(QFileInfo(attachmentFile.fileName()).fileName()).arg(attachment.id);
24+ // check if we need to reduce de image size in case it's bigger than 300k
25+ if (attachmentFile.size() > 307200) {
26+ QImage scaledImage(newFilePath);
27+ if (!scaledImage.isNull()) {
28+ QBuffer buffer(&fileData);
29+ buffer.open(QIODevice::WriteOnly);
30+ scaledImage.scaled(640, 640, Qt::KeepAspectRatio).save(&buffer, "jpg");
31+ } else {
32+ fileData = attachmentFile.readAll();
33+ }
34+ } else {
35+ fileData = attachmentFile.readAll();
36+ }
37 } else if (attachment.contentType.startsWith("text/")) {
38 regions += QString(SMIL_TEXT_REGION).arg(attachment.id);
39 parts += QString(SMIL_TEXT_PART).arg(QFileInfo(attachmentFile.fileName()).fileName()).arg(attachment.id);
40+ fileData = attachmentFile.readAll();
41 } else {
42 continue;
43 }
44
45- QByteArray fileData = attachmentFile.readAll();
46 Tp::MessagePart part;
47 part["content-type"] = QDBusVariant(attachment.contentType);
48 part["identifier"] = QDBusVariant(attachment.id);

Subscribers

People subscribed via source and target branches