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 <QApplication>
26 #include <QItemSelectionModel>
27 #include <QMouseEvent>
28 #include <QVBoxLayout>
30 #include <kdirmodel.h>
31 #include <kfileitemdelegate.h>
33 #include <kiconeffect.h>
34 #include <kio/netaccess.h>
35 #include <kio/renamedialog.h>
36 #include <kio/previewjob.h>
37 #include <kmimetyperesolver.h>
38 #include <konqmimedata.h>
39 #include <konq_operations.h>
42 #include "dolphincontroller.h"
43 #include "dolphinstatusbar.h"
44 #include "dolphinmainwindow.h"
45 #include "dolphindirlister.h"
46 #include "dolphinsortfilterproxymodel.h"
47 #include "dolphindetailsview.h"
48 #include "dolphiniconsview.h"
49 #include "dolphincontextmenu.h"
50 #include "filterbar.h"
51 #include "renamedialog.h"
52 #include "urlnavigator.h"
53 #include "viewproperties.h"
55 DolphinView::DolphinView(DolphinMainWindow
* mainWindow
,
59 bool showHiddenFiles
) :
61 m_showProgress(false),
62 m_blockContentsMovedSignal(false),
67 m_mainWindow(mainWindow
),
73 m_fileItemDelegate(0),
81 setFocusPolicy(Qt::StrongFocus
);
82 m_topLayout
= new QVBoxLayout(this);
83 m_topLayout
->setSpacing(0);
84 m_topLayout
->setMargin(0);
86 connect(m_mainWindow
, SIGNAL(activeViewChanged()),
87 this, SLOT(updateActivationState()));
89 QClipboard
* clipboard
= QApplication::clipboard();
90 connect(clipboard
, SIGNAL(dataChanged()),
91 this, SLOT(updateCutItems()));
93 m_urlNavigator
= new UrlNavigator(url
, this);
94 m_urlNavigator
->setShowHiddenFiles(showHiddenFiles
);
95 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
96 this, SLOT(loadDirectory(const KUrl
&)));
97 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
98 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
99 connect(m_urlNavigator
, SIGNAL(activated()),
100 this, SLOT(requestActivation()));
101 connect(this, SIGNAL(contentsMoved(int, int)),
102 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
104 m_statusBar
= new DolphinStatusBar(this);
106 m_dirLister
= new DolphinDirLister();
107 m_dirLister
->setAutoUpdate(true);
108 m_dirLister
->setMainWindow(this);
109 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
110 m_dirLister
->setDelayedMimeTypes(true);
112 connect(m_dirLister
, SIGNAL(clear()),
113 this, SLOT(updateStatusBar()));
114 connect(m_dirLister
, SIGNAL(percent(int)),
115 this, SLOT(updateProgress(int)));
116 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
117 this, SLOT(updateStatusBar()));
118 connect(m_dirLister
, SIGNAL(completed()),
119 this, SLOT(updateItemCount()));
120 connect(m_dirLister
, SIGNAL(completed()),
121 this, SLOT(updateCutItems()));
122 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
123 this, SLOT(generatePreviews(const KFileItemList
&)));
124 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
125 this, SLOT(showInfoMessage(const QString
&)));
126 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
127 this, SLOT(showErrorMessage(const QString
&)));
129 m_dirModel
= new KDirModel();
130 m_dirModel
->setDirLister(m_dirLister
);
131 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
133 m_proxyModel
= new DolphinSortFilterProxyModel(this);
134 m_proxyModel
->setSourceModel(m_dirModel
);
136 m_controller
= new DolphinController(this);
137 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
138 this, SLOT(openContextMenu(const QPoint
&)));
139 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
140 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
141 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
142 this, SLOT(updateSorting(DolphinView::Sorting
)));
143 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
144 this, SLOT(updateSortOrder(Qt::SortOrder
)));
145 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
146 this, SLOT(triggerItem(const QModelIndex
&)));
147 connect(m_controller
, SIGNAL(selectionChanged()),
148 this, SLOT(emitSelectionChangedSignal()));
149 connect(m_controller
, SIGNAL(activated()),
150 this, SLOT(requestActivation()));
154 m_iconSize
= K3Icon::SizeMedium
;
156 m_filterBar
= new FilterBar(this);
158 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
159 this, SLOT(changeNameFilter(const QString
&)));
160 connect(m_filterBar
, SIGNAL(closeRequest()),
161 this, SLOT(closeFilterBar()));
163 m_topLayout
->addWidget(m_urlNavigator
);
164 m_topLayout
->addWidget(itemView());
165 m_topLayout
->addWidget(m_filterBar
);
166 m_topLayout
->addWidget(m_statusBar
);
169 DolphinView::~DolphinView()
175 void DolphinView::setUrl(const KUrl
& url
)
177 m_urlNavigator
->setUrl(url
);
178 m_controller
->setUrl(url
);
181 const KUrl
& DolphinView::url() const
183 return m_urlNavigator
->url();
186 bool DolphinView::isActive() const
188 return m_mainWindow
->activeView() == this;
191 void DolphinView::setMode(Mode mode
)
193 if (mode
== m_mode
) {
194 return; // the wished mode is already set
199 ViewProperties
props(m_urlNavigator
->url());
200 props
.setViewMode(m_mode
);
203 startDirLister(m_urlNavigator
->url());
208 DolphinView::Mode
DolphinView::mode() const
213 void DolphinView::setShowPreview(bool show
)
215 ViewProperties
props(m_urlNavigator
->url());
216 props
.setShowPreview(show
);
218 m_controller
->setShowPreview(show
);
220 emit
showPreviewChanged();
224 bool DolphinView::showPreview() const
226 return m_controller
->showPreview();
229 void DolphinView::setShowHiddenFiles(bool show
)
231 if (m_dirLister
->showingDotFiles() == show
) {
235 ViewProperties
props(m_urlNavigator
->url());
236 props
.setShowHiddenFiles(show
);
239 m_dirLister
->setShowingDotFiles(show
);
240 m_urlNavigator
->setShowHiddenFiles(show
);
242 emit
showHiddenFilesChanged();
247 bool DolphinView::showHiddenFiles() const
249 return m_dirLister
->showingDotFiles();
252 void DolphinView::renameSelectedItems()
254 DolphinView
* view
= mainWindow()->activeView();
255 const KUrl::List urls
= selectedUrls();
256 if (urls
.count() > 1) {
257 // More than one item has been selected for renaming. Open
258 // a rename dialog and rename all items afterwards.
259 RenameDialog
dialog(urls
);
260 if (dialog
.exec() == QDialog::Rejected
) {
264 const QString
& newName
= dialog
.newName();
265 if (newName
.isEmpty()) {
266 view
->statusBar()->setMessage(dialog
.errorString(),
267 DolphinStatusBar::Error
);
270 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
271 // as one operation instead of n rename operations like it is done now...
272 Q_ASSERT(newName
.contains('#'));
274 // iterate through all selected items and rename them...
275 const int replaceIndex
= newName
.indexOf('#');
276 Q_ASSERT(replaceIndex
>= 0);
279 KUrl::List::const_iterator it
= urls
.begin();
280 KUrl::List::const_iterator end
= urls
.end();
282 const KUrl
& oldUrl
= *it
;
284 number
.setNum(index
++);
286 QString
name(newName
);
287 name
.replace(replaceIndex
, 1, number
);
289 if (oldUrl
.fileName() != name
) {
290 KUrl
newUrl(oldUrl
.upUrl());
291 newUrl
.addPath(name
);
292 m_mainWindow
->rename(oldUrl
, newUrl
);
299 // Only one item has been selected for renaming. Use the custom
300 // renaming mechanism from the views.
301 Q_ASSERT(urls
.count() == 1);
303 // TODO: Think about using KFileItemDelegate as soon as it supports editing.
304 // Currently the RenameDialog is used, but I'm not sure whether inline renaming
305 // is a benefit for the user at all -> let's wait for some input first...
306 RenameDialog
dialog(urls
);
307 if (dialog
.exec() == QDialog::Rejected
) {
311 const QString
& newName
= dialog
.newName();
312 if (newName
.isEmpty()) {
313 view
->statusBar()->setMessage(dialog
.errorString(),
314 DolphinStatusBar::Error
);
317 const KUrl
& oldUrl
= urls
.first();
318 KUrl newUrl
= oldUrl
.upUrl();
319 newUrl
.addPath(newName
);
320 m_mainWindow
->rename(oldUrl
, newUrl
);
325 void DolphinView::selectAll()
327 selectAll(QItemSelectionModel::Select
);
330 void DolphinView::invertSelection()
332 selectAll(QItemSelectionModel::Toggle
);
335 DolphinStatusBar
* DolphinView::statusBar() const
340 int DolphinView::contentsX() const
343 return itemView()->horizontalScrollBar()->value();
346 int DolphinView::contentsY() const
348 return itemView()->verticalScrollBar()->value();
351 void DolphinView::refreshSettings()
353 startDirLister(m_urlNavigator
->url());
356 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
358 emit
requestItemInfo(url
);
361 bool DolphinView::isFilterBarVisible() const
363 return m_filterBar
->isVisible();
366 bool DolphinView::isUrlEditable() const
368 return m_urlNavigator
->isUrlEditable();
371 void DolphinView::zoomIn()
373 m_controller
->triggerZoomIn();
376 void DolphinView::zoomOut()
378 m_controller
->triggerZoomOut();
381 bool DolphinView::isZoomInPossible() const
383 return m_controller
->isZoomInPossible();
386 bool DolphinView::isZoomOutPossible() const
388 return m_controller
->isZoomOutPossible();
391 void DolphinView::setSorting(Sorting sorting
)
393 if (sorting
!= this->sorting()) {
394 updateSorting(sorting
);
398 DolphinView::Sorting
DolphinView::sorting() const
400 return m_proxyModel
->sorting();
403 void DolphinView::setSortOrder(Qt::SortOrder order
)
405 if (sortOrder() != order
) {
406 updateSortOrder(order
);
410 Qt::SortOrder
DolphinView::sortOrder() const
412 return m_proxyModel
->sortOrder();
415 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
417 ViewProperties
props(m_urlNavigator
->url());
418 props
.setAdditionalInfo(info
);
420 m_fileItemDelegate
->setAdditionalInformation(info
);
422 emit
additionalInfoChanged(info
);
426 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
428 return m_fileItemDelegate
->additionalInformation();
431 void DolphinView::goBack()
433 m_urlNavigator
->goBack();
436 void DolphinView::goForward()
438 m_urlNavigator
->goForward();
441 void DolphinView::goUp()
443 m_urlNavigator
->goUp();
446 void DolphinView::goHome()
448 m_urlNavigator
->goHome();
451 void DolphinView::setUrlEditable(bool editable
)
453 m_urlNavigator
->editUrl(editable
);
456 const QLinkedList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
458 return m_urlNavigator
->history(index
);
461 bool DolphinView::hasSelection() const
463 return itemView()->selectionModel()->hasSelection();
466 void DolphinView::clearSelection()
468 itemView()->selectionModel()->clear();
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 Q_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 Q_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 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
514 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
515 return m_dirModel
->itemForIndex(dirModelIndex
);
518 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
522 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
526 KUrl
dest(source
.upUrl());
527 dest
.addPath(newName
);
529 const bool destExists
= KIO::NetAccess::exists(dest
,
531 mainWindow()->activeView());
533 // the destination already exists, hence ask the user
535 KIO::RenameDialog
renameDialog(this,
536 i18n("File Already Exists"),
540 switch (renameDialog
.exec()) {
541 case KIO::R_OVERWRITE
:
542 // the destination should be overwritten
543 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
546 case KIO::R_RENAME
: {
547 // a new name for the destination has been used
548 KUrl
newDest(renameDialog
.newDestUrl());
549 ok
= KIO::NetAccess::file_move(source
, newDest
);
554 // the renaming operation has been canceled
560 // no destination exists, hence just move the file to
562 ok
= KIO::NetAccess::file_move(source
, dest
);
565 const QString destFileName
= dest
.fileName();
567 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
568 DolphinStatusBar::OperationCompleted
);
570 KonqOperations::rename(this, source
, destFileName
);
573 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
574 DolphinStatusBar::Error
);
579 void DolphinView::reload()
581 startDirLister(m_urlNavigator
->url(), true);
584 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
586 QWidget::mouseReleaseEvent(event
);
587 mainWindow()->setActiveView(this);
590 DolphinMainWindow
* DolphinView::mainWindow() const
595 void DolphinView::loadDirectory(const KUrl
& url
)
601 const ViewProperties
props(url
);
603 const Mode mode
= props
.viewMode();
604 if (m_mode
!= mode
) {
610 const bool showHiddenFiles
= props
.showHiddenFiles();
611 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
612 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
613 emit
showHiddenFilesChanged();
616 const DolphinView::Sorting sorting
= props
.sorting();
617 if (sorting
!= m_proxyModel
->sorting()) {
618 m_proxyModel
->setSorting(sorting
);
619 emit
sortingChanged(sorting
);
622 const Qt::SortOrder sortOrder
= props
.sortOrder();
623 if (sortOrder
!= m_proxyModel
->sortOrder()) {
624 m_proxyModel
->setSortOrder(sortOrder
);
625 emit
sortOrderChanged(sortOrder
);
628 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
629 if (info
!= m_fileItemDelegate
->additionalInformation()) {
630 m_fileItemDelegate
->setAdditionalInformation(info
);
632 emit
additionalInfoChanged(info
);
635 const bool showPreview
= props
.showPreview();
636 if (showPreview
!= m_controller
->showPreview()) {
637 m_controller
->setShowPreview(showPreview
);
638 emit
showPreviewChanged();
642 emit
urlChanged(url
);
644 m_statusBar
->clear();
647 void DolphinView::triggerItem(const QModelIndex
& index
)
649 if (!isValidNameIndex(index
)) {
653 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
654 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
655 // items are selected by the user, hence don't trigger the
656 // item specified by 'index'
660 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
665 // Prefer the local path over the URL. This assures that the
666 // volume space information is correct. Assuming that the URL is media:/sda1,
667 // and the local path is /windows/C: For the URL the space info is related
668 // to the root partition (and hence wrong) and for the local path the space
669 // info is related to the windows partition (-> correct).
670 const QString
localPath(item
->localPath());
672 if (localPath
.isEmpty()) {
682 else if (item
->isFile()) {
683 // allow to browse through ZIP and tar files
684 KMimeType::Ptr mime
= item
->mimeTypePtr();
685 if (mime
->is("application/zip")) {
686 url
.setProtocol("zip");
689 else if (mime
->is("application/x-tar") ||
690 mime
->is("application/x-tarz") ||
691 mime
->is("application/x-bzip-compressed-tar") ||
692 mime
->is("application/x-compressed-tar") ||
693 mime
->is("application/x-tzo")) {
694 url
.setProtocol("tar");
706 void DolphinView::updateProgress(int percent
)
708 if (m_showProgress
) {
709 m_statusBar
->setProgress(percent
);
713 void DolphinView::updateItemCount()
715 if (m_showProgress
) {
716 m_statusBar
->setProgressText(QString());
717 m_statusBar
->setProgress(100);
718 m_showProgress
= false;
721 KFileItemList
items(m_dirLister
->items());
722 KFileItemList::const_iterator it
= items
.begin();
723 const KFileItemList::const_iterator end
= items
.end();
729 KFileItem
* item
= *it
;
741 m_blockContentsMovedSignal
= false;
742 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
745 void DolphinView::generatePreviews(const KFileItemList
& items
)
747 if (m_controller
->showPreview()) {
748 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
749 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
750 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
754 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
757 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
758 if (idx
.isValid() && (idx
.column() == 0)) {
759 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
760 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(*item
)) {
761 KIconEffect iconEffect
;
762 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
763 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
766 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
771 void DolphinView::restoreContentsPos()
774 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
775 if (!history
.isEmpty()) {
776 QAbstractItemView
* view
= itemView();
777 // TODO: view->setCurrentItem(history[index].currentFileName());
779 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
781 view
->horizontalScrollBar()->setValue((*it
).contentsX());
782 view
->verticalScrollBar()->setValue((*it
).contentsY());
786 void DolphinView::showInfoMessage(const QString
& msg
)
788 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
791 void DolphinView::showErrorMessage(const QString
& msg
)
793 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
796 void DolphinView::emitSelectionChangedSignal()
798 emit
selectionChanged(DolphinView::selectedItems());
801 void DolphinView::closeFilterBar()
804 emit
showFilterBarChanged(false);
807 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
809 if (!url
.isValid()) {
810 const QString
location(url
.pathOrUrl());
811 if (location
.isEmpty()) {
812 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
815 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
816 DolphinStatusBar::Error
);
821 // Only show the directory loading progress if the status bar does
822 // not contain another progress information. This means that
823 // the directory loading progress information has the lowest priority.
824 const QString
progressText(m_statusBar
->progressText());
825 m_showProgress
= progressText
.isEmpty() ||
826 (progressText
== i18n("Loading directory..."));
827 if (m_showProgress
) {
828 m_statusBar
->setProgressText(i18n("Loading directory..."));
829 m_statusBar
->setProgress(0);
832 m_cutItemsCache
.clear();
833 m_blockContentsMovedSignal
= true;
835 m_dirLister
->openUrl(url
, false, reload
);
838 QString
DolphinView::defaultStatusBarText() const
840 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
846 QString
DolphinView::selectionStatusBarText() const
849 const KFileItemList list
= selectedItems();
850 if (list
.isEmpty()) {
851 // when an item is triggered, it is temporary selected but selectedItems()
852 // will return an empty list
858 KIO::filesize_t byteSize
= 0;
859 KFileItemList::const_iterator it
= list
.begin();
860 const KFileItemList::const_iterator end
= list
.end();
862 KFileItem
* item
= *it
;
868 byteSize
+= item
->size();
873 if (folderCount
> 0) {
874 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
881 const QString
sizeText(KIO::convertSize(byteSize
));
882 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
888 void DolphinView::showFilterBar(bool show
)
890 Q_ASSERT(m_filterBar
!= 0);
899 void DolphinView::updateStatusBar()
901 // As the item count information is less important
902 // in comparison with other messages, it should only
904 // - the status bar is empty or
905 // - shows already the item count information or
906 // - shows only a not very important information
907 // - if any progress is given don't show the item count info at all
908 const QString
msg(m_statusBar
->message());
909 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
910 (msg
== m_statusBar
->defaultText()) ||
911 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
912 (m_statusBar
->progress() == 100);
914 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
915 m_statusBar
->setDefaultText(text
);
917 if (updateStatusBarMsg
) {
918 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
922 void DolphinView::requestActivation()
924 m_mainWindow
->setActiveView(this);
927 void DolphinView::changeSelection(const KFileItemList
& selection
)
930 if (selection
.isEmpty()) {
933 KUrl baseUrl
= url();
935 QItemSelection new_selection
;
936 foreach (KFileItem
* item
, selection
) {
937 url
= item
->url().upUrl();
938 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
939 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
940 new_selection
.select(index
, index
);
943 itemView()->selectionModel()->select(new_selection
,
944 QItemSelectionModel::ClearAndSelect
945 | QItemSelectionModel::Current
);
948 void DolphinView::changeNameFilter(const QString
& nameFilter
)
950 // The name filter of KDirLister does a 'hard' filtering, which
951 // means that only the items are shown where the names match
952 // exactly the filter. This is non-transparent for the user, which
953 // just wants to have a 'soft' filtering: does the name contain
954 // the filter string?
955 QString
adjustedFilter(nameFilter
);
956 adjustedFilter
.insert(0, '*');
957 adjustedFilter
.append('*');
959 // Use the ProxyModel to filter:
960 // This code is #ifdefed as setNameFilter behaves
961 // slightly different than the QSortFilterProxyModel
962 // as it will not remove directories. I will ask
963 // our beloved usability experts for input
966 m_dirLister
->setNameFilter(adjustedFilter
);
967 m_dirLister
->emitChanges();
969 m_proxyModel
->setFilterRegExp( nameFilter
);
973 void DolphinView::openContextMenu(const QPoint
& pos
)
977 const QModelIndex index
= itemView()->indexAt(pos
);
978 if (isValidNameIndex(index
)) {
979 item
= fileItem(index
);
982 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url());
986 void DolphinView::dropUrls(const KUrl::List
& urls
,
987 const QModelIndex
& index
,
990 KFileItem
* directory
= 0;
991 if (isValidNameIndex(index
)) {
992 KFileItem
* item
= fileItem(index
);
995 // the URLs are dropped above a directory
1000 if ((directory
== 0) && (source
== itemView())) {
1001 // The dropping is done into the same viewport where
1002 // the dragging has been started. Just ignore this...
1006 const KUrl
& destination
= (directory
== 0) ? url() :
1008 dropUrls(urls
, destination
);
1011 void DolphinView::dropUrls(const KUrl::List
& urls
,
1012 const KUrl
& destination
)
1014 m_mainWindow
->dropUrls(urls
, destination
);
1017 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
1019 ViewProperties
props(url());
1020 props
.setSorting(sorting
);
1022 m_proxyModel
->setSorting(sorting
);
1024 emit
sortingChanged(sorting
);
1027 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1029 ViewProperties
props(url());
1030 props
.setSortOrder(order
);
1032 m_proxyModel
->setSortOrder(order
);
1034 emit
sortOrderChanged(order
);
1037 void DolphinView::emitContentsMoved()
1039 if (!m_blockContentsMovedSignal
) {
1040 emit
contentsMoved(contentsX(), contentsY());
1044 void DolphinView::updateActivationState()
1046 m_urlNavigator
->setActive(isActive());
1048 emit
urlChanged(url());
1049 emit
selectionChanged(selectedItems());
1053 void DolphinView::updateCutItems()
1055 // restore the icons of all previously selected items to the
1056 // original state...
1057 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
1058 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
1060 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
1061 if (index
.isValid()) {
1062 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
1066 m_cutItemsCache
.clear();
1068 // ... and apply an item effect to all currently cut items
1069 applyCutItemEffect();
1072 void DolphinView::createView()
1074 // delete current view
1075 QAbstractItemView
* view
= itemView();
1077 m_topLayout
->removeWidget(view
);
1079 view
->deleteLater();
1083 m_fileItemDelegate
= 0;
1086 Q_ASSERT(m_iconsView
== 0);
1087 Q_ASSERT(m_detailsView
== 0);
1089 // ... and recreate it representing the current mode
1092 m_iconsView
= new DolphinIconsView(this, m_controller
);
1097 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1098 view
= m_detailsView
;
1102 Q_ASSERT(view
!= 0);
1104 m_fileItemDelegate
= new KFileItemDelegate(view
);
1105 view
->setItemDelegate(m_fileItemDelegate
);
1107 view
->setModel(m_proxyModel
);
1108 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1110 new KMimeTypeResolver(view
, m_dirModel
);
1111 m_topLayout
->insertWidget(1, view
);
1113 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1114 m_controller
, SLOT(indicateSelectionChange()));
1115 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1116 this, SLOT(emitContentsMoved()));
1117 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1118 this, SLOT(emitContentsMoved()));
1121 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1123 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1124 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1126 const QModelIndex topLeft
= itemModel
->index(0, 0);
1127 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1128 itemModel
->columnCount() - 1);
1130 QItemSelection
selection(topLeft
, bottomRight
);
1131 selectionModel
->select(selection
, flags
);
1134 QAbstractItemView
* DolphinView::itemView() const
1136 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1137 if (m_detailsView
!= 0) {
1138 return m_detailsView
;
1143 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1145 return index
.isValid() && (index
.column() == KDirModel::Name
);
1148 bool DolphinView::isCutItem(const KFileItem
& item
) const
1150 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1151 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1153 const KUrl
& itemUrl
= item
.url();
1154 KUrl::List::const_iterator it
= cutUrls
.begin();
1155 const KUrl::List::const_iterator end
= cutUrls
.end();
1157 if (*it
== itemUrl
) {
1166 void DolphinView::applyCutItemEffect()
1168 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1169 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
1173 KFileItemList
items(m_dirLister
->items());
1174 KFileItemList::const_iterator it
= items
.begin();
1175 const KFileItemList::const_iterator end
= items
.end();
1177 KFileItem
* item
= *it
;
1178 if (isCutItem(*item
)) {
1179 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
1180 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
1181 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
1182 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
1183 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
1184 QPixmap pixmap
= icon
.pixmap(128, 128);
1186 // remember current pixmap for the item to be able
1187 // to restore it when other items get cut
1189 cutItem
.url
= item
->url();
1190 cutItem
.pixmap
= pixmap
;
1191 m_cutItemsCache
.append(cutItem
);
1193 // apply icon effect to the cut item
1194 KIconEffect iconEffect
;
1195 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
1196 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
1203 #include "dolphinview.moc"