-
Notifications
You must be signed in to change notification settings - Fork 106
/
SNSystemMessageHistoryViewController_deprecated.m
501 lines (459 loc) · 26.2 KB
/
SNSystemMessageHistoryViewController_deprecated.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
#import "SNSystemMessageHistoryViewController.h"
#import "SNNumberViewController.h"
#import "SNWhitelistViewController.h"
#import "SNBlacklistViewController.h"
#import "SNPrivatelistViewController.h"
#import <objc/runtime.h>
#import <sqlite3.h>
#ifndef SMSNinjaDebug
#define SETTINGS @"/var/mobile/Library/SMSNinja/smsninja.plist"
#define DATABASE @"/var/mobile/Library/SMSNinja/smsninja.db"
#else
#define SETTINGS @"/Users/snakeninny/Library/Application Support/iPhone Simulator/7.0.3/Applications/0C9D35FB-B626-42B7-AAE9-45F6F537890B/Documents/var/mobile/Library/SMSNinja/smsninja.plist"
#define DATABASE @"/Users/snakeninny/Library/Application Support/iPhone Simulator/7.0.3/Applications/0C9D35FB-B626-42B7-AAE9-45F6F537890B/Documents/var/mobile/Library/SMSNinja/smsninja.db"
#endif
@implementation SNSystemMessageHistoryViewController
@synthesize flag;
- (void)dealloc
{
[numberArray release];
numberArray = nil;
[nameArray release];
nameArray = nil;
[timeArray release];
timeArray = nil;
[contentArray release];
contentArray = nil;
[keywordSet release];
keywordSet = nil;
[flag release];
flag = nil;
[super dealloc];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self setEditing:NO animated:NO];
id viewController = self.navigationController.topViewController;
if ([viewController isKindOfClass:[SNNumberViewController class]]) return;
[((UITableViewController *)viewController).tableView reloadData];
}
- (void)initializeAllArrays
{
CPDistributedMessagingCenter *messagingCenter = [objc_getClass("CPDistributedMessagingCenter") centerNamed:@"com.naken.smsninja.springboard"];
NSDictionary *reply = [messagingCenter sendMessageAndReceiveReplyName:@"GetSystemMessageHistory" userInfo:nil];
numberArray = [[NSMutableArray alloc] initWithArray:[reply objectForKey:@"numberArray"]];
nameArray = [[NSMutableArray alloc] initWithArray:[reply objectForKey:@"nameArray"]];
timeArray = [[NSMutableArray alloc] initWithArray:[reply objectForKey:@"timeArray"]];
contentArray = [[NSMutableArray alloc] initWithArray:[reply objectForKey:@"contentArray"]];
keywordSet = [[NSMutableSet alloc] initWithCapacity:600];
sqlite3 *database;
sqlite3_stmt *statement;
int openResult = sqlite3_open([DATABASE UTF8String], &database);
if (openResult == SQLITE_OK)
{
NSString *sql = [NSString stringWithFormat:@"select keyword from %@list", self.flag];
int prepareResult = sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL);
if (prepareResult == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
char *keyword = (char *)sqlite3_column_text(statement, 0);
[keywordSet addObject:keyword ? @(keyword) : @""];
}
sqlite3_finalize(statement);
}
else NSLog(@"SMSNinja: Failed to prepare %@, error %d", sql, prepareResult);
sqlite3_close(database);
}
else NSLog(@"SMSNinja: Failed to open %@, error %d", DATABASE, openResult);
}
- (SNSystemMessageHistoryViewController *)init
{
if ((self = [super initWithStyle:UITableViewStylePlain]))
{
self.title = NSLocalizedString(@"Message History", @"Message History");
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.tableView.allowsSelectionDuringEditing = YES;
[self initializeAllArrays];
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [numberArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"any-cell"];
if (cell == nil) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"any-cell"] autorelease];
for (UIView *subview in [cell.contentView subviews]) [subview removeFromSuperview];
cell.textLabel.text = nil;
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryNone;
UITableViewCell *defaultCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"default-cell"];
int defaultCellHeight = defaultCell.bounds.size.height;
int defaultCellWidth = defaultCell.bounds.size.width;
[defaultCell release];
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 2.0f, (defaultCellWidth - 50.0f) / 2.0f, (defaultCellHeight - 4.0f) / 2.0f)];
nameLabel.tag = 1;
nameLabel.adjustsFontSizeToFitWidth = YES;
nameLabel.text = [[nameArray objectAtIndex:indexPath.row] length] != 0 ? [nameArray objectAtIndex:indexPath.row] : [numberArray objectAtIndex:indexPath.row];
[cell.contentView addSubview:nameLabel];
[nameLabel release];
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabel.frame.origin.x + nameLabel.bounds.size.width, nameLabel.frame.origin.y, nameLabel.bounds.size.width, nameLabel.bounds.size.height)];
timeLabel.tag = 2;
timeLabel.font = nameLabel.font;
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_5_0 && kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_6_0) timeLabel.textAlignment = UITextAlignmentRight;
else timeLabel.textAlignment = NSTextAlignmentRight;
timeLabel.adjustsFontSizeToFitWidth = nameLabel.adjustsFontSizeToFitWidth;
timeLabel.text = [timeArray objectAtIndex:indexPath.row];
timeLabel.textColor = nameLabel.textColor;
[cell.contentView addSubview:timeLabel];
[timeLabel release];
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabel.frame.origin.x, nameLabel.frame.origin.y + nameLabel.bounds.size.height, nameLabel.bounds.size.width + timeLabel.bounds.size.width, nameLabel.bounds.size.height)];
contentLabel.tag = 3;
contentLabel.numberOfLines = 0;
contentLabel.font = nameLabel.font;
contentLabel.text = [contentArray objectAtIndex:indexPath.row];
CGSize expectedLabelSize = [contentLabel.text sizeWithFont:contentLabel.font constrainedToSize:CGSizeMake(contentLabel.bounds.size.width, contentLabel.bounds.size.height * 60.0f) lineBreakMode:contentLabel.lineBreakMode];
CGRect newFrame = contentLabel.frame;
newFrame.size.height = expectedLabelSize.height;
contentLabel.frame = newFrame;
contentLabel.textColor = nameLabel.textColor;
[cell.contentView addSubview:contentLabel];
[contentLabel release];
if ([keywordSet containsObject:[numberArray objectAtIndex:indexPath.row]]) [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
else [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"default-cell"] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
UIFont *font = label.font;
[label release];
return (cell.contentView.bounds.size.height - 4.0f) / 2.0f + [[contentArray objectAtIndex:indexPath.row] sizeWithFont:font constrainedToSize:CGSizeMake((cell.contentView.bounds.size.width - 50.0f), (cell.contentView.bounds.size.height - 4.0f) / 2.0f * 60.0f) lineBreakMode:NSLineBreakByWordWrapping].height + 4.0f;
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == 1) // single
{
if (buttonIndex == 2) [self.tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:buttonIndex inSection:0] animated:NO];
__block NSInteger index = buttonIndex;
__block SNSystemMessageHistoryViewController *weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sqlite3 *database;
int openResult = sqlite3_open([DATABASE UTF8String], &database);
if (openResult == SQLITE_OK)
{
NSString *sql = [NSString stringWithFormat:@"insert or replace into %@list (keyword, type, name, phone, sms, reply, message, forward, number, sound) values ('%@', '0', '', '1', '1', '0', '', '0', '', '%d')", weakSelf.flag, [weakSelf->numberArray objectAtIndex:weakSelf->chosenRow], index];
int execResult = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"SMSNinja: Failed to exec %@, error %d", sql, execResult);
sqlite3_close(database);
id viewController = [weakSelf.navigationController.viewControllers objectAtIndex:([weakSelf.navigationController.viewControllers count] - 2)];
if ([viewController isKindOfClass:[SNBlacklistViewController class]])
{
[((SNBlacklistViewController *)viewController)->keywordArray addObject:[weakSelf->numberArray objectAtIndex:weakSelf->chosenRow]];
[((SNBlacklistViewController *)viewController)->typeArray addObject:@"0"];
[((SNBlacklistViewController *)viewController)->nameArray addObject:@""];
[((SNBlacklistViewController *)viewController)->messageArray addObject:@"1"];
[((SNBlacklistViewController *)viewController)->numberArray addObject:@"1"];
[((SNBlacklistViewController *)viewController)->smsArray addObject:@"0"];
[((SNBlacklistViewController *)viewController)->phoneArray addObject:@""];
[((SNBlacklistViewController *)viewController)->forwardArray addObject:@"0"];
[((SNBlacklistViewController *)viewController)->replyArray addObject:@""];
[((SNBlacklistViewController *)viewController)->soundArray addObject:[NSString stringWithFormat:@"%d", index]];
}
else if ([viewController isKindOfClass:[SNPrivatelistViewController class]])
{
[((SNPrivatelistViewController *)viewController)->keywordArray addObject:[weakSelf->numberArray objectAtIndex:weakSelf->chosenRow]];
[((SNPrivatelistViewController *)viewController)->typeArray addObject:@"0"];
[((SNPrivatelistViewController *)viewController)->nameArray addObject:@""];
[((SNPrivatelistViewController *)viewController)->messageArray addObject:@"1"];
[((SNPrivatelistViewController *)viewController)->numberArray addObject:@"1"];
[((SNPrivatelistViewController *)viewController)->smsArray addObject:@"0"];
[((SNPrivatelistViewController *)viewController)->phoneArray addObject:@""];
[((SNPrivatelistViewController *)viewController)->forwardArray addObject:@"0"];
[((SNPrivatelistViewController *)viewController)->replyArray addObject:@""];
[((SNPrivatelistViewController *)viewController)->soundArray addObject:[NSString stringWithFormat:@"%d", index]];
}
}
else NSLog(@"SMSNinja: Failed to open %@, error %d", DATABASE, openResult);
});
}
else if (actionSheet.tag == 2) // all
{
if (buttonIndex == 2)
for (int i = 0; i < [numberArray count]; i++)
[self.tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] animated:NO];
__block NSInteger index = buttonIndex;
__block SNSystemMessageHistoryViewController *weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sqlite3 *database;
int openResult = sqlite3_open([DATABASE UTF8String], &database);
if (openResult == SQLITE_OK)
{
for (NSString *number in weakSelf->numberArray)
{
NSString *sql = [NSString stringWithFormat:@"insert or replace into %@list (keyword, type, name, phone, sms, reply, message, forward, number, sound) values ('%@', '0', '', '1', '1', '0', '', '0', '', '%d')", weakSelf.flag, number, index];
int execResult = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"SMSNinja: Failed to exec %@, error %d", sql, execResult);
id viewController = [weakSelf.navigationController.viewControllers objectAtIndex:([weakSelf.navigationController.viewControllers count] - 2)];
if ([viewController isKindOfClass:[SNBlacklistViewController class]])
{
[((SNBlacklistViewController *)viewController)->keywordArray addObject:number];
[((SNBlacklistViewController *)viewController)->typeArray addObject:@"0"];
[((SNBlacklistViewController *)viewController)->nameArray addObject:@""];
[((SNBlacklistViewController *)viewController)->messageArray addObject:@"1"];
[((SNBlacklistViewController *)viewController)->numberArray addObject:@"1"];
[((SNBlacklistViewController *)viewController)->smsArray addObject:@"0"];
[((SNBlacklistViewController *)viewController)->phoneArray addObject:@""];
[((SNBlacklistViewController *)viewController)->forwardArray addObject:@"0"];
[((SNBlacklistViewController *)viewController)->replyArray addObject:@""];
[((SNBlacklistViewController *)viewController)->soundArray addObject:[NSString stringWithFormat:@"%d", index]];
}
else if ([viewController isKindOfClass:[SNPrivatelistViewController class]])
{
[((SNPrivatelistViewController *)viewController)->keywordArray addObject:number];
[((SNPrivatelistViewController *)viewController)->typeArray addObject:@"0"];
[((SNPrivatelistViewController *)viewController)->nameArray addObject:@""];
[((SNPrivatelistViewController *)viewController)->messageArray addObject:@"1"];
[((SNPrivatelistViewController *)viewController)->numberArray addObject:@"1"];
[((SNPrivatelistViewController *)viewController)->smsArray addObject:@"0"];
[((SNPrivatelistViewController *)viewController)->phoneArray addObject:@""];
[((SNPrivatelistViewController *)viewController)->forwardArray addObject:@"0"];
[((SNPrivatelistViewController *)viewController)->replyArray addObject:@""];
[((SNPrivatelistViewController *)viewController)->soundArray addObject:[NSString stringWithFormat:@"%d", index]];
}
}
sqlite3_close(database);
}
else NSLog(@"SMSNinja: Failed to open %@, error %d", DATABASE, openResult);
});
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!tableView.editing)
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
SNNumberViewController *numberViewController = [[SNNumberViewController alloc] init];
numberViewController.flag = self.flag;
numberViewController.nameString = [nameArray objectAtIndex:indexPath.row];
numberViewController.keywordString = [numberArray objectAtIndex:indexPath.row];
numberViewController.originalKeyword = numberViewController.keywordString;
numberViewController.phoneAction = @"1";
numberViewController.messageAction = @"1";
numberViewController.replyString = @"0";
numberViewController.messageString = @"";
numberViewController.forwardString = @"0";
numberViewController.numberString = @"";
numberViewController.soundString = @"1";
UINavigationController *navigationController = self.navigationController;
[navigationController popViewControllerAnimated:NO];
[navigationController pushViewController:numberViewController animated:YES];
[numberViewController release];
}
else
{
chosenRow = indexPath.row;
if (![self.flag isEqualToString:@"white"])
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Turn off the beep", @"Turn off the beep"), NSLocalizedString(@"Turn on the beep", @"Turn on the beep"), nil];
actionSheet.tag = 1;
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet release];
}
else
{
__block SNSystemMessageHistoryViewController *weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sqlite3 *database;
int openResult = sqlite3_open([DATABASE UTF8String], &database);
if (openResult == SQLITE_OK)
{
NSString *sql = [NSString stringWithFormat:@"insert or replace into whitelist (keyword, type, name, phone, sms, reply, message, forward, number, sound) values ('%@', '0', '', '1', '1', '0', '', '0', '', '0')", [weakSelf->numberArray objectAtIndex:weakSelf->chosenRow]];
int execResult = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"SMSNinja: Failed to exec %@, error %d", sql, execResult);
sqlite3_close(database);
SNWhitelistViewController *viewController = (SNWhitelistViewController *)[weakSelf.navigationController.viewControllers objectAtIndex:([weakSelf.navigationController.viewControllers count] - 2)];
[viewController->nameArray addObject:@""];
[viewController->keywordArray addObject:[weakSelf->numberArray objectAtIndex:weakSelf->chosenRow]];
[viewController->typeArray addObject:@"0"];
}
else NSLog(@"SMSNinja: Failed to open %@, error %d", DATABASE, openResult);
});
}
}
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
__block int index = indexPath.row;
__block SNSystemMessageHistoryViewController *weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sqlite3 *database;
int openResult = sqlite3_open([DATABASE UTF8String], &database);
if (openResult == SQLITE_OK)
{
NSString *sql = [NSString stringWithFormat:@"delete from %@list where keyword = '%@'", weakSelf.flag, [weakSelf->numberArray objectAtIndex:index]];
int execResult = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"SMSNinja: Failed to exec %@, error %d", sql, execResult);
sqlite3_close(database);
id viewController = [weakSelf.navigationController.viewControllers objectAtIndex:([weakSelf.navigationController.viewControllers count] - 2)];
if ([viewController isKindOfClass:[SNBlacklistViewController class]])
{
[((SNBlacklistViewController *)viewController)->keywordArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->typeArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->nameArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->messageArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->numberArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->smsArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->phoneArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->forwardArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->replyArray removeObjectAtIndex:index];
[((SNBlacklistViewController *)viewController)->soundArray removeObjectAtIndex:index];
}
else if ([viewController isKindOfClass:[SNWhitelistViewController class]])
{
[((SNWhitelistViewController *)viewController)->keywordArray removeObjectAtIndex:index];
[((SNWhitelistViewController *)viewController)->typeArray removeObjectAtIndex:index];
[((SNWhitelistViewController *)viewController)->nameArray removeObjectAtIndex:index];
}
else if ([viewController isKindOfClass:[SNPrivatelistViewController class]])
{
[((SNPrivatelistViewController *)viewController)->keywordArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->typeArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->nameArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->messageArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->numberArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->smsArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->phoneArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->forwardArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->replyArray removeObjectAtIndex:index];
[((SNPrivatelistViewController *)viewController)->soundArray removeObjectAtIndex:index];
}
}
else NSLog(@"SMSNinja: Failed to open %@, error %d", DATABASE, openResult);
});
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleInsert | UITableViewCellEditingStyleDelete;
}
- (void)selectAll:(UIBarButtonItem *)buttonItem
{
if ([buttonItem.title isEqualToString:NSLocalizedString(@"All", @"All")])
{
buttonItem.title = NSLocalizedString(@"None", @"None");
for (int i = 0; i < [numberArray count]; i++) [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
if (![self.flag isEqualToString:@"white"])
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Turn off the beep", @"Turn off the beep"), NSLocalizedString(@"Turn on the beep", @"Turn on the beep"), nil];
actionSheet.tag = 2;
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet release];
}
else
{
__block SNSystemMessageHistoryViewController *weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sqlite3 *database;
int openResult = sqlite3_open([DATABASE UTF8String], &database);
if (openResult == SQLITE_OK)
{
for (NSString *number in weakSelf->numberArray)
{
NSString *sql = [NSString stringWithFormat:@"insert or replace into whitelist (keyword, type, name, phone, sms, reply, message, forward, number, sound) values ('%@', '0', '', '1', '1', '0', '', '0', '', '0')", number];
int execResult = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"SMSNinja: Failed to exec %@, error %d", sql, execResult);
SNWhitelistViewController *viewController = (SNWhitelistViewController *)[weakSelf.navigationController.viewControllers objectAtIndex:([weakSelf.navigationController.viewControllers count] - 2)];
[viewController->nameArray addObject:@""];
[viewController->keywordArray addObject:number];
[viewController->typeArray addObject:@"0"];
}
sqlite3_close(database);
}
else NSLog(@"SMSNinja: Failed to open %@, error %d", DATABASE, openResult);
});
}
}
else if ([buttonItem.title isEqualToString:NSLocalizedString(@"None", @"None")])
{
buttonItem.title = NSLocalizedString(@"All", @"All");
for (int i = 0; i < [numberArray count]; i++) [self.tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] animated:NO];
__block SNSystemMessageHistoryViewController *weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sqlite3 *database;
int openResult = sqlite3_open([DATABASE UTF8String], &database);
if (openResult == SQLITE_OK)
{
for (NSString *number in weakSelf->numberArray)
{
NSString *sql = [NSString stringWithFormat:@"delete from %@list where keyword = '%@'", weakSelf.flag, number];
int execResult = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"SMSNinja: Failed to exec %@, error %d", sql, execResult);
id viewController = [weakSelf.navigationController.viewControllers objectAtIndex:([weakSelf.navigationController.viewControllers count] - 2)];
if ([viewController isKindOfClass:[SNBlacklistViewController class]])
{
[((SNBlacklistViewController *)viewController)->keywordArray removeObject:number];
[((SNBlacklistViewController *)viewController)->typeArray removeObject:number];
[((SNBlacklistViewController *)viewController)->nameArray removeObject:number];
[((SNBlacklistViewController *)viewController)->messageArray removeObject:number];
[((SNBlacklistViewController *)viewController)->numberArray removeObject:number];
[((SNBlacklistViewController *)viewController)->smsArray removeObject:number];
[((SNBlacklistViewController *)viewController)->phoneArray removeObject:number];
[((SNBlacklistViewController *)viewController)->forwardArray removeObject:number];
[((SNBlacklistViewController *)viewController)->replyArray removeObject:number];
[((SNBlacklistViewController *)viewController)->soundArray removeObject:number];
}
else if ([viewController isKindOfClass:[SNWhitelistViewController class]])
{
[((SNWhitelistViewController *)viewController)->keywordArray removeObject:number];
[((SNWhitelistViewController *)viewController)->typeArray removeObject:number];
[((SNWhitelistViewController *)viewController)->nameArray removeObject:number];
}
else if ([viewController isKindOfClass:[SNPrivatelistViewController class]])
{
[((SNPrivatelistViewController *)viewController)->keywordArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->typeArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->nameArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->messageArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->numberArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->smsArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->phoneArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->forwardArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->replyArray removeObject:number];
[((SNPrivatelistViewController *)viewController)->soundArray removeObject:number];
}
}
sqlite3_close(database);
}
else NSLog(@"SMSNinja: Failed to open %@, error %d", DATABASE, openResult);
});
}
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
[self.navigationController setToolbarHidden:!editing animated:animate];
if (editing)
{
for (UITableViewCell *cell in [self.tableView visibleCells]) cell.selectionStyle = UITableViewCellSelectionStyleGray;
[self.navigationItem setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"All", @"All") style:UIBarButtonItemStylePlain target:self action:@selector(selectAll:)] autorelease] animated:animate];
}
else
{
for (UITableViewCell *cell in [self.tableView visibleCells]) cell.selectionStyle = UITableViewCellSelectionStyleBlue;
[self.navigationItem setLeftBarButtonItem:nil animated:animate];
}
[super setEditing:editing animated:animate];
}
@end