Qt4 - Split PLItem and PLModel in two different files.
authorJean-Baptiste Kempf <jb@videolan.org>
Sat, 26 Jan 2008 04:37:06 +0000 (04:37 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Sat, 26 Jan 2008 04:37:06 +0000 (04:37 +0000)
modules/gui/qt4/Modules.am
modules/gui/qt4/components/playlist/playlist_item.cpp [new file with mode: 0644]
modules/gui/qt4/components/playlist/playlist_item.hpp [new file with mode: 0644]
modules/gui/qt4/components/playlist/playlist_model.cpp
modules/gui/qt4/components/playlist/playlist_model.hpp

index 47dbbee..7498167 100644 (file)
@@ -39,6 +39,7 @@ nodist_SOURCES_qt4 = \
                components/open_panels.moc.cpp \
                components/interface_widgets.moc.cpp \
                components/playlist/playlist_model.moc.cpp \
+               components/playlist/playlist_item.moc.cpp \
                components/playlist/playlist.moc.cpp \
                components/playlist/panels.moc.cpp \
                components/playlist/selector.moc.cpp \
@@ -108,6 +109,7 @@ SOURCES_qt4 =       qt4.cpp \
                components/open_panels.cpp \
                components/interface_widgets.cpp \
                components/playlist/playlist_model.cpp \
+               components/playlist/playlist_item.cpp \
                components/playlist/standardpanel.cpp \
                components/playlist/playlist.cpp \
                components/playlist/selector.cpp \
@@ -143,6 +145,7 @@ noinst_HEADERS = \
        components/open_panels.hpp \
        components/interface_widgets.hpp \
        components/playlist/playlist_model.hpp \
+       components/playlist/playlist_item.hpp \
        components/playlist/panels.hpp \
        components/playlist/playlist.hpp \
        components/playlist/selector.hpp \
diff --git a/modules/gui/qt4/components/playlist/playlist_item.cpp b/modules/gui/qt4/components/playlist/playlist_item.cpp
new file mode 100644 (file)
index 0000000..8bedd90
--- /dev/null
@@ -0,0 +1,255 @@
+/*****************************************************************************
+ * playlist_item.cpp : Manage playlist item
+ ****************************************************************************
+ * Copyright (C) 2006-2007 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Clément Stenac <zorglub@videolan.org>
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
+#include "qt4.hpp"
+#include "components/playlist/playlist_model.hpp"
+#include "dialogs/mediainfo.hpp"
+#include <vlc_intf_strings.h>
+
+#include "pixmaps/type_unknown.xpm"
+
+/*************************************************************************
+ * Playlist item implementation
+ *************************************************************************/
+
+/*
+   Playlist item is just a wrapper, an abstraction of the playlist_item
+   in order to be managed by PLModel
+
+   PLItem have a parent, and id and a input Id
+*/
+
+
+void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
+{
+    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 */
+    model      = m;               /* PLModel (QAbsmodel) */
+    i_type     = -1;              /* Item type - Avoid segfault */
+    b_current  = false;           /* Is the item the current Item or not */
+
+    assert( model );              /* We need a model */
+
+    /* No parent, should be the main one */
+    if( parentItem == NULL )
+    {
+        i_showflags = config_GetInt( model->p_intf, "qt-pl-showflags" );
+        updateColumnHeaders();
+    }
+    else
+    {
+        i_showflags = parentItem->i_showflags;
+        //Add empty string and update() handles data appending
+        item_col_strings.append( "" );
+    }
+    msg_Dbg( model->p_intf, "PLItem created of type: %i", model->i_depth );
+}
+
+/*
+   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 )
+{
+    init( _i_id, _i_input_id, parent, m );
+}
+
+PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
+{
+    init( p_item->i_id, p_item->p_input->i_id, parent, m );
+}
+
+PLItem::~PLItem()
+{
+    qDeleteAll( children );
+    children.clear();
+}
+
+/* Column manager */
+void PLItem::updateColumnHeaders()
+{
+    item_col_strings.clear();
+
+    if( model->i_depth == 1 )  /* Selector Panel */
+    {
+        item_col_strings.append( "" );
+        return;
+    }
+
+    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_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;
+            }
+        }
+    }
+}
+
+/* So far signal is always true.
+   Using signal false would not call PLModel... Why ?
+ */
+void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
+{
+    if( signal )
+        model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
+    children.insert( i_pos, item );
+    if( signal )
+        model->endInsertRows();
+}
+
+void PLItem::remove( PLItem *removed )
+{
+    if( model->i_depth == DEPTH_SEL || parentItem )
+    {
+        int i_index = parentItem->children.indexOf( removed );
+        model->beginRemoveRows( model->index( parentItem, 0 ),
+                                i_index, i_index );
+        parentItem->children.removeAt( i_index );
+        model->endRemoveRows();
+    }
+}
+
+/* This function is used to get one's parent's row number in the model */
+int PLItem::row() const
+{
+    if( parentItem )
+        return parentItem->children.indexOf( const_cast<PLItem*>(this) );
+       // We don't ever inherit PLItem, yet, but it might come :D
+    return 0;
+}
+
+/* update the PL Item, get the good names and so on */
+void PLItem::update( playlist_item_t *p_item, bool iscurrent )
+{
+    char psz_duration[MSTRTIME_MAX_SIZE];
+    char *psz_meta;
+
+    assert( p_item->p_input->i_id == i_input_id );
+
+    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_RATING:
+                ADD_META( p_item, Rating );
+            default:
+                break;
+            }
+        }
+
+    }
+#undef ADD_META
+}
+
diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
new file mode 100644 (file)
index 0000000..5f1b73d
--- /dev/null
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * playlist_item.hpp : Item for a playlist tree
+ ****************************************************************************
+ * Copyright (C) 2006 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Clément Stenac <zorglub@videolan.org>
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef _PLAYLIST_ITEM_H_
+#define _PLAYLIST_ITEM_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc/vlc.h>
+#include <vlc_input.h>
+#include <vlc_playlist.h>
+#include "components/playlist/playlist_model.hpp"
+
+#include <QString>
+#include <QList>
+
+class PLModel;
+
+class PLItem
+{
+    friend class PLModel;
+public:
+    PLItem( int, int, PLItem *parent , PLModel * );
+    PLItem( playlist_item_t *, PLItem *parent, PLModel * );
+    ~PLItem();
+
+    int row() const;
+
+    void insertChild( PLItem *, int p, bool signal = true );
+    void appendChild( PLItem *item, bool signal = true )
+    {
+        insertChild( item, children.count(), signal );
+    };
+
+    void remove( PLItem *removed );
+
+    PLItem *child( int row ) { return children.value( row ); };
+    int childCount() const { return children.count(); };
+
+    PLItem *parent() { return parentItem; };
+
+    QString columnString( int col ) { return item_col_strings.value( col ); };
+
+    void update( playlist_item_t *, bool );
+
+protected:
+    QList<PLItem*> children;
+    QList<QString> item_col_strings;
+    bool b_current;
+    int i_type;
+    int i_id;
+    int i_input_id;
+    int i_showflags;
+
+private:
+    void init( int, int, PLItem *, PLModel * );
+    void updateColumnHeaders();
+    PLItem *parentItem;
+    PLModel *model;
+};
+
+#endif
+
index 3fab8bd..7802f38 100644 (file)
@@ -20,6 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -37,8 +38,6 @@
 
 #include "pixmaps/type_unknown.xpm"
 
