Commit 9d547b65 authored by Martin Straka's avatar Martin Straka

iOS: Updated objective-c codes, refactoring, used qml-interaction-zfo

parent 96db84a2
......@@ -21,7 +21,7 @@
</array>
<key>CFBundleTypeIconFiles</key>
<array>
<string>AppIcon_40px.png</string>
<string>AppIcon_80px.png</string>
</array>
</dict>
</array>
......
......@@ -22,14 +22,14 @@
*/
#include <QtCore>
#include "src/files.h"
#include "src/qml_interaction/interaction_zfo_file.h"
#import "app_delegate.h"
@implementation QtAppDelegate
/* Pointer to Files object - use openZfoFileFromStorage for zfo showing */
Files *filesPtr;
/* Pointer to InteractionZfoFile object */
InteractionZfoFile *interactionZfoFilePtr;
+(QtAppDelegate *)sharedQtAppDelegate
{
......@@ -39,7 +39,8 @@ Files *filesPtr;
return shared;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
Q_UNUSED(application);
Q_UNUSED(sourceApplication);
......@@ -48,18 +49,18 @@ Files *filesPtr;
if (url != nil && [url isFileURL]) {
if ([[url pathExtension] isEqualToString:@"zfo"]) {
//NSLog(@"URL:%@", [url absoluteString]);
if (Q_NULLPTR != filesPtr) {
filesPtr->openZfoFileFromStorage(QString::fromNSString(url.path));
if (Q_NULLPTR != interactionZfoFilePtr) {
interactionZfoFilePtr->openZfoFile(QString::fromNSString(url.path));
}
}
}
return YES;
}
void QtAppDelegateInitialize (Files *files)
void QtAppDelegateInitialize(InteractionZfoFile *interactionZfoFile)
{
/* Pointer to Files object */
filesPtr = files;
/* Pointer to InteractionZfoFile object */
interactionZfoFilePtr = interactionZfoFile;
/* Init share app delegate with iOS */
[[UIApplication sharedApplication] setDelegate:[QtAppDelegate sharedQtAppDelegate]];
//NSLog(@"Created a new appdelegate");
......
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#import <UIKit/UIKit.h>
@interface DocViewController : UIViewController <UIDocumentInteractionControllerDelegate>
......
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#import "doc_view_controller.h"
#include <QtCore>
@interface DocViewController ()
@end
......@@ -8,19 +33,23 @@
#pragma mark -
#pragma mark View Life Cycle
- (void)viewDidLoad {
- (void)viewDidLoad
{
[super viewDidLoad];
}
#pragma mark -
#pragma mark Document Interaction Controller Delegate Methods
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *)controller
{
Q_UNUSED(controller);
//return [[[[UIApplication sharedApplication]windows] firstObject]rootViewController];
return self;
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
Q_UNUSED(controller);
[self removeFromParentViewController];
}
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -27,14 +27,13 @@
#include <QtCore/QtGlobal>
#ifdef Q_OS_IOS
//#import <Foundation/Foundation.h>
//#import <Foundation/NSString.h>
#import <UIKit/UIKit.h>
@interface iOSFileOpener : NSObject <UIDocumentInteractionControllerDelegate>
+ (iOSFileOpener *)getInstance;
- (void)openFile:(NSString *)path fromViewController:(UIViewController *)viewController;
+ (iOSFileOpener *)getInstance;
- (void)openFile:(NSString *)path fromViewController:(UIViewController *)viewController;
@end
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -25,7 +25,6 @@
#include <QtCore>
@interface iOSFileOpener ()
@property (nonatomic) bool visible;
@property (nonatomic, strong) UIViewController *viewController;
......@@ -39,17 +38,14 @@
static dispatch_once_t pred;
static iOSFileOpener *instance = nil;
dispatch_once(&pred, ^{
instance = [[iOSFileOpener alloc] init];
});
dispatch_once(&pred, ^{instance = [[iOSFileOpener alloc] init];});
return instance;
}
- (id)init
{
self = [super init];
if(!self)
return nil;
if (!self) return nil;
self.visible = false;
self.documentInteractionController = [[UIDocumentInteractionController alloc] init];
......@@ -60,8 +56,7 @@
- (void)openFile:(NSString *)path fromViewController:(UIViewController *)viewController
{
if (self.visible)
return;
if (self.visible) return;
self.visible = true;
self.viewController = viewController;
......@@ -80,7 +75,6 @@
{
Q_UNUSED(controller);
self.visible = false;
}
@end
......@@ -24,14 +24,14 @@
#ifndef QTAPPDELEGATECINTERFACE_H
#define QTAPPDELEGATECINTERFACE_H
#include "src/files.h"
#include "src/qml_interaction/interaction_zfo_file.h"
/*!
* @brief Inicialization of App Delegate for interaction with iOS service
* "Open in" in Qt.
*
* @param[in] files Pointer to Files object.
* @param[in] interactionZfoFile Pointer to InteractionZfoFile object.
*/
void QtAppDelegateInitialize(Files *files);
void QtAppDelegateInitialize(InteractionZfoFile *interactionZfoFile);
#endif // QTAPPDELEGATECINTERFACE_H
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
......@@ -6,7 +29,7 @@
@interface SimpleEmailSendController:UIViewController<MFMailComposeViewControllerDelegate> {
}
- (void)createEmail:(NSString *)body sub:(NSString *)subject files:(NSArray *)filePaths;
- (void)createEmail:(NSString *)body sub:(NSString *)subject
files:(NSArray *)filePaths;
@end
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#import "send_email_controller.h"
#include <QtCore>
@implementation SimpleEmailSendController
- (void) showCantSendMailAlert {
- (void) showCantSendMailAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString(@"Can't send email", @"Can't send email")
message: NSLocalizedString(@"The device is not configured for sending email", @"The device is not configured for sending email")
delegate: self
......@@ -12,8 +38,8 @@
[alert release];
}
- (NSString *)guessMIMETypeFromFileName:(NSString *)fileName {
- (NSString *)guessMIMETypeFromFileName:(NSString *)fileName
{
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[fileName pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
CFRelease(UTI);
......@@ -23,8 +49,8 @@
return (__bridge NSString *)(MIMEType);
}
- (void)createEmail:(NSString *)body sub:(NSString *)subject files:(NSArray *)filePaths
- (void)createEmail:(NSString *)body sub:(NSString *)subject
files:(NSArray *)filePaths
{
if (![MFMailComposeViewController canSendMail]) {
[self showCantSendMailAlert];
......@@ -41,9 +67,7 @@
for (NSUInteger i = 0; i < [filePaths count]; i++) {
NSData *filedata = [NSData dataWithContentsOfFile:filePaths[i]];
NSString *filename = [filePaths[i] lastPathComponent];
//NSLog(filename);
NSString *mimetype = [self guessMIMETypeFromFileName:filename];
//NSLog(mimetype);
[controller addAttachmentData:filedata mimeType:mimetype fileName:filename];
}
......@@ -51,10 +75,11 @@
[controller release];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
Q_UNUSED(controller);
if (error) {
NSLog(@"Error : %@", error);
}
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -33,7 +33,7 @@
*/
/*!
* @brief Used for opening URLs on iOS.
* @brief Used for opening URLs and create email with attachments on iOS.
*/
class UrlOpener : public QObject {
Q_OBJECT
......@@ -46,8 +46,20 @@ public:
*/
UrlOpener(QObject *parent = 0);
/*!
* @brief Open file on iOS.
*
* @param[in] filePath Path to file.
*/
void openFile(const QString &filePath);
/*!
* @brief Create email on iOS.
*
* @param[in] bodyText Email text.
* @param[in] subject Email subject.
* @param[in] filePaths Paths to attachment files.
*/
void createEmail(const QString &bodyText, const QString &subject,
const QStringList &filePaths);
};
......
......@@ -72,7 +72,6 @@ void UrlOpener::openFile(const QString &filePath)
#endif /* !Q_OS_IOS */
}
void UrlOpener::createEmail(const QString &bodyText, const QString &subject,
const QStringList &filePaths)
{
......
......@@ -294,6 +294,11 @@ ApplicationWindow {
"fromLocalDb": false,
"rawZfoContent": fileContent
}, StackView.Immediate)
/*
* Next function has effect only for iOS.
* Detail info is in the header file.
*/
files.deleteTmpFileFromStorage(filePath)
}
}
......
......@@ -575,6 +575,8 @@ void Files::sendEmail(const QString &emailMessage, const QStringList &fileList,
{
Q_UNUSED(subject);
Q_UNUSED(body);
Q_UNUSED(emailMessage);
Q_UNUSED(msgId);
if (!fileList.isEmpty()) {
......@@ -901,3 +903,13 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
return parseXmlData(Q_NULLPTR, Q_NULLPTR, Q_NULLPTR, &attachModel,
Q_NULLPTR, getXmlFromCms(rawZfoData));
}
void Files::deleteTmpFileFromStorage(const QString &filePath)
{
#if defined Q_OS_IOS
QFile file(filePath);
file.remove();
#else
Q_UNUSED(filePath);
#endif /* defined Q_OS_IOS */
}
......@@ -202,6 +202,18 @@ public:
bool setAttachmentModel(FileListModel &attachModel,
const QByteArray &rawZfoData);
/*!
* @brief Delete temporary file from storage.
*
* @note This function is used on iOS when external ZFO file is opened.
* iOS moves target file to Datovka private folder. Here, after
* reading of file content, Datovka must this file removed itself.
*
* @param[filePath] Path to file.
*/
Q_INVOKABLE
void deleteTmpFileFromStorage(const QString &filePath);
class File {
public:
File(void)
......
......@@ -218,12 +218,6 @@ int main(int argc, char *argv[])
IsdsWrapper isds;
GlobalSettingsQmlWrapper settings;
/* Inicialize app delegate component for interaction with iOS
* Reaction on the iOS action "Open in..." */
#if defined Q_OS_IOS
QtAppDelegateInitialize(&files);
#endif
/* Connect slot for update message detail after downloading */
QObject::connect(&isds, SIGNAL(messageDownloadFinish(QString, qint64)),
&messages, SLOT(fillMessageDetail(QString, qint64)));
......@@ -259,6 +253,12 @@ int main(int argc, char *argv[])
InteractionZfoFile interactionZfoFile;
/* Inicialize app delegate component for interaction with iOS
* Reaction on the iOS action "Open in..." */
#if defined Q_OS_IOS
QtAppDelegateInitialize(&interactionZfoFile);
#endif
/* register classes in QML */
ctx->setContextProperty("isds", &isds);
ctx->setContextProperty("messages", &messages);
......
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