]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/playlist_model.cpp
CodingStyle fixes, use ; when using macros and do not write it in the macro definition.
[vlc] / modules / gui / qt4 / playlist_model.cpp
index 01d097d213fb2d69926530e186959c2ca21b964f..3c1932917640ac02e2627699083c23e73b2c07b5 100644 (file)
@@ -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 <assert.h>
 #include <QIcon>
 #include <vlc_intf_strings.h>
 
 #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];
 
@@ -68,13 +58,12 @@ static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
  *      Duration
  */
 
-void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
+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;
 
-
     if( parentItem == NULL )
     {
         i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" );
@@ -82,7 +71,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
     } else {
         i_showflags = parentItem->i_showflags;
         //Add empty string and update() handles data appending
-        strings.append( qtr("") ); 
+        strings.append( "" );
     }
 }
 
@@ -92,49 +81,49 @@ void PLItem::updateview( void )
 
     if( model->i_depth == 1 )  //left window for playlist etc.
     {
-        strings.append( qtr("") );   
+        strings.append( "" );
         return;
     }
 
-    for( int i_index=1; i_index <= VLC_META_ENGINE_MB_TRM_ID; i_index = i_index*2 )
+    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;
+            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)
+PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
 {
     init( _i_id, _i_input_id, parent, m );
 }
@@ -146,7 +135,7 @@ PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
 
 PLItem::~PLItem()
 {
-    qDeleteAll(children);
+    qDeleteAll( children );
     children.clear();
 }
 
@@ -172,7 +161,7 @@ void PLItem::remove( PLItem *removed )
 int PLItem::row() const
 {
     if( parentItem )
-        return parentItem->children.indexOf(const_cast<PLItem*>(this));
+        return parentItem->children.indexOf( const_cast<PLItem*>(this) );
     return 0;
 }
 
@@ -184,67 +173,76 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
     type = p_item->p_input->i_type;
     current = iscurrent;
 
-    if( current && input_item_GetArtURL( p_item ) &&
-        !strncmp( input_item_GetArtURL( p_item ), "file://", 7 ) )
-        model->sendArt( qfu( input_item_GetArtURL( p_item ) ) );
+    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( p_item->p_input->psz_name );
+        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 );
 
-#define ADD_META( item, meta ) {             \
-      strings.append( qfu( input_item_Get ## meta ( item->p_input ) ) );   \
-
-    for( int i_index=1; i_index <= VLC_META_ENGINE_MB_TRM_ID; i_index = i_index * 2 )
+    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:
-                    if( input_item_GetTitle( p_item->p_input ) )
-                    {
-                        ADD_META( p_item, Title );
-                    } else {
-                        strings.append( qfu( p_item->p_input->psz_name ) );
-                    }
-                    break;
-                case VLC_META_ENGINE_DESCRIPTION:
-                    ADD_META( p_item, Description );
-                    break;
-                case VLC_META_ENGINE_DURATION:
-                    secstotimestr( psz_duration, p_item->p_input->i_duration / 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;
+            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
-
 }
 
 /*************************************************************************
@@ -252,8 +250,8 @@ 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)
-                                    : QAbstractItemModel(parent)
+                    playlist_item_t * p_root, int _i_depth, QObject *parent )
+                                    : QAbstractItemModel( parent )
 {
     i_depth = _i_depth;
     assert( i_depth == 1 || i_depth == -1 );
@@ -265,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();
@@ -294,9 +290,9 @@ Qt::DropActions PLModel::supportedDropActions() const
     return Qt::CopyAction;
 }
 
-Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
+Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
 {
-    Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
+    Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
     if( index.isValid() )
         return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
     else
@@ -310,26 +306,26 @@ QStringList PLModel::mimeTypes() const
     return types;
 }
 
-QMimeData *PLModel::mimeData(const QModelIndexList &indexes) const
+QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
 {
     QMimeData *mimeData = new QMimeData();
     QByteArray encodedData;
-    QDataStream stream(&encodedData, QIODevice::WriteOnly);
+    QDataStream stream( &encodedData, QIODevice::WriteOnly );
 
-    foreach (QModelIndex index, indexes) {
-        if (index.isValid() && index.column() == 0 )
-            stream << itemId(index);
+    foreach( QModelIndex index, indexes ) {
+        ifindex.isValid() && index.column() == 0 )
+            stream << itemId( index );
     }
-    mimeData->setData("vlc/playlist-item-id", encodedData);
+    mimeData->setData( "vlc/playlist-item-id", encodedData );
     return mimeData;
 }
 
-bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
-                           int row, int column, const QModelIndex &target)
+bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
+                           int row, int column, const QModelIndex &target )
 {
-    if ( data->hasFormat("vlc/playlist-item-id") )
+    if( data->hasFormat( "vlc/playlist-item-id" ) )
     {
-        if (action == Qt::IgnoreAction)
+        if( action == Qt::IgnoreAction )
             return true;
 
         PLItem *targetItem;
@@ -338,11 +334,11 @@ bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
         else
             targetItem = rootItem;
 
-        QByteArray encodedData = data->data("vlc/playlist-item-id");
-        QDataStream stream(&encodedData, QIODevice::ReadOnly);
+        QByteArray encodedData = data->data( "vlc/playlist-item-id" );
+        QDataStream stream( &encodedData, QIODevice::ReadOnly );
 
         PLItem *newParentItem;
-        while (!stream.atEnd())
+        while( !stream.atEnd() )
         {
             int i;
             int srcId;
@@ -460,9 +456,9 @@ void PLModel::activateItem( playlist_item_t *p_item )
 }
 
 /****************** Base model mandatory implementations *****************/
-QVariant PLModel::data(const QModelIndex &index, int role) const
+QVariant PLModel::data( const QModelIndex &index, int role ) const
 {
-    if(!index.isValid() ) return QVariant();
+    if( !index.isValid() ) return QVariant();
     PLItem *item = static_cast<PLItem*>(index.internalPointer());
     if( role == Qt::DisplayRole )
     {
@@ -496,25 +492,25 @@ int PLModel::itemId( const QModelIndex &index ) const
 }
 
 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
-                              int role) const
+                              int role ) const
 {
     if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
             return QVariant( rootItem->columnString( section ) );
     return QVariant();
 }
 
-QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
+QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
                   const
 {
     PLItem *parentItem;
-    if (!parent.isValid())
+    if( !parent.isValid() )
         parentItem = rootItem;
     else
         parentItem = static_cast<PLItem*>(parent.internalPointer());
 
-    PLItem *childItem = parentItem->child(row);
-    if (childItem)
-        return createIndex(row, column, childItem);
+    PLItem *childItem = parentItem->child( row );
+    if( childItem )
+        return createIndex( row, column, childItem );
     else
         return QModelIndex();
 }
@@ -530,12 +526,12 @@ QModelIndex PLModel::index( PLItem *item, int column ) const
     return QModelIndex();
 }
 
