Page MenuHomePhorge

No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/src/contents/ui/event-types/Image.qml b/src/contents/ui/event-types/Image.qml
index 9e8b528..b48fc4f 100644
--- a/src/contents/ui/event-types/Image.qml
+++ b/src/contents/ui/event-types/Image.qml
@@ -1,84 +1,101 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import moe.kazv.mxc.kazv 0.0 as MK
import org.kde.kirigami 2.13 as Kirigami
import '..' as Kazv
Simple {
id: upper
property var gender: 'neutral'
property var body: event.content.body
property var mxcUri: event.content.url
property var imageUri: matrixSdk.mxcUriToHttp(mxcUri)
property var imageInfo: event.content.info || {}
property var imageWidth: image.implicitWidth || imageInfo.w || 1 // lest we divide by 0
property var imageHeight: image.implicitHeight || imageInfo.h || 1
property var innerContentWidth: upper.contentMaxWidth - bubble.bubbleSpacing
property var kazvIO: MK.KazvIO{}
Kazv.Bubble {
id: bubble
ColumnLayout {
id: layout
Label {
Layout.fillWidth: false
Layout.maximumWidth: innerContentWidth
wrapMode: Text.Wrap
text: l10n.get('event-message-image-sent', { gender, body })
}
Image {
id: image
source: imageUri
Layout.maximumWidth: innerContentWidth
Layout.preferredWidth: imageWidth
Layout.preferredHeight: imageHeight / imageWidth * width
fillMode: Image.PreserveAspectFit
TapHandler {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onSingleTapped: {
if (eventPoint.event.button === Qt.RightButton) {
optionMenu.popup()
}
if (eventPoint.event.button === Qt.LeftButton) {
// TODO: Open with default program
}
}
onLongPressed: {
optionMenu.popup()
}
}
Menu {
id: optionMenu
Action {
text: l10n.get('menu-option-view')
// TODO: Customizable shortcut keys
// shortcut: "Ctrl+i,Ctrl+v"
// TODO: open with default program
}
Action {
text: l10n.get('menu-option-save-as')
// TODO: Customizable shortcut keys
// shortcut: "Ctrl+i,Ctrl+s"
- onTriggered: kazvIO.saveFileAs(imageUri)
+ onTriggered: {
+ kazvIO.saveFileAs(imageUri)
+ // progressBarLayout.visible = true
+ }
}
}
}
+ RowLayout {
+ id: progressBarLayout
+ // TODO: Show progress bar only while downloading
+ // visible: false
+ ProgressBar {
+ id: progressBar
+ Layout.preferredWidth: imageWidth
+ value: kazvIO.progress
+ }
+ /* ui for cancel, pause, etc.
+ RoundButton {}
+ RoundButton {}
+ */
+ }
}
}
}
diff --git a/src/kazv-io.cpp b/src/kazv-io.cpp
index c34b84c..99c39fa 100644
--- a/src/kazv-io.cpp
+++ b/src/kazv-io.cpp
@@ -1,33 +1,46 @@
#include <QUrl>
#include <KIO/StoredTransferJob>
#include <QObject>
#include <QString>
#include <QSaveFile>
#include <QIODevice>
#include <QFileDialog>
#include <QDebug>
#include "kazv-io.hpp"
void KazvIO::saveFileAs(QUrl url)
{
- auto job = KIO::storedGet(url);
- connect(job, &KJob::result, this, &KazvIO::downloadFinished);
- job->start();
+ m_job = KIO::storedGet(url);
+ connect(m_job, &KJob::result, this, &KazvIO::downloadFinished);
+ connect(m_job, &KJob::percentChanged, this, &KazvIO::onPercentChanged);
+ m_job->start();
}
void KazvIO::downloadFinished(KJob *job) {
if (job->error()) {
qDebug() << job-> errorString();
return;
}
auto storedJob = qobject_cast<KIO::StoredTransferJob *>(job);
if (storedJob) {
auto fileName = QFileDialog::getSaveFileName();
auto file = QSaveFile(fileName);
file.open(QIODevice::WriteOnly);
file.write(storedJob->data());
file.commit();
}
}
+
+float KazvIO::progress()
+{
+ return m_progress;
+}
+
+void KazvIO::onPercentChanged(KJob* job, unsigned long percent)
+{
+ m_progress = 1.0 * percent / 100;
+ progressChanged();
+}
+
diff --git a/src/kazv-io.hpp b/src/kazv-io.hpp
index e293ef0..b540b12 100644
--- a/src/kazv-io.hpp
+++ b/src/kazv-io.hpp
@@ -1,12 +1,21 @@
#include <QWidget>
#include <QUrl>
#include <KIO/Job>
#include <QtQml>
+#include <KIO/StoredTransferJob>
class KazvIO : public QWidget {
Q_OBJECT
QML_ELEMENT
-public Q_SLOTS:
- void saveFileAs(QUrl url);
+ Q_PROPERTY(float progress READ progress NOTIFY progressChanged)
+public:
+ float progress();
+ Q_INVOKABLE void saveFileAs(QUrl url);
+signals:
+ void progressChanged();
+private:
+ KIO::StoredTransferJob *m_job;
+ float m_progress = 0;
void downloadFinished(KJob* job);
+ void onPercentChanged(KJob* job, unsigned long percent);
};

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 9:18 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55451
Default Alt Text
(5 KB)

Event Timeline