X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/4d886d083ca6cb2d635da2d29efb804b2680b6de..75480d07cd820c75ca418b990d3059f154bbdf6e:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 42136f445..1300d9937 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -47,18 +47,18 @@ #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 "draganddrophelper.h" #include "folderexpander.h" -#include "kfilepreviewgenerator.h" #include "renamedialog.h" #include "tooltipmanager.h" #include "viewproperties.h" @@ -106,8 +106,8 @@ DolphinView::DolphinView(QWidget* parent, 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)), @@ -126,7 +126,7 @@ DolphinView::DolphinView(QWidget* parent, this, SLOT(clearHoverInformation())); connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)), - this, SLOT(slotRedirection(KUrl, KUrl))); + this, SIGNAL(redirection(KUrl, KUrl))); connect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreCurrentItem())); @@ -193,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(); @@ -219,6 +220,7 @@ void DolphinView::setMode(Mode mode) } emit modeChanged(); + updateZoomLevel(oldZoomLevel); } DolphinView::Mode DolphinView::mode() const @@ -437,6 +439,7 @@ void DolphinView::reload() void DolphinView::refresh() { const bool oldActivationState = m_active; + const int oldZoomLevel = m_controller->zoomLevel(); m_active = true; createView(); @@ -444,6 +447,7 @@ void DolphinView::refresh() reload(); setActive(oldActivationState); + updateZoomLevel(oldZoomLevel); } void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl) @@ -481,9 +485,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 { @@ -492,6 +496,58 @@ 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()) @@ -558,7 +614,6 @@ void DolphinView::renameSelectedItems() KUrl newUrl = oldUrl; newUrl.setFileName(name); KonqOperations::rename(this, oldUrl, newUrl); - emit doingOperation(KIO::FileUndoManager::Rename); } } } @@ -588,14 +643,12 @@ void DolphinView::renameSelectedItems() KUrl newUrl = oldUrl; newUrl.setFileName(newName); KonqOperations::rename(this, oldUrl, newUrl); - emit doingOperation(KIO::FileUndoManager::Rename); } } } void DolphinView::trashSelectedItems() { - emit doingOperation(KIO::FileUndoManager::Trash); const KUrl::List list = simplifiedSelectedUrls(); KonqOperations::del(this, KonqOperations::TRASH, list); } @@ -657,7 +710,7 @@ void DolphinView::setShowPreview(bool show) props.setShowPreview(show); m_showPreview = show; - m_previewGenerator->setShowPreview(show); + m_previewGenerator->setPreviewShown(show); const int oldZoomLevel = m_controller->zoomLevel(); emit showPreviewChanged(); @@ -816,21 +869,11 @@ void DolphinView::openContextMenu(const QPoint& pos) m_isContextMenuOpen = false; } -void DolphinView::dropUrls(const KUrl::List& urls, +void DolphinView::dropUrls(const KFileItem& destItem, const KUrl& destPath, - const KFileItem& destItem) + QDropEvent* event) { - Q_ASSERT(!urls.isEmpty()); - const KUrl destination = !destItem.isNull() && destItem.isDir() ? - destItem.url() : destPath; - const KUrl sourceDir = KUrl(urls.first().directory()); - if (sourceDir != destination) { - DolphinDropController dropController(this); - // forward doingOperation signal up to the mainwindow - connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)), - this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType))); - dropController.dropUrls(urls, destination); - } + DragAndDropHelper::dropUrls(destItem, destPath, event, this); } void DolphinView::updateSorting(DolphinView::Sorting sorting) @@ -981,18 +1024,11 @@ 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::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl) -{ - if (oldUrl == m_controller->url()) { - m_controller->setUrl(newUrl); - } -} - void DolphinView::slotRequestUrlChange(const KUrl& url) { emit requestUrlChange(url); @@ -1063,9 +1099,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(); @@ -1107,7 +1147,7 @@ void DolphinView::applyViewProperties(const KUrl& url) const bool showPreview = props.showPreview(); if (showPreview != m_showPreview) { m_showPreview = showPreview; - m_previewGenerator->setShowPreview(showPreview); + m_previewGenerator->setPreviewShown(showPreview); const int oldZoomLevel = m_controller->zoomLevel(); emit showPreviewChanged(); @@ -1164,7 +1204,9 @@ void DolphinView::createView() 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); @@ -1180,11 +1222,13 @@ void DolphinView::createView() view->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_previewGenerator = new KFilePreviewGenerator(view, m_proxyModel); - m_previewGenerator->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); @@ -1257,16 +1301,14 @@ 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(KIO::FileUndoManager::Move); clipboard->clear(); } else { KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url); - emit doingOperation(KIO::FileUndoManager::Copy); } } void DolphinView::updateZoomLevel(int oldZoomLevel) -{ +{ const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize()); if (oldZoomLevel != newZoomLevel) { m_controller->setZoomLevel(newZoomLevel); @@ -1277,10 +1319,15 @@ void DolphinView::updateZoomLevel(int oldZoomLevel) KUrl::List DolphinView::simplifiedSelectedUrls() const { KUrl::List list = selectedUrls(); - if ((m_detailsView != 0) && m_detailsView->itemsExpandable()) { + if (itemsExpandable() ) { list = KonqOperations::simplifiedUrlList(list); } return list; } +bool DolphinView::itemsExpandable() const +{ + return (m_detailsView != 0) && m_detailsView->itemsExpandable(); +} + #include "dolphinview.moc"