Bring own profile picture to the about page

This commit is contained in:
Sebastian J. Wolf 2020-08-14 10:33:42 +02:00
parent 1ef7d0b9ad
commit 41ac3c4829
6 changed files with 140 additions and 8 deletions

View file

@ -0,0 +1,76 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.5
import QtGraphicalEffects 1.0
import Sailfish.Silica 1.0
Item {
id: imageTumbnail
property variant imageData;
Image {
Component.onCompleted: {
if (imageData.local.is_downloading_completed) {
singleImage.source = imageData.local.path;
} else {
tdLibWrapper.downloadFile(imageData.id);
}
}
Connections {
target: tdLibWrapper
onFileUpdated: {
if (id === imageData.id) {
console.log("File updated, completed? " + fileInformation.local.is_downloading_completed);
imageTumbnail.imageData = fileInformation;
if (imageTumbnail.imageData.local.is_downloading_completed) {
singleImage.source = imageTumbnail.imageData.local.path;
}
}
}
}
id: singleImage
width: parent.width - Theme.paddingSmall
height: parent.height - Theme.paddingSmall
anchors.centerIn: parent
fillMode: Image.PreserveAspectCrop
autoTransform: true
asynchronous: true
}
Image {
id: imageLoadingBackgroundImage
source: "../../images/background" + ( Theme.colorScheme ? "-black" : "-white" ) + ".png"
anchors {
centerIn: parent
}
width: parent.width - 2 * Theme.paddingLarge
height: parent.height - 2 * Theme.paddingLarge
visible: singleImage.status !== Image.Ready
fillMode: Image.PreserveAspectFit
opacity: 0.15
}
}

View file

@ -18,16 +18,14 @@
*/ */
import QtQuick 2.0 import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import "../components"
import "../js/twemoji.js" as Emoji import "../js/twemoji.js" as Emoji
Page { Page {
id: aboutPage id: aboutPage
allowedOrientations: Orientation.All allowedOrientations: Orientation.All
function getUserName() { property variant userInformation : tdLibWrapper.getUserInformation();
var userInformation = tdLibWrapper.getUserInformation();
return Emoji.emojify(userInformation.first_name + " " + userInformation.last_name, Theme.fontSizeSmall);
}
SilicaFlickable { SilicaFlickable {
id: aboutContainer id: aboutContainer
@ -152,7 +150,7 @@ Page {
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
width: parent.width - ( 2 * Theme.horizontalPageMargin ) width: parent.width - ( 2 * Theme.horizontalPageMargin )
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
text: qsTr("Logged in as %1").arg(aboutPage.getUserName()) text: qsTr("Logged in as %1").arg(Emoji.emojify(aboutPage.userInformation.first_name + " " + aboutPage.userInformation.last_name, Theme.fontSizeSmall))
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap wrapMode: Text.Wrap
color: Theme.primaryColor color: Theme.primaryColor
@ -162,11 +160,20 @@ Page {
} }
} }
ImageThumbnail {
imageData: aboutPage.userInformation.profile_photo.big
width: Theme.itemSizeExtraLarge
height: Theme.itemSizeExtraLarge
anchors {
horizontalCenter: parent.horizontalCenter
}
}
Label { Label {
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
width: parent.width - ( 2 * Theme.horizontalPageMargin ) width: parent.width - ( 2 * Theme.horizontalPageMargin )
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
text: qsTr("Phone number: +%1").arg(tdLibWrapper.getUserInformation().phone_number) text: qsTr("Phone number: +%1").arg(aboutPage.userInformation.phone_number)
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap wrapMode: Text.Wrap
anchors { anchors {

View file

@ -69,6 +69,10 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateUser") { if (objectTypeName == "updateUser") {
this->processUpdateUser(receivedInformation); this->processUpdateUser(receivedInformation);
} }
if (objectTypeName == "updateFile") {
this->processUpdateFile(receivedInformation);
}
} }
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation) void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -105,3 +109,10 @@ void TDLibReceiver::processUpdateUser(const QVariantMap &receivedInformation)
qDebug() << "[TDLibReceiver] User was updated: " << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString(); qDebug() << "[TDLibReceiver] User was updated: " << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString();
emit userUpdated(userInformation); emit userUpdated(userInformation);
} }
void TDLibReceiver::processUpdateFile(const QVariantMap &receivedInformation)
{
QVariantMap fileInformation = receivedInformation.value("file").toMap();
qDebug() << "[TDLibReceiver] File was updated: " << fileInformation.value("id").toString();
emit fileUpdated(fileInformation);
}

View file

