]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Centralize addCydiaHost: to Cydia delegate_.
[cydia.git] / MobileCydia.mm
index f82d393873020c4aa2ac6d788036fda9dd1b195a..617562f6d68f8d63e4c99c474237ebe6ff7d6c64 100644 (file)
@@ -1066,6 +1066,8 @@ static time_t now_;
 bool IsWildcat_;
 static CGFloat ScreenScale_;
 static NSString *Idiom_;
+
+static NSMutableSet *CydiaHosts_;
 /* }}} */
 
 /* Display Helpers {{{ */
@@ -1168,6 +1170,7 @@ bool isSectionVisible(NSString *section) {
 - (CYViewController *) pageForPackage:(NSString *)name;
 - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
 - (void) reloadDataWithInvocation:(NSInvocation *)invocation;
+- (void) addCydiaHost:(NSString *)host;
 @end
 /* }}} */
 
@@ -1638,12 +1641,12 @@ static void PackageImport(const void *key, const void *value, void *context) {
     CYString type_;
     CYString version_;
 
-    NSString *host_;
-    NSString *authority_;
+    _H<NSString> host_;
+    _H<NSString> authority_;
 
     CYString defaultIcon_;
 
-    NSDictionary *record_;
+    _H<NSDictionary> record_;
     BOOL trusted_;
 }
 
@@ -1688,20 +1691,9 @@ static void PackageImport(const void *key, const void *value, void *context) {
     version_.clear();
     defaultIcon_.clear();
 
-    if (record_ != nil) {
-        [record_ release];
-        record_ = nil;
-    }
-
-    if (host_ != nil) {
-        [host_ release];
-        host_ = nil;
-    }
-
-    if (authority_ != nil) {
-        [authority_ release];
-        authority_ = nil;
-    }
+    record_ = nil;
+    host_ = nil;
+    authority_ = nil;
 }
 
 - (void) dealloc {
@@ -1779,22 +1771,18 @@ static void PackageImport(const void *key, const void *value, void *context) {
     }
 
     record_ = [Sources_ objectForKey:[self key]];
-    if (record_ != nil)
-        record_ = [record_ retain];
 
     NSURL *url([NSURL URLWithString:uri_]);
 
     host_ = [url host];
     if (host_ != nil)
-        host_ = [[host_ lowercaseString] retain];
+        host_ = [host_ lowercaseString];
 
     if (host_ != nil)
-        authority_ = host_;
+        // XXX: this is due to a bug in _H<>
+        authority_ = (id) host_;
     else
         authority_ = [url path];
-
-    if (authority_ != nil)
-        authority_ = [authority_ retain];
 }
 
 - (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
@@ -1863,7 +1851,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 }
 
 - (NSString *) name {
-    return origin_.empty() ? authority_ : origin_;
+    return origin_.empty() ? (id) authority_ : origin_;
 }
 
 - (NSString *) description {
@@ -1871,7 +1859,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 }
 
 - (NSString *) label {
-    return label_.empty() ? authority_ : label_;
+    return label_.empty() ? (id) authority_ : label_;
 }
 
 - (NSString *) origin {
@@ -2375,13 +2363,16 @@ struct PackageNameOrdering :
         @"purposes",
         @"relations",
         @"section",
+        @"selection",
         @"shortDescription",
         @"shortSection",
         @"simpleSection",
         @"size",
         @"source",
         @"sponsor",
+        @"state",
         @"support",
+        @"tags",
         @"warnings",
     nil];
 }
@@ -2930,6 +2921,54 @@ struct PackageNameOrdering :
     return files;
 }
 
