Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 141 lines (95 sloc) 4.07 KB
/*
* MPDclient - Music Player Daemon (MPD) remote for Mac OS
* Copyright (C) 2019 Old-Geek
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#import "PlaylistViewController.h"
#import "ViewCache.h"
#import "TableviewContextualMenu.h"
#import "TableHeaderContextualMenu.h"
#import "TableSongGetter.h"
@implementation PlaylistViewController
NSArray *playlistArray;
NSString *currentPl;
long rowSongSelected;
MPDPlayLists *playLists;
- (void)viewDidLoad {
[super viewDidLoad];
// purge sinon crash si nouvelle liste inférieur en nombre à l'ancienne
playlistArray = nil;
[_playlistTableView reloadData];
playlistArray = [[MPDPlayLists alloc] getPlaylistContent:[[ViewCache sViewCache] currentPlaylist]];
[_playlistTableView setTarget:self];
[_playlistTableView setDoubleAction:@selector(doubleClick)];
[MPDDelegate sMPDDelegate].delegatePlyalist = self;
[SearchDelegate sSearchDelegate].delegatePlaylist = self;
[self onStateChange];
}
- (void)awakeFromNib {
[self performSelectorOnMainThread:@selector(updateTable:) withObject:_playlistTableView waitUntilDone:NO];
}
- (void)updateTable:(NSTableView *)table {
[table reloadData];
}
- (void)doubleClick {
unsigned int rowNumber = (unsigned int) [_playlistTableView clickedRow];
[[MPDPlayLists alloc] playingPlaylist:playlistArray position:rowNumber];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [playlistArray count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
TableSongGetter * getter = [[TableSongGetter alloc] initWithArray:playlistArray];
return [getter getCell:tableView tableColumn:tableColumn row:row];
}
- (void)menuWillOpen:(NSMenu *)menu {
[menu removeAllItems];
rowSongSelected = (long)_playlistTableView.clickedRow;
if (rowSongSelected >= 0)
[self setMenu:menu];
}
- (void)setMenu:(NSMenu *)menu {
[menu addItemWithTitle:NSLocalizedString(@"Supprimer", @"delete") action:@selector(supprimer:) keyEquivalent:@""];
[menu addItemWithTitle:NSLocalizedString(@"Ajouter à la liste de lecture", @"add to queue") action:@selector(addToQueue:) keyEquivalent:@""];
}
- (void)addToQueue:(id)sender {
NSMutableDictionary *robert = [NSMutableDictionary dictionary];
[robert setObject:[_playlistTableView selectedRowIndexes] forKey:@"row"];
[robert setObject:playlistArray forKey:@"array"];
[robert setObject:[NSString stringWithFormat:@"%ld", rowSongSelected] forKey:@"selected"];
[[TableviewContextualMenu alloc] addInQueue:robert];
}
- (void)supprimer:(id)sender {
NSIndexSet *row = [_playlistTableView selectedRowIndexes];
playlistArray = [[[TableviewContextualMenu alloc] initWithRowSelected:rowSongSelected] supprimer:@"playlist" array:playlistArray row:row];
[_playlistTableView reloadData];
}
- (void)onStateChange {
[self performSelectorOnMainThread:@selector(updateTable:) withObject:_playlistTableView waitUntilDone:NO];
}
- (void)onSearch:(NSString *)query {
playlistArray = [[MPDPlayLists alloc] getPlaylistContent:[[ViewCache sViewCache] currentPlaylist]];
if (query.length < 1) {
[_playlistTableView reloadData];
return;
}
playlistArray = [playlistArray filterPlaylist:query];
[_playlistTableView reloadData];
}
- (void)showHideColumn:(id)sender {
[[TableHeaderContextualMenu alloc] showHide:_playlistTableView menu:sender];
}
@end
You can’t perform that action at this time.