~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/playlist/playlistitem.h

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#define PLAYLISTITEM_H
20
20
 
21
21
#include <QMap>
 
22
#include <QMetaType>
22
23
#include <QStandardItem>
23
24
#include <QUrl>
24
25
 
25
26
#include <boost/enable_shared_from_this.hpp>
26
 
#include <boost/shared_ptr.hpp>
27
27
 
28
28
#include "core/song.h"
29
29
 
 
30
class QAction;
30
31
class SqlRow;
31
32
 
32
33
class PlaylistItem : public boost::enable_shared_from_this<PlaylistItem> {
41
42
  enum Option {
42
43
    Default = 0x00,
43
44
 
44
 
    // The URL returned by Url() isn't the actual URL of the music - the
45
 
    // item needs to do something special before it can get an actual URL.
46
 
    // Causes StartLoading() to get called when the user wants to play.
47
 
    SpecialPlayBehaviour = 0x01,
48
 
 
49
 
    // This item might be able to provide another track after one finishes, for
50
 
    // example in a radio stream.  Causes LoadNext() to get called when the
51
 
    // next URL is required.
52
 
    ContainsMultipleTracks = 0x02,
53
 
 
54
45
    // Disables the "pause" action.
55
 
    PauseDisabled = 0x04,
 
46
    PauseDisabled = 0x01,
56
47
 
57
48
    // Enables the last.fm "ban" action.
58
 
    LastFMControls = 0x08,
 
49
    LastFMControls = 0x02,
 
50
 
 
51
    // Disables the seek slider.
 
52
    SeekDisabled = 0x04,
59
53
  };
60
54
  Q_DECLARE_FLAGS(Options, Option);
61
55
 
62
 
  // Returned by StartLoading() and LoadNext(), indicates what the player
63
 
  // should do when it wants to load a playlist item that is marked
64
 
  // SpecialPlayBehaviour or ContainsMultipleTracks.
65
 
  struct SpecialLoadResult {
66
 
    enum Type {
67
 
      // There wasn't a track available, and the player should move on to the
68
 
      // next playlist item.
69
 
      NoMoreTracks,
70
 
 
71
 
      // There might be another track available, something will call the
72
 
      // player's HandleSpecialLoad() slot later with the same original_url.
73
 
      WillLoadAsynchronously,
74
 
 
75
 
      // There was a track available.  Its url is in media_url.
76
 
      TrackAvailable,
77
 
    };
78
 
 
79
 
    SpecialLoadResult(Type type = NoMoreTracks,
80
 
                      const QUrl& original_url = QUrl(),
81
 
                      const QUrl& media_url = QUrl());
82
 
 
83
 
    Type type_;
84
 
 
85
 
    // The url that the playlist items has in Url().
86
 
    // Might be something unplayable like lastfm://...
87
 
    QUrl original_url_;
88
 
 
89
 
    // The actual url to something that gstreamer can play.
90
 
    QUrl media_url_;
91
 
  };
92
 
 
93
56
  virtual QString type() const { return type_; }
94
57
 
95
58
  virtual Options options() const { return Default; }
96
59
 
 
60
  virtual QList<QAction*> actions() { return QList<QAction*>(); }
 
61
 
97
62
  virtual bool InitFromQuery(const SqlRow& query) = 0;
98
63
  void BindToQuery(QSqlQuery* query) const;
99
64
  virtual void Reload() {}
102
67
  virtual Song Metadata() const = 0;
103
68
  virtual QUrl Url() const = 0;
104
69
 
105
 
  // Called by the Player if SpecialPlayBehaviour is set - gives the playlist
106
 
  // item a chance to do something clever to get a playable track.
107
 
  virtual SpecialLoadResult StartLoading() { return SpecialLoadResult(); }
108
 
 
109
 
  // Called by the player if ContainsMultipleTracks is set - gives the playlist
110
 
  // item a chance to get another track to play.
111
 
  virtual SpecialLoadResult LoadNext() { return SpecialLoadResult(); }
112
 
 
113
70
  void SetTemporaryMetadata(const Song& metadata);
114
71
  void ClearTemporaryMetadata();
115
72
  bool HasTemporaryMetadata() const { return temp_metadata_.is_valid(); }
131
88
  // Convenience function to find out whether this item is from the local
132
89
  // library, as opposed to a device, a file on disk, or a stream.
133
90
  // Remember that even if this returns true, the library item might be
134
 
  // invalid so you might want to check that it's id is not equal to -1
 
91
  // invalid so you might want to check that its id is not equal to -1
135
92
  // before actually using it.
136
93
  virtual bool IsLocalLibraryItem() const { return false; }
137
94
 
138
95
 protected:
139
96
  enum DatabaseColumn {
140
97
    Column_LibraryId,
141
 
    Column_Url,
142
 
    Column_Title,
143
 
    Column_Artist,
144
 
    Column_Album,
145
 
    Column_Length,
146
 
    Column_RadioService,
147
 
    Column_Beginning,
148
 
    Column_CuePath,
 
98
    Column_InternetService,
149
99
  };
150
100
 
151
101
  virtual QVariant DatabaseValue(DatabaseColumn) const {
152
102
    return QVariant(QVariant::String); }
 
103
  virtual Song DatabaseSongMetadata() const { return Song(); }
153
104
 
154
105
  QString type_;
155
106
 
161
112
typedef boost::shared_ptr<PlaylistItem> PlaylistItemPtr;
162
113
typedef QList<PlaylistItemPtr> PlaylistItemList;
163
114
 
164
 
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::Options);
 
115
Q_DECLARE_METATYPE(PlaylistItemPtr)
 
116
Q_DECLARE_METATYPE(QList<PlaylistItemPtr>)
 
117
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::Options)
165
118
 
166
119
#endif // PLAYLISTITEM_H