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 "dolphincolumnview.h"
43 #include "dolphincontroller.h"
44 #include "dolphinstatusbar.h"
45 #include "dolphinmainwindow.h"
46 #include "dolphindirlister.h"
47 #include "dolphinsortfilterproxymodel.h"
48 #include "dolphindetailsview.h"
49 #include "dolphiniconsview.h"
50 #include "dolphincontextmenu.h"
51 #include "filterbar.h"
52 #include "renamedialog.h"
53 #include "urlnavigator.h"
54 #include "viewproperties.h"
55 #include "dolphinsettings.h"
57 DolphinView::DolphinView(DolphinMainWindow
* mainWindow
,
61 bool showHiddenFiles
) :
63 m_showProgress(false),
64 m_blockContentsMovedSignal(false),
69 m_mainWindow(mainWindow
),
76 m_fileItemDelegate(0),
84 setFocusPolicy(Qt::StrongFocus
);
85 m_topLayout
= new QVBoxLayout(this);
86 m_topLayout
->setSpacing(0);
87 m_topLayout
->setMargin(0);
89 connect(m_mainWindow
, SIGNAL(activeViewChanged()),
90 this, SLOT(updateActivationState()));
92 QClipboard
* clipboard
= QApplication::clipboard();
93 connect(clipboard
, SIGNAL(dataChanged()),
94 this, SLOT(updateCutItems()));
96 m_urlNavigator
= new UrlNavigator(DolphinSettings::instance().bookmarkManager(), url
, this);
97 m_urlNavigator
->setShowHiddenFiles(showHiddenFiles
);
98 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
99 this, SLOT(loadDirectory(const KUrl
&)));
100 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
101 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
102 connect(m_urlNavigator
, SIGNAL(activated()),
103 this, SLOT(requestActivation()));
104 connect(this, SIGNAL(contentsMoved(int, int)),
105 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
107 m_statusBar
= new DolphinStatusBar(this);
109 m_dirLister
= new DolphinDirLister();
110 m_dirLister
->setAutoUpdate(true);
111 m_dirLister
->setMainWindow(this);
112 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
113 m_dirLister
->setDelayedMimeTypes(true);
115 connect(m_dirLister
, SIGNAL(clear()),
116 this, SLOT(updateStatusBar()));
117 connect(m_dirLister
, SIGNAL(percent(int)),
118 this, SLOT(updateProgress(int)));
119 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
120 this, SLOT(updateStatusBar()));
121 connect(m_dirLister
, SIGNAL(completed()),
122 this, SLOT(updateItemCount()));
123 connect(m_dirLister
, SIGNAL(completed()),
124 this, SLOT(updateCutItems()));
125 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
126 this, SLOT(generatePreviews(const KFileItemList
&)));
127 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
128 this, SLOT(showInfoMessage(const QString
&)));
129 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
130 this, SLOT(showErrorMessage(const QString
&)));
132 m_dirModel
= new KDirModel();
133 m_dirModel
->setDirLister(m_dirLister
);
134 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
136 m_proxyModel
= new DolphinSortFilterProxyModel(this);
137 m_proxyModel
->setSourceModel(m_dirModel
);
139 m_controller
= new DolphinController(this);
140 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
141 this, SLOT(openContextMenu(const QPoint
&)));
142 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
143 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
144 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
145 this, SLOT(updateSorting(DolphinView::Sorting
)));
146 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
147 this, SLOT(updateSortOrder(Qt::SortOrder
)));
148 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
149 this, SLOT(triggerItem(const QModelIndex
&)));
150 connect(m_controller
, SIGNAL(selectionChanged()),
151 this, SLOT(emitSelectionChangedSignal()));
152 connect(m_controller
, SIGNAL(activated()),
153 this, SLOT(requestActivation()));
157 m_iconSize
= K3Icon::SizeMedium
;
159 m_filterBar
= new FilterBar(this);
161 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
162 this, SLOT(changeNameFilter(const QString
&)));
163 connect(m_filterBar
, SIGNAL(closeRequest()),
164 this, SLOT(closeFilterBar()));
166 m_topLayout
->addWidget(m_urlNavigator
);
167 m_topLayout
->addWidget(itemView());
168 m_topLayout
->addWidget(m_filterBar
);
169 m_topLayout
->addWidget(m_statusBar
);
172 DolphinView::~DolphinView()
178 void DolphinView::setUrl(const KUrl
& url
)
180 m_urlNavigator
->setUrl(url
);
181 m_controller
->setUrl(url
);
184 const KUrl
& DolphinView::url() const
186 return m_urlNavigator
->url();
189 bool DolphinView::isActive() const
191 return m_mainWindow
->activeView() == this;
194 void DolphinView::setMode(Mode mode
)
196 if (mode
== m_mode
) {
197 return; // the wished mode is already set
202 ViewProperties
props(m_urlNavigator
->url());
203 props
.setViewMode(m_mode
);
206 startDirLister(m_urlNavigator
->url());
211 DolphinView::Mode
DolphinView::mode() const
216 void DolphinView::setShowPreview(bool show
)
218 ViewProperties
props(m_urlNavigator
->url());
219 props
.setShowPreview(show
);
221 m_controller
->setShowPreview(show
);
223 emit
showPreviewChanged();
227 bool DolphinView::showPreview() const
229 return m_controller
->showPreview();
232 void DolphinView::setShowHiddenFiles(bool show
)
234 if (m_dirLister
->showingDotFiles() == show
) {
238 ViewProperties
props(m_urlNavigator
->url());
239 props
.setShowHiddenFiles(show
);
242 m_dirLister
->setShowingDotFiles(show
);
243 m_urlNavigator
->setShowHiddenFiles(show
);
245 emit
showHiddenFilesChanged();
250 bool DolphinView::showHiddenFiles() const
252 return m_dirLister
->showingDotFiles();
255 void DolphinView::renameSelectedItems()
257 DolphinView
* view
= mainWindow()->activeView();
258 const KUrl::List urls
= selectedUrls();
259 if (urls
.count() > 1) {
260 // More than one item has been selected for renaming. Open
261 // a rename dialog and rename all items afterwards.
262 RenameDialog
dialog(urls
);
263 if (dialog
.exec() == QDialog::Rejected
) {
267 const QString
& newName
= dialog
.newName();
268 if (newName
.isEmpty()) {
269 view
->statusBar()->setMessage(dialog
.errorString(),
270 DolphinStatusBar::Error
);
273 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
274 // as one operation instead of n rename operations like it is done now...
275 Q_ASSERT(newName
.contains('#'));
277 // iterate through all selected items and rename them...
278 const int replaceIndex
= newName
.indexOf('#');
279 Q_ASSERT(replaceIndex
>= 0);
282 KUrl::List::const_iterator it
= urls
.begin();
283 KUrl::List::const_iterator end
= urls
.end();
285 const KUrl
& oldUrl
= *it
;
287 number
.setNum(index
++);
289 QString
name(newName
);
290 name
.replace(replaceIndex
, 1, number
);
292 if (oldUrl
.fileName() != name
) {
293 KUrl
newUrl(oldUrl
.upUrl());
294 newUrl
.addPath(name
);
295 m_mainWindow
->rename(oldUrl
, newUrl
);
302 // Only one item has been selected for renaming. Use the custom
303 // renaming mechanism from the views.
304 Q_ASSERT(urls
.count() == 1);
306 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
307 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
308 // is a benefit for the user at all -> let's wait for some input first...
309 RenameDialog
dialog(urls
);
310 if (dialog
.exec() == QDialog::Rejected
) {
314 const QString
& newName
= dialog
.newName();
315 if (newName
.isEmpty()) {
316 view
->statusBar()->setMessage(dialog
.errorString(),
317 DolphinStatusBar::Error
);
320 const KUrl
& oldUrl
= urls
.first();
321 KUrl newUrl
= oldUrl
.upUrl();
322 newUrl
.addPath(newName
);
323 m_mainWindow
->rename(oldUrl
, newUrl
);
328 void DolphinView::selectAll()
330 selectAll(QItemSelectionModel::Select
);
333 void DolphinView::invertSelection()
335 selectAll(QItemSelectionModel::Toggle
);
338 DolphinStatusBar
* DolphinView::statusBar() const
343 int DolphinView::contentsX() const
346 return itemView()->horizontalScrollBar()->value();
349 int DolphinView::contentsY() const
351 return itemView()->verticalScrollBar()->value();
354 void DolphinView::refreshSettings()
356 startDirLister(m_urlNavigator
->url());
359 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
361 emit
requestItemInfo(url
);
364 bool DolphinView::isFilterBarVisible() const
366 return m_filterBar
->isVisible();
369 bool DolphinView::isUrlEditable() const
371 return m_urlNavigator
->isUrlEditable();
374 void DolphinView::zoomIn()
376 m_controller
->triggerZoomIn();
379 void DolphinView::zoomOut()
381 m_controller
->triggerZoomOut();
384 bool DolphinView::isZoomInPossible() const
386 return m_controller
->isZoomInPossible();
389 bool DolphinView::isZoomOutPossible() const
391 return m_controller
->isZoomOutPossible();
394 void DolphinView::setSorting(Sorting sorting
)
396 if (sorting
!= this->sorting()) {
397 updateSorting(sorting
);
401 DolphinView::Sorting
DolphinView::sorting() const
403 return m_proxyModel
->sorting();
406 void DolphinView::setSortOrder(Qt::SortOrder order
)
408 if (sortOrder() != order
) {
409 updateSortOrder(order
);
413 Qt::SortOrder
DolphinView::sortOrder() const
415 return m_proxyModel
->sortOrder();
418 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
420 ViewProperties
props(m_urlNavigator
->url());
421 props
.setAdditionalInfo(info
);
423 m_fileItemDelegate
->setAdditionalInformation(info
);
425 emit
additionalInfoChanged(info
);
429 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
431 return m_fileItemDelegate
->additionalInformation();
434 void DolphinView::goBack()
436 m_urlNavigator
->goBack();
439 void DolphinView::goForward()
441 m_urlNavigator
->goForward();
444 void DolphinView::goUp()
446 m_urlNavigator
->goUp();
449 void DolphinView::goHome()
451 m_urlNavigator
->goHome();
454 void DolphinView::setUrlEditable(bool editable
)
456 m_urlNavigator
->editUrl(editable
);
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
)
599 const ViewProperties
props(url
);
601 const Mode mode
= props
.viewMode();
602 bool changeMode
= (m_mode
!= mode
);
603 if (changeMode
&& isColumnViewActive()) {
604 // The column view is active. Only change the
605 // mode if the current URL is no child of the column view.
606 if (m_dirLister
->url().isParentOf(url
)) {
617 const bool showHiddenFiles
= props
.showHiddenFiles();
618 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
619 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
620 emit
showHiddenFilesChanged();
623 const DolphinView::Sorting sorting
= props
.sorting();
624 if (sorting
!= m_proxyModel
->sorting()) {
625 m_proxyModel
->setSorting(sorting
);
626 emit
sortingChanged(sorting
);
629 const Qt::SortOrder sortOrder
= props
.sortOrder();
630 if (sortOrder
!= m_proxyModel
->sortOrder()) {
631 m_proxyModel
->setSortOrder(sortOrder
);
632 emit
sortOrderChanged(sortOrder
);
635 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
636 if (info
!= m_fileItemDelegate
->additionalInformation()) {
637 m_fileItemDelegate
->setAdditionalInformation(info
);
639 emit
additionalInfoChanged(info
);
642 const bool showPreview
= props
.showPreview();
643 if (showPreview
!= m_controller
->showPreview()) {
644 m_controller
->setShowPreview(showPreview
);
645 emit
showPreviewChanged();
649 emit
urlChanged(url
);
651 m_statusBar
->clear();
654 void DolphinView::triggerItem(const QModelIndex
& index
)
656 if (!isValidNameIndex(index
)) {
660 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
661 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
662 // items are selected by the user, hence don't trigger the
663 // item specified by 'index'
667 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
672 // Prefer the local path over the URL. This assures that the
673 // volume space information is correct. Assuming that the URL is media:/sda1,
674 // and the local path is /windows/C: For the URL the space info is related
675 // to the root partition (and hence wrong) and for the local path the space
676 // info is related to the windows partition (-> correct).
677 const QString
localPath(item
->localPath());
679 if (localPath
.isEmpty()) {
689 else if (item
->isFile()) {
690 // allow to browse through ZIP and tar files
691 KMimeType::Ptr mime
= item
->mimeTypePtr();
692 if (mime
->is("application/zip")) {
693 url
.setProtocol("zip");
696 else if (mime
->is("application/x-tar") ||
697 mime
->is("application/x-tarz") ||
698 mime
->is("application/x-bzip-compressed-tar") ||
699 mime
->is("application/x-compressed-tar") ||
700 mime
->is("application/x-tzo")) {
701 url
.setProtocol("tar");
713 void DolphinView::updateProgress(int percent
)
715 if (m_showProgress
) {
716 m_statusBar
->setProgress(percent
);
720 void DolphinView::updateItemCount()
722 if (m_showProgress
) {
723 m_statusBar
->setProgressText(QString());
724 m_statusBar
->setProgress(100);
725 m_showProgress
= false;
728 KFileItemList
items(m_dirLister
->items());
729 KFileItemList::const_iterator it
= items
.begin();
730 const KFileItemList::const_iterator end
= items
.end();
736 KFileItem
* item
= *it
;
748 m_blockContentsMovedSignal
= false;
749 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
752 void DolphinView::generatePreviews(const KFileItemList
& items
)
754 if (m_controller
->showPreview()) {
755 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
756 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
757 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
761 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
764 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
765 if (idx
.isValid() && (idx
.column() == 0)) {
766 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
767 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(*item
)) {
768 KIconEffect iconEffect
;
769 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
770 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
773 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
778 void DolphinView::restoreContentsPos()
780 UrlNavigator::HistoryElem historyItem
= m_urlNavigator
->currentHistoryItem();
781 if (!historyItem
.url().isEmpty()) {
782 QAbstractItemView
* view
= itemView();
783 // TODO: view->setCurrentItem(historyItem.currentFileName());
784 view
->horizontalScrollBar()->setValue(historyItem
.contentsX());
785 view
->verticalScrollBar()->setValue(historyItem
.contentsY());
789 void DolphinView::showInfoMessage(const QString
& msg
)
791 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
794 void DolphinView::showErrorMessage(const QString
& msg
)
796 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
799 void DolphinView::emitSelectionChangedSignal()
801 emit
selectionChanged(DolphinView::selectedItems());
804 void DolphinView::closeFilterBar()
807 emit
showFilterBarChanged(false);
810 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
812 if (!url
.isValid()) {
813 const QString
location(url
.pathOrUrl());
814 if (location
.isEmpty()) {
815 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
818 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
819 DolphinStatusBar::Error
);
824 // Only show the directory loading progress if the status bar does
825 // not contain another progress information. This means that
826 // the directory loading progress information has the lowest priority.
827 const QString
progressText(m_statusBar
->progressText());
828 m_showProgress
= progressText
.isEmpty() ||
829 (progressText
== i18n("Loading directory..."));
830 if (m_showProgress
) {
831 m_statusBar
->setProgressText(i18n("Loading directory..."));
832 m_statusBar
->setProgress(0);
835 m_cutItemsCache
.clear();
836 m_blockContentsMovedSignal
= true;
839 bool keepOldDirs
= isColumnViewActive();
840 if (keepOldDirs
&& !m_dirLister
->url().isParentOf(url
)) {
841 // The current URL is not a child of the dir lister
842 // URL. This may happen when e. g. a bookmark has been selected
843 // and hence the view must be reset.
846 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
849 QString
DolphinView::defaultStatusBarText() const
851 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
857 QString
DolphinView::selectionStatusBarText() const
860 const KFileItemList list
= selectedItems();
861 if (list
.isEmpty()) {
862 // when an item is triggered, it is temporary selected but selectedItems()
863 // will return an empty list
869 KIO::filesize_t byteSize
= 0;
870 KFileItemList::const_iterator it
= list
.begin();
871 const KFileItemList::const_iterator end
= list
.end();
873 KFileItem
* item
= *it
;
879 byteSize
+= item
->size();
884 if (folderCount
> 0) {
885 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
892 const QString
sizeText(KIO::convertSize(byteSize
));
893 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
899 void DolphinView::showFilterBar(bool show
)
901 Q_ASSERT(m_filterBar
!= 0);
910 void DolphinView::updateStatusBar()
912 // As the item count information is less important
913 // in comparison with other messages, it should only
915 // - the status bar is empty or
916 // - shows already the item count information or
917 // - shows only a not very important information
918 // - if any progress is given don't show the item count info at all
919 const QString
msg(m_statusBar
->message());
920 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
921 (msg
== m_statusBar
->defaultText()) ||
922 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
923 (m_statusBar
->progress() == 100);
925 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
926 m_statusBar
->setDefaultText(text
);
928 if (updateStatusBarMsg
) {
929 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
933 void DolphinView::requestActivation()
935 m_mainWindow
->setActiveView(this);
938 void DolphinView::changeSelection(const KFileItemList
& selection
)
941 if (selection
.isEmpty()) {
944 KUrl baseUrl
= url();
946 QItemSelection new_selection
;
947 foreach (KFileItem
* item
, selection
) {
948 url
= item
->url().upUrl();
949 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
950 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
951 new_selection
.select(index
, index
);
954 itemView()->selectionModel()->select(new_selection
,
955 QItemSelectionModel::ClearAndSelect
956 | QItemSelectionModel::Current
);
959 void DolphinView::changeNameFilter(const QString
& nameFilter
)
961 // The name filter of KDirLister does a 'hard' filtering, which
962 // means that only the items are shown where the names match
963 // exactly the filter. This is non-transparent for the user, which
964 // just wants to have a 'soft' filtering: does the name contain
965 // the filter string?
966 QString
adjustedFilter(nameFilter
);
967 adjustedFilter
.insert(0, '*');
968 adjustedFilter
.append('*');
970 // Use the ProxyModel to filter:
971 // This code is #ifdefed as setNameFilter behaves
972 // slightly different than the QSortFilterProxyModel
973 // as it will not remove directories. I will ask
974 // our beloved usability experts for input
977 m_dirLister
->setNameFilter(adjustedFilter
);
978 m_dirLister
->emitChanges();
980 m_proxyModel
->setFilterRegExp( nameFilter
);
984 void DolphinView::openContextMenu(const QPoint
& pos
)
988 const QModelIndex index
= itemView()->indexAt(pos
);
989 if (isValidNameIndex(index
)) {
990 item
= fileItem(index
);
993 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url());
997 void DolphinView::dropUrls(const KUrl::List
& urls
,
998 const QModelIndex
& index
,
1001 KFileItem
* directory
= 0;
1002 if (isValidNameIndex(index
)) {
1003 KFileItem
* item
= fileItem(index
);
1004 Q_ASSERT(item
!= 0);
1005 if (item
->isDir()) {
1006 // the URLs are dropped above a directory
1011 if ((directory
== 0) && (source
== itemView())) {
1012 // The dropping is done into the same viewport where
1013 // the dragging has been started. Just ignore this...
1017 const KUrl
& destination
= (directory
== 0) ? url() :
1019 dropUrls(urls
, destination
);
1022 void DolphinView::dropUrls(const KUrl::List
& urls
,
1023 const KUrl
& destination
)
1025 m_mainWindow
->dropUrls(urls
, destination
);
1028 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
1030 ViewProperties
props(url());
1031 props
.setSorting(sorting
);
1033 m_proxyModel
->setSorting(sorting
);
1035 emit
sortingChanged(sorting
);
1038 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1040 ViewProperties
props(url());
1041 props
.setSortOrder(order
);
1043 m_proxyModel
->setSortOrder(order
);
1045 emit
sortOrderChanged(order
);
1048 void DolphinView::emitContentsMoved()
1050 if (!m_blockContentsMovedSignal
) {
1051 emit
contentsMoved(contentsX(), contentsY());
1055 void DolphinView::updateActivationState()
1057 m_urlNavigator
->setActive(isActive());
1059 emit
urlChanged(url());
1060 emit
selectionChanged(selectedItems());
1064 void DolphinView::updateCutItems()
1066 // restore the icons of all previously selected items to the
1067 // original state...
1068 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
1069 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
1071 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
1072 if (index
.isValid()) {
1073 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
1077 m_cutItemsCache
.clear();
1079 // ... and apply an item effect to all currently cut items
1080 applyCutItemEffect();
1083 void DolphinView::createView()
1085 // delete current view
1086 QAbstractItemView
* view
= itemView();
1088 m_topLayout
->removeWidget(view
);
1090 view
->deleteLater();
1095 m_fileItemDelegate
= 0;
1098 Q_ASSERT(m_iconsView
== 0);
1099 Q_ASSERT(m_detailsView
== 0);
1100 Q_ASSERT(m_columnView
== 0);
1102 // ... and recreate it representing the current mode
1105 m_iconsView
= new DolphinIconsView(this, m_controller
);
1110 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1111 view
= m_detailsView
;
1115 m_columnView
= new DolphinColumnView(this, m_controller
);
1116 view
= m_columnView
;
1120 Q_ASSERT(view
!= 0);
1122 m_fileItemDelegate
= new KFileItemDelegate(view
);
1123 view
->setItemDelegate(m_fileItemDelegate
);
1125 view
->setModel(m_proxyModel
);
1126 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1128 new KMimeTypeResolver(view
, m_dirModel
);
1129 m_topLayout
->insertWidget(1, view
);
1131 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1132 m_controller
, SLOT(indicateSelectionChange()));
1133 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1134 this, SLOT(emitContentsMoved()));
1135 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1136 this, SLOT(emitContentsMoved()));
1139 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1141 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1142 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1144 const QModelIndex topLeft
= itemModel
->index(0, 0);
1145 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1146 itemModel
->columnCount() - 1);
1148 QItemSelection
selection(topLeft
, bottomRight
);
1149 selectionModel
->select(selection
, flags
);
1152 QAbstractItemView
* DolphinView::itemView() const
1154 if (m_detailsView
!= 0) {
1155 return m_detailsView
;
1157 else if (m_columnView
!= 0) {
1158 return m_columnView
;
1164 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1166 return index
.isValid() && (index
.column() == KDirModel::Name
);
1169 bool DolphinView::isCutItem(const KFileItem
& item
) const
1171 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1172 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1174 const KUrl
& itemUrl
= item
.url();
1175 KUrl::List::const_iterator it
= cutUrls
.begin();
1176 const KUrl::List::const_iterator end
= cutUrls
.end();
1178 if (*it
== itemUrl
) {
1187 void DolphinView::applyCutItemEffect()
1189 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1190 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
1194 KFileItemList
items(m_dirLister
->items());
1195 KFileItemList::const_iterator it
= items
.begin();
1196 const KFileItemList::const_iterator end
= items
.end();
1198 KFileItem
* item
= *it
;
1199 if (isCutItem(*item
)) {
1200 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
1201 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
1202 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
1203 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
1204 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
1205 QPixmap pixmap
= icon
.pixmap(128, 128);
1207 // remember current pixmap for the item to be able
1208 // to restore it when other items get cut
1210 cutItem
.url
= item
->url();
1211 cutItem
.pixmap
= pixmap
;
1212 m_cutItemsCache
.append(cutItem
);
1214 // apply icon effect to the cut item
1215 KIconEffect iconEffect
;
1216 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
1217 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
1224 #include "dolphinview.moc"