File indexing completed on 2024-05-12 05:46:38

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
0003 
0004     library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation, version 2.
0007 
0008     This library is distributed in the hope that it will be useful,
0009     but WITHOUT ANY WARRANTY; without even the implied warranty of
0010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011     Library General Public License for more details.
0012 
0013     You should have received a copy of the GNU Library General Public License
0014     along with this library; see the file COPYING.LIB.  If not, write to
0015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016     Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #include "kfilebookmarkhandler_p.h"
0020 
0021 #include <stdio.h>
0022 #include <stdlib.h>
0023 
0024 #include <QMenu>
0025 
0026 #include <kbookmarkimporter.h>
0027 #include <kbookmarkdombuilder.h>
0028 #include <kio/global.h>
0029 #include <qstandardpaths.h>
0030 
0031 #include "kfilewidget.h"
0032 
0033 KFileBookmarkHandler::KFileBookmarkHandler(KFileWidget *widget)
0034     : QObject(widget),
0035       KBookmarkOwner(),
0036       m_widget(widget)
0037 {
0038     setObjectName(QStringLiteral("KFileBookmarkHandler"));
0039     m_menu = new QMenu(widget);
0040     m_menu->setObjectName(QStringLiteral("bookmark menu"));
0041 
0042     QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kfile/bookmarks.xml"));
0043     if (file.isEmpty()) {
0044         file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kfile/bookmarks.xml");
0045     }
0046 
0047     KBookmarkManager *manager = KBookmarkManager::managerForFile(file, QStringLiteral("kfile"));
0048     manager->setUpdate(true);
0049 
0050     m_bookmarkMenu = new KBookmarkMenu(manager, this, m_menu,
0051                                        widget->actionCollection());
0052 }
0053 
0054 KFileBookmarkHandler::~KFileBookmarkHandler()
0055 {
0056     delete m_bookmarkMenu;
0057 }
0058 
0059 void KFileBookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers)
0060 {
0061     emit openUrl(bm.url().toString());
0062 }
0063 
0064 QUrl KFileBookmarkHandler::currentUrl() const
0065 {
0066     return m_widget->baseUrl();
0067 }
0068 
0069 QString KFileBookmarkHandler::currentTitle() const
0070 {
0071     return m_widget->baseUrl().toDisplayString();
0072 }
0073 
0074 QString KFileBookmarkHandler::currentIcon() const
0075 {
0076     return KIO::iconNameForUrl(currentUrl());
0077 }
0078 
0079 #include "moc_kfilebookmarkhandler_p.cpp"