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