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

« back to all changes in this revision

Viewing changes to src/internet/spotifyservice.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
#ifndef SPOTIFYSERVICE_H
 
2
#define SPOTIFYSERVICE_H
 
3
 
 
4
#include "internetmodel.h"
 
5
#include "internetservice.h"
 
6
#include "spotifyblob/common/spotifymessages.pb.h"
 
7
 
 
8
#include <QProcess>
 
9
#include <QTimer>
 
10
 
 
11
#include <boost/shared_ptr.hpp>
 
12
 
 
13
class Playlist;
 
14
class SpotifyServer;
 
15
 
 
16
class QMenu;
 
17
 
 
18
class SpotifyService : public InternetService {
 
19
  Q_OBJECT
 
20
 
 
21
public:
 
22
  SpotifyService(InternetModel* parent);
 
23
  ~SpotifyService();
 
24
 
 
25
  enum Type {
 
26
    Type_SearchResults = InternetModel::TypeCount,
 
27
    Type_StarredPlaylist,
 
28
    Type_InboxPlaylist,
 
29
    Type_Track,
 
30
  };
 
31
 
 
32
  enum Role {
 
33
    Role_UserPlaylistIndex = InternetModel::RoleCount,
 
34
  };
 
35
 
 
36
  // Values are persisted - don't change.
 
37
  enum LoginState {
 
38
    LoginState_LoggedIn = 1,
 
39
    LoginState_Banned = 2,
 
40
    LoginState_BadCredentials = 3,
 
41
    LoginState_NoPremium = 4,
 
42
    LoginState_OtherError = 5,
 
43
    LoginState_ReloginFailed = 6
 
44
  };
 
45
 
 
46
  static const char* kServiceName;
 
47
  static const char* kSettingsGroup;
 
48
  static const char* kBlobDownloadUrl;
 
49
  static const int kSearchDelayMsec;
 
50
 
 
51
  void ReloadSettings();
 
52
 
 
53
  QStandardItem* CreateRootItem();
 
54
  void LazyPopulate(QStandardItem* parent);
 
55
  void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
 
56
  void ItemDoubleClicked(QStandardItem* item);
 
57
  PlaylistItem::Options playlistitem_options() const;
 
58
 
 
59
  void Logout();
 
60
  void Login(const QString& username, const QString& password);
 
61
  void Search(const QString& text, Playlist* playlist, bool now = false);
 
62
  Q_INVOKABLE void LoadImage(const QString& id);
 
63
 
 
64
  SpotifyServer* server() const;
 
65
 
 
66
  bool IsBlobInstalled() const;
 
67
  void InstallBlob();
 
68
 
 
69
  // Persisted in the settings and updated on each Login().
 
70
  LoginState login_state() const { return login_state_; }
 
71
  bool IsLoggedIn() const { return login_state_ == LoginState_LoggedIn; }
 
72
 
 
73
  static void SongFromProtobuf(const spotify_pb::Track& track, Song* song);
 
74
 
 
75
signals:
 
76
  void BlobStateChanged();
 
77
  void LoginFinished(bool success);
 
78
  void ImageLoaded(const QString& id, const QImage& image);
 
79
 
 
80
public slots:
 
81
  void ShowConfig();
 
82
 
 
83
protected:
 
84
  virtual QModelIndex GetCurrentIndex();
 
85
 
 
86
private:
 
87
  void StartBlobProcess();
 
88
  void FillPlaylist(QStandardItem* item, const spotify_pb::LoadPlaylistResponse& response);
 
89
  void EnsureMenuCreated();
 
90
 
 
91
  QStandardItem* PlaylistBySpotifyIndex(int index) const;
 
92
  bool DoPlaylistsDiffer(const spotify_pb::Playlists& response) const;
 
93
 
 
94
private slots:
 
95
  void EnsureServerCreated(const QString& username = QString(),
 
96
                           const QString& password = QString());
 
97
  void BlobProcessError(QProcess::ProcessError error);
 
98
  void LoginCompleted(bool success, const QString& error,
 
99
                      spotify_pb::LoginResponse_Error error_code);
 
100
  void PlaylistsUpdated(const spotify_pb::Playlists& response);
 
101
  void InboxLoaded(const spotify_pb::LoadPlaylistResponse& response);
 
102
  void StarredLoaded(const spotify_pb::LoadPlaylistResponse& response);
 
103
  void UserPlaylistLoaded(const spotify_pb::LoadPlaylistResponse& response);
 
104
  void SearchResults(const spotify_pb::SearchResponse& response);
 
105
  void SyncPlaylistProgress(const spotify_pb::SyncPlaylistProgress& progress);
 
106
 
 
107
  void OpenSearchTab();
 
108
  void DoSearch();
 
109
 
 
110
  void SyncPlaylist();
 
111
  void BlobDownloadFinished();
 
112
 
 
113
private:
 
114
  SpotifyServer* server_;
 
115
 
 
116
  QString system_blob_path_;
 
117
  QString local_blob_version_;
 
118
  QString local_blob_path_;
 
119
  QProcess* blob_process_;
 
120
 
 
121
  QStandardItem* root_;
 
122
  QStandardItem* search_;
 
123
  QStandardItem* starred_;
 
124
  QStandardItem* inbox_;
 
125
  QList<QStandardItem*> playlists_;
 
126
 
 
127
  int login_task_id_;
 
128
  QString pending_search_;
 
129
  Playlist* pending_search_playlist_;
 
130
 
 
131
  QMenu* context_menu_;
 
132
  QMenu* playlist_context_menu_;
 
133
  QAction* playlist_sync_action_;
 
134
  QModelIndex context_item_;
 
135
 
 
136
  QTimer* search_delay_;
 
137
 
 
138
  int inbox_sync_id_;
 
139
  int starred_sync_id_;
 
140
  QMap<int, int> playlist_sync_ids_;
 
141
 
 
142
  LoginState login_state_;
 
143
  spotify_pb::Bitrate bitrate_;
 
144
  bool volume_normalisation_;
 
145
};
 
146
 
 
147
#endif