5 // Created by Christian Brunschen on 29/05/2008.
7 * Copyright 2008 ZXing authors
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
22 #import "ArchiveController.h"
25 #import "ParsedResult.h"
26 #import "DecoderViewController.h"
28 @implementation ArchiveController
31 @synthesize decoderViewController;
33 - initWithDecoderViewController:(DecoderViewController *)dc {
34 if (self = [super initWithStyle:UITableViewStylePlain]) {
35 self.decoderViewController = dc;
36 self.scans = [NSMutableArray array];
41 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
45 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
49 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
50 static NSString *ScanIdentifier = @"ScanIdentifier";
52 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ScanIdentifier];
54 cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ScanIdentifier] autorelease];
55 cell.font = [cell.font fontWithSize:10.0];
56 cell.lineBreakMode = UILineBreakModeCharacterWrap;
59 Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]];
60 ParsedResult *result = [ParsedResult parsedResultForString:scan.text];
61 cell.text = [result stringForDisplay];
65 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
66 [decoderViewController showScan:[scans objectAtIndex:[self scanIndexForRow:indexPath.row]]];
69 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
70 if (editingStyle == UITableViewCellEditingStyleDelete) {
71 int index = [self scanIndexForRow:indexPath.row];
72 Scan *scan = [self.scans objectAtIndex:index];
73 [[Database sharedDatabase] deleteScan:scan];
74 [self.scans removeObjectAtIndex:index];
75 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
76 [tableView reloadData];
77 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
83 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
88 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
92 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
100 [decoderViewController release];
105 - (void)viewDidLoad {
107 self.title = @"Scan Archive";
108 self.navigationItem.rightBarButtonItem = [self editButtonItem];
112 - (void)viewWillAppear:(BOOL)animated {
113 [super viewWillAppear:animated];
114 self.scans = [NSMutableArray arrayWithArray:[[Database sharedDatabase] scans]];
117 - (void)viewDidAppear:(BOOL)animated {
118 [super viewDidAppear:animated];
121 - (void)viewWillDisappear:(BOOL)animated {
124 - (void)viewDidDisappear:(BOOL)animated {
127 - (void)didReceiveMemoryWarning {
128 [super didReceiveMemoryWarning];
131 - (NSInteger)scanIndexForRow:(NSInteger)row {
132 return scans.count - 1 - row;