• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
BookmarkHandler.cpp
Go to the documentation of this file.
1 /* This file was part of the KDE libraries
2 
3  Copyright 2002 Carsten Pfeiffer <pfeiffer@kde.org>
4  Copyright 2007-2008 Robert Knight <robertknight@gmail.com>
5 
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.
10 
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.
15 
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.
20 */
21 
22 // Born as kdelibs/kio/kfile/kfilebookmarkhandler.cpp
23 
24 // Own
25 #include "BookmarkHandler.h"
26 
27 // Qt
28 #include <QtCore/QFileInfo>
29 
30 // KDE
31 #include <KShell>
32 #include <KBookmarkMenu>
33 #include <KStandardDirs>
34 
35 // Konsole
36 #include "ViewProperties.h"
37 
38 using namespace Konsole;
39 
40 BookmarkHandler::BookmarkHandler(KActionCollection* collection,
41  KMenu* menu,
42  bool toplevel,
43  QObject* parent)
44  : QObject(parent),
45  KBookmarkOwner(),
46  _menu(menu),
47  _toplevel(toplevel),
48  _activeView(0)
49 {
50  setObjectName(QLatin1String("BookmarkHandler"));
51 
52  _file = KStandardDirs::locate("data", "konsole/bookmarks.xml");
53  if (_file.isEmpty())
54  _file = KStandardDirs::locateLocal("data", "konsole/bookmarks.xml");
55 
56  KBookmarkManager* manager = KBookmarkManager::managerForFile(_file, "konsole");
57 
58  manager->setUpdate(true);
59 
60  if (toplevel)
61  _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, collection);
62  else
63  _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, 0);
64 }
65 
66 BookmarkHandler::~BookmarkHandler()
67 {
68  delete _bookmarkMenu;
69 }
70 
71 void BookmarkHandler::openBookmark(const KBookmark& bm, Qt::MouseButtons, Qt::KeyboardModifiers)
72 {
73  emit openUrl(bm.url());
74 }
75 void BookmarkHandler::openFolderinTabs(const KBookmarkGroup& group)
76 {
77  emit openUrls(group.groupUrlList());
78 }
79 bool BookmarkHandler::enableOption(BookmarkOption option) const
80 {
81  if (option == ShowAddBookmark || option == ShowEditBookmark)
82  return _toplevel;
83  else
84  return KBookmarkOwner::enableOption(option);
85 }
86 
87 QString BookmarkHandler::currentUrl() const
88 {
89  return urlForView(_activeView);
90 }
91 
92 QString BookmarkHandler::urlForView(ViewProperties* view) const
93 {
94  if (view)
95  return view->url().prettyUrl();
96  else
97  return QString();
98 }
99 
100 QString BookmarkHandler::currentTitle() const
101 {
102  return titleForView(_activeView);
103 }
104 
105 QString BookmarkHandler::titleForView(ViewProperties* view) const
106 {
107  const KUrl& url = view ? view->url() : KUrl();
108  if (url.isLocalFile()) {
109  QString path = url.path();
110 
111  path = KShell::tildeExpand(path);
112  path = QFileInfo(path).baseName();
113 
114  return path;
115  } else if (url.hasHost()) {
116  if (url.hasUser())
117  return i18nc("@item:inmenu The user's name and host they are connected to via ssh", "%1 on %2", url.user(), url.host());
118  else
119  return i18nc("@item:inmenu The host the user is connected to via ssh", "%1", url.host());
120  }
121 
122  return url.prettyUrl();
123 }
124 
125 bool BookmarkHandler::supportsTabs() const
126 {
127  return true;
128 }
129 
130 QList<QPair<QString, QString> > BookmarkHandler::currentBookmarkList() const
131 {
132  QList<QPair<QString, QString> > list;
133 
134  foreach(ViewProperties* view, _views) {
135  list << QPair<QString, QString>(titleForView(view) , urlForView(view));
136  }
137 
138  return list;
139 }
140 
141 void BookmarkHandler::setViews(const QList<ViewProperties*>& views)
142 {
143  _views = views;
144 }
145 QList<ViewProperties*> BookmarkHandler::views() const
146 {
147  return _views;
148 }
149 void BookmarkHandler::setActiveView(ViewProperties* view)
150 {
151  _activeView = view;
152 }
153 ViewProperties* BookmarkHandler::activeView() const
154 {
155  return _activeView;
156 }
157 
158 #include "BookmarkHandler.moc"
Konsole::BookmarkHandler::setViews
void setViews(const QList< ViewProperties * > &views)
Definition: BookmarkHandler.cpp:141
Konsole::BookmarkHandler::openUrls
void openUrls(const QList< KUrl > &urls)
Emitted when the user selects 'Open Folder in Tabs' from the bookmark menu.
Konsole::BookmarkHandler::currentBookmarkList
virtual QList< QPair< QString, QString > > currentBookmarkList() const
Definition: BookmarkHandler.cpp:130
Konsole::BookmarkHandler::supportsTabs
virtual bool supportsTabs() const
Definition: BookmarkHandler.cpp:125
Konsole::BookmarkHandler::BookmarkHandler
BookmarkHandler(KActionCollection *collection, KMenu *menu, bool toplevel, QObject *parent)
Constructs a new bookmark handler for Konsole bookmarks.
Definition: BookmarkHandler.cpp:40
Konsole::BookmarkHandler::setActiveView
void setActiveView(ViewProperties *view)
Definition: BookmarkHandler.cpp:149
Konsole::BookmarkHandler::openUrl
void openUrl(const KUrl &url)
Emitted when the user selects a bookmark from the bookmark menu.
Konsole::BookmarkHandler::currentTitle
virtual QString currentTitle() const
Definition: BookmarkHandler.cpp:100
Konsole::BookmarkHandler::openFolderinTabs
virtual void openFolderinTabs(const KBookmarkGroup &group)
Definition: BookmarkHandler.cpp:75
QObject
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
QString
QList
KBookmarkOwner
Konsole::ViewProperties
Encapsulates user-visible information about the terminal session currently being displayed in a view...
Definition: ViewProperties.h:44
Konsole::BookmarkHandler::activeView
ViewProperties * activeView() const
Definition: BookmarkHandler.cpp:153
Konsole::BookmarkHandler::~BookmarkHandler
~BookmarkHandler()
Definition: BookmarkHandler.cpp:66
Konsole::BookmarkHandler::enableOption
virtual bool enableOption(BookmarkOption option) const
Definition: BookmarkHandler.cpp:79
QFileInfo
Qt::MouseButtons
typedef MouseButtons
QLatin1String
Konsole::BookmarkHandler::currentUrl
virtual QString currentUrl() const
Definition: BookmarkHandler.cpp:87
BookmarkHandler.h
Konsole::BookmarkHandler::views
QList< ViewProperties * > views() const
Definition: BookmarkHandler.cpp:145
ViewProperties.h
QFileInfo::baseName
QString baseName() const
Konsole::ViewProperties::url
virtual KUrl url() const
Returns the URL current associated with a view.
Definition: ViewProperties.cpp:42
Qt::KeyboardModifiers
typedef KeyboardModifiers
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal