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 <QItemSelectionModel>
27 #include <QMouseEvent>
28 #include <QVBoxLayout>
30 #include <kdirmodel.h>
31 #include <kfileitemdelegate.h>
33 #include <kiconeffect.h>
34 #include <kio/netaccess.h>
35 #include <kio/renamedialog.h>
36 #include <kio/previewjob.h>
37 #include <kmimetyperesolver.h>
38 #include <konqmimedata.h>
39 #include <konq_operations.h>
42 #include "dolphincontroller.h"
43 #include "dolphinstatusbar.h"
44 #include "dolphinmainwindow.h"
45 #include "dolphindirlister.h"
46 #include "dolphinsortfilterproxymodel.h"
47 #include "dolphindetailsview.h"
48 #include "dolphiniconsview.h"
49 #include "dolphincontextmenu.h"
50 #include "filterbar.h"
51 #include "renamedialog.h"
52 #include "urlnavigator.h"
53 #include "viewproperties.h"
55 DolphinView::DolphinView(DolphinMainWindow
* mainWindow
,
59 bool showHiddenFiles
) :
61 m_showProgress(false),
66 m_mainWindow(mainWindow
),
72 m_fileItemDelegate(0),
80 setFocusPolicy(Qt::StrongFocus
);
81 m_topLayout
= new QVBoxLayout(this);
82 m_topLayout
->setSpacing(0);
83 m_topLayout
->setMargin(0);
85 connect(m_mainWindow
, SIGNAL(activeViewChanged()),
86 this, SLOT(updateActivationState()));
88 m_urlNavigator
= new UrlNavigator(url
, this);
89 m_urlNavigator
->setShowHiddenFiles(showHiddenFiles
);
90 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
91 this, SLOT(loadDirectory(const KUrl
&)));
92 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
93 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
94 connect(m_urlNavigator
, SIGNAL(activated()),
95 this, SLOT(requestActivation()));
96 connect(this, SIGNAL(contentsMoved(int, int)),
97 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
99 m_statusBar
= new DolphinStatusBar(this);
101 m_dirLister
= new DolphinDirLister();
102 m_dirLister
->setAutoUpdate(true);
103 m_dirLister
->setMainWindow(this);
104 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
105 m_dirLister
->setDelayedMimeTypes(true);
107 connect(m_dirLister
, SIGNAL(clear()),
108 this, SLOT(updateStatusBar()));
109 connect(m_dirLister
, SIGNAL(percent(int)),
110 this, SLOT(updateProgress(int)));
111 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
112 this, SLOT(updateStatusBar()));
113 connect(m_dirLister
, SIGNAL(completed()),
114 this, SLOT(updateItemCount()));
115 connect(m_dirLister
, SIGNAL(completed()),
116 this, SLOT(updateCutItems()));
117 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
118 this, SLOT(generatePreviews(const KFileItemList
&)));
119 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
120 this, SLOT(showInfoMessage(const QString
&)));
121 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
122 this, SLOT(showErrorMessage(const QString
&)));
124 m_dirModel
= new KDirModel();
125 m_dirModel
->setDirLister(m_dirLister
);
126 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
128 m_proxyModel
= new DolphinSortFilterProxyModel(this);
129 m_proxyModel
->setSourceModel(m_dirModel
);
131 m_controller
= new DolphinController(this);
132 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
133 this, SLOT(openContextMenu(const QPoint
&)));
134 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
135 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
136 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
137 this, SLOT(updateSorting(DolphinView::Sorting
)));
138 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
139 this, SLOT(updateSortOrder(Qt::SortOrder
)));
140 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
141 this, SLOT(triggerItem(const QModelIndex
&)));
142 connect(m_controller
, SIGNAL(selectionChanged()),
143 this, SLOT(emitSelectionChangedSignal()));
144 connect(m_controller
, SIGNAL(activated()),
145 this, SLOT(requestActivation()));
149 m_iconSize
= K3Icon::SizeMedium
;
151 m_filterBar
= new FilterBar(this);
153 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
154 this, SLOT(changeNameFilter(const QString
&)));
155 connect(m_filterBar
, SIGNAL(closeRequest()),
156 this, SLOT(closeFilterBar()));
158 m_topLayout
->addWidget(m_urlNavigator
);
159 m_topLayout
->addWidget(itemView());
160 m_topLayout
->addWidget(m_filterBar
);
161 m_topLayout
->addWidget(m_statusBar
);
163 loadDirectory(m_urlNavigator
->url());
166 DolphinView::~DolphinView()
172 void DolphinView::setUrl(const KUrl
& url
)
174 m_urlNavigator
->setUrl(url
);
175 m_controller
->setUrl(url
);
178 const KUrl
& DolphinView::url() const
180 return m_urlNavigator
->url();
183 bool DolphinView::isActive() const
185 return m_mainWindow
->activeView() == this;
188 void DolphinView::setMode(Mode mode
)
190 if (mode
== m_mode
) {
191 return; // the wished mode is already set
196 ViewProperties
props(m_urlNavigator
->url());
197 props
.setViewMode(m_mode
);
200 startDirLister(m_urlNavigator
->url());
205 DolphinView::Mode
DolphinView::mode() const
210 void DolphinView::setShowPreview(bool show
)
212 ViewProperties
props(m_urlNavigator
->url());
213 props
.setShowPreview(show
);
215 m_controller
->setShowPreview(show
);
217 emit
showPreviewChanged();
221 bool DolphinView::showPreview() const
223 return m_controller
->showPreview();
226 void DolphinView::setShowHiddenFiles(bool show
)
228 if (m_dirLister
->showingDotFiles() == show
) {
232 ViewProperties
props(m_urlNavigator
->url());
233 props
.setShowHiddenFiles(show
);
236 m_dirLister
->setShowingDotFiles(show
);
237 m_urlNavigator
->setShowHiddenFiles(show
);
239 emit
showHiddenFilesChanged();
244 bool DolphinView::showHiddenFiles() const
246 return m_dirLister
->showingDotFiles();
249 void DolphinView::renameSelectedItems()
251 DolphinView
* view
= mainWindow()->activeView();
252 const KUrl::List urls
= selectedUrls();
253 if (urls
.count() > 1) {
254 // More than one item has been selected for renaming. Open
255 // a rename dialog and rename all items afterwards.
256 RenameDialog
dialog(urls
);
257 if (dialog
.exec() == QDialog::Rejected
) {
261 const QString
& newName
= dialog
.newName();
262 if (newName
.isEmpty()) {
263 view
->statusBar()->setMessage(dialog
.errorString(),
264 DolphinStatusBar::Error
);
267 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
268 // as one operation instead of n rename operations like it is done now...
269 Q_ASSERT(newName
.contains('#'));
271 // iterate through all selected items and rename them...
272 const int replaceIndex
= newName
.indexOf('#');
273 Q_ASSERT(replaceIndex
>= 0);
276 KUrl::List::const_iterator it
= urls
.begin();
277 KUrl::List::const_iterator end
= urls
.end();
279 const KUrl
& oldUrl
= *it
;
281 number
.setNum(index
++);
283 QString
name(newName
);
284 name
.replace(replaceIndex
, 1, number
);
286 if (oldUrl
.fileName() != name
) {
287 KUrl
newUrl(oldUrl
.upUrl());
288 newUrl
.addPath(name
);
289 m_mainWindow
->rename(oldUrl
, newUrl
);
296 // Only one item has been selected for renaming. Use the custom
297 // renaming mechanism from the views.
298 Q_ASSERT(urls
.count() == 1);
300 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
301 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
302 // is a benefit for the user at all -> let's wait for some input first...
303 RenameDialog
dialog(urls
);
304 if (dialog
.exec() == QDialog::Rejected
) {
308 const QString
& newName
= dialog
.newName();
309 if (newName
.isEmpty()) {
310 view
->statusBar()->setMessage(dialog
.errorString(),
311 DolphinStatusBar::Error
);
314 const KUrl
& oldUrl
= urls
.first();
315 KUrl newUrl
= oldUrl
.upUrl();
316 newUrl
.addPath(newName
);
317 m_mainWindow
->rename(oldUrl
, newUrl
);
322 void DolphinView::selectAll()
324 selectAll(QItemSelectionModel::Select
);
327 void DolphinView::invertSelection()
329 selectAll(QItemSelectionModel::Toggle
);
332 DolphinStatusBar
* DolphinView::statusBar() const
337 int DolphinView::contentsX() const
340 return itemView()->horizontalScrollBar()->value();
343 int DolphinView::contentsY() const
345 return itemView()->verticalScrollBar()->value();
348 void DolphinView::refreshSettings()
350 startDirLister(m_urlNavigator
->url());
353 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
355 emit
requestItemInfo(url
);
358 bool DolphinView::isFilterBarVisible() const
360 return m_filterBar
->isVisible();
363 bool DolphinView::isUrlEditable() const
365 return m_urlNavigator
->isUrlEditable();
368 void DolphinView::zoomIn()
370 m_controller
->triggerZoomIn();
373 void DolphinView::zoomOut()
375 m_controller
->triggerZoomOut();
378 bool DolphinView::isZoomInPossible() const
380 return m_controller
->isZoomInPossible();
383 bool DolphinView::isZoomOutPossible() const
385 return m_controller
->isZoomOutPossible();
388 void DolphinView::setSorting(Sorting sorting
)
390 if (sorting
!= this->sorting()) {
391 updateSorting(sorting
);
395 DolphinView::Sorting
DolphinView::sorting() const
397 return m_proxyModel
->sorting();
400 void DolphinView::setSortOrder(Qt::SortOrder order
)
402 if (sortOrder() != order
) {
403 updateSortOrder(order
);
407 Qt::SortOrder
DolphinView::sortOrder() const
409 return m_proxyModel
->sortOrder();
412 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
414 ViewProperties
props(m_urlNavigator
->url());
415 props
.setAdditionalInfo(info
);
417 m_fileItemDelegate
->setAdditionalInformation(info
);
419 emit
additionalInfoChanged(info
);
423 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
425 return m_fileItemDelegate
->additionalInformation();
428 void DolphinView::goBack()
430 m_urlNavigator
->goBack();
433 void DolphinView::goForward()
435 m_urlNavigator
->goForward();
438 void DolphinView::goUp()
440 m_urlNavigator
->goUp();
443 void DolphinView::goHome()
445 m_urlNavigator
->goHome();
448 void DolphinView::setUrlEditable(bool editable
)
450 m_urlNavigator
->editUrl(editable
);
453 const QLinkedList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
455 return m_urlNavigator
->history(index
);
458 bool DolphinView::hasSelection() const
460 return itemView()->selectionModel()->hasSelection();
463 void DolphinView::clearSelection()
465 itemView()->selectionModel()->clear();
468 KFileItemList
DolphinView::selectedItems() const
470 const QAbstractItemView
* view
= itemView();
472 // Our view has a selection, we will map them back to the DirModel
473 // and then fill the KFileItemList.
474 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
476 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
477 KFileItemList itemList
;
479 const QModelIndexList indexList
= selection
.indexes();
480 QModelIndexList::const_iterator end
= indexList
.end();
481 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
482 Q_ASSERT((*it
).isValid());
484 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
486 itemList
.append(item
);
493 KUrl::List
DolphinView::selectedUrls() const
497 const KFileItemList list
= selectedItems();
498 KFileItemList::const_iterator it
= list
.begin();
499 const KFileItemList::const_iterator end
= list
.end();
501 KFileItem
* item
= *it
;
502 urls
.append(item
->url());
509 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
511 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
512 return m_dirModel
->itemForIndex(dirModelIndex
);
515 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
519 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
523 KUrl
dest(source
.upUrl());
524 dest
.addPath(newName
);
526 const bool destExists
= KIO::NetAccess::exists(dest
,
528 mainWindow()->activeView());
530 // the destination already exists, hence ask the user
532 KIO::RenameDialog
renameDialog(this,
533 i18n("File Already Exists"),
537 switch (renameDialog
.exec()) {
538 case KIO::R_OVERWRITE
:
539 // the destination should be overwritten
540 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
543 case KIO::R_RENAME
: {
544 // a new name for the destination has been used
545 KUrl
newDest(renameDialog
.newDestUrl());
546 ok
= KIO::NetAccess::file_move(source
, newDest
);
551 // the renaming operation has been canceled
557 // no destination exists, hence just move the file to
559 ok
= KIO::NetAccess::file_move(source
, dest
);
562 const QString destFileName
= dest
.fileName();
564 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
565 DolphinStatusBar::OperationCompleted
);
567 KonqOperations::rename(this, source
, destFileName
);
570 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
571 DolphinStatusBar::Error
);
576 void DolphinView::reload()
578 startDirLister(m_urlNavigator
->url(), true);
581 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
583 QWidget::mouseReleaseEvent(event
);
584 mainWindow()->setActiveView(this);
587 DolphinMainWindow
* DolphinView::mainWindow() const
592 void DolphinView::loadDirectory(const KUrl
& url
)
594 const ViewProperties
props(url
);
596 const Mode mode
= props
.viewMode();
597 if (m_mode
!= mode
) {
603 const bool showHiddenFiles
= props
.showHiddenFiles();
604 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
605 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
606 emit
showHiddenFilesChanged();
609 const DolphinView::Sorting sorting
= props
.sorting();
610 if (sorting
!= m_proxyModel
->sorting()) {
611 m_proxyModel
->setSorting(sorting
);
612 emit
sortingChanged(sorting
);
615 const Qt::SortOrder sortOrder
= props
.sortOrder();
616 if (sortOrder
!= m_proxyModel
->sortOrder()) {
617 m_proxyModel
->setSortOrder(sortOrder
);
618 emit
sortOrderChanged(sortOrder
);
621 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
622 if (info
!= m_fileItemDelegate
->additionalInformation()) {
623 m_fileItemDelegate
->setAdditionalInformation(info
);
625 emit
additionalInfoChanged(info
);
628 const bool showPreview
= props
.showPreview();
629 if (showPreview
!= m_controller
->showPreview()) {
630 m_controller
->setShowPreview(showPreview
);
631 emit
showPreviewChanged();
635 emit
urlChanged(url
);
637 m_statusBar
->clear();
640 void DolphinView::triggerItem(const QModelIndex
& index
)
642 if (!isValidNameIndex(index
)) {
646 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
647 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
648 // items are selected by the user, hence don't trigger the
649 // item specified by 'index'
653 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
658 // Prefer the local path over the URL. This assures that the
659 // volume space information is correct. Assuming that the URL is media:/sda1,
660 // and the local path is /windows/C: For the URL the space info is related
661 // to the root partition (and hence wrong) and for the local path the space
662 // info is related to the windows partition (-> correct).
663 const QString
localPath(item
->localPath());
665 if (localPath
.isEmpty()) {
675 else if (item
->isFile()) {
676 // allow to browse through ZIP and tar files
677 KMimeType::Ptr mime
= item
->mimeTypePtr();
678 if (mime
->is("application/x-zip")) {
679 url
.setProtocol("zip");
682 else if (mime
->is("application/x-tar") ||
683 mime
->is("application/x-tarz") ||
684 mime
->is("application/x-tbz") ||
685 mime
->is("application/x-tgz") ||
686 mime
->is("application/x-tzo")) {
687 url
.setProtocol("tar");
699 void DolphinView::updateProgress(int percent
)
701 if (m_showProgress
) {
702 m_statusBar
->setProgress(percent
);
706 void DolphinView::updateItemCount()
708 if (m_showProgress
) {
709 m_statusBar
->setProgressText(QString());
710 m_statusBar
->setProgress(100);
711 m_showProgress
= false;
714 KFileItemList
items(m_dirLister
->items());
715 KFileItemList::const_iterator it
= items
.begin();
716 const KFileItemList::const_iterator end
= items
.end();
722 KFileItem
* item
= *it
;
734 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
737 void DolphinView::generatePreviews(const KFileItemList
& items
)
739 if (m_controller
->showPreview()) {
740 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
741 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
742 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
745 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
746 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
747 QTimer::singleShot(0, this, SLOT(applyCutEffect()));
751 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
754 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
755 if (idx
.isValid() && (idx
.column() == 0)) {
756 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
757 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(*item
)) {
758 KIconEffect iconEffect
;
759 QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
760 m_dirModel
->setData(idx
, cutPixmap
, Qt::DecorationRole
);
763 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
768 void DolphinView::restoreContentsPos()
771 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
772 if (!history
.isEmpty()) {
773 QAbstractItemView
* view
= itemView();
774 // TODO: view->setCurrentItem(history[index].currentFileName());
776 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
778 view
->horizontalScrollBar()->setValue((*it
).contentsX());
779 view
->verticalScrollBar()->setValue((*it
).contentsY());
783 void DolphinView::showInfoMessage(const QString
& msg
)
785 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
788 void DolphinView::showErrorMessage(const QString
& msg
)
790 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
793 void DolphinView::emitSelectionChangedSignal()
795 emit
selectionChanged();
798 void DolphinView::closeFilterBar()
801 emit
showFilterBarChanged(false);
804 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
806 if (!url
.isValid()) {
807 const QString
location(url
.pathOrUrl());
808 if (location
.isEmpty()) {
809 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
812 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
813 DolphinStatusBar::Error
);
818 // Only show the directory loading progress if the status bar does
819 // not contain another progress information. This means that
820 // the directory loading progress information has the lowest priority.
821 const QString
progressText(m_statusBar
->progressText());
822 m_showProgress
= progressText
.isEmpty() ||
823 (progressText
== i18n("Loading directory..."));
824 if (m_showProgress
) {
825 m_statusBar
->setProgressText(i18n("Loading directory..."));
826 m_statusBar
->setProgress(0);
830 m_dirLister
->openUrl(url
, false, reload
);
833 QString
DolphinView::defaultStatusBarText() const
835 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
841 QString
DolphinView::selectionStatusBarText() const
844 const KFileItemList list
= selectedItems();
845 if (list
.isEmpty()) {
846 // when an item is triggered, it is temporary selected but selectedItems()
847 // will return an empty list
853 KIO::filesize_t byteSize
= 0;
854 KFileItemList::const_iterator it
= list
.begin();
855 const KFileItemList::const_iterator end
= list
.end();
857 KFileItem
* item
= *it
;
863 byteSize
+= item
->size();
868 if (folderCount
> 0) {
869 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
876 const QString
sizeText(KIO::convertSize(byteSize
));
877 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
883 void DolphinView::showFilterBar(bool show
)
885 Q_ASSERT(m_filterBar
!= 0);
894 void DolphinView::updateStatusBar()
896 // As the item count information is less important
897 // in comparison with other messages, it should only
899 // - the status bar is empty or
900 // - shows already the item count information or
901 // - shows only a not very important information
902 // - if any progress is given don't show the item count info at all
903 const QString
msg(m_statusBar
->message());
904 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
905 (msg
== m_statusBar
->defaultText()) ||
906 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
907 (m_statusBar
->progress() == 100);
909 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
910 m_statusBar
->setDefaultText(text
);
912 if (updateStatusBarMsg
) {
913 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
917 void DolphinView::requestActivation()
919 m_mainWindow
->setActiveView(this);
922 void DolphinView::updateCutItems()
924 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
925 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
929 KFileItemList
items(m_dirLister
->items());
930 KFileItemList::const_iterator it
= items
.begin();
931 const KFileItemList::const_iterator end
= items
.end();
933 KFileItem
* item
= *it
;
934 if (isCutItem(*item
)) {
935 QPixmap pixmap
= item
->pixmap(0);
936 KIconEffect iconEffect
;
937 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
938 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
940 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
947 void DolphinView::changeNameFilter(const QString
& nameFilter
)
949 // The name filter of KDirLister does a 'hard' filtering, which
950 // means that only the items are shown where the names match
951 // exactly the filter. This is non-transparent for the user, which
952 // just wants to have a 'soft' filtering: does the name contain
953 // the filter string?
954 QString
adjustedFilter(nameFilter
);
955 adjustedFilter
.insert(0, '*');
956 adjustedFilter
.append('*');
958 // Use the ProxyModel to filter:
959 // This code is #ifdefed as setNameFilter behaves
960 // slightly different than the QSortFilterProxyModel
961 // as it will not remove directories. I will ask
962 // our beloved usability experts for input
965 m_dirLister
->setNameFilter(adjustedFilter
);
966 m_dirLister
->emitChanges();
968 m_proxyModel
->setFilterRegExp( nameFilter
);
972 void DolphinView::openContextMenu(const QPoint
& pos
)
976 const QModelIndex index
= itemView()->indexAt(pos
);
977 if (isValidNameIndex(index
)) {
978 item
= fileItem(index
);
981 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url());
985 void DolphinView::dropUrls(const KUrl::List
& urls
,
986 const QModelIndex
& index
,
989 KFileItem
* directory
= 0;
990 if (isValidNameIndex(index
)) {
991 KFileItem
* item
= fileItem(index
);
994 // the URLs are dropped above a directory
999 if ((directory
== 0) && (source
== itemView())) {
1000 // The dropping is done into the same viewport where
1001 // the dragging has been started. Just ignore this...
1005 const KUrl
& destination
= (directory
== 0) ? url() :
1008 kDebug() << "DolphinView::dropUrls() - destination: " << destination
.prettyUrl() << endl
;
1010 dropUrls(urls
, destination
);
1013 void DolphinView::dropUrls(const KUrl::List
& urls
,
1014 const KUrl
& destination
)
1016 m_mainWindow
->dropUrls(urls
, destination
);
1020 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
1022 ViewProperties
props(url());
1023 props
.setSorting(sorting
);
1025 m_proxyModel
->setSorting(sorting
);
1027 emit
sortingChanged(sorting
);
1030 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1032 ViewProperties
props(url());
1033 props
.setSortOrder(order
);
1035 m_proxyModel
->setSortOrder(order
);
1037 emit
sortOrderChanged(order
);
1040 void DolphinView::emitContentsMoved()
1042 emit
contentsMoved(contentsX(), contentsY());
1045 void DolphinView::updateActivationState()
1047 m_urlNavigator
->setActive(isActive());
1050 void DolphinView::createView()
1052 // delete current view
1053 QAbstractItemView
* view
= itemView();
1055 m_topLayout
->removeWidget(view
);
1057 view
->deleteLater();
1061 m_fileItemDelegate
= 0;
1064 Q_ASSERT(m_iconsView
== 0);
1065 Q_ASSERT(m_detailsView
== 0);
1067 // ... and recreate it representing the current mode
1070 m_iconsView
= new DolphinIconsView(this, m_controller
);
1075 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1076 view
= m_detailsView
;
1080 Q_ASSERT(view
!= 0);
1082 m_fileItemDelegate
= new KFileItemDelegate(view
);
1083 view
->setItemDelegate(m_fileItemDelegate
);
1085 view
->setModel(m_proxyModel
);
1086 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1088 new KMimeTypeResolver(view
, m_dirModel
);
1089 m_topLayout
->insertWidget(1, view
);
1091 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1092 m_controller
, SLOT(indicateSelectionChange()));
1093 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1094 this, SLOT(emitContentsMoved()));
1095 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1096 this, SLOT(emitContentsMoved()));
1099 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1101 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1102 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1104 const QModelIndex topLeft
= itemModel
->index(0, 0);
1105 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1106 itemModel
->columnCount() - 1);
1108 QItemSelection
selection(topLeft
, bottomRight
);
1109 selectionModel
->select(selection
, flags
);
1112 QAbstractItemView
* DolphinView::itemView() const
1114 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1115 if (m_detailsView
!= 0) {
1116 return m_detailsView
;
1121 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1123 return index
.isValid() && (index
.column() == KDirModel::Name
);
1126 bool DolphinView::isCutItem(const KFileItem
& item
) const
1128 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1129 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1131 const KUrl
& itemUrl
= item
.url();
1132 KUrl::List::const_iterator it
= cutUrls
.begin();
1133 const KUrl::List::const_iterator end
= cutUrls
.end();
1135 if (*it
== itemUrl
) {
1144 #include "dolphinview.moc"