Store wikipedia language file in cache folder - as it really is just cached info

This commit is contained in:
craig.p.drummond
2014-01-10 20:05:54 +00:00
committed by craig.p.drummond
parent c20224d478
commit c6a62e5cc6
5 changed files with 27 additions and 10 deletions

View File

@@ -38,19 +38,34 @@
#include <QXmlStreamReader>
#include <QFile>
static const QString constFileName=QLatin1String("wikipedia-available.xml.gz");
static const QString constOldFileName=QLatin1String("wikipedia-available.xml.gz");
static const QString constFileName=QLatin1String("languages.xml.gz");
QString WikipediaSettings::constSubDir=QLatin1String("wikipedia");
static QString localeFile()
{
return Utils::dataDir(QString(), true)+constFileName;
return Utils::cacheDir(WikipediaSettings::constSubDir, true)+constFileName;
}
// Move files from previous ~/.config/cantata to ~/.local/share/cantata
// Move files from previous ~/.config/cantata or ~/.local/share/cantata to ~/.cache/cantata/wikipedia
static void moveToNewLocation()
{
#if !defined Q_OS_WIN && !defined Q_OS_MAC // Not required for windows - as already stored in data location!
// Can't reliable check version here, as migh tnot have opened the wiki settings before version was changed...
Utils::moveFile(Utils::configDir(QString())+constFileName, Utils::dataDir(QString(), true)+constFileName);
QString oldLocation1=Utils::configDir(QString())+constOldFileName;
QString oldLocation2=Utils::dataDir(QString())+constOldFileName;
QString newLocation=localeFile();
bool moved=false;
if (oldLocation2!=constOldFileName && QFile::exists(oldLocation2) && Utils::moveFile(oldLocation2, newLocation)) {
moved=true;
}
if (oldLocation1!=constOldFileName && QFile::exists(oldLocation1)) {
if (moved) {
QFile::remove(oldLocation1);
} else {
Utils::moveFile(oldLocation1, newLocation);
}
}
#endif
}

View File

@@ -63,6 +63,8 @@ class WikipediaSettings : public ToggleList
};
public:
static QString constSubDir;
WikipediaSettings(QWidget *p);
virtual ~WikipediaSettings();

View File

@@ -27,6 +27,7 @@
#include "albumview.h"
#include "songview.h"
#include "contextwidget.h"
#include "wikipediasettings.h"
#include "covers.h"
#include "musiclibrarymodel.h"
#include "utils.h"
@@ -274,6 +275,7 @@ CacheSettings::CacheSettings(QWidget *parent)
new CacheItem(i18n("Magnatune"), Utils::cacheDir("magnatune", false), QStringList() << "*"+MusicLibraryModel::constLibraryCompressedExt << "*.jpg" << "*.png", tree);
new CacheItem(i18n("Podcast Directories"), Utils::cacheDir(PodcastSearchDialog::constCacheDir, false), QStringList() << "*"+PodcastSearchDialog::constExt, tree);
#endif
new CacheItem(i18n("Wikipedia Languages"), Utils::cacheDir(WikipediaSettings::constSubDir, false), QStringList() << "*.xml.gz", tree);
for (int i=0; i<tree->topLevelItemCount(); ++i) {
connect(static_cast<CacheItem *>(tree->topLevelItem(i)), SIGNAL(updated()), this, SLOT(updateSpace()));

View File

@@ -657,11 +657,9 @@ QString Utils::cacheDir(const QString &sub, bool create)
#endif
}
void Utils::moveFile(const QString &from, const QString &to)
bool Utils::moveFile(const QString &from, const QString &to)
{
if (!from.isEmpty() && !to.isEmpty() && from!=to && QFile::exists(from) && !QFile::exists(to)) {
QFile::rename(from, to);
}
return !from.isEmpty() && !to.isEmpty() && from!=to && QFile::exists(from) && !QFile::exists(to) && QFile::rename(from, to);
}
void Utils::moveDir(const QString &from, const QString &to)

View File

@@ -98,7 +98,7 @@ namespace Utils
extern QString configDir(const QString &sub=QString(), bool create=false);
extern QString dataDir(const QString &sub=QString(), bool create=false);
extern QString cacheDir(const QString &sub=QString(), bool create=true);
extern void moveFile(const QString &from, const QString &to);
extern bool moveFile(const QString &from, const QString &to);
extern void moveDir(const QString &from, const QString &to);
extern void clearOldCache(const QString &sub, int maxAge);
extern void touchFile(const QString &fileName);