@ -41,6 +41,7 @@ signals:
void optionUpdated(const QString &optionName, const QVariant &optionValue); void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const QString &connectionState); void connectionStateChanged(const QString &connectionState);
void userUpdated(const QVariantMap &userInformation); void userUpdated(const QVariantMap &userInformation);
void fileUpdated(const QVariantMap &fileInformation);
private: private:
void *tdLibClient; void *tdLibClient;
@ -52,6 +53,7 @@ private:
void processUpdateAuthorizationState(const QVariantMap &receivedInformation); void processUpdateAuthorizationState(const QVariantMap &receivedInformation);
void processUpdateConnectionState(const QVariantMap &receivedInformation); void processUpdateConnectionState(const QVariantMap &receivedInformation);
void processUpdateUser(const QVariantMap &receivedInformation); void processUpdateUser(const QVariantMap &receivedInformation);
void processUpdateFile(const QVariantMap &receivedInformation);
}; };
#endif // TDLIBRECEIVER_H #endif // TDLIBRECEIVER_H

View file

@ -41,8 +41,11 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant))); connect(this->tdLibReceiver, SIGNAL(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant)));
connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString))); connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString)));
connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap))); connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(fileUpdated(QVariantMap)), this, SLOT(handleFileUpdated(QVariantMap)));
this->tdLibReceiver->start(); this->tdLibReceiver->start();
this->setLogVerbosityLevel();
} }
TDLibWrapper::~TDLibWrapper() TDLibWrapper::~TDLibWrapper()
@ -108,6 +111,19 @@ void TDLibWrapper::getChats()
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::downloadFile(const QString &fileId)
{
qDebug() << "[TDLibWrapper] Downloading file " << fileId;
QVariantMap requestObject;
requestObject.insert("@type", "downloadFile");
requestObject.insert("file_id", fileId);
requestObject.insert("synchronous", false);
requestObject.insert("offset", 0);
requestObject.insert("limit", 0);
requestObject.insert("priority", 1);
this->sendRequest(requestObject);
}
QVariantMap TDLibWrapper::getUserInformation() QVariantMap TDLibWrapper::getUserInformation()
{ {
return this->userInformation; return this->userInformation;
@ -208,6 +224,11 @@ void TDLibWrapper::handleUserUpdated(const QVariantMap &userInformation)
} }
} }
void TDLibWrapper::handleFileUpdated(const QVariantMap &userInformation)
{
emit fileUpdated(userInformation.value("id").toInt(), userInformation);
}
void TDLibWrapper::setInitialParameters() void TDLibWrapper::setInitialParameters()
{ {
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";
@ -240,3 +261,12 @@ void TDLibWrapper::setEncryptionKey()
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::setLogVerbosityLevel()
{
qDebug() << "[TDLibWrapper] Setting log verbosity level to something less chatty";
QVariantMap requestObject;
requestObject.insert("@type", "setLogVerbosityLevel");
requestObject.insert("new_verbosity_level", 2);
this->sendRequest(requestObject);
}

View file

@ -58,20 +58,24 @@ public:
}; };
Q_ENUM(ConnectionState) Q_ENUM(ConnectionState)
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
Q_INVOKABLE QString getVersion(); Q_INVOKABLE QString getVersion();
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState(); Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState(); Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
Q_INVOKABLE QVariantMap getUserInformation();
// Direct TDLib functions
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber); Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode);
Q_INVOKABLE void getChats(); Q_INVOKABLE void getChats();
Q_INVOKABLE QVariantMap getUserInformation(); Q_INVOKABLE void downloadFile(const QString &fileId);
signals: signals:
void versionDetected(const QString &version); void versionDetected(const QString &version);
void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState); void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState);
void optionUpdated(const QString &optionName, const QVariant &optionValue); void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState); void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState);
void fileUpdated(const int fileId, const QVariantMap fileInformation);
public slots: public slots:
void handleVersionDetected(const QString &version); void handleVersionDetected(const QString &version);
@ -79,6 +83,7 @@ public slots:
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue); void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
void handleConnectionStateChanged(const QString &connectionState); void handleConnectionStateChanged(const QString &connectionState);
void handleUserUpdated(const QVariantMap &userInformation); void handleUserUpdated(const QVariantMap &userInformation);
void handleFileUpdated(const QVariantMap &userInformation);
private: private:
void *tdLibClient; void *tdLibClient;
@ -91,6 +96,7 @@ private:
void setInitialParameters(); void setInitialParameters();
void setEncryptionKey(); void setEncryptionKey();
void setLogVerbosityLevel();
}; };