+- (NSString *) state {
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
+        return nil;
+
+    switch (iterator_->CurrentState) {
+        case pkgCache::State::NotInstalled:
+            return @"NotInstalled";
+        case pkgCache::State::UnPacked:
+            return @"UnPacked";
+        case pkgCache::State::HalfConfigured:
+            return @"HalfConfigured";
+        case pkgCache::State::HalfInstalled:
+            return @"HalfInstalled";
+        case pkgCache::State::ConfigFiles:
+            return @"ConfigFiles";
+        case pkgCache::State::Installed:
+            return @"Installed";
+        case pkgCache::State::TriggersAwaited:
+            return @"TriggersAwaited";
+        case pkgCache::State::TriggersPending:
+            return @"TriggersPending";
+    }
+
+    return (NSString *) [NSNull null];
+} }
+
+- (NSString *) selection {
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
+        return nil;
+
+    switch (iterator_->SelectedState) {
+        case pkgCache::State::Unknown:
+            return @"Unknown";
+        case pkgCache::State::Install:
+            return @"Install";
+        case pkgCache::State::Hold:
+            return @"Hold";
+        case pkgCache::State::DeInstall:
+            return @"DeInstall";
+        case pkgCache::State::Purge:
+            return @"Purge";
+    }
+
+    return (NSString *) [NSNull null];
+} }
+
 - (NSArray *) warnings {
     NSMutableArray *warnings([NSMutableArray arrayWithCapacity:4]);
     const char *name(iterator_.Name());
@@ -3068,6 +3107,10 @@ struct PackageNameOrdering :
     _assert(false);
 }
 
+- (NSArray *) tags {
+    return tags_;
+}
+
 - (BOOL) hasTag:(NSString *)tag {
     return tags_ == nil ? NO : [tags_ containsObject:tag];
 }
@@ -4087,6 +4130,8 @@ static NSString *Warning_;
 
 + (NSString *) webScriptNameForSelector:(SEL)selector {
     if (false);
+    else if (selector == @selector(addCydiaHost:))
+        return @"addCydiaHost";
     else if (selector == @selector(addTrivialSource:))
         return @"addTrivialSource";
     else if (selector == @selector(close))
@@ -4113,8 +4158,12 @@ static NSString *Warning_;
         return @"refreshSources";
     else if (selector == @selector(removeButton))
         return @"removeButton";
+    else if (selector == @selector(substitutePackageNames:))
+        return @"substitutePackageNames";
     else if (selector == @selector(scrollToBottom:))
         return @"scrollToBottom";
+    else if (selector == @selector(setAllowsNavigationAction:))
+        return @"setAllowsNavigationAction";
     else if (selector == @selector(setButtonImage:withStyle:toFunction:))
         return @"setButtonImage";
     else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
@@ -4125,6 +4174,8 @@ static NSString *Warning_;
         return @"setHidesNavigationBar";
     else if (selector == @selector(setNavigationBarStyle:))
         return @"setNavigationBarStyle";
+    else if (selector == @selector(setNavigationBarTintRed:green:blue:alpha:))
+        return @"setNavigationBarTintColor";
     else if (selector == @selector(setPopupHook:))
         return @"setPopupHook";
     else if (selector == @selector(setToken:))
@@ -4181,6 +4232,10 @@ static NSString *Warning_;
     return [NSString stringWithCString:value];
 }
 
+- (void) addCydiaHost:(NSString *)host {
+    [delegate_ performSelectorOnMainThread:@selector(addCydiaHost:) withObject:host waitUntilDone:NO];
+}
+
 - (void) addTrivialSource:(NSString *)href {
     [delegate_ performSelectorOnMainThread:@selector(addTrivialSource:) withObject:href waitUntilDone:NO];
 }
@@ -4277,6 +4332,17 @@ static NSString *Warning_;
     [delegate_ performSelectorOnMainThread:@selector(installPackages:) withObject:packages waitUntilDone:NO];
 }
 
+- (NSString *) substitutePackageNames:(NSString *)message {
+    NSMutableArray *words([[message componentsSeparatedByString:@" "] mutableCopy]);
+    for (size_t i(0), e([words count]); i != e; ++i) {
+        NSString *word([words objectAtIndex:i]);
+        if (Package *package = [[Database sharedInstance] packageWithName:word])
+            [words replaceObjectAtIndex:i withObject:[package name]];
+    }
+
+    return [words componentsJoinedByString:@" "];
+}
+
 - (void) removeButton {
     [indirect_ removeButton];
 }
@@ -4289,6 +4355,10 @@ static NSString *Warning_;
     [indirect_ setButtonTitle:button withStyle:style toFunction:function];
 }
 
+- (void) setAllowsNavigationAction:(NSString *)value {
+    [indirect_ performSelectorOnMainThread:@selector(setAllowsNavigationActionByNumber:) withObject:value waitUntilDone:NO];
+}
+
 - (void) setHidesBackButton:(NSString *)value {
     [indirect_ performSelectorOnMainThread:@selector(setHidesBackButtonByNumber:) withObject:value waitUntilDone:NO];
 }
