project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
changeset 4539 bad3411cba49
parent 4341 46b8791e577f
child 4540 9b614e420de5
equal deleted inserted replaced
4538:4c2dc9d75742 4539:bad3411cba49
    86 }
    86 }
    87 
    87 
    88 -(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
    88 -(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
    89     if (tagValue == 40)
    89     if (tagValue == 40)
    90         [self.settingsDictionary setObject:textString forKey:@"username"];
    90         [self.settingsDictionary setObject:textString forKey:@"username"];
    91     else
    91     else {
    92         [self.settingsDictionary setObject:textString forKey:@"password"];
    92         [self.settingsDictionary setObject:[NSNumber numberWithInt:[textString length]] forKey:@"password_length"];
       
    93         [self.settingsDictionary setObject:[textString MD5hash] forKey:@"password"];
       
    94     }
    93 }
    95 }
    94 
    96 
    95 #pragma mark -
    97 #pragma mark -
    96 #pragma mark TableView Methods
    98 #pragma mark TableView Methods
    97 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    99 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    98     return 3;
   100     return 3;
    99 }
   101 }
   100 
   102 
   101 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   103 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section {
   102     switch (section) {
   104     switch (section) {
   103         case 0:     // user and pass
   105         case 0:     // user and pass
   104             return 1;   // set 2 here for the password field
   106             return 1;   // set 2 here for the password field
   105             break;
   107             break;
   106         case 1:     // audio
   108         case 1:     // audio
   164                 editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
   166                 editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
   165                 editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
   167                 editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
   166                 editableCell.textField.secureTextEntry = NO;
   168                 editableCell.textField.secureTextEntry = NO;
   167                 editableCell.tag = 40;
   169                 editableCell.tag = 40;
   168             } else {
   170             } else {
       
   171                 // create a dummy password for setting some visual content for the password
       
   172                 int pwdLength = [[self.settingsDictionary objectForKey:@"password_length"] intValue];
       
   173                 char *dummyStr = (char *)malloc(sizeof(char)*pwdLength);
       
   174                 for (int i = 0; i < pwdLength; i++)
       
   175                     dummyStr[i] = i;
       
   176                 NSString *dummy = [[NSString alloc] initWithBytes:dummyStr length:pwdLength encoding:NSASCIIStringEncoding];
       
   177                 free(dummyStr);
   169                 editableCell.titleLabel.text = NSLocalizedString(@"Password","from the settings table");
   178                 editableCell.titleLabel.text = NSLocalizedString(@"Password","from the settings table");
   170                 editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
   179                 editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
   171                 editableCell.textField.text = [self.settingsDictionary objectForKey:@"password"];
   180                 editableCell.textField.text = dummy;
   172                 editableCell.textField.secureTextEntry = YES;
   181                 editableCell.textField.secureTextEntry = YES;
   173                 editableCell.tag = 50;
   182                 editableCell.tag = 50;
       
   183                 [dummy release];
   174             }
   184             }
   175             
   185             
   176             editableCell.accessoryView = nil;
   186             editableCell.accessoryView = nil;
   177             cell = editableCell;
   187             cell = editableCell;
   178             break;
   188             break;