diff --git a/spotifyblob/blob/CMakeLists.txt b/spotifyblob/blob/CMakeLists.txt index e24d929b0..c30612de5 100644 --- a/spotifyblob/blob/CMakeLists.txt +++ b/spotifyblob/blob/CMakeLists.txt @@ -12,6 +12,7 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(SOURCES main.cpp spotifyclient.cpp + spotify_utilities.cpp ${CMAKE_SOURCE_DIR}/src/core/logging.cpp ) diff --git a/spotifyblob/blob/main.cpp b/spotifyblob/blob/main.cpp index da02d2749..5bd9498bb 100644 --- a/spotifyblob/blob/main.cpp +++ b/spotifyblob/blob/main.cpp @@ -27,6 +27,7 @@ int main(int argc, char** argv) { QCoreApplication a(argc, argv); + QCoreApplication::setApplicationName("Clementine"); logging::Init(); diff --git a/spotifyblob/blob/spotify_utilities.cpp b/spotifyblob/blob/spotify_utilities.cpp new file mode 100644 index 000000000..6c72e44ce --- /dev/null +++ b/spotifyblob/blob/spotify_utilities.cpp @@ -0,0 +1,32 @@ +#include "spotify_utilities.h" + +#include + +#include +#include + +namespace utilities { + +QString GetUserCacheDirectory() { +#ifndef Q_OS_WINDOWS + const char* xdg_cache_dir = getenv("XDG_CACHE_HOME"); + if (!xdg_cache_dir) { + return QDir::homePath() + "/.config"; + } + return QString::fromLocal8Bit(xdg_cache_dir); + +#else + const char* cache_dir = getenv("APPDATA"); + if (!cache_dir) { + return QDir::homePath() + "/.config/"; + } + return QDir::fromNativeSeparators(QString::fromLocal8Bit(cache_dir)); +#endif +} + +QString GetCacheDirectory() { + QString user_cache = GetUserCacheDirectory(); + return user_cache + "/" + QCoreApplication::applicationName() + "/spotify-cache"; +} + +} // namespace utilities diff --git a/spotifyblob/blob/spotify_utilities.h b/spotifyblob/blob/spotify_utilities.h new file mode 100644 index 000000000..37265d0c8 --- /dev/null +++ b/spotifyblob/blob/spotify_utilities.h @@ -0,0 +1,12 @@ +#ifndef SPOTIFY_UTILITIES_H +#define SPOTIFY_UTILITIES_H + +#include + +namespace utilities { + +QString GetCacheDirectory(); + +} + +#endif diff --git a/spotifyblob/blob/spotifyclient.cpp b/spotifyblob/blob/spotifyclient.cpp index 63cb97727..3326e2fb3 100644 --- a/spotifyblob/blob/spotifyclient.cpp +++ b/spotifyblob/blob/spotifyclient.cpp @@ -23,6 +23,7 @@ #include "spotifykey.h" #include "spotifymessagehandler.h" #include "spotifymessages.pb.h" +#include "spotify_utilities.h" #include "core/logging.h" #include @@ -67,8 +68,11 @@ SpotifyClient::SpotifyClient(QObject* parent) load_playlist_callbacks_.playlist_state_changed = &PlaylistStateChangedForLoadPlaylist; + QString cache = utilities::GetCacheDirectory(); + qLog(Debug) << "Using:" << cache << "for Spotify cache"; + spotify_config_.api_version = SPOTIFY_API_VERSION; // From libspotify/api.h - spotify_config_.cache_location = strdup(QDir::tempPath().toLocal8Bit().constData()); + spotify_config_.cache_location = strdup(cache.toLocal8Bit().constData()); spotify_config_.settings_location = strdup(QDir::tempPath().toLocal8Bit().constData()); spotify_config_.application_key = api_key_.constData(); spotify_config_.application_key_size = api_key_.size();