@@ -4301,6 +4371,12 @@ static NSString *Warning_;
     [indirect_ performSelectorOnMainThread:@selector(setNavigationBarStyle:) withObject:value waitUntilDone:NO];
 }
 
+- (void) setNavigationBarTintRed:(NSNumber *)red green:(NSNumber *)green blue:(NSNumber *)blue alpha:(NSNumber *)alpha {
+    float opacity(alpha == (id) [WebUndefined undefined] ? 1 : [alpha floatValue]);
+    UIColor *color([UIColor colorWithRed:[red floatValue] green:[green floatValue] blue:[blue floatValue] alpha:opacity]);
+    [indirect_ performSelectorOnMainThread:@selector(setNavigationBarTintColor:) withObject:color waitUntilDone:NO];
+}
+
 - (void) _setToken:(NSString *)token {
     Token_ = token;
 
@@ -4442,7 +4518,7 @@ static NSString *Warning_;
 
 - (void) loadView {
     [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-    [[self view] setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
+    [[self view] setBackgroundColor:[self groupTableViewBackgroundColor]];
 
     indicator_ = [[[CYLoadingIndicator alloc] initWithFrame:[[self view] bounds]] autorelease];
     [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
@@ -4496,7 +4572,7 @@ static NSString *Warning_;
     NSURLResponse *response([source response]);
 
     NSURL *url([response URL]);
-    NSString *scheme([url scheme]);
+    //NSString *scheme([url scheme]);
     NSString *host([url host]);
 
     if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
@@ -4505,11 +4581,7 @@ static NSString *Warning_;
         [self setHeaders:headers forHost:host];
     }
 
-    if (
-        [host isEqualToString:@"cydia.saurik.com"] ||
-        [host hasSuffix:@".cydia.saurik.com"] ||
-        [scheme isEqualToString:@"file"]
-    )
+    if ([CydiaHosts_ containsObject:host])
         [window setValue:cydia_ forKey:@"cydia"];
 }
 
@@ -5867,11 +5939,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     UIActionSheetDelegate
 > {
     _transient Database *database_;
-    Package *package_;
-    NSString *name_;
+    _H<Package> package_;
+    _H<NSString> name_;
     bool commercial_;
-    NSMutableArray *buttons_;
-    UIBarButtonItem *button_;
+    _H<NSMutableArray> buttons_;
+    _H<UIBarButtonItem> button_;
 }
 
 - (id) initWithDatabase:(Database *)database forPackage:(NSString *)name;
@@ -5880,22 +5952,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation CYPackageController
 
-- (void) dealloc {
-    if (package_ != nil)
-        [package_ release];
-    if (name_ != nil)
-        [name_ release];
-
-    [buttons_ release];
-
-    if (button_ != nil)
-        [button_ release];
-
-    [super dealloc];
-}
-
 - (NSURL *) navigationURL {
-    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", name_]];
+    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", (id) name_]];
 }
 
 /* XXX: this is not safe at all... localization of /fail/ */
@@ -5989,23 +6047,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (id) initWithDatabase:(Database *)database forPackage:(NSString *)name {
     if ((self = [super init]) != nil) {
         database_ = database;
-        buttons_ = [[NSMutableArray alloc] initWithCapacity:4];
-        name_ = [[NSString alloc] initWithString:name];
-        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, name_]]];
+        buttons_ = [NSMutableArray arrayWithCapacity:4];
+        name_ = [NSString stringWithString:name];
+        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, (id) name_]]];
     } return self;
 }
 
 - (void) reloadData {
-    if (package_ != nil)
-        [package_ autorelease];
     package_ = [database_ packageWithName:name_];
 
     [buttons_ removeAllObjects];
 
     if (package_ != nil) {
-        [package_ parse];
+        [(Package *) package_ parse];
 
-        package_ = [package_ retain];
         commercial_ = [package_ isCommercial];
 
         if ([package_ mode] != nil)
@@ -6021,9 +6076,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             [buttons_ addObject:UCLocalize("REMOVE")];
     }
 
-    if (button_ != nil)
-        [button_ release];
-
     NSString *title;
     switch ([buttons_ count]) {
         case 0: title = nil; break;
@@ -6031,12 +6083,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         default: title = UCLocalize("MODIFY"); break;
     }
 
-    button_ = [[UIBarButtonItem alloc]
+    button_ = [[[UIBarButtonItem alloc]
         initWithTitle:title
         style:UIBarButtonItemStylePlain
         target:self
         action:@selector(customButtonClicked)
-    ];
+    ] autorelease];
 
     [super reloadData];
 }
