]> cloud.milkyroute.net Git - dolphin.git/blob - src/urlnavigator.h
commited initial version of Dolphin
[dolphin.git] / src / urlnavigator.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #ifndef URLNAVIGATOR_H
22 #define URLNAVIGATOR_H
23
24 #include <q3hbox.h>
25 //Added by qt3to4:
26 #include <QLabel>
27 #include <Q3ValueList>
28 #include <QKeyEvent>
29 #include <Q3PopupMenu>
30 #include <kurl.h>
31 #include <qstring.h>
32
33 class QComboBox;
34 class QLabel;
35 class QLineEdit;
36 class Q3PopupMenu;
37 class QCheckBox;
38
39 class KUrl;
40 class KFileItem;
41 class KUrlComboBox;
42
43 class BookmarkSelector;
44 class DolphinView;
45 class ProtocolCombo;
46
47 /**
48 * @brief Navigation bar which contains the current shown URL.
49 *
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
56 * and drop of items.
57 *
58 * The mode can be changed by a toggle button located on the left side of
59 * the navigator.
60 *
61 * The URL navigator also remembers the URL history and allows to go
62 * back and forward within this history.
63 *
64 * @author Peter Penz
65 */
66
67 typedef Q3ValueList<KUrl> UrlStack;
68
69 class URLNavigator : public Q3HBox
70 {
71 Q_OBJECT
72
73 public:
74 /**
75 * @brief Represents the history element of an URL.
76 *
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.
80 */
81 class HistoryElem {
82 public:
83 HistoryElem();
84 HistoryElem(const KUrl& url);
85 ~HistoryElem(); // non virtual
86
87 const KUrl& url() const { return m_url; }
88
89 void setCurrentFileName(const QString& name) { m_currentFileName = name; }
90 const QString& currentFileName() const { return m_currentFileName; }
91
92 void setContentsX(int x) { m_contentsX = x; }
93 int contentsX() const { return m_contentsX; }
94
95 void setContentsY(int y) { m_contentsY = y; }
96 int contentsY() const { return m_contentsY; }
97
98 private:
99 KUrl m_url;
100 QString m_currentFileName;
101 int m_contentsX;
102 int m_contentsY;
103 };
104
105 URLNavigator(const KUrl& url, DolphinView* dolphinView);;
106 virtual ~URLNavigator();
107
108 /**
109 * Sets the current active URL.
110 * The signals URLNavigator::urlChanged and URLNavigator::historyChanged
111 * are submitted.
112 */
113 void setURL(const KUrl& url);
114
115 /** Returns the current active URL. */
116 const KUrl& url() const;
117
118 /** Returns the portion of the current active URL up to the button at index. */
119 KUrl url(int index) const;
120
121 /**
122 * Returns the complete URL history. The index 0 indicates the oldest
123 * history element.
124 * @param index Output parameter which indicates the current
125 * index of the location.
126 */
127 const Q3ValueList<HistoryElem>& history(int& index) const;
128
129 /**
130 * Goes back one step in the URL history. The signals
131 * URLNavigator::urlChanged and URLNavigator::historyChanged
132 * are submitted.
133 */
134 void goBack();
135
136 /**
137 * Goes forward one step in the URL history. The signals
138 * URLNavigator::urlChanged and URLNavigator::historyChanged
139 * are submitted.
140 */
141 void goForward();
142
143 /**
144 * Goes up one step of the URL path. The signals
145 * URLNavigator::urlChanged and URLNavigator::historyChanged
146 * are submitted.
147 */
148 void goUp();
149
150 /**
151 * Goes to the home URL. The signals URLNavigator::urlChanged
152 * and URLNavigator::historyChanged are submitted.
153 */
154 void goHome();
155
156 /**
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.
160 */
161 bool isURLEditable() const;
162
163 /**
164 * Switches to the edit mode and assures that the keyboard focus
165 * is assigned.
166 */
167 void editURL(bool editOrBrowse); //TODO: switch to an enum
168
169 DolphinView* dolphinView() const;
170
171 signals:
172 void urlChanged(const KUrl& url);
173 void historyChanged();
174
175 protected:
176 /** If the Escape key is pressed, the navigation bar should switch
177 to the browse mode. */
178 virtual void keyReleaseEvent(QKeyEvent* event);
179
180 private slots:
181 void slotReturnPressed(const QString& text);
182 void slotURLActivated(const KUrl& url);
183 void slotRemoteHostActivated();
184 void slotProtocolChanged(const QString& protocol);
185
186 void slotRequestActivation();
187 void slotBookmarkActivated(int index);
188
189 void slotRedirection(const KUrl&, const KUrl&);
190
191 /**
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.
195 */
196 void slotContentsMoved(int x, int y);
197
198 /**
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.
202 */
203 void slotClicked();
204
205 private:
206 int m_historyIndex;
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;
214 QLineEdit* m_host;
215 Q3ValueList<QWidget*> m_navButtons;
216 //UrlStack m_urls;
217
218 /**
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.
222 */
223 void setURLEditable(bool editable);
224
225 /**
226 * Updates the history element with the current file item
227 * and the contents position.
228 */
229 void updateHistoryElem();
230 void updateContent();
231 };
232
233 #endif