Changeset 6667


Ignore:
Timestamp:
Aug 31, 2008, 7:47:11 PM (13 years ago)
Author:
livings124
Message:

initial separation of blocklist downloader and the corresponding view

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Transmission.xcodeproj/project.pbxproj

    r6666 r6667  
    8484                A22180980D148A71007D09ED /* GroupsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = A22180970D148A71007D09ED /* GroupsWindowController.m */; };
    8585                A22180B60D148F0F007D09ED /* GroupsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A22180B50D148F0F007D09ED /* GroupsWindow.xib */; };
     86                A222E9870E6B21D9009FB003 /* BlocklistDownloaderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A222E9860E6B21D9009FB003 /* BlocklistDownloaderViewController.m */; };
    8687                A224D2640DAAC55F000954EA /* Peers.png in Resources */ = {isa = PBXBuildFile; fileRef = A224D2630DAAC55F000954EA /* Peers.png */; };
    8788                A2265F420B5EF5F40093DDA5 /* FileNameCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A2265F400B5EF5F40093DDA5 /* FileNameCell.m */; };
     
    494495                A22180970D148A71007D09ED /* GroupsWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GroupsWindowController.m; path = macosx/GroupsWindowController.m; sourceTree = "<group>"; };
    495496                A22180B50D148F0F007D09ED /* GroupsWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = GroupsWindow.xib; path = macosx/GroupsWindow.xib; sourceTree = "<group>"; };
     497                A222E9850E6B21D9009FB003 /* BlocklistDownloaderViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BlocklistDownloaderViewController.h; path = macosx/BlocklistDownloaderViewController.h; sourceTree = "<group>"; };
     498                A222E9860E6B21D9009FB003 /* BlocklistDownloaderViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BlocklistDownloaderViewController.m; path = macosx/BlocklistDownloaderViewController.m; sourceTree = "<group>"; };
    496499                A223AA7D0D220CEB00840069 /* nl */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = nl; path = macosx/nl.lproj/Creator.xib; sourceTree = "<group>"; };
    497500                A223AA7E0D220CEB00840069 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = macosx/nl.lproj/InfoPlist.strings; sourceTree = "<group>"; };
     
    963966                                A2D307A20D9EC6870051FD27 /* BlocklistDownloader.h */,
    964967                                A2D307A30D9EC6870051FD27 /* BlocklistDownloader.m */,
     968                                A222E9850E6B21D9009FB003 /* BlocklistDownloaderViewController.h */,
     969                                A222E9860E6B21D9009FB003 /* BlocklistDownloaderViewController.m */,
    965970                                A2DF567C0DE323D3000795D5 /* QuickLook.h */,
    966971                                A2DF57720DE46A6A000795D5 /* QuickLookController.h */,
     
    20032008                                A28F4F770E085BDC003A3882 /* ColorTextField.m in Sources */,
    20042009                                A27F0F330E19AD9800B2DB97 /* TorrentGroup.m in Sources */,
     2010                                A222E9870E6B21D9009FB003 /* BlocklistDownloaderViewController.m in Sources */,
    20052011                        );
    20062012                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/macosx/BlocklistDownloader.h

    r6274 r6667  
    2626#import <transmission.h>
    2727
    28 @class PrefsController;
     28@class BlocklistDownloaderViewController;
    2929
    3030@interface BlocklistDownloader : NSObject
    31 {   
    32     PrefsController * fPrefsController;
     31{
     32    NSURLDownload * fDownload;
    3333   
    34     IBOutlet NSWindow * fStatusWindow;
    35     IBOutlet NSProgressIndicator * fProgressBar;
    36     IBOutlet NSTextField * fTextField;
    37     IBOutlet NSButton * fButton;
     34    #warning have to store???
     35    tr_handle * fHandle;
    3836   
    39     NSURLDownload * fDownload;
     37    BlocklistDownloaderViewController * fViewController;
    4038   
    4139    NSUInteger fCurrentSize;
     
    4341}
    4442
    45 + (void) downloadWithPrefsController: (PrefsController *) prefsController; //only use when no other blocklist is downloading
     43+ (BlocklistDownloader *) downloader: (tr_handle *) handle;
     44- (void) setViewController: (BlocklistDownloaderViewController *) viewController;
    4645
    47 - (void) cancelDownload: (id) sender;
     46- (void) cancelDownload;
    4847
    4948@end
  • trunk/macosx/BlocklistDownloader.m

    r6640 r6667  
    2424
    2525#import "BlocklistDownloader.h"
    26 #import "PrefsController.h"
    27 #import "NSStringAdditions.h"
     26#import "BlocklistDownloaderViewController.h"
    2827#import "NSApplicationAdditions.h"
    2928
     
    3332@interface BlocklistDownloader (Private)
    3433
    35 - (id) initWithPrefsController: (PrefsController *) prefsController;
     34- (id) initWithHandle: (tr_handle *) handle;
    3635- (void) startDownload;
    3736- (void) finishDownloadSuccess;
    38 - (void) updateProcessString;
    39 - (void) failureSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info;
    4037
    4138@end
     
    4340@implementation BlocklistDownloader
    4441
    45 + (void) downloadWithPrefsController: (PrefsController *) prefsController
     42BlocklistDownloader * fDownloader = nil;
     43+ (BlocklistDownloader *) downloader: (tr_handle *) handle
    4644{
    47     BlocklistDownloader * downloader = [[BlocklistDownloader alloc] initWithPrefsController: prefsController];
    48     [downloader startDownload];
     45    if (!fDownloader)
     46    {
     47        fDownloader = [[BlocklistDownloader alloc] initWithHandle: handle];
     48        [fDownloader startDownload];
     49    }
     50   
     51    return fDownloader;
    4952}
    5053
    51 - (void) awakeFromNib
     54- (void) setViewController: (BlocklistDownloaderViewController *) viewController
    5255{
    53     [fButton setTitle: NSLocalizedString(@"Cancel", "Blocklist -> cancel button")];
    54    
    55     float oldWidth = [fButton frame].size.width;
    56     [fButton sizeToFit];
    57     NSRect buttonFrame = [fButton frame];
    58     buttonFrame.origin.x -= buttonFrame.size.width - oldWidth;
    59     [fButton setFrame: buttonFrame];
    60    
    61     [fTextField setStringValue: [NSLocalizedString(@"Connecting to site", "Blocklist -> message") stringByAppendingEllipsis]];
    62    
    63     [fProgressBar setUsesThreadedAnimation: YES];
    64     [fProgressBar startAnimation: self];
     56    fViewController = viewController;
     57    if (fViewController)
     58    {
     59        #warning set actual status
     60        [fViewController setStatusStarting];
     61    }
    6562}
    6663
     
    7168}
    7269
    73 - (void) cancelDownload: (id) sender
     70- (void) cancelDownload
    7471{
     72    [fViewController setFinished];
     73   
    7574    [fDownload cancel];
    7675   
    77     [NSApp endSheet: fStatusWindow];
    78     [fStatusWindow orderOut: self];
     76    fDownloader = nil;
    7977    [self release];
    8078}
     
    8583    fExpectedSize = [response expectedContentLength];
    8684   
    87     //change from indeterminate to progress
    88     [fProgressBar setIndeterminate: fExpectedSize == NSURLResponseUnknownLength];
    89     [self updateProcessString];
     85    [fViewController setStatusProgressForCurrentSize: fCurrentSize expectedSize: fExpectedSize];
    9086}
    9187
     
    9389{
    9490    fCurrentSize += length;
    95     [self updateProcessString];
     91    [fViewController setStatusProgressForCurrentSize: fCurrentSize expectedSize: fExpectedSize];
    9692}
    9793
     94#warning release?
    9895- (void) download: (NSURLDownload *) download didFailWithError: (NSError *) error
    9996{
    100     [fProgressBar setHidden: YES];
     97    [fViewController setFailed: [error localizedDescription]];
    10198   
    102     [NSApp endSheet: fStatusWindow];
    103     [fStatusWindow orderOut: self];
    104    
    105     NSAlert * alert = [[[NSAlert alloc] init] autorelease];
    106     [alert addButtonWithTitle: NSLocalizedString(@"OK", "Blocklist -> button")];
    107     [alert setMessageText: NSLocalizedString(@"Download of the blocklist failed.", "Blocklist -> message")];
    108     [alert setAlertStyle: NSWarningAlertStyle];
    109    
    110     [alert setInformativeText: [NSString stringWithFormat: @"%@ - %@", NSLocalizedString(@"Error", "Blocklist -> message"),
    111         [error localizedDescription]]];
    112    
    113     [alert beginSheetModalForWindow: [fPrefsController window] modalDelegate: self
    114         didEndSelector: @selector(failureSheetClosed:returnCode:contextInfo:) contextInfo: nil];
     99    fDownloader = nil;
     100    [self release];
    115101}
    116102
     
    127113@implementation BlocklistDownloader (Private)
    128114
    129 - (id) initWithPrefsController: (PrefsController *) prefsController
     115- (id) initWithHandle: (tr_handle *) handle
    130116{
    131117    if ((self = [super init]))
    132118    {
    133         fPrefsController = prefsController;
     119        fHandle = handle;
    134120    }
    135121   
     
    139125- (void) startDownload
    140126{
    141     //load window and show as sheet
    142     [NSBundle loadNibNamed: @"BlocklistStatusWindow" owner: self];
    143     [NSApp beginSheet: fStatusWindow modalForWindow: [fPrefsController window] modalDelegate: nil didEndSelector: nil contextInfo: nil];
    144    
    145     //start the download
    146127    NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: LIST_URL]];
    147128   
     
    154135    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    155136   
    156     //change to indeterminate while processing
    157     [fProgressBar setIndeterminate: YES];
    158     [fProgressBar startAnimation: self];
    159    
    160     [fTextField setStringValue: [NSLocalizedString(@"Processing blocklist", "Blocklist -> message") stringByAppendingEllipsis]];
    161     [fButton setEnabled: NO];
    162     [fStatusWindow display]; //force window to be updated
     137    [fViewController setStatusProcessing];
    163138   
    164139    //process data
    165     tr_blocklistSetContent([fPrefsController handle], [DESTINATION UTF8String]);
     140    tr_blocklistSetContent(fHandle, [DESTINATION UTF8String]);
    166141   
    167142    //delete downloaded file
     
    171146        [[NSFileManager defaultManager] removeFileAtPath: DESTINATION handler: nil];
    172147   
    173     [fPrefsController updateBlocklistFields];
     148    [fViewController setFinished];
    174149   
    175     [NSApp endSheet: fStatusWindow];
    176     [fStatusWindow orderOut: self];
     150    #warning update date
     151    [[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
    177152   
    178153    [pool release];
    179     [self release];
    180 }
    181 
    182 - (void) updateProcessString
    183 {
    184     NSString * string = NSLocalizedString(@"Downloading blocklist", "Blocklist -> message");
    185     if (fExpectedSize != NSURLResponseUnknownLength)
    186     {
    187         NSString * substring = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Blocklist -> message"),
    188                                 [NSString stringForFileSize: fCurrentSize], [NSString stringForFileSize: fExpectedSize]];
    189         string = [string stringByAppendingFormat: @" (%@)",  substring];
    190         [fProgressBar setDoubleValue: (double)fCurrentSize / fExpectedSize];
    191     }
    192154   
    193     [fTextField setStringValue: string];
    194 }
    195 
    196 - (void) failureSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info
    197 {
    198     [[alert window] orderOut: nil];
     155    fDownloader = nil;
    199156    [self release];
    200157}
  • trunk/macosx/Controller.m

    r6556 r6667  
    560560- (void) applicationWillTerminate: (NSNotification *) notification
    561561{
     562    #warning stop blocklist download
     563   
    562564    //stop timers and notification checking
    563565    [[NSNotificationCenter defaultCenter] removeObserver: self];
  • trunk/macosx/PrefsController.m

    r6563 r6667  
    2424
    2525#import "PrefsController.h"
    26 #import "BlocklistDownloader.h"
     26#import "BlocklistDownloaderViewController.h"
    2727#import "NSApplicationAdditions.h"
    2828#import "NSStringAdditions.h"
     
    128128}
    129129
     130#warning still needed? make class method?
    130131- (tr_handle *) handle
    131132{
     
    135136- (void) dealloc
    136137{
     138    [[NSNotificationCenter defaultCenter] removeObserver: self];
     139   
    137140    [fPortStatusTimer invalidate];
    138141    if (fPortChecker)
     
    223226    //set blocklist
    224227    [self updateBlocklistFields];
     228    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateBlocklistFields)
     229        name: @"BlocklistUpdated" object: nil];
    225230   
    226231    //set rpc port
     
    447452- (void) updateBlocklist: (id) sender
    448453{
    449     [BlocklistDownloader downloadWithPrefsController: self];
     454    [BlocklistDownloaderViewController downloadWithPrefsController: self];
    450455}
    451456
Note: See TracChangeset for help on using the changeset viewer.