File indexing completed on 2024-07-21 12:11:18

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #include "kfilebookmarkhandler_p.h"
0009 
0010 #include <stdio.h>
0011 #include <stdlib.h>
0012 
0013 #include <QMenu>
0014 
0015 #include <KBookmarkDomBuilder>
0016 #include <QStandardPaths>
0017 #include <kbookmarkimporter.h>
0018 #include <kio/global.h>
0019 
0020 #include "kfilewidget.h"
0021 
0022 KFileBookmarkHandler::KFileBookmarkHandler(KFileWidget *widget)
0023     : QObject(widget)
0024     , KBookmarkOwner()
0025     , m_widget(widget)
0026 {
0027     setObjectName(QStringLiteral("KFileBookmarkHandler"));
0028     m_menu = new QMenu(widget);
0029     m_menu->setObjectName(QStringLiteral("bookmark menu"));
0030 
0031     QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kfile/bookmarks.xml"));
0032     if (file.isEmpty()) {
0033         file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kfile/bookmarks.xml");
0034     }
0035 
0036     KBookmarkManager *manager = KBookmarkManager::managerForFile(file, QStringLiteral("kfile"));
0037     manager->setUpdate(true);
0038 
0039     m_bookmarkMenu = new KBookmarkMenu(manager, this, m_menu);
0040 }
0041 
0042 KFileBookmarkHandler::~KFileBookmarkHandler()
0043 {
0044     delete m_bookmarkMenu;
0045 }
0046 
0047 void KFileBookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers)
0048 {
0049     Q_EMIT openUrl(bm.url().toString());
0050 }
0051 
0052 QUrl KFileBookmarkHandler::currentUrl() const
0053 {
0054     return m_widget->baseUrl();
0055 }
0056 
0057 QString KFileBookmarkHandler::currentTitle() const
0058 {
0059     return m_widget->baseUrl().toDisplayString();
0060 }
0061 
0062 QString KFileBookmarkHandler::currentIcon() const
0063 {
0064     return KIO::iconNameForUrl(currentUrl());
0065 }
0066 
0067 #include "moc_kfilebookmarkhandler_p.cpp"