-
Notifications
You must be signed in to change notification settings - Fork 0
/
VNCPrefsView.m
182 lines (149 loc) · 5.4 KB
/
VNCPrefsView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// VNCPrefsView.m
// vnsea
//
// Created by Glenn Kreisel on 11/3/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "VnseaApp.h"
#import "VNCPrefsView.h"
#import <UIKit/UIPreferencesTextTableCell.h>
#import <UIKit/UIPreferencesControlTableCell.h>
#import <UIKit/UINavigationItem.h>
#import "VNCPreferences.h"
//! @brief Navigation bar button index for the Back button.
#define kServerListButton 1
//! Converts a boolean value to the floating point on or off value for a UISwitchControl.
#define BOOL_TO_SWITCH_VALUE(b) ((b) ? 1.0f : 0.0f)
//! Takes a UISwitchControl and returns a boolean from its value.
//!
//! We use a greater than comparison here because floats are not always exact.
#define SWITCH_VALUE_TO_BOOL(s) ([(s) value] > 0.1)
@implementation VNCPrefsView
- (id)initWithFrame:(CGRect)frame
{
if ([super initWithFrame:frame])
{
CGRect subviewFrame;
// Create nav bar
subviewFrame = CGRectMake(0.0f, 0.0f, frame.size.width, 48);
_navBar = [[UINavigationBar alloc] initWithFrame:subviewFrame];
[_navBar showButtonsWithLeftTitle:NSLocalizedString(@"Back", nil) rightTitle:nil leftBack: YES];
[_navBar setBarStyle: 3];
[_navBar setDelegate: self];
[self addSubview: _navBar];
UINavigationItem * item = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(@"Preferences", nil)];
[_navBar pushNavigationItem:item];
// Create preferences table
subviewFrame = CGRectMake(0, 48, frame.size.width, frame.size.height - 48);
_table = [[UIPreferencesTable alloc] initWithFrame:subviewFrame];
[_table setDataSource:self];
[_table setDelegate:self];
[self addSubview:_table];
// Show mouse tracks cell.
UIPreferencesControlTableCell * mouseTracksCell = [[UIPreferencesControlTableCell alloc] init];
[mouseTracksCell setTitle:NSLocalizedString(@"Show Mouse Tracks", nil)];
CGPoint controlOrigin = CGPointMake(200, 9);
_mouseTracksSwitch = [[UISwitchControl alloc] init];
[_mouseTracksSwitch setOrigin:controlOrigin];
[mouseTracksCell setControl:_mouseTracksSwitch];
// Disconnect on suspend cell.
UIPreferencesControlTableCell * disconnectCell = [[UIPreferencesControlTableCell alloc] init];
[disconnectCell setTitle:NSLocalizedString(@"Exit App on Suspend", nil)];
// controlOrigin = CGPointMake(200, 9);
_disconnectSwitch = [[UISwitchControl alloc] init];
[_disconnectSwitch setOrigin:controlOrigin];
[disconnectCell setControl:_disconnectSwitch];
// Show scroll icon cell.
UIPreferencesControlTableCell * showScrollIconCell = [[UIPreferencesControlTableCell alloc] init];
[showScrollIconCell setTitle:NSLocalizedString(@"Show scrolling icon", nil)];
// controlOrigin = CGPointMake(200, 9);
_showScrollIconSwitch = [[UISwitchControl alloc] init];
[_showScrollIconSwitch setOrigin:controlOrigin];
[showScrollIconCell setControl:_showScrollIconSwitch];
// Show zoom percent cell.
UIPreferencesControlTableCell * showZoomPercentCell = [[UIPreferencesControlTableCell alloc] init];
[showZoomPercentCell setTitle:NSLocalizedString(@"Show zoom scale", nil)];
// controlOrigin = CGPointMake(200, 9);
_showZoomPercentSwitch = [[UISwitchControl alloc] init];
[_showZoomPercentSwitch setOrigin:controlOrigin];
[showZoomPercentCell setControl:_showZoomPercentSwitch];
// Create array of cells.
_cells = [[NSArray arrayWithObjects:mouseTracksCell, disconnectCell, showScrollIconCell, showZoomPercentCell, nil] retain];
}
return self;
}
- (void)dealloc
{
[_table release];
[_navBar release];
[_cells release];
[super dealloc];
}
- (void)setDelegate:(id)newDelegate
{
_delegate = newDelegate;
}
- (id)delegate
{
return _delegate;
}
- (void)setKeyboardVisible:(BOOL)visible
{
[_table setKeyboardVisible:visible animated:NO];
}
- (void)updateViewFromPreferences
{
// Update cell values from the prefs info
[_mouseTracksSwitch setValue:BOOL_TO_SWITCH_VALUE([[VNCPreferences sharedPreferences] showMouseTracks])];
[_disconnectSwitch setValue:BOOL_TO_SWITCH_VALUE([[VNCPreferences sharedPreferences] disconnectOnSuspend])];
[_showScrollIconSwitch setValue:BOOL_TO_SWITCH_VALUE([[VNCPreferences sharedPreferences] showScrollingIcon])];
[_showZoomPercentSwitch setValue:BOOL_TO_SWITCH_VALUE([[VNCPreferences sharedPreferences] showZoomPercent])];
[_table reloadData];
}
- (void)navigationBar:(id)navBar buttonClicked:(int)buttonIndex
{
switch (buttonIndex)
{
// Save Prefs and go back
case kServerListButton:
{
[[VNCPreferences sharedPreferences] setShowMouseTracks:SWITCH_VALUE_TO_BOOL(_mouseTracksSwitch)];
[[VNCPreferences sharedPreferences] setDisconnectOnSuspend:SWITCH_VALUE_TO_BOOL(_disconnectSwitch)];
[[VNCPreferences sharedPreferences] setShowScrollingIcon:SWITCH_VALUE_TO_BOOL(_showScrollIconSwitch)];
[[VNCPreferences sharedPreferences] setShowZoomPercent:SWITCH_VALUE_TO_BOOL(_showZoomPercentSwitch)];
break;
}
}
if (_delegate && [_delegate respondsToSelector:@selector(finishedEditingPreferences)])
{
[_delegate finishedEditingPreferences];
}
}
- (int)numberOfGroupsInPreferencesTable:(id)fp8
{
return 1;
}
- (id)preferencesTable:(id)prefsTable cellForRow:(int)rowIndex inGroup:(int)groupIndex
{
if (groupIndex == 0)
{
return [_cells objectAtIndex:rowIndex];
}
}
- (int)preferencesTable:(id)prefsTable numberOfRowsInGroup:(int)groupIndex
{
if (groupIndex == 0)
{
return [_cells count];
}
else
{
return 1;
}
}
- (BOOL)table:(id)prefsTable showDisclosureForRow:(int)rowIndex
{
return NO;
}
@end