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