marcusramberg / iusethis-utils

Various open source utils for the iusethis site

This URL has Read+Write access

marcusramberg (author)
Fri May 15 04:23:50 -0700 2009
commit  9b4510f7ba1dac004846e95c9816b66693325828
tree    7d6b97212cb757de0876cb3182224e404b78c6d0
parent  9f3a56c6b84613db7e5c194be06b9a9cc7d88e94
iusethis-utils / iusethis-quicksilver-plugin / iusethisAction.m
100644 79 lines (62 sloc) 2.833 kb
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
//
// iusethisAction.m
// iusethis
//
// Created by Marcus Ramberg on 15.05.09.
// Copyright Nordaaker Ltd 2009. All rights reserved.
//
 
#import "iusethisAction.h"
 
@implementation iusethisAction
 
- (QSObject *)openHomepageForApplication:(QSObject *)dObject{
   
    NSString *shortName=[self applicationShortName: [dObject stringValue]];
    NSWorkspace *ws=[NSWorkspace sharedWorkspace];
    [ws openURL: [NSURL URLWithString: [ NSString stringWithFormat: @"http://osx.iusethis.com/hp/%@",shortName ]]];
return nil;
}
 
- (QSObject *)downloadLatestForApplication:(QSObject *)dObject{
    
    NSString *shortName=[self applicationShortName: [dObject stringValue]];
    NSWorkspace *ws=[NSWorkspace sharedWorkspace];
    [ws openURL: [NSURL URLWithString: [ NSString stringWithFormat: @"http://osx.iusethis.com/dl/%@",shortName ]]];
return nil;
}
 
- (QSObject *)showIutProfileForApplication:(QSObject *)dObject{
    NSString *shortName=[self applicationShortName: [dObject stringValue]];
    NSWorkspace *ws=[NSWorkspace sharedWorkspace];
    [ws openURL: [NSURL URLWithString: [ NSString stringWithFormat: @"http://osx.iusethis.com/app/%@",shortName ]]];
return nil;
}
 
- (QSObject *)openIusethisWithTag:(QSObject *)dObject{
    NSString *tag=[dObject stringValue];
    NSWorkspace *ws=[NSWorkspace sharedWorkspace];
    [ws openURL: [NSURL URLWithString: [@"http://osx.iusethis.com/tag/" stringByAppendingString: [[tag stringByReplacing:@" " with:@"+"] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding ]]]];
return nil;
}
 
- (QSObject *)searchIusethisFor:(QSObject *)dObject{
    NSString *query=[dObject stringValue];
    NSWorkspace *ws=[NSWorkspace sharedWorkspace];
    [ws openURL: [NSURL URLWithString: [@"http://osx.iusethis.com/search?q=" stringByAppendingString: [ query stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]]];
return nil;
}
 
     
- (NSString *)applicationShortName:(NSString *)name {
    if (!name)
        return nil;
    
    static NSMutableCharacterSet *allowedCharacters = nil;
    if (!allowedCharacters) {
        allowedCharacters = [[NSMutableCharacterSet alphanumericCharacterSet] retain];
        [allowedCharacters addCharactersInString:@"-_@"];
    }
    
    NSMutableString *mname = [NSMutableString stringWithString:name];
    int i;
    for (i = 0; i < [mname length]; i++) {
        if ([allowedCharacters characterIsMember:[mname characterAtIndex:i]])
            continue;
        [mname replaceCharactersInRange:NSMakeRange(i--, 1) withString:@""];
    }
    name = [mname lowercaseString];
    
    // there is a length limitation for iusethis ids:
    // | short | varchar(30) | YES | UNI | NULL | |
    if ([name length] > 30)
        return [name substringToIndex:30];
    
    return name;
}
 
@end