File indexing completed on 2023-05-30 09:09:52
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 2000 Waldo Bastian <bastian@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 #ifndef __khtml_pagecache_h__ 0021 #define __khtml_pagecache_h__ 0022 0023 #include <QObject> 0024 0025 class KHTMLPageCachePrivate; 0026 0027 /** 0028 * Singleton Object that handles a binary cache on top of 0029 * the http cache management of kio. 0030 * 0031 * A limited number of HTML pages are stored in this cache. This 0032 * cache is used for the history and operations like "view source". 0033 * These operations always want to use the original document and 0034 * don't want to fetch the data from the network again. 0035 * 0036 * It operates completely independent from the kio_http cache. 0037 */ 0038 class KHTMLPageCache : public QObject 0039 { 0040 Q_OBJECT 0041 public: 0042 /** 0043 * static "constructor". 0044 * @return returns a pointer to the cache, if it exists. 0045 * creates a new cache otherwise. 0046 */ 0047 static KHTMLPageCache *self(); 0048 ~KHTMLPageCache(); 0049 0050 /** 0051 * Create a new cache entry. 0052 * 0053 * @return a cache entry ID is returned. 0054 */ 0055 long createCacheEntry(); 0056 0057 /** 0058 * Add @p data to the cache entry with id @p id. 0059 */ 0060 void addData(long id, const QByteArray &data); 0061 0062 /** 0063 * Signal end of data for the cache entry with id @p id. 0064 * After calling this the entry is marked complete 0065 */ 0066 void endData(long id); 0067 0068 /** 0069 * Cancel the entry. 0070 */ 0071 void cancelEntry(long id); 0072 0073 /** 0074 * @return true when the cache entry with id @p is still valid, 0075 * and at least some of the data is available for reading (the 0076 * complete data may not yet be loaded) 0077 */ 0078 bool isValid(long id); 0079 0080 /** 0081 * @return true when the cache entry with id @p is still valid, 0082 * and the complete data is available for reading 0083 */ 0084 bool isComplete(long id); 0085 0086 /** 0087 * Fetch data for cache entry @p id and send it to slot @p recvSlot 0088 * in the object @p recvObj 0089 */ 0090 void fetchData(long id, QObject *recvObj, const char *recvSlot); 0091 0092 /** 0093 * Cancel sending data to @p recvObj 0094 */ 0095 void cancelFetch(QObject *recvObj); 0096 0097 public Q_SLOTS: 0098 /** 0099 * Save the data of cache entry @p id to the datastream @p str 0100 */ 0101 void saveData(long id, QDataStream *str); 0102 0103 private Q_SLOTS: 0104 void sendData(); 0105 0106 private: 0107 KHTMLPageCache(); 0108 0109 KHTMLPageCachePrivate *const d; 0110 0111 friend class KHTMLPageCacheSingleton; 0112 }; 0113 0114 class QIODevice; 0115 class KHTMLPageCacheDelivery : public QObject 0116 { 0117 friend class KHTMLPageCache; 0118 Q_OBJECT 0119 public: 0120 KHTMLPageCacheDelivery(QIODevice *_file): file(_file) {} 0121 ~KHTMLPageCacheDelivery(); 0122 0123 Q_SIGNALS: 0124 void emitData(const QByteArray &data); 0125 0126 public: 0127 QObject *recvObj; 0128 QIODevice *file; 0129 }; 0130 0131 #endif