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 m_urlNavigator
->setShowHiddenFiles(showHiddenFiles
);
88 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
89 this, SLOT(loadDirectory(const KUrl
&)));
90 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
91 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
92 connect(m_urlNavigator
, SIGNAL(activated()),
93 this, SLOT(requestActivation()));
94 connect(this, SIGNAL(contentsMoved(int, int)),
95 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
97 m_statusBar
= new DolphinStatusBar(this);
99 m_dirLister
= new DolphinDirLister();
100 m_dirLister
->setAutoUpdate(true);
101 m_dirLister
->setMainWindow(this);
102 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
103 m_dirLister
->setDelayedMimeTypes(true);
105 connect(m_dirLister
, SIGNAL(clear()),
106 this, SLOT(updateStatusBar()));
107 connect(m_dirLister
, SIGNAL(percent(int)),
108 this, SLOT(updateProgress(int)));
109 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
110 this, SLOT(updateStatusBar()));
111 connect(m_dirLister
, SIGNAL(completed()),
112 this, SLOT(updateItemCount()));
113 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
114 this, SLOT(generatePreviews(const KFileItemList
&)));
115 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
116 this, SLOT(showInfoMessage(const QString
&)));
117 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
118 this, SLOT(showErrorMessage(const QString
&)));
120 m_dirModel
= new KDirModel();
121 m_dirModel
->setDirLister(m_dirLister
);
122 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
124 m_proxyModel
= new DolphinSortFilterProxyModel(this);
125 m_proxyModel
->setSourceModel(m_dirModel
);
127 m_controller
= new DolphinController(this);
128 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
129 this, SLOT(openContextMenu(const QPoint
&)));
130 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QPoint
&)),
131 this, SLOT(dropUrls(const KUrl::List
&, const QPoint
&)));
132 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
133 this, SLOT(updateSorting(DolphinView::Sorting
)));
134 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
135 this, SLOT(updateSortOrder(Qt::SortOrder
)));
136 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
137 this, SLOT(triggerItem(const QModelIndex
&)));
138 connect(m_controller
, SIGNAL(selectionChanged()),
139 this, SLOT(emitSelectionChangedSignal()));
140 connect(m_controller
, SIGNAL(activated()),
141 this, SLOT(requestActivation()));
145 m_iconSize
= K3Icon::SizeMedium
;
147 m_filterBar
= new FilterBar(this);
149 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
150 this, SLOT(changeNameFilter(const QString
&)));
151 connect(m_filterBar
, SIGNAL(closeRequest()),
152 this, SLOT(closeFilterBar()));
154 m_topLayout
->addWidget(m_urlNavigator
);
155 m_topLayout
->addWidget(itemView());
156 m_topLayout
->addWidget(m_filterBar
);
157 m_topLayout
->addWidget(m_statusBar
);
159 loadDirectory(m_urlNavigator
->url());
162 DolphinView::~DolphinView()
168 void DolphinView::setUrl(const KUrl
& url
)
170 m_urlNavigator
->setUrl(url
);
171 m_controller
->setUrl(url
);
174 const KUrl
& DolphinView::url() const
176 return m_urlNavigator
->url();
179 bool DolphinView::isActive() const
181 return m_mainWindow
->activeView() == this;
184 void DolphinView::setMode(Mode mode
)
186 if (mode
== m_mode
) {
187 return; // the wished mode is already set
192 ViewProperties
props(m_urlNavigator
->url());
193 props
.setViewMode(m_mode
);
196 startDirLister(m_urlNavigator
->url());
201 DolphinView::Mode
DolphinView::mode() const
206 void DolphinView::setShowPreview(bool show
)
208 ViewProperties
props(m_urlNavigator
->url());
209 props
.setShowPreview(show
);
211 m_controller
->setShowPreview(show
);
213 emit
showPreviewChanged();
217 bool DolphinView::showPreview() const
219 return m_controller
->showPreview();
222 void DolphinView::setShowHiddenFiles(bool show
)
224 if (m_dirLister
->showingDotFiles() == show
) {
228 ViewProperties
props(m_urlNavigator
->url());
229 props
.setShowHiddenFiles(show
);
232 m_dirLister
->setShowingDotFiles(show
);
233 m_urlNavigator
->setShowHiddenFiles(show
);
235 emit
showHiddenFilesChanged();
240 bool DolphinView::showHiddenFiles() const
242 return m_dirLister
->showingDotFiles();
245 void DolphinView::renameSelectedItems()
247 const KUrl::List urls
= selectedUrls();
248 if (urls
.count() > 1) {
249 // More than one item has been selected for renaming. Open
250 // a rename dialog and rename all items afterwards.
251 RenameDialog
dialog(urls
);
252 if (dialog
.exec() == QDialog::Rejected
) {
256 DolphinView
* view
= mainWindow()->activeView();
257 const QString
& newName
= dialog
.newName();
258 if (newName
.isEmpty()) {
259 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
260 DolphinStatusBar::Error
);
263 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
265 //UndoManager& undoMan = UndoManager::instance();
266 //undoMan.beginMacro();
268 assert(newName
.contains('#'));
270 const int urlsCount
= urls
.count();
272 // iterate through all selected items and rename them...
273 const int replaceIndex
= newName
.indexOf('#');
274 assert(replaceIndex
>= 0);
275 for (int i
= 0; i
< urlsCount
; ++i
) {
276 const KUrl
& source
= urls
[i
];
278 number
.setNum(i
+ 1);
280 QString
name(newName
);
281 name
.replace(replaceIndex
, 1, number
);
283 if (source
.fileName() != name
) {
284 KUrl
dest(source
.upUrl());
287 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
289 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
290 DolphinStatusBar::Error
);
293 else if (KIO::NetAccess::file_move(source
, dest
)) {
294 // TODO: From the users point of view he executed one 'rename n files' operation,
295 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
296 //DolphinCommand command(DolphinCommand::Rename, source, dest);
297 //undoMan.addCommand(command);
302 //undoMan.endMacro();
306 // Only one item has been selected for renaming. Use the custom
307 // renaming mechanism from the views.
308 assert(urls
.count() == 1);
310 /*if (m_mode == DetailsView) {
311 Q3ListViewItem* item = m_iconsView->firstChild();
313 if (item->isSelected()) {
314 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
317 item = item->nextSibling();
321 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
323 if (item->isSelected()) {
327 item = static_cast<KFileIconViewItem*>(item->nextItem());
333 void DolphinView::selectAll()
335 selectAll(QItemSelectionModel::Select
);
338 void DolphinView::invertSelection()
340 selectAll(QItemSelectionModel::Toggle
);
343 DolphinStatusBar
* DolphinView::statusBar() const
348 int DolphinView::contentsX() const
351 return itemView()->horizontalScrollBar()->value();
354 int DolphinView::contentsY() const
356 return itemView()->verticalScrollBar()->value();
359 void DolphinView::refreshSettings()
361 startDirLister(m_urlNavigator
->url());
364 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
366 emit
requestItemInfo(url
);
369 bool DolphinView::isFilterBarVisible() const
371 return m_filterBar
->isVisible();
374 bool DolphinView::isUrlEditable() const
376 return m_urlNavigator
->isUrlEditable();
379 void DolphinView::zoomIn()
381 m_controller
->triggerZoomIn();
384 void DolphinView::zoomOut()
386 m_controller
->triggerZoomOut();
389 bool DolphinView::isZoomInPossible() const
391 return m_controller
->isZoomInPossible();
394 bool DolphinView::isZoomOutPossible() const
396 return m_controller
->isZoomOutPossible();
399 void DolphinView::setSorting(Sorting sorting
)
401 if (sorting
!= this->sorting()) {
402 updateSorting(sorting
);
406 DolphinView::Sorting
DolphinView::sorting() const
408 return m_proxyModel
->sorting();
411 void DolphinView::setSortOrder(Qt::SortOrder order
)
413 if (sortOrder() != order
) {
414 updateSortOrder(order
);
418 Qt::SortOrder
DolphinView::sortOrder() const
420 return m_proxyModel
->sortOrder();
423 void DolphinView::goBack()
425 m_urlNavigator
->goBack();
428 void DolphinView::goForward()
430 m_urlNavigator
->goForward();
433 void DolphinView::goUp()
435 m_urlNavigator
->goUp();
438 void DolphinView::goHome()
440 m_urlNavigator
->goHome();
443 void DolphinView::setUrlEditable(bool editable
)
445 m_urlNavigator
->editUrl(editable
);
448 const QLinkedList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
450 return m_urlNavigator
->history(index
);
453 bool DolphinView::hasSelection() const
455 return itemView()->selectionModel()->hasSelection();
458 KFileItemList
DolphinView::selectedItems() const
460 const QAbstractItemView
* view
= itemView();
462 // Our view has a selection, we will map them back to the DirModel
463 // and then fill the KFileItemList.
464 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
466 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
467 KFileItemList itemList
;
469 const QModelIndexList indexList
= selection
.indexes();
470 QModelIndexList::const_iterator end
= indexList
.end();
471 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
472 Q_ASSERT((*it
).isValid());
474 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
476 itemList
.append(item
);
483 KUrl::List
DolphinView::selectedUrls() const
487 const KFileItemList list
= selectedItems();
488 KFileItemList::const_iterator it
= list
.begin();
489 const KFileItemList::const_iterator end
= list
.end();
491 KFileItem
* item
= *it
;
492 urls
.append(item
->url());
499 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
501 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
502 return m_dirModel
->itemForIndex(dirModelIndex
);
505 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
509 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
513 KUrl
dest(source
.upUrl());
514 dest
.addPath(newName
);
516 const bool destExists
= KIO::NetAccess::exists(dest
,
518 mainWindow()->activeView());
520 // the destination already exists, hence ask the user
522 KIO::RenameDialog
renameDialog(this,
523 i18n("File Already Exists"),
527 switch (renameDialog
.exec()) {
528 case KIO::R_OVERWRITE
:
529 // the destination should be overwritten
530 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
533 case KIO::R_RENAME
: {
534 // a new name for the destination has been used
535 KUrl
newDest(renameDialog
.newDestUrl());
536 ok
= KIO::NetAccess::file_move(source
, newDest
);
541 // the renaming operation has been canceled
547 // no destination exists, hence just move the file to
549 ok
= KIO::NetAccess::file_move(source
, dest
);
552 const QString destFileName
= dest
.fileName();
554 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
555 DolphinStatusBar::OperationCompleted
);
557 KonqOperations::rename(this, source
, destFileName
);
560 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
561 DolphinStatusBar::Error
);
566 void DolphinView::reload()
568 startDirLister(m_urlNavigator
->url(), true);
571 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
573 QWidget::mouseReleaseEvent(event
);
574 mainWindow()->setActiveView(this);
577 DolphinMainWindow
* DolphinView::mainWindow() const
582 void DolphinView::loadDirectory(const KUrl
& url
)
584 const ViewProperties
props(url
);
586 const Mode mode
= props
.viewMode();
587 if (m_mode
!= mode
) {
593 const bool showHiddenFiles
= props
.showHiddenFiles();
594 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
595 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
596 emit
showHiddenFilesChanged();
599 const DolphinView::Sorting sorting
= props
.sorting();
600 if (sorting
!= m_proxyModel
->sorting()) {
601 m_proxyModel
->setSorting(sorting
);
602 emit
sortingChanged(sorting
);
605 const Qt::SortOrder sortOrder
= props
.sortOrder();
606 if (sortOrder
!= m_proxyModel
->sortOrder()) {
607 m_proxyModel
->setSortOrder(sortOrder
);
608 emit
sortOrderChanged(sortOrder
);
611 const bool showPreview
= props
.showPreview();
612 if (showPreview
!= m_controller
->showPreview()) {
613 m_controller
->setShowPreview(showPreview
);
614 emit
showPreviewChanged();
618 emit
urlChanged(url
);
620 m_statusBar
->clear();
623 void DolphinView::triggerItem(const QModelIndex
& index
)
625 if (!isValidNameIndex(index
)) {
629 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
630 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
631 // items are selected by the user, hence don't trigger the
632 // item specified by 'index'
636 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
641 // Prefer the local path over the URL. This assures that the
642 // volume space information is correct. Assuming that the URL is media:/sda1,
643 // and the local path is /windows/C: For the URL the space info is related
644 // to the root partition (and hence wrong) and for the local path the space
645 // info is related to the windows partition (-> correct).
646 const QString
localPath(item
->localPath());
648 if (localPath
.isEmpty()) {
658 else if (item
->isFile()) {
659 // allow to browse through ZIP and tar files
660 KMimeType::Ptr mime
= item
->mimeTypePtr();
661 if (mime
->is("application/x-zip")) {
662 url
.setProtocol("zip");
665 else if (mime
->is("application/x-tar") ||
666 mime
->is("application/x-tarz") ||
667 mime
->is("application/x-tbz") ||
668 mime
->is("application/x-tgz") ||
669 mime
->is("application/x-tzo")) {
670 url
.setProtocol("tar");
682 void DolphinView::updateProgress(int percent
)
684 if (m_showProgress
) {
685 m_statusBar
->setProgress(percent
);
689 void DolphinView::updateItemCount()
691 if (m_showProgress
) {
692 m_statusBar
->setProgressText(QString());
693 m_statusBar
->setProgress(100);
694 m_showProgress
= false;
697 KFileItemList
items(m_dirLister
->items());
698 KFileItemList::const_iterator it
= items
.begin();
699 const KFileItemList::const_iterator end
= items
.end();
705 KFileItem
* item
= *it
;
717 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
720 void DolphinView::generatePreviews(const KFileItemList
& items
)
722 if (m_controller
->showPreview()) {
723 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
724 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
725 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
729 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
732 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
733 if (idx
.isValid() && (idx
.column() == 0)) {
734 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
738 void DolphinView::restoreContentsPos()
741 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
742 if (!history
.isEmpty()) {
743 QAbstractItemView
* view
= itemView();
744 // TODO: view->setCurrentItem(history[index].currentFileName());
746 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
748 view
->horizontalScrollBar()->setValue((*it
).contentsX());
749 view
->verticalScrollBar()->setValue((*it
).contentsY());
753 void DolphinView::showInfoMessage(const QString
& msg
)
755 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
758 void DolphinView::showErrorMessage(const QString
& msg
)
760 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
763 void DolphinView::emitSelectionChangedSignal()
765 emit
selectionChanged();
768 void DolphinView::closeFilterBar()
771 emit
showFilterBarChanged(false);
774 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
776 if (!url
.isValid()) {
777 const QString
location(url
.pathOrUrl());
778 if (location
.isEmpty()) {
779 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
782 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
783 DolphinStatusBar::Error
);
788 // Only show the directory loading progress if the status bar does
789 // not contain another progress information. This means that
790 // the directory loading progress information has the lowest priority.
791 const QString
progressText(m_statusBar
->progressText());
792 m_showProgress
= progressText
.isEmpty() ||
793 (progressText
== i18n("Loading directory..."));
794 if (m_showProgress
) {
795 m_statusBar
->setProgressText(i18n("Loading directory..."));
796 m_statusBar
->setProgress(0);
800 m_dirLister
->openUrl(url
, false, reload
);
803 QString
DolphinView::defaultStatusBarText() const
805 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
811 QString
DolphinView::selectionStatusBarText() const
814 const KFileItemList list
= selectedItems();
815 if (list
.isEmpty()) {
816 // when an item is triggered, it is temporary selected but selectedItems()
817 // will return an empty list
823 KIO::filesize_t byteSize
= 0;
824 KFileItemList::const_iterator it
= list
.begin();
825 const KFileItemList::const_iterator end
= list
.end();
827 KFileItem
* item
= *it
;
833 byteSize
+= item
->size();
838 if (folderCount
> 0) {
839 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
846 const QString
sizeText(KIO::convertSize(byteSize
));
847 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
853 void DolphinView::showFilterBar(bool show
)
855 assert(m_filterBar
!= 0);
864 void DolphinView::updateStatusBar()
866 // As the item count information is less important
867 // in comparison with other messages, it should only
869 // - the status bar is empty or
870 // - shows already the item count information or
871 // - shows only a not very important information
872 // - if any progress is given don't show the item count info at all
873 const QString
msg(m_statusBar
->message());
874 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
875 (msg
== m_statusBar
->defaultText()) ||
876 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
877 (m_statusBar
->progress() == 100);
879 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
880 m_statusBar
->setDefaultText(text
);
882 if (updateStatusBarMsg
) {
883 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
887 void DolphinView::requestActivation()
889 m_mainWindow
->setActiveView(this);
892 void DolphinView::changeNameFilter(const QString
& nameFilter
)
894 // The name filter of KDirLister does a 'hard' filtering, which
895 // means that only the items are shown where the names match
896 // exactly the filter. This is non-transparent for the user, which
897 // just wants to have a 'soft' filtering: does the name contain
898 // the filter string?
899 QString
adjustedFilter(nameFilter
);
900 adjustedFilter
.insert(0, '*');
901 adjustedFilter
.append('*');
903 // Use the ProxyModel to filter:
904 // This code is #ifdefed as setNameFilter behaves
905 // slightly different than the QSortFilterProxyModel
906 // as it will not remove directories. I will ask
907 // our beloved usability experts for input
910 m_dirLister
->setNameFilter(adjustedFilter
);
911 m_dirLister
->emitChanges();
913 m_proxyModel
->setFilterRegExp( nameFilter
);
917 void DolphinView::openContextMenu(const QPoint
& pos
)
921 const QModelIndex index
= itemView()->indexAt(pos
);
922 if (isValidNameIndex(index
)) {
923 item
= fileItem(index
);
926 DolphinContextMenu
contextMenu(this, item
);
930 void DolphinView::dropUrls(const KUrl::List
& urls
,
933 KFileItem
* directory
= 0;
934 const QModelIndex index
= itemView()->indexAt(pos
);
935 if (isValidNameIndex(index
)) {
936 KFileItem
* item
= fileItem(index
);
939 // the URLs are dropped above a directory
944 const KUrl
& destination
= (directory
== 0) ? url() :
946 dropUrls(urls
, destination
);
949 void DolphinView::dropUrls(const KUrl::List
& urls
,
950 const KUrl
& destination
)
952 m_mainWindow
->dropUrls(urls
, destination
);
956 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
958 ViewProperties
props(url());
959 props
.setSorting(sorting
);
961 m_proxyModel
->setSorting(sorting
);
963 emit
sortingChanged(sorting
);
966 void DolphinView::updateSortOrder(Qt::SortOrder order
)
968 ViewProperties
props(url());
969 props
.setSortOrder(order
);
971 m_proxyModel
->setSortOrder(order
);
973 emit
sortOrderChanged(order
);
976 void DolphinView::emitContentsMoved()
978 emit
contentsMoved(contentsX(), contentsY());
981 void DolphinView::updateActivationState()
983 m_urlNavigator
->setActive(isActive());
986 void DolphinView::createView()
988 // delete current view
989 QAbstractItemView
* view
= itemView();
991 m_topLayout
->removeWidget(view
);
998 assert(m_iconsView
== 0);
999 assert(m_detailsView
== 0);
1001 // ... and recreate it representing the current mode
1004 m_iconsView
= new DolphinIconsView(this, m_controller
);
1009 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1010 view
= m_detailsView
;
1014 view
->setModel(m_proxyModel
);
1015 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1017 new KMimeTypeResolver(view
, m_dirModel
);
1018 m_topLayout
->insertWidget(1, view
);
1020 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1021 m_controller
, SLOT(indicateSelectionChange()));
1022 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1023 this, SLOT(emitContentsMoved()));
1024 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1025 this, SLOT(emitContentsMoved()));
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 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1044 if (m_detailsView
!= 0) {
1045 return m_detailsView
;
1050 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1052 return index
.isValid() && (index
.column() == KDirModel::Name
);
1055 #include "dolphinview.moc"