Merge lp:~libqtelegram-team/telegram-app/android-images-not-shown-in-secret-chats into lp:telegram-app/dev

Proposed by Roberto Mier Escandon
Status: Merged
Approved by: Michał Karnicki
Approved revision: 170
Merged at revision: 170
Proposed branch: lp:~libqtelegram-team/telegram-app/android-images-not-shown-in-secret-chats
Merge into: lp:telegram-app/dev
Diff against target: 170 lines (+43/-11)
9 files modified
lib/CMakeLists.txt (+1/-1)
lib/secret/decryptedmessagebuilder.cpp (+2/-2)
lib/secret/decryptedmessagebuilder.h (+5/-5)
lib/telegram.cpp (+7/-1)
qmlplugin/CMakeLists.txt (+2/-1)
qmlplugin/config.h (+1/-0)
qmlplugin/telegramservice.cpp (+3/-0)
qmlplugin/tools.cpp (+21/-1)
qmlplugin/tools.h (+1/-0)
To merge this branch: bzr merge lp:~libqtelegram-team/telegram-app/android-images-not-shown-in-secret-chats
Reviewer Review Type Date Requested Status
Michał Karnicki (community) Needs Information
Review via email: mp+248876@code.launchpad.net

Description of the change

Scaled image to have a max of 4096 in width or heigth, maintaining the aspect ratio, for secret chats.

This prevents blank screen on Android devices when shown preview

To post a comment you must log in.
169. By Roberto Mier Escandon

limitted image width or height to 2048

Revision history for this message
Michał Karnicki (karni) :
review: Needs Information
170. By Roberto Mier Escandon

set default width and height for photo set to 0 in case of photos to be sent to secret chats

Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

answered

Revision history for this message
Michał Karnicki (karni) wrote :

