+- (UIPreferencesTableCell *) preferencesTable:(UIPreferencesTable *)table cellForRow:(int)row inGroup:(int)group {
+ UIPreferencesTableCell *cell = [[[UIPreferencesTableCell alloc] init] autorelease];
+ [cell setShowSelection:NO];
+
+ switch (group) {
+ case 0: switch (row) {
+ case 0: {
+ [cell setTitle:@"Downloading"];
+ [cell setValue:SizeString([database_ fetcher].FetchNeeded())];
+ } break;
+
+ case 1: {
+ [cell setTitle:@"Resuming At"];
+ [cell setValue:SizeString([database_ fetcher].PartialPresent())];
+ } break;
+
+ case 2: {
+ double size([database_ cache]->UsrSize());
+
+ if (size < 0) {
+ [cell setTitle:@"Disk Freeing"];
+ [cell setValue:SizeString(-size)];
+ } else {
+ [cell setTitle:@"Disk Using"];
+ [cell setValue:SizeString(size)];
+ }
+ } break;
+
+ default: _assert(false);
+ } break;
+
+ case 1:
+ _assert(size_t(row) < [fields_ count]);
+ [cell setTitle:[[fields_ allKeys] objectAtIndex:row]];
+ [cell addSubview:[[fields_ allValues] objectAtIndex:row]];
+ break;
+
+ default: _assert(false);
+ }
+
+ return cell;
+}
+
+- (id) initWithView:(UIView *)view database:(Database *)database delegate:(id)delegate {
+ if ((self = [super initWithFrame:[view bounds]]) != nil) {
+ database_ = database;
+ delegate_ = delegate;
+
+ transition_ = [[UITransitionView alloc] initWithFrame:[self bounds]];
+ [self addSubview:transition_];
+
+ overlay_ = [[UIView alloc] initWithFrame:[transition_ bounds]];
+
+ CGSize navsize = [UINavigationBar defaultSize];
+ CGRect navrect = {{0, 0}, navsize};
+ CGRect bounds = [overlay_ bounds];
+
+ navbar_ = [[UINavigationBar alloc] initWithFrame:navrect];
+ if (Advanced_)
+ [navbar_ setBarStyle:1];
+ [navbar_ setDelegate:self];
+
+ UINavigationItem *navitem = [[[UINavigationItem alloc] initWithTitle:@"Confirm"] autorelease];
+ [navbar_ pushNavigationItem:navitem];
+ [navbar_ showButtonsWithLeftTitle:@"Cancel" rightTitle:@"Confirm"];
+
+ fields_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
+
+ NSMutableArray *installing = [NSMutableArray arrayWithCapacity:16];
+ NSMutableArray *reinstalling = [NSMutableArray arrayWithCapacity:16];
+ NSMutableArray *upgrading = [NSMutableArray arrayWithCapacity:16];
+ NSMutableArray *downgrading = [NSMutableArray arrayWithCapacity:16];
+ NSMutableArray *removing = [NSMutableArray arrayWithCapacity:16];
+
+ bool remove(false);
+
+ pkgCacheFile &cache([database_ cache]);
+ NSArray *packages = [database_ packages];
+ for (size_t i(0), e = [packages count]; i != e; ++i) {
+ Package *package = [packages objectAtIndex:i];
+ pkgCache::PkgIterator iterator = [package iterator];
+ pkgDepCache::StateCache &state(cache[iterator]);
+
+ NSString *name([package name]);
+
+ if (state.NewInstall())
+ [installing addObject:name];
+ else if (!state.Delete() && (state.iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)
+ [reinstalling addObject:name];
+ else if (state.Upgrade())
+ [upgrading addObject:name];
+ else if (state.Downgrade())
+ [downgrading addObject:name];
+ else if (state.Delete()) {
+ if ([package essential])
+ remove = true;
+ [removing addObject:name];
+ }
+ }
+
+ if (!remove)
+ essential_ = nil;
+ else if (Advanced_ || true) {
+ essential_ = [[UIAlertSheet alloc]
+ initWithTitle:@"Removing Essentials"
+ buttons:[NSArray arrayWithObjects:
+ @"Cancel Operation (Safe)",
+ @"Force Removal (Unsafe)",
+ nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"remove"
+ ];
+
+#ifndef __OBJC2__
+ [essential_ setDestructiveButton:[[essential_ buttons] objectAtIndex:0]];
+#endif
+ [essential_ setBodyText:@"This operation involves the removal of one or more packages that are required for the continued operation of either Cydia or iPhoneOS. If you continue, you may not be able to use Cydia to repair any damage."];
+ } else {
+ essential_ = [[UIAlertSheet alloc]
+ initWithTitle:@"Unable to Comply"
+ buttons:[NSArray arrayWithObjects:@"Okay", nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"unable"
+ ];
+
+ [essential_ setBodyText:@"This operation requires the removal of one or more packages that are required for the continued operation of either Cydia or iPhoneOS. In order to continue and force this operation you will need to be activate the Advanced mode under to continue and force this operation you will need to be activate the Advanced mode under Settings."];
+ }
+
+ AddTextView(fields_, installing, @"Installing");
+ AddTextView(fields_, reinstalling, @"Reinstalling");
+ AddTextView(fields_, upgrading, @"Upgrading");
+ AddTextView(fields_, downgrading, @"Downgrading");
+ AddTextView(fields_, removing, @"Removing");
+
+ table_ = [[UIPreferencesTable alloc] initWithFrame:CGRectMake(
+ 0, navsize.height, bounds.size.width, bounds.size.height - navsize.height
+ )];
+
+ [table_ setReusesTableCells:YES];
+ [table_ setDataSource:self];
+ [table_ reloadData];
+
+ [overlay_ addSubview:navbar_];
+ [overlay_ addSubview:table_];
+
+ [view addSubview:self];
+
+ [transition_ setDelegate:self];
+
+ UIView *blank = [[[UIView alloc] initWithFrame:[transition_ bounds]] autorelease];
+ [transition_ transition:0 toView:blank];
+ [transition_ transition:3 toView:overlay_];
+ } return self;
+}
+
+@end
+/* }}} */
+
+/* Progress Data {{{ */
+@interface ProgressData : NSObject {
+ SEL selector_;
+ id target_;
+ id object_;
+}
+
+- (ProgressData *) initWithSelector:(SEL)selector target:(id)target object:(id)object;
+
+- (SEL) selector;
+- (id) target;
+- (id) object;
+@end
+
+@implementation ProgressData
+
+- (ProgressData *) initWithSelector:(SEL)selector target:(id)target object:(id)object {
+ if ((self = [super init]) != nil) {
+ selector_ = selector;
+ target_ = target;
+ object_ = object;
+ } return self;
+}
+
+- (SEL) selector {
+ return selector_;
+}
+
+- (id) target {
+ return target_;
+}
+
+- (id) object {
+ return object_;
+}
+
+@end
+/* }}} */
+/* Progress View {{{ */
+Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$");
+
+@interface ProgressView : UIView <
+ ConfigurationDelegate,
+ ProgressDelegate
+> {
+ _transient Database *database_;
+ UIView *view_;
+ UIView *background_;
+ UITransitionView *transition_;
+ UIView *overlay_;
+ UINavigationBar *navbar_;
+ UIProgressBar *progress_;
+ UITextView *output_;
+ UITextLabel *status_;
+ UIPushButton *close_;
+ id delegate_;
+}
+
+- (void) transitionViewDidComplete:(UITransitionView*)view fromView:(UIView*)from toView:(UIView*)to;
+
+- (id) initWithFrame:(struct CGRect)frame database:(Database *)database delegate:(id)delegate;
+- (void) setContentView:(UIView *)view;
+- (void) resetView;
+
+- (void) _retachThread;
+- (void) _detachNewThreadData:(ProgressData *)data;
+- (void) detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)object title:(NSString *)title;
+
+@end
+
+@protocol ProgressViewDelegate
+- (void) progressViewIsComplete:(ProgressView *)sender;
+@end
+
+@implementation ProgressView
+
+- (void) dealloc {
+ [transition_ setDelegate:nil];
+ [navbar_ setDelegate:nil];
+
+ [view_ release];
+ if (background_ != nil)
+ [background_ release];
+ [transition_ release];
+ [overlay_ release];
+ [navbar_ release];
+ [progress_ release];
+ [output_ release];
+ [status_ release];
+ [close_ release];
+ [super dealloc];
+}
+
+- (void) transitionViewDidComplete:(UITransitionView*)view fromView:(UIView*)from toView:(UIView*)to {
+ if (bootstrap_ && from == overlay_ && to == view_)
+ exit(0);
+}
+
+- (id) initWithFrame:(struct CGRect)frame database:(Database *)database delegate:(id)delegate {
+ if ((self = [super initWithFrame:frame]) != nil) {
+ database_ = database;
+ delegate_ = delegate;
+
+ transition_ = [[UITransitionView alloc] initWithFrame:[self bounds]];
+ [transition_ setDelegate:self];
+
+ overlay_ = [[UIView alloc] initWithFrame:[transition_ bounds]];
+
+ if (bootstrap_)
+ [overlay_ setBackgroundColor:Black_];
+ else {
+ background_ = [[UIView alloc] initWithFrame:[self bounds]];
+ [background_ setBackgroundColor:Black_];
+ [self addSubview:background_];
+ }
+
+ [self addSubview:transition_];