-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDelegate.m
95 lines (83 loc) · 2.72 KB
/
AppDelegate.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
//
// AppDelegate.m
// Transcode
//
// Created by flamefork on 22.08.08.
// Copyright 2008 Flamefork. All rights reserved.
//
#import "AppDelegate.h"
#import "Clip.h"
#import "BitLyParser.h"
#import "GrowlSender.h"
#import "PrefsController.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
clip_ = [[Clip alloc] init];
[NSApp setServicesProvider:self];
NSUpdateDynamicServices();
growl_ = [[GrowlSender alloc] init];
[growl_ initializeGrowl];
PrefsController * prefs_;
prefs_ = [[PrefsController alloc] init];
//NSLog(@"Showing Preferences");
//[prefsController showWindow: self];
NSAppleEventDescriptor *evtDesc = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent];
AEEventID evtID = [evtDesc eventID];
if (evtDesc && (evtID == kAEReopenApplication || evtID == kAEOpenApplication) && [evtDesc eventClass] == kCoreEventClass) {
Clip * clip = [[Clip alloc] init];
[clip getData];
NSString * url_string = [clip string_];
NSString * url_scheme = [[NSURL URLWithString:url_string] scheme];
if (url_scheme == nil) {
// It is not a url
[growl_ growlString:@"No valid URL provided"];
} else {
// It's a url
BitLyParser * parser = [BitLyParser newWithURLFromString:[clip string_]];
[parser getData];
NSString * result = [parser parseXML];
if (result == nil) {
[growl_ growlString:@"No url in reply"];
} else {
[growl_ growlString:result];
[clip_ setData:result];
}
}
[NSApp terminate:self];
}
}
- (void)shortenURL:(NSPasteboard *)pboard
userData:(NSString *)userData
error:(NSString **)error
{
NSString *pboardString;
NSArray *types;
types = [pboard types];
if (![types containsObject:NSStringPboardType]) {
*error = @"Error: couldn't transcode text.";
return;
}
pboardString = [pboard stringForType:NSStringPboardType];
if (!pboardString) {
*error = @"Error: couldn't transcode text.";
return;
}
NSString * url_scheme = [[NSURL URLWithString:pboardString] scheme];
if (url_scheme == nil) {
// It is not a url
[growl_ growlString:@"No valid URL provided"];
} else {
// It's a url
BitLyParser * parser = [BitLyParser newWithURLFromString:pboardString];
[parser getData];
NSString * result = [parser parseXML];
if (result == nil) {
[growl_ growlString:@"No url in reply"];
} else {
[growl_ growlString:result];
[clip_ setData:result];
}
}
[NSApp terminate:self];
}
@end