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
),
77 setFocusPolicy(Qt::StrongFocus
);
78 m_topLayout
= new QVBoxLayout(this);
79 m_topLayout
->setSpacing(0);
80 m_topLayout
->setMargin(0);
82 m_urlNavigator
= new UrlNavigator(url
, this);
83 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
84 this, SLOT(loadDirectory(const KUrl
&)));
86 m_statusBar
= new DolphinStatusBar(this);
88 m_dirLister
= new DolphinDirLister();
89 m_dirLister
->setAutoUpdate(true);
90 m_dirLister
->setMainWindow(this);
91 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
92 m_dirLister
->setDelayedMimeTypes(true);
94 connect(m_dirLister
, SIGNAL(clear()),
95 this, SLOT(slotClear()));
96 connect(m_dirLister
, SIGNAL(percent(int)),
97 this, SLOT(slotPercent(int)));
98 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
99 this, SLOT(slotDeleteItem(KFileItem
*)));
100 connect(m_dirLister
, SIGNAL(completed()),
101 this, SLOT(slotCompleted()));
102 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
103 this, SLOT(slotInfoMessage(const QString
&)));
104 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
105 this, SLOT(slotErrorMessage(const QString
&)));
107 m_dirModel
= new KDirModel();
108 m_dirModel
->setDirLister(m_dirLister
);
109 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
111 m_proxyModel
= new DolphinSortFilterProxyModel(this);
112 m_proxyModel
->setSourceModel(m_dirModel
);
116 m_iconSize
= K3Icon::SizeMedium
;
118 m_filterBar
= new FilterBar(this);
120 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
121 this, SLOT(slotChangeNameFilter(const QString
&)));
122 connect(m_filterBar
, SIGNAL(closed()),
123 this, SLOT(closeFilterBar()));
125 m_topLayout
->addWidget(m_urlNavigator
);
126 m_topLayout
->addWidget(itemView());
127 m_topLayout
->addWidget(m_filterBar
);
128 m_topLayout
->addWidget(m_statusBar
);
130 loadDirectory(m_urlNavigator
->url());
133 DolphinView::~DolphinView()
139 void DolphinView::setUrl(const KUrl
& url
)
141 m_urlNavigator
->setUrl(url
);
144 const KUrl
& DolphinView::url() const
146 return m_urlNavigator
->url();
149 void DolphinView::requestActivation()
151 mainWindow()->setActiveView(this);
154 bool DolphinView::isActive() const
156 return (mainWindow()->activeView() == this);
159 void DolphinView::setMode(Mode mode
)
161 if (mode
== m_mode
) {
162 return; // the wished mode is already set
167 ViewProperties
props(m_urlNavigator
->url());
168 props
.setViewMode(m_mode
);
171 startDirLister(m_urlNavigator
->url());
176 DolphinView::Mode
DolphinView::mode() const
181 void DolphinView::setShowPreview(bool show
)
183 ViewProperties
props(m_urlNavigator
->url());
184 props
.setShowPreview(show
);
186 // TODO: wait until previews are possible with KFileItemDelegate
188 emit
showPreviewChanged();
191 bool DolphinView::showPreview() const
193 // TODO: wait until previews are possible with KFileItemDelegate
197 void DolphinView::setShowHiddenFiles(bool show
)
199 if (m_dirLister
->showingDotFiles() == show
) {
203 ViewProperties
props(m_urlNavigator
->url());
204 props
.setShowHiddenFiles(show
);
207 m_dirLister
->setShowingDotFiles(show
);
209 emit
showHiddenFilesChanged();
214 bool DolphinView::showHiddenFiles() const
216 return m_dirLister
->showingDotFiles();
219 void DolphinView::renameSelectedItems()
221 const KUrl::List urls
= selectedUrls();
222 if (urls
.count() > 1) {
223 // More than one item has been selected for renaming. Open
224 // a rename dialog and rename all items afterwards.
225 RenameDialog
dialog(urls
);
226 if (dialog
.exec() == QDialog::Rejected
) {
230 DolphinView
* view
= mainWindow()->activeView();
231 const QString
& newName
= dialog
.newName();
232 if (newName
.isEmpty()) {
233 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
234 DolphinStatusBar::Error
);
237 UndoManager
& undoMan
= UndoManager::instance();
238 undoMan
.beginMacro();
240 assert(newName
.contains('#'));
242 const int urlsCount
= urls
.count();
243 ProgressIndicator
* progressIndicator
=
244 new ProgressIndicator(mainWindow(),
245 i18n("Renaming items..."),
246 i18n("Renaming finished."),
249 // iterate through all selected items and rename them...
250 const int replaceIndex
= newName
.indexOf('#');
251 assert(replaceIndex
>= 0);
252 for (int i
= 0; i
< urlsCount
; ++i
) {
253 const KUrl
& source
= urls
[i
];
254 QString
name(newName
);
255 name
.replace(replaceIndex
, 1, renameIndexPresentation(i
+ 1, urlsCount
));
257 if (source
.fileName() != name
) {
258 KUrl
dest(source
.upUrl());
261 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
263 delete progressIndicator
;
264 progressIndicator
= 0;
265 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
266 DolphinStatusBar::Error
);
269 else if (KIO::NetAccess::file_move(source
, dest
)) {
270 // TODO: From the users point of view he executed one 'rename n files' operation,
271 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
272 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
273 undoMan
.addCommand(command
);
277 progressIndicator
->execOperation();
279 delete progressIndicator
;
280 progressIndicator
= 0;
286 // Only one item has been selected for renaming. Use the custom
287 // renaming mechanism from the views.
288 assert(urls
.count() == 1);
290 /*if (m_mode == DetailsView) {
291 Q3ListViewItem* item = m_iconsView->firstChild();
293 if (item->isSelected()) {
294 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
297 item = item->nextSibling();
301 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
303 if (item->isSelected()) {
307 item = static_cast<KFileIconViewItem*>(item->nextItem());
313 void DolphinView::selectAll()
315 selectAll(QItemSelectionModel::Select
);
318 void DolphinView::invertSelection()
320 selectAll(QItemSelectionModel::Toggle
);
323 DolphinStatusBar
* DolphinView::statusBar() const
328 int DolphinView::contentsX() const
331 return 0; //scrollView()->contentsX();
334 int DolphinView::contentsY() const
336 return 0; //scrollView()->contentsY();
339 void DolphinView::refreshSettings()
341 startDirLister(m_urlNavigator
->url());
344 void DolphinView::updateStatusBar()
346 // As the item count information is less important
347 // in comparison with other messages, it should only
349 // - the status bar is empty or
350 // - shows already the item count information or
351 // - shows only a not very important information
352 // - if any progress is given don't show the item count info at all
353 const QString
msg(m_statusBar
->message());
354 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
355 (msg
== m_statusBar
->defaultText()) ||
356 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
357 (m_statusBar
->progress() == 100);
359 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
360 m_statusBar
->setDefaultText(text
);
362 if (updateStatusBarMsg
) {
363 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
367 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
369 emit
requestItemInfo(url
);
372 bool DolphinView::isFilterBarVisible() const
374 return m_filterBar
->isVisible();
377 bool DolphinView::isUrlEditable() const
379 return m_urlNavigator
->isUrlEditable();
382 void DolphinView::zoomIn()
384 //itemEffectsManager()->zoomIn();
387 void DolphinView::zoomOut()
389 //itemEffectsManager()->zoomOut();
392 bool DolphinView::isZoomInPossible() const
394 return false; //itemEffectsManager()->isZoomInPossible();
397 bool DolphinView::isZoomOutPossible() const
399 return false; //itemEffectsManager()->isZoomOutPossible();
402 void DolphinView::setSorting(Sorting sorting
)
404 if (sorting
!= this->sorting()) {
405 ViewProperties
props(url());
406 props
.setSorting(sorting
);
408 m_proxyModel
->setSorting(sorting
);
410 emit
sortingChanged(sorting
);
414 DolphinView::Sorting
DolphinView::sorting() const
416 return m_proxyModel
->sorting();
419 void DolphinView::setSortOrder(Qt::SortOrder order
)
421 if (sortOrder() != order
) {
422 ViewProperties
props(url());
423 props
.setSortOrder(order
);
425 m_proxyModel
->setSortOrder(order
);
427 emit
sortOrderChanged(order
);
431 Qt::SortOrder
DolphinView::sortOrder() const
433 return m_proxyModel
->sortOrder();
436 void DolphinView::goBack()
438 m_urlNavigator
->goBack();
441 void DolphinView::goForward()
443 m_urlNavigator
->goForward();
446 void DolphinView::goUp()
448 m_urlNavigator
->goUp();
451 void DolphinView::goHome()
453 m_urlNavigator
->goHome();
456 void DolphinView::setUrlEditable(bool editable
)
458 m_urlNavigator
->editUrl(editable
);
461 const Q3ValueList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
463 return m_urlNavigator
->history(index
);
466 bool DolphinView::hasSelection() const
468 return itemView()->selectionModel()->hasSelection();
471 KFileItemList
DolphinView::selectedItems() const
473 const QAbstractItemView
* view
= itemView();
475 // Our view has a selection, we will map them back to the DirModel
476 // and then fill the KFileItemList.
477 assert((view
!= 0) && (view
->selectionModel() != 0));
479 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
480 KFileItemList itemList
;
482 const QModelIndexList indexList
= selection
.indexes();
483 QModelIndexList::const_iterator end
= indexList
.end();
484 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
485 assert((*it
).isValid());
487 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
489 itemList
.append(item
);
496 KUrl::List
DolphinView::selectedUrls() const
500 const KFileItemList list
= selectedItems();
501 KFileItemList::const_iterator it
= list
.begin();
502 const KFileItemList::const_iterator end
= list
.end();
504 KFileItem
* item
= *it
;
505 urls
.append(item
->url());
512 const KFileItem
* DolphinView::currentFileItem() const
514 return 0; // fileView()->currentFileItem();
517 void DolphinView::openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
)
519 DolphinContextMenu
contextMenu(this, fileInfo
, pos
);
523 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
527 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
531 KUrl
dest(source
.upUrl());
532 dest
.addPath(newName
);
534 const bool destExists
= KIO::NetAccess::exists(dest
,
536 mainWindow()->activeView());
538 // the destination already exists, hence ask the user
540 KIO::RenameDialog
renameDialog(this,
541 i18n("File Already Exists"),
545 switch (renameDialog
.exec()) {
546 case KIO::R_OVERWRITE
:
547 // the destination should be overwritten
548 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
551 case KIO::R_RENAME
: {
552 // a new name for the destination has been used
553 KUrl
newDest(renameDialog
.newDestUrl());
554 ok
= KIO::NetAccess::file_move(source
, newDest
);
559 // the renaming operation has been canceled
565 // no destination exists, hence just move the file to
567 ok
= KIO::NetAccess::file_move(source
, dest
);
571 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), dest
.fileName()),
572 DolphinStatusBar::OperationCompleted
);
574 DolphinCommand
command(DolphinCommand::Rename
, source
, dest
);
575 UndoManager::instance().addCommand(command
);
578 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), dest
.fileName()),
579 DolphinStatusBar::Error
);
584 void DolphinView::reload()
586 startDirLister(m_urlNavigator
->url(), true);
589 void DolphinView::slotUrlListDropped(QDropEvent
* /* event */,
590 const KUrl::List
& urls
,
593 KUrl
destination(url
);
594 if (destination
.isEmpty()) {
595 destination
= m_urlNavigator
->url();
598 // Check whether the destination Url is a directory. If this is not the
599 // case, use the navigator Url as destination (otherwise the destination,
600 // which represents a file, would be replaced by a copy- or move-operation).
601 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, destination
);
602 if (!fileItem
.isDir()) {
603 destination
= m_urlNavigator
->url();
607 mainWindow()->dropUrls(urls
, destination
);
610 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
612 QWidget::mouseReleaseEvent(event
);
613 mainWindow()->setActiveView(this);
616 DolphinMainWindow
* DolphinView::mainWindow() const
621 void DolphinView::loadDirectory(const KUrl
& url
)
623 const ViewProperties
props(url
);
625 const Mode mode
= props
.viewMode();
626 if (m_mode
!= mode
) {
632 const bool showHiddenFiles
= props
.showHiddenFiles();
633 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
634 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
635 emit
showHiddenFilesChanged();
638 const DolphinView::Sorting sorting
= props
.sorting();
639 if (sorting
!= m_proxyModel
->sorting()) {
640 m_proxyModel
->setSorting(sorting
);
641 emit
sortingChanged(sorting
);
644 const Qt::SortOrder sortOrder
= props
.sortOrder();
645 if (sortOrder
!= m_proxyModel
->sortOrder()) {
646 m_proxyModel
->setSortOrder(sortOrder
);
647 emit
sortOrderChanged(sortOrder
);
650 // TODO: handle previews (props.showPreview())
653 emit
urlChanged(url
);
656 void DolphinView::triggerItem(const QModelIndex
& index
)
658 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
664 // Prefer the local path over the Url. This assures that the
665 // volume space information is correct. Assuming that the Url is media:/sda1,
666 // and the local path is /windows/C: For the Url the space info is related
667 // to the root partition (and hence wrong) and for the local path the space
668 // info is related to the windows partition (-> correct).
669 //m_dirLister->stop();
670 //m_dirLister->openUrl(item->url());
673 const QString
localPath(item
->localPath());
674 if (localPath
.isEmpty()) {
678 setUrl(KUrl(localPath
));
686 void DolphinView::slotPercent(int percent
)
688 if (m_showProgress
) {
689 m_statusBar
->setProgress(percent
);
693 void DolphinView::slotClear()
695 //fileView()->clearView();
699 void DolphinView::slotDeleteItem(KFileItem
* item
)
701 //fileView()->removeItem(item);
705 void DolphinView::slotCompleted()
709 //KFileView* view = fileView();
712 // TODO: in Qt4 the code should get a lot
713 // simpler and nicer due to Interview...
714 /*if (m_iconsView != 0) {
715 m_iconsView->beginItemUpdates();
717 if (m_iconsView != 0) {
718 m_iconsView->beginItemUpdates();
721 if (m_showProgress
) {
722 m_statusBar
->setProgressText(QString::null
);
723 m_statusBar
->setProgress(100);
724 m_showProgress
= false;
727 KFileItemList
items(m_dirLister
->items());
728 KFileItemList::const_iterator it
= items
.begin();
729 const KFileItemList::const_iterator end
= items
.end();
735 KFileItem
* item
= *it
;
736 //view->insertItem(item);
748 /*if (m_iconsView != 0) {
749 // Prevent a flickering of the icon view widget by giving a small
750 // timeslot to swallow asynchronous update events.
751 m_iconsView->setUpdatesEnabled(false);
752 QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
755 if (m_iconsView != 0) {
756 m_iconsView->endItemUpdates();
757 m_refreshing = false;
761 void DolphinView::slotInfoMessage(const QString
& msg
)
763 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
766 void DolphinView::slotErrorMessage(const QString
& msg
)
768 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
771 void DolphinView::slotGrabActivation()
773 mainWindow()->setActiveView(this);
776 void DolphinView::emitSelectionChangedSignal()
778 emit
selectionChanged();
781 void DolphinView::closeFilterBar()
784 emit
showFilterBarChanged(false);
787 void DolphinView::slotContentsMoving(int x
, int y
)
790 // Only emit a 'contents moved' signal if the user
791 // moved the content by adjusting the sliders. Adjustments
792 // resulted by refreshing a directory should not be respected.
793 emit
contentsMoved(x
, y
);
797 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
799 if (!url
.isValid()) {
800 const QString
location(url
.pathOrUrl());
801 if (location
.isEmpty()) {
802 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
805 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
806 DolphinStatusBar::Error
);
811 // Only show the directory loading progress if the status bar does
812 // not contain another progress information. This means that
813 // the directory loading progress information has the lowest priority.
814 const QString
progressText(m_statusBar
->progressText());
815 m_showProgress
= progressText
.isEmpty() ||
816 (progressText
== i18n("Loading directory..."));
817 if (m_showProgress
) {
818 m_statusBar
->setProgressText(i18n("Loading directory..."));
819 m_statusBar
->setProgress(0);
824 m_dirLister
->openUrl(url
, false, reload
);
827 QString
DolphinView::defaultStatusBarText() const
829 // TODO: the following code is not suitable for languages where multiple forms
830 // of plurals are given (e. g. in Poland three forms of plurals exist).
831 const int itemCount
= m_folderCount
+ m_fileCount
;
834 if (itemCount
== 1) {
835 text
= i18n("1 Item");
838 text
= i18n("%1 Items",itemCount
);
843 if (m_folderCount
== 1) {
844 text
+= i18n("1 Folder");
847 text
+= i18n("%1 Folders",m_folderCount
);
852 if (m_fileCount
== 1) {
853 text
+= i18n("1 File");
856 text
+= i18n("%1 Files",m_fileCount
);
864 QString
DolphinView::selectionStatusBarText() const
866 // TODO: the following code is not suitable for languages where multiple forms
867 // of plurals are given (e. g. in Poland three forms of plurals exist).
869 const KFileItemList list
= selectedItems();
870 if (list
.isEmpty()) {
871 // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
872 // DolphinView::hasSelection() is true. Inconsistent behavior?
878 KIO::filesize_t byteSize
= 0;
879 KFileItemList::const_iterator it
= list
.begin();
880 const KFileItemList::const_iterator end
= list
.end();
882 KFileItem
* item
= *it
;
888 byteSize
+= item
->size();
893 if (folderCount
== 1) {
894 text
= i18n("1 Folder selected");
896 else if (folderCount
> 1) {
897 text
= i18n("%1 Folders selected",folderCount
);
900 if ((fileCount
> 0) && (folderCount
> 0)) {
904 const QString
sizeText(KIO::convertSize(byteSize
));
905 if (fileCount
== 1) {
906 text
+= i18n("1 File selected (%1)",sizeText
);
908 else if (fileCount
> 1) {
909 text
+= i18n("%1 Files selected (%1)",fileCount
,sizeText
);
915 QString
DolphinView::renameIndexPresentation(int index
, int itemCount
) const
917 // assure that the string reprentation for all indicess have the same
918 // number of characters based on the given number of items
919 QString
str(QString::number(index
));
921 while (itemCount
>= 10) {
925 str
.reserve(chrCount
);
927 const int insertCount
= chrCount
- str
.length();
928 for (int i
= 0; i
< insertCount
; ++i
) {
934 void DolphinView::slotShowFilterBar(bool show
)
936 assert(m_filterBar
!= 0);
945 void DolphinView::declareViewActive()
947 mainWindow()->setActiveView( this );
950 void DolphinView::slotChangeNameFilter(const QString
& nameFilter
)
952 // The name filter of KDirLister does a 'hard' filtering, which
953 // means that only the items are shown where the names match
954 // exactly the filter. This is non-transparent for the user, which
955 // just wants to have a 'soft' filtering: does the name contain
956 // the filter string?
957 QString
adjustedFilter(nameFilter
);
958 adjustedFilter
.insert(0, '*');
959 adjustedFilter
.append('*');
961 // Use the ProxyModel to filter:
962 // This code is #ifdefed as setNameFilter behaves
963 // slightly different than the QSortFilterProxyModel
964 // as it will not remove directories. I will ask
965 // our beloved usability experts for input
968 m_dirLister
->setNameFilter(adjustedFilter
);
969 m_dirLister
->emitChanges();
971 m_proxyModel
->setFilterRegExp( nameFilter
);
975 void DolphinView::createView()
977 // delete current view
978 QAbstractItemView
* view
= itemView();
980 m_topLayout
->remove(view
);
987 assert(m_iconsView
== 0);
988 assert(m_detailsView
== 0);
990 delete m_mimeTypeResolver
;
991 m_mimeTypeResolver
= 0;
993 // ... and recreate it representing the current mode
996 m_iconsView
= new DolphinIconsView(this);
997 m_iconsView
->setViewMode(QListView::IconMode
);
998 m_iconsView
->setSpacing(32);
1000 // TODO: read out view settings
1004 m_detailsView
= new DolphinDetailsView(this);
1005 view
= m_detailsView
;
1006 // TODO: read out view settings
1010 view
->setModel(m_proxyModel
);
1012 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1014 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
1015 delegate
->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType
);
1016 view
->setItemDelegate(delegate
);
1018 m_mimeTypeResolver
= new KMimeTypeResolver(view
, m_dirModel
);
1020 connect(view
, SIGNAL(clicked(const QModelIndex
&)),
1021 this, SLOT(triggerItem(const QModelIndex
&)));
1022 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1023 this, SLOT(emitSelectionChangedSignal()));
1025 m_topLayout
->insertWidget(1, view
);
1028 int DolphinView::columnIndex(Sorting sorting
) const
1032 case SortByName
: index
= KDirModel::Name
; break;
1033 case SortBySize
: index
= KDirModel::Size
; break;
1034 case SortByDate
: index
= KDirModel::ModifiedTime
; break;
1035 default: assert(false);
1040 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1042 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1043 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1045 const QModelIndex topLeft
= itemModel
->index(0, 0);
1046 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1047 itemModel
->columnCount() - 1);
1049 QItemSelection
selection(topLeft
, bottomRight
);
1050 selectionModel
->select(selection
, flags
);
1053 QAbstractItemView
* DolphinView::itemView() const
1055 assert((m_iconsView
== 0) || (m_detailsView
== 0));
1056 if (m_detailsView
!= 0) {
1057 return m_detailsView
;
1062 #include "dolphinview.moc"