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

Gustavo Pichorim Boiko gustavo.boiko at canonical.com
Fri Jul 4 17:15:18 UTC 2014


Review: Needs Fixing

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

Diff comments:

> === modified file 'handler/texthandler.cpp'
> --- handler/texthandler.cpp	2014-06-25 12:19:20 +0000
> +++ handler/texthandler.cpp	2014-07-03 19:59:02 +0000
> @@ -25,6 +25,7 @@
>  #include "config.h"
>  #include "dbustypes.h"
>  
> +#include <QImage>
>  #include <TelepathyQt/ContactManager>
>  #include <TelepathyQt/PendingContacts>
>  
> @@ -130,6 +131,7 @@
>      header["message-type"] = QDBusVariant(0);
>      message << header;
>      Q_FOREACH(const AttachmentStruct &attachment, attachments) {
> +        QByteArray fileData;
>          QString newFilePath = QString(attachment.filePath).replace("file://", "");
>          QFile attachmentFile(newFilePath);
>          if (!attachmentFile.open(QIODevice::ReadOnly)) {
> @@ -139,14 +141,31 @@
>          if (attachment.contentType.startsWith("image/")) {
>              regions += QString(SMIL_IMAGE_REGION).arg(attachment.id);
>              parts += QString(SMIL_IMAGE_PART).arg(QFileInfo(attachmentFile.fileName()).fileName()).arg(attachment.id);
> +            // check if we need to reduce de image size in case it's bigger than 300k
> +            if (attachmentFile.size() > 1024*300) {

Can you replace 1024*300 by the actual value (307200)?

> +                QImage scaledImage(newFilePath);
> +                if (!scaledImage.isNull()) {
> +                    QBuffer buffer(&fileData);
> +                    buffer.open(QIODevice::WriteOnly);
> +                    if (scaledImage.height() > scaledImage.width()) {
> +                        scaledImage.scaledToHeight(640).save(&buffer, "jpg");
> +                    } else {
> +                        scaledImage.scaledToWidth(640).save(&buffer, "jpg");
> +                    }
> +                } else {

You can replace the width and height checking by this:
scaledImage.scale(640, 640, Qt::KeepAspectRatio).save(&buffer, "jpg");

> +                    fileData = attachmentFile.readAll();
> +                }
> +            } else {
> +                fileData = attachmentFile.readAll();
> +            }
>          } else if (attachment.contentType.startsWith("text/")) {
>              regions += QString(SMIL_TEXT_REGION).arg(attachment.id);
>              parts += QString(SMIL_TEXT_PART).arg(QFileInfo(attachmentFile.fileName()).fileName()).arg(attachment.id);
> +            fileData = attachmentFile.readAll();
>          } else {
>              continue;
>          }
>  
> -        QByteArray fileData = attachmentFile.readAll();
>          Tp::MessagePart part;
>          part["content-type"] =  QDBusVariant(attachment.contentType);
>          part["identifier"] = QDBusVariant(attachment.id);
> 


-- 
https://code.launchpad.net/~tiagosh/telephony-service/fix-attachment-size/+merge/225562
Your team Ubuntu Phablet Team is subscribed to branch lp:telephony-service.



More information about the Ubuntu-reviews mailing list