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 <QApplication>
27 #include <QItemSelectionModel>
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 <kio/previewjob.h>
37 #include <kmimetyperesolver.h>
38 #include <konq_operations.h>
41 #include "dolphincontroller.h"
42 #include "dolphinstatusbar.h"
43 #include "dolphinmainwindow.h"
44 #include "dolphindirlister.h"
45 #include "dolphinsortfilterproxymodel.h"
46 #include "dolphindetailsview.h"
47 #include "dolphiniconsview.h"
48 #include "dolphincontextmenu.h"
49 #include "filterbar.h"
50 #include "renamedialog.h"
51 #include "urlnavigator.h"
52 #include "viewproperties.h"
54 DolphinView::DolphinView(DolphinMainWindow
* mainWindow
,
58 bool showHiddenFiles
) :
60 m_showProgress(false),
65 m_mainWindow(mainWindow
),
78 setFocusPolicy(Qt::StrongFocus
);
79 m_topLayout
= new QVBoxLayout(this);
80 m_topLayout
->setSpacing(0);
81 m_topLayout
->setMargin(0);
83 connect(m_mainWindow
, SIGNAL(activeViewChanged()),
84 this, SLOT(updateActivationState()));
86 m_urlNavigator
= new UrlNavigator(url
, this);
87 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
88 this, SLOT(loadDirectory(const KUrl
&)));
89 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
90 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
91 connect(m_urlNavigator
, SIGNAL(activated()),
92 this, SLOT(requestActivation()));
93 connect(this, SIGNAL(contentsMoved(int, int)),
94 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
96 m_statusBar
= new DolphinStatusBar(this);
98 m_dirLister
= new DolphinDirLister();
99 m_dirLister
->setAutoUpdate(true);
100 m_dirLister
->setMainWindow(this);
101 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
102 m_dirLister
->setDelayedMimeTypes(true);
104 connect(m_dirLister
, SIGNAL(clear()),
105 this, SLOT(updateStatusBar()));
106 connect(m_dirLister
, SIGNAL(percent(int)),
107 this, SLOT(updateProgress(int)));
108 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
109 this, SLOT(updateStatusBar()));
110 connect(m_dirLister
, SIGNAL(completed()),
111 this, SLOT(updateItemCount()));
112 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
113 this, SLOT(generatePreviews(const KFileItemList
&)));
114 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
115 this, SLOT(showInfoMessage(const QString
&)));
116 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
117 this, SLOT(showErrorMessage(const QString
&)));
119 m_dirModel
= new KDirModel();
120 m_dirModel
->setDirLister(m_dirLister
);
121 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
123 m_proxyModel
= new DolphinSortFilterProxyModel(this);
124 m_proxyModel
->setSourceModel(m_dirModel
);
126 m_controller
= new DolphinController(this);
127 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
128 this, SLOT(openContextMenu(const QPoint
&)));
129 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QPoint
&)),
130 this, SLOT(dropUrls(const KUrl::List
&, const QPoint
&)));
131 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
132 this, SLOT(updateSorting(DolphinView::Sorting
)));
133 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
134 this, SLOT(updateSortOrder(Qt::SortOrder
)));
135 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
136 this, SLOT(triggerItem(const QModelIndex
&)));
137 connect(m_controller
, SIGNAL(selectionChanged()),
138 this, SLOT(emitSelectionChangedSignal()));
139 connect(m_controller
, SIGNAL(activated()),
140 this, SLOT(requestActivation()));
144 m_iconSize
= K3Icon::SizeMedium
;
146 m_filterBar
= new FilterBar(this);
148 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
149 this, SLOT(changeNameFilter(const QString
&)));
150 connect(m_filterBar
, SIGNAL(closeRequest()),
151 this, SLOT(closeFilterBar()));
153 m_topLayout
->addWidget(m_urlNavigator
);
154 m_topLayout
->addWidget(itemView());
155 m_topLayout
->addWidget(m_filterBar
);
156 m_topLayout
->addWidget(m_statusBar
);
158 loadDirectory(m_urlNavigator
->url());
161 DolphinView::~DolphinView()
167 void DolphinView::setUrl(const KUrl
& url
)
169 m_urlNavigator
->setUrl(url
);
170 m_controller
->setUrl(url
);
173 const KUrl
& DolphinView::url() const
175 return m_urlNavigator
->url();
178 bool DolphinView::isActive() const
180 return m_mainWindow
->activeView() == this;
183 void DolphinView::setMode(Mode mode
)
185 if (mode
== m_mode
) {
186 return; // the wished mode is already set
191 ViewProperties
props(m_urlNavigator
->url());
192 props
.setViewMode(m_mode
);
195 startDirLister(m_urlNavigator
->url());
200 DolphinView::Mode
DolphinView::mode() const
205 void DolphinView::setShowPreview(bool show
)
207 ViewProperties
props(m_urlNavigator
->url());
208 props
.setShowPreview(show
);
210 m_controller
->setShowPreview(show
);
212 emit
showPreviewChanged();
216 bool DolphinView::showPreview() const
218 return m_controller
->showPreview();
221 void DolphinView::setShowHiddenFiles(bool show
)
223 if (m_dirLister
->showingDotFiles() == show
) {
227 ViewProperties
props(m_urlNavigator
->url());
228 props
.setShowHiddenFiles(show
);
231 m_dirLister
->setShowingDotFiles(show
);
233 emit
showHiddenFilesChanged();
238 bool DolphinView::showHiddenFiles() const
240 return m_dirLister
->showingDotFiles();
243 void DolphinView::renameSelectedItems()
245 const KUrl::List urls
= selectedUrls();
246 if (urls
.count() > 1) {
247 // More than one item has been selected for renaming. Open
248 // a rename dialog and rename all items afterwards.
249 RenameDialog
dialog(urls
);
250 if (dialog
.exec() == QDialog::Rejected
) {
254 DolphinView
* view
= mainWindow()->activeView();
255 const QString
& newName
= dialog
.newName();
256 if (newName
.isEmpty()) {
257 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
258 DolphinStatusBar::Error
);
261 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
263 //UndoManager& undoMan = UndoManager::instance();
264 //undoMan.beginMacro();
266 assert(newName
.contains('#'));
268 const int urlsCount
= urls
.count();
270 // iterate through all selected items and rename them...
271 const int replaceIndex
= newName
.indexOf('#');
272 assert(replaceIndex
>= 0);
273 for (int i
= 0; i
< urlsCount
; ++i
) {
274 const KUrl
& source
= urls
[i
];
276 number
.setNum(i
+ 1);
278 QString
name(newName
);
279 name
.replace(replaceIndex
, 1, number
);
281 if (source
.fileName() != name
) {
282 KUrl
dest(source
.upUrl());
285 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
287 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
288 DolphinStatusBar::Error
);
291 else if (KIO::NetAccess::file_move(source
, dest
)) {
292 // TODO: From the users point of view he executed one 'rename n files' operation,
293 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
294 //DolphinCommand command(DolphinCommand::Rename, source, dest);
295 //undoMan.addCommand(command);
300 //undoMan.endMacro();
304 // Only one item has been selected for renaming. Use the custom
305 // renaming mechanism from the views.
306 assert(urls
.count() == 1);
308 /*if (m_mode == DetailsView) {
309 Q3ListViewItem* item = m_iconsView->firstChild();
311 if (item->isSelected()) {
312 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
315 item = item->nextSibling();
319 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
321 if (item->isSelected()) {
325 item = static_cast<KFileIconViewItem*>(item->nextItem());
331 void DolphinView::selectAll()
333 selectAll(QItemSelectionModel::Select
);
336 void DolphinView::invertSelection()
338 selectAll(QItemSelectionModel::Toggle
);
341 DolphinStatusBar
* DolphinView::statusBar() const
346 int DolphinView::contentsX() const
349 return itemView()->horizontalScrollBar()->value();
352 int DolphinView::contentsY() const
354 return itemView()->verticalScrollBar()->value();
357 void DolphinView::refreshSettings()
359 startDirLister(m_urlNavigator
->url());
362 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
364 emit
requestItemInfo(url
);
367 bool DolphinView::isFilterBarVisible() const
369 return m_filterBar
->isVisible();
372 bool DolphinView::isUrlEditable() const
374 return m_urlNavigator
->isUrlEditable();
377 void DolphinView::zoomIn()
379 //itemEffectsManager()->zoomIn();
382 void DolphinView::zoomOut()
384 //itemEffectsManager()->zoomOut();
387 bool DolphinView::isZoomInPossible() const
389 return false; //itemEffectsManager()->isZoomInPossible();
392 bool DolphinView::isZoomOutPossible() const
394 return false; //itemEffectsManager()->isZoomOutPossible();
397 void DolphinView::setSorting(Sorting sorting
)
399 if (sorting
!= this->sorting()) {
400 updateSorting(sorting
);
404 DolphinView::Sorting
DolphinView::sorting() const
406 return m_proxyModel
->sorting();
409 void DolphinView::setSortOrder(Qt::SortOrder order
)
411 if (sortOrder() != order
) {
412 updateSortOrder(order
);
416 Qt::SortOrder
DolphinView::sortOrder() const
418 return m_proxyModel
->sortOrder();
421 void DolphinView::goBack()
423 m_urlNavigator
->goBack();
426 void DolphinView::goForward()
428 m_urlNavigator
->goForward();
431 void DolphinView::goUp()
433 m_urlNavigator
->goUp();
436 void DolphinView::goHome()
438 m_urlNavigator
->goHome();
441 void DolphinView::setUrlEditable(bool editable
)
443 m_urlNavigator
->editUrl(editable
);
446 const QLinkedList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
448 return m_urlNavigator
->history(index
);
451 bool DolphinView::hasSelection() const
453 return itemView()->selectionModel()->hasSelection();
456 KFileItemList
DolphinView::selectedItems() const
458 const QAbstractItemView
* view
= itemView();
460 // Our view has a selection, we will map them back to the DirModel
461 // and then fill the KFileItemList.
462 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
464 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
465 KFileItemList itemList
;
467 const QModelIndexList indexList
= selection
.indexes();
468 QModelIndexList::const_iterator end
= indexList
.end();
469 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
470 Q_ASSERT((*it
).isValid());
472 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
474 itemList
.append(item
);
481 KUrl::List
DolphinView::selectedUrls() const
485 const KFileItemList list
= selectedItems();
486 KFileItemList::const_iterator it
= list
.begin();
487 const KFileItemList::const_iterator end
= list
.end();
489 KFileItem
* item
= *it
;
490 urls
.append(item
->url());
497 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
499 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
500 return m_dirModel
->itemForIndex(dirModelIndex
);
503 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
507 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
511 KUrl
dest(source
.upUrl());
512 dest
.addPath(newName
);
514 const bool destExists
= KIO::NetAccess::exists(dest
,
516 mainWindow()->activeView());
518 // the destination already exists, hence ask the user
520 KIO::RenameDialog
renameDialog(this,
521 i18n("File Already Exists"),
525 switch (renameDialog
.exec()) {
526 case KIO::R_OVERWRITE
:
527 // the destination should be overwritten
528 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
531 case KIO::R_RENAME
: {
532 // a new name for the destination has been used
533 KUrl
newDest(renameDialog
.newDestUrl());
534 ok
= KIO::NetAccess::file_move(source
, newDest
);
539 // the renaming operation has been canceled
545 // no destination exists, hence just move the file to
547 ok
= KIO::NetAccess::file_move(source
, dest
);
550 const QString destFileName
= dest
.fileName();
552 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
553 DolphinStatusBar::OperationCompleted
);
555 KonqOperations::rename(this, source
, destFileName
);
558 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
559 DolphinStatusBar::Error
);
564 void DolphinView::reload()
566 startDirLister(m_urlNavigator
->url(), true);
569 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
571 QWidget::mouseReleaseEvent(event
);
572 mainWindow()->setActiveView(this);
575 DolphinMainWindow
* DolphinView::mainWindow() const
580 void DolphinView::loadDirectory(const KUrl
& url
)
582 const ViewProperties
props(url
);
584 const Mode mode
= props
.viewMode();
585 if (m_mode
!= mode
) {
591 const bool showHiddenFiles
= props
.showHiddenFiles();
592 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
593 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
594 emit
showHiddenFilesChanged();
597 const DolphinView::Sorting sorting
= props
.sorting();
598 if (sorting
!= m_proxyModel
->sorting()) {
599 m_proxyModel
->setSorting(sorting
);
600 emit
sortingChanged(sorting
);
603 const Qt::SortOrder sortOrder
= props
.sortOrder();
604 if (sortOrder
!= m_proxyModel
->sortOrder()) {
605 m_proxyModel
->setSortOrder(sortOrder
);
606 emit
sortOrderChanged(sortOrder
);
609 const bool showPreview
= props
.showPreview();
610 if (showPreview
!= m_controller
->showPreview()) {
611 m_controller
->setShowPreview(showPreview
);
612 emit
showPreviewChanged();
616 emit
urlChanged(url
);
618 m_statusBar
->clear();
621 void DolphinView::triggerItem(const QModelIndex
& index
)
623 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
624 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
625 // items are selected by the user, hence don't trigger the
626 // item specified by 'index'
630 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
636 // Prefer the local path over the URL. This assures that the
637 // volume space information is correct. Assuming that the URL is media:/sda1,
638 // and the local path is /windows/C: For the URL the space info is related
639 // to the root partition (and hence wrong) and for the local path the space
640 // info is related to the windows partition (-> correct).
641 const QString
localPath(item
->localPath());
642 if (localPath
.isEmpty()) {
646 setUrl(KUrl(localPath
));
654 void DolphinView::updateProgress(int percent
)
656 if (m_showProgress
) {
657 m_statusBar
->setProgress(percent
);
661 void DolphinView::updateItemCount()
663 if (m_showProgress
) {
664 m_statusBar
->setProgressText(QString());
665 m_statusBar
->setProgress(100);
666 m_showProgress
= false;
669 KFileItemList
items(m_dirLister
->items());
670 KFileItemList::const_iterator it
= items
.begin();
671 const KFileItemList::const_iterator end
= items
.end();
677 KFileItem
* item
= *it
;
689 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
692 void DolphinView::generatePreviews(const KFileItemList
& items
)
694 if (m_controller
->showPreview()) {
695 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
696 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
697 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
701 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
703 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
704 Q_ASSERT(idx
.isValid());
705 Q_ASSERT(idx
.column() == 0);
706 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
709 void DolphinView::restoreContentsPos()
712 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
713 if (!history
.isEmpty()) {
714 QAbstractItemView
* view
= itemView();
715 // TODO: view->setCurrentItem(history[index].currentFileName());
717 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
719 view
->horizontalScrollBar()->setValue((*it
).contentsX());
720 view
->verticalScrollBar()->setValue((*it
).contentsY());
724 void DolphinView::showInfoMessage(const QString
& msg
)
726 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
729 void DolphinView::showErrorMessage(const QString
& msg
)
731 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
734 void DolphinView::emitSelectionChangedSignal()
736 emit
selectionChanged();
739 void DolphinView::closeFilterBar()
742 emit
showFilterBarChanged(false);
745 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
747 if (!url
.isValid()) {
748 const QString
location(url
.pathOrUrl());
749 if (location
.isEmpty()) {
750 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
753 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
754 DolphinStatusBar::Error
);
759 // Only show the directory loading progress if the status bar does
760 // not contain another progress information. This means that
761 // the directory loading progress information has the lowest priority.
762 const QString
progressText(m_statusBar
->progressText());
763 m_showProgress
= progressText
.isEmpty() ||
764 (progressText
== i18n("Loading directory..."));
765 if (m_showProgress
) {
766 m_statusBar
->setProgressText(i18n("Loading directory..."));
767 m_statusBar
->setProgress(0);
771 m_dirLister
->openUrl(url
, false, reload
);
774 QString
DolphinView::defaultStatusBarText() const
776 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
782 QString
DolphinView::selectionStatusBarText() const
785 const KFileItemList list
= selectedItems();
786 if (list
.isEmpty()) {
787 // when an item is triggered, it is temporary selected but selectedItems()
788 // will return an empty list
794 KIO::filesize_t byteSize
= 0;
795 KFileItemList::const_iterator it
= list
.begin();
796 const KFileItemList::const_iterator end
= list
.end();
798 KFileItem
* item
= *it
;
804 byteSize
+= item
->size();
809 if (folderCount
> 0) {
810 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
817 const QString
sizeText(KIO::convertSize(byteSize
));
818 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
824 void DolphinView::showFilterBar(bool show
)
826 assert(m_filterBar
!= 0);
835 void DolphinView::updateStatusBar()
837 // As the item count information is less important
838 // in comparison with other messages, it should only
840 // - the status bar is empty or
841 // - shows already the item count information or
842 // - shows only a not very important information
843 // - if any progress is given don't show the item count info at all
844 const QString
msg(m_statusBar
->message());
845 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
846 (msg
== m_statusBar
->defaultText()) ||
847 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
848 (m_statusBar
->progress() == 100);
850 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
851 m_statusBar
->setDefaultText(text
);
853 if (updateStatusBarMsg
) {
854 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
858 void DolphinView::requestActivation()
860 m_mainWindow
->setActiveView(this);
863 void DolphinView::changeNameFilter(const QString
& nameFilter
)
865 // The name filter of KDirLister does a 'hard' filtering, which
866 // means that only the items are shown where the names match
867 // exactly the filter. This is non-transparent for the user, which
868 // just wants to have a 'soft' filtering: does the name contain
869 // the filter string?
870 QString
adjustedFilter(nameFilter
);
871 adjustedFilter
.insert(0, '*');
872 adjustedFilter
.append('*');
874 // Use the ProxyModel to filter:
875 // This code is #ifdefed as setNameFilter behaves
876 // slightly different than the QSortFilterProxyModel
877 // as it will not remove directories. I will ask
878 // our beloved usability experts for input
881 m_dirLister
->setNameFilter(adjustedFilter
);
882 m_dirLister
->emitChanges();
884 m_proxyModel
->setFilterRegExp( nameFilter
);
888 void DolphinView::openContextMenu(const QPoint
& pos
)
892 const QModelIndex index
= itemView()->indexAt(pos
);
893 if (index
.isValid()) {
894 item
= fileItem(index
);
897 DolphinContextMenu
contextMenu(this, item
);
901 void DolphinView::dropUrls(const KUrl::List
& urls
,
904 KFileItem
* directory
= 0;
905 const QModelIndex index
= itemView()->indexAt(pos
);
906 if (index
.isValid()) {
907 KFileItem
* item
= fileItem(index
);
910 // the URLs are dropped above a directory
915 const KUrl
& destination
= (directory
== 0) ? url() :
917 dropUrls(urls
, destination
);
920 void DolphinView::dropUrls(const KUrl::List
& urls
,
921 const KUrl
& destination
)
923 m_mainWindow
->dropUrls(urls
, destination
);
927 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
929 ViewProperties
props(url());
930 props
.setSorting(sorting
);
932 m_proxyModel
->setSorting(sorting
);
934 emit
sortingChanged(sorting
);
937 void DolphinView::updateSortOrder(Qt::SortOrder order
)
939 ViewProperties
props(url());
940 props
.setSortOrder(order
);
942 m_proxyModel
->setSortOrder(order
);
944 emit
sortOrderChanged(order
);
947 void DolphinView::emitContentsMoved()
949 emit
contentsMoved(contentsX(), contentsY());
952 void DolphinView::updateActivationState()
954 m_urlNavigator
->setActive(isActive());
957 void DolphinView::createView()
959 // delete current view
960 QAbstractItemView
* view
= itemView();
962 m_topLayout
->removeWidget(view
);
969 assert(m_iconsView
== 0);
970 assert(m_detailsView
== 0);
972 // ... and recreate it representing the current mode
975 m_iconsView
= new DolphinIconsView(this, m_controller
);
980 m_detailsView
= new DolphinDetailsView(this, m_controller
);
981 view
= m_detailsView
;
985 view
->setModel(m_proxyModel
);
986 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
988 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
989 delegate
->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType
);
990 view
->setItemDelegate(delegate
);
992 new KMimeTypeResolver(view
, m_dirModel
);
993 m_topLayout
->insertWidget(1, view
);
995 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
996 m_controller
, SLOT(indicateSelectionChange()));
997 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
998 this, SLOT(emitContentsMoved()));
999 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1000 this, SLOT(emitContentsMoved()));
1003 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1005 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1006 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1008 const QModelIndex topLeft
= itemModel
->index(0, 0);
1009 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1010 itemModel
->columnCount() - 1);
1012 QItemSelection
selection(topLeft
, bottomRight
);
1013 selectionModel
->select(selection
, flags
);
1016 QAbstractItemView
* DolphinView::itemView() const
1018 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1019 if (m_detailsView
!= 0) {
1020 return m_detailsView
;
1025 #include "dolphinview.moc"