url_opener.mm 3.17 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * 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
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
 *
 * 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.
 */

#include <QtCore> /* Include something from Qt to pull Q_OS_* definitions. */

/*
 * Code inspired by:
 * https://bugreports.qt.io/browse/QTBUG-42942
 * https://github.com/JoseExposito/ubuntuone-qt-files
 */

#ifdef Q_OS_IOS
#include "ios/src/send_email_controller.h"
#include "ios/src/doc_view_controller.h"
#include "ios/src/url_opener.h"
#endif /* Q_OS_IOS */

void UrlOpener::openFile(const QString &filePath)
{
#ifndef Q_OS_IOS

	Q_UNUSED(filePath);

#else /* Q_OS_IOS */

Karel Slaný's avatar
Karel Slaný committed
46 47
	NSString *url = filePath.toNSString();
	NSURL *fileURL = [NSURL fileURLWithPath:url];
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
	static DocViewController* mtv = nil;
	if (mtv != nil) {
		[mtv removeFromParentViewController];
		[mtv release];
	}

	UIDocumentInteractionController *documentInteractionController = nil;
	documentInteractionController = [UIDocumentInteractionController
	    interactionControllerWithURL:fileURL];

	UIViewController *rootv = [[[[UIApplication sharedApplication]windows]
	    firstObject]rootViewController];
	if (rootv != nil) {
		mtv = [[DocViewController alloc] init];
		[rootv addChildViewController:mtv];
		documentInteractionController.delegate = mtv;
		[documentInteractionController presentPreviewAnimated:NO];
	}

#endif /* !Q_OS_IOS */
}

70 71
void UrlOpener::createEmail(const QString &bodyText, const QString &to,
    const QString &subject, const QStringList &filePaths)
72 73 74
{
#ifndef Q_OS_IOS

75
	Q_UNUSED(to);
76 77 78 79 80 81
	Q_UNUSED(bodyText);
	Q_UNUSED(subject);
	Q_UNUSED(filePaths);

#else /* Q_OS_IOS */

82
	NSString *recipient = to.toNSString();
83 84 85 86 87 88 89 90 91
	NSString *body = bodyText.toNSString();
	NSString *sbjct = subject.toNSString();

	NSMutableArray *tmp = [NSMutableArray arrayWithCapacity:filePaths.size()];
	for (int i = 0; i < filePaths.size(); ++i) {
		[tmp addObject:filePaths[i].toNSString()];
	}
	NSArray *filePath = [NSArray arrayWithArray:tmp];

Karel Slaný's avatar
Karel Slaný committed
92
	static SimpleEmailSendController *email = nil;
93 94 95 96 97 98 99 100 101 102
	if (email != nil) {
		[email removeFromParentViewController];
		[email release];
	}

	UIViewController *rootv = [[[[UIApplication sharedApplication]windows]
	    firstObject]rootViewController];
	if (rootv != nil) {
		email = [[SimpleEmailSendController alloc] init];
		[rootv addChildViewController:email];
103
		[email createEmail:body rec:recipient sub:sbjct files:filePath];
104 105 106
	}
#endif /* !Q_OS_IOS */
}