18c08659eab54cea8c37f0508ce1951faa454efe
[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 ZXing authors
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
27 @implementation ZXingAppDelegate
28
29 @synthesize window;
30 @synthesize viewController;
31 @synthesize navigationController;
32
33 - (void)applicationDidFinishLaunching:(UIApplication *)application {
34   
35   for (NSString *familyName in [UIFont familyNames]) {
36     NSLog(@"family name: '%@'", familyName);
37     for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
38       NSLog(@"  font name: '%@'", fontName);
39     }
40   }
41   
42   /* create the view controller */
43   DecoderViewController *vc = 
44     [[DecoderViewController alloc] initWithNibName:@"DecoderView" 
45                                             bundle:[NSBundle mainBundle]];
46   self.viewController = vc;
47   [vc release];
48   
49   navigationController = [[UINavigationController alloc] 
50                           initWithRootViewController:viewController];
51   
52   // hook up the view controller's view to be in the window
53   [window addSubview:navigationController.view];
54   
55   // show the window
56   [window makeKeyAndVisible];
57   
58   if ([[NSUserDefaults standardUserDefaults] boolForKey:@"autoChoosePicture"]) {    
59     // pick and decode using the first available source type in priority order
60 #define N_SOURCE_TYPES 3
61     UIImagePickerControllerSourceType sourceTypes[N_SOURCE_TYPES] = {
62       UIImagePickerControllerSourceTypeCamera,
63       UIImagePickerControllerSourceTypeSavedPhotosAlbum,
64       UIImagePickerControllerSourceTypePhotoLibrary
65     };
66
67     for (int i = 0; i < N_SOURCE_TYPES; i++) {
68       if ([UIImagePickerController isSourceTypeAvailable:sourceTypes[i]]) {
69         [viewController pickAndDecodeFromSource:sourceTypes[i]];
70         break;
71       }
72     }
73 #undef N_SOURCE_TYPES
74   }
75 }
76
77 - (void)dealloc {
78   [window release];
79   [super dealloc];
80 }
81
82 @end