/
GLGUIController.m
880 lines (813 loc) · 28.9 KB
/
GLGUIController.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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
//
// GLLauncherController.h
// GameLauncher
//
// Created by Adam on 25/05/05.
// Copyright 2005 2Sublime.com. All rights reserved.
//
#import "GLGUIController.h"
@implementation GLGUIController
static BOOL alwaysOnTop;
static BOOL shouldMini;
#pragma mark Initialisation/Accessors
static GLGUIController *sharedInstance = nil;
+ (GLGUIController *)sharedInstance
{
return sharedInstance ? sharedInstance : [[self alloc] init];
}
- (void)awakeFromNib
{
}
- (id)init
{
if (sharedInstance) {
[self dealloc];
} else {
sharedInstance = [super init];
//threads
[NSThread prepareForInterThreadMessages];
mainThread = [NSThread currentThread];
[NSThread detachNewThreadSelector:@selector(startRunLoop:)
toTarget:[GLLauncherController sharedInstance]
withObject:mainThread];
//defaults
defaults = [NSUserDefaults standardUserDefaults];
//applistview
applicationList = [NSMutableArray new];
//notifications
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(startProcessTableTimerNotification:)
name:GLStartProcessTableTimerNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(stopProcessTableTimerNotification:)
name:GLStopProcessTableTimerNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(reloadProcessTableNotification:)
name:GLReloadProcessTableNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(startProgressIndTimerNotification:)
name:GLStartProgressTimerNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(stopProgressIndTimerNotification:)
name:GLStopProgressTimerNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(hideSystemUINotification:)
name:GLHideSystemUINotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(revertSystemUINotification:)
name:GLRevertSystemUINotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(launcherBeginQuitAllNotification:)
name:GLBeginQuitAllNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(launcherWillLaunchNotification:)
name:GLWillLaunchNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(launcherBeginRelaunchAllNotification:)
name:GLBeginRelaunchAllNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(launcherDidFinishLaunchingNotification:)
name:GLDidFinishLaunchingNotification
object:nil];
}
return sharedInstance;
}
- (void) dealloc
{
[applicationList release];
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
//check for last crash
UKCrashReporterCheckForCrash();
//set main window position
BOOL quitSuccess = [defaults boolForKey:GLQuitSuccessKey];
if (!quitSuccess) {
[mainWindow center];
[defaults setObject:[NSNumber numberWithBool:NO] forKey:GLQuitSuccessKey];
}
//update defaults if this is first run
NSMutableDictionary *initDefaults = [NSMutableDictionary dictionary];
[initDefaults setValue:[NSNumber numberWithBool:YES]
forKey:GLAppFirstRunKey];
[initDefaults setValue:[NSNumber numberWithBool:YES]
forKey:GLProcessEnabledToggleKey];
[initDefaults setObject:[NSMutableDictionary dictionary]
forKey:GLSelectedApplicationsListKey];
[initDefaults setObject:GLInitLaunchAppPath
forKey:GLLaunchAppPathKey];
[initDefaults setObject:NSStringFromRect([mainWindow frame]) forKey:GLMaxiWindowSizeKey];
NSRect miniFrame;
miniFrame.size = [mainWindow minSize];
miniFrame.origin.x = [mainWindow frame].origin.x;
miniFrame.origin.y = [mainWindow frame].origin.y +
[mainWindow frame].size.height -
[mainWindow minSize].height;
[initDefaults setObject:NSStringFromRect(miniFrame) forKey:GLMiniWindowSizeKey];
[[NSUserDefaults standardUserDefaults] registerDefaults:initDefaults];
[self initGUI];
}
- (void)initGUI
{
//reload application selected
[self setLaunchAppPath:[defaults stringForKey:GLLaunchAppPathKey]];
//process enabled toggle
processEnabledToggle = [defaults boolForKey:GLProcessEnabledToggleKey];
[self updateProcessToggleGUI];
//set tableview sorting
NSData *data = [defaults dataForKey:GLTableSortDescriptorsKey];
if (data) {
[applicationListView setSortDescriptors:(NSArray *)[NSUnarchiver unarchiveObjectWithData:data]];
}
//load selected applictions
selectedApplicationsDefaultsDict = [NSMutableDictionary dictionaryWithDictionary:[defaults objectForKey:GLSelectedApplicationsListKey]];
[selectedApplicationsDefaultsDict retain];
selectedApplications = [NSMutableDictionary dictionaryWithDictionary:[selectedApplicationsDefaultsDict objectForKey:[NSString stringWithFormat:@"%d", processEnabledToggle]]];
[selectedApplications retain];
//start table update timer
[[NSNotificationCenter defaultCenter]
postNotificationName:GLStartProcessTableTimerNotification object:self];
//setup main window
//set window title
srandom(time(NULL));
int i = (abs(random())%[NSLocalizedStringFromTable(@"GLAltWindowTitleNum", GLLocalizablePlist, @"GLAltWindowTitleNum") intValue])+1;
NSString *quote = [NSString stringWithFormat:@"GLAltWindowTitle%d",i];
NSString *windowTitle = @"\n";
windowTitle = [windowTitle stringByAppendingFormat:@" %@", [NSString
stringWithString:NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", @"CFBundleName")]];
windowTitle = [windowTitle stringByAppendingFormat:@" %@", [NSString
stringWithString:NSLocalizedStringFromTable(quote, GLLocalizablePlist, @"GLAltWindowTitle")]];
[mainWindow setTitle:windowTitle];
//unround window
if ([mainWindow respondsToSelector:@selector(setBottomCornerRounded:)])
[mainWindow setBottomCornerRounded:NO];
// [mainWindow setFrame:NSRectFromString([defaults stringForKey:GLMaxiWindowSizeKey]) display:NO];
// Now show the window... (By default we've set it in IB not to be visible at start)
[mainWindow makeKeyAndOrderFront:nil];
[mainWindow makeMainWindow];
//kick off nag screen thread
[NSBundle loadNibNamed:@"NagWebView" owner:self];
if (![defaults boolForKey:GLAppFirstRunKey]) {
[[GLNagController sharedInstance] setNextNagTimer];
}
}
- (void)updateProcessToggleGUI
{
[toggleAllButton setToolTip:@"Toggle selection state"];
if (processEnabledToggle) {
//set icon to minus
[toggleAllButton setImage:[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"bt-remove" ofType:@"png"]]];
[toggleAllButton setAlternateImage:[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"bt-remove_p" ofType:@"png"]]];
} else {
//set icon to tick
[toggleAllButton setImage:[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"bt-add" ofType:@"png"]]];
[toggleAllButton setAlternateImage:[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"bt-add_p" ofType:@"png"]]];
}
}
- (void)updateMainWindowZoomGUI
{
if (!isMini) {
[defaults setObject:NSStringFromRect([mainWindow frame]) forKey:GLMaxiWindowSizeKey];
} else {
[defaults setObject:NSStringFromRect([mainWindow frame]) forKey:GLMiniWindowSizeKey];
}
isMini = !isMini;
[mainWindow setFrame:[self mainWindowFrame] display:YES animate:YES];
}
- (NSRect)mainWindowFrame
{
NSRect newWinFrame;
if (isMini) {
newWinFrame = NSRectFromString([defaults stringForKey:GLMiniWindowSizeKey]);
[quitCurrentAppMenuItem setEnabled:NO];
[toggleAllButton setHidden:YES];
[applicationListView setHidden:YES];
[mainWindow setShowsResizeIndicator:NO];
[[NSNotificationCenter defaultCenter]
postNotificationName:GLStopProcessTableTimerNotification
object:self];
} else {
newWinFrame = NSRectFromString([defaults stringForKey:GLMaxiWindowSizeKey]);
[quitCurrentAppMenuItem setEnabled:YES];
[toggleAllButton setHidden:NO];
[applicationListView setHidden:NO];
[mainWindow setShowsResizeIndicator:YES];
[[NSNotificationCenter defaultCenter]
postNotificationName:GLStartProcessTableTimerNotification
object:self];
}
return newWinFrame;
}
#pragma mark accessor methods
- (NSWindow *)mainWindow
{
return mainWindow;
}
- (NSThread *)mainThread
{
return mainThread;
}
- (GLPreferences *)preferences
{
return [GLPreferences sharedInstance];
}
- (NSArray *)applicationList
{
return [NSArray arrayWithArray:applicationList];
}
- (NSString *)launchAppPath
{
return launchAppPath;
}
- (BOOL)isMini
{
return isMini;
}
#pragma mark Action Methods
//browser button
- (IBAction)browseForApp:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
if (![[GLLauncherController sharedInstance] isLaunching]) {
[panel beginSheetForDirectory:nil
file:nil
types:[NSArray arrayWithObject:@"app"]
modalForWindow:[browseButton window]
modalDelegate:self
didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
}
- (void)setLaunchAppPath:(NSString *)path
{
if ((path != nil)&&
([[NSFileManager defaultManager] fileExistsAtPath:path])){
[path retain];
[launchAppPath release];
launchAppPath = path;
[quitAllAndLaunchButton setEnabled:YES];
[launchMenuItem setEnabled:YES];
[imageWell setImage:[[NSWorkspace sharedWorkspace]
iconForFile:path]];
[launchAppName setStringValue:[[launchAppPath lastPathComponent] stringByDeletingPathExtension]];
[defaults setObject:path forKey:@"GLLaunchAppPath"];
[self addToRecentDocs:[NSURL fileURLWithPath:path]];
} else {
//application not found
launchAppPath = nil;
[quitAllAndLaunchButton setEnabled:NO];
[launchMenuItem setEnabled:NO];
NSImage *image = [NSImage imageNamed:@"GLQuestion.png"];
[imageWell setImage:image];
[launchAppName setStringValue:@""];
}
}
- (void)addToRecentDocs:(NSURL *)newURL
{
//maxdocs declared at top
NSDocumentController *docController = [NSDocumentController sharedDocumentController];
[docController noteNewRecentDocumentURL:newURL];
NSMutableArray *recentDocs = [NSMutableArray arrayWithArray:[docController recentDocumentURLs]];
if ([recentDocs count] > GLMaxRecentDocs) {
[recentDocs removeObjectAtIndex:GLMaxRecentDocs];
[recentDocs insertObject:newURL atIndex:0];
[docController clearRecentDocuments:self];
NSEnumerator *enumerator = [recentDocs reverseObjectEnumerator];
NSURL *docURL;
while ((docURL = [enumerator nextObject])) {
[docController noteNewRecentDocumentURL:docURL];
}
}
}
//button pressed
- (IBAction)quitAllAndLaunch:(id)sender
{
NSThread *launchThread = [[GLLauncherController sharedInstance] myThread];
if ((![[GLLauncherController sharedInstance] isLaunching]) &&
(launchAppPath != nil)) {
[[GLLauncherController sharedInstance] performSelector:@selector(doQuitAllAndLaunch)
inThread:launchThread];
} else {
//cancel launch
[quitAllAndLaunchButton setEnabled:NO];
[launchMenuItem setEnabled:NO];
[[GLLauncherController sharedInstance] cancelLaunch];
}
}
- (IBAction)quitSelectedApp:(id)sender
{
int selectedRow = [applicationListView selectedRow];
NSThread *launchThread = [[GLLauncherController sharedInstance] myThread];
if (selectedRow >= 0) {
GLProcess *process = [applicationList objectAtIndex:selectedRow];
[[GLLauncherController sharedInstance] performSelector:@selector(quitProcess:)
withObject:process
inThread:launchThread];
}
}
//menu item
- (void)showHelp:(id)sender
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"About GameLauncher" ofType:@"pdf"];
[[NSWorkspace sharedWorkspace] openFile:filePath];
}
//menu item
- (IBAction)buyProfessionalLink:(id)sender
{
NSString *buyproUrlText = NSLocalizedStringFromTable(GLBuyProUrlKey, GLLocalizablePlist, GLBuyProUrlKey);
[[NSWorkspace sharedWorkspace]
openURL:[NSURL URLWithString:buyproUrlText]];
}
//menu item
- (IBAction)advertiseLink:(id)sender
{
NSString *advertiseUrlText = NSLocalizedStringFromTable(GLAdvertiseUrlKey, GLLocalizablePlist, GLAdvertiseUrlKey);
[[NSWorkspace sharedWorkspace]
openURL:[NSURL URLWithString:advertiseUrlText]];
}
//menu item
- (IBAction)toggleAllProcesses:(id)sender
{
[selectedApplicationsDefaultsDict setObject:selectedApplications
forKey:[NSString stringWithFormat:@"%d", processEnabledToggle]];
processEnabledToggle = !processEnabledToggle;
[self updateProcessToggleGUI];
if (processEnabledToggle == NO) {
[selectedApplications release];
selectedApplications = [[NSMutableDictionary dictionary] retain];
[selectedApplicationsDefaultsDict setObject:selectedApplications
forKey:[NSString stringWithFormat:@"%d", processEnabledToggle]];
} else {
[selectedApplications release];
selectedApplications = [[defaults objectForKey:GLSelectedApplicationsListKey]
objectForKey:[NSString stringWithFormat:@"%d", processEnabledToggle]];
selectedApplications = [NSMutableDictionary dictionaryWithDictionary:selectedApplications];
[selectedApplications retain];
}
[defaults setObject:selectedApplicationsDefaultsDict forKey:GLSelectedApplicationsListKey];
[defaults setObject:[NSNumber numberWithBool:processEnabledToggle] forKey:GLProcessEnabledToggleKey];
NSArray *enumArray = [NSArray arrayWithArray:applicationList];
NSEnumerator *enumerator = [enumArray objectEnumerator];
GLProcess *process;
while ((process = [enumerator nextObject])) {
if ([selectedApplications valueForKey:[process command]]) {
[process setEnabled:!processEnabledToggle];
} else {
[process setEnabled:processEnabledToggle];
}
}
[applicationListView reloadData];
}
#pragma mark reloadProcessTable
- (void)updateProcessTableGUI
{
NSMutableArray *newApplicationList = [NSMutableArray
arrayWithArray:[GLProcess allUserApplications]];
NSMutableArray *enumArray = [NSMutableArray arrayWithArray:applicationList];
NSEnumerator *enumerator = [enumArray objectEnumerator];
GLProcess *process;
BOOL processTableChanged = NO;
while ((process = [enumerator nextObject])) {
int procIndex = [newApplicationList indexOfObject:process];
if (procIndex == NSNotFound) {
[applicationList removeObject:process];
processTableChanged = YES;
} else {
[newApplicationList removeObjectAtIndex:procIndex];
}
}
if ([newApplicationList count]) {
enumerator = [newApplicationList objectEnumerator];
while ((process = [enumerator nextObject])) {
if ([selectedApplications valueForKey:[process command]]) {
[process setEnabled:!processEnabledToggle];
} else {
[process setEnabled:processEnabledToggle];
}
}
[applicationList addObjectsFromArray:newApplicationList];
processTableChanged = YES;
}
if (processTableChanged) {
[applicationList sortUsingDescriptors:[applicationListView sortDescriptors]];
[applicationListView reloadData];
[applicationListView setNeedsDisplay:YES];
}
}
- (void)updateProgressIndicatorGUI
{
[progressIndicator setDoubleValue:[[GLLauncherController sharedInstance] launchProgress]];
}
#pragma mark OpenPanel delegate
- (void)openPanelDidEnd:(NSOpenPanel *)openPanel
returnCode:(int)returnCode
contextInfo:(void *)x
{
if (returnCode == NSOKButton) {
[self setLaunchAppPath:[openPanel filename]];
}
}
#pragma mark Application Delegate Methods
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
if ([[GLLauncherController sharedInstance] isLaunching]) {
//show alert and ask if ok to quit
NSAlert *quitAlert = [[NSAlert alloc] init];
[quitAlert setMessageText:NSLocalizedStringFromTable(GLShouldQuitTitle, GLLocalizablePlist, GLShouldQuitTitle)];
NSString *infText = NSLocalizedStringFromTable(GLShouldQuitMsg, GLLocalizablePlist, GLShouldQuitMsg);
NSString *newLine = [NSString stringWithFormat: @"%C", NSLineSeparatorCharacter];
AGRegex *regex = [AGRegex regexWithPattern:@"\\\\n"];
NSString *match = [regex replaceWithString:newLine inString:infText];
[quitAlert setInformativeText:match];
[quitAlert addButtonWithTitle:NSLocalizedStringFromTable(GLShouldQuitBut1, GLLocalizablePlist, GLShouldQuitBut1)];
[quitAlert addButtonWithTitle:NSLocalizedStringFromTable(GLShouldQuitBut2, GLLocalizablePlist, GLShouldQuitBut2)];
[quitAlert addButtonWithTitle:NSLocalizedStringFromTable(GLShouldQuitBut3, GLLocalizablePlist, GLShouldQuitBut3)];
int quitRequestButton = [quitAlert runModal];
if (quitRequestButton == NSAlertFirstButtonReturn) {
//quit immediately
} else if (quitRequestButton == NSAlertSecondButtonReturn) {
//relaunch then quit
quitRequested = YES;
[[GLLauncherController sharedInstance] cancelLaunch];
return NSTerminateCancel;
} else {
//cancel
return NSTerminateCancel;
}
}
if (isMini) {
isMini = NO;
[mainWindow orderOut:self];
[mainWindow setFrame:[self mainWindowFrame] display:NO animate:NO];
}
[defaults setObject:[NSNumber numberWithBool:YES] forKey:GLQuitSuccessKey];
[defaults setObject:[NSNumber numberWithBool:NO] forKey:GLAppFirstRunKey];
return NSTerminateNow;
}
- (void)applicationWillHide:(NSNotification *)aNotification
{
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify postNotificationName:GLStopProcessTableTimerNotification object:self];
}
- (void)applicationWillUnhide:(NSNotification *)aNotification
{
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify postNotificationName:GLStartProcessTableTimerNotification object:self];
}
- (BOOL)application:(NSApplication *)theApp openFile:(NSString *)filePath
{
[self setLaunchAppPath:filePath];
return YES;
}
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
{
[self setLaunchAppPath:[filenames lastObject]];
[[NSApplication sharedApplication] replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
}
#pragma mark Window Delegate Methods
- (BOOL)windowShouldClose:(id)sender
{
if (![[GLLauncherController sharedInstance] isLaunching]) {
[mainWindow orderOut:self];
[NSApp terminate:self];
return YES;
} else {
return NO;
}
}
- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame
{
//this is the zoom function call
#ifdef __DEBUG__
NSLog(@"%@: windowWillUseStandardFrame:defaultFrame:", [self class]);
#endif
if (!isMini) {
[defaults setObject:NSStringFromRect([mainWindow frame]) forKey:GLMaxiWindowSizeKey];
} else {
[defaults setObject:NSStringFromRect([mainWindow frame]) forKey:GLMiniWindowSizeKey];
}
isMini = !isMini;
return [self mainWindowFrame];
}
- (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
{
//window should change size
#ifdef __DEBUG__
NSLog(@"%@: windowShouldZoom:toFrame:", [self class]);
#endif
[mainWindow setFrame:newFrame display:YES animate:YES];
return YES;
}
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
{
//lock resizing on mini window
if (isMini) {
if (NSEqualSizes([sender frame].size, [sender minSize])) {
proposedFrameSize = [sender frame].size;
}
} else {
//check that main window can't be resized too small
if (proposedFrameSize.height < ([sender minSize].height + 67.0)){
proposedFrameSize.height = ([sender minSize].height + 67.0);
}
}
return proposedFrameSize;
}
//Window delegate method
- (void)openDocument:(id)sender
{
[self browseForApp:sender];
}
#pragma mark Notification delegates
- (void)startProcessTableTimerNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: startProcessTableTimerNotification:", [self class]);
#endif
if ([refreshTimer isValid]) {
[refreshTimer invalidate];
}
if (refreshTimer != nil) {
[refreshTimer release];
}
float speedDelta = [[GLPreferences sharedInstance] computerSpeed];
refreshTimer = [[NSTimer timerWithTimeInterval:0.3*speedDelta
target:self
selector:@selector(updateProcessTableGUI)
userInfo:nil
repeats:YES] retain];
[[NSRunLoop currentRunLoop] addTimer:refreshTimer
forMode:NSDefaultRunLoopMode];
[self updateProcessTableGUI];
}
//notification delegate
- (void)stopProcessTableTimerNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: stopProcessTableTimerNotification:", [self class]);
#endif
if ([refreshTimer isValid]) {
[refreshTimer invalidate];
}
}
//notification delegate
- (void)reloadProcessTableNotification:(NSNotification *)notification
{
[self updateProcessTableGUI];
}
- (void)startProgressIndTimerNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: startProgressIndTimerNotification:", [self class]);
#endif
if ([progressTimer isValid]) {
[progressTimer invalidate];
}
if (progressTimer != nil) {
[progressTimer release];
}
float speedDelta = [[GLPreferences sharedInstance] computerSpeed];
progressTimer = [[NSTimer timerWithTimeInterval:0.3*speedDelta
target:self
selector:@selector(updateProgressIndicatorGUI)
userInfo:nil
repeats:YES] retain];
[[NSRunLoop currentRunLoop] addTimer:progressTimer
forMode:NSDefaultRunLoopMode];
[self updateProgressIndicatorGUI];
}
- (void)stopProgressIndTimerNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: stopProgressIndTimerNotification:", [self class]);
#endif
if ([progressTimer isValid]) {
[progressTimer invalidate];
}
[progressIndicator setDoubleValue:0.0];
}
- (void)hideSystemUINotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: hideSystemUINotification:", [self class]);
#endif
[mainWindow hideSystemUI];
}
- (void)revertSystemUINotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: revertSystemUINotification:", [self class]);
#endif
[mainWindow revertSystemUI];
}
- (void)launcherBeginQuitAllNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: launcherBeginQuitAllNotification:", [self class]);
#endif
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify postNotificationName:GLReloadProcessTableNotification
object:self];
[notify postNotificationName:GLStartProgressTimerNotification
object:self];
[notify postNotificationName:GLHideSystemUINotification
object:self];
[quitAllAndLaunchButton setTitle:NSLocalizedStringFromTable(GLAbortButton, GLLocalizablePlist, GLAbortButton)];
[launchMenuItem setTitle:NSLocalizedStringFromTable(GLAbortButton, GLLocalizablePlist, GLAbortButton)];
[browseButton setEnabled:NO];
[imageWell setEnabled:NO];
[browseMenuItem setEnabled:NO];
alwaysOnTop = [[GLPreferences sharedInstance] alwaysOnTopDuringLaunch];
shouldMini = !isMini && alwaysOnTop;
if (alwaysOnTop) {
[mainWindow setLevel:NSFloatingWindowLevel];
}
if (shouldMini) {
[self updateMainWindowZoomGUI];
}
}
- (void)launcherWillLaunchNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: launcherWillLaunchNotification:", [self class]);
#endif
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify postNotificationName:GLRevertSystemUINotification
object:self];
[notify postNotificationName:GLStopProgressTimerNotification
object:self];
if (alwaysOnTop) {
[mainWindow setLevel:NSNormalWindowLevel];
}
[quitAllAndLaunchButton setEnabled:NO];
[quitAllAndLaunchButton setTitle:NSLocalizedStringFromTable(GLLaunchButton, GLLocalizablePlist, GLLaunchButton)];
[launchMenuItem setEnabled:NO];
[launchMenuItem setTitle:NSLocalizedStringFromTable(GLLaunchButton, GLLocalizablePlist, GLLaunchButton)];
}
- (void)launcherBeginRelaunchAllNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: launcherBeginRelaunchAllNotification:", [self class]);
#endif
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify postNotificationName:GLStartProgressTimerNotification
object:self];
if (alwaysOnTop) {
[mainWindow setLevel:NSFloatingWindowLevel];
}
}
- (void)launcherDidFinishLaunchingNotification:(NSNotification *)notification
{
#ifdef __DEBUG__
NSLog(@"%@: launcherDidFinishLaunchingNotification:", [self class]);
#endif
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify postNotificationName:GLStopProgressTimerNotification
object:self];
//back to normal
[quitAllAndLaunchButton setTitle:NSLocalizedStringFromTable(GLLaunchButton, GLLocalizablePlist, GLLaunchButton)];
[quitAllAndLaunchButton setEnabled:YES];
[quitAllAndLaunchButton setState:NSOffState];
[launchMenuItem setTitle:NSLocalizedStringFromTable(GLLaunchButton, GLLocalizablePlist, GLLaunchButton)];
[launchMenuItem setEnabled:YES];
[browseMenuItem setEnabled:YES];
[browseButton setEnabled:YES];
[imageWell setEnabled:YES];
[applicationListView displayIfNeeded];
[[GLProcess currentProcess] moveToFrontProcess];
[[GLNagController sharedInstance] setNextNagTimer];
[mainWindow setLevel:NSNormalWindowLevel];
shouldMini = isMini && shouldMini;
if (shouldMini) {
[self updateMainWindowZoomGUI];
}
if (quitRequested) {
[NSApp terminate:self];
}
}
#pragma mark tableView Delegates
#pragma mark tableView datasouce
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [applicationList count];
}
- (void)drawIcon:(NSImage *)image inRect:(NSRect)destRect {
float sqrmodifier = (destRect.size.width - destRect.size.height)/2;
if (sqrmodifier < 0) {
sqrmodifier = abs(sqrmodifier);
destRect.size.height -= sqrmodifier;
destRect.origin.y += sqrmodifier;
}
if (sqrmodifier > 0) {
sqrmodifier = abs(sqrmodifier);
destRect.size.width -= sqrmodifier;
destRect.origin.x += sqrmodifier;
}
[image drawInRect:destRect
fromRect:NSMakeRect(0.0f, 0.0f, [image size].width, [image size].height)
operation:NSCompositeSourceOver
fraction:1.0f];
}
//tableView datasouce
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)row
{
GLProcess *process = [applicationList objectAtIndex:row];
[[aTableColumn dataCell] setEnabled:(![[GLLauncherController sharedInstance] isLaunching])];
if ([[aTableColumn identifier] isEqual:@"imagecell"]) {
IconFamily *iconFamily = [IconFamily iconFamilyWithIconOfFile:[process path]];
NSImage *theIcon = [iconFamily imageWithAllReps];
NSSize canvasSize = NSMakeSize(GLTableIconSize, GLTableIconSize);
NSRect srcRect = NSMakeRect(0.0f, 0.0f, [theIcon size].width, [theIcon size].height);
NSRect destRect = NSMakeRect(0.5f, 0.5f, canvasSize.width-0.5f, canvasSize.height-0.5f);
NSImage *canvas = [[[NSImage alloc] initWithSize:canvasSize] autorelease];
[canvas lockFocus];
[theIcon drawInRect:destRect fromRect:srcRect
operation:NSCompositeSourceOver fraction:1.0f];
[canvas unlockFocus];
return canvas;
} else if ([[aTableColumn identifier] isEqual:@"checkbox"]) {
return [NSNumber numberWithBool:[process enabled]];
} else if ([[aTableColumn identifier] isEqual:@"pid"]) {
return [NSNumber numberWithInt:[process processIdentifier]];
} else if ([[aTableColumn identifier] isEqual:@"application"]) {
return [process annotatedCommand];
} else if ([[aTableColumn identifier] isEqual:@"path"]) {
return [process path];
}
return nil;
}
//tableView change object value
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)row
{
if ([[GLLauncherController sharedInstance] isLaunching])
return;
// only checkbox column accepts input
// no need to check which column
GLProcess *process = [applicationList objectAtIndex:row];
[process setEnabled:[anObject boolValue]];
if (processEnabledToggle != [anObject boolValue]){
//add to selected list
[selectedApplications setValue:[NSNumber numberWithBool:YES] forKey:[process command]];
} else {
//remove from selected list
[selectedApplications removeObjectForKey:[process command]];
}
//update defaults
[selectedApplicationsDefaultsDict setObject:selectedApplications
forKey:[NSString stringWithFormat:@"%d", processEnabledToggle]];
[defaults setObject:selectedApplicationsDefaultsDict forKey:GLSelectedApplicationsListKey];
//check sort descriptors for "enabled"
//if yes then re-sort table
NSEnumerator *enumerator = [[applicationListView sortDescriptors] objectEnumerator];
NSSortDescriptor *tempSort;
while ((tempSort = [enumerator nextObject])) {
if ([[tempSort key] isEqual:@"enabled"]) {
[applicationList sortUsingDescriptors:[applicationListView sortDescriptors]];
[applicationListView reloadData];
[applicationListView selectRowIndexes:[NSIndexSet
indexSetWithIndex:[applicationList indexOfObject:process]]
byExtendingSelection:NO];
}
}
[applicationListView setNeedsDisplay:YES];
}
- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors
{
[applicationList sortUsingDescriptors:[tableView sortDescriptors]];
[tableView reloadData];
//save to defaults
NSData *theData=[NSArchiver archivedDataWithRootObject:[tableView sortDescriptors]];
[defaults setObject:theData forKey:GLTableSortDescriptorsKey];
}
@end