-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSKVideoItem.m
188 lines (152 loc) · 4.49 KB
/
SKVideoItem.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
//
// SKVideoItem.m
// Skreenics
//
// Created by naixn on 24/09/09.
// Copyright 2009 Thibault Martin-Lagardette. All rights reserved.
//
#import "SKVideoItem.h"
#import "SKDefines.h"
@implementation SKVideoItem
@synthesize associatedOperation;
- (id)init
{
return [super init];
}
- (id)initWithPath:(NSString *)path
{
if (self = [super init])
{
SKProgressIndicator* progressIndicator = [[SKProgressIndicator alloc] init];
NSString* fullPath = [path stringByExpandingTildeInPath];
videoItem = [[NSMutableDictionary alloc] init];
[videoItem setValue:fullPath forKey:kSKFilePathKey];
[videoItem setValue:[fullPath lastPathComponent] forKey:kSKFileNameKey];
[videoItem setValue:[[NSWorkspace sharedWorkspace] iconForFile:fullPath] forKey:kSKIconKey];
[videoItem setValue:progressIndicator forKey:kSKProgressIndicatorKey];
[videoItem setValue:[NSNumber numberWithInt:0] forKey:kSKProgressValueKey];
[videoItem setValue:@"Waiting..." forKey:kSKProgressStringKey];
[videoItem setValue:[NSNumber numberWithInt:100] forKey:kSKNumberOfStepsKey];
[progressIndicator release];
}
return self;
}
- (id)copyWithZone:(NSZone *)zone
{
return nil;
}
- (void)dealloc
{
[self setAssociatedOperation:nil];
[[self progressIndicator] removeFromSuperview];
[videoItem release];
[super dealloc];
}
#pragma mark -
#pragma mark Misc
- (void)cleanup
{
[[self progressIndicator] removeFromSuperview];
}
#pragma mark Interesting getters
- (BOOL)isFinished
{
return [[self progressValue] isEqualToNumber:[self numberOfSteps]];
}
- (BOOL)isErroneous
{
return ([[self progressValue] doubleValue] == kSKProgressIndicatorError);
}
#pragma mark Setters
- (void)setNumberOfSteps:(NSNumber *)steps
{
// We want to perform the change on the main thread for UI changes
if ([NSThread isMainThread] == NO)
{
[self performSelectorOnMainThread:@selector(setNumberOfSteps:) withObject:steps waitUntilDone:YES];
}
else
{
[videoItem setValue:steps forKey:kSKNumberOfStepsKey];
[[self progressIndicator] setMaxProgressValue:[steps doubleValue]];
}
}
- (void)setProgressString:(NSString *)progressString
{
// We want to perform the change on the main thread for UI changes
if ([NSThread isMainThread] == NO)
{
[self performSelectorOnMainThread:@selector(setProgressString:) withObject:progressString waitUntilDone:YES];
}
else
{
[videoItem setValue:progressString forKey:kSKProgressStringKey];
}
}
- (void)setProgressValue:(NSNumber *)progress
{
// We want to perform the change on the main thread for UI changes
if ([NSThread isMainThread] == NO)
{
[self performSelectorOnMainThread:@selector(setProgressValue:) withObject:progress waitUntilDone:YES];
}
else
{
[videoItem setValue:progress forKey:kSKProgressValueKey];
[[self progressIndicator] setAnimatedProgressValue:[progress doubleValue]];
}
}
- (void)setProgressString:(NSString *)progressString incrementProgressValue:(BOOL)increment
{
double currentValue;
[self setProgressString:progressString];
if (increment)
{
currentValue = [[self progressValue] doubleValue];
[self setProgressValue:[NSNumber numberWithDouble:(currentValue + 1.0)]];
}
}
- (void)setError:(NSString *)errorString
{
[self setProgressString:errorString];
[self setProgressValue:[NSNumber numberWithDouble:kSKProgressIndicatorError]];
}
#pragma mark Observing
- (void)addObserverForInterestingKeyPaths:(NSObject *)observer
{
[self addObserver:observer forKeyPath:kSKVideoItemProgressValuePath options:NSKeyValueObservingOptionNew context:nil];
}
- (void)removeObserverForInterestingKeyPaths:(NSObject *)observer
{
[self removeObserver:observer forKeyPath:kSKVideoItemProgressValuePath];
}
#pragma mark Simple getters
- (NSString *)filepath
{
return [videoItem objectForKey:kSKFilePathKey];
}
- (NSString *)filename
{
return [videoItem objectForKey:kSKFileNameKey];
}
- (NSImage *)icon
{
return [videoItem objectForKey:kSKIconKey];
}
- (SKProgressIndicator *)progressIndicator
{
return [videoItem objectForKey:kSKProgressIndicatorKey];
}
- (NSNumber *)progressValue
{
return [videoItem objectForKey:kSKProgressValueKey];
}
- (NSString *)progressString
{
return [videoItem objectForKey:kSKProgressStringKey];
}
- (NSNumber *)numberOfSteps
{
return [videoItem objectForKey:kSKNumberOfStepsKey];
}
@end