]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_item.cpp
Merge branch 'df-for-upstream' of git://repo.or.cz/vlc/davidf-public
[vlc] / modules / gui / qt4 / components / playlist / playlist_item.cpp
index 3d52abd8f9fea2a2cef95836bb7fcb023d448566..a64cb166704e96d7c45040a1618adc60903fce07 100644 (file)
@@ -32,7 +32,9 @@
 #include "components/playlist/playlist_model.hpp"
 #include <vlc_intf_strings.h>
 
-#include "pixmaps/type_unknown.xpm"
+#include <QSettings>
+
+#include "sorting.h"
 
 /*************************************************************************
  * Playlist item implementation
@@ -46,7 +48,7 @@
 */
 
 
-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, QSettings *settings )
 {
     parentItem = parent;          /* Can be NULL, but only for the rootItem */
     i_id       = _i_id;           /* Playlist item specific id */
@@ -66,8 +68,12 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
         }
         else
         {
-            QSettings settings( "vlc", "vlc-qt-interface" );
-            i_showflags = settings.value( "qt-pl-showflags" ).toInt();
+            i_showflags = settings->value( "qt-pl-showflags", 39 ).toInt();
+            if( i_showflags < 1)
+                i_showflags = 39; /* reasonable default to show something; */
+            else if ( i_showflags >= COLUMN_END )
+                i_showflags = COLUMN_END - 1; /* show everything */
+
             updateColumnHeaders();
         }
     }
@@ -86,12 +92,17 @@ void PLItem::init( 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 );
+    init( _i_id, _i_input_id, parent, m, NULL );
 }
 
 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
 {
-    init( p_item->i_id, p_item->p_input->i_id, parent, m );
+    init( p_item->i_id, p_item->p_input->i_id, parent, m, NULL );
+}
+
+PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m )
+{
+    init( p_item->i_id, p_item->p_input->i_id, NULL, m, settings );
 }
 
 PLItem::~PLItem()
@@ -105,40 +116,12 @@ void PLItem::updateColumnHeaders()
 {
     item_col_strings.clear();
 
-    for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
+    assert( i_showflags < COLUMN_END );
+
+    for( uint32_t i_index=1; i_index < COLUMN_END; i_index <<= 1 )
     {
         if( i_showflags & i_index )
-        {
-            switch( i_index )
-            {
-            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;
-            case VLC_META_ENGINE_RATING:
-                item_col_strings.append( qtr( VLC_META_RATING ) );
-                break;
-            default:
-                break;
-            }
-        }
+            item_col_strings.append( qfu( psz_column_title( i_index ) ) );
     }
 }
 
@@ -202,62 +185,15 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
         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 );
+    assert( parentItem->i_showflags < COLUMN_END );
 
-    for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
+    for( uint32_t i_index=1; i_index < COLUMN_END; i_index <<= 1 )
     {
         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_RATING:
-                ADD_META( p_item, Rating );
-            default:
-                break;
-            }
+            char *psz = psz_column_meta( p_item->p_input, i_index );
+            item_col_strings.append( qfu( psz ) );
+            free( psz );
         }
     }
-#undef ADD_META
 }
-