1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef DOLPHINCONTROLLER_H
21 #define DOLPHINCONTROLLER_H
23 #include <dolphinview.h>
25 #include <QtCore/QObject>
26 #include <libdolphin_export.h>
28 class QAbstractItemView
;
36 // TODO: get rid of all the state duplications in the controller and allow read access
37 // to the Dolphin view for all view implementations
40 * @brief Acts as mediator between the abstract Dolphin view and the view
43 * The abstract Dolphin view (see DolphinView) represents the parent of the controller.
44 * The lifetime of the controller is equal to the lifetime of the Dolphin view.
45 * The controller is passed to the current view implementation
46 * (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
47 * by passing it in the constructor and informing the controller about the change
48 * of the view implementation:
51 * QAbstractItemView* view = new DolphinIconsView(parent, controller);
52 * controller->setItemView(view);
55 * The communication of the view implementations to the abstract view is done by:
56 * - triggerContextMenuRequest()
57 * - requestActivation()
58 * - triggerUrlChangeRequest()
59 * - indicateDroppedUrls()
60 * - indicateSortingChange()
61 * - indicateSortOrderChanged()
63 * - handleKeyPressEvent()
65 * - emitViewportEntered()
66 * - replaceUrlByClipboard()
68 * The communication of the abstract view to the view implementations is done by:
70 * - setShowHiddenFiles()
72 * - indicateActivationChange()
75 class LIBDOLPHINPRIVATE_EXPORT DolphinController
: public QObject
80 explicit DolphinController(DolphinView
* dolphinView
);
81 virtual ~DolphinController();
84 * Allows read access for the view implementation to the abstract
87 const DolphinView
* dolphinView() const;
90 * Sets the URL to \a url and emits the signal urlChanged() if
91 * \a url is different for the current URL. This method should
92 * be invoked by the abstract Dolphin view whenever the current
93 * URL has been changed.
95 void setUrl(const KUrl
& url
);
96 const KUrl
& url() const;
99 * Changes the current item view where the controller is working. This
100 * is only necessary for views like the tree view, where internally
101 * several QAbstractItemView instances are used.
103 void setItemView(QAbstractItemView
* view
);
105 QAbstractItemView
* itemView() const;
108 * Allows a view implementation to request an URL change to \a url.
109 * The signal requestUrlChange() is emitted and the abstract Dolphin view
110 * will assure that the URL of the Dolphin Controller will be updated
111 * later. Invoking this method makes only sense if the view implementation
112 * shows a hierarchy of URLs and allows to change the URL within
113 * the view (e. g. this is the case in the column view).
115 void triggerUrlChangeRequest(const KUrl
& url
);
118 * Requests a context menu for the position \a pos. This method
119 * should be invoked by the view implementation when a context
120 * menu should be opened. The abstract Dolphin view itself
121 * takes care itself to get the selected items depending from
124 void triggerContextMenuRequest(const QPoint
& pos
);
127 * Requests an activation of the view and emits the signal
128 * activated(). This method should be invoked by the view implementation
129 * if e. g. a mouse click on the view has been done.
130 * After the activation has been changed, the view implementation
131 * might listen to the activationChanged() signal.
133 void requestActivation();
136 * Indicates that URLs are dropped above a destination. This method
137 * should be invoked by the view implementation. The abstract Dolphin view
138 * will start the corresponding action (copy, move, link).
139 * @param destItem Item of the destination (can be null, see KFileItem::isNull()).
140 * @param destPath Path of the destination.
141 * @param event Drop event
143 void indicateDroppedUrls(const KFileItem
& destItem
,
144 const KUrl
& destPath
,
148 * Informs the abstract Dolphin view about a sorting change done inside
149 * the view implementation. This method should be invoked by the view
150 * implementation (e. g. the details view uses this method in combination
151 * with the details header).
153 void indicateSortingChange(DolphinView::Sorting sorting
);
156 * Informs the abstract Dolphin view about a sort order change done inside
157 * the view implementation. This method should be invoked by the view
158 * implementation (e. g. the details view uses this method in combination
159 * with the details header).
161 void indicateSortOrderChange(Qt::SortOrder order
);
164 * Informs the abstract Dolphin view about an additional information change
165 * done inside the view implementation. This method should be invoked by the
166 * view implementation (e. g. the details view uses this method in combination
167 * with the details header).
169 void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
);
172 * Informs the view implementation about a change of the activation
173 * state and is invoked by the abstract Dolphin view. The signal
174 * activationChanged() is emitted.
176 void indicateActivationChange(bool active
);
179 * Sets the zoom level to \a level and emits the signal zoomLevelChanged().
180 * It must be assured that the used level is inside the range
181 * DolphinController::zoomLevelMinimum() and
182 * DolphinController::zoomLevelMaximum().
183 * Is invoked by the abstract Dolphin view.
185 void setZoomLevel(int level
);
186 int zoomLevel() const;
189 * Tells the view implementation to zoom out by emitting the signal zoomOut()
190 * and is invoked by the abstract Dolphin view.
192 void triggerZoomOut();
195 * Should be invoked in each view implementation whenever a key has been
196 * pressed. If the selection model of \a view is not empty and
197 * the return key has been pressed, the selected items will get triggered.
199 void handleKeyPressEvent(QKeyEvent
* event
);
202 * Replaces the URL of the abstract Dolphin view with the content
203 * of the clipboard as URL. If the clipboard contains no text,
204 * nothing will be done.
206 void replaceUrlByClipboard();
209 * Returns the file item for the proxy index \a index of the view \a view.
211 KFileItem
itemForIndex(const QModelIndex
& index
) const;
215 * Emits the signal itemTriggered() if the file item for the index \a index
216 * is not null. The method should be invoked by the
217 * controller parent whenever the user has triggered an item.
219 void triggerItem(const QModelIndex
& index
);
222 * Emits the signal itemEntered() if the file item for the index \a index
223 * is not null. The method should be invoked by the controller parent
224 * whenever the mouse cursor is above an item.
226 void emitItemEntered(const QModelIndex
& index
);
229 * Emits the signal viewportEntered(). The method should be invoked by
230 * the controller parent whenever the mouse cursor is above the viewport.
232 void emitViewportEntered();
236 * Is emitted if the URL for the Dolphin controller has been changed
239 void urlChanged(const KUrl
& url
);
242 * Is emitted if the view implementation requests a changing of the current
243 * URL to \a url (see triggerUrlChangeRequest()).
245 void requestUrlChange(const KUrl
& url
);
248 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
249 * The abstract Dolphin view connects to this signal and will open the context menu.
250 * @param pos Position relative to the view widget where the
251 * context menu should be opened. It is recommended
252 * to get the corresponding model index from
255 void requestContextMenu(const QPoint
& pos
);
258 * Is emitted if the view has been activated by e. g. a mouse click.
259 * The abstract Dolphin view connects to this signal to know the
260 * destination view for the menu actions.
265 * Is emitted if URLs have been dropped to the destination
266 * path \a destPath. If the URLs have been dropped above an item of
267 * the destination path, the item is indicated by \a destItem
268 * (can be null, see KFileItem::isNull()).
270 void urlsDropped(const KFileItem
& destItem
,
271 const KUrl
& destPath
,
275 * Is emitted if the sorting has been changed to \a sorting by
276 * the view implementation (see indicateSortingChanged().
277 * The abstract Dolphin view connects to
278 * this signal to update its menu action.
280 void sortingChanged(DolphinView::Sorting sorting
);
283 * Is emitted if the sort order has been changed to \a order
284 * by the view implementation (see indicateSortOrderChanged().
285 * The abstract Dolphin view connects
286 * to this signal to update its menu actions.
288 void sortOrderChanged(Qt::SortOrder order
);
291 * Is emitted if the additional info has been changed to \a info
292 * by the view implementation. The abstract Dolphin view connects
293 * to this signal to update its menu actions.
295 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
298 * Is emitted if the activation state has been changed to \a active
299 * by the abstract Dolphin view.
300 * The view implementation might connect to this signal if custom
301 * updates are required in this case.
303 void activationChanged(bool active
);
306 * Is emitted if the item \a item should be triggered. The abstract
307 * Dolphin view connects to this signal. If the item represents a directory,
308 * the directory is opened. On a file the corresponding application is opened.
309 * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
311 void itemTriggered(const KFileItem
& item
);
314 * Is emitted if the mouse cursor has entered the item
315 * given by \a index (see emitItemEntered()).
316 * The abstract Dolphin view connects to this signal.
318 void itemEntered(const KFileItem
& item
);
321 * Is emitted if a new tab should be opened for the URL \a url.
323 void tabRequested(const KUrl
& url
);
326 * Is emitted if the mouse cursor has entered
327 * the viewport (see emitViewportEntered().
328 * The abstract Dolphin view connects to this signal.
330 void viewportEntered();
333 * Is emitted if the view should change the zoom to \a level. The view implementation
334 * must connect to this signal if it supports zooming.
336 void zoomLevelChanged(int level
);
339 void updateOpenTabState();
343 bool m_openTab
; // TODO: this is a workaround until Qt-issue 176832 has been fixed
345 DolphinView
* m_dolphinView
;
346 QAbstractItemView
* m_itemView
;
349 inline const DolphinView
* DolphinController::dolphinView() const
351 return m_dolphinView
;
354 inline const KUrl
& DolphinController::url() const
359 inline QAbstractItemView
* DolphinController::itemView() const
364 inline int DolphinController::zoomLevel() const