Use a proper cache directory for spotify on windows and Linux.

This commit is contained in:
John Maguire 2011-07-07 14:54:22 +00:00
parent e4c8eee7d9
commit 712745c605
5 changed files with 51 additions and 1 deletions

View File

@ -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
)

View File

@ -27,6 +27,7 @@
int main(int argc, char** argv) {
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("Clementine");
logging::Init();

View File

@ -0,0 +1,32 @@
#include "spotify_utilities.h"
#include <stdlib.h>
#include <QCoreApplication>
#include <QDir>
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

View File

@ -0,0 +1,12 @@
#ifndef SPOTIFY_UTILITIES_H
#define SPOTIFY_UTILITIES_H
#include <QString>
namespace utilities {
QString GetCacheDirectory();
}
#endif

View File

@ -23,6 +23,7 @@
#include "spotifykey.h"
#include "spotifymessagehandler.h"
#include "spotifymessages.pb.h"
#include "spotify_utilities.h"
#include "core/logging.h"
#include <QCoreApplication>
@ -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();