-#define DEPTH_PL -1
-#define DEPTH_SEL 1
 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
 
 static int PlaylistChanged( vlc_object_t *, const char *,
@@ -52,224 +51,6 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
                         vlc_value_t oval, vlc_value_t nval, void *param );
 
-/*************************************************************************
- * Playlist item implementation
- *************************************************************************/
-
-/*
-   Playlist item is just a wrapper, an abstraction of the playlist_item
-   in order to be managed by PLModel
-
-   PLItem have a parent, and id and a input Id
-*/
-
-
-void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
-{
-    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 */
-    model      = m;               /* PLModel (QAbsmodel) */
-    i_type     = -1;              /* Item type - Avoid segfault */
-    b_current  = false;
-
-    assert( model );
-
-    /* No parent, should be the main one */
-    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
-        item_col_strings.append( "" );
-    }
-    msg_Dbg( model->p_intf, "PLItem created of type: %i", model->i_depth );
-}
-
-/*
-   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 )
-{
-    init( _i_id, _i_input_id, parent, m );
-}
-
-PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
-{
-    init( p_item->i_id, p_item->p_input->i_id, parent, m );
-}
-
-PLItem::~PLItem()
-{
-    qDeleteAll( children );
-    children.clear();
-}
-
-/* Column manager */
-void PLItem::updateview()
-{
-    item_col_strings.clear();
-
-    if( model->i_depth == 1 )  /* Selector Panel */
-    {
-        item_col_strings.append( "" );
-        return;
-    }
-
-    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_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;
-            }
-        }
-    }
-}
-
-/* So far signal is always true.
-   Using signal false would not call PLModel... Why ?
- */
-void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
-{
-    if( signal )
-        model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
-    children.insert( i_pos, item );
-    if( signal )
-        model->endInsertRows();
-}
-
-void PLItem::remove( PLItem *removed )
-{
-    if( model->i_depth == DEPTH_SEL || parentItem )
-    {
-        int i_index = parentItem->children.indexOf( removed );
-        model->beginRemoveRows( model->index( parentItem, 0 ),
-                                i_index, i_index );
-        parentItem->children.removeAt( i_index );
-        model->endRemoveRows();
-    }
-}
-
-/* This function is used to get one's parent's row number in the model */
-int PLItem::row() const
-{
-    if( parentItem )
-        return parentItem->children.indexOf( const_cast<PLItem*>(this) ); // Why this ? I don't think we ever inherit PLItem
-    return 0;
-}
-
-/* update the PL Item, get the good names and so on */
-void PLItem::update( playlist_item_t *p_item, bool iscurrent )
-{
-    char psz_duration[MSTRTIME_MAX_SIZE];
-    char *psz_meta;
-
-    assert( p_item->p_input->i_id == i_input_id );
-
-    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_RATING:
-                ADD_META( p_item, Rating );
-            default:
-                break;
-            }
-        }
-
-    }
-#undef ADD_META
-}
-
 /*************************************************************************
  * Playlist model implementation
  *************************************************************************/
