Commit 7f2132a5 authored by Felix Paul Kühne's avatar Felix Paul Kühne

library: add exception handlers and sanity checks

(cherry picked from commit 3c7fd852)
parent f2025d68
......@@ -91,40 +91,46 @@
- (void)_removeObserver
{
if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"name"];
} else if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject removeObserver:self forKeyPath:@"episodes"];
else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
} else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"tracks"];
} else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
[_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
[anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
[_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
[_mediaObject removeObserver:self forKeyPath:@"duration"];
[_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
[_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
[_mediaObject removeObserver:self forKeyPath:@"album"];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"genre"];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[(MLFile*)_mediaObject didHide];
@try {
if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"name"];
} else if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject removeObserver:self forKeyPath:@"episodes"];
else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
} else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"tracks"];
} else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
[_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
if (anyFileFromTrack)
[anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
[_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
[_mediaObject removeObserver:self forKeyPath:@"duration"];
[_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
[_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
[_mediaObject removeObserver:self forKeyPath:@"album"];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"genre"];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[(MLFile*)_mediaObject didHide];
}
}
@catch (NSException *exception) {
APLog(@"removing observer failed");
}
}
......@@ -149,7 +155,8 @@
[_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
[anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
if (anyFileFromTrack)
[anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
......@@ -318,6 +325,8 @@
- (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
{
if (!mediaLibraryFile)
return;
CGFloat position = mediaLibraryFile.lastPosition.floatValue;
CGFloat duration = mediaLibraryFile.duration.floatValue;
......
......@@ -58,40 +58,46 @@
- (void)_removeObserver
{
if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"name"];
} else if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject removeObserver:self forKeyPath:@"episodes"];
else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
} else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"tracks"];
} else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
[_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
[anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
[_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
[_mediaObject removeObserver:self forKeyPath:@"duration"];
[_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
[_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
[_mediaObject removeObserver:self forKeyPath:@"album"];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"genre"];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[(MLFile*)_mediaObject didHide];
@try {
if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"name"];
} else if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject removeObserver:self forKeyPath:@"episodes"];
else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
} else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
[_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"tracks"];
} else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
[_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
if (anyFileFromTrack)
[anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
[_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
[_mediaObject removeObserver:self forKeyPath:@"duration"];
[_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
[_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
[_mediaObject removeObserver:self forKeyPath:@"album"];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"genre"];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[(MLFile*)_mediaObject didHide];
}
}
@catch (NSException *exception) {
APLog(@"removing observer failed");
}
}
......@@ -116,7 +122,8 @@
[_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
[anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
if (anyFileFromTrack)
[anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
......@@ -305,6 +312,8 @@
- (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
{
if (!mediaLibraryFile)
return;
CGFloat position = mediaLibraryFile.lastPosition.floatValue;
CGFloat duration = mediaLibraryFile.duration.floatValue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment