#include <pcre.h>
/* }}} */
-/* Miscellaneous Messages {{{ */
-@interface NSString (Cydia)
-- (NSString *) stringByAddingPercentEscapes;
-- (NSString *) stringByReplacingCharacter:(unsigned short)arg0 withCharacter:(unsigned short)arg1;
-@end
-/* }}} */
/* iPhoneOS 2.0 Compatibility {{{ */
#ifdef __OBJC2__
@interface UICGColor : NSObject {
#endif
/* }}} */
+@interface NSString (UIKit)
+- (NSString *) stringByAddingPercentEscapes;
+- (NSString *) stringByReplacingCharacter:(unsigned short)arg0 withCharacter:(unsigned short)arg1;
+@end
+
+@interface NSString (Cydia)
++ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length;
+@end
+
+@implementation NSString (Cydia)
+
++ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length {
+ char data[length + 1];
+ memcpy(data, bytes, length);
+ data[length] = '\0';
+ return [NSString stringWithUTF8String:data];
+}
+
+@end
+
/* Perl-Compatible RegEx {{{ */
class Pcre {
private:
}
NSString *operator [](size_t match) {
- return [NSString
- stringWithCString:(data_ + matches_[match * 2])
- length:(matches_[match * 2 + 1] - matches_[match * 2])
- ];
+ return [NSString stringWithUTF8Bytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2])];
}
bool operator ()(const char *data, size_t size) {
name_ = [email_r[1] retain];
email_ = [email_r[2] retain];
} else {
- name_ = [[NSString stringWithCString:data length:size] retain];
+ name_ = [[NSString alloc]
+ initWithBytes:data
+ length:size
+ encoding:kCFStringEncodingUTF8
+ ];
+
email_ = nil;
}
} return self;
/* Random Global Variables {{{ */
static const int PulseInterval_ = 50000;
+static const int ButtonBarHeight_ = 48;
+static const float KeyboardTime_ = 0.4f;
static CGColor Black_;
static CGColor Clear_;
static NSString *Home_;
static BOOL Sounds_Keyboard_;
+static BOOL Advanced_;
+
const char *Firmware_ = NULL;
const char *Machine_ = NULL;
const char *SerialNumber_ = NULL;
}
virtual void Fetch(pkgAcquire::ItemDesc &item) {
- [delegate_ setProgressTitle:[NSString stringWithCString:("Downloading " + item.ShortDesc).c_str()]];
+ [delegate_ setProgressTitle:[NSString stringWithUTF8String:("Downloading " + item.ShortDesc).c_str()]];
}
virtual void Done(pkgAcquire::ItemDesc &item) {
)
return;
- [delegate_ setProgressError:[NSString stringWithCString:item.Owner->ErrorText.c_str()]];
+ [delegate_ setProgressError:[NSString stringWithUTF8String:item.Owner->ErrorText.c_str()]];
}
virtual bool Pulse(pkgAcquire *Owner) {
protected:
virtual void Update() {
- [delegate_ setProgressTitle:[NSString stringWithCString:Op.c_str()]];
+ [delegate_ setProgressTitle:[NSString stringWithUTF8String:Op.c_str()]];
[delegate_ setProgressPercent:(Percent / 100)];
}
if ((self = [super init]) != nil) {
trusted_ = index->IsTrusted();
- uri_ = [[NSString stringWithCString:index->GetURI().c_str()] retain];
- distribution_ = [[NSString stringWithCString:index->GetDist().c_str()] retain];
- type_ = [[NSString stringWithCString:index->GetType()] retain];
+ uri_ = [[NSString stringWithUTF8String:index->GetURI().c_str()] retain];
+ distribution_ = [[NSString stringWithUTF8String:index->GetDist().c_str()] retain];
+ type_ = [[NSString stringWithUTF8String:index->GetType()] retain];
description_ = nil;
label_ = nil;
value = value.substr(1);
if (name == "Default-Icon")
- defaultIcon_ = [[NSString stringWithCString:value.c_str()] retain];
+ defaultIcon_ = [[NSString stringWithUTF8String:value.c_str()] retain];
else if (name == "Description")
- description_ = [[NSString stringWithCString:value.c_str()] retain];
+ description_ = [[NSString stringWithUTF8String:value.c_str()] retain];
else if (name == "Label")
- label_ = [[NSString stringWithCString:value.c_str()] retain];
+ label_ = [[NSString stringWithUTF8String:value.c_str()] retain];
else if (name == "Origin")
- origin_ = [[NSString stringWithCString:value.c_str()] retain];
+ origin_ = [[NSString stringWithUTF8String:value.c_str()] retain];
else if (name == "Version")
- version_ = [[NSString stringWithCString:value.c_str()] retain];
+ version_ = [[NSString stringWithUTF8String:value.c_str()] retain];
}
}
} return self;
return defaultIcon_;
}
+@end
+/* }}} */
+/* Relationship Class {{{ */
+@interface Relationship : NSObject {
+ NSString *type_;
+ NSString *id_;
+}
+
+- (NSString *) type;
+- (NSString *) id;
+- (NSString *) name;
+
+@end
+
+@implementation Relationship
+
+- (void) dealloc {
+ [type_ release];
+ [id_ release];
+ [super dealloc];
+}
+
+- (NSString *) type {
+ return type_;
+}
+
+- (NSString *) id {
+ return id_;
+}
+
+- (NSString *) name {
+ _assert(false);
+ return nil;
+}
+
@end
/* }}} */
/* Package Class {{{ */
const char *line = std::find(value, end, '\n');
while (line != value && line[-1] == ' ')
--line;
- return [NSString stringWithCString:value length:(line - value)];
+
+ return [NSString stringWithUTF8Bytes:value length:(line - value)];
} else {
begin = std::find(begin, end, '\n');
if (begin == end)
NSString *tagline_;
NSString *icon_;
NSString *website_;
+
+ NSArray *relationships_;
}
- (Package *) initWithIterator:(pkgCache::PkgIterator)iterator database:(Database *)database version:(pkgCache::VerIterator)version file:(pkgCache::VerFileIterator)file;
+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator database:(Database *)database;
+- (pkgCache::PkgIterator) iterator;
+
- (NSString *) section;
- (Address *) maintainer;
- (size_t) size;
- (NSString *) icon;
- (NSString *) website;
+- (NSArray *) relationships;
+
- (Source *) source;
- (BOOL) matches:(NSString *)text;
if (website_ != nil)
[website_ release];
+ if (relationships_ != nil)
+ [relationships_ release];
+
[super dealloc];
}
version_ = version;
file_ = file;
- latest_ = [[NSString stringWithCString:version_.VerStr()] retain];
- installed_ = iterator_.CurrentVer().end() ? nil : [[NSString stringWithCString:iterator_.CurrentVer().VerStr()] retain];
+ latest_ = [[NSString stringWithUTF8String:version_.VerStr()] retain];
+ installed_ = iterator_.CurrentVer().end() ? nil : [[NSString stringWithUTF8String:iterator_.CurrentVer().VerStr()] retain];
pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
const char *begin, *end;
parser->GetRec(begin, end);
- id_ = [[[NSString stringWithCString:iterator_.Name()] lowercaseString] retain];
+ id_ = [[[NSString stringWithUTF8String:iterator_.Name()] lowercaseString] retain];
name_ = Scour("Name", begin, end);
if (name_ != nil)
name_ = [name_ retain];
- tagline_ = [[NSString stringWithCString:parser->ShortDesc().c_str()] retain];
+ tagline_ = [[NSString stringWithUTF8String:parser->ShortDesc().c_str()] retain];
icon_ = Scour("Icon", begin, end);
if (icon_ != nil)
icon_ = [icon_ retain];
return nil;
}
+- (pkgCache::PkgIterator) iterator {
+ return iterator_;
+}
+
- (NSString *) section {
const char *section = iterator_.Section();
- return section == NULL ? nil : [[NSString stringWithCString:section] stringByReplacingCharacter:'_' withCharacter:' '];
+ return section == NULL ? nil : [[NSString stringWithUTF8String:section] stringByReplacingCharacter:'_' withCharacter:' '];
}
- (Address *) maintainer {
pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
- return [Address addressWithString:[NSString stringWithCString:parser->Maintainer().c_str()]];
+ return [Address addressWithString:[NSString stringWithUTF8String:parser->Maintainer().c_str()]];
}
- (size_t) size {
- (NSString *) description {
pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
- NSString *description([NSString stringWithCString:parser->LongDesc().c_str()]);
+ NSString *description([NSString stringWithUTF8String:parser->LongDesc().c_str()]);
NSArray *lines = [description componentsSeparatedByString:@"\n"];
NSMutableArray *trimmed = [NSMutableArray arrayWithCapacity:([lines count] - 1)];
return website_;
}
+- (NSArray *) relationships {
+ return relationships_;
+}
+
- (Source *) source {
if (!cached_) {
source_ = [[database_ getSource:file_.File()] retain];
buffer >> percent;
[delegate_ setProgressPercent:(percent / 100)];
- NSString *string = [NSString stringWithCString:(data + matches[8]) length:(matches[9] - matches[8])];
+ NSString *string = [NSString stringWithUTF8Bytes:(data + matches[8]) length:(matches[9] - matches[8])];
+
std::string type(line.substr(matches[2], matches[3] - matches[2]));
if (type == "pmerror")
std::string line;
while (std::getline(is, line))
- [delegate_ addProgressOutput:[NSString stringWithCString:line.c_str()]];
+ [delegate_ addProgressOutput:[NSString stringWithUTF8String:line.c_str()]];
[pool release];
_assert(false);
];
}
+ pkgDepCache::Policy Plcy;
+
[packages_ removeAllObjects];
for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator)
- if (Package *package = [Package packageWithIterator:iterator database:self])
- if ([package source] != nil || [package installed] != nil)
+ if (!Plcy.GetCandidateVer(iterator).end())
+ if (Package *package = [Package packageWithIterator:iterator database:self])
[packages_ addObject:package];
[packages_ sortUsingSelector:@selector(compareByName:)];
bool remove(false);
pkgCacheFile &cache([database_ cache]);
- for (pkgCache::PkgIterator iterator = cache->PkgBegin(); !iterator.end(); ++iterator) {
- Package *package([Package packageWithIterator:iterator database:database_]);
- NSString *name([package name]);
- bool essential((iterator->Flags & pkgCache::Flag::Essential) != 0);
+ 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)
else if (state.Downgrade())
[downgrading addObject:name];
else if (state.Delete()) {
- if (essential)
+ if ([package essential])
remove = true;
[removing addObject:name];
}
if (list != nil) {
[files_ addObjectsFromArray:[list componentsSeparatedByString:@"\n"]];
[files_ removeLastObject];
+ [files_ removeObjectAtIndex:0];
[files_ sortUsingSelector:@selector(compare:)];
+
+ NSMutableArray *stack = [NSMutableArray arrayWithCapacity:8];
+ [stack addObject:@"/"];
+
+ for (int i(0), e([files_ count]); i != e; ++i) {
+ NSString *file = [files_ objectAtIndex:i];
+ while (![file hasPrefix:[stack lastObject]])
+ [stack removeLastObject];
+ NSString *directory = [stack lastObject];
+ [stack addObject:[file stringByAppendingString:@"/"]];
+ [files_ replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%*s%@",
+ ([stack count] - 2) * 4, "",
+ [file substringFromIndex:[directory length]]
+ ]];
+ }
}
}
}
- (NSString *) title {
- return @"File Contents";
+ return @"Installed Files";
+}
+
+- (NSString *) backButtonTitle {
+ return @"Files";
}
@end
return number;
} else if ([package_ installed] != nil && group-- == 0)
return 2;
- else if (group-- == 0)
- return 4;
- else if ([package_ source] != nil && group-- == 0)
+ else if (group-- == 0) {
+ int number = 4;
+ if ([package_ relationships] != nil)
+ ++number;
+ return number;
+ } else if ([package_ source] != nil && group-- == 0)
return 3;
else _assert(false);
}
UIPreferencesTableCell *cell = [[[UIPreferencesTableCell alloc] init] autorelease];
[cell setShowSelection:NO];
- if (group-- == 0)
- switch (row) {
- case 0:
- [cell setTitle:[package_ name]];
- [cell setValue:[package_ latest]];
- break;
-
- case 1:
- [cell addSubview:description_];
- break;
-
- case 2:
- if ([package_ website] != nil) {
- [cell setTitle:@"More Information"];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- break;
- }
- case 3:
- [cell setIcon:[UIImage applicationImageNamed:@"trusted.png"]];
- [cell setValue:@"This package has been signed."];
- break;
-
- default: _assert(false);
- }
- else if ([package_ installed] != nil && group-- == 0)
- switch (row) {
- case 0: {
- [cell setTitle:@"Version"];
- NSString *installed([package_ installed]);
- [cell setValue:(installed == nil ? @"n/a" : installed)];
- } break;
-
- case 1:
- [cell setTitle:@"File Content"];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- break;
-
- default: _assert(false);
- }
- else if (group-- == 0)
- switch (row) {
- case 0:
- [cell setTitle:@"Identifier"];
- [cell setValue:[package_ id]];
- break;
-
- case 1: {
- [cell setTitle:@"Section"];
- NSString *section([package_ section]);
- [cell setValue:(section == nil ? @"n/a" : section)];
- } break;
-
- case 2:
- [cell setTitle:@"Expanded Size"];
- [cell setValue:SizeString([package_ size])];
- break;
-
- case 3:
- [cell setTitle:@"Maintainer"];
- [cell setValue:[[package_ maintainer] name]];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- break;
-
- default: _assert(false);
- }
- else if ([package_ source] != nil && group-- == 0)
- switch (row) {
- case 0:
- [cell setTitle:[[package_ source] label]];
- [cell setValue:[[package_ source] version]];
- break;
-
- case 1:
- [cell setValue:[[package_ source] description]];
- break;
-
- case 2:
- [cell setTitle:@"Origin"];
- [cell setValue:[[package_ source] origin]];
- break;
-
- default: _assert(false);
- }
- else _assert(false);
+ if (group-- == 0) {
+ if (row-- == 0) {
+ [cell setTitle:[package_ name]];
+ [cell setValue:[package_ latest]];
+ } else if (row-- == 0) {
+ [cell addSubview:description_];
+ } else if ([package_ website] != nil && row-- == 0) {
+ [cell setTitle:@"More Information"];
+ [cell setShowDisclosure:YES];
+ [cell setShowSelection:YES];
+ } else if ([[package_ source] trusted] && row-- == 0) {
+ [cell setIcon:[UIImage applicationImageNamed:@"trusted.png"]];
+ [cell setValue:@"This package has been signed."];
+ } else _assert(false);
+ } else if ([package_ installed] != nil && group-- == 0) {
+ if (row-- == 0) {
+ [cell setTitle:@"Version"];
+ NSString *installed([package_ installed]);
+ [cell setValue:(installed == nil ? @"n/a" : installed)];
+ } else if (row-- == 0) {
+ [cell setTitle:@"Filesystem Content"];
+ [cell setShowDisclosure:YES];
+ [cell setShowSelection:YES];
+ } else _assert(false);
+ } else if (group-- == 0) {
+ if (row-- == 0) {
+ [cell setTitle:@"Identifier"];
+ [cell setValue:[package_ id]];
+ } else if (row-- == 0) {
+ [cell setTitle:@"Section"];
+ NSString *section([package_ section]);
+ [cell setValue:(section == nil ? @"n/a" : section)];
+ } else if (row-- == 0) {
+ [cell setTitle:@"Expanded Size"];
+ [cell setValue:SizeString([package_ size])];
+ } else if (row-- == 0) {
+ [cell setTitle:@"Maintainer"];
+ [cell setValue:[[package_ maintainer] name]];
+ [cell setShowDisclosure:YES];
+ [cell setShowSelection:YES];
+ } else if ([package_ relationships] != nil && row-- == 0) {
+ [cell setTitle:@"Package Relationships"];
+ [cell setShowDisclosure:YES];
+ [cell setShowSelection:YES];
+ } else _assert(false);
+ } else if ([package_ source] != nil && group-- == 0) {
+ if (row-- == 0) {
+ [cell setTitle:[[package_ source] label]];
+ [cell setValue:[[package_ source] version]];
+ } else if (row-- == 0) {
+ [cell setValue:[[package_ source] description]];
+ } else if (row-- == 0) {
+ [cell setTitle:@"Origin"];
+ [cell setValue:[[package_ source] origin]];
+ } else _assert(false);
+ } else _assert(false);
return cell;
}
- (void) reloadData;
- (void) resetCursor;
+- (UISectionList *) list;
+
- (void) setShouldHideHeaderInShortLists:(BOOL)hide;
@end
[[list_ table] scrollPointVisibleAtTopLeft:CGPointMake(0, 0) animated:NO];
}
+- (UISectionList *) list {
+ return list_;
+}
+
- (void) setShouldHideHeaderInShortLists:(BOOL)hide {
[list_ setShouldHideHeaderInShortLists:hide];
}
timeoutInterval:30.0
];
- [request addValue:[NSString stringWithCString:Firmware_] forHTTPHeaderField:@"X-Firmware"];
- [request addValue:[NSString stringWithCString:Machine_] forHTTPHeaderField:@"X-Machine"];
- [request addValue:[NSString stringWithCString:SerialNumber_] forHTTPHeaderField:@"X-Serial-Number"];
+ [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) _showKeyboard:(BOOL)show {
+ CGSize keysize = [UIKeyboard defaultSize];
+ CGRect keydown = [book_ pageBounds];
+ CGRect keyup = keydown;
+ keyup.size.height -= keysize.height - ButtonBarHeight_;
+
+ float delay = KeyboardTime_ * ButtonBarHeight_ / keysize.height;
+
+ UIFrameAnimation *animation = [[[UIFrameAnimation alloc] initWithTarget:[table_ list]] autorelease];
+ [animation setSignificantRectFields:8];
+
+ if (show) {
+ [animation setStartFrame:keydown];
+ [animation setEndFrame:keyup];
+ } else {
+ [animation setStartFrame:keyup];
+ [animation setEndFrame:keydown];
+ }
+
+ UIAnimator *animator = [UIAnimator sharedAnimator];
+
+ [animator
+ addAnimations:[NSArray arrayWithObjects:animation, nil]
+ withDuration:(KeyboardTime_ - delay)
+ start:!show
+ ];
+
+ if (show)
+ [animator performSelector:@selector(startAnimation:) withObject:animation afterDelay:delay];
+
+ [delegate_ showKeyboard:show];
+}
+
- (void) textFieldDidBecomeFirstResponder:(UITextField *)field {
- [delegate_ showKeyboard:YES];
+ [self _showKeyboard:YES];
}
- (void) textFieldDidResignFirstResponder:(UITextField *)field {
- [delegate_ showKeyboard:NO];
+ [self _showKeyboard:NO];
}
- (void) keyboardInputChanged:(UIFieldEditor *)editor {
if ((self = [super initWithFrame:frame]) != nil) {
database_ = database;
+ if (Advanced_)
+ [navbar_ setBarStyle:1];
+
CGRect ovrrect = [navbar_ bounds];
ovrrect.size.height = [UINavigationBar defaultSizeWithPrompt].height - [UINavigationBar defaultSize].height;
CGRect indrect = {{indoffset, indoffset}, indsize};
indicator_ = [[UIProgressIndicator alloc] initWithFrame:indrect];
- [indicator_ setStyle:2];
+ [indicator_ setStyle:(Advanced_ ? 2 : 3)];
[overlay_ addSubview:indicator_];
CGSize prmsize = {200, indsize.width};
prompt_ = [[UITextLabel alloc] initWithFrame:prmrect];
- [prompt_ setColor:White_];
+ [prompt_ setColor:(Advanced_ ? White_ : Black_)];
[prompt_ setBackgroundColor:Clear_];
[prompt_ setFont:font];
buttonbar_ = [[UIButtonBar alloc]
initInView:overlay_
withFrame:CGRectMake(
- 0, screenrect.size.height - 48,
- screenrect.size.width, 48
+ 0, screenrect.size.height - ButtonBarHeight_,
+ screenrect.size.width, ButtonBarHeight_
)
withItemList:buttonitems
];
for (int i = 0; i != 5; ++i)
[[buttonbar_ viewWithTag:(i + 1)] setFrame:CGRectMake(
- i * 64 + 2, 1, 60, 48
+ i * 64 + 2, 1, 60, ButtonBarHeight_
)];
[buttonbar_ showSelectionForButton:1];
[[UIAnimator sharedAnimator]
addAnimations:[NSArray arrayWithObjects:animation, nil]
- withDuration:0.4f
+ withDuration:KeyboardTime_
start:YES
];
}