X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/2e6c1426b817fe8236e916ef74646b9e358173fd..fe9c8d24cf66dbdc80b36349552213c13b67bf5d:/Cydia.mm diff --git a/Cydia.mm b/Cydia.mm index 02c2ae9a..efbb9b83 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -41,14 +41,13 @@ #define USE_SYSTEM_MALLOC 1 /* #include Directives {{{ */ -#import "UICaboodle/UCPlatform.h" -#import "UICaboodle/UCLocalize.h" +#include "UICaboodle/UCPlatform.h" +#include "UICaboodle/UCLocalize.h" #include #include #include -#include #include #if 0 @@ -60,10 +59,12 @@ #include #include -#import +#include +#include "iPhonePrivate.h" + +#include #include -#import #include #include @@ -100,6 +101,7 @@ #include #include +#include #include #include @@ -116,53 +118,13 @@ extern "C" { #include -#import "UICaboodle/BrowserView.h" -#import "UICaboodle/ResetView.h" +#include "UICaboodle/BrowserView.h" +#include "UICaboodle/ResetView.h" -#import "substrate.h" +#include "substrate.h" // Apple's sample Reachability code, ASPL licensed. -#import "Reachability.h" -/* }}} */ - -/* Header Fixes and Updates {{{ */ -typedef enum { - UIModalPresentationFullScreen = 0, - UIModalPresentationPageSheet, - UIModalPresentationFormSheet, - UIModalPresentationCurrentContext, -} UIModalPresentationStyle; - -@interface UIAlertView (Private) -- (void)setNumberOfRows:(int)rows; -- (void)setContext:(id)context; -- (id)context; -@end - -@interface UIViewController (UIKit) -- (id)navigationItem; -- (id)navigationController; -- (id)tabBarItem; -@end - -@interface UITabBarController : UIViewController { - id _tabBar; - id _containerView; - id _viewControllerTransitionView; - id _viewControllers; - id _tabBarItemsToViewControllers; - id _selectedViewController; - id _moreNavigationController; - id _customizableViewControllers; - id _delegate; - id _selectedViewControllerDuringWillAppear; - id _transientViewController; - unsigned int isShowingMoreItem:1; - unsigned int needsToRebuildItems:1; - unsigned int isBarHidden:1; - unsigned int editButtonOnLeft:1; -} -@end +#include "Reachability.h" /* }}} */ /* Profiler {{{ */ @@ -257,6 +219,15 @@ static _finline NSString *CydiaURL(NSString *path) { return [[NSString stringWithUTF8String:page] stringByAppendingString:path]; } +static _finline void UpdateExternalStatus(uint64_t newStatus) { + int notify_token; + if (notify_register_check("com.saurik.Cydia.status", ¬ify_token) == NOTIFY_STATUS_OK) { + notify_set_state(notify_token, newStatus); + notify_cancel(notify_token); + } + notify_post("com.saurik.Cydia.status"); +} + /* [NSObject yieldToSelector:(withObject:)] {{{*/ @interface NSObject (Cydia) - (id) yieldToSelector:(SEL)selector withObject:(id)object; @@ -675,10 +646,6 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s return length; } -@interface NSString (UIKit) -- (NSString *) stringByAddingPercentEscapes; -@end - /* Cydia NSString Additions {{{ */ @interface NSString (Cydia) + (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length; @@ -1239,13 +1206,15 @@ bool isSectionVisible(NSString *section) { - (void) installPackage:(Package *)package; - (void) installPackages:(NSArray *)packages; - (void) removePackage:(Package *)package; +- (void) beginUpdate; +- (BOOL) updating; - (void) distUpgrade; - (void) updateData; - (void) syncData; -- (void) askForSettings; +- (void) showSettings; - (UIProgressHUD *) addProgressHUD; - (void) removeProgressHUD:(UIProgressHUD *)hud; -- (UIViewController *) pageForPackage:(NSString *)name; +- (UCViewController *) pageForPackage:(NSString *)name; - (PackageController *) packageController; @end /* }}} */ @@ -1437,7 +1406,7 @@ typedef std::map< unsigned long, _H > SourceMap; @end /* }}} */ /* Delegate Helpers {{{ */ -@implementation NSObject(ProgressDelegate) +@implementation NSObject (ProgressDelegate) - (void) _setProgressErrorPackage:(NSArray *)args { [self performSelector:@selector(setProgressError:forPackage:) @@ -1463,7 +1432,7 @@ typedef std::map< unsigned long, _H > SourceMap; - (void) setProgressError:(NSString *)error forPackage:(NSString *)id { Package *package = id == nil ? nil : [[Database sharedInstance] packageWithName:id]; // XXX: holy typecast batman! - [self setProgressError:error withTitle:(package == nil ? id : [package name])]; + [(id)self setProgressError:error withTitle:(package == nil ? id : [package name])]; } @end @@ -3964,7 +3933,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (id) init { - if ((self = [super initWithWidth:[[self view] bounds].size.width ofClass:[CYBrowserController class]]) != nil) { + if ((self = [super initWithWidth:0 ofClass:[CYBrowserController class]]) != nil) { cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_]; WebView *webview([document_ webView]); @@ -4020,22 +3989,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super dealloc]; } -- (void) actionSheet:(UIActionSheet *)sheet clickedButtonAtIndex:(NSInteger)button { - NSString *context([sheet context]); - - if ([context isEqualToString:@"cancel"]) { - bool clear; - - if (button == [sheet cancelButtonIndex]) return; - else if (button == [sheet destructiveButtonIndex]) clear = true; - else clear = false; - - [sheet dismissWithClickedButtonIndex:0xDEADBEEF animated:YES]; - [self dismissModalViewControllerAnimated:YES]; - [delegate_ cancelAndClear:clear]; - } -} - - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { NSString *context([alert context]); @@ -4057,11 +4010,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } +- (id) invokeDefaultMethodWithArguments:(NSArray *)args { + [self dismissModalViewControllerAnimated:YES]; + [delegate_ cancelAndClear:NO]; + + return nil; +} + - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { [super webView:sender didClearWindowObject:window forFrame:frame]; [window setValue:changes_ forKey:@"changes"]; [window setValue:issues_ forKey:@"issues"]; [window setValue:sizes_ forKey:@"sizes"]; + [window setValue:self forKey:@"queue"]; } - (id) initWithDatabase:(Database *)database { @@ -4152,7 +4113,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"confirm" ofType:@"html"]]]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] - initWithTitle:[NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("CANCEL"), UCLocalize("QUEUE")] + initWithTitle:UCLocalize("CANCEL") + // OLD: [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("CANCEL"), UCLocalize("QUEUE")] style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonClicked) @@ -4179,20 +4141,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) cancelButtonClicked { - UIActionSheet *sheet = [[UIActionSheet alloc] - initWithTitle:nil - delegate:self - cancelButtonTitle:nil - destructiveButtonTitle:nil - otherButtonTitles:nil - ]; - - [sheet addButtonWithTitle:UCLocalize("CANCEL_CLEAR")]; - [sheet setDestructiveButtonIndex:[sheet numberOfButtons] - 1]; - [sheet addButtonWithTitle:UCLocalize("CONTINUE_QUEUING")]; - [sheet setContext:@"cancel"]; - - [delegate_ showActionSheet:[sheet autorelease] fromItem:[[self navigationItem] leftBarButtonItem]]; + [self dismissModalViewControllerAnimated:YES]; + [delegate_ cancelAndClear:YES]; } #if !AlwaysReload @@ -4300,7 +4250,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [database_ setDelegate:self]; delegate_ = delegate; - [[self view] setBackgroundColor:(CGColor *)[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]]; + [[self view] setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]]; progress_ = [[UIProgressBar alloc] init]; [progress_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin)]; @@ -4374,7 +4324,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) viewWillAppear:(BOOL)animated { [super viewDidAppear:animated]; [[self navigationItem] setHidesBackButton:YES]; - [[[self navigationController] navigationBar] setBarStyle:1]; + [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlack]; [self positionViews]; } @@ -4397,6 +4347,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) closeButtonPushed { running_ = NO; + UpdateExternalStatus(0); + switch (Finish_) { case 0: [self dismissModalViewControllerAnimated:YES]; @@ -4470,6 +4422,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { system("su -c /usr/bin/uicache mobile"); + UpdateExternalStatus(Finish_ == 0 ? 2 : 0); + [delegate_ setStatusBarShowsProgress:NO]; } @@ -4481,6 +4435,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)object title:(NSString *)title { + UpdateExternalStatus(1); + if (title_ != nil) [title_ release]; if (title == nil) @@ -4651,8 +4607,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Cell Content View {{{ */ +@protocol ContentDelegate +- (void) drawContentRect:(CGRect)rect; +@end + @interface ContentView : UIView { - _transient id delegate_; + _transient id delegate_; } @end @@ -4665,7 +4625,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } return self; } -- (void) setDelegate:(id)delegate { +- (void) setDelegate:(id)delegate { delegate_ = delegate; } @@ -4676,7 +4636,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Cell {{{ */ -@interface PackageCell : UITableViewCell { +@interface PackageCell : UITableViewCell < + ContentDelegate +> { UIImage *icon_; NSString *name_; NSString *description_; @@ -4891,7 +4853,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Section Cell {{{ */ -@interface SectionCell : UITableViewCell { +@interface SectionCell : UITableViewCell < + ContentDelegate +> { NSString *basic_; NSString *section_; NSString *name_; @@ -4902,7 +4866,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { BOOL editing_; } -- (id) init; - (void) setSection:(Section *)section editing:(BOOL)editing; @end @@ -4999,7 +4962,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [switch_ setOn:(isSectionVisible(basic_) ? 1 : 0) animated:NO]; } - [self setAccessoryType:editing ? 0 : 1 /*UITableViewCellAccessoryDisclosureIndicator*/]; + [self setAccessoryType:editing ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator]; [content_ setNeedsDisplay]; } @@ -5038,7 +5001,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* File Table {{{ */ -@interface FileTable : CYViewController { +@interface FileTable : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { _transient Database *database_; Package *package_; NSString *name_; @@ -5067,9 +5033,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return files_ == nil ? 0 : [files_ count]; } -- (float) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - return 24; -} +/*- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return 24.0f; +}*/ - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuseIdentifier = @"Cell"; @@ -5080,7 +5046,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [cell setFont:[UIFont systemFontOfSize:16]]; } [cell setText:[files_ objectAtIndex:indexPath.row]]; - [cell setSelectionStyle:0 /*UITableViewCellSelectionStyleNone*/]; + [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; return cell; } @@ -5094,6 +5060,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { files_ = [[NSMutableArray arrayWithCapacity:32] retain]; list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:24.0f]; [[self view] addSubview:list_]; [list_ setDataSource:self]; @@ -5208,8 +5176,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } [sheet dismissWithClickedButtonIndex:-1 animated:YES]; - } else { - [super alertSheet:sheet clickedButtonAtIndex:button]; } } @@ -5264,7 +5230,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) reloadButtonClicked { - // You don't reload a package view by clicking the button. + // Don't reload a package view by clicking the button. +} + +- (void) applyLoadingTitle { + // Don't show "Loading" as the title. Ever. } #endif @@ -5357,7 +5327,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Table {{{ */ -@interface PackageTable : UIView { +@interface PackageTable : UIView < + UITableViewDataSource, + UITableViewDelegate +> { _transient Database *database_; NSMutableArray *packages_; NSMutableArray *sections_; @@ -5421,7 +5394,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path { - PackageCell *cell([table dequeueReusableCellWithIdentifier:@"Package"]); + PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]); if (cell == nil) cell = [[[PackageCell alloc] init] autorelease]; [cell setPackage:[self packageAtIndexPath:path]]; @@ -5432,10 +5405,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; } -- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path { - return 73; +/*- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path { return [PackageCell heightForPackage:[self packageAtIndexPath:path]]; -} +}*/ - (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path { Package *package([self packageAtIndexPath:path]); @@ -5467,6 +5439,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { list_ = [[UITableView alloc] initWithFrame:[self bounds] style:UITableViewStylePlain]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:73.0f]; [self addSubview:list_]; [list_ setDataSource:self]; @@ -5695,7 +5668,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Source Cell {{{ */ -@interface SourceCell : UITableViewCell { +@interface SourceCell : UITableViewCell < + ContentDelegate +> { UIImage *icon_; NSString *origin_; NSString *description_; @@ -5789,7 +5764,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Source Table {{{ */ -@interface SourceTable : CYViewController { +@interface SourceTable : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { _transient Database *database_; UITableView *list_; NSMutableArray *sources_; @@ -5810,6 +5788,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) initWithDatabase:(Database *)database; +- (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated; + @end @implementation SourceTable @@ -5895,8 +5875,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return cell; } -- (int) tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath { - return 1; //UITableViewCellAccessoryDisclosureIndicator? +- (UITableViewCellAccessoryType) tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath { + return UITableViewCellAccessoryDisclosureIndicator; } - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { @@ -6218,6 +6198,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { ]; [[self navigationItem] setRightBarButtonItem:rightItem animated:animated]; [rightItem release]; + + if (IsWildcat_ && !editing) { + UIBarButtonItem *settingsItem = [[UIBarButtonItem alloc] + initWithTitle:UCLocalize("SETTINGS") + style:UIBarButtonItemStylePlain + target:self + action:@selector(settingsButtonClicked) + ]; + [[self navigationItem] setLeftBarButtonItem:settingsItem]; + [settingsItem release]; + } +} + +- (void) settingsButtonClicked { + [delegate_ showSettings]; } - (void) editButtonClicked { @@ -6236,6 +6231,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) initWithDatabase:(Database *)database; +- (void) updateRoleButton; +- (void) queueStatusDidChange; + @end @implementation InstalledController @@ -6367,6 +6365,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @interface ManageController : CYBrowserController { } +- (void) queueStatusDidChange; @end @implementation ManageController @@ -6389,20 +6388,23 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) settingsButtonClicked { - [delegate_ askForSettings]; - [delegate_ updateData]; + [delegate_ showSettings]; } #if !AlwaysReload - (void) queueButtonClicked { [delegate_ queue]; } -#endif -- (void) didFinishLoading { - [self queueStatusDidChange]; +- (void) applyLoadingTitle { + // No "Loading" title. } +- (void) applyRightButton { + // No right button. +} +#endif + - (void) queueStatusDidChange { #if !AlwaysReload if (!IsWildcat_ && Queuing_) { @@ -6477,10 +6479,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [self setTintColor:[UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1]]; - [self setBarStyle:1]; + [self setBarStyle:UIBarStyleBlack]; - int barstyle([self _barStyle:NO]); - bool ugly(barstyle == 0); + UIBarStyle barstyle([self _barStyle:NO]); + bool ugly(barstyle == UIBarStyleDefault); UIProgressIndicatorStyle style = ugly ? UIProgressIndicatorStyleMediumBrown : @@ -6536,6 +6538,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ +@class CYNavigationController; + /* Cydia Tab Bar Controller {{{ */ @interface CYTabBarController : UITabBarController { Database *database_; @@ -6551,7 +6555,7 @@ freeing the view controllers on tab change */ - (void) reloadData { size_t count([[self viewControllers] count]); for (size_t i(0); i != count; ++i) { - UIViewController *page([[self viewControllers] objectAtIndex:(count - i - 1)]); + CYNavigationController *page([[self viewControllers] objectAtIndex:(count - i - 1)]); [page reloadData]; } } @@ -6566,9 +6570,7 @@ freeing the view controllers on tab change */ /* }}} */ /* Cydia Navigation Controller {{{ */ -@interface CYNavigationController : UINavigationController < - ProgressDelegate -> { +@interface CYNavigationController : UINavigationController { _transient Database *database_; id delegate_; } @@ -6597,7 +6599,7 @@ freeing the view controllers on tab change */ - (void) reloadData { size_t count([[self viewControllers] count]); for (size_t i(0); i != count; ++i) { - UIViewController *page([[self viewControllers] objectAtIndex:(count - i - 1)]); + CYViewController *page([[self viewControllers] objectAtIndex:(count - i - 1)]); [page reloadData]; } } @@ -6716,7 +6718,10 @@ freeing the view controllers on tab change */ /* }}} */ /* Sections Controller {{{ */ -@interface SectionsController : CYViewController { +@interface SectionsController : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { _transient Database *database_; NSMutableArray *sections_; NSMutableArray *filtered_; @@ -6729,6 +6734,8 @@ freeing the view controllers on tab change */ - (void) reloadData; - (void) resetView; +- (void) editButtonClicked; + @end @implementation SectionsController @@ -6758,9 +6765,9 @@ freeing the view controllers on tab change */ return editing_ ? [sections_ count] : [filtered_ count] + 1; } -- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - return 45; -} +/*- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return 45.0f; +}*/ - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuseIdentifier = @"SectionCell"; @@ -6816,6 +6823,7 @@ freeing the view controllers on tab change */ list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:45.0f]; [[self view] addSubview:list_]; [list_ setDataSource:self]; @@ -6944,7 +6952,10 @@ freeing the view controllers on tab change */ @end /* }}} */ /* Changes Controller {{{ */ -@interface ChangesController : CYViewController { +@interface ChangesController : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { _transient Database *database_; NSMutableArray *packages_; NSMutableArray *sections_; @@ -7004,17 +7015,16 @@ freeing the view controllers on tab change */ } - (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path { - PackageCell *cell([table dequeueReusableCellWithIdentifier:@"Package"]); + PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]); if (cell == nil) cell = [[[PackageCell alloc] init] autorelease]; [cell setPackage:[self packageAtIndexPath:path]]; return cell; } -- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path { - return 73; +/*- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path { return [PackageCell heightForPackage:[self packageAtIndexPath:path]]; -} +}*/ - (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path { Package *package([self packageAtIndexPath:path]); @@ -7026,7 +7036,7 @@ freeing the view controllers on tab change */ } - (void) refreshButtonClicked { - [[UIApplication sharedApplication] beginUpdate]; + [delegate_ beginUpdate]; [[self navigationItem] setLeftBarButtonItem:nil]; } @@ -7046,6 +7056,7 @@ freeing the view controllers on tab change */ list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:73.0f]; [[self view] addSubview:list_]; [list_ setDataSource:self]; @@ -7164,15 +7175,17 @@ freeing the view controllers on tab change */ target:self action:@selector(refreshButtonClicked) ]; - if (![[UIApplication sharedApplication] updating]) [[self navigationItem] setLeftBarButtonItem:leftItem]; + if (![delegate_ updating]) [[self navigationItem] setLeftBarButtonItem:leftItem]; [leftItem release]; } @end /* }}} */ /* Search Controller {{{ */ -@interface SearchController : FilteredPackageController { - id search_; +@interface SearchController : FilteredPackageController < + UISearchBarDelegate +> { + UISearchBar *search_; } - (id) initWithDatabase:(Database *)database; @@ -7207,7 +7220,7 @@ freeing the view controllers on tab change */ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (!search_) { - search_ = [[objc_getClass("UISearchBar") alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)]; + search_ = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)]; [search_ layoutSubviews]; [search_ setPlaceholder:UCLocalize("SEARCH_EX")]; UITextField *textField = [search_ searchField]; @@ -7237,15 +7250,18 @@ freeing the view controllers on tab change */ @end /* }}} */ /* Settings Controller {{{ */ -@interface SettingsController : CYViewController { +@interface SettingsController : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { _transient Database *database_; NSString *name_; Package *package_; - UIPreferencesTable *table_; - _UISwitchSlider *subscribedSwitch_; - _UISwitchSlider *ignoredSwitch_; - UIPreferencesControlTableCell *subscribedCell_; - UIPreferencesControlTableCell *ignoredCell_; + UITableView *table_; + id subscribedSwitch_; + id ignoredSwitch_; + UITableViewCell *subscribedCell_; + UITableViewCell *ignoredCell_; } - (id) initWithDatabase:(Database *)database package:(NSString *)package; @@ -7255,8 +7271,6 @@ freeing the view controllers on tab change */ @implementation SettingsController - (void) dealloc { - [table_ setDataSource:nil]; - [name_ release]; if (package_ != nil) [package_ release]; @@ -7265,64 +7279,32 @@ freeing the view controllers on tab change */ [ignoredSwitch_ release]; [subscribedCell_ release]; [ignoredCell_ release]; + [super dealloc]; } -- (int) numberOfGroupsInPreferencesTable:(UIPreferencesTable *)table { +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { if (package_ == nil) return 0; - return 2; -} - -- (NSString *) preferencesTable:(UIPreferencesTable *)table titleForGroup:(int)group { - if (package_ == nil) - return nil; - - switch (group) { - case 0: return nil; - case 1: return nil; - - _nodefault - } - - return nil; -} - -- (BOOL) preferencesTable:(UIPreferencesTable *)table isLabelGroup:(int)group { - if (package_ == nil) - return NO; - - switch (group) { - case 0: return NO; - case 1: return YES; - - _nodefault - } - - return NO; + return 1; } -- (int) preferencesTable:(UIPreferencesTable *)table numberOfRowsInGroup:(int)group { +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (package_ == nil) return 0; - switch (group) { - case 0: return 1; - case 1: return 1; - - _nodefault - } + return 1; +} - return 0; +- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { + return UCLocalize("SHOW_ALL_CHANGES_EX"); } -- (void) onSomething:(UIPreferencesControlTableCell *)cell withKey:(NSString *)key { +- (void) onSomething:(BOOL)value withKey:(NSString *)key { if (package_ == nil) return; - _UISwitchSlider *slider([cell control]); - BOOL value([slider value] != 0); NSMutableDictionary *metadata([package_ metadata]); BOOL before; @@ -7338,38 +7320,22 @@ freeing the view controllers on tab change */ } } -- (void) onSubscribed:(UIPreferencesControlTableCell *)cell { - [self onSomething:cell withKey:@"IsSubscribed"]; +- (void) onSubscribed:(id)control { + [self onSomething:(int) [control isOn] withKey:@"IsSubscribed"]; } -- (void) onIgnored:(UIPreferencesControlTableCell *)cell { - [self onSomething:cell withKey:@"IsIgnored"]; +- (void) onIgnored:(id)control { + [self onSomething:(int) [control isOn] withKey:@"IsIgnored"]; } -- (id) preferencesTable:(UIPreferencesTable *)table cellForRow:(int)row inGroup:(int)group { +- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (package_ == nil) return nil; - switch (group) { - case 0: switch (row) { - case 0: - return subscribedCell_; - case 1: - return ignoredCell_; - _nodefault - } break; - - case 1: switch (row) { - case 0: { - UIPreferencesControlTableCell *cell([[[UIPreferencesControlTableCell alloc] init] autorelease]); - [cell setShowSelection:NO]; - [cell setTitle:UCLocalize("SHOW_ALL_CHANGES_EX")]; - return cell; - } - - _nodefault - } break; - + switch ([indexPath row]) { + case 0: return subscribedCell_; + case 1: return ignoredCell_; + _nodefault } @@ -7385,26 +7351,29 @@ freeing the view controllers on tab change */ [[self navigationItem] setTitle:UCLocalize("SETTINGS")]; - table_ = [[UIPreferencesTable alloc] initWithFrame:[[self view] bounds]]; + table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; + [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [table_ setAllowsSelection:NO]; [[self view] addSubview:table_]; - subscribedSwitch_ = [[_UISwitchSlider alloc] initWithFrame:CGRectMake(200, 10, 50, 20)]; - [subscribedSwitch_ addTarget:self action:@selector(onSubscribed:) forEvents:UIControlEventTouchUpInside]; + subscribedSwitch_ = [[objc_getClass("UISwitch") alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; + [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; + [subscribedSwitch_ addTarget:self action:@selector(onSubscribed:) forEvents:UIControlEventValueChanged]; - ignoredSwitch_ = [[_UISwitchSlider alloc] initWithFrame:CGRectMake(200, 10, 50, 20)]; - [ignoredSwitch_ addTarget:self action:@selector(onIgnored:) forEvents:UIControlEventTouchUpInside]; + ignoredSwitch_ = [[objc_getClass("UISwitch") alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; + [ignoredSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; + [ignoredSwitch_ addTarget:self action:@selector(onIgnored:) forEvents:UIControlEventValueChanged]; - subscribedCell_ = [[UIPreferencesControlTableCell alloc] init]; - [subscribedCell_ setShowSelection:NO]; - [subscribedCell_ setTitle:UCLocalize("SHOW_ALL_CHANGES")]; - [subscribedCell_ setControl:subscribedSwitch_]; + subscribedCell_ = [[UITableViewCell alloc] init]; + [subscribedCell_ setText:UCLocalize("SHOW_ALL_CHANGES")]; + [subscribedCell_ setAccessoryView:subscribedSwitch_]; - ignoredCell_ = [[UIPreferencesControlTableCell alloc] init]; - [ignoredCell_ setShowSelection:NO]; - [ignoredCell_ setTitle:UCLocalize("IGNORE_UPGRADES")]; - [ignoredCell_ setControl:ignoredSwitch_]; + ignoredCell_ = [[UITableViewCell alloc] init]; + [ignoredCell_ setText:UCLocalize("IGNORE_UPGRADES")]; + [ignoredCell_ setAccessoryView:ignoredSwitch_]; [table_ setDataSource:self]; + [table_ setDelegate:self]; [self reloadData]; } return self; } @@ -7415,8 +7384,8 @@ freeing the view controllers on tab change */ package_ = [database_ packageWithName:name_]; if (package_ != nil) { [package_ retain]; - [subscribedSwitch_ setValue:([package_ subscribed] ? 1 : 0) animated:NO]; - [ignoredSwitch_ setValue:([package_ ignored] ? 1 : 0) animated:NO]; + [subscribedSwitch_ setOn:([package_ subscribed] ? 1 : 0) animated:NO]; + [ignoredSwitch_ setOn:([package_ ignored] ? 1 : 0) animated:NO]; } [table_ reloadData]; @@ -7459,6 +7428,172 @@ freeing the view controllers on tab change */ [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"signature" ofType:@"html"]]]; } +@end +/* }}} */ +/* Role Controller {{{ */ +@interface RoleController : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { + _transient Database *database_; + id roledelegate_; + UITableView *table_; + UISegmentedControl *segment_; + UIView *container_; +} + +- (void) showDoneButton; +- (void) resizeSegmentedControl; + +@end + +@implementation RoleController +- (void) dealloc { + [table_ release]; + [segment_ release]; + [container_ release]; + + [super dealloc]; +} + +- (id) initWithDatabase:(Database *)database delegate:(id)delegate { + if ((self = [super init])) { + database_ = database; + roledelegate_ = delegate; + + [[self navigationItem] setTitle:UCLocalize("WHO_ARE_YOU")]; + + NSArray *items = [NSArray arrayWithObjects: + UCLocalize("USER"), + UCLocalize("HACKER"), + UCLocalize("DEVELOPER"), + nil]; + segment_ = [[UISegmentedControl alloc] initWithItems:items]; + container_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)]; + [container_ addSubview:segment_]; + + int index = -1; + if ([Role_ isEqualToString:@"User"]) index = 0; + if ([Role_ isEqualToString:@"Hacker"]) index = 1; + if ([Role_ isEqualToString:@"Developer"]) index = 2; + if (index != -1) { + [segment_ setSelectedSegmentIndex:index]; + [self showDoneButton]; + } + + [segment_ addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged]; + [self resizeSegmentedControl]; + + table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; + [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [table_ setDelegate:self]; + [table_ setDataSource:self]; + [[self view] addSubview:table_]; + [table_ reloadData]; + } return self; +} + +- (void) resizeSegmentedControl { + CGFloat width = [[self view] frame].size.width; + [segment_ setFrame:CGRectMake(width / 32.0f, 0, width - (width / 32.0f * 2.0f), 44.0f)]; +} + +- (void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + [self resizeSegmentedControl]; +} + +- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { + [self resizeSegmentedControl]; +} + +- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + [self resizeSegmentedControl]; +} + +- (void) save { + NSString *role = nil; + + switch ([segment_ selectedSegmentIndex]) { + case 0: role = @"User"; break; + case 1: role = @"Hacker"; break; + case 2: role = @"Developer"; break; + + _nodefault + } + + if (![role isEqualToString:Role_]) { + Role_ = role; + + Settings_ = [NSMutableDictionary dictionaryWithObjectsAndKeys: + Role_, @"Role", + nil]; + + [Metadata_ setObject:Settings_ forKey:@"Settings"]; + + Changed_ = true; + + [roledelegate_ updateData]; + } +} + +- (void) segmentChanged:(UISegmentedControl *)control { + [self showDoneButton]; +} + +- (void) doneButtonClicked { + [self save]; + [[self navigationController] dismissModalViewControllerAnimated:YES]; +} + +- (void) showDoneButton { + UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] + initWithTitle:UCLocalize("DONE") + style:UIBarButtonItemStyleDone + target:self + action:@selector(doneButtonClicked) + ]; + [[self navigationItem] setRightBarButtonItem:rightItem animated:[[self navigationItem] rightBarButtonItem] == nil]; + [rightItem release]; +} + +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + // XXX: For not having a single cell in the table, this sure is a lot of sections. + return 6; +} + +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 0; // :( +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + return nil; // This method is required by the protocol. +} + +- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { + if (section == 1) + return UCLocalize("ROLE_EX"); + if (section == 4) + return [NSString stringWithFormat: + @"%@: %@\n%@: %@\n%@: %@", + UCLocalize("USER"), UCLocalize("USER_EX"), + UCLocalize("HACKER"), UCLocalize("HACKER_EX"), + UCLocalize("DEVELOPER"), UCLocalize("DEVELOPER_EX") + ]; + else return nil; +} + +- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { + if (section == 3) return 44.0f; + else return 0; +} + +- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { + if (section == 3) return container_; + else return nil; +} + @end /* }}} */ @@ -7470,9 +7605,15 @@ freeing the view controllers on tab change */ bool dropped_; bool updating_; id updatedelegate_; - UIViewController *root_; + UITabBarController *root_; } +- (void) setTabBarController:(UITabBarController *)controller; + +- (void) dropBar:(BOOL)animated; +- (void) beginUpdate; +- (void) raiseBar:(BOOL)animated; + @end @implementation CYContainer @@ -7504,7 +7645,7 @@ freeing the view controllers on tab change */ return YES; /* XXX: return YES; */ } -- (void) setRootController:(UIViewController *)controller { +- (void) setTabBarController:(UITabBarController *)controller { root_ = controller; [[self view] addSubview:[root_ view]]; } @@ -7649,8 +7790,7 @@ freeing the view controllers on tab change */ [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } -- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration -{ +- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { // XXX: fix Apple's layout bug [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } @@ -7728,8 +7868,8 @@ typedef enum { bool loaded_; } -- (UIViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class; -- (void) setPage:(UIViewController *)page; +- (UCViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class; +- (void) setPage:(UCViewController *)page; @end @@ -7811,7 +7951,7 @@ static _finline void _setHomePage(Cydia *self) { if (tag_ != 4 && search_ != nil) [search_ reloadData]; - [[tabbar_ selectedViewController] reloadData]; + [(CYNavigationController *)[tabbar_ selectedViewController] reloadData]; } - (int)indexOfTabWithTag:(int)tag { @@ -8053,17 +8193,17 @@ static _finline void _setHomePage(Cydia *self) { [self complete]; } -- (void) setPage:(UIViewController *)page { +- (void) setPage:(UCViewController *)page { [page setDelegate:self]; - UINavigationController *navController = [tabbar_ selectedViewController]; + CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController]; [navController setViewControllers:[NSArray arrayWithObject:page] animated:NO]; - for (UIViewController *page in [tabbar_ viewControllers]) { + for (CYNavigationController *page in [tabbar_ viewControllers]) { if (page != navController) [page setViewControllers:nil]; } } -- (UIViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class { +- (UCViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class { CYBrowserController *browser = [[[_class alloc] init] autorelease]; [browser loadURL:url]; return browser; @@ -8115,7 +8255,7 @@ static _finline void _setHomePage(Cydia *self) { - (void) tabBarController:(id)tabBarController didSelectViewController:(UIViewController *)viewController { int tag = [[viewController tabBarItem] tag]; if (tag == tag_) { - [[tabbar_ selectedViewController] popToRootViewControllerAnimated:YES]; + [(CYNavigationController *)[tabbar_ selectedViewController] popToRootViewControllerAnimated:YES]; return; } else if (tag_ == 1) { [[self sectionsController] resetView]; @@ -8137,40 +8277,11 @@ static _finline void _setHomePage(Cydia *self) { tag_ = tag; } -- (void) askForSettings { - NSString *parenthetical(UCLocalize("PARENTHETICAL")); - - CYActionSheet *role([[[CYActionSheet alloc] - initWithTitle:UCLocalize("WHO_ARE_YOU") - buttons:[NSArray arrayWithObjects: - [NSString stringWithFormat:parenthetical, UCLocalize("USER"), UCLocalize("USER_EX")], - [NSString stringWithFormat:parenthetical, UCLocalize("HACKER"), UCLocalize("HACKER_EX")], - [NSString stringWithFormat:parenthetical, UCLocalize("DEVELOPER"), UCLocalize("DEVELOPER_EX")], - nil] - defaultButtonIndex:-1 - ] autorelease]); - - [role setMessage:UCLocalize("ROLE_EX")]; - - int button([role yieldToPopupAlertAnimated:YES]); - - switch (button) { - case 1: Role_ = @"User"; break; - case 2: Role_ = @"Hacker"; break; - case 3: Role_ = @"Developer"; break; - - _nodefault - } - - Settings_ = [NSMutableDictionary dictionaryWithObjectsAndKeys: - Role_, @"Role", - nil]; - - [Metadata_ setObject:Settings_ forKey:@"Settings"]; - - Changed_ = true; - - [role dismiss]; +- (void) showSettings { + RoleController *role = [[RoleController alloc] initWithDatabase:database_ delegate:self]; + CYNavigationController *nav = [[CYNavigationController alloc] initWithRootViewController:role]; + if (IsWildcat_) [nav setModalPresentationStyle:UIModalPresentationFormSheet]; + [container_ presentModalViewController:nav animated:YES]; } - (void) setPackageController:(PackageController *)view { @@ -8228,7 +8339,7 @@ static _finline void _setHomePage(Cydia *self) { Queuing_ = true; [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kManageTag] != -1 ? [self indexOfTabWithTag:kManageTag] : [self indexOfTabWithTag:kInstalledTag]] tabBarItem] setBadgeValue:UCLocalize("Q_D")]; - [[tabbar_ selectedViewController] reloadData]; + [(CYNavigationController *)[tabbar_ selectedViewController] reloadData]; [queueDelegate_ queueStatusDidChange]; } @@ -8321,7 +8432,7 @@ static _finline void _setHomePage(Cydia *self) { [window_ setUserInteractionEnabled:YES]; } -- (UIViewController *) pageForPackage:(NSString *)name { +- (UCViewController *) pageForPackage:(NSString *)name { if (Package *package = [database_ packageWithName:name]) { PackageController *view([self packageController]); [view setPackage:package]; @@ -8333,7 +8444,7 @@ static _finline void _setHomePage(Cydia *self) { } } -- (UIViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag { +- (UCViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag { if (tag != NULL) *tag = -1; @@ -8385,13 +8496,21 @@ static _finline void _setHomePage(Cydia *self) { - (void) applicationOpenURL:(NSURL *)url { [super applicationOpenURL:url]; int tag; - if (UIViewController *page = [self pageForURL:url hasTag:&tag]) { + if (UCViewController *page = [self pageForURL:url hasTag:&tag]) { [self setPage:page]; tag_ = tag; [tabbar_ setSelectedViewController:(tag_ == -1 ? nil : [[tabbar_ viewControllers] objectAtIndex:tag_])]; } } +- (void) applicationWillResignActive:(UIApplication *)application { + // Stop refreshing if you get a phone call or lock the device. + if ([container_ updating]) [container_ cancelUpdate]; + + if ([[self superclass] instancesRespondToSelector:@selector(applicationWillResignActive:)]) + [super applicationWillResignActive:application]; +} + - (void) applicationDidFinishLaunching:(id)unused { [CYBrowserController _initialize]; @@ -8450,7 +8569,7 @@ static _finline void _setHomePage(Cydia *self) { } if (Role_ == nil) - [self askForSettings]; + [self showSettings]; _trace(); @@ -8477,9 +8596,8 @@ static _finline void _setHomePage(Cydia *self) { [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("MANAGE") image:[UIImage applicationImageNamed:@"manage.png"] tag:kManageTag] autorelease] atIndex:3]; } - for (int i = 0; i < [items count]; i++) { + for (size_t i(0); i != [items count]; i++) [[controllers objectAtIndex:i] setTabBarItem:[items objectAtIndex:i]]; - } tabbar_ = [[CYTabBarController alloc] initWithDatabase:database_]; [tabbar_ setViewControllers:controllers]; @@ -8488,7 +8606,7 @@ static _finline void _setHomePage(Cydia *self) { container_ = [[CYContainer alloc] initWithDatabase:database_]; [container_ setUpdateDelegate:self]; - [container_ setRootController:tabbar_]; + [container_ setTabBarController:tabbar_]; [window_ addSubview:[container_ view]]; [[tabbar_ view] setFrame:CGRectMake(0, -20.0f, [window_ bounds].size.width, [window_ bounds].size.height)]; @@ -8829,4 +8947,4 @@ int main(int argc, char *argv[]) { _pooled CFRelease(Locale_); return value; -} \ No newline at end of file +}