1 /***************************************************************************
2 * copyright : (C) 2007 Ian Monroe <ian@monroe.nu> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License version 2 *
6 * as published by the Free Software Foundation. *
7 ***************************************************************************/
9 #ifndef AMAROK_PLAYLISTMODEL_H
10 #define AMAROK_PLAYLISTMODEL_H
14 #include "UndoCommands.h"
16 #include <QAbstractListModel>
21 #include <kdemacros.h>
22 #include "PlaylistItem.h"
29 //PORT rename to Playlist when the playlist class is removed
30 namespace PlaylistNS
{
68 ///Options for insertTracks
71 Append
= 1, /// inserts media after the last item in the playlist
72 Queue
= 2, /// inserts media after the currentTrack
73 Replace
= 4, /// clears the playlist first
74 DirectPlay
= 8, /// start playback of the first item in the list
75 Unique
= 16, /// don't insert anything already in the playlist
76 StartPlay
= 32, /// start playback of the first item in the list if nothing else playing
77 Colorize
= 64, /// colorize newly added items
78 AppendAndPlay
= Append
| Unique
| StartPlay
81 class Model
: public QAbstractListModel
, Meta::Observer
83 friend class AddTracksCmd
;
84 friend class RemoveTracksCmd
;
87 Model( QObject
* parent
= 0 );
89 //required by QAbstractListModel
90 int rowCount(const QModelIndex
&parent
= QModelIndex() ) const;
91 int columnCount(const QModelIndex
&parent
= QModelIndex() ) const { Q_UNUSED(parent
); return 1; }
92 QVariant
data(const QModelIndex
&index
, int role
) const;
93 //overriding QAbstractItemModel
94 bool removeRows( int row
, int count
, const QModelIndex
&parent
= QModelIndex() );
95 QVariant
headerData(int /*section*/, Qt::Orientation
/*orientation*/, int /*role*/) const { return QVariant(); }
96 Qt::DropActions
supportedDropActions() const;
98 //Drag and Drop methods
99 virtual bool insertRows( int /*row*/, int /*count*/, const QModelIndex
&parent
= QModelIndex() ) { Q_UNUSED(parent
); return true; }
100 Qt::ItemFlags
flags(const QModelIndex
&index
) const;
101 QStringList
mimeTypes() const;
102 QMimeData
* mimeData(const QModelIndexList
&indexes
) const;
103 bool dropMimeData ( const QMimeData
* data
, Qt::DropAction action
, int row
, int column
, const QModelIndex
& parent
);
106 ///Restore playlist from previous session of Amarok
107 void restoreSession() { }
108 ///Save M3U of current playlist to a given location
109 bool saveM3U( const QString
&path
, bool relative
) const;
112 * Insert tracks into the playlist with some handy options.
113 * @param list tracks to add
114 * @param options valid values are Unique || (Append xor Queue xor Replace) || ( DirectPlay xor StartPlay )
116 void insertOptioned( Meta::TrackList list
, int options
);
117 void insertOptioned( Meta::TrackPtr track
, int options
); //convenience method
118 void insertOptioned( QueryMaker
*qm
, int options
);
119 void insertTrack( int row
, Meta::TrackPtr track
); //convenience method
120 void insertTracks( int row
, Meta::TrackList list
);
121 void insertTracks( int row
, QueryMaker
*qm
);
123 int activeRow() const { return m_activeRow
; }
124 void setActiveRow( int row
);
125 Meta::TrackPtr
activeTrack() const { return m_items
.at( m_activeRow
)->track(); }
126 // Qt::ItemFlags flags(const QModelIndex &index) const;
128 ///deprecated function to ease porting to Meta::Track from URLs
129 KDE_DEPRECATED
void insertMedia( KUrl::List list
, int options
= Append
);
130 virtual void metadataChanged( Meta::Track
*track
);
131 virtual void metadataChanged( Meta::Album
*album
);
132 void play( int row
);
133 static Model
* s_instance
; //! instance variable
135 //various methods for playlist name
136 //I believe this is used for when you open a playlist file, it can keep the same name when it is
138 void setPlaylistName( const QString
&name
, bool proposeOverwriting
= false ) { m_playlistName
= name
; m_proposeOverwriting
= proposeOverwriting
; }
139 void proposePlaylistName( const QString
&name
, bool proposeOverwriting
= false ) { if( ( rowCount() == 0 ) || m_playlistName
==i18n("Untitled") ) m_playlistName
= name
; m_proposeOverwriting
= proposeOverwriting
; }
140 const QString
&playlistName() const { return m_playlistName
; }
141 bool proposeOverwriteOnSave() const { return m_proposeOverwriting
; }
144 void play( const QModelIndex
& index
);
146 void clear(); ///clear the playlist of all items
148 void trackFinished(); //! what to do when a track finishes
150 void newResultReady( const QString
&collectionId
, const Meta::TrackList
&tracks
);
153 QString m_playlistName
;
154 bool m_proposeOverwriting
;
156 /**This performs the actual work involved with inserting tracks. It is to be *only* called by an UndoCommand.
157 * @arg row Row number in the playlist to insert the list after.
158 * @arg list The list to be inserted.
160 void insertTracksCommand( int row
, Meta::TrackList list
);
161 /**This performs the actual work involved with removing tracks. It is to be *only* called by an UndoCommand.
162 * @arg row Row number in the playlist to insert the list after.
163 * @arg list The list to be inserted.
165 Meta::TrackList
removeRowsCommand( int position
, int rows
);
167 static QString
prettyColumnName( Column index
); //!takes a Column enum and returns its string name
169 QList
<Item
*> m_items
; //! list of tracks in order currently in the playlist
170 int m_activeRow
; //! the row being played
171 TrackAdvancer
* m_advancer
; //! the strategy of what to do when a track finishes playing
172 QUndoStack
* m_undoStack
; //! for pushing on undo commands
173 QHash
<QueryMaker
*, int> m_queryMap
; //!maps queries to the row where the results should be inserted
174 QHash
<QueryMaker
*, int> m_optionedQueryMap
; //!maps queries to the options to be used when inserting the result