octover / lexikon

An iPhone application to query and cache results from the online Lexin Swedish-English dictionary for immigrants

This URL has Read+Write access

octover (author)
Mon Feb 16 02:56:17 -0800 2009
commit  843fb66036afdea8981c7ede625aae4b44ff9551
tree    09e00ebcba988ba99c295e0caa9c9218f6d4fcf5
parent  99ae845836eb73a35e3af66cb10cc11633b351cc
lexikon / AboutViewController.m
100644 98 lines (74 sloc) 3.982 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// AboutViewController.m
// Lexikon
//
// Created by Caleb Jaffa on 1/3/09.
// Copyright 2008-2009 Caleb Jaffa, MIT licensed
//
 
#import "AboutViewController.h"
 
 
@implementation AboutViewController
 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    // Custom initialization
  }
  return self;
}
 
- (void)viewDidLoad {
  // get the version and build numbers for substituting into the html document
  NSString *version = [[[NSBundle mainBundle] infoDictionary] valueForKey:[NSString stringWithFormat:@"CFBundleShortVersionString"]];
  NSString *build = [[[NSBundle mainBundle] infoDictionary] valueForKey:[NSString stringWithFormat:@"CFBundleVersion"]];
  
  // get the size of the database for substituting into the html document
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *DBPath = [documentsDirectory stringByAppendingPathComponent:@"database.sqlite3"];
  NSFileManager *fileManager = [NSFileManager defaultManager];
  NSDictionary *database = [fileManager fileAttributesAtPath:DBPath traverseLink:YES];
  NSString *filesize = [self stringFromFileSize:[database fileSize]];
  
  // set the html document up, substituting in some variables
  NSString *html = [[[[NSString stringWithContentsOfFile:[[[NSBundle mainBundle] resourcePath]
                                                         stringByAppendingPathComponent:@"aboutView.html"]]
                      stringByReplacingOccurrencesOfString:@"{version}" withString:version]
                     stringByReplacingOccurrencesOfString:@"{build}" withString:build]
                    stringByReplacingOccurrencesOfString:@"{filesize}" withString:filesize];
  
  
  // by passing the bundle as the url we can reference the logo mark easily in the html
  [webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
  self.title = NSLocalizedString(@"About", @"About button");
  
}
 
- (NSString *)stringFromFileSize:(int)theSize {
float floatSize = theSize;
if (theSize<1023) {
return([NSString stringWithFormat:@"%i bytes",theSize]);
  }
 
floatSize = floatSize / 1024;
 
if (floatSize<1023) {
return([NSString stringWithFormat:@"%1.1f KB",floatSize]);
  }
 
  floatSize = floatSize / 1024;
 
  if (floatSize<1023) {
return([NSString stringWithFormat:@"%1.1f MB",floatSize]);
  }
 
  floatSize = floatSize / 1024;
 
return([NSString stringWithFormat:@"%1.1f GB",floatSize]);
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}
 
 
- (void)dealloc {
    [super dealloc];
}
 
 
// send external web requests and mail links to be handled by the default app (Safari, mail, etc.)
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
  NSURL *loadURL = [[request URL] retain]; // retain the loadURL for use
  if (([[loadURL scheme] isEqualToString: @"http"] ||
       [[loadURL scheme] isEqualToString: @"https"] ||
       [[loadURL scheme] isEqualToString: @"mailto"] ||
       [[loadURL scheme] isEqualToString: @"tel"] ||
       [[loadURL scheme] isEqualToString: @"sms"]) &&
      (navigationType == UIWebViewNavigationTypeLinkClicked)) // Check if the scheme is http/https. You can also use these for custom links to open parts of your application.
    return ![[UIApplication sharedApplication] openURL:[loadURL autorelease]]; // Auto release the loadurl because we wont get to release later. then return the opposite of openURL, so if safari cant open the url, open it in the UIWebView.
  [loadURL release];
  return YES; // URL is not http/https and should open in UIWebView
}
 
 
@end