]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
Make it (almost) possible to have more than one Dolphin KMainWindow
[dolphin.git] / src / dolphinview.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
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
22 #ifndef _DOLPHINVIEW_H_
23 #define _DOLPHINVIEW_H_
24
25 #include <qwidget.h>
26 //Added by qt3to4:
27 #include <QDropEvent>
28 #include <Q3ValueList>
29 #include <QMouseEvent>
30 #include <Q3VBoxLayout>
31 #include <kparts/part.h>
32 #include <kfileitem.h>
33 #include <kfileiconview.h>
34 #include <kio/job.h>
35 #include <urlnavigator.h>
36
37 #include <QListView>
38
39 class QPainter;
40 class KUrl;
41 class KDirModel;
42 class QLineEdit;
43 class UrlNavigator;
44 class QTimer;
45 class Q3IconViewItem;
46 class Q3ListViewItem;
47 class Q3VBoxLayout;
48 //class KFileView;
49 class DolphinMainWindow;
50 class DolphinDirLister;
51 class DolphinStatusBar;
52 class DolphinIconsView;
53 class DolphinDetailsView;
54 class ViewProperties;
55 class Q3ScrollView;
56 class KProgress;
57 class ItemEffectsManager;
58 class FilterBar;
59
60 class QModelIndex;
61
62 /**
63 * @short Represents a view for the directory content
64 * including the navigation bar and status bar.
65 *
66 * View modes for icons, details and previews are supported. Currently
67 * Dolphin allows to have up to two views inside the main window.
68 *
69 * @see DolphinIconsView
70 * @see DolphinDetailsView
71 * @see UrlNavigator
72 * @see DolphinStatusBar
73 *
74 * @author Peter Penz <peter.penz@gmx.at>
75 */
76 class DolphinView : public QWidget
77 {
78 Q_OBJECT
79
80 public:
81 /**
82 * Defines the view mode for a directory. The view mode
83 * can be defined when constructing a DolphinView. The
84 * view mode is automatically updated if the directory itself
85 * defines a view mode (see class ViewProperties for details).
86 */
87 enum Mode
88 {
89 /**
90 * The directory items are shown as icons including an
91 * icon name. */
92 IconsView = 0,
93
94 /**
95 * The icon, the name and at least the size of the directory
96 * items are shown in a table. It is possible to add columns
97 * for date, group and permissions.
98 */
99 DetailsView = 1,
100
101 /**
102 * The directory items are shown as preview if possible. As
103 * fallback the items are shown as icons.
104 */
105 PreviewsView = 2,
106 MaxModeEnum = PreviewsView
107 };
108
109 /** Defines the sort order for the items of a directory. */
110 enum Sorting
111 {
112 SortByName = 0,
113 SortBySize = 1,
114 SortByDate = 2,
115 MaxSortEnum = SortByDate
116 };
117
118 DolphinView(DolphinMainWindow* mainwindow,
119 QWidget *parent,
120 const KUrl& url,
121 Mode mode = IconsView,
122 bool showHiddenFiles = false);
123
124 virtual ~DolphinView();
125
126 /**
127 * Sets the current active Url.
128 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
129 * are submitted.
130 */
131 void setUrl(const KUrl& url);
132
133 /** Returns the current active Url. */
134 const KUrl& url() const;
135
136 void requestActivation();
137 bool isActive() const;
138
139 void setMode(Mode mode);
140 Mode mode() const;
141 void setShowHiddenFilesEnabled(bool show);
142 bool isShowHiddenFilesEnabled() const;
143
144 void setViewProperties(const ViewProperties& props);
145
146 /**
147 * Triggers the renaming of the currently selected items, where
148 * the user must input a new name for the items.
149 */
150 void renameSelectedItems();
151
152 /**
153 * Selects all items.
154 * @see DolphinView::selectedItems()
155 */
156 void selectAll();
157
158 /**
159 * Inverts the current selection: selected items get unselected,
160 * unselected items get selected.
161 * @see DolphinView::selectedItems()
162 */
163 void invertSelection();
164
165 /**
166 * Goes back one step in the Url history. The signals
167 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
168 * are submitted.
169 */
170 void goBack();
171
172 /**
173 * Goes forward one step in the Url history. The signals
174 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
175 * are submitted.
176 */
177 void goForward();
178
179 /**
180 * Goes up one step of the Url path. The signals
181 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
182 * are submitted.
183 */
184 void goUp();
185
186 /**
187 * Goes to the home Url. The signals UrlNavigator::urlChanged
188 * and UrlNavigator::historyChanged are submitted.
189 */
190 void goHome();
191
192 /**
193 * Sets the Url of the navigation bar to an editable state
194 * if \a editable is true. If \a editable is false, each part of
195 * the location is presented by a button for a fast navigation.
196 */
197 void setUrlEditable(bool editable);
198
199 /**
200 * Returns the complete Url history. The index 0 indicates the oldest
201 * history element.
202 * @param index Output parameter which indicates the current
203 * index of the location.
204 */
205 const Q3ValueList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
206
207 /**
208 * Returns true, if at least one item is selected.
209 */
210 bool hasSelection() const;
211
212 /**
213 * Returns the selected items. 0 is returned, if no item
214 * is selected.
215 * @see DolphinView::selectedUrls()
216 */
217 const KFileItemList* selectedItems() const;
218
219 /**
220 * Returns a list of Urls for all selected items. An empty list
221 * is returned, if no item is selected.
222 * @see DolphinView::selectedItems()
223 */
224 KUrl::List selectedUrls() const;
225
226 /**
227 * Returns the current item, where the cursor is. 0 is returned, if there is no
228 * current item (e. g. if the view is empty). Note that the current item must
229 * not be a selected item.
230 * @see DolphinView::selectedItems()
231 */
232 const KFileItem* currentFileItem() const;
233
234 /**
235 * Opens the context menu for the item indicated by \a fileInfo
236 * on the position \a pos. If 0 is passed for the file info, a context
237 * menu for the viewport is opened.
238 */
239 void openContextMenu(KFileItem* fileInfo, const QPoint& pos);
240
241 /**
242 * Renames the filename of the source Url by the new file name.
243 * If the new file name already exists, a dialog is opened which
244 * asks the user to enter a new name.
245 */
246 void rename(const KUrl& source, const QString& newName);
247
248 /** Returns the status bar of the view. */
249 DolphinStatusBar* statusBar() const;
250
251 /**
252 * Returns the x-position of the view content.
253 * The content of the view might be larger than the visible area
254 * and hence a scrolling must be done.
255 */
256 int contentsX() const;
257
258 /**
259 * Returns the y-position of the view content.
260 * The content of the view might be larger than the visible area
261 * and hence a scrolling must be done.
262 */
263 int contentsY() const;
264
265 /**
266 * Returns true, if the Url shown by the navigation bar is editable.
267 * @see UrlNavigator
268 */
269 bool isUrlEditable() const;
270
271 /** Increases the size of the current set view mode. */
272 void zoomIn();
273
274 /** Decreases the size of the current set view mode. */
275 void zoomOut();
276
277 /**
278 * Returns true, if zooming in is possible. If false is returned,
279 * the minimal zoom size is possible.
280 */
281 bool isZoomInPossible() const;
282
283 /**
284 * Returns true, if zooming out is possible. If false is returned,
285 * the maximum zoom size is possible.
286 */
287 bool isZoomOutPossible() const;
288
289 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
290 void setSorting(Sorting sorting);
291
292 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
293 Sorting sorting() const;
294
295 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
296 void setSortOrder(Qt::SortOrder order);
297
298 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
299 Qt::SortOrder sortOrder() const;
300
301 /** Refreshs the view settings by reading out the stored settings. */
302 void refreshSettings();
303
304 /**
305 * Updates the number of items (= number of files + number of
306 * directories) in the statusbar. If files are selected, the number
307 * of selected files and the sum of the filesize is shown.
308 */
309 void updateStatusBar();
310
311 /** Returns the UrlNavigator of the view for read access. */
312 const UrlNavigator* urlNavigator() const { return m_urlNavigator; }
313
314 /**
315 * Triggers to request user information for the item given
316 * by the Url \a url. The signal signalRequestItemInfo is emitted,
317 * which provides a way for widgets to get an indication to update
318 * the item information.
319 */
320 void requestItemInfo(const KUrl& url);
321
322 /**
323 * Checks if the filter bar is visible.
324 *
325 * @return @c true Filter bar is visible.
326 * @return @c false Filter bar is not visible.
327 */
328 bool isFilterBarVisible();
329
330 /**
331 * Return the DolphinMainWindow this View belongs to. It is guranteed
332 * that we have one.
333 */
334 DolphinMainWindow* mainWindow() const ;
335
336 public slots:
337 void reload();
338 void slotUrlListDropped(QDropEvent* event,
339 const KUrl::List& urls,
340 const KUrl& url);
341
342 /**
343 * Slot that popups the filter bar like FireFox popups his Search bar.
344 */
345 void slotShowFilterBar(bool show);
346
347 /**
348 * Declare this View as the activeview of the mainWindow()
349 */
350 void declareViewActive();
351
352 signals:
353 /** Is emitted if Url of the view has been changed to \a url. */
354 void signalUrlChanged(const KUrl& url);
355
356 /**
357 * Is emitted if the view mode (IconsView, DetailsView,
358 * PreviewsView) has been changed.
359 */
360 void signalModeChanged();
361
362 /** Is emitted if the 'show hidden files' property has been changed. */
363 void signalShowHiddenFilesChanged();
364
365 /** Is emitted if the sorting by name, size or date has been changed. */
366 void signalSortingChanged(DolphinView::Sorting sorting);
367
368 /** Is emitted if the sort order (ascending or descending) has been changed. */
369 void signalSortOrderChanged(Qt::SortOrder order);
370
371 /**
372 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
373 * It the Url is empty, no item information request is pending.
374 */
375 void signalRequestItemInfo(const KUrl& url);
376
377 /** Is emitted if the contents has been moved to \a x, \a y. */
378 void contentsMoved(int x, int y);
379
380 /**
381 * Is emitted whenever the selection has been changed. The current selection can
382 * be retrieved by mainWindow()->activeView()->selectedItems() or by
383 * mainWindow()->activeView()->selectedUrls().
384 */
385 void signalSelectionChanged();
386
387 /**
388 * Is emitted whenever the directory view is redirected by an ioslave
389 */
390 void redirection(const KUrl& oldUrl, const KUrl& newUrl);
391
392 protected:
393 /** @see QWidget::mouseReleaseEvent */
394 virtual void mouseReleaseEvent(QMouseEvent* event);
395
396
397 private slots:
398 void slotUrlChanged(const KUrl& kurl);
399 void triggerIconsViewItem(Q3IconViewItem *item);
400 void triggerItem(const QModelIndex& index);
401 void updateUrl();
402
403 void slotPercent(int percent);
404 void slotClear();
405 void slotDeleteItem(KFileItem* item);
406 void slotCompleted();
407 void slotInfoMessage(const QString& msg);
408 void slotErrorMessage(const QString& msg);
409
410 void slotGrabActivation();
411
412 /**
413 * Is invoked shortly before the contents of a view implementation
414 * has been moved and emits the signal contentsMoved. Note that no
415 * signal is emitted when the contents moving is only temporary by
416 * e. g. reloading a directory.
417 */
418 void slotContentsMoving(int x, int y);
419
420 /**
421 * Filters the currently shown items by \a nameFilter. All items
422 * which contain the given filter string will be shown.
423 */
424 void slotChangeNameFilter(const QString& nameFilter);
425
426 private:
427 //KFileView* fileView() const;
428 Q3ScrollView* scrollView() const;
429 ItemEffectsManager* itemEffectsManager() const;
430 void startDirLister(const KUrl& url, bool reload = false);
431
432 /**
433 * Returns the default text of the status bar, if no item is
434 * selected.
435 */
436 QString defaultStatusBarText() const;
437
438 /**
439 * Returns the text for the status bar, if at least one item
440 * is selected.
441 */
442 QString selectionStatusBarText() const;
443
444 /**
445 * Returns the string representation for the index \a index
446 * for renaming \itemCount items.
447 */
448 QString renameIndexPresentation(int index, int itemCount) const;
449
450 /**
451 * Applies the current view mode m_mode to the
452 * view implementation.
453 */
454 void applyModeToView();
455
456 DolphinMainWindow *m_mainWindow;
457 bool m_refreshing;
458 bool m_showProgress;
459 Mode m_mode;
460
461 Q3VBoxLayout* m_topLayout;
462 UrlNavigator* m_urlNavigator;
463 DolphinIconsView* m_iconsView;
464 DolphinStatusBar* m_statusBar;
465
466 int m_iconSize;
467 int m_folderCount;
468 int m_fileCount;
469
470 DolphinDirLister* m_dirLister;
471
472 FilterBar *m_filterBar;
473 };
474
475 #endif // _DOLPHINVIEW_H_