diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2008-08-02 00:07:34 +0000 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2010-09-30 07:08:12 +0000 |
commit | 7b0ce2dae1de402fa371933b3254bf19b81a89eb (patch) | |
tree | de4092e90e986e872cb6cbaa5006a5d38445d1a8 | |
parent | 5afbb4b7d503caece8ad938cb7b53a1fd4175ce9 (diff) |
Added settings and sources to manage and fixed a few small nits.
-rw-r--r-- | Cydia.app/Repositories.png | bin | 2455 -> 0 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Administration.png (renamed from Cydia.app/Administration.png) | bin | 1403 -> 1403 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Archiving.png (renamed from Cydia.app/Archiving.png) | bin | 2475 -> 2475 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Data Storage.png (renamed from Cydia.app/Data Storage.png) | bin | 2744 -> 2744 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Development.png (renamed from Cydia.app/Development.png) | bin | 2242 -> 2242 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Games.png (renamed from Cydia.app/Games.png) | bin | 1587 -> 1587 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Java.png (renamed from Cydia.app/Java.png) | bin | 2356 -> 2356 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Localization.png (renamed from Cydia.app/Localization.png) | bin | 2223 -> 2223 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Multimedia.png (renamed from Cydia.app/Multimedia.png) | bin | 3133 -> 3133 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Networking.png (renamed from Cydia.app/Networking.png) | bin | 2520 -> 2520 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Packaging.png (renamed from Cydia.app/Packaging.png) | bin | 1490 -> 1490 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Planet-iPhones Mods.png | bin | 0 -> 2097 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Productivity.png | bin | 0 -> 2872 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Repositories.png | bin | 0 -> 2621 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Scripting.png (renamed from Cydia.app/Scripting.png) | bin | 1223 -> 1223 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Security.png (renamed from Cydia.app/Security.png) | bin | 1959 -> 1959 bytes | |||
-rw-r--r-- | Cydia.app/Sections/System.png (renamed from Cydia.app/System.png) | bin | 1939 -> 1939 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Terminal Support.png (renamed from Cydia.app/Terminal Support.png) | bin | 1649 -> 1649 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Text Editors.png (renamed from Cydia.app/Text Editors.png) | bin | 1272 -> 1272 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Themes.png (renamed from Cydia.app/Themes.png) | bin | 1873 -> 1873 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Toys.png (renamed from Cydia.app/Toys.png) | bin | 2604 -> 2604 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Tweaks.png (renamed from Cydia.app/Tweaks.png) | bin | 1693 -> 1693 bytes | |||
-rw-r--r-- | Cydia.app/Sections/Utilities.png (renamed from Cydia.app/Utilities.png) | bin | 2484 -> 2484 bytes | |||
-rw-r--r-- | Cydia.app/Sections/X Window.png (renamed from Cydia.app/X Window.png) | bin | 1878 -> 1878 bytes | |||
-rw-r--r-- | Cydia.app/Sources/apt.bigboss.us.com.png | bin | 0 -> 6405 bytes | |||
-rw-r--r-- | Cydia.app/Sources/apt.saurik.com.png | bin | 0 -> 1952 bytes | |||
-rw-r--r-- | Cydia.app/Sources/iphone.hackndev.org.png | bin | 0 -> 1655 bytes | |||
-rw-r--r-- | Cydia.app/Sources/iphonehe. | bin | 0 -> 10770 bytes | |||
-rw-r--r-- | Cydia.app/Sources/modmyifone.com.png | bin | 0 -> 3285 bytes | |||
-rw-r--r-- | Cydia.app/Sources/repo.smxy.org.png | bin | 0 -> 737 bytes | |||
-rw-r--r-- | Cydia.app/Sources/urbanfanatics.com.png | bin | 0 -> 7057 bytes | |||
-rw-r--r-- | Cydia.app/Sources/www.zodttd.com.png | bin | 0 -> 2482 bytes | |||
-rw-r--r-- | Cydia.app/error.html (renamed from Cydia.app/home.html) | 0 | ||||
-rw-r--r-- | Cydia.app/manage.html | 114 | ||||
-rw-r--r-- | Cydia.app/packages.png | bin | 0 -> 8884 bytes | |||
-rw-r--r-- | Cydia.app/sections.txt | 1 | ||||
-rw-r--r-- | Cydia.app/sources.png | bin | 0 -> 22251 bytes | |||
-rw-r--r-- | Cydia.app/storage.png | bin | 0 -> 14343 bytes | |||
-rw-r--r-- | Cydia.mm | 1599 | ||||
-rw-r--r-- | UICaboodle/RVBook.mm | 13 | ||||
-rw-r--r-- | UICaboodle/RVPage.h | 10 | ||||
-rw-r--r-- | UICaboodle/RVPage.mm | 8 | ||||
-rw-r--r-- | makefile | 2 |
43 files changed, 1216 insertions, 531 deletions
diff --git a/Cydia.app/Repositories.png b/Cydia.app/Repositories.png Binary files differdeleted file mode 100644 index 29c9db0..0000000 --- a/Cydia.app/Repositories.png +++ /dev/null diff --git a/Cydia.app/Administration.png b/Cydia.app/Sections/Administration.png Binary files differindex 8b4b44f..8b4b44f 100644 --- a/Cydia.app/Administration.png +++ b/Cydia.app/Sections/Administration.png diff --git a/Cydia.app/Archiving.png b/Cydia.app/Sections/Archiving.png Binary files differindex 68b486a..68b486a 100644 --- a/Cydia.app/Archiving.png +++ b/Cydia.app/Sections/Archiving.png diff --git a/Cydia.app/Data Storage.png b/Cydia.app/Sections/Data Storage.png Binary files differindex e8a8449..e8a8449 100644 --- a/Cydia.app/Data Storage.png +++ b/Cydia.app/Sections/Data Storage.png diff --git a/Cydia.app/Development.png b/Cydia.app/Sections/Development.png Binary files differindex 25afa9f..25afa9f 100644 --- a/Cydia.app/Development.png +++ b/Cydia.app/Sections/Development.png diff --git a/Cydia.app/Games.png b/Cydia.app/Sections/Games.png Binary files differindex 6e0efaf..6e0efaf 100644 --- a/Cydia.app/Games.png +++ b/Cydia.app/Sections/Games.png diff --git a/Cydia.app/Java.png b/Cydia.app/Sections/Java.png Binary files differindex 4b543db..4b543db 100644 --- a/Cydia.app/Java.png +++ b/Cydia.app/Sections/Java.png diff --git a/Cydia.app/Localization.png b/Cydia.app/Sections/Localization.png Binary files differindex 2450175..2450175 100644 --- a/Cydia.app/Localization.png +++ b/Cydia.app/Sections/Localization.png diff --git a/Cydia.app/Multimedia.png b/Cydia.app/Sections/Multimedia.png Binary files differindex 07f20b6..07f20b6 100644 --- a/Cydia.app/Multimedia.png +++ b/Cydia.app/Sections/Multimedia.png diff --git a/Cydia.app/Networking.png b/Cydia.app/Sections/Networking.png Binary files differindex ee1f0a1..ee1f0a1 100644 --- a/Cydia.app/Networking.png +++ b/Cydia.app/Sections/Networking.png diff --git a/Cydia.app/Packaging.png b/Cydia.app/Sections/Packaging.png Binary files differindex c1b72a5..c1b72a5 100644 --- a/Cydia.app/Packaging.png +++ b/Cydia.app/Sections/Packaging.png diff --git a/Cydia.app/Sections/Planet-iPhones Mods.png b/Cydia.app/Sections/Planet-iPhones Mods.png Binary files differnew file mode 100644 index 0000000..e641970 --- /dev/null +++ b/Cydia.app/Sections/Planet-iPhones Mods.png diff --git a/Cydia.app/Sections/Productivity.png b/Cydia.app/Sections/Productivity.png Binary files differnew file mode 100644 index 0000000..943b8bd --- /dev/null +++ b/Cydia.app/Sections/Productivity.png diff --git a/Cydia.app/Sections/Repositories.png b/Cydia.app/Sections/Repositories.png Binary files differnew file mode 100644 index 0000000..bed4a4a --- /dev/null +++ b/Cydia.app/Sections/Repositories.png diff --git a/Cydia.app/Scripting.png b/Cydia.app/Sections/Scripting.png Binary files differindex d020f71..d020f71 100644 --- a/Cydia.app/Scripting.png +++ b/Cydia.app/Sections/Scripting.png diff --git a/Cydia.app/Security.png b/Cydia.app/Sections/Security.png Binary files differindex b091a84..b091a84 100644 --- a/Cydia.app/Security.png +++ b/Cydia.app/Sections/Security.png diff --git a/Cydia.app/System.png b/Cydia.app/Sections/System.png Binary files differindex f16c216..f16c216 100644 --- a/Cydia.app/System.png +++ b/Cydia.app/Sections/System.png diff --git a/Cydia.app/Terminal Support.png b/Cydia.app/Sections/Terminal Support.png Binary files differindex 864374c..864374c 100644 --- a/Cydia.app/Terminal Support.png +++ b/Cydia.app/Sections/Terminal Support.png diff --git a/Cydia.app/Text Editors.png b/Cydia.app/Sections/Text Editors.png Binary files differindex 8176c27..8176c27 100644 --- a/Cydia.app/Text Editors.png +++ b/Cydia.app/Sections/Text Editors.png diff --git a/Cydia.app/Themes.png b/Cydia.app/Sections/Themes.png Binary files differindex f5b44db..f5b44db 100644 --- a/Cydia.app/Themes.png +++ b/Cydia.app/Sections/Themes.png diff --git a/Cydia.app/Toys.png b/Cydia.app/Sections/Toys.png Binary files differindex 88df4ab..88df4ab 100644 --- a/Cydia.app/Toys.png +++ b/Cydia.app/Sections/Toys.png diff --git a/Cydia.app/Tweaks.png b/Cydia.app/Sections/Tweaks.png Binary files differindex 14d400b..14d400b 100644 --- a/Cydia.app/Tweaks.png +++ b/Cydia.app/Sections/Tweaks.png diff --git a/Cydia.app/Utilities.png b/Cydia.app/Sections/Utilities.png Binary files differindex 2d7c31d..2d7c31d 100644 --- a/Cydia.app/Utilities.png +++ b/Cydia.app/Sections/Utilities.png diff --git a/Cydia.app/X Window.png b/Cydia.app/Sections/X Window.png Binary files differindex 5b1b7f5..5b1b7f5 100644 --- a/Cydia.app/X Window.png +++ b/Cydia.app/Sections/X Window.png diff --git a/Cydia.app/Sources/apt.bigboss.us.com.png b/Cydia.app/Sources/apt.bigboss.us.com.png Binary files differnew file mode 100644 index 0000000..8c79a38 --- /dev/null +++ b/Cydia.app/Sources/apt.bigboss.us.com.png diff --git a/Cydia.app/Sources/apt.saurik.com.png b/Cydia.app/Sources/apt.saurik.com.png Binary files differnew file mode 100644 index 0000000..f2bfcab --- /dev/null +++ b/Cydia.app/Sources/apt.saurik.com.png diff --git a/Cydia.app/Sources/iphone.hackndev.org.png b/Cydia.app/Sources/iphone.hackndev.org.png Binary files differnew file mode 100644 index 0000000..1f701df --- /dev/null +++ b/Cydia.app/Sources/iphone.hackndev.org.png diff --git a/Cydia.app/Sources/iphonehe. b/Cydia.app/Sources/iphonehe. Binary files differnew file mode 100644 index 0000000..b20263e --- /dev/null +++ b/Cydia.app/Sources/iphonehe. diff --git a/Cydia.app/Sources/modmyifone.com.png b/Cydia.app/Sources/modmyifone.com.png Binary files differnew file mode 100644 index 0000000..a7ca470 --- /dev/null +++ b/Cydia.app/Sources/modmyifone.com.png diff --git a/Cydia.app/Sources/repo.smxy.org.png b/Cydia.app/Sources/repo.smxy.org.png Binary files differnew file mode 100644 index 0000000..26c9655 --- /dev/null +++ b/Cydia.app/Sources/repo.smxy.org.png diff --git a/Cydia.app/Sources/urbanfanatics.com.png b/Cydia.app/Sources/urbanfanatics.com.png Binary files differnew file mode 100644 index 0000000..9cf47c4 --- /dev/null +++ b/Cydia.app/Sources/urbanfanatics.com.png diff --git a/Cydia.app/Sources/www.zodttd.com.png b/Cydia.app/Sources/www.zodttd.com.png Binary files differnew file mode 100644 index 0000000..83a3b33 --- /dev/null +++ b/Cydia.app/Sources/www.zodttd.com.png diff --git a/Cydia.app/home.html b/Cydia.app/error.html index f72240d..f72240d 100644 --- a/Cydia.app/home.html +++ b/Cydia.app/error.html diff --git a/Cydia.app/manage.html b/Cydia.app/manage.html new file mode 100644 index 0000000..ebda79a --- /dev/null +++ b/Cydia.app/manage.html @@ -0,0 +1,114 @@ +<?xml version="1.0" encoding="UTF-16"?> +<html><head> + <title>Manage</title> + <meta name="viewport" content="width=320, minimum-scale=1.0, maximum-scale=1.0"/> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + + <style> + body { + background: url(pinstripe.png); + display: table; + font-family: Helvetica; + height: 337px; + margin: 0; + padding: 0; + -webkit-text-size-adjust: none; + -webkit-user-select: none; + } + + div.page { + display: table-cell; + text-align: center; + margin: 0 auto; + vertical-align: middle; + width: 320px; + } + + a.giant-button { + color: #193250; + display: block; + margin: 10px; + text-decoration: none; + } + + a.giant-button > div.contents { + position: absolute; + text-align: left; + width: 300px; + -webkit-background-size: 75px auto; + z-index: 2; + } + + a.giant-button > div.contents > img { + float: left; + height: 80px; + margin: 10px; + width: 80px; + vertical-align: middle; + } + + a.giant-button > div.contents > label { + display: block; + float: left; + font-size: 30px; + margin: 10px 0 4px 4px; + text-align: center; + text-shadow: rgba(200, 200, 200, 0.75) 1px 1px 0; + width: 180px; + } + + a.giant-button > div.contents > div { + display: block; + float: left; + font-size: 14px; + margin-left: 4px; + text-align: center; + width: 180px; + } + + a.giant-button > div.background { + background-color: #000000; + height: 98px; + opacity: 0.15; + -webkit-border-radius: 10px; + } + </style> +</head><body><div class="page"> +<div class="dialog"> + <div class="panel"> + +<a href="cydia://packages" class="giant-button"> + <div class="contents"> + <img src="packages.png"/> + <label>Packages</label> + <div>View or remove packages you previously installed.</div> + </div> + + <div class="background"></div> +</a> + +<a href="cydia://sources" class="giant-button"> + <div class="contents"> + <img src="sources.png"/> + <label>Sources</label> + <div>List current sources and add custom ones you may know.</div> + </div> + + <div class="background"></div> +</a> + +<a href="cydia://storage" class="giant-button" style="opacity: 0.4"> + <div class="contents"> + <img src="storage.png" class="icon"/> + <label>Storage</label> + <div>See how much room you have left for new packages.</div> + </div> + + <div class="background"></div> +</a> + + <div style="position: absolute; top: 256px; color: red; margin: 0 auto; font-size: 40px; height: 40px; width: 320px; -webkit-transform:rotate(-10deg); text-shadow: rgba(250, 150, 150, 0.75) 1px 1px 0">Coming Soon!</div> + + </div> +</div> +</div></body></html> diff --git a/Cydia.app/packages.png b/Cydia.app/packages.png Binary files differnew file mode 100644 index 0000000..404fe0c --- /dev/null +++ b/Cydia.app/packages.png diff --git a/Cydia.app/sections.txt b/Cydia.app/sections.txt new file mode 100644 index 0000000..423c164 --- /dev/null +++ b/Cydia.app/sections.txt @@ -0,0 +1 @@ +Tweaks_2.0 Tweaks diff --git a/Cydia.app/sources.png b/Cydia.app/sources.png Binary files differnew file mode 100644 index 0000000..e8422e4 --- /dev/null +++ b/Cydia.app/sources.png diff --git a/Cydia.app/storage.png b/Cydia.app/storage.png Binary files differnew file mode 100644 index 0000000..3cefef0 --- /dev/null +++ b/Cydia.app/storage.png @@ -40,6 +40,7 @@ #define textTraits textInputTraits #define setAutoCapsType setAutocapitalizationType #define setAutoCorrectionType setAutocorrectionType + #define setPreferredKeyboardType setKeyboardType #endif /* #include Directives {{{ */ @@ -267,8 +268,6 @@ class Pcre { }; /* }}} */ /* Mime Addresses {{{ */ -Pcre email_r("^\"?(.*)\"? <([^>]*)>$"); - @interface Address : NSObject { NSString *name_; NSString *email_; @@ -307,6 +306,8 @@ Pcre email_r("^\"?(.*)\"? <([^>]*)>$"); const char *data = [string UTF8String]; size_t size = [string length]; + static Pcre email_r("^\"?(.*)\"? <([^>]*)>$"); + if (email_r(data, size)) { name_ = [email_r[1] retain]; email_ = [email_r[2] retain]; @@ -429,6 +430,7 @@ static CGColor Black_; static CGColor Clear_; static CGColor Red_; static CGColor White_; +static CGColor Gray_; static NSString *Home_; static BOOL Sounds_Keyboard_; @@ -456,9 +458,13 @@ CGColorSpaceRef space_; bool bootstrap_; bool reload_; +static NSMutableDictionary *SectionMap_; static NSMutableDictionary *Metadata_; -static NSMutableDictionary *Packages_; -static NSMutableDictionary *Sections_; +static _transient NSMutableDictionary *Settings_; +static _transient NSString *Role_; +static _transient NSMutableDictionary *Packages_; +static _transient NSMutableDictionary *Sections_; +static _transient NSMutableDictionary *Sources_; static bool Changed_; static NSDate *now_; @@ -527,11 +533,19 @@ NSString *Simplify(NSString *title) { const char *data = [title UTF8String]; size_t size = [title length]; - Pcre title_r("^(.*?)( \\(.*\\))?$"); + static Pcre square_r("^\\[(.*)\\]$"); + if (square_r(data, size)) + return Simplify(square_r[1]); + + static Pcre paren_r("^\\((.*)\\)$"); + if (paren_r(data, size)) + return Simplify(paren_r[1]); + + static Pcre title_r("^(.*?) \\(.*\\)$"); if (title_r(data, size)) - return title_r[1]; - else - return title; + return Simplify(title_r[1]); + + return title; } /* }}} */ @@ -577,6 +591,9 @@ bool isSectionVisible(NSString *section) { - (void) slideUp:(UIAlertSheet *)alert; - (void) distUpgrade; - (void) updateData; +- (void) syncData; +- (void) askForSettings; +- (UIProgressHUD *) addProgressHUD; @end /* }}} */ @@ -710,6 +727,7 @@ class Progress : - (pkgProblemResolver *) resolver; - (pkgAcquire &) fetcher; - (NSArray *) packages; +- (NSArray *) sources; - (void) reloadData; - (void) configure; @@ -738,23 +756,31 @@ class Progress : NSString *defaultIcon_; + NSDictionary *record_; BOOL trusted_; } - (Source *) initWithMetaIndex:(metaIndex *)index; +- (NSComparisonResult) compareByNameAndType:(Source *)source; + +- (NSDictionary *) record; - (BOOL) trusted; - (NSString *) uri; - (NSString *) distribution; - (NSString *) type; +- (NSString *) key; +- (NSString *) host; +- (NSString *) name; - (NSString *) description; - (NSString *) label; - (NSString *) origin; - (NSString *) version; - (NSString *) defaultIcon; + @end @implementation Source @@ -774,6 +800,8 @@ class Progress : [version_ release]; if (defaultIcon_ != nil) [defaultIcon_ release]; + if (record_ != nil) + [record_ release]; [super dealloc]; } @@ -818,9 +846,40 @@ class Progress : version_ = [[NSString stringWithUTF8String:value.c_str()] retain]; } } + + record_ = [Sources_ objectForKey:[self key]]; + if (record_ != nil) + record_ = [record_ retain]; } return self; } +- (NSComparisonResult) compareByNameAndType:(Source *)source { + NSDictionary *lhr = [self record]; + NSDictionary *rhr = [source record]; + + if (lhr != rhr) + return lhr == nil ? NSOrderedDescending : NSOrderedAscending; + + NSString *lhs = [self name]; + NSString *rhs = [source name]; + + if ([lhs length] != 0 && [rhs length] != 0) { + unichar lhc = [lhs characterAtIndex:0]; + unichar rhc = [rhs characterAtIndex:0]; + + if (isalpha(lhc) && !isalpha(rhc)) + return NSOrderedAscending; + else if (!isalpha(lhc) && isalpha(rhc)) + return NSOrderedDescending; + } + + return [lhs caseInsensitiveCompare:rhs]; +} + +- (NSDictionary *) record { + return record_; +} + - (BOOL) trusted { return trusted_; } @@ -837,12 +896,24 @@ class Progress : return type_; } +- (NSString *) key { + return [NSString stringWithFormat:@"%@:%@:%@", type_, uri_, distribution_]; +} + +- (NSString *) host { + return [[[NSURL URLWithString:[self uri]] host] lowercaseString]; +} + +- (NSString *) name { + return origin_ == nil ? [self host] : origin_; +} + - (NSString *) description { return description_; } - (NSString *) label { - return label_; + return label_ == nil ? [self host] : label_; } - (NSString *) origin { @@ -944,6 +1015,7 @@ NSString *Scour(const char *field, const char *begin, const char *end) { Address *sponsor_; Address *author_; NSArray *tags_; + NSString *role_; NSArray *relationships_; } @@ -986,10 +1058,11 @@ NSString *Scour(const char *field, const char *begin, const char *end) { - (NSArray *) relationships; - (Source *) source; +- (NSString *) role; - (BOOL) matches:(NSString *)text; -- (bool) hasUsefulPurpose; +- (bool) hasSupportingRole; - (BOOL) hasTag:(NSString *)tag; - (NSComparisonResult) compareByName:(Package *)package; @@ -1000,9 +1073,10 @@ NSString *Scour(const char *field, const char *begin, const char *end) { - (void) install; - (void) remove; -- (NSNumber *) isSearchedForBy:(NSString *)search; +- (NSNumber *) isVisiblySearchedForBy:(NSString *)search; - (NSNumber *) isInstalledInSection:(NSString *)section; -- (NSNumber *) isUninstalledInSection:(NSString *)section; +- (NSNumber *) isVisiblyUninstalledInSection:(NSString *)section; +- (NSNumber *) isVisibleInSource:(Source *)source; @end @@ -1030,6 +1104,8 @@ NSString *Scour(const char *field, const char *begin, const char *end) { [author_ release]; if (tags_ != nil) [tags_ release]; + if (role_ != nil) + [role_ release]; if (relationships_ != nil) [relationships_ release]; @@ -1086,6 +1162,15 @@ NSString *Scour(const char *field, const char *begin, const char *end) { tags_ = [[tags componentsSeparatedByString:@", "] retain]; } + if (tags_ != nil) + for (int i(0), e([tags_ count]); i != e; ++i) { + NSString *tag = [tags_ objectAtIndex:i]; + if ([tag hasPrefix:@"role::"]) { + role_ = [[tag substringFromIndex:6] retain]; + break; + } + } + NSMutableDictionary *metadata = [Packages_ objectForKey:id_]; if (metadata == nil || [metadata count] == 0) { metadata = [NSMutableDictionary dictionaryWithObjectsAndKeys: @@ -1111,7 +1196,13 @@ NSString *Scour(const char *field, const char *begin, const char *end) { - (NSString *) section { const char *section = iterator_.Section(); - return section == NULL ? nil : [[NSString stringWithUTF8String:section] stringByReplacingCharacter:'_' withCharacter:' ']; + if (section == NULL) + return nil; + NSString *key = [[NSString stringWithUTF8String:section] stringByReplacingCharacter:' ' withCharacter:'_']; + NSString *value = [SectionMap_ objectForKey:key]; + if (value == nil) + value = key; + return [value stringByReplacingCharacter:'_' withCharacter:' ']; } - (Address *) maintainer { @@ -1187,7 +1278,7 @@ NSString *Scour(const char *field, const char *begin, const char *end) { - (BOOL) visible { NSString *section = [self section]; - return [self hasUsefulPurpose] && (section == nil || isSectionVisible(section)); + return [self hasSupportingRole] && (section == nil || isSectionVisible(section)); } - (BOOL) half { @@ -1285,6 +1376,10 @@ NSString *Scour(const char *field, const char *begin, const char *end) { return source_; } +- (NSString *) role { + return role_; +} + - (BOOL) matches:(NSString *)text { if (text == nil) return NO; @@ -1306,27 +1401,22 @@ NSString *Scour(const char *field, const char *begin, const char *end) { return NO; } -- (bool) hasUsefulPurpose { - if (tags_ == nil) +- (bool) hasSupportingRole { + if (role_ == nil) return true; - bool purpose(false); - - for (int i(0), e([tags_ count]); i != e; ++i) { - NSString *tag = [tags_ objectAtIndex:i]; - if ([tag hasPrefix:@"purpose::"]) { - bool purpose(false); - if ([tag isEqualToString:@"purpose::console"]) { - return true; - } else if ([tag isEqualToString:@"purpose::library"]) { - return true; - } else if ([tag isEqualToString:@"purpose::x"]) { - return true; - } else - purpose = true; - } - } - - return !purpose; + if ([role_ isEqualToString:@"enduser"]) + return true; + if ([Role_ isEqualToString:@"User"]) + return false; + if ([role_ isEqualToString:@"hacker"]) + return true; + if ([Role_ isEqualToString:@"Hacker"]) + return false; + if ([role_ isEqualToString:@"developer"]) + return true; + if ([Role_ isEqualToString:@"Developer"]) + return false; + _assert(false); } - (BOOL) hasTag:(NSString *)tag { @@ -1425,22 +1515,29 @@ NSString *Scour(const char *field, const char *begin, const char *end) { [database_ cache]->MarkDelete(iterator_, true); } -- (NSNumber *) isSearchedForBy:(NSString *)search { - return [NSNumber numberWithBool:([self valid] && [self matches:search])]; +- (NSNumber *) isVisiblySearchedForBy:(NSString *)search { + return [NSNumber numberWithBool:([self valid] && [self visible] && [self matches:search])]; } - (NSNumber *) isInstalledInSection:(NSString *)section { return [NSNumber numberWithBool:([self installed] != nil && (section == nil || [section isEqualToString:[self section]]))]; } -- (NSNumber *) isUninstalledInSection:(NSString *)name { +- (NSNumber *) isVisiblyUninstalledInSection:(NSString *)name { NSString *section = [self section]; - return [NSNumber numberWithBool:([self valid] && [self installed] == nil && ( - (name == nil && [self visible] || - section == nil && [name length] == 0 || - [name isEqualToString:section]) - ))]; + return [NSNumber numberWithBool:( + [self valid] && [self visible] && + [self installed] == nil && ( + name == nil || + section == nil && [name length] == 0 || + [name isEqualToString:section] + ) + )]; +} + +- (NSNumber *) isVisibleInSource:(Source *)source { + return [NSNumber numberWithBool:([self source] == source && [self visible])]; } @end @@ -1548,8 +1645,8 @@ NSString *Scour(const char *field, const char *begin, const char *end) { std::istream is(&ib); std::string line; - Pcre conffile_r("^status: [^ ]* : conffile-prompt : (.*?) *$"); - Pcre pmstatus_r("^([^:]*):([^:]*):([^:]*):(.*)$"); + static Pcre conffile_r("^status: [^ ]* : conffile-prompt : (.*?) *$"); + static Pcre pmstatus_r("^([^:]*):([^:]*):([^:]*):(.*)$"); while (std::getline(is, line)) { const char *data(line.c_str()); @@ -1690,6 +1787,10 @@ NSString *Scour(const char *field, const char *begin, const char *end) { return packages_; } +- (NSArray *) sources { + return [sources_ allValues]; +} + - (void) reloadData { _error->Discard(); @@ -2256,8 +2357,6 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString @end /* }}} */ /* Progress View {{{ */ -Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); - @interface ProgressView : UIView < ConfigurationDelegate, ProgressDelegate @@ -2403,7 +2502,7 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [close_ setAutosizesToFit:NO]; [close_ setDrawsShadow:YES]; [close_ setStretchBackground:YES]; - [close_ setTitle:@"Close Window"]; + [close_ setTitle:@"Return to Cydia"]; [close_ setEnabled:YES]; GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 22); @@ -2564,6 +2663,8 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); } - (void) _setConfigurationData:(NSString *)data { + static Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); + _assert(conffile_r(data)); NSString *ofile = conffile_r[1]; @@ -2627,11 +2728,6 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); - (PackageCell *) init; - (void) setPackage:(Package *)package; -- (void) _setSelected:(float)fraction; -- (void) setSelected:(BOOL)selected; -- (void) setSelected:(BOOL)selected withFade:(BOOL)fade; -- (void) _setSelectionFadeFraction:(float)fraction; - + (int) heightForPackage:(Package *)package; @end @@ -2653,7 +2749,7 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); - (PackageCell *) init { if ((self = [super init]) != nil) { - GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 20); + GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 18); GSFontRef large = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 12); GSFontRef small = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 14); @@ -2663,7 +2759,7 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [name_ setBackgroundColor:Clear_]; [name_ setFont:bold]; - source_ = [[UITextLabel alloc] initWithFrame:CGRectMake(58, 28, 225, 20)]; + source_ = [[UITextLabel alloc] initWithFrame:CGRectMake(58, 27, 225, 20)]; [source_ setBackgroundColor:Clear_]; [source_ setFont:large]; @@ -2682,10 +2778,6 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [status_ setFont:small]; #endif - /*[icon_ setImage:[UIImage applicationImageNamed:@"unknown.png"]]; - [icon_ zoomToScale:0.5]; - [icon_ setFrame:CGRectMake(10, 10, 30, 30)];*/ - [self addSubview:icon_]; [self addSubview:name_]; [self addSubview:description_]; @@ -2709,7 +2801,7 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); if (NSString *icon = [package icon]) image = [UIImage imageAtPath:[icon substringFromIndex:6]]; if (image == nil) if (NSString *section = [package section]) - image = [UIImage applicationImageNamed:[Simplify(section) stringByAppendingString:@".png"]]; + image = [UIImage applicationImageNamed:[NSString stringWithFormat:@"Sections/%@.png", Simplify(section)]]; /*if (image == nil) if (NSString *icon = [source defaultIcon]) image = [UIImage imageAtPath:[icon substringFromIndex:6]];*/ if (image == nil) @@ -2735,8 +2827,7 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); trusted = [source trusted]; } else if ([[package id] isEqualToString:@"firmware"]) label = @"Apple"; - - if (label == nil) + else label = @"Unknown/Local"; NSString *from = [NSString stringWithFormat:@"from %@", label]; @@ -2833,11 +2924,6 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); - (id) init; - (void) setSection:(Section *)section editing:(BOOL)editing; -- (void) _setSelected:(float)fraction; -- (void) setSelected:(BOOL)selected; -- (void) setSelected:(BOOL)selected withFade:(BOOL)fade; -- (void) _setSelectionFadeFraction:(float)fraction; - @end @implementation SectionCell @@ -2851,6 +2937,32 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [super dealloc]; } +- (void) _setSelected:(float)fraction { + CGColor black(space_, + Interpolate(0.0, 1.0, fraction), + Interpolate(0.0, 1.0, fraction), + Interpolate(0.0, 1.0, fraction), + 1.0); + + [name_ setColor:black]; +} + +- (void) setSelected:(BOOL)selected { + [self _setSelected:(selected ? 1.0 : 0.0)]; + [super setSelected:selected]; +} + +- (void) setSelected:(BOOL)selected withFade:(BOOL)fade { + if (!fade) + [self _setSelected:(selected ? 1.0 : 0.0)]; + [super setSelected:selected withFade:fade]; +} + +- (void) _setSelectionFadeFraction:(float)fraction { + [self _setSelected:fraction]; + [super _setSelectionFadeFraction:fraction]; +} + - (id) init { if ((self = [super init]) != nil) { GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 22); @@ -2925,32 +3037,6 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [name_ setFrame:CGRectMake(48, 9, editing_ ? 165 : 250, 25)]; } -- (void) _setSelected:(float)fraction { - CGColor black(space_, - Interpolate(0.0, 1.0, fraction), - Interpolate(0.0, 1.0, fraction), - Interpolate(0.0, 1.0, fraction), - 1.0); - - [name_ setColor:black]; -} - -- (void) setSelected:(BOOL)selected { - [self _setSelected:(selected ? 1.0 : 0.0)]; - [super setSelected:selected]; -} - -- (void) setSelected:(BOOL)selected withFade:(BOOL)fade { - if (!fade) - [self _setSelected:(selected ? 1.0 : 0.0)]; - [super setSelected:selected withFade:fade]; -} - -- (void) _setSelectionFadeFraction:(float)fraction { - [self _setSelected:fraction]; - [super _setSelectionFadeFraction:fraction]; -} - @end /* }}} */ @@ -3649,6 +3735,633 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); @end /* }}} */ +/* Add Source View {{{ */ +@interface AddSourceView : RVPage { + _transient Database *database_; +} + +- (id) initWithBook:(RVBook *)book database:(Database *)database; + +@end + +@implementation AddSourceView + +- (id) initWithBook:(RVBook *)book database:(Database *)database { + if ((self = [super initWithBook:book]) != nil) { + database_ = database; + } return self; +} + +@end +/* }}} */ +/* Source Cell {{{ */ +@interface SourceCell : UITableCell { + UIImageView *icon_; + UITextLabel *origin_; + UITextLabel *description_; + UITextLabel *label_; +} + +- (void) dealloc; + +- (SourceCell *) initWithSource:(Source *)source; + +@end + +@implementation SourceCell + +- (void) dealloc { + [origin_ release]; + [description_ release]; + [label_ release]; + [super dealloc]; +} + +- (SourceCell *) initWithSource:(Source *)source { + if ((self = [super init]) != nil) { + GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 18); + GSFontRef large = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 12); + GSFontRef small = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 14); + + icon_ = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)]; + + UIImage *image = nil; + if (image == nil) + image = [UIImage applicationImageNamed:[NSString stringWithFormat:@"Sources/%@.png", [source host]]]; + if (image == nil) + image = [UIImage applicationImageNamed:@"unknown.png"]; + + [icon_ setImage:image]; + [icon_ zoomToScale:0.5]; + [icon_ setFrame:CGRectMake(10, 10, 30, 30)]; + + origin_ = [[UITextLabel alloc] initWithFrame:CGRectMake(48, 8, 240, 25)]; + [origin_ setBackgroundColor:Clear_]; + [origin_ setFont:bold]; + + label_ = [[UITextLabel alloc] initWithFrame:CGRectMake(58, 27, 225, 20)]; + [label_ setBackgroundColor:Clear_]; + [label_ setFont:large]; + + description_ = [[UITextLabel alloc] initWithFrame:CGRectMake(12, 46, 280, 20)]; + [description_ setBackgroundColor:Clear_]; + [description_ setFont:small]; + + [origin_ setText:[source name]]; + [label_ setText:[source uri]]; + [description_ setText:[source description]]; + + [self addSubview:icon_]; + [self addSubview:origin_]; + [self addSubview:description_]; + [self addSubview:label_]; + + CFRelease(small); + CFRelease(bold); + } return self; +} + +- (void) _setSelected:(float)fraction { + CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); + + float black[] = { + Interpolate(0.0, 1.0, fraction), + Interpolate(0.0, 1.0, fraction), + Interpolate(0.0, 1.0, fraction), + 1.0}; + + float blue[] = { + Interpolate(0.2, 1.0, fraction), + Interpolate(0.2, 1.0, fraction), + Interpolate(1.0, 1.0, fraction), + 1.0}; + + float gray[] = { + Interpolate(0.4, 1.0, fraction), + Interpolate(0.4, 1.0, fraction), + Interpolate(0.4, 1.0, fraction), + 1.0}; + + [origin_ setColor:CGColorCreate(space, black)]; + [label_ setColor:CGColorCreate(space, blue)]; + [description_ setColor:CGColorCreate(space, gray)]; +} + +- (void) setSelected:(BOOL)selected { + [self _setSelected:(selected ? 1.0 : 0.0)]; + [super setSelected:selected]; +} + +- (void) setSelected:(BOOL)selected withFade:(BOOL)fade { + if (!fade) + [self _setSelected:(selected ? 1.0 : 0.0)]; + [super setSelected:selected withFade:fade]; +} + +- (void) _setSelectionFadeFraction:(float)fraction { + [self _setSelected:fraction]; + [super _setSelectionFadeFraction:fraction]; +} + +@end +/* }}} */ +/* Source Table {{{ */ +@interface SourceTable : RVPage { + _transient Database *database_; + UISectionList *list_; + NSMutableArray *sources_; + UIAlertSheet *alert_; + int offset_; + + NSString *href_; + UIProgressHUD *hud_; + NSError *error_; + + //NSURLConnection *installer_; + NSURLConnection *trivial_bz2_; + NSURLConnection *trivial_gz_; + //NSURLConnection *automatic_; + + BOOL trivial_; +} + +- (id) initWithBook:(RVBook *)book database:(Database *)database; + +@end + +@implementation SourceTable + +- (void) _deallocConnection:(NSURLConnection *)connection { + if (connection != nil) { + [connection cancel]; + //[connection setDelegate:nil]; + [connection release]; + } +} + +- (void) dealloc { + [[list_ table] setDelegate:nil]; + [list_ setDataSource:nil]; + + if (href_ != nil) + [href_ release]; + if (hud_ != nil) + [hud_ release]; + if (error_ != nil) + [error_ release]; + + //[self _deallocConnection:installer_]; + [self _deallocConnection:trivial_gz_]; + [self _deallocConnection:trivial_bz2_]; + //[self _deallocConnection:automatic_]; + + [sources_ release]; + [list_ release]; + [super dealloc]; +} + +- (int) numberOfSectionsInSectionList:(UISectionList *)list { + return offset_ == 0 ? 1 : 2; +} + +- (NSString *) sectionList:(UISectionList *)list titleForSection:(int)section { + switch (section + (offset_ == 0 ? 1 : 0)) { + case 0: return @"Entered by User"; + case 1: return @"Installed by Packages"; + + default: + _assert(false); + return nil; + } +} + +- (int) sectionList:(UISectionList *)list rowForSection:(int)section { + switch (section + (offset_ == 0 ? 1 : 0)) { + case 0: return 0; + case 1: return offset_; + + default: + _assert(false); + return -1; + } +} + +- (int) numberOfRowsInTable:(UITable *)table { + return [sources_ count]; +} + +- (float) table:(UITable *)table heightForRow:(int)row { + Source *source = [sources_ objectAtIndex:row]; + return [source description] == nil ? 58 : 73; +} + +- (UITableCell *) table:(UITable *)table cellForRow:(int)row column:(UITableColumn *)col { + Source *source = [sources_ objectAtIndex:row]; + // XXX: weird warning, stupid selectors ;P + return [[[SourceCell alloc] initWithSource:(id)source] autorelease]; +} + +- (BOOL) table:(UITable *)table showDisclosureForRow:(int)row { + return YES; +} + +- (BOOL) table:(UITable *)table canSelectRow:(int)row { + return YES; +} + +- (void) tableRowSelected:(NSNotification*)notification { + UITable *table([list_ table]); + int row([table selectedRow]); + if (row == INT_MAX) + return; + + Source *source = [sources_ objectAtIndex:row]; + + PackageTable *packages = [[[PackageTable alloc] + initWithBook:book_ + database:database_ + title:[source label] + filter:@selector(isVisibleInSource:) + with:source + ] autorelease]; + + [packages setDelegate:delegate_]; + + [book_ pushPage:packages]; +} + +- (BOOL) table:(UITable *)table canDeleteRow:(int)row { + Source *source = [sources_ objectAtIndex:row]; + return [source record] != nil; +} + +- (void) table:(UITable *)table willSwipeToDeleteRow:(int)row { + [[list_ table] setDeleteConfirmationRow:row]; +} + +- (void) table:(UITable *)table deleteRow:(int)row { + Source *source = [sources_ objectAtIndex:row]; + [Sources_ removeObjectForKey:[source key]]; + [delegate_ syncData]; +} + +- (void) _endConnection:(NSURLConnection *)connection { + NSURLConnection **field = NULL; + if (connection == trivial_bz2_) + field = &trivial_bz2_; + else if (connection == trivial_gz_) + field = &trivial_gz_; + _assert(field != NULL); + [connection release]; + *field = nil; + + if ( + trivial_bz2_ == nil && + trivial_gz_ == nil + ) { + [delegate_ setStatusBarShowsProgress:NO]; + + [hud_ show:NO]; + [hud_ removeFromSuperview]; + [hud_ autorelease]; + hud_ = nil; + + if (trivial_) { + [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"deb", @"Type", + href_, @"URI", + @"./", @"Distribution", + nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href_]]; + + [delegate_ syncData]; + } else if (error_ != nil) { + UIAlertSheet *sheet = [[[UIAlertSheet alloc] + initWithTitle:@"Verification Error" + buttons:[NSArray arrayWithObjects:@"OK", nil] + defaultButtonIndex:0 + delegate:self + context:@"urlerror" + ] autorelease]; + + [sheet setBodyText:[error_ localizedDescription]]; + [sheet popupAlertAnimated:YES]; + } else { + UIAlertSheet *sheet = [[[UIAlertSheet alloc] + initWithTitle:@"Did not Find Repository" + buttons:[NSArray arrayWithObjects:@"OK", nil] + defaultButtonIndex:0 + delegate:self + context:@"trivial" + ] autorelease]; + + [sheet setBodyText:@"The indicated repository could not be found. This could be because you are trying to add a legacy Installer repository (these are not supported). Also, this interface is only capable of working with exact repository URLs. If you host a repository and are having issues please contact the author of Cydia with any questions you have."]; + [sheet popupAlertAnimated:YES]; + } + + [href_ release]; + href_ = nil; + + if (error_ != nil) { + [error_ release]; + error_ = nil; + } + } +} + +- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response { + switch ([response statusCode]) { + case 200: + trivial_ = YES; + } +} + +- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { + fprintf(stderr, "connection:\"%s\" didFailWithError:\"%s\"", [href_ UTF8String], [[error localizedDescription] UTF8String]); + if (error_ != nil) + error_ = [error retain]; + [self _endConnection:connection]; +} + +- (void) connectionDidFinishLoading:(NSURLConnection *)connection { + [self _endConnection:connection]; +} + +- (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method { + NSMutableURLRequest *request = [NSMutableURLRequest + requestWithURL:[NSURL URLWithString:href] + cachePolicy:NSURLRequestUseProtocolCachePolicy + timeoutInterval:20.0 + ]; + + [request setHTTPMethod:method]; + + return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; +} + +- (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button { + NSString *context = [sheet context]; + if ([context isEqualToString:@"source"]) + switch (button) { + case 1: { + NSString *href = [[sheet textField] text]; + + //installer_ = [[self _requestHRef:href method:@"GET"] retain]; + + if (![href hasSuffix:@"/"]) + href_ = [href stringByAppendingString:@"/"]; + else + href_ = href; + href_ = [href_ retain]; + + trivial_bz2_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages.bz2"] method:@"HEAD"] retain]; + trivial_gz_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages.gz"] method:@"HEAD"] retain]; + //trivial_bz2_ = [[self _requestHRef:[href stringByAppendingString:@"dists/Release"] method:@"HEAD"] retain]; + + trivial_ = false; + + hud_ = [delegate_ addProgressHUD]; + [hud_ setText:@"Verifying URL"]; + } break; + + case 2: + break; + + default: + _assert(false); + } + + [sheet dismiss]; +} + +- (id) initWithBook:(RVBook *)book database:(Database *)database { + if ((self = [super initWithBook:book]) != nil) { + database_ = database; + sources_ = [[NSMutableArray arrayWithCapacity:16] retain]; + + //list_ = [[UITable alloc] initWithFrame:[self bounds]]; + list_ = [[UISectionList alloc] initWithFrame:[self bounds] showSectionIndex:NO]; + [list_ setShouldHideHeaderInShortLists:NO]; + + [self addSubview:list_]; + [list_ setDataSource:self]; + + UITableColumn *column = [[UITableColumn alloc] + initWithTitle:@"Name" + identifier:@"name" + width:[self frame].size.width + ]; + + UITable *table = [list_ table]; + [table setSeparatorStyle:1]; + [table addTableColumn:column]; + [table setDelegate:self]; + + [self reloadData]; + } return self; +} + +- (void) reloadData { + pkgSourceList list; + _assert(list.ReadMainList()); + + [sources_ removeAllObjects]; + [sources_ addObjectsFromArray:[database_ sources]]; + [sources_ sortUsingSelector:@selector(compareByNameAndType:)]; + + int count = [sources_ count]; + for (offset_ = 0; offset_ != count; ++offset_) { + Source *source = [sources_ objectAtIndex:offset_]; + if ([source record] == nil) + break; + } + + [list_ reloadData]; +} + +- (void) resetViewAnimated:(BOOL)animated { + [list_ resetViewAnimated:animated]; +} + +- (void) _leftButtonClicked { + /*[book_ pushPage:[[[AddSourceView alloc] + initWithBook:book_ + database:database_ + ] autorelease]];*/ + + UIAlertSheet *sheet = [[[UIAlertSheet alloc] + initWithTitle:@"Enter Cydia/APT URL" + buttons:[NSArray arrayWithObjects:@"Add Source", @"Cancel", nil] + defaultButtonIndex:0 + delegate:self + context:@"source" + ] autorelease]; + + [sheet addTextFieldWithValue:@"http://" label:@""]; + + UITextTraits *traits = [[sheet textField] textTraits]; + [traits setAutoCapsType:0]; + [traits setPreferredKeyboardType:3]; + [traits setAutoCorrectionType:1]; + + [sheet popupAlertAnimated:YES]; +} + +- (void) _rightButtonClicked { + UITable *table = [list_ table]; + BOOL editing = [table isRowDeletionEnabled]; + [table enableRowDeletion:!editing animated:YES]; + [book_ reloadButtonsForPage:self]; +} + +- (NSString *) title { + return @"Sources"; +} + +- (NSString *) backButtonTitle { + return @"Sources"; +} + +- (NSString *) leftButtonTitle { + return [[list_ table] isRowDeletionEnabled] ? @"Add" : nil; +} + +- (NSString *) rightButtonTitle { + return [[list_ table] isRowDeletionEnabled] ? @"Done" : @"Edit"; +} + +- (RVUINavBarButtonStyle) rightButtonStyle { + return [[list_ table] isRowDeletionEnabled] ? RVUINavBarButtonStyleHighlighted : RVUINavBarButtonStyleNormal; +} + +@end +/* }}} */ + +/* Installed View {{{ */ +@interface InstalledView : RVPage { + _transient Database *database_; + PackageTable *packages_; +} + +- (id) initWithBook:(RVBook *)book database:(Database *)database; + +@end + +@implementation InstalledView + +- (void) dealloc { + [packages_ release]; + [super dealloc]; +} + +- (id) initWithBook:(RVBook *)book database:(Database *)database { + if ((self = [super initWithBook:book]) != nil) { + database_ = database; + + packages_ = [[PackageTable alloc] + initWithBook:book + database:database + title:nil + filter:@selector(isInstalledInSection:) + with:nil + ]; + + [self addSubview:packages_]; + } return self; +} + +- (void) resetViewAnimated:(BOOL)animated { + [packages_ resetViewAnimated:animated]; +} + +- (void) reloadData { + [packages_ reloadData]; +} + +- (NSString *) title { + return @"Installed Packages"; +} + +- (NSString *) backButtonTitle { + return @"Packages"; +} + +- (void) setDelegate:(id)delegate { + [super setDelegate:delegate]; + [packages_ setDelegate:delegate]; +} + +@end +/* }}} */ + +@interface HomeView : BrowserView { +} + +@end + +@implementation HomeView + +- (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button { + [sheet dismiss]; +} + +- (void) _leftButtonClicked { + UIAlertSheet *sheet = [[[UIAlertSheet alloc] + initWithTitle:@"About Cydia Installer" + buttons:[NSArray arrayWithObjects:@"Close", nil] + defaultButtonIndex:0 + delegate:self + context:@"about" + ] autorelease]; + + [sheet setBodyText: + @"Copyright (C) 2008\n" + "Jay Freeman (saurik)\n" + "saurik@saurik.com\n" + "http://www.saurik.com/\n" + "\n" + "The Okori Group\n" + "http://www.theokorigroup.com/\n" + "\n" + "College of Creative Studies,\n" + "University of California,\n" + "Santa Barbara\n" + "http://www.ccs.ucsb.edu/" + ]; + + [sheet popupAlertAnimated:YES]; +} + +- (NSString *) leftButtonTitle { + return @"About"; +} + +@end + +@interface ManageView : BrowserView { +} + +@end + +@implementation ManageView + +- (NSString *) title { + return @"Manage"; +} + +- (void) _leftButtonClicked { + [delegate_ askForSettings]; +} + +- (NSString *) leftButtonTitle { + return @"Settings"; +} + +- (NSString *) rightButtonTitle { + return nil; +} + +@end + /* Browser Implementation {{{ */ @implementation BrowserView @@ -3671,27 +4384,28 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); } - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy { - NSMutableURLRequest *request = [NSMutableURLRequest + [self loadRequest:[NSURLRequest requestWithURL:url cachePolicy:policy timeoutInterval:30.0 - ]; - - [request addValue:[NSString stringWithUTF8String:Firmware_] forHTTPHeaderField:@"X-Firmware"]; - [request addValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; - [request addValue:[NSString stringWithUTF8String:SerialNumber_] forHTTPHeaderField:@"X-Serial-Number"]; - - [self loadRequest:request]; + ]]; } - - (void) loadURL:(NSURL *)url { [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy]; } -// XXX: this needs to add the headers - (NSURLRequest *) _addHeadersToRequest:(NSURLRequest *)request { - return request; + NSMutableURLRequest *copy = [request mutableCopy]; + + [copy addValue:[NSString stringWithUTF8String:Firmware_] forHTTPHeaderField:@"X-Firmware"]; + [copy addValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; + [copy addValue:[NSString stringWithUTF8String:SerialNumber_] forHTTPHeaderField:@"X-Serial-Number"]; + + if (Role_ != nil) + [copy addValue:Role_ forHTTPHeaderField:@"X-Role"]; + + return copy; } - (void) loadRequest:(NSURLRequest *)request { @@ -3717,6 +4431,26 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [self view:sender didSetFrame:frame]; } +- (void) pushPage:(RVPage *)page { + [self setBackButtonTitle:title_]; + [page setDelegate:delegate_]; + [book_ pushPage:page]; +} + +- (void) getCydia:(NSString *)href { + RVPage *page = nil; + + if ([href isEqualToString:@"cydia://add-source"]) + page = [[[AddSourceView alloc] initWithBook:book_ database:database_] autorelease]; + else if ([href isEqualToString:@"cydia://sources"]) + page = [[[SourceTable alloc] initWithBook:book_ database:database_] autorelease]; + else if ([href isEqualToString:@"cydia://packages"]) + page = [[[InstalledView alloc] initWithBook:book_ database:database_] autorelease]; + + if (page != nil) + [self pushPage:page]; +} + - (void) getAppTapp:(NSString *)href { if ([href hasPrefix:@"apptapp://package/"]) { NSString *name = [href substringFromIndex:18]; @@ -3736,31 +4470,42 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [sheet popupAlertAnimated:YES]; } else { - [self setBackButtonTitle:title_]; PackageView *view = [[[PackageView alloc] initWithBook:book_ database:database_] autorelease]; - [view setDelegate:delegate_]; [view setPackage:package]; - [book_ pushPage:view]; + [self pushPage:view]; } } } - (void) webView:(WebView *)sender willClickElement:(id)element { + if ([[element localName] isEqualToString:@"img"]) + do if ((element = [element parentNode]) == nil) + return; + while (![[element localName] isEqualToString:@"a"]); if (![element respondsToSelector:@selector(href)]) return; NSString *href = [element href]; if (href == nil) return; - if ([href hasPrefix:@"apptapp://package/"]) + if ([href hasPrefix:@"cydia://"]) + [self getCydia:href]; + if ([href hasPrefix:@"apptapp://"]) [self getAppTapp:href]; } - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource { - if ([[[request URL] scheme] isEqualToString:@"apptapp"]) { + NSString *scheme = [[request URL] scheme]; + + if ([scheme isEqualToString:@"apptapp"]) { [self getAppTapp:[[request URL] absoluteString]]; return nil; } + if ([scheme isEqualToString:@"cydia"]) { + [self getCydia:[[request URL] absoluteString]]; + return nil; + } + if (!pushed_) { pushed_ = true; [book_ pushPage:self]; @@ -3770,21 +4515,27 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); } - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request { - if (request != nil && [[[request URL] scheme] isEqualToString:@"apptapp"]) - return nil; - else { - [self setBackButtonTitle:title_]; + if (request != nil) { + NSString *scheme = [[request URL] scheme]; - BrowserView *browser = [[[BrowserView alloc] initWithBook:book_ database:database_] autorelease]; - [browser setDelegate:delegate_]; + if ( + [scheme isEqualToString:@"apptapp"] || + [scheme isEqualToString:@"cydia"] + ) + return nil; + } - if (request != nil) { - [browser loadRequest:[self _addHeadersToRequest:request]]; - [book_ pushPage:browser]; - } + [self setBackButtonTitle:title_]; - return [browser webView]; + BrowserView *browser = [[[BrowserView alloc] initWithBook:book_ database:database_] autorelease]; + [browser setDelegate:delegate_]; + + if (request != nil) { + [browser loadRequest:[self _addHeadersToRequest:request]]; + [book_ pushPage:browser]; } + + return [browser webView]; } - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { @@ -3835,8 +4586,9 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); if ([frame parentFrame] != nil) return; [self _finishLoading]; + [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", - [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"home" ofType:@"html"]] absoluteString], + [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString], [[error localizedDescription] stringByAddingPercentEscapes] ]]]; } @@ -3894,46 +4646,11 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); } return self; } -- (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button { - [sheet dismiss]; -} - -- (void) _leftButtonClicked { - UIAlertSheet *sheet = [[[UIAlertSheet alloc] - initWithTitle:@"About Cydia Installer" - buttons:[NSArray arrayWithObjects:@"Close", nil] - defaultButtonIndex:0 - delegate:self - context:@"about" - ] autorelease]; - - [sheet setBodyText: - @"Copyright (C) 2008\n" - "Jay Freeman (saurik)\n" - "saurik@saurik.com\n" - "http://www.saurik.com/\n" - "\n" - "The Okori Group\n" - "http://www.theokorigroup.com/\n" - "\n" - "College of Creative Studies,\n" - "University of California,\n" - "Santa Barbara\n" - "http://www.ccs.ucsb.edu/" - ]; - - [sheet popupAlertAnimated:YES]; -} - - (void) _rightButtonClicked { reloading_ = true; [self reloadURL]; } -- (NSString *) leftButtonTitle { - return @"About"; -} - - (NSString *) rightButtonTitle { return loading_ ? @"" : @"Reload"; } @@ -3980,235 +4697,6 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); @end -/* Source Cell {{{ */ -@interface SourceCell : UITableCell { - UITextLabel *description_; - UIRightTextLabel *label_; - UITextLabel *origin_; -} - -- (void) dealloc; - -- (SourceCell *) initWithSource:(Source *)source; - -- (void) _setSelected:(float)fraction; -- (void) setSelected:(BOOL)selected; -- (void) setSelected:(BOOL)selected withFade:(BOOL)fade; -- (void) _setSelectionFadeFraction:(float)fraction; - -@end - -@implementation SourceCell - -- (void) dealloc { - [description_ release]; - [label_ release]; - [origin_ release]; - [super dealloc]; -} - -- (SourceCell *) initWithSource:(Source *)source { - if ((self = [super init]) != nil) { - GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 20); - GSFontRef small = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 14); - - CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); - float clear[] = {0, 0, 0, 0}; - - NSString *description = [source description]; - if (description == nil) - description = [source uri]; - - description_ = [[UITextLabel alloc] initWithFrame:CGRectMake(12, 7, 270, 25)]; - [description_ setBackgroundColor:CGColorCreate(space, clear)]; - [description_ setFont:bold]; - [description_ setText:description]; - - NSString *label = [source label]; - if (label == nil) - label = [source type]; - - label_ = [[UIRightTextLabel alloc] initWithFrame:CGRectMake(290, 32, 90, 25)]; - [label_ setBackgroundColor:CGColorCreate(space, clear)]; - [label_ setFont:small]; - [label_ setText:label]; - - NSString *origin = [source origin]; - if (origin == nil) - origin = [source distribution]; - - origin_ = [[UITextLabel alloc] initWithFrame:CGRectMake(13, 35, 315, 20)]; - [origin_ setBackgroundColor:CGColorCreate(space, clear)]; - [origin_ setFont:small]; - [origin_ setText:origin]; - - [self addSubview:description_]; - [self addSubview:label_]; - [self addSubview:origin_]; - - CFRelease(small); - CFRelease(bold); - } return self; -} - -- (void) _setSelected:(float)fraction { - CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); - - float black[] = { - Interpolate(0.0, 1.0, fraction), - Interpolate(0.0, 1.0, fraction), - Interpolate(0.0, 1.0, fraction), - 1.0}; - - float blue[] = { - Interpolate(0.2, 1.0, fraction), - Interpolate(0.2, 1.0, fraction), - Interpolate(1.0, 1.0, fraction), - 1.0}; - - float gray[] = { - Interpolate(0.4, 1.0, fraction), - Interpolate(0.4, 1.0, fraction), - Interpolate(0.4, 1.0, fraction), - 1.0}; - - [description_ setColor:CGColorCreate(space, black)]; - [label_ setColor:CGColorCreate(space, blue)]; - [origin_ setColor:CGColorCreate(space, gray)]; -} - -- (void) setSelected:(BOOL)selected { - [self _setSelected:(selected ? 1.0 : 0.0)]; - [super setSelected:selected]; -} - -- (void) setSelected:(BOOL)selected withFade:(BOOL)fade { - if (!fade) - [self _setSelected:(selected ? 1.0 : 0.0)]; - [super setSelected:selected withFade:fade]; -} - -- (void) _setSelectionFadeFraction:(float)fraction { - [self _setSelected:fraction]; - [super _setSelectionFadeFraction:fraction]; -} - -@end -/* }}} */ -/* Source Table {{{ */ -@interface SourceTable : RVPage { - _transient Database *database_; - UISectionList *list_; - NSMutableArray *sources_; - UIAlertSheet *alert_; -} - -- (id) initWithBook:(RVBook *)book database:(Database *)database; - -@end - -@implementation SourceTable - -- (void) dealloc { - [list_ setDataSource:nil]; - - if (sources_ != nil) - [sources_ release]; - [list_ release]; - [super dealloc]; -} - -- (int) numberOfSectionsInSectionList:(UISectionList *)list { - return 1; -} - -- (NSString *) sectionList:(UISectionList *)list titleForSection:(int)section { - return @"Sources"; -} - -- (int) sectionList:(UISectionList *)list rowForSection:(int)section { - return 0; -} - -- (int) numberOfRowsInTable:(UITable *)table { - return [sources_ count]; -} - -- (float) table:(UITable *)table heightForRow:(int)row { - return 64; -} - -- (UITableCell *) table:(UITable *)table cellForRow:(int)row column:(UITableColumn *)col { - return [[[SourceCell alloc] initWithSource:[sources_ objectAtIndex:row]] autorelease]; -} - -- (BOOL) table:(UITable *)table showDisclosureForRow:(int)row { - return NO; -} - -- (void) tableRowSelected:(NSNotification*)notification { - UITable *table([list_ table]); - int row([table selectedRow]); - if (row == INT_MAX) - return; - - [table selectRow:-1 byExtendingSelection:NO withFade:YES]; -} - -- (id) initWithBook:(RVBook *)book database:(Database *)database { - if ((self = [super initWithBook:book]) != nil) { - database_ = database; - sources_ = nil; - - list_ = [[UISectionList alloc] initWithFrame:[self bounds]]; - - [self addSubview:list_]; - - [list_ setDataSource:self]; - [list_ setShouldHideHeaderInShortLists:NO]; - - UITableColumn *column = [[UITableColumn alloc] - initWithTitle:@"Name" - identifier:@"name" - width:[self frame].size.width - ]; - - UITable *table = [list_ table]; - [table setSeparatorStyle:1]; - [table addTableColumn:column]; - [table setDelegate:self]; - } return self; -} - -- (void) reloadData { - pkgSourceList list; - _assert(list.ReadMainList()); - - if (sources_ != nil) - [sources_ release]; - - sources_ = [[NSMutableArray arrayWithCapacity:16] retain]; - for (pkgSourceList::const_iterator source = list.begin(); source != list.end(); ++source) - [sources_ addObject:[[[Source alloc] initWithMetaIndex:*source] autorelease]]; - - [list_ reloadData]; -} - -- (void) resetViewAnimated:(BOOL)animated { - [list_ resetViewAnimated:animated]; -} - -- (NSString *) leftTitle { - return @"Refresh All"; -} - -- (NSString *) rightTitle { - return @"Edit"; -} - -@end -/* }}} */ - /* Install View {{{ */ @interface InstallView : RVPage { _transient Database *database_; @@ -4295,7 +4783,7 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); initWithBook:book_ database:database_ title:title - filter:@selector(isUninstalledInSection:) + filter:@selector(isVisiblyUninstalledInSection:) with:name ] autorelease]; @@ -4614,72 +5102,6 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); @end /* }}} */ -/* Manage View {{{ */ -@interface ManageView : RVPage { - _transient Database *database_; - PackageTable *packages_; - SourceTable *sources_; -} - -- (id) initWithBook:(RVBook *)book database:(Database *)database; - -@end - -@implementation ManageView - -- (void) dealloc { - [packages_ release]; - [sources_ release]; - [super dealloc]; -} - -- (id) initWithBook:(RVBook *)book database:(Database *)database { - if ((self = [super initWithBook:book]) != nil) { - database_ = database; - - packages_ = [[PackageTable alloc] - initWithBook:book - database:database - title:nil - filter:@selector(isInstalledInSection:) - with:nil - ]; - - sources_ = [[SourceTable alloc] - initWithBook:book - database:database - ]; - - [self addSubview:packages_]; - } return self; -} - -- (void) resetViewAnimated:(BOOL)animated { - [packages_ resetViewAnimated:animated]; - [sources_ resetViewAnimated:animated]; -} - -- (void) reloadData { - [packages_ reloadData]; - [sources_ reloadData]; -} - -- (NSString *) title { - return @"Installed Packages"; -} - -- (NSString *) backButtonTitle { - return @"Packages"; -} - -- (void) setDelegate:(id)delegate { - [super setDelegate:delegate]; - [packages_ setDelegate:delegate]; - [sources_ setDelegate:delegate]; -} - -@end -/* }}} */ /* Search View {{{ */ @protocol SearchViewDelegate - (void) showKeyboard:(BOOL)show; @@ -4833,7 +5255,7 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); initWithBook:book database:database title:nil - filter:@selector(isSearchedForBy:) + filter:@selector(isVisiblySearchedForBy:) with:nil ]; @@ -5183,16 +5605,6 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [database_ reloadData]; - if (Packages_ == nil) { - Packages_ = [[NSMutableDictionary alloc] initWithCapacity:128]; - [Metadata_ setObject:Packages_ forKey:@"Packages"]; - } - - if (Sections_ == nil) { - Sections_ = [[NSMutableDictionary alloc] initWithCapacity:32]; - [Metadata_ setObject:Sections_ forKey:@"Sections"]; - } - size_t changes(0); [essential_ removeAllObjects]; @@ -5237,25 +5649,60 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [hud removeFromSuperview];*/ } -- (void) updateData { +- (void) _saveConfig { if (Changed_) { _assert([Metadata_ writeToFile:@"/var/lib/cydia/metadata.plist" atomically:YES] == YES); Changed_ = false; } +} + +- (void) updateData { + [self _saveConfig]; /* XXX: this is just stupid */ if (tag_ != 2) [install_ reloadData]; if (tag_ != 3) [changes_ reloadData]; - if (tag_ != 4) - [manage_ reloadData]; if (tag_ != 5) [search_ reloadData]; [book_ reloadData]; } +- (void) update_ { + [database_ update]; +} + +- (void) syncData { + FILE *file = fopen("/etc/apt/sources.list.d/cydia.list", "w"); + _assert(file != NULL); + + NSArray *keys = [Sources_ allKeys]; + + for (int i(0), e([keys count]); i != e; ++i) { + NSString *key = [keys objectAtIndex:i]; + NSDictionary *source = [Sources_ objectForKey:key]; + + fprintf(file, "%s %s %s\n", + [[source objectForKey:@"Type"] UTF8String], + [[source objectForKey:@"URI"] UTF8String], + [[source objectForKey:@"Distribution"] UTF8String] + ); + } + + fclose(file); + + [self _saveConfig]; + + [progress_ + detachNewThreadSelector:@selector(update_) + toTarget:self + withObject:nil + title:@"Updating Sources..." + ]; +} + - (void) reloadData { @synchronized (self) { if (confirm_ == nil) @@ -5373,74 +5820,22 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); } } -- (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button { - NSString *context = [sheet context]; - if ([context isEqualToString:@"fixhalf"]) - switch (button) { - case 1: - @synchronized (self) { - for (int i = 0, e = [broken_ count]; i != e; ++i) { - Package *broken = [broken_ objectAtIndex:i]; - [broken remove]; - - NSString *id = [broken id]; - unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.prerm", id] UTF8String]); - unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postrm", id] UTF8String]); - unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.preinst", id] UTF8String]); - unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postinst", id] UTF8String]); - } - - [self resolve]; - [self perform]; - } - break; - - case 2: - [broken_ removeAllObjects]; - [self _loaded]; - break; - - default: - _assert(false); - } - else if ([context isEqualToString:@"upgrade"]) - switch (button) { - case 1: - @synchronized (self) { - for (int i = 0, e = [essential_ count]; i != e; ++i) { - Package *essential = [essential_ objectAtIndex:i]; - [essential install]; - } - - [self resolve]; - [self perform]; - } - break; - - case 2: - Ignored_ = YES; - break; - - default: - _assert(false); - } - - [sheet dismiss]; -} - - (void) setPage:(RVPage *)page { [page resetViewAnimated:NO]; [page setDelegate:self]; [book_ setPage:page]; } -- (RVPage *) _setHomePage { - BrowserView *browser = [[[BrowserView alloc] initWithBook:book_ database:database_] autorelease]; - [self setPage:browser]; - [browser loadURL:[NSURL URLWithString:@"http://cydia.saurik.com/"]]; +- (RVPage *) _pageForURL:(NSURL *)url withClass:(Class)_class { + BrowserView *browser = [[[_class alloc] initWithBook:book_ database:database_] autorelease]; + [browser loadURL:url]; return browser; } +- (void) _setHomePage { + [self setPage:[self _pageForURL:[NSURL URLWithString:@"http://cydia.saurik.com/"] withClass:[HomeView class]]]; +} + - (void) buttonBarItemTapped:(id)sender { unsigned tag = [sender tag]; if (tag == tag_) { @@ -5494,6 +5889,23 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [super applicationWillSuspend]; } +- (void) askForSettings { + UIAlertSheet *role = [[[UIAlertSheet alloc] + initWithTitle:@"Who Are You?" + buttons:[NSArray arrayWithObjects: + @"User (Graphical Only)", + @"Hacker (Command Line)", + @"Developer (No Filters)", + nil] + defaultButtonIndex:-1 + delegate:self + context:@"role" + ] autorelease]; + + [role setBodyText:@"Not all of the packages available via Cydia are designed to be used by all users. Please categorize yourself so that Cydia can apply helpful filters.\n\nThis choice can be changed from \"Settings\" under the \"Manage\" tab."]; + [role popupAlertAnimated:YES]; +} + - (void) finish { if (hud_ != nil) { [self setStatusBarShowsProgress:NO]; @@ -5512,6 +5924,11 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); return; } + if (Role_ == nil) { + [self askForSettings]; + return; + } + overlay_ = [[UIView alloc] initWithFrame:[underlay_ bounds]]; CGRect screenrect = [UIHardware fullScreenApplicationContentRect]; @@ -5609,9 +6026,13 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); install_ = [[InstallView alloc] initWithBook:book_ database:database_]; changes_ = [[ChangesView alloc] initWithBook:book_ database:database_]; - manage_ = [[ManageView alloc] initWithBook:book_ database:database_]; search_ = [[SearchView alloc] initWithBook:book_ database:database_]; + manage_ = (ManageView *) [[self + _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]] + withClass:[ManageView class] + ] retain]; + if (!bootstrap_) [underlay_ addSubview:overlay_]; @@ -5623,6 +6044,86 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [self _setHomePage]; } +- (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button { + NSString *context = [sheet context]; + if ([context isEqualToString:@"fixhalf"]) + switch (button) { + case 1: + @synchronized (self) { + for (int i = 0, e = [broken_ count]; i != e; ++i) { + Package *broken = [broken_ objectAtIndex:i]; + [broken remove]; + + NSString *id = [broken id]; + unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.prerm", id] UTF8String]); + unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postrm", id] UTF8String]); + unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.preinst", id] UTF8String]); + unlink([[NSString stringWithFormat:@"/var/lib/dpkg/info/%@.postinst", id] UTF8String]); + } + + [self resolve]; + [self perform]; + } + break; + + case 2: + [broken_ removeAllObjects]; + [self _loaded]; + break; + + default: + _assert(false); + } + else if ([context isEqualToString:@"role"]) { + switch (button) { + case 1: Role_ = @"User"; break; + case 2: Role_ = @"Hacker"; break; + case 3: Role_ = @"Developer"; break; + + default: + Role_ = nil; + _assert(false); + } + + bool reset = Settings_ != nil; + + Settings_ = [NSMutableDictionary dictionaryWithObjectsAndKeys: + Role_, @"Role", + nil]; + + [Metadata_ setObject:Settings_ forKey:@"Settings"]; + + Changed_ = true; + + if (reset) + [self updateData]; + else + [self finish]; + } else if ([context isEqualToString:@"upgrade"]) + switch (button) { + case 1: + @synchronized (self) { + for (int i = 0, e = [essential_ count]; i != e; ++i) { + Package *essential = [essential_ objectAtIndex:i]; + [essential install]; + } + + [self resolve]; + [self perform]; + } + break; + + case 2: + Ignored_ = YES; + break; + + default: + _assert(false); + } + + [sheet dismiss]; +} + - (void) reorganize { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; system("/usr/libexec/cydia/free.sh"); @@ -5645,6 +6146,13 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); [super _setSuspended:value]; } +- (UIProgressHUD *) addProgressHUD { + UIProgressHUD *hud = [[UIProgressHUD alloc] initWithWindow:window_]; + [hud show:YES]; + [underlay_ addSubview:hud]; + return hud; +} + - (void) applicationDidFinishLaunching:(id)unused { _assert(pkgInitConfig(*_config)); _assert(pkgInitSystem(*_config, _system)); @@ -5682,10 +6190,8 @@ Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); ) { [self setIdleTimerDisabled:YES]; - hud_ = [[UIProgressHUD alloc] initWithWindow:window_]; + hud_ = [self addProgressHUD]; [hud_ setText:@"Reorganizing\n\nWill Automatically\nRestart When Done"]; - [hud_ show:YES]; - [underlay_ addSubview:hud_]; [self setStatusBarShowsProgress:YES]; @@ -5851,8 +6357,29 @@ int main(int argc, char *argv[]) { if ((Metadata_ = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"]) == NULL) Metadata_ = [[NSMutableDictionary alloc] initWithCapacity:2]; else { + Settings_ = [Metadata_ objectForKey:@"Settings"]; + Packages_ = [Metadata_ objectForKey:@"Packages"]; Sections_ = [Metadata_ objectForKey:@"Sections"]; + Sources_ = [Metadata_ objectForKey:@"Sources"]; + } + + if (Settings_ != nil) + Role_ = [Settings_ objectForKey:@"Role"]; + + if (Packages_ == nil) { + Packages_ = [[[NSMutableDictionary alloc] initWithCapacity:128] autorelease]; + [Metadata_ setObject:Packages_ forKey:@"Packages"]; + } + + if (Sections_ == nil) { + Sections_ = [[[NSMutableDictionary alloc] initWithCapacity:32] autorelease]; + [Metadata_ setObject:Sections_ forKey:@"Sections"]; + } + + if (Sources_ == nil) { + Sources_ = [[[NSMutableDictionary alloc] initWithCapacity:0] autorelease]; + [Metadata_ setObject:Sources_ forKey:@"Sources"]; } if (access("/User", F_OK) != 0) @@ -5866,6 +6393,22 @@ int main(int argc, char *argv[]) { Clear_.Set(space_, 0.0, 0.0, 0.0, 0.0); Red_.Set(space_, 1.0, 0.0, 0.0, 1.0); White_.Set(space_, 1.0, 1.0, 1.0, 1.0); + Gray_.Set(space_, 0.4, 0.4, 0.4, 1.0); + + SectionMap_ = [NSMutableDictionary dictionaryWithCapacity:16]; { + std::ifstream fin([[[NSBundle mainBundle] pathForResource:@"sections" ofType:@"txt"] UTF8String]); + std::string line; + while (std::getline(fin, line)) { + size_t space = line.find_first_of(' '); + if (space == std::string::npos) + continue; + [SectionMap_ + setObject:[NSString stringWithUTF8String:line.substr(space + 1).c_str()] + forKey:[NSString stringWithUTF8String:line.substr(0, space).c_str()] + ]; + } + } + int value = UIApplicationMain(argc, argv, [Cydia class]); diff --git a/UICaboodle/RVBook.mm b/UICaboodle/RVBook.mm index ccd3e42..d83d760 100644 --- a/UICaboodle/RVBook.mm +++ b/UICaboodle/RVBook.mm @@ -172,8 +172,17 @@ - (void) reloadButtonsForPage:(RVPage *)page { if ([pages_ count] == 0 || page != [pages_ lastObject]) return; - NSString *leftButtonTitle([pages_ count] == 1 ? [page leftButtonTitle] : nil); - [navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle]]; + NSString *leftButtonTitle([page leftButtonTitle]); + RVUINavBarButtonStyle leftButtonStyle = [page leftButtonStyle]; + RVUINavBarButtonStyle rightButtonStyle = [page rightButtonStyle]; + //[navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle] leftBack:(leftButtonTitle == nil)]; + + [navbar_ + showLeftButton:leftButtonTitle + withStyle:leftButtonStyle + rightButton:[page rightButtonTitle] + withStyle:rightButtonStyle + ]; } - (NSString *) getTitleForPage:(RVPage *)page { diff --git a/UICaboodle/RVPage.h b/UICaboodle/RVPage.h index 5065dd2..8b0a2e4 100644 --- a/UICaboodle/RVPage.h +++ b/UICaboodle/RVPage.h @@ -2,6 +2,13 @@ #import <UIKit/UIView.h> +enum RVUINavBarButtonStyle { + RVUINavBarButtonStyleNormal, + RVUINavBarButtonStyleBack, + RVUINavBarButtonStyleHighlighted, + RVUINavBarButtonStyleDestructive +}; + @class NSString; @class RVBook; @@ -16,6 +23,9 @@ - (NSString *) leftButtonTitle; - (UIView *) accessoryView; +- (RVUINavBarButtonStyle) leftButtonStyle; +- (RVUINavBarButtonStyle) rightButtonStyle; + - (void) _rightButtonClicked; - (void) _leftButtonClicked; diff --git a/UICaboodle/RVPage.mm b/UICaboodle/RVPage.mm index a92058e..ee85a7e 100644 --- a/UICaboodle/RVPage.mm +++ b/UICaboodle/RVPage.mm @@ -24,6 +24,14 @@ return nil; } +- (RVUINavBarButtonStyle) leftButtonStyle { + return [self leftButtonTitle] == nil ? RVUINavBarButtonStyleBack : RVUINavBarButtonStyleNormal; +} + +- (RVUINavBarButtonStyle) rightButtonStyle { + return RVUINavBarButtonStyleNormal; +} + - (void) _rightButtonClicked { [self doesNotRecognizeSelector:_cmd]; } @@ -19,7 +19,7 @@ exec: exec.mm makefile $(target)g++ -Wall -Werror -o $@ $< -framework Foundation -framework CoreFoundation -lobjc Cydia: Cydia.mm ../uicaboodle.m/*.mm *.h makefile - $(target)g++ -I../uicaboodle.m -fobjc-call-cxx-cdtors -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework IOKit -framework CoreFoundation -framework Foundation -framework CoreGraphics -framework GraphicsServices $(frameworks) -lobjc -lapt-pkg -lpcre -fobjc-exceptions -I/apl/i20 -F"$${PKG_ROOT}"/System/Library/PrivateFrameworks + $(target)g++ -march=armv6 -mcpu=arm1176jzf-s -I../uicaboodle.m -fobjc-call-cxx-cdtors -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework IOKit -framework CoreFoundation -framework Foundation -framework CoreGraphics -framework GraphicsServices $(frameworks) -lobjc -lapt-pkg -lpcre -fobjc-exceptions -I/apl/i20 -F"$${PKG_ROOT}"/System/Library/PrivateFrameworks sign: Cydia CODESIGN_ALLOCATE=$$(which "$(target)codesign_allocate") /apl/tel/util/ldid -S Cydia |