X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/040bdcea237e2576aad744bc4e7b5cadedcc98dc..9f7c2424d9c6df1a8461e24a8865552629fcda1a:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index aec798d31..fdf93a1da 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include #include #include @@ -55,15 +57,24 @@ #include "dolphindetailsview.h" #include "dolphin_detailsmodesettings.h" #include "dolphiniconsview.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphin_generalsettings.h" #include "draganddrophelper.h" #include "folderexpander.h" #include "renamedialog.h" -#include "tooltipmanager.h" +#include "tooltips/tooltipmanager.h" #include "viewproperties.h" #include "zoomlevelinfo.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, KDirLister* dirLister, @@ -76,6 +87,7 @@ DolphinView::DolphinView(QWidget* parent, m_storedCategorizedSorting(false), m_tabsForFiles(false), m_isContextMenuOpen(false), + m_ignoreViewProperties(false), m_mode(DolphinView::IconsView), m_topLayout(0), m_controller(0), @@ -91,7 +103,7 @@ DolphinView::DolphinView(QWidget* parent, m_toolTipManager(0), m_rootUrl(), m_currentItemUrl(), - m_expandedViews() + m_expandedDragSource(0) { m_topLayout = new QVBoxLayout(this); m_topLayout->setSpacing(0); @@ -137,7 +149,9 @@ DolphinView::DolphinView(QWidget* parent, DolphinView::~DolphinView() { - deleteExpandedViews(); + kDebug() << "Deleted view " << m_expandedDragSource; + delete m_expandedDragSource; + m_expandedDragSource = 0; } const KUrl& DolphinView::url() const @@ -222,7 +236,7 @@ void DolphinView::setMode(Mode mode) } emit modeChanged(); - + updateZoomLevel(oldZoomLevel); if (m_showPreview) { loadDirectory(viewPropsUrl); @@ -378,7 +392,7 @@ void DolphinView::setZoomLevel(int level) } else if (level > ZoomLevelInfo::maximumLevel()) { level = ZoomLevelInfo::maximumLevel(); } - + if (level != zoomLevel()) { m_controller->setZoomLevel(level); m_previewGenerator->updatePreviews(); @@ -444,6 +458,8 @@ void DolphinView::reload() void DolphinView::refresh() { + m_ignoreViewProperties = false; + const bool oldActivationState = m_active; const int oldZoomLevel = m_controller->zoomLevel(); m_active = true; @@ -511,7 +527,7 @@ QString DolphinView::statusBarText() const int folderCount = 0; int fileCount = 0; KIO::filesize_t totalFileSize = 0; - + if (hasSelection()) { // give a summary of the status of the selected files const KFileItemList list = selectedItems(); @@ -533,17 +549,26 @@ QString DolphinView::statusBarText() const } ++it; } - - const QString foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount); - const QString filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount); - if ((folderCount > 0) && (fileCount > 0)) { - text = i18nc("@info:status folders, files (size)", "%1, %2 (%3)", - foldersText, filesText, KIO::convertSize(totalFileSize)); - } else if (fileCount > 0) { - text = i18nc("@info:status files (size)", "%1 (%2)", filesText, KIO::convertSize(totalFileSize)); + + if (folderCount + fileCount == 1) { + // if only one item is selected, show the filename + const QString name = list.first().name(); + text = (folderCount == 1) ? i18nc("@info:status", "%1 selected", name) : + i18nc("@info:status", "%1 selected (%2)", + name, KIO::convertSize(totalFileSize)); } else { - Q_ASSERT(folderCount > 0); - text = foldersText; + // at least 2 items are selected + const QString foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount); + const QString filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount); + if ((folderCount > 0) && (fileCount > 0)) { + text = i18nc("@info:status folders, files (size)", "%1, %2 (%3)", + foldersText, filesText, KIO::convertSize(totalFileSize)); + } else if (fileCount > 0) { + text = i18nc("@info:status files (size)", "%1 (%2)", filesText, KIO::convertSize(totalFileSize)); + } else { + Q_ASSERT(folderCount > 0); + text = foldersText; + } } } else { calculateItemCount(fileCount, folderCount, totalFileSize); @@ -585,12 +610,12 @@ void DolphinView::changeSelection(const KFileItemList& selection) void DolphinView::renameSelectedItems() { - const KFileItemList items = selectedItems(); + KFileItemList items = selectedItems(); 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. @@ -607,9 +632,13 @@ void DolphinView::renameSelectedItems() // 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) { + foreach (const KFileItem& item, items) { const KUrl& oldUrl = item.url(); QString number; number.setNum(index++); @@ -626,7 +655,7 @@ void DolphinView::renameSelectedItems() } } else if (DolphinSettings::instance().generalSettings()->renameInline()) { Q_ASSERT(itemCount == 1); - + if (isColumnViewActive()) { m_columnView->editItem(items.first()); } else { @@ -636,7 +665,7 @@ void DolphinView::renameSelectedItems() } } else { Q_ASSERT(itemCount == 1); - + RenameDialog dialog(this, items); if (dialog.exec() == QDialog::Rejected) { return; @@ -677,19 +706,14 @@ void DolphinView::deleteSelectedItems() void DolphinView::cutSelectedItems() { - QMimeData* mimeData = new QMimeData(); - const KUrl::List kdeUrls = simplifiedSelectedUrls(); - const KUrl::List mostLocalUrls; - KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true); + QMimeData* mimeData = selectionMimeData(); + KonqMimeData::addIsCutSelection(mimeData, true); QApplication::clipboard()->setMimeData(mimeData); } void DolphinView::copySelectedItems() { - QMimeData* mimeData = new QMimeData(); - const KUrl::List kdeUrls = selectedUrls(); - const KUrl::List mostLocalUrls; - KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false); + QMimeData* mimeData = selectionMimeData(); QApplication::clipboard()->setMimeData(mimeData); } @@ -718,10 +742,10 @@ void DolphinView::setShowPreview(bool show) m_showPreview = 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: @@ -823,24 +847,33 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event) m_controller->requestActivation(); } break; - + case QEvent::MouseButtonPress: - if ((watched == itemView()->viewport()) && (m_expandedViews.count() > 0)) { + kDebug() << "m_expandedDragSource = " << m_expandedDragSource; + if ((watched == itemView()->viewport()) && (m_expandedDragSource != 0)) { // Listening to a mousebutton press event to delete expanded views is a // workaround, as it seems impossible for the FolderExpander to know when // a dragging outside a view has been finished. However it works quite well: // A mousebutton press event indicates that a drag operation must be // finished already. - deleteExpandedViews(); + kDebug() << "Deleted view " << m_expandedDragSource; + m_expandedDragSource->deleteLater(); + m_expandedDragSource = 0; } break; - + case QEvent::DragEnter: if (watched == itemView()->viewport()) { setActive(true); } break; - + + case QEvent::KeyPress: + if ((watched == itemView()) && (m_toolTipManager != 0)) { + m_toolTipManager->hideTip(); + } + break; + default: break; } @@ -1028,6 +1061,34 @@ bool DolphinView::isTabsForFilesEnabled() const return m_tabsForFiles; } +bool DolphinView::itemsExpandable() const +{ + return (m_detailsView != 0) && m_detailsView->itemsExpandable(); +} + +void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view) +{ + if (view == 0) + return; + + if (DragAndDropHelper::instance().isDragSource(view)) { + kDebug() << "Is current drag source"; + // We must store for later deletion. + if (m_expandedDragSource != 0) { + // The old stored view is obviously not the drag source anymore. + kDebug() << "Deleted old view " << m_expandedDragSource; + m_expandedDragSource->deleteLater(); + m_expandedDragSource = 0; + } + view->hide(); + m_expandedDragSource = view; + } + else { + kDebug() << "Deleted new view " << view; + view->deleteLater(); + } +} + void DolphinView::emitContentsMoved() { // only emit the contents moved signal if: @@ -1080,16 +1141,6 @@ void DolphinView::restoreCurrentItem() } } -void DolphinView::enterDir(const QModelIndex& index, QAbstractItemView* view) -{ - // Deleting a view that is the root of a drag operation is not allowed, otherwise - // the dragging gets automatically cancelled by Qt. So before entering a new - // directory, the current view is remembered in m_expandedViews and deleted - // later when the drag operation has been finished (see DolphinView::eventFilter()). - m_expandedViews.append(view); - m_controller->triggerItem(index); -} - void DolphinView::loadDirectory(const KUrl& url, bool reload) { if (!url.isValid()) { @@ -1129,6 +1180,10 @@ KUrl DolphinView::viewPropertiesUrl() const void DolphinView::applyViewProperties(const KUrl& url) { + if (m_ignoreViewProperties) { + return; + } + if (isColumnViewActive() && rootUrl().isParentOf(url)) { // The column view is active, hence don't apply the view properties // of sub directories (represented by columns) to the view. The @@ -1141,11 +1196,11 @@ 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) { @@ -1189,15 +1244,22 @@ void DolphinView::applyViewProperties(const KUrl& url) if (showPreview != m_showPreview) { m_showPreview = 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); } + + 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() @@ -1229,6 +1291,7 @@ void DolphinView::createView() Q_ASSERT(view != 0); view->installEventFilter(this); view->viewport()->installEventFilter(this); + setFocusProxy(view); if (m_mode != ColumnView) { // Give the view the ability to auto-expand its directories on hovering @@ -1240,8 +1303,13 @@ void DolphinView::createView() FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel); folderExpander->setEnabled(enabled); - connect(folderExpander, SIGNAL(enterDir(const QModelIndex&, QAbstractItemView*)), - this, SLOT(enterDir(const QModelIndex&, QAbstractItemView*))); + connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)), + m_controller, SLOT(triggerItem(const QModelIndex&))); + } + else { + // Listen out for requests to delete the current column. + connect(m_columnView, SIGNAL(requestColumnDeletion(QAbstractItemView*)), + this, SLOT(deleteWhenNotDragSource(QAbstractItemView*))); } m_controller->setItemView(view); @@ -1291,34 +1359,28 @@ void DolphinView::deleteView() // 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()). + setFocusProxy(0); setFocus(); m_topLayout->removeWidget(view); view->close(); - + + // m_previewGenerator's parent is not always destroyed, and we + // don't want two active at once - manually delete. + delete m_previewGenerator; + m_previewGenerator = 0; + disconnect(view); m_controller->disconnect(view); view->disconnect(); - - bool deleteView = true; - foreach (const QAbstractItemView* expandedView, m_expandedViews) { - if (view == expandedView) { - // the current view got already expanded and must stay alive - // until the dragging has been completed - deleteView = false; - break; - } - } - if (deleteView) { - view->deleteLater(); - } + + deleteWhenNotDragSource(view); view = 0; - + m_iconsView = 0; m_detailsView = 0; m_columnView = 0; m_fileItemDelegate = 0; - m_previewGenerator = 0; m_toolTipManager = 0; } } @@ -1379,25 +1441,21 @@ KUrl::List DolphinView::simplifiedSelectedUrls() const { KUrl::List list = selectedUrls(); if (itemsExpandable() ) { - list = KonqOperations::simplifiedUrlList(list); + list = KDirModel::simplifiedUrlList(list); } return list; } -void DolphinView::deleteExpandedViews() +QMimeData* DolphinView::selectionMimeData() const { - const QAbstractItemView* view = itemView(); - foreach (QAbstractItemView* expandedView, m_expandedViews) { - if (expandedView != view) { - expandedView->deleteLater(); - } + if (isColumnViewActive()) { + return m_columnView->selectionMimeData(); } - m_expandedViews.clear(); -} -bool DolphinView::itemsExpandable() const -{ - return (m_detailsView != 0) && m_detailsView->itemsExpandable(); + const QAbstractItemView* view = itemView(); + Q_ASSERT((view != 0) && (view->selectionModel() != 0)); + const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection()); + return m_dolphinModel->mimeData(selection.indexes()); } #include "dolphinview.moc"