1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-16 11:42:05 +01:00

Use a proper directory for spotify settings and add a couple more

callbacks.
This commit is contained in:
John Maguire 2011-11-24 13:40:05 +01:00
parent e32bb5cc89
commit d14bbeb7a5
5 changed files with 44 additions and 2 deletions

View File

@ -28,6 +28,8 @@
int main(int argc, char** argv) {
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("Clementine");
QCoreApplication::setOrganizationName("Clementine");
QCoreApplication::setOrganizationDomain("clementine-player.org");
logging::Init();

View File

@ -4,6 +4,8 @@
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QSettings>
namespace utilities {
@ -31,4 +33,13 @@ QString GetCacheDirectory() {
return user_cache + "/" + QCoreApplication::applicationName() + "/spotify-cache";
}
QString GetSettingsDirectory() {
QSettings settings;
QString file_name = settings.fileName();
QFileInfo info(file_name);
QDir dir = info.dir();
dir.mkdir("spotify-settings");
return info.absolutePath() + "/spotify-settings";
}
} // namespace utilities

View File

@ -10,6 +10,8 @@ QString GetUserCacheDirectory();
// Get the path for Clementine's cache.
QString GetCacheDirectory();
QString GetSettingsDirectory();
}
#endif

View File

@ -60,6 +60,10 @@ SpotifyClient::SpotifyClient(QObject* parent)
spotify_callbacks_.end_of_track = &EndOfTrackCallback;
spotify_callbacks_.streaming_error = &StreamingErrorCallback;
spotify_callbacks_.offline_status_updated = &OfflineStatusUpdatedCallback;
spotify_callbacks_.connection_error = &ConnectionErrorCallback;
spotify_callbacks_.message_to_user = &UserMessageCallback;
spotify_callbacks_.get_audio_buffer_stats = &GetAudioBufferStatsCallback;
playlistcontainer_callbacks_.container_loaded = &PlaylistContainerLoadedCallback;
playlistcontainer_callbacks_.playlist_added = &PlaylistAddedCallback;
@ -72,10 +76,12 @@ SpotifyClient::SpotifyClient(QObject* parent)
QString cache = utilities::GetCacheDirectory();
qLog(Debug) << "Using:" << cache << "for Spotify cache";
QString settings_dir = utilities::GetSettingsDirectory();
qLog(Debug) << "Using:" << settings_dir << "for Spotify settings";
spotify_config_.api_version = SPOTIFY_API_VERSION; // From libspotify/api.h
spotify_config_.cache_location = strdup(cache.toLocal8Bit().constData());
spotify_config_.settings_location = strdup(QDir::tempPath().toLocal8Bit().constData());
spotify_config_.cache_location = strdup(cache.toUtf8().constData());
spotify_config_.settings_location = strdup(settings_dir.toUtf8().constData());
spotify_config_.application_key = api_key_.constData();
spotify_config_.application_key_size = api_key_.size();
spotify_config_.callbacks = &spotify_callbacks_;
@ -694,6 +700,22 @@ void SpotifyClient::StreamingErrorCallback(sp_session* session, sp_error error)
me->SendPlaybackError(QString::fromUtf8(sp_error_message(error)));
}
void SpotifyClient::ConnectionErrorCallback(sp_session* session, sp_error error) {
qLog(Debug) << Q_FUNC_INFO << sp_error_message(error);
}
void SpotifyClient::UserMessageCallback(sp_session* session, const char* message) {
qLog(Debug) << Q_FUNC_INFO << message;
}
void SpotifyClient::GetAudioBufferStatsCallback(
sp_session* session,
sp_audio_buffer_stats* stats) {
SpotifyClient* me = reinterpret_cast<SpotifyClient*>(sp_session_userdata(session));
stats->stutter = 0;
stats->samples = me->media_socket_ ? me->media_socket_->bytesToWrite() / 2 : 0;
}
void SpotifyClient::OfflineStatusUpdatedCallback(sp_session* session) {
SpotifyClient* me = reinterpret_cast<SpotifyClient*>(sp_session_userdata(session));
sp_playlistcontainer* container = sp_session_playlistcontainer(session);

View File

@ -70,6 +70,11 @@ private:
static void SP_CALLCONV EndOfTrackCallback(sp_session* session);
static void SP_CALLCONV StreamingErrorCallback(sp_session* session, sp_error error);
static void SP_CALLCONV OfflineStatusUpdatedCallback(sp_session* session);
static void SP_CALLCONV ConnectionErrorCallback(sp_session* session, sp_error error);
static void SP_CALLCONV UserMessageCallback(sp_session* session, const char* message);
static void SP_CALLCONV GetAudioBufferStatsCallback(
sp_session* session,
sp_audio_buffer_stats* stats);
// Spotify playlist container callbacks.
static void SP_CALLCONV PlaylistAddedCallback(