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
),
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 UndoManager
& undoMan
= UndoManager::instance();
237 undoMan
.beginMacro();
239 assert(newName
.contains('#'));
241 const int urlsCount
= urls
.count();
242 ProgressIndicator
* progressIndicator
=
243 new ProgressIndicator(mainWindow(),
244 i18n("Renaming items..."),
245 i18n("Renaming finished."),
248 // iterate through all selected items and rename them...
249 const int replaceIndex
= newName
.indexOf('#');
250 assert(replaceIndex
>= 0);
251 for (int i
= 0; i
< urlsCount
; ++i
) {
252 const KUrl
& source
= urls
[i
];
253 QString
name(newName
);
254 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
256 if (source
.fileName() != name
) {
257 KUrl
dest(source
.upUrl());
260 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
262 delete progressIndicator
;
263 progressIndicator
= 0;
264 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
265 DolphinStatusBar::Error
);
268 else if (KIO::NetAccess::file_move(source
, dest
)) {
269 // TODO: From the users point of view he executed one 'rename n files' operation,
270 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
271 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
272 undoMan
.addCommand(command
);
276 progressIndicator
->execOperation();
278 delete progressIndicator
;
279 progressIndicator
= 0;
285 // Only one item has been selected for renaming. Use the custom
286 // renaming mechanism from the views.
287 assert(urls
.count() == 1);
289 /*if (m_mode == DetailsView) {
290 Q3ListViewItem* item = m_iconsView->firstChild();
292 if (item->isSelected()) {
293 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
296 item = item->nextSibling();
300 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
302 if (item->isSelected()) {
306 item = static_cast<KFileIconViewItem*>(item->nextItem());
312 void DolphinView::selectAll()
314 selectAll(QItemSelectionModel::Select
);
317 void DolphinView::invertSelection()
319 selectAll(QItemSelectionModel::Toggle
);
322 DolphinStatusBar
* DolphinView::statusBar() const
327 int DolphinView::contentsX() const
330 return 0; //scrollView()->contentsX();
333 int DolphinView::contentsY() const
335 return 0; //scrollView()->contentsY();
338 void DolphinView::refreshSettings()
340 startDirLister(m_urlNavigator
->url());
343 void DolphinView::updateStatusBar()
345 // As the item count information is less important
346 // in comparison with other messages, it should only
348 // - the status bar is empty or
349 // - shows already the item count information or
350 // - shows only a not very important information
351 // - if any progress is given don't show the item count info at all
352 const QString
msg(m_statusBar
->message());
353 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
354 (msg
== m_statusBar
->defaultText()) ||
355 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
356 (m_statusBar
->progress() == 100);
358 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
359 m_statusBar
->setDefaultText(text
);
361 if (updateStatusBarMsg
) {
362 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
366 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
368 emit
requestItemInfo(url
);
371 bool DolphinView::isFilterBarVisible() const
373 return m_filterBar
->isVisible();
376 bool DolphinView::isUrlEditable() const
378 return m_urlNavigator
->isUrlEditable();
381 void DolphinView::zoomIn()
383 //itemEffectsManager()->zoomIn();
386 void DolphinView::zoomOut()
388 //itemEffectsManager()->zoomOut();
391 bool DolphinView::isZoomInPossible() const
393 return false; //itemEffectsManager()->isZoomInPossible();
396 bool DolphinView::isZoomOutPossible() const
398 return false; //itemEffectsManager()->isZoomOutPossible();
401 void DolphinView::setSorting(Sorting sorting
)
403 if (sorting
!= this->sorting()) {
404 ViewProperties
props(url());
405 props
.setSorting(sorting
);
407 m_proxyModel
->setSorting(sorting
);
409 emit
sortingChanged(sorting
);
413 DolphinView::Sorting
DolphinView::sorting() const
415 return m_proxyModel
->sorting();
418 void DolphinView::setSortOrder(Qt::SortOrder order
)
420 if (sortOrder() != order
) {
421 ViewProperties
props(url());
422 props
.setSortOrder(order
);
424 m_proxyModel
->setSortOrder(order
);
426 emit
sortOrderChanged(order
);
430 Qt::SortOrder
DolphinView::sortOrder() const
432 return m_proxyModel
->sortOrder();
435 void DolphinView::goBack()
437 m_urlNavigator
->goBack();
440 void DolphinView::goForward()
442 m_urlNavigator
->goForward();
445 void DolphinView::goUp()
447 m_urlNavigator
->goUp();
450 void DolphinView::goHome()
452 m_urlNavigator
->goHome();
455 void DolphinView::setUrlEditable(bool editable
)
457 m_urlNavigator
->editUrl(editable
);
460 const Q3ValueList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
462 return m_urlNavigator
->history(index
);
465 bool DolphinView::hasSelection() const
467 return itemView()->selectionModel()->hasSelection();
470 KFileItemList
DolphinView::selectedItems() const
472 const QAbstractItemView
* view
= itemView();
474 // Our view has a selection, we will map them back to the DirModel
475 // and then fill the KFileItemList.
476 assert((view
!= 0) && (view
->selectionModel() != 0));
478 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
479 KFileItemList itemList
;
481 const QModelIndexList indexList
= selection
.indexes();
482 QModelIndexList::const_iterator end
= indexList
.end();
483 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
484 assert((*it
).isValid());
486 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
488 itemList
.append(item
);
495 KUrl::List
DolphinView::selectedUrls() const
499 const KFileItemList list
= selectedItems();
500 KFileItemList::const_iterator it
= list
.begin();
501 const KFileItemList::const_iterator end
= list
.end();
503 KFileItem
* item
= *it
;
504 urls
.append(item
->url());
511 const KFileItem
* DolphinView::currentFileItem() const
513 return 0; // fileView()->currentFileItem();
516 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
518 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
522 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
526 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
530 KUrl
dest(source
.upUrl());
531 dest
.addPath(newName
);
533 const bool destExists
= KIO::NetAccess::exists(dest
,
535 mainWindow()->activeView());
537 // the destination already exists, hence ask the user
539 KIO::RenameDialog
renameDialog(this,
540 i18n("File Already Exists"),
544 switch (renameDialog
.exec()) {
545 case KIO::R_OVERWRITE
:
546 // the destination should be overwritten
547 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
550 case KIO::R_RENAME
: {
551 // a new name for the destination has been used
552 KUrl
newDest(renameDialog
.newDestUrl());
553 ok
= KIO::NetAccess::file_move(source
, newDest
);
558 // the renaming operation has been canceled
564 // no destination exists, hence just move the file to
566 ok
= KIO::NetAccess::file_move(source
, dest
);
570 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
571 DolphinStatusBar::OperationCompleted
);
573 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
574 UndoManager::instance().addCommand(command
);
577 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
578 DolphinStatusBar::Error
);
583 void DolphinView::reload()
585 startDirLister(m_urlNavigator
->url(), true);
588 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
589 const KUrl::List
& urls
,
592 KUrl
destination(url
);
593 if (destination
.isEmpty()) {
594 destination
= m_urlNavigator
->url();
597 // Check whether the destination Url is a directory. If this is not the
598 // case, use the navigator Url as destination (otherwise the destination,
599 // which represents a file, would be replaced by a copy- or move-operation).
600 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
601 if (!fileItem
.isDir()) {
602 destination
= m_urlNavigator
->url();
606 mainWindow()->dropUrls(urls
, destination
);
609 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
611 QWidget::mouseReleaseEvent(event
);
612 mainWindow()->setActiveView(this);
615 DolphinMainWindow
* DolphinView::mainWindow() const
620 void DolphinView::loadDirectory(const KUrl
& url
)
622 const ViewProperties
props(url
);
624 const Mode mode
= props
.viewMode();
625 if (m_mode
!= mode
) {
631 const bool showHiddenFiles
= props
.showHiddenFiles();
632 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
633 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
634 emit
showHiddenFilesChanged();
637 const DolphinView::Sorting sorting
= props
.sorting();
638 if (sorting
!= m_proxyModel
->sorting()) {
639 m_proxyModel
->setSorting(sorting
);
640 emit
sortingChanged(sorting
);
643 const Qt::SortOrder sortOrder
= props
.sortOrder();
644 if (sortOrder
!= m_proxyModel
->sortOrder()) {
645 m_proxyModel
->setSortOrder(sortOrder
);
646 emit
sortOrderChanged(sortOrder
);
649 // TODO: handle previews (props.showPreview())
652 emit
urlChanged(url
);
655 void DolphinView::triggerItem(const QModelIndex
& index
)
657 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
663 // Prefer the local path over the Url. This assures that the
664 // volume space information is correct. Assuming that the Url is media:/sda1,
665 // and the local path is /windows/C: For the Url the space info is related
666 // to the root partition (and hence wrong) and for the local path the space
667 // info is related to the windows partition (-> correct).
668 //m_dirLister->stop();
669 //m_dirLister->openUrl(item->url());
672 const QString
localPath(item
->localPath());
673 if (localPath
.isEmpty()) {
677 setUrl(KUrl(localPath
));
685 void DolphinView::slotPercent(int percent
)
687 if (m_showProgress
) {
688 m_statusBar
->setProgress(percent
);
692 void DolphinView::slotClear()
694 //fileView()->clearView();
698 void DolphinView::slotDeleteItem(KFileItem
* item
)
700 //fileView()->removeItem(item);
704 void DolphinView::slotCompleted()
708 //KFileView* view = fileView();
711 // TODO: in Qt4 the code should get a lot
712 // simpler and nicer due to Interview...
713 /*if (m_iconsView != 0) {
714 m_iconsView->beginItemUpdates();
716 if (m_iconsView != 0) {
717 m_iconsView->beginItemUpdates();
720 if (m_showProgress
) {
721 m_statusBar
->setProgressText(QString::null
);
722 m_statusBar
->setProgress(100);
723 m_showProgress
= false;
726 KFileItemList
items(m_dirLister
->items());
727 KFileItemList::const_iterator it
= items
.begin();
728 const KFileItemList::const_iterator end
= items
.end();
734 KFileItem
* item
= *it
;
735 //view->insertItem(item);
747 /*if (m_iconsView != 0) {
748 // Prevent a flickering of the icon view widget by giving a small
749 // timeslot to swallow asynchronous update events.
750 m_iconsView->setUpdatesEnabled(false);
751 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
754 if (m_iconsView != 0) {
755 m_iconsView->endItemUpdates();
756 m_refreshing = false;
760 void DolphinView::slotInfoMessage(const QString
& msg
)
762 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
765 void DolphinView::slotErrorMessage(const QString
& msg
)
767 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
770 void DolphinView::slotGrabActivation()
772 mainWindow()->setActiveView(this);
775 void DolphinView::emitSelectionChangedSignal()
777 emit
selectionChanged();
780 void DolphinView::closeFilterBar()
783 emit
showFilterBarChanged(false);
786 void DolphinView::slotContentsMoving(int x
, int y
)
789 // Only emit a 'contents moved' signal if the user
790 // moved the content by adjusting the sliders. Adjustments
791 // resulted by refreshing a directory should not be respected.
792 emit
contentsMoved(x
, y
);
796 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
798 if (!url
.isValid()) {
799 const QString
location(url
.pathOrUrl());
800 if (location
.isEmpty()) {
801 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
804 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
805 DolphinStatusBar::Error
);
810 // Only show the directory loading progress if the status bar does
811 // not contain another progress information. This means that
812 // the directory loading progress information has the lowest priority.
813 const QString
progressText(m_statusBar
->progressText());
814 m_showProgress
= progressText
.isEmpty() ||
815 (progressText
== i18n("Loading directory..."));
816 if (m_showProgress
) {
817 m_statusBar
->setProgressText(i18n("Loading directory..."));
818 m_statusBar
->setProgress(0);
823 m_dirLister
->openUrl(url
, false, reload
);
826 QString
DolphinView::defaultStatusBarText() const
828 // TODO: the following code is not suitable for languages where multiple forms
829 // of plurals are given (e. g. in Poland three forms of plurals exist).
830 const int itemCount
= m_folderCount
+ m_fileCount
;
833 if (itemCount
== 1) {
834 text
= i18n("1 Item");
837 text
= i18n("%1 Items",itemCount
);
842 if (m_folderCount
== 1) {
843 text
+= i18n("1 Folder");
846 text
+= i18n("%1 Folders",m_folderCount
);
851 if (m_fileCount
== 1) {
852 text
+= i18n("1 File");
855 text
+= i18n("%1 Files",m_fileCount
);
863 QString
DolphinView::selectionStatusBarText() const
865 // TODO: the following code is not suitable for languages where multiple forms
866 // of plurals are given (e. g. in Poland three forms of plurals exist).
868 const KFileItemList list
= selectedItems();
869 if (list
.isEmpty()) {
870 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
871 // DolphinView::hasSelection() is true. Inconsistent behavior?
877 KIO::filesize_t byteSize
= 0;
878 KFileItemList::const_iterator it
= list
.begin();
879 const KFileItemList::const_iterator end
= list
.end();
881 KFileItem
* item
= *it
;
887 byteSize
+= item
->size();
892 if (folderCount
== 1) {
893 text
= i18n("1 Folder selected");
895 else if (folderCount
> 1) {
896 text
= i18n("%1 Folders selected",folderCount
);
899 if ((fileCount
> 0) && (folderCount
> 0)) {
903 const QString
sizeText(KIO::convertSize(byteSize
));
904 if (fileCount
== 1) {
905 text
+= i18n("1 File selected (%1)",sizeText
);
907 else if (fileCount
> 1) {
908 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
914 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
916 // assure that the string reprentation for all indicess have the same
917 // number of characters based on the given number of items
918 QString
str(QString::number(index
));
920 while (itemCount
>= 10) {
924 str
.reserve(chrCount
);
926 const int insertCount
= chrCount
- str
.length();
927 for (int i
= 0; i
< insertCount
; ++i
) {
933 void DolphinView::slotShowFilterBar(bool show
)
935 assert(m_filterBar
!= 0);
944 void DolphinView::declareViewActive()
946 mainWindow()->setActiveView( this );
949 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
951 // The name filter of KDirLister does a 'hard' filtering, which
952 // means that only the items are shown where the names match
953 // exactly the filter. This is non-transparent for the user, which
954 // just wants to have a 'soft' filtering: does the name contain
955 // the filter string?
956 QString
adjustedFilter(nameFilter
);
957 adjustedFilter
.insert(0, '*');
958 adjustedFilter
.append('*');
960 // Use the ProxyModel to filter:
961 // This code is #ifdefed as setNameFilter behaves
962 // slightly different than the QSortFilterProxyModel
963 // as it will not remove directories. I will ask
964 // our beloved usability experts for input
967 m_dirLister
->setNameFilter(adjustedFilter
);
968 m_dirLister
->emitChanges();
970 m_proxyModel
->setFilterRegExp( nameFilter
);
974 void DolphinView::createView()
976 // delete current view
977 QAbstractItemView
* view
= itemView();
979 m_topLayout
->remove(view
);
986 assert(m_iconsView
== 0);
987 assert(m_detailsView
== 0);
989 // ... and recreate it representing the current mode
992 m_iconsView
= new DolphinIconsView(this);
993 m_iconsView
->setViewMode(QListView::IconMode
);
994 m_iconsView
->setSpacing(32);
996 // TODO: read out view settings
1000 m_detailsView
= new DolphinDetailsView(this);
1001 view
= m_detailsView
;
1002 // TODO: read out view settings
1006 view
->setModel(m_proxyModel
);
1008 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1010 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
1011 delegate
->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType
);
1012 view
->setItemDelegate(delegate
);
1014 new KMimeTypeResolver(view
, m_dirModel
);
1016 connect(view
, SIGNAL(clicked(const QModelIndex
&)),
1017 this, SLOT(triggerItem(const QModelIndex
&)));
1018 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1019 this, SLOT(emitSelectionChangedSignal()));
1021 m_topLayout
->insertWidget(1, view
);
1024 int DolphinView::columnIndex(Sorting sorting
) const
1028 case SortByName
: index
= KDirModel::Name
; break;
1029 case SortBySize
: index
= KDirModel::Size
; break;
1030 case SortByDate
: index
= KDirModel::ModifiedTime
; break;
1031 default: assert(false);
1036 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1038 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1039 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1041 const QModelIndex topLeft
= itemModel
->index(0, 0);
1042 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1043 itemModel
->columnCount() - 1);
1045 QItemSelection
selection(topLeft
, bottomRight
);
1046 selectionModel
->select(selection
, flags
);
1049 QAbstractItemView
* DolphinView::itemView() const
1051 assert((m_iconsView
== 0) || (m_detailsView
== 0));
1052 if (m_detailsView
!= 0) {
1053 return m_detailsView
;
1058 #include "dolphinview.moc"