void SpotifyServer::LoadImage(const QString& id) {
  pb::spotify::Message message;
  pb::spotify::ImageRequest* req = message.mutable_image_request();

  req->set_id(DataCommaSizeFromQString(id));
  SendOrQueueMessage(message);
}
void SpotifyServer::AlbumBrowse(const QString& uri) {
  pb::spotify::Message message;
  pb::spotify::BrowseAlbumRequest* req = message.mutable_browse_album_request();

  req->set_uri(DataCommaSizeFromQString(uri));
  SendOrQueueMessage(message);
}
void SpotifyServer::Seek(qint64 offset_nsec) {
  pb::spotify::Message message;
  pb::spotify::SeekRequest* req = message.mutable_seek_request();

  req->set_offset_nsec(offset_nsec);
  SendOrQueueMessage(message);
}
void SpotifyServer::StartPlayback(const QString& uri, quint16 port) {
  pb::spotify::Message message;
  pb::spotify::PlaybackRequest* req = message.mutable_playback_request();

  req->set_track_uri(DataCommaSizeFromQString(uri));
  req->set_media_port(port);
  SendOrQueueMessage(message);
}
void SpotifyServer::MessageArrived(const pb::spotify::Message& message) {
  if (message.has_login_response()) {
    const pb::spotify::LoginResponse& response = message.login_response();
    logged_in_ = response.success();

    if (response.success()) {
      // Send any messages that were queued before the client logged in
      for (const pb::spotify::Message& message : queued_messages_) {
        SendOrQueueMessage(message);
      }
      queued_messages_.clear();
    }

    emit LoginCompleted(response.success(),
                        QStringFromStdString(response.error()),
                        response.error_code());
  } else if (message.has_playlists_updated()) {
    emit PlaylistsUpdated(message.playlists_updated());
  } else if (message.has_load_playlist_response()) {
    const pb::spotify::LoadPlaylistResponse& response =
        message.load_playlist_response();

    switch (response.request().type()) {
      case pb::spotify::Inbox:
        emit InboxLoaded(response);
        break;

      case pb::spotify::Starred:
        emit StarredLoaded(response);
        break;

      case pb::spotify::UserPlaylist:
        emit UserPlaylistLoaded(response);
        break;
    }
  } else if (message.has_playback_error()) {
    emit PlaybackError(QStringFromStdString(message.playback_error().error()));
  } else if (message.has_search_response()) {
    emit SearchResults(message.search_response());
  } else if (message.has_image_response()) {
    const pb::spotify::ImageResponse& response = message.image_response();
    const QString id = QStringFromStdString(response.id());

    if (response.has_data()) {
      emit ImageLoaded(
          id, QImage::fromData(
                  QByteArray(response.data().data(), response.data().size())));
    } else {
      emit ImageLoaded(id, QImage());
    }
  } else if (message.has_sync_playlist_progress()) {
    emit SyncPlaylistProgress(message.sync_playlist_progress());
  } else if (message.has_browse_album_response()) {
    emit AlbumBrowseResults(message.browse_album_response());
  } else if (message.has_browse_toplist_response()) {
    emit ToplistBrowseResults(message.browse_toplist_response());
  }
}
void SpotifyServer::LoadToplist() {
  pb::spotify::Message message;
  pb::spotify::BrowseToplistRequest* req =
      message.mutable_browse_toplist_request();
  req->set_type(pb::spotify::BrowseToplistRequest::Tracks);
  req->set_region(pb::spotify::BrowseToplistRequest::Everywhere);

  SendOrQueueMessage(message);
}
void SpotifyServer::Search(const QString& text, int limit, int limit_album) {
  pb::spotify::Message message;
  pb::spotify::SearchRequest* req = message.mutable_search_request();

  req->set_query(DataCommaSizeFromQString(text));
  req->set_limit(limit);
  req->set_limit_album(limit_album);
  SendOrQueueMessage(message);
}
Beispiel #8
0
void SpotifyServer::NewConnection() {
  QTcpSocket* socket = server_->nextPendingConnection();
  SetDevice(socket);

  qLog(Info) << "Connection from port" << socket->peerPort();

  // Send any login messages that were queued before the client connected
  foreach (const pb::spotify::Message& message, queued_login_messages_) {
    SendOrQueueMessage(message);
  }
void SpotifyServer::SetPlaybackSettings(pb::spotify::Bitrate bitrate,
                                        bool volume_normalisation) {
  pb::spotify::Message message;

  pb::spotify::PlaybackSettings* request =
      message.mutable_set_playback_settings_request();
  request->set_bitrate(bitrate);
  request->set_volume_normalisation(volume_normalisation);

  SendOrQueueMessage(message);
}
void SpotifyServer::RemoveSongsFromPlaylist(
    int playlist_index, const QList<int>& songs_indices_to_remove) {
  pb::spotify::Message message;
  pb::spotify::RemoveTracksFromPlaylistRequest* req =
      message.mutable_remove_tracks_from_playlist();
  req->set_playlist_index(playlist_index);
  for (int song_index : songs_indices_to_remove) {
    req->add_track_index(song_index);
  }
  SendOrQueueMessage(message);
}
void SpotifyServer::AddSongsToPlaylist(int playlist_index,
                                       const QList<QUrl>& songs_urls) {
  pb::spotify::Message message;
  pb::spotify::AddTracksToPlaylistRequest* req =
      message.mutable_add_tracks_to_playlist();
  req->set_playlist_index(playlist_index);
  for (const QUrl& song_url : songs_urls) {
    req->add_track_uri(DataCommaSizeFromQString(song_url.toString()));
  }
  SendOrQueueMessage(message);
}
void SpotifyServer::LoadPlaylist(pb::spotify::PlaylistType type, int index) {
  pb::spotify::Message message;
  pb::spotify::LoadPlaylistRequest* req =
      message.mutable_load_playlist_request();

  req->set_type(type);
  if (index != -1) {
    req->set_user_playlist_index(index);
  }

  SendOrQueueMessage(message);
}
void SpotifyServer::SyncPlaylist(pb::spotify::PlaylistType type, int index,
                                 bool offline) {
  pb::spotify::Message message;
  pb::spotify::SyncPlaylistRequest* req =
      message.mutable_sync_playlist_request();
  req->mutable_request()->set_type(type);
  if (index != -1) {
    req->mutable_request()->set_user_playlist_index(index);
  }
  req->set_offline_sync(offline);

  SendOrQueueMessage(message);
}
void SpotifyServer::NewConnection() {
  QTcpSocket* socket = server_->nextPendingConnection();
  SetDevice(socket);

  qLog(Info) << "Connection from port" << socket->peerPort();

  // Send any login messages that were queued before the client connected
  for (const pb::spotify::Message& message : queued_login_messages_) {
    SendOrQueueMessage(message);
  }
  queued_login_messages_.clear();

  // Don't take any more connections from clients
  disconnect(server_, SIGNAL(newConnection()), this, 0);
}
void SpotifyServer::Login(const QString& username, const QString& password,
                          pb::spotify::Bitrate bitrate,
                          bool volume_normalisation) {
  pb::spotify::Message message;

  pb::spotify::LoginRequest* request = message.mutable_login_request();
  request->set_username(DataCommaSizeFromQString(username));
  if (!password.isEmpty()) {
    request->set_password(DataCommaSizeFromQString(password));
  }
  request->mutable_playback_settings()->set_bitrate(bitrate);
  request->mutable_playback_settings()->set_volume_normalisation(
      volume_normalisation);

  SendOrQueueMessage(message);
}
void SpotifyServer::SetPaused(const bool paused) {
  pb::spotify::Message message;
  pb::spotify::PauseRequest* req = message.mutable_pause_request();
  req->set_paused(paused);
  SendOrQueueMessage(message);
}