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

« back to all changes in this revision

Viewing changes to src/radio/lastfmservice.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:
1
 
/* This file is part of Clementine.
2
 
   Copyright 2010, David Sansome <me@davidsansome.com>
3
 
 
4
 
   Clementine is free software: you can redistribute it and/or modify
5
 
   it under the terms of the GNU General Public License as published by
6
 
   the Free Software Foundation, either version 3 of the License, or
7
 
   (at your option) any later version.
8
 
 
9
 
   Clementine is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
   GNU General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU General Public License
15
 
   along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16
 
*/
17
 
 
18
 
#ifndef LASTFMSERVICE_H
19
 
#define LASTFMSERVICE_H
20
 
 
21
 
namespace lastfm {
22
 
class RadioStation;
23
 
class Track;
24
 
}
25
 
 
26
 
#include <QtGlobal>
27
 
uint qHash(const lastfm::Track& track);
28
 
 
29
 
#include "fixlastfm.h"
30
 
#include <lastfm/Track>
31
 
#include <lastfm/ws.h>
32
 
 
33
 
#include "radiomodel.h"
34
 
#include "radioservice.h"
35
 
#include "lastfmstationdialog.h"
36
 
#include "core/song.h"
37
 
#include "playlist/playlistitem.h"
38
 
 
39
 
#include <QMap>
40
 
#include <QMenu>
41
 
#include <QQueue>
42
 
 
43
 
#include <boost/scoped_ptr.hpp>
44
 
 
45
 
class QAction;
46
 
 
47
 
class QNetworkAccessManager;
48
 
 
49
 
class LastFMService : public RadioService {
50
 
  Q_OBJECT
51
 
 
52
 
 public:
53
 
  LastFMService(RadioModel* parent);
54
 
  ~LastFMService();
55
 
 
56
 
  static const char* kServiceName;
57
 
  static const char* kSettingsGroup;
58
 
  static const char* kAudioscrobblerClientId;
59
 
  static const char* kApiKey;
60
 
  static const char* kSecret;
61
 
 
62
 
  static const char* kUrlArtist;
63
 
  static const char* kUrlTag;
64
 
  static const char* kUrlCustom;
65
 
 
66
 
  static const char* kTitleArtist;
67
 
  static const char* kTitleTag;
68
 
  static const char* kTitleCustom;
69
 
 
70
 
  enum ItemType {
71
 
    Type_Root = RadioModel::TypeCount,
72
 
    Type_Artists,
73
 
    Type_Tags,
74
 
    Type_Custom,
75
 
    Type_Friends,
76
 
    Type_Neighbours,
77
 
    Type_OtherUser,
78
 
  };
79
 
 
80
 
  // RadioService
81
 
  QStandardItem* CreateRootItem();
82
 
  void LazyPopulate(QStandardItem* parent);
83
 
 
84
 
  void ShowContextMenu(const QModelIndex& index, const QPoint &global_pos);
85
 
 
86
 
  PlaylistItem::SpecialLoadResult StartLoading(const QUrl& url);
87
 
  PlaylistItem::SpecialLoadResult LoadNext(const QUrl& url);
88
 
 
89
 
  PlaylistItem::Options playlistitem_options() const;
90
 
 
91
 
  void ReloadSettings();
92
 
 
93
 
  virtual QString Icon() { return ":last.fm/lastfm.png"; }
94
 
 
95
 
  // Last.fm specific stuff
96
 
  bool IsAuthenticated() const;
97
 
  bool IsScrobblingEnabled() const { return scrobbling_enabled_; }
98
 
  bool AreButtonsVisible() const { return buttons_visible_; }
99
 
 
100
 
  void Authenticate(const QString& username, const QString& password);
101
 
  void SignOut();
102
 
 
103
 
  void FetchMoreTracks();
104
 
 
105
 
  PlaylistItemPtr PlaylistItemForUrl(const QUrl& url);
106
 
 
107
 
 public slots:
108
 
  void NowPlaying(const Song& song);
109
 
  void Scrobble();
110
 
  void Love();
111
 
  void Ban();
112
 
  void ShowConfig();
113
 
 
114
 
 signals:
115
 
  void AuthenticationComplete(bool success);
116
 
  void ScrobblingEnabledChanged(bool value);
117
 
  void ButtonVisibilityChanged(bool value);
118
 
 
119
 
 protected:
120
 
  QModelIndex GetCurrentIndex();
121
 
 
122
 
 private slots:
123
 
  void AuthenticateReplyFinished();
124
 
  void RefreshFriendsFinished();
125
 
  void RefreshNeighboursFinished();
126
 
 
127
 
  void TunerTrackAvailable();
128
 
  void TunerError(lastfm::ws::Error error);
129
 
 
130
 
  void AddArtistRadio();
131
 
  void AddTagRadio();
132
 
  void AddCustomRadio();
133
 
  void Remove();
134
 
 
135
 
  // Radio tuner.
136
 
  void FetchMoreTracksFinished();
137
 
  void TuneFinished();
138
 
 
139
 
  void StreamMetadataReady();
140
 
 
141
 
 private:
142
 
  QStandardItem* CreateStationItem(QStandardItem* parent,
143
 
      const QString& name, const QString& icon, const QString& url,
144
 
      const QString& title);
145
 
  QString ErrorString(lastfm::ws::Error error) const;
146
 
  bool InitScrobbler();
147
 
  lastfm::Track TrackFromSong(const Song& song) const;
148
 
  void RefreshFriends();
149
 
  void RefreshNeighbours();
150
 
  void AddArtistOrTag(const QString& name,
151
 
                      LastFMStationDialog::Type dialog_type,
152
 
                      const QString& url_pattern,
153
 
                      const QString& title_pattern,
154
 
                      const QString& icon, QStandardItem* list);
155
 
  void SaveList(const QString& name, QStandardItem* list) const;
156
 
  void RestoreList(const QString& name,
157
 
                   const QString& url_pattern,
158
 
                   const QString& title_pattern,
159
 
                   const QIcon& icon, QStandardItem* parent);
160
 
 
161
 
  static QUrl FixupUrl(const QUrl& url);
162
 
  void Tune(const lastfm::RadioStation& station);
163
 
 
164
 
  void AddSelectedToPlaylist(bool clear_first);
165
 
 
166
 
 private:
167
 
  lastfm::Audioscrobbler* scrobbler_;
168
 
  lastfm::Track last_track_;
169
 
  lastfm::Track next_metadata_;
170
 
  QQueue<lastfm::Track> playlist_;
171
 
 
172
 
  boost::scoped_ptr<LastFMStationDialog> station_dialog_;
173
 
 
174
 
  boost::scoped_ptr<QMenu> context_menu_;
175
 
  QAction* remove_action_;
176
 
  QAction* add_artist_action_;
177
 
  QAction* add_tag_action_;
178
 
  QAction* add_custom_action_;
179
 
  QStandardItem* context_item_;
180
 
 
181
 
  QUrl last_url_;
182
 
  bool initial_tune_;
183
 
  int tune_task_id_;
184
 
 
185
 
  bool scrobbling_enabled_;
186
 
  bool buttons_visible_;
187
 
 
188
 
  QStandardItem* artist_list_;
189
 
  QStandardItem* tag_list_;
190
 
  QStandardItem* custom_list_;
191
 
  QStandardItem* friends_list_;
192
 
  QStandardItem* neighbours_list_;
193
 
 
194
 
  QHash<lastfm::Track, QString> art_urls_;
195
 
};
196
 
 
197
 
#endif // LASTFMSERVICE_H