mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
More implementation of NSProgress
This commit is contained in:
parent
c72ebff803
commit
a983e7222d
2 changed files with 41 additions and 11 deletions
|
@ -40,6 +40,9 @@ typedef NSString* NSProgressKind;
|
|||
typedef NSString* NSProgressUserInfoKey;
|
||||
typedef NSString* NSProgressFileOperationKind;
|
||||
|
||||
DEFINE_BLOCK_TYPE(GSProgressCancellationHandler, void, void);
|
||||
DEFINE_BLOCK_TYPE(GSProgressPausingHandler, void, void);
|
||||
|
||||
@interface NSProgress : NSObject
|
||||
{
|
||||
#if GS_EXPOSE(NSProgress)
|
||||
|
@ -58,9 +61,10 @@ GS_NSProgress_IVARS;
|
|||
@private id _internal GS_UNUSED_IVAR;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
DEFINE_BLOCK_TYPE(NSProgressPublishingHandler, void, NSProgress*);
|
||||
DEFINE_BLOCK_TYPE(NSProgressUnpublishingHandler, void, void);
|
||||
DEFINE_BLOCK_TYPE(GSProgressPendingUnitCountBlock, void, void);
|
||||
|
||||
// Creating progress objects...
|
||||
- (instancetype)initWithParent: (NSProgress *)parent
|
||||
|
@ -94,13 +98,11 @@ DEFINE_BLOCK_TYPE(NSProgressUnpublishingHandler, void, void);
|
|||
- (BOOL) isCancellable;
|
||||
- (BOOL) isCancelled;
|
||||
- (void) cancel;
|
||||
DEFINE_BLOCK_TYPE(GSProgressCancellationHandler, void, void);
|
||||
- (void) setCancellationHandler: (GSProgressCancellationHandler) handler;
|
||||
|
||||
- (BOOL) isPausable;
|
||||
- (BOOL) isPaused;
|
||||
- (void) pause;
|
||||
DEFINE_BLOCK_TYPE(GSProgressPausingHandler, void, void);
|
||||
- (void) setPausingHandler: (GSProgressPausingHandler) handler;
|
||||
|
||||
- (void) resume;
|
||||
|
@ -134,7 +136,6 @@ DEFINE_BLOCK_TYPE(GSProgressResumingHandler, void, void);
|
|||
// Instance methods
|
||||
- (void) publish;
|
||||
- (void) unpublish;
|
||||
DEFINE_BLOCK_TYPE(GSProgressPendingUnitCountBlock, void, void);
|
||||
- (void)performAsCurrentWithPendingUnitCount: (int64_t)unitCount
|
||||
usingBlock: (GSProgressPendingUnitCountBlock)work;
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
BOOL _indeterminate; \
|
||||
BOOL _finished; \
|
||||
double _fractionCompleted; \
|
||||
GSProgressCancellationHandler _cancellationHandler; \
|
||||
NSProgress *_parent;
|
||||
|
||||
#define EXPOSE_NSProgress_IVARS
|
||||
|
@ -49,15 +50,18 @@
|
|||
#import <Foundation/NSObject.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSProgress.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
#import <Foundation/NSURL.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSProgress.h>
|
||||
|
||||
#define GSInternal NSProgressInternal
|
||||
#include "GSInternal.h"
|
||||
GS_PRIVATE_INTERNAL(NSProgress)
|
||||
|
||||
// NSProgress for current thread....
|
||||
static NSProgress *__currentProgress = nil;
|
||||
|
||||
@implementation NSProgress
|
||||
|
||||
// Creating progress objects...
|
||||
|
@ -90,7 +94,7 @@ GS_PRIVATE_INTERNAL(NSProgress)
|
|||
internal->_indeterminate = NO;
|
||||
internal->_finished = NO;
|
||||
internal->_fractionCompleted = 0.0;
|
||||
internal->_parent = parent;
|
||||
internal->_parent = parent; // this is a weak reference and not retained.
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -98,6 +102,13 @@ GS_PRIVATE_INTERNAL(NSProgress)
|
|||
- (void) dealloc
|
||||
{
|
||||
RELEASE(internal->_userInfo);
|
||||
RELEASE(internal->_fileOperationKind);
|
||||
RELEASE(internal->_kind);
|
||||
RELEASE(internal->_estimatedTimeRemaining);
|
||||
RELEASE(internal->_fileCompletedCount);
|
||||
RELEASE(internal->_fileTotalCount);
|
||||
RELEASE(internal->_throughput);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -127,23 +138,38 @@ GS_PRIVATE_INTERNAL(NSProgress)
|
|||
return AUTORELEASE(p);
|
||||
}
|
||||
|
||||
// Private methods
|
||||
- (void) _setParent: (NSProgress *)p
|
||||
{
|
||||
internal->_parent = p; // Not retained since this is defined in docs as a weak reference
|
||||
}
|
||||
|
||||
- (NSProgress *) _parent
|
||||
{
|
||||
return internal->_parent;
|
||||
}
|
||||
|
||||
// Current progress
|
||||
+ (NSProgress *)currentProgress
|
||||
{
|
||||
return nil;
|
||||
return __currentProgress;
|
||||
}
|
||||
|
||||
- (void)becomeCurrentWithPendingUnitCount:(int64_t)unitCount
|
||||
{
|
||||
[self setTotalUnitCount: unitCount];
|
||||
__currentProgress = self;
|
||||
}
|
||||
|
||||
- (void)addChild:(NSProgress *)child withPendingUnitCount: (int64_t)inUnitCount
|
||||
{
|
||||
[child _setParent: self];
|
||||
[child setTotalUnitCount: inUnitCount];
|
||||
}
|
||||
|
||||
- (void)resignCurrent
|
||||
{
|
||||
__currentProgress = nil;
|
||||
}
|
||||
|
||||
// Reporting progress
|
||||
|
@ -288,7 +314,7 @@ GS_PRIVATE_INTERNAL(NSProgress)
|
|||
|
||||
- (void) setEstimatedTimeRemaining: (NSNumber *)n
|
||||
{
|
||||
ASSIGN(internal->_estimatedTimeRemaining, n);
|
||||
ASSIGNCOPY(internal->_estimatedTimeRemaining, n);
|
||||
}
|
||||
|
||||
- (NSNumber *) estimatedTimeRemaining
|
||||
|
@ -298,29 +324,32 @@ GS_PRIVATE_INTERNAL(NSProgress)
|
|||
|
||||
- (void) setFileCompletedCount: (NSNumber *)n
|
||||
{
|
||||
ASSIGNCOPY(internal->_fileCompletedCount, n);
|
||||
}
|
||||
|
||||
- (NSNumber *) fileCompletedCount
|
||||
{
|
||||
return nil;
|
||||
return internal->_fileCompletedCount;
|
||||
}
|
||||
|
||||
- (void) setFileTotalCount: (NSNumber *)n
|
||||
{
|
||||
ASSIGNCOPY(internal->_fileTotalCount, n);
|
||||
}
|
||||
|
||||
- (NSNumber *) fileTotalCount
|
||||
{
|
||||
return nil;
|
||||
return internal->_fileTotalCount;
|
||||
}
|
||||
|
||||
- (void) setThroughput: (NSNumber *)n
|
||||
{
|
||||
ASSIGNCOPY(internal->_throughput, n);
|
||||
}
|
||||
|
||||
- (NSNumber *) throughtput
|
||||
{
|
||||
return nil;
|
||||
return internal->_throughput;
|
||||
}
|
||||
|
||||
// Instance methods
|
||||
|
|
Loading…
Reference in a new issue