From 2e8e305ebc16cfbf553f4b72f14255615ffb43be Mon Sep 17 00:00:00 2001 From: stippi Date: Wed, 17 Mar 2010 19:39:46 +0000 Subject: [PATCH] * Fixed bug that would save the history for each item in the history when loading the history from disk... * Don't touch items when loading them from disk, messing up their visited time. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@323 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowsingHistory.cpp | 56 ++++++++++++++---------- src/apps/webpositive/BrowsingHistory.h | 1 + 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/apps/webpositive/BrowsingHistory.cpp b/src/apps/webpositive/BrowsingHistory.cpp index e5a7e8afe4..c93482e088 100644 --- a/src/apps/webpositive/BrowsingHistory.cpp +++ b/src/apps/webpositive/BrowsingHistory.cpp @@ -154,7 +154,7 @@ BrowsingHistory::BrowsingHistory() BMessage historyItemArchive; for (int32 i = 0; settingsArchive.FindMessage("history item", i, &historyItemArchive) == B_OK; i++) { - addItem(BrowsingHistoryItem(&historyItemArchive)); + privateAddItem(BrowsingHistoryItem(&historyItemArchive), false); historyItemArchive.MakeEmpty(); } } @@ -177,28 +177,7 @@ bool BrowsingHistory::addItem(const BrowsingHistoryItem& item) { BAutolock _(this); - int32 count = countItems(); - int32 insertionIndex = count; - for (int32 i = 0; i < count; i++) { - BrowsingHistoryItem* existingItem = reinterpret_cast( - m_historyItems.ItemAtFast(i)); - if (item.url() == existingItem->url()) { - existingItem->invoked(); - return true; - } - if (item < *existingItem) - insertionIndex = i; - } - BrowsingHistoryItem* newItem = new(std::nothrow) BrowsingHistoryItem(item); - if (!newItem || !m_historyItems.AddItem(newItem, insertionIndex)) { - delete newItem; - return false; - } - - newItem->invoked(); - saveSettings(); - - return true; + return privateAddItem(item, false); } int32 BrowsingHistory::BrowsingHistory::countItems() const @@ -238,6 +217,37 @@ void BrowsingHistory::privateClear() m_historyItems.MakeEmpty(); } +bool BrowsingHistory::privateAddItem(const BrowsingHistoryItem& item, bool internal) +{ + int32 count = countItems(); + int32 insertionIndex = count; + for (int32 i = 0; i < count; i++) { + BrowsingHistoryItem* existingItem = reinterpret_cast( + m_historyItems.ItemAtFast(i)); + if (item.url() == existingItem->url()) { + if (!internal) { + existingItem->invoked(); + saveSettings(); + } + return true; + } + if (item < *existingItem) + insertionIndex = i; + } + BrowsingHistoryItem* newItem = new(std::nothrow) BrowsingHistoryItem(item); + if (!newItem || !m_historyItems.AddItem(newItem, insertionIndex)) { + delete newItem; + return false; + } + + if (!internal) { + newItem->invoked(); + saveSettings(); + } + + return true; +} + // #pragma mark - private void BrowsingHistory::saveSettings() diff --git a/src/apps/webpositive/BrowsingHistory.h b/src/apps/webpositive/BrowsingHistory.h index 00e4f3a5e7..e25dee27ed 100644 --- a/src/apps/webpositive/BrowsingHistory.h +++ b/src/apps/webpositive/BrowsingHistory.h @@ -79,6 +79,7 @@ private: BrowsingHistory(); virtual ~BrowsingHistory(); void privateClear(); + bool privateAddItem(const BrowsingHistoryItem& item, bool invoke); void saveSettings(); bool openSettingsFile(BFile& file, uint32 mode);