-
Notifications
You must be signed in to change notification settings - Fork 1
/
RootController.m
134 lines (120 loc) · 4.02 KB
/
RootController.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
//
// RootController.m
// Flowrate
//
// Created by Nathan Vander Wilt on 1/21/10.
// Copyright 2010 Calf Trail Software, LLC. All rights reserved.
//
#import "RootController.h"
#import "HostView.h"
#import "AppDelegate.h"
#import "AlbumInfo.h"
#import "AlbumController.h"
#import "StageController.h"
#import "MenuController.h"
#import "NSColor+TLExtensions.h"
#import "NSObject+TLKVO.h"
#import "CALayer+TLExtensions.h"
#import <QuartzCore/QuartzCore.h>
@implementation RootController
@synthesize status;
- (id)init {
self = [super init];
if (self) {
self.layer.backgroundColor = [[NSColor whiteColor] tl_CGColor];
statusLayer = [CATextLayer layer];
statusLayer.foregroundColor = [[NSColor blackColor] tl_CGColor];
statusLayer.font = @"Futura";
statusLayer.alignmentMode = kCAAlignmentCenter;
[self.layer addSublayer:statusLayer];
[self.layer setNeedsLayout];
TLKVORegisterSelf(self, @"status",
NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(albumInfoDidLoad:)
name:AlbumInfoDidReloadNotification object:nil];
}
return self;
}
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object
change:(NSDictionary*)change context:(void*)context
{
if (context == &TLKVOContext) {
if ([keyPath isEqualToString:@"status"]) {
switch (self.status) {
case RootRemoteError:
statusLayer.string = @"Remote broken — Upgrade OS X";
break;
case RootLibraryError:
statusLayer.string = @"No iPhoto library found!";
break;
case RootNoPhotos:
statusLayer.string = @"No photos need rating.";
break;
case RootLoading:
statusLayer.string = @"Photons: loading.";
break;
case RootQuitting:
statusLayer.string = @"Finishing work: please stand by.";
break;
default:
NSAssert(false, @"Bad status is bad");
}
[[NSApp delegate] preventFullScreen];
}
}
else {
[super observeValueForKeyPath:keyPath ofObject:object
change:change context:context];
}
}
- (void)layoutSublayersOfLayer:(CALayer*)theLayer {
NSAssert(theLayer == self.layer, @"Layout own layer only");
CGFloat hScale = CGRectGetWidth(theLayer.bounds) / 800;
CGFloat vScale = CGRectGetHeight(theLayer.bounds) / 600;
statusLayer.fontSize = 50 * MIN(vScale, hScale);
statusLayer.bounds = CGRectMake(0, 0, 800 * hScale, 75 * vScale);
statusLayer.position = CGPointMake(400 * hScale, 350 * vScale);
statusLayer.frame = [theLayer tl_pixelAlignRect:statusLayer.frame];
}
- (void)layerDidAppear {
if ([[NSApp delegate] isTerminating]) return;
if (albumPicker) {
NSDictionary* selectedAlbum = [albumPicker.albums objectAtIndex:albumPicker.position];
NSArray* unratedItems = [selectedAlbum objectForKey:@"items"];
NSInteger numStages = [[NSUserDefaults standardUserDefaults] integerForKey:@"NumberOfStages"];
numStages = (numStages > 0) ? numStages : 4;
numStages = MIN(numStages, 4);
//printf("Number of stages: %li\n", (long)numStages);
StageController* stagehand = [[StageController alloc] initWithItems:unratedItems
stages:numStages];
[self.hostView pushController:stagehand];
albumPicker = nil;
[[NSApp delegate] allowFullScreen];
}
else if (self.status == RootLoading) {
[[NSApp delegate] preventFullScreen];
[[AlbumInfo sharedAlbumInfo] reload];
}
}
- (void)albumInfoDidLoad:(NSNotification*)aNotification {
NSArray* unratedAlbums = [[aNotification userInfo] objectForKey:AlbumInfoDidReloadAlbumsKey];
if (unratedAlbums) {
NSAssert([unratedAlbums count], @"Albums expected!");
albumPicker = [[AlbumController alloc] initWithAlbums:unratedAlbums];
[self.hostView pushController:albumPicker];
}
else {
NSError* err = [[aNotification userInfo] objectForKey:AlbumInfoDidReloadErrorKey];
if ([[err domain] isEqualToString:@"com.calftrail.photostar"]) {
self.status = RootNoPhotos;
}
else {
NSLog(@"Error loading iPhoto data - %@", err);
self.status = RootLibraryError;
}
}
}
- (void)buttonMenu {
[NSApp terminate:self];
}
@end