Konsole
BookmarkHandler.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "BookmarkHandler.h"
00026
00027
00028 #include <QtCore/QFile>
00029 #include <QtCore/QFileInfo>
00030
00031
00032 #include <kshell.h>
00033
00034 #include <KBookmarkMenu>
00035 #include <KDebug>
00036 #include <KMenu>
00037 #include <KStandardDirs>
00038
00039
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"