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