From 2a444b45324bd67debe3b6069a5422fc49de31e4 Mon Sep 17 00:00:00 2001 From: dorian Date: Sun, 19 Jan 2020 12:32:43 +0100 Subject: [PATCH] - added file handler for IOS - fixed icon colors --- fannyapp.pro | 8 +++ headers/filehelper.h | 3 +- headers/ios/docviewcontroller.hpp | 21 +++++++ headers/ios/iosshareutils.hpp | 28 +++++++++ qml/Components/CompatibleToolButton.qml | 4 ++ qml/Forms/FilterForm.qml | 1 + sources/filehelper.cpp | 7 ++- sources/ios/docviewcontroller.mm | 32 ++++++++++ sources/ios/iosshareutils.mm | 83 +++++++++++++++++++++++++ 9 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 headers/ios/docviewcontroller.hpp create mode 100755 headers/ios/iosshareutils.hpp create mode 100644 sources/ios/docviewcontroller.mm create mode 100755 sources/ios/iosshareutils.mm diff --git a/fannyapp.pro b/fannyapp.pro index 427fbc7..a331cfb 100644 --- a/fannyapp.pro +++ b/fannyapp.pro @@ -67,6 +67,14 @@ win { ios { QMAKE_ASSET_CATALOGS += shared/Assets.xcassets + + OBJECTIVE_SOURCES += \ + sources/ios/docviewcontroller.mm \ + sources/ios/iosshareutils.mm + + HEADERS += \ + headers/ios/docviewcontroller.hpp \ + headers/ios/iosshareutils.hpp } DISTFILES += \ diff --git a/headers/filehelper.h b/headers/filehelper.h index 2c32d95..e7d7244 100644 --- a/headers/filehelper.h +++ b/headers/filehelper.h @@ -5,7 +5,7 @@ #include #if defined(Q_OS_IOS) - mPlatformShareUtils = new IosShareUtils(this); + #include "ios/iosshareutils.hpp" #elif defined(Q_OS_ANDROID) #include #include @@ -32,6 +32,7 @@ public: private: #if defined(Q_OS_IOS) + #elif defined(Q_OS_ANDROID) void processActivityResult(int requestCode, int resultCode); static FileHelper* mInstance; diff --git a/headers/ios/docviewcontroller.hpp b/headers/ios/docviewcontroller.hpp new file mode 100644 index 0000000..896f0b8 --- /dev/null +++ b/headers/ios/docviewcontroller.hpp @@ -0,0 +1,21 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#ifndef DOCVIEWCONTROLLER_HPP +#define DOCVIEWCONTROLLER_HPP + +#import +#import "headers/ios/iosshareutils.hpp" + +@interface DocViewController : UIViewController + +@property int requestId; + +@property IosShareUtils *mIosShareUtils; + +@end + + + +#endif // DOCVIEWCONTROLLER_HPP diff --git a/headers/ios/iosshareutils.hpp b/headers/ios/iosshareutils.hpp new file mode 100755 index 0000000..8d1acc6 --- /dev/null +++ b/headers/ios/iosshareutils.hpp @@ -0,0 +1,28 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#ifndef __IOSSHAREUTILS_H__ +#define __IOSSHAREUTILS_H__ + +#include + +class IosShareUtils : public QObject +{ + Q_OBJECT + +public: + explicit IosShareUtils(QObject *parent = 0); + bool checkMimeTypeView(const QString &mimeType); + bool checkMimeTypeEdit(const QString &mimeType); + void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId); + + void handleDocumentPreviewDone(const int &requestId); + +signals: + void shareFinished(int requestCode); + void shareNoAppAvailable(int requestCode); + void shareError(int requestCode, QString message); +}; + +#endif diff --git a/qml/Components/CompatibleToolButton.qml b/qml/Components/CompatibleToolButton.qml index daa84ce..8d6e09a 100644 --- a/qml/Components/CompatibleToolButton.qml +++ b/qml/Components/CompatibleToolButton.qml @@ -18,6 +18,10 @@ Loader { onNameChanged: { control.syncProperties() } + + onColorChanged: { + control.syncProperties() + } } onTextChanged: { diff --git a/qml/Forms/FilterForm.qml b/qml/Forms/FilterForm.qml index cf3f1e2..7f7c009 100644 --- a/qml/Forms/FilterForm.qml +++ b/qml/Forms/FilterForm.qml @@ -293,6 +293,7 @@ Page { height: parent.height icon.name: "delete" + icon.color: app.style.style.textColor text: "X" diff --git a/sources/filehelper.cpp b/sources/filehelper.cpp index 59e583b..086b137 100644 --- a/sources/filehelper.cpp +++ b/sources/filehelper.cpp @@ -1,10 +1,10 @@ -#include "../headers/filehelper.h" +#include "headers/filehelper.h" #if defined(Q_OS_IOS) #include #include #include - +#elif defined(Q_OS_ANDROID) #include #include #endif @@ -15,12 +15,15 @@ FileHelper::FileHelper(QObject *parent) : QObject(parent) #elif defined(Q_OS_ANDROID) mInstance = this; #else + #endif } void FileHelper::viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) { #if defined(Q_OS_IOS) + IosShareUtils iosShareUtils; + iosShareUtils.sendFile(filePath, title, mimeType, requestId); #elif defined(Q_OS_ANDROID) QAndroidJniObject jsPath = QAndroidJniObject::fromString(filePath); QAndroidJniObject jsTitle = QAndroidJniObject::fromString(title); diff --git a/sources/ios/docviewcontroller.mm b/sources/ios/docviewcontroller.mm new file mode 100644 index 0000000..294eac5 --- /dev/null +++ b/sources/ios/docviewcontroller.mm @@ -0,0 +1,32 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#import "headers/ios/docviewcontroller.hpp" + +#include + +@interface DocViewController () +@end +@implementation DocViewController +#pragma mark - +#pragma mark View Life Cycle +- (void)viewDidLoad { + [super viewDidLoad]; +} +#pragma mark - +#pragma mark Document Interaction Controller Delegate Methods +- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller { +#pragma unused (controller) + return self; +} +- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller +{ +#pragma unused (controller) + qDebug() << "end preview"; + + self.mIosShareUtils->handleDocumentPreviewDone(self.requestId); + + [self removeFromParentViewController]; +} +@end diff --git a/sources/ios/iosshareutils.mm b/sources/ios/iosshareutils.mm new file mode 100755 index 0000000..3938aa7 --- /dev/null +++ b/sources/ios/iosshareutils.mm @@ -0,0 +1,83 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#import "headers/ios/iosshareutils.hpp" + +#import +#import +#import +#import +#import +#import + +#import + +#import "headers/ios/docviewcontroller.hpp" + +IosShareUtils::IosShareUtils(QObject *parent) : QObject(parent) +{ + // Sharing Files from other iOS Apps I got the ideas and some code contribution from: + // Thomas K. Fischer (@taskfabric) - http://taskfabric.com - thx + QDesktopServices::setUrlHandler("file", this, "handleFileUrlReceived"); +} + +bool IosShareUtils::checkMimeTypeView(const QString &mimeType) { +#pragma unused (mimeType) + // dummi implementation on iOS + // MimeType not used yet + return true; +} + +bool IosShareUtils::checkMimeTypeEdit(const QString &mimeType) { +#pragma unused (mimeType) + // dummi implementation on iOS + // MimeType not used yet + return true; +} + +// altImpl not used yet on iOS, on Android twi ways to use JNI +void IosShareUtils::sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) { +#pragma unused (title, mimeType) + + NSString* nsFilePath = filePath.toNSString(); + NSURL *nsFileUrl = [NSURL fileURLWithPath:nsFilePath]; + + static DocViewController* docViewController = nil; + if(docViewController!=nil) + { + [docViewController removeFromParentViewController]; + [docViewController release]; + } + + UIDocumentInteractionController* documentInteractionController = nil; + documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:nsFileUrl]; + + UIViewController* qtUIViewController = [[[[UIApplication sharedApplication]windows] firstObject]rootViewController]; + if(qtUIViewController!=nil) + { + docViewController = [[DocViewController alloc] init]; + + docViewController.requestId = requestId; + // we need this to be able to execute handleDocumentPreviewDone() method, + // when preview was finished + docViewController.mIosShareUtils = this; + + [qtUIViewController addChildViewController:docViewController]; + documentInteractionController.delegate = docViewController; + // [documentInteractionController presentPreviewAnimated:YES]; + if(![documentInteractionController presentPreviewAnimated:YES]) + { + emit shareError(0, tr("No App found to open: %1").arg(filePath)); + } + } +} + +void IosShareUtils::handleDocumentPreviewDone(const int &requestId) +{ + // documentInteractionControllerDidEndPreview + qDebug() << "handleShareDone: " << requestId; + //emit shareFinished(requestId); +} + +