• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

BookmarkHandler.cpp

Go to the documentation of this file.
00001 /*  This file was part of the KDE libraries
00002     
00003     Copyright 2002 Carsten Pfeiffer <pfeiffer@kde.org>
00004     Copyright 2007-2008 Robert Knight <robertknight@gmail.com> 
00005 
00006     library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation, version 2
00009     or ( at your option ), any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 // Born as kdelibs/kio/kfile/kfilebookmarkhandler.characterpp
00023 
00024 // Own
00025 #include "BookmarkHandler.h"
00026 
00027 // Qt
00028 #include <QtCore/QFile>
00029 #include <QtCore/QFileInfo>
00030 
00031 // KDE
00032 #include <kshell.h>
00033 
00034 #include <KBookmarkMenu>
00035 #include <KDebug>
00036 #include <KMenu>
00037 #include <KStandardDirs>
00038 
00039 // Konsole
00040 #include "ViewProperties.h"
00041 
00042 using namespace Konsole;
00043 
00044 BookmarkHandler::BookmarkHandler( KActionCollection* collection, 
00045                                   KMenu* menu, 
00046                                   bool toplevel , 
00047                                   QObject* parent )
00048     : QObject( parent ),
00049       KBookmarkOwner(),
00050       m_toplevel(toplevel),
00051       m_activeView(0)
00052 {
00053     setObjectName( "BookmarkHandler" );
00054 
00055     m_menu = menu;
00056 
00057     QString new_bm_file = KStandardDirs::locateLocal( "data", "konsole/bookmarks.xml" );
00058 
00059     m_file = KStandardDirs::locate( "data", "konsole/bookmarks.xml" );
00060     if ( m_file.isEmpty() )
00061         m_file = KStandardDirs::locateLocal( "data", "konsole/bookmarks.xml" );
00062 
00063     KBookmarkManager *manager = KBookmarkManager::managerForFile( m_file, "konsole" );
00064 
00065     manager->setUpdate( true );
00066 
00067     if (toplevel) {
00068         m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu,
00069                                             collection );
00070     } else {
00071         m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu,
00072                                             NULL);
00073     }
00074 }
00075 
00076 BookmarkHandler::~BookmarkHandler()
00077 {
00078     delete m_bookmarkMenu;
00079 }
00080 
00081 void BookmarkHandler::openBookmark( const KBookmark & bm, Qt::MouseButtons, Qt::KeyboardModifiers )
00082 {
00083     emit openUrl( bm.url() );
00084 }
00085 void BookmarkHandler::openFolderinTabs( const KBookmarkGroup& group )
00086 {
00087     emit openUrls(group.groupUrlList());
00088 }
00089 bool BookmarkHandler::enableOption(BookmarkOption option ) const
00090 {
00091     if(option == ShowAddBookmark || option == ShowEditBookmark)
00092         return m_toplevel;
00093     else
00094         return KBookmarkOwner::enableOption(option);
00095 }
00096 
00097 QString BookmarkHandler::currentUrl() const
00098 {
00099     return urlForView(m_activeView);
00100 }
00101 
00102 QString BookmarkHandler::urlForView(ViewProperties* view) const
00103 {
00104     if ( view )
00105     {
00106         return view->url().prettyUrl();
00107     }
00108     else
00109     {
00110         return QString(); 
00111     }
00112 }
00113 
00114 QString BookmarkHandler::currentTitle() const
00115 {
00116     return titleForView(m_activeView);
00117 }
00118 
00119 QString BookmarkHandler::titleForView(ViewProperties* view) const
00120 {
00121     const KUrl &u = view ? view->url() : KUrl(); 
00122     if (u.isLocalFile())
00123     {
00124        QString path = u.path();
00125        path = KShell::tildeExpand(path);
00126 
00127        path = QFileInfo(path).baseName();
00128 
00129        return path;
00130     }
00131     else if ( u.hasHost() )
00132     {
00133         if ( u.hasUser() )
00134             return i18n("%1 on %2",u.user(),u.host());
00135         else
00136             return i18n("%1",u.host());
00137     }
00138     return u.prettyUrl();
00139 }
00140 
00141 bool BookmarkHandler::supportsTabs() const
00142 {
00143     return true;
00144 }
00145 
00146 QList<QPair<QString,QString> > BookmarkHandler::currentBookmarkList() const
00147 {
00148     QList<QPair<QString,QString> > list;
00149 
00150     QListIterator<ViewProperties*> iter( m_views );
00151     
00152     while ( iter.hasNext() )
00153     {
00154         ViewProperties* next = iter.next();
00155         list << QPair<QString,QString>(titleForView(next) , urlForView(next));
00156     }
00157 
00158     return list;
00159 }
00160 
00161 void BookmarkHandler::setViews(const QList<ViewProperties*>& views) 
00162 {
00163     m_views = views;
00164 }
00165 QList<ViewProperties*> BookmarkHandler::views() const
00166 {
00167     return m_views;
00168 }
00169 void BookmarkHandler::setActiveView( ViewProperties* view )
00170 {
00171     m_activeView = view;
00172 }
00173 ViewProperties* BookmarkHandler::activeView() const
00174 {
00175     return m_activeView;
00176 }
00177 
00178 #include "BookmarkHandler.moc"

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal