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/renamedlg.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
);
109 m_proxyModel
= new DolphinSortFilterProxyModel(this);
110 m_proxyModel
->setSourceModel(m_dirModel
);
112 m_iconsView
->setModel(m_dirModel
); // TODO: using m_proxyModel crashed when clicking on an item
114 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
115 m_iconsView
->setItemDelegate(delegate
);
117 m_dirLister
->setDelayedMimeTypes(true);
118 new KMimeTypeResolver(m_iconsView
, m_dirModel
);
120 m_iconSize
= K3Icon::SizeMedium
;
122 m_filterBar
= new FilterBar(this);
124 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
125 this, SLOT(slotChangeNameFilter(const QString
&)));
126 connect(m_filterBar
, SIGNAL(closed()),
127 this, SLOT(closeFilterBar()));
129 m_topLayout
->addWidget(m_urlNavigator
);
130 m_topLayout
->addWidget(m_iconsView
);
131 m_topLayout
->addWidget(m_filterBar
);
132 m_topLayout
->addWidget(m_statusBar
);
134 connect(m_iconsView
, SIGNAL(clicked(const QModelIndex
&)),
135 this, SLOT(triggerItem(const QModelIndex
&)));
136 connect(m_iconsView
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
137 this, SLOT(emitSelectionChangedSignal()));
139 startDirLister(m_urlNavigator
->url());
142 DolphinView::~DolphinView()
148 void DolphinView::setUrl(const KUrl
& url
)
150 m_urlNavigator
->setUrl(url
);
153 const KUrl
& DolphinView::url() const
155 return m_urlNavigator
->url();
158 void DolphinView::requestActivation()
160 mainWindow()->setActiveView(this);
163 bool DolphinView::isActive() const
165 return (mainWindow()->activeView() == this);
168 void DolphinView::setMode(Mode mode
)
170 if (mode
== m_mode
) {
171 return; // the wished mode is already set
176 ViewProperties
props(m_urlNavigator
->url());
177 props
.setViewMode(m_mode
);
180 startDirLister(m_urlNavigator
->url());
185 DolphinView::Mode
DolphinView::mode() const
190 void DolphinView::setShowHiddenFiles(bool show
)
192 if (m_dirLister
->showingDotFiles() == show
) {
196 ViewProperties
props(m_urlNavigator
->url());
197 props
.setShowHiddenFiles(show
);
200 m_dirLister
->setShowingDotFiles(show
);
202 emit
showHiddenFilesChanged();
207 bool DolphinView::showHiddenFiles() const
209 return m_dirLister
->showingDotFiles();
212 void DolphinView::setViewProperties(const ViewProperties
& props
)
214 setMode(props
.viewMode());
215 setSorting(props
.sorting());
216 setSortOrder(props
.sortOrder());
217 setShowHiddenFiles(props
.showHiddenFiles());
220 void DolphinView::renameSelectedItems()
222 const KUrl::List urls
= selectedUrls();
223 if (urls
.count() > 1) {
224 // More than one item has been selected for renaming. Open
225 // a rename dialog and rename all items afterwards.
226 RenameDialog
dialog(urls
);
227 if (dialog
.exec() == QDialog::Rejected
) {
231 DolphinView
* view
= mainWindow()->activeView();
232 const QString
& newName
= dialog
.newName();
233 if (newName
.isEmpty()) {
234 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
235 DolphinStatusBar::Error
);
238 UndoManager
& undoMan
= UndoManager::instance();
239 undoMan
.beginMacro();
241 assert(newName
.contains('#'));
243 const int urlsCount
= urls
.count();
244 ProgressIndicator
* progressIndicator
=
245 new ProgressIndicator(mainWindow(),
246 i18n("Renaming items..."),
247 i18n("Renaming finished."),
250 // iterate through all selected items and rename them...
251 const int replaceIndex
= newName
.indexOf('#');
252 assert(replaceIndex
>= 0);
253 for (int i
= 0; i
< urlsCount
; ++i
) {
254 const KUrl
& source
= urls
[i
];
255 QString
name(newName
);
256 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
258 if (source
.fileName() != name
) {
259 KUrl
dest(source
.upUrl());
262 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
264 delete progressIndicator
;
265 progressIndicator
= 0;
266 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
267 DolphinStatusBar::Error
);
270 else if (KIO::NetAccess::file_move(source
, dest
)) {
271 // TODO: From the users point of view he executed one 'rename n files' operation,
272 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
273 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
274 undoMan
.addCommand(command
);
278 progressIndicator
->execOperation();
280 delete progressIndicator
;
281 progressIndicator
= 0;
287 // Only one item has been selected for renaming. Use the custom
288 // renaming mechanism from the views.
289 assert(urls
.count() == 1);
291 /*if (m_mode == DetailsView) {
292 Q3ListViewItem* item = m_iconsView->firstChild();
294 if (item->isSelected()) {
295 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
298 item = item->nextSibling();
302 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
304 if (item->isSelected()) {
308 item = static_cast<KFileIconViewItem*>(item->nextItem());
314 void DolphinView::selectAll()
316 selectAll(QItemSelectionModel::Select
);
319 void DolphinView::invertSelection()
321 selectAll(QItemSelectionModel::Toggle
);
324 DolphinStatusBar
* DolphinView::statusBar() const
329 int DolphinView::contentsX() const
332 return 0; //scrollView()->contentsX();
335 int DolphinView::contentsY() const
337 return 0; //scrollView()->contentsY();
340 void DolphinView::refreshSettings()
342 startDirLister(m_urlNavigator
->url());
345 void DolphinView::updateStatusBar()
347 // As the item count information is less important
348 // in comparison with other messages, it should only
350 // - the status bar is empty or
351 // - shows already the item count information or
352 // - shows only a not very important information
353 // - if any progress is given don't show the item count info at all
354 const QString
msg(m_statusBar
->message());
355 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
356 (msg
== m_statusBar
->defaultText()) ||
357 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
358 (m_statusBar
->progress() == 100);
360 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
361 m_statusBar
->setDefaultText(text
);
363 if (updateStatusBarMsg
) {
364 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
368 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
370 emit
requestItemInfo(url
);
373 bool DolphinView::isFilterBarVisible() const
375 return m_filterBar
->isVisible();
378 bool DolphinView::isUrlEditable() const
380 return m_urlNavigator
->isUrlEditable();
383 void DolphinView::zoomIn()
385 //itemEffectsManager()->zoomIn();
388 void DolphinView::zoomOut()
390 //itemEffectsManager()->zoomOut();
393 bool DolphinView::isZoomInPossible() const
395 return false; //itemEffectsManager()->isZoomInPossible();
398 bool DolphinView::isZoomOutPossible() const
400 return false; //itemEffectsManager()->isZoomOutPossible();
403 void DolphinView::setSorting(Sorting sorting
)
405 if (sorting
!= this->sorting()) {
406 ViewProperties
props(url());
407 props
.setSorting(sorting
);
409 m_proxyModel
->setSorting(sorting
);
411 emit
sortingChanged(sorting
);
415 DolphinView::Sorting
DolphinView::sorting() const
417 return m_proxyModel
->sorting();
420 void DolphinView::setSortOrder(Qt::SortOrder order
)
422 if (sortOrder() != order
) {
423 ViewProperties
props(url());
424 props
.setSortOrder(order
);
426 m_proxyModel
->setSortOrder(order
);
428 emit
sortOrderChanged(order
);
432 Qt::SortOrder
DolphinView::sortOrder() const
434 return m_proxyModel
->sortOrder();
437 void DolphinView::goBack()
439 m_urlNavigator
->goBack();
442 void DolphinView::goForward()
444 m_urlNavigator
->goForward();
447 void DolphinView::goUp()
449 m_urlNavigator
->goUp();
452 void DolphinView::goHome()
454 m_urlNavigator
->goHome();
457 void DolphinView::setUrlEditable(bool editable
)
459 m_urlNavigator
->editUrl(editable
);
462 const Q3ValueList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
464 return m_urlNavigator
->history(index
);
467 bool DolphinView::hasSelection() const
469 return m_iconsView
->selectionModel()->hasSelection();
472 KFileItemList
DolphinView::selectedItems() const
474 QItemSelectionModel
* selModel
= m_iconsView
->selectionModel();
475 assert(selModel
!= 0);
477 KFileItemList itemList
;
478 if (selModel
->hasSelection()) {
479 const QModelIndexList indexList
= selModel
->selectedIndexes();
481 QModelIndexList::const_iterator end
= indexList
.end();
482 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
483 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
485 itemList
.append(item
);
492 KUrl::List
DolphinView::selectedUrls() const
496 const KFileItemList list
= selectedItems();
497 KFileItemList::const_iterator it
= list
.begin();
498 const KFileItemList::const_iterator end
= list
.end();
500 KFileItem
* item
= *it
;
501 urls
.append(item
->url());
508 const KFileItem
* DolphinView::currentFileItem() const
510 return 0; // fileView()->currentFileItem();
513 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
515 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
519 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
523 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
527 KUrl
dest(source
.upUrl());
528 dest
.addPath(newName
);
530 const bool destExists
= KIO::NetAccess::exists(dest
,
532 mainWindow()->activeView());
534 // the destination already exists, hence ask the user
536 KIO::RenameDlg
renameDialog(this,
537 i18n("File Already Exists"),
541 switch (renameDialog
.exec()) {
542 case KIO::R_OVERWRITE
:
543 // the destination should be overwritten
544 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
547 case KIO::R_RENAME
: {
548 // a new name for the destination has been used
549 KUrl
newDest(renameDialog
.newDestUrl());
550 ok
= KIO::NetAccess::file_move(source
, newDest
);
555 // the renaming operation has been canceled
561 // no destination exists, hence just move the file to
563 ok
= KIO::NetAccess::file_move(source
, dest
);
567 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
568 DolphinStatusBar::OperationCompleted
);
570 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
571 UndoManager::instance().addCommand(command
);
574 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
575 DolphinStatusBar::Error
);
580 void DolphinView::reload()
582 startDirLister(m_urlNavigator
->url(), true);
585 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
586 const KUrl::List
& urls
,
589 KUrl
destination(url
);
590 if (destination
.isEmpty()) {
591 destination
= m_urlNavigator
->url();
594 // Check whether the destination Url is a directory. If this is not the
595 // case, use the navigator Url as destination (otherwise the destination,
596 // which represents a file, would be replaced by a copy- or move-operation).
597 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
598 if (!fileItem
.isDir()) {
599 destination
= m_urlNavigator
->url();
603 mainWindow()->dropUrls(urls
, destination
);
606 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
608 QWidget::mouseReleaseEvent(event
);
609 mainWindow()->setActiveView(this);
612 DolphinMainWindow
* DolphinView::mainWindow() const
617 void DolphinView::loadDirectory(const KUrl
& url
)
619 const ViewProperties
props(url
);
620 setMode(props
.viewMode());
622 const bool showHiddenFiles
= props
.showHiddenFiles();
623 setShowHiddenFiles(showHiddenFiles
);
624 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
626 setSorting(props
.sorting());
627 setSortOrder(props
.sortOrder());
630 emit
urlChanged(url
);
633 void DolphinView::triggerIconsViewItem(Q3IconViewItem
* item
)
636 const Qt::ButtonState keyboardState = KApplication::keyboardMouseState();
637 const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) ||
638 ((keyboardState & Qt::ControlModifier) > 0);*/
639 const bool isSelectionActive
= false;
640 if ((item
!= 0) && !isSelectionActive
) {
641 // Updating the Url must be done outside the scope of this slot,
642 // as iconview items will get deleted.
643 QTimer::singleShot(0, this, SLOT(updateUrl()));
644 mainWindow()->setActiveView(this);
648 void DolphinView::triggerItem(const QModelIndex
& index
)
650 KFileItem
* item
= m_dirModel
->itemForIndex(index
);
656 // Prefer the local path over the Url. This assures that the
657 // volume space information is correct. Assuming that the Url is media:/sda1,
658 // and the local path is /windows/C: For the Url the space info is related
659 // to the root partition (and hence wrong) and for the local path the space
660 // info is related to the windows partition (-> correct).
661 //m_dirLister->stop();
662 //m_dirLister->openUrl(item->url());
665 const QString
localPath(item
->localPath());
666 if (localPath
.isEmpty()) {
670 setUrl(KUrl(localPath
));
678 void DolphinView::updateUrl()
680 //KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
681 // static_cast<KFileView*>(m_iconsView);
683 KFileItem
* fileItem
= 0; // TODO: fileView->currentFileItem();
688 if (fileItem
->isDir()) {
689 // Prefer the local path over the Url. This assures that the
690 // volume space information is correct. Assuming that the Url is media:/sda1,
691 // and the local path is /windows/C: For the Url the space info is related
692 // to the root partition (and hence wrong) and for the local path the space
693 // info is related to the windows partition (-> correct).
694 const QString
localPath(fileItem
->localPath());
695 if (localPath
.isEmpty()) {
696 setUrl(fileItem
->url());
699 setUrl(KUrl(localPath
));
707 void DolphinView::slotPercent(int percent
)
709 if (m_showProgress
) {
710 m_statusBar
->setProgress(percent
);
714 void DolphinView::slotClear()
716 //fileView()->clearView();
720 void DolphinView::slotDeleteItem(KFileItem
* item
)
722 //fileView()->removeItem(item);
726 void DolphinView::slotCompleted()
730 //KFileView* view = fileView();
733 // TODO: in Qt4 the code should get a lot
734 // simpler and nicer due to Interview...
735 /*if (m_iconsView != 0) {
736 m_iconsView->beginItemUpdates();
738 if (m_iconsView != 0) {
739 m_iconsView->beginItemUpdates();
742 if (m_showProgress
) {
743 m_statusBar
->setProgressText(QString::null
);
744 m_statusBar
->setProgress(100);
745 m_showProgress
= false;
748 KFileItemList
items(m_dirLister
->items());
749 KFileItemList::const_iterator it
= items
.begin();
750 const KFileItemList::const_iterator end
= items
.end();
756 KFileItem
* item
= *it
;
757 //view->insertItem(item);
769 /*if (m_iconsView != 0) {
770 // Prevent a flickering of the icon view widget by giving a small
771 // timeslot to swallow asynchronous update events.
772 m_iconsView->setUpdatesEnabled(false);
773 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
776 if (m_iconsView != 0) {
777 m_iconsView->endItemUpdates();
778 m_refreshing = false;
782 void DolphinView::slotInfoMessage(const QString
& msg
)
784 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
787 void DolphinView::slotErrorMessage(const QString
& msg
)
789 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
792 void DolphinView::slotGrabActivation()
794 mainWindow()->setActiveView(this);
797 void DolphinView::emitSelectionChangedSignal()
799 emit
selectionChanged();
802 void DolphinView::closeFilterBar()
805 emit
showFilterBarChanged(false);
808 void DolphinView::slotContentsMoving(int x
, int y
)
811 // Only emit a 'contents moved' signal if the user
812 // moved the content by adjusting the sliders. Adjustments
813 // resulted by refreshing a directory should not be respected.
814 emit
contentsMoved(x
, y
);
818 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
820 if (!url
.isValid()) {
821 const QString
location(url
.pathOrUrl());
822 if (location
.isEmpty()) {
823 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
826 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
827 DolphinStatusBar::Error
);
832 // Only show the directory loading progress if the status bar does
833 // not contain another progress information. This means that
834 // the directory loading progress information has the lowest priority.
835 const QString
progressText(m_statusBar
->progressText());
836 m_showProgress
= progressText
.isEmpty() ||
837 (progressText
== i18n("Loading directory..."));
838 if (m_showProgress
) {
839 m_statusBar
->setProgressText(i18n("Loading directory..."));
840 m_statusBar
->setProgress(0);
845 m_dirLister
->openUrl(url
, false, reload
);
848 QString
DolphinView::defaultStatusBarText() const
850 // TODO: the following code is not suitable for languages where multiple forms
851 // of plurals are given (e. g. in Poland three forms of plurals exist).
852 const int itemCount
= m_folderCount
+ m_fileCount
;
855 if (itemCount
== 1) {
856 text
= i18n("1 Item");
859 text
= i18n("%1 Items",itemCount
);
864 if (m_folderCount
== 1) {
865 text
+= i18n("1 Folder");
868 text
+= i18n("%1 Folders",m_folderCount
);
873 if (m_fileCount
== 1) {
874 text
+= i18n("1 File");
877 text
+= i18n("%1 Files",m_fileCount
);
885 QString
DolphinView::selectionStatusBarText() const
887 // TODO: the following code is not suitable for languages where multiple forms
888 // of plurals are given (e. g. in Poland three forms of plurals exist).
890 const KFileItemList list
= selectedItems();
891 if (list
.isEmpty()) {
892 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
893 // DolphinView::hasSelection() is true. Inconsistent behavior?
899 KIO::filesize_t byteSize
= 0;
900 KFileItemList::const_iterator it
= list
.begin();
901 const KFileItemList::const_iterator end
= list
.end();
903 KFileItem
* item
= *it
;
909 byteSize
+= item
->size();
914 if (folderCount
== 1) {
915 text
= i18n("1 Folder selected");
917 else if (folderCount
> 1) {
918 text
= i18n("%1 Folders selected",folderCount
);
921 if ((fileCount
> 0) && (folderCount
> 0)) {
925 const QString
sizeText(KIO::convertSize(byteSize
));
926 if (fileCount
== 1) {
927 text
+= i18n("1 File selected (%1)",sizeText
);
929 else if (fileCount
> 1) {
930 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
936 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
938 // assure that the string reprentation for all indicess have the same
939 // number of characters based on the given number of items
940 QString
str(QString::number(index
));
942 while (itemCount
>= 10) {
946 str
.reserve(chrCount
);
948 const int insertCount
= chrCount
- str
.length();
949 for (int i
= 0; i
< insertCount
; ++i
) {
955 void DolphinView::slotShowFilterBar(bool show
)
957 assert(m_filterBar
!= 0);
966 void DolphinView::declareViewActive()
968 mainWindow()->setActiveView( this );
971 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
973 // The name filter of KDirLister does a 'hard' filtering, which
974 // means that only the items are shown where the names match
975 // exactly the filter. This is non-transparent for the user, which
976 // just wants to have a 'soft' filtering: does the name contain
977 // the filter string?
978 QString
adjustedFilter(nameFilter
);
979 adjustedFilter
.insert(0, '*');
980 adjustedFilter
.append('*');
982 m_dirLister
->setNameFilter(adjustedFilter
);
983 m_dirLister
->emitChanges();
986 void DolphinView::applyModeToView()
988 //m_iconsView->setAlternatingRowColors(true);
989 m_iconsView
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
991 // TODO: the following code just tries to test some QListView capabilities
994 m_iconsView
->setViewMode(QListView::IconMode
);
995 m_iconsView
->setGridSize(QSize(128, 64));
999 m_iconsView
->setViewMode(QListView::ListMode
);
1000 m_iconsView
->setGridSize(QSize(256, 24));
1005 int DolphinView::columnIndex(Sorting sorting
) const
1009 case SortByName
: index
= KDirModel::Name
; break;
1010 case SortBySize
: index
= KDirModel::Size
; break;
1011 case SortByDate
: index
= KDirModel::ModifiedTime
; break;
1012 default: assert(false);
1017 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1019 QItemSelectionModel
* selectionModel
= m_iconsView
->selectionModel();
1020 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1022 const QModelIndex topLeft
= itemModel
->index(0, 0);
1023 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1024 itemModel
->columnCount() - 1);
1026 QItemSelection
selection(topLeft
, bottomRight
);
1027 selectionModel
->select(selection
, flags
);
1030 #include "dolphinview.moc"