Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QNetworkDiskCachePrivate Class Reference

#include <qnetworkdiskcache_p.h>

Inheritance diagram for QNetworkDiskCachePrivate:
QAbstractNetworkCachePrivate QObjectPrivate QObjectData

Public Functions

QString cacheFileName (const QUrl &url) const
 Generates fully qualified path of cached resource from a URL. More...
 
void prepareLayout ()
 Create subdirectories and other housekeeping on the filesystem. More...
 
 QNetworkDiskCachePrivate ()
 
bool removeFile (const QString &file)
 Put all of the misc file removing into one function to be extra safe. More...
 
void storeItem (QCacheItem *item)
 
QString tmpCacheFileName () const
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static quint32 crc32 (const char *data, uint len)
 
static QString uniqueFileName (const QUrl &url)
 Given a URL, generates a unique enough filename (and subdirectory) More...
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QString cacheDirectory
 
qint64 currentCacheSize
 
QString dataDirectory
 
QHash< QIODevice *, QCacheItem * > inserting
 
QCacheItem lastItem
 
qint64 maximumCacheSize
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 98 of file qnetworkdiskcache_p.h.

Constructors and Destructors

◆ QNetworkDiskCachePrivate()

QNetworkDiskCachePrivate::QNetworkDiskCachePrivate ( )
inline

Functions

◆ cacheFileName()

QString QNetworkDiskCachePrivate::cacheFileName ( const QUrl url) const

Generates fully qualified path of cached resource from a URL.

Definition at line 626 of file qnetworkdiskcache.cpp.

627 {
628  if (!url.isValid())
629  return QString();
630 
631  QString fullpath = dataDirectory + uniqueFileName(url);
632  return fullpath;
633 }
static QString uniqueFileName(const QUrl &url)
Given a URL, generates a unique enough filename (and subdirectory)
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ crc32()

static quint32 QNetworkDiskCachePrivate::crc32 ( const char *  data,
uint  len 
)
static

◆ prepareLayout()

void QNetworkDiskCachePrivate::prepareLayout ( )

Create subdirectories and other housekeeping on the filesystem.

Prevents too many files from being present in any single directory.

Definition at line 260 of file qnetworkdiskcache.cpp.

261 {
262  QDir helper;
264 
265  //Create directory and subdirectories 0-F
266  helper.mkpath(dataDirectory);
267  for (uint i = 0; i < 16 ; i++) {
268  QString str = QString::number(i, 16);
269  QString subdir = dataDirectory + str;
270  helper.mkdir(subdir);
271  }
272 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
Definition: qdir.cpp:1477
bool mkdir(const QString &dirName) const
Creates a sub-directory called dirName.
Definition: qdir.cpp:1424
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define PREPARED_SLASH
unsigned int uint
Definition: qglobal.h:996

◆ removeFile()

bool QNetworkDiskCachePrivate::removeFile ( const QString file)

Put all of the misc file removing into one function to be extra safe.

Definition at line 346 of file qnetworkdiskcache.cpp.

Referenced by QNetworkDiskCache::fileMetaData().

347 {
348 #if defined(QNETWORKDISKCACHE_DEBUG)
349  qDebug() << "QNetworkDiskCache::removFile()" << file;
350 #endif
351  if (file.isEmpty())
352  return false;
353  QFileInfo info(file);
354  QString fileName = info.fileName();
355  if (!fileName.endsWith(CACHE_POSTFIX))
356  return false;
357  qint64 size = info.size();
358  if (QFile::remove(file)) {
359  currentCacheSize -= size;
360  return true;
361  }
362  return false;
363 }
static mach_timebase_info_data_t info
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
__int64 qint64
Definition: qglobal.h:942
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
static QString fileName(const QString &fileUrl)
#define CACHE_POSTFIX

◆ storeItem()

void QNetworkDiskCachePrivate::storeItem ( QCacheItem item)

Definition at line 275 of file qnetworkdiskcache.cpp.

276 {
278  Q_ASSERT(cacheItem->metaData.saveToDisk());
279 
280  QString fileName = cacheFileName(cacheItem->metaData.url());
281  Q_ASSERT(!fileName.isEmpty());
282 
283  if (QFile::exists(fileName)) {
284  if (!QFile::remove(fileName)) {
285  qWarning() << "QNetworkDiskCache: couldn't remove the cache file " << fileName;
286  return;
287  }
288  }
289 
290  if (currentCacheSize > 0)
291  currentCacheSize += 1024 + cacheItem->size();
292  currentCacheSize = q->expire();
293  if (!cacheItem->file) {
294  QString templateName = tmpCacheFileName();
295  cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data);
296  if (cacheItem->file->open()) {
297  cacheItem->writeHeader(cacheItem->file);
298  cacheItem->writeCompressedData(cacheItem->file);
299  }
300  }
301 
302  if (cacheItem->file
303  && cacheItem->file->isOpen()
304  && cacheItem->file->error() == QFile::NoError) {
305  cacheItem->file->setAutoRemove(false);
306  // ### use atomic rename rather then remove & rename
307  if (cacheItem->file->rename(fileName))
308  currentCacheSize += cacheItem->file->size();
309  else
310  cacheItem->file->setAutoRemove(true);
311  }
312  if (cacheItem->metaData.url() == lastItem.metaData.url())
313  lastItem.reset();
314 }
The QTemporaryFile class is an I/O device that operates on temporary files.
The QNetworkDiskCache class provides a very basic disk cache.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString cacheFileName(const QUrl &url) const
Generates fully qualified path of cached resource from a URL.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
QUrl url() const
Returns the URL this network cache meta data is referring to.
#define Q_Q(Class)
Definition: qglobal.h:2483
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
QNetworkCacheMetaData metaData
Q_CORE_EXPORT void qWarning(const char *,...)
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
static QString fileName(const QString &fileUrl)

