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