Commit 17828b06 authored by Michael Pyne's avatar Michael Pyne

Finish cache port from KStandardDirs to QStandardPaths.

parent b3299530
......@@ -130,10 +130,7 @@ static void parsePlaylistStream(QDataStream &s, PlaylistCollection *collection)
void Cache::loadPlaylists(PlaylistCollection *collection) // static
{
const QString playlistsFile =
// Despite the 'Cache' class name, this data is not regenerable and so
// should not be stored in cache directory.
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/playlists";
const QString playlistsFile = playlistsCacheFileName();
QFile f(playlistsFile);
if(!f.open(QIODevice::ReadOnly))
......@@ -177,14 +174,7 @@ void Cache::loadPlaylists(PlaylistCollection *collection) // static
void Cache::savePlaylists(const PlaylistList &playlists)
{
QString dirName = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
QDir playlistDir(dirName);
if(!playlistDir.exists() && !playlistDir.mkpath(dirName)) {
qCWarning(JUK_LOG) << "Unable to create appdata dir" << dirName;
return;
}
QString playlistsFile = dirName + "/playlists";
QString playlistsFile = playlistsCacheFileName();
QSaveFile f(playlistsFile);
if(!f.open(QIODevice::WriteOnly)) {
......@@ -236,9 +226,30 @@ void Cache::savePlaylists(const PlaylistList &playlists)
qCCritical(JUK_LOG) << "Error saving collection:" << f.errorString();
}
void Cache::ensureAppDataStorageExists() // static
{
QString dirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
QDir appDataDir(dirPath);
if(!appDataDir.exists() && !appDataDir.mkpath(dirPath))
qCCritical(JUK_LOG) << "Unable to create appdata storage in" << dirPath;
}
bool Cache::cacheFileExists() // static
{
return QFile::exists(KGlobal::dirs()->saveLocation("appdata") + "cache");
return QFile::exists(fileHandleCacheFileName());
}
// Despite the 'Cache' class name, these data files are not regenerable and so
// should not be stored in cache directory.
QString Cache::fileHandleCacheFileName() // static
{
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/cache";
}
QString Cache::playlistsCacheFileName() // static
{
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/playlists";
}
////////////////////////////////////////////////////////////////////////////////
......@@ -252,9 +263,7 @@ Cache::Cache()
bool Cache::prepareToLoadCachedItems()
{
QString cacheFileName = KGlobal::dirs()->saveLocation("appdata") + "cache";
m_loadFile.setFileName(cacheFileName);
m_loadFile.setFileName(fileHandleCacheFileName());
if(!m_loadFile.open(QIODevice::ReadOnly))
return false;
......
......@@ -58,8 +58,12 @@ public:
static void loadPlaylists(PlaylistCollection *collection);
static void savePlaylists(const PlaylistList &playlists);
static void ensureAppDataStorageExists();
static bool cacheFileExists();
static QString fileHandleCacheFileName();
static QString playlistsCacheFileName();
bool prepareToLoadCachedItems();
FileHandle loadNextCachedItem();
......
......@@ -21,7 +21,6 @@
#include <kmenu.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kglobal.h>
#include <kactioncollection.h>
#include <kstandarddirs.h>
#include <ktoolbarpopupaction.h>
......@@ -239,10 +238,7 @@ void CollectionList::saveItemsToCache() const
{
qCDebug(JUK_LOG) << "Saving collection list to cache";
QString cacheFileName =
KGlobal::dirs()->saveLocation("appdata") + QLatin1String("cache");
QSaveFile f(cacheFileName);
QSaveFile f(Cache::fileHandleCacheFileName());
if(!f.open(QIODevice::WriteOnly)) {
qCCritical(JUK_LOG) << "Error saving cache:" << f.errorString();
......
......@@ -88,6 +88,8 @@ JuK::JuK(const QStringList &filesToOpen, QWidget *parent) :
readSettings();
Cache::ensureAppDataStorageExists();
if(m_showSplash && !m_startDocked && Cache::cacheFileExists()) {
if(SplashScreen* splash = SplashScreen::instance()) {
splash->show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment