X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/09e1cc4d7726b649710fe5ce49741ae736ce4d06..22b050a1d04e22097bc9d149e8e73b2d7fdfcdcc:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 00751bf77..2c2dbc231 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #include @@ -68,15 +67,6 @@ #include "zoomlevelinfo.h" #include "dolphindetailsviewexpander.h" -/** - * Helper function for sorting items with qSort() in - * DolphinView::renameSelectedItems(). - */ -bool lessThan(const KFileItem& item1, const KFileItem& item2) -{ - return KStringHandler::naturalCompare(item1.name(), item2.name()) < 0; -} - DolphinView::DolphinView(QWidget* parent, const KUrl& url, DolphinSortFilterProxyModel* proxyModel) : @@ -86,7 +76,6 @@ DolphinView::DolphinView(QWidget* parent, m_storedCategorizedSorting(false), m_tabsForFiles(false), m_isContextMenuOpen(false), - m_ignoreViewProperties(false), m_assureVisibleCurrentIndex(false), m_mode(DolphinView::IconsView), m_topLayout(0), @@ -290,18 +279,9 @@ bool DolphinView::supportsCategorizedSorting() const return m_viewAccessor.supportsCategorizedSorting(); } -bool DolphinView::hasSelection() const -{ - const QAbstractItemView* view = m_viewAccessor.itemView(); - return (view != 0) && view->selectionModel()->hasSelection(); -} - -void DolphinView::markUrlsAsSelected(const QList& urls) +KFileItemList DolphinView::items() const { - foreach (const KUrl& url, urls) { - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); - m_selectedItems.append(item); - } + return m_viewAccessor.dirLister()->items(); } KFileItemList DolphinView::selectedItems() const @@ -325,16 +305,6 @@ KFileItemList DolphinView::selectedItems() const return itemList; } -KUrl::List DolphinView::selectedUrls() const -{ - KUrl::List urls; - const KFileItemList list = selectedItems(); - foreach (const KFileItem &item, list) { - urls.append(item.url()); - } - return urls; -} - int DolphinView::selectedItemsCount() const { const QAbstractItemView* view = m_viewAccessor.itemView(); @@ -345,9 +315,21 @@ int DolphinView::selectedItemsCount() const return view->selectionModel()->selectedIndexes().count(); } -QItemSelectionModel* DolphinView::selectionModel() const +void DolphinView::markUrlsAsSelected(const QList& urls) +{ + foreach (const KUrl& url, urls) { + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); + m_selectedItems.append(item); + } +} + +void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled) { - return m_viewAccessor.itemView()->selectionModel(); + const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern); + const QItemSelectionModel::SelectionFlags command = enabled + ? QItemSelectionModel::Select + : QItemSelectionModel::Deselect; + m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command); } void DolphinView::setZoomLevel(int level) @@ -438,10 +420,13 @@ void DolphinView::reload() restoreState(restoreStream); } -void DolphinView::refresh() +void DolphinView::stopLoading() { - m_ignoreViewProperties = false; + m_viewAccessor.dirLister()->stop(); +} +void DolphinView::refresh() +{ const bool oldActivationState = m_active; const int oldZoomLevel = m_viewModeController->zoomLevel(); m_active = true; @@ -545,6 +530,7 @@ void DolphinView::setUrl(const KUrl& url) // The selection model might change in the case of the column view. Disconnect // from the current selection model and reconnect later after the URL switch. + const bool hadSelection = hasSelection(); QAbstractItemView* view = m_viewAccessor.itemView(); disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); @@ -566,6 +552,9 @@ void DolphinView::setUrl(const KUrl& url) view = m_viewAccessor.itemView(); connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); + if (hadSelection || hasSelection()) { + emitSelectionChangedSignal(); + } } void DolphinView::selectAll() @@ -599,82 +588,17 @@ void DolphinView::renameSelectedItems() return; } - if (itemCount > 1) { - // More than one item has been selected for renaming. Open - // a rename dialog and rename all items afterwards. - QPointer dialog = new RenameDialog(this, items); - if (dialog->exec() == QDialog::Rejected) { - delete dialog; - return; - } - - const QString newName = dialog->newName(); - if (newName.isEmpty()) { - emit errorMessage(dialog->errorString()); - delete dialog; - return; - } - delete dialog; - - // the selection would be invalid after renaming the items, so just clear - // it before - clearSelection(); - - // 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('#')); - - // currently the items are sorted by the selection order, resort - // them by the file name - qSort(items.begin(), items.end(), lessThan); - - // iterate through all selected items and rename them... - int index = 1; - foreach (const KFileItem& item, items) { - const KUrl& oldUrl = item.url(); - QString number; - number.setNum(index++); - - QString name = newName; - name.replace('#', number); - - if (oldUrl.fileName() != name) { - KUrl newUrl = oldUrl; - newUrl.setFileName(name); - KonqOperations::rename(this, oldUrl, newUrl); - } - } - } else if (DolphinSettings::instance().generalSettings()->renameInline()) { - Q_ASSERT(itemCount == 1); + if ((itemCount == 1) && DolphinSettings::instance().generalSettings()->renameInline()) { const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForItem(items.first()); const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex); m_viewAccessor.itemView()->edit(proxyIndex); } else { - Q_ASSERT(itemCount == 1); - - QPointer dialog = new RenameDialog(this, items); - if (dialog->exec() == QDialog::Rejected) { - delete dialog; - return; - } - - const QString newName = dialog->newName(); - if (newName.isEmpty()) { - emit errorMessage(dialog->errorString()); - delete dialog; - return; - } - delete dialog; - - const KUrl& oldUrl = items.first().url(); - KUrl newUrl = oldUrl; - newUrl.setFileName(newName); - KonqOperations::rename(this, oldUrl, newUrl); + RenameDialog* dialog = new RenameDialog(this, items); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + dialog->raise(); + dialog->activateWindow(); } - - // assure that the current index remains visible when KDirLister - // will notify the view about changed items - m_assureVisibleCurrentIndex = true; } void DolphinView::trashSelectedItems() @@ -778,40 +702,6 @@ void DolphinView::setCategorizedSorting(bool categorized) emit categorizedSortingChanged(); } -void DolphinView::toggleSortOrder() -{ - const Qt::SortOrder order = (sortOrder() == Qt::AscendingOrder) ? - Qt::DescendingOrder : - Qt::AscendingOrder; - setSortOrder(order); -} - -void DolphinView::toggleSortFoldersFirst() -{ - setSortFoldersFirst(!sortFoldersFirst()); -} - -void DolphinView::toggleAdditionalInfo(QAction* action) -{ - const KFileItemDelegate::Information info = - static_cast(action->data().toInt()); - - KFileItemDelegate::InformationList list = additionalInfo(); - - const bool show = action->isChecked(); - - const int index = list.indexOf(info); - const bool containsInfo = (index >= 0); - if (show && !containsInfo) { - list.append(info); - setAdditionalInfo(list); - } else if (!show && containsInfo) { - list.removeAt(index); - setAdditionalInfo(list); - Q_ASSERT(list.indexOf(info) < 0); - } -} - void DolphinView::mouseReleaseEvent(QMouseEvent* event) { QWidget::mouseReleaseEvent(event); @@ -905,7 +795,8 @@ void DolphinView::slotSelectionChanged(const QItemSelection& selected, const QIt void DolphinView::emitSelectionChangedSignal() { - emit selectionChanged(DolphinView::selectedItems()); + m_selectionChangedTimer->stop(); + emit selectionChanged(selectedItems()); } void DolphinView::openContextMenu(const QPoint& pos, @@ -1060,6 +951,12 @@ void DolphinView::saveState(QDataStream& stream) stream << m_viewAccessor.expandedUrls(); } +bool DolphinView::hasSelection() const +{ + const QAbstractItemView* view = m_viewAccessor.itemView(); + return (view != 0) && view->selectionModel()->hasSelection(); +} + void DolphinView::observeCreatedItem(const KUrl& url) { m_createdItemUrl = url; @@ -1164,6 +1061,8 @@ void DolphinView::slotLoadingCompleted() // Restore the contents position. This has to be done using a Qt::QueuedConnection // because the view might not be in its final state yet. QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection); + + emit finishedPathLoading(url()); } void DolphinView::slotRefreshItems() @@ -1192,10 +1091,6 @@ void DolphinView::loadDirectory(const KUrl& url, bool reload) void DolphinView::applyViewProperties() { - if (m_ignoreViewProperties) { - return; - } - const ViewProperties props(rootUrl()); const Mode mode = props.viewMode(); @@ -1262,29 +1157,17 @@ void DolphinView::applyViewProperties() // the used zoom level of the controller must be adjusted manually: updateZoomLevel(oldZoomLevel); } - - if (DolphinSettings::instance().generalSettings()->globalViewProps()) { - // During the lifetime of a DolphinView instance the global view properties - // should not be changed. This allows e. g. to split a view and use different - // view properties for each view. - m_ignoreViewProperties = true; - } } void DolphinView::createView() { - QAbstractItemView* view = m_viewAccessor.itemView(); - if ((view != 0) && (view->selectionModel() != 0)) { - disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), - this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); - } - deleteView(); Q_ASSERT(m_viewAccessor.itemView() == 0); + Q_ASSERT(m_dolphinViewController->itemView() == 0); m_viewAccessor.createView(this, m_dolphinViewController, m_viewModeController, m_mode); - view = m_viewAccessor.itemView(); + QAbstractItemView* view = m_viewAccessor.itemView(); Q_ASSERT(view != 0); view->installEventFilter(this); view->viewport()->installEventFilter(this); @@ -1304,7 +1187,15 @@ void DolphinView::createView() void DolphinView::deleteView() { QAbstractItemView* view = m_viewAccessor.itemView(); + Q_ASSERT((m_dolphinViewController->itemView() == 0) || (m_dolphinViewController->itemView() == view)); + m_dolphinViewController->setItemView(0); + if (view != 0) { + if (view->selectionModel() != 0) { + disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); + } + // 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 @@ -1312,13 +1203,7 @@ void DolphinView::deleteView() setFocusProxy(0); setFocus(); - m_topLayout->removeWidget(view); - view->close(); - - // disconnect all signal/slots - disconnect(view); m_viewModeController->disconnect(view); - view->disconnect(); m_viewAccessor.deleteView(); } @@ -1341,11 +1226,19 @@ void DolphinView::updateZoomLevel(int oldZoomLevel) KUrl::List DolphinView::simplifiedSelectedUrls() const { - KUrl::List list = selectedUrls(); - if (itemsExpandable() ) { - list = KDirModel::simplifiedUrlList(list); + KUrl::List urls; + + const KFileItemList items = selectedItems(); + foreach (const KFileItem &item, items) { + urls.append(item.url()); } - return list; + + + if (itemsExpandable()) { + urls = KDirModel::simplifiedUrlList(urls); + } + + return urls; } QMimeData* DolphinView::selectionMimeData() const @@ -1364,6 +1257,30 @@ void DolphinView::addNewFileNames(const QMimeData* mimeData) } } +QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const +{ + QItemSelection matchingIndexes; + const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel(); + const DolphinModel* dolphinModel = m_viewAccessor.dirModel(); + + const int rowCount = proxyModel->rowCount(parent); + + for (int row = 0; row < rowCount; ++row) { + QModelIndex index = proxyModel->index(row, 0, parent); + QModelIndex sourceIndex = proxyModel->mapToSource(index); + + if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) { + matchingIndexes += QItemSelectionRange(index); + } + + if (proxyModel->hasChildren(index)) { + matchingIndexes += childrenMatchingPattern(index, pattern); + } + } + + return matchingIndexes; +} + DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) : m_iconsView(0), m_detailsView(0), @@ -1414,32 +1331,38 @@ void DolphinView::ViewAccessor::createView(QWidget* parent, void DolphinView::ViewAccessor::deleteView() { - QAbstractItemView* view = itemView(); - if (view != 0) { - if (DragAndDropHelper::instance().isDragSource(view)) { - // The view is a drag source (the feature "Open folders - // during drag operations" is used). Deleting the view - // during an ongoing drag operation is not allowed, so - // this will postponed. - if (m_dragSource != 0) { - // the old stored view is obviously not the drag source anymore - m_dragSource->deleteLater(); - m_dragSource = 0; + if (m_columnsContainer != 0) { + m_columnsContainer->close(); + m_columnsContainer->disconnect(); + m_columnsContainer->deleteLater(); + m_columnsContainer = 0; + } else { + QAbstractItemView* view = itemView(); + if (view != 0) { + view->close(); + view->disconnect(); + + if (DragAndDropHelper::instance().isDragSource(view)) { + // The view is a drag source (the feature "Open folders + // during drag operations" is used). Deleting the view + // during an ongoing drag operation is not allowed, so + // this will postponed. + if (m_dragSource != 0) { + // the old stored view is obviously not the drag source anymore + m_dragSource->deleteLater(); + m_dragSource = 0; + } + view->hide(); + m_dragSource = view; + } else { + view->deleteLater(); + view = 0; } - view->hide(); - m_dragSource = view; - } else { - view->deleteLater(); } - } - m_iconsView = 0; - m_detailsView = 0; - - if (m_columnsContainer != 0) { - m_columnsContainer->deleteLater(); + m_iconsView = 0; + m_detailsView = 0; } - m_columnsContainer = 0; }