]> git.saurik.com Git - cydia.git/commitdiff
Move some code of Window/TabBarController to Cyte.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 5 Mar 2017 04:18:40 +0000 (20:18 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 5 Mar 2017 04:18:40 +0000 (20:18 -0800)
CyteKit/CyteKit.h
CyteKit/TabBarController.h
CyteKit/TabBarController.mm
CyteKit/ViewController.h
CyteKit/ViewController.mm
CyteKit/Window.h [new file with mode: 0644]
CyteKit/Window.mm [new file with mode: 0644]
MobileCydia.mm

index c25bc3f51ac6bc9fd8b8822db1dd04db33ccad13..53cef3cd3997facd21080dff116a26449cc9f1c2 100644 (file)
@@ -29,6 +29,7 @@
 #include "CyteKit/URLCache.h"
 #include "CyteKit/WebViewController.h"
 #include "CyteKit/WebViewTableViewCell.h"
+#include "CyteKit/Window.h"
 
 #include "CyteKit/countByEnumeratingWithState.h"
 #include "CyteKit/extern.h"
index 2aa403c4230721f7126c5e586f2cf2f13878e4a0..220609c6e0b90c8d9fa3db876a69c50fd2bd0175 100644 (file)
 
 #include <UIKit/UIKit.h>
 
-@interface UITabBarController (Cydia)
-@end
-
 @interface CyteTabBarController : UITabBarController
 
 - (NSArray *) navigationURLCollection;
+- (void) addViewControllers:(id)no, ...;
 - (UIViewController *) unselectedViewController;
 - (void) setUnselectedViewController:(UIViewController *)transient;
 
index 35a2bd0f6717dd8893e9fa94d3faecd19f48c227..a6cd088bd452a0179d7d5d0469ffd05d6aec9350 100644 (file)
 #include "iPhonePrivate.h"
 #include <Menes/ObjectHandle.h>
 
-@implementation UITabBarController (Cydia)
-
-@end
-
 @implementation CyteTabBarController {
     _transient UIViewController *transient_;
     _H<UIViewController> remembered_;
     return items;
 }
 
+- (void) addViewControllers:(id)no, ... {
+    va_list args;
+    va_start(args, no);
+
+    NSMutableArray *controllers([NSMutableArray array]);
+
+    for (;;) {
+        auto title(va_arg(args, NSString *));
+        if (title == nil)
+            break;
+
+        UINavigationController *controller([[[UINavigationController alloc] init] autorelease]);
+        [controllers addObject:controller];
+
+        auto legacy(va_arg(args, NSString *));
+        auto normal(va_arg(args, NSString *));
+        auto select(va_arg(args, NSString *));
+
+        if (kCFCoreFoundationVersionNumber < 800)
+            [controller setTabBarItem:[[[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:legacy] tag:0] autorelease]];
+        else
+            [controller setTabBarItem:[[[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:normal] selectedImage:[UIImage imageNamed:select]] autorelease]];
+    }
+
+    va_end(args);
+
+    [self setViewControllers:controllers];
+}
+
 - (void) didReceiveMemoryWarning {
     [super didReceiveMemoryWarning];
 
index 156f3cbf27b8b245d22924af0dd127497c4bd2fd..da4a33b9d060926c1a42e3857adc1045ea8965fd 100644 (file)
@@ -36,6 +36,7 @@
 - (void) unloadData;
 
 - (UIViewController *) parentOrPresentingViewController;
+- (UIViewController *) rootViewController;
 
 // This URL is used to save the state of the view controller. Return
 // nil if you cannot or should not save the URL for this page.
index 28c7c438ce0fd6b92f1e90ac2f29a9efbfe62daf..41e7ea9a5c53704c9cc3b100d98a6f8b492d5fd8 100644 (file)
     return nil;
 }
 
+- (UIViewController *) rootViewController {
+    UIViewController *base(self);
+    while ([base parentOrPresentingViewController] != nil)
+        base = [base parentOrPresentingViewController];
+    return base;
+}
+
 - (NSURL *) navigationURL {
     return nil;
 }
diff --git a/CyteKit/Window.h b/CyteKit/Window.h
new file mode 100644 (file)
index 0000000..c7224f7
--- /dev/null
@@ -0,0 +1,33 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2015  Jay Freeman (saurik)
+*/
+
+/* GNU General Public License, Version 3 {{{ */
+/*
+ * Cydia is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Cydia is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cydia.  If not, see <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#ifndef CyteKit_Window_H
+#define CyteKit_Window_H
+
+#include <UIKit/UIKit.h>
+
+@interface CyteWindow : UIWindow
+
+- (void) unloadData;
+
+@end
+
+#endif//CyteKit_Window_H
diff --git a/CyteKit/Window.mm b/CyteKit/Window.mm
new file mode 100644 (file)
index 0000000..4746e7c
--- /dev/null
@@ -0,0 +1,49 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2015  Jay Freeman (saurik)
+*/
+
+/* GNU General Public License, Version 3 {{{ */
+/*
+ * Cydia is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Cydia is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cydia.  If not, see <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#include "CyteKit/UCPlatform.h"
+
+#include "CyteKit/ViewController.h"
+#include "CyteKit/Window.h"
+
+#include "iPhonePrivate.h"
+#include <Menes/ObjectHandle.h>
+
+@implementation CyteWindow {
+    _transient UIViewController *root_;
+}
+
+- (void) setRootViewController:(UIViewController *)controller {
+    if ([super respondsToSelector:@selector(setRootViewController:)])
+        [super setRootViewController:controller];
+    else {
+        [self addSubview:[controller view]];
+        [[root_ view] removeFromSuperview];
+    }
+
+    root_ = controller;
+}
+
+- (void) unloadData {
+    [root_ unloadData];
+}
+
+@end
index 2842f0797c55dc0e37db837c5e3ebb66b60be3b3..99b2b57a4510563fdd85a02ebe7ababd2abaafa5 100644 (file)
@@ -4593,7 +4593,7 @@ static _H<NSMutableSet> Diversions_;
 }
 
 - (void) unload {
-    [delegate_ performSelectorOnMainThread:@selector(unloadData) withObject:nil waitUntilDone:NO];
+    [[indirect_ rootViewController] performSelectorOnMainThread:@selector(unloadData) withObject:nil waitUntilDone:NO];
 }
 
 - (void) setScrollAlwaysBounceVertical:(NSNumber *)value {
@@ -6526,9 +6526,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [self getKeyboardCurve:&curve duration:&duration forNotification:notification];
 
     CGRect kbframe = CGRectMake(Retina(center.x - bounds.size.width / 2), Retina(center.y - bounds.size.height / 2), bounds.size.width, bounds.size.height);
-    UIViewController *base = self;
-    while ([base parentOrPresentingViewController] != nil)
-        base = [base parentOrPresentingViewController];
+    UIViewController *base([self rootViewController]);
     CGRect viewframe = [[base view] convertRect:[list_ frame] fromView:[list_ superview]];
     CGRect intersection = CGRectIntersection(viewframe, kbframe);
 
@@ -8823,7 +8821,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi
     DatabaseDelegate,
     CydiaDelegate
 > {
-    _H<UIWindow> window_;
+    _H<CyteWindow> window_;
     _H<CydiaTabBarController> tabbar_;
     _H<CyteTabBarController> emulated_;
     _H<AppCacheController> appcache_;
@@ -8958,13 +8956,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi
     return [controllers objectAtIndex:3];
 }
 
-- (void) unloadData {
-    [tabbar_ unloadData];
-}
-
 - (void) _updateData {
     [self _saveConfig];
-    [self unloadData];
+    [window_ unloadData];
 
     UINavigationController *navigation = [self queueNavigationController];
 
@@ -9083,14 +9077,9 @@ _end
     if (emulated_ == nil)
         return;
 
-    if ([window_ respondsToSelector:@selector(setRootViewController:)])
-        [window_ setRootViewController:tabbar_];
-    else {
-        [window_ addSubview:[tabbar_ view]];
-        [[emulated_ view] removeFromSuperview];
-    }
-
+    [window_ setRootViewController:tabbar_];
     emulated_ = nil;
+
     [window_ setUserInteractionEnabled:YES];
 }
 
@@ -9684,39 +9673,6 @@ _end
     [self reloadSpringBoard];
 }
 
-- (void) setupViewControllers {
-    tabbar_ = [[[CydiaTabBarController alloc] initWithDatabase:database_] autorelease];
-
-    NSMutableArray *items;
-    if (kCFCoreFoundationVersionNumber < 800) {
-        items = [NSMutableArray arrayWithObjects:
-            [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage imageNamed:@"home.png"] tag:0] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("SOURCES") image:[UIImage imageNamed:@"install.png"] tag:0] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage imageNamed:@"changes.png"] tag:0] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("INSTALLED") image:[UIImage imageNamed:@"manage.png"] tag:0] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage imageNamed:@"search.png"] tag:0] autorelease],
-        nil];
-    } else {
-        items = [NSMutableArray arrayWithObjects:
-            [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage imageNamed:@"home7.png"] selectedImage:[UIImage imageNamed:@"home7s.png"]] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("SOURCES") image:[UIImage imageNamed:@"install7.png"] selectedImage:[UIImage imageNamed:@"install7s.png"]] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage imageNamed:@"changes7.png"] selectedImage:[UIImage imageNamed:@"changes7s.png"]] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("INSTALLED") image:[UIImage imageNamed:@"manage7.png"] selectedImage:[UIImage imageNamed:@"manage7s.png"]] autorelease],
-            [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage imageNamed:@"search7.png"] selectedImage:[UIImage imageNamed:@"search7s.png"]] autorelease],
-        nil];
-    }
-
-    NSMutableArray *controllers([NSMutableArray array]);
-    for (UITabBarItem *item in items) {
-        UINavigationController *controller([[[UINavigationController alloc] init] autorelease]);
-        [controller setTabBarItem:item];
-        [controllers addObject:controller];
-    }
-    [tabbar_ setViewControllers:controllers];
-
-    [tabbar_ setUpdateDelegate:self];
-}
-
 - (void) applicationDidFinishLaunching:(id)unused {
     [super applicationDidFinishLaunching:unused];
 _trace();
@@ -9746,7 +9702,7 @@ _trace();
     appcache_ = [[[AppCacheController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] autorelease];
     [appcache_ reloadData];
 
-    window_ = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
+    window_ = [[[CyteWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
     [window_ orderFront:self];
     [window_ makeKey:self];
     [window_ setHidden:NO];
@@ -9793,7 +9749,18 @@ _trace();
     [database_ setDelegate:self];
 
     [window_ setUserInteractionEnabled:NO];
-    [self setupViewControllers];
+
+    tabbar_ = [[[CydiaTabBarController alloc] initWithDatabase:database_] autorelease];
+
+    [tabbar_ addViewControllers:nil,
+        @"Cydia", @"home.png", @"home7.png", @"home7s.png",
+        UCLocalize("SOURCES"), @"install.png", @"install7.png", @"install7s.png",
+        UCLocalize("CHANGES"), @"changes.png", @"changes7.png", @"changes7s.png",
+        UCLocalize("INSTALLED"), @"manage.png", @"manage7.png", @"manage7s.png",
+        UCLocalize("SEARCH"), @"search.png", @"search7.png", @"search7s.png",
+    nil];
+
+    [tabbar_ setUpdateDelegate:self];
 
     CydiaLoadingViewController *loading([[[CydiaLoadingViewController alloc] init] autorelease]);
     UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
@@ -9806,10 +9773,7 @@ _trace();
     if ([emulated_ respondsToSelector:@selector(concealTabBarSelection)])
         [emulated_ concealTabBarSelection];
 
-    if ([window_ respondsToSelector:@selector(setRootViewController:)])
-        [window_ setRootViewController:emulated_];
-    else
-        [window_ addSubview:[emulated_ view]];
+    [window_ setRootViewController:emulated_];
 
     [self performSelector:@selector(loadData) withObject:nil afterDelay:0];
 _trace();