]> cloud.milkyroute.net Git - dolphin.git/blob - src/urlnavigator.h
Cleanup of URL drop handling (simplified code, modifier keys work again). After furth...
[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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #ifndef UrlNAVIGATOR_H
22 #define UrlNAVIGATOR_H
23
24
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 #include <kvbox.h>
33
34 class QComboBox;
35 class QLabel;
36 class QLineEdit;
37 class Q3PopupMenu;
38 class QCheckBox;
39
40 class KUrl;
41 class KFileItem;
42 class KUrlComboBox;
43
44 class BookmarkSelector;
45 class DolphinView;
46 class ProtocolCombo;
47
48 /**
49 * @brief Navigation bar which contains the current shown Url.
50 *
51 * The Url navigator offers two modes:
52 * - Editable: Represents the 'classic' mode, where the current Url
53 * is editable inside a line editor.
54 * - Non editable: The Url is represented by a number of buttons, where
55 * clicking on a button results in activating the Url
56 * the button represents. This mode also supports drag
57 * and drop of items.
58 *
59 * The mode can be changed by a toggle button located on the left side of
60 * the navigator.
61 *
62 * The Url navigator also remembers the Url history and allows to go
63 * back and forward within this history.
64 *
65 * @author Peter Penz
66 */
67
68 typedef Q3ValueList<KUrl> UrlStack;
69
70 class UrlNavigator : public KHBox
71 {
72 Q_OBJECT
73
74 public:
75 /**
76 * @brief Represents the history element of an Url.
77 *
78 * A history element contains the Url, the name of the current file
79 * (the 'current file' is the file where the cursor is located) and
80 * the x- and y-position of the content.
81 */
82 class HistoryElem {
83 public:
84 HistoryElem();
85 HistoryElem(const KUrl& url);
86 ~HistoryElem(); // non virtual
87
88 const KUrl& url() const { return m_url; }
89
90 void setCurrentFileName(const QString& name) { m_currentFileName = name; }
91 const QString& currentFileName() const { return m_currentFileName; }
92
93 void setContentsX(int x) { m_contentsX = x; }
94 int contentsX() const { return m_contentsX; }
95
96 void setContentsY(int y) { m_contentsY = y; }
97 int contentsY() const { return m_contentsY; }
98
99 private:
100 KUrl m_url;
101 QString m_currentFileName;
102 int m_contentsX;
103 int m_contentsY;
104 };
105
106 UrlNavigator(const KUrl& url, DolphinView* dolphinView);
107 virtual ~UrlNavigator();
108
109 /**
110 * Sets the current active Url.
111 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
112 * are submitted.
113 */
114 void setUrl(const KUrl& url);
115
116 /** Returns the current active Url. */
117 const KUrl& url() const;
118
119 /** Returns the portion of the current active Url up to the button at index. */
120 KUrl url(int index) const;
121
122 /**
123 * Returns the complete Url history. The index 0 indicates the oldest
124 * history element.
125 * @param index Output parameter which indicates the current
126 * index of the location.
127 */
128 const Q3ValueList<HistoryElem>& history(int& index) const;
129
130 /**
131 * Goes back one step in the Url history. The signals
132 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
133 * are submitted.
134 */
135 void goBack();
136
137 /**
138 * Goes forward one step in the Url history. The signals
139 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
140 * are submitted.
141 */
142 void goForward();
143
144 /**
145 * Goes up one step of the Url path. The signals
146 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
147 * are submitted.
148 */
149 void goUp();
150
151 /**
152 * Goes to the home Url. The signals UrlNavigator::urlChanged
153 * and UrlNavigator::historyChanged are submitted.
154 */
155 void goHome();
156
157 /**
158 * @return True, if the Url is editable by the user within a line editor.
159 * If false is returned, each part of the Url is presented by a button
160 * for fast navigation.
161 */
162 bool isUrlEditable() const;
163
164 /**
165 * Switches to the edit mode and assures that the keyboard focus
166 * is assigned.
167 */
168 void editUrl(bool editOrBrowse); //TODO: switch to an enum
169
170 DolphinView* dolphinView() const;
171
172 signals:
173 void urlChanged(const KUrl& url);
174 void historyChanged();
175
176 protected:
177 /** If the Escape key is pressed, the navigation bar should switch
178 to the browse mode. */
179 virtual void keyReleaseEvent(QKeyEvent* event);
180
181 private slots:
182 void slotReturnPressed(const QString& text);
183 void slotUrlActivated(const KUrl& url);
184 void slotRemoteHostActivated();
185 void slotProtocolChanged(const QString& protocol);
186
187 void slotRequestActivation();
188 void slotBookmarkActivated(int index);
189
190 void slotRedirection(const KUrl&, const KUrl&);
191
192 /**
193 * Stores the coordinates of the moved content into
194 * the current history element. Is usually triggered
195 * by the signal 'contentsMoved' emitted by DolphinView.
196 */
197 void slotContentsMoved(int x, int y);
198
199 /**
200 * Switches the navigation bar between the editable and noneditable
201 * state (see setUrlEditable()) and is connected to the clicked signal
202 * of the navigation bar button.
203 */
204 void slotClicked();
205
206 private:
207 int m_historyIndex;
208 DolphinView* m_dolphinView;
209 Q3ValueList<HistoryElem> m_history;
210 QCheckBox* m_toggleButton;
211 BookmarkSelector* m_bookmarkSelector;
212 KUrlComboBox* m_pathBox;
213 ProtocolCombo* m_protocols;
214 QLabel* m_protocolSeparator;
215 QLineEdit* m_host;
216 Q3ValueList<QWidget*> m_navButtons;
217 //UrlStack m_urls;
218
219 /**
220 * Allows to edit the Url of the navigation bar if \a editable
221 * is true. If \a editable is false, each part of
222 * the Url is presented by a button for a fast navigation.
223 */
224 void setUrlEditable(bool editable);
225
226 /**
227 * Updates the history element with the current file item
228 * and the contents position.
229 */
230 void updateHistoryElem();
231 void updateContent();
232 };
233
234 #endif