Permalink
Browse files

add dopplr token fetching support.

git-svn-id: https://jerakeen.org/svn/tomi/Projects/Shelf@3848 ab05c693-d3d1-0310-8e8b-e1346d90d6a5
  • Loading branch information...
1 parent d13fed8 commit 52a859e1152a90574fb3e991347fc28815c36311 tomi committed Feb 26, 2008
View
@@ -4,6 +4,9 @@
from AddressBook import *
from ScriptingBridge import *
+from Carbon.AppleEvents import kAEISGetURL, kAEInternetSuite
+import struct
+
import objc
import re
import traceback
@@ -13,12 +16,15 @@
from Utilities import *
from Clue import *
+from PyShelfURLProtocol import *
+
class ShelfController (NSWindowController):
companyView = objc.IBOutlet()
imageView = objc.IBOutlet()
nameView = objc.IBOutlet()
webView = objc.IBOutlet()
+ prefsWindow = objc.IBOutlet()
# first-cut init goes here - we've been woken up, and all the GUI
# component objects exist. Don't spend too long here, though, I think
@@ -51,6 +57,16 @@ def awakeFromNib(self):
os.mkdir( folder )
+
+ # Add a handler for the event GURL/GURL. One might think that
+ # Carbon.AppleEvents.kEISInternetSuite/kAEISGetURL would work,
+ # but the system headers (and hence the Python wrapper for those)
+ # are wrong.
+ manager = NSAppleEventManager.sharedAppleEventManager()
+
+ manager.setEventHandler_andSelector_forEventClass_andEventID_(
+ self, 'handleURLEvent:withReplyEvent:', fourCharToInt( "GURL" ), fourCharToInt( "GURL" ))
+
# this is called once we're all launched. Bouncing all over now.
def applicationDidFinishLaunching_(self, sender):
# There's no initial context.
@@ -277,3 +293,29 @@ def webView_decidePolicyForNavigationAction_request_frame_decisionListener_( sel
listener.ignore()
NSWorkspace.sharedWorkspace().openURL_( url )
+ def getDopplrToken_(self, sender):
+ url = "https://www.dopplr.com/api/AuthSubRequest?scope=http://www.dopplr.com&next=shelf://shelf/&session=1"
+ NSWorkspace.sharedWorkspace().openURL_( NSURL.URLWithString_(url) )
+
+ def handleURLEvent_withReplyEvent_(self, event, replyEvent):
+ theURL = event.descriptorForKeyword_(fourCharToInt('----'))
+
+ matches = re.search(r'token=(.*)', theURL.stringValue())
+ if matches:
+ token = matches.group(1)
+ NSUserDefaults.standardUserDefaults().setObject_forKey_(token, "dopplrToken")
+ alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
+ "Shelf", "Continue", None, None, "Got a Dopplr token!")
+ else:
+ alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
+ "Shelf", "Continue", None, None, "Failed to get token - sorry.")
+
+ self.prefsWindow.display()
+ self.prefsWindow.makeKeyAndOrderFront_(self)
+ alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
+ self.prefsWindow, self, None, None)
+
+
+def fourCharToInt(code):
+ return struct.unpack('>l', code)[0]
+
View
@@ -28,6 +28,7 @@
'googleSocialContext':False,
'bringAppForward':True,
'alwaysOnTop':True,
+ 'firstRun':True,
'debug':False
})
@@ -23,7 +23,7 @@ def __init__(self, provider, url):
Cache.getContentOfUrlAndCallback( callback = self.gotDopplrData, url = url, timeout = 3600, wantStale = True, failure = self.failed )
def failed(self, error):
- self.dead = true
+ self.dead = True
self.changed()
def gotDopplrData(self, data, stale):
Oops, something went wrong.

0 comments on commit 52a859e

Please sign in to comment.