forked from mvexel/MilkMaid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MilkMaidWindowController.m
executable file
·615 lines (511 loc) · 23.3 KB
/
MilkMaidWindowController.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
//
// MilkMaidWindowController.m
// MilkMaid
//
// Created by Gregamel on 2/28/10.
// Copyright 2010 JGA. All rights reserved.
//
#import "MilkMaidWindowController.h"
#define TOKEN @"Token"
#define LAST_LIST @"LastList"
#define TAGS @"Tags"
@implementation MilkMaidWindowController
-(void)awakeFromNib {
[self.window setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
NSString *apiKey = @"1734ba9431007c2242b6865a69940aa5";
NSString *secret = @"72d1c12ffb26e759";
priority1Image = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"priority1" ofType:@"png"]];
priority2Image = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"priority2" ofType:@"png"]];
priority3Image = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"priority3" ofType:@"png"]];
id tags = [[NSUserDefaults standardUserDefaults] objectForKey:TAGS];
if (tags) {
tagList = [[NSMutableArray alloc] initWithArray:[(NSMutableArray*)tags sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
} else {
tagList = [[NSMutableArray alloc] init];
}
[progress setForeColor:[NSColor whiteColor]];
[progress startAnimation:nil];
[taskTable setDelegate:self];
[taskTable setDataSource:self];
//return;
rtmController = [[EVRZRtmApi alloc] initWithApiKey:apiKey andApiSecret:secret];
[NSThread detachNewThreadSelector:@selector(checkToken) toTarget:self withObject:nil];
}
- (void)checkToken {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString * token = [[NSUserDefaults standardUserDefaults] objectForKey:TOKEN];
if (token) {
rtmController.token = token;
NSDictionary *data = [rtmController dataByCallingMethod:@"rtm.auth.checkToken" andParameters:[[NSDictionary alloc]init] withToken:YES];
if ([[data objectForKey:@"stat"] isEqualToString:@"ok"]) {
timeline = [rtmController timeline];
[timeline retain];
[self getLists];
//[self performSelectorOnMainThread:@selector(getLists) withObject:nil waitUntilDone:NO];
} else {
[self getAuthToken];
}
} else {
[self getAuthToken];
}
[pool release];
}
-(void)getAuthToken {
NSString *frob = [rtmController frob];
NSString *url = [rtmController authUrlForPerms:@"delete" withFrob:frob];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
[self performSelectorOnMainThread:@selector(showAuthMessage:) withObject:frob waitUntilDone:NO];
//[self showAuthMessage:frob];
}
-(void)showAuthMessage:(NSString*)frob {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Done"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Accept Permissions"];
[alert setInformativeText:@"A browser has been opened. Please press the \"OK, I'll allow it\" button then press the Done button below."];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] == NSAlertFirstButtonReturn) {
NSString *token = [rtmController tokenWithFrob:frob];
rtmController.token = token;
[[NSUserDefaults standardUserDefaults] setObject:token forKey:TOKEN];
[self performSelectorOnMainThread:@selector(getLists) withObject:nil waitUntilDone:NO];
//[self doneLoading];
}
[alert release];
}
-(RTMSearch*)getCurrentList {
return [lists objectAtIndex:[listPopUp indexOfSelectedItem]-1];
}
- (void)getLists {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDictionary *data = [rtmController dataByCallingMethod:@"rtm.lists.getList" andParameters:[[NSDictionary alloc]init] withToken:YES];
lists = [RTMHelper getLists:data];
for (RTMSearch *list in lists) {
[listPopUp addItemWithTitle:list.title];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"tagsInDropDown"]) {
for (NSString *tag in tagList) {
[self addTagToDropDown:tag];
}
}
[lists retain];
//[data release];
[pool release];
[progress setHidden:YES];
[self performSelectorOnMainThread:@selector(selectLast) withObject:nil waitUntilDone:NO];
}
-(void)setLoadLastList:(BOOL)load {
loadLastList = load;
}
-(void)selectLast {
if (loadLastList) {
NSString *lastList = [[NSUserDefaults standardUserDefaults] objectForKey:LAST_LIST];
if (lastList) {
[listPopUp selectItemWithTitle:lastList];
[self listSelected:nil];
}
}
}
-(void)listSelected:(id)sender {
NSInteger selectedIndex = [listPopUp indexOfSelectedItem];
selectedIndex--;
if (selectedIndex > -1) {
RTMSearch *selectedList = [self getCurrentList];
if (!lastListTitle || ![selectedList.title isEqualToString:lastListTitle]) {
[[taskScroll contentView] scrollToPoint:NSMakePoint(0, 0)];
if (![selectedList.searchType isEqualToString:@"search"]) {
[[NSUserDefaults standardUserDefaults] setObject:selectedList.title forKey:LAST_LIST];
}
lastListTitle = selectedList.title;
[NSThread detachNewThreadSelector:@selector(getTasks) toTarget:self withObject:nil];
}
}
}
-(void)getTasks {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[progress setHidden:NO];
NSDictionary *data = [rtmController dataByCallingMethod:@"rtm.tasks.getList" andParameters:[[self getCurrentList] searchParams] withToken:YES];
RTMHelper *rtmHelper = [[RTMHelper alloc] init];
tasks = [rtmHelper getFlatTaskList:data];
[self performSelectorOnMainThread:@selector(loadTaskData) withObject:nil waitUntilDone:NO];
[tasks retain];
[rtmHelper release];
[pool release];
[progress setHidden:YES];
}
-(void)menuRefresh:(id)sender {
[NSThread detachNewThreadSelector:@selector(getTasks) toTarget:self withObject:nil];
}
-(void)loadTaskData {
//NSLog(@"%@", tasks);
[self.window setTitle:[NSString stringWithFormat:@"MilkMaid (%d)", [tasks count]]];
if ([tasks count] != 0) {
[[[NSApplication sharedApplication] dockTile] setBadgeLabel:[[NSNumber numberWithInt:[tasks count]] stringValue]];
} else {
[[[NSApplication sharedApplication] dockTile] setBadgeLabel:@""];
}
for (NSDictionary *task in tasks) {
[self addGlobalTags:[task objectForKey:@"tags"]];
}
// sorting of the array with priority
[tasks sortUsingComparator:^(NSDictionary *task1, NSDictionary *task2){
NSString *pri1 = [task1 objectForKey:@"priority"];
NSString *pri2 = [task2 objectForKey:@"priority"];
return [pri1 caseInsensitiveCompare:pri2];
}] ;
[taskTable reloadData];
}
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [tasks count];
}
-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
//check type of cell
id cell = [tableColumn dataCellForRow:row];
//NSLog(@"%@", cell);
if ([cell isMemberOfClass:[BWTransparentCheckboxCell class]]) {
return [NSNumber numberWithInteger:NSOffState];
} else if ([cell isMemberOfClass:[NSImageCell class]]) {
NSDictionary *task = [tasks objectAtIndex:row];
NSString *pri = [task objectForKey:@"priority"];
if ([pri isEqualToString:@"1"]) {
return priority1Image;
} else if ([pri isEqualToString:@"2"]) {
return priority2Image;
} else if ([pri isEqualToString:@"3"]) {
return priority3Image;
} else {
return nil;
}
} else {//if ([cell isMemberOfClass:[BWTransparentTableViewCell class]]) {
NSDictionary *task = [tasks objectAtIndex:row];
id due = [task objectForKey:@"due"];
if ([due isKindOfClass:[NSDate class]]) {
[cell setAlternate2Text:[due relativeFormattedDateOnly]];
if ([due isPastDate] || [[NSDate date] isEqualToDate:due]) {
[cell setBold:YES];
}
} else {
[cell setAlternate2Text:@""];
[cell setBold:NO];
}
[cell setAlternateText:[[task objectForKey:@"tags"] componentsJoinedByString:@","]];
return [task objectForKey:@"name"];
}
}
-(void)addTagToDropDown:(NSString*)tagName {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"tagsInDropDown"]) {
NSString *tag = [NSString stringWithFormat:@"#%@", tagName];
RTMSearch *search = [[RTMSearch alloc]
initWithTitle:tag
searchType:@"tag"
searchParams:[[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"tag:%@ and status:incomplete",tagName], @"filter", nil]
addAttributes:tag];
[lists addObject:search];
[listPopUp addItemWithTitle:tag];
}
}
-(void)addGlobalTags:(NSArray*)tags {
for (NSString *tag in tags) {
if (![tagList containsObject:tag]){
[tagList addObject:tag];
[self addTagToDropDown:tag];
}
}
[tagList retain];
[[NSUserDefaults standardUserDefaults] setObject:tagList forKey:TAGS];
}
-(void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSDictionary *task = [tasks objectAtIndex:row];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", nil]];
[tasks removeObject:task];
[NSThread detachNewThreadSelector:@selector(completeTask:) toTarget:self withObject:params];
[self loadTaskData];
}
-(void)completeTask:(NSDictionary *)taskInfo {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDictionary *data = [rtmController dataByCallingMethod:@"rtm.tasks.complete" andParameters:taskInfo withToken:YES];
[pool release];
[progress setHidden:YES];
}
-(void)menuAddTask:(id)sender {
if (!singleInputWindowController)
singleInputWindowController = [[SingleInputWindowController alloc] initWithWindowNibName:@"SingleInput"];
[singleInputWindowController setButtonText:@"Add Task"];
NSWindow *sheet = [singleInputWindowController window];
[NSApp beginSheet:sheet modalForWindow:self.window modalDelegate:self
didEndSelector:@selector(closeAddTaskSheet:returnCode:contextInfo:) contextInfo:nil];
}
-(void)closeAddTaskSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
[sheet orderOut:self];
if (returnCode == 1) {
NSString *task = [singleInputWindowController text];
[NSThread detachNewThreadSelector:@selector(addTask:) toTarget:self withObject:task];
}
}
-(void)addTask:(NSString*)task {
[progress setHidden:NO];
RTMSearch *currentList = [self getCurrentList];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (currentList.addAttributes)
task = [NSString stringWithFormat:@"%@ %@", task, currentList.addAttributes];
NSMutableDictionary *orgParams = [[NSMutableDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, task, @"1", nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"name", @"parse", nil]];
NSMutableDictionary *params = [orgParams mutableCopy];
if (currentList.addParams) {
[params addEntriesFromDictionary:currentList.addParams];
}
NSDictionary * returnValues= [rtmController dataByCallingMethod:@"rtm.tasks.add" andParameters:params withToken:YES];
NSDictionary* error = [returnValues objectForKey:@"err"];
if (error ) {
// we have an error!
if ([(NSString*)[error valueForKey:@"code"] isEqualToString:@"4020"]) {
//this is the error code used for @"Cannot add task to a Smart List.", hence we need to kill the list add
NSDictionary * secondReturn= [rtmController dataByCallingMethod:@"rtm.tasks.add" andParameters:orgParams withToken:YES];
NSDictionary* error2 = [secondReturn objectForKey:@"err"];
if (error2) {
NSLog(@"Error 2: %@",error2);
}
}
}
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)addTasks:(NSArray*)newTasksArray {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *newTasks = [newTasksArray objectAtIndex:0];
NSString *globalAttributes = [newTasksArray objectAtIndex:1];
RTMSearch *currentSearch = [self getCurrentList];
for (NSString *t in newTasks) {
NSString *globalTaskAttributes = (currentSearch.addAttributes)?currentSearch.addAttributes:@"";
NSString *taskName = [NSString stringWithFormat:@"%@ %@ %@", t, globalTaskAttributes, globalAttributes];
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, taskName, @"1", nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"name", @"parse", nil]];
if (currentSearch.addParams) {
[params addEntriesFromDictionary:currentSearch.addParams];
}
[rtmController dataByCallingMethod:@"rtm.tasks.add" andParameters:params withToken:YES];
}
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)menuShowLists:(id)sender {
[listPopUp performClick:self];
}
-(void)menuPriority:(id)sender {
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], [sender title], nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", @"priority", nil]];
[NSThread detachNewThreadSelector:@selector(setPriority:) toTarget:self withObject:params];
}
-(void)setPriority:(NSDictionary*)params {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[rtmController dataByCallingMethod:@"rtm.tasks.setPriority" andParameters:params withToken:YES];
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)menuDueDate:(id)sender {
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], [sender title], @"1", nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", @"due", @"parse", nil]];
[NSThread detachNewThreadSelector:@selector(setDueDate:) toTarget:self withObject:params];
}
-(void)setDueDate:(NSDictionary*)params {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[rtmController dataByCallingMethod:@"rtm.tasks.setDueDate" andParameters:params withToken:YES];
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)menuPostponeTask:(id)sender {
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", nil]];
[NSThread detachNewThreadSelector:@selector(postponeTask:) toTarget:self withObject:params];
}
-(void)postponeTask:(NSDictionary*)params {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[rtmController dataByCallingMethod:@"rtm.tasks.postpone" andParameters:params withToken:YES];
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)menuDeleteTask:(id)sender {
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", nil]];
[NSThread detachNewThreadSelector:@selector(deleteTask:) toTarget:self withObject:params];
}
-(void)deleteTask:(NSDictionary*)params {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[rtmController dataByCallingMethod:@"rtm.tasks.delete" andParameters:params withToken:YES];
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)menuSearch:(id)sender {
if (!singleInputWindowController)
singleInputWindowController = [[SingleInputWindowController alloc] initWithWindowNibName:@"SingleInput"];
[singleInputWindowController setButtonText:@"Search"];
NSWindow *sheet = [singleInputWindowController window];
[NSApp beginSheet:sheet modalForWindow:self.window modalDelegate:self
didEndSelector:@selector(closeSearchSheet:returnCode:contextInfo:) contextInfo:nil];
}
-(void)search:(NSString*)searchString {
RTMSearch *search = [[RTMSearch alloc]
initWithTitle:searchString
searchType:@"search"
searchParams:[[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"(%@) and status:incomplete",searchString], @"filter", nil]
addAttributes:nil];
[lists addObject:search];
[listPopUp addItemWithTitle:searchString];
[listPopUp selectItemWithTitle:searchString];
[self listSelected:nil];
}
-(void)closeSearchSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
[sheet orderOut:self];
if (returnCode == 1) {
NSString *currentSearch = [singleInputWindowController text];
[self search:currentSearch];
//[NSThread detachNewThreadSelector:@selector(searchTasks:) toTarget:self withObject:currentSearch];
}
}
-(void)menuMultiAdd:(id)sender {
if (!multiAddWindowController)
multiAddWindowController = [[MultiAddWindowController alloc] initWithWindowNibName:@"MultiAdd"];
NSWindow *sheet = [multiAddWindowController window];
[NSApp beginSheet:sheet modalForWindow:self.window modalDelegate:self
didEndSelector:@selector(closeMultiAddSheet:returnCode:contextInfo:) contextInfo:nil];
}
-(void)closeMultiAddSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
[sheet orderOut:self];
if (returnCode == 1) {
NSArray *newTasks = [multiAddWindowController tasks];
NSString *globalAttributes = [multiAddWindowController globalAttributes];
[NSThread detachNewThreadSelector:@selector(addTasks:) toTarget:self withObject:[NSArray arrayWithObjects: newTasks,globalAttributes,nil]];
}
}
-(void)menuRenameTask:(id)sender {
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
if (!singleInputWindowController)
singleInputWindowController = [[SingleInputWindowController alloc] initWithWindowNibName:@"SingleInput"];
[singleInputWindowController setButtonText:@"Rename"];
[singleInputWindowController setTextValue:[task objectForKey:@"name"]];
NSWindow *sheet = [singleInputWindowController window];
[NSApp beginSheet:sheet modalForWindow:self.window modalDelegate:self
didEndSelector:@selector(closeRenameTaskSheet:returnCode:contextInfo:) contextInfo:nil];
}
-(void)closeRenameTaskSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
[sheet orderOut:self];
if (returnCode == 1) {
NSString *taskName = [singleInputWindowController text];
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], taskName,nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", @"name", nil]];
[NSThread detachNewThreadSelector:@selector(renameTask:) toTarget:self withObject:params];
}
}
-(void)renameTask:(NSDictionary*)params {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[rtmController dataByCallingMethod:@"rtm.tasks.setName" andParameters:params withToken:YES];
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)menuSetTagsTask:(id)sender {
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
if (!singleInputWindowController)
singleInputWindowController = [[SingleInputWindowController alloc] initWithWindowNibName:@"SingleInput"];
[singleInputWindowController setButtonText:@"Set Tags"];
[singleInputWindowController setTextValue:[[task objectForKey:@"tags"] componentsJoinedByString:@","]];
NSWindow *sheet = [singleInputWindowController window];
[NSApp beginSheet:sheet modalForWindow:self.window modalDelegate:self
didEndSelector:@selector(closeSetTagsTaskSheet:returnCode:contextInfo:) contextInfo:nil];
}
-(void)closeSetTagsTaskSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
[sheet orderOut:self];
if (returnCode == 1) {
NSString *tags = [singleInputWindowController text];
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], tags,nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", @"tags", nil]];
[NSThread detachNewThreadSelector:@selector(setTagsTask:) toTarget:self withObject:params];
}
}
-(void)setTagsTask:(NSDictionary*)params {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[rtmController dataByCallingMethod:@"rtm.tasks.setTags" andParameters:params withToken:YES];
[self getTasks];
[pool release];
[progress setHidden:YES];
}
-(void)menuSetDueTask:(id)sender {
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
if (!singleInputWindowController)
singleInputWindowController = [[SingleInputWindowController alloc] initWithWindowNibName:@"SingleInput"];
[singleInputWindowController setButtonText:@"Set Due"];
[singleInputWindowController setTextValue:[[task objectForKey:@"due"] isKindOfClass:[NSDate class]] ? [[task objectForKey:@"due"] relativeFormattedDateOnly] : @""];
NSWindow *sheet = [singleInputWindowController window];
[NSApp beginSheet:sheet modalForWindow:self.window modalDelegate:self
didEndSelector:@selector(closeSetDueTaskSheet:returnCode:contextInfo:) contextInfo:nil];
}
-(void)closeSetDueTaskSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
[sheet orderOut:self];
if (returnCode == 1) {
NSString *due = [singleInputWindowController text];
NSInteger rowIndex = [taskTable selectedRow];
if (rowIndex == -1)
return;
NSDictionary *task = [tasks objectAtIndex:rowIndex];
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:timeline, [task objectForKey:@"list_id"], [task objectForKey:@"taskseries_id"], [task objectForKey:@"task_id"], due, @"1", nil]
forKeys:[NSArray arrayWithObjects:@"timeline", @"list_id", @"taskseries_id", @"task_id", @"due", @"parse", nil]];
[NSThread detachNewThreadSelector:@selector(setDueTask:) toTarget:self withObject:params];
}
}
-(void)setDueTask:(NSDictionary*)params {
[progress setHidden:NO];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[rtmController dataByCallingMethod:@"rtm.tasks.setDueDate" andParameters:params withToken:YES];
[self getTasks];
[pool release];
[progress setHidden:YES];
}
@end