~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-security

« back to all changes in this revision

Viewing changes to macosx/BlocklistDownloader.m

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2008-11-28 15:33:48 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20081128153348-it70trfnxiroblmc
Tags: 1.40-0ubuntu1
* New upstream release (LP: #302672)
  - Tracker communication uses fewer resources
  - More accurate bandwidth limits
  - Reduce disk fragmentation by preallocating files (LP: #287726)
  - Stability, security and performance improvements to the RPC /
    Web UI server (closes LP: #290423)
  - Support compression when serving Web UI and RPC responses
  - Simplify the RPC whitelist
  - Fix bug that prevented handshakes with encrypted BitComet peers
  - Fix 1.3x bug that could re-download some data unnecessarily
    (LP: #295040)
  - Option to automatically update the blocklist weekly
  - Added off-hour bandwidth scheduling
  - Simplify file/priority selection in the details dialog
  - Fix a couple of crashes
  - New / updated translations
  - Don't inhibit hibernation by default (LP: #292929)
  - Use "close" animation when sending to notification area (LP: #130811)
  - Fix resize problems (LP: #269872)
  - Support "--version" option when launching from command line
    (LP: #292011)
  - Correctly parse announce URLs that have leading or trailing
    spaces (LP: #262411)
  - Display an error when "Open Torrent" fails (LP: #281463)
* Dropped 10_fix_crasher_from_upstream.dpatch: Fix is in this
  upstream release.
* debian/control: Don't just build-depend on libcurl-dev, which is
  a virtual package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: BlocklistDownloader.m 6753 2008-09-16 16:39:19Z charles $
 
2
 * $Id: BlocklistDownloader.m 6682 2008-09-01 15:46:00Z livings124 $
3
3
 *
4
4
 * Copyright (c) 2008 Transmission authors and contributors
5
5
 *
23
23
 *****************************************************************************/
24
24
 
25
25
#import "BlocklistDownloader.h"
 
26
#import "BlocklistDownloaderViewController.h"
 
27
#import "BlocklistScheduler.h"
26
28
#import "PrefsController.h"
27
 
#import "NSStringAdditions.h"
28
29
#import "NSApplicationAdditions.h"
29
30
 
30
31
#define LIST_URL @"http://download.m0k.org/transmission/files/level1.gz"
32
33
 
33
34
@interface BlocklistDownloader (Private)
34
35
 
35
 
- (id) initWithPrefsController: (PrefsController *) prefsController;
36
36
- (void) startDownload;
37
37
- (void) finishDownloadSuccess;
38
 
- (void) updateProcessString;
39
 
- (void) failureSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info;
40
38
 
41
39
@end
42
40
 
43
41
@implementation BlocklistDownloader
44
42
 
45
 
+ (void) downloadWithPrefsController: (PrefsController *) prefsController
46
 
{
47
 
    BlocklistDownloader * downloader = [[BlocklistDownloader alloc] initWithPrefsController: prefsController];
48
 
    [downloader startDownload];
49
 
}
50
 
 
51
 
- (void) awakeFromNib
52
 
{
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];
 
43
BlocklistDownloader * fDownloader = nil;
 
44
+ (BlocklistDownloader *) downloader
 
45
{
 
46
    if (!fDownloader)
 
47
    {
 
48
        fDownloader = [[BlocklistDownloader alloc] init];
 
49
        [fDownloader startDownload];
 
50
    }
 
51
    
 
52
    return fDownloader;
 
53
}
 
54
 
 
55
+ (BOOL) isRunning
 
56
{
 
57
    return fDownloader != nil;
 
58
}
 
59
 
 
60
- (void) setViewController: (BlocklistDownloaderViewController *) viewController
 
61
{
 
62
    fViewController = viewController;
 
63
    if (fViewController)
 
64
    {
 
65
        switch (fState)
 
66
        {
 
67
            case BLOCKLIST_DL_START:
 
68
                [fViewController setStatusStarting];
 
69
                break;
 
70
            case BLOCKLIST_DL_DOWNLOADING:
 
71
                [fViewController setStatusProgressForCurrentSize: fCurrentSize expectedSize: fExpectedSize];
 
72
                break;
 
73
            case BLOCKLIST_DL_PROCESSING:
 
74
                [fViewController setStatusProcessing];
 
75
                break;
 
76
        }
 
77
    }
65
78
}
66
79
 
67
80
- (void) dealloc
70
83
    [super dealloc];
71
84
}
72
85
 
73
 
- (void) cancelDownload: (id) sender
 
86
- (void) cancelDownload
74
87
{
 
88
    [fViewController setFinished];
 
89
    
75
90
    [fDownload cancel];
76
91
    
77
 
    [NSApp endSheet: fStatusWindow];
78
 
    [fStatusWindow orderOut: self];
 
92
    [[BlocklistScheduler scheduler] updateSchedule];
 
93
    
 
94
    fDownloader = nil;
79
95
    [self release];
80
96
}
81
97
 
82
98
- (void) download: (NSURLDownload *) download didReceiveResponse: (NSURLResponse *) response
83
99
{
 
100
    fState = BLOCKLIST_DL_DOWNLOADING;
 
101
    
84
102
    fCurrentSize = 0;
85
103
    fExpectedSize = [response expectedContentLength];
86
104
    
87
 
    //change from indeterminate to progress
88
 
    [fProgressBar setIndeterminate: fExpectedSize == NSURLResponseUnknownLength];
89
 
    [self updateProcessString];
 
105
    [fViewController setStatusProgressForCurrentSize: fCurrentSize expectedSize: fExpectedSize];
90
106
}
91
107
 
92
108
- (void) download: (NSURLDownload *) download didReceiveDataOfLength: (NSUInteger) length
93
109
{
94
110
    fCurrentSize += length;
95
 
    [self updateProcessString];
 
111
    [fViewController setStatusProgressForCurrentSize: fCurrentSize expectedSize: fExpectedSize];
96
112
}
97
113
 
98
114
- (void) download: (NSURLDownload *) download didFailWithError: (NSError *) error
99
115
{
100
 
    [fProgressBar setHidden: YES];
101
 
    
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];
 
116
    [fViewController setFailed: [error localizedDescription]];
 
117
    
 
118
    [[BlocklistScheduler scheduler] updateSchedule];
 
119
    
 
120
    fDownloader = nil;
 
121
    [self release];
115
122
}
116
123
 
117
124
- (void) downloadDidFinish: (NSURLDownload *) download
118
125
{
 
126
    fState = BLOCKLIST_DL_PROCESSING;
 
127
    
119
128
    if ([NSApp isOnLeopardOrBetter])
120
129
        [self performSelectorInBackground: @selector(finishDownloadSuccess) withObject: nil];
121
130
    else
126
135
 
127
136
@implementation BlocklistDownloader (Private)
128
137
 
129
 
- (id) initWithPrefsController: (PrefsController *) prefsController
130
 
{
131
 
    if ((self = [super init]))
132
 
    {
133
 
        fPrefsController = prefsController;
134
 
    }
135
 
    
136
 
    return self;
137
 
}
138
 
 
139
138
- (void) startDownload
140
139
{
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
 
140
    fState = BLOCKLIST_DL_START;
 
141
    
 
142
    [[BlocklistScheduler scheduler] cancelSchedule];
 
143
    
146
144
    NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: LIST_URL]];
147
145
    
148
146
    fDownload = [[NSURLDownload alloc] initWithRequest: request delegate: self];
153
151
{
154
152
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
155
153
    
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
 
154
    [fViewController setStatusProcessing];
163
155
    
164
156
    //process data
165
 
    tr_blocklistSetContent([fPrefsController handle], [DESTINATION UTF8String]);
 
157
    tr_blocklistSetContent([PrefsController handle], [DESTINATION UTF8String]);
166
158
    
167
159
    //delete downloaded file
168
160
    if ([NSApp isOnLeopardOrBetter])
170
162
    else
171
163
        [[NSFileManager defaultManager] removeFileAtPath: DESTINATION handler: nil];
172
164
    
173
 
    [fPrefsController updateBlocklistFields];
174
 
    
175
 
    [NSApp endSheet: fStatusWindow];
176
 
    [fStatusWindow orderOut: self];
 
165
    [fViewController setFinished];
 
166
    
 
167
    //update last updated date for schedule
 
168
    [[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: @"BlocklistLastUpdate"];
 
169
    [[BlocklistScheduler scheduler] updateSchedule];
 
170
    
 
171
    [[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
177
172
    
178
173
    [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
 
    }
192
174
    
193
 
    [fTextField setStringValue: string];
194
 
}
195
 
 
196
 
- (void) failureSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info
197
 
{
198
 
    [[alert window] orderOut: nil];
 
175
    fDownloader = nil;
199
176
    [self release];
200
177
}
201
178