2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine .
* Copyright 2010 , David Sansome < me @ davidsansome . com >
2021-03-20 21:14:47 +01:00
* Copyright 2018 - 2021 , Jonas Kvinge < jonas @ jkvinge . net >
2018-02-27 18:06:05 +01:00
*
* Strawberry 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 .
*
* Strawberry 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 Strawberry . If not , see < http : //www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
# include "config.h"
2018-05-01 00:41:33 +02:00
# include <QObject>
# include <QWidget>
2020-02-08 15:03:11 +01:00
# include <QStandardItemModel>
# include <QAbstractItemModel>
# include <QItemSelectionModel>
# include <QSortFilterProxyModel>
2018-05-01 00:41:33 +02:00
# include <QSet>
2020-02-08 15:03:11 +01:00
# include <QList>
2018-05-01 00:41:33 +02:00
# include <QVariant>
# include <QString>
# include <QPixmap>
2018-02-27 18:06:05 +01:00
# include <QPainter>
2018-05-01 00:41:33 +02:00
# include <QIcon>
# include <QSize>
2020-02-08 15:03:11 +01:00
# include <QMenu>
# include <QAction>
2020-06-28 18:36:48 +02:00
# include <QSettings>
2018-05-01 00:41:33 +02:00
# include <QMessageBox>
# include <QInputDialog>
# include <QToolButton>
2020-02-08 15:03:11 +01:00
# include <QShowEvent>
# include <QContextMenuEvent>
2018-02-27 18:06:05 +01:00
2018-05-01 00:41:33 +02:00
# include "core/application.h"
# include "core/iconloader.h"
# include "core/player.h"
2018-02-27 18:06:05 +01:00
# include "playlist.h"
2018-05-01 00:41:33 +02:00
# include "playlistbackend.h"
# include "playlistlistview.h"
2018-02-27 18:06:05 +01:00
# include "playlistlistcontainer.h"
# include "playlistlistmodel.h"
# include "playlistmanager.h"
# include "ui_playlistlistcontainer.h"
2020-08-04 21:18:14 +02:00
# include "organize/organizedialog.h"
2020-06-28 18:36:48 +02:00
# include "settings/appearancesettingspage.h"
2019-08-07 17:13:40 +02:00
# ifndef Q_OS_WIN
# include "device / devicemanager.h"
# include "device / devicestatefiltermodel.h"
# endif
2018-02-27 18:06:05 +01:00
class PlaylistListSortFilterModel : public QSortFilterProxyModel {
public :
explicit PlaylistListSortFilterModel ( QObject * parent )
2020-10-01 19:49:06 +02:00
: QSortFilterProxyModel ( parent ) { }
2018-02-27 18:06:05 +01:00
2020-06-15 21:55:05 +02:00
bool lessThan ( const QModelIndex & left , const QModelIndex & right ) const override {
2018-02-27 18:06:05 +01:00
// Compare the display text first.
const int ret = left . data ( ) . toString ( ) . localeAwareCompare ( right . data ( ) . toString ( ) ) ;
if ( ret < 0 ) return true ;
if ( ret > 0 ) return false ;
2018-05-01 00:41:33 +02:00
// Now use the source model row order to ensure we always get a deterministic sorting even when two items are named the same.
2018-02-27 18:06:05 +01:00
return left . row ( ) < right . row ( ) ;
}
} ;
PlaylistListContainer : : PlaylistListContainer ( QWidget * parent )
: QWidget ( parent ) ,
app_ ( nullptr ) ,
ui_ ( new Ui_PlaylistListContainer ) ,
menu_ ( nullptr ) ,
action_new_folder_ ( new QAction ( this ) ) ,
action_remove_ ( new QAction ( this ) ) ,
action_save_playlist_ ( new QAction ( this ) ) ,
2020-10-08 19:19:39 +02:00
# ifndef Q_OS_WIN
2019-08-07 17:13:40 +02:00
action_copy_to_device_ ( new QAction ( this ) ) ,
2020-10-08 19:19:39 +02:00
# endif
2018-02-27 18:06:05 +01:00
model_ ( new PlaylistListModel ( this ) ) ,
proxy_ ( new PlaylistListSortFilterModel ( this ) ) ,
loaded_icons_ ( false ) ,
active_playlist_id_ ( - 1 )
{
ui_ - > setupUi ( this ) ;
ui_ - > tree - > setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
action_new_folder_ - > setText ( tr ( " New folder " ) ) ;
action_remove_ - > setText ( tr ( " Delete " ) ) ;
action_save_playlist_ - > setText ( tr ( " Save playlist " , " Save playlist menu action. " ) ) ;
2020-10-08 19:19:39 +02:00
# ifndef Q_OS_WIN
2019-08-07 17:13:40 +02:00
action_copy_to_device_ - > setText ( tr ( " Copy to device... " ) ) ;
2020-10-08 19:19:39 +02:00
# endif
2018-02-27 18:06:05 +01:00
ui_ - > new_folder - > setDefaultAction ( action_new_folder_ ) ;
ui_ - > remove - > setDefaultAction ( action_remove_ ) ;
ui_ - > save_playlist - > setDefaultAction ( action_save_playlist_ ) ;
2021-01-26 16:48:04 +01:00
QObject : : connect ( action_new_folder_ , & QAction : : triggered , this , & PlaylistListContainer : : NewFolderClicked ) ;
QObject : : connect ( action_remove_ , & QAction : : triggered , this , & PlaylistListContainer : : Delete ) ;
QObject : : connect ( action_save_playlist_ , & QAction : : triggered , this , & PlaylistListContainer : : SavePlaylist ) ;
2020-10-08 19:19:39 +02:00
# ifndef Q_OS_WIN
2021-01-26 16:48:04 +01:00
QObject : : connect ( action_copy_to_device_ , & QAction : : triggered , this , & PlaylistListContainer : : CopyToDevice ) ;
2020-10-08 19:19:39 +02:00
# endif
2021-01-26 16:48:04 +01:00
QObject : : connect ( model_ , & PlaylistListModel : : PlaylistPathChanged , this , & PlaylistListContainer : : PlaylistPathChanged ) ;
2018-02-27 18:06:05 +01:00
proxy_ - > setSourceModel ( model_ ) ;
proxy_ - > setDynamicSortFilter ( true ) ;
proxy_ - > sort ( 0 ) ;
ui_ - > tree - > setModel ( proxy_ ) ;
2021-01-26 16:48:04 +01:00
QObject : : connect ( ui_ - > tree , & PlaylistListView : : ItemsSelectedChanged , this , & PlaylistListContainer : : ItemsSelectedChanged ) ;
QObject : : connect ( ui_ - > tree , & PlaylistListView : : doubleClicked , this , & PlaylistListContainer : : ItemDoubleClicked ) ;
2018-02-27 18:06:05 +01:00
model_ - > invisibleRootItem ( ) - > setData ( PlaylistListModel : : Type_Folder , PlaylistListModel : : Role_Type ) ;
2020-06-28 18:36:48 +02:00
ReloadSettings ( ) ;
2018-02-27 18:06:05 +01:00
}
PlaylistListContainer : : ~ PlaylistListContainer ( ) { delete ui_ ; }
2020-06-28 18:36:48 +02:00
void PlaylistListContainer : : SetApplication ( Application * app ) {
app_ = app ;
PlaylistManager * manager = app_ - > playlist_manager ( ) ;
Player * player = app_ - > player ( ) ;
2021-01-26 16:48:04 +01:00
QObject : : connect ( manager , & PlaylistManager : : PlaylistAdded , this , & PlaylistListContainer : : AddPlaylist ) ;
QObject : : connect ( manager , & PlaylistManager : : PlaylistFavorited , this , & PlaylistListContainer : : PlaylistFavoriteStateChanged ) ;
QObject : : connect ( manager , & PlaylistManager : : PlaylistRenamed , this , & PlaylistListContainer : : PlaylistRenamed ) ;
QObject : : connect ( manager , & PlaylistManager : : CurrentChanged , this , & PlaylistListContainer : : CurrentChanged ) ;
QObject : : connect ( manager , & PlaylistManager : : ActiveChanged , this , & PlaylistListContainer : : ActiveChanged ) ;
2020-06-28 18:36:48 +02:00
2021-01-26 16:48:04 +01:00
QObject : : connect ( model_ , & PlaylistListModel : : PlaylistRenamed , manager , & PlaylistManager : : Rename ) ;
2020-06-28 18:36:48 +02:00
2021-01-26 16:48:04 +01:00
QObject : : connect ( player , & Player : : Paused , this , & PlaylistListContainer : : ActivePaused ) ;
QObject : : connect ( player , & Player : : Playing , this , & PlaylistListContainer : : ActivePlaying ) ;
QObject : : connect ( player , & Player : : Stopped , this , & PlaylistListContainer : : ActiveStopped ) ;
2020-06-28 18:36:48 +02:00
// Get all playlists, even ones that are hidden in the UI.
for ( const PlaylistBackend : : Playlist & p : app - > playlist_backend ( ) - > GetAllFavoritePlaylists ( ) ) {
QStandardItem * playlist_item = model_ - > NewPlaylist ( p . name , p . id ) ;
QStandardItem * parent_folder = model_ - > FolderByPath ( p . ui_path ) ;
parent_folder - > appendRow ( playlist_item ) ;
}
}
void PlaylistListContainer : : ReloadSettings ( ) {
QSettings s ;
s . beginGroup ( AppearanceSettingsPage : : kSettingsGroup ) ;
int iconsize = s . value ( AppearanceSettingsPage : : kIconSizeLeftPanelButtons , 22 ) . toInt ( ) ;
s . endGroup ( ) ;
ui_ - > new_folder - > setIconSize ( QSize ( iconsize , iconsize ) ) ;
ui_ - > remove - > setIconSize ( QSize ( iconsize , iconsize ) ) ;
ui_ - > save_playlist - > setIconSize ( QSize ( iconsize , iconsize ) ) ;
}
2018-02-27 18:06:05 +01:00
void PlaylistListContainer : : showEvent ( QShowEvent * e ) {
// Loading icons is expensive so only do it when the view is first opened
2020-08-30 01:57:21 +02:00
if ( ! loaded_icons_ ) {
loaded_icons_ = true ;
2018-02-27 18:06:05 +01:00
2020-08-30 01:57:21 +02:00
action_new_folder_ - > setIcon ( IconLoader : : Load ( " folder-new " ) ) ;
action_remove_ - > setIcon ( IconLoader : : Load ( " edit-delete " ) ) ;
action_save_playlist_ - > setIcon ( IconLoader : : Load ( " document-save " ) ) ;
2020-10-08 19:19:39 +02:00
# ifndef Q_OS_WIN
2020-08-30 01:57:21 +02:00
action_copy_to_device_ - > setIcon ( IconLoader : : Load ( " device " ) ) ;
2020-10-08 19:19:39 +02:00
# endif
2018-02-27 18:06:05 +01:00
2020-08-30 01:57:21 +02:00
model_ - > SetIcons ( IconLoader : : Load ( " view-media-playlist " ) , IconLoader : : Load ( " folder " ) ) ;
2018-02-27 18:06:05 +01:00
2020-08-30 01:57:21 +02:00
// Apply these icons to items that have already been created.
RecursivelySetIcons ( model_ - > invisibleRootItem ( ) ) ;
}
ui_ - > remove - > setEnabled ( ui_ - > tree - > ItemsSelected ( ) ) ;
ui_ - > save_playlist - > setEnabled ( ui_ - > tree - > ItemsSelected ( ) ) ;
2018-02-27 18:06:05 +01:00
QWidget : : showEvent ( e ) ;
}
void PlaylistListContainer : : RecursivelySetIcons ( QStandardItem * parent ) const {
for ( int i = 0 ; i < parent - > rowCount ( ) ; + + i ) {
QStandardItem * child = parent - > child ( i ) ;
switch ( child - > data ( PlaylistListModel : : Role_Type ) . toInt ( ) ) {
case PlaylistListModel : : Type_Folder :
child - > setIcon ( model_ - > folder_icon ( ) ) ;
RecursivelySetIcons ( child ) ;
break ;
case PlaylistListModel : : Type_Playlist :
child - > setIcon ( model_ - > playlist_icon ( ) ) ;
break ;
}
}
}
void PlaylistListContainer : : NewFolderClicked ( ) {
QString name = QInputDialog : : getText ( this , tr ( " New folder " ) , tr ( " Enter the name of the folder " ) ) ;
if ( name . isEmpty ( ) ) {
return ;
}
name . replace ( " / " , " " ) ;
model_ - > invisibleRootItem ( ) - > appendRow ( model_ - > NewFolder ( name ) ) ;
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : AddPlaylist ( const int id , const QString & name , const bool favorite ) {
2018-02-27 18:06:05 +01:00
if ( ! favorite ) {
return ;
}
if ( model_ - > PlaylistById ( id ) ) {
2018-05-01 00:41:33 +02:00
// We know about this playlist already - it was probably one of the open ones that was loaded on startup.
2018-02-27 18:06:05 +01:00
return ;
}
const QString & ui_path = app_ - > playlist_manager ( ) - > playlist ( id ) - > ui_path ( ) ;
QStandardItem * playlist_item = model_ - > NewPlaylist ( name , id ) ;
QStandardItem * parent_folder = model_ - > FolderByPath ( ui_path ) ;
parent_folder - > appendRow ( playlist_item ) ;
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : PlaylistRenamed ( const int id , const QString & new_name ) {
2018-02-27 18:06:05 +01:00
QStandardItem * item = model_ - > PlaylistById ( id ) ;
if ( ! item ) {
return ;
}
item - > setText ( new_name ) ;
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : RemovePlaylist ( const int id ) {
2018-02-27 18:06:05 +01:00
QStandardItem * item = model_ - > PlaylistById ( id ) ;
if ( item ) {
QStandardItem * parent = item - > parent ( ) ;
if ( ! parent ) {
parent = model_ - > invisibleRootItem ( ) ;
}
parent - > removeRow ( item - > row ( ) ) ;
}
}
void PlaylistListContainer : : SavePlaylist ( ) {
2020-10-01 19:49:06 +02:00
const QModelIndex proxy_idx = ui_ - > tree - > currentIndex ( ) ;
if ( ! proxy_idx . isValid ( ) ) return ;
const QModelIndex idx = proxy_ - > mapToSource ( proxy_idx ) ;
if ( ! idx . isValid ( ) ) return ;
2018-02-27 18:06:05 +01:00
// Is it a playlist?
2020-10-01 19:49:06 +02:00
if ( idx . data ( PlaylistListModel : : Role_Type ) . toInt ( ) = = PlaylistListModel : : Type_Playlist ) {
const int playlist_id = idx . data ( PlaylistListModel : : Role_PlaylistId ) . toInt ( ) ;
2018-02-27 18:06:05 +01:00
QStandardItem * item = model_ - > PlaylistById ( playlist_id ) ;
QString playlist_name = item ? item - > text ( ) : tr ( " Playlist " ) ;
app_ - > playlist_manager ( ) - > SaveWithUI ( playlist_id , playlist_name ) ;
}
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : PlaylistFavoriteStateChanged ( const int id , const bool favorite ) {
2018-02-27 18:06:05 +01:00
if ( favorite ) {
const QString & name = app_ - > playlist_manager ( ) - > GetPlaylistName ( id ) ;
AddPlaylist ( id , name , favorite ) ;
}
else {
RemovePlaylist ( id ) ;
}
}
void PlaylistListContainer : : ActiveChanged ( Playlist * new_playlist ) {
const int new_id = new_playlist - > id ( ) ;
if ( new_id ! = active_playlist_id_ ) {
UpdateActiveIcon ( active_playlist_id_ , QIcon ( ) ) ;
}
active_playlist_id_ = new_id ;
}
void PlaylistListContainer : : CurrentChanged ( Playlist * new_playlist ) {
if ( ! new_playlist ) {
return ;
}
// Focus this playlist in the tree
QStandardItem * item = model_ - > PlaylistById ( new_playlist - > id ( ) ) ;
if ( ! item ) {
return ;
}
2020-10-01 19:49:06 +02:00
QModelIndex idx = proxy_ - > mapFromSource ( item - > index ( ) ) ;
ui_ - > tree - > selectionModel ( ) - > setCurrentIndex ( idx , QItemSelectionModel : : ClearAndSelect ) ;
ui_ - > tree - > scrollTo ( idx ) ;
2018-02-27 18:06:05 +01:00
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : PlaylistPathChanged ( const int id , const QString & new_path ) {
2018-02-27 18:06:05 +01:00
// Update the path in the database
app_ - > playlist_backend ( ) - > SetPlaylistUiPath ( id , new_path ) ;
Playlist * playlist = app_ - > playlist_manager ( ) - > playlist ( id ) ;
// Check the playlist exists (if it's not opened it's not in the manager)
if ( playlist ) {
playlist - > set_ui_path ( new_path ) ;
}
}
2020-08-06 16:00:03 +02:00
void PlaylistListContainer : : ItemsSelectedChanged ( const bool selected ) {
ui_ - > remove - > setEnabled ( selected ) ;
ui_ - > save_playlist - > setEnabled ( selected ) ;
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : ItemDoubleClicked ( const QModelIndex proxy_idx ) {
2018-02-27 18:06:05 +01:00
2020-10-01 19:49:06 +02:00
const QModelIndex idx = proxy_ - > mapToSource ( proxy_idx ) ;
if ( ! idx . isValid ( ) ) return ;
2018-02-27 18:06:05 +01:00
// Is it a playlist?
2020-10-01 19:49:06 +02:00
if ( idx . data ( PlaylistListModel : : Role_Type ) . toInt ( ) = = PlaylistListModel : : Type_Playlist ) {
app_ - > playlist_manager ( ) - > SetCurrentOrOpen ( idx . data ( PlaylistListModel : : Role_PlaylistId ) . toInt ( ) ) ;
2018-02-27 18:06:05 +01:00
}
}
2020-08-06 16:00:03 +02:00
void PlaylistListContainer : : CopyToDevice ( ) {
2020-10-01 19:49:06 +02:00
2019-08-07 17:13:40 +02:00
# ifndef Q_OS_WIN
2020-10-01 19:49:06 +02:00
const QModelIndex proxy_idx = ui_ - > tree - > currentIndex ( ) ;
if ( ! proxy_idx . isValid ( ) ) return ;
const QModelIndex idx = proxy_ - > mapToSource ( proxy_idx ) ;
if ( ! idx . isValid ( ) ) return ;
2019-08-07 17:13:40 +02:00
// Is it a playlist?
2020-10-01 19:49:06 +02:00
if ( idx . data ( PlaylistListModel : : Role_Type ) . toInt ( ) = = PlaylistListModel : : Type_Playlist ) {
const int playlist_id = idx . data ( PlaylistListModel : : Role_PlaylistId ) . toInt ( ) ;
2019-08-07 17:13:40 +02:00
2020-10-08 19:19:39 +02:00
Playlist * playlist = app_ - > playlist_manager ( ) - > playlist ( playlist_id ) ;
if ( ! playlist ) {
QMessageBox : : critical ( this , tr ( " Copy to device " ) , tr ( " Playlist must be open first. " ) ) ;
return ;
}
2019-08-07 17:13:40 +02:00
QStandardItem * item = model_ - > PlaylistById ( playlist_id ) ;
QString playlist_name = item ? item - > text ( ) : tr ( " Playlist " ) ;
2020-10-08 19:19:39 +02:00
// Reuse the organize dialog, but set the detail about the playlist name
if ( ! organize_dialog_ ) {
2020-10-27 17:50:16 +01:00
organize_dialog_ . reset ( new OrganizeDialog ( app_ - > task_manager ( ) , nullptr , this ) ) ;
2020-10-08 19:19:39 +02:00
}
organize_dialog_ - > SetDestinationModel ( app_ - > device_manager ( ) - > connected_devices_model ( ) , true ) ;
organize_dialog_ - > SetCopy ( true ) ;
organize_dialog_ - > SetPlaylist ( playlist_name ) ;
organize_dialog_ - > SetSongs ( playlist - > GetAllSongs ( ) ) ;
2020-08-04 21:18:14 +02:00
organize_dialog_ - > show ( ) ;
2019-08-07 17:13:40 +02:00
}
# endif
2020-10-08 19:19:39 +02:00
2019-08-07 17:13:40 +02:00
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : Delete ( ) {
if ( ui_ - > tree - > selectionModel ( ) - > selectedRows ( ) . count ( ) = = 0 ) return ;
2018-02-27 18:06:05 +01:00
QSet < int > ids ;
QList < QPersistentModelIndex > folders_to_delete ;
2020-11-13 20:34:29 +01:00
for ( const QModelIndex & proxy_index : ui_ - > tree - > selectionModel ( ) - > selectedRows ( ) ) {
2020-10-01 19:49:06 +02:00
const QModelIndex idx = proxy_ - > mapToSource ( proxy_index ) ;
2018-02-27 18:06:05 +01:00
// Is it a playlist?
2020-10-01 19:49:06 +02:00
switch ( idx . data ( PlaylistListModel : : Role_Type ) . toInt ( ) ) {
2018-02-27 18:06:05 +01:00
case PlaylistListModel : : Type_Playlist :
2020-10-01 19:49:06 +02:00
ids < < idx . data ( PlaylistListModel : : Role_PlaylistId ) . toInt ( ) ;
2018-02-27 18:06:05 +01:00
break ;
case PlaylistListModel : : Type_Folder :
// Find all the playlists inside.
2020-10-01 19:49:06 +02:00
RecursivelyFindPlaylists ( idx , & ids ) ;
folders_to_delete < < idx ;
2018-02-27 18:06:05 +01:00
break ;
}
}
// Make sure the user really wants to unfavorite all these playlists.
if ( ids . count ( ) > 1 ) {
const int button = QMessageBox : : question ( this , tr ( " Remove playlists " ) , tr ( " You are about to remove %1 playlists from your favorites, are you sure? " ) . arg ( ids . count ( ) ) , QMessageBox : : Yes , QMessageBox : : Cancel ) ;
if ( button ! = QMessageBox : : Yes ) {
return ;
}
}
// Unfavorite the playlists
2021-03-21 04:47:11 +01:00
for ( const int id : qAsConst ( ids ) ) {
2018-02-27 18:06:05 +01:00
app_ - > playlist_manager ( ) - > Favorite ( id , false ) ;
}
// Delete the top-level folders.
2020-10-01 19:49:06 +02:00
for ( const QPersistentModelIndex & idx : folders_to_delete ) {
if ( idx . isValid ( ) ) {
model_ - > removeRow ( idx . row ( ) , idx . parent ( ) ) ;
2018-02-27 18:06:05 +01:00
}
}
}
void PlaylistListContainer : : RecursivelyFindPlaylists ( const QModelIndex & parent , QSet < int > * ids ) const {
switch ( parent . data ( PlaylistListModel : : Role_Type ) . toInt ( ) ) {
case PlaylistListModel : : Type_Playlist :
ids - > insert ( parent . data ( PlaylistListModel : : Role_PlaylistId ) . toInt ( ) ) ;
break ;
case PlaylistListModel : : Type_Folder :
for ( int i = 0 ; i < parent . model ( ) - > rowCount ( parent ) ; + + i ) {
2020-01-05 23:26:07 +01:00
RecursivelyFindPlaylists ( parent . model ( ) - > index ( i , 0 , parent ) , ids ) ;
2018-02-27 18:06:05 +01:00
}
break ;
}
}
void PlaylistListContainer : : contextMenuEvent ( QContextMenuEvent * e ) {
if ( ! menu_ ) {
menu_ = new QMenu ( this ) ;
menu_ - > addAction ( action_new_folder_ ) ;
menu_ - > addAction ( action_remove_ ) ;
menu_ - > addSeparator ( ) ;
menu_ - > addAction ( action_save_playlist_ ) ;
2020-10-08 19:19:39 +02:00
# ifndef Q_OS_WIN
2019-08-07 17:13:40 +02:00
menu_ - > addSeparator ( ) ;
menu_ - > addAction ( action_copy_to_device_ ) ;
2020-10-08 19:19:39 +02:00
# endif
2018-02-27 18:06:05 +01:00
}
2020-10-01 19:49:06 +02:00
action_remove_ - > setVisible ( ui_ - > tree - > ItemsSelected ( ) ) ;
action_save_playlist_ - > setVisible ( ui_ - > tree - > ItemsSelected ( ) ) ;
2020-10-08 19:19:39 +02:00
# ifndef Q_OS_WIN
2020-10-01 19:49:06 +02:00
action_copy_to_device_ - > setVisible ( ui_ - > tree - > ItemsSelected ( ) ) ;
2020-10-08 19:19:39 +02:00
# endif
2020-10-01 19:49:06 +02:00
2018-02-27 18:06:05 +01:00
menu_ - > popup ( e - > globalPos ( ) ) ;
}
void PlaylistListContainer : : ActivePlaying ( ) {
if ( padded_play_icon_ . isNull ( ) ) {
2018-08-29 21:42:24 +02:00
QPixmap pixmap ( " :/pictures/tiny-play.png " ) ;
2018-02-27 18:06:05 +01:00
QPixmap new_pixmap ( QSize ( pixmap . height ( ) , pixmap . height ( ) ) ) ;
new_pixmap . fill ( Qt : : transparent ) ;
QPainter p ( & new_pixmap ) ;
p . drawPixmap ( ( new_pixmap . width ( ) - pixmap . width ( ) ) / 2 , 0 , pixmap . width ( ) , pixmap . height ( ) , pixmap ) ;
p . end ( ) ;
padded_play_icon_ . addPixmap ( new_pixmap ) ;
}
UpdateActiveIcon ( active_playlist_id_ , padded_play_icon_ ) ;
}
void PlaylistListContainer : : ActivePaused ( ) {
2018-08-29 21:42:24 +02:00
UpdateActiveIcon ( active_playlist_id_ , QIcon ( " :/pictures/tiny-pause.png " ) ) ;
2018-02-27 18:06:05 +01:00
}
void PlaylistListContainer : : ActiveStopped ( ) {
UpdateActiveIcon ( active_playlist_id_ , QIcon ( ) ) ;
}
2020-10-01 19:49:06 +02:00
void PlaylistListContainer : : UpdateActiveIcon ( const int id , const QIcon & icon ) {
2018-02-27 18:06:05 +01:00
if ( id = = - 1 ) {
return ;
}
QStandardItem * item = model_ - > PlaylistById ( id ) ;
if ( ! item ) {
return ;
}
if ( icon . isNull ( ) ) {
item - > setIcon ( model_ - > playlist_icon ( ) ) ;
}
else {
item - > setIcon ( icon ) ;
}
}