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 startDirLister(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();
483 * Our view has a selection, we will map them back to the DirModel
484 * and then fill the KFileItemList
486 KFileItemList
DolphinView::selectedItems() const
488 assert( m_iconsView
&& m_iconsView
->selectionModel() );
490 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource( m_iconsView
->selectionModel()->selection() );
491 KFileItemList itemList
;
493 const QModelIndexList indexList
= selection
.indexes();
494 QModelIndexList::const_iterator end
= indexList
.end();
495 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
496 assert( (*it
).isValid() );
498 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
500 itemList
.append(item
);
507 KUrl::List
DolphinView::selectedUrls() const
511 const KFileItemList list
= selectedItems();
512 KFileItemList::const_iterator it
= list
.begin();
513 const KFileItemList::const_iterator end
= list
.end();
515 KFileItem
* item
= *it
;
516 urls
.append(item
->url());
523 const KFileItem
* DolphinView::currentFileItem() const
525 return 0; // fileView()->currentFileItem();
528 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
530 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
534 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
538 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
542 KUrl
dest(source
.upUrl());
543 dest
.addPath(newName
);
545 const bool destExists
= KIO::NetAccess::exists(dest
,
547 mainWindow()->activeView());
549 // the destination already exists, hence ask the user
551 KIO::RenameDialog
renameDialog(this,
552 i18n("File Already Exists"),
556 switch (renameDialog
.exec()) {
557 case KIO::R_OVERWRITE
:
558 // the destination should be overwritten
559 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
562 case KIO::R_RENAME
: {
563 // a new name for the destination has been used
564 KUrl
newDest(renameDialog
.newDestUrl());
565 ok
= KIO::NetAccess::file_move(source
, newDest
);
570 // the renaming operation has been canceled
576 // no destination exists, hence just move the file to
578 ok
= KIO::NetAccess::file_move(source
, dest
);
582 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
583 DolphinStatusBar::OperationCompleted
);
585 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
586 UndoManager::instance().addCommand(command
);
589 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
590 DolphinStatusBar::Error
);
595 void DolphinView::reload()
597 startDirLister(m_urlNavigator
->url(), true);
600 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
601 const KUrl::List
& urls
,
604 KUrl
destination(url
);
605 if (destination
.isEmpty()) {
606 destination
= m_urlNavigator
->url();
609 // Check whether the destination Url is a directory. If this is not the
610 // case, use the navigator Url as destination (otherwise the destination,
611 // which represents a file, would be replaced by a copy- or move-operation).
612 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
613 if (!fileItem
.isDir()) {
614 destination
= m_urlNavigator
->url();
618 mainWindow()->dropUrls(urls
, destination
);
621 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
623 QWidget::mouseReleaseEvent(event
);
624 mainWindow()->setActiveView(this);
627 DolphinMainWindow
* DolphinView::mainWindow() const
632 void DolphinView::loadDirectory(const KUrl
& url
)
634 const ViewProperties
props(url
);
636 const Mode mode
= props
.viewMode();
637 if (m_mode
!= mode
) {
643 const bool showHiddenFiles
= props
.showHiddenFiles();
644 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
645 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
646 emit
showHiddenFilesChanged();
649 const DolphinView::Sorting sorting
= props
.sorting();
650 if (sorting
!= m_proxyModel
->sorting()) {
651 m_proxyModel
->setSorting(sorting
);
652 emit
sortingChanged(sorting
);
655 const Qt::SortOrder sortOrder
= props
.sortOrder();
656 if (sortOrder
!= m_proxyModel
->sortOrder()) {
657 m_proxyModel
->setSortOrder(sortOrder
);
658 emit
sortOrderChanged(sortOrder
);
661 // TODO: handle previews (props.showPreview())
664 emit
urlChanged(url
);
667 void DolphinView::triggerItem(const QModelIndex
& index
)
669 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
675 // Prefer the local path over the Url. This assures that the
676 // volume space information is correct. Assuming that the Url is media:/sda1,
677 // and the local path is /windows/C: For the Url the space info is related
678 // to the root partition (and hence wrong) and for the local path the space
679 // info is related to the windows partition (-> correct).
680 //m_dirLister->stop();
681 //m_dirLister->openUrl(item->url());
684 const QString
localPath(item
->localPath());
685 if (localPath
.isEmpty()) {
689 setUrl(KUrl(localPath
));
697 void DolphinView::slotPercent(int percent
)
699 if (m_showProgress
) {
700 m_statusBar
->setProgress(percent
);
704 void DolphinView::slotClear()
706 //fileView()->clearView();
710 void DolphinView::slotDeleteItem(KFileItem
* item
)
712 //fileView()->removeItem(item);
716 void DolphinView::slotCompleted()
720 //KFileView* view = fileView();
723 // TODO: in Qt4 the code should get a lot
724 // simpler and nicer due to Interview...
725 /*if (m_iconsView != 0) {
726 m_iconsView->beginItemUpdates();
728 if (m_iconsView != 0) {
729 m_iconsView->beginItemUpdates();
732 if (m_showProgress
) {
733 m_statusBar
->setProgressText(QString::null
);
734 m_statusBar
->setProgress(100);
735 m_showProgress
= false;
738 KFileItemList
items(m_dirLister
->items());
739 KFileItemList::const_iterator it
= items
.begin();
740 const KFileItemList::const_iterator end
= items
.end();
746 KFileItem
* item
= *it
;
747 //view->insertItem(item);
759 /*if (m_iconsView != 0) {
760 // Prevent a flickering of the icon view widget by giving a small
761 // timeslot to swallow asynchronous update events.
762 m_iconsView->setUpdatesEnabled(false);
763 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
766 if (m_iconsView != 0) {
767 m_iconsView->endItemUpdates();
768 m_refreshing = false;
772 void DolphinView::slotInfoMessage(const QString
& msg
)
774 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
777 void DolphinView::slotErrorMessage(const QString
& msg
)
779 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
782 void DolphinView::slotGrabActivation()
784 mainWindow()->setActiveView(this);
787 void DolphinView::emitSelectionChangedSignal()
789 emit
selectionChanged();
792 void DolphinView::closeFilterBar()
795 emit
showFilterBarChanged(false);
798 void DolphinView::slotContentsMoving(int x
, int y
)
801 // Only emit a 'contents moved' signal if the user
802 // moved the content by adjusting the sliders. Adjustments
803 // resulted by refreshing a directory should not be respected.
804 emit
contentsMoved(x
, y
);
808 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
810 if (!url
.isValid()) {
811 const QString
location(url
.pathOrUrl());
812 if (location
.isEmpty()) {
813 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
816 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
817 DolphinStatusBar::Error
);
822 // Only show the directory loading progress if the status bar does
823 // not contain another progress information. This means that
824 // the directory loading progress information has the lowest priority.
825 const QString
progressText(m_statusBar
->progressText());
826 m_showProgress
= progressText
.isEmpty() ||
827 (progressText
== i18n("Loading directory..."));
828 if (m_showProgress
) {
829 m_statusBar
->setProgressText(i18n("Loading directory..."));
830 m_statusBar
->setProgress(0);
835 m_dirLister
->openUrl(url
, false, reload
);
838 QString
DolphinView::defaultStatusBarText() const
840 // TODO: the following code is not suitable for languages where multiple forms
841 // of plurals are given (e. g. in Poland three forms of plurals exist).
842 const int itemCount
= m_folderCount
+ m_fileCount
;
845 if (itemCount
== 1) {
846 text
= i18n("1 Item");
849 text
= i18n("%1 Items",itemCount
);
854 if (m_folderCount
== 1) {
855 text
+= i18n("1 Folder");
858 text
+= i18n("%1 Folders",m_folderCount
);
863 if (m_fileCount
== 1) {
864 text
+= i18n("1 File");
867 text
+= i18n("%1 Files",m_fileCount
);
875 QString
DolphinView::selectionStatusBarText() const
877 // TODO: the following code is not suitable for languages where multiple forms
878 // of plurals are given (e. g. in Poland three forms of plurals exist).
880 const KFileItemList list
= selectedItems();
881 if (list
.isEmpty()) {
882 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
883 // DolphinView::hasSelection() is true. Inconsistent behavior?
889 KIO::filesize_t byteSize
= 0;
890 KFileItemList::const_iterator it
= list
.begin();
891 const KFileItemList::const_iterator end
= list
.end();
893 KFileItem
* item
= *it
;
899 byteSize
+= item
->size();
904 if (folderCount
== 1) {
905 text
= i18n("1 Folder selected");
907 else if (folderCount
> 1) {
908 text
= i18n("%1 Folders selected",folderCount
);
911 if ((fileCount
> 0) && (folderCount
> 0)) {
915 const QString
sizeText(KIO::convertSize(byteSize
));
916 if (fileCount
== 1) {
917 text
+= i18n("1 File selected (%1)",sizeText
);
919 else if (fileCount
> 1) {
920 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
926 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
928 // assure that the string reprentation for all indicess have the same
929 // number of characters based on the given number of items
930 QString
str(QString::number(index
));
932 while (itemCount
>= 10) {
936 str
.reserve(chrCount
);
938 const int insertCount
= chrCount
- str
.length();
939 for (int i
= 0; i
< insertCount
; ++i
) {
945 void DolphinView::slotShowFilterBar(bool show
)
947 assert(m_filterBar
!= 0);
956 void DolphinView::declareViewActive()
958 mainWindow()->setActiveView( this );
961 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
963 // The name filter of KDirLister does a 'hard' filtering, which
964 // means that only the items are shown where the names match
965 // exactly the filter. This is non-transparent for the user, which
966 // just wants to have a 'soft' filtering: does the name contain
967 // the filter string?
968 QString
adjustedFilter(nameFilter
);
969 adjustedFilter
.insert(0, '*');
970 adjustedFilter
.append('*');
973 * Use the ProxyModel to filter:
974 * This code is #ifdefed as setNameFilter behaves
975 * slightly different than the QSortFilterProxyModel
976 * as it will not remove directories. I will ask
977 * our beloved usability experts for input
981 m_dirLister
->setNameFilter(adjustedFilter
);
982 m_dirLister
->emitChanges();
984 m_proxyModel
->setFilterRegExp( nameFilter
);
988 void DolphinView::applyModeToView()
990 m_iconsView
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
992 // TODO: the following code just tries to test some QListView capabilities
995 m_iconsView
->setViewMode(QListView::IconMode
);
996 m_iconsView
->setSpacing(32);
997 // m_iconsView->setAlternatingRowColors(false);
998 // m_iconsView->setGridSize(QSize(128, 64));
1002 m_iconsView
->setViewMode(QListView::ListMode
);
1003 m_iconsView
->setSpacing(0);
1004 // m_iconsView->setAlternatingRowColors(true);
1005 // m_iconsView->setGridSize(QSize(256, 24));
1010 int DolphinView::columnIndex(Sorting sorting
) const
1014 case SortByName
: index
= KDirModel::Name
; break;
1015 case SortBySize
: index
= KDirModel::Size
; break;
1016 case SortByDate
: index
= KDirModel::ModifiedTime
; break;
1017 default: assert(false);
1022 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1024 QItemSelectionModel
* selectionModel
= m_iconsView
->selectionModel();
1025 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1027 const QModelIndex topLeft
= itemModel
->index(0, 0);
1028 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1029 itemModel
->columnCount() - 1);
1031 QItemSelection
selection(topLeft
, bottomRight
);
1032 selectionModel
->select(selection
, flags
);
1035 #include "dolphinview.moc"