Commit 0f91a37d authored by Martin Straka's avatar Martin Straka

Removed timer and some global variables

parent e5d3af96
...@@ -24,11 +24,10 @@ ...@@ -24,11 +24,10 @@
#include <QList> #include <QList>
#include <QUrl> #include <QUrl>
#import "ios/src/doc_picker_controller.h" #include "src/auxiliaries/icloud_helper.h"
#include "src/global.h"
// External globals for transporting of async result back to C++ and QML. #import "ios/src/doc_picker_controller.h"
QList<QUrl> selectedFileUrls; // Url list of selected files
bool isControllerOpen; // holds information if DocumentPickerController is active.
@interface DocumentPickerController () <UIDocumentPickerDelegate> @interface DocumentPickerController () <UIDocumentPickerDelegate>
...@@ -66,24 +65,23 @@ bool isControllerOpen; // holds information if DocumentPickerController is activ ...@@ -66,24 +65,23 @@ bool isControllerOpen; // holds information if DocumentPickerController is activ
if (controller.documentPickerMode == UIDocumentPickerModeImport) { if (controller.documentPickerMode == UIDocumentPickerModeImport) {
NSLog(@"SELECTED FILE URLs: %@", urls); NSLog(@"SELECTED FILE URLs: %@", urls);
QList<QUrl> qurls; QList<QUrl> qUrls;
// Convert NSURL on QUrl for all selected files
for (NSURL *url in urls) { for (NSURL *url in urls) {
QUrl tmpUrl = QUrl::fromNSURL(url); QUrl tmpUrl = QUrl::fromNSURL(url);
qurls.append(tmpUrl); qUrls.append(tmpUrl);
} }
selectedFileUrls = qurls; GlobInstcs::iCloudHelperPtr->importFilesToAppInbox(qUrls);
} else if (controller.documentPickerMode == UIDocumentPickerModeExportToService) { } else if (controller.documentPickerMode == UIDocumentPickerModeExportToService) {
NSLog(@"STORAGE FILE URLs: %@", urls); NSLog(@"STORAGE FILE URLs: %@", urls);
} }
isControllerOpen = false;
} }
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
Q_UNUSED(controller); Q_UNUSED(controller);
isControllerOpen = false;
} }
@end @end
...@@ -44,8 +44,7 @@ bool isSearchRunning; ...@@ -44,8 +44,7 @@ bool isSearchRunning;
ICloudHelper::ICloudHelper(QObject *parent) ICloudHelper::ICloudHelper(QObject *parent)
: QObject(parent), : QObject(parent),
m_icloudTimer(new QTimer(this)), m_icloudTimer(new QTimer(this))
m_dpcTimer(new QTimer(this))
{ {
} }
...@@ -320,40 +319,16 @@ void ICloudHelper::openDocumentPickerController(void) ...@@ -320,40 +319,16 @@ void ICloudHelper::openDocumentPickerController(void)
#ifdef Q_OS_IOS #ifdef Q_OS_IOS
if (isControllerOpen) { ICloudIo::openDocumentPickerController(QStringList());
return;
}
selectedFileUrls.clear();
isControllerOpen = ICloudIo::openDocumentPickerController(QStringList());
if (isControllerOpen) {
connect(m_dpcTimer, SIGNAL(timeout()),
this, SLOT(receivedSelectedFilePath()));
m_dpcTimer->start(200);
}
#endif /* Q_OS_IOS */ #endif /* Q_OS_IOS */
} }
void ICloudHelper::receivedSelectedFilePath(void) void ICloudHelper::importFilesToAppInbox(QList<QUrl> selectedFileUrls)
{ {
foreach (const QUrl &fileUrl, selectedFileUrls) {
#ifdef Q_OS_IOS moveFileToSendDir(fileUrl);
if (!isControllerOpen) {
m_dpcTimer->stop();
disconnect(m_dpcTimer, SIGNAL(timeout()),
this, SLOT(receivedSelectedFilePath()));
if (!selectedFileUrls.isEmpty()) {
foreach (const QUrl &fileUrl, selectedFileUrls) {
moveFileToSendDir(fileUrl);
}
selectedFileUrls.clear();
}
} }
#endif
} }
void ICloudHelper::moveFileToSendDir(const QUrl &sourceFileUrl) void ICloudHelper::moveFileToSendDir(const QUrl &sourceFileUrl)
......
...@@ -36,8 +36,6 @@ ...@@ -36,8 +36,6 @@
*/ */
extern QStringList iCloudFileList; extern QStringList iCloudFileList;
extern bool isSearchRunning; extern bool isSearchRunning;
extern QList<QUrl> selectedFileUrls;
extern bool isControllerOpen;
/*! /*!
* @brief Provides iCloud interface for iOS. * @brief Provides iCloud interface for iOS.
...@@ -140,6 +138,13 @@ public: ...@@ -140,6 +138,13 @@ public:
Q_INVOKABLE Q_INVOKABLE
QString getShortSendFilePath(const QString &sandBoxFilePath); QString getShortSendFilePath(const QString &sandBoxFilePath);
/*!
* @brief Is activated when iCloud hierarchy has been received.
*
* @param[in] selectedFileUrls Path file list of iCloud for QML.
*/
void importFilesToAppInbox(QList<QUrl> selectedFileUrls);
signals: signals:
/*! /*!
...@@ -170,11 +175,6 @@ private slots: ...@@ -170,11 +175,6 @@ private slots:
*/ */
void receivedCloudHierarchy(void); void receivedCloudHierarchy(void);
/*!
* @brief Is activated when a file has been chosen with document picker.
*/
void receivedSelectedFilePath(void);
private: private:
/*! /*!
...@@ -186,6 +186,4 @@ private: ...@@ -186,6 +186,4 @@ private:
/* Detect moment when async search response with iCloud hierarchy finished. */ /* Detect moment when async search response with iCloud hierarchy finished. */
QTimer *m_icloudTimer; QTimer *m_icloudTimer;
/* Detect moment when a file was selected with document picker contorller. */
QTimer *m_dpcTimer;
}; };
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
...@@ -40,3 +40,5 @@ class RecordsManagementDb *GlobInstcs::recMgmtDbPtr = Q_NULLPTR; ...@@ -40,3 +40,5 @@ class RecordsManagementDb *GlobInstcs::recMgmtDbPtr = Q_NULLPTR;
class AccountsMap *GlobInstcs::acntMapPtr = Q_NULLPTR; class AccountsMap *GlobInstcs::acntMapPtr = Q_NULLPTR;
class ImageProvider *GlobInstcs::imgProvPtr = Q_NULLPTR; class ImageProvider *GlobInstcs::imgProvPtr = Q_NULLPTR;
class ICloudHelper *GlobInstcs::iCloudHelperPtr = Q_NULLPTR;
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
...@@ -43,6 +43,8 @@ class AccountsMap; ...@@ -43,6 +43,8 @@ class AccountsMap;
class ImageProvider; class ImageProvider;
class ICloudHelper;
/*! /*!
* @brief The namespace holds pointers to all globally accessible structures. * @brief The namespace holds pointers to all globally accessible structures.
*/ */
...@@ -75,4 +77,6 @@ namespace GlobInstcs { ...@@ -75,4 +77,6 @@ namespace GlobInstcs {
extern extern
class ImageProvider *imgProvPtr; /*!< Image provider. */ class ImageProvider *imgProvPtr; /*!< Image provider. */
extern
class ICloudHelper *iCloudHelperPtr; /*!< iCloud helper. */
} }
...@@ -448,7 +448,6 @@ int main(int argc, char *argv[]) ...@@ -448,7 +448,6 @@ int main(int argc, char *argv[])
Messages messages; Messages messages;
Accounts accounts; Accounts accounts;
Files files; Files files;
ICloudHelper iCloudHelper;
Log log(&memLog); Log log(&memLog);
IsdsWrapper isds; IsdsWrapper isds;
GovWrapper gov(&isds); GovWrapper gov(&isds);
...@@ -458,6 +457,14 @@ int main(int argc, char *argv[]) ...@@ -458,6 +457,14 @@ int main(int argc, char *argv[])
StringManipulation strManipulation; StringManipulation strManipulation;
Zfo zfo; Zfo zfo;
ICloudHelper iCloudHelper;
GlobInstcs::iCloudHelperPtr = new (std::nothrow) ICloudHelper;
if (GlobInstcs::iCloudHelperPtr == Q_NULLPTR) {
logErrorNL("%s", "Cannot create iCloud helper.");
return EXIT_FAILURE;
}
GlobInstcs::iCloudHelperPtr = &iCloudHelper;
/* Inicialize app delegate component for interaction with iOS /* Inicialize app delegate component for interaction with iOS
* Reaction on the iOS action "Open in..." */ * Reaction on the iOS action "Open in..." */
#if defined Q_OS_IOS #if defined Q_OS_IOS
......
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