1
/* $Id: ConfigViewController.m 3550 2011-05-05 05:33:27Z nanang $ */
3
* Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#import "ConfigViewController.h"
20
#import "ipjsuaAppDelegate.h"
23
@implementation ConfigViewController
31
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
32
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
33
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
34
// Custom initialization
41
// Implement loadView to create a view hierarchy programmatically, without using a nib.
46
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
48
// Dismiss the keyboard when the view outside the text view is touched.
49
[textView resignFirstResponder];
50
[super touchesBegan:touches withEvent:event];
53
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
57
[textView setFont:[UIFont fontWithName:@"Courier" size:10]];
58
ipjsuaAppDelegate *appd = (ipjsuaAppDelegate *)[[UIApplication sharedApplication] delegate];
61
/* Load config file and display it in the text view */
62
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
63
NSString *cfgPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/config.cfg"];
64
textView.text = [NSMutableString stringWithContentsOfFile:cfgPath encoding:NSASCIIStringEncoding error:NULL];
66
/* Add keyboard show/hide notifications so that we can resize the text view */
68
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
69
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
70
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
72
/* Add button press event-handlers */
73
[self.button1 addTarget:self action:@selector(button1Pressed:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
74
[self.button2 addTarget:self action:@selector(button2Pressed:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
77
-(void) keyboardWillShow:(NSNotification *) note
81
/* Shrink the text view area when the keyboard appears */
82
[UIView beginAnimations:nil context:NULL];
83
[UIView setAnimationDuration:0.3];
84
CGRect r = self.textView.frame, t;
85
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
86
r.size.height -= t.size.height - 51;
87
self.textView.frame = r;
88
[UIView commitAnimations];
91
[self.button1 setEnabled:true];
92
[self.button1.titleLabel setEnabled:true];
93
[self.button2 setEnabled:true];
94
[self.button2.titleLabel setEnabled:true];
97
-(void) keyboardWillHide:(NSNotification *) note
99
CGRect r = self.textView.frame, t;
100
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
101
r.size.height += t.size.height - 51;
102
self.textView.frame = r;
106
- (void)button1Pressed:(id)sender {
107
/* Save the config file */
108
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
109
NSString *cfgPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/config.cfg"];
110
[self.textView.text writeToFile:cfgPath atomically:NO encoding:NSASCIIStringEncoding error:NULL];
112
[self.textView resignFirstResponder];
113
[self.button1 setEnabled:false];
114
[self.button1.titleLabel setEnabled:false];
115
[self.button2 setEnabled:false];
116
[self.button2.titleLabel setEnabled:false];
119
- (void)button2Pressed:(id)sender {
120
/* Reload the config file */
121
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
122
NSString *cfgPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/config.cfg"];
123
self.textView.text = [NSMutableString stringWithContentsOfFile:cfgPath encoding:NSASCIIStringEncoding error:NULL];
125
[self.textView resignFirstResponder];
126
[self.button1 setEnabled:false];
127
[self.button1.titleLabel setEnabled:false];
128
[self.button2 setEnabled:false];
129
[self.button2.titleLabel setEnabled:false];
133
// Override to allow orientations other than the default portrait orientation.
134
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
135
// Return YES for supported orientations
136
return (interfaceOrientation == UIInterfaceOrientationPortrait);
140
- (void)didReceiveMemoryWarning {
141
// Releases the view if it doesn't have a superview.
142
[super didReceiveMemoryWarning];
144
// Release any cached data, images, etc that aren't in use.
147
- (void)viewDidUnload {
148
// Release any retained subviews of the main view.
149
// e.g. self.myOutlet = nil;