-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainController+Utilities.m
212 lines (173 loc) · 6.42 KB
/
MainController+Utilities.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
// MainController+Utilities.m
// Toucan
//
// Created by will on 23/03/10.
// Copyright 2010 ExoApps. All rights reserved.
//
#import "MainController+Utilities.h"
@implementation MainController(Utilities)
# pragma mark -
# pragma mark Growl Notifications
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
{
BOOL resultKey = NO;
if (commandSelector == @selector(insertNewline:))
{
// enter pressed
resultKey = YES;
[self start: self];
}
else if(commandSelector == @selector(moveLeft:))
{
// left arrow pressed
resultKey = NO;
}
else if(commandSelector == @selector(moveRight:))
{
// rigth arrow pressed
resultKey = NO;
}
else if(commandSelector == @selector(moveUp:))
{
// up arrow pressed
resultKey = NO;
}
else if(commandSelector == @selector(moveDown:))
{
// down arrow pressed
resultKey = NO;
}
else if(commandSelector == @selector(cancelOperation:))
{
// esc pressed
resultKey = NO;
}
return resultKey;
}
- (NSDictionary *)registrationDictionaryForGrowl
{
NSArray * notifications;
notifications = [NSArray arrayWithObjects:
@"Download OK",
@"Download Fails",
@"Path has changed",
@"Connexion Failed",
@"Growl Started",
@"Growl Stopped",
nil];
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
notifications, GROWL_NOTIFICATIONS_ALL,
notifications, GROWL_NOTIFICATIONS_DEFAULT,
nil];
return (dict);
}
- (NSString *)stringFromFileSize:(int)theSize
{
float floatSize = theSize;
if(theSize < 1023) return [NSString stringWithFormat: @"%i bytes", theSize];
floatSize = floatSize / 1000;
if(floatSize < 1023) return [NSString stringWithFormat: @"%1.1f Ko", floatSize];
floatSize = floatSize / 1000;
if(floatSize < 1023) return [NSString stringWithFormat: @"%1.1f Mo", floatSize];
floatSize = floatSize / 1000;
return [NSString stringWithFormat: @"%1.1f Go", floatSize];
}
- (void)updateDockWithTitle:(NSString *)stats withIconName:(NSString *)icon
{
// NSDockTile * dockTile = [[NSApplication sharedApplication] dockTile];
// [dockTile setBadgeLabel: [NSString stringWithFormat: @"%i/%i", iii, max]];
NSDockTile * dockTile = [[NSApplication sharedApplication] dockTile];
//setup our image view for the dock tile
NSRect frame = NSMakeRect(0, 0, dockTile.size.width, dockTile.size.height);
NSImageView * dockImageView = [[NSImageView alloc] initWithFrame: frame];
[dockImageView setImage: [NSImage imageNamed: icon]];
//by default, add it to the NSDockTile
[dockTile setContentView: dockImageView];
[dockTile display];
//Show Notification Badge '45'
// [dockTile setShowsApplicationBadge: YES];
[dockTile setBadgeLabel: stats];
[dockImageView release];
UKDockProgressIndicator * pbdock = [[UKDockProgressIndicator alloc] init];
[pbdock setMaxValue: [self.itemsToDownload count]];
[pbdock setMinValue: 0];
[pbdock setDoubleValue: iii];
// [pbdock display];
[pbdock release];
}
- (void)deleteImagesFromArray:(NSMutableArray *)anArray itemsAtIndexes:(NSIndexSet *)indexes fromDisc:(BOOL)choice withFilePath:(NSString *)path
{
for(NSUInteger index = [indexes lastIndex]; index != NSNotFound; index = [indexes indexLessThanIndex: index])
{
if(choice == YES)
{
NSFileManager * manager = [NSFileManager defaultManager];
if(![manager movePath:
[path stringByAppendingPathComponent:
[[anArray objectAtIndex: index] valueForKey: @"name"]]
toPath: [[NSHomeDirectory() stringByAppendingPathComponent: @".Trash"] stringByAppendingPathComponent: [[anArray objectAtIndex: index] valueForKey: @"name"]]
handler: self])
[manager movePath: [path stringByAppendingPathComponent: [[anArray objectAtIndex: index] valueForKey: @"name"]]
toPath: [[NSHomeDirectory() stringByAppendingPathComponent: @".Trash"]
stringByAppendingPathComponent: [NSString stringWithFormat: @"%@-%@.%@", [[[anArray objectAtIndex: index] valueForKey: @"name"] stringByDeletingPathExtension], [NSDate date], [[[anArray objectAtIndex: index] valueForKey: @"name"] pathExtension]]]
handler: self];
}
[anArray removeObjectAtIndex: index];
}
}
- (void)folderChoiceClosed:(NSOpenPanel *)openPanel returnCode:(NSInteger)code contextInfo:(void *)contextInfo
{
if (code == NSOKButton)
{
NSArray * files = [openPanel filenames];
for(NSString * fileName in files)
{
DLog(@"%@",fileName);
id prefs = [[NSUserDefaultsController sharedUserDefaultsController] values];
[prefs setValue: fileName forKey: @"OutputFolder"];
id path = [prefs valueForKey: @"OutputFolder"];
id output = [path stringByAppendingPathComponent: [[searchTermTextField stringValue] capitalizedString]];
if(([createSearchFolder state] == 1) && ([[NSFileManager defaultManager] fileExistsAtPath: output]) && (![fileName isEqualToString: [[searchTermTextField stringValue] capitalizedString]])) [dest setStringValue: output];
else [dest setStringValue: path];
// if([createSearchFolder state] == 1) [dest setStringValue: output];
// else [dest setStringValue: path];
}
if(growlIsNotifying == YES)
[GrowlApplicationBridge notifyWithTitle: [NSString stringWithFormat: @"%@ Info",
[[NSFileManager defaultManager] displayNameAtPath: [[NSBundle mainBundle] bundlePath]]
]
description: [NSString stringWithFormat:
NSLocalizedString(@"GROWL_PATH_CHANGED_DESCRIPTION_NOTIFICATION",@"Dossier de destination modifié avec succès => %@"),
[dest stringValue]
]
notificationName: @"Path has changed"
iconData: nil
priority: 1
isSticky: NO
clickContext: nil];
[self tableViewStuff];
}
else
{
return;
}
}
- (IBAction)chooseSaveFolder:(id)sender
{
NSOpenPanel * oPanel = [NSOpenPanel openPanel];
[oPanel setCanChooseFiles: NO];
[oPanel setCanCreateDirectories: YES];
[oPanel setCanChooseDirectories: YES];
[oPanel setAllowsMultipleSelection: NO];
[oPanel setDirectory: [NSHomeDirectory() stringByAppendingPathComponent: @"Desktop"]];
[oPanel setTitle: NSLocalizedString(@"DESTINATION_FOLDER_DIALOG_TITLE",@"Dossier de destination")];
[oPanel beginSheetForDirectory: nil
file: nil
types: nil
modalForWindow: win
modalDelegate: self
didEndSelector: @selector(folderChoiceClosed:returnCode:contextInfo:)
contextInfo: nil];
}
@end