Commit f8edac30 authored by Karel Slaný's avatar Karel Slaný

Made some methods static.

parent 6cac4186
...@@ -35,7 +35,6 @@ class ICloudIo : public QObject { ...@@ -35,7 +35,6 @@ class ICloudIo : public QObject {
Q_OBJECT Q_OBJECT
public: public:
/*! /*!
* @brief Return state describing what happened. * @brief Return state describing what happened.
*/ */
...@@ -47,13 +46,15 @@ public: ...@@ -47,13 +46,15 @@ public:
ICLOUD_TARGET_SAVE_DIR_ERROR /*!< Target dir is missing or not created. */ ICLOUD_TARGET_SAVE_DIR_ERROR /*!< Target dir is missing or not created. */
}; };
private:
/*! /*!
* @brief Constructor. * @brief Constructor.
* *
* @param[in] parent Parent object. * @param[in] parent Parent object.
*/ */
ICloudIo(QObject *parent = Q_NULLPTR); explicit ICloudIo(QObject *parent = Q_NULLPTR);
public:
/*! /*!
* @brief Test if iCloud is on. * @brief Test if iCloud is on.
* *
......
...@@ -29,15 +29,20 @@ ICloudIo::ICloudIo(QObject *parent) ...@@ -29,15 +29,20 @@ ICloudIo::ICloudIo(QObject *parent)
{ {
} }
NSURL *getCloudBaseUrl() { static
NSURL *getCloudBaseUrl(void)
{
return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
} }
NSURL *getCloudDocumentsUrl(NSURL *baseURL) { static
NSURL *getCloudDocumentsUrl(NSURL *baseURL)
{
return [baseURL URLByAppendingPathComponent:@"Documents"]; return [baseURL URLByAppendingPathComponent:@"Documents"];
} }
bool ICloudIo::isCloudOn(void) { bool ICloudIo::isCloudOn(void)
{
return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
} }
...@@ -82,7 +87,7 @@ ICloudIo::ICloudResult ICloudIo::moveFileToCloud( ...@@ -82,7 +87,7 @@ ICloudIo::ICloudResult ICloudIo::moveFileToCloud(
bool ICloudIo::openDocumentPickerController(const QStringList &exportFilesPath) bool ICloudIo::openDocumentPickerController(const QStringList &exportFilesPath)
{ {
static DocumentPickerController* dpc = nil; static DocumentPickerController *dpc = nil;
if (dpc != nil) { if (dpc != nil) {
[dpc removeFromParentViewController]; [dpc removeFromParentViewController];
[dpc release]; [dpc release];
...@@ -101,7 +106,7 @@ bool ICloudIo::openDocumentPickerController(const QStringList &exportFilesPath) ...@@ -101,7 +106,7 @@ bool ICloudIo::openDocumentPickerController(const QStringList &exportFilesPath)
NSMutableArray<NSURL*> *exportUrls = [NSMutableArray array]; NSMutableArray<NSURL*> *exportUrls = [NSMutableArray array];
// covert export file paths to array of nsurl // covert export file paths to array of nsurl
for (int i = 0; i < exportFilesPath.count(); ++i) { for (int i = 0; i < exportFilesPath.count(); ++i) {
QUrl url = QUrl::fromLocalFile(exportFilesPath.at(i)); QUrl url(QUrl::fromLocalFile(exportFilesPath.at(i)));
if (url.isValid()) { if (url.isValid()) {
NSURL *fileUrl = url.toNSURL(); NSURL *fileUrl = url.toNSURL();
[exportUrls addObject:fileUrl]; [exportUrls addObject:fileUrl];
......
...@@ -37,19 +37,21 @@ ...@@ -37,19 +37,21 @@
class UrlOpener : public QObject { class UrlOpener : public QObject {
Q_OBJECT Q_OBJECT
public: private:
/*! /*!
* @brief Constructor. * @brief Constructor.
* *
* @param[in] parent Parent object. * @param[in] parent Parent object.
*/ */
UrlOpener(QObject *parent = 0); explicit UrlOpener(QObject *parent = Q_NULLPTR);
public:
/*! /*!
* @brief Open file on iOS. * @brief Open file on iOS.
* *
* @param[in] filePath Path to file. * @param[in] filePath Path to file.
*/ */
static
void openFile(const QString &filePath); void openFile(const QString &filePath);
/*! /*!
...@@ -60,6 +62,7 @@ public: ...@@ -60,6 +62,7 @@ public:
* @param[in] subject Email subject. * @param[in] subject Email subject.
* @param[in] filePaths Paths to attachment files. * @param[in] filePaths Paths to attachment files.
*/ */
static
void createEmail(const QString &bodyText, const QString &to, void createEmail(const QString &bodyText, const QString &to,
const QString &subject, const QStringList &filePaths); const QString &subject, const QStringList &filePaths);
}; };
...@@ -48,8 +48,8 @@ void UrlOpener::openFile(const QString &filePath) ...@@ -48,8 +48,8 @@ void UrlOpener::openFile(const QString &filePath)
#else /* Q_OS_IOS */ #else /* Q_OS_IOS */
NSString* url = filePath.toNSString(); NSString *url = filePath.toNSString();
NSURL* fileURL = [NSURL fileURLWithPath:url]; NSURL *fileURL = [NSURL fileURLWithPath:url];
static DocViewController* mtv = nil; static DocViewController* mtv = nil;
if (mtv != nil) { if (mtv != nil) {
[mtv removeFromParentViewController]; [mtv removeFromParentViewController];
...@@ -94,7 +94,7 @@ void UrlOpener::createEmail(const QString &bodyText, const QString &to, ...@@ -94,7 +94,7 @@ void UrlOpener::createEmail(const QString &bodyText, const QString &to,
} }
NSArray *filePath = [NSArray arrayWithArray:tmp]; NSArray *filePath = [NSArray arrayWithArray:tmp];
static SimpleEmailSendController* email = nil; static SimpleEmailSendController *email = nil;
if (email != nil) { if (email != nil) {
[email removeFromParentViewController]; [email removeFromParentViewController];
[email release]; [email release];
......
...@@ -127,8 +127,7 @@ void sendEmail(const QString &emailMessage, const QStringList &fileList, ...@@ -127,8 +127,7 @@ void sendEmail(const QString &emailMessage, const QStringList &fileList,
#if defined Q_OS_IOS #if defined Q_OS_IOS
UrlOpener urlOpener; UrlOpener::createEmail(body, to, subject, fileList);
urlOpener.createEmail(body, to, subject, fileList);
#elif defined Q_OS_ANDROID #elif defined Q_OS_ANDROID
......
...@@ -49,7 +49,7 @@ void IosHelper::storeFilesToCloud(const QStringList &srcFilePaths, ...@@ -49,7 +49,7 @@ void IosHelper::storeFilesToCloud(const QStringList &srcFilePaths,
if (!ICloudIo::isCloudOn()) { if (!ICloudIo::isCloudOn()) {
QMessageBox::critical(Q_NULLPTR, tr("iCloud error"), QMessageBox::critical(Q_NULLPTR, tr("iCloud error"),
tr("Unable to access iCloud Account. Open the Settings app and enter your Apple ID into iCloud settings."), tr("Unable to access iCloud account. Open the settings and check your iCloud settings."),
QMessageBox::Ok); QMessageBox::Ok);
return; return;
} }
...@@ -67,25 +67,25 @@ void IosHelper::storeFilesToCloud(const QStringList &srcFilePaths, ...@@ -67,25 +67,25 @@ void IosHelper::storeFilesToCloud(const QStringList &srcFilePaths,
switch (retCode) { switch (retCode) {
case ICloudIo::ICLOUD_NOT_ON: case ICloudIo::ICLOUD_NOT_ON:
success &= false; success = false;
errorUploads.append(tr("Unable to access iCloud!")); errorUploads.append(tr("Unable to access iCloud!"));
goto finish; goto finish;
break; break;
case ICloudIo::ICLOUD_TARGET_SAVE_DIR_ERROR: case ICloudIo::ICLOUD_TARGET_SAVE_DIR_ERROR:
success &= false; success = false;
errorUploads.append(tr("Cannot create subdir '%1' in iCloud.").arg(targetPath)); errorUploads.append(tr("Cannot create subdirectory '%1' in iCloud.").arg(targetPath));
goto finish; goto finish;
break; break;
case ICloudIo::ICLOUD_FILE_EXISTS: case ICloudIo::ICLOUD_FILE_EXISTS:
success &= false; success = false;
errorUploads.append(tr("File '%1' already exists in iCloud.").arg(fi.fileName())); errorUploads.append(tr("File '%1' already exists in iCloud.").arg(fi.fileName()));
break; break;
case ICloudIo::ICLOUD_FILE_UPLOAD_ERROR: case ICloudIo::ICLOUD_FILE_UPLOAD_ERROR:
success &= false; success = false;
errorUploads.append(tr("File '%1' upload failed.").arg(fi.fileName())); errorUploads.append(tr("File '%1' upload failed.").arg(fi.fileName()));
break; break;
case ICloudIo::ICLOUD_FILE_UPLOAD_SUCCESS: case ICloudIo::ICLOUD_FILE_UPLOAD_SUCCESS:
errorUploads.append(tr("File '%1' has been moved in iCloud.").arg(fi.fileName())); errorUploads.append(tr("File '%1' has been stored into iCloud.").arg(fi.fileName()));
break; break;
default: default:
break; break;
...@@ -93,16 +93,15 @@ void IosHelper::storeFilesToCloud(const QStringList &srcFilePaths, ...@@ -93,16 +93,15 @@ void IosHelper::storeFilesToCloud(const QStringList &srcFilePaths,
} }
finish: finish:
/* Delete files and source directory. */
/* Delete files and source dir */
QFileInfo fi(filePath); QFileInfo fi(filePath);
QDir dir(fi.absolutePath()); QDir dir(fi.absolutePath());
dir.removeRecursively(); dir.removeRecursively();
/* Show final notification */ /* Show final notification */
if (success) { if (success) {
QMessageBox::critical(Q_NULLPTR, tr("iCloud saving"), QMessageBox::information(Q_NULLPTR, tr("Saved to iCloud"),
tr("Files have been saved to iCloud.") + "\n\n" + tr("Files have been stored into 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);
...@@ -111,8 +110,8 @@ finish: ...@@ -111,8 +110,8 @@ finish:
foreach (const QString &error, errorUploads) { foreach (const QString &error, errorUploads) {
txt += "\n" + error; txt += "\n" + error;
} }
QMessageBox::critical(Q_NULLPTR, QMessageBox::warning(Q_NULLPTR,
tr("iCloud saving problem"), tr("iCloud Problem"),
tr("Files have not been saved!") + "\n" + txt, tr("Files have not been saved!") + "\n" + txt,
QMessageBox::Ok); QMessageBox::Ok);
} }
...@@ -159,33 +158,13 @@ void IosHelper::openDocumentPickerController(void) ...@@ -159,33 +158,13 @@ void IosHelper::openDocumentPickerController(void)
#endif /* Q_OS_IOS */ #endif /* Q_OS_IOS */
} }
void IosHelper::importFilesToAppInbox(QList<QUrl> selectedFileUrls) void IosHelper::importFilesToAppInbox(const QList<QUrl> &selectedFileUrls)
{ {
foreach (const QUrl &fileUrl, selectedFileUrls) { foreach (const QUrl &fileUrl, selectedFileUrls) {
moveFileToSendDir(fileUrl); moveFileToSendDir(fileUrl);
} }
} }
void IosHelper::moveFileToSendDir(const QUrl &sourceFileUrl)
{
#ifdef Q_OS_IOS
if (Q_UNLIKELY(!sourceFileUrl.isValid())) {
return;
}
QUrl targetFileUrl = ICloudIo::moveFile(sourceFileUrl, appSendDirPath());
if (targetFileUrl.isValid()) {
targetFileUrl.setScheme(QString());
emit fileSelectedSig(targetFileUrl.toString());
}
#else /* !Q_OS_IOS */
Q_UNUSED(sourceFileUrl);
#endif
}
void IosHelper::storeFilesToDeviceStorage(const QStringList &srcFilePaths) void IosHelper::storeFilesToDeviceStorage(const QStringList &srcFilePaths)
{ {
debugFuncCall(); debugFuncCall();
...@@ -211,3 +190,21 @@ bool IosHelper::isIos(void) ...@@ -211,3 +190,21 @@ bool IosHelper::isIos(void)
return false; return false;
#endif #endif
} }
void IosHelper::moveFileToSendDir(const QUrl &sourceFileUrl)
{
#ifdef Q_OS_IOS
if (Q_UNLIKELY(!sourceFileUrl.isValid())) {
return;
}
QUrl targetFileUrl(ICloudIo::moveFile(sourceFileUrl, appSendDirPath()));
if (targetFileUrl.isValid()) {
targetFileUrl.setScheme(QString());
emit fileSelectedSig(targetFileUrl.toString());
}
#else /* !Q_OS_IOS */
Q_UNUSED(sourceFileUrl);
#endif
}
...@@ -35,13 +35,12 @@ class IosHelper : public QObject { ...@@ -35,13 +35,12 @@ class IosHelper : public QObject {
Q_OBJECT Q_OBJECT
public: public:
/*! /*!
* @brief Constructor. * @brief Constructor.
* *
* @param[in] parent Parent object. * @param[in] parent Parent object.
*/ */
IosHelper(QObject *parent = Q_NULLPTR); explicit IosHelper(QObject *parent = Q_NULLPTR);
/*! /*!
* @brief Store files to iCloud. * @brief Store files to iCloud.
...@@ -49,54 +48,55 @@ public: ...@@ -49,54 +48,55 @@ public:
* @param[in] srcFilePaths List of file paths to be saved into iCloud. * @param[in] srcFilePaths List of file paths to be saved into iCloud.
* @param[in] targetPath Target iCloud path where files will store. * @param[in] targetPath Target iCloud path where files will store.
*/ */
static
void storeFilesToCloud(const QStringList &srcFilePaths, void storeFilesToCloud(const QStringList &srcFilePaths,
const QString &targetPath); const QString &targetPath);
/*! /*!
* @brief Store files to device local storage. * @brief Retrun short local send file path (without full sandbox path).
* *
* @param[in] srcFilePaths List of file paths to be saved into storage. * @param[in] sandBoxFilePath Send file path.
* @return Short path to app sandbox where send file was stored.
*/ */
void storeFilesToDeviceStorage(const QStringList &srcFilePaths); Q_INVOKABLE static
QString getShortSendFilePath(const QString &sandBoxFilePath);
/*! /*!
* @brief Clear send and tmp folder. * @brief Clear send and tmp folder.
*/ */
Q_INVOKABLE Q_INVOKABLE static
void clearSendAndTmpDirs(void); void clearSendAndTmpDirs(void);
/*! /*!
* @brief Create and open document picker controller. * @brief Create and open document picker controller.
*/ */
Q_INVOKABLE Q_INVOKABLE static
void openDocumentPickerController(void); void openDocumentPickerController(void);
/*! /*!
* @brief Retrun short local send file path (without full sandbox path). * @brief Is activated when files have been selected with iOS file picker.
* *
* @param[in] sandBoxFilePath Send file path. * @param[in] selectedFileUrls Path file list for QML.
* @return Short path to app sandbox where send file was stored.
*/ */
Q_INVOKABLE void importFilesToAppInbox(const QList<QUrl> &selectedFileUrls);
QString getShortSendFilePath(const QString &sandBoxFilePath);
/*! /*!
* @brief Is activated when files have been selected with iOS file picker. * @brief Store files to device local storage.
* *
* @param[in] selectedFileUrls Path file list for QML. * @param[in] srcFilePaths List of file paths to be saved into storage.
*/ */
void importFilesToAppInbox(QList<QUrl> selectedFileUrls); static
void storeFilesToDeviceStorage(const QStringList &srcFilePaths);
/*! /*!
* @brief iOS check for QML. * @brief iOS check for QML.
* *
* @return True if iOS. * @return True if iOS.
*/ */
Q_INVOKABLE Q_INVOKABLE static
bool isIos(void); bool isIos(void);
signals: signals:
/*! /*!
* @brief Is activated when a file has been chosen with document picker. * @brief Is activated when a file has been chosen with document picker.
* *
...@@ -105,7 +105,6 @@ signals: ...@@ -105,7 +105,6 @@ signals:
void fileSelectedSig(QString filePath); void fileSelectedSig(QString filePath);
private: private:
/*! /*!
* @brief Move file from app temporary inbox to send path. * @brief Move file from app temporary inbox to send path.
* *
......
...@@ -264,8 +264,7 @@ void Files::openAttachmentFromPath(const QString &filePath) ...@@ -264,8 +264,7 @@ void Files::openAttachmentFromPath(const QString &filePath)
#ifdef Q_OS_IOS #ifdef Q_OS_IOS
UrlOpener urlOpener; UrlOpener::openFile(filePath);
urlOpener.openFile(filePath);
#elif defined (Q_OS_ANDROID) #elif defined (Q_OS_ANDROID)
...@@ -653,9 +652,9 @@ void exportFilesiOS(const QStringList &destFilePaths, ...@@ -653,9 +652,9 @@ void exportFilesiOS(const QStringList &destFilePaths,
int ret = msgBox.exec(); int ret = msgBox.exec();
if (ret == QMessageBox::Yes) { if (ret == QMessageBox::Yes) {
GlobInstcs::iOSHelperPtr->storeFilesToCloud(destFilePaths, targetDir); IosHelper::storeFilesToCloud(destFilePaths, targetDir);
} else if (ret == QMessageBox::No) { } else if (ret == QMessageBox::No) {
GlobInstcs::iOSHelperPtr->storeFilesToDeviceStorage(destFilePaths); IosHelper::storeFilesToDeviceStorage(destFilePaths);
} }
} }
#endif #endif
......
...@@ -471,7 +471,7 @@ int main(int argc, char *argv[]) ...@@ -471,7 +471,7 @@ int main(int argc, char *argv[])
GlobInstcs::iOSHelperPtr = &iOSHelper; GlobInstcs::iOSHelperPtr = &iOSHelper;
/* Clear send and tmp dir (iOS only). */ /* Clear send and tmp dir (iOS only). */
iOSHelper.clearSendAndTmpDirs(); IosHelper::clearSendAndTmpDirs();
#endif #endif
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment