• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BathyScapheのSQLiteデータベース内を覗くアプリ


Commit MetaInfo

修订版6d5e0b2407690367272c4c561672826efb89b653 (tree)
时间2008-06-20 21:33:20
作者masakih <masakih@user...>
Commitermasakih

Log Message

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

更改概述

差异

--- a/BSDBViewer.h
+++ b/BSDBViewer.h
@@ -13,6 +13,8 @@
1313 IBOutlet id threadView;
1414
1515 int progressStack;
16+
17+ NSMutableDictionary *boardNameCache;
1618 }
1719
1820 + (SQLiteDB *)sqliteDB;
--- a/BSDBViewer.m
+++ b/BSDBViewer.m
@@ -85,6 +85,14 @@ final:
8585 return resolveAlias(res);
8686 }
8787
88++ (NSString *)BSDocumentFolder
89+{
90+ id res = [self BSSupportFolder];
91+
92+ res = [res stringByAppendingPathComponent:@"Documents"];
93+
94+ return resolveAlias(res);
95+}
8896 + (NSString *)databasePath
8997 {
9098 id res = [self BSSupportFolder];
@@ -118,6 +126,19 @@ final:
118126 return [[self class] sqliteDB];
119127 }
120128
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+}
121142 #pragma mark-
122143 - (void)setInProgress:(BOOL)new
123144 {
@@ -139,7 +160,71 @@ final:
139160 progressStack--;
140161 [self didChangeValueForKey:InProgressKey];
141162 }
163+
142164 #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+}
143228 - (void)deleteThreadInformations:(NSArray *)infos
144229 {
145230 NSString *query =
@@ -208,7 +293,11 @@ final:
208293 }
209294 - (IBAction)openInBathyScaphe:(id)sender
210295 {
296+ NSArray *infos = [self targetObjectsInTableView:threadView arrayController:threadArrayController];
211297
298+ [self performSelector:@selector(openThreadsInBS:)
299+ withObject:infos
300+ afterDelay:0.0];
212301 }
213302
214303 #pragma mark-
@@ -242,7 +331,20 @@ final:
242331 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
243332 {
244333 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+ }
246348
247349 return YES;
248350 }
--- a/BSDBViewer.xcodeproj/project.pbxproj
+++ b/BSDBViewer.xcodeproj/project.pbxproj
@@ -146,9 +146,9 @@
146146 F46C0F040DFFFF3000C1CDCC /* UTILDescription.h */,
147147 F46C0F050DFFFF3000C1CDCC /* UTILError.h */,
148148 F46C0F060DFFFF3000C1CDCC /* UTILKit.h */,
149- F46C0E8E0DFD72C600C1CDCC /* SQLiteDB.m */,
150- F46C0E8F0DFD72C600C1CDCC /* SQLiteDB.h */,
151149 F46C0E900DFD72C600C1CDCC /* sqlite3.h */,
150+ F46C0E8F0DFD72C600C1CDCC /* SQLiteDB.h */,
151+ F46C0E8E0DFD72C600C1CDCC /* SQLiteDB.m */,
152152 );
153153 name = "External Sources";
154154 sourceTree = "<group>";
--- a/Info.plist
+++ b/Info.plist
@@ -17,7 +17,7 @@
1717 <key>CFBundlePackageType</key>
1818 <string>APPL</string>
1919 <key>CFBundleShortVersionString</key>
20- <string>1.0.1</string>
20+ <string>1.1</string>
2121 <key>CFBundleSignature</key>
2222 <string>????</string>
2323 <key>CFBundleVersion</key>