bool BrowsingHistory::_AddItem(const BrowsingHistoryItem& item, bool internal) { int32 count = CountItems(); int32 insertionIndex = count; for (int32 i = 0; i < count; i++) { BrowsingHistoryItem* existingItem = reinterpret_cast<BrowsingHistoryItem*>( fHistoryItems.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 || !fHistoryItems.AddItem(newItem, insertionIndex)) { delete newItem; return false; } if (!internal) { newItem->Invoked(); _SaveSettings(); } return true; }
virtual void FetchChoicesFor(const BString& pattern) { int32 count = CountChoices(); for (int32 i = 0; i < count; i++) { delete reinterpret_cast<BAutoCompleter::Choice*>( fChoices.ItemAtFast(i)); } fChoices.MakeEmpty(); // Search through BrowsingHistory for any matches. BrowsingHistory* history = BrowsingHistory::DefaultInstance(); if (!history->Lock()) return; BString lastBaseURL; int32 priority = INT_MAX; count = history->CountItems(); for (int32 i = 0; i < count; i++) { BrowsingHistoryItem item = history->HistoryItemAt(i); const BString& choiceText = item.URL(); int32 matchPos = choiceText.IFindFirst(pattern); if (matchPos < 0) continue; if (lastBaseURL.Length() > 0 && choiceText.FindFirst(lastBaseURL) >= 0) { priority--; } else priority = INT_MAX; lastBaseURL = baseURL(choiceText); fChoices.AddItem(new URLChoice(choiceText, choiceText, matchPos, pattern.Length(), priority)); } history->Unlock(); fChoices.SortItems(_CompareChoices); }