-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanViewController.m
More file actions
256 lines (196 loc) · 6.18 KB
/
ScanViewController.m
File metadata and controls
256 lines (196 loc) · 6.18 KB
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
#import "ScanViewController.h"
#import "TivoDetailsViewController.h"
#include <syslog.h>
#include <time.h>
@implementation ScanViewNavController
{
}
-(id)initWithRootViewController:(id)controller
{
self = [super initWithRootViewController:controller];
return self;
}
-(void)loadView
{
[super loadView];
}
-(void)setTivoObjects: (Beacon*)b withHttpServer:(TiVoHTTPServer*)h
{
beacon = b;
httpd = h;
}
-(void)setDVRMobilePrefs: (DVRMobilePrefs*)p
{
prefs = p;
tivos = [prefs GetTivos];
}
@end;
@implementation ScanViewController
{
}
-(void)loadView
{
self.tableView = [[[UITableView alloc] initWithFrame:
[[UIScreen mainScreen] bounds]] autorelease];
self.title = @"Devices";
refreshBtn = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:@selector(refreshTable:)] autorelease];
tivoIcon = [UIImage imageNamed:@"icon2.png"];
pcIcon = [UIImage imageNamed:@"pc.png"];
iphoneIcon = [UIImage imageNamed:@"iphone.png"];
customSpinningGearView = [[CustomSpinningGearView alloc] autorelease];
[customSpinningGearView initialize];
[customSpinningGearView setText: @"Scanning"];
[self.view addSubview: customSpinningGearView];
}
-(void)refreshTable: (id) sender
{
/* the beacon is already scanning, simply reload the table data */
[customSpinningGearView show];
[NSThread detachNewThreadSelector:@selector(refreshTableThread:)
toTarget:self withObject:nil];
[self.tableView reloadData];
}
-(void)refreshTableThread: (id) sender
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
sleep(2);
[self.tableView reloadData];
[customSpinningGearView stop];
[pool release];
}
-(void)viewDidLoad {
self.navigationItem.rightBarButtonItem = refreshBtn;
}
-(void)setTivoObjects: (Beacon*)b withHttpServer:(TiVoHTTPServer*)h
{
beacon = b;
httpd = h;
}
-(void)setDVRMobilePrefs: (DVRMobilePrefs*)p
{
prefs = p;
tivos = [prefs GetTivos];
}
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
syslog(LOG_DEBUG, "willBeginEditingRowAtIndexPath..");
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
syslog(LOG_DEBUG, "editingStyleForRowAtIndexPath..");
return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
int row = [indexPath row];
syslog(LOG_DEBUG, "commitEditingStyle for row %d..", row);
[tivos removeObjectAtIndex: row];
[prefs SetDirty: YES];
[tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
if ([tivos count] > 0) {
return [tivos count];
}
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"TivoCellIdentifier";
UILabel *machineLabel, *descrLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
CGRect cellFrame = CGRectMake(0, 0, 300, 70);
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:MyIdentifier] autorelease];
}
int row = [indexPath row];
if ([tivos count] > 0) {
TivoDevice *device = [tivos objectAtIndex:row];
machineLabel = [[UILabel alloc] initWithFrame:CGRectMake(80,5,290,35)];
descrLabel = [[UILabel alloc] initWithFrame:CGRectMake(80,45,290,25)];
if ([device->machine_name length] > 20)
machineLabel.font = [UIFont boldSystemFontOfSize:18];
else
machineLabel.font = [UIFont boldSystemFontOfSize:20];
machineLabel.text = device->machine_name;
descrLabel.font = [UIFont boldSystemFontOfSize:14];
descrLabel.textColor = [UIColor lightGrayColor];
descrLabel.text = [[[device->platform
stringByAppendingString: @" ["]
stringByAppendingString: device->address]
stringByAppendingString: @"]"];
[cell setText: @""];
if (device->platform == nil)
[cell setImage: tivoIcon];
if ([device->platform hasPrefix:@"pc/iphone"])
[cell setImage: iphoneIcon];
else if ([device->platform hasPrefix:@"pc"])
[cell setImage: pcIcon];
else
[cell setImage: tivoIcon];
[cell.contentView addSubview: machineLabel];
[cell.contentView addSubview: descrLabel];
[descrLabel release];
[machineLabel release];
} else {
[cell setText:@"[No TiVo Devices Found]"];
cell.textAlignment = UITextAlignmentCenter;
}
return cell;
}
-(NSIndexPath *) tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tivos count] == 0)
return nil;
return indexPath;
}
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int row = [indexPath row];
if ([tivos count] > 0) {
TivoDevice *tivo = [tivos objectAtIndex:row];
syslog(LOG_INFO, "selected tivo device %s", [tivo->machine_name UTF8String]);
tivoView = [[TivoDetailsViewController alloc] autorelease];
[tivoView setTivoDevice: tivo];
[tivoView setDVRMobilePrefs: prefs];
[self.navigationController pushViewController: tivoView animated:YES];
}
}
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
return 80.0;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc
{
[super dealloc];
}
@end