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
14@implementation AboutController
15
16// The designated initializer. Override if you create the controller programmatically and want to
17// perform customization that is not appropriate for viewDidLoad.
18- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
19{
20 if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
21 {
22
23 // set title and tab-bar image
24 [self setTitle:NSLocalizedString(@"About", @"About Controller title")];
25 UIImage *tabBarIcon = [UIImage
26 imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tabbar_icon_about"
27 ofType:@"png"]];
28 [self setTabBarItem:[[[UITabBarItem alloc]
29 initWithTitle:NSLocalizedString(@"About", @"Tabbar item about")
30 image:tabBarIcon
31 tag:0] autorelease]];
32
33 last_link_clicked = nil;
34 }
35 return self;
36}
37
38- (void)dealloc
39{
40 [super dealloc];
41 [last_link_clicked release];
42}
43
44// Implement loadView to create a view hierarchy programmatically, without using a nib.
45- (void)loadView
46{
47 WKWebViewConfiguration *config = [[[WKWebViewConfiguration alloc] init] autorelease];
48 [config setDataDetectorTypes:WKDataDetectorTypeNone];
49 webView = [[[WKWebView alloc] initWithFrame:CGRectZero configuration:config] autorelease];
50 [webView
51 setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
52 [webView setAutoresizesSubviews:YES];
53 [webView setNavigationDelegate:self];
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 WKWebView callbacks
87- (void)webView:(WKWebView *)wv
88 decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
89 decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
90{
91 NSURLRequest *request = [navigationAction request];
92
93 if ([[request URL] isFileURL])
94 {
95 decisionHandler(WKNavigationActionPolicyAllow);
96 return;
97 }
98
99 if ([navigationAction navigationType] == WKNavigationTypeLinkActivated)
100 {
101 [last_link_clicked release];
102 last_link_clicked = [[[request URL] absoluteString] retain];
103 UIAlertController *alert = [UIAlertController
104 alertControllerWithTitle:NSLocalizedString(@"External Link",
105 @"External Link Alert Title")
106 message:[NSString
107 stringWithFormat:
108 NSLocalizedString(
109 @"Open [%@] in Browser?",
110 @"Open link in browser (with link as parameter)"),
111 last_link_clicked]
112 preferredStyle:UIAlertControllerStyleAlert];
113
114 [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"No", @"No Button")
115 style:UIAlertActionStyleCancel
116 handler:nil]];
117 [alert
118 addAction:[UIAlertAction
119 actionWithTitle:NSLocalizedString(@"OK", @"OK Button")
120 style:UIAlertActionStyleDefault
121 handler:^(UIAlertAction *action) {
122 [[UIApplication sharedApplication]
123 openURL:[NSURL URLWithString:last_link_clicked]
124 options:@{}
125 completionHandler:nil];
126 }]];
127
128 [self presentViewController:alert animated:YES completion:nil];
129
130 decisionHandler(WKNavigationActionPolicyCancel);
131 return;
132 }
133
134 decisionHandler(WKNavigationActionPolicyAllow);
135}
136
137@end