]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.cpp
Let the user choose if folders are always shown first in the views of
[dolphin.git] / src / dolphinview.cpp
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 #include "dolphinview.h"
22
23 #include <QApplication>
24 #include <QClipboard>
25 #include <QKeyEvent>
26 #include <QItemSelection>
27 #include <QBoxLayout>
28 #include <QTimer>
29 #include <QScrollBar>
30
31 #include <kactioncollection.h>
32 #include <kcolorscheme.h>
33 #include <kdirlister.h>
34 #include <kfilepreviewgenerator.h>
35 #include <kiconeffect.h>
36 #include <kfileitem.h>
37 #include <klocale.h>
38 #include <kio/deletejob.h>
39 #include <kio/netaccess.h>
40 #include <kio/previewjob.h>
41 #include <kjob.h>
42 #include <kmenu.h>
43 #include <kmessagebox.h>
44 #include <kmimetyperesolver.h>
45 #include <konq_fileitemcapabilities.h>
46 #include <konq_operations.h>
47 #include <konqmimedata.h>
48 #include <kstringhandler.h>
49 #include <ktoggleaction.h>
50 #include <kurl.h>
51
52 #include "dolphinmodel.h"
53 #include "dolphincolumnview.h"
54 #include "dolphincontroller.h"
55 #include "dolphindetailsview.h"
56 #include "dolphinfileitemdelegate.h"
57 #include "dolphinnewmenuobserver.h"
58 #include "dolphinsortfilterproxymodel.h"
59 #include "dolphin_detailsmodesettings.h"
60 #include "dolphiniconsview.h"
61 #include "dolphin_generalsettings.h"
62 #include "draganddrophelper.h"
63 #include "folderexpander.h"
64 #include "renamedialog.h"
65 #include "tooltips/tooltipmanager.h"
66 #include "settings/dolphinsettings.h"
67 #include "viewproperties.h"
68 #include "zoomlevelinfo.h"
69
70 /**
71 * Helper function for sorting items with qSort() in
72 * DolphinView::renameSelectedItems().
73 */
74 bool lessThan(const KFileItem& item1, const KFileItem& item2)
75 {
76 return KStringHandler::naturalCompare(item1.name(), item2.name()) < 0;
77 }
78
79 DolphinView::DolphinView(QWidget* parent,
80 const KUrl& url,
81 KDirLister* dirLister,
82 DolphinModel* dolphinModel,
83 DolphinSortFilterProxyModel* proxyModel) :
84 QWidget(parent),
85 m_active(true),
86 m_showPreview(false),
87 m_loadingDirectory(false),
88 m_storedCategorizedSorting(false),
89 m_tabsForFiles(false),
90 m_isContextMenuOpen(false),
91 m_ignoreViewProperties(false),
92 m_assureVisibleCurrentIndex(false),
93 m_mode(DolphinView::IconsView),
94 m_topLayout(0),
95 m_controller(0),
96 m_iconsView(0),
97 m_detailsView(0),
98 m_columnView(0),
99 m_fileItemDelegate(0),
100 m_selectionModel(0),
101 m_dolphinModel(dolphinModel),
102 m_dirLister(dirLister),
103 m_proxyModel(proxyModel),
104 m_previewGenerator(0),
105 m_toolTipManager(0),
106 m_rootUrl(),
107 m_currentItemUrl(),
108 m_createdItemUrl(),
109 m_selectedItems(),
110 m_expandedDragSource(0)
111 {
112 m_topLayout = new QVBoxLayout(this);
113 m_topLayout->setSpacing(0);
114 m_topLayout->setMargin(0);
115
116 m_controller = new DolphinController(this);
117 m_controller->setUrl(url);
118
119 connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
120 this, SIGNAL(urlChanged(const KUrl&)));
121 connect(m_controller, SIGNAL(requestUrlChange(const KUrl&)),
122 this, SLOT(slotRequestUrlChange(const KUrl&)));
123
124 connect(m_controller, SIGNAL(requestContextMenu(const QPoint&, const QList<QAction*>&)),
125 this, SLOT(openContextMenu(const QPoint&, const QList<QAction*>&)));
126 connect(m_controller, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)),
127 this, SLOT(dropUrls(const KFileItem&, const KUrl&, QDropEvent*)));
128 connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
129 this, SLOT(updateSorting(DolphinView::Sorting)));
130 connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
131 this, SLOT(updateSortOrder(Qt::SortOrder)));
132 connect(m_controller, SIGNAL(sortFoldersFirstChanged(bool)),
133 this, SLOT(updateSortFoldersFirst(bool)));
134 connect(m_controller, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)),
135 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&)));
136 connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
137 this, SLOT(triggerItem(const KFileItem&)));
138 connect(m_controller, SIGNAL(tabRequested(const KUrl&)),
139 this, SIGNAL(tabRequested(const KUrl&)));
140 connect(m_controller, SIGNAL(activated()),
141 this, SLOT(activate()));
142 connect(m_controller, SIGNAL(itemEntered(const KFileItem&)),
143 this, SLOT(showHoverInformation(const KFileItem&)));
144 connect(m_controller, SIGNAL(viewportEntered()),
145 this, SLOT(clearHoverInformation()));
146
147 connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)),
148 this, SIGNAL(redirection(KUrl, KUrl)));
149 connect(m_dirLister, SIGNAL(completed()),
150 this, SLOT(restoreCurrentItem()));
151 connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
152 this, SLOT(slotRefreshItems()));
153
154 // When a new item has been created by the "Create New..." menu, the item should
155 // get selected and it must be assured that the item will get visible. As the
156 // creation is done asynchronously, several signals must be checked:
157 connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)),
158 this, SLOT(observeCreatedItem(const KUrl&)));
159
160 applyViewProperties(url);
161 m_topLayout->addWidget(itemView());
162 }
163
164 DolphinView::~DolphinView()
165 {
166 delete m_expandedDragSource;
167 m_expandedDragSource = 0;
168 }
169
170 const KUrl& DolphinView::url() const
171 {
172 return m_controller->url();
173 }
174
175 KUrl DolphinView::rootUrl() const
176 {
177 return isColumnViewActive() ? m_columnView->rootUrl() : url();
178 }
179
180 void DolphinView::setActive(bool active)
181 {
182 if (active == m_active) {
183 return;
184 }
185
186 m_active = active;
187
188 QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
189 if (active) {
190 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
191 // bypasses the problem when having a split view and changing the active view to
192 // update the some URL dependent states. A nicer approach should be no big deal...
193 emit urlChanged(url());
194 emit selectionChanged(selectedItems());
195 } else {
196 color.setAlpha(150);
197 }
198
199 QWidget* viewport = itemView()->viewport();
200 QPalette palette;
201 palette.setColor(viewport->backgroundRole(), color);
202 viewport->setPalette(palette);
203
204 update();
205
206 if (active) {
207 itemView()->setFocus();
208 emit activated();
209 }
210
211 m_controller->indicateActivationChange(active);
212 }
213
214 bool DolphinView::isActive() const
215 {
216 return m_active;
217 }
218
219 void DolphinView::setMode(Mode mode)
220 {
221 if (mode == m_mode) {
222 return; // the wished mode is already set
223 }
224
225 const int oldZoomLevel = m_controller->zoomLevel();
226 m_mode = mode;
227
228 deleteView();
229
230 const KUrl viewPropsUrl = viewPropertiesUrl();
231 ViewProperties props(viewPropsUrl);
232 props.setViewMode(m_mode);
233 createView();
234
235 // the file item delegate has been recreated, apply the current
236 // additional information manually
237 const KFileItemDelegate::InformationList infoList = props.additionalInfo();
238 m_fileItemDelegate->setShowInformation(infoList);
239 emit additionalInfoChanged();
240
241 // Not all view modes support categorized sorting. Adjust the sorting model
242 // if changing the view mode results in a change of the categorized sorting
243 // capabilities.
244 m_storedCategorizedSorting = props.categorizedSorting();
245 const bool categorized = m_storedCategorizedSorting && supportsCategorizedSorting();
246 if (categorized != m_proxyModel->isCategorizedModel()) {
247 m_proxyModel->setCategorizedModel(categorized);
248 emit categorizedSortingChanged();
249 }
250
251 emit modeChanged();
252
253 updateZoomLevel(oldZoomLevel);
254 if (m_showPreview) {
255 loadDirectory(viewPropsUrl);
256 }
257 }
258
259 DolphinView::Mode DolphinView::mode() const
260 {
261 return m_mode;
262 }
263
264 bool DolphinView::showPreview() const
265 {
266 return m_showPreview;
267 }
268
269 bool DolphinView::showHiddenFiles() const
270 {
271 return m_dirLister->showingDotFiles();
272 }
273
274 bool DolphinView::categorizedSorting() const
275 {
276 // If all view modes would support categorized sorting, returning
277 // m_proxyModel->isCategorizedModel() would be the way to go. As
278 // currently only the icons view supports caterized sorting, we remember
279 // the stored view properties state in m_storedCategorizedSorting and
280 // return this state. The application takes care to disable the corresponding
281 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
282 // that this setting is not applied to the current view mode.
283 return m_storedCategorizedSorting;
284 }
285
286 bool DolphinView::supportsCategorizedSorting() const
287 {
288 return m_iconsView != 0;
289 }
290
291 void DolphinView::selectAll()
292 {
293 QAbstractItemView* view = itemView();
294 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
295 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
296 // selection instead of selecting all items. This is bypassed for KDE 4.0
297 // by invoking clearSelection() first.
298 view->clearSelection();
299 view->selectAll();
300 }
301
302 void DolphinView::invertSelection()
303 {
304 if (isColumnViewActive()) {
305 // QAbstractItemView does not offer a virtual method invertSelection()
306 // as counterpart to QAbstractItemView::selectAll(). This makes it
307 // necessary to delegate the inverting of the selection to the
308 // column view, as only the selection of the active column should
309 // get inverted.
310 m_columnView->invertSelection();
311 } else {
312 QItemSelectionModel* selectionModel = itemView()->selectionModel();
313 const QAbstractItemModel* itemModel = selectionModel->model();
314
315 const QModelIndex topLeft = itemModel->index(0, 0);
316 const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
317 itemModel->columnCount() - 1);
318
319 const QItemSelection selection(topLeft, bottomRight);
320 selectionModel->select(selection, QItemSelectionModel::Toggle);
321 }
322 }
323
324 bool DolphinView::hasSelection() const
325 {
326 return itemView()->selectionModel()->hasSelection();
327 }
328
329 void DolphinView::clearSelection()
330 {
331 QItemSelectionModel* selModel = itemView()->selectionModel();
332 const QModelIndex currentIndex = selModel->currentIndex();
333 selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
334 QItemSelectionModel::Clear);
335 }
336
337 KFileItemList DolphinView::selectedItems() const
338 {
339 if (isColumnViewActive()) {
340 return m_columnView->selectedItems();
341 }
342
343 const QAbstractItemView* view = itemView();
344
345 // Our view has a selection, we will map them back to the DolphinModel
346 // and then fill the KFileItemList.
347 Q_ASSERT((view != 0) && (view->selectionModel() != 0));
348
349 const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
350 KFileItemList itemList;
351
352 const QModelIndexList indexList = selection.indexes();
353 foreach (const QModelIndex &index, indexList) {
354 KFileItem item = m_dolphinModel->itemForIndex(index);
355 if (!item.isNull()) {
356 itemList.append(item);
357 }
358 }
359
360 return itemList;
361 }
362
363 KUrl::List DolphinView::selectedUrls() const
364 {
365 KUrl::List urls;
366 const KFileItemList list = selectedItems();
367 foreach (const KFileItem &item, list) {
368 urls.append(item.url());
369 }
370 return urls;
371 }
372
373 int DolphinView::selectedItemsCount() const
374 {
375 if (isColumnViewActive()) {
376 // TODO: get rid of this special case by adjusting the dir lister
377 // to the current column
378 return m_columnView->selectedItems().count();
379 }
380
381 return itemView()->selectionModel()->selection().count();
382 }
383
384 void DolphinView::setContentsPosition(int x, int y)
385 {
386 QAbstractItemView* view = itemView();
387
388 // the ColumnView takes care itself for the horizontal scrolling
389 if (!isColumnViewActive()) {
390 view->horizontalScrollBar()->setValue(x);
391 }
392 view->verticalScrollBar()->setValue(y);
393
394 m_loadingDirectory = false;
395 }
396
397 QPoint DolphinView::contentsPosition() const
398 {
399 const int x = itemView()->horizontalScrollBar()->value();
400 const int y = itemView()->verticalScrollBar()->value();
401 return QPoint(x, y);
402 }
403
404 void DolphinView::setZoomLevel(int level)
405 {
406 if (level < ZoomLevelInfo::minimumLevel()) {
407 level = ZoomLevelInfo::minimumLevel();
408 } else if (level > ZoomLevelInfo::maximumLevel()) {
409 level = ZoomLevelInfo::maximumLevel();
410 }
411
412 if (level != zoomLevel()) {
413 m_controller->setZoomLevel(level);
414 m_previewGenerator->updateIcons();
415 emit zoomLevelChanged(level);
416 }
417 }
418
419 int DolphinView::zoomLevel() const
420 {
421 return m_controller->zoomLevel();
422 }
423
424 void DolphinView::setSorting(Sorting sorting)
425 {
426 if (sorting != this->sorting()) {
427 updateSorting(sorting);
428 }
429 }
430
431 DolphinView::Sorting DolphinView::sorting() const
432 {
433 return m_proxyModel->sorting();
434 }
435
436 void DolphinView::setSortOrder(Qt::SortOrder order)
437 {
438 if (sortOrder() != order) {
439 updateSortOrder(order);
440 }
441 }
442
443 Qt::SortOrder DolphinView::sortOrder() const
444 {
445 return m_proxyModel->sortOrder();
446 }
447
448 void DolphinView::setSortFoldersFirst(bool foldersFirst)
449 {
450 if (sortFoldersFirst() != foldersFirst) {
451 updateSortFoldersFirst(foldersFirst);
452 }
453 }
454
455 bool DolphinView::sortFoldersFirst() const
456 {
457 return m_proxyModel->sortFoldersFirst();
458 }
459
460 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info)
461 {
462 const KUrl viewPropsUrl = viewPropertiesUrl();
463 ViewProperties props(viewPropsUrl);
464 props.setAdditionalInfo(info);
465 m_fileItemDelegate->setShowInformation(info);
466
467 emit additionalInfoChanged();
468
469 if (itemView() != m_detailsView) {
470 // the details view requires no reloading of the directory, as it maps
471 // the file item delegate info to its columns internally
472 loadDirectory(viewPropsUrl);
473 }
474 }
475
476 KFileItemDelegate::InformationList DolphinView::additionalInfo() const
477 {
478 return m_fileItemDelegate->showInformation();
479 }
480
481 void DolphinView::reload()
482 {
483 setUrl(url());
484 loadDirectory(url(), true);
485 }
486
487 void DolphinView::refresh()
488 {
489 m_ignoreViewProperties = false;
490
491 const bool oldActivationState = m_active;
492 const int oldZoomLevel = m_controller->zoomLevel();
493 m_active = true;
494
495 createView();
496 applyViewProperties(m_controller->url());
497 reload();
498
499 setActive(oldActivationState);
500 updateZoomLevel(oldZoomLevel);
501 }
502
503 void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
504 {
505 if (m_controller->url() == url) {
506 return;
507 }
508
509 m_previewGenerator->cancelPreviews();
510 m_controller->setUrl(url); // emits urlChanged, which we forward
511
512 if (!rootUrl.isEmpty() && rootUrl.isParentOf(url)) {
513 applyViewProperties(rootUrl);
514 loadDirectory(rootUrl);
515 if (itemView() == m_columnView) {
516 m_columnView->setRootUrl(rootUrl);
517 m_columnView->showColumn(url);
518 }
519 } else {
520 applyViewProperties(url);
521 loadDirectory(url);
522 }
523
524 emit startedPathLoading(url);
525 }
526
527 void DolphinView::setNameFilter(const QString& nameFilter)
528 {
529 m_proxyModel->setFilterRegExp(nameFilter);
530
531 if (isColumnViewActive()) {
532 // adjusting the directory lister is not enough in the case of the
533 // column view, as each column has its own directory lister internally...
534 m_columnView->setNameFilter(nameFilter);
535 }
536 }
537
538 void DolphinView::calculateItemCount(int& fileCount,
539 int& folderCount,
540 KIO::filesize_t& totalFileSize) const
541 {
542 foreach (const KFileItem& item, m_dirLister->items()) {
543 if (item.isDir()) {
544 ++folderCount;
545 } else {
546 ++fileCount;
547 totalFileSize += item.size();
548 }
549 }
550 }
551
552 QString DolphinView::statusBarText() const
553 {
554 QString text;
555 int folderCount = 0;
556 int fileCount = 0;
557 KIO::filesize_t totalFileSize = 0;
558
559 if (hasSelection()) {
560 // give a summary of the status of the selected files
561 const KFileItemList list = selectedItems();
562 if (list.isEmpty()) {
563 // when an item is triggered, it is temporary selected but selectedItems()
564 // will return an empty list
565 return text;
566 }
567
568 KFileItemList::const_iterator it = list.begin();
569 const KFileItemList::const_iterator end = list.end();
570 while (it != end) {
571 const KFileItem& item = *it;
572 if (item.isDir()) {
573 ++folderCount;
574 } else {
575 ++fileCount;
576 totalFileSize += item.size();
577 }
578 ++it;
579 }
580
581 if (folderCount + fileCount == 1) {
582 // if only one item is selected, show the filename
583 const QString name = list.first().name();
584 text = (folderCount == 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name) :
585 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
586 name, KIO::convertSize(totalFileSize));
587 } else {
588 // at least 2 items are selected
589 const QString foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
590 const QString filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
591 if ((folderCount > 0) && (fileCount > 0)) {
592 text = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
593 foldersText, filesText, KIO::convertSize(totalFileSize));
594 } else if (fileCount > 0) {
595 text = i18nc("@info:status files (size)", "%1 (%2)", filesText, KIO::convertSize(totalFileSize));
596 } else {
597 Q_ASSERT(folderCount > 0);
598 text = foldersText;
599 }
600 }
601 } else {
602 calculateItemCount(fileCount, folderCount, totalFileSize);
603 text = KIO::itemsSummaryString(fileCount + folderCount,
604 fileCount, folderCount,
605 totalFileSize, true);
606 }
607
608 return text;
609 }
610
611 void DolphinView::setUrl(const KUrl& url)
612 {
613 // remember current item candidate (see restoreCurrentItem())
614 m_currentItemUrl = url;
615 updateView(url, KUrl());
616 }
617
618 void DolphinView::changeSelection(const KFileItemList& selection)
619 {
620 clearSelection();
621 if (selection.isEmpty()) {
622 return;
623 }
624 const KUrl& baseUrl = url();
625 KUrl url;
626 QItemSelection newSelection;
627 foreach(const KFileItem& item, selection) {
628 url = item.url().upUrl();
629 if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
630 QModelIndex index = m_proxyModel->mapFromSource(m_dolphinModel->indexForItem(item));
631 newSelection.select(index, index);
632 }
633 }
634 itemView()->selectionModel()->select(newSelection,
635 QItemSelectionModel::ClearAndSelect
636 | QItemSelectionModel::Current);
637 }
638
639 void DolphinView::renameSelectedItems()
640 {
641 KFileItemList items = selectedItems();
642 const int itemCount = items.count();
643 if (itemCount < 1) {
644 return;
645 }
646
647 if (itemCount > 1) {
648 // More than one item has been selected for renaming. Open
649 // a rename dialog and rename all items afterwards.
650 RenameDialog dialog(this, items);
651 if (dialog.exec() == QDialog::Rejected) {
652 return;
653 }
654
655 const QString newName = dialog.newName();
656 if (newName.isEmpty()) {
657 emit errorMessage(dialog.errorString());
658 return;
659 }
660
661 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
662 // as one operation instead of n rename operations like it is done now...
663 Q_ASSERT(newName.contains('#'));
664
665 // currently the items are sorted by the selection order, resort
666 // them by the file name
667 qSort(items.begin(), items.end(), lessThan);
668
669 // iterate through all selected items and rename them...
670 int index = 1;
671 foreach (const KFileItem& item, items) {
672 const KUrl& oldUrl = item.url();
673 QString number;
674 number.setNum(index++);
675
676 QString name = newName;
677 name.replace('#', number);
678
679 if (oldUrl.fileName() != name) {
680 KUrl newUrl = oldUrl;
681 newUrl.setFileName(name);
682 KonqOperations::rename(this, oldUrl, newUrl);
683 }
684 }
685 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
686 Q_ASSERT(itemCount == 1);
687
688 if (isColumnViewActive()) {
689 m_columnView->editItem(items.first());
690 } else {
691 const QModelIndex dirIndex = m_dolphinModel->indexForItem(items.first());
692 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
693 itemView()->edit(proxyIndex);
694 }
695 } else {
696 Q_ASSERT(itemCount == 1);
697
698 RenameDialog dialog(this, items);
699 if (dialog.exec() == QDialog::Rejected) {
700 return;
701 }
702
703 const QString& newName = dialog.newName();
704 if (newName.isEmpty()) {
705 emit errorMessage(dialog.errorString());
706 return;
707 }
708
709 const KUrl& oldUrl = items.first().url();
710 KUrl newUrl = oldUrl;
711 newUrl.setFileName(newName);
712 KonqOperations::rename(this, oldUrl, newUrl);
713 }
714
715 // assure that the current index remains visible when KDirLister
716 // will notify the view about changed items
717 m_assureVisibleCurrentIndex = true;
718 }
719
720 void DolphinView::trashSelectedItems()
721 {
722 const KUrl::List list = simplifiedSelectedUrls();
723 KonqOperations::del(this, KonqOperations::TRASH, list);
724 }
725
726 void DolphinView::deleteSelectedItems()
727 {
728 const KUrl::List list = simplifiedSelectedUrls();
729 const bool del = KonqOperations::askDeleteConfirmation(list,
730 KonqOperations::DEL,
731 KonqOperations::DEFAULT_CONFIRMATION,
732 this);
733
734 if (del) {
735 KIO::Job* job = KIO::del(list);
736 connect(job, SIGNAL(result(KJob*)),
737 this, SLOT(slotDeleteFileFinished(KJob*)));
738 }
739 }
740
741 void DolphinView::cutSelectedItems()
742 {
743 QMimeData* mimeData = selectionMimeData();
744 KonqMimeData::addIsCutSelection(mimeData, true);
745 QApplication::clipboard()->setMimeData(mimeData);
746 }
747
748 void DolphinView::copySelectedItems()
749 {
750 QMimeData* mimeData = selectionMimeData();
751 QApplication::clipboard()->setMimeData(mimeData);
752 }
753
754 void DolphinView::paste()
755 {
756 pasteToUrl(url());
757 }
758
759 void DolphinView::pasteIntoFolder()
760 {
761 const KFileItemList items = selectedItems();
762 if ((items.count() == 1) && items.first().isDir()) {
763 pasteToUrl(items.first().url());
764 }
765 }
766
767 void DolphinView::setShowPreview(bool show)
768 {
769 if (m_showPreview == show) {
770 return;
771 }
772
773 const KUrl viewPropsUrl = viewPropertiesUrl();
774 ViewProperties props(viewPropsUrl);
775 props.setShowPreview(show);
776
777 m_showPreview = show;
778 m_previewGenerator->setPreviewShown(show);
779
780 const int oldZoomLevel = m_controller->zoomLevel();
781 emit showPreviewChanged();
782
783 // Enabling or disabling the preview might change the icon size of the view.
784 // As the view does not emit a signal when the icon size has been changed,
785 // the used zoom level of the controller must be adjusted manually:
786 updateZoomLevel(oldZoomLevel);
787
788 loadDirectory(viewPropsUrl);
789 }
790
791 void DolphinView::setShowHiddenFiles(bool show)
792 {
793 if (m_dirLister->showingDotFiles() == show) {
794 return;
795 }
796
797 const KUrl viewPropsUrl = viewPropertiesUrl();
798 ViewProperties props(viewPropsUrl);
799 props.setShowHiddenFiles(show);
800
801 m_dirLister->setShowingDotFiles(show);
802 emit showHiddenFilesChanged();
803
804 loadDirectory(viewPropsUrl);
805 }
806
807 void DolphinView::setCategorizedSorting(bool categorized)
808 {
809 if (categorized == categorizedSorting()) {
810 return;
811 }
812
813 // setCategorizedSorting(true) may only get invoked
814 // if the view supports categorized sorting
815 Q_ASSERT(!categorized || supportsCategorizedSorting());
816
817 ViewProperties props(viewPropertiesUrl());
818 props.setCategorizedSorting(categorized);
819 props.save();
820
821 m_storedCategorizedSorting = categorized;
822 m_proxyModel->setCategorizedModel(categorized);
823
824 emit categorizedSortingChanged();
825 }
826
827 void DolphinView::toggleSortOrder()
828 {
829 const Qt::SortOrder order = (sortOrder() == Qt::AscendingOrder) ?
830 Qt::DescendingOrder :
831 Qt::AscendingOrder;
832 setSortOrder(order);
833 }
834
835 void DolphinView::toggleSortFoldersFirst()
836 {
837 setSortFoldersFirst(!sortFoldersFirst());
838 }
839
840 void DolphinView::toggleAdditionalInfo(QAction* action)
841 {
842 const KFileItemDelegate::Information info =
843 static_cast<KFileItemDelegate::Information>(action->data().toInt());
844
845 KFileItemDelegate::InformationList list = additionalInfo();
846
847 const bool show = action->isChecked();
848
849 const int index = list.indexOf(info);
850 const bool containsInfo = (index >= 0);
851 if (show && !containsInfo) {
852 list.append(info);
853 setAdditionalInfo(list);
854 } else if (!show && containsInfo) {
855 list.removeAt(index);
856 setAdditionalInfo(list);
857 Q_ASSERT(list.indexOf(info) < 0);
858 }
859 }
860
861 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
862 {
863 QWidget::mouseReleaseEvent(event);
864 setActive(true);
865 }
866
867 void DolphinView::wheelEvent(QWheelEvent* event)
868 {
869 if (event->modifiers() & Qt::ControlModifier) {
870 const int delta = event->delta();
871 const int level = zoomLevel();
872 if (delta > 0) {
873 setZoomLevel(level + 1);
874 } else if (delta < 0) {
875 setZoomLevel(level - 1);
876 }
877 event->accept();
878 }
879 }
880
881 bool DolphinView::eventFilter(QObject* watched, QEvent* event)
882 {
883 switch (event->type()) {
884 case QEvent::FocusIn:
885 if (watched == itemView()) {
886 m_controller->requestActivation();
887 }
888 break;
889
890 case QEvent::MouseButtonPress:
891 if ((watched == itemView()->viewport()) && (m_expandedDragSource != 0)) {
892 // Listening to a mousebutton press event to delete expanded views is a
893 // workaround, as it seems impossible for the FolderExpander to know when
894 // a dragging outside a view has been finished. However it works quite well:
895 // A mousebutton press event indicates that a drag operation must be
896 // finished already.
897 m_expandedDragSource->deleteLater();
898 m_expandedDragSource = 0;
899 }
900 break;
901
902 case QEvent::DragEnter:
903 if (watched == itemView()->viewport()) {
904 setActive(true);
905 }
906 break;
907
908 case QEvent::KeyPress:
909 if (watched == itemView()) {
910 if (m_toolTipManager != 0) {
911 m_toolTipManager->hideTip();
912 }
913
914 // clear the selection when Escape has been pressed
915 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
916 if (keyEvent->key() == Qt::Key_Escape) {
917 clearSelection();
918 }
919 }
920 break;
921
922 default:
923 break;
924 }
925
926 return QWidget::eventFilter(watched, event);
927 }
928
929 void DolphinView::activate()
930 {
931 setActive(true);
932 }
933
934 void DolphinView::triggerItem(const KFileItem& item)
935 {
936 const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
937 if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
938 // items are selected by the user, hence don't trigger the
939 // item specified by 'index'
940 return;
941 }
942
943 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
944 if (item.isNull() || m_isContextMenuOpen) {
945 return;
946 }
947
948 if (m_toolTipManager != 0) {
949 m_toolTipManager->hideTip();
950 }
951 emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
952 }
953
954 void DolphinView::emitSelectionChangedSignal()
955 {
956 emit selectionChanged(DolphinView::selectedItems());
957 }
958
959 void DolphinView::openContextMenu(const QPoint& pos,
960 const QList<QAction*>& customActions)
961 {
962 KFileItem item;
963 if (isColumnViewActive()) {
964 item = m_columnView->itemAt(pos);
965 } else {
966 const QModelIndex index = itemView()->indexAt(pos);
967 if (index.isValid() && (index.column() == DolphinModel::Name)) {
968 const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
969 item = m_dolphinModel->itemForIndex(dolphinModelIndex);
970 }
971 }
972
973 if (m_toolTipManager != 0) {
974 m_toolTipManager->hideTip();
975 }
976
977 m_isContextMenuOpen = true; // TODO: workaround for Qt-issue 207192
978 emit requestContextMenu(item, url(), customActions);
979 m_isContextMenuOpen = false;
980 }
981
982 void DolphinView::dropUrls(const KFileItem& destItem,
983 const KUrl& destPath,
984 QDropEvent* event)
985 {
986 DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
987 }
988
989 void DolphinView::updateSorting(DolphinView::Sorting sorting)
990 {
991 ViewProperties props(viewPropertiesUrl());
992 props.setSorting(sorting);
993
994 m_proxyModel->setSorting(sorting);
995
996 emit sortingChanged(sorting);
997 }
998
999 void DolphinView::updateSortOrder(Qt::SortOrder order)
1000 {
1001 ViewProperties props(viewPropertiesUrl());
1002 props.setSortOrder(order);
1003
1004 m_proxyModel->setSortOrder(order);
1005
1006 emit sortOrderChanged(order);
1007 }
1008
1009 void DolphinView::updateSortFoldersFirst(bool foldersFirst)
1010 {
1011 ViewProperties props(viewPropertiesUrl());
1012 props.setSortFoldersFirst(foldersFirst);
1013
1014 m_proxyModel->setSortFoldersFirst(foldersFirst);
1015
1016 emit sortFoldersFirstChanged(foldersFirst);
1017 }
1018
1019 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info)
1020 {
1021 ViewProperties props(viewPropertiesUrl());
1022 props.setAdditionalInfo(info);
1023 props.save();
1024
1025 m_fileItemDelegate->setShowInformation(info);
1026
1027 emit additionalInfoChanged();
1028 }
1029
1030 void DolphinView::updateAdditionalInfoActions(KActionCollection* collection)
1031 {
1032 const bool enable = (m_mode == DolphinView::DetailsView) ||
1033 (m_mode == DolphinView::IconsView);
1034
1035 QAction* showSizeInfo = collection->action("show_size_info");
1036 QAction* showDateInfo = collection->action("show_date_info");
1037 QAction* showPermissionsInfo = collection->action("show_permissions_info");
1038 QAction* showOwnerInfo = collection->action("show_owner_info");
1039 QAction* showGroupInfo = collection->action("show_group_info");
1040 QAction* showMimeInfo = collection->action("show_mime_info");
1041
1042 showSizeInfo->setChecked(false);
1043 showDateInfo->setChecked(false);
1044 showPermissionsInfo->setChecked(false);
1045 showOwnerInfo->setChecked(false);
1046 showGroupInfo->setChecked(false);
1047 showMimeInfo->setChecked(false);
1048
1049 showSizeInfo->setEnabled(enable);
1050 showDateInfo->setEnabled(enable);
1051 showPermissionsInfo->setEnabled(enable);
1052 showOwnerInfo->setEnabled(enable);
1053 showGroupInfo->setEnabled(enable);
1054 showMimeInfo->setEnabled(enable);
1055
1056 foreach (KFileItemDelegate::Information info, m_fileItemDelegate->showInformation()) {
1057 switch (info) {
1058 case KFileItemDelegate::Size:
1059 showSizeInfo->setChecked(true);
1060 break;
1061 case KFileItemDelegate::ModificationTime:
1062 showDateInfo->setChecked(true);
1063 break;
1064 case KFileItemDelegate::Permissions:
1065 showPermissionsInfo->setChecked(true);
1066 break;
1067 case KFileItemDelegate::Owner:
1068 showOwnerInfo->setChecked(true);
1069 break;
1070 case KFileItemDelegate::OwnerAndGroup:
1071 showGroupInfo->setChecked(true);
1072 break;
1073 case KFileItemDelegate::FriendlyMimeType:
1074 showMimeInfo->setChecked(true);
1075 break;
1076 default:
1077 break;
1078 }
1079 }
1080 }
1081
1082 QPair<bool, QString> DolphinView::pasteInfo() const
1083 {
1084 return KonqOperations::pasteInfo(url());
1085 }
1086
1087 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles)
1088 {
1089 m_tabsForFiles = tabsForFiles;
1090 }
1091
1092 bool DolphinView::isTabsForFilesEnabled() const
1093 {
1094 return m_tabsForFiles;
1095 }
1096
1097 bool DolphinView::itemsExpandable() const
1098 {
1099 return (m_detailsView != 0) && m_detailsView->itemsExpandable();
1100 }
1101
1102 void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
1103 {
1104 if (view == 0)
1105 return;
1106
1107 if (DragAndDropHelper::instance().isDragSource(view)) {
1108 // We must store for later deletion.
1109 if (m_expandedDragSource != 0) {
1110 // The old stored view is obviously not the drag source anymore.
1111 m_expandedDragSource->deleteLater();
1112 m_expandedDragSource = 0;
1113 }
1114 view->hide();
1115 m_expandedDragSource = view;
1116 }
1117 else {
1118 view->deleteLater();
1119 }
1120 }
1121
1122 void DolphinView::observeCreatedItem(const KUrl& url)
1123 {
1124 m_createdItemUrl = url;
1125 connect(m_dolphinModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
1126 this, SLOT(selectAndScrollToCreatedItem()));
1127 }
1128
1129 void DolphinView::selectAndScrollToCreatedItem()
1130 {
1131 const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_createdItemUrl);
1132 if (dirIndex.isValid()) {
1133 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
1134 itemView()->setCurrentIndex(proxyIndex);
1135 }
1136
1137 disconnect(m_dolphinModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
1138 this, SLOT(selectAndScrollToCreatedItem()));
1139 m_createdItemUrl = KUrl();
1140 }
1141
1142 void DolphinView::restoreSelection()
1143 {
1144 disconnect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreSelection()));
1145 changeSelection(m_selectedItems);
1146 }
1147
1148 void DolphinView::emitContentsMoved()
1149 {
1150 // only emit the contents moved signal if:
1151 // - no directory loading is ongoing (this would reset the contents position
1152 // always to (0, 0))
1153 // - if the Column View is active: the column view does an automatic
1154 // positioning during the loading operation, which must be remembered
1155 if (!m_loadingDirectory || isColumnViewActive()) {
1156 const QPoint pos(contentsPosition());
1157 emit contentsMoved(pos.x(), pos.y());
1158 }
1159 }
1160
1161 void DolphinView::showHoverInformation(const KFileItem& item)
1162 {
1163 emit requestItemInfo(item);
1164 }
1165
1166 void DolphinView::clearHoverInformation()
1167 {
1168 emit requestItemInfo(KFileItem());
1169 }
1170
1171 void DolphinView::slotDeleteFileFinished(KJob* job)
1172 {
1173 if (job->error() == 0) {
1174 emit operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1175 } else if (job->error() != KIO::ERR_USER_CANCELED) {
1176 emit errorMessage(job->errorString());
1177 }
1178 }
1179
1180 void DolphinView::slotRequestUrlChange(const KUrl& url)
1181 {
1182 emit requestUrlChange(url);
1183 m_controller->setUrl(url);
1184 }
1185
1186 void DolphinView::restoreCurrentItem()
1187 {
1188 if (!m_currentItemUrl.isEmpty()) {
1189 const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
1190 if (dirIndex.isValid()) {
1191 const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
1192 QAbstractItemView* view = itemView();
1193 const bool clearSelection = !hasSelection();
1194 view->setCurrentIndex(proxyIndex);
1195 if (clearSelection) {
1196 view->clearSelection();
1197 }
1198 }
1199 m_currentItemUrl.clear();
1200 }
1201 }
1202
1203 void DolphinView::slotRefreshItems()
1204 {
1205 if (m_assureVisibleCurrentIndex) {
1206 m_assureVisibleCurrentIndex = false;
1207 itemView()->scrollTo(itemView()->currentIndex());
1208 }
1209 }
1210
1211 void DolphinView::loadDirectory(const KUrl& url, bool reload)
1212 {
1213 if (!url.isValid()) {
1214 const QString location(url.pathOrUrl());
1215 if (location.isEmpty()) {
1216 emit errorMessage(i18nc("@info:status", "The location is empty."));
1217 } else {
1218 emit errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location));
1219 }
1220 return;
1221 }
1222
1223 m_loadingDirectory = true;
1224
1225 if (reload) {
1226 m_selectedItems = selectedItems();
1227 connect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreSelection()));
1228 }
1229
1230 m_dirLister->stop();
1231 m_dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
1232
1233 if (isColumnViewActive()) {
1234 // adjusting the directory lister is not enough in the case of the
1235 // column view, as each column has its own directory lister internally...
1236 if (reload) {
1237 m_columnView->reload();
1238 } else {
1239 m_columnView->showColumn(url);
1240 }
1241 }
1242 }
1243
1244 KUrl DolphinView::viewPropertiesUrl() const
1245 {
1246 if (isColumnViewActive()) {
1247 return m_columnView->rootUrl();
1248 }
1249
1250 return url();
1251 }
1252
1253 void DolphinView::applyViewProperties(const KUrl& url)
1254 {
1255 if (m_ignoreViewProperties) {
1256 return;
1257 }
1258
1259 if (isColumnViewActive() && rootUrl().isParentOf(url)) {
1260 // The column view is active, hence don't apply the view properties
1261 // of sub directories (represented by columns) to the view. The
1262 // view always represents the properties of the first column.
1263 return;
1264 }
1265
1266 const ViewProperties props(url);
1267
1268 const Mode mode = props.viewMode();
1269 if (m_mode != mode) {
1270 const int oldZoomLevel = m_controller->zoomLevel();
1271
1272 m_mode = mode;
1273 createView();
1274 emit modeChanged();
1275
1276 updateZoomLevel(oldZoomLevel);
1277 }
1278 if (itemView() == 0) {
1279 createView();
1280 }
1281 Q_ASSERT(itemView() != 0);
1282 Q_ASSERT(m_fileItemDelegate != 0);
1283
1284 const bool showHiddenFiles = props.showHiddenFiles();
1285 if (showHiddenFiles != m_dirLister->showingDotFiles()) {
1286 m_dirLister->setShowingDotFiles(showHiddenFiles);
1287 emit showHiddenFilesChanged();
1288 }
1289
1290 m_storedCategorizedSorting = props.categorizedSorting();
1291 const bool categorized = m_storedCategorizedSorting && supportsCategorizedSorting();
1292 if (categorized != m_proxyModel->isCategorizedModel()) {
1293 m_proxyModel->setCategorizedModel(categorized);
1294 emit categorizedSortingChanged();
1295 }
1296
1297 const DolphinView::Sorting sorting = props.sorting();
1298 if (sorting != m_proxyModel->sorting()) {
1299 m_proxyModel->setSorting(sorting);
1300 emit sortingChanged(sorting);
1301 }
1302
1303 const Qt::SortOrder sortOrder = props.sortOrder();
1304 if (sortOrder != m_proxyModel->sortOrder()) {
1305 m_proxyModel->setSortOrder(sortOrder);
1306 emit sortOrderChanged(sortOrder);
1307 }
1308
1309 const bool sortFoldersFirst = props.sortFoldersFirst();
1310 if (sortFoldersFirst != m_proxyModel->sortFoldersFirst()) {
1311 m_proxyModel->setSortFoldersFirst(sortFoldersFirst);
1312 emit sortFoldersFirstChanged(sortFoldersFirst);
1313 }
1314
1315 KFileItemDelegate::InformationList info = props.additionalInfo();
1316 if (info != m_fileItemDelegate->showInformation()) {
1317 m_fileItemDelegate->setShowInformation(info);
1318 emit additionalInfoChanged();
1319 }
1320
1321 const bool showPreview = props.showPreview();
1322 if (showPreview != m_showPreview) {
1323 m_showPreview = showPreview;
1324 m_previewGenerator->setPreviewShown(showPreview);
1325
1326 const int oldZoomLevel = m_controller->zoomLevel();
1327 emit showPreviewChanged();
1328
1329 // Enabling or disabling the preview might change the icon size of the view.
1330 // As the view does not emit a signal when the icon size has been changed,
1331 // the used zoom level of the controller must be adjusted manually:
1332 updateZoomLevel(oldZoomLevel);
1333 }
1334
1335 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1336 // During the lifetime of a DolphinView instance the global view properties
1337 // should not be changed. This allows e. g. to split a view and use different
1338 // view properties for each view.
1339 m_ignoreViewProperties = true;
1340 }
1341 }
1342
1343 void DolphinView::createView()
1344 {
1345 deleteView();
1346 Q_ASSERT(m_iconsView == 0);
1347 Q_ASSERT(m_detailsView == 0);
1348 Q_ASSERT(m_columnView == 0);
1349
1350 QAbstractItemView* view = 0;
1351 switch (m_mode) {
1352 case IconsView: {
1353 m_iconsView = new DolphinIconsView(this, m_controller);
1354 view = m_iconsView;
1355 break;
1356 }
1357
1358 case DetailsView:
1359 m_detailsView = new DolphinDetailsView(this, m_controller);
1360 view = m_detailsView;
1361 break;
1362
1363 case ColumnView:
1364 m_columnView = new DolphinColumnView(this, m_controller);
1365 view = m_columnView;
1366 break;
1367 }
1368
1369 Q_ASSERT(view != 0);
1370 view->installEventFilter(this);
1371 view->viewport()->installEventFilter(this);
1372 setFocusProxy(view);
1373
1374 if (m_mode != ColumnView) {
1375 // Give the view the ability to auto-expand its directories on hovering
1376 // (the column view takes care about this itself). If the details view
1377 // uses expandable folders, the auto-expanding should be used always.
1378 DolphinSettings& settings = DolphinSettings::instance();
1379 const bool enabled = settings.generalSettings()->autoExpandFolders() ||
1380 ((m_detailsView != 0) && settings.detailsModeSettings()->expandableFolders());
1381
1382 FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel);
1383 folderExpander->setEnabled(enabled);
1384 connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
1385 m_controller, SLOT(triggerItem(const QModelIndex&)));
1386 }
1387 else {
1388 // Listen out for requests to delete the current column.
1389 connect(m_columnView, SIGNAL(requestColumnDeletion(QAbstractItemView*)),
1390 this, SLOT(deleteWhenNotDragSource(QAbstractItemView*)));
1391 }
1392
1393 m_controller->setItemView(view);
1394
1395 m_fileItemDelegate = new DolphinFileItemDelegate(view);
1396 m_fileItemDelegate->setShowToolTipWhenElided(false);
1397 m_fileItemDelegate->setMinimizedNameColumn(m_mode == DetailsView);
1398 view->setItemDelegate(m_fileItemDelegate);
1399
1400 view->setModel(m_proxyModel);
1401 if (m_selectionModel != 0) {
1402 view->setSelectionModel(m_selectionModel);
1403 } else {
1404 m_selectionModel = view->selectionModel();
1405 }
1406
1407 // reparent the selection model, as it should not be deleted
1408 // when deleting the model
1409 m_selectionModel->setParent(this);
1410
1411 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
1412
1413 m_previewGenerator = new KFilePreviewGenerator(view);
1414 m_previewGenerator->setPreviewShown(m_showPreview);
1415
1416 if (DolphinSettings::instance().generalSettings()->showToolTips()) {
1417 m_toolTipManager = new ToolTipManager(view, m_proxyModel);
1418 connect(m_controller, SIGNAL(hideToolTip()),
1419 m_toolTipManager, SLOT(hideTip()));
1420 }
1421
1422 m_topLayout->insertWidget(1, view);
1423
1424 connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
1425 this, SLOT(emitSelectionChangedSignal()));
1426 connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
1427 this, SLOT(emitContentsMoved()));
1428 connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1429 this, SLOT(emitContentsMoved()));
1430 }
1431
1432 void DolphinView::deleteView()
1433 {
1434 QAbstractItemView* view = itemView();
1435 if (view != 0) {
1436 // It's important to set the keyboard focus to the parent
1437 // before deleting the view: Otherwise when having a split
1438 // view the other view will get the focus and will request
1439 // an activation (see DolphinView::eventFilter()).
1440 setFocusProxy(0);
1441 setFocus();
1442
1443 m_topLayout->removeWidget(view);
1444 view->close();
1445
1446 // m_previewGenerator's parent is not always destroyed, and we
1447 // don't want two active at once - manually delete.
1448 delete m_previewGenerator;
1449 m_previewGenerator = 0;
1450
1451 disconnect(view);
1452 m_controller->disconnect(view);
1453 view->disconnect();
1454
1455 deleteWhenNotDragSource(view);
1456 view = 0;
1457
1458 m_iconsView = 0;
1459 m_detailsView = 0;
1460 m_columnView = 0;
1461 m_fileItemDelegate = 0;
1462 m_toolTipManager = 0;
1463 }
1464 }
1465
1466 QAbstractItemView* DolphinView::itemView() const
1467 {
1468 if (m_detailsView != 0) {
1469 return m_detailsView;
1470 } else if (m_columnView != 0) {
1471 return m_columnView;
1472 }
1473
1474 return m_iconsView;
1475 }
1476
1477 bool DolphinView::isCutItem(const KFileItem& item) const
1478 {
1479 const QMimeData* mimeData = QApplication::clipboard()->mimeData();
1480 const KUrl::List cutUrls = KUrl::List::fromMimeData(mimeData);
1481
1482 const KUrl& itemUrl = item.url();
1483 KUrl::List::const_iterator it = cutUrls.begin();
1484 const KUrl::List::const_iterator end = cutUrls.end();
1485 while (it != end) {
1486 if (*it == itemUrl) {
1487 return true;
1488 }
1489 ++it;
1490 }
1491
1492 return false;
1493 }
1494
1495 void DolphinView::pasteToUrl(const KUrl& url)
1496 {
1497 KonqOperations::doPaste(this, url);
1498 }
1499
1500 void DolphinView::updateZoomLevel(int oldZoomLevel)
1501 {
1502 const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize());
1503 if (oldZoomLevel != newZoomLevel) {
1504 m_controller->setZoomLevel(newZoomLevel);
1505 emit zoomLevelChanged(newZoomLevel);
1506 }
1507 }
1508
1509 KUrl::List DolphinView::simplifiedSelectedUrls() const
1510 {
1511 KUrl::List list = selectedUrls();
1512 if (itemsExpandable() ) {
1513 list = KDirModel::simplifiedUrlList(list);
1514 }
1515 return list;
1516 }
1517
1518 QMimeData* DolphinView::selectionMimeData() const
1519 {
1520 if (isColumnViewActive()) {
1521 return m_columnView->selectionMimeData();
1522 }
1523
1524 const QAbstractItemView* view = itemView();
1525 Q_ASSERT((view != 0) && (view->selectionModel() != 0));
1526 const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
1527 return m_dolphinModel->mimeData(selection.indexes());
1528 }
1529
1530
1531 #include "dolphinview.moc"