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

Made some methods static.

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