Marble

CacheStoragePolicy.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
4//
5
6// Own
7#include "CacheStoragePolicy.h"
8
9// Qt
10#include <QDir>
11
12using namespace Marble;
13
14CacheStoragePolicy::CacheStoragePolicy(const QString &cacheDirectory)
15 : m_cache(cacheDirectory)
16{
17 if (!QDir(cacheDirectory).exists())
18 QDir::root().mkpath(cacheDirectory);
19}
20
21CacheStoragePolicy::~CacheStoragePolicy() = default;
22
23bool CacheStoragePolicy::fileExists(const QString &fileName) const
24{
25 return m_cache.exists(fileName);
26}
27
28bool CacheStoragePolicy::updateFile(const QString &fileName, const QByteArray &data)
29{
30 if (!m_cache.insert(fileName, data)) {
31 m_errorMsg = QObject::tr("Unable to insert data into cache");
32 return false;
33 }
34
35 return true;
36}
37
38void CacheStoragePolicy::clearCache()
39{
40 m_cache.clear();
41}
42
43QString CacheStoragePolicy::lastErrorMessage() const
44{
45 return m_errorMsg;
46}
47
48QByteArray CacheStoragePolicy::data(const QString &fileName)
49{
50 QByteArray data;
51 m_cache.find(fileName, data);
52
53 return data;
54}
55
56void CacheStoragePolicy::setCacheLimit(quint64 bytes)
57{
58 m_cache.setCacheLimit(bytes);
59}
60
61quint64 CacheStoragePolicy::cacheLimit() const
62{
63 return m_cache.cacheLimit();
64}
65
66#include "moc_CacheStoragePolicy.cpp"
KIOCORE_EXPORT MkpathJob * mkpath(const QUrl &url, const QUrl &baseUrl=QUrl(), JobFlags flags=DefaultFlags)
Binds a QML item to a specific geodetic location in screen coordinates.
QDir root()
QString tr(const char *sourceText, const char *disambiguation, int n)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.