Commit 8003c88a authored by Martin Straka's avatar Martin Straka

Added iCloud file downloading during its selection

parent eb82436d
...@@ -147,17 +147,19 @@ ICloudIo::ICloudResult ICloudIo::moveFileToCloud( ...@@ -147,17 +147,19 @@ ICloudIo::ICloudResult ICloudIo::moveFileToCloud(
QString ICloudIo::copyFileFromCloud(const QString &cloudFilePath, QString ICloudIo::copyFileFromCloud(const QString &cloudFilePath,
const QString &localFilePath) const QString &localFilePath)
{ {
// Test if file was downloaded from iCloud
if (!isDownloadedFromCloud(cloudFilePath)) { if (!isDownloadedFromCloud(cloudFilePath)) {
NSLog(@"Local: File has not been downloaded yet from iCloud."); NSLog(@"Local: File has not been downloaded yet from iCloud.");
return QString(); return QString();
} }
NSError *error = nil; // Convert string path to URL
NSURL *fileCloudUrl = [NSURL URLWithString:cloudFilePath.toNSString()]; NSURL *fileCloudUrl = [NSURL URLWithString:cloudFilePath.toNSString()];
NSURL* localFileUrl = [NSURL fileURLWithPath:localFilePath.toNSString()]; NSURL* localFileUrl = [NSURL fileURLWithPath:localFilePath.toNSString()];
NSString *fileName = [fileCloudUrl lastPathComponent]; NSString *fileName = [fileCloudUrl lastPathComponent];
// Create subdirectorues on Local // Create subdirectorues on Local
NSError *error = nil;
if (![[NSFileManager defaultManager] createDirectoryAtURL:localFileUrl if (![[NSFileManager defaultManager] createDirectoryAtURL:localFileUrl
withIntermediateDirectories:YES attributes:nil error:&error]) { withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"Local: Create message subdirectories error: %@", error.localizedDescription); NSLog(@"Local: Create message subdirectories error: %@", error.localizedDescription);
...@@ -165,23 +167,23 @@ QString ICloudIo::copyFileFromCloud(const QString &cloudFilePath, ...@@ -165,23 +167,23 @@ QString ICloudIo::copyFileFromCloud(const QString &cloudFilePath,
} }
NSURL *fileLocalUrl = [localFileUrl URLByAppendingPathComponent:fileName]; NSURL *fileLocalUrl = [localFileUrl URLByAppendingPathComponent:fileName];
NSLog(@"iCloud url: %@", fileCloudUrl); //NSLog(@"iCloud url: %@", fileCloudUrl);
NSLog(@"Local file url: %@", fileLocalUrl); //NSLog(@"Local file url: %@", fileLocalUrl);
// Remove file from local
[[NSFileManager defaultManager] removeItemAtURL:fileLocalUrl error:&error];
if ([[NSFileManager defaultManager] copyItemAtURL:fileCloudUrl toURL:fileLocalUrl error:&error]) { if ([[NSFileManager defaultManager] copyItemAtURL:fileCloudUrl toURL:fileLocalUrl error:&error]) {
NSLog(@"Local: File has been uploaded."); NSLog(@"Local: File has copied to app sandbox.");
return QString(); return QString::fromNSString(fileLocalUrl.absoluteString);
} else { } else {
if (error.code == NSFileWriteFileExistsError) { if (error.code == NSFileWriteFileExistsError) {
NSLog(@"Local: File with the same name already exists."); NSLog(@"Local: File with the same name already exists.");
return QString();
} else if (error.code == NSFileReadNoSuchFileError) { } else if (error.code == NSFileReadNoSuchFileError) {
NSLog(@"Local: File has not been downloaded yet from iCloud."); NSLog(@"Local: File has not downloaded yet from iCloud.");
return QString();
} else { } else {
NSLog(@"Local: Error code: %zd %@", error.code, error.localizedDescription); NSLog(@"Local: Error code: %zd %@", error.code, error);
} }
} }
return QString(); return QString();
...@@ -197,18 +199,22 @@ bool ICloudIo::isDownloadedFromCloud(const QString &cloudFilePath) ...@@ -197,18 +199,22 @@ bool ICloudIo::isDownloadedFromCloud(const QString &cloudFilePath)
NSError *error = nil; NSError *error = nil;
NSString *downloadStatus = nil; NSString *downloadStatus = nil;
NSURL *fileCloudUrl = [NSURL URLWithString:cloudFilePath.toNSString()]; NSURL *fileCloudUrl = [NSURL URLWithString:cloudFilePath.toNSString()];
if ([fileCloudUrl getResourceValue:&downloadStatus forKey:NSURLUbiquitousItemDownloadingStatusKey error:&error] == YES) { if ([fileCloudUrl getResourceValue:&downloadStatus forKey:NSURLUbiquitousItemDownloadingStatusKey error:&error] == YES) {
if ([downloadStatus isEqualToString:NSURLUbiquitousItemDownloadingStatusNotDownloaded] == YES) { if ([downloadStatus isEqualToString:NSURLUbiquitousItemDownloadingStatusNotDownloaded] == YES) {
NSLog(@"File must be downloaded: %@", fileCloudUrl); NSLog(@"File missing and must be downloaded: %@", fileCloudUrl);
[[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:fileCloudUrl error:&error];
return false;
} else if ([downloadStatus isEqualToString:NSURLUbiquitousItemDownloadingStatusDownloaded] == YES) {
NSLog(@"Up-to-date version of file must be downloaded: %@", fileCloudUrl);
[[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:fileCloudUrl error:&error]; [[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:fileCloudUrl error:&error];
return false; return false;
} else { } else {
NSLog(@"File has been downloaded: %@", fileCloudUrl); NSLog(@"Up-to-date version of file is available: %@", fileCloudUrl);
return true;
} }
} }
return true; return false;
} }
...@@ -62,6 +62,7 @@ Dialog { ...@@ -62,6 +62,7 @@ Dialog {
property int selectedFileIndex: -1 property int selectedFileIndex: -1
property bool showDirs: true property bool showDirs: true
property bool showFiles: true property bool showFiles: true
property bool iOS: false
signal finished(variant pathListModel) signal finished(variant pathListModel)
...@@ -69,7 +70,8 @@ Dialog { ...@@ -69,7 +70,8 @@ Dialog {
return (root.showDirs && !root.showFiles); return (root.showDirs && !root.showFiles);
} }
function raise(title, filters, showFiles, targetLocation) { function raise(title, filters, showFiles, targetLocation, isiOS) {
iOS = isiOS
if (targetLocation !== "") { if (targetLocation !== "") {
folderNavigation.visible = false folderNavigation.visible = false
folderModel.folder = "file://" + targetLocation folderModel.folder = "file://" + targetLocation
...@@ -80,6 +82,9 @@ Dialog { ...@@ -80,6 +82,9 @@ Dialog {
if (filters !== "") { if (filters !== "") {
folderModel.nameFilters = filters folderModel.nameFilters = filters
} }
if (iOS) {
folderModel.folder = standardLocationUrl(InteractionFilesystem.DOCUMENTS_LOCATION)
}
selectedFileIndex = -1 selectedFileIndex = -1
// clear add path list model // clear add path list model
pathListModel.clear() pathListModel.clear()
...@@ -128,6 +133,7 @@ Dialog { ...@@ -128,6 +133,7 @@ Dialog {
ColumnLayout { ColumnLayout {
id: folderNavigation id: folderNavigation
AccessibleComboBox { AccessibleComboBox {
visible: !iOS
anchors { anchors {
left: parent.left; left: parent.left;
right: parent.right; right: parent.right;
...@@ -207,7 +213,7 @@ Dialog { ...@@ -207,7 +213,7 @@ Dialog {
showFiles: root.showFiles showFiles: root.showFiles
showDirsFirst: true showDirsFirst: true
nameFilters: ["*.*"] nameFilters: ["*.*"]
folder: standardLocationUrl(InteractionFilesystem.DESKTOP_LOCATION) folder: standardLocationUrl(InteractionFilesystem.DOCUMENTS_LOCATION)
onFolderChanged: { onFolderChanged: {
selectedFileIndex = -1 selectedFileIndex = -1
pathField.text = stripUrlPrefix(folder) pathField.text = stripUrlPrefix(folder)
......
...@@ -88,15 +88,19 @@ Dialog { ...@@ -88,15 +88,19 @@ Dialog {
target: iCloudHelper target: iCloudHelper
onCloudContentSig: { onCloudContentSig: {
iCloudHelper.setCloudFileModel(cloudFileListModel, iCloudFileList); iCloudHelper.setCloudFileModel(cloudFileListModel, iCloudFileList);
if (cloudFileListModel.rowCount() > 1) { if (cloudFileListModel.rowCount() > 0) {
cloudFileList.visible = true cloudFileList.visible = true
emptyList.visible = false emptyList.visible = !cloudFileList.visible
} else {
emptyList.text = qsTr("No files in the iCloud.")
cloudFileList.visible = false
emptyList.visible = !cloudFileList.visible
} }
} }
onCloudActivitySig: { onCloudActivitySig: {
emptyList.text = txt emptyList.text = txt
cloudFileList.visible = false cloudFileList.visible = false
emptyList.visible = true emptyList.visible = !cloudFileList.visible
} }
} }
Component { Component {
...@@ -128,7 +132,7 @@ Dialog { ...@@ -128,7 +132,7 @@ Dialog {
font.bold: true font.bold: true
} }
Text { Text {
text: rFileShortPath text: "iCloud:" + rFileShortPath
color: datovkaPalette.mid color: datovkaPalette.mid
font.pointSize: textFontSizeSmall font.pointSize: textFontSizeSmall
} }
...@@ -143,7 +147,10 @@ Dialog { ...@@ -143,7 +147,10 @@ Dialog {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
cloudFileListModel.setFileSelected(rFileCloudPath, !rFileSelected) if (!rFileSelected) {
iCloudHelper.downloadFileFromCloud(rFileCloudPath)
}
cloudFileListModel.setFileSelected(rFileCloudPath)
} }
} }
} // Rectangle } // Rectangle
...@@ -198,7 +205,10 @@ Dialog { ...@@ -198,7 +205,10 @@ Dialog {
onAccepted: { onAccepted: {
for (var i = 0; i < cloudFileListModel.rowCount(); ++i) { for (var i = 0; i < cloudFileListModel.rowCount(); ++i) {
if (cloudFileListModel.fileSelected(i)) { if (cloudFileListModel.fileSelected(i)) {
pathListModel.append({path: cloudFileListModel.fileCloudPathFromRow(i)}) var filePath = iCloudHelper.copyFileFromCloud(cloudFileListModel.fileCloudPathFromRow(i), cloudFileListModel.fileShortCloudPathFromRow(i))
if (filePath !== "") {
pathListModel.append({path: filePath})
}
} }
} }
finished(pathListModel) finished(pathListModel)
......
...@@ -54,6 +54,8 @@ Item { ...@@ -54,6 +54,8 @@ Item {
property string text_COLOR_RED: "#ff0000" property string text_COLOR_RED: "#ff0000"
property bool iOS: false
/* This property holds total attachment size in bytes */ /* This property holds total attachment size in bytes */
property int totalAttachmentSizeBytes: 0 property int totalAttachmentSizeBytes: 0
...@@ -163,7 +165,30 @@ Item { ...@@ -163,7 +165,30 @@ Item {
} }
} }
/* Append selected files to send model */
function appendFilesToSendModel(pathListModel) {
var listLength = pathListModel.count
for (var j = 0; j < listLength; ++j) {
var isInFiletList = false
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
if (sendMsgAttachmentModel.filePathFromRow(i) === pathListModel.get(j).path) {
isInFiletList = true
break
}
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(pathListModel.get(j).path)
var fileSizeBytes = files.getAttachmentSizeInBytes(pathListModel.get(j).path)
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, pathListModel.get(j).path, fileSizeBytes)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
}
pathListModel.clear()
}
Component.onCompleted: { Component.onCompleted: {
iOS = files.isIos()
actionButton.enabled = false actionButton.enabled = false
initPDZ.visible = false initPDZ.visible = false
initPDZ.checked = false initPDZ.checked = false
...@@ -194,52 +219,13 @@ Item { ...@@ -194,52 +219,13 @@ Item {
FileDialogue { FileDialogue {
id: fileDialogue id: fileDialogue
multiSelect: true multiSelect: true
onFinished: { onFinished: appendFilesToSendModel(pathListModel)
var listLength = pathListModel.count
for (var j = 0; j < listLength; ++j) {
var isInFiletList = false
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
if (sendMsgAttachmentModel.filePathFromRow(i) === pathListModel.get(j).path) {
isInFiletList = true
break
}
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(pathListModel.get(j).path)
var fileSizeBytes = files.getAttachmentSizeInBytes(pathListModel.get(j).path)
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, pathListModel.get(j).path, fileSizeBytes)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
}
pathListModel.clear()
}
} }
/* File dialog for choose of files from iCloud */ /* File dialog for choose of files from iCloud */
FileDialogueIos { FileDialogueIos {
id: fileDialogueIos id: fileDialogueIos
onFinished: { onFinished: appendFilesToSendModel(pathListModel)
var listLength = pathListModel.count
for (var j = 0; j < listLength; ++j) {
var localFilePath = iCloudHelper.downloadFileFromCloud(pathListModel.get(j).path)
var isInFiletList = false
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
if (sendMsgAttachmentModel.filePathFromRow(i) === localFilePath) {
isInFiletList = true
break
}
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(localFilePath)
var fileSizeBytes = files.getAttachmentSizeInBytes(localFilePath)
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, localFilePath, fileSizeBytes)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
}
pathListModel.clear()
}
} }
/* Holds send message recipent list model */ /* Holds send message recipent list model */
...@@ -524,12 +510,12 @@ Item { ...@@ -524,12 +510,12 @@ Item {
font.pointSize: defaultTextFont.font.pointSize font.pointSize: defaultTextFont.font.pointSize
text: qsTr("Add file") text: qsTr("Add file")
onClicked: { onClicked: {
fileDialogue.raise(qsTr("Select files"), ["*.*"], true, "") fileDialogue.raise(qsTr("Select files"), ["*.*"], true, "", iOS)
} }
} }
AccessibleButton { AccessibleButton {
id: icloud id: icloud
visible: files.isIos() visible: iOS
height: inputItemHeight height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize font.pointSize: defaultTextFont.font.pointSize
text: qsTr("iCloud") text: qsTr("iCloud")
......
...@@ -21,9 +21,11 @@ ...@@ -21,9 +21,11 @@
* the two. * the two.
*/ */
#include <QDebug>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QMessageBox> #include <QMessageBox>
#include <QUrl>
#include "src/auxiliaries/icloud_helper.h" #include "src/auxiliaries/icloud_helper.h"
#include "src/io/filesystem.h" #include "src/io/filesystem.h"
...@@ -33,6 +35,7 @@ ...@@ -33,6 +35,7 @@
#ifdef Q_OS_IOS #ifdef Q_OS_IOS
#include "ios/src/icloud_io.h" #include "ios/src/icloud_io.h"
#define ICLOUD_DATOVKA_CONTAINER_NAME "Datovka" #define ICLOUD_DATOVKA_CONTAINER_NAME "Datovka"
#define ICLOUD_FILE_CONTAINER_ID "iCloud~cz~nic~mobile-datovka/Documents"
#endif /* Q_OS_IOS */ #endif /* Q_OS_IOS */
#ifndef Q_OS_IOS #ifndef Q_OS_IOS
...@@ -54,7 +57,7 @@ QStringList testCloudPathList(void) ...@@ -54,7 +57,7 @@ QStringList testCloudPathList(void)
void ICloudHelper::createCloudConteiner(void) void ICloudHelper::createCloudConteiner(void)
{ {
debugSlotCall(); debugFuncCall();
#ifdef Q_OS_IOS #ifdef Q_OS_IOS
...@@ -65,7 +68,7 @@ void ICloudHelper::createCloudConteiner(void) ...@@ -65,7 +68,7 @@ void ICloudHelper::createCloudConteiner(void)
void ICloudHelper::getCloudHierarchyAsync(void) void ICloudHelper::getCloudHierarchyAsync(void)
{ {
debugSlotCall(); debugFuncCall();
#ifdef Q_OS_IOS #ifdef Q_OS_IOS
...@@ -94,7 +97,7 @@ void ICloudHelper::getCloudHierarchyAsync(void) ...@@ -94,7 +97,7 @@ void ICloudHelper::getCloudHierarchyAsync(void)
void ICloudHelper::storeFilesToCloud(const QStringList &srcFilePaths, void ICloudHelper::storeFilesToCloud(const QStringList &srcFilePaths,
const QString &targetPath) const QString &targetPath)
{ {
debugSlotCall(); debugFuncCall();
#ifdef Q_OS_IOS #ifdef Q_OS_IOS
...@@ -152,14 +155,12 @@ finish: ...@@ -152,14 +155,12 @@ finish:
/* Show final notification */ /* Show final notification */
if (success) { if (success) {
qCritical() << "Files have been saved to iCloud.";
QMessageBox::critical(Q_NULLPTR, tr("iCloud saving"), QMessageBox::critical(Q_NULLPTR, tr("iCloud saving"),
tr("Files have been saved to iCloud.") + "\n\n" + tr("Files have been saved to iCloud.") + "\n\n" +
tr("Path: '%1'").arg(QString(ICLOUD_DATOVKA_CONTAINER_NAME) tr("Path: '%1'").arg(QString(ICLOUD_DATOVKA_CONTAINER_NAME)
+ "/" + targetPath), + "/" + targetPath),
QMessageBox::Ok); QMessageBox::Ok);
} else { } else {
qCritical() << "Files upload to iCloud failed!";
QString txt; QString txt;
foreach (const QString &error, errorUploads) { foreach (const QString &error, errorUploads) {
txt += "\n" + error; txt += "\n" + error;
...@@ -178,22 +179,58 @@ finish: ...@@ -178,22 +179,58 @@ finish:
#endif /* Q_OS_IOS */ #endif /* Q_OS_IOS */
} }
QString ICloudHelper::downloadFileFromCloud(const QString &cloudFilePath) bool ICloudHelper::downloadFileFromCloud(const QString &cloudFilePath)
{ {
debugSlotCall(); debugFuncCall();
#ifdef Q_OS_IOS #ifdef Q_OS_IOS
QString localFilePath; return ICloudIo::isDownloadedFromCloud(cloudFilePath);
QFileInfo fi(cloudFilePath);
localFilePath = appSendDirPath() + QDir::separator() + #else
QUrl::fromPercentEncoding(fi.fileName().toUtf8()); Q_UNUSED(cloudFilePath);
return false;
#endif
}
QString ICloudHelper::copyFileFromCloud(const QString &cloudFilePath,
const QString &localFilePath)
{
debugFuncCall();
#ifdef Q_OS_IOS
ICloudIo::copyFileFromCloud(cloudFilePath, appSendDirPath()); QString lfPath = ICloudIo::copyFileFromCloud(cloudFilePath,
return localFilePath; appSendDirPath() + localFilePath);
if (!lfPath.isEmpty()) {
lfPath = QUrl::fromPercentEncoding(lfPath.toUtf8());
lfPath = lfPath.replace("file://", "");
return lfPath;
} else {
return QString();
}
#else #else
Q_UNUSED(cloudFilePath); Q_UNUSED(cloudFilePath);
Q_UNUSED(localFilePath);
return QString();
#endif
}
/*
* Retrun short iCloud path.
*/
QString getShortPathFromCloudPath(const QString &fileCloudPath)
{
#ifdef Q_OS_IOS
// Get short file path from iCloud path
QString pattern(ICLOUD_FILE_CONTAINER_ID);
int pos = fileCloudPath.indexOf(pattern) + pattern.length();
return fileCloudPath.mid(pos);
#else
Q_UNUSED(fileCloudPath);
return QString(); return QString();
#endif #endif
} }
...@@ -201,9 +238,9 @@ QString ICloudHelper::downloadFileFromCloud(const QString &cloudFilePath) ...@@ -201,9 +238,9 @@ QString ICloudHelper::downloadFileFromCloud(const QString &cloudFilePath)
void ICloudHelper::setCloudFileModel(const QVariant &cloudFileModelVariant, void ICloudHelper::setCloudFileModel(const QVariant &cloudFileModelVariant,
const QStringList &fileList) const QStringList &fileList)
{ {
debugSlotCall(); debugFuncCall();
/* Obtain pointer to attachment model. */ /* Obtain pointer to icloud file model from variant. */
CloudFileListModel *cloudModel = CloudFileListModel *cloudModel =
CloudFileListModel::fromVariant(cloudFileModelVariant); CloudFileListModel::fromVariant(cloudFileModelVariant);
if (cloudModel == Q_NULLPTR) { if (cloudModel == Q_NULLPTR) {
...@@ -211,16 +248,18 @@ void ICloudHelper::setCloudFileModel(const QVariant &cloudFileModelVariant, ...@@ -211,16 +248,18 @@ void ICloudHelper::setCloudFileModel(const QVariant &cloudFileModelVariant,
return; return;
} }
foreach (const QString &file, fileList) { foreach (const QString &fileCloudPath, fileList) {
QFileInfo fi(file);
QFileInfo fi(fileCloudPath);
if (fi.fileName().isEmpty()) { if (fi.fileName().isEmpty()) {
// Skip directories
continue; continue;
} }
QString filePath = fi.path();
QString pattern("iCloud~cz~nic~mobile-datovka/Documents"); // Append file to model, false means file is unselected
int pos = filePath.indexOf(pattern) + pattern.length(); cloudModel->appendFileFromCloud(fileCloudPath,
filePath = QStringLiteral("iCloud:Datovka") + filePath.mid(pos) + QStringLiteral("/"); QUrl::fromPercentEncoding(fi.fileName().toUtf8()),
cloudModel->appendFileFromCloud(file, fi.fileName(), filePath, false); getShortPathFromCloudPath(fi.path()), false);
} }
} }
...@@ -242,9 +281,7 @@ void ICloudHelper::receivedCloudHierarchy(void) ...@@ -242,9 +281,7 @@ void ICloudHelper::receivedCloudHierarchy(void)
m_timer->stop(); m_timer->stop();
disconnect(m_timer, SIGNAL(timeout()), disconnect(m_timer, SIGNAL(timeout()),
this, SLOT(receivedCloudHierarchy())); this, SLOT(receivedCloudHierarchy()));
if (!iCloudFileList.isEmpty()) { emit cloudContentSig(iCloudFileList);
emit cloudContentSig(iCloudFileList);
}
} else { } else {
emit cloudActivitySig(tr("Searching for iCloud files...")); emit cloudActivitySig(tr("Searching for iCloud files..."));
} }
......
...@@ -72,10 +72,21 @@ public: ...@@ -72,10 +72,21 @@ public:
* @brief Download file from iCloud if not exists in the local storage. * @brief Download file from iCloud if not exists in the local storage.
* *
* @param[in] cloudFilePath File path in iCloud. * @param[in] cloudFilePath File path in iCloud.
* @return Full path where file will stored. * @return True if success.
*/ */
Q_INVOKABLE Q_INVOKABLE
QString downloadFileFromCloud(const QString &cloudFilePath); bool downloadFileFromCloud(const QString &cloudFilePath);
/*!
* @brief Copy single file from iCloud continer to Datovka sandbox.
*
* @param[in] cloudFilePath Source file path.
* @param[in] localFilePath iCloud target path.
* @return Full path to app sandbox where file was stored.
*/
Q_INVOKABLE
QString copyFileFromCloud(const QString &cloudFilePath,
const QString &localFilePath);
/*! /*!
* @brief Set iCloud file model in QML. * @brief Set iCloud file model in QML.
......
...@@ -167,6 +167,15 @@ QString CloudFileListModel::fileCloudPathFromRow(int row) ...@@ -167,6 +167,15 @@ QString CloudFileListModel::fileCloudPathFromRow(int row)
return m_files[row].fileClaudPath(); return m_files[row].fileClaudPath();
} }
QString CloudFileListModel::fileShortCloudPathFromRow(int row)
{
if ((row < 0) || (row >= m_files.size())) {
return QString();
}
return m_files[row].fileShortPath();
}
Qt::ItemFlags CloudFileListModel::flags(const QModelIndex &index) const Qt::ItemFlags CloudFileListModel::flags(const QModelIndex &index) const
{ {
return QAbstractListModel::flags(index); return QAbstractListModel::flags(index);
...@@ -181,7 +190,7 @@ void CloudFileListModel::appendFileFromCloud(const QString &fileClaudPath, ...@@ -181,7 +190,7 @@ void CloudFileListModel::appendFileFromCloud(const QString &fileClaudPath,
endInsertRows(); endInsertRows();
} }
void CloudFileListModel::setFileSelected(const QString &filePath, bool selected) void CloudFileListModel::setFileSelected(const QString &filePath)
{ {
if (Q_UNLIKELY(filePath.isEmpty())) { if (Q_UNLIKELY(filePath.isEmpty())) {
return; return;
...@@ -190,7 +199,7 @@ void CloudFileListModel::setFileSelected(const QString &filePath, bool selected) ...@@ -190,7 +199,7 @@ void CloudFileListModel::setFileSelected(const QString &filePath, bool selected)
for (int i = 0; i < m_files.size(); ++i) { for (int i = 0; i < m_files.size(); ++i) {
if (filePath == m_files.at(i).fileClaudPath()) { if (filePath == m_files.at(i).fileClaudPath()) {
beginResetModel(); beginResetModel();
m_files[i].setSelected(selected); m_files[i].setSelected(!m_files[i].selected());
endResetModel(); endResetModel();
} }
} }
......
...@@ -129,6 +129,15 @@ public: ...@@ -129,6 +129,15 @@ public:
Q_INVOKABLE Q_INVOKABLE
QString fileCloudPathFromRow(int row); QString fileCloudPathFromRow(int row);
/*!
* @brief Return file path from attachment model.
*
* @param[in] row Row specifying the item.
* @return File path string.
*/
Q_INVOKABLE
QString fileShortCloudPathFromRow(int row);
/*! /*!
* @brief Returns item flags for given index. * @brief Returns item flags for given index.
* *
...@@ -160,7 +169,7 @@ public: ...@@ -160,7 +169,7 @@ public:
* @brief Set file selection to the model. * @brief Set file selection to the model.
*/ */
Q_INVOKABLE Q_INVOKABLE
void setFileSelected(const QString &filePath, bool selected); void setFileSelected(const QString &filePath);
/*! /*!
* @brief Get file selection from the model.