~ubuntu-branches/ubuntu/utopic/sflphone/utopic

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjsip-apps/src/ipjsua/Classes/ConfigViewController.m

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: ConfigViewController.m 3550 2011-05-05 05:33:27Z nanang $ */
 
2
/*
 
3
 * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 */
 
19
#import "ConfigViewController.h"
 
20
#import "ipjsuaAppDelegate.h"
 
21
 
 
22
 
 
23
@implementation ConfigViewController
 
24
@synthesize textView;
 
25
@synthesize button1;
 
26
@synthesize button2;
 
27
 
 
28
bool kshow = false;
 
29
 
 
30
/*
 
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
 
35
    }
 
36
    return self;
 
37
}
 
38
*/
 
39
 
 
40
/*
 
41
// Implement loadView to create a view hierarchy programmatically, without using a nib.
 
42
- (void)loadView {
 
43
}
 
44
*/
 
45
 
 
46
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 
47
{
 
48
    // Dismiss the keyboard when the view outside the text view is touched.
 
49
    [textView resignFirstResponder];
 
50
    [super touchesBegan:touches withEvent:event];
 
51
}
 
52
 
 
53
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 
54
- (void)viewDidLoad {
 
55
    [super viewDidLoad];
 
56
 
 
57
    [textView setFont:[UIFont fontWithName:@"Courier" size:10]];
 
58
    ipjsuaAppDelegate *appd = (ipjsuaAppDelegate *)[[UIApplication sharedApplication] delegate];
 
59
    appd.cfgView = self;
 
60
 
 
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];
 
65
 
 
66
    /* Add keyboard show/hide notifications so that we can resize the text view */
 
67
    kshow = false;
 
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];
 
71
 
 
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];
 
75
}
 
76
 
 
77
-(void) keyboardWillShow:(NSNotification *) note
 
78
{
 
79
    if (kshow) return;
 
80
 
 
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];
 
89
    kshow = true;
 
90
 
 
91
    [self.button1 setEnabled:true];
 
92
    [self.button1.titleLabel setEnabled:true];
 
93
    [self.button2 setEnabled:true];
 
94
    [self.button2.titleLabel setEnabled:true];
 
95
}
 
96
 
 
97
-(void) keyboardWillHide:(NSNotification *) note
 
98
{
 
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;
 
103
    kshow = false;
 
104
}
 
105
 
 
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];
 
111
 
 
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];
 
117
}
 
118
 
 
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];
 
124
 
 
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];
 
130
}
 
131
 
 
132
/*
 
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);
 
137
}
 
138
*/
 
139
 
 
140
- (void)didReceiveMemoryWarning {
 
141
    // Releases the view if it doesn't have a superview.
 
142
    [super didReceiveMemoryWarning];
 
143
 
 
144
    // Release any cached data, images, etc that aren't in use.
 
145
}
 
146
 
 
147
- (void)viewDidUnload {
 
148
    // Release any retained subviews of the main view.
 
149
    // e.g. self.myOutlet = nil;
 
150
}
 
151
 
 
152
 
 
153
- (void)dealloc {
 
154
    [super dealloc];
 
155
}
 
156
 
 
157
 
 
158
@end