[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/apps
From:       David Faure <faure () kde ! org>
Date:       2009-04-02 1:41:41
Message-ID: 1238636501.329343.2677.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 948035 by dfaure:

Extract a KonqHistoryLoader from KonqHistoryManager, with only the loading code. Me \
likes modularity. Made public in libkonq (but don't use it yet, it doesn't update \
later on, that might be done by another class). Moved KonqHistoryEntry back to \
libkonq too, but now with a cleaner API.


 M  +1 -2      konqueror/src/CMakeLists.txt  
 D             konqueror/src/konqhistoryentry.cpp  
 D             konqueror/src/konqhistoryentry.h  
 M  +32 -183   konqueror/src/konqhistorymanager.cpp  
 M  +13 -52    konqueror/src/konqhistorymanager.h  
 M  +1 -1      konqueror/src/konqhistorymodel.h  
 M  +11 -6     lib/konq/CMakeLists.txt  
 A             lib/konq/konq_historyentry.cpp   [License: LGPL (v2/3+eV)]
 A             lib/konq/konq_historyentry.h   [License: LGPL (v2/3+eV)]
 A             lib/konq/konq_historyloader.cpp   [License: LGPL (v2/3+eV)]
 A             lib/konq/konq_historyloader.h   [License: LGPL (v2/3+eV)]


--- trunk/KDE/kdebase/apps/konqueror/src/CMakeLists.txt #948034:948035
@@ -20,13 +20,12 @@
 set(konquerorprivate_SRCS
    konqpixmapprovider.cpp
    konqhistorymanager.cpp
-   konqhistoryentry.cpp
 )
 qt4_add_dbus_interface(konquerorprivate_SRCS \
${CMAKE_CURRENT_SOURCE_DIR}/../../lib/konq/favicons/org.kde.FavIcon.xml \
favicon_interface)  qt4_add_dbus_adaptor(konquerorprivate_SRCS \
org.kde.Konqueror.HistoryManager.xml konqhistorymanager.h KonqHistoryManager \
konqhistorymanageradaptor KonqHistoryManagerAdaptor)  
 kde4_add_library(konquerorprivate SHARED ${konquerorprivate_SRCS})
-target_link_libraries(konquerorprivate ${KDE4_KPARTS_LIBS} ${ZLIB_LIBRARY})
+target_link_libraries(konquerorprivate konq ${KDE4_KPARTS_LIBS} ${ZLIB_LIBRARY})
 set_target_properties(konquerorprivate PROPERTIES VERSION ${GENERIC_LIB_VERSION} \
SOVERSION ${GENERIC_LIB_SOVERSION} )  install(TARGETS konquerorprivate \
${INSTALL_TARGETS_DEFAULT_ARGS})  
--- trunk/KDE/kdebase/apps/konqueror/src/konqhistorymanager.cpp #948034:948035
@@ -20,6 +20,7 @@
 
 #include "konqhistorymanager.h"
 #include "konqhistorymanageradaptor.h"
+#include <konq_historyloader.h>
 #include <kbookmarkmanager.h>
 
 #include <QtDBus/QtDBus>
@@ -33,9 +34,6 @@
 #include <zlib.h> // for crc32
 #include <kconfiggroup.h>
 
-
-const int KonqHistoryManager::s_historyVersion = 4;
-
 KonqHistoryManager::KonqHistoryManager( KBookmarkManager* bookmarkManager, QObject \
*parent )  : KParts::HistoryProvider( parent ),
       m_bookmarkManager(bookmarkManager)
@@ -49,8 +47,6 @@
     m_maxCount = qMax( 1, m_maxCount );
     m_maxAgeDays = cs.readEntry( "Maximum age of History entries", 90);
 
-    m_filename = KStandardDirs::locateLocal( "data", \
                QLatin1String("konqueror/konq_history"));
-
     // take care of the completion object
     m_pCompletion = new KCompletion;
     m_pCompletion->setOrder( KCompletion::Weighted );
@@ -93,150 +89,59 @@
     return dbusService() == msg.service();
 }
 
