forked from phoenix3200/libstatusbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLSStatusBarItem.mm
308 lines (229 loc) · 6.22 KB
/
LSStatusBarItem.mm
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
//#define TESTING
#import "common.h"
#import "defines.h"
#import "LSStatusBarItem.h"
#import "LSStatusBarClient.h"
#import "classes.h"
NSMutableDictionary* sbitems = nil;
@implementation LSStatusBarItem
+ (void) _updateProperties: (NSMutableDictionary*) dict forIdentifier: (NSString*) identifier
{
if(!sbitems)
{
sbitems = [NSMutableDictionary new];
}
NSArray* idArray = [sbitems objectForKey: identifier];
for(LSStatusBarItem* item in idArray)
{
[item _setProperties: dict];
}
}
- (id) initWithIdentifier: (NSString*) identifier alignment: (StatusBarAlignment) alignment
{
if(!identifier)
{
[NSException raise: NSInternalInconsistencyException format: @"LSStatusBarItem: No identifer specified"];
}
if(!alignment)
{
[NSException raise: NSInternalInconsistencyException format: @"LSStatusBarItem: Alignment not specified"];
}
/*
if($UIApplication && ![$UIApplication sharedApplication])
{
TRACE_F();
[NSException raise: NSInternalInconsistencyException format: @"LSStatusBarItem: Wait for UIApp to load!"];
}*/
if((self = [super init]))
{
if(!sbitems)
{
sbitems = [NSMutableDictionary new];
}
NSMutableArray* idArray = [sbitems objectForKey: identifier];
LSStatusBarItem* item = idArray ? [idArray count] ? [idArray objectAtIndex: 0] : nil : nil;
NSMutableDictionary* properties = item ? [item properties] : nil;
if(!properties)
properties = [NSMutableDictionary new];
// save all the settings
{
_identifier = [identifier retain];
[self _setProperties: properties];
NSNumber* align = [_properties objectForKey: @"alignment"];
if(!align)
{
[_properties setObject: [NSNumber numberWithInt: alignment] forKey: @"alignment"];
}
else if([align intValue] != alignment)
{
[NSException raise: NSInternalInconsistencyException format: @"LSStatusBarItem: You cannot specify a new alignment!"];
}
}
// keep track of StatusBarItem(s)
{
NSMutableArray* idArray = [sbitems objectForKey: identifier];
if(!idArray)
{
// this creates a retain/release-less NSMutableArray
idArray = (NSMutableArray*) CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
[sbitems setObject: idArray forKey: identifier];
CFRelease(idArray);
}
if(idArray)
{
[idArray addObject: self];
}
}
return self;
}
return nil;
}
- (void) dealloc
{
if(sbitems)
{
NSMutableArray* idArray = [sbitems objectForKey: _identifier];
// kill the current item count
if(idArray)
{
[idArray removeObject: self];
if([idArray count] == 0)
{
// item is no longer in use by this process, let the server no
[[LSStatusBarClient sharedInstance] setProperties: nil forItem: _identifier];
}
}
[_identifier release];
[_properties release];
}
[super dealloc];
}
- (NSDictionary*) properties
{
return _properties;
}
- (void) _setProperties: (NSDictionary*) dict
{
if(dict == _properties)
return;
[_properties release];
if(!dict)
{
_properties = [NSMutableDictionary new];
}
else
{
_properties = [dict mutableCopy];
}
}
- (StatusBarAlignment) alignment
{
NSNumber* alignment = [_properties objectForKey: @"alignment"];
return alignment ? (StatusBarAlignment) [alignment intValue] : StatusBarAlignmentLeft;
}
- (void) setVisible: (BOOL) visible
{
[_properties setObject: [NSNumber numberWithBool: visible] forKey: @"visible"];
if(!_manualUpdate)
[self update];
}
- (BOOL) isVisible
{
NSNumber* visible = [_properties objectForKey: @"visible"];
return visible ? [visible boolValue] : YES;
}
- (void) setHidesTime: (BOOL) hidesTime
{
NSNumber* oldTime = [_properties objectForKey: @"imageName"];
if([oldTime boolValue] != hidesTime)
{
[_properties setObject: [NSNumber numberWithBool: hidesTime] forKey: @"hidesTime"];
if(!_manualUpdate)
[self update];
}
}
- (BOOL) hidesTime
{
NSNumber* hidesTime = [_properties objectForKey: @"hidesTime"];
return hidesTime ? [hidesTime boolValue] : NO;
}
- (void) setImageName: (NSString*) imageName
{
if(self.alignment & StatusBarAlignmentCenter)
{
[NSException raise: NSInternalInconsistencyException format: @"LSStatusBarItem: Cannot use images with a center alignment"];
}
NSString* oldImageName = [_properties objectForKey: @"imageName"];
if(!oldImageName || ![oldImageName isEqualToString: imageName])
{
[_properties setValue: imageName forKey: @"imageName"];
if(!_manualUpdate)
[self update];
}
}
- (NSString*) imageName
{
return [_properties objectForKey: @"imageName"];
}
- (void) setTitleString: (NSString*) string
{
if(self.alignment & (StatusBarAlignmentLeft | StatusBarAlignmentRight))
{
[NSException raise: NSInternalInconsistencyException format: @"LSStatusBarItem: Cannot use a title string with a side alignment"];
}
NSString* oldTitle = [_properties objectForKey: @"titleString"];
if((!oldTitle && string) || (oldTitle && ![oldTitle isEqualToString: string]))
{
NSLog(@"oldTitle = %@, newTitle = %@", oldTitle, string);
[_properties setValue: string forKey: @"titleString"];
if(!_manualUpdate)
[self update];
}
}
- (void) setCustomViewClass: (NSString*) customViewClass
{
NSString* oldClass = [_properties objectForKey: @"customViewClass"];
if(oldClass)
[NSException raise: NSInternalInconsistencyException format: @"LSStatusBarItem: Item already has a custom view class!"];
[_properties setValue: customViewClass forKey: @"customViewClass"];
if(!_manualUpdate)
[self update];
}
- (NSString*) customViewClass
{
return [_properties objectForKey: @"customViewClass"];
}
- (NSString*) titleString
{
return [_properties objectForKey: @"titleString"];
}
- (void) setManualUpdate: (BOOL) manualUpdate
{
_manualUpdate = manualUpdate;
}
- (BOOL) isManualUpdate
{
return _manualUpdate;
}
- (void) update
{
SelLog();
[[LSStatusBarClient sharedInstance] setProperties: _properties forItem: _identifier];
[LSStatusBarItem _updateProperties: _properties forIdentifier: _identifier];
}
// future API
- (void) setExclusiveToApp: (NSString*) bundleId
{
[_properties setObject: bundleId forKey: @"exclusiveToApp"];
}
- (NSString*) exclusiveToApp
{
return [_properties objectForKey: @"exclusiveToApp"];
}
- (void) addTouchDelegate: (id) delegate
{
}
- (void) removeTouchDelegate: (id) delegate
{
}
@end