[Libreoffice-commits] core.git: 2 commits - ios/iosremote

siqi me at siqi.fr
Fri Jun 7 09:34:53 PDT 2013


 ios/iosremote/iosremote.xcodeproj/project.pbxproj               |   22 +-
 ios/iosremote/iosremote/Base64.h                                |   29 ++
 ios/iosremote/iosremote/Base64.m                                |   97 ++++++++++
 ios/iosremote/iosremote/Communication/.DS_Store                 |binary
 ios/iosremote/iosremote/Communication/Client.h                  |    8 
 ios/iosremote/iosremote/Communication/Client.m                  |   71 ++++---
 ios/iosremote/iosremote/Communication/CommandInterpreter.h      |   19 +
 ios/iosremote/iosremote/Communication/CommandInterpreter.m      |   82 ++++++++
 ios/iosremote/iosremote/Communication/CommunicationManager.h    |   28 ++
 ios/iosremote/iosremote/Communication/Receiver.h                |   14 -
 ios/iosremote/iosremote/Communication/Receiver.m                |   14 -
 ios/iosremote/iosremote/Communication/SlideShow.h               |   20 ++
 ios/iosremote/iosremote/Communication/SlideShow.m               |   20 ++
 ios/iosremote/iosremote/en.lproj/MainStoryboard_iPad.storyboard |   17 -
 ios/iosremote/iosremote/libreoffice_sdremoteViewController.h    |   13 -
 ios/iosremote/iosremote/libreoffice_sdremoteViewController.m    |    7 
 16 files changed, 382 insertions(+), 79 deletions(-)

New commits:
commit d3aa6c58d40a6516c188e85ed6ad12f1b4012a94
Author: siqi <me at siqi.fr>
Date:   Fri Jun 7 18:25:00 2013 +0200

     cmd interpreter implemented

diff --git a/ios/iosremote/iosremote.xcodeproj/project.pbxproj b/ios/iosremote/iosremote.xcodeproj/project.pbxproj
index 9e02f0f..7930e11 100644
--- a/ios/iosremote/iosremote.xcodeproj/project.pbxproj
+++ b/ios/iosremote/iosremote.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		57B7625D17621E42007703F6 /* SlideShow.m in Sources */ = {isa = PBXBuildFile; fileRef = 57B7625C17621E42007703F6 /* SlideShow.m */; };
 		57C6E3F3175E06E800E8BC5F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57C6E3F2175E06E800E8BC5F /* UIKit.framework */; };
 		57C6E3F5175E06E800E8BC5F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57C6E3F4175E06E800E8BC5F /* Foundation.framework */; };
 		57C6E3F7175E06E800E8BC5F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57C6E3F6175E06E800E8BC5F /* CoreGraphics.framework */; };
@@ -21,11 +22,15 @@
 		57C6E412175E06E800E8BC5F /* libreoffice_sdremoteViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 57C6E411175E06E800E8BC5F /* libreoffice_sdremoteViewController.m */; };
 		57C6E42E175E076900E8BC5F /* Client.m in Sources */ = {isa = PBXBuildFile; fileRef = 57C6E427175E076900E8BC5F /* Client.m */; };
 		57C6E42F175E076900E8BC5F /* CommunicationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 57C6E429175E076900E8BC5F /* CommunicationManager.m */; };
