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),
62 m_blockContentsMovedSignal(false),
67 m_mainWindow(mainWindow
),
73 m_fileItemDelegate(0),
81 setFocusPolicy(Qt::StrongFocus
);
82 m_topLayout
= new QVBoxLayout(this);
83 m_topLayout
->setSpacing(0);
84 m_topLayout
->setMargin(0);
86 connect(m_mainWindow
, SIGNAL(activeViewChanged()),
87 this, SLOT(updateActivationState()));
89 m_urlNavigator
= new UrlNavigator(url
, this);
90 m_urlNavigator
->setShowHiddenFiles(showHiddenFiles
);
91 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
92 this, SLOT(loadDirectory(const KUrl
&)));
93 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
94 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
95 connect(m_urlNavigator
, SIGNAL(activated()),
96 this, SLOT(requestActivation()));
97 connect(this, SIGNAL(contentsMoved(int, int)),
98 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
100 m_statusBar
= new DolphinStatusBar(this);
102 m_dirLister
= new DolphinDirLister();
103 m_dirLister
->setAutoUpdate(true);
104 m_dirLister
->setMainWindow(this);
105 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
106 m_dirLister
->setDelayedMimeTypes(true);
108 connect(m_dirLister
, SIGNAL(clear()),
109 this, SLOT(updateStatusBar()));
110 connect(m_dirLister
, SIGNAL(percent(int)),
111 this, SLOT(updateProgress(int)));
112 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
113 this, SLOT(updateStatusBar()));
114 connect(m_dirLister
, SIGNAL(completed()),
115 this, SLOT(updateItemCount()));
116 connect(m_dirLister
, SIGNAL(completed()),
117 this, SLOT(updateCutItems()));
118 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
119 this, SLOT(generatePreviews(const KFileItemList
&)));
120 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
121 this, SLOT(showInfoMessage(const QString
&)));
122 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
123 this, SLOT(showErrorMessage(const QString
&)));
125 m_dirModel
= new KDirModel();
126 m_dirModel
->setDirLister(m_dirLister
);
127 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
129 m_proxyModel
= new DolphinSortFilterProxyModel(this);
130 m_proxyModel
->setSourceModel(m_dirModel
);
132 m_controller
= new DolphinController(this);
133 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
134 this, SLOT(openContextMenu(const QPoint
&)));
135 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
136 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
137 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
138 this, SLOT(updateSorting(DolphinView::Sorting
)));
139 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
140 this, SLOT(updateSortOrder(Qt::SortOrder
)));
141 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
142 this, SLOT(triggerItem(const QModelIndex
&)));
143 connect(m_controller
, SIGNAL(selectionChanged()),
144 this, SLOT(emitSelectionChangedSignal()));
145 connect(m_controller
, SIGNAL(activated()),
146 this, SLOT(requestActivation()));
150 m_iconSize
= K3Icon::SizeMedium
;
152 m_filterBar
= new FilterBar(this);
154 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
155 this, SLOT(changeNameFilter(const QString
&)));
156 connect(m_filterBar
, SIGNAL(closeRequest()),
157 this, SLOT(closeFilterBar()));
159 m_topLayout
->addWidget(m_urlNavigator
);
160 m_topLayout
->addWidget(itemView());
161 m_topLayout
->addWidget(m_filterBar
);
162 m_topLayout
->addWidget(m_statusBar
);
164 loadDirectory(m_urlNavigator
->url());
167 DolphinView::~DolphinView()
173 void DolphinView::setUrl(const KUrl
& url
)
175 m_urlNavigator
->setUrl(url
);
176 m_controller
->setUrl(url
);
179 const KUrl
& DolphinView::url() const
181 return m_urlNavigator
->url();
184 bool DolphinView::isActive() const
186 return m_mainWindow
->activeView() == this;
189 void DolphinView::setMode(Mode mode
)
191 if (mode
== m_mode
) {
192 return; // the wished mode is already set
197 ViewProperties
props(m_urlNavigator
->url());
198 props
.setViewMode(m_mode
);
201 startDirLister(m_urlNavigator
->url());
206 DolphinView::Mode
DolphinView::mode() const
211 void DolphinView::setShowPreview(bool show
)
213 ViewProperties
props(m_urlNavigator
->url());
214 props
.setShowPreview(show
);
216 m_controller
->setShowPreview(show
);
218 emit
showPreviewChanged();
222 bool DolphinView::showPreview() const
224 return m_controller
->showPreview();
227 void DolphinView::setShowHiddenFiles(bool show
)
229 if (m_dirLister
->showingDotFiles() == show
) {
233 ViewProperties
props(m_urlNavigator
->url());
234 props
.setShowHiddenFiles(show
);
237 m_dirLister
->setShowingDotFiles(show
);
238 m_urlNavigator
->setShowHiddenFiles(show
);
240 emit
showHiddenFilesChanged();
245 bool DolphinView::showHiddenFiles() const
247 return m_dirLister
->showingDotFiles();
250 void DolphinView::renameSelectedItems()
252 DolphinView
* view
= mainWindow()->activeView();
253 const KUrl::List urls
= selectedUrls();
254 if (urls
.count() > 1) {
255 // More than one item has been selected for renaming. Open
256 // a rename dialog and rename all items afterwards.
257 RenameDialog
dialog(urls
);
258 if (dialog
.exec() == QDialog::Rejected
) {
262 const QString
& newName
= dialog
.newName();
263 if (newName
.isEmpty()) {
264 view
->statusBar()->setMessage(dialog
.errorString(),
265 DolphinStatusBar::Error
);
268 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
269 // as one operation instead of n rename operations like it is done now...
270 Q_ASSERT(newName
.contains('#'));
272 // iterate through all selected items and rename them...
273 const int replaceIndex
= newName
.indexOf('#');
274 Q_ASSERT(replaceIndex
>= 0);
277 KUrl::List::const_iterator it
= urls
.begin();
278 KUrl::List::const_iterator end
= urls
.end();
280 const KUrl
& oldUrl
= *it
;
282 number
.setNum(index
++);
284 QString
name(newName
);
285 name
.replace(replaceIndex
, 1, number
);
287 if (oldUrl
.fileName() != name
) {
288 KUrl
newUrl(oldUrl
.upUrl());
289 newUrl
.addPath(name
);
290 m_mainWindow
->rename(oldUrl
, newUrl
);
297 // Only one item has been selected for renaming. Use the custom
298 // renaming mechanism from the views.
299 Q_ASSERT(urls
.count() == 1);
301 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
302 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
303 // is a benefit for the user at all -> let's wait for some input first...
304 RenameDialog
dialog(urls
);
305 if (dialog
.exec() == QDialog::Rejected
) {
309 const QString
& newName
= dialog
.newName();
310 if (newName
.isEmpty()) {
311 view
->statusBar()->setMessage(dialog
.errorString(),
312 DolphinStatusBar::Error
);
315 const KUrl
& oldUrl
= urls
.first();
316 KUrl newUrl
= oldUrl
.upUrl();
317 newUrl
.addPath(newName
);
318 m_mainWindow
->rename(oldUrl
, newUrl
);
323 void DolphinView::selectAll()
325 selectAll(QItemSelectionModel::Select
);
328 void DolphinView::invertSelection()
330 selectAll(QItemSelectionModel::Toggle
);
333 DolphinStatusBar
* DolphinView::statusBar() const
338 int DolphinView::contentsX() const
341 return itemView()->horizontalScrollBar()->value();
344 int DolphinView::contentsY() const
346 return itemView()->verticalScrollBar()->value();
349 void DolphinView::refreshSettings()
351 startDirLister(m_urlNavigator
->url());
354 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
356 emit
requestItemInfo(url
);
359 bool DolphinView::isFilterBarVisible() const
361 return m_filterBar
->isVisible();
364 bool DolphinView::isUrlEditable() const
366 return m_urlNavigator
->isUrlEditable();
369 void DolphinView::zoomIn()
371 m_controller
->triggerZoomIn();
374 void DolphinView::zoomOut()
376 m_controller
->triggerZoomOut();
379 bool DolphinView::isZoomInPossible() const
381 return m_controller
->isZoomInPossible();
384 bool DolphinView::isZoomOutPossible() const
386 return m_controller
->isZoomOutPossible();
389 void DolphinView::setSorting(Sorting sorting
)
391 if (sorting
!= this->sorting()) {
392 updateSorting(sorting
);
396 DolphinView::Sorting
DolphinView::sorting() const
398 return m_proxyModel
->sorting();
401 void DolphinView::setSortOrder(Qt::SortOrder order
)
403 if (sortOrder() != order
) {
404 updateSortOrder(order
);
408 Qt::SortOrder
DolphinView::sortOrder() const
410 return m_proxyModel
->sortOrder();
413 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
415 ViewProperties
props(m_urlNavigator
->url());
416 props
.setAdditionalInfo(info
);
418 m_fileItemDelegate
->setAdditionalInformation(info
);
420 emit
additionalInfoChanged(info
);
424 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
426 return m_fileItemDelegate
->additionalInformation();
429 void DolphinView::goBack()
431 m_urlNavigator
->goBack();
434 void DolphinView::goForward()
436 m_urlNavigator
->goForward();
439 void DolphinView::goUp()
441 m_urlNavigator
->goUp();
444 void DolphinView::goHome()
446 m_urlNavigator
->goHome();
449 void DolphinView::setUrlEditable(bool editable
)
451 m_urlNavigator
->editUrl(editable
);
454 const QLinkedList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
456 return m_urlNavigator
->history(index
);
459 bool DolphinView::hasSelection() const
461 return itemView()->selectionModel()->hasSelection();
464 void DolphinView::clearSelection()
466 itemView()->selectionModel()->clear();
469 KFileItemList
DolphinView::selectedItems() const
471 const QAbstractItemView
* view
= itemView();
473 // Our view has a selection, we will map them back to the DirModel
474 // and then fill the KFileItemList.
475 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
477 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
478 KFileItemList itemList
;
480 const QModelIndexList indexList
= selection
.indexes();
481 QModelIndexList::const_iterator end
= indexList
.end();
482 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
483 Q_ASSERT((*it
).isValid());
485 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
487 itemList
.append(item
);
494 KUrl::List
DolphinView::selectedUrls() const
498 const KFileItemList list
= selectedItems();
499 KFileItemList::const_iterator it
= list
.begin();
500 const KFileItemList::const_iterator end
= list
.end();
502 KFileItem
* item
= *it
;
503 urls
.append(item
->url());
510 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
512 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
513 return m_dirModel
->itemForIndex(dirModelIndex
);
516 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
520 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
524 KUrl
dest(source
.upUrl());
525 dest
.addPath(newName
);
527 const bool destExists
= KIO::NetAccess::exists(dest
,
529 mainWindow()->activeView());
531 // the destination already exists, hence ask the user
533 KIO::RenameDialog
renameDialog(this,
534 i18n("File Already Exists"),
538 switch (renameDialog
.exec()) {
539 case KIO::R_OVERWRITE
:
540 // the destination should be overwritten
541 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
544 case KIO::R_RENAME
: {
545 // a new name for the destination has been used
546 KUrl
newDest(renameDialog
.newDestUrl());
547 ok
= KIO::NetAccess::file_move(source
, newDest
);
552 // the renaming operation has been canceled
558 // no destination exists, hence just move the file to
560 ok
= KIO::NetAccess::file_move(source
, dest
);
563 const QString destFileName
= dest
.fileName();
565 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
566 DolphinStatusBar::OperationCompleted
);
568 KonqOperations::rename(this, source
, destFileName
);
571 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
572 DolphinStatusBar::Error
);
577 void DolphinView::reload()
579 startDirLister(m_urlNavigator
->url(), true);
582 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
584 QWidget::mouseReleaseEvent(event
);
585 mainWindow()->setActiveView(this);
588 DolphinMainWindow
* DolphinView::mainWindow() const
593 void DolphinView::loadDirectory(const KUrl
& url
)
595 const ViewProperties
props(url
);
597 const Mode mode
= props
.viewMode();
598 if (m_mode
!= mode
) {
604 const bool showHiddenFiles
= props
.showHiddenFiles();
605 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
606 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
607 emit
showHiddenFilesChanged();
610 const DolphinView::Sorting sorting
= props
.sorting();
611 if (sorting
!= m_proxyModel
->sorting()) {
612 m_proxyModel
->setSorting(sorting
);
613 emit
sortingChanged(sorting
);
616 const Qt::SortOrder sortOrder
= props
.sortOrder();
617 if (sortOrder
!= m_proxyModel
->sortOrder()) {
618 m_proxyModel
->setSortOrder(sortOrder
);
619 emit
sortOrderChanged(sortOrder
);
622 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
623 if (info
!= m_fileItemDelegate
->additionalInformation()) {
624 m_fileItemDelegate
->setAdditionalInformation(info
);
626 emit
additionalInfoChanged(info
);
629 const bool showPreview
= props
.showPreview();
630 if (showPreview
!= m_controller
->showPreview()) {
631 m_controller
->setShowPreview(showPreview
);
632 emit
showPreviewChanged();
636 emit
urlChanged(url
);
638 m_statusBar
->clear();
641 void DolphinView::triggerItem(const QModelIndex
& index
)
643 if (!isValidNameIndex(index
)) {
647 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
648 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
649 // items are selected by the user, hence don't trigger the
650 // item specified by 'index'
654 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
659 // Prefer the local path over the URL. This assures that the
660 // volume space information is correct. Assuming that the URL is media:/sda1,
661 // and the local path is /windows/C: For the URL the space info is related
662 // to the root partition (and hence wrong) and for the local path the space
663 // info is related to the windows partition (-> correct).
664 const QString
localPath(item
->localPath());
666 if (localPath
.isEmpty()) {
676 else if (item
->isFile()) {
677 // allow to browse through ZIP and tar files
678 KMimeType::Ptr mime
= item
->mimeTypePtr();
679 if (mime
->is("application/x-zip")) {
680 url
.setProtocol("zip");
683 else if (mime
->is("application/x-tar") ||
684 mime
->is("application/x-tarz") ||
685 mime
->is("application/x-tbz") ||
686 mime
->is("application/x-tgz") ||
687 mime
->is("application/x-tzo")) {
688 url
.setProtocol("tar");
700 void DolphinView::updateProgress(int percent
)
702 if (m_showProgress
) {
703 m_statusBar
->setProgress(percent
);
707 void DolphinView::updateItemCount()
709 if (m_showProgress
) {
710 m_statusBar
->setProgressText(QString());
711 m_statusBar
->setProgress(100);
712 m_showProgress
= false;
715 KFileItemList
items(m_dirLister
->items());
716 KFileItemList::const_iterator it
= items
.begin();
717 const KFileItemList::const_iterator end
= items
.end();
723 KFileItem
* item
= *it
;
735 m_blockContentsMovedSignal
= false;
736 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
739 void DolphinView::generatePreviews(const KFileItemList
& items
)
741 if (m_controller
->showPreview()) {
742 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
743 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
744 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
748 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
751 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
752 if (idx
.isValid() && (idx
.column() == 0)) {
753 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
754 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(*item
)) {
755 KIconEffect iconEffect
;
756 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
757 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
760 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
765 void DolphinView::restoreContentsPos()
768 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
769 if (!history
.isEmpty()) {
770 QAbstractItemView
* view
= itemView();
771 // TODO: view->setCurrentItem(history[index].currentFileName());
773 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
775 view
->horizontalScrollBar()->setValue((*it
).contentsX());
776 view
->verticalScrollBar()->setValue((*it
).contentsY());
780 void DolphinView::showInfoMessage(const QString
& msg
)
782 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
785 void DolphinView::showErrorMessage(const QString
& msg
)
787 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
790 void DolphinView::emitSelectionChangedSignal()
792 emit
selectionChanged();
795 void DolphinView::closeFilterBar()
798 emit
showFilterBarChanged(false);
801 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
803 if (!url
.isValid()) {
804 const QString
location(url
.pathOrUrl());
805 if (location
.isEmpty()) {
806 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
809 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
810 DolphinStatusBar::Error
);
815 // Only show the directory loading progress if the status bar does
816 // not contain another progress information. This means that
817 // the directory loading progress information has the lowest priority.
818 const QString
progressText(m_statusBar
->progressText());
819 m_showProgress
= progressText
.isEmpty() ||
820 (progressText
== i18n("Loading directory..."));
821 if (m_showProgress
) {
822 m_statusBar
->setProgressText(i18n("Loading directory..."));
823 m_statusBar
->setProgress(0);
826 m_blockContentsMovedSignal
= true;
828 m_dirLister
->openUrl(url
, false, reload
);
831 QString
DolphinView::defaultStatusBarText() const
833 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
839 QString
DolphinView::selectionStatusBarText() const
842 const KFileItemList list
= selectedItems();
843 if (list
.isEmpty()) {
844 // when an item is triggered, it is temporary selected but selectedItems()
845 // will return an empty list
851 KIO::filesize_t byteSize
= 0;
852 KFileItemList::const_iterator it
= list
.begin();
853 const KFileItemList::const_iterator end
= list
.end();
855 KFileItem
* item
= *it
;
861 byteSize
+= item
->size();
866 if (folderCount
> 0) {
867 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
874 const QString
sizeText(KIO::convertSize(byteSize
));
875 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
881 void DolphinView::showFilterBar(bool show
)
883 Q_ASSERT(m_filterBar
!= 0);
892 void DolphinView::updateStatusBar()
894 // As the item count information is less important
895 // in comparison with other messages, it should only
897 // - the status bar is empty or
898 // - shows already the item count information or
899 // - shows only a not very important information
900 // - if any progress is given don't show the item count info at all
901 const QString
msg(m_statusBar
->message());
902 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
903 (msg
== m_statusBar
->defaultText()) ||
904 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
905 (m_statusBar
->progress() == 100);
907 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
908 m_statusBar
->setDefaultText(text
);
910 if (updateStatusBarMsg
) {
911 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
915 void DolphinView::requestActivation()
917 m_mainWindow
->setActiveView(this);
920 void DolphinView::updateCutItems()
922 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
923 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
927 KFileItemList
items(m_dirLister
->items());
928 KFileItemList::const_iterator it
= items
.begin();
929 const KFileItemList::const_iterator end
= items
.end();
931 KFileItem
* item
= *it
;
932 if (isCutItem(*item
)) {
933 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
934 const QVariant value
= m_dirModel
->data(idx
, Qt::DecorationRole
);
935 if (value
.type() == QVariant::Icon
) {
936 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
937 KIconEffect iconEffect
;
938 const QPixmap pixmap
= iconEffect
.apply(icon
.pixmap(128, 128),
940 K3Icon::DisabledState
);
941 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
948 void DolphinView::changeNameFilter(const QString
& nameFilter
)
950 // The name filter of KDirLister does a 'hard' filtering, which
951 // means that only the items are shown where the names match
952 // exactly the filter. This is non-transparent for the user, which
953 // just wants to have a 'soft' filtering: does the name contain
954 // the filter string?
955 QString
adjustedFilter(nameFilter
);
956 adjustedFilter
.insert(0, '*');
957 adjustedFilter
.append('*');
959 // Use the ProxyModel to filter:
960 // This code is #ifdefed as setNameFilter behaves
961 // slightly different than the QSortFilterProxyModel
962 // as it will not remove directories. I will ask
963 // our beloved usability experts for input
966 m_dirLister
->setNameFilter(adjustedFilter
);
967 m_dirLister
->emitChanges();
969 m_proxyModel
->setFilterRegExp( nameFilter
);
973 void DolphinView::openContextMenu(const QPoint
& pos
)
977 const QModelIndex index
= itemView()->indexAt(pos
);
978 if (isValidNameIndex(index
)) {
979 item
= fileItem(index
);
982 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url());
986 void DolphinView::dropUrls(const KUrl::List
& urls
,
987 const QModelIndex
& index
,
990 KFileItem
* directory
= 0;
991 if (isValidNameIndex(index
)) {
992 KFileItem
* item
= fileItem(index
);
995 // the URLs are dropped above a directory
1000 if ((directory
== 0) && (source
== itemView())) {
1001 // The dropping is done into the same viewport where
1002 // the dragging has been started. Just ignore this...
1006 const KUrl
& destination
= (directory
== 0) ? url() :
1009 dropUrls(urls
, destination
);
1012 void DolphinView::dropUrls(const KUrl::List
& urls
,
1013 const KUrl
& destination
)
1015 m_mainWindow
->dropUrls(urls
, destination
);
1019 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
1021 ViewProperties
props(url());
1022 props
.setSorting(sorting
);
1024 m_proxyModel
->setSorting(sorting
);
1026 emit
sortingChanged(sorting
);
1029 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1031 ViewProperties
props(url());
1032 props
.setSortOrder(order
);
1034 m_proxyModel
->setSortOrder(order
);
1036 emit
sortOrderChanged(order
);
1039 void DolphinView::emitContentsMoved()
1041 if (!m_blockContentsMovedSignal
) {
1042 emit
contentsMoved(contentsX(), contentsY());
1046 void DolphinView::updateActivationState()
1048 m_urlNavigator
->setActive(isActive());
1051 void DolphinView::createView()
1053 // delete current view
1054 QAbstractItemView
* view
= itemView();
1056 m_topLayout
->removeWidget(view
);
1058 view
->deleteLater();
1062 m_fileItemDelegate
= 0;
1065 Q_ASSERT(m_iconsView
== 0);
1066 Q_ASSERT(m_detailsView
== 0);
1068 // ... and recreate it representing the current mode
1071 m_iconsView
= new DolphinIconsView(this, m_controller
);
1076 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1077 view
= m_detailsView
;
1081 Q_ASSERT(view
!= 0);
1083 m_fileItemDelegate
= new KFileItemDelegate(view
);
1084 view
->setItemDelegate(m_fileItemDelegate
);
1086 view
->setModel(m_proxyModel
);
1087 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1089 new KMimeTypeResolver(view
, m_dirModel
);
1090 m_topLayout
->insertWidget(1, view
);
1092 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1093 m_controller
, SLOT(indicateSelectionChange()));
1094 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1095 this, SLOT(emitContentsMoved()));
1096 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1097 this, SLOT(emitContentsMoved()));
1100 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1102 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1103 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1105 const QModelIndex topLeft
= itemModel
->index(0, 0);
1106 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1107 itemModel
->columnCount() - 1);
1109 QItemSelection
selection(topLeft
, bottomRight
);
1110 selectionModel
->select(selection
, flags
);
1113 QAbstractItemView
* DolphinView::itemView() const
1115 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1116 if (m_detailsView
!= 0) {
1117 return m_detailsView
;
1122 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1124 return index
.isValid() && (index
.column() == KDirModel::Name
);
1127 bool DolphinView::isCutItem(const KFileItem
& item
) const
1129 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1130 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1132 const KUrl
& itemUrl
= item
.url();
1133 KUrl::List::const_iterator it
= cutUrls
.begin();
1134 const KUrl::List::const_iterator end
= cutUrls
.end();
1136 if (*it
== itemUrl
) {
1145 #include "dolphinview.moc"