diff options
author | stuconnolly <stuart02@gmail.com> | 2009-08-29 19:39:28 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-08-29 19:39:28 +0000 |
commit | 08e024dd1af93f9b05a4bd18b227845822082175 (patch) | |
tree | 2fbfacf1f79ef2bbb20eecee999207f28c365343 /Source/SPCSVExporter.m | |
parent | fb82d1f21998fb4328bf04372477592e5a1af9f7 (diff) | |
download | sequelpro-08e024dd1af93f9b05a4bd18b227845822082175.tar.gz sequelpro-08e024dd1af93f9b05a4bd18b227845822082175.tar.bz2 sequelpro-08e024dd1af93f9b05a4bd18b227845822082175.zip |
More data export work.
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)]; |