#include <errno.h>
#include <pcre.h>
-#include <ext/hash_map>
-
#include "UICaboodle/BrowserView.h"
#include "substrate.h"
private:
CGColorRef color_;
+ static CGColorRef Create_(CGColorSpaceRef space, float red, float green, float blue, float alpha) {
+ CGFloat color[] = {red, green, blue, alpha};
+ return CGColorCreate(space, color);
+ }
+
public:
CYColor() :
color_(NULL)
}
CYColor(CGColorSpaceRef space, float red, float green, float blue, float alpha) :
- color_(NULL)
+ color_(Create_(space, red, green, blue, alpha))
{
Set(space, red, green, blue, alpha);
}
void Set(CGColorSpaceRef space, float red, float green, float blue, float alpha) {
Clear();
- float color[] = {red, green, blue, alpha};
- color_ = CGColorCreate(space, (CGFloat *) color);
+ color_ = Create_(space, red, green, blue, alpha);
}
operator CGColorRef() {
- (bool) upgrade;
- (void) update;
-- (void) setVisible;
-
- (void) updateWithStatus:(Status &)status;
- (void) setDelegate:(id)delegate;
CYString section_;
_transient NSString *section$_;
bool essential_;
- bool required_;
- bool visible_;
bool obsolete_;
NSString *latest_;
_transient NSDate *firstSeen_;
_transient NSDate *lastSeen_;
bool subscribed_;
+ bool ignored_;
}
- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
- (BOOL) hasMode;
- (NSString *) mode;
-- (void) setVisible;
-
- (NSString *) id;
- (NSString *) name;
- (UIImage *) icon;
- (uint32_t) compareBySection:(NSArray *)sections;
-- (uint32_t) compareForChanges;
-
- (void) install;
- (void) remove;
- (bool) isUnfilteredAndSearchedForBy:(NSString *)search;
- (bool) isUnfilteredAndSelectedForBy:(NSString *)search;
-- (bool) isInstalledAndVisible:(NSNumber *)number;
+- (bool) isInstalledAndUnfiltered:(NSNumber *)number;
- (bool) isVisibleInSection:(NSString *)section;
- (bool) isVisibleInSource:(Source *)source;
_end
}
-- (void) setVisible {
- visible_ = required_ && [self unfiltered];
-}
-
- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
if ((self = [super init]) != nil) {
_profile(Package$initWithVersion)
data[i] |= 0x20;
_end
- if (!file_.end()) {
- _profile(Package$initWithVersion$Source)
- source_ = [([database_ getSource:file_.File()] ?: (Source *) [NSNull null]) retain];
- _end
- }
-
- required_ = true;
-
_profile(Package$initWithVersion$Tags)
pkgCache::TagIterator tag(iterator_.TagList());
if (!tag.end()) {
[tags_ addObject:[(NSString *)CYStringCreate(name) autorelease]];
if (role_ == nil && strncmp(name, "role::", 6) == 0 /*&& strcmp(name, "role::leaper") != 0*/)
role_ = (NSString *) CYStringCreate(name + 6);
- if (required_ && strncmp(name, "require::", 9) == 0 && (
- true
- ))
- required_ = false;
++tag;
} while (!tag.end());
}
essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"];
_end
- _profile(Package$initWithVersion$setVisible)
- [self setVisible];
- _end
+ ignored_ = iterator_->SelectedState == pkgCache::State::Hold;
_end } return self;
}
if (section_.empty())
return nil;
- std::replace(section_.data(), section_.data() + section_.size(), '_', ' ');
- NSString *name(section_);
-
- lookup:
- if (NSDictionary *value = [SectionMap_ objectForKey:name])
- if (NSString *rename = [value objectForKey:@"Rename"]) {
- name = rename;
- goto lookup;
- }
-
- section$_ = name;
+ _profile(Package$section)
+ std::replace(section_.data(), section_.data() + section_.size(), '_', ' ');
+ NSString *name(section_);
+ section$_ = [SectionMap_ objectForKey:name] ?: name;
+ _end
} return section$_;
}
}
- (Address *) maintainer {
- if (file_.end())
+@synchronized (database_) {
+ if ([database_ era] != era_ || file_.end())
return nil;
+
pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
const std::string &maintainer(parser->Maintainer());
return maintainer.empty() ? nil : [Address addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
-}
+} }
- (size_t) size {
- return version_.end() ? 0 : version_->InstalledSize;
-}
+@synchronized (database_) {
+ if ([database_ era] != era_ || version_.end())
+ return 0;
+
+ return version_->InstalledSize;
+} }
- (NSString *) longDescription {
@synchronized (database_) {
}
- (BOOL) ignored {
- NSDictionary *metadata([self metadata]);
- if (NSNumber *ignored = [metadata objectForKey:@"IsIgnored"])
- return [ignored boolValue];
- else
- return false;
+ return ignored_;
}
- (NSString *) latest {
_profile(Package$upgradableAndEssential)
pkgCache::VerIterator current(iterator_.CurrentVer());
if (current.end())
- return essential && essential_ && visible_;
+ return essential && essential_;
else
- return !version_.end() && version_ != current;// && (!essential || ![database_ cache][iterator_].Keep());
+ return !version_.end() && version_ != current;
_end
}
return false;
_end
- NSString *section;
+ return true;
+}
- _profile(Package$unfiltered$section)
- section = [self section];
- _end
+- (BOOL) visible {
+ if (![self unfiltered])
+ return false;
- _profile(Package$unfiltered$isSectionVisible)
+ NSString *section([self section]);
+
+ _profile(Package$visible$isSectionVisible)
if (section != nil && !isSectionVisible(section))
return false;
_end
return true;
}
-- (BOOL) visible {
- return visible_;
-}
-
- (BOOL) half {
unsigned char current(iterator_->CurrentState);
return current == pkgCache::State::HalfConfigured || current == pkgCache::State::HalfInstalled;
icon = [UIImage imageAtPath:[static_cast<id>(icon_) substringFromIndex:7]];
if (icon == nil) if (section != nil)
icon = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]];
- if (icon == nil) if (source_ != nil) if (NSString *dicon = [source_ defaultIcon])
+ if (icon == nil) if (Source *source = [self source]) if (NSString *dicon = [source defaultIcon])
if ([dicon hasPrefix:@"file:///"])
// XXX: correct escaping
icon = [UIImage imageAtPath:[dicon substringFromIndex:7]];
return _not(uint32_t);
}
-- (uint32_t) compareForChanges {
- union {
- uint32_t key;
-
- struct {
- uint32_t timestamp : 30;
- uint32_t ignored : 1;
- uint32_t upgradable : 1;
- } bits;
- } value;
-
- bool upgradable([self upgradableAndEssential:YES]);
- value.bits.upgradable = upgradable ? 1 : 0;
-
- if (upgradable) {
- value.bits.timestamp = 0;
- value.bits.ignored = [self ignored] ? 0 : 1;
- value.bits.upgradable = 1;
- } else {
- value.bits.timestamp = static_cast<uint32_t>([[self seen] timeIntervalSince1970]) >> 2;
- value.bits.ignored = 0;
- value.bits.upgradable = 0;
- }
-
- return _not(uint32_t) - value.key;
-}
-
- (void) clear {
@synchronized (database_) {
pkgProblemResolver *resolver = [database_ resolver];
_end
}
-- (bool) isInstalledAndVisible:(NSNumber *)number {
- return ((![number boolValue] && ![role_ isEqualToString:@"cydia"]) || [self visible]) && ![self uninstalled];
+- (bool) isInstalledAndUnfiltered:(NSNumber *)number {
+ return ![self uninstalled] && (![number boolValue] && ![role_ isEqualToString:@"cydia"] || [self unfiltered]);
}
- (bool) isVisibleInSection:(NSString *)name {
- NSString *section = [self section];
+ NSString *section([self section]);
- return
- [self visible] && (
- name == nil ||
- section == nil && [name length] == 0 ||
- [name isEqualToString:section]
- );
+ return (
+ name == nil ||
+ section == nil && [name length] == 0 ||
+ [name isEqualToString:section]
+ ) && [self visible];
}
- (bool) isVisibleInSource:(Source *)source {
/* }}} */
static NSString *Colon_;
+static NSString *Elision_;
static NSString *Error_;
static NSString *Warning_;
return era_;
}
+- (void) releasePackages {
+ CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast<CFArrayApplierFunction>(&CFRelease), NULL);
+ CFArrayRemoveAllValues(packages_);
+}
+
- (void) dealloc {
// XXX: actually implement this thing
_assert(false);
- NSRecycleZone(zone_);
- // XXX: malloc_destroy_zone(zone_);
+ [self releasePackages];
apr_pool_destroy(pool_);
+ NSRecycleZone(zone_);
[super dealloc];
}
@synchronized (self) {
++era_;
- CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast<CFArrayApplierFunction>(&CFRelease), NULL);
- CFArrayRemoveAllValues(packages_);
-
+ [self releasePackages];
sources_.clear();
_error->Discard();
[self updateWithStatus:status_];
}
-- (void) setVisible {
- for (Package *package in [self packages])
- [package setVisible];
-}
-
- (void) updateWithStatus:(Status &)status {
_transient NSObject<ProgressDelegate> *delegate(status.getDelegate());
NSString *title(UCLocalize("REFRESHING_DATA"));
- (NSArray *) getInstalledPackages {
NSArray *packages([[Database sharedInstance] packages]);
- NSMutableArray *installed([NSMutableArray arrayWithCapacity:[packages count]]);
+ NSMutableArray *installed([NSMutableArray arrayWithCapacity:1024]);
for (Package *package in packages)
if ([package installed] != nil)
[installed addObject:package];
@end
@implementation ContentView
+
- (id) initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame]) != nil) {
- /* Fix landscape stretching. */
[self setNeedsDisplayOnBoundsChange:YES];
} return self;
}
[super drawRect:rect];
[delegate_ drawContentRect:rect];
}
+
+@end
+/* }}} */
+/* Cydia TableView Cell {{{ */
+@interface CYTableViewCell : UITableViewCell {
+ ContentView *content_;
+ bool highlighted_;
+}
+
+@end
+
+@implementation CYTableViewCell
+
+- (void) dealloc {
+ [content_ release];
+ [super dealloc];
+}
+
+- (void) _updateHighlightColorsForView:(id)view highlighted:(BOOL)highlighted {
+ //NSLog(@"_updateHighlightColorsForView:%@ highlighted:%s [content_=%@]", view, highlighted ? "YES" : "NO", content_);
+
+ if (view == content_) {
+ //NSLog(@"_updateHighlightColorsForView:content_ highlighted:%s", highlighted ? "YES" : "NO", content_);
+ highlighted_ = highlighted;
+ }
+
+ [super _updateHighlightColorsForView:view highlighted:highlighted];
+}
+
+- (void) setSelected:(BOOL)selected animated:(BOOL)animated {
+ //NSLog(@"setSelected:%s animated:%s", selected ? "YES" : "NO", animated ? "YES" : "NO");
+ highlighted_ = selected;
+
+ [super setSelected:selected animated:animated];
+ [content_ setNeedsDisplay];
+}
+
@end
/* }}} */
/* Package Cell {{{ */
-@interface PackageCell : UITableViewCell <
+@interface PackageCell : CYTableViewCell <
ContentDelegate
> {
UIImage *icon_;
NSString *source_;
UIImage *badge_;
Package *package_;
- UIColor *color_;
- ContentView *content_;
- BOOL faded_;
- float fade_;
UIImage *placard_;
}
- (void) dealloc {
[self clearPackage];
- [content_ release];
- [color_ release];
[super dealloc];
}
-- (float) fade {
- return faded_ ? [self selectionPercent] : fade_;
-}
-
- (PackageCell *) init {
CGRect frame(CGRectMake(0, 0, 320, 74));
if ((self = [super initWithFrame:frame reuseIdentifier:@"Package"]) != nil) {
[content_ setDelegate:self];
[content_ setOpaque:YES];
- if ([self respondsToSelector:@selector(selectionPercent)])
- faded_ = YES;
} return self;
}
}
- (void) drawContentRect:(CGRect)rect {
- bool selected([self isSelected]);
+ bool highlighted(highlighted_);
float width([self bounds].size.width);
#if 0
)];
}
- if (selected)
+ if (highlighted)
UISetColor(White_);
- if (!selected)
+ if (!highlighted)
UISetColor(commercial_ ? Purple_ : Black_);
[name_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - (placard_ == nil ? 80 : 106)) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
[source_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
- if (!selected)
+ if (!highlighted)
UISetColor(commercial_ ? Purplish_ : Gray_);
[description_ drawAtPoint:CGPointMake(12, 46) forWidth:(width - 46) withFont:Font14_ lineBreakMode:UILineBreakModeTailTruncation];
[placard_ drawAtPoint:CGPointMake(width - 52, 9)];
}
-- (void) setSelected:(BOOL)selected animated:(BOOL)fade {
- //[self _setBackgroundColor];
- [super setSelected:selected animated:fade];
- [content_ setNeedsDisplay];
-}
-
+ (int) heightForPackage:(Package *)package {
return 73;
}
@end
/* }}} */
/* Section Cell {{{ */
-@interface SectionCell : UITableViewCell <
+@interface SectionCell : CYTableViewCell <
ContentDelegate
> {
NSString *basic_;
NSString *name_;
NSString *count_;
UIImage *icon_;
- ContentView *content_;
UISwitch *switch_;
BOOL editing_;
}
[self clearSection];
[icon_ release];
[switch_ release];
- [content_ release];
-
[super dealloc];
}
}
- (void) drawContentRect:(CGRect)rect {
- BOOL selected = [self isSelected];
+ bool highlighted(highlighted_);
[icon_ drawInRect:CGRectMake(8, 7, 32, 32)];
- if (selected)
+ if (highlighted)
UISetColor(White_);
- if (!selected)
- UISetColor(Black_);
-
float width(rect.size.width);
if (editing_)
width -= 87;
+ if (!highlighted)
+ UISetColor(Black_);
[name_ drawAtPoint:CGPointMake(48, 9) forWidth:(width - 70) withFont:Font22Bold_ lineBreakMode:UILineBreakModeTailTruncation];
CGSize size = [count_ sizeWithFont:Font14_];
@end
/* }}} */
/* Source Cell {{{ */
-@interface SourceCell : UITableViewCell <
+@interface SourceCell : CYTableViewCell <
ContentDelegate
> {
UIImage *icon_;
NSString *origin_;
NSString *description_;
NSString *label_;
- ContentView *content_;
}
- (void) setSource:(Source *)source;
- (void) dealloc {
[self clearSource];
- [content_ release];
[super dealloc];
}
} return self;
}
-- (void) setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- [content_ setNeedsDisplay];
-}
-
- (void) drawContentRect:(CGRect)rect {
- bool selected([self isSelected]);
+ bool highlighted(highlighted_);
float width(rect.size.width);
if (icon_ != nil)
[icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
- if (selected)
+ if (highlighted)
UISetColor(White_);
- if (!selected)
+ if (!highlighted)
UISetColor(Black_);
[origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
- if (!selected)
+ if (!highlighted)
UISetColor(Blue_);
[label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
- if (!selected)
+ if (!highlighted)
UISetColor(Gray_);
[description_ drawAtPoint:CGPointMake(12, 46) forWidth:(width - 40) withFont:Font14_ lineBreakMode:UILineBreakModeTailTruncation];
}
- (NSString *) title { return UCLocalize("INSTALLED"); }
- (id) initWithDatabase:(Database *)database {
- if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndVisible:) with:[NSNumber numberWithBool:YES]]) != nil) {
+ if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndUnfiltered:) with:[NSNumber numberWithBool:YES]]) != nil) {
[self updateRoleButton];
[self queueStatusDidChange];
} return self;
[sections_ removeAllObjects];
[filtered_ removeAllObjects];
-#if 0
- typedef __gnu_cxx::hash_map<NSString *, Section *, NSStringMapHash, NSStringMapEqual> SectionMap;
- SectionMap sections;
- sections.resize(64);
-#else
NSMutableDictionary *sections([NSMutableDictionary dictionaryWithCapacity:32]);
-#endif
_trace();
for (Package *package in packages) {
NSString *name([package section]);
NSString *key(name == nil ? @"" : name);
-#if 0
- Section **section;
-
- _profile(SectionsView$reloadData$Section)
- section = §ions[key];
- if (*section == nil) {
- _profile(SectionsView$reloadData$Section$Allocate)
- *section = [[[Section alloc] initWithName:name localize:YES] autorelease];
- _end
- }
- _end
-
- [*section addToCount];
-
- _profile(SectionsView$reloadData$Filter)
- if (![package valid] || ![package visible])
- continue;
- _end
-
- [*section addToRow];
-#else
Section *section;
_profile(SectionsView$reloadData$Section)
_end
[section addToRow];
-#endif
}
_trace();
-#if 0
- for (SectionMap::const_iterator i(sections.begin()), e(sections.end()); i != e; ++i)
- [sections_ addObject:i->second];
-#else
[sections_ addObjectsFromArray:[sections allValues]];
-#endif
[sections_ sortUsingSelector:@selector(compareByLocalized:)];
- (void) _reloadPackages:(NSArray *)packages {
_trace();
for (Package *package in packages)
- if (
- [package uninstalled] && [package valid] && [package visible] ||
- [package upgradableAndEssential:YES]
- )
+ if ([package upgradableAndEssential:YES] || [package visible])
CFArrayAppendValue(packages_, package);
_trace();
[sections_ removeAllObjects];
-#if 0
+#if 1
UIProgressHUD *hud([delegate_ addProgressHUD]);
- // XXX: localize
- [hud setText:@"Loading Changes"];
+ [hud setText:UCLocalize("LOADING")];
//NSLog(@"HUD:%@::%@", delegate_, hud);
[self yieldToSelector:@selector(_reloadPackages:) withObject:packages];
[delegate_ removeProgressHUD:hud];
#endif
Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
- Section *ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") localize:NO] autorelease];
+ Section *ignored = nil;
Section *section = nil;
NSDate *last = nil;
}
[section addToCount];
- } else if ([package ignored])
+ } else if ([package ignored]) {
+ if (ignored == nil) {
+ ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") row:offset localize:NO] autorelease];
+ }
[ignored addToCount];
- else {
+ } else {
++upgrades_;
[upgradable addToCount];
}
}
- (void) onIgnored:(id)control {
- [self onSomething:(int) [control isOn] withKey:@"IsIgnored"];
+ // TODO: set Held state - possibly call out to dpkg, etc.
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Database *database_;
int tag_;
-
- UIKeyboard *keyboard_;
- int huds_;
+ int hudcount_;
+ NSURL *starturl_;
SectionsController *sections_;
ChangesController *changes_;
}
- (void) updateData {
- [database_ setVisible];
[self _updateData];
}
}
- (BOOL) hudIsShowing {
- return (huds_ > 0);
+ return (hudcount_ > 0);
}
- (void) applicationSuspend:(__GSEvent *)event {
while ([target modalViewController] != nil) target = [target modalViewController];
[[target view] addSubview:hud];
- huds_++;
+ hudcount_++;
return hud;
}
[hud show:NO];
[hud removeFromSuperview];
[window_ setUserInteractionEnabled:YES];
- huds_--;
+ hudcount_--;
}
- (CYViewController *) pageForPackage:(NSString *)name {
return nil;
}
-- (void) applicationOpenURL:(NSURL *)url {
- [super applicationOpenURL:url];
- int tag;
- if (CYViewController *page = [self pageForURL:url hasTag:&tag]) {
+- (BOOL) openCydiaURL:(NSURL *)url {
+ CYViewController *page = nil;
+ int tag = 0;
+
+ NSLog(@"open url: %@", url);
+
+ if ((page = [self pageForURL:url hasTag:&tag])) {
[self setPage:page];
tag_ = tag;
[tabbar_ setSelectedViewController:(tag_ == -1 ? nil : [[tabbar_ viewControllers] objectAtIndex:tag_])];
}
+
+ return !!page;
+}
+
+- (void) applicationOpenURL:(NSURL *)url {
+ [super applicationOpenURL:url];
+ NSLog(@"first: %@", url);
+ if (!loaded_) starturl_ = [url retain];
+ else [self openCydiaURL:url];
}
- (void) applicationWillResignActive:(UIApplication *)application {
[label setTextColor:[UIColor blackColor]];
[label setShadowColor:[UIColor whiteColor]];
[label setShadowOffset:CGSizeMake(0, 1)];
- [label setText:UCLocalize("LOADING_DATA")];
+ [label setText:[NSString stringWithFormat:Elision_, UCLocalize("LOADING"), nil]];
[container addSubview:label];
CGSize viewsize = [[tabbar_ view] frame].size;
[self reloadData];
PrintTimes();
- // Show the home page
- [tabbar_ setSelectedIndex:0];
- _setHomePage(self);
+ // Show the initial page
+ if (starturl_ == nil || ![self openCydiaURL:starturl_]) {
+ [tabbar_ setSelectedIndex:0];
+ _setHomePage(self);
+ }
+
+ [starturl_ release];
+ starturl_ = nil;
+
[window_ setUserInteractionEnabled:YES];
// XXX: does this actually slow anything down?
/* }}} */
Colon_ = UCLocalize("COLON_DELIMITED");
+ Elision_ = UCLocalize("ELISION");
Error_ = UCLocalize("ERROR");
Warning_ = UCLocalize("WARNING");