Added Search functionality, and fixed navigation
[spotify:spotify.git] / libqspotify / src / qspotifyplaylist.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QMLify research project.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QSPOTIFYPLAYLIST_H
43 #define QSPOTIFYPLAYLIST_H
44
45 #include <QString>
46 #include <QObject>
47 #include <QVector>
48 #include <QAbstractListModel>
49
50 #include "qspotifytrack.h"
51
52 struct sp_playlist;
53 struct sp_playlistcontainer;
54
55 class QSPOTIFYSHARED_EXPORT QSpotifyPlaylist : public QAbstractListModel
56 {
57     Q_OBJECT
58
59     Q_PROPERTY(QString name READ name NOTIFY playlistRenamed);
60     Q_PROPERTY(int playlistType READ playlistType);
61 public:
62     QSpotifyPlaylist(sp_playlist *, int playlistType);
63     ~QSpotifyPlaylist();
64
65     QString name() const;
66
67     Q_INVOKABLE QSpotifyTrack *trackAt(int i) const;
68
69     int rowCount(const QModelIndex & parent = QModelIndex()) const;
70     QVariant data(const QModelIndex &index, int role) const;
71
72     int playlistType() const;
73
74     void addTracks(QList<QSpotifyTrack *>tracks, int position);
75     void removeTracks(int numberOfTracks,int position);
76     void moveTracks(int numberOfTracks, int oldPosition, int newPosition);
77
78     bool assertIsTheSame(sp_playlist *playlist)
79     { return m_playlist == playlist; }
80 signals:
81     void tracksAdded(int nTracks, int position);
82     void tracksRemoved(int nTracks);
83     void tracksMoved(int nTracks, int position);
84     void playlistRenamed();
85     void playlistStateChanged();
86     void playlistUpdateInProgress();
87     void playlistUpdateFinished();
88     void playlistMetaDataUpdated();
89 private:
90     sp_playlist *m_playlist;
91     bool m_cacheListValid;
92     QVector<QSpotifyTrack *> m_cacheList;
93     int m_playlistType;
94 };
95
96 class QSPOTIFYSHARED_EXPORT QSpotifyPlaylistContainer : public QAbstractListModel
97 {
98 Q_OBJECT
99 public:
100     QSpotifyPlaylistContainer(sp_playlistcontainer *pc, QObject *parent = 0);
101
102     int rowCount(const QModelIndex & parent = QModelIndex()) const;
103     QVariant data(const QModelIndex &index, int role) const;
104
105     Q_INVOKABLE QSpotifyPlaylist *playlistAt(int i) const;
106
107     void invalidateCache();
108     void setIsFullyLoaded();
109     void addPlaylist(QSpotifyPlaylist *, int pos);
110     void removePlaylist(int pos);
111     void movePlaylist(int oldPos, int newPos);
112
113 signals:
114     void containerFullyLoaded();
115
116 private:
117     sp_playlistcontainer *m_pc;
118     QVector<QSpotifyPlaylist *> m_cacheList;
119     bool m_isFullyLoaded;
120
121 };
122
123 #endif // QSPOTIFYPLAYLIST_H