-
Notifications
You must be signed in to change notification settings - Fork 2
/
QSURLSearchActions.m
118 lines (98 loc) · 4.64 KB
/
QSURLSearchActions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#import "QSURLSearchActions.h"
#import "QSWebSearchController.h"
# define kURLSearchForAction @"QSURLSearchForAction"
# define kURLSearchForAndReturnAction @"QSURLSearchForAndReturnAction"
# define kURLFindWithAction @"QSURLFindWithAction"
@implementation QSURLSearchActions
- (NSString *) defaultWebClient{
NSURL *appURL = nil;
OSStatus err;
err = LSGetApplicationForURL((CFURLRef)[NSURL URLWithString: @"http:"],kLSRolesAll, NULL, (CFURLRef *)&appURL);
if (err != noErr) NSLog(@"error %ld", (long)err);
// else NSLog(@"%@", appURL);
return [appURL path];
}
- (NSArray *)validIndirectObjectsForAction:(NSString *)action directObject:(QSObject *)dObject{
// if it's a 'find with...' action, only return search URLs
if ([action isEqualToString:kURLFindWithAction]) {
return [QSLib scoredArrayForType:QSSearchURLType];
}
// 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];
}
return nil;
}
- (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSObject *)iObject{
NSString *urlString=[[dObject arrayForType:QSSearchURLType] lastObject];
NSMutableArray *newActions=[NSMutableArray arrayWithCapacity:1];
NSString *query = nil;
if (urlString){
NSURL *url=[NSURL URLWithString:[urlString URLEncoding]];
query =[url absoluteString];
}
if (query) {
[newActions addObject:kURLSearchForAction];
[newActions addObject:kURLSearchForAndReturnAction];
}
else if ([dObject containsType:QSTextType] && ![dObject containsType:QSFilePathType]) {
[newActions addObject:kURLFindWithAction];
}
return newActions;
}
- (QSObject *)doURLSearchAction:(QSObject *)dObject{
// get an NSURL
[[QSWebSearchController sharedInstance] searchURL:[dObject objectForType:QSSearchURLType]];
return nil;
}
- (QSObject *)doURLSearchForAction:(QSObject *)dObject withString:(QSObject *)iObject{
for(NSString * urlString in [dObject arrayForType:QSSearchURLType]){
for (QSObject *obj in [iObject splitObjects]) {
NSString *string = [obj stringValue];
if (![string length]) {
NSBeep();
NSLog(@"web search attempted with no search terms");
continue;
}
[[QSWebSearchController sharedInstance] searchURL:urlString forString:string];
}
}
return nil;
}
- (QSObject *)doURLSearchForAndReturnAction:(QSObject *)dObject withString:(QSObject *)iObject{
QSWebSearchController *c = [QSWebSearchController sharedInstance];
QSGCDAsync(^{
for(NSString * urlString in [dObject arrayForType:QSSearchURLType]){
NSString *string=[iObject stringValue];
NSString *query=[c resolvedURL:urlString forString:string];
BOOL post=NO;
NSURL *url = [NSURL URLWithString:query];
if ([[url scheme]isEqualToString:@"qssp-http"]){
[c openPOSTURL:[NSURL URLWithString:[query stringByReplacingOccurrencesOfString:@"qssp-http" withString:@"http"]]];
// return;
} else if ([[url scheme]isEqualToString:@"http-post"]){
NSBeep();
post=YES;
query=[query stringByReplacingOccurrencesOfString:@"http-post" withString:@"http"];
// return;
} else if ([[url scheme]isEqualToString:@"qss-http"]){
query=[query stringByReplacingOccurrencesOfString:@"qss-http" withString:@"http"];
} else if ([[url scheme]isEqualToString:@"qss-https"]) {
query=[query stringByReplacingOccurrencesOfString:@"qss-https" withString:@"https"];
}else{
}
id <QSParser> parser=[QSReg instanceForKey:@"html" inTable:@"QSURLTypeParsers"];
//NSLog(@" %@ %@",type,parser);
[QSTasks updateTask:@"DownloadPage" status:@"Downloading Page" progress:0];
NSMutableArray *children = [[parser objectsFromURL:[NSURL URLWithString:query] withSettings:nil] mutableCopy];
[QSTasks removeTask:@"DownloadPage"];
QSGCDMainAsync(^{
[[QSReg preferredCommandInterface] showArray:children];
});
}
});
return nil;
}
@end