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 <QItemSelectionModel>
24 #include <Q3ValueList>
26 #include <QMouseEvent>
27 #include <QVBoxLayout>
29 #include <kdirmodel.h>
30 #include <kfileitemdelegate.h>
33 #include <kio/netaccess.h>
34 #include <kio/renamedialog.h>
35 #include <kmimetyperesolver.h>
38 #include "urlnavigator.h"
39 #include "dolphinstatusbar.h"
40 #include "dolphinmainwindow.h"
41 #include "dolphindirlister.h"
42 #include "dolphinsortfilterproxymodel.h"
43 #include "viewproperties.h"
44 #include "dolphindetailsview.h"
45 #include "dolphiniconsview.h"
46 #include "dolphincontextmenu.h"
47 #include "undomanager.h"
48 #include "renamedialog.h"
49 #include "progressindicator.h"
50 #include "filterbar.h"
52 DolphinView::DolphinView(DolphinMainWindow
*mainWindow
,
56 bool showHiddenFiles
) :
59 m_showProgress(false),
64 m_mainWindow(mainWindow
),
75 setFocusPolicy(Qt::StrongFocus
);
76 m_topLayout
= new QVBoxLayout(this);
77 m_topLayout
->setSpacing(0);
78 m_topLayout
->setMargin(0);
80 m_urlNavigator
= new UrlNavigator(url
, this);
81 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
82 this, SLOT(loadDirectory(const KUrl
&)));
84 m_statusBar
= new DolphinStatusBar(this);
86 m_dirLister
= new DolphinDirLister();
87 m_dirLister
->setAutoUpdate(true);
88 m_dirLister
->setMainWindow(this);
89 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
90 connect(m_dirLister
, SIGNAL(clear()),
91 this, SLOT(slotClear()));
92 connect(m_dirLister
, SIGNAL(percent(int)),
93 this, SLOT(slotPercent(int)));
94 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
95 this, SLOT(slotDeleteItem(KFileItem
*)));
96 connect(m_dirLister
, SIGNAL(completed()),
97 this, SLOT(slotCompleted()));
98 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
99 this, SLOT(slotInfoMessage(const QString
&)));
100 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
101 this, SLOT(slotErrorMessage(const QString
&)));
103 m_iconsView
= new DolphinIconsView(this);
106 m_dirModel
= new KDirModel();
107 m_dirModel
->setDirLister(m_dirLister
);
108 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
110 m_proxyModel
= new DolphinSortFilterProxyModel(this);
111 m_proxyModel
->setSourceModel(m_dirModel
);
113 m_iconsView
->setModel(m_proxyModel
);
115 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
116 delegate
->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType
);
117 m_iconsView
->setItemDelegate(delegate
);
119 m_dirLister
->setDelayedMimeTypes(true);
120 new KMimeTypeResolver(m_iconsView
, m_dirModel
);
122 m_iconSize
= K3Icon::SizeMedium
;
124 m_filterBar
= new FilterBar(this);
126 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
127 this, SLOT(slotChangeNameFilter(const QString
&)));
128 connect(m_filterBar
, SIGNAL(closed()),
129 this, SLOT(closeFilterBar()));
131 m_topLayout
->addWidget(m_urlNavigator
);
132 m_topLayout
->addWidget(m_iconsView
);
133 m_topLayout
->addWidget(m_filterBar
);
134 m_topLayout
->addWidget(m_statusBar
);
136 connect(m_iconsView
, SIGNAL(clicked(const QModelIndex
&)),
137 this, SLOT(triggerItem(const QModelIndex
&)));
138 connect(m_iconsView
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
139 this, SLOT(emitSelectionChangedSignal()));
141 loadDirectory(m_urlNavigator
->url());
144 DolphinView::~DolphinView()
150 void DolphinView::setUrl(const KUrl
& url
)
152 m_urlNavigator
->setUrl(url
);
155 const KUrl
& DolphinView::url() const
157 return m_urlNavigator
->url();
160 void DolphinView::requestActivation()
162 mainWindow()->setActiveView(this);
165 bool DolphinView::isActive() const
167 return (mainWindow()->activeView() == this);
170 void DolphinView::setMode(Mode mode
)
172 if (mode
== m_mode
) {
173 return; // the wished mode is already set
178 ViewProperties
props(m_urlNavigator
->url());
179 props
.setViewMode(m_mode
);
182 startDirLister(m_urlNavigator
->url());
187 DolphinView::Mode
DolphinView::mode() const
192 void DolphinView::setShowPreview(bool show
)
194 ViewProperties
props(m_urlNavigator
->url());
195 props
.setShowPreview(show
);
197 // TODO: wait until previews are possible with KFileItemDelegate
199 emit
showPreviewChanged();
202 bool DolphinView::showPreview() const
204 // TODO: wait until previews are possible with KFileItemDelegate
208 void DolphinView::setShowHiddenFiles(bool show
)
210 if (m_dirLister
->showingDotFiles() == show
) {
214 ViewProperties
props(m_urlNavigator
->url());
215 props
.setShowHiddenFiles(show
);
218 m_dirLister
->setShowingDotFiles(show
);
220 emit
showHiddenFilesChanged();
225 bool DolphinView::showHiddenFiles() const
227 return m_dirLister
->showingDotFiles();
230 void DolphinView::renameSelectedItems()
232 const KUrl::List urls
= selectedUrls();
233 if (urls
.count() > 1) {
234 // More than one item has been selected for renaming. Open
235 // a rename dialog and rename all items afterwards.
236 RenameDialog
dialog(urls
);
237 if (dialog
.exec() == QDialog::Rejected
) {
241 DolphinView
* view
= mainWindow()->activeView();
242 const QString
& newName
= dialog
.newName();
243 if (newName
.isEmpty()) {
244 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
245 DolphinStatusBar::Error
);
248 UndoManager
& undoMan
= UndoManager::instance();
249 undoMan
.beginMacro();
251 assert(newName
.contains('#'));
253 const int urlsCount
= urls
.count();
254 ProgressIndicator
* progressIndicator
=
255 new ProgressIndicator(mainWindow(),
256 i18n("Renaming items..."),
257 i18n("Renaming finished."),
260 // iterate through all selected items and rename them...
261 const int replaceIndex
= newName
.indexOf('#');
262 assert(replaceIndex
>= 0);
263 for (int i
= 0; i
< urlsCount
; ++i
) {
264 const KUrl
& source
= urls
[i
];
265 QString
name(newName
);
266 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
268 if (source
.fileName() != name
) {
269 KUrl
dest(source
.upUrl());
272 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
274 delete progressIndicator
;
275 progressIndicator
= 0;
276 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
277 DolphinStatusBar::Error
);
280 else if (KIO::NetAccess::file_move(source
, dest
)) {
281 // TODO: From the users point of view he executed one 'rename n files' operation,
282 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
283 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
284 undoMan
.addCommand(command
);
288 progressIndicator
->execOperation();
290 delete progressIndicator
;
291 progressIndicator
= 0;
297 // Only one item has been selected for renaming. Use the custom
298 // renaming mechanism from the views.
299 assert(urls
.count() == 1);
301 /*if (m_mode == DetailsView) {
302 Q3ListViewItem* item = m_iconsView->firstChild();
304 if (item->isSelected()) {
305 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
308 item = item->nextSibling();
312 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
314 if (item->isSelected()) {
318 item = static_cast<KFileIconViewItem*>(item->nextItem());
324 void DolphinView::selectAll()
326 selectAll(QItemSelectionModel::Select
);
329 void DolphinView::invertSelection()
331 selectAll(QItemSelectionModel::Toggle
);
334 DolphinStatusBar
* DolphinView::statusBar() const
339 int DolphinView::contentsX() const
342 return 0; //scrollView()->contentsX();
345 int DolphinView::contentsY() const
347 return 0; //scrollView()->contentsY();
350 void DolphinView::refreshSettings()
352 startDirLister(m_urlNavigator
->url());
355 void DolphinView::updateStatusBar()
357 // As the item count information is less important
358 // in comparison with other messages, it should only
360 // - the status bar is empty or
361 // - shows already the item count information or
362 // - shows only a not very important information
363 // - if any progress is given don't show the item count info at all
364 const QString
msg(m_statusBar
->message());
365 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
366 (msg
== m_statusBar
->defaultText()) ||
367 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
368 (m_statusBar
->progress() == 100);
370 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
371 m_statusBar
->setDefaultText(text
);
373 if (updateStatusBarMsg
) {
374 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
378 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
380 emit
requestItemInfo(url
);
383 bool DolphinView::isFilterBarVisible() const
385 return m_filterBar
->isVisible();
388 bool DolphinView::isUrlEditable() const
390 return m_urlNavigator
->isUrlEditable();
393 void DolphinView::zoomIn()
395 //itemEffectsManager()->zoomIn();
398 void DolphinView::zoomOut()
400 //itemEffectsManager()->zoomOut();
403 bool DolphinView::isZoomInPossible() const
405 return false; //itemEffectsManager()->isZoomInPossible();
408 bool DolphinView::isZoomOutPossible() const
410 return false; //itemEffectsManager()->isZoomOutPossible();
413 void DolphinView::setSorting(Sorting sorting
)
415 if (sorting
!= this->sorting()) {
416 ViewProperties
props(url());
417 props
.setSorting(sorting
);
419 m_proxyModel
->setSorting(sorting
);
421 emit
sortingChanged(sorting
);
425 DolphinView::Sorting
DolphinView::sorting() const
427 return m_proxyModel
->sorting();
430 void DolphinView::setSortOrder(Qt::SortOrder order
)
432 if (sortOrder() != order
) {
433 ViewProperties
props(url());
434 props
.setSortOrder(order
);
436 m_proxyModel
->setSortOrder(order
);
438 emit
sortOrderChanged(order
);
442 Qt::SortOrder
DolphinView::sortOrder() const
444 return m_proxyModel
->sortOrder();
447 void DolphinView::goBack()
449 m_urlNavigator
->goBack();
452 void DolphinView::goForward()
454 m_urlNavigator
->goForward();
457 void DolphinView::goUp()
459 m_urlNavigator
->goUp();
462 void DolphinView::goHome()
464 m_urlNavigator
->goHome();
467 void DolphinView::setUrlEditable(bool editable
)
469 m_urlNavigator
->editUrl(editable
);
472 const Q3ValueList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
474 return m_urlNavigator
->history(index
);
477 bool DolphinView::hasSelection() const
479 return m_iconsView
->selectionModel()->hasSelection();
482 KFileItemList
DolphinView::selectedItems() const
484 // Our view has a selection, we will map them back to the DirModel
485 // and then fill the KFileItemList.
486 assert(m_iconsView
&& m_iconsView
->selectionModel());
488 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(m_iconsView
->selectionModel()->selection());
489 KFileItemList itemList
;
491 const QModelIndexList indexList
= selection
.indexes();
492 QModelIndexList::const_iterator end
= indexList
.end();
493 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
494 assert((*it
).isValid());
496 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
498 itemList
.append(item
);
505 KUrl::List
DolphinView::selectedUrls() const
509 const KFileItemList list
= selectedItems();
510 KFileItemList::const_iterator it
= list
.begin();
511 const KFileItemList::const_iterator end
= list
.end();
513 KFileItem
* item
= *it
;
514 urls
.append(item
->url());
521 const KFileItem
* DolphinView::currentFileItem() const
523 return 0; // fileView()->currentFileItem();
526 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
528 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
532 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
536 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
540 KUrl
dest(source
.upUrl());
541 dest
.addPath(newName
);
543 const bool destExists
= KIO::NetAccess::exists(dest
,
545 mainWindow()->activeView());
547 // the destination already exists, hence ask the user
549 KIO::RenameDialog
renameDialog(this,
550 i18n("File Already Exists"),
554 switch (renameDialog
.exec()) {
555 case KIO::R_OVERWRITE
:
556 // the destination should be overwritten
557 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
560 case KIO::R_RENAME
: {
561 // a new name for the destination has been used
562 KUrl
newDest(renameDialog
.newDestUrl());
563 ok
= KIO::NetAccess::file_move(source
, newDest
);
568 // the renaming operation has been canceled
574 // no destination exists, hence just move the file to
576 ok
= KIO::NetAccess::file_move(source
, dest
);
580 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
581 DolphinStatusBar::OperationCompleted
);
583 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
584 UndoManager::instance().addCommand(command
);
587 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
588 DolphinStatusBar::Error
);
593 void DolphinView::reload()
595 startDirLister(m_urlNavigator
->url(), true);
598 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
599 const KUrl::List
& urls
,
602 KUrl
destination(url
);
603 if (destination
.isEmpty()) {
604 destination
= m_urlNavigator
->url();
607 // Check whether the destination Url is a directory. If this is not the
608 // case, use the navigator Url as destination (otherwise the destination,
609 // which represents a file, would be replaced by a copy- or move-operation).
610 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
611 if (!fileItem
.isDir()) {
612 destination
= m_urlNavigator
->url();
616 mainWindow()->dropUrls(urls
, destination
);
619 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
621 QWidget::mouseReleaseEvent(event
);
622 mainWindow()->setActiveView(this);
625 DolphinMainWindow
* DolphinView::mainWindow() const
630 void DolphinView::loadDirectory(const KUrl
& url
)
632 const ViewProperties
props(url
);
634 const Mode mode
= props
.viewMode();
635 if (m_mode
!= mode
) {
641 const bool showHiddenFiles
= props
.showHiddenFiles();
642 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
643 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
644 emit
showHiddenFilesChanged();
647 const DolphinView::Sorting sorting
= props
.sorting();
648 if (sorting
!= m_proxyModel
->sorting()) {
649 m_proxyModel
->setSorting(sorting
);
650 emit
sortingChanged(sorting
);
653 const Qt::SortOrder sortOrder
= props
.sortOrder();
654 if (sortOrder
!= m_proxyModel
->sortOrder()) {
655 m_proxyModel
->setSortOrder(sortOrder
);
656 emit
sortOrderChanged(sortOrder
);
659 // TODO: handle previews (props.showPreview())
662 emit
urlChanged(url
);
665 void DolphinView::triggerItem(const QModelIndex
& index
)
667 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
673 // Prefer the local path over the Url. This assures that the
674 // volume space information is correct. Assuming that the Url is media:/sda1,
675 // and the local path is /windows/C: For the Url the space info is related
676 // to the root partition (and hence wrong) and for the local path the space
677 // info is related to the windows partition (-> correct).
678 //m_dirLister->stop();
679 //m_dirLister->openUrl(item->url());
682 const QString
localPath(item
->localPath());
683 if (localPath
.isEmpty()) {
687 setUrl(KUrl(localPath
));
695 void DolphinView::slotPercent(int percent
)
697 if (m_showProgress
) {
698 m_statusBar
->setProgress(percent
);
702 void DolphinView::slotClear()
704 //fileView()->clearView();
708 void DolphinView::slotDeleteItem(KFileItem
* item
)
710 //fileView()->removeItem(item);
714 void DolphinView::slotCompleted()
718 //KFileView* view = fileView();
721 // TODO: in Qt4 the code should get a lot
722 // simpler and nicer due to Interview...
723 /*if (m_iconsView != 0) {
724 m_iconsView->beginItemUpdates();
726 if (m_iconsView != 0) {
727 m_iconsView->beginItemUpdates();
730 if (m_showProgress
) {
731 m_statusBar
->setProgressText(QString::null
);
732 m_statusBar
->setProgress(100);
733 m_showProgress
= false;
736 KFileItemList
items(m_dirLister
->items());
737 KFileItemList::const_iterator it
= items
.begin();
738 const KFileItemList::const_iterator end
= items
.end();
744 KFileItem
* item
= *it
;
745 //view->insertItem(item);
757 /*if (m_iconsView != 0) {
758 // Prevent a flickering of the icon view widget by giving a small
759 // timeslot to swallow asynchronous update events.
760 m_iconsView->setUpdatesEnabled(false);
761 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
764 if (m_iconsView != 0) {
765 m_iconsView->endItemUpdates();
766 m_refreshing = false;
770 void DolphinView::slotInfoMessage(const QString
& msg
)
772 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
775 void DolphinView::slotErrorMessage(const QString
& msg
)
777 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
780 void DolphinView::slotGrabActivation()
782 mainWindow()->setActiveView(this);
785 void DolphinView::emitSelectionChangedSignal()
787 emit
selectionChanged();
790 void DolphinView::closeFilterBar()
793 emit
showFilterBarChanged(false);
796 void DolphinView::slotContentsMoving(int x
, int y
)
799 // Only emit a 'contents moved' signal if the user
800 // moved the content by adjusting the sliders. Adjustments
801 // resulted by refreshing a directory should not be respected.
802 emit
contentsMoved(x
, y
);
806 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
808 if (!url
.isValid()) {
809 const QString
location(url
.pathOrUrl());
810 if (location
.isEmpty()) {
811 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
814 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
815 DolphinStatusBar::Error
);
820 // Only show the directory loading progress if the status bar does
821 // not contain another progress information. This means that
822 // the directory loading progress information has the lowest priority.
823 const QString
progressText(m_statusBar
->progressText());
824 m_showProgress
= progressText
.isEmpty() ||
825 (progressText
== i18n("Loading directory..."));
826 if (m_showProgress
) {
827 m_statusBar
->setProgressText(i18n("Loading directory..."));
828 m_statusBar
->setProgress(0);
833 m_dirLister
->openUrl(url
, false, reload
);
836 QString
DolphinView::defaultStatusBarText() const
838 // TODO: the following code is not suitable for languages where multiple forms
839 // of plurals are given (e. g. in Poland three forms of plurals exist).
840 const int itemCount
= m_folderCount
+ m_fileCount
;
843 if (itemCount
== 1) {
844 text
= i18n("1 Item");
847 text
= i18n("%1 Items",itemCount
);
852 if (m_folderCount
== 1) {
853 text
+= i18n("1 Folder");
856 text
+= i18n("%1 Folders",m_folderCount
);
861 if (m_fileCount
== 1) {
862 text
+= i18n("1 File");
865 text
+= i18n("%1 Files",m_fileCount
);
873 QString
DolphinView::selectionStatusBarText() const
875 // TODO: the following code is not suitable for languages where multiple forms
876 // of plurals are given (e. g. in Poland three forms of plurals exist).
878 const KFileItemList list
= selectedItems();
879 if (list
.isEmpty()) {
880 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
881 // DolphinView::hasSelection() is true. Inconsistent behavior?
887 KIO::filesize_t byteSize
= 0;
888 KFileItemList::const_iterator it
= list
.begin();
889 const KFileItemList::const_iterator end
= list
.end();
891 KFileItem
* item
= *it
;
897 byteSize
+= item
->size();
902 if (folderCount
== 1) {
903 text
= i18n("1 Folder selected");
905 else if (folderCount
> 1) {
906 text
= i18n("%1 Folders selected",folderCount
);
909 if ((fileCount
> 0) && (folderCount
> 0)) {
913 const QString
sizeText(KIO::convertSize(byteSize
));
914 if (fileCount
== 1) {
915 text
+= i18n("1 File selected (%1)",sizeText
);
917 else if (fileCount
> 1) {
918 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
924 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
926 // assure that the string reprentation for all indicess have the same
927 // number of characters based on the given number of items
928 QString
str(QString::number(index
));
930 while (itemCount
>= 10) {
934 str
.reserve(chrCount
);
936 const int insertCount
= chrCount
- str
.length();
937 for (int i
= 0; i
< insertCount
; ++i
) {
943 void DolphinView::slotShowFilterBar(bool show
)
945 assert(m_filterBar
!= 0);
954 void DolphinView::declareViewActive()
956 mainWindow()->setActiveView( this );
959 void DolphinView::slotChangeNameFilter(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::applyModeToView()
986 m_iconsView
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
988 // TODO: the following code just tries to test some QListView capabilities
991 m_iconsView
->setViewMode(QListView::IconMode
);
992 m_iconsView
->setSpacing(32);
993 // m_iconsView->setAlternatingRowColors(false);
994 // m_iconsView->setGridSize(QSize(128, 64));
998 m_iconsView
->setViewMode(QListView::ListMode
);
999 m_iconsView
->setSpacing(0);
1000 // m_iconsView->setAlternatingRowColors(true);
1001 // m_iconsView->setGridSize(QSize(256, 24));
1006 int DolphinView::columnIndex(Sorting sorting
) const
1010 case SortByName
: index
= KDirModel::Name
; break;
1011 case SortBySize
: index
= KDirModel::Size
; break;
1012 case SortByDate
: index
= KDirModel::ModifiedTime
; break;
1013 default: assert(false);
1018 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1020 QItemSelectionModel
* selectionModel
= m_iconsView
->selectionModel();
1021 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1023 const QModelIndex topLeft
= itemModel
->index(0, 0);
1024 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1025 itemModel
->columnCount() - 1);
1027 QItemSelection
selection(topLeft
, bottomRight
);
1028 selectionModel
->select(selection
, flags
);
1031 #include "dolphinview.moc"