First version of the iphone client that actually works, for at least a subset
[zxing.git] / iphone / Classes / ZXingAppDelegate.m
1 //
2 //  ZXingAppDelegate.m
3 //  ZXing
4 //
5 //  Created by Christian Brunschen on 23/04/2008.
6 //
7 /*
8  * Copyright 2008 Google Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22
23
24 #import "ZXingAppDelegate.h"
25 #import "DecoderViewController.h"
26 #import "RotatingNavigationController.h"
27
28 @implementation ZXingAppDelegate
29
30 @synthesize window;
31 @synthesize viewController;
32 @synthesize navigationController;
33
34 - (void)applicationDidFinishLaunching:(UIApplication *)application {
35   /* create the view controller */
36   DecoderViewController *vc = 
37     [[DecoderViewController alloc] initWithNibName:@"DecoderView" 
38                                          bundle:[NSBundle mainBundle]];
39   self.viewController = vc;
40   [vc release];
41   
42   navigationController = [[RotatingNavigationController alloc] 
43                           initWithRootViewController:viewController];
44   
45   // hook up the view controller's view to be in the window
46   [window addSubview:navigationController.view];
47   
48   // show the window
49   [window makeKeyAndVisible];
50   
51   if ([[NSUserDefaults standardUserDefaults] boolForKey:@"autoChoosePicture"]) {    
52     // pick and decode using the first available source type in priority order
53 #define N_SOURCE_TYPES 3
54     UIImagePickerControllerSourceType sourceTypes[N_SOURCE_TYPES] = {
55       UIImagePickerControllerSourceTypeCamera,
56       UIImagePickerControllerSourceTypeSavedPhotosAlbum,
57       UIImagePickerControllerSourceTypePhotoLibrary
58     };
59
60     for (int i = 0; i < N_SOURCE_TYPES; i++) {
61       if ([UIImagePickerController isSourceTypeAvailable:sourceTypes[i]]) {
62         [viewController pickAndDecodeFromSource:sourceTypes[i]];
63         break;
64       }
65     }
66 #undef N_SOURCE_TYPES
67   }
68 }
69
70 - (void)dealloc {
71   [window release];
72   [super dealloc];
73 }
74
75 @end