Standardize and update all copyright statements to name "ZXing authors" as suggested...
[zxing.git] / iphone / Classes / ArchiveController.m
1 //
2 //  ArchiveController.m
3 //  UIShowcase
4 //
5 //  Created by Christian Brunschen on 29/05/2008.
6 /*
7  * Copyright 2008 ZXing authors
8  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  */
21
22 #import "ArchiveController.h"
23 #import "Database.h"
24 #import "Scan.h"
25 #import "ParsedResult.h"
26 #import "DecoderViewController.h"
27
28 @implementation ArchiveController
29
30 @synthesize scans;
31 @synthesize decoderViewController;
32
33 - initWithDecoderViewController:(DecoderViewController *)dc {
34         if (self = [super initWithStyle:UITableViewStylePlain]) {
35     self.decoderViewController = dc;
36     self.scans = [NSMutableArray array];
37         }
38         return self;
39 }
40
41 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
42         return 1;
43 }
44
45 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
46         return [scans count];
47 }
48
49 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
50         static NSString *ScanIdentifier = @"ScanIdentifier";
51         
52         UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ScanIdentifier];
53         if (cell == nil) {
54                 cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ScanIdentifier] autorelease];
55     cell.font = [cell.font fontWithSize:10.0];
56     cell.lineBreakMode = UILineBreakModeCharacterWrap;
57         }
58         // Configure the cell
59   Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]];
60   ParsedResult *result = [ParsedResult parsedResultForString:scan.text];
61   cell.text = [result stringForDisplay];
62         return cell;
63 }
64
65 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
66   [decoderViewController showScan:[scans objectAtIndex:[self scanIndexForRow:indexPath.row]]];
67 }
68
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) {
78     // no insertions!
79         }
80 }
81
82 /*
83 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
84         return YES;
85 }
86 */
87 /*
88 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
89 }
90 */
91 /*
92 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
93         return YES;
94 }
95 */
96
97
98 - (void)dealloc {
99   [scans release];
100   [decoderViewController release];
101         [super dealloc];
102 }
103
104
105 - (void)viewDidLoad {
106         [super viewDidLoad];
107   self.title = @"Scan Archive";
108   self.navigationItem.rightBarButtonItem = [self editButtonItem];
109 }
110
111
112 - (void)viewWillAppear:(BOOL)animated {
113         [super viewWillAppear:animated];
114   self.scans = [NSMutableArray arrayWithArray:[[Database sharedDatabase] scans]];
115 }
116
117 - (void)viewDidAppear:(BOOL)animated {
118         [super viewDidAppear:animated];
119 }
120
121 - (void)viewWillDisappear:(BOOL)animated {
122 }
123
124 - (void)viewDidDisappear:(BOOL)animated {
125 }
126
127 - (void)didReceiveMemoryWarning {
128         [super didReceiveMemoryWarning];
129 }
130
131 - (NSInteger)scanIndexForRow:(NSInteger)row {
132   return scans.count - 1 - row;
133 }
134
135 @end
136