X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/525fdd8afc1468dc72e6a150cf75dee4c330bdcd..e4170c1910ad91fd31bc64edfab17ddc814411d5:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 0b8fe5883..297ab9934 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -39,11 +38,14 @@ #include #include #include +#include +#include #include #include #include #include +#include "dolphindropcontroller.h" #include "dolphinmodel.h" #include "dolphincolumnview.h" #include "dolphincontroller.h" @@ -75,7 +77,8 @@ DolphinView::DolphinView(QWidget* parent, m_selectionModel(0), m_dolphinModel(dolphinModel), m_dirLister(dirLister), - m_proxyModel(proxyModel) + m_proxyModel(proxyModel), + m_previewJob(0) { setFocusPolicy(Qt::StrongFocus); m_topLayout = new QVBoxLayout(this); @@ -128,6 +131,10 @@ DolphinView::DolphinView(QWidget* parent, DolphinView::~DolphinView() { + if (m_previewJob != 0) { + m_previewJob->kill(); + m_previewJob = 0; + } } const KUrl& DolphinView::url() const @@ -147,6 +154,7 @@ void DolphinView::setActive(bool active) } m_active = active; + m_selectionModel->clearSelection(); QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); if (active) { @@ -312,7 +320,13 @@ bool DolphinView::supportsCategorizedSorting() const void DolphinView::selectAll() { - itemView()->selectAll(); + QAbstractItemView* view = itemView(); + // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if + // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the + // selection instead of selecting all items. This is bypassed for KDE 4.0 + // by invoking clearSelection() first. + view->clearSelection(); + view->selectAll(); } void DolphinView::invertSelection() @@ -567,17 +581,25 @@ void DolphinView::triggerItem(const KFileItem& item) void DolphinView::generatePreviews(const KFileItemList& items) { if (m_controller->dolphinView()->showPreview()) { - KIO::PreviewJob* job = KIO::filePreview(items, 128); - connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(showPreview(const KFileItem&, const QPixmap&))); + if (m_previewJob != 0) { + m_previewJob->kill(); + m_previewJob = 0; + } + + m_previewJob = KIO::filePreview(items, 128); + connect(m_previewJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), + this, SLOT(replaceIcon(const KFileItem&, const QPixmap&))); + connect(m_previewJob, SIGNAL(finished(KJob*)), + this, SLOT(slotPreviewJobFinished(KJob*))); } } -void DolphinView::showPreview(const KFileItem& item, const QPixmap& pixmap) +void DolphinView::replaceIcon(const KFileItem& item, const QPixmap& pixmap) { Q_ASSERT(!item.isNull()); - if (item.url().directory() != m_dirLister->url().path()) { - // the preview job is still working on items of an older URL, hence + if (!m_showPreview || (item.url().directory() != m_dirLister->url().path())) { + // the preview has been deactivated in the meanwhile or the preview + // job is still working on items of an older URL, hence // the item is not part of the directory model anymore return; } @@ -736,6 +758,7 @@ void DolphinView::dropUrls(const KUrl::List& urls, 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()); @@ -747,7 +770,11 @@ void DolphinView::dropUrls(const KUrl::List& urls, void DolphinView::dropUrls(const KUrl::List& urls, const KUrl& destination) { - emit urlsDropped(urls, destination); + 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); } void DolphinView::updateSorting(DolphinView::Sorting sorting) @@ -816,7 +843,7 @@ void DolphinView::updateCutItems() void DolphinView::showHoverInformation(const KFileItem& item) { - if (hasSelection()) { + if (hasSelection() || !m_active) { return; } @@ -825,7 +852,9 @@ void DolphinView::showHoverInformation(const KFileItem& item) void DolphinView::clearHoverInformation() { - emit requestItemInfo(KFileItem()); + if (m_active) { + emit requestItemInfo(KFileItem()); + } } @@ -867,7 +896,9 @@ void DolphinView::createView() m_selectionModel = view->selectionModel(); } - m_selectionModel->setParent(this); //Reparent the selection model. We do not want it to be deleted when we delete the model + // reparent the selection model, as it should not be deleted + // when deleting the model + m_selectionModel->setParent(this); view->setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -1104,6 +1135,12 @@ void DolphinView::slotDeleteFileFinished(KJob* job) } } +void DolphinView::slotPreviewJobFinished(KJob* job) +{ + Q_ASSERT(job == m_previewJob); + m_previewJob = 0; +} + void DolphinView::cutSelectedItems() { QMimeData* mimeData = new QMimeData(); @@ -1172,8 +1209,8 @@ QPair DolphinView::pasteInfo() const } if (ret.first) { - const KUrl::List urls = selectedUrls(); - const uint count = urls.count(); + const KFileItemList items = selectedItems(); + const uint count = items.count(); if (count > 1) { // pasting should not be allowed when more than one file // is selected @@ -1181,13 +1218,7 @@ QPair DolphinView::pasteInfo() const } else if (count == 1) { // Only one file is selected. Pasting is only allowed if this // file is a directory. - // TODO: this doesn't work with remote protocols; instead we need a - // m_activeViewContainer->selectedFileItems() to get the real KFileItems - const KFileItem fileItem(S_IFDIR, - KFileItem::Unknown, - urls.first(), - true); - ret.first = fileItem.isDir(); + ret.first = items.first().isDir(); } } return ret;