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"
25 #include <QItemSelectionModel>
26 #include <Q3ValueList> // TODO
28 #include <QMouseEvent>
29 #include <QVBoxLayout>
31 #include <kdirmodel.h>
32 #include <kfileitemdelegate.h>
34 #include <kio/netaccess.h>
35 #include <kio/renamedialog.h>
36 #include <kmimetyperesolver.h>
37 #include <konq_operations.h>
40 #include "dolphinstatusbar.h"
41 #include "dolphinmainwindow.h"
42 #include "dolphindirlister.h"
43 #include "dolphinsortfilterproxymodel.h"
44 #include "dolphindetailsview.h"
45 #include "dolphiniconsview.h"
46 #include "dolphincontextmenu.h"
47 #include "filterbar.h"
48 #include "renamedialog.h"
49 #include "urlnavigator.h"
50 #include "viewproperties.h"
52 DolphinView::DolphinView(DolphinMainWindow
*mainWindow
,
56 bool showHiddenFiles
) :
59 m_showProgress(false),
64 m_mainWindow(mainWindow
),
76 setFocusPolicy(Qt::StrongFocus
);
77 m_topLayout
= new QVBoxLayout(this);
78 m_topLayout
->setSpacing(0);
79 m_topLayout
->setMargin(0);
81 m_urlNavigator
= new UrlNavigator(url
, this);
82 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
83 this, SLOT(loadDirectory(const KUrl
&)));
85 m_statusBar
= new DolphinStatusBar(this);
87 m_dirLister
= new DolphinDirLister();
88 m_dirLister
->setAutoUpdate(true);
89 m_dirLister
->setMainWindow(this);
90 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
91 m_dirLister
->setDelayedMimeTypes(true);
93 connect(m_dirLister
, SIGNAL(clear()),
94 this, SLOT(slotClear()));
95 connect(m_dirLister
, SIGNAL(percent(int)),
96 this, SLOT(slotPercent(int)));
97 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
98 this, SLOT(slotDeleteItem(KFileItem
*)));
99 connect(m_dirLister
, SIGNAL(completed()),
100 this, SLOT(slotCompleted()));
101 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
102 this, SLOT(slotInfoMessage(const QString
&)));
103 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
104 this, SLOT(slotErrorMessage(const QString
&)));
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
);
115 m_iconSize
= K3Icon::SizeMedium
;
117 m_filterBar
= new FilterBar(this);
119 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
120 this, SLOT(slotChangeNameFilter(const QString
&)));
121 connect(m_filterBar
, SIGNAL(closed()),
122 this, SLOT(closeFilterBar()));
124 m_topLayout
->addWidget(m_urlNavigator
);
125 m_topLayout
->addWidget(itemView());
126 m_topLayout
->addWidget(m_filterBar
);
127 m_topLayout
->addWidget(m_statusBar
);
129 loadDirectory(m_urlNavigator
->url());
132 DolphinView::~DolphinView()
138 void DolphinView::setUrl(const KUrl
& url
)
140 m_urlNavigator
->setUrl(url
);
143 const KUrl
& DolphinView::url() const
145 return m_urlNavigator
->url();
148 void DolphinView::requestActivation()
150 mainWindow()->setActiveView(this);
153 bool DolphinView::isActive() const
155 return (mainWindow()->activeView() == this);
158 void DolphinView::setMode(Mode mode
)
160 if (mode
== m_mode
) {
161 return; // the wished mode is already set
166 ViewProperties
props(m_urlNavigator
->url());
167 props
.setViewMode(m_mode
);
170 startDirLister(m_urlNavigator
->url());
175 DolphinView::Mode
DolphinView::mode() const
180 void DolphinView::setShowPreview(bool show
)
182 ViewProperties
props(m_urlNavigator
->url());
183 props
.setShowPreview(show
);
185 // TODO: wait until previews are possible with KFileItemDelegate
187 emit
showPreviewChanged();
190 bool DolphinView::showPreview() const
192 // TODO: wait until previews are possible with KFileItemDelegate
196 void DolphinView::setShowHiddenFiles(bool show
)
198 if (m_dirLister
->showingDotFiles() == show
) {
202 ViewProperties
props(m_urlNavigator
->url());
203 props
.setShowHiddenFiles(show
);
206 m_dirLister
->setShowingDotFiles(show
);
208 emit
showHiddenFilesChanged();
213 bool DolphinView::showHiddenFiles() const
215 return m_dirLister
->showingDotFiles();
218 void DolphinView::renameSelectedItems()
220 const KUrl::List urls
= selectedUrls();
221 if (urls
.count() > 1) {
222 // More than one item has been selected for renaming. Open
223 // a rename dialog and rename all items afterwards.
224 RenameDialog
dialog(urls
);
225 if (dialog
.exec() == QDialog::Rejected
) {
229 DolphinView
* view
= mainWindow()->activeView();
230 const QString
& newName
= dialog
.newName();
231 if (newName
.isEmpty()) {
232 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
233 DolphinStatusBar::Error
);
236 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
238 //UndoManager& undoMan = UndoManager::instance();
239 //undoMan.beginMacro();
241 assert(newName
.contains('#'));
243 const int urlsCount
= urls
.count();
245 // iterate through all selected items and rename them...
246 const int replaceIndex
= newName
.indexOf('#');
247 assert(replaceIndex
>= 0);
248 for (int i
= 0; i
< urlsCount
; ++i
) {
249 const KUrl
& source
= urls
[i
];
250 QString
name(newName
);
251 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
253 if (source
.fileName() != name
) {
254 KUrl
dest(source
.upUrl());
257 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
259 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
260 DolphinStatusBar::Error
);
263 else if (KIO::NetAccess::file_move(source
, dest
)) {
264 // TODO: From the users point of view he executed one 'rename n files' operation,
265 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
266 //DolphinCommand command(DolphinCommand::Rename, source, dest);
267 //undoMan.addCommand(command);
272 //undoMan.endMacro();
276 // Only one item has been selected for renaming. Use the custom
277 // renaming mechanism from the views.
278 assert(urls
.count() == 1);
280 /*if (m_mode == DetailsView) {
281 Q3ListViewItem* item = m_iconsView->firstChild();
283 if (item->isSelected()) {
284 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
287 item = item->nextSibling();
291 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
293 if (item->isSelected()) {
297 item = static_cast<KFileIconViewItem*>(item->nextItem());
303 void DolphinView::selectAll()
305 selectAll(QItemSelectionModel::Select
);
308 void DolphinView::invertSelection()
310 selectAll(QItemSelectionModel::Toggle
);
313 DolphinStatusBar
* DolphinView::statusBar() const
318 int DolphinView::contentsX() const
321 return 0; //scrollView()->contentsX();
324 int DolphinView::contentsY() const
326 return 0; //scrollView()->contentsY();
329 void DolphinView::refreshSettings()
331 startDirLister(m_urlNavigator
->url());
334 void DolphinView::updateStatusBar()
336 // As the item count information is less important
337 // in comparison with other messages, it should only
339 // - the status bar is empty or
340 // - shows already the item count information or
341 // - shows only a not very important information
342 // - if any progress is given don't show the item count info at all
343 const QString
msg(m_statusBar
->message());
344 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
345 (msg
== m_statusBar
->defaultText()) ||
346 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
347 (m_statusBar
->progress() == 100);
349 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
350 m_statusBar
->setDefaultText(text
);
352 if (updateStatusBarMsg
) {
353 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
357 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
359 emit
requestItemInfo(url
);
362 bool DolphinView::isFilterBarVisible() const
364 return m_filterBar
->isVisible();
367 bool DolphinView::isUrlEditable() const
369 return m_urlNavigator
->isUrlEditable();
372 void DolphinView::zoomIn()
374 //itemEffectsManager()->zoomIn();
377 void DolphinView::zoomOut()
379 //itemEffectsManager()->zoomOut();
382 bool DolphinView::isZoomInPossible() const
384 return false; //itemEffectsManager()->isZoomInPossible();
387 bool DolphinView::isZoomOutPossible() const
389 return false; //itemEffectsManager()->isZoomOutPossible();
392 void DolphinView::setSorting(Sorting sorting
)
394 if (sorting
!= this->sorting()) {
395 ViewProperties
props(url());
396 props
.setSorting(sorting
);
398 m_proxyModel
->setSorting(sorting
);
400 emit
sortingChanged(sorting
);
404 DolphinView::Sorting
DolphinView::sorting() const
406 return m_proxyModel
->sorting();
409 void DolphinView::setSortOrder(Qt::SortOrder order
)
411 if (sortOrder() != order
) {
412 ViewProperties
props(url());
413 props
.setSortOrder(order
);
415 m_proxyModel
->setSortOrder(order
);
417 emit
sortOrderChanged(order
);
421 Qt::SortOrder
DolphinView::sortOrder() const
423 return m_proxyModel
->sortOrder();
426 void DolphinView::goBack()
428 m_urlNavigator
->goBack();
431 void DolphinView::goForward()
433 m_urlNavigator
->goForward();
436 void DolphinView::goUp()
438 m_urlNavigator
->goUp();
441 void DolphinView::goHome()
443 m_urlNavigator
->goHome();
446 void DolphinView::setUrlEditable(bool editable
)
448 m_urlNavigator
->editUrl(editable
);
451 const Q3ValueList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
453 return m_urlNavigator
->history(index
);
456 bool DolphinView::hasSelection() const
458 return itemView()->selectionModel()->hasSelection();
461 KFileItemList
DolphinView::selectedItems() const
463 const QAbstractItemView
* view
= itemView();
465 // Our view has a selection, we will map them back to the DirModel
466 // and then fill the KFileItemList.
467 assert((view
!= 0) && (view
->selectionModel() != 0));
469 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
470 KFileItemList itemList
;
472 const QModelIndexList indexList
= selection
.indexes();
473 QModelIndexList::const_iterator end
= indexList
.end();
474 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
475 assert((*it
).isValid());
477 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
479 itemList
.append(item
);
486 KUrl::List
DolphinView::selectedUrls() const
490 const KFileItemList list
= selectedItems();
491 KFileItemList::const_iterator it
= list
.begin();
492 const KFileItemList::const_iterator end
= list
.end();
494 KFileItem
* item
= *it
;
495 urls
.append(item
->url());
502 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
504 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
505 return m_dirModel
->itemForIndex(dirModelIndex
);
508 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
510 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
514 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
518 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
522 KUrl
dest(source
.upUrl());
523 dest
.addPath(newName
);
525 const bool destExists
= KIO::NetAccess::exists(dest
,
527 mainWindow()->activeView());
529 // the destination already exists, hence ask the user
531 KIO::RenameDialog
renameDialog(this,
532 i18n("File Already Exists"),
536 switch (renameDialog
.exec()) {
537 case KIO::R_OVERWRITE
:
538 // the destination should be overwritten
539 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
542 case KIO::R_RENAME
: {
543 // a new name for the destination has been used
544 KUrl
newDest(renameDialog
.newDestUrl());
545 ok
= KIO::NetAccess::file_move(source
, newDest
);
550 // the renaming operation has been canceled
556 // no destination exists, hence just move the file to
558 ok
= KIO::NetAccess::file_move(source
, dest
);
561 const QString destFileName
= dest
.fileName();
563 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
564 DolphinStatusBar::OperationCompleted
);
566 KonqOperations::rename(this, source
, destFileName
);
569 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
570 DolphinStatusBar::Error
);
575 void DolphinView::reload()
577 startDirLister(m_urlNavigator
->url(), true);
580 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
581 const KUrl::List
& urls
,
584 KUrl
destination(url
);
585 if (destination
.isEmpty()) {
586 destination
= m_urlNavigator
->url();
589 // Check whether the destination Url is a directory. If this is not the
590 // case, use the navigator Url as destination (otherwise the destination,
591 // which represents a file, would be replaced by a copy- or move-operation).
592 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
593 if (!fileItem
.isDir()) {
594 destination
= m_urlNavigator
->url();
598 mainWindow()->dropUrls(urls
, destination
);
601 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
603 QWidget::mouseReleaseEvent(event
);
604 mainWindow()->setActiveView(this);
607 DolphinMainWindow
* DolphinView::mainWindow() const
612 void DolphinView::loadDirectory(const KUrl
& url
)
614 const ViewProperties
props(url
);
616 const Mode mode
= props
.viewMode();
617 if (m_mode
!= mode
) {
623 const bool showHiddenFiles
= props
.showHiddenFiles();
624 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
625 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
626 emit
showHiddenFilesChanged();
629 const DolphinView::Sorting sorting
= props
.sorting();
630 if (sorting
!= m_proxyModel
->sorting()) {
631 m_proxyModel
->setSorting(sorting
);
632 emit
sortingChanged(sorting
);
635 const Qt::SortOrder sortOrder
= props
.sortOrder();
636 if (sortOrder
!= m_proxyModel
->sortOrder()) {
637 m_proxyModel
->setSortOrder(sortOrder
);
638 emit
sortOrderChanged(sortOrder
);
641 // TODO: handle previews (props.showPreview())
644 emit
urlChanged(url
);
647 void DolphinView::triggerItem(const QModelIndex
& index
)
649 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
655 // Prefer the local path over the Url. This assures that the
656 // volume space information is correct. Assuming that the Url is media:/sda1,
657 // and the local path is /windows/C: For the Url the space info is related
658 // to the root partition (and hence wrong) and for the local path the space
659 // info is related to the windows partition (-> correct).
660 //m_dirLister->stop();
661 //m_dirLister->openUrl(item->url());
664 const QString
localPath(item
->localPath());
665 if (localPath
.isEmpty()) {
669 setUrl(KUrl(localPath
));
677 void DolphinView::slotPercent(int percent
)
679 if (m_showProgress
) {
680 m_statusBar
->setProgress(percent
);
684 void DolphinView::slotClear()
686 //fileView()->clearView();
690 void DolphinView::slotDeleteItem(KFileItem
* item
)
692 //fileView()->removeItem(item);
696 void DolphinView::slotCompleted()
700 //KFileView* view = fileView();
703 // TODO: in Qt4 the code should get a lot
704 // simpler and nicer due to Interview...
705 /*if (m_iconsView != 0) {
706 m_iconsView->beginItemUpdates();
708 if (m_iconsView != 0) {
709 m_iconsView->beginItemUpdates();
712 if (m_showProgress
) {
713 m_statusBar
->setProgressText(QString::null
);
714 m_statusBar
->setProgress(100);
715 m_showProgress
= false;
718 KFileItemList
items(m_dirLister
->items());
719 KFileItemList::const_iterator it
= items
.begin();
720 const KFileItemList::const_iterator end
= items
.end();
726 KFileItem
* item
= *it
;
727 //view->insertItem(item);
739 /*if (m_iconsView != 0) {
740 // Prevent a flickering of the icon view widget by giving a small
741 // timeslot to swallow asynchronous update events.
742 m_iconsView->setUpdatesEnabled(false);
743 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
746 if (m_iconsView != 0) {
747 m_iconsView->endItemUpdates();
748 m_refreshing = false;
752 void DolphinView::slotInfoMessage(const QString
& msg
)
754 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
757 void DolphinView::slotErrorMessage(const QString
& msg
)
759 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
762 void DolphinView::slotGrabActivation()
764 mainWindow()->setActiveView(this);
767 void DolphinView::emitSelectionChangedSignal()
769 emit
selectionChanged();
772 void DolphinView::closeFilterBar()
775 emit
showFilterBarChanged(false);
778 void DolphinView::slotContentsMoving(int x
, int y
)
781 // Only emit a 'contents moved' signal if the user
782 // moved the content by adjusting the sliders. Adjustments
783 // resulted by refreshing a directory should not be respected.
784 emit
contentsMoved(x
, y
);
788 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
790 if (!url
.isValid()) {
791 const QString
location(url
.pathOrUrl());
792 if (location
.isEmpty()) {
793 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
796 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
797 DolphinStatusBar::Error
);
802 // Only show the directory loading progress if the status bar does
803 // not contain another progress information. This means that
804 // the directory loading progress information has the lowest priority.
805 const QString
progressText(m_statusBar
->progressText());
806 m_showProgress
= progressText
.isEmpty() ||
807 (progressText
== i18n("Loading directory..."));
808 if (m_showProgress
) {
809 m_statusBar
->setProgressText(i18n("Loading directory..."));
810 m_statusBar
->setProgress(0);
815 m_dirLister
->openUrl(url
, false, reload
);
818 QString
DolphinView::defaultStatusBarText() const
820 // TODO: the following code is not suitable for languages where multiple forms
821 // of plurals are given (e. g. in Poland three forms of plurals exist).
822 const int itemCount
= m_folderCount
+ m_fileCount
;
825 if (itemCount
== 1) {
826 text
= i18n("1 Item");
829 text
= i18n("%1 Items",itemCount
);
834 if (m_folderCount
== 1) {
835 text
+= i18n("1 Folder");
838 text
+= i18n("%1 Folders",m_folderCount
);
843 if (m_fileCount
== 1) {
844 text
+= i18n("1 File");
847 text
+= i18n("%1 Files",m_fileCount
);
855 QString
DolphinView::selectionStatusBarText() const
857 // TODO: the following code is not suitable for languages where multiple forms
858 // of plurals are given (e. g. in Poland three forms of plurals exist).
860 const KFileItemList list
= selectedItems();
861 if (list
.isEmpty()) {
862 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
863 // DolphinView::hasSelection() is true. Inconsistent behavior?
869 KIO::filesize_t byteSize
= 0;
870 KFileItemList::const_iterator it
= list
.begin();
871 const KFileItemList::const_iterator end
= list
.end();
873 KFileItem
* item
= *it
;
879 byteSize
+= item
->size();
884 if (folderCount
== 1) {
885 text
= i18n("1 Folder selected");
887 else if (folderCount
> 1) {
888 text
= i18n("%1 Folders selected",folderCount
);
891 if ((fileCount
> 0) && (folderCount
> 0)) {
895 const QString
sizeText(KIO::convertSize(byteSize
));
896 if (fileCount
== 1) {
897 text
+= i18n("1 File selected (%1)",sizeText
);
899 else if (fileCount
> 1) {
900 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
906 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
908 // assure that the string reprentation for all indicess have the same
909 // number of characters based on the given number of items
910 QString
str(QString::number(index
));
912 while (itemCount
>= 10) {
916 str
.reserve(chrCount
);
918 const int insertCount
= chrCount
- str
.length();
919 for (int i
= 0; i
< insertCount
; ++i
) {
925 void DolphinView::slotShowFilterBar(bool show
)
927 assert(m_filterBar
!= 0);
936 void DolphinView::declareViewActive()
938 mainWindow()->setActiveView( this );
941 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
943 // The name filter of KDirLister does a 'hard' filtering, which
944 // means that only the items are shown where the names match
945 // exactly the filter. This is non-transparent for the user, which
946 // just wants to have a 'soft' filtering: does the name contain
947 // the filter string?
948 QString
adjustedFilter(nameFilter
);
949 adjustedFilter
.insert(0, '*');
950 adjustedFilter
.append('*');
952 // Use the ProxyModel to filter:
953 // This code is #ifdefed as setNameFilter behaves
954 // slightly different than the QSortFilterProxyModel
955 // as it will not remove directories. I will ask
956 // our beloved usability experts for input
959 m_dirLister
->setNameFilter(adjustedFilter
);
960 m_dirLister
->emitChanges();
962 m_proxyModel
->setFilterRegExp( nameFilter
);
966 void DolphinView::createView()
968 // delete current view
969 QAbstractItemView
* view
= itemView();
971 m_topLayout
->remove(view
);
978 assert(m_iconsView
== 0);
979 assert(m_detailsView
== 0);
981 // ... and recreate it representing the current mode
984 m_iconsView
= new DolphinIconsView(this);
985 m_iconsView
->setViewMode(QListView::IconMode
);
986 m_iconsView
->setSpacing(32);
988 // TODO: read out view settings
992 m_detailsView
= new DolphinDetailsView(this);
993 view
= m_detailsView
;
994 // TODO: read out view settings
998 view
->setModel(m_proxyModel
);
1000 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1002 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
1003 delegate
->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType
);
1004 view
->setItemDelegate(delegate
);
1006 new KMimeTypeResolver(view
, m_dirModel
);
1008 connect(view
, SIGNAL(clicked(const QModelIndex
&)),
1009 this, SLOT(triggerItem(const QModelIndex
&)));
1010 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1011 this, SLOT(emitSelectionChangedSignal()));
1013 m_topLayout
->insertWidget(1, view
);
1016 int DolphinView::columnIndex(Sorting sorting
) const
1020 case SortByName
: index
= KDirModel::Name
; break;
1021 case SortBySize
: index
= KDirModel::Size
; break;
1022 case SortByDate
: index
= KDirModel::ModifiedTime
; break;
1023 default: assert(false);
1028 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1030 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1031 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1033 const QModelIndex topLeft
= itemModel
->index(0, 0);
1034 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1035 itemModel
->columnCount() - 1);
1037 QItemSelection
selection(topLeft
, bottomRight
);
1038 selectionModel
->select(selection
, flags
);
1041 QAbstractItemView
* DolphinView::itemView() const
1043 assert((m_iconsView
== 0) || (m_detailsView
== 0));
1044 if (m_detailsView
!= 0) {
1045 return m_detailsView
;
1050 #include "dolphinview.moc"