Permalink
Browse files

Better support for network locks; Now with RPC and peer ports customi…

…zation
1 parent 4f4e147 commit c84171e9372f4c531e2c4c121e34bcaa91126880 @changpingc committed Dec 10, 2011
@@ -107,6 +107,8 @@
7E98A44B146A4F6D006ADF77 /* ITActivityInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E98A44A146A4F6D006ADF77 /* ITActivityInspectorViewController.m */; };
7E98A44E146A4F91006ADF77 /* ITFilesInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E98A44D146A4F90006ADF77 /* ITFilesInspectorViewController.m */; };
7E98A451146A4FA3006ADF77 /* ITPeersInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E98A450146A4FA3006ADF77 /* ITPeersInspectorViewController.m */; };
+ 7EC0F6E21492E4F300C02C73 /* ITKeyboardController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EC0F6E01492E4F200C02C73 /* ITKeyboardController.h */; };
+ 7EC0F6E31492E4F300C02C73 /* ITKeyboardController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EC0F6E11492E4F200C02C73 /* ITKeyboardController.m */; };
7EF00987146E634300AD1BA5 /* Icon-iPad.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF00981146E634200AD1BA5 /* Icon-iPad.png */; };
7EF00988146E634300AD1BA5 /* Icon-Small-50.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF00982146E634200AD1BA5 /* Icon-Small-50.png */; };
7EF00989146E634300AD1BA5 /* Icon-Small.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF00983146E634200AD1BA5 /* Icon-Small.png */; };
@@ -280,6 +282,8 @@
7E98A44D146A4F90006ADF77 /* ITFilesInspectorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ITFilesInspectorViewController.m; sourceTree = "<group>"; };
7E98A44F146A4FA3006ADF77 /* ITPeersInspectorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITPeersInspectorViewController.h; sourceTree = "<group>"; };
7E98A450146A4FA3006ADF77 /* ITPeersInspectorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ITPeersInspectorViewController.m; sourceTree = "<group>"; };
+ 7EC0F6E01492E4F200C02C73 /* ITKeyboardController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITKeyboardController.h; sourceTree = "<group>"; };
+ 7EC0F6E11492E4F200C02C73 /* ITKeyboardController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ITKeyboardController.m; sourceTree = "<group>"; };
7EEA898A146C121A006EF611 /* ITTimerListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITTimerListener.h; sourceTree = "<group>"; };
7EF00981146E634200AD1BA5 /* Icon-iPad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-iPad.png"; sourceTree = "<group>"; };
7EF00982146E634200AD1BA5 /* Icon-Small-50.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-Small-50.png"; sourceTree = "<group>"; };
@@ -524,6 +528,8 @@
7E217D69148E282A00C7BD50 /* ITPrefViewController.m */,
7EF00986146E634200AD1BA5 /* Icon@2x.png */,
7E217D66148E27EF00C7BD50 /* ITPrefViewController.xib */,
+ 7EC0F6E01492E4F200C02C73 /* ITKeyboardController.h */,
+ 7EC0F6E11492E4F200C02C73 /* ITKeyboardController.m */,
);
path = iTransmission;
sourceTree = "<group>";
@@ -608,6 +614,7 @@
7E217D6A148E282B00C7BD50 /* ITPrefViewController.h in Headers */,
7E856DA314919F4C00F9E912 /* ITNetworkSwitcher.h in Headers */,
7E856DA81491A00800F9E912 /* Reachability.h in Headers */,
+ 7EC0F6E21492E4F300C02C73 /* ITKeyboardController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -782,6 +789,7 @@
7E217D6B148E282B00C7BD50 /* ITPrefViewController.m in Sources */,
7E856DA414919F4C00F9E912 /* ITNetworkSwitcher.m in Sources */,
7E856DA91491A00800F9E912 /* Reachability.m in Sources */,
+ 7EC0F6E31492E4F300C02C73 /* ITKeyboardController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -13,7 +13,7 @@
#import "ITTimerListener.h"
#import "ITNetworkSwitcher.h"
-@interface ITAppDelegate : UIResponder <UIApplicationDelegate>
+@interface ITAppDelegate : UIResponder <UIApplicationDelegate, UIDocumentInteractionControllerDelegate>
@property (strong, nonatomic) ITController *controller;
@property (strong, nonatomic) UIWindow *window;
@@ -22,6 +22,7 @@
@property (nonatomic, strong) NSMutableArray *timerEventListeners;
@property (nonatomic, strong) NSTimer *persistentTimer;
@property (strong, nonatomic) ITNetworkSwitcher *networkSwitcher;
+@property (strong, nonatomic) UIDocumentInteractionController *interactionController;
+ (id)sharedDelegate;
- (void)startTransmission;
@@ -34,4 +35,6 @@
- (void)registerForTimerEvent:(id<ITTimerListener>)obj;
- (void)unregisterForTimerEvent:(id<ITTimerListener>)obj;
+- (void)requestToOpenURL:(NSURL*)URL;
+
@end
@@ -15,6 +15,7 @@
#import "ITInfoViewController.h"
#import "ITExperimentalViewController.h"
#import "ITPrefViewController.h"
+#import "UIAlertView+Lazy.h"
@implementation ITAppDelegate
@@ -25,7 +26,7 @@ @implementation ITAppDelegate
@synthesize persistentTimer = _persistentTimer;
@synthesize timerEventListeners = _timerEventListeners;
@synthesize networkSwitcher = _networkSwitcher;
-
+@synthesize interactionController = _interactionController;
+ (id)sharedDelegate
{
@@ -48,7 +49,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSMutableArray *viewControllers = [NSMutableArray array];
[viewControllers addObject:[[ITNavigationController alloc] initWithRootViewController:[[ITTransfersViewController alloc] init]]];
-// [viewControllers addObject:[[ITNavigationController alloc] initWithRootViewController:[[ITWebViewController alloc] init]]];
+ [viewControllers addObject:[[ITNavigationController alloc] initWithRootViewController:[[ITWebViewController alloc] init]]];
// [viewControllers addObject:[[ITExperimentalViewController alloc] init]];
[viewControllers addObject:[[ITNavigationController alloc] initWithRootViewController:[[ITPrefViewController alloc] init]]];
[viewControllers addObject:[[ITNavigationController alloc] initWithRootViewController:[[ITInfoViewController alloc] initWithPageName:@"about"]]];
@@ -61,7 +62,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.networkSwitcher = [[ITNetworkSwitcher alloc] init];
[self performSelectorInBackground:@selector(startTransmission) withObject:nil];
-// [self performSelector:@selector(_test) withObject:nil afterDelay:3.0f];
+#ifdef __EVIL_DEVEL
+ [self performSelector:@selector(_test) withObject:nil afterDelay:1.0f];
+#endif
[self.window makeKeyAndVisible];
return YES;
@@ -156,4 +159,35 @@ - (void)applicationWillTerminate:(UIApplication *)application
self.networkSwitcher = nil;
}
+- (void)requestToOpenURL:(NSURL*)URL
+{
+ if ([URL isFileURL]) {
+ self.interactionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
+ self.interactionController.delegate = self;
+
+ if ([self.interactionController presentOpenInMenuFromRect:self.window.bounds inView:self.window animated:YES] == NO) {
+ [UIAlertView showMessageWithDismissButton:[NSString stringWithFormat:@"No application can open \"%@\"!\n", [URL absoluteURL]]];
+ self.interactionController = nil;
+ }
+ }
+ else {
+ if ([[UIApplication sharedApplication] canOpenURL:URL]) {
+ [[UIApplication sharedApplication] openURL:URL];
+ }
+ else {
+ [UIAlertView showMessageWithDismissButton:[NSString stringWithFormat:@"No application can open \"%@\"!\n", [URL absoluteURL]]];
+ }
+ }
+}
+
+- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application
+{
+ self.interactionController = nil;
+}
+
+- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller
+{
+ self.interactionController = nil;
+}
+
@end
@@ -89,7 +89,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView{
self.title = title;
if ([[[[webView.request URL] absoluteString] lastPathComponent] isEqualToString:@"about.html"]) {
- NSString *viTrans = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
+ NSString *viTrans = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('itransmission_version').innerHTML = '%@'", viTrans]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('libtransmission_version').innerHTML = '%s'", LONG_VERSION_STRING]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('libevent_version').innerHTML = '%s'", _EVENT_VERSION]];
@@ -0,0 +1,36 @@
+//
+// ITKeyboardController.h
+// iTransmission
+//
+// Created by Mike Chen on 12/10/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+typedef enum _ITKeyboardToolbarOptions {
+ ITKeyboardOptionCancel = 1 << 0,
+ ITKeyboardOptionDone = 1 << 1,
+ ITKeyboardOptionResetToDefault = 1 << 2,
+} ITKeyboardToolbarOptions;
+
+@protocol ITKeyboardControllerDelegate <NSObject>
+- (ITKeyboardToolbarOptions)keyboardOptionsForTextField:(UITextField*)textField;
+- (BOOL)textFieldCanFinishEditing:(UITextField*)textField withText:(NSString *)string;
+- (void)textFieldFinishedEditing:(UITextField*)textField;
+- (NSString*)defaultTextForTextField:(UITextField*)textField;
+@end
+
+@interface ITKeyboardController : NSObject <UITextFieldDelegate>
+@property (nonatomic, strong) UIToolbar *keyboardToolbar;
+@property (nonatomic, assign) id<ITKeyboardControllerDelegate> delegate;
+@property (nonatomic, retain) UIBarButtonItem *doneButton;
+@property (nonatomic, retain) UIBarButtonItem *cancelButton;
+@property (nonatomic, retain) UIBarButtonItem *resetToDefaultButton;
+@property (nonatomic, assign) UITextField *currentTextField;
+@property (nonatomic, strong) NSString *originalText;
+- (id)initWithDelegate:(id<ITKeyboardControllerDelegate>)d;
+- (void)doneButtonClicked:(id)sender;
+- (void)cancelButtonClicked:(id)sender;
+- (void)resetToDefaultButtonClicked:(id)sender;
+@end
@@ -0,0 +1,100 @@
+//
+// ITKeyboardController.m
+// iTransmission
+//
+// Created by Mike Chen on 12/10/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "ITKeyboardController.h"
+
+@implementation ITKeyboardController
+@synthesize doneButton;
+@synthesize cancelButton;
+@synthesize resetToDefaultButton;
+@synthesize keyboardToolbar = _keyboardToolbar;
+@synthesize delegate = _delegate;
+@synthesize currentTextField;
+@synthesize originalText;
+
+- (id)initWithDelegate:(id<ITKeyboardControllerDelegate>)d
+{
+ if ((self = [super init])) {
+ self.delegate = d;
+ self.keyboardToolbar = [[UIToolbar alloc] init];
+ [self.keyboardToolbar sizeToFit];
+ self.keyboardToolbar.barStyle = UIBarStyleBlackTranslucent;
+ self.doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonClicked:)];
+ self.resetToDefaultButton = [[UIBarButtonItem alloc] initWithTitle:@"Reset Default" style:UIBarButtonItemStyleBordered target:self action:@selector(resetToDefaultButtonClicked:)];
+ self.cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonClicked:)];
+ }
+ return self;
+}
+
+- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
+{
+ [self.keyboardToolbar sizeToFit];
+ textField.inputAccessoryView = self.keyboardToolbar;
+
+ ITKeyboardToolbarOptions options = [self.delegate keyboardOptionsForTextField:textField];
+ NSMutableArray *buttons = [NSMutableArray arrayWithCapacity:4];
+ if (options & ITKeyboardOptionCancel) {
+ [buttons addObject:self.cancelButton];
+ }
+ if (options & ITKeyboardOptionResetToDefault) {
+ [buttons addObject:self.resetToDefaultButton];
+ }
+ [buttons addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];
+ if (options & ITKeyboardOptionDone) {
+ [buttons addObject:self.doneButton];
+ }
+
+ self.keyboardToolbar.items = buttons;
+
+ return YES;
+}
+
+- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
+{
+ NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
+ if ([self.delegate textFieldCanFinishEditing:textField withText:newText]) {
+ self.doneButton.enabled = YES;
+ }
+ else {
+ self.doneButton.enabled = NO;
+ }
+ return YES;
+}
+
+- (void)textFieldDidBeginEditing:(UITextField *)textField
+{
+ self.currentTextField = textField;
+ self.originalText = textField.text;
+}
+
+- (void)textFieldDidEndEditing:(UITextField *)textField
+{
+ self.currentTextField = nil;
+ [self.delegate textFieldFinishedEditing:textField];
+}
+
+- (void)doneButtonClicked:(id)sender
+{
+ [self.currentTextField resignFirstResponder];
+ self.originalText = nil;
+}
+
+- (void)cancelButtonClicked:(id)sender
+{
+ [self.currentTextField setText:self.originalText];
+ [self.currentTextField resignFirstResponder];
+}
+
+- (void)resetToDefaultButtonClicked:(id)sender
+{
+ NSString *defaultText = [self.delegate defaultTextForTextField:self.currentTextField];
+ assert(defaultText);
+ [self.currentTextField setText:defaultText];
+}
+
+@end
@@ -16,7 +16,7 @@
@property (assign, nonatomic) UIViewController *rootViewController;
@property (strong, nonatomic) ITSidebarItem *sidebarItem;
@property (strong, nonatomic) ITSidebarController *sidebarController;
-
+@property (nonatomic, assign) BOOL useDefaultTheme;
- (UIBarButtonItem*)sidebarButtonItem;
- (void)sidebarButtonItemClicked:(id)sender;
@@ -19,6 +19,7 @@ @implementation ITNavigationController
@synthesize sidebarController = _sidebarController;
@synthesize sidebarItem = _sidebarItem;
@synthesize rootViewController = _rootViewController;
+@synthesize useDefaultTheme = _useDefaultTheme;
- (UIBarButtonItem*)sidebarButtonItem
{
@@ -34,15 +35,21 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController
// self.navigationBar.barStyle = UIBarStyleBlack;
self.delegate = self;
self.rootViewController = rootViewController;
- self.navigationBar.tintColor = [UIColor barBlueColor];
- UIImage *barBackground = [UIImage imageNamed:@"bar-bg.png"];
- if ([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
- [self.navigationBar setBackgroundImage:barBackground forBarMetrics:UIBarMetricsDefault];
- }
+ _useDefaultTheme = NO;
}
return self;
}
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+}
+
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
@@ -71,10 +78,8 @@ - (void)setSidebarController:(ITSidebarController *)sidebarController
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
-// if (self.sidebarController) {
-// if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
-// viewController.navigationItem.leftBarButtonItem = [self sidebarButtonItem];
-// }
+ if (_useDefaultTheme == NO)
+ [self setUseDefaultTheme:NO];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
@@ -85,28 +90,20 @@ - (void)navigationController:(UINavigationController *)navigationController didS
// }
}
-#pragma mark - View lifecycle
-
-/*
-// Implement loadView to create a view hierarchy programmatically, without using a nib.
-- (void)loadView
-{
-}
-*/
-
-/*
-// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-- (void)viewDidLoad
-{
- [super viewDidLoad];
-}
-*/
-
-- (void)viewDidUnload
+- (void)setUseDefaultTheme:(BOOL)useDefaultTheme
{
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
+ if (useDefaultTheme == NO) {
+ self.navigationBar.tintColor = [UIColor barBlueColor];
+ UIImage *barBackground = [UIImage imageNamed:@"bar-bg.png"];
+ if ([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
+ [self.navigationBar setBackgroundImage:barBackground forBarMetrics:UIBarMetricsDefault];
+ }
+ }
+ else {
+ self.navigationBar.tintColor = nil;
+ self.navigationBar.barStyle = UIBarStyleDefault;
+ }
+ _useDefaultTheme = useDefaultTheme;
}
@end
@@ -30,4 +30,5 @@ typedef enum _ITNetworkSwitcherPolicy {
+ (id)sharedNetworkSwitcher;
- (void)reachabilityChangedNotification:(NSNotification*)notification;
- (void)updatePolicyForNetworkStatus:(NetworkStatus)status;
+- (BOOL)canStartTransfer;
@end
Oops, something went wrong.

0 comments on commit c84171e

Please sign in to comment.