]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_item.cpp
qt4: remove b_is_node and use childCount() > 0 instead in playlist_model
[vlc] / modules / gui / qt4 / components / playlist / playlist_item.cpp
index 2c9fd9a4d52f5e28f0fb3511f58972c2c2ec4264..6c0c3a3f1010051b75c83abd0f67fd680ca24401 100644 (file)
 #include "components/playlist/playlist_model.hpp"
 #include <vlc_intf_strings.h>
 
-#include "pixmaps/type_unknown.xpm"
-
 #include <QSettings>
 
+#include "sorting.h"
+
 /*************************************************************************
  * Playlist item implementation
  *************************************************************************/
 */
 
 
-void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
+void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent, PLModel *m, QSettings *settings )
 {
     parentItem = parent;          /* Can be NULL, but only for the rootItem */
-    i_id       = _i_id;           /* Playlist item specific id */
-    i_input_id = _i_input_id;     /* Identifier of the input */
+    i_id       = _playlist_item->i_id;           /* Playlist item specific id */
     model      = m;               /* PLModel (QAbsmodel) */
     i_type     = -1;              /* Item type - Avoid segfault */
-    b_current  = false;           /* Is the item the current Item or not */
+    p_input    = _playlist_item->p_input;
+    vlc_gc_incref( p_input );
 
     assert( model );              /* We need a model */
 
@@ -64,88 +64,45 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
     {
         if( model->i_depth == DEPTH_SEL )  /* Selector Panel */
         {
-            item_col_strings.append( "" );
+            i_showflags = 0;
         }
         else
         {
-            QSettings settings( "vlc", "vlc-qt-interface" );
-            i_showflags = settings.value( "qt-pl-showflags", 39 ).toInt();
+            i_showflags = settings->value( "qt-pl-showflags", COLUMN_DEFAULT ).toInt();
             if( i_showflags < 1)
-                i_showflags = 39; //reasonable default to show something;
-            updateColumnHeaders();
+                i_showflags = COLUMN_DEFAULT; /* reasonable default to show something; */
+            else if ( i_showflags >= COLUMN_END )
+                i_showflags = COLUMN_END - 1; /* show everything */
+
         }
     }
     else
     {
         i_showflags = parentItem->i_showflags;
-        //Add empty string and update() handles data appending
-        item_col_strings.append( "" );
     }
 }
 
 /*
    Constructors
    Call the above function init
-   So far the first constructor isn't used...
    */
-PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
+PLItem::PLItem( playlist_item_t *p_item, PLItem *parent, PLModel *m )
 {
-    init( _i_id, _i_input_id, parent, m );
+    init( p_item, parent, m, NULL );
 }
 
-PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
+PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m )
 {
-    init( p_item->i_id, p_item->p_input->i_id, parent, m );
+    init( p_item, NULL, m, settings );
 }
 
 PLItem::~PLItem()
 {
+    vlc_gc_decref( p_input );
     qDeleteAll( children );
     children.clear();
 }
 
-/* Column manager */
-void PLItem::updateColumnHeaders()
-{
-    item_col_strings.clear();
-
-    for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
-    {
-        if( i_showflags & i_index )
-        {
-            switch( i_index )
-            {
-            case VLC_META_ENGINE_TRACKID:
-                item_col_strings.append( qtr( VLC_META_TRACKID ) );
-                break;
-            case VLC_META_ENGINE_ARTIST:
-                item_col_strings.append( qtr( VLC_META_ARTIST ) );
-                break;
-            case VLC_META_ENGINE_TITLE:
-                item_col_strings.append( qtr( VLC_META_TITLE ) );
-                break;
-            case VLC_META_ENGINE_DESCRIPTION:
-                item_col_strings.append( qtr( VLC_META_DESCRIPTION ) );
-                break;
-            case VLC_META_ENGINE_DURATION:
-                item_col_strings.append( qtr( "Duration" ) );
-                break;
-            case VLC_META_ENGINE_GENRE:
-                item_col_strings.append( qtr( VLC_META_GENRE ) );
-                break;
-            case VLC_META_ENGINE_COLLECTION:
-                item_col_strings.append( qtr( VLC_META_COLLECTION ) );
-                break;
-            case VLC_META_ENGINE_SEQ_NUM:
-                item_col_strings.append( qtr( VLC_META_SEQ_NUM ) );
-                break;
-            default:
-                break;
-            }
-        }
-    }
-}
-
 /* So far signal is always true.
    Using signal false would not call PLModel... Why ?
  */
@@ -180,89 +137,13 @@ int PLItem::row() const
 }
 
 /* update the PL Item, get the good names and so on */
-/* This function may not be the best way to do it
-   It destroys everything and gets everything again instead of just
-   building the necessary columns.
-   This does extra work if you re-display the same column. Slower...
-   On the other hand, this way saves memory.
-   There must be a more clever way.
-   */
-void PLItem::update( playlist_item_t *p_item, bool iscurrent )
+void PLItem::update( playlist_item_t *p_item )
 {
-    char psz_duration[MSTRTIME_MAX_SIZE];
-    char *psz_meta;
-
-    assert( p_item->p_input->i_id == i_input_id );
+    assert( p_item->p_input == p_input);
 
     /* Useful for the model */
     i_type = p_item->p_input->i_type;
-    b_current = iscurrent;
-
-    item_col_strings.clear();
-
-    if( model->i_depth == 1 )  /* Selector Panel */
-    {
-        item_col_strings.append( qfu( p_item->p_input->psz_name ) );
-        return;
-    }
 
-#define ADD_META( item, meta ) \
-    psz_meta = input_item_Get ## meta ( item->p_input ); \
-    item_col_strings.append( qfu( psz_meta ) ); \
-    free( psz_meta );
-
-    for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; 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_title = input_item_GetTitle( p_item->p_input );
-                if( psz_title )
-                {
-                    ADD_META( p_item, Title );
-                    free( psz_title );
-                }
-                else
-                {
-                    psz_title = input_item_GetName( p_item->p_input );
-                    if( psz_title )
-                    {
-                        item_col_strings.append( qfu( psz_title ) );
-                    }
-                    free( psz_title );
-                }
-                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 );
-                item_col_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_TRACKID:
-                item_col_strings.append( QString::number( p_item->i_id ) );
-                break;
-            default:
-                break;
-            }
-        }
-    }
-#undef ADD_META
+    i_showflags = parentItem ? parentItem->i_showflags : i_showflags;
 }