Commit 2903e5dd authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx/playlist: move core callbacks to model

parent 896af425
...@@ -63,6 +63,8 @@ typedef enum { ...@@ -63,6 +63,8 @@ typedef enum {
- (PLRootType)currentRootType; - (PLRootType)currentRootType;
- (BOOL)editAllowed; - (BOOL)editAllowed;
- (void)deleteSelectedItem;
// updates from core // updates from core
- (void)addItem:(int)i_item withParentNode:(int)i_node; - (void)addItem:(int)i_item withParentNode:(int)i_node;
- (void)removeItem:(int)i_item; - (void)removeItem:(int)i_item;
...@@ -71,6 +73,8 @@ typedef enum { ...@@ -71,6 +73,8 @@ typedef enum {
- (PLItem *)currentlyPlayingItem; - (PLItem *)currentlyPlayingItem;
- (void)playbackModeUpdated;
// sorting / searching // sorting / searching
- (void)sortForColumn:(NSString *)o_column withMode:(int)i_mode; - (void)sortForColumn:(NSString *)o_column withMode:(int)i_mode;
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#import "playlist.h" #import "playlist.h"
#import "StringUtility.h" #import "StringUtility.h"
#import "intf.h"
#import "ControlsBar.h"
#import "MainMenu.h"
#import "playlistinfo.h"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# import "config.h" # import "config.h"
...@@ -36,6 +40,61 @@ ...@@ -36,6 +40,61 @@
#include <vlc_input.h> #include <vlc_input.h>
#include <vlc_url.h> #include <vlc_url.h>
static int PLItemUpdated(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(plItemUpdated) withObject:nil waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int PLItemAppended(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
playlist_add_t *p_add = new_val.p_address;
NSArray *o_val = [NSArray arrayWithObjects:[NSNumber numberWithInt:p_add->i_node], [NSNumber numberWithInt:p_add->i_item], nil];
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(plItemAppended:) withObject:o_val waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int PLItemRemoved(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
NSNumber *o_val = [NSNumber numberWithInt:new_val.i_int];
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(plItemRemoved:) withObject:o_val waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int PlaybackModeUpdated(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(playbackModeUpdated) withObject:nil waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
dispatch_async(dispatch_get_main_queue(), ^{
[[[VLCMain sharedInstance] mainWindow] updateVolumeSlider];
});
return VLC_SUCCESS;
}
}
#pragma mark - #pragma mark -
@interface PLModel () @interface PLModel ()
...@@ -45,6 +104,7 @@ ...@@ -45,6 +104,7 @@
// TODO: for transition // TODO: for transition
VLCPlaylist *_playlist; VLCPlaylist *_playlist;
NSUInteger _retainedRowSelection;
} }
@end @end
...@@ -61,19 +121,38 @@ ...@@ -61,19 +121,38 @@
_outlineView = outlineView; _outlineView = outlineView;
_playlist = plObj; _playlist = plObj;
var_AddCallback(p_playlist, "item-change", PLItemUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "playlist-item-append", PLItemAppended, (__bridge void *)self);
var_AddCallback(p_playlist, "playlist-item-deleted", PLItemRemoved, (__bridge void *)self);
var_AddCallback(p_playlist, "random", PlaybackModeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "repeat", PlaybackModeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "loop", PlaybackModeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "volume", VolumeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "mute", VolumeUpdated, (__bridge void *)self);
PL_LOCK; PL_LOCK;
_rootItem = [[PLItem alloc] initWithPlaylistItem:root]; _rootItem = [[PLItem alloc] initWithPlaylistItem:root];
[self rebuildPLItem:_rootItem]; [self rebuildPLItem:_rootItem];
PL_UNLOCK; PL_UNLOCK;
} }
return self; return self;
} }
- (void)dealloc
{
var_DelCallback(p_playlist, "item-change", PLItemUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "playlist-item-append", PLItemAppended, (__bridge void *)self);
var_DelCallback(p_playlist, "playlist-item-deleted", PLItemRemoved, (__bridge void *)self);
var_DelCallback(p_playlist, "random", PlaybackModeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "repeat", PlaybackModeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "loop", PlaybackModeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "volume", VolumeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "mute", VolumeUpdated, (__bridge void *)self);
}
- (void)changeRootItem:(playlist_item_t *)p_root; - (void)changeRootItem:(playlist_item_t *)p_root;
{ {
NSLog(@"change root item to %p", p_root);
PL_ASSERT_LOCKED; PL_ASSERT_LOCKED;
_rootItem = [[PLItem alloc] initWithPlaylistItem:p_root]; _rootItem = [[PLItem alloc] initWithPlaylistItem:p_root];
[self rebuildPLItem:_rootItem]; [self rebuildPLItem:_rootItem];
...@@ -104,10 +183,31 @@ ...@@ -104,10 +183,31 @@
[self currentRootType] == ROOT_TYPE_PLAYLIST; [self currentRootType] == ROOT_TYPE_PLAYLIST;
} }
- (void)rebuildPLItem:(PLItem *)o_item - (void)deleteSelectedItem
{
// check if deletion is allowed
if (![self editAllowed])
return;
NSIndexSet *selectedIndexes = [_outlineView selectedRowIndexes];
_retainedRowSelection = [selectedIndexes firstIndex];
if (_retainedRowSelection == NSNotFound)
_retainedRowSelection = 0;
[selectedIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
PLItem *item = [_outlineView itemAtRow: idx];
if (!item)
return;
// model deletion is done via callback
playlist_DeleteFromInput(p_playlist, [item input], pl_Unlocked);
}];
}
- (void)rebuildPLItem:(PLItem *)item
{ {
[o_item clear]; [item clear];
playlist_item_t *p_item = playlist_ItemGetById(p_playlist, [o_item plItemId]); playlist_item_t *p_item = playlist_ItemGetById(p_playlist, [item plItemId]);
if (p_item) { if (p_item) {
int currPos = 0; int currPos = 0;
for(int i = 0; i < p_item->i_children; ++i) { for(int i = 0; i < p_item->i_children; ++i) {
...@@ -116,11 +216,11 @@ ...@@ -116,11 +216,11 @@
if (p_child->i_flags & PLAYLIST_DBL_FLAG) if (p_child->i_flags & PLAYLIST_DBL_FLAG)
continue; continue;
PLItem *o_child = [[PLItem alloc] initWithPlaylistItem:p_child]; PLItem *child = [[PLItem alloc] initWithPlaylistItem:p_child];
[o_item addChild:o_child atPos:currPos++]; [item addChild:child atPos:currPos++];
if (p_child->i_children >= 0) { if (p_child->i_children >= 0) {
[self rebuildPLItem:o_child]; [self rebuildPLItem:child];
} }
} }
...@@ -158,10 +258,48 @@ ...@@ -158,10 +258,48 @@
#pragma mark - #pragma mark -
#pragma mark Core events #pragma mark Core events
- (void)addItem:(int)i_item withParentNode:(int)i_node
- (void)plItemAppended:(NSArray *)valueArray
{
int i_node = [[valueArray firstObject] intValue];
int i_item = [valueArray[1] intValue];
[self addItem:i_item withParentNode:i_node];
// update badge in sidebar
[[[VLCMain sharedInstance] mainWindow] updateWindow];
[[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
object: nil
userInfo: nil];
}
- (void)plItemRemoved:(NSNumber *)value
{ {
NSLog(@"add item with index %d, parent: %d", i_item, i_node); int i_item = [value intValue];
[self removeItem:i_item];
// retain selection before deletion
[_outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:_retainedRowSelection] byExtendingSelection:NO];
// update badge in sidebar
[[[VLCMain sharedInstance] mainWindow] updateWindow];
[[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
object: nil
userInfo: nil];
}
- (void)plItemUpdated
{
VLCMain *instance = [VLCMain sharedInstance];
[[instance mainWindow] updateName];
[[VLCInfo sharedInstance] updateMetadata];
}
- (void)addItem:(int)i_item withParentNode:(int)i_node
{
PLItem *o_parent = [self findItemByPlaylistId:i_node]; PLItem *o_parent = [self findItemByPlaylistId:i_node];
if (!o_parent) { if (!o_parent) {
return; return;
...@@ -195,8 +333,6 @@ ...@@ -195,8 +333,6 @@
- (void)removeItem:(int)i_item - (void)removeItem:(int)i_item
{ {
NSLog(@"remove item with index %d", i_item);
PLItem *o_item = [self findItemByPlaylistId:i_item]; PLItem *o_item = [self findItemByPlaylistId:i_item];
if (!o_item) { if (!o_item) {
return; return;
...@@ -246,6 +382,28 @@ ...@@ -246,6 +382,28 @@
return item; return item;
} }
- (void)playbackModeUpdated
{
bool loop = var_GetBool(p_playlist, "loop");
bool repeat = var_GetBool(p_playlist, "repeat");
VLCMainWindowControlsBar *controlsBar = (VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar];
VLCMainMenu *mainMenu = [[VLCMain sharedInstance] mainMenu];
if (repeat) {
[controlsBar setRepeatOne];
[mainMenu setRepeatOne];
} else if (loop) {
[controlsBar setRepeatAll];
[mainMenu setRepeatAll];
} else {
[controlsBar setRepeatOff];
[mainMenu setRepeatOff];
}
[controlsBar setShuffle];
[mainMenu setShuffle];
}
#pragma mark - #pragma mark -
#pragma mark Sorting / Searching #pragma mark Sorting / Searching
......
...@@ -60,8 +60,6 @@ ...@@ -60,8 +60,6 @@
- (BOOL)isSelectionEmpty; - (BOOL)isSelectionEmpty;
- (void)deletionCompleted;
- (IBAction)playItem:(id)sender; - (IBAction)playItem:(id)sender;
- (IBAction)revealItemInFinder:(id)sender; - (IBAction)revealItemInFinder:(id)sender;
- (IBAction)preparseItem:(id)sender; - (IBAction)preparseItem:(id)sender;
......
...@@ -42,76 +42,15 @@ ...@@ -42,76 +42,15 @@
#import "CompatibilityFixes.h" #import "CompatibilityFixes.h"
#import "intf.h" #import "intf.h"
#import "bookmarks.h"
#import "playlistinfo.h"
#import "playlist.h" #import "playlist.h"
#import "misc.h"
#import "open.h"
#import "MainMenu.h" #import "MainMenu.h"
#import "CoreInteraction.h" #import "playlistinfo.h"
#import "ControlsBar.h"
#import "ResumeDialogController.h" #import "ResumeDialogController.h"
#include <vlc_keys.h> #include <vlc_keys.h>
#import <vlc_interface.h> #import <vlc_interface.h>
#include <vlc_url.h> #include <vlc_url.h>
static int PLItemUpdated(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(plItemUpdated) withObject:nil waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int PLItemAppended(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
playlist_add_t *p_add = new_val.p_address;
NSArray *o_val = [NSArray arrayWithObjects:[NSNumber numberWithInt:p_add->i_node], [NSNumber numberWithInt:p_add->i_item], nil];
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(plItemAppended:) withObject:o_val waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int PLItemRemoved(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
NSNumber *o_val = [NSNumber numberWithInt:new_val.i_int];
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(plItemRemoved:) withObject:o_val waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int PlaybackModeUpdated(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
[[[VLCMain sharedInstance] playlist] performSelectorOnMainThread:@selector(playbackModeUpdated) withObject:nil waitUntilDone:NO];
return VLC_SUCCESS;
}
}
static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
@autoreleasepool {
dispatch_async(dispatch_get_main_queue(), ^{
[[[VLCMain sharedInstance] mainWindow] updateVolumeSlider];
});
return VLC_SUCCESS;
}
}
/***************************************************************************** /*****************************************************************************
* An extension to NSOutlineView's interface to fix compilation warnings * An extension to NSOutlineView's interface to fix compilation warnings
* and let us access these 2 functions properly. * and let us access these 2 functions properly.
...@@ -133,7 +72,6 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var, ...@@ -133,7 +72,6 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
BOOL b_selected_item_met; BOOL b_selected_item_met;
BOOL b_isSortDescending; BOOL b_isSortDescending;
NSTableColumn *_sortTableColumn; NSTableColumn *_sortTableColumn;
NSUInteger retainedRowSelection;
BOOL b_playlistmenu_nib_loaded; BOOL b_playlistmenu_nib_loaded;
BOOL b_view_setup; BOOL b_view_setup;
...@@ -162,36 +100,6 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var, ...@@ -162,36 +100,6 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
[defaults registerDefaults:appDefaults]; [defaults registerDefaults:appDefaults];
} }
- (instancetype)init
{
self = [super init];
if (self) {
playlist_t *p_playlist = pl_Get(VLCIntf);
var_AddCallback(p_playlist, "item-change", PLItemUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "playlist-item-append", PLItemAppended, (__bridge void *)self);
var_AddCallback(p_playlist, "playlist-item-deleted", PLItemRemoved, (__bridge void *)self);
var_AddCallback(p_playlist, "random", PlaybackModeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "repeat", PlaybackModeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "loop", PlaybackModeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "volume", VolumeUpdated, (__bridge void *)self);
var_AddCallback(p_playlist, "mute", VolumeUpdated, (__bridge void *)self);
}
return self;
}
- (void)dealloc
{
playlist_t *p_playlist = pl_Get(VLCIntf);
var_DelCallback(p_playlist, "item-change", PLItemUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "playlist-item-append", PLItemAppended, (__bridge void *)self);
var_DelCallback(p_playlist, "playlist-item-deleted", PLItemRemoved, (__bridge void *)self);
var_DelCallback(p_playlist, "random", PlaybackModeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "repeat", PlaybackModeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "loop", PlaybackModeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "volume", VolumeUpdated, (__bridge void *)self);
var_DelCallback(p_playlist, "mute", VolumeUpdated, (__bridge void *)self);
}
- (PLModel *)model - (PLModel *)model
{ {
return _model; return _model;
...@@ -304,66 +212,9 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var, ...@@ -304,66 +212,9 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
[_outlineView reloadData]; [_outlineView reloadData];
} }
- (void)plItemAppended:(NSArray *)valueArray
{
int i_node = [[valueArray firstObject] intValue];
int i_item = [valueArray[1] intValue];
[[self model] addItem:i_item withParentNode:i_node];
// update badge in sidebar
[[[VLCMain sharedInstance] mainWindow] updateWindow];
[[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
object: nil
userInfo: nil];
}
- (void)plItemRemoved:(NSNumber *)value
{
int i_item = [value intValue];
[[self model] removeItem:i_item];
[self deletionCompleted];
// update badge in sidebar
[[[VLCMain sharedInstance] mainWindow] updateWindow];
[[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
object: nil
userInfo: nil];
}
- (void)plItemUpdated
{
VLCMain *instance = [VLCMain sharedInstance];
[[instance mainWindow] updateName];
[[VLCInfo sharedInstance] updateMetadata];
}
- (void)playbackModeUpdated - (void)playbackModeUpdated
{ {
playlist_t * p_playlist = pl_Get(VLCIntf); [_model playbackModeUpdated];
bool loop = var_GetBool(p_playlist, "loop");
bool repeat = var_GetBool(p_playlist, "repeat");
VLCMainWindowControlsBar *controlsBar = (VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar];
VLCMainMenu *mainMenu = [[VLCMain sharedInstance] mainMenu];
if (repeat) {
[controlsBar setRepeatOne];
[mainMenu setRepeatOne];
} else if (loop) {
[controlsBar setRepeatAll];
[mainMenu setRepeatAll];
} else {
[controlsBar setRepeatOff];
[mainMenu setRepeatOff];
}
[controlsBar setShuffle];
[mainMenu setShuffle];
} }
- (void)updateTogglePlaylistState - (void)updateTogglePlaylistState
...@@ -546,33 +397,9 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var, ...@@ -546,33 +397,9 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
[[VLCInfo sharedInstance] initPanel]; [[VLCInfo sharedInstance] initPanel];
} }
- (void)deletionCompleted
{
// retain selection before deletion
[_outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:retainedRowSelection] byExtendingSelection:NO];
}
- (IBAction)deleteItem:(id)sender - (IBAction)deleteItem:(id)sender
{ {
playlist_t * p_playlist = pl_Get(VLCIntf); [_model deleteSelectedItem];
// check if deletion is allowed
if (![[self model] editAllowed])
return;
NSIndexSet *selectedIndexes = [_outlineView selectedRowIndexes];
retainedRowSelection = [selectedIndexes firstIndex];
if (retainedRowSelection == NSNotFound)
retainedRowSelection = 0;
[selectedIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
PLItem *o_item = [_outlineView itemAtRow: idx];
if (!o_item)
return;
// model deletion is done via callback
playlist_DeleteFromInput(p_playlist, [o_item input], pl_Unlocked);
}];
} }
- (IBAction)sortNodeByName:(id)sender - (IBAction)sortNodeByName:(id)sender
......
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