PageRenderTime 365ms CodeModel.GetById 81ms app.highlight 147ms RepoModel.GetById 95ms app.codeStats 1ms

/src/libtomahawk/playlist/trackmodel.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 153 lines | 95 code | 39 blank | 19 comment | 0 complexity | fb73ae9594b9f138bb50a710b845f426 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2011       Leo Franchi <lfranchi@kde.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#ifndef TRACKMODEL_H
 21#define TRACKMODEL_H
 22
 23#include <QAbstractItemModel>
 24
 25#include "playlistinterface.h"
 26#include "trackmodelitem.h"
 27#include "typedefs.h"
 28
 29#include "dllmacro.h"
 30
 31class QMetaData;
 32
 33class DLLEXPORT TrackModel : public QAbstractItemModel
 34{
 35Q_OBJECT
 36
 37public:
 38    enum TrackItemStyle
 39    { Detailed = 0, Short = 1, ShortWithAvatars = 2 };
 40
 41    enum TrackModelRole
 42    { StyleRole = Qt::UserRole + 1 };
 43
 44    enum Columns {
 45        Artist = 0,
 46        Track = 1,
 47        Composer = 2,
 48        Album = 3,
 49        AlbumPos = 4,
 50        Duration = 5,
 51        Bitrate = 6,
 52        Age = 7,
 53        Year = 8,
 54        Filesize = 9,
 55        Origin = 10,
 56        Score = 11
 57    };
 58
 59    explicit TrackModel( QObject* parent = 0 );
 60    virtual ~TrackModel();
 61
 62    TrackModel::TrackItemStyle style() const { return m_style; }
 63    void setStyle( TrackModel::TrackItemStyle style );
 64
 65    virtual QModelIndex index( int row, int column, const QModelIndex& parent ) const;
 66    virtual QModelIndex parent( const QModelIndex& child ) const;
 67
 68    virtual bool isReadOnly() const { return m_readOnly; }
 69    virtual void setReadOnly( bool b ) { m_readOnly = b; }
 70
 71    virtual QString title() const { return m_title; }
 72    virtual void setTitle( const QString& title ) { m_title = title; }
 73    virtual QString description() const { return m_description; }
 74    virtual void setDescription( const QString& description ) { m_description = description; }
 75
 76    virtual int trackCount() const { return rowCount( QModelIndex() ); }
 77
 78    virtual int rowCount( const QModelIndex& parent ) const;
 79    virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const;
 80
 81    virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
 82    virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
 83
 84    virtual QMimeData* mimeData( const QModelIndexList& indexes ) const;
 85    virtual QStringList mimeTypes() const;
 86    virtual Qt::DropActions supportedDropActions() const;
 87    virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
 88
 89    virtual QPersistentModelIndex currentItem() { return m_currentIndex; }
 90    virtual Tomahawk::QID currentItemUuid() { return m_currentUuid; }
 91
 92    virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return Tomahawk::PlaylistInterface::NoRepeat; }
 93    virtual bool shuffled() const { return false; }
 94
 95    virtual void ensureResolved();
 96
 97    TrackModelItem* itemFromIndex( const QModelIndex& index ) const;
 98    /// Returns a flat list of all tracks in this model
 99    QList< Tomahawk::query_ptr > queries() const;
100
101signals:
102    void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
103    void shuffleModeChanged( bool enabled );
104
105    void trackCountChanged( unsigned int tracks );
106
107    void loadingStarted();
108    void loadingFinished();
109
110public slots:
111    virtual void setCurrentItem( const QModelIndex& index );
112
113    virtual void clear();
114
115    virtual void append( const QList< Tomahawk::query_ptr >& queries );
116    virtual void append( const Tomahawk::query_ptr& query );
117    virtual void append( const Tomahawk::artist_ptr& artist ) { Q_UNUSED( artist ); }
118    virtual void append( const Tomahawk::album_ptr& album ) { Q_UNUSED( album ); }
119
120    virtual void insert( const QList< Tomahawk::query_ptr >& queries, int row = 0 );
121    virtual void insert( const Tomahawk::query_ptr& query, int row = 0 );
122
123    virtual void remove( int row, bool moreToCome = false );
124    virtual void remove( const QModelIndex& index, bool moreToCome = false );
125    virtual void remove( const QList<QModelIndex>& indexes );
126    virtual void remove( const QList<QPersistentModelIndex>& indexes );
127
128    virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
129    virtual void setShuffled( bool /*shuffled*/ ) {}
130
131protected:
132    TrackModelItem* rootItem() const { return m_rootItem; }
133
134private slots:
135    void onPlaybackStarted( const Tomahawk::result_ptr& result );
136    void onPlaybackStopped();
137
138private:
139    Qt::Alignment columnAlignment( int column ) const;
140
141    TrackModelItem* m_rootItem;
142    QPersistentModelIndex m_currentIndex;
143    Tomahawk::QID m_currentUuid;
144
145    bool m_readOnly;
146
147    QString m_title;
148    QString m_description;
149
150    TrackItemStyle m_style;
151};
152
153#endif // TRACKMODEL_H