icloud_helper.h 4.85 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 * This program 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.
 *
 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

#pragma once

#include <QObject>
#include <QString>
#include <QStringList>
#include <QTimer>
30
#include <QUrl>
31

32 33 34 35 36
/*
 * External global variables. These are using for transporting of async results
 * from native objective-C methods back to C++ and QML.
 * Used for iCloud file search async query and async document picker controller.
 */
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
extern QStringList iCloudFileList;
extern bool isSearchRunning;

/*!
 * @brief Provides iCloud interface for iOS.
 */
class ICloudHelper : public QObject {
	Q_OBJECT

public:

	/*!
	 * @brief Constructor.
	 *
	 * @param[in] parent Parent object.
	 */
	ICloudHelper(QObject *parent = Q_NULLPTR);

	/*!
	 * @brief Create Datovka iCloud conteiner if not exists.
	 */
	void createCloudConteiner(void);

	/*!
	 * @brief Create and send async search query for iCloud hierarchy.
	 */
	Q_INVOKABLE
	void getCloudHierarchyAsync(void);

66 67 68 69 70 71
	/*!
	 * @brief Stop async search query for iCloud hierarchy.
	 */
	Q_INVOKABLE
	void stopCloudHierarchyAsync(void);

72 73 74 75 76 77 78 79 80 81
	/*!
	 * @brief Store files to iCloud.
	 *
	 * @param[in] srcFilePaths List of file paths to be saved into iCloud.
	 * @param[in] targetPath Target iCloud path where files will store.
	 */
	Q_INVOKABLE static
	void storeFilesToCloud(const QStringList &srcFilePaths,
	    const QString &targetPath);

82 83 84 85 86 87 88 89
	/*!
	 * @brief Store files to device local storage.
	 *
	 * @param[in] srcFilePaths List of file paths to be saved into storage.
	 */
	Q_INVOKABLE
	void storeFilesToDeviceStorage(const QStringList &srcFilePaths);

90 91 92 93
	/*!
	 * @brief Download file from iCloud if not exists in the local storage.
	 *
	 * @param[in] cloudFilePath File path in iCloud.
94
	 * @return True if success.
95 96
	 */
	Q_INVOKABLE
97 98 99 100 101 102 103 104 105 106 107 108
	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);
109 110 111 112 113 114 115 116 117 118 119 120 121 122

	/*!
	 * @brief Set iCloud file model in QML.
	 *
	 * @param[in,out] cloudFileModelVariant iCloud file model from QML.
	 * @param[in] fileList Path file list of iCloud.
	 */
	Q_INVOKABLE
	void setCloudFileModel(const QVariant &cloudFileModelVariant,
	    const QStringList &fileList);

	/*!
	 * @brief Clear send folder.
	 */
123
	Q_INVOKABLE
124 125
	void clearSendDir(void);

126 127 128 129 130 131
	/*!
	 * @brief Create and open document picker controller.
	 */
	Q_INVOKABLE
	void openDocumentPickerController(void);

132 133 134 135 136 137 138 139 140
	/*!
	 * @brief Retrun short local send file path.
	 *
	 * @param[in] sandBoxFilePath Send file path.
	 * @return Short path to app sandbox where send file was stored.
	 */
	Q_INVOKABLE
	QString getShortSendFilePath(const QString &sandBoxFilePath);

141 142 143 144 145 146 147
	/*!
	 * @brief Is activated when iCloud hierarchy has been received.
	 *
	 * @param[in] selectedFileUrls Path file list of iCloud for QML.
	 */
	void importFilesToAppInbox(QList<QUrl> selectedFileUrls);

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
signals:

	/*!
	 * @brief Is activated when iCloud hierarchy has been received.
	 *
	 * @param[in] iCloudFileList Path file list of iCloud for QML.
	 */
	void cloudContentSig(QStringList iCloudFileList);

	/*!
	 * @brief Is activated when an iCloud activity is processed.
	 *
	 * @param[in] txt Description what happened.
	 */
	void cloudActivitySig(QString txt);

164 165 166 167 168 169 170
	/*!
	 * @brief Is activated when a file has been chosen with document picker.
	 *
	 * @param[in] filePath Path file for QML.
	 */
	void fileSelectedSig(QString filePath);

171 172 173 174 175 176 177 178 179
private slots:

	/*!
	 * @brief Is activated when iCloud hierarchy has been received.
	 */
	void receivedCloudHierarchy(void);

private:

180 181 182
	/*!
	 * @brief Move file from app temporary inbox to send path.
	 *
183
	 * @param[in] sourceFileUrl Source file url from inbox.
184
	 */
185
	void moveFileToSendDir(const QUrl &sourceFileUrl);
186 187 188

	/* Detect moment when async search response with iCloud hierarchy finished. */
	QTimer *m_icloudTimer;
189
};