1 // -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 // This file is part of the LibreOffice project.
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #import "MLOMainViewController.h"
11 #import "MLOInvoker.h"
12 #include "touch/touch.h"
17 #define APP_STUB_DEF (UIApplication *) X { (void) X;}
19 static MLOManager * instance = nil;
21 static const NSTimeInterval FADE_IN_DURATION = 0.3;
23 @interface MLOManager ()
25 @property NSObject<MLOInvoker> * invoker;
26 @property NSString * openedFileNameWithExtension;
27 @property NSString * openedFilePath;
31 @implementation MLOManager
37 self.mainViewController = nil;
39 [self resetOpenedFile];
45 return self.mainViewController != nil;
48 - (void)applicationDidEnterBackground: APP_STUB_DEF
49 - (void)applicationWillEnterForeground: APP_STUB_DEF
50 - (void)applicationDidBecomeActive: APP_STUB_DEF
51 - (void)applicationWillTerminate: APP_STUB_DEF
54 - (void)applicationWillResignActive:(UIApplication *) application{
55 if (_mainViewController) {
56 [_mainViewController hideLibreOffice];
60 -(BOOL)application:(UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions{
65 - (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
67 IGNORE_ARG(application);
69 IGNORE_ARG(oldStatusBarFrame);
71 [self.mainViewController rotate];
76 NSLog(@"L O : START LIBREOFFICE");
80 NSLog(@"L O : BEGINNING INITIALIZATION");
84 NSLog(@"L O : INITIALIZATION COMPLETED!!!");
86 NSLog(@"L O : SKIPPED. ALREADY INITIALIZED.");
90 +(MLOManager *) getInstance{
92 instance = [self new];
99 self.mainViewController = [MLOMainViewController new];
101 [[[NSThread alloc] initWithTarget:self selector:@selector(threadMainMethod:) object:nil] start];
105 -(void)addLibreOfficeAsSubview:(UIView * ) superview{
107 self.mainViewController.view.alpha = 0;
109 [superview addSubview: self.mainViewController.view];
111 [UIView animateWithDuration:FADE_IN_DURATION animations:^(){
112 self.mainViewController.view.alpha = 1;
116 -(void)showLibreOfficeAfterAddingToSuperView:(UIWindow *) window{
117 window.backgroundColor = [UIColor whiteColor];
119 [_mainViewController showLibreOffice:window];
122 - (void)threadMainMethod:(id)argument
124 IGNORE_ARG(argument);
127 NSLog(@"CALLING mlo_initialize");
131 NSLog(@"touch_lo_runMain RETURNED\r\n\r\nCALLING lo_runMain");
135 NSLog(@"lo_runMain RETURNED");
139 -(void) hideLibreOffice{
141 [self.invoker willHideLibreOffice];
145 [self resetOpenedFile];
147 [self.mainViewController.view removeFromSuperview];
149 [self.invoker didHideLibreOffice];
154 return [self.invoker bounds];
157 -(void)resetOpenedFile{
158 self.openedFileNameWithExtension = nil;
159 self.openedFilePath = nil;
162 -(void)openInLibreOfficeFilePath:(NSString *) filePath fileNameWithExtension:(NSString *) fileNameWithExtension superView:(UIView *) superview window:(UIWindow *) window invoker:
163 (NSObject<MLOInvoker> *) invoker{
164 self.invoker = invoker;
165 self.openedFileNameWithExtension = fileNameWithExtension;
166 self.openedFilePath = filePath;
167 if(mlo_open_file(filePath)){
168 [invoker willShowLibreOffice];
169 [self addLibreOfficeAsSubview:superview];
170 [self showLibreOfficeAfterAddingToSuperView:window];
171 [invoker didShowLibreOffice];
173 [self hideLibreOffice];
178 -(void)openInLibreOfficeFilePath:(NSString *) filePath superView:(UIView *) superview window:(UIWindow *) window invoker:(NSObject<MLOInvoker> *) invoker{
179 [self openInLibreOfficeFilePath:filePath
180 fileNameWithExtension:[filePath lastPathComponent]
187 -(NSString *)extension{
189 NSString * extension= [self.openedFilePath pathExtension];
190 NSLog(@"File extension is %@",extension);
193 -(NSString *)filenameWithExtension{
194 NSLog(@"Filename with extension is %@",self.openedFileNameWithExtension);
195 return self.openedFileNameWithExtension;