FreeRDP
Loading...
Searching...
No Matches
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 WKWebViewConfiguration *config = [[[WKWebViewConfiguration alloc] init] autorelease];
49 [config setDataDetectorTypes:WKDataDetectorTypeNone];
50 webView = [[[WKWebView alloc] initWithFrame:CGRectZero configuration:config] autorelease];
51 [webView
52 setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
53 [webView setAutoresizesSubviews:YES];
54 [webView setNavigationDelegate:self];
55 [self setView:webView];
56}
57
58// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
59- (void)viewDidLoad
60{
61 [super viewDidLoad];
62
63 NSString *filename = (IsPhone() ? @"about_phone" : @"about");
64 NSString *htmlString = [[[NSString alloc]
65 initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename
66 ofType:@"html"
67 inDirectory:@"about_page"]
68 encoding:NSUTF8StringEncoding
69 error:nil] autorelease];
70
71 [webView
72 loadHTMLString:[NSString stringWithFormat:htmlString, TSXAppFullVersion(),
73 [[UIDevice currentDevice] systemName],
74 [[UIDevice currentDevice] systemVersion],
75 [[UIDevice currentDevice] model]]
76 baseURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] bundlePath]
77 stringByAppendingPathComponent:@"about_page"]]];
78}
79
80// Override to allow orientations other than the default portrait orientation.
81- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
82{
83 return YES;
84}
85
86#pragma mark -
87#pragma mark WKWebView callbacks
88- (void)webView:(WKWebView *)wv
89 decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
90 decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
91{
92 NSURLRequest *request = [navigationAction request];
93
94 if ([[request URL] isFileURL])
95 {
96 decisionHandler(WKNavigationActionPolicyAllow);
97 return;
98 }
99
100 if ([navigationAction navigationType] == WKNavigationTypeLinkActivated)
101 {
102 [last_link_clicked release];
103 last_link_clicked = [[[request URL] absoluteString] retain];
105 alertWithTitle:NSLocalizedString(@"External Link", @"External Link Alert Title")
106 message:[NSString stringWithFormat:
107 NSLocalizedString(
108 @"Open [%@] in Browser?",
109 @"Open link in browser (with link as parameter)"),
110 last_link_clicked]];
111
112 [alert setCancelButtonWithTitle:NSLocalizedString(@"No", @"No Button") block:nil];
113 [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK Button")
114 block:^{
115 [[UIApplication sharedApplication]
116 openURL:[NSURL URLWithString:last_link_clicked]
117 options:@{}
118 completionHandler:nil];
119 }];
120
121 [alert show];
122
123 decisionHandler(WKNavigationActionPolicyCancel);
124 return;
125 }
126
127 decisionHandler(WKNavigationActionPolicyAllow);
128}
129
130@end