Permalink
Browse files

Add preference for opensocial server

  • Loading branch information...
hongrich committed Aug 5, 2010
1 parent eb9e73d commit a4cbcb6bba05d5395fcb1ac092247fe12c95a838
@@ -125,7 +125,9 @@ - (void)actionSheet:(UIActionSheet *)aActionSheet clickedButtonAtIndex:(NSIntege
- (BOOL)webView:(UIWebView *)aWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// TODO: move this code out of thise class so DashboardBrowserViewController can be reused.
- if ([[[request URL] path] hasSuffix:@".zip"] || [[[request URL] path] hasSuffix:@".widget"] || [[[request URL] path] hasSuffix:@".xml"]) {
+ BOOL allowOpenSocial = [[[NSUserDefaults standardUserDefaults] stringForKey:@"preference_opensocial_server"] length] > 0;
+ if ([[[request URL] path] hasSuffix:@".zip"] || [[[request URL] path] hasSuffix:@".widget"] ||
+ (allowOpenSocial && [[[request URL] path] hasSuffix:@".xml"])) {
if ([[self parentViewController] isKindOfClass:[DashboardViewController class]]) {
DashboardViewController *viewController = (DashboardViewController*)[self parentViewController];
[viewController.widgetsView addItem:request];
@@ -32,17 +32,17 @@
@interface DashboardGadget : NSObject {
NSString *title;
- NSString *content;
+ NSString *url;
NSInteger height;
NSInteger width;
}
@property (nonatomic, retain) NSString *title;
-@property (nonatomic, retain) NSString *content;
+@property (nonatomic, retain) NSString *url;
@property (nonatomic) NSInteger height;
@property (nonatomic) NSInteger width;
-- (DashboardGadget*) init;
+- (DashboardGadget*) initWithUrl:(NSString*) aUrl;
- (NSString*) createWidget;
@end
View
@@ -31,13 +31,14 @@
@implementation DashboardGadget
-@synthesize title, content, height, width;
+@synthesize title, url, height, width;
-- (DashboardGadget*) init {
+- (DashboardGadget*) initWithUrl:(NSString*) aUrl {
if ((self = [super init])) {
- // Do Stuff here
+ // Default settings
self.height = 100;
self.width = 300;
+ self.url = aUrl;
}
return self;
}
@@ -72,7 +73,9 @@ - (NSString*) createWidget {
// Change iframe src
NSStringEncoding enc;
NSString *file = [NSString stringWithContentsOfFile:[widgetDir stringByAppendingPathComponent:@"gadget.html"] usedEncoding:&enc error:NULL];
- file = [file stringByReplacingOccurrencesOfString:@"src=\"inner.html\"" withString:[NSString stringWithFormat:@"src=\"%@\"", self.content]];
+ NSString *server = [[NSUserDefaults standardUserDefaults] stringForKey:@"preference_opensocial_server"];
+ NSString *src = [[server stringByAppendingPathComponent:@"gadgets/ifr?url="] stringByAppendingString: self.url];
+ file = [file stringByReplacingOccurrencesOfString:@"src=\"inner.html\"" withString:[NSString stringWithFormat:@"src=\"%@\"", src]];
[file writeToFile:[widgetDir stringByAppendingPathComponent:@"gadget.html"] atomically:NO encoding:enc error:NULL];
return path;
}
@@ -83,7 +86,6 @@ - (NSString*) createWidget {
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
- NSLog(@"%s: %@, %@, %@, %@", _cmd, elementName, namespaceURI, qualifiedName, attributeDict);
if ([elementName isEqualToString:@"ModulePrefs"]) {
self.title = [attributeDict valueForKey:@"title"];
@@ -93,14 +95,12 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
if ([attributeDict objectForKey:@"width"] != nil) {
self.width = [[attributeDict valueForKey:@"width"] intValue];
}
- } else if ([elementName isEqualToString:@"Content"]) {
- self.content = [attributeDict valueForKey:@"href"];
}
}
- (void) dealloc {
self.title = nil;
- self.content = nil;
+ self.url = nil;
[super dealloc];
}
@@ -318,7 +318,7 @@ - (void)downloadItem:(DashboardDownloadItem *)downloadItem didFinishWithData:(NS
#pragma mark downloadItem helpers
- (void)handleGadgetDownloadItem:(DashboardDownloadItem *)downloadItem data:(NSData *)data {
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
- DashboardGadget *gadget = [[DashboardGadget alloc] init];
+ DashboardGadget *gadget = [[DashboardGadget alloc] initWithUrl:[[[downloadItem request] URL] absoluteString]];
[parser setDelegate:gadget];
[parser parse];
NSString *path = [gadget createWidget];
View
@@ -68,6 +68,30 @@
<key>AutocorrectionType</key>
<string>No</string>
</dict>
+ <dict>
+ <key>Type</key>
+ <string>PSGroupSpecifier</string>
+ <key>Title</key>
+ <string>OpenSocial Server (Optional)</string>
+ </dict>
+ <dict>
+ <key>KeyboardType</key>
+ <string>URL</string>
+ <key>Type</key>
+ <string>PSTextFieldSpecifier</string>
+ <key>Title</key>
+ <string>URL</string>
+ <key>Key</key>
+ <string>preference_opensocial_server</string>
+ <key>DefaultValue</key>
+ <string></string>
+ <key>IsSecure</key>
+ <false/>
+ <key>AutocapitalizationType</key>
+ <string>None</string>
+ <key>AutocorrectionType</key>
+ <string>No</string>
+ </dict>
</array>
</dict>
</plist>
Binary file not shown.

0 comments on commit a4cbcb6

Please sign in to comment.