-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVNCServerListView.m
275 lines (232 loc) · 7.81 KB
/
VNCServerListView.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//
// VNCServerListView.m
// vnsea
//
// Created by Chris Reed on 9/9/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "VNCServerListView.h"
#import <UIKit/UITable.h>
#import <UIKit/UITableCell.h>
#import <UIKit/UISimpleTableCell.h>
#import <UIKit/UITableColumn.h>
#import <UIKit/UIImageAndTextTableCell.h>
#import <UIKit/UINavBarButton.h>
#import <UIKit/UINavigationItem.h>
#import "ServerStandAlone.h"
#import "ServerFromPrefs.h"
#define kNavBarHeight (48)
#define kButtonBarHeight (48)
#define kAddButtonWidth (34)
#define kAddButtonHeight (40)
#define kAboutButtonHeight (32)
#define kAboutButtonWidth (80)
#define kPreferencesButtonHeight (32)
#define kPreferencesButtonWidth (120)
extern id UIImageGetNavigationBarAddButton();
@implementation VNCServerListView
- (id)initWithFrame:(CGRect)frame
{
if ([super initWithFrame:frame])
{
CGRect subframe;
CGSize navBarSize = [UINavigationBar defaultSize];
subframe = CGRectMake(0.0f, 0.0f, frame.size.width, navBarSize.height);
// Setup navbar
_navBar = [[UINavigationBar alloc] initWithFrame: subframe];
[_navBar showLeftButton:nil withStyle:0 rightButton:UIImageGetNavigationBarAddButton() withStyle:0];
[_navBar setBarStyle: 3];
[_navBar setDelegate: self];
[_navBar enableAnimation];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(@"VNC Servers", nil)];
[_navBar pushNavigationItem:item];
// Setup button bar at bottom
subframe = CGRectMake(0, frame.size.height - kButtonBarHeight, frame.size.width, kButtonBarHeight);
_buttonBar = [[UIGradientBar alloc] initWithFrame:subframe];
const float kTextComponents[] = { .94, .94, .94, .7 };
const float kTransparentComponents[] = { 0, 0, 1, 0 };
const float kTextComponentsDateTime[] = { 0.4, 0.4, 0.4, 1 };
CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef textColorStatus = CGColorCreate(rgbSpace, kTextComponents);
CGColorRef rgbTransparent = CGColorCreate(rgbSpace, kTransparentComponents);
_textColorDateTime = CGColorCreate(rgbSpace, kTextComponentsDateTime);
CGColorSpaceRelease(rgbSpace);
// Go ahead and create font for drawing the last connect column
_lastConnectFont = GSFontCreateWithName("Helvetica", 0, 12.0f);
// Add about button
subframe = CGRectMake(10.0f, (kButtonBarHeight - kAboutButtonHeight) / 2.0 + 1, kAboutButtonWidth, kAboutButtonHeight);
_aboutButton = [[UINavBarButton alloc] initWithFrame:subframe];
[_aboutButton setAutosizesToFit: NO];
[_aboutButton addTarget:self action: @selector(showAbout:) forEvents:kGSEventTypeButtonSelected];
[_aboutButton setNavBarButtonStyle: 0];
[_aboutButton setTitle: NSLocalizedString(@"About", nil)];
[_aboutButton setEnabled: YES];
// Add server button
subframe = CGRectMake(frame.size.width - 10.0f - kPreferencesButtonWidth, (kButtonBarHeight - kPreferencesButtonHeight) / 2.0 + 1, kPreferencesButtonWidth, kPreferencesButtonHeight);
_preferencesButton = [[UINavBarButton alloc] initWithFrame:subframe];
[_preferencesButton setAutosizesToFit: NO];
[_preferencesButton addTarget:self action: @selector(showPreferences:) forEvents:kGSEventTypeButtonSelected];
[_preferencesButton setNavBarButtonStyle: 0];
[_preferencesButton setTitle: NSLocalizedString(@"Preferences", nil)];
[_preferencesButton setEnabled: YES];
// Setup server table
subframe = CGRectMake(0, navBarSize.height, frame.size.width, frame.size.height - navBarSize.height - kButtonBarHeight-1);
_serverColumn = [[UITableColumn alloc] initWithTitle:@"Servers" identifier:@"servers" width:frame.size.width - (150)];
_serverLastConnectColumn = [[UITableColumn alloc] initWithTitle:@"Last Connect" identifier:@"lastConnect" width:150];
_serverTable = [[UITable alloc] initWithFrame:subframe];
[_serverTable addTableColumn:_serverColumn];
[_serverTable addTableColumn:_serverLastConnectColumn];
[_serverTable setDelegate:self];
[_serverTable setDataSource:self];
[_serverTable setReusesTableCells:NO];
// Construct view hierarchy
[_navBar addSubview:_addButton];
[_buttonBar addSubview:_aboutButton];
[_buttonBar addSubview:_preferencesButton];
[self addSubview:_buttonBar];
[self addSubview:_navBar];
[self addSubview:_serverTable];
}
return self;
}
- (void)dealloc
{
CFRelease(_textColorDateTime);
CFRelease(_lastConnectFont);
[_servers release];
[super dealloc];
}
- (void)setServerList:(NSArray *)list
{
[_servers release];
_servers = [list retain];
[_serverTable reloadData];
[_serverTable updateDisclosures];
}
- (void)setDelegate:(id)newDelegate
{
_delegate = newDelegate;
}
- (id)delegate
{
return _delegate;
}
- (void)handleNotification:(NSNotification *)notification
{
NSLog(@"notification:%@ userInfo=%@", notification, [notification userInfo]);
}
- (void)addNewServer:(id)sender
{
if (_delegate && [_delegate respondsToSelector:@selector(addNewServer)])
{
[_delegate addNewServer];
}
}
- (void)showPreferences:(id)sender
{
if (_delegate && [_delegate respondsToSelector:@selector(displayPrefs)])
{
[_delegate displayPrefs];
}
}
- (void)showAbout:(id)sender
{
if (_delegate && [_delegate respondsToSelector:@selector(displayAbout)])
{
[_delegate displayAbout];
}
}
- (void)navigationBar:(id)navBar buttonClicked:(int)buttonIndex
{
NSLog(@"navbar:%@ button:%d", navBar, buttonIndex);
switch (buttonIndex)
{
case kNavBarAddServerButton:
[self addNewServer:nil];
break;
}
}
- (void)alertSheet:(id)sheet buttonClicked:(int)buttonIndex
{
[sheet dismissAnimated:YES];
[sheet release];
}
- (void)tableRowSelected:(id)theTable
{
int selection = [_serverTable selectedRow];
if (_delegate && [_delegate respondsToSelector:@selector(serverSelected:)])
{
[_delegate serverSelected:selection];
}
}
- (BOOL)table:(id)theTable disclosureClickableForRow:(int)rowIndex
{
return YES;
}
- (void)table:(UITable *)theTable disclosureClickedForRow:(int)row
{
if (_delegate && [_delegate respondsToSelector:@selector(editServer:)])
{
[_delegate editServer:row];
}
}
- (int)numberOfRowsInTable:(id)theTable
{
return [_servers count];
}
- (id)table:(id)theTable cellForRow:(int)rowIndex column:(id)columnIndex
{
if (columnIndex == _serverLastConnectColumn )
{
UIImageAndTextTableCell * cell = [[[UIImageAndTextTableCell alloc] init] autorelease];
NSNumber *nb = [[_servers objectAtIndex:rowIndex] objectForKey:SERVER_LAST_CONNECT];
if (nb == nil)
{
[cell setTitle:@"--- -- --:-- --"];
}
else
{
NSDate *dtLastConnect = [NSDate dateWithTimeIntervalSinceReferenceDate: [nb doubleValue]];
[cell setTitle:[dtLastConnect descriptionWithCalendarFormat:@"%b %1d %I:%M %p" timeZone:nil locale:nil]];
}
[[cell titleTextLabel] setFont:_lastConnectFont];
[[cell titleTextLabel] setColor:_textColorDateTime];
[cell setShowDisclosure:YES];
[cell setDisclosureClickable:YES];
[cell setDisclosureStyle:1];
return cell;
}
else
{
UISimpleTableCell * cell = [[[UISimpleTableCell alloc] init] autorelease];
[cell setTitle:[[_servers objectAtIndex:rowIndex] objectForKey:@"Name"]];
[cell setShowDisclosure:NO];
[cell setDisclosureClickable:YES];
[cell setDisclosureStyle:1];
return cell;
}
return nil;
}
- (BOOL)table:(id)theTable canSelectRow:(int)rowIndex;
{
return YES;
}
/*
//These Methods track delegate calls made to the application
- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector
{
NSLog(@"Requested method for selector: %@", NSStringFromSelector(selector));
return [super methodSignatureForSelector:selector];
}
- (BOOL)respondsToSelector:(SEL)aSelector
{
NSLog(@"Request for selector: %@", NSStringFromSelector(aSelector));
return [super respondsToSelector:aSelector];
}
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
NSLog(@"Called from: %@", NSStringFromSelector([anInvocation selector]));
[super forwardInvocation:anInvocation];
}
*/
@end