// // LocationItemView.m // iWebCams // // Created by Andreas Linde on 26.12.07. // Copyright 2007 __MyCompanyName__. All rights reserved. // #import #import #import #import #import "LocationsItemView.h" @interface LocationsItemView (Private) - (void)save; - (void)reconfig; - (NSString*)getTextField:(int)fieldIdx; - (void)returnToListAndSave:(BOOL)saveOrNot; - (int)fieldCountForType; @end @implementation LocationsItemView - (void)dealloc { [_navBar release]; [_prefsTable release]; [_editCell release]; int i; for (i = 0; i < LBIV_MAXFIELDROWS; i++) { [_editField[i] release]; } [super dealloc]; } ///////////// Constructor //////////////// - (id)initWithFrame:(struct CGRect)frame app:(id)app; { self = [super initWithFrame:frame]; if (self) { _transDelegate = app; _navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, LBIV_NAVBAR_HEIGHT)]; [_navBar showButtonsWithLeftTitle: @"Back" rightTitle: @"Save" leftBack: TRUE]; //[_navBar setPrompt: @"Details"]; [_navBar setBarStyle: 1]; [_navBar enableAnimation]; [_navBar setDelegate: self]; frame.origin.y = LBIV_NAVBAR_HEIGHT; frame.size.height -= LBIV_NAVBAR_HEIGHT; _prefsTable = [[UIPreferencesTable alloc] initWithFrame: frame]; [_prefsTable setDataSource: self]; [_prefsTable setDelegate: self]; [self addSubview: _navBar]; [self addSubview: _prefsTable]; _editCell = [[UIPreferencesTableCell alloc] init]; int i; for (i = 0; i < LBIV_MAXFIELDROWS; i++) { _editField[i] = [[UIPreferencesTextTableCell alloc] init]; } [self reconfig]; } return self; } - (void)reconfig { /* Keyboard Types: 0: Standard 1: Standard but numbers come up first 2: Phone number pad with +,*,#,"pause" (Modem mode i guess) 3: URL 4: lowercase only with dialpad numbers, no punct 5: Standard w/ alpha 6: Numberpad only 7: Numberpad only w/ alpha 8: email 9: */ NSLog(@"Row: %d", _row); [_editField[0] setTitle: @"Location"]; if (_row == -1) { [[_editField[0] textField] setText: @""]; } else { NSLog(@"Get Cell Value %@", [[_transDelegate getLocationList] objectAtIndex:_row]); [[_editField[0] textField] setText: [[_transDelegate getLocationList] objectAtIndex:_row]]; } [[_editField[0] textField] setAutoCapsType: 0]; [[_editField[2] textField] setPreferredKeyboardType: 0]; [[_editField[0] textField] setAutoCorrectionType: 1]; [_editField[1] setTitle: @"Website"]; if (_row == -1) { [[_editField[1] textField] setText: @"http://"]; } else { [[_editField[1] textField] setText: [[_transDelegate getURLList]objectAtIndex:_row]]; } [[_editField[1] textField] setAutoCapsType: 0]; [[_editField[1] textField] setPreferredKeyboardType: 3]; [[_editField[1] textField] setAutoCorrectionType: 3]; [_prefsTable reloadData]; } - (void)setItem:(int)row { NSLog(@"Set item: %d", row); _row = row; [self reconfig]; } - (NSString*)getTextField:(int)fieldIdx { if ([[_editField[fieldIdx] textField] text] != NULL) { // todo: chomp return [[NSString alloc] initWithString: [[_editField[fieldIdx] textField] text]]; } else { return[[NSString alloc] init]; } } - (void)navigationBar:(UINavigationBar*)navbar buttonClicked:(int)button { NSLog(@"navBar buttonClicked: %d", button); switch (button) { case 1: // Back [_prefsTable setKeyboardVisible:FALSE animated:TRUE]; [_transDelegate transToLocationsView]; // [self returnToListAndSave:TRUE]; break; case 0: // right button [_transDelegate changeLocation:_row name:[[_editField[0] textField] text] url:[[_editField[1] textField] text]]; [_transDelegate transToLocationsView]; break; } } - (BOOL)canSelectRow:(int)row { NSLog(@"canSelectRow: %d"); return TRUE; } - (void)tableRowSelected:(NSNotification *)notification { // Delete clicked (it's always the last row) int row = [_prefsTable selectedRow]; NSLog(@"tableRowSelected: %d editingRow %d", [_prefsTable selectedRow], [_prefsTable editingRow]); if (row == [_prefsTable editingRow] ) { // user tapped the text of the field they are editing - stop editing that cell. [_prefsTable stopEditing]; } else if (row > 0 && row <= LBIV_MAXFIELDROWS) { // user tapped a field different from the one they're editing. Switch focus. [[_editField[row - 1] textField] becomeFirstResponder]; [_prefsTable _setEditingCell:_editField[row - 1]]; } } // Start of Preference required methods - (int) numberOfGroupsInPreferencesTable: (UIPreferencesTable*)table { NSLog(@"numberOfGroupsInPreferencesTable"); return 1; } - (int) preferencesTable: (UIPreferencesTable*)table numberOfRowsInGroup: (int)group { NSLog(@"numberOfRowsInGroup: %d", group); return 2; } - (UIPreferencesTableCell*) preferencesTable: (UIPreferencesTable*)table cellForGroup: (int)group { NSLog(@"cellForGroup: %d", group); NSLog(@"editCell: %@", _editCell); return _editCell; } - (UIPreferencesTableCell*) preferencesTable: (UIPreferencesTable*)table cellForRow: (int)row inGroup: (int)group { NSLog(@"cellForRow: %d inGroup: %d", row, group); if (row >= LBIV_MAXFIELDROWS) return NULL; return _editField[row]; } - (float) preferencesTable: (UIPreferencesTable*)table heightForRow: (int)row inGroup: (int)group withProposedHeight: (float)proposed { //NSLog(@"heightForRow: %d group: %d withProposedHeight: %4.1f", row, group, proposed); return proposed; } // End of Preferences required modules @end