-		57C6E430175E076900E8BC5F /* Receiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 57C6E42B175E076900E8BC5F /* Receiver.m */; };
+		57C6E430175E076900E8BC5F /* CommandInterpreter.m in Sources */ = {isa = PBXBuildFile; fileRef = 57C6E42B175E076900E8BC5F /* CommandInterpreter.m */; };
 		57C6E431175E076900E8BC5F /* Server.m in Sources */ = {isa = PBXBuildFile; fileRef = 57C6E42D175E076900E8BC5F /* Server.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		57B7625B17621E42007703F6 /* SlideShow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideShow.h; sourceTree = "<group>"; };
+		57B7625C17621E42007703F6 /* SlideShow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideShow.m; sourceTree = "<group>"; };
+		57B7625E1762368F007703F6 /* Base64.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Base64.h; path = ../Base64.h; sourceTree = "<group>"; };
+		57B7625F1762368F007703F6 /* Base64.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Base64.m; path = ../Base64.m; sourceTree = "<group>"; };
 		57C6E3EF175E06E800E8BC5F /* iosremote.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosremote.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		57C6E3F2175E06E800E8BC5F /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
 		57C6E3F4175E06E800E8BC5F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -47,8 +52,8 @@
 		57C6E427175E076900E8BC5F /* Client.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Client.m; sourceTree = "<group>"; };
 		57C6E428175E076900E8BC5F /* CommunicationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommunicationManager.h; sourceTree = "<group>"; };
 		57C6E429175E076900E8BC5F /* CommunicationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommunicationManager.m; sourceTree = "<group>"; };
-		57C6E42A175E076900E8BC5F /* Receiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Receiver.h; sourceTree = "<group>"; };
-		57C6E42B175E076900E8BC5F /* Receiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Receiver.m; sourceTree = "<group>"; };
+		57C6E42A175E076900E8BC5F /* CommandInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommandInterpreter.h; sourceTree = "<group>"; };
+		57C6E42B175E076900E8BC5F /* CommandInterpreter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommandInterpreter.m; sourceTree = "<group>"; };
 		57C6E42C175E076900E8BC5F /* Server.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Server.h; sourceTree = "<group>"; };
 		57C6E42D175E076900E8BC5F /* Server.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Server.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -126,14 +131,18 @@
 		57C6E425175E076900E8BC5F /* Communication */ = {
 			isa = PBXGroup;
 			children = (
+				57B7625E1762368F007703F6 /* Base64.h */,
+				57B7625F1762368F007703F6 /* Base64.m */,
 				57C6E426175E076900E8BC5F /* Client.h */,
 				57C6E427175E076900E8BC5F /* Client.m */,
 				57C6E428175E076900E8BC5F /* CommunicationManager.h */,
 				57C6E429175E076900E8BC5F /* CommunicationManager.m */,
-				57C6E42A175E076900E8BC5F /* Receiver.h */,
-				57C6E42B175E076900E8BC5F /* Receiver.m */,
+				57C6E42A175E076900E8BC5F /* CommandInterpreter.h */,
+				57C6E42B175E076900E8BC5F /* CommandInterpreter.m */,
 				57C6E42C175E076900E8BC5F /* Server.h */,
 				57C6E42D175E076900E8BC5F /* Server.m */,
+				57B7625B17621E42007703F6 /* SlideShow.h */,
+				57B7625C17621E42007703F6 /* SlideShow.m */,
 			);
 			name = Communication;
 			path = iosremote/Communication;
@@ -212,8 +221,9 @@
 				57C6E412175E06E800E8BC5F /* libreoffice_sdremoteViewController.m in Sources */,
 				57C6E42E175E076900E8BC5F /* Client.m in Sources */,
 				57C6E42F175E076900E8BC5F /* CommunicationManager.m in Sources */,
-				57C6E430175E076900E8BC5F /* Receiver.m in Sources */,
+				57C6E430175E076900E8BC5F /* CommandInterpreter.m in Sources */,
 				57C6E431175E076900E8BC5F /* Server.m in Sources */,
+				57B7625D17621E42007703F6 /* SlideShow.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/ios/iosremote/iosremote/Base64.h b/ios/iosremote/iosremote/Base64.h
new file mode 100644
index 0000000..f61160d
--- /dev/null
+++ b/ios/iosremote/iosremote/Base64.h
@@ -0,0 +1,29 @@
+//
+//  Base64.h
+//  CryptTest
+//
+//  Created by Kiichi Takeuchi on 4/20/10.
+//  Copyright 2010 ObjectGraph LLC. All rights reserved.
+// 
+// Original Source Code is donated by Cyrus
+// Public Domain License
+// http://www.cocoadev.com/index.pl?BaseSixtyFour
+
+#import <Foundation/Foundation.h>
+
+
+ at interface Base64 : NSObject {
+
+}
+
++ (void) initialize;
+
++ (NSString*) encode:(const uint8_t*) input length:(NSInteger) length;
+
++ (NSString*) encode:(NSData*) rawBytes;
+
++ (NSData*) decode:(const char*) string length:(NSInteger) inputLength;
+
++ (NSData*) decode:(NSString*) string;
+
+ at end
diff --git a/ios/iosremote/iosremote/Base64.m b/ios/iosremote/iosremote/Base64.m
new file mode 100644
index 0000000..56e080b
--- /dev/null
+++ b/ios/iosremote/iosremote/Base64.m
@@ -0,0 +1,97 @@
+//
+//  Base64.m
+//  CryptTest
+//
+//  Created by Kiichi Takeuchi on 4/20/10.
+//  Copyright 2010 ObjectGraph LLC. All rights reserved.
+//
+
+#import "Base64.h"
+
+
+ at implementation Base64
+#define ArrayLength(x) (sizeof(x)/sizeof(*(x)))
+
+static char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static char decodingTable[128];
+
++ (void) initialize {
+	if (self == [Base64 class]) {
+		memset(decodingTable, 0, ArrayLength(decodingTable));
+		for (NSInteger i = 0; i < ArrayLength(encodingTable); i++) {
+			decodingTable[encodingTable[i]] = i;
+		}
+	}
+}
+
+
++ (NSString*) encode:(const uint8_t*) input length:(NSInteger) length {
+    NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
+    uint8_t* output = (uint8_t*)data.mutableBytes;
+	
+    for (NSInteger i = 0; i < length; i += 3) {
+        NSInteger value = 0;
+        for (NSInteger j = i; j < (i + 3); j++) {
+            value <<= 8;
+			
+            if (j < length) {
+                value |= (0xFF & input[j]);
+            }
+        }
+		
+        NSInteger index = (i / 3) * 4;
+        output[index + 0] =                    encodingTable[(value >> 18) & 0x3F];
+        output[index + 1] =                    encodingTable[(value >> 12) & 0x3F];
+        output[index + 2] = (i + 1) < length ? encodingTable[(value >> 6)  & 0x3F] : '=';
+        output[index + 3] = (i + 2) < length ? encodingTable[(value >> 0)  & 0x3F] : '=';
+    }
+	
+    return [[[NSString alloc] initWithData:data
+                                  encoding:NSASCIIStringEncoding] autorelease];
+}
+
+
++ (NSString*) encode:(NSData*) rawBytes {
+    return [self encode:(const uint8_t*) rawBytes.bytes length:rawBytes.length];
+}
+
+
++ (NSData*) decode:(const char*) string length:(NSInteger) inputLength {
+	if ((string == NULL) || (inputLength % 4 != 0)) {
+		return nil;
+	}
+	
+	while (inputLength > 0 && string[inputLength - 1] == '=') {
+		inputLength--;
+	}
+	
+	NSInteger outputLength = inputLength * 3 / 4;
+	NSMutableData* data = [NSMutableData dataWithLength:outputLength];
+	uint8_t* output = data.mutableBytes;
+	
+	NSInteger inputPoint = 0;
+	NSInteger outputPoint = 0;
+	while (inputPoint < inputLength) {
+		char i0 = string[inputPoint++];
+		char i1 = string[inputPoint++];
+		char i2 = inputPoint < inputLength ? string[inputPoint++] : 'A'; /* 'A' will decode to \0 */
+		char i3 = inputPoint < inputLength ? string[inputPoint++] : 'A';
+		
+		output[outputPoint++] = (decodingTable[i0] << 2) | (decodingTable[i1] >> 4);
+		if (outputPoint < outputLength) {
+			output[outputPoint++] = ((decodingTable[i1] & 0xf) << 4) | (decodingTable[i2] >> 2);
+		}
+		if (outputPoint < outputLength) {
+			output[outputPoint++] = ((decodingTable[i2] & 0x3) << 6) | decodingTable[i3];
+		}
+	}
+	
+	return data;
+}
+
+
++ (NSData*) decode:(NSString*) string {
+	return [self decode:[string cStringUsingEncoding:NSASCIIStringEncoding] length:string.length];
+}
+
+ at end
diff --git a/ios/iosremote/iosremote/Communication/.DS_Store b/ios/iosremote/iosremote/Communication/.DS_Store
index bbb5276..83d9e2a 100644
Binary files a/ios/iosremote/iosremote/Communication/.DS_Store and b/ios/iosremote/iosremote/Communication/.DS_Store differ
diff --git a/ios/iosremote/iosremote/Communication/Client.h b/ios/iosremote/iosremote/Communication/Client.h
index ac98afd..7ba32a5 100644
--- a/ios/iosremote/iosremote/Communication/Client.h
+++ b/ios/iosremote/iosremote/Communication/Client.h
@@ -9,15 +9,19 @@
 #import <Foundation/Foundation.h>
 #import "Server.h"
 #import "CommunicationManager.h"
