FreeRDP
AboutController.m
1 /*
2  Application info controller
3 
4  Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5 
6  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7  If a copy of the MPL was not distributed with this file, You can obtain one at
8  http://mozilla.org/MPL/2.0/.
9  */
10 
11 #import "AboutController.h"
12 #import "Utils.h"
13 #import "BlockAlertView.h"
14 
15 @implementation AboutController
16 
17 // The designated initializer. Override if you create the controller programmatically and want to
18 // perform customization that is not appropriate for viewDidLoad.
19 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
20 {
21  if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
22  {
23 
24  // set title and tab-bar image
25  [self setTitle:NSLocalizedString(@"About", @"About Controller title")];
26  UIImage *tabBarIcon = [UIImage
27  imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tabbar_icon_about"
28  ofType:@"png"]];
29  [self setTabBarItem:[[[UITabBarItem alloc]
30  initWithTitle:NSLocalizedString(@"About", @"Tabbar item about")
31  image:tabBarIcon
32  tag:0] autorelease]];
33 
34  last_link_clicked = nil;
35  }
36  return self;
37 }
38 
39 - (void)dealloc
40 {
41  [super dealloc];
42  [last_link_clicked release];
43 }
44 
45 // Implement loadView to create a view hierarchy programmatically, without using a nib.
46 - (void)loadView
47 {
48  webView = [[[UIWebView alloc] initWithFrame:CGRectZero] autorelease];
49  [webView
50  setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
51  [webView setAutoresizesSubviews:YES];
52  [webView setDelegate:self];
53  [webView setDataDetectorTypes:UIDataDetectorTypeNone];
54  [self setView:webView];
55 }
56 
57 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
58 - (void)viewDidLoad
59 {
60  [super viewDidLoad];
61 
62  NSString *filename = (IsPhone() ? @"about_phone" : @"about");
63  NSString *htmlString = [[[NSString alloc]
64  initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename
65  ofType:@"html"
66  inDirectory:@"about_page"]
67  encoding:NSUTF8StringEncoding
68  error:nil] autorelease];
69 
70  [webView
71  loadHTMLString:[NSString stringWithFormat:htmlString, TSXAppFullVersion(),
72  [[UIDevice currentDevice] systemName],
73  [[UIDevice currentDevice] systemVersion],
74  [[UIDevice currentDevice] model]]
75  baseURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] bundlePath]
76  stringByAppendingPathComponent:@"about_page"]]];
77 }
78 
79 // Override to allow orientations other than the default portrait orientation.
80 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
81 {
82  return YES;
83 }
84 
85 #pragma mark -
86 #pragma mark UIWebView callbacks
87 - (BOOL)webView:(UIWebView *)webView
88  shouldStartLoadWithRequest:(NSURLRequest *)request
89  navigationType:(UIWebViewNavigationType)navigationType
90 {
91  if ([[request URL] isFileURL])
92  return YES;
93 
94  if (navigationType == UIWebViewNavigationTypeLinkClicked)
95  {
96  [last_link_clicked release];
97  last_link_clicked = [[[request URL] absoluteString] retain];
99  alertWithTitle:NSLocalizedString(@"External Link", @"External Link Alert Title")
100  message:[NSString stringWithFormat:
101  NSLocalizedString(
102  @"Open [%@] in Browser?",
103  @"Open link in browser (with link as parameter)"),
104  last_link_clicked]];
105 
106  [alert setCancelButtonWithTitle:NSLocalizedString(@"No", @"No Button") block:nil];
107  [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK Button")
108  block:^{
109  [[UIApplication sharedApplication]
110  openURL:[NSURL URLWithString:last_link_clicked]];
111  }];
112 
113  [alert show];
114 
115  return NO;
116  }
117  return YES;
118 }
119 
120 @end