#include <objc/objc.h>
#include <objc/runtime.h>
+#include <map>
#include <sstream>
+#include <string>
+
#include <ext/stdio_filebuf.h>
#include <apt-pkg/acquire.h>
#include <mach-o/nlist.h>
}
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include <errno.h>
#include <pcre.h>
-#include <string.h>
/* }}} */
/* Extension Keywords {{{ */
#define _trace() fprintf(stderr, "_trace()@%s:%u[%s]\n", __FILE__, __LINE__, __FUNCTION__)
static CGColor Red_;
static CGColor White_;
+static NSString *Home_;
+static BOOL Sounds_Keyboard_;
+
const char *Firmware_ = NULL;
const char *Machine_ = NULL;
const char *SerialNumber_ = NULL;
return text;
}
+
+NSString *Simplify(NSString *title) {
+ const char *data = [title UTF8String];
+ size_t size = [title length];
+
+ Pcre title_r("^(.*?)( \\(.*\\))?$");
+ if (title_r(data, size))
+ return title_r[1];
+ else
+ return title;
+}
/* }}} */
@class Package;
}
- (void) perform {
+ pkgSourceList list;
+ _assert(list.ReadMainList());
+
+ /*std::map<std::string> before;
+
+ for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source)
+ before.add((*source)->GetURI().c_str());
+ exit(0);*/
+
if (fetcher_->Run(PulseInterval_) != pkgAcquire::Continue)
return;
return;
if (result != pkgPackageManager::Completed)
return;
+
+ _assert(list.ReadMainList());
}
- (void) upgrade {
if ([pages_ count] != 0)
[[pages_ lastObject] setPageActive:NO];
- NSString *title = [page title]; {
- const char *data = [title UTF8String];
- size_t size = [title length];
-
- Pcre title_r("^(.*?)( \\(.*\\))?$");
- if (title_r(data, size))
- title = title_r[1];
- }
+ NSString *title = Simplify([page title]);
NSString *backButtonTitle = [page backButtonTitle];
if (backButtonTitle == nil)
GSFontRef small = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 14);
icon_ = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
- [icon_ zoomToScale:0.5f];
name_ = [[UITextLabel alloc] initWithFrame:CGRectMake(48, 8, 240, 25)];
[name_ setBackgroundColor:Clear_];
image = [UIImage imageAtPath:[icon substringFromIndex:6]];
if (image == nil)
image = [UIImage applicationImageNamed:@"unknown.png"];
-
[icon_ setImage:image];
+
+ if (image != nil) {
+ CGSize size = [image size];
+ float scale = 30 / std::max(size.width, size.height);
+ [icon_ zoomToScale:scale];
+ }
+
[icon_ setFrame:CGRectMake(10, 10, 30, 30)];
[name_ setText:[package name]];
trusted = false;
}
- [source_ setText:[NSString stringWithFormat:@"from %@", label]];
+ [source_ setText:[NSString stringWithFormat:@"from %@ (%@)", label, Simplify([package section])]];
if (trusted)
[self addSubview:trusted_];
- (id) initWithBook:(RVBook *)book database:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object;
- (void) setDelegate:(id)delegate;
+- (void) setObject:(id)object;
+
- (void) reloadData;
+- (void) resetCursor;
@end
delegate_ = delegate;
}
+- (void) setObject:(id)object {
+ if (object_ != nil)
+ [object_ release];
+ if (object == nil)
+ object_ = nil;
+ else
+ object_ = [object retain];
+}
+
- (void) reloadData {
NSArray *packages = [database_ packages];
[list_ resetViewAnimated:animated];
}
+- (void) resetCursor {
+ [[list_ table] scrollPointVisibleAtTopLeft:CGPointMake(0, 0) animated:NO];
+}
+
@end
/* }}} */
@end
/* }}} */
+@interface CYBook : RVBook <
+ ProgressDelegate
+> {
+ _transient Database *database_;
+ UIView *overlay_;
+ UIProgressIndicator *indicator_;
+ UITextLabel *prompt_;
+ UIProgressBar *progress_;
+ bool updating_;
+}
+
+- (id) initWithFrame:(CGRect)frame database:(Database *)database;
+- (void) update;
+- (BOOL) updating;
+
+@end
+
/* Install View {{{ */
@interface InstallView : RVPage {
_transient Database *database_;
[book_ pushPage:view];
}
+- (void) _leftButtonClicked {
+ [(CYBook *)book_ update];
+ [self reloadButtons];
+}
+
- (void) _rightButtonClicked {
[delegate_ distUpgrade];
}
[list_ resetViewAnimated:animated];
}
+- (NSString *) leftButtonTitle {
+ return [(CYBook *)book_ updating] ? nil : @"Refresh";
+}
+
- (NSString *) rightButtonTitle {
return upgrades_ == 0 ? nil : [NSString stringWithFormat:@"Upgrade All (%u)", upgrades_];
}
- (void) showKeyboard:(BOOL)show;
@end
-@interface SearchView : PackageTable {
+@interface SearchView : RVPage {
UIView *accessory_;
UISearchField *field_;
+ UITransitionView *transition_;
+ PackageTable *table_;
+ UIPreferencesTable *advanced_;
+ UIView *dimmed_;
+ bool flipped_;
}
- (id) initWithBook:(RVBook *)book database:(Database *)database;
[accessory_ release];
[field_ release];
+ [transition_ release];
+ [table_ release];
+ [advanced_ release];
+ [dimmed_ release];
[super dealloc];
}
- (void) textFieldDidBecomeFirstResponder:(UITextField *)field {
[delegate_ showKeyboard:YES];
- [list_ setEnabled:NO];
-
- /*CGColor dimmed(alpha, 0, 0, 0, 0.5);
- [editor_ setBackgroundColor:dimmed];*/
+ [table_ setEnabled:NO];
+ [self addSubview:dimmed_];
}
- (void) textFieldDidResignFirstResponder:(UITextField *)field {
- [list_ setEnabled:YES];
+ [dimmed_ removeFromSuperview];
+ [table_ setEnabled:YES];
[delegate_ showKeyboard:NO];
}
}
- (id) initWithBook:(RVBook *)book database:(Database *)database {
- if ((self = [super
- initWithBook:book
- database:database
- title:nil
- filter:@selector(isSearchedForBy:)
- with:nil
- ]) != nil) {
- CGRect cnfrect = {{0, 36}, {17, 18}};
+ if ((self = [super initWithBook:book]) != nil) {
+ CGRect pageBounds = [book_ pageBounds];
+
+ /*UIImageView *pinstripe = [[[UIImageView alloc] initWithFrame:pageBounds] autorelease];
+ [pinstripe setImage:[UIImage applicationImageNamed:@"pinstripe.png"]];
+ [self addSubview:pinstripe];*/
+
+ dimmed_ = [[UIView alloc] initWithFrame:pageBounds];
+ CGColor dimmed(space_, 0, 0, 0, 0.5);
+ [dimmed_ setBackgroundColor:dimmed];
+
+ transition_ = [[UITransitionView alloc] initWithFrame:pageBounds];
+ [self addSubview:transition_];
+
+ advanced_ = [[UIPreferencesTable alloc] initWithFrame:pageBounds];
+
+ table_ = [[PackageTable alloc]
+ initWithBook:book
+ database:database
+ title:nil
+ filter:@selector(isSearchedForBy:)
+ with:nil
+ ];
+
+ [transition_ transition:0 toView:table_];
+
+ CGRect cnfrect = {{3, 36}, {17, 18}};
CGRect area;
- area.origin.x = cnfrect.size.width + 6;
+ area.origin.x = cnfrect.size.width + 12;
area.origin.y = 30;
- area.size.width = [self bounds].size.width - area.origin.x - 12;
+ area.size.width = [self bounds].size.width - area.origin.x - 18;
area.size.height = [UISearchField defaultHeight];
field_ = [[UISearchField alloc] initWithFrame:area];
} return self;
}
+- (void) flipPage {
+ LKAnimation *animation = [LKTransition animation];
+ [animation setType:@"oglFlip"];
+ [animation setTimingFunction:[LKTimingFunction functionWithName:@"easeInEaseOut"]];
+ [animation setFillMode:@"extended"];
+ [animation setTransitionFlags:3];
+ [animation setDuration:10];
+ [animation setSpeed:0.35];
+ [animation setSubtype:(flipped_ ? @"fromLeft" : @"fromRight")];
+ [[transition_ _layer] addAnimation:animation forKey:0];
+ [transition_ transition:0 toView:(flipped_ ? (UIView *) table_ : (UIView *) advanced_)];
+ flipped_ = !flipped_;
+}
+
- (void) configurePushed {
- // XXX: implement flippy advanced panel
+ [field_ resignFirstResponder];
+ [self flipPage];
+}
+
+- (void) resetViewAnimated:(BOOL)animated {
+ if (flipped_)
+ [self flipPage];
+ [table_ resetViewAnimated:animated];
}
- (void) reloadData {
- object_ = [[field_ text] retain];
- [super reloadData];
- [[list_ table] scrollPointVisibleAtTopLeft:CGPointMake(0, 0) animated:NO];
+ if (flipped_)
+ [self flipPage];
+ [table_ setObject:[field_ text]];
+ [table_ reloadData];
+ [table_ resetCursor];
}
- (UIView *) accessoryView {
return accessory_;
}
+- (NSString *) title {
+ return nil;
+}
+
- (NSString *) backButtonTitle {
return @"Search";
}
@end
/* }}} */
-@interface CYBook : RVBook <
- ProgressDelegate
-> {
- _transient Database *database_;
- UIView *overlay_;
- UIProgressIndicator *indicator_;
- UITextLabel *prompt_;
- UIProgressBar *progress_;
-}
-
-- (id) initWithFrame:(CGRect)frame database:(Database *)database;
-- (void) update;
-
-@end
-
@implementation CYBook
- (void) dealloc {
[super dealloc];
}
+- (BOOL) updating {
+ return updating_;
+}
+
- (void) update {
+ [navbar_ setPrompt:@""];
[navbar_ addSubview:overlay_];
[indicator_ startAnimation];
[prompt_ setText:@"Updating Database..."];
[progress_ setProgress:0];
+ updating_ = true;
+
[NSThread
detachNewThreadSelector:@selector(_update)
toTarget:self
}
- (void) _update_ {
+ updating_ = false;
+
[overlay_ removeFromSuperview];
[indicator_ stopAnimation];
[delegate_ reloadData];
CGSize keysize = [UIKeyboard defaultSize];
CGRect keyrect = {{0, [overlay_ bounds].size.height - keysize.height}, keysize};
keyboard_ = [[UIKeyboard alloc] initWithFrame:keyrect];
+ [[UIKeyboardImpl sharedInstance] setSoundsEnabled:(Sounds_Keyboard_ ? YES : NO)];
[self reloadData];
[book_ update];
}*/
int main(int argc, char *argv[]) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
bootstrap_ = argc > 1 && strcmp(argv[1], "--bootstrap") == 0;
+ Home_ = NSHomeDirectory();
+
+ {
+ NSString *plist = [Home_ stringByAppendingString:@"/Library/Preferences/com.apple.preferences.sounds.plist"];
+ if (NSDictionary *sounds = [NSDictionary dictionaryWithContentsOfFile:plist])
+ if (NSNumber *keyboard = [sounds objectForKey:@"keyboard"])
+ Sounds_Keyboard_ = [keyboard boolValue];
+ }
+
setuid(0);
setgid(0);
dealloc_ = dealloc->method_imp;
dealloc->method_imp = (IMP) &Dealloc_;*/
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
if (NSDictionary *sysver = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]) {
if (NSString *prover = [sysver valueForKey:@"ProductVersion"]) {
Firmware_ = strdup([prover UTF8String]);