@@ -7119,7 +7171,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 /* Section Controller {{{ */
 @interface SectionController : FilteredPackageListController {
-    NSString *section_;
+    _H<NSString> section_;
 }
 
 - (id) initWithDatabase:(Database *)database section:(NSString *)section;
@@ -7612,7 +7664,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @interface SearchController : FilteredPackageListController <
     UISearchBarDelegate
 > {
-    UISearchBar *search_;
+    _H<UISearchBar> search_;
     BOOL searchloaded_;
 }
 
@@ -7625,7 +7677,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation SearchController
 
 - (void) dealloc {
-    [search_ release];
+    [search_ setDelegate:nil];
     [super dealloc];
 }
 
@@ -7654,7 +7706,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil])) {
-        search_ = [[UISearchBar alloc] init];
+        search_ = [[[UISearchBar alloc] init] autorelease];
+        [search_ setDelegate:self];
     } return self;
 }
 
@@ -7674,7 +7727,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             textField = MSHookIvar<UITextField *>(search_, "_searchField");
 
         [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
-        [search_ setDelegate:self];
         [textField setEnablesReturnKeyAutomatically:NO];
         [[self navigationItem] setTitleView:textField];
     }
@@ -9095,7 +9147,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) repairWithInvocation:(NSInvocation *)invocation {
     _trace();
-    [self invokeNewProgress:invocation forController:nil withTitle:UCLocalize("REPAIRING")];
+    [self invokeNewProgress:invocation forController:nil withTitle:@"REPAIRING"];
     _trace();
 }
 
@@ -9121,7 +9173,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     fclose(file);
 
-    [self detachNewProgressSelector:@selector(update_) toTarget:self forController:nil title:UCLocalize("UPDATING_SOURCES")];
+    [self detachNewProgressSelector:@selector(update_) toTarget:self forController:nil title:@"UPDATING_SOURCES"];
 
     [self complete];
 }
@@ -9227,7 +9279,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) confirmWithNavigationController:(UINavigationController *)navigation {
     Queuing_ = false;
     ++locked_;
-    [self detachNewProgressSelector:@selector(perform) toTarget:database_ forController:navigation title:UCLocalize("RUNNING")];
+    [self detachNewProgressSelector:@selector(perform) toTarget:database_ forController:navigation title:@"RUNNING"];
     --locked_;
     [self complete];
 }
@@ -9612,11 +9664,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [tabbar_ setUpdateDelegate:self];
 }
 
+- (void) addCydiaHost:(NSString *)host {
+    [CydiaHosts_ addObject:host];
+}
+
 - (void) applicationDidFinishLaunching:(id)unused {
 _trace();
     if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
         [self setApplicationSupportsShakeToEdit:NO];
 
+    [self addCydiaHost:[[NSURL URLWithString:CydiaURL(@"")] host]];
+
     [NSURLCache setSharedURLCache:[[[SDURLCache alloc]
         initWithMemoryCapacity:524288
         diskCapacity:10485760
@@ -9877,6 +9935,8 @@ int main(int argc, char *argv[]) { _pooled
             NSLog(@"unknown UIUserInterfaceIdiom!");
     }
 
+    CydiaHosts_ = [NSMutableSet setWithCapacity:2];
+
     UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]);
 
     PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
@@ -10109,7 +10169,7 @@ int main(int argc, char *argv[]) { _pooled
     if (access("/tmp/.cydia.fw", F_OK) == 0) {
         unlink("/tmp/.cydia.fw");
         goto firmware;
-    } else if (access("/User", F_OK) != 0 || version < 2) {
+    } else if (access("/User", F_OK) != 0 || version < 4) {
       firmware:
         _trace();
         system("/usr/libexec/cydia/firmware.sh");