Skip to content

Commit

Permalink
Select image resolution based on screen dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Seppälä committed Aug 19, 2015
1 parent 49ccc29 commit 75579d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/vk/vk-posts/vk-posts.pro
Expand Up @@ -8,6 +8,8 @@ include($$PWD/../../common.pri)
include($$PWD/../vk-common.pri)
include($$PWD/vk-posts.pri)

PKGCONFIG += mlite5

vk_posts_sync_profile.path = /etc/buteo/profiles/sync
vk_posts_sync_profile.files = $$PWD/vk.Posts.xml
vk_posts_client_plugin_xml.path = /etc/buteo/profiles/client
Expand Down
32 changes: 31 additions & 1 deletion src/vk/vk-posts/vkpostsyncadaptor.cpp
Expand Up @@ -16,6 +16,8 @@
#include <QtCore/QJsonDocument>
#include <QtCore/QUrlQuery>

#include <MGConfItem>

#define SOCIALD_VK_POSTS_ID_PREFIX QStringLiteral("vk-posts-")
#define SOCIALD_VK_POSTS_GROUPNAME QStringLiteral("vk")

Expand Down Expand Up @@ -60,6 +62,7 @@ void VKPostSyncAdaptor::finalize(int accountId)
} else {
SOCIALD_LOG_DEBUG("finalizing VK posts sync with account:" << accountId);
m_db.removePosts(accountId); // always purge all posts for the account, prior to saving most recent.
determineOptimalImageSize();
Q_FOREACH (const PostData &post, m_postsToAdd) {
saveVKPostFromObject(post.accountId, post.post, post.userProfiles, post.groupProfiles);
}
Expand Down Expand Up @@ -212,7 +215,7 @@ void VKPostSyncAdaptor::saveVKPostFromObject(int accountId, const QJsonObject &p
if (type == QStringLiteral("photo")
|| type == QStringLiteral("posted_photo")
|| type == QStringLiteral("graffiti")) {
QString src = typedValue.value(QStringLiteral("photo_1280")).toString();
QString src = typedValue.value(m_optimalImageSize).toString();
if (!src.isEmpty()) {
images.append(qMakePair(src, SocialPostImage::Photo));
}
Expand Down Expand Up @@ -269,3 +272,30 @@ void VKPostSyncAdaptor::saveVKPostFromObject(int accountId, const QJsonObject &p

m_db.addVKPost(identifier, createdTime, body, newPost, images, posterName, posterIcon, accountId);
}


void VKPostSyncAdaptor::determineOptimalImageSize()
{
int width = 0, height = 0;
const int defaultValue = 0;
MGConfItem widthConf("/lipstick/screen/primary/width");
if (widthConf.value(defaultValue).toInt() != defaultValue) {
width = widthConf.value(defaultValue).toInt();
}
MGConfItem heightConf("/lipstick/screen/primary/height");
if (heightConf.value(defaultValue).toInt() != defaultValue) {
height = heightConf.value(defaultValue).toInt();
}

// we want to use the largest of these dimensions as the "optimal"
int maxDimension = qMax(width, height);
if (maxDimension >= 2048) {
m_optimalImageSize = "photo_1280";
} else if (maxDimension >= 960) {
m_optimalImageSize = "photo_604";
} else {
m_optimalImageSize = "photo_75";
}

SOCIALD_LOG_DEBUG("Determined optimal image size for dimension " << maxDimension << " as " << m_optimalImageSize);
}
2 changes: 2 additions & 0 deletions src/vk/vk-posts/vkpostsyncadaptor.h
Expand Up @@ -38,6 +38,7 @@ class VKPostSyncAdaptor : public VKDataTypeSyncAdaptor

private:
void requestPosts(int accountId, const QString &accessToken);
void determineOptimalImageSize();

private Q_SLOTS:
void finishedPostsHandler();
Expand All @@ -57,6 +58,7 @@ private Q_SLOTS:
};
QList<PostData> m_postsToAdd;
VKPostsDatabase m_db;
QString m_optimalImageSize;
};

#endif // VKPOSTSYNCADAPTOR_H

0 comments on commit 75579d9

Please sign in to comment.