git.iko.soy/cinny-click-packaging
on main help sign in
Fix uploads and downloads
commit37a66548cf5f02b5a1abb2e1b2bbc2b2243770c3 authorMarcel Alexandru Nitan <nitan.marcel@protonmail.com> dateFri 1 Apr 2022, 23:21 (5 years ago) parent94456a6
8 files changed+84−114
cinny.apparmor+1 patches/0006-Download-media-using-qml-backend.patch+9−16 plugins/Backend/backend.cpp+13−5 plugins/Backend/backend.h+1 po/cinny.nitanmarcel.pot+9−17 qml/DownloadPage.qml+21−66 qml/Main.qml+9−6 qml/UploadPage.qml+21−4
cinny.apparmor+1
@@ -2,6 +2,7 @@
22 "policy_groups": [
33 "networking",
44 "content_exchange",
5+ "content_exchange_source",
56 "keep-display-on",
67 "webview",
78 "push-notification-client"
patches/0006-Download-media-using-qml-backend.patch+9−16
@@ -1,17 +1,17 @@
1−From f4aefbc12103f50041244d8243a83c01b80a8b95 Mon Sep 17 00:00:00 2001
1+From a1936e6dc3ee25dbc41d8d4374e38b0656e05a6e Mon Sep 17 00:00:00 2001
22From: Marcel Alexandru Nitan <nitan.marcel@protonmail.com>
3−Date: Fri, 25 Mar 2022 23:47:05 +0200
3+Date: Fri, 1 Apr 2022 23:21:02 +0300
44Subject: [PATCH] Download media using qml backend
55
66---
7− src/app/molecules/media/Media.jsx | 11 ++++++-----
8− 1 file changed, 6 insertions(+), 5 deletions(-)
7+ src/app/molecules/media/Media.jsx | 8 ++++----
8+ 1 file changed, 4 insertions(+), 4 deletions(-)
99
1010diff --git a/src/app/molecules/media/Media.jsx b/src/app/molecules/media/Media.jsx
11−index f119e40..65ae00d 100644
11+index 262aa94..88f14ea 100644
1212--- a/src/app/molecules/media/Media.jsx
1313+++ b/src/app/molecules/media/Media.jsx
14−@@ -79,10 +79,11 @@ function FileHeader({
14+@@ -90,10 +90,10 @@ function FileHeader({
1515 }
1616
1717 async function handleDownload(e) {
@@ -20,13 +20,12 @@ index f119e40..65ae00d 100644
2020 e.preventDefault();
2121- await getFile();
2222- e.target.click();
23−+ QML.downloadMedia(url || link)
24−+ // await getFile();
25−+ // e.target.click();
23++ const base64 = url != null ? url.split(',')[1] : link.split(',')[1];
24++ QML.handleDownload(base64, name);
2625 }
2726 }
2827 return (
29−@@ -100,12 +101,12 @@ function FileHeader({
28+@@ -111,7 +111,7 @@ function FileHeader({
3029 />
3130 )
3231 }
@@ -35,12 +34,6 @@ index f119e40..65ae00d 100644
3534 <IconButton
3635 size="extra-small"
3736 tooltip="Download"
38− src={DownloadSVG}
39−- onClick={handleDownload}
40−+ onClick={() => QML.downloadMedia(url || link)}
41− />
42− </a>
43− </>
4437--
45382.30.2
4639
plugins/Backend/backend.cpp+13−5
@@ -18,6 +18,7 @@
1818#include <QDir>
1919#include <QFile>
2020#include <QString>
21+#include <QByteArray>
2122
2223#include "backend.h"
2324
@@ -32,10 +33,17 @@ QString Backend::getIndexPath() {
3233}
3334
3435void Backend::removeDownload(QString path) {
35− if (path.startsWith(QString("file://"))) {
36− QFile file(path.replace(QString("file://"), QString("")));
37− if (file.exists()) {
38− file.remove();
39− }
36+ QFile file(path.replace(QString("file://"), QString("")));
37+ if (file.exists()) {
38+ file.remove();
4039 }
4140}
41+
42+QString Backend::saveBase64File(QString fileBase64, QString fileName) {
43+ QString path("/home/phablet/.cache/cinny.nitanmarcel" + QString(QDir::separator()) + fileName);
44+ QFile file(path);
45+ file.open(QIODevice::WriteOnly);
46+ file.write(QByteArray::fromBase64(fileBase64.toLocal8Bit()));
47+ file.close();
48+ return path;
49+}
plugins/Backend/backend.h+1
@@ -29,6 +29,7 @@ public:
2929
3030 Q_INVOKABLE QString getIndexPath();
3131 Q_INVOKABLE void removeDownload(QString path);
32+ Q_INVOKABLE QString saveBase64File(QString fileBase64, QString fileName);
3233};
3334
3435#endif
po/cinny.nitanmarcel.pot+9−17
@@ -8,7 +8,7 @@ msgid ""
88msgstr ""
99"Project-Id-Version: cinny.nitanmarcel\n"
1010"Report-Msgid-Bugs-To: \n"
11−"POT-Creation-Date: 2022-03-30 21:12+0000\n"
11+"POT-Creation-Date: 2022-04-01 20:14+0000\n"
1212"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,34 +17,26 @@ msgstr ""
1717"Content-Type: text/plain; charset=CHARSET\n"
1818"Content-Transfer-Encoding: 8bit\n"
1919
20−#: ../qml/DownloadPage.qml:41
21−msgid "Save with"
20+#: ../qml/DownloadPage.qml:35 ../qml/UploadPage.qml:37
21+msgid "Content Picker"
2222msgstr ""
2323
24−#: ../qml/DownloadPage.qml:112
25−msgid "Downloading"
24+#: ../qml/DownloadPage.qml:40 ../qml/UploadPage.qml:42
25+msgid "Back"
2626msgstr ""
2727
28−#: ../qml/DownloadPage.qml:126 ../qml/Main.qml:193
29−msgid "Cancel"
30−msgstr ""
31−
32−#: ../qml/Main.qml:176
28+#: ../qml/Main.qml:180
3329msgid "Javascript Dialog"
3430msgstr ""
3531
36−#: ../qml/Main.qml:188
32+#: ../qml/Main.qml:192
3733msgid "Yes"
3834msgstr ""
3935
40−#: ../qml/UploadPage.qml:35
41−msgid "Choose"
36+#: ../qml/Main.qml:197
37+msgid "Cancel"
4238msgstr ""
4339
4440#: cinny.desktop.in.h:1
4541msgid "Cinny"
4642msgstr ""
47−
48−#: ../push/push.cpp:30
49−msgid "New message"
50−msgstr ""
qml/DownloadPage.qml+21−66
@@ -16,14 +16,10 @@
1616
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
19−import Ubuntu.Components.Popups 1.3
2019import Ubuntu.Content 1.3
21−import Ubuntu.DownloadManager 1.2
22−
2320import Backend 1.0
2421
2522
26−
2723Page {
2824 id: picker
2925 property var activeTransfer
@@ -32,39 +28,49 @@ Page {
3228 property string handler
3329 property string contentType
3430
35− property var popup
36−
3731 signal cancel()
3832 signal imported(string fileUrl)
3933
40− header: PageHeader {
41− title: i18n.tr("Save with")
34+ header: PageHeader{
35+ title: i18n.tr("Save With")
36+ leadingActionBar.actions:[
37+ Action {
38+ id: backAction
39+ iconName: "back"
40+ text: i18n.tr('Back')
41+ onTriggered:{
42+ Backend.removeDownload(picker.url)
43+ pageStack.pop()
44+ }
45+ }
46+ ]
4247 }
43−
4448 ContentPeerPicker {
4549 anchors { fill: parent; topMargin: picker.header.height }
4650 visible: parent.visible
47− showTitle: true
51+ showTitle: false
4852 contentType: ContentType.All
49− handler: ContentHandler.Destination
53+ handler: ContentHandler.Share
5054
5155 onPeerSelected: {
5256 //peer.selectionType = ContentTransfer.Single
5357 picker.activeTransfer = peer.request()
5458 picker.activeTransfer.stateChanged.connect(function() {
5559 if (picker.activeTransfer.state === ContentTransfer.InProgress) {
56− console.log("In progress");
60+ console.log("In progress " + picker.url);
5761 //picker.activeTransfer.items = picker.activeTransfer.items[0].url = url;
58− console.log(picker.url)
59− picker.activeTransfer.items = [ resultComponent.createObject(parent, {"url": picker.url}) ];
60−
62+ picker.activeTransfer.items = [ resultComponent.createObject(parent, {"url": "file://" + picker.url}) ];
6163 picker.activeTransfer.state = ContentTransfer.Charged;
6264 Backend.removeDownload(picker.url)
6365 pageStack.pop()
6466 }
67+
6568 })
6669 }
70+
71+
6772 onCancelPressed: {
73+ Backend.removeDownload()
6874 Backend.removeDownload(picker.url)
6975 pageStack.pop()
7076 }
@@ -75,59 +81,8 @@ Page {
7581 anchors.fill: parent
7682 activeTransfer: picker.activeTransfer
7783 }
78−
79− SingleDownload {
80− id: singleDownload
81−
82− metadata: Metadata {
83− showInIndicator: true
84− }
85−
86− onFinished: function (path) {
87− picker.url = "file://" + path
88− PopupUtils.close(picker.popup)
89− }
90−
91− onCanceled: function () {
92− PopupUtils.close(picker.popup)
93− pageStack.pop()
94− }
95− }
9684 Component {
9785 id: resultComponent
9886 ContentItem {}
9987 }
100−
101− Component.onCompleted: function () {
102− picker.popup = PopupUtils.open(dialogComponent)
103− singleDownload.metadata.title = url.substring(url.lastIndexOf("/")+1)
104− singleDownload.download(url)
105− }
106−
107− Component {
108− id: dialogComponent
109− Dialog {
110−
111− id: downloadDialog
112− title: i18n.tr("Downloading")
113−
114− ProgressBar {
115− minimumValue: 0
116− maximumValue: 100
117− value: singleDownload.progress
118−
119− anchors {
120− left: parent.left
121− right: parent.right
122− }
123− }
124−
125− Button {
126− text: i18n.tr("Cancel")
127− onClicked: {
128− singleDownload.cancel()
129− }
130− }
131− }
132− }
13388}
qml/Main.qml+9−6
@@ -104,7 +104,7 @@ MainView {
104104 profile : WebEngineProfile {
105105 id : webContext
106106 storageName : "Storage"
107− persistentStoragePath : "/home/phablet/.cache/cinny.nitanmarcel/cinny.nitanmarcel/QtWebEngine"
107+ persistentStoragePath : "/home/phablet/.local/share/cinny.nitanmarcel/QWebEngine"
108108
109109 onDownloadRequested: function (download) {
110110 console.log("Downloading")
@@ -123,8 +123,10 @@ MainView {
123123 request.accepted = true;
124124 var uploadPage = mainPageStack.push(Qt.resolvedUrl("UploadPage.qml"), {"contentType": ContentType.All, "handler": ContentHandler.Source})
125125 uploadPage.imported.connect(function (fileUrl) {
126− request.dialogAccept(String(fileUrl).replace("file://", ""));
127− mainPageStack.push(mainPage)
126+ request.dialogAccept(fileUrl);
127+ })
128+ uploadPage.rejected.connect(function () {
129+ request.dialogReject()
128130 })
129131 }
130132
@@ -156,9 +158,10 @@ MainView {
156158
157159 signal matrixPushTokenChanged();
158160
159− function downloadMedia(fileUrl) {
160− console.log("Download")
161− var downloadPage = mainPageStack.push(Qt.resolvedUrl("DownloadPage.qml"), {"url": fileUrl, "contentType": ContentType.All, "handler": ContentHandler.Destination})
161+ function handleDownload(fileBase64, fileName) {
162+ var filePath = Backend.saveBase64File(fileBase64, fileName)
163+ console.log("Downloaded to " + filePath)
164+ var downloadPage = mainPageStack.push(Qt.resolvedUrl("DownloadPage.qml"), {"url": filePath, "contentType": ContentType.All, "handler": ContentHandler.Destination})
162165 }
163166
164167 function setTheme(themeName) {
qml/UploadPage.qml+21−4
@@ -17,11 +17,12 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.Content 1.3
20+import Backend 1.0
2021
2122
2223
2324Page {
24− id: picker
25+ id: picker
2526 property var activeTransfer
2627
2728 property var url
@@ -30,9 +31,23 @@ Page {
3031
3132 signal cancel()
3233 signal imported(string fileUrl)
34+ signal rejected()
3335
34− header: PageHeader {
35− title: i18n.tr("Choose")
36+ header: PageHeader{
37+ title: i18n.tr("Chose")
38+ leadingActionBar.actions:[
39+ Action {
40+ id: backAction
41+ iconName: "back"
42+ text: i18n.tr('Back')
43+ onTriggered:{
44+ Backend.removeDownload(url)
45+ rejected()
46+ pageStack.pop()
47+
48+ }
49+ }
50+ ]
3651 }
3752
3853 ContentPeerPicker {
@@ -47,7 +62,7 @@ Page {
4762 picker.activeTransfer = peer.request()
4863 picker.activeTransfer.stateChanged.connect(function() {
4964 if (picker.activeTransfer.state === ContentTransfer.InProgress) {
50− console.log("In progress");
65+ console.log("In progress " + url);
5166 picker.activeTransfer.items = picker.activeTransfer.items[0].url = url;
5267 picker.activeTransfer.state = ContentTransfer.Charged;
5368 }
@@ -56,6 +71,7 @@ Page {
5671 picker.imported(picker.activeTransfer.items[0].url)
5772 console.log(picker.activeTransfer.items[0].url)
5873 picker.activeTransfer = null
74+ pageStack.pop()
5975 }
6076 })
6177 }
@@ -63,6 +79,7 @@ Page {
6379
6480 onCancelPressed: {
6581 console.log("Cancelled")
82+ rejected()
6683 pageStack.pop()
6784 }
6885 }