X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f32987d719f4b396ea2679b59a712a8bc288b8d2..e7bd514a39f0b07ddfec85f5f7b391e16af7d279:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 28e50a0a2..cd9b67bb7 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,24 +41,28 @@ #include #include #include +#include #include #include #include #include -#include "dolphindropcontroller.h" #include "dolphinmodel.h" #include "dolphincolumnview.h" #include "dolphincontroller.h" +#include "dolphinfileitemdelegate.h" #include "dolphinsortfilterproxymodel.h" #include "dolphindetailsview.h" +#include "dolphin_detailsmodesettings.h" #include "dolphiniconsview.h" #include "dolphinsettings.h" #include "dolphin_generalsettings.h" -#include "iconmanager.h" +#include "draganddrophelper.h" +#include "folderexpander.h" #include "renamedialog.h" #include "tooltipmanager.h" #include "viewproperties.h" +#include "zoomlevelinfo.h" DolphinView::DolphinView(QWidget* parent, const KUrl& url, @@ -70,6 +74,7 @@ DolphinView::DolphinView(QWidget* parent, m_showPreview(false), m_loadingDirectory(false), m_storedCategorizedSorting(false), + m_tabsForFiles(false), m_isContextMenuOpen(false), m_mode(DolphinView::IconsView), m_topLayout(0), @@ -82,10 +87,11 @@ DolphinView::DolphinView(QWidget* parent, m_dolphinModel(dolphinModel), m_dirLister(dirLister), m_proxyModel(proxyModel), - m_iconManager(0), - m_toolTipManager(0) + m_previewGenerator(0), + m_toolTipManager(0), + m_rootUrl(), + m_currentItemUrl() { - setFocusPolicy(Qt::StrongFocus); m_topLayout = new QVBoxLayout(this); m_topLayout->setSpacing(0); m_topLayout->setMargin(0); @@ -93,19 +99,15 @@ DolphinView::DolphinView(QWidget* parent, m_controller = new DolphinController(this); m_controller->setUrl(url); - // Receiver of the DolphinView signal 'urlChanged()' don't need - // to care whether the internal controller changed the URL already or whether - // the controller just requested an URL change and will be updated later. - // In both cases the URL has been changed: connect(m_controller, SIGNAL(urlChanged(const KUrl&)), this, SIGNAL(urlChanged(const KUrl&))); connect(m_controller, SIGNAL(requestUrlChange(const KUrl&)), - this, SIGNAL(urlChanged(const KUrl&))); + this, SLOT(slotRequestUrlChange(const KUrl&))); connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)), this, SLOT(openContextMenu(const QPoint&))); - connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&, const KFileItem&)), - this, SLOT(dropUrls(const KUrl::List&, const KUrl&, const KFileItem&))); + connect(m_controller, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)), + this, SLOT(dropUrls(const KFileItem&, const KUrl&, QDropEvent*))); connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)), this, SLOT(updateSorting(DolphinView::Sorting))); connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)), @@ -123,6 +125,11 @@ DolphinView::DolphinView(QWidget* parent, connect(m_controller, SIGNAL(viewportEntered()), this, SLOT(clearHoverInformation())); + connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)), + this, SIGNAL(redirection(KUrl, KUrl))); + connect(m_dirLister, SIGNAL(completed()), + this, SLOT(restoreCurrentItem())); + applyViewProperties(url); m_topLayout->addWidget(itemView()); } @@ -148,7 +155,6 @@ void DolphinView::setActive(bool active) } m_active = active; - m_selectionModel->clearSelection(); QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); if (active) { @@ -169,6 +175,7 @@ void DolphinView::setActive(bool active) update(); if (active) { + itemView()->setFocus(); emit activated(); } @@ -186,6 +193,7 @@ void DolphinView::setMode(Mode mode) return; // the wished mode is already set } + const int oldZoomLevel = m_controller->zoomLevel(); m_mode = mode; deleteView(); @@ -212,6 +220,7 @@ void DolphinView::setMode(Mode mode) } emit modeChanged(); + updateZoomLevel(oldZoomLevel); } DolphinView::Mode DolphinView::mode() const @@ -291,6 +300,10 @@ void DolphinView::clearSelection() KFileItemList DolphinView::selectedItems() const { + if (isColumnViewActive()) { + return m_columnView->selectedItems(); + } + const QAbstractItemView* view = itemView(); // Our view has a selection, we will map them back to the DolphinModel @@ -321,10 +334,15 @@ KUrl::List DolphinView::selectedUrls() const return urls; } -KFileItem DolphinView::fileItem(const QModelIndex& index) const +int DolphinView::selectedItemsCount() const { - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - return m_dolphinModel->itemForIndex(dolphinModelIndex); + if (isColumnViewActive()) { + // TODO: get rid of this special case by adjusting the dir lister + // to the current column + return m_columnView->selectedItems().count(); + } + + return itemView()->selectionModel()->selection().count(); } void DolphinView::setContentsPosition(int x, int y) @@ -347,26 +365,24 @@ QPoint DolphinView::contentsPosition() const return QPoint(x, y); } -void DolphinView::zoomIn() +void DolphinView::setZoomLevel(int level) { - m_controller->triggerZoomIn(); - m_iconManager->updatePreviews(); -} - -void DolphinView::zoomOut() -{ - m_controller->triggerZoomOut(); - m_iconManager->updatePreviews(); -} - -bool DolphinView::isZoomInPossible() const -{ - return m_controller->isZoomInPossible(); + if (level < ZoomLevelInfo::minimumLevel()) { + level = ZoomLevelInfo::minimumLevel(); + } else if (level > ZoomLevelInfo::maximumLevel()) { + level = ZoomLevelInfo::maximumLevel(); + } + + if (level != zoomLevel()) { + m_controller->setZoomLevel(level); + m_previewGenerator->updatePreviews(); + emit zoomLevelChanged(level); + } } -bool DolphinView::isZoomOutPossible() const +int DolphinView::zoomLevel() const { - return m_controller->isZoomOutPossible(); + return m_controller->zoomLevel(); } void DolphinView::setSorting(Sorting sorting) @@ -438,6 +454,7 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl) return; } + m_previewGenerator->cancelPreviews(); m_controller->setUrl(url); // emits urlChanged, which we forward if (!rootUrl.isEmpty() && rootUrl.isParentOf(url)) { @@ -466,9 +483,9 @@ void DolphinView::setNameFilter(const QString& nameFilter) } } -void DolphinView::calculateItemCount(int& fileCount, int& folderCount) +void DolphinView::calculateItemCount(int& fileCount, int& folderCount) const { - foreach (const KFileItem &item, m_dirLister->items()) { + foreach (const KFileItem& item, m_dirLister->items()) { if (item.isDir()) { ++folderCount; } else { @@ -477,8 +494,62 @@ void DolphinView::calculateItemCount(int& fileCount, int& folderCount) } } +QString DolphinView::statusBarText() const +{ + if (hasSelection()) { + // give a summary of the status of the selected files + QString text; + const KFileItemList list = selectedItems(); + if (list.isEmpty()) { + // when an item is triggered, it is temporary selected but selectedItems() + // will return an empty list + return QString(); + } + + int fileCount = 0; + int folderCount = 0; + KIO::filesize_t byteSize = 0; + KFileItemList::const_iterator it = list.begin(); + const KFileItemList::const_iterator end = list.end(); + while (it != end) { + const KFileItem& item = *it; + if (item.isDir()) { + ++folderCount; + } else { + ++fileCount; + byteSize += item.size(); + } + ++it; + } + + if (folderCount > 0) { + text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount); + if (fileCount > 0) { + text += ", "; + } + } + + if (fileCount > 0) { + const QString sizeText(KIO::convertSize(byteSize)); + text += i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText); + } + return text; + } else { + // Give a summary of the status of the current folder. + int folderCount = 0; + int fileCount = 0; + calculateItemCount(fileCount, folderCount); + return KIO::itemsSummaryString(fileCount + folderCount, + fileCount, + folderCount, + 0, false); + } +} + void DolphinView::setUrl(const KUrl& url) { + // remember current item candidate (see restoreCurrentItem()) + m_currentItemUrl = url; updateView(url, KUrl()); } @@ -506,7 +577,12 @@ void DolphinView::changeSelection(const KFileItemList& selection) void DolphinView::renameSelectedItems() { const KFileItemList items = selectedItems(); - if (items.count() > 1) { + const int itemCount = items.count(); + if (itemCount < 1) { + return; + } + + if (itemCount > 1) { // More than one item has been selected for renaming. Open // a rename dialog and rename all items afterwards. RenameDialog dialog(this, items); @@ -518,7 +594,7 @@ void DolphinView::renameSelectedItems() if (newName.isEmpty()) { emit errorMessage(dialog.errorString()); } else { - // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations + // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations // as one operation instead of n rename operations like it is done now... Q_ASSERT(newName.contains('#')); @@ -536,13 +612,12 @@ void DolphinView::renameSelectedItems() KUrl newUrl = oldUrl; newUrl.setFileName(name); KonqOperations::rename(this, oldUrl, newUrl); - emit doingOperation(KonqFileUndoManager::RENAME); } } } } else if (DolphinSettings::instance().generalSettings()->renameInline()) { - Q_ASSERT(items.count() == 1); - + Q_ASSERT(itemCount == 1); + if (isColumnViewActive()) { m_columnView->editItem(items.first()); } else { @@ -551,8 +626,8 @@ void DolphinView::renameSelectedItems() itemView()->edit(proxyIndex); } } else { - Q_ASSERT(items.count() == 1); - + Q_ASSERT(itemCount == 1); + RenameDialog dialog(this, items); if (dialog.exec() == QDialog::Rejected) { return; @@ -566,20 +641,19 @@ void DolphinView::renameSelectedItems() KUrl newUrl = oldUrl; newUrl.setFileName(newName); KonqOperations::rename(this, oldUrl, newUrl); - emit doingOperation(KonqFileUndoManager::RENAME); } } } void DolphinView::trashSelectedItems() { - emit doingOperation(KonqFileUndoManager::TRASH); - KonqOperations::del(this, KonqOperations::TRASH, selectedUrls()); + const KUrl::List list = simplifiedSelectedUrls(); + KonqOperations::del(this, KonqOperations::TRASH, list); } void DolphinView::deleteSelectedItems() { - const KUrl::List list = selectedUrls(); + const KUrl::List list = simplifiedSelectedUrls(); const bool del = KonqOperations::askDeleteConfirmation(list, KonqOperations::DEL, KonqOperations::DEFAULT_CONFIRMATION, @@ -595,7 +669,7 @@ void DolphinView::deleteSelectedItems() void DolphinView::cutSelectedItems() { QMimeData* mimeData = new QMimeData(); - const KUrl::List kdeUrls = selectedUrls(); + const KUrl::List kdeUrls = simplifiedSelectedUrls(); const KUrl::List mostLocalUrls; KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true); QApplication::clipboard()->setMimeData(mimeData); @@ -634,8 +708,15 @@ void DolphinView::setShowPreview(bool show) props.setShowPreview(show); m_showPreview = show; - m_iconManager->setShowPreview(show); + m_previewGenerator->setPreviewShown(show); + + const int oldZoomLevel = m_controller->zoomLevel(); emit showPreviewChanged(); + + // Enabling or disabling the preview might change the icon size of the view. + // As the view does not emit a signal when the icon size has been changed, + // the used zoom level of the controller must be adjusted manually: + updateZoomLevel(oldZoomLevel); loadDirectory(viewPropsUrl); } @@ -705,7 +786,6 @@ void DolphinView::toggleAdditionalInfo(QAction* action) } } - void DolphinView::mouseReleaseEvent(QMouseEvent* event) { QWidget::mouseReleaseEvent(event); @@ -716,10 +796,11 @@ void DolphinView::wheelEvent(QWheelEvent* event) { if (event->modifiers() & Qt::ControlModifier) { const int delta = event->delta(); - if ((delta > 0) && isZoomInPossible()) { - zoomIn(); - } else if ((delta < 0) && isZoomOutPossible()) { - zoomOut(); + const int level = zoomLevel(); + if (delta > 0) { + setZoomLevel(level + 1); + } else if (delta < 0) { + setZoomLevel(level - 1); } event->accept(); } @@ -748,7 +829,7 @@ void DolphinView::triggerItem(const KFileItem& item) return; } - // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue xxxxxx + // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192 if (item.isNull() || m_isContextMenuOpen) { return; } @@ -767,42 +848,30 @@ void DolphinView::emitSelectionChangedSignal() void DolphinView::openContextMenu(const QPoint& pos) { KFileItem item; - - const QModelIndex index = itemView()->indexAt(pos); - if (index.isValid() && (index.column() == DolphinModel::Name)) { - item = fileItem(index); + if (isColumnViewActive()) { + item = m_columnView->itemAt(pos); + } else { + const QModelIndex index = itemView()->indexAt(pos); + if (index.isValid() && (index.column() == DolphinModel::Name)) { + const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); + item = m_dolphinModel->itemForIndex(dolphinModelIndex); + } } if (m_toolTipManager != 0) { m_toolTipManager->hideTip(); } - m_isContextMenuOpen = true; // TODO: workaround for Qt-issue xxxxxx + m_isContextMenuOpen = true; // TODO: workaround for Qt-issue 207192 emit requestContextMenu(item, url()); m_isContextMenuOpen = false; } -void DolphinView::dropUrls(const KUrl::List& urls, +void DolphinView::dropUrls(const KFileItem& destItem, const KUrl& destPath, - const KFileItem& destItem) -{ - Q_ASSERT(!urls.isEmpty()); - const KUrl& destination = !destItem.isNull() && destItem.isDir() ? - destItem.url() : destPath; - const KUrl sourceDir = KUrl(urls.first().directory()); - if (sourceDir != destination) { - dropUrls(urls, destination); - } -} - -void DolphinView::dropUrls(const KUrl::List& urls, - const KUrl& destination) + QDropEvent* event) { - DolphinDropController dropController(this); - // forward doingOperation signal up to the mainwindow - connect(&dropController, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)), - this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType))); - dropController.dropUrls(urls, destination); + DragAndDropHelper::dropUrls(destItem, destPath, event, this); } void DolphinView::updateSorting(DolphinView::Sorting sorting) @@ -896,7 +965,10 @@ QPair DolphinView::pasteInfo() const KUrl::List urls = KUrl::List::fromMimeData(mimeData); if (!urls.isEmpty()) { - ret.first = true; + // disable the paste action if no writing is supported + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url()); + ret.first = KonqFileItemCapabilities(KFileItemList() << item).supportsWriting(); + if (urls.count() == 1) { const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, urls.first(), true); ret.second = item.isDir() ? i18nc("@action:inmenu", "Paste One Folder") : @@ -913,6 +985,16 @@ QPair DolphinView::pasteInfo() const return ret; } +void DolphinView::setTabsForFilesEnabled(bool tabsForFiles) +{ + m_tabsForFiles = tabsForFiles; +} + +bool DolphinView::isTabsForFilesEnabled() const +{ + return m_tabsForFiles; +} + void DolphinView::emitContentsMoved() { // only emit the contents moved signal if: @@ -940,11 +1022,31 @@ void DolphinView::slotDeleteFileFinished(KJob* job) { if (job->error() == 0) { emit operationCompletedMessage(i18nc("@info:status", "Delete operation completed.")); - } else { + } else if (job->error() != KIO::ERR_USER_CANCELED) { emit errorMessage(job->errorString()); } } +void DolphinView::slotRequestUrlChange(const KUrl& url) +{ + emit requestUrlChange(url); + m_controller->setUrl(url); +} + +void DolphinView::restoreCurrentItem() +{ + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl); + if (dirIndex.isValid()) { + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + QAbstractItemView* view = itemView(); + const bool clearSelection = !hasSelection(); + view->setCurrentIndex(proxyIndex); + if (clearSelection) { + view->clearSelection(); + } + } +} + void DolphinView::loadDirectory(const KUrl& url, bool reload) { if (!url.isValid()) { @@ -995,9 +1097,13 @@ void DolphinView::applyViewProperties(const KUrl& url) const Mode mode = props.viewMode(); if (m_mode != mode) { + const int oldZoomLevel = m_controller->zoomLevel(); + m_mode = mode; createView(); emit modeChanged(); + + updateZoomLevel(oldZoomLevel); } if (itemView() == 0) { createView(); @@ -1039,8 +1145,15 @@ void DolphinView::applyViewProperties(const KUrl& url) const bool showPreview = props.showPreview(); if (showPreview != m_showPreview) { m_showPreview = showPreview; - m_iconManager->setShowPreview(showPreview); + m_previewGenerator->setPreviewShown(showPreview); + + const int oldZoomLevel = m_controller->zoomLevel(); emit showPreviewChanged(); + + // Enabling or disabling the preview might change the icon size of the view. + // As the view does not emit a signal when the icon size has been changed, + // the used zoom level of the controller must be adjusted manually: + updateZoomLevel(oldZoomLevel); } } @@ -1073,9 +1186,25 @@ void DolphinView::createView() Q_ASSERT(view != 0); view->installEventFilter(this); + if (m_mode != ColumnView) { + // Give the view the ability to auto-expand its directories on hovering + // (the column view takes care about this itself). If the details view + // uses expandable folders, the auto-expanding should be used always. + DolphinSettings& settings = DolphinSettings::instance(); + const bool enabled = settings.generalSettings()->autoExpandFolders() || + ((m_detailsView != 0) && settings.detailsModeSettings()->expandableFolders()); + + FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel); + folderExpander->setEnabled(enabled); + connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)), + m_controller, SLOT(triggerItem(const QModelIndex&))); + } + m_controller->setItemView(view); - m_fileItemDelegate = new KFileItemDelegate(view); + m_fileItemDelegate = new DolphinFileItemDelegate(view); + m_fileItemDelegate->setShowToolTipWhenElided(false); + m_fileItemDelegate->setMinimizedNameColumn(m_mode == DetailsView); view->setItemDelegate(m_fileItemDelegate); view->setModel(m_proxyModel); @@ -1091,12 +1220,13 @@ void DolphinView::createView() view->setSelectionMode(QAbstractItemView::ExtendedSelection); - new KMimeTypeResolver(view, m_dolphinModel); - m_iconManager = new IconManager(view, m_proxyModel); - m_iconManager->setShowPreview(m_showPreview); + m_previewGenerator = new KFilePreviewGenerator(view); + m_previewGenerator->setPreviewShown(m_showPreview); if (DolphinSettings::instance().generalSettings()->showToolTips()) { m_toolTipManager = new ToolTipManager(view, m_proxyModel); + connect(m_controller, SIGNAL(hideToolTip()), + m_toolTipManager, SLOT(hideTip())); } m_topLayout->insertWidget(1, view); @@ -1113,6 +1243,12 @@ void DolphinView::deleteView() { QAbstractItemView* view = itemView(); if (view != 0) { + // It's important to set the keyboard focus to the parent + // before deleting the view: Otherwise when having a split + // view the other view will get the focus and will request + // an activation (see DolphinView::eventFilter()). + setFocus(); + m_topLayout->removeWidget(view); view->close(); view->deleteLater(); @@ -1121,7 +1257,7 @@ void DolphinView::deleteView() m_detailsView = 0; m_columnView = 0; m_fileItemDelegate = 0; - m_iconManager = 0; + m_previewGenerator = 0; m_toolTipManager = 0; } } @@ -1163,12 +1299,33 @@ void DolphinView::pasteToUrl(const KUrl& url) const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData); if (KonqMimeData::decodeIsCutSelection(mimeData)) { KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url); - emit doingOperation(KonqFileUndoManager::MOVE); clipboard->clear(); } else { KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url); - emit doingOperation(KonqFileUndoManager::COPY); } } +void DolphinView::updateZoomLevel(int oldZoomLevel) +{ + const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize()); + if (oldZoomLevel != newZoomLevel) { + m_controller->setZoomLevel(newZoomLevel); + emit zoomLevelChanged(newZoomLevel); + } +} + +KUrl::List DolphinView::simplifiedSelectedUrls() const +{ + KUrl::List list = selectedUrls(); + if (itemsExpandable() ) { + list = KonqOperations::simplifiedUrlList(list); + } + return list; +} + +bool DolphinView::itemsExpandable() const +{ + return (m_detailsView != 0) && m_detailsView->itemsExpandable(); +} + #include "dolphinview.moc"