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