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 QClipboard
* clipboard
= QApplication::clipboard();
90 connect(clipboard
, SIGNAL(dataChanged()),
91 this, SLOT(updateCutItems()));
93 m_urlNavigator
= new UrlNavigator(url
, this);
94 m_urlNavigator
->setShowHiddenFiles(showHiddenFiles
);
95 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
96 this, SLOT(loadDirectory(const KUrl
&)));
97 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
98 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
99 connect(m_urlNavigator
, SIGNAL(activated()),
100 this, SLOT(requestActivation()));
101 connect(this, SIGNAL(contentsMoved(int, int)),
102 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
104 m_statusBar
= new DolphinStatusBar(this);
106 m_dirLister
= new DolphinDirLister();
107 m_dirLister
->setAutoUpdate(true);
108 m_dirLister
->setMainWindow(this);
109 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
110 m_dirLister
->setDelayedMimeTypes(true);
112 connect(m_dirLister
, SIGNAL(clear()),
113 this, SLOT(updateStatusBar()));
114 connect(m_dirLister
, SIGNAL(percent(int)),
115 this, SLOT(updateProgress(int)));
116 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
117 this, SLOT(updateStatusBar()));
118 connect(m_dirLister
, SIGNAL(completed()),
119 this, SLOT(updateItemCount()));
120 connect(m_dirLister
, SIGNAL(completed()),
121 this, SLOT(updateCutItems()));
122 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
123 this, SLOT(generatePreviews(const KFileItemList
&)));
124 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
125 this, SLOT(showInfoMessage(const QString
&)));
126 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
127 this, SLOT(showErrorMessage(const QString
&)));
129 m_dirModel
= new KDirModel();
130 m_dirModel
->setDirLister(m_dirLister
);
131 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
133 m_proxyModel
= new DolphinSortFilterProxyModel(this);
134 m_proxyModel
->setSourceModel(m_dirModel
);
136 m_controller
= new DolphinController(this);
137 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
138 this, SLOT(openContextMenu(const QPoint
&)));
139 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
140 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
141 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
142 this, SLOT(updateSorting(DolphinView::Sorting
)));
143 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
144 this, SLOT(updateSortOrder(Qt::SortOrder
)));
145 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
146 this, SLOT(triggerItem(const QModelIndex
&)));
147 connect(m_controller
, SIGNAL(selectionChanged()),
148 this, SLOT(emitSelectionChangedSignal()));
149 connect(m_controller
, SIGNAL(activated()),
150 this, SLOT(requestActivation()));
154 m_iconSize
= K3Icon::SizeMedium
;
156 m_filterBar
= new FilterBar(this);
158 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
159 this, SLOT(changeNameFilter(const QString
&)));
160 connect(m_filterBar
, SIGNAL(closeRequest()),
161 this, SLOT(closeFilterBar()));
163 m_topLayout
->addWidget(m_urlNavigator
);
164 m_topLayout
->addWidget(itemView());
165 m_topLayout
->addWidget(m_filterBar
);
166 m_topLayout
->addWidget(m_statusBar
);
168 loadDirectory(m_urlNavigator
->url());
171 DolphinView::~DolphinView()
177 void DolphinView::setUrl(const KUrl
& url
)
179 m_urlNavigator
->setUrl(url
);
180 m_controller
->setUrl(url
);
183 const KUrl
& DolphinView::url() const
185 return m_urlNavigator
->url();
188 bool DolphinView::isActive() const
190 return m_mainWindow
->activeView() == this;
193 void DolphinView::setMode(Mode mode
)
195 if (mode
== m_mode
) {
196 return; // the wished mode is already set
201 ViewProperties
props(m_urlNavigator
->url());
202 props
.setViewMode(m_mode
);
205 startDirLister(m_urlNavigator
->url());
210 DolphinView::Mode
DolphinView::mode() const
215 void DolphinView::setShowPreview(bool show
)
217 ViewProperties
props(m_urlNavigator
->url());
218 props
.setShowPreview(show
);
220 m_controller
->setShowPreview(show
);
222 emit
showPreviewChanged();
226 bool DolphinView::showPreview() const
228 return m_controller
->showPreview();
231 void DolphinView::setShowHiddenFiles(bool show
)
233 if (m_dirLister
->showingDotFiles() == show
) {
237 ViewProperties
props(m_urlNavigator
->url());
238 props
.setShowHiddenFiles(show
);
241 m_dirLister
->setShowingDotFiles(show
);
242 m_urlNavigator
->setShowHiddenFiles(show
);
244 emit
showHiddenFilesChanged();
249 bool DolphinView::showHiddenFiles() const
251 return m_dirLister
->showingDotFiles();
254 void DolphinView::renameSelectedItems()
256 DolphinView
* view
= mainWindow()->activeView();
257 const KUrl::List urls
= selectedUrls();
258 if (urls
.count() > 1) {
259 // More than one item has been selected for renaming. Open
260 // a rename dialog and rename all items afterwards.
261 RenameDialog
dialog(urls
);
262 if (dialog
.exec() == QDialog::Rejected
) {
266 const QString
& newName
= dialog
.newName();
267 if (newName
.isEmpty()) {
268 view
->statusBar()->setMessage(dialog
.errorString(),
269 DolphinStatusBar::Error
);
272 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
273 // as one operation instead of n rename operations like it is done now...
274 Q_ASSERT(newName
.contains('#'));
276 // iterate through all selected items and rename them...
277 const int replaceIndex
= newName
.indexOf('#');
278 Q_ASSERT(replaceIndex
>= 0);
281 KUrl::List::const_iterator it
= urls
.begin();
282 KUrl::List::const_iterator end
= urls
.end();
284 const KUrl
& oldUrl
= *it
;
286 number
.setNum(index
++);
288 QString
name(newName
);
289 name
.replace(replaceIndex
, 1, number
);
291 if (oldUrl
.fileName() != name
) {
292 KUrl
newUrl(oldUrl
.upUrl());
293 newUrl
.addPath(name
);
294 m_mainWindow
->rename(oldUrl
, newUrl
);
301 // Only one item has been selected for renaming. Use the custom
302 // renaming mechanism from the views.
303 Q_ASSERT(urls
.count() == 1);
305 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
306 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
307 // is a benefit for the user at all -> let's wait for some input first...
308 RenameDialog
dialog(urls
);
309 if (dialog
.exec() == QDialog::Rejected
) {
313 const QString
& newName
= dialog
.newName();
314 if (newName
.isEmpty()) {
315 view
->statusBar()->setMessage(dialog
.errorString(),
316 DolphinStatusBar::Error
);
319 const KUrl
& oldUrl
= urls
.first();
320 KUrl newUrl
= oldUrl
.upUrl();
321 newUrl
.addPath(newName
);
322 m_mainWindow
->rename(oldUrl
, newUrl
);
327 void DolphinView::selectAll()
329 selectAll(QItemSelectionModel::Select
);
332 void DolphinView::invertSelection()
334 selectAll(QItemSelectionModel::Toggle
);
337 DolphinStatusBar
* DolphinView::statusBar() const
342 int DolphinView::contentsX() const
345 return itemView()->horizontalScrollBar()->value();
348 int DolphinView::contentsY() const
350 return itemView()->verticalScrollBar()->value();
353 void DolphinView::refreshSettings()
355 startDirLister(m_urlNavigator
->url());
358 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
360 emit
requestItemInfo(url
);
363 bool DolphinView::isFilterBarVisible() const
365 return m_filterBar
->isVisible();
368 bool DolphinView::isUrlEditable() const
370 return m_urlNavigator
->isUrlEditable();
373 void DolphinView::zoomIn()
375 m_controller
->triggerZoomIn();
378 void DolphinView::zoomOut()
380 m_controller
->triggerZoomOut();
383 bool DolphinView::isZoomInPossible() const
385 return m_controller
->isZoomInPossible();
388 bool DolphinView::isZoomOutPossible() const
390 return m_controller
->isZoomOutPossible();
393 void DolphinView::setSorting(Sorting sorting
)
395 if (sorting
!= this->sorting()) {
396 updateSorting(sorting
);
400 DolphinView::Sorting
DolphinView::sorting() const
402 return m_proxyModel
->sorting();
405 void DolphinView::setSortOrder(Qt::SortOrder order
)
407 if (sortOrder() != order
) {
408 updateSortOrder(order
);
412 Qt::SortOrder
DolphinView::sortOrder() const
414 return m_proxyModel
->sortOrder();
417 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
419 ViewProperties
props(m_urlNavigator
->url());
420 props
.setAdditionalInfo(info
);
422 m_fileItemDelegate
->setAdditionalInformation(info
);
424 emit
additionalInfoChanged(info
);
428 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
430 return m_fileItemDelegate
->additionalInformation();
433 void DolphinView::goBack()
435 m_urlNavigator
->goBack();
438 void DolphinView::goForward()
440 m_urlNavigator
->goForward();
443 void DolphinView::goUp()
445 m_urlNavigator
->goUp();
448 void DolphinView::goHome()
450 m_urlNavigator
->goHome();
453 void DolphinView::setUrlEditable(bool editable
)
455 m_urlNavigator
->editUrl(editable
);
458 const QLinkedList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
460 return m_urlNavigator
->history(index
);
463 bool DolphinView::hasSelection() const
465 return itemView()->selectionModel()->hasSelection();
468 void DolphinView::clearSelection()
470 itemView()->selectionModel()->clear();
473 KFileItemList
DolphinView::selectedItems() const
475 const QAbstractItemView
* view
= itemView();
477 // Our view has a selection, we will map them back to the DirModel
478 // and then fill the KFileItemList.
479 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
481 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
482 KFileItemList itemList
;
484 const QModelIndexList indexList
= selection
.indexes();
485 QModelIndexList::const_iterator end
= indexList
.end();
486 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
487 Q_ASSERT((*it
).isValid());
489 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
491 itemList
.append(item
);
498 KUrl::List
DolphinView::selectedUrls() const
502 const KFileItemList list
= selectedItems();
503 KFileItemList::const_iterator it
= list
.begin();
504 const KFileItemList::const_iterator end
= list
.end();
506 KFileItem
* item
= *it
;
507 urls
.append(item
->url());
514 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
516 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
517 return m_dirModel
->itemForIndex(dirModelIndex
);
520 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
524 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
528 KUrl
dest(source
.upUrl());
529 dest
.addPath(newName
);
531 const bool destExists
= KIO::NetAccess::exists(dest
,
533 mainWindow()->activeView());
535 // the destination already exists, hence ask the user
537 KIO::RenameDialog
renameDialog(this,
538 i18n("File Already Exists"),
542 switch (renameDialog
.exec()) {
543 case KIO::R_OVERWRITE
:
544 // the destination should be overwritten
545 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
548 case KIO::R_RENAME
: {
549 // a new name for the destination has been used
550 KUrl
newDest(renameDialog
.newDestUrl());
551 ok
= KIO::NetAccess::file_move(source
, newDest
);
556 // the renaming operation has been canceled
562 // no destination exists, hence just move the file to
564 ok
= KIO::NetAccess::file_move(source
, dest
);
567 const QString destFileName
= dest
.fileName();
569 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
570 DolphinStatusBar::OperationCompleted
);
572 KonqOperations::rename(this, source
, destFileName
);
575 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
576 DolphinStatusBar::Error
);
581 void DolphinView::reload()
583 startDirLister(m_urlNavigator
->url(), true);
586 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
588 QWidget::mouseReleaseEvent(event
);
589 mainWindow()->setActiveView(this);
592 DolphinMainWindow
* DolphinView::mainWindow() const
597 void DolphinView::loadDirectory(const KUrl
& url
)
599 const ViewProperties
props(url
);
601 const Mode mode
= props
.viewMode();
602 if (m_mode
!= mode
) {
608 const bool showHiddenFiles
= props
.showHiddenFiles();
609 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
610 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
611 emit
showHiddenFilesChanged();
614 const DolphinView::Sorting sorting
= props
.sorting();
615 if (sorting
!= m_proxyModel
->sorting()) {
616 m_proxyModel
->setSorting(sorting
);
617 emit
sortingChanged(sorting
);
620 const Qt::SortOrder sortOrder
= props
.sortOrder();
621 if (sortOrder
!= m_proxyModel
->sortOrder()) {
622 m_proxyModel
->setSortOrder(sortOrder
);
623 emit
sortOrderChanged(sortOrder
);
626 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
627 if (info
!= m_fileItemDelegate
->additionalInformation()) {
628 m_fileItemDelegate
->setAdditionalInformation(info
);
630 emit
additionalInfoChanged(info
);
633 const bool showPreview
= props
.showPreview();
634 if (showPreview
!= m_controller
->showPreview()) {
635 m_controller
->setShowPreview(showPreview
);
636 emit
showPreviewChanged();
640 emit
urlChanged(url
);
642 m_statusBar
->clear();
645 void DolphinView::triggerItem(const QModelIndex
& index
)
647 if (!isValidNameIndex(index
)) {
651 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
652 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
653 // items are selected by the user, hence don't trigger the
654 // item specified by 'index'
658 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
663 // Prefer the local path over the URL. This assures that the
664 // volume space information is correct. Assuming that the URL is media:/sda1,
665 // and the local path is /windows/C: For the URL the space info is related
666 // to the root partition (and hence wrong) and for the local path the space
667 // info is related to the windows partition (-> correct).
668 const QString
localPath(item
->localPath());
670 if (localPath
.isEmpty()) {
680 else if (item
->isFile()) {
681 // allow to browse through ZIP and tar files
682 KMimeType::Ptr mime
= item
->mimeTypePtr();
683 if (mime
->is("application/zip")) {
684 url
.setProtocol("zip");
687 else if (mime
->is("application/x-tar") ||
688 mime
->is("application/x-tarz") ||
689 mime
->is("application/x-bzip-compressed-tar") ||
690 mime
->is("application/x-compressed-tar") ||
691 mime
->is("application/x-tzo")) {
692 url
.setProtocol("tar");
704 void DolphinView::updateProgress(int percent
)
706 if (m_showProgress
) {
707 m_statusBar
->setProgress(percent
);
711 void DolphinView::updateItemCount()
713 if (m_showProgress
) {
714 m_statusBar
->setProgressText(QString());
715 m_statusBar
->setProgress(100);
716 m_showProgress
= false;
719 KFileItemList
items(m_dirLister
->items());
720 KFileItemList::const_iterator it
= items
.begin();
721 const KFileItemList::const_iterator end
= items
.end();
727 KFileItem
* item
= *it
;
739 m_blockContentsMovedSignal
= false;
740 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
743 void DolphinView::generatePreviews(const KFileItemList
& items
)
745 if (m_controller
->showPreview()) {
746 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
747 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
748 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
752 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
755 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
756 if (idx
.isValid() && (idx
.column() == 0)) {
757 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
758 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(*item
)) {
759 KIconEffect iconEffect
;
760 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
761 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
764 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
769 void DolphinView::restoreContentsPos()
772 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
773 if (!history
.isEmpty()) {
774 QAbstractItemView
* view
= itemView();
775 // TODO: view->setCurrentItem(history[index].currentFileName());
777 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
779 view
->horizontalScrollBar()->setValue((*it
).contentsX());
780 view
->verticalScrollBar()->setValue((*it
).contentsY());
784 void DolphinView::showInfoMessage(const QString
& msg
)
786 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
789 void DolphinView::showErrorMessage(const QString
& msg
)
791 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
794 void DolphinView::emitSelectionChangedSignal()
796 emit
selectionChanged();
799 void DolphinView::closeFilterBar()
802 emit
showFilterBarChanged(false);
805 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
807 if (!url
.isValid()) {
808 const QString
location(url
.pathOrUrl());
809 if (location
.isEmpty()) {
810 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
813 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
814 DolphinStatusBar::Error
);
819 // Only show the directory loading progress if the status bar does
820 // not contain another progress information. This means that
821 // the directory loading progress information has the lowest priority.
822 const QString
progressText(m_statusBar
->progressText());
823 m_showProgress
= progressText
.isEmpty() ||
824 (progressText
== i18n("Loading directory..."));
825 if (m_showProgress
) {
826 m_statusBar
->setProgressText(i18n("Loading directory..."));
827 m_statusBar
->setProgress(0);
830 m_cutItemsCache
.clear();
831 m_blockContentsMovedSignal
= true;
833 m_dirLister
->openUrl(url
, false, reload
);
836 QString
DolphinView::defaultStatusBarText() const
838 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
844 QString
DolphinView::selectionStatusBarText() const
847 const KFileItemList list
= selectedItems();
848 if (list
.isEmpty()) {
849 // when an item is triggered, it is temporary selected but selectedItems()
850 // will return an empty list
856 KIO::filesize_t byteSize
= 0;
857 KFileItemList::const_iterator it
= list
.begin();
858 const KFileItemList::const_iterator end
= list
.end();
860 KFileItem
* item
= *it
;
866 byteSize
+= item
->size();
871 if (folderCount
> 0) {
872 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
879 const QString
sizeText(KIO::convertSize(byteSize
));
880 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
886 void DolphinView::showFilterBar(bool show
)
888 Q_ASSERT(m_filterBar
!= 0);
897 void DolphinView::updateStatusBar()
899 // As the item count information is less important
900 // in comparison with other messages, it should only
902 // - the status bar is empty or
903 // - shows already the item count information or
904 // - shows only a not very important information
905 // - if any progress is given don't show the item count info at all
906 const QString
msg(m_statusBar
->message());
907 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
908 (msg
== m_statusBar
->defaultText()) ||
909 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
910 (m_statusBar
->progress() == 100);
912 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
913 m_statusBar
->setDefaultText(text
);
915 if (updateStatusBarMsg
) {
916 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
920 void DolphinView::requestActivation()
922 m_mainWindow
->setActiveView(this);
925 void DolphinView::changeNameFilter(const QString
& nameFilter
)
927 // The name filter of KDirLister does a 'hard' filtering, which
928 // means that only the items are shown where the names match
929 // exactly the filter. This is non-transparent for the user, which
930 // just wants to have a 'soft' filtering: does the name contain
931 // the filter string?
932 QString
adjustedFilter(nameFilter
);
933 adjustedFilter
.insert(0, '*');
934 adjustedFilter
.append('*');
936 // Use the ProxyModel to filter:
937 // This code is #ifdefed as setNameFilter behaves
938 // slightly different than the QSortFilterProxyModel
939 // as it will not remove directories. I will ask
940 // our beloved usability experts for input
943 m_dirLister
->setNameFilter(adjustedFilter
);
944 m_dirLister
->emitChanges();
946 m_proxyModel
->setFilterRegExp( nameFilter
);
950 void DolphinView::openContextMenu(const QPoint
& pos
)
954 const QModelIndex index
= itemView()->indexAt(pos
);
955 if (isValidNameIndex(index
)) {
956 item
= fileItem(index
);
959 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url());
963 void DolphinView::dropUrls(const KUrl::List
& urls
,
964 const QModelIndex
& index
,
967 KFileItem
* directory
= 0;
968 if (isValidNameIndex(index
)) {
969 KFileItem
* item
= fileItem(index
);
972 // the URLs are dropped above a directory
977 if ((directory
== 0) && (source
== itemView())) {
978 // The dropping is done into the same viewport where
979 // the dragging has been started. Just ignore this...
983 const KUrl
& destination
= (directory
== 0) ? url() :
985 dropUrls(urls
, destination
);
988 void DolphinView::dropUrls(const KUrl::List
& urls
,
989 const KUrl
& destination
)
991 m_mainWindow
->dropUrls(urls
, destination
);
994 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
996 ViewProperties
props(url());
997 props
.setSorting(sorting
);
999 m_proxyModel
->setSorting(sorting
);
1001 emit
sortingChanged(sorting
);
1004 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1006 ViewProperties
props(url());
1007 props
.setSortOrder(order
);
1009 m_proxyModel
->setSortOrder(order
);
1011 emit
sortOrderChanged(order
);
1014 void DolphinView::emitContentsMoved()
1016 if (!m_blockContentsMovedSignal
) {
1017 emit
contentsMoved(contentsX(), contentsY());
1021 void DolphinView::updateActivationState()
1023 m_urlNavigator
->setActive(isActive());
1026 void DolphinView::updateCutItems()
1028 // restore the icons of all previously selected items to the
1029 // original state...
1030 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
1031 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
1033 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
1034 if (index
.isValid()) {
1035 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
1039 m_cutItemsCache
.clear();
1041 // ... and apply an item effect to all currently cut items
1042 applyCutItemEffect();
1045 void DolphinView::createView()
1047 // delete current view
1048 QAbstractItemView
* view
= itemView();
1050 m_topLayout
->removeWidget(view
);
1052 view
->deleteLater();
1056 m_fileItemDelegate
= 0;
1059 Q_ASSERT(m_iconsView
== 0);
1060 Q_ASSERT(m_detailsView
== 0);
1062 // ... and recreate it representing the current mode
1065 m_iconsView
= new DolphinIconsView(this, m_controller
);
1070 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1071 view
= m_detailsView
;
1075 Q_ASSERT(view
!= 0);
1077 m_fileItemDelegate
= new KFileItemDelegate(view
);
1078 view
->setItemDelegate(m_fileItemDelegate
);
1080 view
->setModel(m_proxyModel
);
1081 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1083 new KMimeTypeResolver(view
, m_dirModel
);
1084 m_topLayout
->insertWidget(1, view
);
1086 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1087 m_controller
, SLOT(indicateSelectionChange()));
1088 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1089 this, SLOT(emitContentsMoved()));
1090 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1091 this, SLOT(emitContentsMoved()));
1094 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1096 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1097 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1099 const QModelIndex topLeft
= itemModel
->index(0, 0);
1100 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1101 itemModel
->columnCount() - 1);
1103 QItemSelection
selection(topLeft
, bottomRight
);
1104 selectionModel
->select(selection
, flags
);
1107 QAbstractItemView
* DolphinView::itemView() const
1109 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1110 if (m_detailsView
!= 0) {
1111 return m_detailsView
;
1116 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1118 return index
.isValid() && (index
.column() == KDirModel::Name
);
1121 bool DolphinView::isCutItem(const KFileItem
& item
) const
1123 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1124 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1126 const KUrl
& itemUrl
= item
.url();
1127 KUrl::List::const_iterator it
= cutUrls
.begin();
1128 const KUrl::List::const_iterator end
= cutUrls
.end();
1130 if (*it
== itemUrl
) {
1139 void DolphinView::applyCutItemEffect()
1141 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1142 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
1146 KFileItemList
items(m_dirLister
->items());
1147 KFileItemList::const_iterator it
= items
.begin();
1148 const KFileItemList::const_iterator end
= items
.end();
1150 KFileItem
* item
= *it
;
1151 if (isCutItem(*item
)) {
1152 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
1153 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
1154 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
1155 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
1156 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
1157 QPixmap pixmap
= icon
.pixmap(128, 128);
1159 // remember current pixmap for the item to be able
1160 // to restore it when other items get cut
1162 cutItem
.url
= item
->url();
1163 cutItem
.pixmap
= pixmap
;
1164 m_cutItemsCache
.append(cutItem
);
1166 // apply icon effect to the cut item
1167 KIconEffect iconEffect
;
1168 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
1169 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
1176 #include "dolphinview.moc"