X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fplaylist_model.cpp;h=fcc00c87368340fb8d2b5ac527b08b4c821796a2;hb=00e3654a317f56cf2c89d20878348b6b6086bd38;hp=13e7671e70e4554d5376ee51762f16cc504c9ac7;hpb=0c5a114ac8e0f5bcb610b90bc23af36e5f7879f7;p=vlc diff --git a/modules/gui/qt4/playlist_model.cpp b/modules/gui/qt4/playlist_model.cpp index 13e7671e70..fcc00c8736 100644 --- a/modules/gui/qt4/playlist_model.cpp +++ b/modules/gui/qt4/playlist_model.cpp @@ -20,7 +20,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#define PLI_NAME( p ) p ? p->p_input->psz_name : "null" #include #include @@ -34,15 +33,6 @@ #include #include "pixmaps/type_unknown.xpm" -#include "pixmaps/type_afile.xpm" -#include "pixmaps/type_vfile.xpm" -#include "pixmaps/type_net.xpm" -#include "pixmaps/type_card.xpm" -#include "pixmaps/type_disc.xpm" -#include "pixmaps/type_cdda.xpm" -#include "pixmaps/type_directory.xpm" -#include "pixmaps/type_playlist.xpm" -#include "pixmaps/type_node.xpm" QIcon PLModel::icons[ITEM_TYPE_NUMBER]; @@ -73,12 +63,66 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) parentItem = parent; i_id = _i_id; i_input_id = _i_input_id; model = m; - strings.append( "" ); - strings.append( "" ); - strings.append( "" ); - strings.append( "" ); + + if( parentItem == NULL ) + { + i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" ); + updateview(); + } else { + i_showflags = parentItem->i_showflags; + //Add empty string and update() handles data appending + strings.append( "" ); + } } +void PLItem::updateview( void ) +{ + strings.clear(); + + if( model->i_depth == 1 ) //left window for playlist etc. + { + strings.append( "" ); + return; + } + + for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index*2 ) + { + if( i_showflags & i_index ) + { + switch( i_index ) + { + case VLC_META_ENGINE_ARTIST: + strings.append( qtr( VLC_META_ARTIST ) ); + break; + case VLC_META_ENGINE_TITLE: + strings.append( qtr( VLC_META_TITLE ) ); + break; + case VLC_META_ENGINE_DESCRIPTION: + strings.append( qtr( VLC_META_DESCRIPTION ) ); + break; + case VLC_META_ENGINE_DURATION: + strings.append( qtr( "Duration" ) ); + break; + case VLC_META_ENGINE_GENRE: + strings.append( qtr( VLC_META_GENRE ) ); + break; + case VLC_META_ENGINE_COLLECTION: + strings.append( qtr( VLC_META_COLLECTION ) ); + break; + case VLC_META_ENGINE_SEQ_NUM: + strings.append( qtr( VLC_META_SEQ_NUM ) ); + break; + case VLC_META_ENGINE_RATING: + strings.append( qtr( VLC_META_RATING ) ); + break; + default: + break; + } + } + } +} + + PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) { init( _i_id, _i_input_id, parent, m ); @@ -125,22 +169,80 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent ) { char psz_duration[MSTRTIME_MAX_SIZE]; assert( p_item->p_input->i_id == i_input_id ); - strings[0] = QString::fromUtf8( p_item->p_input->psz_name ); - if( p_item->p_input->p_meta ) - { - strings[1] = QString::fromUtf8( p_item->p_input->p_meta->psz_artist ); - } - secstotimestr( psz_duration, p_item->p_input->i_duration / 1000000 ); - strings[2] = QString( psz_duration ); + type = p_item->p_input->i_type; current = iscurrent; - if( current && p_item->p_input->p_meta && - p_item->p_input->p_meta->psz_arturl && - !strncmp( p_item->p_input->p_meta->psz_arturl, "file://", 7 ) ) - model->sendArt( qfu( p_item->p_input->p_meta->psz_arturl ) ); + char *psz_arturl = input_item_GetArtURL( p_item->p_input ); + if( ( current && psz_arturl ) && + !strncmp( psz_arturl, "file://", 7 ) ) + model->sendArt( qfu( psz_arturl ) ) ; else if( current ) model->removeArt(); + free( psz_arturl ); + + strings.clear(); + + if( model->i_depth == 1 ) //left window for playlist etc. + { + strings.append( qfu( p_item->p_input->psz_name ) ); + return; + } + + char *psz_meta; +#define ADD_META( item, meta ) \ + psz_meta = input_item_Get ## meta ( item->p_input ); \ + strings.append( qfu( psz_meta ) ); \ + free( psz_meta ); + + for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index * 2 ) + { + if( parentItem->i_showflags & i_index ) + { + switch( i_index ) + { + case VLC_META_ENGINE_ARTIST: + ADD_META( p_item, Artist ); + break; + case VLC_META_ENGINE_TITLE: + char *psz_title, *psz_name; + psz_title = input_item_GetTitle( p_item->p_input ); + psz_name = input_item_GetName( p_item->p_input ); + if( psz_title ) + { + ADD_META( p_item, Title ); + } else { + strings.append( qfu( psz_name ) ); + } + free( psz_title ); + free( psz_name ); + break; + case VLC_META_ENGINE_DESCRIPTION: + ADD_META( p_item, Description ); + break; + case VLC_META_ENGINE_DURATION: + secstotimestr( psz_duration, + input_item_GetDuration( p_item->p_input ) / 1000000 ); + strings.append( QString( psz_duration ) ); + break; + case VLC_META_ENGINE_GENRE: + ADD_META( p_item, Genre ); + break; + case VLC_META_ENGINE_COLLECTION: + ADD_META( p_item, Album ); + break; + case VLC_META_ENGINE_SEQ_NUM: + ADD_META( p_item, TrackNum ); + break; + case VLC_META_ENGINE_RATING: + ADD_META( p_item, Rating ); + default: + break; + } + } + + } +#undef ADD_META } /************************************************************************* @@ -148,7 +250,7 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent ) *************************************************************************/ PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf, - playlist_item_t * p_root, int _i_depth, QObject *parent) + playlist_item_t * p_root, int _i_depth, QObject *parent) : QAbstractItemModel(parent) { i_depth = _i_depth; @@ -161,24 +263,22 @@ PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf, i_cached_input_id = -1; i_popup_item = i_popup_parent = -1; -#define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( type_##x##_xpm ) ); - ADD_ICON( UNKNOWN , unknown ); - ADD_ICON( AFILE,afile ); - ADD_ICON( VFILE, vfile ); - ADD_ICON( DIRECTORY, directory ); - ADD_ICON( DISC, disc ); - ADD_ICON( CDDA, cdda ); - ADD_ICON( CARD, card ); - ADD_ICON( NET, net ); - ADD_ICON( PLAYLIST, playlist ); - ADD_ICON( NODE, node ); +#define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) ); + ADD_ICON( UNKNOWN , type_unknown_xpm ); + ADD_ICON( FILE, ":/pixmaps/type_file.png" ); + ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" ); + ADD_ICON( DISC, ":/pixmaps/disc_16px.png" ); + ADD_ICON( CDDA, ":/pixmaps/cdda_16px.png" ); + ADD_ICON( CARD, ":/pixmaps/capture-card_16px.png" ); + ADD_ICON( NET, ":/pixmaps/type_net.png" ); + ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" ); + ADD_ICON( NODE, ":/pixmaps/type_node.png" ); rootItem = NULL; addCallbacks(); rebuild( p_root ); } - PLModel::~PLModel() { delCallbacks(); @@ -446,8 +546,7 @@ QModelIndex PLModel::parent(const QModelIndex &index) const int PLModel::columnCount( const QModelIndex &i) const { - if( i_depth == 1 ) return 1; - return 3; + return rootItem->strings.count(); } int PLModel::childrenCount(const QModelIndex &parent) const @@ -648,19 +747,19 @@ void PLModel::rebuild( playlist_item_t *p_root ) /* Clear the tree */ if( rootItem ) { - beginRemoveRows( index( rootItem, 0 ), 0, - rootItem->children.size() -1 ); - qDeleteAll( rootItem->children ); - rootItem->children.clear(); - endRemoveRows(); + if( rootItem->children.size() ) + { + beginRemoveRows( index( rootItem, 0 ), 0, + rootItem->children.size() -1 ); + qDeleteAll( rootItem->children ); + rootItem->children.clear(); + endRemoveRows(); + } } if( p_root ) { //if( rootItem ) delete rootItem; rootItem = new PLItem( p_root, NULL, this ); - rootItem->strings[0] = qtr("Name"); - rootItem->strings[1] = qtr("Artist"); - rootItem->strings[2] = qtr("Duration"); } assert( rootItem ); /* Recreate from root */ @@ -861,12 +960,74 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) ); menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) ); } +#ifdef WIN32 + menu->addSeparator(); + menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) ); +#endif menu->popup( point ); } else PL_UNLOCK; } + +void PLModel::viewchanged( int meta ) +{ + if( rootItem ) + { + int index=0; + switch( meta ) + { + case VLC_META_ENGINE_TITLE: + index=0; + break; + case VLC_META_ENGINE_DURATION: + index=1; + break; + case VLC_META_ENGINE_ARTIST: + index=2; + break; + case VLC_META_ENGINE_GENRE: + index=3; + break; + case VLC_META_ENGINE_COPYRIGHT: + index=4; + break; + case VLC_META_ENGINE_COLLECTION: + index=5; + break; + case VLC_META_ENGINE_SEQ_NUM: + index=6; + break; + case VLC_META_ENGINE_DESCRIPTION: + index=7; + break; + default: + break; + } + emit layoutAboutToBeChanged(); + index = __MIN( index , rootItem->strings.count() ); + QModelIndex parent = createIndex( 0, 0, rootItem ); + if( rootItem->i_showflags & meta ) + { + beginRemoveColumns( parent , index, index+1 ); + rootItem->i_showflags &= ~( meta ); + rootItem->updateview(); + endRemoveColumns(); + } + else + { + beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 ); + rootItem->i_showflags |= meta; + rootItem->updateview(); + endInsertColumns(); + } + rebuild(); + config_PutInt( p_intf, "qt-pl-showflags", rootItem->i_showflags ); + config_SaveConfigFile( p_intf, NULL ); + } +} + void PLModel::popupDel() { doDelete( current_selection ); @@ -903,6 +1064,14 @@ void PLModel::popupSave() fprintf( stderr, "Save not implemented\n" ); } +#ifdef WIN32 +#include +void PLModel::popupExplore() +{ + ShellExecuteW(NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL ); +} +#endif + /********************************************************************** * Playlist callbacks **********************************************************************/