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