BathyScapheのSQLiteデータベース内を覗くアプリ
修订版 | 6d5e0b2407690367272c4c561672826efb89b653 (tree) |
---|---|
时间 | 2008-06-20 21:33:20 |
作者 | masakih <masakih@user...> |
Commiter | masakih |
BSDBViewer.[h|m]
BathyScapheで開く機能を付けた。
Info.plist
versionを1.1にup
git-svn-id: svn+ssh://macmini/usr/local/svnrepos/BSDBViewer/BSDBViewer@11 477addb1-df5c-4826-a637-c2b1bdcd60d4
@@ -13,6 +13,8 @@ | ||
13 | 13 | IBOutlet id threadView; |
14 | 14 | |
15 | 15 | int progressStack; |
16 | + | |
17 | + NSMutableDictionary *boardNameCache; | |
16 | 18 | } |
17 | 19 | |
18 | 20 | + (SQLiteDB *)sqliteDB; |
@@ -85,6 +85,14 @@ final: | ||
85 | 85 | return resolveAlias(res); |
86 | 86 | } |
87 | 87 | |
88 | ++ (NSString *)BSDocumentFolder | |
89 | +{ | |
90 | + id res = [self BSSupportFolder]; | |
91 | + | |
92 | + res = [res stringByAppendingPathComponent:@"Documents"]; | |
93 | + | |
94 | + return resolveAlias(res); | |
95 | +} | |
88 | 96 | + (NSString *)databasePath |
89 | 97 | { |
90 | 98 | id res = [self BSSupportFolder]; |
@@ -118,6 +126,19 @@ final: | ||
118 | 126 | return [[self class] sqliteDB]; |
119 | 127 | } |
120 | 128 | |
129 | +- (NSString *)nameOfBathyScaphe | |
130 | +{ | |
131 | + NSUserDefaults *d = [NSUserDefaults standardUserDefaults]; | |
132 | + | |
133 | + NSString *bundleID = [d stringForKey:@"OpenApplicationBundleID"]; | |
134 | + if(!bundleID) return @"BathyScaphe"; | |
135 | + | |
136 | + NSWorkspace *w = [NSWorkspace sharedWorkspace]; | |
137 | + NSString *app = [w absolutePathForAppBundleWithIdentifier:bundleID]; | |
138 | + if(!app) return @"BathyScaphe"; | |
139 | + | |
140 | + return [app lastPathComponent]; | |
141 | +} | |
121 | 142 | #pragma mark- |
122 | 143 | - (void)setInProgress:(BOOL)new |
123 | 144 | { |
@@ -139,7 +160,71 @@ final: | ||
139 | 160 | progressStack--; |
140 | 161 | [self didChangeValueForKey:InProgressKey]; |
141 | 162 | } |
163 | + | |
142 | 164 | #pragma mark- |
165 | +- (NSString *)boardNameFromBoardID:(id)boardID | |
166 | +{ | |
167 | + NSString *result = [boardNameCache objectForKey:boardID]; | |
168 | + if(result) return result; | |
169 | + | |
170 | + NSString *query = [NSString stringWithFormat:@"SELECT boardname FROM boardInfo " | |
171 | + @"WHERE boardid = %@" | |
172 | + , | |
173 | + boardID]; | |
174 | + | |
175 | + SQLiteDB *db = [self sqliteDB]; | |
176 | + id cursor; | |
177 | + if([db beginTransaction]) { | |
178 | + cursor = [db cursorForSQL:query]; | |
179 | + if([db lastErrorID] != 0) { | |
180 | + NSLog(@"Fail Sending Query: %@", query); | |
181 | + NSLog(@"SQLite Error: %@", [db lastError]); | |
182 | + } | |
183 | + [db commitTransaction]; | |
184 | + } | |
185 | + | |
186 | + NSString *boardName = [cursor valueForColumn:@"boardname" atRow:0]; | |
187 | + if(!boardName) return nil; | |
188 | + | |
189 | + [boardNameCache setObject:boardName forKey:boardID]; | |
190 | + | |
191 | + return boardName; | |
192 | +} | |
193 | +- (NSString *)pathForThreadID:(id)threadID boardID:(id)boardID | |
194 | +{ | |
195 | + if(!threadID || !boardID) return nil; | |
196 | + | |
197 | + NSString *path = [[self class] BSDocumentFolder]; | |
198 | + | |
199 | + NSString *boardName = [self boardNameFromBoardID:boardID]; | |
200 | + if(!boardName) { | |
201 | + NSLog(@"Can not find boardName from boardID(%@).", boardID); | |
202 | + return nil; | |
203 | + } | |
204 | + path = [path stringByAppendingPathComponent:boardName]; | |
205 | + path = [path stringByAppendingPathComponent:threadID]; | |
206 | + path = [path stringByAppendingPathExtension:@"thread"]; | |
207 | + | |
208 | + return path; | |
209 | +} | |
210 | +- (void) openInBSThreadID:(id)threadID boardID:(id)boardID | |
211 | +{ | |
212 | + [[NSWorkspace sharedWorkspace] openFile:[self pathForThreadID:threadID boardID:boardID] | |
213 | + withApplication:[self nameOfBathyScaphe]]; | |
214 | +} | |
215 | + | |
216 | +- (void)openThreadsInBS:(NSArray *)infos | |
217 | +{ | |
218 | + id enume = [infos objectEnumerator]; | |
219 | + id obj; | |
220 | + id targetBoardID = [threadSource boardID]; | |
221 | + | |
222 | + while(obj = [enume nextObject]) { | |
223 | + id threadID = [obj objectForKey:@"threadid"]; | |
224 | + if(!threadID) continue; | |
225 | + [self openInBSThreadID:threadID boardID:targetBoardID]; | |
226 | + } | |
227 | +} | |
143 | 228 | - (void)deleteThreadInformations:(NSArray *)infos |
144 | 229 | { |
145 | 230 | NSString *query = |
@@ -208,7 +293,11 @@ final: | ||
208 | 293 | } |
209 | 294 | - (IBAction)openInBathyScaphe:(id)sender |
210 | 295 | { |
296 | + NSArray *infos = [self targetObjectsInTableView:threadView arrayController:threadArrayController]; | |
211 | 297 | |
298 | + [self performSelector:@selector(openThreadsInBS:) | |
299 | + withObject:infos | |
300 | + afterDelay:0.0]; | |
212 | 301 | } |
213 | 302 | |
214 | 303 | #pragma mark- |
@@ -242,7 +331,20 @@ final: | ||
242 | 331 | - (BOOL)validateMenuItem:(NSMenuItem *)menuItem |
243 | 332 | { |
244 | 333 | if(@selector(showThreadInfo:) == [menuItem action]) return NO; |
245 | - if(@selector(openInBathyScaphe:) == [menuItem action]) return NO; | |
334 | + | |
335 | + if(@selector(openInBathyScaphe:) == [menuItem action]) { | |
336 | + id selection = [self targetObjectsInTableView:threadView | |
337 | + arrayController:threadArrayController]; | |
338 | + if([selection count] != 1) return NO; | |
339 | + | |
340 | + NSString *path = [self pathForThreadID:[[selection objectAtIndex:0] objectForKey:@"threadid"] | |
341 | + boardID:[threadSource boardID]]; | |
342 | + if(!path) return NO; | |
343 | + | |
344 | + BOOL isDir = NO; | |
345 | + if(![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] | |
346 | + || isDir) return NO; | |
347 | + } | |
246 | 348 | |
247 | 349 | return YES; |
248 | 350 | } |
@@ -146,9 +146,9 @@ | ||
146 | 146 | F46C0F040DFFFF3000C1CDCC /* UTILDescription.h */, |
147 | 147 | F46C0F050DFFFF3000C1CDCC /* UTILError.h */, |
148 | 148 | F46C0F060DFFFF3000C1CDCC /* UTILKit.h */, |
149 | - F46C0E8E0DFD72C600C1CDCC /* SQLiteDB.m */, | |
150 | - F46C0E8F0DFD72C600C1CDCC /* SQLiteDB.h */, | |
151 | 149 | F46C0E900DFD72C600C1CDCC /* sqlite3.h */, |
150 | + F46C0E8F0DFD72C600C1CDCC /* SQLiteDB.h */, | |
151 | + F46C0E8E0DFD72C600C1CDCC /* SQLiteDB.m */, | |
152 | 152 | ); |
153 | 153 | name = "External Sources"; |
154 | 154 | sourceTree = "<group>"; |
@@ -17,7 +17,7 @@ | ||
17 | 17 | <key>CFBundlePackageType</key> |
18 | 18 | <string>APPL</string> |
19 | 19 | <key>CFBundleShortVersionString</key> |
20 | - <string>1.0.1</string> | |
20 | + <string>1.1</string> | |
21 | 21 | <key>CFBundleSignature</key> |
22 | 22 | <string>????</string> |
23 | 23 | <key>CFBundleVersion</key> |