katebookmarkhandler.cpp 2.27 KB
Newer Older
1 2 3
/* This file is part of the KDE project
   Copyright (C) xxxx KFile Authors
   Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
4
   Copyright (C) 2009 Dominik Haumann <dhaumann kde org>
5
   Copyright (C) 2007 Mirko Stocker <me@misto.ch>
6

7 8 9
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.
10

11 12 13 14
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
15

16 17 18 19 20 21
   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

22 23
#include "katebookmarkhandler.h"
#include "katefilebrowser.h"
24

Albert Astals Cid's avatar
Albert Astals Cid committed
25
#include <kdiroperator.h>
26

27
#include <QStandardPaths>
Christoph Cullmann's avatar
Christoph Cullmann committed
28
#include <QMenu>
29

30 31 32 33 34
KateBookmarkHandler::KateBookmarkHandler(KateFileBrowser *parent, QMenu *kpopupmenu)
    : QObject(parent)
    , KBookmarkOwner()
    , mParent(parent)
    , m_menu(kpopupmenu)
35
{
36 37 38
    setObjectName(QStringLiteral("KateBookmarkHandler"));
    if (!m_menu)
        m_menu = new QMenu(parent);
39

40 41 42
    QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kate/fsbookmarks.xml"));
    if (file.isEmpty())
        file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kate/fsbookmarks.xml");
43

44 45
    KBookmarkManager *manager = KBookmarkManager::managerForFile(file, QStringLiteral("kate"));
    manager->setUpdate(true);
46

47
    m_bookmarkMenu = new KBookmarkMenu(manager, this, m_menu, parent->actionCollection());
48 49
}

50
KateBookmarkHandler::~KateBookmarkHandler()
51
{
52
    delete m_bookmarkMenu;
53 54
}

55
QUrl KateBookmarkHandler::currentUrl() const
56
{
57
    return mParent->dirOperator()->url();
58 59
}

60
QString KateBookmarkHandler::currentTitle() const
61
{
62
    return currentUrl().url();
63 64
}

65
void KateBookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers)
66
{
67
    emit openUrl(bm.url().url());
68 69 70
}

// kate: space-indent on; indent-width 2; replace-tabs on;