diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-23 18:38:08 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-07 02:41:12 -0800 |
commit | bcbac8f75c0b4943a7d732192920abede6ac8cee (patch) | |
tree | 96a4770e11492c496c4e8346b6a6498c5d188122 | |
parent | b0b11d99657d83a32f186ec8e448982e2c30e2d3 (diff) |
Expose download stats to JavaScript.
-rw-r--r-- | MobileCydia.mm | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index c50934e..9ee0bd0 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1210,6 +1210,7 @@ bool isSectionVisible(NSString *section) { @protocol ProgressDelegate - (void) addProgressEvent:(CydiaProgressEvent *)event; - (void) setProgressPercent:(NSNumber *)percent; +- (void) setProgressStatus:(NSDictionary *)status; - (void) setProgressCancellable:(NSNumber *)cancellable; - (bool) isProgressCancelled; - (void) setTitle:(NSString *)title; @@ -1272,12 +1273,19 @@ class Status : virtual bool Pulse(pkgAcquire *Owner) { bool value = pkgAcquireStatus::Pulse(Owner); - float percent( + double percent( double(CurrentBytes + CurrentItems) / double(TotalBytes + TotalItems) ); - [delegate_ performSelectorOnMainThread:@selector(setProgressPercent:) withObject:[NSNumber numberWithFloat:percent] waitUntilDone:YES]; + [delegate_ performSelectorOnMainThread:@selector(setProgressStatus:) withObject:[NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:percent], @"Percent", + + [NSNumber numberWithDouble:CurrentBytes], @"Current", + [NSNumber numberWithDouble:TotalBytes], @"Total", + [NSNumber numberWithDouble:CurrentCPS], @"Speed", + nil] waitUntilDone:YES]; + if (value && ![delegate_ isProgressCancelled]) return true; else { @@ -1298,6 +1306,7 @@ class Status : virtual void Stop() { pkgAcquireStatus::Stop(); [delegate_ performSelectorOnMainThread:@selector(setProgressCancellable:) withObject:[NSNumber numberWithBool:NO] waitUntilDone:YES]; + [delegate_ performSelectorOnMainThread:@selector(setProgressStatus:) withObject:nil waitUntilDone:YES]; } }; /* }}} */ @@ -4892,6 +4901,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { bool running_; float percent_; + float current_; + float total_; + float speed_; + _H<NSMutableArray> events_; _H<NSString> title_; @@ -4905,11 +4918,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { + (NSArray *) _attributeKeys { return [NSArray arrayWithObjects: + @"current", @"events", @"finish", @"percent", @"running", + @"speed", @"title", + @"total", nil]; } @@ -4939,6 +4955,30 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSNumber numberWithFloat:percent_]; } +- (void) setCurrent:(float)value { + current_ = value; +} + +- (NSNumber *) current { + return [NSNumber numberWithFloat:current_]; +} + +- (void) setTotal:(float)value { + total_ = value; +} + +- (NSNumber *) total { + return [NSNumber numberWithFloat:total_]; +} + +- (void) setSpeed:(float)value { + speed_ = value; +} + +- (NSNumber *) speed { + return [NSNumber numberWithFloat:speed_]; +} + - (NSArray *) events { return events_; } @@ -5226,6 +5266,22 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self updateProgress]; } +- (void) setProgressStatus:(NSDictionary *)status { + if (status == nil) { + [progress_ setCurrent:0]; + [progress_ setTotal:0]; + [progress_ setSpeed:0]; + } else { + [progress_ setPercent:[[status objectForKey:@"Percent"] floatValue]]; + + [progress_ setCurrent:[[status objectForKey:@"Current"] floatValue]]; + [progress_ setTotal:[[status objectForKey:@"Total"] floatValue]]; + [progress_ setSpeed:[[status objectForKey:@"Speed"] floatValue]]; + } + + [self updateProgress]; +} + @end /* }}} */ @@ -6789,6 +6845,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [refreshbar_ setProgress:[percent floatValue]]; } +- (void) setProgressStatus:(NSDictionary *)status { + if (status != nil) + [self setProgressPercent:[status objectForKey:@"Percent"]]; +} + - (void) setUpdateDelegate:(id)delegate { updatedelegate_ = delegate; } |