Desenvolver e Download de Software Open Source

Browse Subversion Repository

Diff of /bathyscaphe/trunk/application/source/browser/BSThreadsListOPTask.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1421 by tsawada2, Sun Apr 8 15:23:28 2012 UTC revision 1422 by masakih, Tue May 1 13:07:47 2012 UTC
# Line 3  Line 3 
3  //  BathyScaphe  //  BathyScaphe
4  //  //
5  //  Created by Hori,Masaki on 06/08/06.  //  Created by Hori,Masaki on 06/08/06.
6  //  Copyright 2006-2011 BathyScaphe Project. All rights reserved.  //  Copyright 2006-2012 BathyScaphe Project. All rights reserved.
7  //  encoding="UTF-8"  //  encoding="UTF-8"
8  //  //
9    
# Line 14  Line 14 
14  #import "BSDownloadTask.h"  #import "BSDownloadTask.h"
15  #import "BSDBThreadsListDBUpdateTask2.h"  #import "BSDBThreadsListDBUpdateTask2.h"
16    
 #import "CMRTaskManager.h"  
 #import "CMXWorkerContext.h"  
17  #import "AppDefaults.h"  #import "AppDefaults.h"
18  #import "BoardManager.h"  #import "BoardManager.h"
19  #import "CMRHostHandler.h"  #import "CMRHostHandler.h"
20    
21  NSString *const ThreadsListDownloaderShouldRetryUpdateNotification = @"ThreadsListDownloaderShouldRetryUpdateNotification";  NSString *const ThreadsListDownloaderShouldRetryUpdateNotification = @"ThreadsListDownloaderShouldRetryUpdateNotification";
22    
23    
24    @interface BSThreadsListOPTask ()
25    @property (retain) NSURL *URL;
26    @property (assign) BSDBThreadList *targetList;
27    @end
28    
29  @implementation BSThreadsListOPTask  @implementation BSThreadsListOPTask
30    @synthesize URL = targetURL;
31    @synthesize targetList = m_targetList;
32    
33  + (id)taskWithThreadList:(BSDBThreadList *)list forceDownload:(BOOL)forceDownload  + (id)taskWithThreadList:(BSDBThreadList *)list forceDownload:(BOOL)forceDownload
34  {  {
35          return [[[[self class] alloc] initWithThreadList:list forceDownload:forceDownload rebuild:NO] autorelease];          return [[[[self class] alloc] initWithThreadList:list forceDownload:forceDownload rebuild:NO] autorelease];
# Line 31  NSString *const ThreadsListDownloaderSho Line 38  NSString *const ThreadsListDownloaderSho
38  - (id)initWithThreadList:(BSDBThreadList *)list forceDownload:(BOOL)forceDownload rebuild:(BOOL)flag  - (id)initWithThreadList:(BSDBThreadList *)list forceDownload:(BOOL)forceDownload rebuild:(BOOL)flag
39  {  {
40          if (self = [super init]) {          if (self = [super init]) {
41                  m_targetList = list;                  self.targetList = list;
42                  m_forceDL = forceDownload;                  m_forceDL = forceDownload;
43                  isRebuilding = flag;                  isRebuilding = flag;
44                  [self setBoardName:[list boardName]];                  self.boardName = [list boardName];
45    
46                  if (![self boardName]) goto fail;                  if (!self.boardName) goto fail;
47          }          }
48                    
49          return self;          return self;
# Line 60  fail: Line 67  fail:
67  }  }
68    
69  #pragma mark-  #pragma mark-
 - (void)setURL:(NSURL *)url  
 {  
         id temp = targetURL;  
         targetURL = [url retain];  
         [temp release];  
 }  
   
 - (NSURL *)url  
 {  
         return targetURL;  
 }  
70    
71  - (void)setBoardName:(NSString *)name  - (void)setBoardName:(NSString *)name
72  {  {
# Line 83  fail: Line 79  fail:
79      isLivedoor = host ? is_jbbs_livedoor(host) : NO;      isLivedoor = host ? is_jbbs_livedoor(host) : NO;
80    
81          id temp = bbsName;          id temp = bbsName;
82          bbsName = [name retain];          bbsName = [name copy];
83          [temp release];          [temp release];
84                    
85          [self setURL:u];          self.URL = u;
86  }  }
87    
88  - (NSString *)boardName  - (NSString *)boardName
# Line 99  fail: Line 95  fail:
95  {  {
96          NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];          NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
97                    
98          dlTask = [[BSDownloadTask alloc] initWithURL:[self url]];          dlTask = [[BSDownloadTask alloc] initWithURL:self.URL];
99    
100          [nc addObserver:self          [nc addObserver:self
101                     selector:@selector(dlDidFinishDownloadNotification:)                     selector:@selector(dlDidFinishDownloadNotification:)
# Line 129  fail: Line 125  fail:
125  {  {
126          BoardManager *bm = [BoardManager defaultManager];          BoardManager *bm = [BoardManager defaultManager];
127      NSError *error;      NSError *error;
128          if ([bm tryToDetectMovedBoard:[self boardName] error:&error]) {          if ([bm tryToDetectMovedBoard:self.boardName error:&error]) {
129                  UTILNotifyName(ThreadsListDownloaderShouldRetryUpdateNotification);                  UTILNotifyName(ThreadsListDownloaderShouldRetryUpdateNotification);
130          } else {          } else {
131          NSAlert *alert = [NSAlert alertWithError:error];          NSAlert *alert = [NSAlert alertWithError:error];
# Line 159  fail: Line 155  fail:
155    
156          NSString *message = [NSString stringWithFormat:          NSString *message = [NSString stringWithFormat:
157                  NSLocalizedStringFromTable(APP_TLIST_NOT_FOUND_MSG_FMT, @"ThreadsList", nil),                  NSLocalizedStringFromTable(APP_TLIST_NOT_FOUND_MSG_FMT, @"ThreadsList", nil),
158                  [targetURL absoluteString]];                  [self.URL absoluteString]];
159    
160          NSAlert *alert = [[[NSAlert alloc] init] autorelease];          NSAlert *alert = [[[NSAlert alloc] init] autorelease];
161          [alert setAlertStyle:NSWarningAlertStyle];          [alert setAlertStyle:NSWarningAlertStyle];
# Line 173  fail: Line 169  fail:
169  }  }
170    
171  #pragma mark-  #pragma mark-
172  - (void)doExecuteWithLayout:(CMRThreadLayout *)layout  - (void)excute
173  {  {
174          [self checkIsInterrupted];          if(self.isInterrupted) goto abort;
175          if ([CMRPref isOnlineMode] || m_forceDL) {          if ([CMRPref isOnlineMode] || m_forceDL) {
176                  dlTask = [self makeDownloadTask];                  dlTask = [self makeDownloadTask];
177                  [dlTask run];                  [dlTask run];
# Line 183  fail: Line 179  fail:
179                  dlTask = nil;                  dlTask = nil;
180                  [temp release];                  [temp release];
181                                    
182                  [self checkIsInterrupted];                  if(self.isInterrupted) goto abort;
183                  if (m_downloadData && [m_downloadData length] != 0) {                  if (m_downloadData && [m_downloadData length] != 0) {
184                          dbupTask = [[BSDBThreadsListDBUpdateTask2 taskWithBBSName:bbsName data:m_downloadData livedoor:isLivedoor rebuilding:isRebuilding] retain];                          dbupTask = [[BSDBThreadsListDBUpdateTask2 taskWithBBSName:bbsName data:m_downloadData livedoor:isLivedoor rebuilding:isRebuilding] retain];
185                          [dbupTask run];                          [dbupTask run];
186              if (isRebuilding && [dbupTask lastErrorWhileRebuilding]) {              if (isRebuilding && [dbupTask lastErrorWhileRebuilding]) {
187                  m_targetList.rebuildError = [dbupTask lastErrorWhileRebuilding];                  self.targetList.rebuildError = [dbupTask lastErrorWhileRebuilding];
188              }              }
189    
190              id temp2 = dbupTask;              id temp2 = dbupTask;
191              dbupTask = nil;              dbupTask = nil;
192              [temp2 release];              [temp2 release];
193                                                    
194                          [self checkIsInterrupted];                          if(self.isInterrupted) goto abort;
195                  } else if (m_downloadError) {                  } else if (m_downloadError) {
196                          [self showDownloadErrorAlert];                          [self showDownloadErrorAlert];
197                  } else {                  } else {
# Line 203  fail: Line 199  fail:
199                  }                  }
200          }          }
201                    
202          [m_targetList updateCursor];  abort:
203            [self.targetList updateCursor];
204                    
205          [[NSNotificationCenter defaultCenter] removeObserver:self];          [[NSNotificationCenter defaultCenter] removeObserver:self];
206  }  }
207    
 - (void)finalizeWhenInterrupted  
 {  
         [m_targetList updateCursor];  
         [[NSNotificationCenter defaultCenter] removeObserver:self];  
         [super finalizeWhenInterrupted]; // 2008-03-11  
 }  
208                    
209  - (void)dlDidFinishDownloadNotification:(NSNotification *)notification  - (void)dlDidFinishDownloadNotification:(NSNotification *)notification
210  {  {
# Line 229  fail: Line 220  fail:
220    
221  -(void)dlCancelDownloadNotification:(NSNotification *)notification  -(void)dlCancelDownloadNotification:(NSNotification *)notification
222  {  {
223          [self setIsInterrupted:YES];          self.isInterrupted = YES;
224  }  }
225  -(void)dlAbortDownloadNotification:(NSNotification *)notification  -(void)dlAbortDownloadNotification:(NSNotification *)notification
226  {  {
# Line 237  fail: Line 228  fail:
228  }  }
229    
230  #pragma mark -  #pragma mark -
 - (id)identifier  
 {  
         return [NSString stringWithFormat:@"%@-%p", self, self];  
 }  
231  - (NSString *)title  - (NSString *)title
232  {  {
233          return [NSString stringWithFormat:NSLocalizedStringFromTable(@"Update threads list. %@", @"ThreadsList", @""),          return [NSString stringWithFormat:NSLocalizedStringFromTable(@"Update threads list. %@", @"ThreadsList", @""),
234                  bbsName];                  self.boardName];
235  }  }
236  - (NSString *)messageInProgress  - (NSString *)message
237  {  {
238          return [NSString stringWithFormat:NSLocalizedStringFromTable(@"Update threads list. %@", @"ThreadsList", @""),          return [NSString stringWithFormat:NSLocalizedStringFromTable(@"Update threads list. %@", @"ThreadsList", @""),
239                  bbsName];                  self.boardName];
240  }  }
241    
242  -(IBAction)cancel:(id)sender  -(IBAction)cancel:(id)sender
243  {  {
244          [dlTask cancel:self];          [dlTask cancel:self];
245          m_targetList = nil;          self.targetList = nil;
246                    
247          [super cancel:sender];          [super cancel:sender];
248  }  }

Legend:
Removed from v.1421  
changed lines
  Added in v.1422

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26