playlist_model.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * playlist_model.hpp : Model for a playlist tree
00003  ****************************************************************************
00004  * Copyright (C) 2006 the VideoLAN team
00005  * $Id: 494df32046354865822aa1e55be75471757b113c $
00006  *
00007  * Authors: Clément Stenac <zorglub@videolan.org>
00008  *          Jakob Leben <jleben@videolan.org>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef _PLAYLIST_MODEL_H_
00026 #define _PLAYLIST_MODEL_H_
00027 
00028 #ifdef HAVE_CONFIG_H
00029 # include "config.h"
00030 #endif
00031 
00032 #include "qt4.hpp"
00033 
00034 #include <vlc_input.h>
00035 #include <vlc_playlist.h>
00036 
00037 #include "playlist_item.hpp"
00038 
00039 #include <QModelIndex>
00040 #include <QObject>
00041 #include <QEvent>
00042 #include <QMimeData>
00043 #include <QSignalMapper>
00044 #include <QAbstractItemModel>
00045 #include <QVariant>
00046 #include <QAction>
00047 
00048 class PLItem;
00049 class PLSelector;
00050 class PlMimeData;
00051 
00052 class PLModel : public QAbstractItemModel
00053 {
00054     Q_OBJECT
00055 
00056 friend class PLItem;
00057 friend class PLSelector;
00058 
00059 public:
00060     enum {
00061       IsCurrentRole = Qt::UserRole,
00062       IsLeafNodeRole
00063     };
00064 
00065     PLModel( playlist_t *, intf_thread_t *,
00066              playlist_item_t *, QObject *parent = 0 );
00067     ~PLModel();
00068 
00069     /*** QModel subclassing ***/
00070 
00071     /* Data structure */
00072     QVariant data( const QModelIndex &index, int role ) const;
00073     QVariant headerData( int section, Qt::Orientation orientation,
00074                          int role = Qt::DisplayRole ) const;
00075     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
00076     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
00077     Qt::ItemFlags flags( const QModelIndex &index ) const;
00078     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
00079     QModelIndex parent( const QModelIndex &index ) const;
00080 
00081     /* Drag and Drop */
00082     Qt::DropActions supportedDropActions() const;
00083     QMimeData* mimeData( const QModelIndexList &indexes ) const;
00084     bool dropMimeData( const QMimeData *data, Qt::DropAction action,
00085                       int row, int column, const QModelIndex &target );
00086     QStringList mimeTypes() const;
00087 
00088     /**** Custom ****/
00089 
00090     /* Lookups */
00091     QStringList selectedURIs();
00092     QModelIndex index( PLItem *, int c ) const;
00093     QModelIndex index( int i_id, int c );
00094     QModelIndex currentIndex();
00095     bool isCurrent( const QModelIndex &index ) const;
00096     int itemId( const QModelIndex &index ) const;
00097     static int columnFromMeta( int meta_column );
00098     static int columnToMeta( int column );
00099 
00100     /* Actions */
00101     bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
00102     void doDelete( QModelIndexList selected );
00103     void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
00104     void sort( int column, Qt::SortOrder order );
00105     void sort( int i_root_id, int column, Qt::SortOrder order );
00106     void rebuild();
00107     void rebuild( playlist_item_t * );
00108 
00109     inline PLItem *getItem( QModelIndex index ) const
00110     {
00111         if( index.isValid() )
00112             return static_cast<PLItem*>( index.internalPointer() );
00113         else return rootItem;
00114     }
00115 
00116 signals:
00117     void currentChanged( const QModelIndex& );
00118     void rootChanged();
00119 
00120 public slots:
00121     void activateItem( const QModelIndex &index );
00122     void activateItem( playlist_item_t *p_item );
00123 
00124 private:
00125     /* General */
00126     PLItem *rootItem;
00127 
00128     playlist_t *p_playlist;
00129     intf_thread_t *p_intf;
00130 
00131     static QIcon icons[ITEM_TYPE_NUMBER];
00132 
00133     /* Shallow actions (do not affect core playlist) */
00134     void updateTreeItem( PLItem * );
00135     void removeItem ( PLItem * );
00136     void removeItem( int );
00137     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
00138     void takeItem( PLItem * ); //will not delete item
00139     void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
00140     /* ...of which  the following will not update the views */
00141     void updateChildren( PLItem * );
00142     void updateChildren( playlist_item_t *, PLItem * );
00143 
00144     /* Deep actions (affect core playlist) */
00145     void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
00146     void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
00147 
00148     /* Popup */
00149     int i_popup_item, i_popup_parent, i_popup_column;
00150     QModelIndexList current_selection;
00151     QMenu *sortingMenu;
00152     QSignalMapper *sortingMapper;
00153 
00154     /* Lookups */
00155     PLItem *findById( PLItem *, int );
00156     PLItem *findByInput( PLItem *, int );
00157     PLItem *findInner( PLItem *, int , bool );
00158     bool canEdit() const;
00159 
00160     PLItem *p_cached_item;
00161     PLItem *p_cached_item_bi;
00162     int i_cached_id;
00163     int i_cached_input_id;
00164 
00165 private slots:
00166     void popupPlay();
00167     void popupDel();
00168     void popupInfo();
00169     void popupStream();
00170     void popupSave();
00171     void popupExplore();
00172     void popupAddNode();
00173     void popupSort( int column );
00174     void processInputItemUpdate( input_item_t *);
00175     void processInputItemUpdate( input_thread_t* p_input );
00176     void processItemRemoval( int i_id );
00177     void processItemAppend( int item, int parent );
00178 };
00179 
00180 class PlMimeData : public QMimeData
00181 {
00182     Q_OBJECT
00183 
00184 public:
00185     PlMimeData();
00186     ~PlMimeData();
00187     void appendItem( input_item_t *p_item );
00188     QList<input_item_t*> inputItems() const;
00189     QStringList formats () const;
00190 
00191 private:
00192     QList<input_item_t*> _inputItems;
00193     QMimeData *_mimeData;
00194 };
00195 
00196 #endif

Generated on Tue May 25 08:04:57 2010 for VLC by  doxygen 1.5.6