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
29 class KBookmarkManager
;
33 * @brief Navigation bar which contains the current shown URL.
35 * The URL navigator offers two modes:
36 * - Editable: Represents the 'classic' mode, where the current URL
37 * is editable inside a line editor.
38 * - Non editable: The URL is represented by a number of buttons, where
39 * clicking on a button results in activating the URL
40 * the button represents. This mode also supports drag
43 * The mode can be changed by a toggle button located on the left side of
46 * The URL navigator also remembers the URL history and allows to go
47 * back and forward within this history.
49 class UrlNavigator
: public QWidget
55 * @brief Represents the history element of an URL.
57 * A history element contains the URL, the name of the current file
58 * (the 'current file' is the file where the cursor is located) and
59 * the x- and y-position of the content.
64 HistoryElem(const KUrl
& url
);
65 ~HistoryElem(); // non virtual
67 const KUrl
& url() const { return m_url
; }
69 void setCurrentFileName(const QString
& name
) { m_currentFileName
= name
; }
70 const QString
& currentFileName() const { return m_currentFileName
; }
72 void setContentsX(int x
) { m_contentsX
= x
; }
73 int contentsX() const { return m_contentsX
; }
75 void setContentsY(int y
) { m_contentsY
= y
; }
76 int contentsY() const { return m_contentsY
; }
80 QString m_currentFileName
;
85 UrlNavigator(KBookmarkManager
* bookmarkManager
, const KUrl
& url
, QWidget
* parent
);
86 virtual ~UrlNavigator();
88 /** Returns the current active URL. */
89 const KUrl
& url() const;
91 /** Returns the portion of the current active URL up to the button at index. */
92 KUrl
url(int index
) const;
94 /** Returns the amount of items in the history */
95 int historySize() const;
98 * Returns one item out of the history. The index 0 indicates the oldest
100 * @param index Output parameter which indicates the current
101 * index of the location.
103 HistoryElem
currentHistoryItem() const;
106 * Goes back one step in the URL history. The signals
107 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
113 * Goes forward one step in the URL history. The signals
114 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
120 * Goes up one step of the URL path. The signals
121 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
127 * Goes to the home URL. The signals UrlNavigator::urlChanged
128 * and UrlNavigator::historyChanged are submitted.
133 * @return True, if the URL is editable by the user within a line editor.
134 * If false is returned, each part of the URL is presented by a button
135 * for fast navigation.
137 bool isUrlEditable() const;
140 * Switches to the edit mode and assures that the keyboard focus
143 void editUrl(bool editOrBrowse
); //TODO: switch to an enum
146 * Set the URL navigator to the active mode, if \a active
147 * is true. The active mode is default. Using the URL navigator
148 * in the inactive mode is useful when having split views,
149 * where the inactive view is indicated by a an inactive URL
150 * navigator visually.
152 void setActive(bool active
);
155 * Returns true, if the URL navigator is in the active mode.
156 * @see UrlNavigator::setActive()
158 bool isActive() const;
161 * Sets whether or not to show hidden files in lists
163 void setShowHiddenFiles( bool show
);
166 * Returns true if the URL navigator is set to show hidden files
168 bool showHiddenFiles() const; // TODO rename, looks like a verb
171 * Handles the dropping of the URLs \a urls to the given
172 * destination \a destination and emits the signal urlsDropped.
174 void dropUrls(const KUrl::List
& urls
,
175 const KUrl
& destination
);
179 * Sets the current active URL.
180 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
183 void setUrl(const KUrl
& url
);
186 * Activates the URL navigator (UrlNavigator::isActive() will return true)
187 * and emits the signal 'activationChanged()'.
189 void requestActivation();
192 * Stores the coordinates of the contents into
193 * the current history element.
195 void storeContentsPosition(int x
, int y
);
199 * Is emitted, if the URL navigator has been activated by
200 * a user interaction.
205 * Is emitted, if the URL has been changed e. g. by
209 void urlChanged(const KUrl
& url
);
212 * Is emitted, if the history has been changed. Usually
213 * the history is changed if a new URL has been selected.
215 void historyChanged();
218 * Is emitted if the URLs \a urls have been dropped
219 * to the destination \a destination.
221 void urlsDropped(const KUrl::List
& urls
,
222 const KUrl
& destination
);
226 * If the Escape key is pressed, the navigation bar should switch
227 * to the browse mode.
229 virtual void keyReleaseEvent(QKeyEvent
* event
);
232 * Paste the clipboard content as URL, if the middle mouse
233 * button has been clicked.
235 virtual void mouseReleaseEvent(QMouseEvent
* event
);
238 Q_PRIVATE_SLOT(d
, void slotReturnPressed(const QString
& text
))
239 Q_PRIVATE_SLOT(d
, void slotRemoteHostActivated())
240 Q_PRIVATE_SLOT(d
, void slotProtocolChanged(const QString
& protocol
))
241 Q_PRIVATE_SLOT(d
, void switchView())
242 //Q_PRIVATE_SLOT(d, void slotRedirection(const KUrl&, const KUrl&))
248 Q_DISABLE_COPY( UrlNavigator
)