-QModelIndex PLModel::parent(const QModelIndex &index) const
+QModelIndex PLModel::parent( const QModelIndex &index ) const
 {
     if( !index.isValid() ) return QModelIndex();
 
     PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
-    if( !childItem ) { msg_Err( p_playlist, "NULL CHILD \n" ); return QModelIndex(); }
+    if( !childItem ) { msg_Err( p_playlist, "NULL CHILD" ); return QModelIndex(); }
     PLItem *parentItem = childItem->parent();
     if( !parentItem || parentItem == rootItem ) return QModelIndex();
     if( ! parentItem->parentItem )
@@ -553,16 +549,16 @@ int PLModel::columnCount( const QModelIndex &i) const
     return rootItem->strings.count();
 }
 
-int PLModel::childrenCount(const QModelIndex &parent) const
+int PLModel::childrenCount( const QModelIndex &parent ) const
 {
     return rowCount( parent );
 }
 
-int PLModel::rowCount(const QModelIndex &parent) const
+int PLModel::rowCount( const QModelIndex &parent ) const
 {
     PLItem *parentItem;
 
-    if (!parent.isValid())
+    if( !parent.isValid() )
         parentItem = rootItem;
     else
         parentItem = static_cast<PLItem*>(parent.internalPointer());
@@ -864,7 +860,7 @@ void PLModel::doDelete( QModelIndexList selected )
     }
 }
 
-void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
+void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
 {
     for( int i = children.size() - 1; i >= 0 ; i-- )
     {
@@ -917,7 +913,7 @@ void PLModel::sort( int column, Qt::SortOrder order )
                                         order == Qt::AscendingOrder ?
                                             ORDER_NORMAL : ORDER_REVERSE );
     }
-    PL_UNLOCK
+    PL_UNLOCK;
     rebuild();
 }
 
@@ -964,32 +960,10 @@ 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();
-
-        ContextUpdateMapper = new QSignalMapper(this);
-
-        QMenu *selectColMenu = new QMenu( qtr("Show columns") );
-
-#define ADD_META_ACTION( meta ) { \
-   QAction* option = selectColMenu->addAction( qfu(VLC_META_##meta) );     \
-   option->setCheckable( true );                                           \
-   option->setChecked( rootItem->i_showflags & VLC_META_ENGINE_##meta );   \
-   ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta );      \
-   CONNECT( option, triggered(), ContextUpdateMapper, map() );             \
-   }
-        CONNECT(ContextUpdateMapper, mapped( int ), this, viewchanged( int ) );
-
-        ADD_META_ACTION( TITLE );
-        ADD_META_ACTION( ARTIST );
-        ADD_META_ACTION( DURATION );
-        ADD_META_ACTION( COLLECTION );
-        ADD_META_ACTION( GENRE );
-        ADD_META_ACTION( SEQ_NUM );
-        ADD_META_ACTION( RATING );
-        ADD_META_ACTION( DESCRIPTION );
-
-#undef ADD_META_ACTION
-        menu->addMenu( selectColMenu );
+        menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
+#endif
         menu->popup( point );
     }
     else
@@ -1004,32 +978,32 @@ void PLModel::viewchanged( int meta )
        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;
+       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() );
@@ -1072,23 +1046,32 @@ void PLModel::popupPlay()
 void PLModel::popupInfo()
 {
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                    i_popup_item,VLC_TRUE );
+                                                    i_popup_item,
+                                                    VLC_TRUE );
     if( p_item )
     {
-        MediaInfoDialog *mid = new MediaInfoDialog( p_intf );
-        mid->setInput( p_item->p_input );
+        MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
         mid->show();
     }
 }
 
 void PLModel::popupStream()
 {
-    fprintf( stderr, "Stream not implemented\n" );
+     msg_Err( p_playlist, "Stream not implemented" );
 }
+
 void PLModel::popupSave()
 {
-    fprintf( stderr, "Save not implemented\n" );
+     msg_Err( p_playlist, "Save not implemented" );
+}
+
+#ifdef WIN32
+#include <shellapi.h>
+void PLModel::popupExplore()
+{
+    ShellExecuteW(NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL );
 }
+#endif
 
 /**********************************************************************
  * Playlist callbacks