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
),
74 setFocusPolicy(Qt::StrongFocus
);
75 m_topLayout
= new QVBoxLayout(this);
76 m_topLayout
->setSpacing(0);
77 m_topLayout
->setMargin(0);
79 m_urlNavigator
= new UrlNavigator(url
, this);
80 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
81 this, SLOT(loadDirectory(const KUrl
&)));
83 m_statusBar
= new DolphinStatusBar(this);
85 m_dirLister
= new DolphinDirLister();
86 m_dirLister
->setAutoUpdate(true);
87 m_dirLister
->setMainWindow(this);
88 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
89 connect(m_dirLister
, SIGNAL(clear()),
90 this, SLOT(slotClear()));
91 connect(m_dirLister
, SIGNAL(percent(int)),
92 this, SLOT(slotPercent(int)));
93 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
94 this, SLOT(slotDeleteItem(KFileItem
*)));
95 connect(m_dirLister
, SIGNAL(completed()),
96 this, SLOT(slotCompleted()));
97 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
98 this, SLOT(slotInfoMessage(const QString
&)));
99 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
100 this, SLOT(slotErrorMessage(const QString
&)));
102 m_iconsView
= new DolphinIconsView(this);
105 KDirModel
* model
= new KDirModel();
106 model
->setDirLister(m_dirLister
);
108 m_proxyModel
= new DolphinSortFilterProxyModel(this);
109 m_proxyModel
->setSourceModel(model
);
110 m_proxyModel
->setDynamicSortFilter(true);
112 m_iconsView
->setModel(model
);
114 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
115 m_iconsView
->setItemDelegate(delegate
);
117 m_dirLister
->setDelayedMimeTypes(true);
118 new KMimeTypeResolver(m_iconsView
, model
);
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 KDirModel
* dirModel
= static_cast<KDirModel
*>(m_iconsView
->model());
480 const QModelIndexList indexList
= selModel
->selectedIndexes();
482 QModelIndexList::const_iterator end
= indexList
.end();
483 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
484 KFileItem
* item
= dirModel
->itemForIndex(*it
);
486 itemList
.append(item
);
493 KUrl::List
DolphinView::selectedUrls() const
497 const KFileItemList list
= selectedItems();
498 KFileItemList::const_iterator it
= list
.begin();
499 const KFileItemList::const_iterator end
= list
.end();
501 KFileItem
* item
= *it
;
502 urls
.append(item
->url());
509 const KFileItem
* DolphinView::currentFileItem() const
511 return 0; // fileView()->currentFileItem();
514 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
516 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
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::RenameDlg
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
);
568 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
569 DolphinStatusBar::OperationCompleted
);
571 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
572 UndoManager::instance().addCommand(command
);
575 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
576 DolphinStatusBar::Error
);
581 void DolphinView::reload()
583 startDirLister(m_urlNavigator
->url(), true);
586 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
587 const KUrl::List
& urls
,
590 KUrl
destination(url
);
591 if (destination
.isEmpty()) {
592 destination
= m_urlNavigator
->url();
595 // Check whether the destination Url is a directory. If this is not the
596 // case, use the navigator Url as destination (otherwise the destination,
597 // which represents a file, would be replaced by a copy- or move-operation).
598 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
599 if (!fileItem
.isDir()) {
600 destination
= m_urlNavigator
->url();
604 mainWindow()->dropUrls(urls
, destination
);
607 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
609 QWidget::mouseReleaseEvent(event
);
610 mainWindow()->setActiveView(this);
613 DolphinMainWindow
* DolphinView::mainWindow() const
618 void DolphinView::loadDirectory(const KUrl
& url
)
620 const ViewProperties
props(url
);
621 setMode(props
.viewMode());
623 const bool showHiddenFiles
= props
.showHiddenFiles();
624 setShowHiddenFiles(showHiddenFiles
);
625 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
627 setSorting(props
.sorting());
628 setSortOrder(props
.sortOrder());
631 emit
urlChanged(url
);
634 void DolphinView::triggerIconsViewItem(Q3IconViewItem
* item
)
637 const Qt::ButtonState keyboardState = KApplication::keyboardMouseState();
638 const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) ||
639 ((keyboardState & Qt::ControlModifier) > 0);*/
640 const bool isSelectionActive
= false;
641 if ((item
!= 0) && !isSelectionActive
) {
642 // Updating the Url must be done outside the scope of this slot,
643 // as iconview items will get deleted.
644 QTimer::singleShot(0, this, SLOT(updateUrl()));
645 mainWindow()->setActiveView(this);
649 void DolphinView::triggerItem(const QModelIndex
& index
)
651 KDirModel
* dirModel
= static_cast<KDirModel
*>(m_iconsView
->model());
652 KFileItem
* item
= dirModel
->itemForIndex(index
);
658 // Prefer the local path over the Url. This assures that the
659 // volume space information is correct. Assuming that the Url is media:/sda1,
660 // and the local path is /windows/C: For the Url the space info is related
661 // to the root partition (and hence wrong) and for the local path the space
662 // info is related to the windows partition (-> correct).
663 //m_dirLister->stop();
664 //m_dirLister->openUrl(item->url());
667 const QString
localPath(item
->localPath());
668 if (localPath
.isEmpty()) {
672 setUrl(KUrl(localPath
));
680 void DolphinView::updateUrl()
682 //KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
683 // static_cast<KFileView*>(m_iconsView);
685 KFileItem
* fileItem
= 0; // TODO: fileView->currentFileItem();
690 if (fileItem
->isDir()) {
691 // Prefer the local path over the Url. This assures that the
692 // volume space information is correct. Assuming that the Url is media:/sda1,
693 // and the local path is /windows/C: For the Url the space info is related
694 // to the root partition (and hence wrong) and for the local path the space
695 // info is related to the windows partition (-> correct).
696 const QString
localPath(fileItem
->localPath());
697 if (localPath
.isEmpty()) {
698 setUrl(fileItem
->url());
701 setUrl(KUrl(localPath
));
709 void DolphinView::slotPercent(int percent
)
711 if (m_showProgress
) {
712 m_statusBar
->setProgress(percent
);
716 void DolphinView::slotClear()
718 //fileView()->clearView();
722 void DolphinView::slotDeleteItem(KFileItem
* item
)
724 //fileView()->removeItem(item);
728 void DolphinView::slotCompleted()
732 //KFileView* view = fileView();
735 // TODO: in Qt4 the code should get a lot
736 // simpler and nicer due to Interview...
737 /*if (m_iconsView != 0) {
738 m_iconsView->beginItemUpdates();
740 if (m_iconsView != 0) {
741 m_iconsView->beginItemUpdates();
744 if (m_showProgress
) {
745 m_statusBar
->setProgressText(QString::null
);
746 m_statusBar
->setProgress(100);
747 m_showProgress
= false;
750 KFileItemList
items(m_dirLister
->items());
751 KFileItemList::const_iterator it
= items
.begin();
752 const KFileItemList::const_iterator end
= items
.end();
758 KFileItem
* item
= *it
;
759 //view->insertItem(item);
771 /*if (m_iconsView != 0) {
772 // Prevent a flickering of the icon view widget by giving a small
773 // timeslot to swallow asynchronous update events.
774 m_iconsView->setUpdatesEnabled(false);
775 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
778 if (m_iconsView != 0) {
779 m_iconsView->endItemUpdates();
780 m_refreshing = false;
784 void DolphinView::slotInfoMessage(const QString
& msg
)
786 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
789 void DolphinView::slotErrorMessage(const QString
& msg
)
791 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
794 void DolphinView::slotGrabActivation()
796 mainWindow()->setActiveView(this);
799 void DolphinView::emitSelectionChangedSignal()
801 emit
selectionChanged();
804 void DolphinView::closeFilterBar()
807 emit
showFilterBarChanged(false);
810 void DolphinView::slotContentsMoving(int x
, int y
)
813 // Only emit a 'contents moved' signal if the user
814 // moved the content by adjusting the sliders. Adjustments
815 // resulted by refreshing a directory should not be respected.
816 emit
contentsMoved(x
, y
);
820 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
822 if (!url
.isValid()) {
823 const QString
location(url
.pathOrUrl());
824 if (location
.isEmpty()) {
825 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
828 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
829 DolphinStatusBar::Error
);
834 // Only show the directory loading progress if the status bar does
835 // not contain another progress information. This means that
836 // the directory loading progress information has the lowest priority.
837 const QString
progressText(m_statusBar
->progressText());
838 m_showProgress
= progressText
.isEmpty() ||
839 (progressText
== i18n("Loading directory..."));
840 if (m_showProgress
) {
841 m_statusBar
->setProgressText(i18n("Loading directory..."));
842 m_statusBar
->setProgress(0);
847 m_dirLister
->openUrl(url
, false, reload
);
850 QString
DolphinView::defaultStatusBarText() const
852 // TODO: the following code is not suitable for languages where multiple forms
853 // of plurals are given (e. g. in Poland three forms of plurals exist).
854 const int itemCount
= m_folderCount
+ m_fileCount
;
857 if (itemCount
== 1) {
858 text
= i18n("1 Item");
861 text
= i18n("%1 Items",itemCount
);
866 if (m_folderCount
== 1) {
867 text
+= i18n("1 Folder");
870 text
+= i18n("%1 Folders",m_folderCount
);
875 if (m_fileCount
== 1) {
876 text
+= i18n("1 File");
879 text
+= i18n("%1 Files",m_fileCount
);
887 QString
DolphinView::selectionStatusBarText() const
889 // TODO: the following code is not suitable for languages where multiple forms
890 // of plurals are given (e. g. in Poland three forms of plurals exist).
892 const KFileItemList list
= selectedItems();
893 if (list
.isEmpty()) {
894 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
895 // DolphinView::hasSelection() is true. Inconsistent behavior?
901 KIO::filesize_t byteSize
= 0;
902 KFileItemList::const_iterator it
= list
.begin();
903 const KFileItemList::const_iterator end
= list
.end();
905 KFileItem
* item
= *it
;
911 byteSize
+= item
->size();
916 if (folderCount
== 1) {
917 text
= i18n("1 Folder selected");
919 else if (folderCount
> 1) {
920 text
= i18n("%1 Folders selected",folderCount
);
923 if ((fileCount
> 0) && (folderCount
> 0)) {
927 const QString
sizeText(KIO::convertSize(byteSize
));
928 if (fileCount
== 1) {
929 text
+= i18n("1 File selected (%1)",sizeText
);
931 else if (fileCount
> 1) {
932 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
938 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
940 // assure that the string reprentation for all indicess have the same
941 // number of characters based on the given number of items
942 QString
str(QString::number(index
));
944 while (itemCount
>= 10) {
948 str
.reserve(chrCount
);
950 const int insertCount
= chrCount
- str
.length();
951 for (int i
= 0; i
< insertCount
; ++i
) {
957 void DolphinView::slotShowFilterBar(bool show
)
959 assert(m_filterBar
!= 0);
968 void DolphinView::declareViewActive()
970 mainWindow()->setActiveView( this );
973 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
975 // The name filter of KDirLister does a 'hard' filtering, which
976 // means that only the items are shown where the names match
977 // exactly the filter. This is non-transparent for the user, which
978 // just wants to have a 'soft' filtering: does the name contain
979 // the filter string?
980 QString
adjustedFilter(nameFilter
);
981 adjustedFilter
.insert(0, '*');
982 adjustedFilter
.append('*');
984 m_dirLister
->setNameFilter(adjustedFilter
);
985 m_dirLister
->emitChanges();
988 void DolphinView::applyModeToView()
990 //m_iconsView->setAlternatingRowColors(true);
991 m_iconsView
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
993 // TODO: the following code just tries to test some QListView capabilities
996 m_iconsView
->setViewMode(QListView::IconMode
);
997 m_iconsView
->setGridSize(QSize(128, 64));
1001 m_iconsView
->setViewMode(QListView::ListMode
);
1002 m_iconsView
->setGridSize(QSize(256, 24));
1007 int DolphinView::columnIndex(Sorting sorting
) const
1011 case SortByName
: index
= KDirModel::Name
; break;
1012 case SortBySize
: index
= KDirModel::Size
; break;
1013 case SortByDate
: index
= KDirModel::ModifiedTime
; break;
1014 default: assert(false);
1019 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1021 QItemSelectionModel
* selectionModel
= m_iconsView
->selectionModel();
1022 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1024 const QModelIndex topLeft
= itemModel
->index(0, 0);
1025 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1026 itemModel
->columnCount() - 1);
1028 QItemSelection
selection(topLeft
, bottomRight
);
1029 selectionModel
->select(selection
, flags
);
1032 #include "dolphinview.moc"