Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Annotation of /bathyscaphe/trunk/application/source/browser/BSThreadListUpdateTask.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 961 - (hide annotations) (download)
Sun Oct 12 16:49:15 2008 UTC (15 years, 7 months ago) by tsawada2
File size: 4316 byte(s)
v334 update

1 masakih 419 //
2     // BSThreadListUpdateTask.m
3     // BathyScaphe
4     //
5     // Created by Hori,Masaki on 06/03/29.
6 masakih 792 // Copyright 2006 BathyScaphe Project. All rights reserved.
7 masakih 419 //
8    
9     #import "BSThreadListUpdateTask.h"
10     #import "BSDBThreadList.h"
11     #import "BoardListItem.h"
12     #import "DatabaseManager.h"
13     #import "AppDefaults.h"
14    
15 masakih 586 NSString *BSThreadListUpdateTaskDidFinishNotification = @"BSThreadListUpdateTaskDidFinishNotification";
16    
17 masakih 419 @implementation BSThreadListUpdateTask
18    
19     + (id)taskWithBSDBThreadList:(BSDBThreadList *)threadList
20     {
21     return [[[[self class] alloc] initWithBSDBThreadList:threadList] autorelease];
22     }
23     - (id)initWithBSDBThreadList:(BSDBThreadList *)threadList
24     {
25     if(self = [super init]) {
26 masakih 518 target = threadList; //[threadList retain];
27 masakih 419 progress = YES;
28     userCanceled = NO;
29 masakih 683
30     bbsName = [[[target boardListItem] representName] copy];
31 masakih 419 }
32    
33     return self;
34     }
35     - (void)dealloc
36     {
37 masakih 593 [cursor release];
38 masakih 419
39     [super dealloc];
40     }
41    
42     - (id) identifier
43     {
44     return [NSValue valueWithPointer:self];
45     }
46    
47     - (NSString *) title
48     {
49 masakih 683 return bbsName;
50 masakih 419 }
51 masakih 586 - (NSString *) messageInProgress
52 masakih 419 {
53 masakih 586 return [NSString stringWithFormat:
54 tsawada2 753 NSLocalizedStringFromTable(@"Updating Thread(%@)", @"ThreadsList", @""),
55 masakih 683 bbsName];
56 masakih 419 }
57    
58     - (IBAction) cancel : (id) sender
59     {
60     userCanceled = YES;
61 masakih 611 target = nil;
62 masakih 419 }
63    
64     #pragma mark-
65 tsawada2 961 /*
66 masakih 419 static inline NSArray *componentsSeparatedByWhiteSpace(NSString *string)
67     {
68     NSMutableArray *result = [NSMutableArray array];
69     NSScanner *s = [NSScanner scannerWithString : string];
70     NSCharacterSet *cs = [NSCharacterSet whitespaceCharacterSet];
71     NSString *str;
72    
73     while ([s scanUpToCharactersFromSet : cs intoString : &str]) {
74     [result addObject : str];
75     }
76    
77     if ([result count] == 0) {
78     return nil;
79     }
80    
81     return result;
82     }
83     static inline NSString *whereClauseFromSearchString(NSString *searchString)
84     {
85     NSMutableString *clause;
86     NSArray *searchs;
87     NSEnumerator *searchsEnum;
88     NSString *token;
89    
90     NSString *p = @"";
91    
92     searchs = componentsSeparatedByWhiteSpace(searchString);
93    
94     if (!searchs || [searchs count] == 0) {
95     return nil;
96     }
97    
98     clause = [NSMutableString stringWithFormat : @" WHERE "];
99    
100     searchsEnum = [searchs objectEnumerator];
101     while (token = [searchsEnum nextObject]) {
102     if ([token hasPrefix : @"!"]) {
103     if ([token length] == 1) continue;
104    
105     [clause appendFormat : @"%@NOT %@ LIKE '%%%@%%' ",
106     p, ThreadNameColumn, [token substringFromIndex : 1]];
107     } else {
108     [clause appendFormat : @"%@%@ LIKE '%%%@%%' ",
109     p, ThreadNameColumn, token];
110     }
111     p = @"AND ";
112     }
113    
114     return clause;
115     }
116 tsawada2 961 */
117 masakih 917 - (NSString *) sqlForList
118 masakih 419 {
119     NSString *targetTable = [[target boardListItem] query];
120     NSMutableString *sql;
121 tsawada2 961 // NSString *searchCondition;
122 masakih 419
123     sql = [NSMutableString stringWithFormat : @"SELECT * FROM (%@) ",targetTable];
124 tsawada2 961 /*
125 masakih 419 if ([target searchString] && ![[target searchString] isEmpty]) {
126     searchCondition = whereClauseFromSearchString([target searchString]);
127     if (searchCondition) {
128     [sql appendString : searchCondition];
129     }
130     }
131 tsawada2 961 */
132 masakih 419 return sql;
133     }
134     - (id)cursor
135     {
136 masakih 586 return cursor;
137     }
138     - (void) setCursor:(id)new
139     {
140     id temp = cursor;
141     cursor = [new retain];
142     [temp release];
143     }
144     - (void) doExecuteWithLayout : (CMRThreadLayout *) layout
145     {
146 masakih 880 id <SQLiteMutableCursor> result = nil;
147    
148 masakih 419 SQLiteDB *db = [[DatabaseManager defaultManager] databaseForCurrentThread];
149     NSString *sql;
150    
151     UTILAssertNotNil(db);
152    
153 masakih 917 sql = [self sqlForList];
154 masakih 880 if(userCanceled) goto final;
155     result = [db cursorForSQL : sql];
156     if ([db lastErrorID] != 0) {
157     NSLog(@"sql error on %s line %d.\n\tReason : %@", __FILE__, __LINE__, [db lastError]);
158     result = nil;
159     }
160 masakih 419
161     final:
162 masakih 586 [self setCursor:result];
163 masakih 419 [self postTaskDidFinishNotification];
164     }
165    
166     @end
167    
168 masakih 586 @implementation BSThreadListUpdateTask(Notification)
169 masakih 419
170     - (void) postTaskDidFinishNotification
171     {
172     NSNotificationCenter *nc_;
173 masakih 586
174 masakih 419 nc_ = [NSNotificationCenter defaultCenter];
175 masakih 586 [nc_ postNotificationName : BSThreadListUpdateTaskDidFinishNotification
176 masakih 419 object : self];
177     }
178     @end
179 masakih 518
180     @implementation NSString(BSThreadListUpdateTaskAddition)
181     - (NSComparisonResult)numericCompare:(NSString *)string
182     {
183     return [self compare:string options:NSNumericSearch];
184     }
185     @end
186 tsawada2 961
187 masakih 518 @implementation NSNumber(BSThreadListUpdateTaskAddition)
188     - (NSComparisonResult)numericCompare:(id)obj
189     {
190     return [self compare:obj];
191     }
192     @end
193 masakih 880 @implementation NSDate(BSThreadListUpdateTaskAddition)
194     - (NSComparisonResult)numericCompare:(id)obj
195     {
196     return [self compare:obj];
197     }
198     @end

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