playlist_model.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00070
00071
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
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
00089
00090
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
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
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
00134 void updateTreeItem( PLItem * );
00135 void removeItem ( PLItem * );
00136 void removeItem( int );
00137 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
00138 void takeItem( PLItem * );
00139 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
00140
00141 void updateChildren( PLItem * );
00142 void updateChildren( playlist_item_t *, PLItem * );
00143
00144
00145 void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
00146 void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
00147
00148
00149 int i_popup_item, i_popup_parent, i_popup_column;
00150 QModelIndexList current_selection;
00151 QMenu *sortingMenu;
00152 QSignalMapper *sortingMapper;
00153
00154
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