-#import "Receiver.h"
+#import "CommandInterpreter.h"
 
 @interface Client : NSObject
 
+ at property BOOL mReady;
+ at property (nonatomic, strong) NSNumber* mPin;
+ at property (nonatomic, strong) NSString* mName;
+
 -(void) connect;
 
 - (id) initWithServer:(Server*)server
             managedBy:(CommunicationManager*)manager
-        interpretedBy:(Receiver*)receiver;
+        interpretedBy:(CommandInterpreter*)receiver;
 
 -(void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode;
 
diff --git a/ios/iosremote/iosremote/Communication/Client.m b/ios/iosremote/iosremote/Communication/Client.m
index 37ac0e9..16c4aa2 100644
--- a/ios/iosremote/iosremote/Communication/Client.m
+++ b/ios/iosremote/iosremote/Communication/Client.m
@@ -9,7 +9,7 @@
 
 #import "Client.h"
 #import "Server.h"
-#import "Receiver.h"
+#import "CommandInterpreter.h"
 #import "CommunicationManager.h"
 
 @interface Client() <NSStreamDelegate>
@@ -17,18 +17,12 @@
 @property (nonatomic, strong) NSInputStream* mInputStream;
 @property (nonatomic, strong) NSOutputStream* mOutputStream;
 
- at property (nonatomic, strong) NSString* mPin;
- at property (nonatomic, strong) NSString* mName;
 @property uint mPort;
 
 @property (nonatomic, weak) Server* mServer;
- at property (nonatomic, weak) Receiver* mReceiver;
+ at property (nonatomic, weak) CommandInterpreter* mReceiver;
 @property (nonatomic, weak) CommunicationManager* mComManager;
 
- at property (nonatomic, retain) NSMutableData* mData;
-
- at property BOOL mReady;
-
 @end
 
 
@@ -41,31 +35,44 @@
 @synthesize mName = _mName;
 @synthesize mServer = _mServer;
 @synthesize mComManager = _mComManager;
- at synthesize mData = _mData;
 @synthesize mReady = _mReady;
 
 NSString * const CHARSET = @"UTF-8";
 
 - (id) initWithServer:(Server*)server
             managedBy:(CommunicationManager*)manager
-        interpretedBy:(Receiver*)receiver
+        interpretedBy:(CommandInterpreter*)receiver
 {
-    self.mPin = [self getPin];
-    NSLog(@"mPin: %@", self.mPin);
-    self.mName = [[UIDevice currentDevice] name];
-    self.mServer = server;
-    self.mComManager = manager;
-    self.mReceiver = receiver;
-    // hardcoded here to test the communication TODO
-    self.mPort = 1599;
-    
+    self = [self init];
+    if (self)
+    {
+        self.mReady = NO;
+        self.mName = [[UIDevice currentDevice] name];
+        self.mPin = [NSNumber numberWithInteger:[self getPin]];
+        self.mServer = server;
+        self.mComManager = manager;
+        self.mReceiver = receiver;
+        self.mPort = 1599;
+    }
     return self;
 }
 
-- (NSString *) getPin
+- (NSInteger) getPin
 {
+    // Look up if there is already a pin code for this client.
+    NSUserDefaults * userDefaluts = [NSUserDefaults standardUserDefaults];
+    
+    if(!userDefaluts)
+        NSLog(@"userDefaults nil");
+    NSInteger newPin = [userDefaluts integerForKey:self.mName];
+    
+    // If not, generate one.
+    if (!newPin) {
+        newPin = arc4random() % 9999;
+        [userDefaluts setInteger:newPin forKey:self.mName];
+    }
     
-    NSString* newPin = [NSString stringWithFormat:@"%04d", arc4random() % 9999];
+    return newPin;
 }
 
 - (void)streamOpenWithIp:(NSString *)ip withPortNumber:(uint)portNumber
@@ -91,8 +98,8 @@ NSString * const CHARSET = @"UTF-8";
         [self.mOutputStream setDelegate:self];
         [self.mOutputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
         [self.mOutputStream open];
-    
-//        NSLog(@"Stream opened %@ %@", @"iPad", self.mPin);
+        
+        //        NSLog(@"Stream opened %@ %@", @"iPad", self.mPin);
         
         NSArray *temp = [[NSArray alloc]initWithObjects:@"LO_SERVER_CLIENT_PAIR\n", self.mName, @"\n", self.mPin, @"\n\n", nil];
         
@@ -116,21 +123,23 @@ NSString * const CHARSET = @"UTF-8";
     switch(eventCode) {
         case NSStreamEventOpenCompleted:
             NSLog(@"Connection established");
+            self.mReady = YES;
             break;
         case NSStreamEventErrorOccurred:
             NSLog(@"Connection error occured");
             break;
         case NSStreamEventHasBytesAvailable:
         {
+            NSMutableData* data;
             NSLog(@"NSStreamEventHasBytesAvailable");
-            if(!self.mData) {
-                self.mData = [NSMutableData data];
+            if(!data) {
+                data = [NSMutableData data];
             }
             uint8_t buf[1024];
             unsigned int len = 0;
             len = [(NSInputStream *)stream read:buf maxLength:1024];
             if(len) {
-                [self.mData appendBytes:(const void *)buf length:len];
+                [data appendBytes:(const void *)buf length:len];
                 int bytesRead = 0;
                 // bytesRead is an instance variable of type NSNumber.
                 bytesRead += len;
@@ -138,17 +147,17 @@ NSString * const CHARSET = @"UTF-8";
                 NSLog(@"No data but received event for whatever reasons!");
             }
             
-            NSString *str = [[NSString alloc] initWithData:self.mData
+            NSString *str = [[NSString alloc] initWithData:data
                                                   encoding:NSUTF8StringEncoding];
             NSLog(@"Data Received: %@", str);
             
-            self.mData = nil;
+            data = nil;
         } break;
         default:
         {
-        
+            
         }
-    
+            
     }
 }
 
diff --git a/ios/iosremote/iosremote/Communication/Receiver.h b/ios/iosremote/iosremote/Communication/CommandInterpreter.h
similarity index 71%
rename from ios/iosremote/iosremote/Communication/Receiver.h
rename to ios/iosremote/iosremote/Communication/CommandInterpreter.h
index cf3781b..856bff7 100644
--- a/ios/iosremote/iosremote/Communication/Receiver.h
+++ b/ios/iosremote/iosremote/Communication/CommandInterpreter.h
@@ -8,7 +8,12 @@
 
 
 #import <Foundation/Foundation.h>
+#import "SlideShow.h"
 
- at interface Receiver : NSObject
+ at interface CommandInterpreter : NSObject
+
+ at property (nonatomic, strong) SlideShow* mSlideShow;
+
+- (void) parse:(NSArray *)cmd;
 
 @end
diff --git a/ios/iosremote/iosremote/Communication/CommandInterpreter.m b/ios/iosremote/iosremote/Communication/CommandInterpreter.m
new file mode 100644
index 0000000..91c513d
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/CommandInterpreter.m
@@ -0,0 +1,82 @@
+// -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+//
+// This file is part of the LibreOffice project.
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#import "CommandInterpreter.h"
+#import "SlideShow.h"
+#import "Base64.h"
+#import "CommunicationManager.h"
+
+ at interface CommandInterpreter()
+
+ at end
+
+ at implementation CommandInterpreter
+
+ at synthesize mSlideShow = _mSlideShow;
+
+- (BOOL) isSlideRunning {
+    return [self.mSlideShow size] > 0;
+}
+
+// Received a set of instructions from server.
+- (void) parse:(NSArray*)command{
+    if ([command count] == 0) {
+        return;
+    }
+    NSString *instruction = [command objectAtIndex:0];
+    
+    if([instruction isEqualToString:@"slideshow_started"]){
+        unsigned int slideLength = [[command objectAtIndex:1] unsignedIntValue];
+        unsigned int currentSlide = [[command objectAtIndex:2] unsignedIntValue];
+        
+        [self.mSlideShow setLength:slideLength];
+        [self.mSlideShow setCurrentSlide:currentSlide];
+        
+        [[NSNotificationCenter defaultCenter] postNotificationName:STATUS_CONNECTED_NOSLIDESHOW
+                          object:nil];
+        [[NSNotificationCenter defaultCenter] postNotificationName:MSG_SLIDE_CHANGED object:self.mSlideShow.mCurrentSlide];
+        
+    } else if ([instruction isEqualToString:@"slideshow_finished"]){
+        self.mSlideShow = [SlideShow init];
+        [[NSNotificationCenter defaultCenter] postNotificationName:STATUS_CONNECTED_NOSLIDESHOW object:nil];
+    } else {
+        if (self.mSlideShow == nil)
+            return;
+        if ([instruction isEqualToString:@"slide_updated"]) {
+            unsigned int newSlideNumber = [[command objectAtIndex:1] unsignedIntValue];
+            [self.mSlideShow setCurrentSlide:newSlideNumber];
+            
+            [[NSNotificationCenter defaultCenter] postNotificationName:MSG_SLIDE_CHANGED object:nil];
+            
+        } else if ([instruction isEqualToString:@"slide_preview"]){
+            unsigned int slideNumber = [[command objectAtIndex:1] unsignedIntValue];
+            NSString * imageData = [command objectAtIndex:2];
+            [Base64 initialize];
+            NSData* data = [Base64 decode:imageData];
+            UIImage* img = [UIImage imageWithData:data];
+            [self.mSlideShow putImage:img
+                              AtIndex:slideNumber];
+            [[NSNotificationCenter defaultCenter] postNotificationName:MSG_SLIDE_PREVIEW object:[NSNumber numberWithUnsignedInt:slideNumber]];
+        } else if ([instruction isEqualToString:@"slide_notes"]){
+            unsigned int slideNumber = [[command objectAtIndex:1] unsignedIntValue];
+            NSString *notes;
+            for (int i = 2; i<command.count; ++i) {
+                [notes stringByAppendingString:[command objectAtIndex:i]];
+            }
+            
+            [self.mSlideShow putNotes:notes
+                              AtIndex:slideNumber];
+            [[NSNotificationCenter defaultCenter] postNotificationName:MSG_SLIDE_NOTES object: [NSNumber numberWithUnsignedInt:slideNumber]];
+        }
+        
+    }
+    
+}
+
+ at end
diff --git a/ios/iosremote/iosremote/Communication/CommunicationManager.h b/ios/iosremote/iosremote/Communication/CommunicationManager.h
index 152c779..5f6de05 100644
--- a/ios/iosremote/iosremote/Communication/CommunicationManager.h
+++ b/ios/iosremote/iosremote/Communication/CommunicationManager.h
@@ -9,6 +9,34 @@
 
 #import <Foundation/Foundation.h>
 
+#define MSG_SLIDESHOW_STARTED @"SLIDESHOW_STARTED"
+#define MSG_SLIDE_CHANGED @"SLIDE_CHANGED"
+#define MSG_SLIDE_PREVIEW @"SLIDE_PREVIEW"
+#define MSG_SLIDE_NOTES @"SLIDE_NOTES"
+
+#define MSG_SERVERLIST_CHANGED @"SERVERLIST_CHANGED"
+#define MSG_PAIRING_STARTED @"PAIRING_STARTED"
+#define MSG_PAIRING_SUCCESSFUL @"PAIRING_SUCCESSFUL"
+
+/**
+ * Notify the UI that the service has connected to a server AND a slideshow
+ * is running.
+ * In this case the PresentationActivity should be started.
+ */
+#define STATUS_CONNECTED_SLIDESHOW_RUNNING @"STATUS_CONNECTED_SLIDESHOW_RUNNING"
+/**
+ * Notify the UI that the service has connected to a server AND no slideshow
+ * is running.
+ * In this case the StartPresentationActivity should be started.
+ */
+#define STATUS_CONNECTED_NOSLIDESHOW @"STATUS_CONNECTED_NOSLIDESHOW"
+
+#define STATUS_PAIRING_PINVALIDATION @"STATUS_PAIRING_PINVALIDATION"
+
+#define STATUS_CONNECTION_FAILED @"STATUS_CONNECTION_FAILED"
+
+
+
 @interface CommunicationManager : NSObject
 
 @end
diff --git a/ios/iosremote/iosremote/Communication/Receiver.m b/ios/iosremote/iosremote/Communication/Receiver.m
deleted file mode 100644
index bffd302..0000000
--- a/ios/iosremote/iosremote/Communication/Receiver.m
+++ /dev/null
@@ -1,14 +0,0 @@
-// -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-//
-// This file is part of the LibreOffice project.
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-
-#import "Receiver.h"
-
- at implementation Receiver
-
- at end
diff --git a/ios/iosremote/iosremote/Communication/SlideShow.h b/ios/iosremote/iosremote/Communication/SlideShow.h
new file mode 100644
index 0000000..11ea4d8
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/SlideShow.h
@@ -0,0 +1,20 @@
+//
+//  SlideShow.h
+//  iosremote
+//
+//  Created by Liu Siqi on 6/7/13.
+//  Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+ at interface SlideShow : NSObject
+
+ at property (nonatomic, strong) NSArray* mSlides;
+ at property (nonatomic, strong) NSNumber* mCurrentSlide;
+
+- (NSUInteger) size;
+- (void) setCurrentSlide:(NSUInteger)number;
+- (void) setLength:(NSUInteger)number;
+
+ at end
diff --git a/ios/iosremote/iosremote/Communication/SlideShow.m b/ios/iosremote/iosremote/Communication/SlideShow.m
new file mode 100644
index 0000000..d6435e9
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/SlideShow.m
@@ -0,0 +1,20 @@
+//
+//  SlideShow.m
+//  iosremote
+//
+//  Created by Liu Siqi on 6/7/13.
+//  Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import "SlideShow.h"
+
+ at implementation SlideShow
+
+ at synthesize mSlides = _mSlides;
+ at synthesize mCurrentSlide = _mCurrentSlide;
+
+- (NSUInteger) size{
+    return self.mSlides.count;
+}
+
+ at end
diff --git a/ios/iosremote/iosremote/en.lproj/MainStoryboard_iPad.storyboard b/ios/iosremote/iosremote/en.lproj/MainStoryboard_iPad.storyboard
index 0571d20..d4a118a 100644
--- a/ios/iosremote/iosremote/en.lproj/MainStoryboard_iPad.storyboard
+++ b/ios/iosremote/iosremote/en.lproj/MainStoryboard_iPad.storyboard
@@ -18,6 +18,13 @@
                                 <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                 <textInputTraits key="textInputTraits"/>
                             </textField>
+                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="pinLabel" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Cg3-f5-zuM">
+                                <rect key="frame" x="253" y="218" width="263" height="82"/>
+                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                                <fontDescription key="fontDescription" type="system" pointSize="64"/>
+                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+                                <nil key="highlightedColor"/>
+                            </label>
                         </subviews>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                     </view>
@@ -30,6 +37,7 @@
                     </navigationItem>
                     <connections>
                         <outlet property="ipAddressTextEdit" destination="9w1-Ym-HcF" id="hab-JH-3Lf"/>
+                        <outlet property="pinLabel" destination="Cg3-f5-zuM" id="HaU-jr-8oJ"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="3" sceneMemberID="firstResponder"/>
@@ -55,15 +63,6 @@
             <point key="canvasLocation" x="721" y="-301"/>
         </scene>
     </scenes>
-    <classes>
-        <class className="libreoffice_sdremoteViewController" superclassName="UIViewController">
-            <source key="sourceIdentifier" type="project" relativePath="./Classes/libreoffice_sdremoteViewController.h"/>
-            <relationships>
-                <relationship kind="action" name="connectToServer:"/>
-                <relationship kind="outlet" name="ipAddressTextEdit" candidateClass="UITextField"/>
-            </relationships>
-        </class>
-    </classes>
     <simulatedMetricsContainer key="defaultSimulatedMetrics">
         <simulatedStatusBarMetrics key="statusBar" statusBarStyle="blackTranslucent"/>
         <simulatedOrientationMetrics key="orientation"/>
diff --git a/ios/iosremote/iosremote/libreoffice_sdremoteViewController.h b/ios/iosremote/iosremote/libreoffice_sdremoteViewController.h
index 077b1b3..504c902 100644
--- a/ios/iosremote/iosremote/libreoffice_sdremoteViewController.h
+++ b/ios/iosremote/iosremote/libreoffice_sdremoteViewController.h
@@ -1,11 +1,10 @@
-// -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 //
-// This file is part of the LibreOffice project.
+//  libreoffice_sdremoteViewController.h
+//  iosremote
+//
+//  Created by Liu Siqi on 6/4/13.
+//  Copyright (c) 2013 libreoffice. All rights reserved.
 //
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
 
 #import <UIKit/UIKit.h>
 
@@ -13,6 +12,8 @@
 
 - (IBAction)connectToServer:(id)sender;
 
+ at property (weak, nonatomic) IBOutlet UILabel *pinLabel;
+
 @property (weak, nonatomic) IBOutlet UITextField *ipAddressTextEdit;
 
 @end
diff --git a/ios/iosremote/iosremote/libreoffice_sdremoteViewController.m b/ios/iosremote/iosremote/libreoffice_sdremoteViewController.m
index 504b976..ba4340b 100644
--- a/ios/iosremote/iosremote/libreoffice_sdremoteViewController.m
+++ b/ios/iosremote/iosremote/libreoffice_sdremoteViewController.m
@@ -42,11 +42,18 @@
     self.server = [[Server alloc] initWithProtocol:NETWORK atAddress:address ofName:@"Server"];
     self.client = [[Client alloc] initWithServer:self.server managedBy:nil interpretedBy:nil];
     [self.client connect];
+    
+    if([self.client mReady])
+    {
+        [self.pinLabel setText:[NSString stringWithFormat:@"%@", self.client.mPin]];
+    }
 }
 
 
 - (void)viewDidUnload {
     [self setIpAddressTextEdit:nil];
+    [self setPinLabel:nil];
+    [self setPinLabel:nil];
     [super viewDidUnload];
 }
 @end
commit f78070377035eaafd51a1eb36c821e131c987887
Author: siqi <me at siqi.fr>
Date:   Wed Jun 5 10:57:00 2013 +0200

    autogen client pin

diff --git a/ios/iosremote/iosremote/Communication/Client.m b/ios/iosremote/iosremote/Communication/Client.m
index b5e6644..37ac0e9 100644
--- a/ios/iosremote/iosremote/Communication/Client.m
+++ b/ios/iosremote/iosremote/Communication/Client.m
@@ -50,7 +50,7 @@ NSString * const CHARSET = @"UTF-8";
             managedBy:(CommunicationManager*)manager
         interpretedBy:(Receiver*)receiver
 {
-    self.mPin = [NSString stringWithFormat:@"%04d", arc4random() % 9999];
+    self.mPin = [self getPin];
     NSLog(@"mPin: %@", self.mPin);
     self.mName = [[UIDevice currentDevice] name];
     self.mServer = server;
@@ -62,6 +62,12 @@ NSString * const CHARSET = @"UTF-8";
     return self;
 }
 
+- (NSString *) getPin
+{
+    
+    NSString* newPin = [NSString stringWithFormat:@"%04d", arc4random() % 9999];
+}
+
 - (void)streamOpenWithIp:(NSString *)ip withPortNumber:(uint)portNumber
 {
     NSLog(@"Connecting to %@:%u", ip, portNumber);


More information about the Libreoffice-commits mailing list