1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef URLNAVIGATOR_H
22 #define URLNAVIGATOR_H
27 #include <Q3ValueList>
29 #include <Q3PopupMenu>
43 class BookmarkSelector
;
48 * @brief Navigation bar which contains the current shown URL.
50 * The URL navigator offers two modes:
51 * - Editable: Represents the 'classic' mode, where the current URL
52 * is editable inside a line editor.
53 * - Non editable: The URL is represented by a number of buttons, where
54 * clicking on a button results in activating the URL
55 * the button represents. This mode also supports drag
58 * The mode can be changed by a toggle button located on the left side of
61 * The URL navigator also remembers the URL history and allows to go
62 * back and forward within this history.
67 typedef Q3ValueList
<KUrl
> UrlStack
;
69 class URLNavigator
: public Q3HBox
75 * @brief Represents the history element of an URL.
77 * A history element contains the URL, the name of the current file
78 * (the 'current file' is the file where the cursor is located) and
79 * the x- and y-position of the content.
84 HistoryElem(const KUrl
& url
);
85 ~HistoryElem(); // non virtual
87 const KUrl
& url() const { return m_url
; }
89 void setCurrentFileName(const QString
& name
) { m_currentFileName
= name
; }
90 const QString
& currentFileName() const { return m_currentFileName
; }
92 void setContentsX(int x
) { m_contentsX
= x
; }
93 int contentsX() const { return m_contentsX
; }
95 void setContentsY(int y
) { m_contentsY
= y
; }
96 int contentsY() const { return m_contentsY
; }
100 QString m_currentFileName
;
105 URLNavigator(const KUrl
& url
, DolphinView
* dolphinView
);;
106 virtual ~URLNavigator();
109 * Sets the current active URL.
110 * The signals URLNavigator::urlChanged and URLNavigator::historyChanged
113 void setURL(const KUrl
& url
);
115 /** Returns the current active URL. */
116 const KUrl
& url() const;
118 /** Returns the portion of the current active URL up to the button at index. */
119 KUrl
url(int index
) const;
122 * Returns the complete URL history. The index 0 indicates the oldest
124 * @param index Output parameter which indicates the current
125 * index of the location.
127 const Q3ValueList
<HistoryElem
>& history(int& index
) const;
130 * Goes back one step in the URL history. The signals
131 * URLNavigator::urlChanged and URLNavigator::historyChanged
137 * Goes forward one step in the URL history. The signals
138 * URLNavigator::urlChanged and URLNavigator::historyChanged
144 * Goes up one step of the URL path. The signals
145 * URLNavigator::urlChanged and URLNavigator::historyChanged
151 * Goes to the home URL. The signals URLNavigator::urlChanged
152 * and URLNavigator::historyChanged are submitted.
157 * @return True, if the URL is editable by the user within a line editor.
158 * If false is returned, each part of the URL is presented by a button
159 * for fast navigation.
161 bool isURLEditable() const;
164 * Switches to the edit mode and assures that the keyboard focus
167 void editURL(bool editOrBrowse
); //TODO: switch to an enum
169 DolphinView
* dolphinView() const;
172 void urlChanged(const KUrl
& url
);
173 void historyChanged();
176 /** If the Escape key is pressed, the navigation bar should switch
177 to the browse mode. */
178 virtual void keyReleaseEvent(QKeyEvent
* event
);
181 void slotReturnPressed(const QString
& text
);
182 void slotURLActivated(const KUrl
& url
);
183 void slotRemoteHostActivated();
184 void slotProtocolChanged(const QString
& protocol
);
186 void slotRequestActivation();
187 void slotBookmarkActivated(int index
);
189 void slotRedirection(const KUrl
&, const KUrl
&);
192 * Stores the coordinates of the moved content into
193 * the current history element. Is usually triggered
194 * by the signal 'contentsMoved' emitted by DolphinView.
196 void slotContentsMoved(int x
, int y
);
199 * Switches the navigation bar between the editable and noneditable
200 * state (see setURLEditable()) and is connected to the clicked signal
201 * of the navigation bar button.
207 DolphinView
* m_dolphinView
;
208 Q3ValueList
<HistoryElem
> m_history
;
209 QCheckBox
* m_toggleButton
;
210 BookmarkSelector
* m_bookmarkSelector
;
211 KUrlComboBox
* m_pathBox
;
212 ProtocolCombo
* m_protocols
;
213 QLabel
* m_protocolSeparator
;
215 Q3ValueList
<QWidget
*> m_navButtons
;
219 * Allows to edit the URL of the navigation bar if \a editable
220 * is true. If \a editable is false, each part of
221 * the URL is presented by a button for a fast navigation.
223 void setURLEditable(bool editable
);
226 * Updates the history element with the current file item
227 * and the contents position.
229 void updateHistoryElem();
230 void updateContent();