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 KFileItemList
DolphinView::selectedItems() const
465 const QAbstractItemView
* view
= itemView();
467 // Our view has a selection, we will map them back to the DirModel
468 // and then fill the KFileItemList.
469 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
471 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
472 KFileItemList itemList
;
474 const QModelIndexList indexList
= selection
.indexes();
475 QModelIndexList::const_iterator end
= indexList
.end();
476 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
477 Q_ASSERT((*it
).isValid());
479 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
481 itemList
.append(item
);
488 KUrl::List
DolphinView::selectedUrls() const
492 const KFileItemList list
= selectedItems();
493 KFileItemList::const_iterator it
= list
.begin();
494 const KFileItemList::const_iterator end
= list
.end();
496 KFileItem
* item
= *it
;
497 urls
.append(item
->url());
504 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
506 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
507 return m_dirModel
->itemForIndex(dirModelIndex
);
510 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
514 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
518 KUrl
dest(source
.upUrl());
519 dest
.addPath(newName
);
521 const bool destExists
= KIO::NetAccess::exists(dest
,
523 mainWindow()->activeView());
525 // the destination already exists, hence ask the user
527 KIO::RenameDialog
renameDialog(this,
528 i18n("File Already Exists"),
532 switch (renameDialog
.exec()) {
533 case KIO::R_OVERWRITE
:
534 // the destination should be overwritten
535 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
538 case KIO::R_RENAME
: {
539 // a new name for the destination has been used
540 KUrl
newDest(renameDialog
.newDestUrl());
541 ok
= KIO::NetAccess::file_move(source
, newDest
);
546 // the renaming operation has been canceled
552 // no destination exists, hence just move the file to
554 ok
= KIO::NetAccess::file_move(source
, dest
);
557 const QString destFileName
= dest
.fileName();
559 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
560 DolphinStatusBar::OperationCompleted
);
562 KonqOperations::rename(this, source
, destFileName
);
565 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
566 DolphinStatusBar::Error
);
571 void DolphinView::reload()
573 startDirLister(m_urlNavigator
->url(), true);
576 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
578 QWidget::mouseReleaseEvent(event
);
579 mainWindow()->setActiveView(this);
582 DolphinMainWindow
* DolphinView::mainWindow() const
587 void DolphinView::loadDirectory(const KUrl
& url
)
589 const ViewProperties
props(url
);
591 const Mode mode
= props
.viewMode();
592 if (m_mode
!= mode
) {
598 const bool showHiddenFiles
= props
.showHiddenFiles();
599 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
600 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
601 emit
showHiddenFilesChanged();
604 const DolphinView::Sorting sorting
= props
.sorting();
605 if (sorting
!= m_proxyModel
->sorting()) {
606 m_proxyModel
->setSorting(sorting
);
607 emit
sortingChanged(sorting
);
610 const Qt::SortOrder sortOrder
= props
.sortOrder();
611 if (sortOrder
!= m_proxyModel
->sortOrder()) {
612 m_proxyModel
->setSortOrder(sortOrder
);
613 emit
sortOrderChanged(sortOrder
);
616 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
617 if (info
!= m_fileItemDelegate
->additionalInformation()) {
618 m_fileItemDelegate
->setAdditionalInformation(info
);
620 emit
additionalInfoChanged(info
);
623 const bool showPreview
= props
.showPreview();
624 if (showPreview
!= m_controller
->showPreview()) {
625 m_controller
->setShowPreview(showPreview
);
626 emit
showPreviewChanged();
630 emit
urlChanged(url
);
632 m_statusBar
->clear();
635 void DolphinView::triggerItem(const QModelIndex
& index
)
637 if (!isValidNameIndex(index
)) {
641 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
642 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
643 // items are selected by the user, hence don't trigger the
644 // item specified by 'index'
648 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
653 // Prefer the local path over the URL. This assures that the
654 // volume space information is correct. Assuming that the URL is media:/sda1,
655 // and the local path is /windows/C: For the URL the space info is related
656 // to the root partition (and hence wrong) and for the local path the space
657 // info is related to the windows partition (-> correct).
658 const QString
localPath(item
->localPath());
660 if (localPath
.isEmpty()) {
670 else if (item
->isFile()) {
671 // allow to browse through ZIP and tar files
672 KMimeType::Ptr mime
= item
->mimeTypePtr();
673 if (mime
->is("application/x-zip")) {
674 url
.setProtocol("zip");
677 else if (mime
->is("application/x-tar") ||
678 mime
->is("application/x-tarz") ||
679 mime
->is("application/x-tbz") ||
680 mime
->is("application/x-tgz") ||
681 mime
->is("application/x-tzo")) {
682 url
.setProtocol("tar");
694 void DolphinView::updateProgress(int percent
)
696 if (m_showProgress
) {
697 m_statusBar
->setProgress(percent
);
701 void DolphinView::updateItemCount()
703 if (m_showProgress
) {
704 m_statusBar
->setProgressText(QString());
705 m_statusBar
->setProgress(100);
706 m_showProgress
= false;
709 KFileItemList
items(m_dirLister
->items());
710 KFileItemList::const_iterator it
= items
.begin();
711 const KFileItemList::const_iterator end
= items
.end();
717 KFileItem
* item
= *it
;
729 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
732 void DolphinView::generatePreviews(const KFileItemList
& items
)
734 if (m_controller
->showPreview()) {
735 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
736 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
737 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
740 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
741 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
742 QTimer::singleShot(0, this, SLOT(applyCutEffect()));
746 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
749 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
750 if (idx
.isValid() && (idx
.column() == 0)) {
751 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
752 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(*item
)) {
753 KIconEffect iconEffect
;
754 QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
755 m_dirModel
->setData(idx
, cutPixmap
, Qt::DecorationRole
);
758 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
763 void DolphinView::restoreContentsPos()
766 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
767 if (!history
.isEmpty()) {
768 QAbstractItemView
* view
= itemView();
769 // TODO: view->setCurrentItem(history[index].currentFileName());
771 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
773 view
->horizontalScrollBar()->setValue((*it
).contentsX());
774 view
->verticalScrollBar()->setValue((*it
).contentsY());
778 void DolphinView::showInfoMessage(const QString
& msg
)
780 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
783 void DolphinView::showErrorMessage(const QString
& msg
)
785 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
788 void DolphinView::emitSelectionChangedSignal()
790 emit
selectionChanged();
793 void DolphinView::closeFilterBar()
796 emit
showFilterBarChanged(false);
799 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
801 if (!url
.isValid()) {
802 const QString
location(url
.pathOrUrl());
803 if (location
.isEmpty()) {
804 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
807 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
808 DolphinStatusBar::Error
);
813 // Only show the directory loading progress if the status bar does
814 // not contain another progress information. This means that
815 // the directory loading progress information has the lowest priority.
816 const QString
progressText(m_statusBar
->progressText());
817 m_showProgress
= progressText
.isEmpty() ||
818 (progressText
== i18n("Loading directory..."));
819 if (m_showProgress
) {
820 m_statusBar
->setProgressText(i18n("Loading directory..."));
821 m_statusBar
->setProgress(0);
825 m_dirLister
->openUrl(url
, false, reload
);
828 QString
DolphinView::defaultStatusBarText() const
830 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
836 QString
DolphinView::selectionStatusBarText() const
839 const KFileItemList list
= selectedItems();
840 if (list
.isEmpty()) {
841 // when an item is triggered, it is temporary selected but selectedItems()
842 // will return an empty list
848 KIO::filesize_t byteSize
= 0;
849 KFileItemList::const_iterator it
= list
.begin();
850 const KFileItemList::const_iterator end
= list
.end();
852 KFileItem
* item
= *it
;
858 byteSize
+= item
->size();
863 if (folderCount
> 0) {
864 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
871 const QString
sizeText(KIO::convertSize(byteSize
));
872 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
878 void DolphinView::showFilterBar(bool show
)
880 Q_ASSERT(m_filterBar
!= 0);
889 void DolphinView::updateStatusBar()
891 // As the item count information is less important
892 // in comparison with other messages, it should only
894 // - the status bar is empty or
895 // - shows already the item count information or
896 // - shows only a not very important information
897 // - if any progress is given don't show the item count info at all
898 const QString
msg(m_statusBar
->message());
899 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
900 (msg
== m_statusBar
->defaultText()) ||
901 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
902 (m_statusBar
->progress() == 100);
904 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
905 m_statusBar
->setDefaultText(text
);
907 if (updateStatusBarMsg
) {
908 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
912 void DolphinView::requestActivation()
914 m_mainWindow
->setActiveView(this);
917 void DolphinView::updateCutItems()
919 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
920 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
924 KFileItemList
items(m_dirLister
->items());
925 KFileItemList::const_iterator it
= items
.begin();
926 const KFileItemList::const_iterator end
= items
.end();
928 KFileItem
* item
= *it
;
929 if (isCutItem(*item
)) {
930 QPixmap pixmap
= item
->pixmap(0);
931 KIconEffect iconEffect
;
932 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
933 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
935 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
942 void DolphinView::changeNameFilter(const QString
& nameFilter
)
944 // The name filter of KDirLister does a 'hard' filtering, which
945 // means that only the items are shown where the names match
946 // exactly the filter. This is non-transparent for the user, which
947 // just wants to have a 'soft' filtering: does the name contain
948 // the filter string?
949 QString
adjustedFilter(nameFilter
);
950 adjustedFilter
.insert(0, '*');
951 adjustedFilter
.append('*');
953 // Use the ProxyModel to filter:
954 // This code is #ifdefed as setNameFilter behaves
955 // slightly different than the QSortFilterProxyModel
956 // as it will not remove directories. I will ask
957 // our beloved usability experts for input
960 m_dirLister
->setNameFilter(adjustedFilter
);
961 m_dirLister
->emitChanges();
963 m_proxyModel
->setFilterRegExp( nameFilter
);
967 void DolphinView::openContextMenu(const QPoint
& pos
)
971 const QModelIndex index
= itemView()->indexAt(pos
);
972 if (isValidNameIndex(index
)) {
973 item
= fileItem(index
);
976 DolphinContextMenu
contextMenu(m_mainWindow
,
983 void DolphinView::dropUrls(const KUrl::List
& urls
,
984 const QModelIndex
& index
,
987 KFileItem
* directory
= 0;
988 if (isValidNameIndex(index
)) {
989 KFileItem
* item
= fileItem(index
);
992 // the URLs are dropped above a directory
997 if ((directory
== 0) && (source
== itemView())) {
998 // The dropping is done into the same viewport where
999 // the dragging has been started. Just ignore this...
1003 const KUrl
& destination
= (directory
== 0) ? url() :
1006 kDebug() << "DolphinView::dropUrls() - destination: " << destination
.prettyUrl() << endl
;
1008 dropUrls(urls
, destination
);
1011 void DolphinView::dropUrls(const KUrl::List
& urls
,
1012 const KUrl
& destination
)
1014 m_mainWindow
->dropUrls(urls
, destination
);
1018 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
1020 ViewProperties
props(url());
1021 props
.setSorting(sorting
);
1023 m_proxyModel
->setSorting(sorting
);
1025 emit
sortingChanged(sorting
);
1028 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1030 ViewProperties
props(url());
1031 props
.setSortOrder(order
);
1033 m_proxyModel
->setSortOrder(order
);
1035 emit
sortOrderChanged(order
);
1038 void DolphinView::emitContentsMoved()
1040 emit
contentsMoved(contentsX(), contentsY());
1043 void DolphinView::updateActivationState()
1045 m_urlNavigator
->setActive(isActive());
1048 void DolphinView::createView()
1050 // delete current view
1051 QAbstractItemView
* view
= itemView();
1053 m_topLayout
->removeWidget(view
);
1055 view
->deleteLater();
1059 m_fileItemDelegate
= 0;
1062 Q_ASSERT(m_iconsView
== 0);
1063 Q_ASSERT(m_detailsView
== 0);
1065 // ... and recreate it representing the current mode
1068 m_iconsView
= new DolphinIconsView(this, m_controller
);
1073 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1074 view
= m_detailsView
;
1078 Q_ASSERT(view
!= 0);
1080 m_fileItemDelegate
= new KFileItemDelegate(view
);
1081 view
->setItemDelegate(m_fileItemDelegate
);
1083 view
->setModel(m_proxyModel
);
1084 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1086 new KMimeTypeResolver(view
, m_dirModel
);
1087 m_topLayout
->insertWidget(1, view
);
1089 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1090 m_controller
, SLOT(indicateSelectionChange()));
1091 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1092 this, SLOT(emitContentsMoved()));
1093 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1094 this, SLOT(emitContentsMoved()));
1097 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1099 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1100 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1102 const QModelIndex topLeft
= itemModel
->index(0, 0);
1103 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1104 itemModel
->columnCount() - 1);
1106 QItemSelection
selection(topLeft
, bottomRight
);
1107 selectionModel
->select(selection
, flags
);
1110 QAbstractItemView
* DolphinView::itemView() const
1112 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1113 if (m_detailsView
!= 0) {
1114 return m_detailsView
;
1119 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1121 return index
.isValid() && (index
.column() == KDirModel::Name
);
1124 bool DolphinView::isCutItem(const KFileItem
& item
) const
1126 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1127 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1129 const KUrl
& itemUrl
= item
.url();
1130 KUrl::List::const_iterator it
= cutUrls
.begin();
1131 const KUrl::List::const_iterator end
= cutUrls
.end();
1133 if (*it
== itemUrl
) {
1142 #include "dolphinview.moc"