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