]> git.saurik.com Git - cydia.git/blobdiff - Cydia.mm
Merge branch 'master' of saurik.com:cydia
[cydia.git] / Cydia.mm
index 55627d374effa3b71d1eed8ff68982c2edd7484d..936856dbaf73b03ff0404e25f9f57d07f4bbb24a 100644 (file)
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -311,7 +311,7 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) {
     } return self;
 }
 
-- (void)_updateFrameForDisplay {
+- (void) _updateFrameForDisplay {
     [super _updateFrameForDisplay];
     if ([self cancelButtonIndex] == -1) {
         NSArray *buttons = [self buttons];
@@ -384,7 +384,7 @@ static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive |
 #define ShowInternals (0 && !ForRelease)
 #define IgnoreInstall (0 && !ForRelease)
 #define RecycleWebViews 0
-#define RecyclePackageViews (1 && ForRelease)
+#define RecyclePackageViews (0 && ForRelease)
 #define AlwaysReload (1 && !ForRelease)
 
 #if !TraceLogging
@@ -618,7 +618,9 @@ void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFCompar
 @end
 /* }}} */
 
-NSUInteger WebScriptObject$countByEnumeratingWithState$objects$count$(WebScriptObject *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
+@implementation WebScriptObject (NSFastEnumeration)
+
+- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count {
     size_t length([self count] - state->state);
     if (length <= 0)
         return 0;
@@ -631,6 +633,8 @@ NSUInteger WebScriptObject$countByEnumeratingWithState$objects$count$(WebScriptO
     return length;
 }
 
+@end
+
 NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
     size_t length([self length] - state->state);
     if (length <= 0)
@@ -1046,14 +1050,14 @@ static UIFont *Font18Bold_;
 static UIFont *Font22Bold_;
 
 static const char *Machine_ = NULL;
-static const NSString *System_ = NULL;
-static const NSString *SerialNumber_ = nil;
-static const NSString *ChipID_ = nil;
-static const NSString *Token_ = nil;
-static const NSString *UniqueID_ = nil;
-static const NSString *Build_ = nil;
-static const NSString *Product_ = nil;
-static const NSString *Safari_ = nil;
+static NSString *System_ = nil;
+static NSString *SerialNumber_ = nil;
+static NSString *ChipID_ = nil;
+static NSString *Token_ = nil;
+static NSString *UniqueID_ = nil;
+static NSString *Build_ = nil;
+static NSString *Product_ = nil;
+static NSString *Safari_ = nil;
 
 static CFLocaleRef Locale_;
 static NSArray *Languages_;
@@ -1630,11 +1634,11 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 }
 
 - (NSString *) depictionForPackage:(NSString *)package {
-    return depiction_.empty() ? nil : [depiction_ stringByReplacingOccurrencesOfString:@"*" withString:package];
+    return depiction_.empty() ? nil : [static_cast<id>(depiction_) stringByReplacingOccurrencesOfString:@"*" withString:package];
 }
 
 - (NSString *) supportForPackage:(NSString *)package {
-    return support_.empty() ? nil : [support_ stringByReplacingOccurrencesOfString:@"*" withString:package];
+    return support_.empty() ? nil : [static_cast<id>(support_) stringByReplacingOccurrencesOfString:@"*" withString:package];
 }
 
 - (NSDictionary *) record {
@@ -2176,7 +2180,7 @@ struct PackageNameOrdering :
         _end
 
         bool changed(false);
-        NSString *key([id_ lowercaseString]);
+        NSString *key([static_cast<id>(id_) lowercaseString]);
 
         _profile(Package$initWithVersion$Metadata)
             metadata_ = [Packages_ objectForKey:key];
@@ -2482,9 +2486,9 @@ struct PackageNameOrdering :
 
     UIImage *icon(nil);
     if (!icon_.empty())
-        if ([icon_ hasPrefix:@"file:///"])
+        if ([static_cast<id>(icon_) hasPrefix:@"file:///"])
             // XXX: correct escaping
-            icon = [UIImage imageAtPath:[icon_ substringFromIndex:7]];
+            icon = [UIImage imageAtPath:[static_cast<id>(icon_) substringFromIndex:7]];
     if (icon == nil) if (section != nil)
         icon = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]];
     if (icon == nil) if (source_ != nil) if (NSString *dicon = [source_ defaultIcon])
@@ -7620,11 +7624,16 @@ freeing the view controllers on tab change */
 - (void) dropBar:(BOOL)animated;
 - (void) beginUpdate;
 - (void) raiseBar:(BOOL)animated;
+- (BOOL) updating;
 
 @end
 
 @implementation CYContainer
 
+- (BOOL) _reallyWantsFullScreenLayout {
+    return YES;
+}
+
 // NOTE: UIWindow only sends the top controller these messages,
 //       So we have to forward them on.
 
@@ -7757,17 +7766,30 @@ freeing the view controllers on tab change */
     updatedelegate_ = delegate;
 }
 
+- (CGFloat) statusBarHeight {
+    if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) {
+        return [[UIApplication sharedApplication] statusBarFrame].size.height;
+    } else {
+        return [[UIApplication sharedApplication] statusBarFrame].size.width;
+    }
+}
+
 - (void) dropBar:(BOOL)animated {
     if (dropped_) return;
     dropped_ = true;
 
     [[self view] addSubview:refreshbar_];
 
+    CGFloat sboffset = [self statusBarHeight];
+
+    CGRect barframe = [refreshbar_ frame];   
+    barframe.origin.y = sboffset;
+    [refreshbar_ setFrame:barframe];
+
     if (animated) [UIView beginAnimations:nil context:NULL];
-    CGRect barframe = [refreshbar_ frame];
     CGRect viewframe = [[root_ view] frame];
-    viewframe.origin.y += barframe.size.height;
-    viewframe.size.height -= barframe.size.height;
+    viewframe.origin.y += barframe.size.height + sboffset;
+    viewframe.size.height -= barframe.size.height + sboffset;
     [[root_ view] setFrame:viewframe];
     if (animated) [UIView commitAnimations];
 
@@ -7785,11 +7807,13 @@ freeing the view controllers on tab change */
 
     [refreshbar_ removeFromSuperview];
 
+    CGFloat sboffset = [self statusBarHeight]; 
+
     if (animated) [UIView beginAnimations:nil context:NULL];
     CGRect barframe = [refreshbar_ frame];
     CGRect viewframe = [[root_ view] frame];
-    viewframe.origin.y -= barframe.size.height;
-    viewframe.size.height += barframe.size.height;
+    viewframe.origin.y -= barframe.size.height + sboffset;
+    viewframe.size.height += barframe.size.height + sboffset;
     [[root_ view] setFrame:viewframe];
     if (animated) [UIView commitAnimations];
 
@@ -7812,16 +7836,25 @@ freeing the view controllers on tab change */
     [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
 }
 
+- (void) statusBarFrameChanged:(NSNotification *)notification {
+    if (dropped_) {
+        [self raiseBar:NO];
+        [self dropBar:NO];
+    }
+}
+
 - (void) dealloc {
     [refreshbar_ release];
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
     [super dealloc];
 }
 
-- (id) initWithDatabase: (Database *)database {
+- (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
         database_ = database;
 
         [[self view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
 
         refreshbar_ = [[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self];
     } return self;
@@ -8219,7 +8252,7 @@ static _finline void _setHomePage(Cydia *self) {
     [page setDelegate:self];
 
     CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController];
-    [navController setViewControllers:[NSArray arrayWithObject:page] animated:NO];
+    [navController setViewControllers:[NSArray arrayWithObject:page]];
     for (CYNavigationController *page in [tabbar_ viewControllers]) {
         if (page != navController) [page setViewControllers:nil];
     }
@@ -8342,29 +8375,40 @@ static _finline void _setHomePage(Cydia *self) {
 #endif
 }
 
+// Returns the navigation controller for the queuing badge.
+- (id) queueBadgeController {
+    int index = [self indexOfTabWithTag:kManageTag];
+    if (index == -1) index = [self indexOfTabWithTag:kInstalledTag];
+    
+    return [[tabbar_ viewControllers] objectAtIndex:index];
+}
+
 - (void) cancelAndClear:(bool)clear {
     @synchronized (self) {
         if (clear) {
-            /* XXX: clear marks instead of reloading data */
-            /*pkgCacheFile &cache([database_ cache]);
+            // Clear all marks.
+            pkgCacheFile &cache([database_ cache]);
             for (pkgCache::PkgIterator iterator = cache->PkgBegin(); !iterator.end(); ++iterator) {
-                if (!cache[iterator].Keep()) cache->MarkKeep(iterator, false, false);
+                // Unmark method taken from Synaptic Package Manager.
+                               // Thanks for being sane, unlike Aptitude.
+                               if (!cache[iterator].Keep()) {
+                                       cache->MarkKeep(iterator, false);
+                                       cache->SetReInstall(iterator, false);
+                               }
             }
 
-            [self updateData];
-
+                       // Stop queuing.
             Queuing_ = false;
-            [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kManageTag] != -1 ? [self indexOfTabWithTag:kManageTag] : [self indexOfTabWithTag:kInstalledTag]] tabBarItem] setBadgeValue:nil];
-            [queueDelegate_ queueStatusDidChange];*/
-            [self reloadData];
+            [[[self queueBadgeController] tabBarItem] setBadgeValue:nil];
         } else {
+                       // Start queuing.
             Queuing_ = true;
-
-            [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kManageTag] != -1 ? [self indexOfTabWithTag:kManageTag] : [self indexOfTabWithTag:kInstalledTag]] tabBarItem] setBadgeValue:UCLocalize("Q_D")];
-            [(CYNavigationController *)[tabbar_ selectedViewController] reloadData];
-
-            [queueDelegate_ queueStatusDidChange];
-        }
+            [[[self queueBadgeController] tabBarItem] setBadgeValue:UCLocalize("Q_D")];
+               }
+        
+               // Show the changes in the current view.
+        [(CYNavigationController *) [tabbar_ selectedViewController] reloadData];
+        [queueDelegate_ queueStatusDidChange];
     }
 }
 
@@ -8713,7 +8757,6 @@ int main(int argc, char *argv[]) { _pooled
     PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
 
     /* Library Hacks {{{ */
-    class_addMethod(objc_getClass("WebScriptObject"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &WebScriptObject$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
     class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
 
     $WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");