+1 once tested with 1 portrait and 1 landscape picture to iOS

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/CMakeLists.txt'
2--- lib/CMakeLists.txt 2015-01-30 08:20:13 +0000
3+++ lib/CMakeLists.txt 2015-02-11 12:02:02 +0000
4@@ -33,7 +33,7 @@
5 secret/decryptedmessagebuilder.cpp)
6 set_property(TARGET ${LIB_NAME} PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS} -fpermissive")
7 set_target_properties(${LIB_NAME} PROPERTIES VERSION ${VERSION} SOVERSION 1)
8-qt5_use_modules(${LIB_NAME} Network)
9+qt5_use_modules(${LIB_NAME} Network Multimedia)
10 target_link_libraries(${LIB_NAME} ${OPENSSL_LDFLAGS})
11
12 if (IS_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
13
14=== modified file 'lib/secret/decryptedmessagebuilder.cpp'
15--- lib/secret/decryptedmessagebuilder.cpp 2015-02-03 17:18:25 +0000
16+++ lib/secret/decryptedmessagebuilder.cpp 2015-02-11 12:02:02 +0000
17@@ -66,8 +66,8 @@
18 }
19
20 DecryptedMessage DecryptedMessageBuilder::buildDecryptedMessageForSendPhoto(qint64 randomId, qint32 ttl, const QByteArray &key, const QByteArray &iv, qint32 size,
21- const QByteArray &thumb, qint32 thumbW, qint32 thumbH,
22- qint32 width, qint32 height) {
23+ qint32 width, qint32 height,
24+ const QByteArray &thumb, qint32 thumbW, qint32 thumbH) {
25
26 DecryptedMessageMedia media(DecryptedMessageMedia::typeDecryptedMessageMediaPhoto);
27 media.setThumb(thumb);
28
29=== modified file 'lib/secret/decryptedmessagebuilder.h'
30--- lib/secret/decryptedmessagebuilder.h 2015-02-03 17:18:25 +0000
31+++ lib/secret/decryptedmessagebuilder.h 2015-02-11 12:02:02 +0000
32@@ -17,12 +17,12 @@
33 DecryptedMessage buildDecryptedMessageForTtl(qint64 randomId, qint32 ttl);
34 DecryptedMessage buildDecryptedMessageForResend(qint64 randomId, qint32 startSeqNo, qint32 endSeqNo);
35 DecryptedMessage buildDecryptedMessageForSendPhoto(qint64 randomId, qint32 ttl, const QByteArray &key, const QByteArray &iv, qint32 size = 0,
36- const QByteArray &thumb = QByteArray(), qint32 thumbW = 90, qint32 thumbH = 90,
37- qint32 width = 100, qint32 height = 100);
38+ qint32 width = 0, qint32 height = 0,
39+ const QByteArray &thumb = QByteArray(), qint32 thumbW = 90, qint32 thumbH = 90);
40 DecryptedMessage buildDecryptedMessageForSendVideo(qint64 randomId, qint32 ttl, const QByteArray &key, const QByteArray &iv, qint32 size = 0,
41- const QString &mimeType = QString(),
42- qint32 duration = 0, qint32 width = 0, qint32 height = 0,
43- const QByteArray &thumb = QByteArray(), qint32 thumbW = 90, qint32 thumbH = 90);
44+ const QString &mimeType = QString(),
45+ qint32 duration = 0, qint32 width = 0, qint32 height = 0,
46+ const QByteArray &thumb = QByteArray(), qint32 thumbW = 90, qint32 thumbH = 90);
47
48 private:
49 qint32 mLayer;
50
51=== modified file 'lib/telegram.cpp'
52--- lib/telegram.cpp 2015-02-04 15:57:51 +0000
53+++ lib/telegram.cpp 2015-02-11 12:02:02 +0000
54@@ -33,6 +33,7 @@
55 #include <QFileInfo>
56 #include <QMimeDatabase>
57 #include <QtEndian>
58+#include <QImage>
59
60 #include "core/tlvalues.h"
61
62@@ -422,8 +423,13 @@
63 QFileInfo fileInfo(filePath);
64 qint32 size = fileInfo.size();
65
66+ QImage image;
67+ image.load(filePath);
68+ qint32 width = image.width();
69+ qint32 height = image.height();
70+
71 DecryptedMessageBuilder builder(secretChat->layer());
72- DecryptedMessage decryptedMessage = builder.buildDecryptedMessageForSendPhoto(randomId, ttl, key, iv, size);
73+ DecryptedMessage decryptedMessage = builder.buildDecryptedMessageForSendPhoto(randomId, ttl, key, iv, size, width, height);
74 op->setDecryptedMessage(decryptedMessage);
75
76 return uploadSendFile(*op, filePath);
77
78=== modified file 'qmlplugin/CMakeLists.txt'
79--- qmlplugin/CMakeLists.txt 2015-02-03 08:56:27 +0000
80+++ qmlplugin/CMakeLists.txt 2015-02-11 12:02:02 +0000
81@@ -1,4 +1,5 @@
82 find_package(Qt5Network REQUIRED)
83+find_package(Qt5Multimedia REQUIRED)
84 pkg_check_modules(SQLITE3 REQUIRED sqlite3)
85 pkg_check_modules(THUMBNAILER thumbnailer REQUIRED)
86 pkg_check_modules(MEDIAINFO libmediainfo REQUIRED)
87@@ -129,7 +130,7 @@
88 string(REGEX REPLACE "\\." "/" MODULE_OUTPUT_DIR ${MODULE_NAME})
89
90 set_target_properties(${QMLPLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${MODULE_OUTPUT_DIR})
91-qt5_use_modules(${QMLPLUGIN_NAME} Gui Qml Quick Sql)
92+qt5_use_modules(${QMLPLUGIN_NAME} Gui Qml Quick Sql Multimedia)
93
94 # Create qmldir content
95 file(WRITE qmldir "module " ${MODULE_NAME}\n)
96
97=== modified file 'qmlplugin/config.h'
98--- qmlplugin/config.h 2014-10-31 08:50:53 +0000
99+++ qmlplugin/config.h 2015-02-11 12:02:02 +0000
100@@ -22,6 +22,7 @@
101 #define PHOTOS_MEDIA_FOLDER "photos"
102 #define VIDEOS_MEDIA_FOLDER "videos"
103 #define OUTGOING_MEDIA_FOLDER "outgoing"
104+#define PHOTO_MAX_DIMENSION 2048
105
106 #include <QString>
107 #include <QLoggingCategory>
108
109=== modified file 'qmlplugin/telegramservice.cpp'
110--- qmlplugin/telegramservice.cpp 2015-02-04 21:41:51 +0000
111+++ qmlplugin/telegramservice.cpp 2015-02-11 12:02:02 +0000
112@@ -669,6 +669,9 @@
113 return -1;
114 }
115
116+ // Android secret chat only previews photos with max size 4096x4096
117+ Tools::resizePhotoIfNeeded(photoLocalPath);
118+
119 qint64 randomId = Tools::generateRandomId();
120 qint64 requestId = mTelegramLib->messagesSendEncryptedPhoto(chatId, randomId, ttl, photoLocalPath);
121 DecryptedMessage message;
122
123=== modified file 'qmlplugin/tools.cpp'
124--- qmlplugin/tools.cpp 2015-02-03 08:56:27 +0000
125+++ qmlplugin/tools.cpp 2015-02-11 12:02:02 +0000
126@@ -19,6 +19,7 @@
127 */
128 #include "tools.h"
129 #include "core/utils.h"
130+#include "config.h"
131 #include <iostream>
132 #include <stdexcept>
133 #include <QMimeDatabase>
134@@ -209,4 +210,23 @@
135 return jpegFile;
136 }
137
138-
139+void Tools::resizePhotoIfNeeded(const QString &photoFilePath) {
140+ QImage image;
141+ image.load(photoFilePath);
142+ qint32 originalWidth = image.width();
143+ qint32 originalHeight = image.height();
144+
145+ qint32 max = originalWidth > originalHeight ? originalWidth : originalHeight;
146+
147+ if (max > PHOTO_MAX_DIMENSION) {
148+ QImage small;
149+ if (originalWidth == max) {
150+ small = image.scaled(PHOTO_MAX_DIMENSION, originalHeight, Qt::KeepAspectRatio);
151+ } else if (originalHeight == max) {
152+ small = image.scaled(originalWidth, PHOTO_MAX_DIMENSION, Qt::KeepAspectRatio);
153+ }
154+ qCDebug(TG_PLUGIN_LOGIC) << "original size " << originalWidth << "x" << originalHeight << "reduced to"
155+ << small.width() << "x" << small.height();
156+ small.save(photoFilePath);
157+ }
158+}
159
160=== modified file 'qmlplugin/tools.h'
161--- qmlplugin/tools.h 2015-02-03 08:56:27 +0000
162+++ qmlplugin/tools.h 2015-02-11 12:02:02 +0000
163@@ -44,6 +44,7 @@
164 static MessageMedia::MessageMediaType toMessageMediaType(DecryptedMessageMedia::DecryptedMessageMediaType decryptedMessageMediaType);
165 static qint32 getBelongingDialogId(const Message &message);
166 static QString pngToJpeg(const QString &pngFile, qint32 quality = -1);
167+ static void resizePhotoIfNeeded(const QString &photoFilePath);
168 };
169
170 #endif // TOOLS_H

Subscribers

People subscribed via source and target branches

to all changes: