1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (<peter.penz@gmx.at>) *
3 * Copyright (C) 2006 by Aaron J. Seigo (<aseigo@kde.org>) *
4 * Copyright (C) 2006 by Patrice Tremblay *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program 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 *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #ifndef URLNAVIGATOR_H
23 #define URLNAVIGATOR_H
28 #include <QLinkedList>
30 class KBookmarkManager
;
41 class BookmarkSelector
;
42 class UrlNavigatorButton
;
46 * @brief Navigation bar which contains the current shown URL.
48 * The URL navigator offers two modes:
49 * - Editable: Represents the 'classic' mode, where the current URL
50 * is editable inside a line editor.
51 * - Non editable: The URL is represented by a number of buttons, where
52 * clicking on a button results in activating the URL
53 * the button represents. This mode also supports drag
56 * The mode can be changed by a toggle button located on the left side of
59 * The URL navigator also remembers the URL history and allows to go
60 * back and forward within this history.
62 class UrlNavigator
: public QWidget
68 * @brief Represents the history element of an URL.
70 * A history element contains the URL, the name of the current file
71 * (the 'current file' is the file where the cursor is located) and
72 * the x- and y-position of the content.
77 HistoryElem(const KUrl
& url
);
78 ~HistoryElem(); // non virtual
80 const KUrl
& url() const { return m_url
; }
82 void setCurrentFileName(const QString
& name
) { m_currentFileName
= name
; }
83 const QString
& currentFileName() const { return m_currentFileName
; }
85 void setContentsX(int x
) { m_contentsX
= x
; }
86 int contentsX() const { return m_contentsX
; }
88 void setContentsY(int y
) { m_contentsY
= y
; }
89 int contentsY() const { return m_contentsY
; }
93 QString m_currentFileName
;
98 UrlNavigator(KBookmarkManager
* bookmarkManager
, const KUrl
& url
, QWidget
* parent
);
99 virtual ~UrlNavigator();
101 /** Returns the current active URL. */
102 const KUrl
& url() const;
104 /** Returns the portion of the current active URL up to the button at index. */
105 KUrl
url(int index
) const;
107 /** Returns the amount of items in the history */
108 int historySize() const;
111 * Returns one item out of the history. The index 0 indicates the oldest
113 * @param index Output parameter which indicates the current
114 * index of the location.
116 HistoryElem
currentHistoryItem() const;
119 * Goes back one step in the URL history. The signals
120 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
126 * Goes forward one step in the URL history. The signals
127 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
133 * Goes up one step of the URL path. The signals
134 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
140 * Goes to the home URL. The signals UrlNavigator::urlChanged
141 * and UrlNavigator::historyChanged are submitted.
146 * @return True, if the URL is editable by the user within a line editor.
147 * If false is returned, each part of the URL is presented by a button
148 * for fast navigation.
150 bool isUrlEditable() const;
153 * Switches to the edit mode and assures that the keyboard focus
156 void editUrl(bool editOrBrowse
); //TODO: switch to an enum
159 * Set the URL navigator to the active mode, if \a active
160 * is true. The active mode is default. Using the URL navigator
161 * in the inactive mode is useful when having split views,
162 * where the inactive view is indicated by a an inactive URL
163 * navigator visually.
165 void setActive(bool active
);
168 * Returns true, if the URL navigator is in the active mode.
169 * @see UrlNavigator::setActive()
171 bool isActive() const { return m_active
; }
174 * Sets whether or not to show hidden files in lists
176 void setShowHiddenFiles( bool show
);
179 * Returns true if the URL navigator is set to show hidden files
181 bool showHiddenFiles() { return m_showHiddenFiles
; }
184 * Handles the dropping of the URLs \a urls to the given
185 * destination \a destination and emits the signal urlsDropped.
187 void dropUrls(const KUrl::List
& urls
,
188 const KUrl
& destination
);
192 * Sets the current active URL.
193 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
196 void setUrl(const KUrl
& url
);
199 * Activates the URL navigator (UrlNavigator::isActive() will return true)
200 * and emits the signal 'activationChanged()'.
202 void requestActivation();
205 * Stores the coordinates of the contents into
206 * the current history element.
208 void storeContentsPosition(int x
, int y
);
212 * Is emitted, if the URL navigator has been activated by
213 * a user interaction.
218 * Is emitted, if the URL has been changed e. g. by
222 void urlChanged(const KUrl
& url
);
225 * Is emitted, if the history has been changed. Usually
226 * the history is changed if a new URL has been selected.
228 void historyChanged();
231 * Is emitted if the URLs \a urls have been dropped
232 * to the destination \a destination.
234 void urlsDropped(const KUrl::List
& urls
,
235 const KUrl
& destination
);
239 * If the Escape key is pressed, the navigation bar should switch
240 * to the browse mode.
242 virtual void keyReleaseEvent(QKeyEvent
* event
);
245 * Paste the clipboard content as URL, if the middle mouse
246 * button has been clicked.
248 virtual void mouseReleaseEvent(QMouseEvent
* event
);
251 void slotReturnPressed(const QString
& text
);
252 void slotUrlActivated(const KUrl
& url
);
253 void slotRemoteHostActivated();
254 void slotProtocolChanged(const QString
& protocol
);
255 void slotRedirection(const KUrl
&, const KUrl
&);
258 * Switches the navigation bar between the breadcrumb view and the
259 * traditional view (see setUrlEditable()) and is connected to the clicked signal
260 * of the navigation bar button.
266 * Allows to edit the Url of the navigation bar if \a editable
267 * is true. If \a editable is false, each part of
268 * the Url is presented by a button for a fast navigation.
270 void setUrlEditable(bool editable
);
273 * Updates the history element with the current file item
274 * and the contents position.
276 void updateHistoryElem();
277 void updateContent();
280 * Updates all buttons to have one button for each part of the
281 * path \a path. Existing buttons, which are available by m_navButtons,
282 * are reused if possible. If the path is longer, new buttons will be
283 * created, if the path is shorter, the remaining buttons will be deleted.
284 * @param startIndex Start index of path part (/), where the buttons
285 * should be created for each following part.
287 void updateButtons(const QString
& path
, int startIndex
);
290 * Deletes all URL navigator buttons. m_navButtons is
291 * empty after this operation.
293 void deleteButtons();
296 * Appends the widget at the end of the URL navigator. It is assured
297 * that the filler widget remains as last widget to fill the remaining
300 void appendWidget(QWidget
* widget
);
304 bool m_showHiddenFiles
;
307 QHBoxLayout
* m_layout
;
309 QList
<HistoryElem
> m_history
;
310 QToolButton
* m_toggleButton
;
311 BookmarkSelector
* m_bookmarkSelector
;
312 KUrlComboBox
* m_pathBox
;
313 ProtocolCombo
* m_protocols
;
314 QLabel
* m_protocolSeparator
;
316 QLinkedList
<UrlNavigatorButton
*> m_navButtons
;