diff --git a/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib b/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib index aaab3b6169532e285f9e8c36ded58856ccdfcee3..eab65dcab2c6e4b8735899afbcbcfbe1ed3ef7f8 100644 --- a/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib +++ b/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib @@ -44,6 +44,7 @@ <constraint firstItem="ohB-P0-nCv" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="mGo-gc-dR6"/> <constraint firstItem="Hnm-OH-KKY" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="owl-FT-tZX"/> <constraint firstItem="Hnm-OH-KKY" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="vEf-1U-gh4"/> + <constraint firstItem="3Ha-ZH-fa9" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="ohB-P0-nCv" secondAttribute="trailing" constant="10" id="wQv-VX-Hhb"/> </constraints> <connections> <outlet property="durationTextField" destination="3Ha-ZH-fa9" id="vbh-oE-Afj"/> diff --git a/modules/gui/macosx/VLCPlaylistController.h b/modules/gui/macosx/VLCPlaylistController.h index a2fdd85966dc6259d42bf8961fd6197ecef8259a..ced07666d6d979908de869a5213c1060b5994dfe 100644 --- a/modules/gui/macosx/VLCPlaylistController.h +++ b/modules/gui/macosx/VLCPlaylistController.h @@ -47,6 +47,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readwrite, assign) VLCPlaylistDataSource *playlistDataSource; +/** + * Index of the current playlist item + */ +@property (readonly) size_t currentPlaylistIndex; + /** * indicates whether there is a previous item in the list the user could go back to */ diff --git a/modules/gui/macosx/VLCPlaylistController.m b/modules/gui/macosx/VLCPlaylistController.m index f5e632e9255dfb231e76496f4925c0a661911622..e4aa8e37368b3bdd602730fab34cc453426b5884 100644 --- a/modules/gui/macosx/VLCPlaylistController.m +++ b/modules/gui/macosx/VLCPlaylistController.m @@ -32,9 +32,11 @@ vlc_playlist_listener_id *_playlistListenerID; } +- (void)playlistResetWithItems:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems; - (void)playlistAdded:(vlc_playlist_item_t *const *)items atIndex:(size_t)insertionIndex count:(size_t)numberOfItems; - (void)playlistRemovedItemsAtIndex:(size_t)index count:(size_t)numberOfItems; - (void)currentPlaylistItemChanged:(ssize_t)index; +- (void)playlistUpdatedForIndex:(size_t)firstUpdatedIndex items:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems; @end @@ -48,6 +50,8 @@ cb_playlist_items_reset(vlc_playlist_t *playlist, void *p_data) { NSLog(@"%s: numberOfItems %zu", __func__, numberOfItems); + VLCPlaylistController *playlistController = (__bridge VLCPlaylistController *)p_data; + [playlistController playlistResetWithItems:items count:numberOfItems]; } static void @@ -75,12 +79,14 @@ cb_playlist_items_removed(vlc_playlist_t *playlist, static void cb_playlist_items_updated(vlc_playlist_t *playlist, - size_t index, + size_t firstUpdatedIndex, vlc_playlist_item_t *const items[], - size_t len, + size_t numberOfUpdatedItems, void *p_data) { - NSLog(@"%s: index: %zu len: %zu", __func__, index, len); + NSLog(@"%s: index: %zu len: %zu", __func__, firstUpdatedIndex, numberOfUpdatedItems); + VLCPlaylistController *playlistController = (__bridge VLCPlaylistController *)p_data; + [playlistController playlistUpdatedForIndex:firstUpdatedIndex items:items count:numberOfUpdatedItems]; } static void @@ -159,6 +165,17 @@ static const struct vlc_playlist_callbacks playlist_callbacks = { #pragma mark - callback forwarders +- (void)playlistResetWithItems:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems +{ + NSLog(@"%s", __func__); + + for (size_t i = 0; i < numberOfItems; i++) { + [_playlistModel addItem:items[i]]; + } + + [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO]; +} + - (void)playlistAdded:(vlc_playlist_item_t *const *)items atIndex:(size_t)insertionIndex count:(size_t)numberOfItems { NSLog(@"%s", __func__); @@ -184,6 +201,17 @@ static const struct vlc_playlist_callbacks playlist_callbacks = { - (void)currentPlaylistItemChanged:(ssize_t)index { + _currentPlaylistIndex = index; + [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO]; +} + +- (void)playlistUpdatedForIndex:(size_t)firstUpdatedIndex items:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems +{ + NSLog(@"%s", __func__); + VLC_UNUSED(items); + for (size_t i = firstUpdatedIndex; i < firstUpdatedIndex + numberOfItems; i++) { + [_playlistModel updateItemAtIndex:i]; + } [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO]; } diff --git a/modules/gui/macosx/VLCPlaylistDataSource.m b/modules/gui/macosx/VLCPlaylistDataSource.m index 05e7df8a550636a7c83add861a8c206b112ac2ef..cedb6060aecde1f3198ed82ce563b746ddd7ded0 100644 --- a/modules/gui/macosx/VLCPlaylistDataSource.m +++ b/modules/gui/macosx/VLCPlaylistDataSource.m @@ -77,7 +77,7 @@ static NSString *VLCPlaylistCellIdentifier = @"VLCPlaylistCellIdentifier"; } cellView.mediaTitleTextField.stringValue = item.title; - cellView.durationTextField.stringValue = [NSString stringWithTime:item.duration]; + cellView.durationTextField.stringValue = [NSString stringWithTimeFromTicks:item.duration]; cellView.mediaImageView.image = [NSImage imageNamed: @"noart.png"]; // TODO: show more data if available diff --git a/modules/gui/macosx/VLCPlaylistItem.h b/modules/gui/macosx/VLCPlaylistItem.h index 8168b1dc27ef2b8da82fa0f97e7cae54e3dafae5..b1b0f28ffbe84b1806cfa95ebcbe5efbacded3dd 100644 --- a/modules/gui/macosx/VLCPlaylistItem.h +++ b/modules/gui/macosx/VLCPlaylistItem.h @@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN @property (readwrite, retain, nullable) NSString *artworkURLString; - (instancetype)initWithPlaylistItem:(vlc_playlist_item_t *)p_item; +- (void)updateRepresentation; @end diff --git a/modules/gui/macosx/VLCPlaylistItem.m b/modules/gui/macosx/VLCPlaylistItem.m index 52da3b1c5f21f1e290f66e44ae163bf023bff79e..c881709bef7e7ef9133e141e949e7eb8ca1534f3 100644 --- a/modules/gui/macosx/VLCPlaylistItem.m +++ b/modules/gui/macosx/VLCPlaylistItem.m @@ -32,24 +32,29 @@ self = [super init]; if (self) { _playlistItem = p_item; - input_item_t *p_media = vlc_playlist_item_GetMedia(p_item); - vlc_mutex_lock(&p_media->lock); - _title = toNSStr(p_media->psz_name); - _duration = p_media->i_duration; - - if (p_media->p_meta) { - _artistName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Artist)); - _albumName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Album)); - _artworkURLString = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_ArtworkURL)); - } - vlc_mutex_unlock(&p_media->lock); + [self updateRepresentation]; } return self; } - (NSString *)description { - return [NSString stringWithFormat:@"item %p, title: %@", &_playlistItem, _title]; + return [NSString stringWithFormat:@"item %p, title: %@ duration %lli", &_playlistItem, _title, _duration]; +} + +- (void)updateRepresentation +{ + input_item_t *p_media = vlc_playlist_item_GetMedia(_playlistItem); + vlc_mutex_lock(&p_media->lock); + _title = toNSStr(p_media->psz_name); + _duration = p_media->i_duration; + + if (p_media->p_meta) { + _artistName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Artist)); + _albumName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Album)); + _artworkURLString = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_ArtworkURL)); + } + vlc_mutex_unlock(&p_media->lock); } - (NSString *)path diff --git a/modules/gui/macosx/VLCPlaylistModel.h b/modules/gui/macosx/VLCPlaylistModel.h index d5697739e0fa19e00c064200a761ac7bc20dd81c..855d622b869ac74fe361754a28b14ae8e016ab90 100644 --- a/modules/gui/macosx/VLCPlaylistModel.h +++ b/modules/gui/macosx/VLCPlaylistModel.h @@ -33,9 +33,12 @@ NS_ASSUME_NONNULL_BEGIN @property (readwrite, assign) VLCPlaylistController *playlistController; @property (readonly) size_t numberOfPlaylistItems; +- (void)dropExistingData; - (VLCPlaylistItem *)playlistItemAtIndex:(NSInteger)index; +- (void)addItem:(vlc_playlist_item_t *)item; - (void)addItem:(vlc_playlist_item_t *)item atIndex:(size_t)index; - (void)removeItemAtIndex:(size_t)index; +- (void)updateItemAtIndex:(size_t)index; @end diff --git a/modules/gui/macosx/VLCPlaylistModel.m b/modules/gui/macosx/VLCPlaylistModel.m index 795f691e151e8ed1af2c4634929000a2fce7b8e3..2183b76f8d60f4b19523d6f3d82d9b0e0ab2610b 100644 --- a/modules/gui/macosx/VLCPlaylistModel.m +++ b/modules/gui/macosx/VLCPlaylistModel.m @@ -53,11 +53,22 @@ return ret; } +- (void)dropExistingData +{ + [_playlistArray removeAllObjects]; +} + - (VLCPlaylistItem *)playlistItemAtIndex:(NSInteger)index { return _playlistArray[index]; } +- (void)addItem:(vlc_playlist_item_t *)item +{ + VLCPlaylistItem *playlistItem = [[VLCPlaylistItem alloc] initWithPlaylistItem:item]; + [_playlistArray addObject:playlistItem]; +} + - (void)addItem:(vlc_playlist_item_t *)item atIndex:(size_t)index { VLCPlaylistItem *playlistItem = [[VLCPlaylistItem alloc] initWithPlaylistItem:item]; @@ -69,4 +80,10 @@ [_playlistArray removeObjectAtIndex:index]; } +- (void)updateItemAtIndex:(size_t)index +{ + VLCPlaylistItem *item = _playlistArray[index]; + [item updateRepresentation]; +} + @end