File indexing completed on 2024-04-28 04:58:11
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "konq_historyentry.h" 0008 #include <QDataStream> 0009 0010 KonqHistoryEntry::KonqHistoryEntry() 0011 : numberOfTimesVisited(1), d(nullptr) 0012 { 0013 } 0014 0015 KonqHistoryEntry::~KonqHistoryEntry() 0016 { 0017 } 0018 0019 KonqHistoryEntry::KonqHistoryEntry(const KonqHistoryEntry &other) 0020 { 0021 operator=(other); 0022 } 0023 0024 KonqHistoryEntry &KonqHistoryEntry::operator=(const KonqHistoryEntry &other) 0025 { 0026 url = other.url; 0027 typedUrl = other.typedUrl; 0028 title = other.title; 0029 numberOfTimesVisited = other.numberOfTimesVisited; 0030 firstVisited = other.firstVisited; 0031 lastVisited = other.lastVisited; 0032 d = nullptr; 0033 return *this; 0034 } 0035 0036 bool KonqHistoryEntry::operator==(const KonqHistoryEntry &entry) const 0037 { 0038 return url == entry.url && 0039 typedUrl == entry.typedUrl && 0040 title == entry.title && 0041 numberOfTimesVisited == entry.numberOfTimesVisited && 0042 firstVisited == entry.firstVisited && 0043 lastVisited == entry.lastVisited; 0044 } 0045 0046 void KonqHistoryEntry::load(QDataStream &s, Flags flags) 0047 { 0048 if (flags & MarshalUrlAsStrings) { 0049 QString urlStr; 0050 s >> urlStr; 0051 url = QUrl(urlStr); 0052 } else { 0053 s >> url; 0054 } 0055 s >> typedUrl; 0056 s >> title; 0057 s >> numberOfTimesVisited; 0058 s >> firstVisited; 0059 s >> lastVisited; 0060 } 0061 0062 void KonqHistoryEntry::save(QDataStream &s, Flags flags) const 0063 { 0064 if (flags & MarshalUrlAsStrings) { 0065 s << url.url(); 0066 } else { 0067 s << url; 0068 } 0069 s << typedUrl; 0070 s << title; 0071 s << numberOfTimesVisited; 0072 s << firstVisited; 0073 s << lastVisited; 0074 } 0075 0076 //// 0077 0078 KonqHistoryList::iterator KonqHistoryList::findEntry(const QUrl &url) 0079 { 0080 // we search backwards, probably faster to find an entry 0081 KonqHistoryList::iterator it = end(); 0082 while (it != begin()) { 0083 --it; 0084 if ((*it).url == url) { 0085 return it; 0086 } 0087 } 0088 return end(); 0089 } 0090 0091 KonqHistoryList::const_iterator KonqHistoryList::constFindEntry(const QUrl &url) const 0092 { 0093 // we search backwards, probably faster to find an entry 0094 KonqHistoryList::const_iterator it = constEnd(); 0095 while (it != constBegin()) { 0096 --it; 0097 if ((*it).url == url) { 0098 return it; 0099 } 0100 } 0101 return constEnd(); 0102 } 0103 0104 void KonqHistoryList::removeEntry(const QUrl &url) 0105 { 0106 iterator it = findEntry(url); 0107 if (it != end()) { 0108 erase(it); 0109 } 0110 } 0111