1
/***************************************************************************
2
* copyright : (C) 2007 Ian Monroe <ian@monroe.nu>
3
* (C) 2008 Seb Ruiz <ruiz@kde.org>
4
* (C) 2008 Soren Harward <stharward@gmail.com>
5
* : (C) 2008 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation; either version 2 of
10
* the License or (at your option) version 3 or any later version
11
* accepted by the membership of KDE e.V. (or its successor approved
12
* by the membership of KDE e.V.), which shall act as a proxy
13
* defined in Section 14 of version 3 of the license.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
**************************************************************************/
1
/****************************************************************************************
2
* Copyright (c) 2007 Ian Monroe <ian@monroe.nu> *
3
* Copyright (c) 2008 Seb Ruiz <ruiz@kde.org> *
4
* Copyright (c) 2008 Soren Harward <stharward@gmail.com> *
5
* Copyright (c) 2008 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com> *
7
* This program is free software; you can redistribute it and/or modify it under *
8
* the terms of the GNU General Public License as published by the Free Software *
9
* Foundation; either version 2 of the License, or (at your option) version 3 or *
10
* any later version accepted by the membership of KDE e.V. (or its successor approved *
11
* by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of *
12
* version 3 of the license. *
14
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
15
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
16
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License along with *
19
* this program. If not, see <http://www.gnu.org/licenses/>. *
20
****************************************************************************************/
24
22
#ifndef AMAROK_PLAYLISTMODEL_H
25
23
#define AMAROK_PLAYLISTMODEL_H
25
#include "proxymodels/AbstractModel.h"
27
26
#include "Amarok.h"
28
#include "PlaylistDefines.h"
29
#include "PlaylistItem.h"
30
27
#include "UndoCommands.h"
31
28
#include "meta/Meta.h"
121
100
* @return the id of the row specified, or 0 if the row does not exist
123
102
quint64 idAt( const int row ) const;
126
105
* Returns the unique playlist item id of the active track
127
* @return the playlist item's id, or 0 if no active track
106
* (or 0 if no track is active).
107
* @return The playlist item's id.
129
quint64 activeId() const; // returns 0 for "no active row"
109
quint64 activeId() const;
132
112
* Set the active track based on the playlist id given.
133
113
* @param id the unique playlist id
140
120
Item::State stateOfId( quint64 id ) const;
122
void setAllUnplayed();
142
124
// methods to save playlist to file
143
bool exportPlaylist( const QString &path ) const;
144
void setPlaylistName( const QString &name, bool proposeOverwriting = false );
145
void proposePlaylistName( const QString &name, bool proposeOverwriting = false );
146
const QString& playlistName() const { return m_playlistName; }
147
bool proposeOverwriteOnSave() const { return m_proposeOverwriting; }
126
* Saves a playlist to a specified location.
127
* @param path the path of the playlist file, as chosen by a FileDialog in MainWindow.
129
virtual bool exportPlaylist( const QString &path ) const;
148
130
inline const QString defaultPlaylistPath() const { return Amarok::saveLocation() + "current.xspf"; }
150
132
// static member functions
151
133
static QString prettyColumnName( Column index ); //!takes a Column enum and returns its string name
154
* Find the first track in the playlist that matches the search term in one of the
155
* specified search fields. This function emits found() or notFound() depending on
156
* whether a match is found.
157
* @param searchTerm The term to search for.
158
* @param searchFields A bitmask specifying the fields to look in.
159
* @return The row of the first found match, -1 if no match is found.
161
int find( const QString & searchTerm, int searchFields = MatchTrack );
164
* Find the first track below a given row that matches the search term in one of the
165
* specified search fields. This function emits found() or notFound() depending on
166
* whether a match is found. If no row is found below the current row, the function wraps
167
* around and returns the first match. If no match is found at all, -1 is returned.
168
* @param searchTerm The term to search for.
169
* @param selectedRow The offset row.
170
* @param searchFields A bitmask specifying the fields to look in.
171
* @return The row of the first found match below the offset, -1 if no match is found.
173
int findNext( const QString & searchTerm, int selectedRow, int searchFields = MatchTrack );
176
* Find the first track above a given row that matches the search term in one of the
177
* specified search fields. This function emits found() or notFound() depending on
178
* whether a match is found. If no row is found above the current row, the function wraps
179
* around and returns the last match. If no match is found at all, -1 is returned.
180
* @param searchTerm The term to search for.
181
* @param selectedRow The offset row.
182
* @param searchFields A bitmask specifying the fields to look in.
183
* @return The row of the first found match above the offset, -1 if no match is found.
185
int findPrevious( const QString & searchTerm, int selectedRow, int searchFields = MatchTrack );
187
void clearSearchTerm();
190
* Check if a given row matches the current search term with the current
192
* @param row The row to check.
193
* @return True if the row matches, false otherwise.
195
bool matchesCurrentSearchTerm( int row ) const;
198
* Get the current search term.
199
* @return The curent search term.
201
QString currentSearchTerm() { return m_currentSearchTerm; }
204
* Get the current search fields bit bitmask.
205
* @return The current search fields.
207
int currentSearchFields() { return m_currentSearchFields; }
210
bool savePlaylist() const;
135
int rowToBottomModel( const int row ) { return row; }
213
138
void insertedIds( const QList<quint64>& );
214
139
void removedIds( const QList<quint64>& );
215
140
void activeTrackChanged( quint64 );
216
141
void activeRowChanged( int );
217
void itemsAdded( int firstRow );
223
144
// inherit from QAbstractListModel, and make private so that nobody uses them
224
145
bool insertRow( int, const QModelIndex& parent = QModelIndex() ) { Q_UNUSED( parent ); return false; }
225
146
bool insertRows( int, int, const QModelIndex& parent = QModelIndex() ) { Q_UNUSED( parent ); return false; }
233
154
void clearCommand();
234
155
void setStateOfRow( int row, Item::State state ) { m_items.at( row )->setState( state ); }
237
* Check if a certain tracks matches a search term when looking at the fields
238
* specified by the searchFields bitmask.
239
* @param track The track to match against.
240
* @param searchTerm The search term.
241
* @param searchFields A bitmask containing the fields that should be matched against.
242
* @return True if a match is found in any field, false otherwise.
244
bool trackMatch( Meta::TrackPtr track, const QString &searchTerm, int searchFields ) const;
246
157
QList<Item*> m_items; //! list of tracks in order currently in the playlist
247
158
QHash<quint64, Item*> m_itemIds; //! maps track id's to items
248
159
int m_activeRow; //! the row being played