Permalink
Browse files

Merged pull request #31 from pjrobertson/web-search.

Web search plugin updated
  • Loading branch information...
2 parents 1945915 + a580fc2 commit 255cad407e391a78d77ea69f7bea6be249d17d70 @skurfer skurfer committed Apr 27, 2011
@@ -1,96 +1,167 @@
-{
- "CFBundleDevelopmentRegion" = English;
- CFBundleExecutable = "$(EXECUTABLE_NAME)";
- CFBundleIdentifier = "com.blacktree.Quicksilver.QSWebSearchPlugIn";
- "CFBundleInfoDictionaryVersion" = "6.0";
- CFBundleName = "Web Search Module";
- CFBundlePackageType = BNDL;
- CFBundleVersion = 11B;
- NSPrincipalClass = QSWebSearchPlugIn;
- QSActions = {
- QSURLFindWithAction = {
- actionClass = QSURLSearchActions;
- actionSelector = "doURLSearchForAction:withString:";
- description = "Find text on a website";
- directTypes = (
- NSStringPboardType,
- );
- icon = Find;
- name = "Find With...";
- reverseArguments = YES;
- validatesObjects = YES;
- };
- QSURLSearchForAction = {
- actionClass = QSURLSearchActions;
- actionSelector = "doURLSearchForAction:withString:";
- alternateAction = "QSURLSearchForAndReturnAction";
- description = "Search for text on a web site";
- directTypes = (
- "Apple URL pasteboard type",
- );
- icon = Find;
- name = "Search For...";
- rankModification = "4.000000";
- validatesObjects = YES;
- };
- "QSURLSearchForAndReturnAction" = {
- actionClass = QSURLSearchActions;
- actionSelector = "doURLSearchForAndReturnAction:withString:";
- description = "Returns the results of a query directly to the command window";
- directTypes = (
- "Apple URL pasteboard type",
- );
- enabled = NO;
- icon = Find;
- name = "Show Results for Search...";
- validatesObjects = YES;
- };
- };
- QSObjectSources = {
- QSWebSearchSource = QSWebSearchSource;
- };
- QSPlugIn = {
- author = "Blacktree, Inc.";
- categories = (
- Web,
- Search,
- );
- description = "Allows searching the web";
- icon = Find;
- "relatedBundles " = (
- "com.apple.Safari",
- );
- };
- QSPresetAdditions = (
- {
- ID = "QSPresetDocWebSearches";
- enabled = YES;
- name = "Web Searches (from docs.blacktree.com)";
- settings = {
- contentPrefix = "<div class=\"QSWebSearchContentStart\"></div>";
- contentSuffix = "<div class=\"QSWebSearchContentEnd\"></div>";
- path = "http://docs.blacktree.com/doku.php?id=quicksilver:web_search_list";
- };
- source = QSWebSource;
- },
- {
- ID = "QSPresetDocWebFullListSearches";
- enabled = NO;
- name = "Web Searches - Full List (from docs.blacktree.com)";
- settings = {
- contentPrefix = "<div class=\"QSWebSearchContentStart\"></div>";
- contentSuffix = "<div class=\"QSWebSearchContentEnd\"></div>";
- path = "http://docs.blacktree.com/quicksilver/extended_web_search_list";
- };
- source = QSWebSource;
- },
- );
- QSRegistration = {
- QSActionProviders = {
- QSURLSearchActions = QSURLSearchActions;
- };
- QSObjectSources = {
- QSWebSearchSource = QSWebSearchSource;
- };
- };
-}
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.blacktree.Quicksilver.QSWebSearchPlugIn</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>Web Search Module</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleVersion</key>
+ <string>213</string>
+ <key>NSPrincipalClass</key>
+ <string>QSWebSearchPlugIn</string>
+ <key>QSActions</key>
+ <dict>
+ <key>QSURLFindWithAction</key>
+ <dict>
+ <key>actionClass</key>
+ <string>QSURLSearchActions</string>
+ <key>actionSelector</key>
+ <string>doURLSearchForAction:withString:</string>
+ <key>description</key>
+ <string>Find text on a website</string>
+ <key>directTypes</key>
+ <array>
+ <string>NSStringPboardType</string>
+ </array>
+ <key>icon</key>
+ <string>Find</string>
+ <key>name</key>
+ <string>Find With...</string>
+ <key>reverseArguments</key>
+ <string>YES</string>
+ <key>validatesObjects</key>
+ <string>YES</string>
+ </dict>
+ <key>QSURLSearchForAction</key>
+ <dict>
+ <key>actionClass</key>
+ <string>QSURLSearchActions</string>
+ <key>actionSelector</key>
+ <string>doURLSearchForAction:withString:</string>
+ <key>alternateAction</key>
+ <string>QSURLSearchForAndReturnAction</string>
+ <key>description</key>
+ <string>Search for text on a web site</string>
+ <key>directTypes</key>
+ <array>
+ <string>Apple URL pasteboard type</string>
+ </array>
+ <key>icon</key>
+ <string>Find</string>
+ <key>name</key>
+ <string>Search For...</string>
+ <key>rankModification</key>
+ <string>4.000000</string>
+ <key>validatesObjects</key>
+ <string>YES</string>
+ </dict>
+ <key>QSURLSearchForAndReturnAction</key>
+ <dict>
+ <key>actionClass</key>
+ <string>QSURLSearchActions</string>
+ <key>actionSelector</key>
+ <string>doURLSearchForAndReturnAction:withString:</string>
+ <key>description</key>
+ <string>Returns the results of a query directly to the command window</string>
+ <key>directTypes</key>
+ <array>
+ <string>Apple URL pasteboard type</string>
+ </array>
+ <key>enabled</key>
+ <string>NO</string>
+ <key>icon</key>
+ <string>Find</string>
+ <key>name</key>
+ <string>Show Results for Search...</string>
+ <key>validatesObjects</key>
+ <string>YES</string>
+ </dict>
+ </dict>
+ <key>QSObjectSources</key>
+ <dict>
+ <key>QSWebSearchSource</key>
+ <string>QSWebSearchSource</string>
+ </dict>
+ <key>QSPlugIn</key>
+ <dict>
+ <key>author</key>
+ <string>Blacktree, Inc.</string>
+ <key>categories</key>
+ <array>
+ <string>Web</string>
+ <string>Search</string>
+ </array>
+ <key>description</key>
+ <string>Allows searching the web</string>
+ <key>icon</key>
+ <string>Find</string>
+ <key>relatedBundles </key>
+ <array>
+ <string>com.apple.Safari</string>
+ </array>
+ </dict>
+ <key>QSPresetAdditions</key>
+ <array>
+ <dict>
+ <key>ID</key>
+ <string>QSPresetDocWebSearchesSimple</string>
+ <key>enabled</key>
+ <string>YES</string>
+ <key>name</key>
+ <string>Web Searches (Simple)</string>
+ <key>settings</key>
+ <dict>
+ <key>contentPrefix</key>
+ <string>&lt;div class="QSWebSearchContentStart"&gt;&lt;/div&gt;</string>
+ <key>contentSuffix</key>
+ <string>&lt;div class="QSWebSearchContentEnd"&gt;&lt;/div&gt;</string>
+ <key>path</key>
+ <string>http://qs0.qsapp.com/plugin-data/web-search-list.php?type=simple</string>
+ </dict>
+ <key>source</key>
+ <string>QSWebSource</string>
+ </dict>
+ <dict>
+ <key>ID</key>
+ <string>QSPresetDocWebSearches</string>
+ <key>enabled</key>
+ <string>NO</string>
+ <key>name</key>
+ <string>Web Searches (Full List)</string>
+ <key>settings</key>
+ <dict>
+ <key>contentPrefix</key>
+ <string>&lt;div class="QSWebSearchContentStart"&gt;&lt;/div&gt;</string>
+ <key>contentSuffix</key>
+ <string>&lt;div class="QSWebSearchContentEnd"&gt;&lt;/div&gt;</string>
+ <key>path</key>
+ <string>http://qs0.qsapp.com/plugin-data/web-search-list.php?type=full</string>
+ </dict>
+ <key>source</key>
+ <string>QSWebSource</string>
+ </dict>
+ </array>
+ <key>QSRegistration</key>
+ <dict>
+ <key>QSActionProviders</key>
+ <dict>
+ <key>QSURLSearchActions</key>
+ <string>QSURLSearchActions</string>
+ </dict>
+ <key>QSObjectSources</key>
+ <dict>
+ <key>QSWebSearchSource</key>
+ <string>QSWebSearchSource</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
@@ -7,7 +7,7 @@
# define kURLSearchForAction @"QSURLSearchForAction"
# define kURLSearchForAndReturnAction @"QSURLSearchForAndReturnAction"
# define kURLFindWithAction @"QSURLFindWithAction"
-
+# define kQSSearchURLType @"QSSearchURLType"
@implementation QSURLSearchActions
- (NSString *) defaultWebClient{
@@ -24,8 +24,26 @@ - (NSString *) defaultWebClient{
- (NSArray *)validIndirectObjectsForAction:(NSString *)action directObject:(QSObject *)dObject{
// NSLog(@"request");
-
- if ([action isEqualToString:kURLSearchForAction] || [action isEqualToString:kURLSearchForAndReturnAction]){
+ // if it's a 'find with...' action, only return valid URLs with *** in them
+ if ([action isEqualToString:kURLFindWithAction]) {
+ // Get a list of all
+ NSMutableArray *urlObjects=[QSLib scoredArrayForString:nil inSet:[QSLib arrayForType:QSURLType]];
+ NSMutableArray *objects=[NSMutableArray arrayWithCapacity:1];
+ for(QSObject *individual in urlObjects){
+ // For some reason QSLib returns folders as QSURLType. This checks to make sure they're URLs
+ NSString *urlString=[[individual arrayForType:QSURLType]lastObject];
+ if(urlString){
+ NSURL *url=[NSURL URLWithString:[urlString URLEncoding]];
+ NSString *query=[url absoluteString];
+ if ([query rangeOfString:QUERY_KEY].location!=NSNotFound){
+ [objects addObject:individual];
+ }
+ }
+ }
+ return [NSArray arrayWithObjects:[NSNull null],objects,nil];
+ }
+ // if it's a 'search for...' action, return a text bot for text
+ else if ([action isEqualToString:kURLSearchForAction] || [action isEqualToString:kURLSearchForAndReturnAction]){
NSString *webSearchString=[[NSPasteboard pasteboardWithName:NSFindPboard] stringForType:NSStringPboardType];
return [NSArray arrayWithObject: [QSObject textProxyObjectWithDefaultValue:(webSearchString?webSearchString:@"")]]; //[QSLibarrayForType:NSFilenamesPboardType];
// return [NSArray arrayWithObject:[QSTextEntryProxy sharedInstance]]; //[QSLibarrayForType:NSFilenamesPboardType];
@@ -56,29 +74,42 @@ - (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSO
- (QSObject *)doURLSearchAction:(QSObject *)dObject{
- NSURL *url=[NSURL URLWithString:[dObject objectForType:QSURLType]];
- [[NSClassFromString(@"QSWebSearchController") sharedInstance] searchURL:url];
+ // define encoding of the string
+ CFStringEncoding encoding=[[dObject objectForMeta:kQSStringEncoding]intValue];
+ if(!encoding)
+ encoding = NSUTF8StringEncoding;
+
+ // get an NSURL
+
+ [[NSClassFromString(@"QSWebSearchController") sharedInstance] searchURL:[dObject objectForType:QSURLType]];
return nil;
}
+#warning encoding here is returning 'null'
+// The encoding of the object is returning null. This will break in a future release of OS X
- (QSObject *)doURLSearchForAction:(QSObject *)dObject withString:(QSObject *)iObject{
for(NSString * urlString in [dObject arrayForType:QSURLType]){
- NSURL *url=[NSURL URLWithString:urlString];
-
- NSString *string=[iObject stringValue];
CFStringEncoding encoding=[[dObject objectForMeta:kQSStringEncoding]intValue];
- [[NSClassFromString(@"QSWebSearchController") sharedInstance] searchURL:url forString:string encoding:encoding];
+ // Make sure characters such as | are escaped
+ if(!encoding)
+ encoding = NSUTF8StringEncoding;
+
+ NSString *string=[iObject stringValue];
+ [[NSClassFromString(@"QSWebSearchController") sharedInstance] searchURL:urlString forString:string encoding:encoding];
}
return nil;
}
- (QSObject *)doURLSearchForAndReturnAction:(QSObject *)dObject withString:(QSObject *)iObject{
for(NSString * urlString in [dObject arrayForType:QSURLType]){
- NSURL *url=[NSURL URLWithString:urlString];
- NSString *string=[iObject stringValue];
CFStringEncoding encoding=[[dObject objectForMeta:kQSStringEncoding]intValue];
- NSString *query=[[NSClassFromString(@"QSWebSearchController") sharedInstance] resolvedURL:url forString:string encoding:encoding];
+ if(!encoding)
+ encoding = NSUTF8StringEncoding;
+
+ NSString *string=[iObject stringValue];
+
+ NSString *query=[[NSClassFromString(@"QSWebSearchController") sharedInstance] resolvedURL:urlString forString:string encoding:encoding];
BOOL post=NO;
- NSURL *queryURL=nil;
+ NSURL *url = [NSURL URLWithString:query];
if ([[url scheme]isEqualToString:@"qssp-http"]){
query=[self openPOSTURL:[NSURL URLWithString:[query stringByReplacing:@"qssp-http" with:@"http"]]];
// return;
@@ -18,9 +18,9 @@
//- (IBAction) hideSearchView:sender;
- (IBAction) showSearchView:sender;
-- (void)searchURL:(NSURL *)searchURL;
+- (void)searchURL:(NSString *)searchURL;
- (void)openPOSTURL:(NSURL *)searchURL;
-- (void)searchURL:(NSURL *)searchURL forString:(NSString *)string;
+- (void)searchURL:(NSString *)searchURL forString:(NSString *)string;
+ (id)sharedInstance;
@end
Oops, something went wrong.

0 comments on commit 255cad4

Please sign in to comment.