From 61aef7446e221539ec5dcb87233c7d8f125eefa9 Mon Sep 17 00:00:00 2001 From: Alexey Chechetkin Date: Tue, 23 Jun 2015 18:55:49 +0300 Subject: [PATCH] Created RPCServerConfig class with NSCoding implementation --- .../project.pbxproj | 15 +++- TransmissionRPCClient/AppDelegate.m | 21 ------ .../Base.lproj/LaunchScreen.xib | 19 ++--- TransmissionRPCClient/Info.plist | 1 + TransmissionRPCClient/RPCServerConfig.h | 28 ++++++++ TransmissionRPCClient/RPCServerConfig.m | 71 +++++++++++++++++++ 6 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 TransmissionRPCClient/RPCServerConfig.h create mode 100644 TransmissionRPCClient/RPCServerConfig.m diff --git a/TransmissionRPCClient.xcodeproj/project.pbxproj b/TransmissionRPCClient.xcodeproj/project.pbxproj index 8d605ba..68448e9 100644 --- a/TransmissionRPCClient.xcodeproj/project.pbxproj +++ b/TransmissionRPCClient.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 2C5810E11B39A5E50069020D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2C5810E01B39A5E50069020D /* Images.xcassets */; }; 2C5810E41B39A5E50069020D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C5810E21B39A5E50069020D /* LaunchScreen.xib */; }; 2C5810F01B39A5E50069020D /* TransmissionRPCClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C5810EF1B39A5E50069020D /* TransmissionRPCClientTests.m */; }; + 2C5810FB1B39A7B20069020D /* RPCServerConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C5810FA1B39A7B20069020D /* RPCServerConfig.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -35,6 +36,8 @@ 2C5810E91B39A5E50069020D /* TransmissionRPCClientTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TransmissionRPCClientTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 2C5810EE1B39A5E50069020D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 2C5810EF1B39A5E50069020D /* TransmissionRPCClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TransmissionRPCClientTests.m; sourceTree = ""; }; + 2C5810F91B39A7B20069020D /* RPCServerConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RPCServerConfig.h; sourceTree = ""; }; + 2C5810FA1B39A7B20069020D /* RPCServerConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RPCServerConfig.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -78,8 +81,6 @@ children = ( 2C5810DD1B39A5E50069020D /* AppDelegate.h */, 2C5810DE1B39A5E50069020D /* AppDelegate.m */, - 2C5810E01B39A5E50069020D /* Images.xcassets */, - 2C5810E21B39A5E50069020D /* LaunchScreen.xib */, 2C5810D91B39A5E50069020D /* Supporting Files */, ); path = TransmissionRPCClient; @@ -88,8 +89,12 @@ 2C5810D91B39A5E50069020D /* Supporting Files */ = { isa = PBXGroup; children = ( + 2C5810E21B39A5E50069020D /* LaunchScreen.xib */, + 2C5810E01B39A5E50069020D /* Images.xcassets */, 2C5810DA1B39A5E50069020D /* Info.plist */, 2C5810DB1B39A5E50069020D /* main.m */, + 2C5810F91B39A7B20069020D /* RPCServerConfig.h */, + 2C5810FA1B39A7B20069020D /* RPCServerConfig.m */, ); name = "Supporting Files"; sourceTree = ""; @@ -160,6 +165,7 @@ TargetAttributes = { 2C5810D51B39A5E50069020D = { CreatedOnToolsVersion = 6.3.2; + DevelopmentTeam = 72C28QMYS6; }; 2C5810E81B39A5E50069020D = { CreatedOnToolsVersion = 6.3.2; @@ -212,6 +218,7 @@ files = ( 2C5810DF1B39A5E50069020D /* AppDelegate.m in Sources */, 2C5810DC1B39A5E50069020D /* main.m in Sources */, + 2C5810FB1B39A7B20069020D /* RPCServerConfig.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -331,7 +338,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; INFOPLIST_FILE = TransmissionRPCClient/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -341,7 +350,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; INFOPLIST_FILE = TransmissionRPCClient/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/TransmissionRPCClient/AppDelegate.m b/TransmissionRPCClient/AppDelegate.m index 47d2197..b3d4e9d 100644 --- a/TransmissionRPCClient/AppDelegate.m +++ b/TransmissionRPCClient/AppDelegate.m @@ -23,26 +23,5 @@ return YES; } -- (void)applicationWillResignActive:(UIApplication *)application { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. -} @end diff --git a/TransmissionRPCClient/Base.lproj/LaunchScreen.xib b/TransmissionRPCClient/Base.lproj/LaunchScreen.xib index fc35882..9a0330f 100644 --- a/TransmissionRPCClient/Base.lproj/LaunchScreen.xib +++ b/TransmissionRPCClient/Base.lproj/LaunchScreen.xib @@ -1,7 +1,8 @@ - + - + + @@ -12,15 +13,15 @@ - diff --git a/TransmissionRPCClient/Info.plist b/TransmissionRPCClient/Info.plist index 93603dc..2359cb6 100644 --- a/TransmissionRPCClient/Info.plist +++ b/TransmissionRPCClient/Info.plist @@ -33,6 +33,7 @@ UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortraitUpsideDown UISupportedInterfaceOrientations~ipad diff --git a/TransmissionRPCClient/RPCServerConfig.h b/TransmissionRPCClient/RPCServerConfig.h new file mode 100644 index 0000000..6ce361b --- /dev/null +++ b/TransmissionRPCClient/RPCServerConfig.h @@ -0,0 +1,28 @@ +// +// RPCServerConfig.h +// Holds transmission remote rpc settings +// + +#import + +#define RPC_DEFAULT_PORT 8090 +#define RPC_DEFAULT_PATH @"/transmission/rpc" +#define RPC_DEFAULT_REFRESH_TIME 5 +#define RPC_DEFAULT_REQUEST_TIMEOUT 10 +#define RPC_DEFAULT_USE_SSL NO +#define RPC_DEFAULT_NAME @"?" +#define RPC_DEFAULT_HOST @"?" + +@interface RPCServerConfig : NSObject + +@property(nonatomic) NSString *name; // common server name +@property(nonatomic) NSString *host; // ip address of domain name of server +@property(nonatomic) int port; // RPC port to connect to (default 8090) +@property(nonatomic) NSString *rpcPath; // rpc path (default /transmission/remote/rpc +@property(nonatomic) NSString *userName; // http basic auth user name +@property(nonatomic) NSString *userPassword; // http basic auth password +@property(nonatomic) BOOL useSSL; // use https +@property(nonatomic) int refreshTime; // refresh time in seconds +@property(nonatomic) int requestTimeout; // request timeout to server in seconds + +@end diff --git a/TransmissionRPCClient/RPCServerConfig.m b/TransmissionRPCClient/RPCServerConfig.m new file mode 100644 index 0000000..460a2d5 --- /dev/null +++ b/TransmissionRPCClient/RPCServerConfig.m @@ -0,0 +1,71 @@ +// +// RPCServerConfig.m +// Holds transmission remote rpc settings + +#import "RPCServerConfig.h" + +static NSString *CODER_NAME = @"name"; +static NSString *CODER_RPC_PATH = @"path"; +static NSString *CODER_USER_NAME = @"username"; +static NSString *CODER_USER_PASSWORD = @"pass"; +static NSString *CODER_PORT = @"port"; +static NSString *CODER_HOST = @"host"; +static NSString *CODER_USE_SSL = @"ssl"; +static NSString *CODER_REFRESH_TIME = @"time"; +static NSString *CODER_REQUEST_TIMEOUT = @"reqtimeout"; + +@implementation RPCServerConfig + +// init with default params +- (instancetype)init +{ + self = [super init]; + if( self ) + { + _name = RPC_DEFAULT_NAME; + _host = RPC_DEFAULT_HOST; + _port = RPC_DEFAULT_PORT; + _useSSL = RPC_DEFAULT_USE_SSL; + _rpcPath = RPC_DEFAULT_PATH; + _refreshTime = RPC_DEFAULT_REFRESH_TIME; + _requestTimeout = RPC_DEFAULT_REQUEST_TIMEOUT; + } + + return self; +} + +#pragma mark - NSCoding protocol imp + +- (id)initWithCoder:(NSCoder *)aDecoder +{ + self = [super init]; + if( self ) + { + _name = [aDecoder decodeObjectForKey:CODER_NAME]; + _rpcPath = [aDecoder decodeObjectForKey:CODER_RPC_PATH]; + _userName = [aDecoder decodeObjectForKey:CODER_USER_NAME]; + _userPassword = [aDecoder decodeObjectForKey:CODER_USER_PASSWORD]; + _port = [aDecoder decodeIntForKey:CODER_PORT]; + _host = [aDecoder decodeObjectForKey:CODER_HOST]; + _useSSL = [aDecoder decodeBoolForKey:CODER_USE_SSL]; + _refreshTime = [aDecoder decodeIntForKey:CODER_REFRESH_TIME]; + _requestTimeout = [aDecoder decodeIntForKey:CODER_REQUEST_TIMEOUT]; + } + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:self.name forKey:CODER_NAME]; + [coder encodeObject:self.rpcPath forKey:CODER_RPC_PATH]; + [coder encodeObject:self.host forKey:CODER_HOST]; + [coder encodeObject:self.userName forKey:CODER_USER_NAME]; + [coder encodeObject:self.userPassword forKey: CODER_USER_PASSWORD]; + [coder encodeInt:self.port forKey:CODER_PORT]; + [coder encodeInt:self.refreshTime forKey: CODER_REFRESH_TIME]; + [coder encodeInt:self.requestTimeout forKey:CODER_REQUEST_TIMEOUT]; + [coder encodeBool:self.useSSL forKey:CODER_USE_SSL]; +} + +@end