#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_;
- (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());
}
obsolete_ = [self hasTag:@"cydia::obsolete"];
essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"];
_end
-
- _profile(Package$initWithVersion$setVisible)
- [self setVisible];
- _end
_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$_;
}
_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;
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_;
[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"));
@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];
}
- (void) updateData {
- [database_ setVisible];
[self _updateData];
}
[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;
/* }}} */
Colon_ = UCLocalize("COLON_DELIMITED");
+ Elision_ = UCLocalize("ELISION");
Error_ = UCLocalize("ERROR");
Warning_ = UCLocalize("WARNING");