Browse Source

Prevent empty hostname field when showing the network login panel for the first time

Felix Paul Kühne 11 years ago
parent
commit
89ba624d3b

+ 7 - 10
AspenProject/VLCLocalServerListViewController.m

@@ -92,6 +92,9 @@
     refreshControl = [[UIRefreshControl alloc] init];
     [refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
     [self.tableView addSubview:refreshControl];
+
+    _loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:nil bundle:nil];
+    _loginViewController.delegate = self;
 }
 
 - (void)viewWillDisappear:(BOOL)animated
@@ -208,13 +211,13 @@
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
-    [_activityIndicator startAnimating];
     [tableView deselectRowAtIndexPath:indexPath animated:YES];
 
     NSUInteger row = indexPath.row;
     NSUInteger section = indexPath.section;
 
     if (section == 0) {
+        [_activityIndicator startAnimating];
         BasicUPnPDevice *device = _filteredUPNPDevices[row];
         if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
             MediaServer1Device *server = (MediaServer1Device*)device;
@@ -222,11 +225,6 @@
             [self.navigationController pushViewController:targetViewController animated:YES];
         }
     } else if (section == 1) {
-        if (_loginViewController == nil) {
-            _loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:nil bundle:nil];
-            _loginViewController.delegate = self;
-        }
-
         UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_loginViewController];
         [navCon loadTheme];
         navCon.navigationBarHidden = NO;
@@ -243,11 +241,10 @@
         } else
             [self.navigationController pushViewController:_loginViewController animated:YES];
 
-        if (row != 0) { // FTP Connect To Server Special Item
-            if ([_ftpServices[row] hostName].length > 0)
-                _loginViewController.serverAddressField.text = [NSString stringWithFormat:@"ftp://%@", [_ftpServices[row] hostName]];
+        if (row != 0 && [_ftpServices[row] hostName].length > 0) { // FTP Connect To Server Special Item and hostname is long enough
+            _loginViewController.hostname = [_ftpServices[row] hostName];
         } else
-            _loginViewController.serverAddressField.text = @"";
+            _loginViewController.hostname = @"";
     } else if (section == 2) {
         VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
         [appDelegate openMovieFromURL:[[_sapDiscoverer.discoveredMedia mediaAtIndex:row] url]];

+ 4 - 1
AspenProject/VLCNetworkLoginViewController.h

@@ -12,7 +12,7 @@
 
 @protocol VLCNetworkLoginViewController <NSObject>
 @required
-- (void)loginToURL:(NSURL *)url confirmedWithUsername:(NSString *)username andPassword:(NSString *)password;
+- (void)loginToURL:(NSURL *)url confirmedWithUsername:(NSString *)username andPassword:(NSString *)thePassword;
 @end
 
 @interface VLCNetworkLoginViewController : UIViewController
@@ -26,6 +26,9 @@
 @property (nonatomic, strong) IBOutlet UILabel *serverAddressHelpLabel;
 @property (nonatomic, strong) IBOutlet UILabel *loginHelpLabel;
 @property (weak, nonatomic) IBOutlet UITableView *historyLogin;
+@property (nonatomic, retain) NSString *hostname;
+@property (nonatomic, retain) NSString *username;
+@property (nonatomic, retain) NSString *password;
 
 @property (nonatomic, retain) id delegate;
 

+ 42 - 1
AspenProject/VLCNetworkLoginViewController.m

@@ -16,6 +16,9 @@
     NSMutableArray *_saveServer;
     NSMutableArray *_saveLogin;
     NSMutableArray *_savePass;
+    NSString *_hostname;
+    NSString *_username;
+    NSString *_password;
 }
 @end
 
@@ -69,7 +72,12 @@
     _savePass = [NSMutableArray arrayWithArray:[defaults objectForKey:kVLCFTPPassword]];
 
     [super viewWillAppear:animated];
-
+    if (_hostname.length > 0)
+        self.serverAddressField.text = _hostname;
+    if (_username.length > 0)
+        self.usernameField.text = _username;
+    if (_password.length > 0)
+        self.passwordField.text = _password;
 }
 
 - (IBAction)dismissWithAnimation:(id)sender
@@ -207,4 +215,37 @@
     [self.historyLogin deselectRowAtIndexPath:indexPath animated:NO];
 }
 
+- (void)setHostname:(NSString *)theHostname
+{
+    _hostname = theHostname;
+    self.serverAddressField.text = theHostname;
+}
+
+- (NSString *)hostname
+{
+    return self.serverAddressField.text;
+}
+
+- (void)setUsername:(NSString *)theUsername
+{
+    _username = theUsername;
+    self.usernameField.text = theUsername;
+}
+
+- (NSString *)username
+{
+    return self.usernameField.text;
+}
+
+- (void)setPassword:(NSString *)thePassword
+{
+    _password = thePassword;
+    self.passwordField.text = thePassword;
+}
+
+- (NSString *)password
+{
+    return self.passwordField.text;
+}
+
 @end