- added file handler for IOS
- fixed icon colors
This commit is contained in:
parent
ccc962505d
commit
2a444b4532
9 changed files with 184 additions and 3 deletions
|
@ -67,6 +67,14 @@ win {
|
||||||
|
|
||||||
ios {
|
ios {
|
||||||
QMAKE_ASSET_CATALOGS += shared/Assets.xcassets
|
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 += \
|
DISTFILES += \
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#if defined(Q_OS_IOS)
|
#if defined(Q_OS_IOS)
|
||||||
mPlatformShareUtils = new IosShareUtils(this);
|
#include "ios/iosshareutils.hpp"
|
||||||
#elif defined(Q_OS_ANDROID)
|
#elif defined(Q_OS_ANDROID)
|
||||||
#include <QtAndroid>
|
#include <QtAndroid>
|
||||||
#include <QAndroidActivityResultReceiver>
|
#include <QAndroidActivityResultReceiver>
|
||||||
|
@ -32,6 +32,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(Q_OS_IOS)
|
#if defined(Q_OS_IOS)
|
||||||
|
|
||||||
#elif defined(Q_OS_ANDROID)
|
#elif defined(Q_OS_ANDROID)
|
||||||
void processActivityResult(int requestCode, int resultCode);
|
void processActivityResult(int requestCode, int resultCode);
|
||||||
static FileHelper* mInstance;
|
static FileHelper* mInstance;
|
||||||
|
|
21
headers/ios/docviewcontroller.hpp
Normal file
21
headers/ios/docviewcontroller.hpp
Normal file
|
@ -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 <UIKit/UIKit.h>
|
||||||
|
#import "headers/ios/iosshareutils.hpp"
|
||||||
|
|
||||||
|
@interface DocViewController : UIViewController <UIDocumentInteractionControllerDelegate>
|
||||||
|
|
||||||
|
@property int requestId;
|
||||||
|
|
||||||
|
@property IosShareUtils *mIosShareUtils;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DOCVIEWCONTROLLER_HPP
|
28
headers/ios/iosshareutils.hpp
Executable file
28
headers/ios/iosshareutils.hpp
Executable file
|
@ -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 <QObject>
|
||||||
|
|
||||||
|
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
|
|
@ -18,6 +18,10 @@ Loader {
|
||||||
onNameChanged: {
|
onNameChanged: {
|
||||||
control.syncProperties()
|
control.syncProperties()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onColorChanged: {
|
||||||
|
control.syncProperties()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
|
|
|
@ -293,6 +293,7 @@ Page {
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
|
||||||
icon.name: "delete"
|
icon.name: "delete"
|
||||||
|
icon.color: app.style.style.textColor
|
||||||
|
|
||||||
text: "X"
|
text: "X"
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "../headers/filehelper.h"
|
#include "headers/filehelper.h"
|
||||||
|
|
||||||
#if defined(Q_OS_IOS)
|
#if defined(Q_OS_IOS)
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#elif defined(Q_OS_ANDROID)
|
||||||
#include <QtAndroidExtras/QAndroidJniObject>
|
#include <QtAndroidExtras/QAndroidJniObject>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,12 +15,15 @@ FileHelper::FileHelper(QObject *parent) : QObject(parent)
|
||||||
#elif defined(Q_OS_ANDROID)
|
#elif defined(Q_OS_ANDROID)
|
||||||
mInstance = this;
|
mInstance = this;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileHelper::viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId)
|
void FileHelper::viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId)
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_IOS)
|
#if defined(Q_OS_IOS)
|
||||||
|
IosShareUtils iosShareUtils;
|
||||||
|
iosShareUtils.sendFile(filePath, title, mimeType, requestId);
|
||||||
#elif defined(Q_OS_ANDROID)
|
#elif defined(Q_OS_ANDROID)
|
||||||
QAndroidJniObject jsPath = QAndroidJniObject::fromString(filePath);
|
QAndroidJniObject jsPath = QAndroidJniObject::fromString(filePath);
|
||||||
QAndroidJniObject jsTitle = QAndroidJniObject::fromString(title);
|
QAndroidJniObject jsTitle = QAndroidJniObject::fromString(title);
|
||||||
|
|
32
sources/ios/docviewcontroller.mm
Normal file
32
sources/ios/docviewcontroller.mm
Normal file
|
@ -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 <QDebug>
|
||||||
|
|
||||||
|
@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
|
83
sources/ios/iosshareutils.mm
Executable file
83
sources/ios/iosshareutils.mm
Executable file
|
@ -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 <UIKit/UIKit.h>
|
||||||
|
#import <QGuiApplication>
|
||||||
|
#import <QQuickWindow>
|
||||||
|
#import <QDesktopServices>
|
||||||
|
#import <QUrl>
|
||||||
|
#import <QFileInfo>
|
||||||
|
|
||||||
|
#import <UIKit/UIDocumentInteractionController.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue