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