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>
28 #include <QItemSelectionModel>
29 #include <QMouseEvent>
30 #include <QVBoxLayout>
32 #include <kdirmodel.h>
33 #include <kfileitemdelegate.h>
35 #include <kiconeffect.h>
36 #include <kio/netaccess.h>
37 #include <kio/renamedialog.h>
38 #include <kio/previewjob.h>
39 #include <kmimetyperesolver.h>
40 #include <konqmimedata.h>
41 #include <konq_operations.h>
44 #include "dolphincontroller.h"
45 #include "dolphinstatusbar.h"
46 #include "dolphinmainwindow.h"
47 #include "dolphindirlister.h"
48 #include "dolphinsortfilterproxymodel.h"
49 #include "dolphindetailsview.h"
50 #include "dolphiniconsview.h"
51 #include "dolphincontextmenu.h"
52 #include "filterbar.h"
53 #include "renamedialog.h"
54 #include "urlnavigator.h"
55 #include "viewproperties.h"
57 DolphinView::DolphinView(DolphinMainWindow
* mainWindow
,
61 bool showHiddenFiles
) :
63 m_showProgress(false),
68 m_mainWindow(mainWindow
),
74 m_fileItemDelegate(0),
82 setFocusPolicy(Qt::StrongFocus
);
83 m_topLayout
= new QVBoxLayout(this);
84 m_topLayout
->setSpacing(0);
85 m_topLayout
->setMargin(0);
87 connect(m_mainWindow
, SIGNAL(activeViewChanged()),
88 this, SLOT(updateActivationState()));
90 m_urlNavigator
= new UrlNavigator(url
, this);
91 m_urlNavigator
->setShowHiddenFiles(showHiddenFiles
);
92 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
93 this, SLOT(loadDirectory(const KUrl
&)));
94 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
95 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
96 connect(m_urlNavigator
, SIGNAL(activated()),
97 this, SLOT(requestActivation()));
98 connect(this, SIGNAL(contentsMoved(int, int)),
99 m_urlNavigator
, SLOT(storeContentsPosition(int, int)));
101 m_statusBar
= new DolphinStatusBar(this);
103 m_dirLister
= new DolphinDirLister();
104 m_dirLister
->setAutoUpdate(true);
105 m_dirLister
->setMainWindow(this);
106 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
107 m_dirLister
->setDelayedMimeTypes(true);
109 connect(m_dirLister
, SIGNAL(clear()),
110 this, SLOT(updateStatusBar()));
111 connect(m_dirLister
, SIGNAL(percent(int)),
112 this, SLOT(updateProgress(int)));
113 connect(m_dirLister
, SIGNAL(deleteItem(KFileItem
*)),
114 this, SLOT(updateStatusBar()));
115 connect(m_dirLister
, SIGNAL(completed()),
116 this, SLOT(updateItemCount()));
117 connect(m_dirLister
, SIGNAL(completed()),
118 this, SLOT(updateCutItems()));
119 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
120 this, SLOT(generatePreviews(const KFileItemList
&)));
121 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
122 this, SLOT(showInfoMessage(const QString
&)));
123 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
124 this, SLOT(showErrorMessage(const QString
&)));
126 m_dirModel
= new KDirModel();
127 m_dirModel
->setDirLister(m_dirLister
);
128 m_dirModel
->setDropsAllowed(KDirModel::DropOnDirectory
);
130 m_proxyModel
= new DolphinSortFilterProxyModel(this);
131 m_proxyModel
->setSourceModel(m_dirModel
);
133 m_controller
= new DolphinController(this);
134 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
135 this, SLOT(openContextMenu(const QPoint
&)));
136 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
137 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
138 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
139 this, SLOT(updateSorting(DolphinView::Sorting
)));
140 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
141 this, SLOT(updateSortOrder(Qt::SortOrder
)));
142 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
143 this, SLOT(triggerItem(const QModelIndex
&)));
144 connect(m_controller
, SIGNAL(selectionChanged()),
145 this, SLOT(emitSelectionChangedSignal()));
146 connect(m_controller
, SIGNAL(activated()),
147 this, SLOT(requestActivation()));
151 m_iconSize
= K3Icon::SizeMedium
;
153 m_filterBar
= new FilterBar(this);
155 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
156 this, SLOT(changeNameFilter(const QString
&)));
157 connect(m_filterBar
, SIGNAL(closeRequest()),
158 this, SLOT(closeFilterBar()));
160 m_topLayout
->addWidget(m_urlNavigator
);
161 m_topLayout
->addWidget(itemView());
162 m_topLayout
->addWidget(m_filterBar
);
163 m_topLayout
->addWidget(m_statusBar
);
165 loadDirectory(m_urlNavigator
->url());
168 DolphinView::~DolphinView()
174 void DolphinView::setUrl(const KUrl
& url
)
176 m_urlNavigator
->setUrl(url
);
177 m_controller
->setUrl(url
);
180 const KUrl
& DolphinView::url() const
182 return m_urlNavigator
->url();
185 bool DolphinView::isActive() const
187 return m_mainWindow
->activeView() == this;
190 void DolphinView::setMode(Mode mode
)
192 if (mode
== m_mode
) {
193 return; // the wished mode is already set
198 ViewProperties
props(m_urlNavigator
->url());
199 props
.setViewMode(m_mode
);
202 startDirLister(m_urlNavigator
->url());
207 DolphinView::Mode
DolphinView::mode() const
212 void DolphinView::setShowPreview(bool show
)
214 ViewProperties
props(m_urlNavigator
->url());
215 props
.setShowPreview(show
);
217 m_controller
->setShowPreview(show
);
219 emit
showPreviewChanged();
223 bool DolphinView::showPreview() const
225 return m_controller
->showPreview();
228 void DolphinView::setShowHiddenFiles(bool show
)
230 if (m_dirLister
->showingDotFiles() == show
) {
234 ViewProperties
props(m_urlNavigator
->url());
235 props
.setShowHiddenFiles(show
);
238 m_dirLister
->setShowingDotFiles(show
);
239 m_urlNavigator
->setShowHiddenFiles(show
);
241 emit
showHiddenFilesChanged();
246 bool DolphinView::showHiddenFiles() const
248 return m_dirLister
->showingDotFiles();
251 void DolphinView::renameSelectedItems()
253 const KUrl::List urls
= selectedUrls();
254 if (urls
.count() > 1) {
255 // More than one item has been selected for renaming. Open
256 // a rename dialog and rename all items afterwards.
257 RenameDialog
dialog(urls
);
258 if (dialog
.exec() == QDialog::Rejected
) {
262 DolphinView
* view
= mainWindow()->activeView();
263 const QString
& newName
= dialog
.newName();
264 if (newName
.isEmpty()) {
265 view
->statusBar()->setMessage(i18n("The new item name is invalid."),
266 DolphinStatusBar::Error
);
269 // TODO: check how this can be integrated into KonqUndoManager/KonqOperations
271 //UndoManager& undoMan = UndoManager::instance();
272 //undoMan.beginMacro();
274 assert(newName
.contains('#'));
276 const int urlsCount
= urls
.count();
278 // iterate through all selected items and rename them...
279 const int replaceIndex
= newName
.indexOf('#');
280 assert(replaceIndex
>= 0);
281 for (int i
= 0; i
< urlsCount
; ++i
) {
282 const KUrl
& source
= urls
[i
];
284 number
.setNum(i
+ 1);
286 QString
name(newName
);
287 name
.replace(replaceIndex
, 1, number
);
289 if (source
.fileName() != name
) {
290 KUrl
dest(source
.upUrl());
293 const bool destExists
= KIO::NetAccess::exists(dest
, false, view
);
295 view
->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name
),
296 DolphinStatusBar::Error
);
299 else if (KIO::NetAccess::file_move(source
, dest
)) {
300 // TODO: From the users point of view he executed one 'rename n files' operation,
301 // but internally we store it as n 'rename 1 file' operations for the undo mechanism.
302 //DolphinCommand command(DolphinCommand::Rename, source, dest);
303 //undoMan.addCommand(command);
308 //undoMan.endMacro();
312 // Only one item has been selected for renaming. Use the custom
313 // renaming mechanism from the views.
314 assert(urls
.count() == 1);
316 /*if (m_mode == DetailsView) {
317 Q3ListViewItem* item = m_iconsView->firstChild();
319 if (item->isSelected()) {
320 m_iconsView->rename(item, DolphinDetailsView::NameColumn);
323 item = item->nextSibling();
327 KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
329 if (item->isSelected()) {
333 item = static_cast<KFileIconViewItem*>(item->nextItem());
339 void DolphinView::selectAll()
341 selectAll(QItemSelectionModel::Select
);
344 void DolphinView::invertSelection()
346 selectAll(QItemSelectionModel::Toggle
);
349 DolphinStatusBar
* DolphinView::statusBar() const
354 int DolphinView::contentsX() const
357 return itemView()->horizontalScrollBar()->value();
360 int DolphinView::contentsY() const
362 return itemView()->verticalScrollBar()->value();
365 void DolphinView::refreshSettings()
367 startDirLister(m_urlNavigator
->url());
370 void DolphinView::emitRequestItemInfo(const KUrl
& url
)
372 emit
requestItemInfo(url
);
375 bool DolphinView::isFilterBarVisible() const
377 return m_filterBar
->isVisible();
380 bool DolphinView::isUrlEditable() const
382 return m_urlNavigator
->isUrlEditable();
385 void DolphinView::zoomIn()
387 m_controller
->triggerZoomIn();
390 void DolphinView::zoomOut()
392 m_controller
->triggerZoomOut();
395 bool DolphinView::isZoomInPossible() const
397 return m_controller
->isZoomInPossible();
400 bool DolphinView::isZoomOutPossible() const
402 return m_controller
->isZoomOutPossible();
405 void DolphinView::setSorting(Sorting sorting
)
407 if (sorting
!= this->sorting()) {
408 updateSorting(sorting
);
412 DolphinView::Sorting
DolphinView::sorting() const
414 return m_proxyModel
->sorting();
417 void DolphinView::setSortOrder(Qt::SortOrder order
)
419 if (sortOrder() != order
) {
420 updateSortOrder(order
);
424 Qt::SortOrder
DolphinView::sortOrder() const
426 return m_proxyModel
->sortOrder();
429 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
431 ViewProperties
props(m_urlNavigator
->url());
432 props
.setAdditionalInfo(info
);
434 m_fileItemDelegate
->setAdditionalInformation(info
);
436 emit
additionalInfoChanged(info
);
440 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
442 return m_fileItemDelegate
->additionalInformation();
445 void DolphinView::goBack()
447 m_urlNavigator
->goBack();
450 void DolphinView::goForward()
452 m_urlNavigator
->goForward();
455 void DolphinView::goUp()
457 m_urlNavigator
->goUp();
460 void DolphinView::goHome()
462 m_urlNavigator
->goHome();
465 void DolphinView::setUrlEditable(bool editable
)
467 m_urlNavigator
->editUrl(editable
);
470 const QLinkedList
<UrlNavigator::HistoryElem
> DolphinView::urlHistory(int& index
) const
472 return m_urlNavigator
->history(index
);
475 bool DolphinView::hasSelection() const
477 return itemView()->selectionModel()->hasSelection();
480 KFileItemList
DolphinView::selectedItems() const
482 const QAbstractItemView
* view
= itemView();
484 // Our view has a selection, we will map them back to the DirModel
485 // and then fill the KFileItemList.
486 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
488 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
489 KFileItemList itemList
;
491 const QModelIndexList indexList
= selection
.indexes();
492 QModelIndexList::const_iterator end
= indexList
.end();
493 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
494 Q_ASSERT((*it
).isValid());
496 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
498 itemList
.append(item
);
505 KUrl::List
DolphinView::selectedUrls() const
509 const KFileItemList list
= selectedItems();
510 KFileItemList::const_iterator it
= list
.begin();
511 const KFileItemList::const_iterator end
= list
.end();
513 KFileItem
* item
= *it
;
514 urls
.append(item
->url());
521 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
523 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
524 return m_dirModel
->itemForIndex(dirModelIndex
);
527 void DolphinView::rename(const KUrl
& source
, const QString
& newName
)
531 if (newName
.isEmpty() || (source
.fileName() == newName
)) {
535 KUrl
dest(source
.upUrl());
536 dest
.addPath(newName
);
538 const bool destExists
= KIO::NetAccess::exists(dest
,
540 mainWindow()->activeView());
542 // the destination already exists, hence ask the user
544 KIO::RenameDialog
renameDialog(this,
545 i18n("File Already Exists"),
549 switch (renameDialog
.exec()) {
550 case KIO::R_OVERWRITE
:
551 // the destination should be overwritten
552 ok
= KIO::NetAccess::file_move(source
, dest
, -1, true);
555 case KIO::R_RENAME
: {
556 // a new name for the destination has been used
557 KUrl
newDest(renameDialog
.newDestUrl());
558 ok
= KIO::NetAccess::file_move(source
, newDest
);
563 // the renaming operation has been canceled
569 // no destination exists, hence just move the file to
571 ok
= KIO::NetAccess::file_move(source
, dest
);
574 const QString destFileName
= dest
.fileName();
576 m_statusBar
->setMessage(i18n("Renamed file '%1' to '%2'.",source
.fileName(), destFileName
),
577 DolphinStatusBar::OperationCompleted
);
579 KonqOperations::rename(this, source
, destFileName
);
582 m_statusBar
->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source
.fileName(), destFileName
),
583 DolphinStatusBar::Error
);
588 void DolphinView::reload()
590 startDirLister(m_urlNavigator
->url(), true);
593 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
595 QWidget::mouseReleaseEvent(event
);
596 mainWindow()->setActiveView(this);
599 DolphinMainWindow
* DolphinView::mainWindow() const
604 void DolphinView::loadDirectory(const KUrl
& url
)
606 const ViewProperties
props(url
);
608 const Mode mode
= props
.viewMode();
609 if (m_mode
!= mode
) {
615 const bool showHiddenFiles
= props
.showHiddenFiles();
616 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
617 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
618 emit
showHiddenFilesChanged();
621 const DolphinView::Sorting sorting
= props
.sorting();
622 if (sorting
!= m_proxyModel
->sorting()) {
623 m_proxyModel
->setSorting(sorting
);
624 emit
sortingChanged(sorting
);
627 const Qt::SortOrder sortOrder
= props
.sortOrder();
628 if (sortOrder
!= m_proxyModel
->sortOrder()) {
629 m_proxyModel
->setSortOrder(sortOrder
);
630 emit
sortOrderChanged(sortOrder
);
633 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
634 if (info
!= m_fileItemDelegate
->additionalInformation()) {
635 m_fileItemDelegate
->setAdditionalInformation(info
);
637 emit
additionalInfoChanged(info
);
640 const bool showPreview
= props
.showPreview();
641 if (showPreview
!= m_controller
->showPreview()) {
642 m_controller
->setShowPreview(showPreview
);
643 emit
showPreviewChanged();
647 emit
urlChanged(url
);
649 m_statusBar
->clear();
652 void DolphinView::triggerItem(const QModelIndex
& index
)
654 if (!isValidNameIndex(index
)) {
658 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
659 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
660 // items are selected by the user, hence don't trigger the
661 // item specified by 'index'
665 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
670 // Prefer the local path over the URL. This assures that the
671 // volume space information is correct. Assuming that the URL is media:/sda1,
672 // and the local path is /windows/C: For the URL the space info is related
673 // to the root partition (and hence wrong) and for the local path the space
674 // info is related to the windows partition (-> correct).
675 const QString
localPath(item
->localPath());
677 if (localPath
.isEmpty()) {
687 else if (item
->isFile()) {
688 // allow to browse through ZIP and tar files
689 KMimeType::Ptr mime
= item
->mimeTypePtr();
690 if (mime
->is("application/x-zip")) {
691 url
.setProtocol("zip");
694 else if (mime
->is("application/x-tar") ||
695 mime
->is("application/x-tarz") ||
696 mime
->is("application/x-tbz") ||
697 mime
->is("application/x-tgz") ||
698 mime
->is("application/x-tzo")) {
699 url
.setProtocol("tar");
711 void DolphinView::updateProgress(int percent
)
713 if (m_showProgress
) {
714 m_statusBar
->setProgress(percent
);
718 void DolphinView::updateItemCount()
720 if (m_showProgress
) {
721 m_statusBar
->setProgressText(QString());
722 m_statusBar
->setProgress(100);
723 m_showProgress
= false;
726 KFileItemList
items(m_dirLister
->items());
727 KFileItemList::const_iterator it
= items
.begin();
728 const KFileItemList::const_iterator end
= items
.end();
734 KFileItem
* item
= *it
;
746 QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
749 void DolphinView::generatePreviews(const KFileItemList
& items
)
751 if (m_controller
->showPreview()) {
752 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
753 connect(job
, SIGNAL(gotPreview(const KFileItem
*, const QPixmap
&)),
754 this, SLOT(showPreview(const KFileItem
*, const QPixmap
&)));
757 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
758 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
759 QTimer::singleShot(1000, this, SLOT(applyCutEffect()));
763 void DolphinView::showPreview(const KFileItem
* item
, const QPixmap
& pixmap
)
766 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
767 if (idx
.isValid() && (idx
.column() == 0)) {
768 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
769 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(*item
)) {
770 KIconEffect iconEffect
;
771 QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
772 m_dirModel
->setData(idx
, cutPixmap
, Qt::DecorationRole
);
775 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
780 void DolphinView::restoreContentsPos()
783 const QLinkedList
<UrlNavigator::HistoryElem
> history
= urlHistory(index
);
784 if (!history
.isEmpty()) {
785 QAbstractItemView
* view
= itemView();
786 // TODO: view->setCurrentItem(history[index].currentFileName());
788 QLinkedList
<UrlNavigator::HistoryElem
>::const_iterator it
= history
.begin();
790 view
->horizontalScrollBar()->setValue((*it
).contentsX());
791 view
->verticalScrollBar()->setValue((*it
).contentsY());
795 void DolphinView::showInfoMessage(const QString
& msg
)
797 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
800 void DolphinView::showErrorMessage(const QString
& msg
)
802 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
805 void DolphinView::emitSelectionChangedSignal()
807 emit
selectionChanged();
810 void DolphinView::closeFilterBar()
813 emit
showFilterBarChanged(false);
816 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
818 if (!url
.isValid()) {
819 const QString
location(url
.pathOrUrl());
820 if (location
.isEmpty()) {
821 m_statusBar
->setMessage(i18n("The location is empty."), DolphinStatusBar::Error
);
824 m_statusBar
->setMessage(i18n("The location '%1' is invalid.",location
),
825 DolphinStatusBar::Error
);
830 // Only show the directory loading progress if the status bar does
831 // not contain another progress information. This means that
832 // the directory loading progress information has the lowest priority.
833 const QString
progressText(m_statusBar
->progressText());
834 m_showProgress
= progressText
.isEmpty() ||
835 (progressText
== i18n("Loading directory..."));
836 if (m_showProgress
) {
837 m_statusBar
->setProgressText(i18n("Loading directory..."));
838 m_statusBar
->setProgress(0);
842 m_dirLister
->openUrl(url
, false, reload
);
845 QString
DolphinView::defaultStatusBarText() const
847 return KIO::itemsSummaryString(m_fileCount
+ m_folderCount
,
853 QString
DolphinView::selectionStatusBarText() const
856 const KFileItemList list
= selectedItems();
857 if (list
.isEmpty()) {
858 // when an item is triggered, it is temporary selected but selectedItems()
859 // will return an empty list
865 KIO::filesize_t byteSize
= 0;
866 KFileItemList::const_iterator it
= list
.begin();
867 const KFileItemList::const_iterator end
= list
.end();
869 KFileItem
* item
= *it
;
875 byteSize
+= item
->size();
880 if (folderCount
> 0) {
881 text
= i18np("1 Folder selected", "%1 Folders selected", folderCount
);
888 const QString
sizeText(KIO::convertSize(byteSize
));
889 text
+= i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
895 void DolphinView::showFilterBar(bool show
)
897 assert(m_filterBar
!= 0);
906 void DolphinView::updateStatusBar()
908 // As the item count information is less important
909 // in comparison with other messages, it should only
911 // - the status bar is empty or
912 // - shows already the item count information or
913 // - shows only a not very important information
914 // - if any progress is given don't show the item count info at all
915 const QString
msg(m_statusBar
->message());
916 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
917 (msg
== m_statusBar
->defaultText()) ||
918 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
919 (m_statusBar
->progress() == 100);
921 const QString
text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
922 m_statusBar
->setDefaultText(text
);
924 if (updateStatusBarMsg
) {
925 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
929 void DolphinView::requestActivation()
931 m_mainWindow
->setActiveView(this);
934 void DolphinView::updateCutItems()
936 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
937 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
941 KFileItemList
items(m_dirLister
->items());
942 KFileItemList::const_iterator it
= items
.begin();
943 const KFileItemList::const_iterator end
= items
.end();
945 KFileItem
* item
= *it
;
946 if (isCutItem(*item
)) {
947 QPixmap pixmap
= item
->pixmap(0);
948 KIconEffect iconEffect
;
949 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
950 const QModelIndex idx
= m_dirModel
->indexForItem(*item
);
952 m_dirModel
->setData(idx
, pixmap
, Qt::DecorationRole
);
959 void DolphinView::changeNameFilter(const QString
& nameFilter
)
961 // The name filter of KDirLister does a 'hard' filtering, which
962 // means that only the items are shown where the names match
963 // exactly the filter. This is non-transparent for the user, which
964 // just wants to have a 'soft' filtering: does the name contain
965 // the filter string?
966 QString
adjustedFilter(nameFilter
);
967 adjustedFilter
.insert(0, '*');
968 adjustedFilter
.append('*');
970 // Use the ProxyModel to filter:
971 // This code is #ifdefed as setNameFilter behaves
972 // slightly different than the QSortFilterProxyModel
973 // as it will not remove directories. I will ask
974 // our beloved usability experts for input
977 m_dirLister
->setNameFilter(adjustedFilter
);
978 m_dirLister
->emitChanges();
980 m_proxyModel
->setFilterRegExp( nameFilter
);
984 void DolphinView::openContextMenu(const QPoint
& pos
)
988 const QModelIndex index
= itemView()->indexAt(pos
);
989 if (isValidNameIndex(index
)) {
990 item
= fileItem(index
);
993 DolphinContextMenu
contextMenu(this, item
);
997 void DolphinView::dropUrls(const KUrl::List
& urls
,
998 const QModelIndex
& index
,
1001 KFileItem
* directory
= 0;
1002 if (isValidNameIndex(index
)) {
1003 KFileItem
* item
= fileItem(index
);
1005 if (item
->isDir()) {
1006 // the URLs are dropped above a directory
1011 if ((directory
== 0) && (source
== itemView())) {
1012 // The dropping is done into the same viewport where
1013 // the dragging has been started. Just ignore this...
1017 const KUrl
& destination
= (directory
== 0) ? url() :
1020 kDebug() << "DolphinView::dropUrls() - destination: " << destination
.prettyUrl() << endl
;
1022 dropUrls(urls
, destination
);
1025 void DolphinView::dropUrls(const KUrl::List
& urls
,
1026 const KUrl
& destination
)
1028 m_mainWindow
->dropUrls(urls
, destination
);
1032 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
1034 ViewProperties
props(url());
1035 props
.setSorting(sorting
);
1037 m_proxyModel
->setSorting(sorting
);
1039 emit
sortingChanged(sorting
);
1042 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1044 ViewProperties
props(url());
1045 props
.setSortOrder(order
);
1047 m_proxyModel
->setSortOrder(order
);
1049 emit
sortOrderChanged(order
);
1052 void DolphinView::emitContentsMoved()
1054 emit
contentsMoved(contentsX(), contentsY());
1057 void DolphinView::updateActivationState()
1059 m_urlNavigator
->setActive(isActive());
1062 void DolphinView::createView()
1064 // delete current view
1065 QAbstractItemView
* view
= itemView();
1067 m_topLayout
->removeWidget(view
);
1069 view
->deleteLater();
1072 m_fileItemDelegate
= 0;
1075 assert(m_iconsView
== 0);
1076 assert(m_detailsView
== 0);
1078 // ... and recreate it representing the current mode
1081 m_iconsView
= new DolphinIconsView(this, m_controller
);
1086 m_detailsView
= new DolphinDetailsView(this, m_controller
);
1087 view
= m_detailsView
;
1092 m_fileItemDelegate
= new KFileItemDelegate(view
);
1093 view
->setItemDelegate(m_fileItemDelegate
);
1095 view
->setModel(m_proxyModel
);
1096 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
1098 new KMimeTypeResolver(view
, m_dirModel
);
1099 m_topLayout
->insertWidget(1, view
);
1101 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1102 m_controller
, SLOT(indicateSelectionChange()));
1103 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1104 this, SLOT(emitContentsMoved()));
1105 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1106 this, SLOT(emitContentsMoved()));
1109 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
1111 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
1112 const QAbstractItemModel
* itemModel
= selectionModel
->model();
1114 const QModelIndex topLeft
= itemModel
->index(0, 0);
1115 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
1116 itemModel
->columnCount() - 1);
1118 QItemSelection
selection(topLeft
, bottomRight
);
1119 selectionModel
->select(selection
, flags
);
1122 QAbstractItemView
* DolphinView::itemView() const
1124 Q_ASSERT((m_iconsView
== 0) || (m_detailsView
== 0));
1125 if (m_detailsView
!= 0) {
1126 return m_detailsView
;
1131 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
1133 return index
.isValid() && (index
.column() == KDirModel::Name
);
1136 bool DolphinView::isCutItem(const KFileItem
& item
) const
1138 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
1139 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
1141 const KUrl
& itemUrl
= item
.url();
1142 KUrl::List::const_iterator it
= cutUrls
.begin();
1143 const KUrl::List::const_iterator end
= cutUrls
.end();
1145 if (*it
== itemUrl
) {
1154 #include "dolphinview.moc"