Issue 412
[zxing.git] / iphone / Classes / URIParsedResult.m
1 //
2 //  URIParsedResult.m
3 //  ZXing
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 "URIParsedResult.h"
23 #import "OpenUrlAction.h"
24 #import "EmailAction.h"
25 #import "SMSAction.h"
26
27
28 @implementation URIParsedResult
29
30 @synthesize urlString;
31 @synthesize title;
32 @synthesize URL;
33
34 - (ResultAction *)createAction {
35   return [OpenUrlAction actionWithURL:self.URL];
36 }
37
38 - (id)initWithURLString:(NSString *)s title:(NSString *)t URL:(NSURL *)url {
39   if ((self = [super init]) != nil) {
40     self.urlString = s;
41     self.title = t;
42     self.URL = url;
43   }
44   return self;
45 }
46
47 - (id)initWithURLString:(NSString *)s URL:(NSURL *)url {
48   return [self initWithURLString:s title:nil URL:url];
49 }
50
51 - (id)initWithURLString:(NSString *)s title:(NSString *)t {
52   return [self initWithURLString:s title:t URL:[NSURL URLWithString:s]];
53 }
54
55 - (id)initWithURLString:(NSString *)s {
56   return [self initWithURLString:s title:nil URL:[NSURL URLWithString:s]];
57 }
58
59 - (NSString *)stringForDisplay {
60   return self.title ? 
61   [NSString stringWithFormat:@"%@ <%@>", self.title, self.urlString] :
62   self.urlString;
63 }
64
65 + (NSString *)typeName {
66   return NSLocalizedString(@"URIParsedResult type name", @"URI");
67 }
68
69 - (UIImage *)icon {
70   return [UIImage imageNamed:@"link2.png"];
71 }
72
73 - (void)populateActions { 
74 #ifdef DEBUG
75   NSLog(@"creating action to open URL '%@'", self.urlString);
76 #endif
77   
78   [actions addObject:[self createAction]];
79 }
80
81 - (void)dealloc {
82   [URL release];
83   [urlString release];
84   [super dealloc];
85 }
86
87 @end