@protocol ProgressDelegate
- (void) addProgressEvent:(CydiaProgressEvent *)event;
- (void) setProgressPercent:(NSNumber *)percent;
+- (void) setProgressStatus:(NSDictionary *)status;
- (void) setProgressCancellable:(NSNumber *)cancellable;
- (bool) isProgressCancelled;
- (void) setTitle:(NSString *)title;
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 {
virtual void Stop() {
pkgAcquireStatus::Stop();
[delegate_ performSelectorOnMainThread:@selector(setProgressCancellable:) withObject:[NSNumber numberWithBool:NO] waitUntilDone:YES];
+ [delegate_ performSelectorOnMainThread:@selector(setProgressStatus:) withObject:nil waitUntilDone:YES];
}
};
/* }}} */
bool running_;
float percent_;
+ float current_;
+ float total_;
+ float speed_;
+
_H<NSMutableArray> events_;
_H<NSString> title_;
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
+ @"current",
@"events",
@"finish",
@"percent",
@"running",
+ @"speed",
@"title",
+ @"total",
nil];
}
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_;
}
[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
/* }}} */
[refreshbar_ setProgress:[percent floatValue]];
}
+- (void) setProgressStatus:(NSDictionary *)status {
+ if (status != nil)
+ [self setProgressPercent:[status objectForKey:@"Percent"]];
+}
+
- (void) setUpdateDelegate:(id)delegate {
updatedelegate_ = delegate;
}