TODO for 4.1: provide a preview helper class which can be shared between DolphinView and the special use case of DolphinColumnViewWidget
BUG: 153816
svn path=/trunk/KDE/kdebase/apps/; revision=747348
#include <kfileitem.h>
#include <kio/previewjob.h>
#include <kiconeffect.h>
#include <kfileitem.h>
#include <kio/previewjob.h>
#include <kiconeffect.h>
#include <kmimetyperesolver.h>
#include <konqmimedata.h>
#include <kmimetyperesolver.h>
#include <konqmimedata.h>
m_dirLister(0),
m_dolphinModel(0),
m_proxyModel(0),
m_dirLister(0),
m_dolphinModel(0),
m_proxyModel(0),
m_dragging(false),
m_dropRect()
{
m_dragging(false),
m_dropRect()
{
delete m_dolphinModel;
m_dolphinModel = 0;
m_dirLister = 0; // deleted by m_dolphinModel
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)
}
void DolphinColumnWidget::setDecorationSize(const QSize& size)
// for generatePreviews(), showPreview() and isCutItem()
if (m_view->m_controller->dolphinView()->showPreview()) {
// 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());
{
// 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;
// the preview job is still working on items of an older URL, hence
// the item is not part of the directory model anymore
return;
m_view->m_controller->emitItemEntered(item);
}
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);
void DolphinColumnWidget::activate()
{
setFocus(Qt::OtherFocusReason);
class DolphinModel;
class DolphinSortFilterProxyModel;
class KDirLister;
class DolphinModel;
class DolphinSortFilterProxyModel;
class KDirLister;
class KFileItem;
class KFileItemList;
class QPixmap;
class KFileItem;
class KFileItemList;
class QPixmap;
+namespace KIO
+{
+ class PreviewJob;
+}
/**
* Represents one column inside the DolphinColumnView and has been
/**
* Represents one column inside the DolphinColumnView and has been
* Replaces the icon of the item \a item by the preview pixmap
* \a pixmap.
*/
* 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);
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();
private:
/** Used by DolphinColumnWidget::setActive(). */
void activate();
DolphinModel* m_dolphinModel;
DolphinSortFilterProxyModel* m_proxyModel;
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
};
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
};
#include <kio/deletejob.h>
#include <kio/netaccess.h>
#include <kio/previewjob.h>
#include <kio/deletejob.h>
#include <kio/netaccess.h>
#include <kio/previewjob.h>
#include <kmimetyperesolver.h>
#include <konqmimedata.h>
#include <konq_operations.h>
#include <kmimetyperesolver.h>
#include <konqmimedata.h>
#include <konq_operations.h>
m_selectionModel(0),
m_dolphinModel(dolphinModel),
m_dirLister(dirLister),
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);
{
setFocusPolicy(Qt::StrongFocus);
m_topLayout = new QVBoxLayout(this);
DolphinView::~DolphinView()
{
DolphinView::~DolphinView()
{
+ if (m_previewJob != 0) {
+ m_previewJob->kill();
+ m_previewJob = 0;
+ }
}
const KUrl& DolphinView::url() const
}
const KUrl& DolphinView::url() const
void DolphinView::generatePreviews(const KFileItemList& items)
{
if (m_controller->dolphinView()->showPreview()) {
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());
{
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;
}
// the item is not part of the directory model anymore
return;
}
+void DolphinView::slotPreviewJobFinished(KJob* job)
+{
+ Q_ASSERT(job == m_previewJob);
+ m_previewJob = 0;
+}
+
void DolphinView::cutSelectedItems()
{
QMimeData* mimeData = new QMimeData();
void DolphinView::cutSelectedItems()
{
QMimeData* mimeData = new QMimeData();
class DolphinSortFilterProxyModel;
class QModelIndex;
class ViewProperties;
class DolphinSortFilterProxyModel;
class QModelIndex;
class ViewProperties;
+namespace KIO
+{
+ class PreviewJob;
+}
/**
* @short Represents a view for the directory content.
/**
* @short Represents a view for the directory content.
* Replaces the icon of the item \a item by the preview pixmap
* \a pixmap.
*/
* 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();
void emitSelectionChangedSignal();
*/
void slotDeleteFileFinished(KJob* job);
*/
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);
private:
void loadDirectory(const KUrl& url, bool reload = false);
KDirLister* m_dirLister;
DolphinSortFilterProxyModel* m_proxyModel;
KDirLister* m_dirLister;
DolphinSortFilterProxyModel* m_proxyModel;
+ KIO::PreviewJob* m_previewJob;
+
QList<CutItem> m_cutItemsCache;
KUrl m_rootUrl;
QList<CutItem> m_cutItemsCache;
KUrl m_rootUrl;