Kaydet (Commit) 57058331 authored tarafından siqi's avatar siqi

slides preview works

üst 16c554e7
//
// 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
/*
* 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 <Foundation/Foundation.h>
@interface Base64 : NSObject {
@interface NSData (Base64)
}
+(id)dataWithBase64String:(NSString *)base64String;
+ (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;
@end
@end
\ No newline at end of file
//
// Base64.m
// CryptTest
//
// Created by Kiichi Takeuchi on 4/20/10.
// Copyright 2010 ObjectGraph LLC. All rights reserved.
//
/*
* 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 "Base64.h"
@implementation NSData(Base64)
@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];
}
+ (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)) {
+ (id) dataWithBase64String:(NSString *)base64Encoding
{
if ([base64Encoding length] % 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;
NSString *plist = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><plist version=\"1.0\"><data>%@</data></plist>", base64Encoding];
return [NSPropertyListSerialization propertyListWithData:[plist dataUsingEncoding:NSASCIIStringEncoding] options:0 format:NULL error:NULL];
}
+ (NSData*) decode:(NSString*) string {
return [self decode:[string cStringUsingEncoding:NSASCIIStringEncoding] length:string.length];
}
@end
......@@ -73,13 +73,11 @@
AtIndex:slideNumber];
[[NSNotificationCenter defaultCenter] postNotificationName:MSG_SLIDE_PREVIEW object:[NSNumber numberWithUnsignedInt:slideNumber]];
} else if ([instruction isEqualToString:@"slide_notes"]){
NSLog(@"Interpreter: slide_notes");
uint slideNumber = [[command objectAtIndex:1] integerValue];
NSString *notes;
NSMutableString *notes = [[NSMutableString alloc] init];
for (int i = 2; i<command.count; ++i) {
[notes stringByAppendingString:[command objectAtIndex:i]];
[notes appendString:[command objectAtIndex:i]];
}
[self.slideShow putNotes:notes
AtIndex:slideNumber];
[[NSNotificationCenter defaultCenter] postNotificationName:MSG_SLIDE_NOTES object: [NSNumber numberWithUnsignedInt:slideNumber]];
......
......@@ -62,11 +62,11 @@
*/
- (void) blankScreenWithColor:(UIColor*)color
{
CGColorRef colorRef = color.CGColor;
NSString *colorString = [CIColor colorWithCGColor:colorRef].stringRepresentation;
// CGColorRef colorRef = color.CGColor;
// NSString *colorString = [CIColor colorWithCGColor:colorRef].stringRepresentation;
// Need new server-end interface, since this is a platform dependent representation
[self.client sendCommand:[NSString stringWithFormat:@"presentation_blank_screen\n%@\n\n", colorString]];
// [self.client sendCommand:[NSString stringWithFormat:@"presentation_blank_screen\n%@\n\n", colorString]];
}
- (void) resume
......
......@@ -36,7 +36,18 @@
#define STATUS_CONNECTION_FAILED @"STATUS_CONNECTION_FAILED"
typedef enum ConnectionState : NSInteger ConnectionState;
enum ConnectionState : NSInteger {
DISCONNECTED,
SEARCHING,
CONNECTING,
CONNECTED
};
@interface CommunicationManager : NSObject
@property ConnectionState state;
@end
......@@ -8,12 +8,50 @@
#import "CommunicationManager.h"
#import "Client.h"
#import "Server.h"
#import "CommandTransmitter.h"
#import "CommandInterpreter.h"
@interface CommunicationManager()
@property (nonatomic, strong) Client* client;
@end
// Singlton Pattern
@implementation CommunicationManager
@synthesize client = _client;
@synthesize state = _state;
+ (CommunicationManager *)sharedComManager
{
static CommunicationManager *sharedComManager = nil;
static dispatch_once_t _singletonPredicate;
dispatch_once(&_singletonPredicate, ^{
sharedComManager = [[super allocWithZone:nil] init];
});
return sharedComManager;
}
- (id) init
{
self = [super init];
self.state = DISCONNECTED;
return self;
}
+ (id)allocWithZone:(NSZone *)zone
{
return [self sharedComManager];
}
@end
......@@ -17,4 +17,7 @@
- (void) putImage: (NSString *)img AtIndex: (uint) index;
- (void) putNotes: (NSString *)notes AtIndex: (uint) index;
- (UIImage *) getImageAtIndex: (uint) index;
- (NSString *) getNotesAtIndex: (uint) index;
@end
......@@ -24,21 +24,36 @@
- (SlideShow *) init{
self = [super init];
self.imagesArray = [[NSMutableArray alloc] init];
self.notesArray = [[NSMutableArray alloc] init];
_size = 0;
_currentSlide = 0;
return self;
}
- (void) putImage: (NSString *)img AtIndex: (uint) index{
[Base64 initialize];
NSData* data = [Base64 decode:img];
NSData* data = [NSData dataWithBase64String:img];
UIImage* image = [UIImage imageWithData:data];
[self.imagesArray insertObject:image atIndex:index];
[[NSNotificationCenter defaultCenter] postNotificationName:@"IMAGE_READY" object:nil];
}
- (void) putNotes: (NSString *)notes AtIndex: (uint) index{
[self.notesArray insertObject:notes atIndex:index];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTE_READY" object:nil];
}
- (UIImage *) getImageAtIndex: (uint) index
{
return [self.imagesArray objectAtIndex:index];
}
- (NSString *) getNotesAtIndex: (uint) index
{
return [self.notesArray objectAtIndex:index];
}
@end
......@@ -10,6 +10,7 @@
#import "libreoffice_sdremoteViewController.h"
#import "Server.h"
#import "Client.h"
#import "slideShowViewController.h"
@interface libreoffice_sdremoteViewController ()
......@@ -39,11 +40,18 @@
self.slideShowPreviewStartObserver = [self.center addObserverForName:STATUS_CONNECTED_SLIDESHOW_RUNNING object:nil
queue:mainQueue usingBlock:^(NSNotification *note) {
NSLog(@"Received performSegue!");
[self performSegueWithIdentifier:@"slidesPreview" sender:self];
[self performSegueWithIdentifier:@"slidesPreviewSegue" sender:self];
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"slidesPreviewSegue"]) {
slideShowViewController *destViewController = segue.destinationViewController;
destViewController.slideshow = [self.interpreter slideShow];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
......
......@@ -7,9 +7,15 @@
//
#import <UIKit/UIKit.h>
#import "SlideShow.h"
@interface slideShowViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UIWebView *lecturer_notes;
@property (nonatomic, strong) SlideShow *slideshow;
@property (nonatomic, strong) id slideShowImageReadyObserver;
@property (nonatomic, strong) id slideShowNoteReadyObserver;
@end
......@@ -7,6 +7,7 @@
//
#import "slideShowViewController.h"
#import "SlideShow.h"
@interface slideShowViewController ()
......@@ -14,6 +15,10 @@
@implementation slideShowViewController
@synthesize slideshow = _slideshow;
@synthesize slideShowImageReadyObserver = _slideShowImageReadyObserver;
@synthesize slideShowNoteReadyObserver = _slideShowNoteReadyObserver;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
......@@ -26,9 +31,23 @@
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
self.slideShowImageReadyObserver = [center addObserverForName:@"IMAGE_READY" object:nil
queue:mainQueue usingBlock:^(NSNotification *note) {
NSLog(@"Getting image to display: %@", [self.slideshow getImageAtIndex:0]);
[self.image setImage:[self.slideshow getImageAtIndex:0]];
}];
self.slideShowNoteReadyObserver = [center addObserverForName:@"NOTE_READY" object:nil
queue:mainQueue usingBlock:^(NSNotification *note) {
NSLog(@"Getting note to display: %@", [self.slideshow getNotesAtIndex:0]);
[self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:0]baseURL:nil];
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
......@@ -37,6 +56,7 @@
- (void)viewDidUnload {
[self setImage:nil];
[self setLecturer_notes:nil];
[super viewDidUnload];
}
@end
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