Changeset 3211
- Timestamp:
- 12/17/07 18:39:15 (13 months ago)
- Location:
- lang/objective-c/SafariHatenaBookmark
- Files:
-
- 3 modified
-
SHBController.h (modified) (1 diff)
-
SHBController.m (modified) (1 diff)
-
SafariHatenaBookmark.xcodeproj/project.pbxproj (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/objective-c/SafariHatenaBookmark/SHBController.h
r3208 r3211 12 12 @interface SHBController : NSObject { 13 13 IBOutlet NSMenu* topMenu; 14 id receivedData; 14 15 } 15 16 -
lang/objective-c/SafariHatenaBookmark/SHBController.m
r3208 r3211 7 7 // 8 8 9 #import <WebKit/WebKit.h> 10 #import <JSON/JSON.h> 9 11 #import "SHBController.h" 10 12 13 @implementation SHBController 11 14 12 @implementation SHBController 13 - (void) awakeFromNib 14 { 15 // [self reloadUserScripts: nil]; 15 - (void) awakeFromNib { 16 NSLog(@"SHBController:awakeFromNib"); 16 17 17 NSLog(@"SHBController:awakeFromNib"); 18 // Menu 19 NSMenuItem* item; 18 // Menu 19 NSMenuItem* item; 20 20 21 item = [[NSMenuItem alloc] init];22 [item setSubmenu: topMenu];21 item = [[NSMenuItem alloc] init]; 22 [item setSubmenu: topMenu]; 23 23 24 [topMenu setTitle: @"はてな"];24 [topMenu setTitle: @"はてな"]; 25 25 26 [[NSApp mainMenu] addItem: item]; 27 [item release]; 26 [[NSApp mainMenu] addItem: item]; 27 [item release]; 28 29 // Notification 30 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 31 [center addObserver: self 32 selector: @selector(progressStarted:) 33 name: WebViewProgressStartedNotification 34 object: nil]; 35 [center addObserver: self 36 selector: @selector(progressFinished:) 37 name: WebViewProgressFinishedNotification 38 object: nil]; 39 40 #if 0 41 [center addObserver: self 42 selector: @selector(applicationDidFinishLaunching:) 43 name: NSApplicationDidFinishLaunchingNotification 44 object: NSApp]; 45 #endif // 0 28 46 } 29 47 48 - (void) progressStarted: (NSNotification*) n 49 { 50 WebView* webView = [n object]; 51 WebDataSource* source = [[webView mainFrame] provisionalDataSource]; 52 if (! source) { 53 // source = [[webView mainFrame] provisionalDataSource]; 54 } 55 NSURL* cur_url = [[source request] URL]; 56 57 NSLog(@"progressStarted: cur_url = %@", cur_url); 58 59 // construct request 60 NSString *urlString = [NSString stringWithFormat: 61 @"http://b.hatena.ne.jp/entry/json/%@", cur_url]; 62 63 NSLog(@"progressStarted: url = %@", urlString); 64 NSURL *url = [NSURL URLWithString:urlString]; 65 NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url]; 66 //[urlRequest setHTTPMethod:@"POST"]; 67 //[urlRequest setHTTPBody:[content dataUsingEncoding:NSUTF8StringEncoding]]; 68 69 // connect it 70 NSURLConnection *theConnection = [NSURLConnection 71 connectionWithRequest:urlRequest 72 delegate:self]; 73 if (theConnection) { 74 receivedData = [[NSMutableData data] retain]; 75 } else { 76 NSLog(@"not connected correctly."); 77 } 78 } 79 80 - (void) progressFinished: (NSNotification*) n 81 { 82 WebView* webView = [n object]; 83 //NSURL* url = WebFrameRequestURL([webView mainFrame]); 84 WebDataSource* source = [[webView mainFrame] provisionalDataSource]; 85 if (! source) { 86 // source = [[webView mainFrame] provisionalDataSource]; 87 } 88 NSURL* url = [[source request] URL]; 89 NSLog(@"progressFinished: url = %@", url); 90 } 91 92 30 93 - (id) init { 31 NSLog(@"SHBController %p - init", self);94 NSLog(@"SHBController %p - init", self); 32 95 33 self = [super init];34 if (! self)35 return nil;96 self = [super init]; 97 if (! self) 98 return nil; 36 99 37 [NSBundle loadNibNamed: @"Menu.nib" owner: self];38 NSLog(@"SHBController:init: nib loaded");39 return self;100 [NSBundle loadNibNamed: @"Menu.nib" owner: self]; 101 NSLog(@"SHBController:init: nib loaded"); 102 return self; 40 103 } 41 104 42 105 - (IBAction)bookmark:(id)sender { 43 NSLog(@"bookmark");106 NSLog(@"bookmark"); 44 107 } 45 108 46 109 - (IBAction)diary:(id)sender { 47 NSLog(@"diary");110 NSLog(@"diary"); 48 111 } 49 112 50 113 - (IBAction)haiku:(id)sender { 51 NSLog(@"haiku");114 NSLog(@"haiku"); 52 115 } 53 116 117 118 // callbacks 119 - (void) connection : (NSURLConnection *) connection 120 didReceiveResponse : (NSURLResponse *) response { 121 NSDictionary *dicHead = [(NSHTTPURLResponse *)response allHeaderFields]; 122 NSLog(@"didReceiveResponse : %@", [dicHead objectForKey:@"Status"]); 123 [receivedData setLength:0]; 124 } 125 126 - (void) connection : (NSURLConnection *) connection 127 didReceiveData : (NSData *) data { 128 [receivedData appendData:data]; 129 } 130 131 - (void) connection : (NSURLConnection *) connection 132 didFailWithError : (NSError *) error { 133 NSLog(@"didFailWithError 1"); 134 // [connection release]; 135 [receivedData release]; 136 NSLog(@"didFailWithError 2"); 137 } 138 139 - (void) connectionDidFinishLoading:(NSURLConnection *)connection { 140 NSLog(@"connectionDidFinishLoading: succeeded to load %d bytes", [receivedData length]); 141 NSString *result = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; 142 NSLog(@"connectionDidFinishLoading: result=%@", result); 143 id json = [result JSONValue]; 144 NSLog(@"connectionDidFinishLoading: id=%@", json); 145 146 // [connection release]; 147 [receivedData release]; 148 } 149 150 54 151 @end -
lang/objective-c/SafariHatenaBookmark/SafariHatenaBookmark.xcodeproj/project.pbxproj
r3208 r3211 12 12 86A7D1D10D16639600D35D4C /* SHBController.m in Sources */ = {isa = PBXBuildFile; fileRef = 86A7D1CE0D16639600D35D4C /* SHBController.m */; }; 13 13 86A7D1D20D16639600D35D4C /* PluginLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 86A7D1D00D16639600D35D4C /* PluginLoader.m */; }; 14 86C597AA0D166CC10000340D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 86C597A90D166CC10000340D /* WebKit.framework */; }; 15 86C597D00D1673140000340D /* JSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 86C597CF0D1673140000340D /* JSON.framework */; }; 14 16 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; }; 15 17 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; }; … … 28 30 86A7D1CF0D16639600D35D4C /* PluginLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginLoader.h; sourceTree = "<group>"; }; 29 31 86A7D1D00D16639600D35D4C /* PluginLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PluginLoader.m; sourceTree = "<group>"; }; 32 86C597A90D166CC10000340D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = /System/Library/Frameworks/WebKit.framework; sourceTree = "<absolute>"; }; 33 86C597CF0D1673140000340D /* JSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JSON.framework; sourceTree = "<group>"; }; 30 34 8D5B49B6048680CD000E48DA /* SafariHatenaBookmark.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SafariHatenaBookmark.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 31 35 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; … … 39 43 files = ( 40 44 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */, 45 86C597AA0D166CC10000340D /* WebKit.framework in Frameworks */, 46 86C597D00D1673140000340D /* JSON.framework in Frameworks */, 41 47 ); 42 48 runOnlyForDeploymentPostprocessing = 0; … … 82 88 86A7D1CD0D16639600D35D4C /* SHBController.h */, 83 89 86A7D1CE0D16639600D35D4C /* SHBController.m */, 90 86C597CF0D1673140000340D /* JSON.framework */, 91 86C597A90D166CC10000340D /* WebKit.framework */, 84 92 86A7D1CF0D16639600D35D4C /* PluginLoader.h */, 85 93 86A7D1D00D16639600D35D4C /* PluginLoader.m */, … … 201 209 buildSettings = { 202 210 COPY_PHASE_STRIP = NO; 211 FRAMEWORK_SEARCH_PATHS = ( 212 "$(inherited)", 213 "\"$(SRCROOT)\"", 214 ); 203 215 GCC_DYNAMIC_NO_PIC = NO; 204 216 GCC_ENABLE_FIX_AND_CONTINUE = YES; … … 219 231 buildSettings = { 220 232 DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 233 FRAMEWORK_SEARCH_PATHS = ( 234 "$(inherited)", 235 "\"$(SRCROOT)\"", 236 ); 221 237 GCC_MODEL_TUNING = G5; 222 238 GCC_PRECOMPILE_PREFIX_HEADER = YES;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)