playlist_model.hpp 5.37 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * playlist_model.hpp : Model for a playlist tree
 ****************************************************************************
4
5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
zorglub's avatar
zorglub committed
6
7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jakob Leben <jleben@videolan.org>
zorglub's avatar
zorglub committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * 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_MODEL_H_
#define _PLAYLIST_MODEL_H_

Christophe Mutricy's avatar
Christophe Mutricy committed
28
29
30
31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
32
33
#include "qt4.hpp"

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
34
35
36
#include <vlc_input.h>
#include <vlc_playlist.h>

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
37
#include "playlist_item.hpp"
38

zorglub's avatar
zorglub committed
39
#include <QModelIndex>
zorglub's avatar
zorglub committed
40
41
#include <QObject>
#include <QEvent>
zorglub's avatar
zorglub committed
42
#include <QMimeData>
43
#include <QSignalMapper>
44
45
#include <QAbstractItemModel>
#include <QVariant>
zorglub's avatar
zorglub committed
46

47
class QSignalMapper;
48
class PLItem;
49

zorglub's avatar
zorglub committed
50
51
52
53
class PLModel : public QAbstractItemModel
{
    Q_OBJECT

54
55
friend class PLItem;

zorglub's avatar
zorglub committed
56
public:
57
58
59
60
    enum {
      IsCurrentRole = Qt::UserRole
    };

zorglub's avatar
zorglub committed
61
    PLModel( playlist_t *, intf_thread_t *,
62
             playlist_item_t *, QObject *parent = 0 );
zorglub's avatar
zorglub committed
63
64
    ~PLModel();

jpd's avatar
jpd committed
65
66
67
    /*** QModel subclassing ***/

    /* Data structure */
68
    QVariant data( const QModelIndex &index, int role ) const;
zorglub's avatar
zorglub committed
69
    QVariant headerData( int section, Qt::Orientation orientation,
70
                         int role = Qt::DisplayRole ) const;
zorglub's avatar
zorglub committed
71
72
    int rowCount( const QModelIndex &parent = QModelIndex() ) const;
    int columnCount( const QModelIndex &parent = QModelIndex() ) const;
jpd's avatar
jpd committed
73
74
75
    Qt::ItemFlags flags( const QModelIndex &index ) const;
    QModelIndex index( int r, int c, const QModelIndex &parent ) const;
    QModelIndex parent( const QModelIndex &index ) const;
zorglub's avatar
zorglub committed
76

jpd's avatar
jpd committed
77
78
79
80
81
82
    /* Drag and Drop */
    Qt::DropActions supportedDropActions() const;
    QMimeData* mimeData( const QModelIndexList &indexes ) const;
    bool dropMimeData( const QMimeData *data, Qt::DropAction action,
                      int row, int column, const QModelIndex &target );
    QStringList mimeTypes() const;
83

jpd's avatar
jpd committed
84
85
86
87
88
    /**** Custom ****/

    /* Lookups */
    QStringList selectedURIs();
    QModelIndex index( PLItem *, int c ) const;
89
    QModelIndex index( int i_id, int c );
90
    QModelIndex currentIndex();
jpd's avatar
jpd committed
91
92
    bool isCurrent( const QModelIndex &index ) const;
    int itemId( const QModelIndex &index ) const;
zorglub's avatar
zorglub committed
93

jpd's avatar
jpd committed
94
    /* Actions */
jpd's avatar
jpd committed
95
    void popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
zorglub's avatar
zorglub committed
96
    void doDelete( QModelIndexList selected );
97
    void search( const QString& search_text );
zorglub's avatar
zorglub committed
98
    void sort( int column, Qt::SortOrder order );
99
    void sort( int i_root_id, int column, Qt::SortOrder order );
zorglub's avatar
zorglub committed
100
    void removeItem( int );
101
    void rebuild(); void rebuild( playlist_item_t *, bool b_first = false );
102

103
104
105
106
107
108
    inline PLItem *getItem( QModelIndex index ) const
    {
        if( index.isValid() )
            return static_cast<PLItem*>( index.internalPointer() );
        else return rootItem;
    }
109

zorglub's avatar
zorglub committed
110
private:
zorglub's avatar
zorglub committed
111

jpd's avatar
jpd committed
112
    /* General */
zorglub's avatar
zorglub committed
113
114
115
    PLItem *rootItem;

    playlist_t *p_playlist;
zorglub's avatar
zorglub committed
116
    intf_thread_t *p_intf;
zorglub's avatar
zorglub committed
117
    int i_depth;
zorglub's avatar
zorglub committed
118

zorglub's avatar
zorglub committed
119
120
    static QIcon icons[ITEM_TYPE_NUMBER];

zorglub's avatar
zorglub committed
121
    /* Actions */
122
    void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
123
    void updateTreeItem( PLItem * );
124
    void removeItem ( PLItem * );
jpd's avatar
jpd committed
125
126
    void takeItem( PLItem * ); //will not delete item
    void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
127
128
    void dropAppendCopy( QByteArray& data, PLItem *target );
    void dropMove( QByteArray& data, PLItem *target, int new_pos );
129
    /* The following actions will not signal the view! */
jpd's avatar
jpd committed
130
131
    void updateChildren( PLItem * );
    void updateChildren( playlist_item_t *, PLItem * );
zorglub's avatar
zorglub committed
132

zorglub's avatar
zorglub committed
133
    /* Popup */
134
    int i_popup_item, i_popup_parent, i_popup_column;
zorglub's avatar
zorglub committed
135
136
    QModelIndexList current_selection;

zorglub's avatar
zorglub committed
137
    /* Lookups */
jpd's avatar
jpd committed
138
139
140
    PLItem *findById( PLItem *, int );
    PLItem *findByInput( PLItem *, int );
    PLItem *findInner( PLItem *, int , bool );
141

142
143
    int columnFromMeta( int meta_column ) const;
    int columnToMeta( int column ) const;
144
    bool canEdit() const;
zorglub's avatar
zorglub committed
145
146
147
148
    PLItem *p_cached_item;
    PLItem *p_cached_item_bi;
    int i_cached_id;
    int i_cached_input_id;
jpd's avatar
jpd committed
149

150
signals:
151
    void currentChanged( const QModelIndex& );
152
    void rootChanged();
153

zorglub's avatar
zorglub committed
154
155
public slots:
    void activateItem( const QModelIndex &index );
zorglub's avatar
zorglub committed
156
    void activateItem( playlist_item_t *p_item );
157

zorglub's avatar
zorglub committed
158
159
160
private slots:
    void popupPlay();
    void popupDel();
zorglub's avatar
zorglub committed
161
162
163
    void popupInfo();
    void popupStream();
    void popupSave();
164
    void popupExplore();
jpd's avatar
jpd committed
165
    void popupAddNode();
166
167
    void popupSortAsc();
    void popupSortDesc();
jpd's avatar
jpd committed
168
169
    void processInputItemUpdate( input_item_t *);
    void processInputItemUpdate( input_thread_t* p_input );
170
171
    void processItemRemoval( int i_id );
    void processItemAppend( int item, int parent );
zorglub's avatar
zorglub committed
172
173
174
};

#endif