forked from overcyn/Enqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSNotificationCenter+Extensions.m
190 lines (138 loc) · 6.29 KB
/
NSNotificationCenter+Extensions.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
#import "NSNotificationCenter+Extensions.h"
#import "PRPlaylists.h"
@implementation PRChangeSet
@end
@implementation PRLibraryChange
@end
@implementation PRItemChange
@end
@implementation PRMovieChange
@end
@implementation PRListsChange
@end
@implementation PRListChange
@end
@implementation PRListItemsChange
@end
@implementation PRNowPlayingChange
@end
NSString * const PRLibraryDidChangeNotification = @"PRLibraryDidChangeNotification";
NSString * const PRTagsDidChangeNotification = @"PRTagsDidChangeNotification";
NSString * const PRPlaylistDidChangeNotification = @"PRPlaylistDidChangeNotification";
NSString * const PRPlaylistsDidChangeNotification = @"PRPlaylistsDidChangeNotification";
NSString * const PRPlaylistFilesChangedNote = @"PRPlaylistFilesChangedNote";
NSString * const PRCurrentListDidChangeNotification = @"PRCurrentListDidChangeNotification";
NSString * const PRLibraryViewSelectionDidChangeNotification = @"PRLibraryViewSelectionDidChangeNotification";
NSString * const PRPreGainDidChangeNotification = @"PRPreGainDidChangeNotification";
NSString * const PRUseAlbumArtistDidChangeNotification = @"PRUseAlbumArtistDidChangeNotification";
NSString * const PRIsPlayingDidChangeNotification = @"PRIsPlayingDidChangeNotification";
NSString * const PRMovieDidFinishNotification = @"PRMovieDidFinishNotification";
NSString * const PRMovieAlmostFinishedNote = @"PRMovieAlmostFinishedNote";
NSString * const PRLastfmStateDidChangeNotification = @"PRLastfmStateDidChangeNotification";
NSString * const PRTimeChangedNote = @"PRTimeChangedNote";
NSString * const PRCurrentFileDidChangeNotification = @"PRCurrentFileDidChangeNotification";
NSString * const PRShuffleDidChangeNotification = @"PRShuffleDidChangeNotification";
NSString * const PRRepeatDidChangeNotification = @"PRRepeatDidChangeNotification";
NSString * const PRVolumeChangedNote = @"PRVolumeChangedNote";
NSString * const PREQChangedNote = @"PREQChangedNote";
NSString * const PRDeviceDidChangeNotification = @"PRDeviceDidChangeNotification";
@implementation NSNotificationCenter (Extensions)
+ (void)post:(NSString *)name {
[[NSNotificationCenter defaultCenter] postNotificationName:name object:nil];
}
+ (void)post:(NSString *)name object:(id)object info:(NSDictionary *)info {
[[NSNotificationCenter defaultCenter] postNotificationName:name object:object userInfo:info];
}
+ (void)addObserver:(id)observer selector:(SEL)selector name:(NSString *)name object:(id)object {
[[NSNotificationCenter defaultCenter] addObserver:observer selector:selector name:name object:object];
}
+ (void)removeObserver:(id)observer {
[[NSNotificationCenter defaultCenter] removeObserver:observer];
}
- (void)postChanges:(NSArray *)changes {
PRChangeSet *changeSet = [[PRChangeSet alloc] init];
[changeSet setChanges:changes];
[self postNotificationName:@"changeset" object:nil userInfo:@{@"changeset":changeSet}];
}
- (void)observeBackendChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:@"changeset" object:nil];
}
// Db notifications
- (void)postLibraryChanged {
[self postNotificationName:PRLibraryDidChangeNotification object:nil];
}
- (void)postItemsChanged:(NSArray *)items {
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:items, @"files", nil];
[self postNotificationName:PRTagsDidChangeNotification object:nil userInfo:info];
}
- (void)postListsDidChange {
[self postNotificationName:PRPlaylistsDidChangeNotification object:nil];
}
- (void)postListDidChange:(NSNumber *)list {
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:list, @"playlist", nil];
[self postNotificationName:PRPlaylistDidChangeNotification object:nil userInfo:info];
}
- (void)postListItemsDidChange:(NSNumber *)list {
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:list, @"playlist", nil];
[self postNotificationName:PRPlaylistFilesChangedNote object:nil userInfo:info];
}
- (void)observeLibraryChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRLibraryDidChangeNotification object:nil];
}
- (void)observeItemsChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRTagsDidChangeNotification object:nil];
}
- (void)observePlaylistsChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRPlaylistsDidChangeNotification object:nil];
}
- (void)observePlaylistChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRPlaylistDidChangeNotification object:nil];
}
- (void)observePlaylistFilesChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRPlaylistFilesChangedNote object:nil];
}
// Preferences
- (void)postPreGainChanged {
[self postNotificationName:PRPreGainDidChangeNotification object:nil];
}
- (void)postUseAlbumArtistChanged {
[self postNotificationName:PRUseAlbumArtistDidChangeNotification object:nil];
}
- (void)postEQChanged {
[self postNotificationName:PREQChangedNote object:nil];
}
- (void)observePreGainChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRPreGainDidChangeNotification object:nil];
}
- (void)observeUseAlbumArtistChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRUseAlbumArtistDidChangeNotification object:nil];
}
- (void)observeEQChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PREQChangedNote object:nil];
}
// Playing
- (void)postTimeChanged {
[self postNotificationName:PRTimeChangedNote object:nil];
}
- (void)postPlayingChanged {
[self postNotificationName:PRIsPlayingDidChangeNotification object:nil];
}
- (void)postMovieFinished {
[self postNotificationName:PRMovieDidFinishNotification object:nil];
}
- (void)postMovieAlmostFinished {
[self postNotificationName:PRMovieAlmostFinishedNote object:nil];
}
- (void)observeTimeChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRTimeChangedNote object:nil];
}
- (void)observePlayingChanged:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRIsPlayingDidChangeNotification object:nil];
}
- (void)observeMovieFinished:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRMovieDidFinishNotification object:nil];
}
- (void)observeMovieAlmostFinished:(id)obs sel:(SEL)sel {
[self addObserver:obs selector:sel name:PRMovieAlmostFinishedNote object:nil];
}
@end