@@ -1042,7 +823,7 @@ void PLModel::viewchanged( int meta )
        {
            beginRemoveColumns( parent, index, index+1 );
            rootItem->i_showflags &= ~( meta );
-           rootItem->updateview();
+           rootItem->updateColumnHeaders();
            endRemoveColumns();
        }
        else
@@ -1050,7 +831,7 @@ void PLModel::viewchanged( int meta )
            /* Adding columns */
            beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
            rootItem->i_showflags |= meta;
-           rootItem->updateview();
+           rootItem->updateColumnHeaders();
            endInsertColumns();
        }
        rebuild();
index 86ad09f..dd6ca2c 100644 (file)
 #include <vlc/vlc.h>
 #include <vlc_input.h>
 #include <vlc_playlist.h>
+#include "playlist_item.hpp"
 
 #include <QModelIndex>
 #include <QObject>
 #include <QEvent>
 #include <QMimeData>
 #include <QSignalMapper>
+#include <QAbstractItemModel>
+#include <QVariant>
 
-class PLModel;
 class QSignalMapper;
 
-class PLItem
-{
-    friend class PLModel;
-public:
-    PLItem( int, int, PLItem *parent , PLModel * );
-    PLItem( playlist_item_t *, PLItem *parent, PLModel * );
-    ~PLItem();
-
-    int row() const;
-    void insertChild( PLItem *, int p, bool signal = true );
-
-    void appendChild( PLItem *item, bool signal = true )
-    {
-        insertChild( item, children.count(), signal );
-    };
-    void remove( PLItem *removed );
-
-    PLItem *child( int row ) { return children.value( row ); };
-    int childCount() const { return children.count(); };
-    QString columnString( int col ) { return item_col_strings.value( col ); };
-    PLItem *parent() { return parentItem; };
-
-    void update( playlist_item_t *, bool );
-protected:
-    QList<PLItem*> children;
-    QList<QString> item_col_strings;
-    bool b_current;
-    int i_type;
-    int i_id;
-    int i_input_id;
-    int i_showflags;
+class PLItem;
 
-    void updateview();
-private:
-    void init( int, int, PLItem *, PLModel * );
-    PLItem *parentItem;
-    PLModel *model;
-};
+#define DEPTH_PL -1
+#define DEPTH_SEL 1
 
 static int ItemUpdate_Type = QEvent::User + 2;
 static int ItemDelete_Type = QEvent::User + 3;
@@ -90,16 +58,16 @@ class PLEvent : public QEvent
 public:
     PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
     { i_id = id; p_add = NULL; };
+
     PLEvent(  playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
     { p_add = a; };
+
     virtual ~PLEvent() {};
 
     int i_id;
     playlist_add_t *p_add;
 };
 
-#include <QAbstractItemModel>
-#include <QVariant>
 
 class PLModel : public QAbstractItemModel
 {
@@ -147,6 +115,7 @@ public:
     QStringList mimeTypes() const;
 
     int shownFlags() {  return rootItem->i_showflags;  }
+
 private:
     void addCallbacks();
     void delCallbacks();
@@ -189,12 +158,14 @@ private:
     int i_cached_input_id;
 signals:
     void shouldRemove( int );
+
 public slots:
     void activateItem( const QModelIndex &index );
     void activateItem( playlist_item_t *p_item );
     void setRandom( bool );
     void setLoop( bool );
     void setRepeat( bool );
+
 private slots:
     void popupPlay();
     void popupDel();
@@ -204,6 +175,7 @@ private slots:
 #ifdef WIN32
     void popupExplore();
 #endif
+
     void viewchanged( int );
 };