Add support for documents

This commit is contained in:
Sebastian J. Wolf 2020-08-28 16:18:33 +02:00
parent 0b77f1527d
commit ecf4c859e8
9 changed files with 162 additions and 9 deletions

View file

@ -24,6 +24,7 @@ SOURCES += src/harbour-fernschreiber.cpp \
DISTFILES += qml/harbour-fernschreiber.qml \
qml/components/AudioPreview.qml \
qml/components/DocumentPreview.qml \
qml/components/ImagePreview.qml \
qml/js/functions.js \
qml/pages/ChatPage.qml \

View file

@ -66,7 +66,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: {
tdLibWrapper.handleAdditionalInformation(notificationItem.additionalInformation);
tdLibWrapper.openFileOnDevice(notificationItem.additionalInformation);
}
visible: additionalInformation ? true : false
}

View file

@ -0,0 +1,94 @@
/*
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: documentPreviewItem
width: parent.width
height: Theme.itemSizeLarge
property variant documentData;
Component.onCompleted: {
updateDocument();
}
function updateDocument() {
if (typeof documentData === "object") {
if (documentData.document.local.is_downloading_completed) {
downloadDocumentButton.visible = false;
openDocumentButton.visible = true;
} else {
openDocumentButton.visible = false;
downloadDocumentButton.visible = true;
}
}
}
Connections {
target: tdLibWrapper
onFileUpdated: {
if (typeof documentData !== "undefined" && fileId === documentData.document.id) {
if (fileInformation.local.is_downloading_completed) {
downloadBusyIndicator.running = false;
documentData.document = fileInformation;
downloadDocumentButton.visible = false;
openDocumentButton.visible = true;
tdLibWrapper.openFileOnDevice(documentData.document.local.path);
}
}
}
}
Button {
id: downloadDocumentButton
preferredWidth: Theme.buttonWidthMedium
anchors.centerIn: parent
text: qsTr("Download Document")
visible: false
onClicked: {
downloadDocumentButton.visible = false;
downloadBusyIndicator.running = true;
tdLibWrapper.downloadFile(documentData.document.id);
}
}
BusyIndicator {
id: downloadBusyIndicator
running: false
size: BusyIndicatorSize.Medium
visible: running
anchors.centerIn: parent
}
Button {
id: openDocumentButton
preferredWidth: Theme.buttonWidthMedium
anchors.centerIn: parent
text: qsTr("Open Document")
visible: false
onClicked: {
tdLibWrapper.openFileOnDevice(documentData.document.local.path);
}
}
}

View file

@ -69,6 +69,13 @@ function getMessageText(message, simple) {
return simple ? qsTr("shared a voice note") : "";
}
}
if (message.content['@type'] === 'messageDocument') {
if (message.content.document.file_name !== "") {
return simple ? qsTr("Document: %1").arg(message.content.document.file_name) : message.content.document.file_name
} else {
return simple ? qsTr("shared a document") : "";
}
}
if (message.content['@type'] === 'messageLocation') {
return qsTr("shared their location");
}
@ -84,7 +91,7 @@ function getMessageText(message, simple) {
if (message.content['@type'] === 'messageChatDeleteMember') {
return qsTr("left this chat.");
}
return "?";
return qsTr("Unsupported message: %1").arg(message.content['@type'].substring(7));
}
function getDateTimeElapsed(timestamp) {

View file

@ -458,6 +458,12 @@ Page {
onScreen: chatPage.status === PageStatus.Active
}
DocumentPreview {
id: messageDocumentPreview
documentData: ( display.content['@type'] === "messageDocument" ) ? display.content.document : ""
visible: display.content['@type'] === "messageDocument"
}
Timer {
id: messageDateUpdater
interval: 60000

View file

@ -262,17 +262,16 @@ void TDLibWrapper::copyFileToDownloads(const QString &filePath)
}
}
void TDLibWrapper::handleAdditionalInformation(const QString &additionalInformation)
void TDLibWrapper::openFileOnDevice(const QString &filePath)
{
qDebug() << "[TDLibWrapper] Additional information: " << additionalInformation;
// For now only used to open downloaded files...
qDebug() << "[TDLibWrapper] Open file on device: " << filePath;
QStringList argumentsList;
argumentsList.append(additionalInformation);
argumentsList.append(filePath);
bool successfullyStarted = QProcess::startDetached("xdg-open", argumentsList);
if (successfullyStarted) {
qDebug() << "Successfully opened file " << additionalInformation;
qDebug() << "Successfully opened file " << filePath;
} else {
qDebug() << "Error opening file " << additionalInformation;
qDebug() << "Error opening file " << filePath;
}
}

View file

@ -68,7 +68,7 @@ public:
Q_INVOKABLE QVariantMap getBasicGroup(const QString &groupId);
Q_INVOKABLE QVariantMap getSuperGroup(const QString &groupId);
Q_INVOKABLE void copyFileToDownloads(const QString &filePath);
Q_INVOKABLE void handleAdditionalInformation(const QString &additionalInformation);
Q_INVOKABLE void openFileOnDevice(const QString &filePath);
Q_INVOKABLE void controlScreenSaver(const bool &enabled);
// Direct TDLib functions

View file

@ -189,6 +189,17 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DocumentPreview</name>
<message>
<source>Download Document</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open Document</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ImagePage</name>
<message>
@ -363,5 +374,17 @@
<source>shared an animation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported message: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Document: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>shared a document</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -189,6 +189,17 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DocumentPreview</name>
<message>
<source>Download Document</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open Document</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ImagePage</name>
<message>
@ -363,5 +374,17 @@
<source>shared an animation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported message: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Document: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>shared a document</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>