1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
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. *
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. *
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 ***************************************************************************/
21 #include "dolphinview.h"
23 #include <QApplication>
26 #include <QItemSelection>
31 #include <kdirmodel.h>
32 #include <kdirlister.h>
33 #include <kfileitemdelegate.h>
34 #include <kglobalsettings.h>
36 #include <kiconeffect.h>
37 #include <kio/netaccess.h>
38 #include <kio/renamedialog.h>
39 #include <kio/previewjob.h>
40 #include <kmimetyperesolver.h>
41 #include <konqmimedata.h>
42 #include <konq_operations.h>
45 #include "dolphincolumnview.h"
46 #include "dolphincontroller.h"
47 #include "dolphinsortfilterproxymodel.h"
48 #include "dolphindetailsview.h"
49 #include "dolphiniconsview.h"
50 #include "dolphinitemcategorizer.h"
51 #include "renamedialog.h"
52 #include "viewproperties.h"
53 #include "dolphinsettings.h"
54 #include "dolphin_generalsettings.h"
56 DolphinView::DolphinView(QWidget
* parent
,
58 KDirLister
* dirLister
,
60 DolphinSortFilterProxyModel
* proxyModel
,
62 bool showHiddenFiles
) :
65 m_blockContentsMovedSignal(false),
66 m_initializeColumnView(false),
73 m_fileItemDelegate(0),
75 m_dirLister(dirLister
),
76 m_proxyModel(proxyModel
)
78 setFocusPolicy(Qt::StrongFocus
);
79 m_topLayout
= new QVBoxLayout(this);
80 m_topLayout
->setSpacing(0);
81 m_topLayout
->setMargin(0);
83 QClipboard
* clipboard
= QApplication::clipboard();
84 connect(clipboard
, SIGNAL(dataChanged()),
85 this, SLOT(updateCutItems()));
87 connect(m_dirLister
, SIGNAL(completed()),
88 this, SLOT(restoreContentsPos()));
89 connect(m_dirLister
, SIGNAL(completed()),
90 this, SLOT(updateCutItems()));
91 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
92 this, SLOT(generatePreviews(const KFileItemList
&)));
94 m_controller
= new DolphinController(this);
95 m_controller
->setUrl(url
);
96 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
97 this, SLOT(openContextMenu(const QPoint
&)));
98 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
99 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
100 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
101 this, SLOT(updateSorting(DolphinView::Sorting
)));
102 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
103 this, SLOT(updateSortOrder(Qt::SortOrder
)));
104 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
105 this, SLOT(triggerItem(const QModelIndex
&)));
106 connect(m_controller
, SIGNAL(activated()),
107 this, SLOT(activate()));
108 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
109 this, SLOT(showHoverInformation(const QModelIndex
&)));
110 connect(m_controller
, SIGNAL(viewportEntered()),
111 this, SLOT(clearHoverInformation()));
114 m_topLayout
->addWidget(itemView());
117 DolphinView::~DolphinView()
121 const KUrl
& DolphinView::url() const
123 return m_controller
->url();
126 KUrl
DolphinView::rootUrl() const
128 return isColumnViewActive() ? m_dirLister
->url() : url();
131 void DolphinView::setActive(bool active
)
133 if (active
== m_active
) {
139 QColor color
= KGlobalSettings::baseColor();
141 emit
urlChanged(url());
142 emit
selectionChanged(selectedItems());
147 QWidget
* viewport
= itemView()->viewport();
149 palette
.setColor(viewport
->backgroundRole(), color
);
150 viewport
->setPalette(palette
);
159 bool DolphinView::isActive() const
164 void DolphinView::setMode(Mode mode
)
166 if (mode
== m_mode
) {
167 return; // the wished mode is already set
172 if (isColumnViewActive()) {
173 // When changing the mode in the column view, it makes sense
174 // to go back to the root URL of the column view automatically.
175 // Otherwise there it would not be possible to turn off the column view
176 // without focusing the first column.
177 // TODO: reactivate again after DolphinView/DolphinViewController split works
178 //setUrl(m_dirLister->url());
179 //m_controller->setUrl(m_dirLister->url());
182 ViewProperties
props(url());
183 props
.setViewMode(m_mode
);
186 startDirLister(url());
191 DolphinView::Mode
DolphinView::mode() const
196 void DolphinView::setShowPreview(bool show
)
198 ViewProperties
props(url());
199 props
.setShowPreview(show
);
201 m_controller
->setShowPreview(show
);
202 emit
showPreviewChanged();
204 startDirLister(url(), true);
207 bool DolphinView::showPreview() const
209 return m_controller
->showPreview();
212 void DolphinView::setShowHiddenFiles(bool show
)
214 if (m_dirLister
->showingDotFiles() == show
) {
218 ViewProperties
props(url());
219 props
.setShowHiddenFiles(show
);
221 m_dirLister
->setShowingDotFiles(show
);
222 emit
showHiddenFilesChanged();
224 startDirLister(url(), true);
227 bool DolphinView::showHiddenFiles() const
229 return m_dirLister
->showingDotFiles();
232 void DolphinView::setCategorizedSorting(bool categorized
)
234 if (!supportsCategorizedSorting() || (categorized
== categorizedSorting())) {
238 Q_ASSERT(m_iconsView
!= 0);
240 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
241 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
243 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
244 m_iconsView
->setItemCategorizer(0);
248 ViewProperties
props(url());
249 props
.setCategorizedSorting(categorized
);
252 emit
categorizedSortingChanged();
255 bool DolphinView::categorizedSorting() const
257 if (!supportsCategorizedSorting()) {
261 Q_ASSERT(m_iconsView
!= 0);
262 return m_iconsView
->itemCategorizer() != 0;
265 bool DolphinView::supportsCategorizedSorting() const
267 return m_iconsView
!= 0;
270 void DolphinView::renameSelectedItems()
272 // TODO: temporary deactivate due to DolphinView/DolphinViewController split
274 /*DolphinView* view = 0; //mainWindow()->activeView();
275 const KUrl::List urls = selectedUrls();
276 if (urls.count() > 1) {
277 // More than one item has been selected for renaming. Open
278 // a rename dialog and rename all items afterwards.
279 RenameDialog dialog(urls);
280 if (dialog.exec() == QDialog::Rejected) {
284 const QString& newName = dialog.newName();
285 if (newName.isEmpty()) {
286 view->statusBar()->setMessage(dialog.errorString(),
287 DolphinStatusBar::Error);
289 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
290 // as one operation instead of n rename operations like it is done now...
291 Q_ASSERT(newName.contains('#'));
293 // iterate through all selected items and rename them...
294 const int replaceIndex = newName.indexOf('#');
295 Q_ASSERT(replaceIndex >= 0);
298 KUrl::List::const_iterator it = urls.begin();
299 KUrl::List::const_iterator end = urls.end();
301 const KUrl& oldUrl = *it;
303 number.setNum(index++);
305 QString name(newName);
306 name.replace(replaceIndex, 1, number);
308 if (oldUrl.fileName() != name) {
309 KUrl newUrl = oldUrl;
310 newUrl.setFileName(name);
311 m_mainWindow->rename(oldUrl, newUrl);
317 // Only one item has been selected for renaming. Use the custom
318 // renaming mechanism from the views.
319 Q_ASSERT(urls.count() == 1);
321 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
322 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
323 // is a benefit for the user at all -> let's wait for some input first...
324 RenameDialog dialog(urls);
325 if (dialog.exec() == QDialog::Rejected) {
329 const QString& newName = dialog.newName();
330 if (newName.isEmpty()) {
331 view->statusBar()->setMessage(dialog.errorString(),
332 DolphinStatusBar::Error);
334 const KUrl& oldUrl = urls.first();
335 KUrl newUrl = oldUrl;
336 newUrl.setFileName(newName);
337 m_mainWindow->rename(oldUrl, newUrl);
342 void DolphinView::selectAll()
344 selectAll(QItemSelectionModel::Select
);
347 void DolphinView::invertSelection()
349 selectAll(QItemSelectionModel::Toggle
);
352 int DolphinView::contentsX() const
354 return itemView()->horizontalScrollBar()->value();
357 int DolphinView::contentsY() const
359 return itemView()->verticalScrollBar()->value();
362 void DolphinView::zoomIn()
364 m_controller
->triggerZoomIn();
367 void DolphinView::zoomOut()
369 m_controller
->triggerZoomOut();
372 bool DolphinView::isZoomInPossible() const
374 return m_controller
->isZoomInPossible();
377 bool DolphinView::isZoomOutPossible() const
379 return m_controller
->isZoomOutPossible();
382 void DolphinView::setSorting(Sorting sorting
)
384 if (sorting
!= this->sorting()) {
385 updateSorting(sorting
);
389 DolphinView::Sorting
DolphinView::sorting() const
391 return m_proxyModel
->sorting();
394 void DolphinView::setSortOrder(Qt::SortOrder order
)
396 if (sortOrder() != order
) {
397 updateSortOrder(order
);
401 Qt::SortOrder
DolphinView::sortOrder() const
403 return m_proxyModel
->sortOrder();
406 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
408 ViewProperties
props(url());
409 props
.setAdditionalInfo(info
);
411 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
412 m_fileItemDelegate
->setAdditionalInformation(info
);
414 emit
additionalInfoChanged(info
);
415 startDirLister(url(), true);
418 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
420 return m_fileItemDelegate
->additionalInformation();
423 bool DolphinView::hasSelection() const
425 return itemView()->selectionModel()->hasSelection();
428 void DolphinView::clearSelection()
430 itemView()->selectionModel()->clear();
433 KFileItemList
DolphinView::selectedItems() const
435 const QAbstractItemView
* view
= itemView();
437 // Our view has a selection, we will map them back to the DirModel
438 // and then fill the KFileItemList.
439 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
441 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
442 KFileItemList itemList
;
444 const QModelIndexList indexList
= selection
.indexes();
445 QModelIndexList::const_iterator end
= indexList
.end();
446 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
447 Q_ASSERT((*it
).isValid());
449 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
451 itemList
.append(item
);
458 KUrl::List
DolphinView::selectedUrls() const
462 const KFileItemList list
= selectedItems();
463 KFileItemList::const_iterator it
= list
.begin();
464 const KFileItemList::const_iterator end
= list
.end();
466 KFileItem
* item
= *it
;
467 urls
.append(item
->url());
474 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
476 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
477 return m_dirModel
->itemForIndex(dirModelIndex
);
480 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
484 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
488 KUrl
dest(source
.upUrl());
489 dest
.addPath(newName
);
491 const bool destExists
= KIO::NetAccess::exists(dest
, false, this);
493 // the destination already exists, hence ask the user
495 KIO::RenameDialog
renameDialog(this,
496 i18n("File Already Exists"),
500 switch (renameDialog
.exec()) {
501 case KIO::R_OVERWRITE
:
502 // the destination should be overwritten
503 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
506 case KIO::R_RENAME
: {
507 // a new name for the destination has been used
508 KUrl
newDest(renameDialog
.newDestUrl());
509 ok
= KIO::NetAccess::file_move(source
, newDest
);
514 // the renaming operation has been canceled
518 // no destination exists, hence just move the file to
520 ok
= KIO::NetAccess::file_move(source
, dest
);
523 const QString destFileName
= dest
.fileName();
526 //m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.", source.fileName(), destFileName),
527 // DolphinStatusBar::OperationCompleted);
529 KonqOperations::rename(this, source
, destFileName
);
532 //m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.", source.fileName(), destFileName),
533 // DolphinStatusBar::Error);
537 void DolphinView::reload()
540 startDirLister(url(), true);
543 void DolphinView::refresh()
549 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
551 QWidget::mouseReleaseEvent(event
);
554 void DolphinView::activate()
559 void DolphinView::triggerItem(const QModelIndex
& index
)
561 if (!isValidNameIndex(index
)) {
563 showHoverInformation(index
);
567 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
568 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
569 // items are selected by the user, hence don't trigger the
570 // item specified by 'index'
574 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
579 // Prefer the local path over the URL. This assures that the
580 // volume space information is correct. Assuming that the URL is media:/sda1,
581 // and the local path is /windows/C: For the URL the space info is related
582 // to the root partition (and hence wrong) and for the local path the space
583 // info is related to the windows partition (-> correct).
584 const QString
localPath(item
->localPath());
586 if (localPath
.isEmpty()) {
594 } else if (item
->isFile()) {
595 // allow to browse through ZIP and tar files
596 KMimeType::Ptr mime
= item
->mimeTypePtr();
597 if (mime
->is("application/zip")) {
598 url
.setProtocol("zip");
600 } else if (mime
->is("application/x-tar") ||
601 mime
->is("application/x-tarz") ||
602 mime
->is("application/x-bzip-compressed-tar") ||
603 mime
->is("application/x-compressed-tar") ||
604 mime
->is("application/x-tzo")) {
605 url
.setProtocol("tar");
615 void DolphinView::generatePreviews(const KFileItemList
& items
)
617 if (m_controller
->showPreview()) {
619 // Must turn QList<KFileItem *> to QList<KFileItem>...
620 QList
<KFileItem
> itemsToPreview
;
621 foreach( KFileItem
* it
, items
)
622 itemsToPreview
.append( *it
);
624 KIO::PreviewJob
* job
= KIO::filePreview(itemsToPreview
, 128);
625 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
626 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
630 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
632 Q_ASSERT(!item
.isNull());
633 if (item
.url().directory() != m_dirLister
->url().path()) {
634 // the preview job is still working on items of an older URL, hence
635 // the item is not part of the directory model anymore
639 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
640 if (idx
.isValid() && (idx
.column() == 0)) {
641 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
642 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
643 KIconEffect iconEffect
;
644 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
645 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
647 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
652 void DolphinView::restoreContentsPos()
654 m_blockContentsMovedSignal
= false;
655 if (!url().isEmpty()) {
656 QAbstractItemView
* view
= itemView();
657 // TODO #1: view->setCurrentItem(m_urlNavigator->currentFileName());
658 // TODO #2: temporary deactivated due to DolphinView/DolphinViewController split
659 //QPoint pos = m_urlNavigator->savedPosition();
661 view
->horizontalScrollBar()->setValue(pos
.x());
662 view
->verticalScrollBar()->setValue(pos
.y());
666 void DolphinView::emitSelectionChangedSignal()
668 emit
selectionChanged(DolphinView::selectedItems());
671 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
673 if (!url
.isValid()) {
674 // TODO: temporary deactivated due to DolphinView/DolphinViewController split
676 //const QString location(url.pathOrUrl());
677 //if (location.isEmpty()) {
678 // m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error);
680 // m_statusBar->setMessage(i18n("The location '%1' is invalid.", location),
681 // DolphinStatusBar::Error);
686 // Only show the directory loading progress if the status bar does
687 // not contain another progress information. This means that
688 // the directory loading progress information has the lowest priority.
690 // TODO: temporary deactivated due to DolphinView/DolphinViewController split
691 //const QString progressText(m_statusBar->progressText());
692 //m_showProgress = progressText.isEmpty() ||
693 // (progressText == i18n("Loading folder..."));
694 //if (m_showProgress) {
695 // m_statusBar->setProgressText(i18n("Loading folder..."));
696 // m_statusBar->setProgress(0);
699 m_cutItemsCache
.clear();
700 m_blockContentsMovedSignal
= true;
704 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
705 m_initializeColumnView
= false;
711 const KUrl
& dirListerUrl
= m_dirLister
->url();
712 if (dirListerUrl
.isValid()) {
713 const KUrl::List dirs
= m_dirLister
->directories();
716 m_dirLister
->updateDirectory(url
);
720 } else if (m_dirLister
->directories().contains(url
)) {
721 // The dir lister contains the directory already, so
722 // KDirLister::openUrl() may not been invoked twice.
723 m_dirLister
->updateDirectory(url
);
726 const KUrl
& dirListerUrl
= m_dirLister
->url();
727 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
728 // The current URL is not a child of the dir lister
729 // URL. This may happen when e. g. a bookmark has been selected
730 // and hence the view must be reset.
737 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
741 void DolphinView::setUrl(const KUrl
& url
)
743 if (m_controller
->url() == url
) {
747 m_controller
->setUrl(url
);
749 const ViewProperties
props(url
);
751 const Mode mode
= props
.viewMode();
752 bool changeMode
= (m_mode
!= mode
);
753 if (changeMode
&& isColumnViewActive()) {
754 // The column view is active. Only change the
755 // mode if the current URL is no child of the column view.
756 if (m_dirLister
->url().isParentOf(url
)) {
766 if (m_mode
== ColumnView
) {
767 // The mode has been changed to the Column View. When starting the dir
768 // lister with DolphinView::startDirLister() it is important to give a
769 // hint that the dir lister may not keep the current directory
770 // although this is the default for showing a hierarchy.
771 m_initializeColumnView
= true;
775 const bool showHiddenFiles
= props
.showHiddenFiles();
776 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
777 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
778 emit
showHiddenFilesChanged();
781 const bool categorized
= props
.categorizedSorting();
782 if (categorized
!= categorizedSorting()) {
783 if (supportsCategorizedSorting()) {
784 Q_ASSERT(m_iconsView
!= 0);
786 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
787 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
789 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
790 m_iconsView
->setItemCategorizer(0);
794 emit
categorizedSortingChanged();
797 const DolphinView::Sorting sorting
= props
.sorting();
798 if (sorting
!= m_proxyModel
->sorting()) {
799 m_proxyModel
->setSorting(sorting
);
800 emit
sortingChanged(sorting
);
803 const Qt::SortOrder sortOrder
= props
.sortOrder();
804 if (sortOrder
!= m_proxyModel
->sortOrder()) {
805 m_proxyModel
->setSortOrder(sortOrder
);
806 emit
sortOrderChanged(sortOrder
);
809 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
810 if (info
!= m_fileItemDelegate
->additionalInformation()) {
811 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
812 m_fileItemDelegate
->setAdditionalInformation(info
);
813 emit
additionalInfoChanged(info
);
816 const bool showPreview
= props
.showPreview();
817 if (showPreview
!= m_controller
->showPreview()) {
818 m_controller
->setShowPreview(showPreview
);
819 emit
showPreviewChanged();
823 emit
urlChanged(url
);
825 // TODO: temporary deactivated due to DolphinView/DolphinViewController split
826 //m_statusBar->clear();
829 void DolphinView::changeSelection(const KFileItemList
& selection
)
832 if (selection
.isEmpty()) {
835 const KUrl
& baseUrl
= url();
837 QItemSelection new_selection
;
838 foreach(KFileItem
* item
, selection
) {
839 url
= item
->url().upUrl();
840 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
841 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
842 new_selection
.select(index
, index
);
845 itemView()->selectionModel()->select(new_selection
,
846 QItemSelectionModel::ClearAndSelect
847 | QItemSelectionModel::Current
);
850 void DolphinView::openContextMenu(const QPoint
& pos
)
854 const QModelIndex index
= itemView()->indexAt(pos
);
855 if (isValidNameIndex(index
)) {
856 item
= fileItem(index
);
859 emit
requestContextMenu(item
, url());
862 void DolphinView::dropUrls(const KUrl::List
& urls
,
863 const QModelIndex
& index
,
866 KFileItem
* directory
= 0;
867 if (isValidNameIndex(index
)) {
868 KFileItem
* item
= fileItem(index
);
871 // the URLs are dropped above a directory
876 if ((directory
== 0) && (source
== itemView())) {
877 // The dropping is done into the same viewport where
878 // the dragging has been started. Just ignore this...
882 const KUrl
& destination
= (directory
== 0) ?
883 url() : directory
->url();
884 dropUrls(urls
, destination
);
887 void DolphinView::dropUrls(const KUrl::List
& urls
,
888 const KUrl
& destination
)
890 emit
urlsDropped(urls
, destination
);
893 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
895 ViewProperties
props(url());
896 props
.setSorting(sorting
);
898 m_proxyModel
->setSorting(sorting
);
900 emit
sortingChanged(sorting
);
903 void DolphinView::updateSortOrder(Qt::SortOrder order
)
905 ViewProperties
props(url());
906 props
.setSortOrder(order
);
908 m_proxyModel
->setSortOrder(order
);
910 emit
sortOrderChanged(order
);
913 void DolphinView::emitContentsMoved()
915 if (!m_blockContentsMovedSignal
) {
916 emit
contentsMoved(contentsX(), contentsY());
920 void DolphinView::updateCutItems()
922 // restore the icons of all previously selected items to the
924 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
925 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
927 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
928 if (index
.isValid()) {
929 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
933 m_cutItemsCache
.clear();
935 // ... and apply an item effect to all currently cut items
936 applyCutItemEffect();
939 void DolphinView::showHoverInformation(const QModelIndex
& index
)
941 if (hasSelection()) {
945 const KFileItem
* item
= fileItem(index
);
947 // TODO: temporary deactivated due to DolphinView/DolphinViewController split
948 //m_statusBar->setMessage(item->getStatusBarInfo(), DolphinStatusBar::Default);
949 emit
requestItemInfo(item
->url());
953 void DolphinView::clearHoverInformation()
955 // TODO: temporary deactivated due to DolphinView/DolphinViewController split
956 //m_statusBar->clear();
957 emit
requestItemInfo(KUrl());
961 void DolphinView::createView()
963 // delete current view
964 QAbstractItemView
* view
= itemView();
966 m_topLayout
->removeWidget(view
);
968 if (view
== m_iconsView
) {
969 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
970 m_iconsView
->setItemCategorizer(0);
978 m_fileItemDelegate
= 0;
981 Q_ASSERT(m_iconsView
== 0);
982 Q_ASSERT(m_detailsView
== 0);
983 Q_ASSERT(m_columnView
== 0);
985 // ... and recreate it representing the current mode
988 m_iconsView
= new DolphinIconsView(this, m_controller
);
993 m_detailsView
= new DolphinDetailsView(this, m_controller
);
994 view
= m_detailsView
;
998 m_columnView
= new DolphinColumnView(this, m_controller
);
1003 Q_ASSERT(view
!= 0);
1005 m_fileItemDelegate
= new KFileItemDelegate(view
);
1006 view
->setItemDelegate(m_fileItemDelegate
);
1008 view
->setModel(m_proxyModel
);
1009 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1011 new KMimeTypeResolver(view
, m_dirModel
);
1012 m_topLayout
->insertWidget(1, view
);
1014 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1015 this, SLOT(emitSelectionChangedSignal()));
1016 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1017 this, SLOT(emitContentsMoved()));
1018 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1019 this, SLOT(emitContentsMoved()));
1022 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1024 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1025 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1027 const QModelIndex topLeft
= itemModel
->index(0, 0);
1028 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1029 itemModel
->columnCount() - 1);
1031 QItemSelection
selection(topLeft
, bottomRight
);
1032 selectionModel
->select(selection
, flags
);
1035 QAbstractItemView
* DolphinView::itemView() const
1037 if (m_detailsView
!= 0) {
1038 return m_detailsView
;
1039 } else if (m_columnView
!= 0) {
1040 return m_columnView
;
1046 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1048 return index
.isValid() && (index
.column() == KDirModel::Name
);
1051 bool DolphinView::isCutItem(const KFileItem
& item
) const
1053 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1054 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1056 const KUrl
& itemUrl
= item
.url();
1057 KUrl::List::const_iterator it
= cutUrls
.begin();
1058 const KUrl::List::const_iterator end
= cutUrls
.end();
1060 if (*it
== itemUrl
) {
1069 void DolphinView::applyCutItemEffect()
1071 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1072 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
1076 KFileItemList
items(m_dirLister
->items());
1077 KFileItemList::const_iterator it
= items
.begin();
1078 const KFileItemList::const_iterator end
= items
.end();
1080 KFileItem
* item
= *it
;
1081 if (isCutItem(*item
)) {
1082 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
1083 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
1084 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
1085 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
1086 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
1087 QPixmap pixmap
= icon
.pixmap(128, 128);
1089 // remember current pixmap for the item to be able
1090 // to restore it when other items get cut
1092 cutItem
.url
= item
->url();
1093 cutItem
.pixmap
= pixmap
;
1094 m_cutItemsCache
.append(cutItem
);
1096 // apply icon effect to the cut item
1097 KIconEffect iconEffect
;
1098 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
1099 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
1106 #include "dolphinview.moc"