konq_historymgr.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; see the file COPYING. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KONQ_HISTORY_H 00021 #define KONQ_HISTORY_H 00022 00023 #include <tqdatastream.h> 00024 #include <tqfile.h> 00025 #include <tqptrlist.h> 00026 #include <tqobject.h> 00027 #include <tqmap.h> 00028 #include <tqtimer.h> 00029 00030 #include <dcopobject.h> 00031 00032 #include <kcompletion.h> 00033 #include <kurl.h> 00034 #include <tdeparts/historyprovider.h> 00035 00036 #include "konq_historycomm.h" 00037 00038 #include <libkonq_export.h> 00039 00040 class TDECompletion; 00041 00042 00043 typedef TQPtrList<KonqHistoryEntry> KonqBaseHistoryList; 00044 typedef TQPtrListIterator<KonqHistoryEntry> KonqHistoryIterator; 00045 00046 class LIBKONQ_EXPORT KonqHistoryList : public KonqBaseHistoryList 00047 { 00048 public: 00054 KonqHistoryEntry * findEntry( const KURL& url ); 00055 00056 protected: 00060 virtual int compareItems( TQPtrCollection::Item, TQPtrCollection::Item ); 00061 }; 00062 00063 00065 00066 00074 class LIBKONQ_EXPORT KonqHistoryManager : public KParts::HistoryProvider, 00075 public KonqHistoryComm 00076 { 00077 Q_OBJECT 00078 00079 public: 00080 static KonqHistoryManager *kself() { 00081 return static_cast<KonqHistoryManager*>( KParts::HistoryProvider::self() ); 00082 } 00083 00084 KonqHistoryManager( TQObject *parent, const char *name ); 00085 ~KonqHistoryManager(); 00086 00094 void emitSetMaxCount( TQ_UINT32 count ); 00095 00105 void emitSetMaxAge( TQ_UINT32 days ); 00106 00113 void emitRemoveFromHistory( const KURL& url ); 00114 00121 void emitRemoveFromHistory( const KURL::List& urls ); 00122 00126 TQ_UINT32 maxCount() const { return m_maxCount; } 00127 00131 TQ_UINT32 maxAge() const { return m_maxAgeDays; } 00132 00150 void addPending( const KURL& url, const TQString& typedURL = TQString::null, 00151 const TQString& title = TQString::null ); 00152 00156 void confirmPending( const KURL& url, 00157 const TQString& typedURL = TQString::null, 00158 const TQString& title = TQString::null ); 00159 00164 void removePending( const KURL& url ); 00165 00169 TDECompletion * completionObject() const { return m_pCompletion; } 00170 00175 const KonqHistoryList& entries() const { return m_history; } 00176 00177 // HistoryProvider interfae, let konq handle this 00184 virtual void insert( const TQString& ); 00185 virtual void remove( const TQString& ) {} 00186 virtual void clear() {} 00187 00188 00189 public slots: 00193 bool loadHistory(); 00194 00198 bool saveHistory(); 00199 00205 void emitClear(); 00206 00207 00208 signals: 00212 void loadingFinished(); 00213 00217 void entryAdded( const KonqHistoryEntry *entry ); 00218 00224 void entryRemoved( const KonqHistoryEntry *entry ); 00225 00226 protected: 00231 void adjustSize(); 00232 00237 inline bool isExpired( KonqHistoryEntry *entry ) { 00238 return (entry && m_maxAgeDays > 0 && entry->lastVisited < 00239 TQDateTime(TQDate::currentDate().addDays( -m_maxAgeDays ))); 00240 } 00241 00245 void emitAddToHistory( const KonqHistoryEntry& entry ); 00246 00256 virtual void notifyHistoryEntry( KonqHistoryEntry e, TQCString saveId ); 00257 00262 virtual void notifyMaxCount( TQ_UINT32 count, TQCString saveId ); 00263 00268 virtual void notifyMaxAge( TQ_UINT32 days, TQCString saveId ); 00269 00273 virtual void notifyClear( TQCString saveId ); 00274 00279 virtual void notifyRemove( KURL url, TQCString saveId ); 00280 00285 virtual void notifyRemove( KURL::List urls, TQCString saveId ); 00286 00290 virtual TQStringList allURLs() const; 00291 00303 void addToHistory( bool pending, const KURL& url, 00304 const TQString& typedURL = TQString::null, 00305 const TQString& title = TQString::null ); 00306 00307 00313 virtual bool filterOut( const KURL& url ); 00314 00315 void addToUpdateList( const TQString& url ) { 00316 m_updateURLs.append( url ); 00317 m_updateTimer->start( 500, true ); 00318 } 00319 00325 TQStringList m_updateURLs; 00326 00327 private slots: 00332 void slotEmitUpdated(); 00333 00334 private: 00338 bool isSenderOfBroadcast(); 00339 00340 void clearPending(); 00347 KonqHistoryEntry * findEntry( const KURL& url ); 00348 00353 bool loadFallback(); 00354 KonqHistoryEntry * createFallbackEntry( const TQString& ) const; 00355 00356 void addToCompletion( const TQString& url, const TQString& typedURL, int numberOfTimesVisited = 1 ); 00357 void removeFromCompletion( const TQString& url, const TQString& typedURL ); 00358 00359 TQString m_filename; 00360 KonqHistoryList m_history; 00361 00368 TQMap<TQString,KonqHistoryEntry*> m_pending; 00369 00370 TQ_UINT32 m_maxCount; // maximum of history entries 00371 TQ_UINT32 m_maxAgeDays; // maximum age of a history entry 00372 00373 TDECompletion *m_pCompletion; // the completion object we sync with 00374 00379 TQTimer *m_updateTimer; 00380 00381 static const TQ_UINT32 s_historyVersion; 00382 }; 00383 00384 00385 #endif // KONQ_HISTORY_H