CatNiP prefinal
Sähköinen nuottikirja, HY-TKTKL-OHTUPROJ KESÄ11
|
MediaWikiDownload saves a remote file to local storage. More...
#import <MediaWikiDownload.h>
Public Member Functions | |
(void) | - abortRead |
Aborts the data transfer in progress. | |
(void) | - addProgressListener: |
Adds a progress listener object to this object's listeners. | |
(NSString *) | - buildQueryURL |
Builds the query URL, intended to be easily re-implemented in sublcasses. | |
(void) | - connection:didFailWithError: |
NSURLConnection delegate method. | |
(void) | - connection:didReceiveData: |
NSURLConnection delegate method. | |
(void) | - connection:didReceiveResponse: |
NSURLConnection delegate method. | |
(void) | - connectionDidFinishLoading: |
NSURLConnection delegate method. | |
(id) | - init [implementation] |
Initializes the object. | |
(id) | - initWithDelegate: |
Initialize a new MediaWikiDownload object with the specified delegate. | |
(id) | - initWithDelegate:mediaWikiURL: |
Initialize a new MediaWikiDownload object with the specified delegate and MediaWiki URL (as a string) | |
(void) | - removeProgressListener: |
Removes a progress listener object from this object's listeners. | |
(BOOL) | - startQuery |
Launches the query process. | |
Protected Attributes | |
NSURLConnection * | mediaWikiConnection |
NSMutableURLRequest * | mediaWikiRequest |
NSFileHandle * | outHandle |
NSString * | outputPath |
NSMutableSet * | progressListeners |
id< MediaWikiDownloadDelegate > | queryDelegate |
NSMutableData * | receivedData |
BOOL | working |
Properties | |
NSInteger | currentBytes |
Manual accessor for currentBytes. | |
NSInteger | expectedSize |
Manual accessor for expectedSize. | |
NSString * | mediaWikiFilename |
The filename of the file to download. | |
NSString * | mediaWikiURLString |
The base URL for this MediaWiki query. |
MediaWikiDownload saves a remote file to local storage.
MediaWikiDownload is designed to fetch an attachment file from a MediaWiki site, specifically IMSLP. It sets any cookies required and manually saves the data to the temp directory, moving it to the Documents storage once complete.
A succesful download is reported to the delegate.
Created by Antti V J Niemela, tkol on 6/7/11. Copyright 2011 University of Helsinki. All rights reserved.
Definition at line 15 of file MediaWikiDownload.h.
- (void) abortRead |
Aborts the data transfer in progress.
The temporary file (if it exists) is not destroyed.
Definition at line 297 of file MediaWikiDownload.m.
References mediaWikiConnection, outHandle, outputPath, and working.
- (void) addProgressListener: | (id <MediaWikiProgressListener>) | listener |
Adds a progress listener object to this object's listeners.
Progress Listeners receive periodic updates on the progress of the data transfer taking place. Multiple listeners are supported.
listener | A MediaWikiProgressListener that should receive updates. |
Definition at line 274 of file MediaWikiDownload.m.
References progressListeners.
- (NSString *) buildQueryURL |
Builds the query URL, intended to be easily re-implemented in sublcasses.
Builds the query URL.
The URL is based on the mediaWikiURLString property. The filename property is appended to the base URL to receive the final, complete URL to download.
Definition at line 95 of file MediaWikiDownload.m.
- (void) connection: | (NSURLConnection *) | connection | |
didFailWithError: | (NSError *) | error | |
NSURLConnection delegate method.
NSURLConnectionDelegate implementation, reports the error with NSLog and cleans file handles.
The temporary file that might have been created is not destroyed.
Definition at line 214 of file MediaWikiDownload.m.
References mediaWikiConnection, outHandle, outputPath, CatNiPErrorManager::reportError:, CatNiPErrorManager::sharedManager, and working.
- (void) connection: | (NSURLConnection *) | connection | |
didReceiveData: | (NSData *) | data | |
NSURLConnection delegate method.
NSURLConnectionDelegate implementation, passes the data to a filehandle and updates any MediaWikiProgressListeners.
Definition at line 200 of file MediaWikiDownload.m.
References currentBytes, outHandle, and progressListeners.
- (void) connection: | (NSURLConnection *) | connection | |
didReceiveResponse: | (NSURLResponse *) | response | |
NSURLConnection delegate method.
NSURLConnectionDelegate implementation, resets the output file handle (only the data from the last response is stuff we're interested in).
Definition at line 159 of file MediaWikiDownload.m.
References expectedSize, outHandle, and outputPath.
- (void) connectionDidFinishLoading: | (NSURLConnection *) | connection |
NSURLConnection delegate method.
NSURLConnectionDelegate implementation, informs the MediaWikiDownloadDelegate about a succesful download.
Definition at line 237 of file MediaWikiDownload.m.
References mediaWikiConnection, outHandle, outputPath, queryDelegate, CatNiPErrorManager::reportError:, CatNiPErrorManager::sharedManager, and working.
- (id) init | [implementation] |
Initializes the object.
Definition at line 43 of file MediaWikiDownload.m.
References currentBytes, expectedSize, and progressListeners.
- (id) initWithDelegate: | (id <MediaWikiDownloadDelegate>) | mediaWikiDownloadDelegate |
Initialize a new MediaWikiDownload object with the specified delegate.
Initializes the object with the specified delegate.
MediaWikiDownloadDelegate | The delegate object that will receive the data read from the URL |
Definition at line 58 of file MediaWikiDownload.m.
References init, queryDelegate, and working.
- (id) initWithDelegate: | (id <MediaWikiDownloadDelegate>) | mediaWikiDownloadDelegate | |
mediaWikiURL: | (NSString*) | mwURLString | |
Initialize a new MediaWikiDownload object with the specified delegate and MediaWiki URL (as a string)
Initializes the object with the specified delegate and MediaWiki URL.
MediaWikiDownloadDelegate | The delegate object that will receive the data read from the URL |
mwURLString | The URL to read from. |
Definition at line 78 of file MediaWikiDownload.m.
References initWithDelegate:.
- (void) removeProgressListener: | (id <MediaWikiProgressListener>) | listener |
Removes a progress listener object from this object's listeners.
listener | The listener to remove from this object's listener set. |
Definition at line 287 of file MediaWikiDownload.m.
References progressListeners.
- (BOOL) startQuery |
Launches the query process.
Starts the MediaWiki query.
Starts the HTTP query represented by the URL received using [self buildQueryURL] using an internal NSURLConnection object. This object functions as the delegate for the NSURLConnection, and passes the read data to it's delegate once the connection finishes loading.
Definition at line 107 of file MediaWikiDownload.m.
References buildQueryURL, mediaWikiConnection, mediaWikiFilename, mediaWikiRequest, CatNiPErrorManager::reportError:, CatNiPErrorManager::sharedManager, and working.
- (NSURLConnection*) mediaWikiConnection [protected] |
Definition at line 20 of file MediaWikiDownload.h.
- (NSMutableURLRequest*) mediaWikiRequest [protected] |
Definition at line 19 of file MediaWikiDownload.h.
- (NSFileHandle*) outHandle [protected] |
Definition at line 22 of file MediaWikiDownload.h.
- (NSString*) outputPath [protected] |
Definition at line 23 of file MediaWikiDownload.h.
- (NSMutableSet*) progressListeners [protected] |
Definition at line 26 of file MediaWikiDownload.h.
- (id<MediaWikiDownloadDelegate>) queryDelegate [protected] |
Definition at line 16 of file MediaWikiDownload.h.
- (NSMutableData*) receivedData [protected] |
Definition at line 21 of file MediaWikiDownload.h.
- (BOOL) working [protected] |
Definition at line 27 of file MediaWikiDownload.h.
- (NSInteger) currentBytes [read, assign] |
Manual accessor for currentBytes.
Definition at line 25 of file MediaWikiDownload.h.
- (NSInteger) expectedSize [read, assign] |
Manual accessor for expectedSize.
Only available once a NSURLResponse has been received from the target host. Returns NSIntegerMin if a response has not yet been received, and -1 when a response has been received but it did not contain information on the size of the response.
Definition at line 24 of file MediaWikiDownload.h.
- (NSString *) mediaWikiFilename [read, write, copy] |
The filename of the file to download.
Definition at line 18 of file MediaWikiDownload.h.
- (NSString *) mediaWikiURLString [read, write, copy] |
The base URL for this MediaWiki query.
Definition at line 17 of file MediaWikiDownload.h.