]> git.saurik.com Git - cydia.git/blob - CyteKit/ViewController.mm
On iOS 6 iPads, Cydia incorrectly uses pinstripes.
[cydia.git] / CyteKit / ViewController.mm
1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2013 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include "CyteKit/ViewController.h"
23
24 #include <Foundation/Foundation.h>
25 #include <UIKit/UIKit.h>
26
27 #include "iPhonePrivate.h"
28
29 extern bool IsWildcat_;
30
31 @implementation UIViewController (Cydia)
32
33 - (BOOL) hasLoaded {
34 return YES;
35 }
36
37 - (void) reloadData {
38 [self view];
39 }
40
41 - (void) unloadData {
42 if (UIViewController *modal = [self modalViewController])
43 [modal unloadData];
44 }
45
46 - (UIViewController *) parentOrPresentingViewController {
47 if (UIViewController *parent = [self parentViewController])
48 return parent;
49 if ([self respondsToSelector:@selector(presentingViewController)])
50 return [self presentingViewController];
51 return nil;
52 }
53
54 @end
55
56 @implementation CyteViewController
57
58 - (void) setDelegate:(id)delegate {
59 delegate_ = delegate;
60 }
61
62 - (id) delegate {
63 return delegate_;
64 }
65
66 - (void) viewWillAppear:(BOOL)animated {
67 [super viewWillAppear:animated];
68
69 // Load on first appearance. We don't need to set the loaded flag here
70 // because it is set for us the first time -reloadData is called.
71 if (![self hasLoaded])
72 [self reloadData];
73 }
74
75 - (BOOL) hasLoaded {
76 return loaded_;
77 }
78
79 - (void) releaseSubviews {
80 loaded_ = NO;
81 }
82
83 - (void) setView:(UIView *)view {
84 // Nasty hack for 2.x-compatibility. In 3.0+, we can and
85 // should just override -viewDidUnload instead.
86 if (view == nil)
87 [self releaseSubviews];
88
89 [super setView:view];
90 }
91
92 - (void) reloadData {
93 [super reloadData];
94
95 // This is called automatically on the first appearance of a controller,
96 // or any other time it needs to reload the information shown. However (!),
97 // this is not called by any tab bar or navigation controller's -reloadData
98 // method unless this controller returns YES from -hadLoaded.
99 loaded_ = YES;
100 }
101
102 - (void) unloadData {
103 loaded_ = NO;
104 [super unloadData];
105 }
106
107 - (NSURL *) navigationURL {
108 return nil;
109 }
110
111 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
112 return IsWildcat_ || orientation == UIInterfaceOrientationPortrait;
113 }
114
115 - (NSUInteger) supportedInterfaceOrientations {
116 return IsWildcat_ ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskPortrait;
117 }
118
119 - (BOOL) shouldAutorotate {
120 return YES;
121 }
122
123 - (void) setPageColor:(UIColor *)color {
124 if (color == nil) {
125 color = [UIColor groupTableViewBackgroundColor];
126 // on iOS 6 they removed groupTableViewBackgroundColor (it is present on iOS 5 and iOS 6)
127 if ([color isEqual:[UIColor clearColor]]) {
128 if (!IsWildcat_) // on devices that aren't iPads, we can just fall back to pinStripeColor
129 color = [UIColor pinStripeColor];
130 else // I don't remember where I got this color, but it is only an approximation of a gradient
131 color = [UIColor colorWithRed:(215.0/255.0) green:(217.0/255.0) blue:(223.0/255.0) alpha:1.0];
132 }
133 } color_ = color;
134 }
135
136 @end