diff options
Diffstat (limited to 'Source/SPCSVExporter.m')
-rw-r--r-- | Source/SPCSVExporter.m | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/Source/SPCSVExporter.m b/Source/SPCSVExporter.m index c4a33fb0..a157b051 100644 --- a/Source/SPCSVExporter.m +++ b/Source/SPCSVExporter.m @@ -49,22 +49,26 @@ @synthesize csvOutputEncoding; +@synthesize csvExportIsRunning; +@synthesize csvThreadShouldExit; + /** - * Initialize an instance of the exporter using the supplied file handle. + * Initialize an instance of the exporter setting some default values */ -- (id)initWithFileHandle:(NSFileHandle *)fileHandle +- (id)init { if ((self == [super init])) { - [self setCsvFileHandle:fileHandle]; + [self setCsvExportIsRunning:NO]; + [self setCsvThreadShouldExit:NO]; } return self; } /** - * + * Start the CSV export process. */ -- (BOOL)startCSVExport +- (BOOL)startExportProcess { // Check that we have all the required info before starting the export if ((![self csvFileHandle]) || @@ -94,10 +98,14 @@ if (delegate && [delegate respondsToSelector:@selector(exportProcessDidStart:)]) { [delegate exportProcessDidStart:self]; } + + [self setCsvExportIsRunning:YES]; // Start the export in a new thread [NSThread detachNewThreadSelector:@selector(startCSVExportInBackgroundThread) toTarget:self withObject:nil]; + [self setCsvExportIsRunning:NO]; + // Tell the delegate that the export process has ended if (delegate && [delegate respondsToSelector:@selector(exportProcessDidEnd:)]) { [delegate exportProcessDidEnd:self]; @@ -107,6 +115,18 @@ } /** + * Stop the CSV export process by killing the export thread and cleaning up if its running. + */ +- (BOOL)stopExportProcess +{ + if (![self csvExportIsRunning]) return NO; + + // Kill the running thread here + + return YES; +} + +/** * Dealloc */ - (void)dealloc @@ -210,6 +230,13 @@ // Walk through the supplied data constructing the CSV string for (i = startingRow; i < totalRows; i++) { + // Check if we should stop and exit the export operation + if ([self csvThreadShouldExit]) { + [pool release]; + + return; + } + // Update the progress value if (totalRows) [self setProgressValue:(((i + 1) * 100) / totalRows)]; |