-// loads the entire history
 bool KonqHistoryManager::loadHistory()
 {
     clearPending();
-    m_history.clear();
     m_pCompletion->clear();
 
-    QFile file( m_filename );
-    if ( !file.open( QIODevice::ReadOnly ) ) {
-	if ( file.exists() )
-	    kWarning() << "Can't open " << file.fileName() ;
-
-	// try to load the old completion history
-	bool ret = loadFallback();
-	emit loadingFinished();
-	return ret;
+    KonqHistoryLoader loader;
+    if (!loader.loadHistory()) {
+        return false;
     }
 
-    QDataStream fileStream( &file );
-    QByteArray data; // only used for version == 2
-    // we construct the stream object now but fill in the data later.
-    QDataStream crcStream( &data, QIODevice::ReadOnly );
+    m_history = loader.entries();
+    adjustSize();
 
-    if ( !fileStream.atEnd() ) {
-	quint32 version;
-        fileStream >> version;
+    QListIterator<KonqHistoryEntry> it(m_history);
+    while (it.hasNext()) {
+        const KonqHistoryEntry& entry = it.next();
+        const QString prettyUrlString = entry.url.prettyUrl();
+        addToCompletion(prettyUrlString, entry.typedUrl, \
entry.numberOfTimesVisited);  
-        QDataStream *stream = &fileStream;
-
-        bool crcChecked = false;
-        bool crcOk = false;
-
-        if ( version >= 2 && version <= 4) {
-            quint32 crc;
-            crcChecked = true;
-            fileStream >> crc >> data;
-            crcOk = crc32( 0, reinterpret_cast<unsigned char *>( data.data() ), \
                data.size() ) == crc;
-            stream = &crcStream; // pick up the right stream
-        }
-
-        // We can't read v3 history anymore, because operator<<(KURL) disappeared.
-        if ( version == 4)
-        {
-            // Use QUrl marshalling for V4 format.
-	    KonqHistoryEntry::marshalURLAsStrings = false;
-	}
-
-	if ( version != 0 && version < 3 ) //Versions 1,2 (but not 0) are also valid
-	{
-	    //Turn on backwards compatibility mode..
-	    KonqHistoryEntry::marshalURLAsStrings = true;
-	    // it doesn't make sense to save to save maxAge and maxCount  in the
-	    // binary file, this would make backups impossible (they would clear
-	    // themselves on startup, because all entries expire).
-	    // [But V1 and V2 formats did it, so we do a dummy read]
-	    quint32 dummy;
-	    *stream >> dummy;
-	    *stream >> dummy;
-
-	    //OK.
-	    version = 3;
-	}
-
-        if ( s_historyVersion != (int)version || ( crcChecked && !crcOk ) ) {
-	    kWarning() << "The history version doesn't match, aborting loading" ;
-	    file.close();
-	    emit loadingFinished();
-	    return false;
-	}
-
-
-        while ( !stream->atEnd() ) {
-	    KonqHistoryEntry entry;
-            *stream >> entry;
-	    // kDebug(1202) << "loaded entry:" << entry.url << ", Title:" << entry.title;
-	    m_history.append( entry );
-	    QString urlString2 = entry.url.prettyUrl();
-
-	    addToCompletion( urlString2, entry.typedUrl, entry.numberOfTimesVisited );
-
-	    // and fill our baseclass.
-            QString urlString = entry.url.url();
-	    KParts::HistoryProvider::insert( urlString );
-            // DF: also insert the "pretty" version if different
-            // This helps getting 'visited' links on websites which don't use \
                fully-escaped urls.
-
-            if ( urlString != urlString2 )
-                KParts::HistoryProvider::insert( urlString2 );
-	}
-
-	//kDebug(1202) << "loaded:" << m_history.count() << "entries.";
-
-	qSort( m_history.begin(), m_history.end(), lastVisitedOrder );
-	adjustSize();
+        // and fill our baseclass.
+        const QString urlString = entry.url.url();
+        KParts::HistoryProvider::insert(urlString);
+        // DF: also insert the "pretty" version if different
+        // This helps getting 'visited' links on websites which don't use \
fully-escaped urls. +        if (urlString != prettyUrlString)
+            KParts::HistoryProvider::insert(prettyUrlString);
     }
 
-
-    //This is important - we need to switch to a consistent marshalling format for
-    //communicating between different konqueror instances. Since during an upgrade
-    //some "old" copies may still running, we use the old format for the DBUS \
                transfers.
-    //This doesn't make that much difference performance-wise for single entries \
                anyway.
-    KonqHistoryEntry::marshalURLAsStrings = true;
-
-
-    // Theoretically, we should emit update() here, but as we only ever
-    // load items on startup up to now, this doesn't make much sense. Same
-    // thing for the above loadFallback().
-    // emit KParts::HistoryProvider::update( some list );
-
-
-
-    file.close();
-    emit loadingFinished();
-
     return true;
 }
 
-
-// saves the entire history
 bool KonqHistoryManager::saveHistory()
 {
-    KSaveFile file( m_filename );
+    const QString filename = KStandardDirs::locateLocal("data", \
QLatin1String("konqueror/konq_history")); +    KSaveFile file(filename);
     if ( !file.open() ) {
         kWarning() << "Can't open " << file.fileName() ;
         return false;
     }
 
     QDataStream fileStream ( &file );
-    fileStream << s_historyVersion;
+    fileStream << KonqHistoryLoader::historyVersion();
 
     QByteArray data;
     QDataStream stream( &data, QIODevice::WriteOnly );
 
-    //We use QUrl for marshalling URLs in entries in the V4
-    //file format
-    KonqHistoryEntry::marshalURLAsStrings = false;
     QListIterator<KonqHistoryEntry> it( m_history );
     while ( it.hasNext() ) {
-        stream << it.next();
+        //We use QUrl for marshalling URLs in entries in the V4
+        //file format
+        it.next().save(stream, KonqHistoryEntry::NoFlags);
     }
 
-    //For DBUS, transfer strings instead - wire compat.
-    KonqHistoryEntry::marshalURLAsStrings = true;
-
     quint32 crc = crc32( 0, reinterpret_cast<unsigned char *>( data.data() ), \
data.size() );  fileStream << crc << data;
 
@@ -372,7 +277,8 @@
 {
     QByteArray data;
     QDataStream stream( &data, QIODevice::WriteOnly );
-    stream << entry << dbusService();
+    entry.save(stream, KonqHistoryEntry::MarshalUrlAsStrings);
+    stream << dbusService();
     // Protection against very long urls (like data:)
     if ( data.size() > 4096 )
         return;
@@ -444,7 +350,12 @@
 {
     KonqHistoryEntry e;
     QDataStream stream( const_cast<QByteArray *>( &data ), QIODevice::ReadOnly );
-    stream >> e;
+
+    //This is important - we need to switch to a consistent marshalling format for
+    //communicating between different konqueror instances. Since during an upgrade
+    //some "old" copies may still running, we use the old format for the DBUS \
transfers. +    //This doesn't make that much difference performance-wise for single \
entries anyway. +    e.load(stream, KonqHistoryEntry::MarshalUrlAsStrings);
     //kDebug(1202) << "Got new entry from Broadcast:" << e.url;
 
     KonqHistoryList::iterator existingEntry = findEntry( e.url );
@@ -595,68 +506,6 @@
         saveHistory();
 }
 
-// compatibility fallback, try to load the old completion history
-bool KonqHistoryManager::loadFallback()
-{
-    QString file = KStandardDirs::locateLocal( "config", \
                QLatin1String("konq_history"));
-    if ( file.isEmpty() )
-	return false;
-
-    KConfig config(  file, KConfig::SimpleConfig);
-    const KConfigGroup group = config.group("History");
-    const QStringList items = group.readEntry( "CompletionItems", QStringList() );
-    QStringList::const_iterator it = items.begin();
-
-    while ( it != items.end() ) {
-	KonqHistoryEntry entry = createFallbackEntry( *it );
-	if ( entry.url.isValid() ) {
-	    m_history.append( entry );
-	    addToCompletion( entry.url.prettyUrl(), QString(), entry.numberOfTimesVisited \
                );
-
-	    KParts::HistoryProvider::insert( entry.url.url() );
-   	}
-	++it;
-    }
-
-    qSort( m_history.begin(), m_history.end(), lastVisitedOrder );
-    adjustSize();
-    saveHistory();
-
-    return true;
-}
-
-// tries to create a small KonqHistoryEntry out of a string, where the string
-// looks like "http://www.bla.com/bla.html:23"
-// the attached :23 is the weighting from KCompletion
-KonqHistoryEntry KonqHistoryManager::createFallbackEntry(const QString& item) const
-{
-    // code taken from KCompletion::addItem(), adjusted to use weight = 1
-    uint len = item.length();
-    uint weight = 1;
-
-    // find out the weighting of this item (appended to the string as ":num")
-    int index = item.lastIndexOf(':');
-    if ( index > 0 ) {
-	bool ok;
-	weight = item.mid( index + 1 ).toUInt( &ok );
-	if ( !ok )
-	    weight = 1;
-
-	len = index; // only insert until the ':'
-    }
-
-
-    KonqHistoryEntry entry;
-    KUrl u( item.left( len ));
-    // that's the only entries we know about...
-    entry.url = u;
-    entry.numberOfTimesVisited = weight;
-    // to make it not expire immediately...
-    entry.lastVisited = QDateTime::currentDateTime();
-
-    return entry;
-}
-
 KonqHistoryList::iterator KonqHistoryManager::findEntry( const KUrl& url )
 {
     // small optimization (dict lookup) for items _not_ in our history
--- trunk/KDE/kdebase/apps/konqueror/src/konqhistorymanager.h #948034:948035
@@ -28,31 +28,14 @@
 
 #include <kparts/historyprovider.h>
 
-#include "konqhistoryentry.h"
+#include <konqprivate_export.h>
 
+#include "konq_historyentry.h"
+
 class KBookmarkManager;
 class QDBusMessage;
 class KCompletion;
 
-class KONQUERORPRIVATE_EXPORT KonqHistoryList : public QList<KonqHistoryEntry>
-{
-public:
-    /**
-     * Finds an entry by URL and return an iterator to it.
-     * If no matching entry is found, end() is returned.
-     */
-    iterator findEntry( const KUrl& url );
-
-    /**
-     * Finds an entry by URL and removes it
-     */
-    void removeEntry( const KUrl& url );
-};
-
-
-///////////////////////////////////////////////////////////////////
-
-
 /**
  * This class maintains and manages a history of all URLs visited by one
  * Konqueror instance. Additionally it synchronizes the history with other
@@ -182,30 +165,14 @@
 
 public Q_SLOTS:
     /**
-     * Loads the history and fills the completion object.
-     */
-    bool loadHistory();
-
-    /**
-     * Saves the entire history.
-     */
-    bool saveHistory();
-
-    /**
      * Clears the history and tells all other Konqueror instances via DBUS
      * to do the same.
      * The history is saved afterwards, if necessary.
      */
     void emitClear();
 
-
 Q_SIGNALS:
     /**
-     * Emitted after the entire history was loaded from disk.
-     */
-    void loadingFinished();
-
-    /**
      * Emitted after a new entry was added
      */
     void entryAdded( const KonqHistoryEntry& entry );
@@ -286,6 +253,16 @@
 
 private:
     /**
+     * Loads the history and fills the completion object.
+     */
+    bool loadHistory();
+
+    /**
+     * Saves the entire history.
+     */
+    bool saveHistory();
+
+    /**
      * Does the work for @ref addPending() and @ref confirmPending().
      *
      * Adds an entry to the history. If an entry with @p url already exists,
@@ -343,25 +320,9 @@
      */
     KonqHistoryList::iterator findEntry( const KUrl& url );
 
-    /**
-     * Stuff to create a proper history out of KDE 2.0's konq_history for
-     * completion.
-     */
-    bool loadFallback();
-    KonqHistoryEntry createFallbackEntry( const QString& ) const;
-
     void addToCompletion( const QString& url, const QString& typedUrl, int \
                numberOfTimesVisited = 1 );
     void removeFromCompletion( const QString& url, const QString& typedUrl );
 
-    /**
-     * Ensures that the items are sorted by the lastVisited date
-     * (oldest goes first)
-     */
-    static bool lastVisitedOrder( const KonqHistoryEntry& lhs, const \
                KonqHistoryEntry& rhs ) {
-        return lhs.lastVisited < rhs.lastVisited;
-    }
-
-    QString m_filename;
     KonqHistoryList m_history;
 
     /**
--- trunk/KDE/kdebase/apps/konqueror/src/konqhistorymodel.h #948034:948035
@@ -22,7 +22,7 @@
 
 #include <QtCore/QAbstractItemModel>
 
-#include "konqhistoryentry.h"
+#include "konq_historyentry.h"
 
 class KonqHistoryManager;
 namespace KHM
--- trunk/KDE/kdebase/apps/lib/konq/CMakeLists.txt #948034:948035
@@ -5,23 +5,28 @@
 
 ########### libkonq ###############
 
-# Please use .cpp for new files
+# For crc32 in konq_historyloader.cpp
+include_directories( ${ZLIB_INCLUDE_DIR} )
+
 set(konq_LIB_SRCS
-   konq_popupmenu.cpp       # remains in libkonq, was needed by kicker applets like \
                the trash applet
-   konq_popupmenuinformation.cpp # used by KonqPopupMenu, KonqMenuActions and \
KonqPopupMenuPlugin +   konq_popupmenu.cpp       # used by konqueror, kfind, \
folderview, kickoff  konq_popupmenuplugin.cpp # for KonqPopupMenu and its plugins
    knewmenu.cpp             # used by dolphin, KonqPopupMenu, and konqueror (File \
                menu; to be moved to dolphinpart)
-   konq_menuactions.cpp     # used by dolphin, KonqPopupMenu. Move to kdelibs, for \
kickoff?  konq_copytomenu.cpp      # used by dolphin, KonqPopupMenu
    konq_operations.cpp      # used by dolphin and konqueror
    konq_events.cpp
    konqmimedata.cpp         # used by dolphin, KonqOperations, some filemanagement \
                konqueror modules.
-   konq_fileitemcapabilities.cpp # used in dolphin and dolphinpart already.
+   konq_historyentry.cpp
+   konq_historyloader.cpp
+   
+   konq_popupmenuinformation.cpp # deprecated (functionality has moved to kdelibs)
+   konq_menuactions.cpp     # deprecated (functionality has moved to kdelibs)
+   konq_fileitemcapabilities.cpp # deprecated (functionality has moved to kdelibs)
 )
 
 kde4_add_library(konq SHARED ${konq_LIB_SRCS})
 
-target_link_libraries(konq ${KDE4_KPARTS_LIBS})
+target_link_libraries(konq ${KDE4_KPARTS_LIBS} ${ZLIB_LIBRARY})
 target_link_libraries(konq LINK_INTERFACE_LIBRARIES ${KDE4_KPARTS_LIBS})
 
 set_target_properties(konq PROPERTIES


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic