File indexing completed on 2025-09-14 05:30:45
0001 /* 0002 SPDX-FileCopyrightText: 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be> 0003 SPDX-FileCopyrightText: 2012 Marco Gulino <marco.gulino@xpeppers.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "konqueror.h" 0009 #include "bookmarkmatch.h" 0010 0011 #include <QIcon> 0012 #include <QStack> 0013 #include <QStandardPaths> 0014 #include <QUrl> 0015 0016 #include <KBookmarkManager> 0017 #include <KIO/Global> 0018 0019 QIcon KDEFavicon::iconFor(const QString &url) 0020 { 0021 const QString iconFile = KIO::favIconForUrl(QUrl(url)); 0022 if (iconFile.isEmpty()) { 0023 return defaultIcon(); 0024 } 0025 return QIcon::fromTheme(iconFile); 0026 } 0027 0028 KDEFavicon::KDEFavicon(QObject *parent) 0029 : Favicon(parent) 0030 { 0031 } 0032 0033 Konqueror::Konqueror(QObject *parent) 0034 : QObject(parent) 0035 , m_favicon(new KDEFavicon(this)) 0036 { 0037 const QString bookmarksFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/konqueror/bookmarks.xml"); 0038 m_bookmarkManager = new KBookmarkManager(bookmarksFile, this); 0039 } 0040 0041 QList<BookmarkMatch> Konqueror::match(const QString &term, bool addEverything) 0042 { 0043 KBookmarkGroup bookmarkGroup = m_bookmarkManager->root(); 0044 0045 QList<BookmarkMatch> matches; 0046 QStack<KBookmarkGroup> groups; 0047 0048 KBookmark bookmark = bookmarkGroup.first(); 0049 while (!bookmark.isNull()) { 0050 // if (!context.isValid()) { 0051 // return; 0052 // } TODO: restore? 0053 0054 if (bookmark.isSeparator()) { 0055 bookmark = bookmarkGroup.next(bookmark); 0056 continue; 0057 } 0058 0059 if (bookmark.isGroup()) { // descend 0060 // qDebug(kdbg_code) << "descending into" << bookmark.text(); 0061 groups.push(bookmarkGroup); 0062 bookmarkGroup = bookmark.toGroup(); 0063 bookmark = bookmarkGroup.first(); 0064 0065 while (bookmark.isNull() && !groups.isEmpty()) { 0066 // if (!context.isValid()) { 0067 // return; 0068 // } TODO: restore? 0069 0070 bookmark = bookmarkGroup; 0071 bookmarkGroup = groups.pop(); 0072 bookmark = bookmarkGroup.next(bookmark); 0073 } 0074 0075 continue; 0076 } 0077 0078 const QString url = bookmark.url().url(); 0079 BookmarkMatch bookmarkMatch(m_favicon->iconFor(url), term, bookmark.text(), url); 0080 bookmarkMatch.addTo(matches, addEverything); 0081 0082 bookmark = bookmarkGroup.next(bookmark); 0083 while (bookmark.isNull() && !groups.isEmpty()) { 0084 // if (!context.isValid()) { 0085 // return; 0086 // } // TODO: restore? 0087 0088 bookmark = bookmarkGroup; 0089 bookmarkGroup = groups.pop(); 0090 ////qDebug() << "ascending from" << bookmark.text() << "to" << bookmarkGroup.text(); 0091 bookmark = bookmarkGroup.next(bookmark); 0092 } 0093 } 0094 return matches; 0095 }