~ubuntu-branches/ubuntu/karmic/amarok/karmic

« back to all changes in this revision

Viewing changes to src/playlist/PlaylistModel.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-09-03 23:49:07 UTC
  • mfrom: (1.77.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090903234907-rk4lt6hnxwckvuon
Tags: 2:2.1.80-0ubuntu1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
6
 
 *
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.
14
 
 *
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.
19
 
 *
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>                    *
 
6
 *                                                                                      *
 
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.                                                            *
 
13
 *                                                                                      *
 
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.              *
 
17
 *                                                                                      *
 
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
 ****************************************************************************************/
23
21
 
24
22
#ifndef AMAROK_PLAYLISTMODEL_H
25
23
#define AMAROK_PLAYLISTMODEL_H
26
24
 
 
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"
32
29
 
42
39
 
43
40
namespace Playlist
44
41
{
45
 
class Model;
46
 
}
47
 
 
48
 
namespace The
49
 
{
50
 
AMAROK_EXPORT Playlist::Model* playlistModel();
51
 
}
52
 
 
53
 
namespace Playlist
54
 
{
55
 
 
56
 
    
57
 
enum DataRoles
58
 
{
59
 
    TrackRole = Qt::UserRole,
60
 
    StateRole,
61
 
    UniqueIdRole,
62
 
    ActiveTrackRole,
63
 
    QueuePositionRole,
64
 
    InCollectionRole,
65
 
    MultiSourceRole,
66
 
    StopAfterTrackRole
67
 
};
68
 
 
69
 
class AMAROK_EXPORT Model : public QAbstractListModel, public Meta::Observer
 
42
 
 
43
class AMAROK_EXPORT Model : public QAbstractListModel, public Meta::Observer, public AbstractModel
70
44
{
71
45
    friend class InsertTracksCmd;
72
46
    friend class RemoveTracksCmd;
75
49
    Q_OBJECT
76
50
 
77
51
    public:
78
 
        static Model* instance();
79
 
        static void destroy();
 
52
        Model( QObject *parent = 0 );
 
53
        ~Model();
80
54
 
81
55
        // inherited from QAbstractListModel
82
56
        int rowCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return m_items.size(); }
109
83
        Meta::TrackPtr trackAt( int row ) const;
110
84
        Meta::TrackPtr activeTrack() const;
111
85
 
 
86
        /**
 
87
         * Get the ordered list of tracks from this model
 
88
         */
 
89
        virtual Meta::TrackList tracks() const;
 
90
 
112
91
        // position-independent access methods
113
92
        // these are useful when you care what tracks are in the playlist, but not what order they're in (eg, the Random Track navigator)
114
93
        bool containsId( const quint64 id ) const { return m_itemIds.contains( id ); }
121
100
         * @return the id of the row specified, or 0 if the row does not exist
122
101
         */
123
102
        quint64 idAt( const int row ) const;
124
 
        
 
103
 
125
104
        /**
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.
128
108
         */
129
 
        quint64 activeId() const; // returns 0 for "no active row"
130
 
        
 
109
        quint64 activeId() const;
 
110
 
131
111
        /**
132
112
         * Set the active track based on the playlist id given.
133
113
         * @param id the unique playlist id
139
119
         */
140
120
        Item::State stateOfId( quint64 id ) const;
141
121
 
 
122
        void setAllUnplayed();
 
123
 
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; }
 
125
        /**
 
126
         * Saves a playlist to a specified location.
 
127
         * @param path the path of the playlist file, as chosen by a FileDialog in MainWindow.
 
128
         */
 
129
        virtual bool exportPlaylist( const QString &path ) const;
148
130
        inline const QString defaultPlaylistPath() const { return Amarok::saveLocation() + "current.xspf"; }
149
131
 
150
132
        // static member functions
151
133
        static QString prettyColumnName( Column index ); //!takes a Column enum and returns its string name
152
 
        
153
 
        /**
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.
160
 
         */
161
 
        int find( const QString & searchTerm, int searchFields = MatchTrack );
162
 
 
163
 
        /**
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.
172
 
         */
173
 
        int findNext( const QString & searchTerm, int selectedRow, int searchFields = MatchTrack   );
174
 
 
175
 
        /**
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.
184
 
         */
185
 
        int findPrevious( const QString & searchTerm, int selectedRow, int searchFields = MatchTrack  );
186
 
 
187
 
        void clearSearchTerm();
188
 
 
189
 
        /**
190
 
         * Check if a given row matches the current search term with the current
191
 
         * search fields.
192
 
         * @param row The row to check.
193
 
         * @return True if the row matches, false otherwise.
194
 
         */
195
 
        bool matchesCurrentSearchTerm( int row ) const;
196
 
 
197
 
        /**
198
 
         * Get the current search term.
199
 
         * @return The curent search term.
200
 
         */
201
 
        QString currentSearchTerm() { return m_currentSearchTerm; }
202
 
        
203
 
        /**
204
 
         * Get the current search fields bit bitmask.
205
 
         * @return The current search fields.
206
 
         */
207
 
        int currentSearchFields() { return m_currentSearchFields; }
208
 
 
209
 
    public slots:
210
 
        bool savePlaylist() const;
 
134
 
 
135
        int rowToBottomModel( const int row ) { return row; }
211
136
 
212
137
    signals:
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 );
218
142
 
219
143
    private:
220
 
        Model();
221
 
        ~Model();
222
 
 
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 ); }
235
156
 
236
 
        /**
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.
243
 
         */
244
 
        bool trackMatch( Meta::TrackPtr track, const QString &searchTerm, int searchFields ) const;
245
 
 
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
252
163
        QString m_playlistName;
253
164
        bool m_proposeOverwriting;
254
165
 
255
 
        QString m_currentSearchTerm;
256
 
        int m_currentSearchFields;
257
 
 
258
 
        static Model* s_instance;      //! instance variable
259
 
 
260
166
};
261
167
} // namespace Playlist
262
168