forked from tweakweek/ReadLaterAction
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 41fe52a
Showing
17 changed files
with
515 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
._* | ||
*.deb | ||
.debmake | ||
_ | ||
obj | ||
.theos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[submodule "framework"] | ||
path = framework | ||
url = git://github.com/rpetrich/theos.git | ||
[submodule "Localization"] | ||
path = Localization | ||
url = git://github.com/rpetrich/Localization.git | ||
[submodule "newsyc"] | ||
path = newsyc | ||
url = git://github.com/newsyc/newsyc.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
typedef enum { | ||
AMMenuItemStyleDefault = 0, | ||
// Default display style (what the user has selected) | ||
AMMenuItemStyleText = 1, | ||
// Always display text | ||
AMMenuItemStyleImage = 2, | ||
// Display image where available, otherwise display text | ||
} AMMenuItemStyle; | ||
|
||
typedef enum { | ||
AMActionMenuBehaviorDefault = 0, | ||
// Default additional behaviors provided by Action Menu | ||
AMActionMenuBehaviorDisableMenu = (1 << 0), | ||
// Disable the popup menu that Action Menu has added | ||
} AMActionMenuBehaviors; | ||
|
||
|
||
#define kAMMenuItemPrioritySelect 100 | ||
#define kAMMenuItemPrioritySelectAll 200 | ||
#define kAMMenuItemPriorityCut 300 | ||
#define kAMMenuItemPriorityCopy 400 | ||
#define kAMMenuItemPriorityPaste 500 | ||
#define kAMMenuItemPriorityDelete 600 | ||
#define kAMMenuItemPriorityCorrect 900 | ||
#define kAMMenuItemPriorityDefault 1000 | ||
|
||
#define kAMMenuItemPriorityCopyAll 450 | ||
#define kAMMenuItemPriorityHistory 525 | ||
#define kAMMenuItemPriorityFavorites 550 | ||
#define kAMMenuItemPriorityDial 925 | ||
#define kAMMenuItemPriorityLookup 950 | ||
#define kAMMenuItemPriorityFind 975 | ||
#define kAMMenuItemPriorityTweet 1100 | ||
#define kAMMenuItemPriorityScroll 1200 | ||
|
||
#define kAMMenuItemPriorityBuiltins 510 | ||
|
||
@protocol AMMenuItem <NSObject> | ||
@property (nonatomic, readonly) SEL action; | ||
// Selector that will be sent to the target when menu item is pressed | ||
@property (nonatomic, readonly) SEL canPerform; | ||
// Selector that will be sent to the target to query whether menu item is valid | ||
@property (nonatomic, copy) NSString *title; | ||
// Localized title of the menu item | ||
@property (nonatomic, assign) UIImage *image; | ||
// Image that will be used to display the menu item | ||
@property (nonatomic, assign) AMMenuItemStyle style; | ||
// Style of the menu item | ||
@property (nonatomic) NSInteger priority; | ||
// Specify the priority of the item | ||
@end | ||
|
||
@interface UIMenuController (ActionMenu) | ||
// Plugin Registration functions | ||
- (id<AMMenuItem>)registerAction:(SEL)action title:(NSString *)title canPerform:(SEL)canPerform; | ||
- (id<AMMenuItem>)registerAction:(SEL)action title:(NSString *)title canPerform:(SEL)canPerform forPlugin:(NSString *)pluginName; | ||
// action will be sent to the target when the menu item has been pressed | ||
// canPerform will be sent to the target when the menu is about to be shown and we need to know if the menu item is valid | ||
// title is the localized title of the menu item | ||
// pluginName is the unlocalized title of the plugin | ||
@end | ||
|
||
@interface UIResponder (ActionMenu) | ||
- (NSString *)textualRepresentation; | ||
// Called by plugins to get the text of the object; implement manually for custom views | ||
- (NSString *)selectedTextualRepresentation; | ||
// Returns only the selected text; if unimplemented, will call and return textualRepresentation | ||
- (AMActionMenuBehaviors)actionMenuBehaviors; | ||
// Control which additional ActionMenu behaviors are valid on this target | ||
- (BOOL)always; | ||
// Always returns YES (used by actions that are always valid) | ||
@end | ||
|
||
@interface UIAlertView (ActionMenu) | ||
- (void)showAboveExistingAlert; | ||
@end | ||
|
||
/* | ||
Notes: | ||
Plugins will be loaded lazily from /Libary/ActionMenu/Plugins when the menu is first shown; this is usually much later than one might expect. | ||
If the user disables a plugin after it has been loaded, the plugin will still be resident in memory, but its items will no longer show. | ||
If the user enables a plugin, it will be loaded the next time the menu becomes visible. | ||
Plugins may be either .dylibs or .bundles | ||
Dylib plugins get a ON/OFF switch in the preferences pane. | ||
Bundle plugins get their own subpane to do what they please with. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// InstapaperAPI.h | ||
// newsyc | ||
// | ||
// Created by Grant Paul on 3/10/11. | ||
// Copyright 2011 Xuzz Productions, LLC. All rights reserved. | ||
// | ||
// Imported from the newsyc project and edited to remove dependencies | ||
|
||
#define kInstapaperAPIRootURL [NSURL URLWithString:@"https://instapaper.com/api/"] | ||
#define kInstapaperAPIAuthenticationURL [NSURL URLWithString:[[kInstapaperAPIRootURL absoluteString] stringByAppendingString:@"authenticate"]] | ||
#define kInstapaperAPIAddItemURL [NSURL URLWithString:[[kInstapaperAPIRootURL absoluteString] stringByAppendingString:@"add"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// InstapaperRequest.h | ||
// newsyc | ||
// | ||
// Created by Grant Paul on 4/7/11. | ||
// Copyright 2011 Xuzz Productions, LLC. All rights reserved. | ||
// | ||
|
||
#import "InstapaperAPI.h" | ||
|
||
@class RLAInstapaperSession; | ||
@interface RLAInstapaperRequest : NSObject { | ||
RLAInstapaperSession *session; | ||
} | ||
|
||
@property (nonatomic, readonly) RLAInstapaperSession *session; | ||
|
||
- (void)addItemWithURL:(NSURL *)url title:(NSString *)title selection:(NSString *)selection; | ||
- (void)addItemWithURL:(NSURL *)url title:(NSString *)title; | ||
- (void)addItemWithURL:(NSURL *)url; | ||
|
||
- (id)initWithSession:(RLAInstapaperSession *)session_; | ||
|
||
@end | ||
|
||
#define kInstapaperRequestSucceededNotification @"rla-instapaper-request-completed" | ||
#define kInstapaperRequestFailedNotification @"rla-instapaper-request-failed" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// InstapaperRequest.m | ||
// newsyc | ||
// | ||
// Created by Grant Paul on 4/7/11. | ||
// Copyright 2011 Xuzz Productions, LLC. All rights reserved. | ||
// | ||
|
||
#import "InstapaperRequest.h" | ||
#import "InstapaperSession.h" | ||
|
||
@implementation RLAInstapaperRequest | ||
@synthesize session; | ||
|
||
- (void)dealloc { | ||
[session release]; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
- (id)initWithSession:(RLAInstapaperSession *)session_ { | ||
if ((self = [super init])) { | ||
session = [session_ retain]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)succeed { | ||
[[NSNotificationCenter defaultCenter] postNotificationName:kInstapaperRequestSucceededNotification object:self]; | ||
} | ||
|
||
- (void)failWithError:(NSError *)error { | ||
[[NSNotificationCenter defaultCenter] postNotificationName:kInstapaperRequestFailedNotification object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:@"error"]]; | ||
} | ||
|
||
- (void)failWithErrorText:(NSString *)text { | ||
NSError *error = [NSError errorWithDomain:@"instapaper" code:0 userInfo:[NSDictionary dictionaryWithObject:text forKey:NSLocalizedDescriptionKey]]; | ||
|
||
[self failWithError:error]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { | ||
[self failWithError:error]; | ||
[connection cancel]; | ||
[self autorelease]; | ||
} | ||
|
||
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { | ||
[connection cancel]; | ||
[self autorelease]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { | ||
if ([response isKindOfClass:[NSHTTPURLResponse class]]) { | ||
int status = [(NSHTTPURLResponse *) response statusCode]; | ||
if (status == 403) [self failWithErrorText:@"Invalid username or password."]; | ||
if (status == 500) [self failWithErrorText:@"Internal error, try again later."]; | ||
if (status == 201) [self succeed]; | ||
} else { | ||
[self failWithErrorText:@"Unknown error."]; | ||
} | ||
} | ||
|
||
static inline NSString *URLEncode(NSString *string) | ||
{ | ||
CFStringRef result = CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)string, NULL, (CFStringRef) @"!*'\"();:@&=+$,/?%#[]% ", kCFStringEncodingUTF8); | ||
return [(NSString *)result autorelease]; | ||
} | ||
|
||
- (void)addItemWithURL:(NSURL *)url title:(NSString *)title selection:(NSString *)selection { | ||
NSString *password = [session password]; | ||
NSString *username = [session username]; | ||
|
||
NSString *query = @""; | ||
query = [query stringByAppendingFormat:@"username=%@&", URLEncode(username)]; | ||
if (password != nil && [password length] > 0) query = [query stringByAppendingFormat:@"password=%@&", URLEncode(password)]; | ||
if (title != nil && [title length] > 0) query = [query stringByAppendingFormat:@"title=%@&", URLEncode(title)]; | ||
if (selection != nil && [selection length] > 0) query = [query stringByAppendingFormat:@"&title=%@&", URLEncode(selection)]; | ||
query = [query stringByAppendingFormat:@"url=%@&", URLEncode([url absoluteString])]; | ||
|
||
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:kInstapaperAPIAddItemURL] autorelease]; | ||
NSData *data = [query dataUsingEncoding:NSUTF8StringEncoding]; | ||
[request setHTTPMethod: @"POST"]; | ||
[request setHTTPBody:data]; | ||
[request setValue:[NSString stringWithFormat:@"%u", [data length]] forHTTPHeaderField:@"Content-Length"]; | ||
[request setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField: @"Content-Type"]; | ||
|
||
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; | ||
[connection start]; | ||
[connection autorelease]; | ||
[self retain]; | ||
} | ||
|
||
- (void)addItemWithURL:(NSURL *)url title:(NSString *)title { | ||
[self addItemWithURL:url title:title selection:nil]; | ||
} | ||
|
||
- (void)addItemWithURL:(NSURL *)url { | ||
[self addItemWithURL:url title:nil selection:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// InstapaperSession.h | ||
// newsyc | ||
// | ||
// Created by Grant Paul on 3/10/11. | ||
// Copyright 2011 Xuzz Productions, LLC. All rights reserved. | ||
// | ||
|
||
#import "InstapaperAPI.h" | ||
|
||
@interface RLAInstapaperSession : NSObject { | ||
@private | ||
NSString *username; | ||
NSString *password; | ||
} | ||
|
||
@property (nonatomic, copy) NSString *username; | ||
@property (nonatomic, copy) NSString *password; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// InstapaperSession.m | ||
// newsyc | ||
// | ||
// Created by Grant Paul on 3/10/11. | ||
// Copyright 2011 Xuzz Productions, LLC. All rights reserved. | ||
// | ||
|
||
#import "InstapaperSession.h" | ||
|
||
@implementation RLAInstapaperSession | ||
@synthesize username, password; | ||
|
||
- (void)dealloc | ||
{ | ||
[username release]; | ||
[password release]; | ||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Copyright (c) 2011, Ryan Petrich | ||
|
||
Portions Copyright (c) 2011, Xuzz Productions, LLC | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
Neither the name of the Xuzz Productions, LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BUNDLE_NAME = ReadLater | ||
ReadLater_FILES = ReadLater.m Instapaper/InstapaperRequest.m Instapaper/InstapaperSession.m | ||
ReadLater_FRAMEWORKS = UIKit QuartzCore | ||
ReadLater_PRIVATE_FRAMEWORKS = Preferences WebKit WebCore | ||
ReadLater_INSTALL_PATH = /Library/ActionMenu/Plugins | ||
|
||
include framework/makefiles/common.mk | ||
include framework/makefiles/bundle.mk |
Oops, something went wrong.