diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index ad18f03bb8..8872dea384 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_dirLister(0), m_dolphinModel(0), m_proxyModel(0), + m_previewJob(0), m_dragging(false), m_dropRect() { @@ -132,6 +134,11 @@ DolphinColumnWidget::~DolphinColumnWidget() delete m_dolphinModel; m_dolphinModel = 0; m_dirLister = 0; // deleted by m_dolphinModel + + if (m_previewJob != 0) { + m_previewJob->kill(); + m_previewJob = 0; + } } void DolphinColumnWidget::setDecorationSize(const QSize& size) @@ -356,19 +363,27 @@ void DolphinColumnWidget::generatePreviews(const KFileItemList& items) // for generatePreviews(), showPreview() and isCutItem() if (m_view->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 DolphinColumnWidget::showPreview(const KFileItem& item, const QPixmap& pixmap) +void DolphinColumnWidget::replaceIcon(const KFileItem& item, const QPixmap& pixmap) { // TODO: same implementation as in DolphinView; create helper class // for generatePreviews(), showPreview() and isCutItem() Q_ASSERT(!item.isNull()); - if (item.url().directory() != m_dirLister->url().path()) { + const bool showPreview = m_view->m_controller->dolphinView()->showPreview(); + if (!showPreview || (item.url().directory() != m_dirLister->url().path())) { // the preview job is still working on items of an older URL, hence // the item is not part of the directory model anymore return; @@ -394,6 +409,12 @@ void DolphinColumnWidget::slotEntered(const QModelIndex& index) m_view->m_controller->emitItemEntered(item); } +void DolphinColumnWidget::slotPreviewJobFinished(KJob* job) +{ + Q_ASSERT(job == m_previewJob); + m_previewJob = 0; +} + void DolphinColumnWidget::activate() { setFocus(Qt::OtherFocusReason); diff --git a/src/dolphincolumnwidget.h b/src/dolphincolumnwidget.h index 5cb7e1168d..8702462694 100644 --- a/src/dolphincolumnwidget.h +++ b/src/dolphincolumnwidget.h @@ -31,9 +31,14 @@ class DolphinColumnView; class DolphinModel; class DolphinSortFilterProxyModel; class KDirLister; +class KJob; class KFileItem; class KFileItemList; class QPixmap; +namespace KIO +{ + class PreviewJob; +} /** * Represents one column inside the DolphinColumnView and has been @@ -124,10 +129,16 @@ private slots: * Replaces the icon of the item \a item by the preview pixmap * \a pixmap. */ - void showPreview(const KFileItem& item, const QPixmap& pixmap); + void replaceIcon(const KFileItem& item, const QPixmap& pixmap); void slotEntered(const QModelIndex& index); + /** + * Is invoked when the preview job has been finished and + * set m_previewJob to 0. + */ + void slotPreviewJobFinished(KJob* job); + private: /** Used by DolphinColumnWidget::setActive(). */ void activate(); @@ -157,6 +168,8 @@ private: DolphinModel* m_dolphinModel; DolphinSortFilterProxyModel* m_proxyModel; + KIO::PreviewJob* m_previewJob; + bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4 }; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index d4609d3828..dcabe8329e 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -75,7 +76,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 +130,10 @@ DolphinView::DolphinView(QWidget* parent, DolphinView::~DolphinView() { + if (m_previewJob != 0) { + m_previewJob->kill(); + m_previewJob = 0; + } } const KUrl& DolphinView::url() const @@ -568,17 +574,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; } @@ -1109,6 +1123,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(); diff --git a/src/dolphinview.h b/src/dolphinview.h index 508862e9c5..3cd7860f1d 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -52,6 +52,10 @@ class DolphinMainWindow; class DolphinSortFilterProxyModel; class QModelIndex; class ViewProperties; +namespace KIO +{ + class PreviewJob; +} /** * @short Represents a view for the directory content. @@ -541,7 +545,7 @@ private slots: * Replaces the icon of the item \a item by the preview pixmap * \a pixmap. */ - void showPreview(const KFileItem& item, const QPixmap& pixmap); + void replaceIcon(const KFileItem& item, const QPixmap& pixmap); void emitSelectionChangedSignal(); @@ -614,6 +618,12 @@ private slots: */ void slotDeleteFileFinished(KJob* job); + /** + * Is invoked when the preview job has been finished and + * set m_previewJob to 0. + */ + void slotPreviewJobFinished(KJob* job); + private: void loadDirectory(const KUrl& url, bool reload = false); @@ -696,6 +706,8 @@ private: KDirLister* m_dirLister; DolphinSortFilterProxyModel* m_proxyModel; + KIO::PreviewJob* m_previewJob; + QList m_cutItemsCache; KUrl m_rootUrl;