Commit 21cefda1 authored by David's avatar David
Browse files

macosx: playlist: delete old NSOutlineViewDataSource and helpers

This is superseeded by the new PLModel object. Also remove old
helper functions which are not used anymore.
parent ff0e7068
......@@ -62,8 +62,6 @@
{
IBOutlet VLCPlaylistView* o_outline_view;
NSMutableDictionary *o_outline_dict;
IBOutlet id o_controller;
IBOutlet id o_playlist_wizard;
......@@ -98,7 +96,6 @@
- (PLModel *)model;
- (playlist_item_t *)currentPlaylistRoot;
- (void)reloadStyles;
- (NSMenu *)menuForEvent:(NSEvent *)o_event;
......@@ -124,7 +121,6 @@
- (IBAction)recursiveExpandNode:(id)sender;
- (IBAction)showInfoPanel:(id)sender;
- (id)playingItem;
- (NSArray *)draggedItems;
/**
......
......@@ -159,8 +159,6 @@
*****************************************************************************/
@interface VLCPlaylist ()
{
playlist_item_t * p_current_root_item;
NSImage *o_descendingSortingImage;
NSImage *o_ascendingSortingImage;
......@@ -195,13 +193,6 @@
[o_columnArray release];
}
- (playlist_item_t *)currentPlaylistRoot
{
// TODO remove
playlist_t *p_playlist = pl_Get(VLCIntf);
return p_playlist->p_playing;
}
- (PLModel *)model
{
return o_model;
......@@ -226,22 +217,8 @@
[o_outline_view setRowHeight:rowHeight];
}
- (id)init
{
self = [super init];
if (self != nil) {
playlist_t * p_playlist = pl_Get(VLCIntf);
p_current_root_item = p_playlist->p_local_category;
o_outline_dict = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)dealloc
{
[o_outline_dict release];
[super dealloc];
}
......@@ -259,7 +236,7 @@
[self reloadStyles];
[self initStrings];
o_model = [[PLModel alloc] initWithOutlineView:o_outline_view playlist:p_playlist rootItem:p_current_root_item playlistObject:self];
o_model = [[PLModel alloc] initWithOutlineView:o_outline_view playlist:p_playlist rootItem:p_playlist->p_playing playlistObject:self];
[o_outline_view setDataSource:o_model];
[o_outline_view reloadData];
......@@ -334,8 +311,7 @@
[o_outline_view setHighlightedTableColumn:nil];
o_tc_sortColumn = nil;
// TODO Find a way to keep the dict size to a minimum
//[o_outline_dict removeAllObjects];
[o_outline_view reloadData];
[[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
......@@ -389,57 +365,35 @@
playlist_item_t *p_item, *p_temp_item;
NSMutableArray *o_array = [NSMutableArray array];
PL_LOCK;
p_item = playlist_CurrentPlayingItem(p_playlist);
if (p_item == NULL) {
PL_UNLOCK;
return;
}
p_temp_item = p_item;
while(p_temp_item->p_parent) {
[o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
p_temp_item = p_temp_item->p_parent;
}
PL_UNLOCK;
NSUInteger count = [o_array count];
for (NSUInteger j = 0; j < count - 1; j++) {
id o_item;
if ((o_item = [o_outline_dict objectForKey:
[NSString stringWithFormat: @"%p",
[[o_array objectAtIndex:j] pointerValue]]]) != nil) {
[o_outline_view expandItem: o_item];
}
}
id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
NSInteger i_index = [o_outline_view rowForItem:o_item];
[o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
[o_outline_view setNeedsDisplay:YES];
}
/* Check if p_item is a child of p_node recursively. We need to check the item
existence first since OSX sometimes tries to redraw items that have been
deleted. We don't do it when not required since this verification takes
quite a long time on big playlists (yes, pretty hacky). */
// todo remove useless parameters
- (BOOL)isItem: (PLItem *)p_item inNode: (PLItem *)p_node checkItemExistence:(BOOL)b_check locked:(BOOL)b_locked
{
PLItem *p_temp_item = p_item;
if ([p_node plItemId] == [p_item plItemId])
return YES;
while(p_temp_item) {
p_temp_item = [p_temp_item parent];
if ([p_temp_item plItemId] == [p_node plItemId]) {
return YES;
}
}
return NO;
// TODO Rework
// PL_LOCK;
// p_item = playlist_CurrentPlayingItem(p_playlist);
// if (p_item == NULL) {
// PL_UNLOCK;
// return;
// }
//
// p_temp_item = p_item;
// while(p_temp_item->p_parent) {
// [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
// p_temp_item = p_temp_item->p_parent;
// }
// PL_UNLOCK;
//
// NSUInteger count = [o_array count];
// for (NSUInteger j = 0; j < count - 1; j++) {
// id o_item;
// if ((o_item = [o_outline_dict objectForKey:
// [NSString stringWithFormat: @"%p",
// [[o_array objectAtIndex:j] pointerValue]]]) != nil) {
// [o_outline_view expandItem: o_item];
// }
// }
//
// id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
// NSInteger i_index = [o_outline_view rowForItem:o_item];
// [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
// [o_outline_view setNeedsDisplay:YES];
}
- (IBAction)savePlaylist:(id)sender
......@@ -952,12 +906,6 @@
return;
playlist_t *p_playlist = pl_Get(p_intf);
id o_playing_item;
PL_LOCK;
o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem(p_playlist)]];
PL_UNLOCK;
NSFont *fontToUse;
if (config_GetInt(VLCIntf, "macosx-large-text"))
fontToUse = [NSFont systemFontOfSize:13.];
......@@ -984,19 +932,6 @@
[cell setFont: [[NSFontManager sharedFontManager] convertFont:fontToUse toNotHaveTrait:NSBoldFontMask]];
}
- (id)playingItem
{
playlist_t *p_playlist = pl_Get(VLCIntf);
id o_playing_item;
PL_LOCK;
o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem(p_playlist)]];
PL_UNLOCK;
return o_playing_item;
}
// TODO remove method
- (NSArray *)draggedItems
{
......@@ -1213,207 +1148,3 @@
}
@end
@implementation VLCPlaylist (NSOutlineViewDataSource)
/* return the number of children for Obj-C pointer item */ /* DONE */
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
int i_return = 0;
playlist_item_t *p_item = NULL;
playlist_t * p_playlist = pl_Get(VLCIntf);
//assert(outlineView == o_outline_view);
PL_LOCK;
if (!item)
p_item = p_current_root_item;
else
p_item = (playlist_item_t *)[item pointerValue];
if (p_item)
i_return = p_item->i_children;
PL_UNLOCK;
return i_return > 0 ? i_return : 0;
}
/* return the child at index for the Obj-C pointer item */ /* DONE */
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
playlist_item_t *p_return = NULL, *p_item = NULL;
NSValue *o_value;
playlist_t * p_playlist = pl_Get(VLCIntf);
PL_LOCK;
if (item == nil)
p_item = p_current_root_item; /* root object */
else
p_item = (playlist_item_t *)[item pointerValue];
if (p_item && index < p_item->i_children && index >= 0)
p_return = p_item->pp_children[index];
PL_UNLOCK;
o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
if (o_value == nil) {
/* FIXME: Why is there a warning if that happens all the time and seems
* to be normal? Add an assert and fix it.
* msg_Warn(VLCIntf, "playlist item misses pointer value, adding one"); */
o_value = [[NSValue valueWithPointer: p_return] retain];
}
[o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
return o_value;
}
/* is the item expandable */
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
int i_return = 0;
playlist_t *p_playlist = pl_Get(VLCIntf);
PL_LOCK;
if (item == nil) {
/* root object */
if (p_current_root_item) {
i_return = p_current_root_item->i_children;
}
} else {
playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
if (p_item)
i_return = p_item->i_children;
}
PL_UNLOCK;
return (i_return >= 0);
}
/* retrieve the string values for the cells */
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
{
id o_value = nil;
char * psz_value;
playlist_item_t *p_item;
/* For error handling */
static BOOL attempted_reload = NO;
if (item == nil || ![item isKindOfClass: [NSValue class]]) {
/* Attempt to fix the error by asking for a data redisplay
* This might cause infinite loop, so add a small check */
if (!attempted_reload) {
attempted_reload = YES;
[outlineView reloadData];
}
return @"error" ;
}
p_item = (playlist_item_t *)[item pointerValue];
if (!p_item || !p_item->p_input) {
/* Attempt to fix the error by asking for a data redisplay
* This might cause infinite loop, so add a small check */
if (!attempted_reload) {
attempted_reload = YES;
[outlineView reloadData];
}
return @"error";
}
attempted_reload = NO;
NSString * o_identifier = [o_tc identifier];
if ([o_identifier isEqualToString:TRACKNUM_COLUMN]) {
psz_value = input_item_GetTrackNumber(p_item->p_input);
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:TITLE_COLUMN]) {
/* sanity check to prevent the NSString class from crashing */
char *psz_title = input_item_GetTitleFbName(p_item->p_input);
if (psz_title) {
o_value = [NSString stringWithUTF8String:psz_title];
free(psz_title);
}
} else if ([o_identifier isEqualToString:ARTIST_COLUMN]) {
psz_value = input_item_GetArtist(p_item->p_input);
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:@"duration"]) {
char psz_duration[MSTRTIME_MAX_SIZE];
mtime_t dur = input_item_GetDuration(p_item->p_input);
if (dur != -1) {
secstotimestr(psz_duration, dur/1000000);
o_value = [NSString stringWithUTF8String:psz_duration];
}
else
o_value = @"--:--";
} else if ([o_identifier isEqualToString:GENRE_COLUMN]) {
psz_value = input_item_GetGenre(p_item->p_input);
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:ALBUM_COLUMN]) {
psz_value = input_item_GetAlbum(p_item->p_input);
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:DESCRIPTION_COLUMN]) {
psz_value = input_item_GetDescription(p_item->p_input);
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:DATE_COLUMN]) {
psz_value = input_item_GetDate(p_item->p_input);
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:LANGUAGE_COLUMN]) {
psz_value = input_item_GetLanguage(p_item->p_input);
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
}
else if ([o_identifier isEqualToString:URI_COLUMN]) {
psz_value = decode_URI(input_item_GetURI(p_item->p_input));
if (psz_value) {
o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
}
else if ([o_identifier isEqualToString:FILESIZE_COLUMN]) {
psz_value = input_item_GetURI(p_item->p_input);
o_value = @"";
if (psz_value) {
NSURL *url = [NSURL URLWithString:[NSString stringWithUTF8String:psz_value]];
if ([url isFileURL]) {
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:[url path]]) {
NSError *error;
NSDictionary *attributes = [fileManager attributesOfItemAtPath:[url path] error:&error];
o_value = [VLCByteCountFormatter stringFromByteCount:[attributes fileSize] countStyle:NSByteCountFormatterCountStyleDecimal];
}
}
free(psz_value);
}
}
else if ([o_identifier isEqualToString:@"status"]) {
if (input_item_HasErrorWhenReading(p_item->p_input)) {
o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
[o_value setSize: NSMakeSize(16,16)];
}
}
return o_value;
}
@end
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