◆ tmpCacheFileName()

QString QNetworkDiskCachePrivate::tmpCacheFileName ( ) const

Definition at line 617 of file qnetworkdiskcache.cpp.

618 {
619  //The subdirectory is presumed to be already read for use.
621 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define PREPARED_SLASH
#define CACHE_POSTFIX

◆ uniqueFileName()

QString QNetworkDiskCachePrivate::uniqueFileName ( const QUrl url)
static

Given a URL, generates a unique enough filename (and subdirectory)

Definition at line 599 of file qnetworkdiskcache.cpp.

Referenced by QCacheItem::read().

600 {
601  QUrl cleanUrl = url;
602  cleanUrl.setPassword(QString());
603  cleanUrl.setFragment(QString());
604 
606  hash.addData(cleanUrl.toEncoded());
607  // convert sha1 to base36 form and return first 8 bytes for use as string
608  QByteArray id = QByteArray::number(*(qlonglong*)hash.result().data(), 36).left(8);
609  // generates <one-char subdir>/<8-char filname.d>
610  uint code = (uint)id.at(id.length()-1) % 16;
611  QString pathFragment = QString::number(code, 16) + QLatin1Char('/')
613 
614  return pathFragment;
615 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
#define at(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
unsigned int uint
Definition: qglobal.h:996
void setFragment(const QString &fragment)
Sets the fragment of the URL to fragment.
Definition: qurl.cpp:5669
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
qint64 qlonglong
Definition: qglobal.h:951
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define CACHE_POSTFIX
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void setPassword(const QString &password)
Sets the URL&#39;s password to password.
Definition: qurl.cpp:4736
The QCryptographicHash class provides a way to generate cryptographic hashes.

Properties

◆ cacheDirectory

QString QNetworkDiskCachePrivate::cacheDirectory

Definition at line 116 of file qnetworkdiskcache_p.h.

◆ currentCacheSize

qint64 QNetworkDiskCachePrivate::currentCacheSize

Definition at line 119 of file qnetworkdiskcache_p.h.

◆ dataDirectory

QString QNetworkDiskCachePrivate::dataDirectory

Definition at line 117 of file qnetworkdiskcache_p.h.

◆ inserting

QHash<QIODevice*, QCacheItem*> QNetworkDiskCachePrivate::inserting

Definition at line 121 of file qnetworkdiskcache_p.h.

◆ lastItem

QCacheItem QNetworkDiskCachePrivate::lastItem
mutable

Definition at line 115 of file qnetworkdiskcache_p.h.

◆ maximumCacheSize

qint64 QNetworkDiskCachePrivate::maximumCacheSize

Definition at line 118 of file qnetworkdiskcache_p.h.


The documentation for this class was generated from the following files: