diff --git a/.gitignore b/.gitignore index 14ce7f3..cb7b8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ **/xcuserdata/ +Build diff --git a/Limelight.xcodeproj/project.pbxproj b/Limelight.xcodeproj/project.pbxproj index 2d7ee76..e0ebc14 100644 --- a/Limelight.xcodeproj/project.pbxproj +++ b/Limelight.xcodeproj/project.pbxproj @@ -50,7 +50,7 @@ FBD3494319FC9C04002D2A60 /* AppManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3494219FC9C04002D2A60 /* AppManager.m */; }; FBD3495019FF2174002D2A60 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3494F19FF2174002D2A60 /* SettingsViewController.m */; }; FBD3495319FF36FB002D2A60 /* SWRevealViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3495219FF36FB002D2A60 /* SWRevealViewController.m */; }; - FBD3495B1A004411002D2A60 /* Hosts.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3495A1A004411002D2A60 /* Hosts.m */; }; + FBD3495B1A004411002D2A60 /* Host.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3495A1A004411002D2A60 /* Host.m */; }; FBD3495E1A004412002D2A60 /* Settings.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3495D1A004412002D2A60 /* Settings.m */; }; FBD349621A0089F6002D2A60 /* DataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD349611A0089F6002D2A60 /* DataManager.m */; }; FBDE86E019F7A837001C18A8 /* UIComputerView.m in Sources */ = {isa = PBXBuildFile; fileRef = FBDE86DF19F7A837001C18A8 /* UIComputerView.m */; }; @@ -227,8 +227,8 @@ FBD3495119FF36FB002D2A60 /* SWRevealViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWRevealViewController.h; sourceTree = ""; }; FBD3495219FF36FB002D2A60 /* SWRevealViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWRevealViewController.m; sourceTree = ""; }; FBD349571A003F05002D2A60 /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; - FBD349591A004411002D2A60 /* Hosts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Hosts.h; path = Database/Hosts.h; sourceTree = ""; }; - FBD3495A1A004411002D2A60 /* Hosts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Hosts.m; path = Database/Hosts.m; sourceTree = ""; }; + FBD349591A004411002D2A60 /* Host.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Host.h; path = Database/Host.h; sourceTree = ""; }; + FBD3495A1A004411002D2A60 /* Host.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Host.m; path = Database/Host.m; sourceTree = ""; }; FBD3495C1A004412002D2A60 /* Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Settings.h; path = Database/Settings.h; sourceTree = ""; }; FBD3495D1A004412002D2A60 /* Settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Settings.m; path = Database/Settings.m; sourceTree = ""; }; FBD349601A0089F6002D2A60 /* DataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DataManager.h; path = Database/DataManager.h; sourceTree = ""; }; @@ -620,8 +620,8 @@ children = ( FBD3495C1A004412002D2A60 /* Settings.h */, FBD3495D1A004412002D2A60 /* Settings.m */, - FBD349591A004411002D2A60 /* Hosts.h */, - FBD3495A1A004411002D2A60 /* Hosts.m */, + FBD349591A004411002D2A60 /* Host.h */, + FBD3495A1A004411002D2A60 /* Host.m */, FBD349601A0089F6002D2A60 /* DataManager.h */, FBD349611A0089F6002D2A60 /* DataManager.m */, ); @@ -763,7 +763,7 @@ FB89462C19F646E200339C8A /* HttpManager.m in Sources */, FB89462D19F646E200339C8A /* MDNSManager.m in Sources */, FB89462B19F646E200339C8A /* StreamView.m in Sources */, - FBD3495B1A004411002D2A60 /* Hosts.m in Sources */, + FBD3495B1A004411002D2A60 /* Host.m in Sources */, FB89463519F646E200339C8A /* MainFrameViewController.m in Sources */, FB89463619F646E200339C8A /* StreamFrameViewController.m in Sources */, FB89462819F646E200339C8A /* CryptoManager.m in Sources */, diff --git a/Limelight/Database/DataManager.h b/Limelight/Database/DataManager.h index 3a193be..88450bc 100644 --- a/Limelight/Database/DataManager.h +++ b/Limelight/Database/DataManager.h @@ -9,7 +9,7 @@ #import #import "Settings.h" #import "AppDelegate.h" -#import "Hosts.h" +#import "Host.h" @interface DataManager : NSObject @@ -17,6 +17,8 @@ - (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width; - (Settings*) retrieveSettings; - +- (NSArray*) retrieveHosts; +- (void) saveHosts; +- (Host*) createHost:(NSString*)name hostname:(NSString*)address; @end diff --git a/Limelight/Database/DataManager.m b/Limelight/Database/DataManager.m index 1613022..13f9f97 100644 --- a/Limelight/Database/DataManager.m +++ b/Limelight/Database/DataManager.m @@ -26,21 +26,20 @@ static NSInteger DEFAULT_WIDTH = 1280; settingsToSave.bitrate = [NSNumber numberWithInteger:bitrate]; settingsToSave.height = [NSNumber numberWithInteger:height]; settingsToSave.width = [NSNumber numberWithInteger:width]; - [self saveSettings:settingsToSave]; + NSError* error; + if (![[self.appDelegate managedObjectContext] save:&error]) { + NSLog(@"ERROR: Unable to save settings to database"); + } + [self.appDelegate saveContext]; } - (Settings*) retrieveSettings { - NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init]; - NSEntityDescription* entity = [NSEntityDescription entityForName:@"Settings" inManagedObjectContext:[self.appDelegate managedObjectContext]]; - [fetchRequest setEntity:entity]; - [fetchRequest setAffectedStores:[NSArray arrayWithObjects:[[self.appDelegate persistentStoreCoordinator] persistentStoreForURL:[self.appDelegate getStoreURL]], nil]]; - - NSError* error; - NSArray* fetchedRecords = [[self.appDelegate managedObjectContext] executeFetchRequest:fetchRequest error:&error]; - + NSArray* fetchedRecords = [self fetchRecords:@"Settings"]; if (fetchedRecords.count == 0) { // create a new settings object with the default values + NSEntityDescription* entity = [NSEntityDescription entityForName:@"Settings" inManagedObjectContext:[self.appDelegate managedObjectContext]]; Settings* settings = [[Settings alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]]; + settings.framerate = [NSNumber numberWithInteger:DEFAULT_FRAMERATE]; settings.bitrate = [NSNumber numberWithInteger:DEFAULT_BITRATE]; settings.height = [NSNumber numberWithInteger:DEFAULT_HEIGHT]; @@ -52,14 +51,40 @@ static NSInteger DEFAULT_WIDTH = 1280; } } -- (void) saveSettings:(Settings*)settings { +- (Host*) createHost:(NSString*)name hostname:(NSString*)address { + NSEntityDescription* entity = [NSEntityDescription entityForName:@"Host" inManagedObjectContext:[self.appDelegate managedObjectContext]]; + Host* host = [[Host alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]]; + + host.name = name; + host.address = address; + return host; +} + +- (void) saveHosts { NSError* error; if (![[self.appDelegate managedObjectContext] save:&error]) { - NSLog(@"ERROR: Unable to save settings to database"); + NSLog(@"ERROR: Unable to save hosts to database"); } - [self.appDelegate saveContext]; } +- (NSArray*) retrieveHosts { + return [self fetchRecords:@"Host"]; +} + +- (NSArray*) fetchRecords:(NSString*)entityName { + NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init]; + NSEntityDescription* entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[self.appDelegate managedObjectContext]]; + [fetchRequest setEntity:entity]; + [fetchRequest setAffectedStores:[NSArray arrayWithObjects:[[self.appDelegate persistentStoreCoordinator] persistentStoreForURL:[self.appDelegate getStoreURL]], nil]]; + + NSError* error; + NSArray* fetchedRecords = [[self.appDelegate managedObjectContext] executeFetchRequest:fetchRequest error:&error]; + //TODO: handle errors + + return fetchedRecords; + +} @end + diff --git a/Limelight/Database/Hosts.h b/Limelight/Database/Host.h similarity index 86% rename from Limelight/Database/Hosts.h rename to Limelight/Database/Host.h index 2b4d184..c63b4c4 100644 --- a/Limelight/Database/Hosts.h +++ b/Limelight/Database/Host.h @@ -1,5 +1,5 @@ // -// Hosts.h +// Host.h // Limelight // // Created by Diego Waxemberg on 10/28/14. @@ -10,7 +10,7 @@ #import -@interface Hosts : NSManagedObject +@interface Host : NSManagedObject @property (nonatomic, retain) NSString * address; @property (nonatomic, retain) NSString * name; diff --git a/Limelight/Database/Hosts.m b/Limelight/Database/Host.m similarity index 76% rename from Limelight/Database/Hosts.m rename to Limelight/Database/Host.m index 71eeaa6..7413518 100644 --- a/Limelight/Database/Hosts.m +++ b/Limelight/Database/Host.m @@ -1,15 +1,15 @@ // -// Hosts.m +// Host.m // Limelight // // Created by Diego Waxemberg on 10/28/14. // Copyright (c) 2014 Limelight Stream. All rights reserved. // -#import "Hosts.h" +#import "Host.h" -@implementation Hosts +@implementation Host @dynamic address; @dynamic name; diff --git a/Limelight/Limelight.xcdatamodeld/Limelight.xcdatamodel/contents b/Limelight/Limelight.xcdatamodeld/Limelight.xcdatamodel/contents index 4012f03..b8b065e 100644 --- a/Limelight/Limelight.xcdatamodeld/Limelight.xcdatamodel/contents +++ b/Limelight/Limelight.xcdatamodeld/Limelight.xcdatamodel/contents @@ -1,6 +1,6 @@ - - + + @@ -11,7 +11,7 @@ - - + + \ No newline at end of file diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index fe6d06c..9c992e6 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -116,7 +116,9 @@ static StreamConfiguration* streamConfig; Computer* newHost = [[Computer alloc] initWithIp:host]; [hostList addObject:newHost]; [self updateHosts:[hostList allObjects]]; - + DataManager* dataMan = [[DataManager alloc] init]; + [dataMan createHost:newHost.displayName hostname:newHost.hostName]; + [dataMan saveHosts]; //TODO: get pair state @@ -192,7 +194,8 @@ static StreamConfiguration* streamConfig; appScrollView = [[UIScrollView alloc] init]; appScrollView.frame = CGRectMake(0, hostScrollView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height / 2); [appScrollView setShowsHorizontalScrollIndicator:NO]; - + + [self retrieveSavedHosts]; [self updateHosts:[hostList allObjects]]; [self.view addSubview:hostScrollView]; [self.view addSubview:appScrollView]; @@ -200,7 +203,7 @@ static StreamConfiguration* streamConfig; - (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; + [super viewDidAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; _mDNSManager = [[MDNSManager alloc] initWithCallback:self]; [_mDNSManager searchForHosts]; @@ -208,10 +211,22 @@ static StreamConfiguration* streamConfig; - (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; + [super viewDidDisappear:animated]; [_mDNSManager stopSearching]; } +- (void) retrieveSavedHosts { + //TODO: Get rid of Computer and only use Host + + DataManager* dataMan = [[DataManager alloc] init]; + NSArray* hosts = [dataMan retrieveHosts]; + for (Host* host in hosts) { + Computer* comp = [[Computer alloc] initWithIp:host.address]; + comp.displayName = host.name; + [hostList addObject:comp]; + } +} + - (void)updateHosts:(NSArray *)hosts { [hostList addObjectsFromArray:hosts]; [[hostScrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index 667283e..0dbc7b2 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -15,7 +15,7 @@ @implementation SettingsViewController { NSInteger _bitrate; } -static NSString* bitrateFormat = @"Bitrate: %d bps"; +static NSString* bitrateFormat = @"Bitrate: %d kbps"; - (void)viewDidLoad { diff --git a/iPad.storyboard b/iPad.storyboard index 8ab6bbd..86400a9 100644 --- a/iPad.storyboard +++ b/iPad.storyboard @@ -1,36 +1,130 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -54,6 +148,7 @@ + @@ -62,16 +157,15 @@ - - + - + diff --git a/iPhone.storyboard b/iPhone.storyboard index 1068cad..cd22b7f 100644 --- a/iPhone.storyboard +++ b/iPhone.storyboard @@ -1,5 +1,5 @@ - + @@ -45,7 +45,7 @@ - + @@ -59,8 +59,8 @@ -