1 /* This file was part of the KDE libraries
3 Copyright 2002 Carsten Pfeiffer <pfeiffer@kde.org>
4 Copyright 2007-2008 Robert Knight <robertknight@gmail.com>
6 library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation, version 2
9 or ( at your option ), any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 // Born as kdelibs/kio/kfile/kfilebookmarkhandler.characterpp
25 #include "BookmarkHandler.h"
28 #include <QtCore/QFile>
29 #include <QtCore/QFileInfo>
34 #include <KBookmarkMenu>
37 #include <KStandardDirs>
40 #include "ViewProperties.h"
42 using namespace Konsole
;
44 BookmarkHandler::BookmarkHandler( KActionCollection
* collection
,
53 setObjectName( "BookmarkHandler" );
57 QString new_bm_file
= KStandardDirs::locateLocal( "data", "konsole/bookmarks.xml" );
59 m_file
= KStandardDirs::locate( "data", "konsole/bookmarks.xml" );
60 if ( m_file
.isEmpty() )
61 m_file
= KStandardDirs::locateLocal( "data", "konsole/bookmarks.xml" );
63 KBookmarkManager
*manager
= KBookmarkManager::managerForFile( m_file
, "konsole" );
65 manager
->setUpdate( true );
68 m_bookmarkMenu
= new KBookmarkMenu( manager
, this, m_menu
,
71 m_bookmarkMenu
= new KBookmarkMenu( manager
, this, m_menu
,
76 BookmarkHandler::~BookmarkHandler()
78 delete m_bookmarkMenu
;
81 void BookmarkHandler::openBookmark( const KBookmark
& bm
, Qt::MouseButtons
, Qt::KeyboardModifiers
)
83 emit
openUrl( bm
.url() );
85 void BookmarkHandler::openFolderinTabs( const KBookmarkGroup
& group
)
87 emit
openUrls(group
.groupUrlList());
89 bool BookmarkHandler::enableOption(BookmarkOption option
) const
91 if(option
== ShowAddBookmark
|| option
== ShowEditBookmark
)
94 return KBookmarkOwner::enableOption(option
);
97 QString
BookmarkHandler::currentUrl() const
99 return urlForView(m_activeView
);
102 QString
BookmarkHandler::urlForView(ViewProperties
* view
) const
106 return view
->url().prettyUrl();
114 QString
BookmarkHandler::currentTitle() const
116 return titleForView(m_activeView
);
119 QString
BookmarkHandler::titleForView(ViewProperties
* view
) const
121 const KUrl
&u
= view
? view
->url() : KUrl();
124 QString path
= u
.path();
125 path
= KShell::tildeExpand(path
);
127 path
= QFileInfo(path
).baseName();
131 else if ( u
.hasHost() )
134 return i18n("%1 on %2",u
.user(),u
.host());
136 return i18n("%1",u
.host());
138 return u
.prettyUrl();
141 bool BookmarkHandler::supportsTabs() const
146 QList
<QPair
<QString
,QString
> > BookmarkHandler::currentBookmarkList() const
148 QList
<QPair
<QString
,QString
> > list
;
150 QListIterator
<ViewProperties
*> iter( m_views
);
152 while ( iter
.hasNext() )
154 ViewProperties
* next
= iter
.next();
155 list
<< QPair
<QString
,QString
>(titleForView(next
) , urlForView(next
));
161 void BookmarkHandler::setViews(const QList
<ViewProperties
*>& views
)
165 QList
<ViewProperties
*> BookmarkHandler::views() const
169 void BookmarkHandler::setActiveView( ViewProperties
* view
)
173 ViewProperties
* BookmarkHandler::activeView() const
178 #include "BookmarkHandler.moc"