1 // vim: set tabstop=4 shiftwidth=4 noexpandtab
2 /* Gwenview - A simple image viewer for KDE
3 Copyright 2000-2004 Aurélien Gâteau <aurelien.gateau@free.fr>
4 This class is based on the ImagePreviewJob class from Konqueror.
6 /* This file is part of the KDE project
7 Copyright (C) 2000 David Faure <faure@kde.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifndef THUMBNAILLOADJOB_H
25 #define THUMBNAILLOADJOB_H
27 #include <lib/gwenviewlib_export.h>
34 #include <QWaitCondition>
38 #include <kfileitem.h>
41 #include <lib/thumbnailgroup.h>
44 class ThumbnailThread
: public QThread
{
50 const QString
& originalUri
,
53 const QString
& originalMimeType
,
54 const QString
& pixPath
,
55 const QString
& thumbnailPath
,
56 ThumbnailGroup::Enum group
);
64 void done( const QImage
&, const QSize
&);
69 void storeThumbnailInCache();
72 QString mThumbnailPath
;
76 QString mOriginalMimeType
;
81 ThumbnailGroup::Enum mThumbnailGroup
;
86 * A job that determines the thumbnails for the images in the current directory
88 class GWENVIEWLIB_EXPORT ThumbnailLoadJob
: public KIO::Job
{
92 * Create a job for determining the pixmaps of the images in the @p itemList
94 ThumbnailLoadJob(const KFileItemList
& itemList
, ThumbnailGroup::Enum
);
95 virtual ~ThumbnailLoadJob();
98 * Call this to get started
103 * To be called whenever items are removed from the view
105 void removeItems(const KFileItemList
& itemList
);
108 * Returns the list of items waiting for a thumbnail
110 const KFileItemList
& pendingItems() const;
113 * Add an item to a running job
115 void appendItem(const KFileItem
& item
);
118 * Defines size of thumbnails to generate
120 void setThumbnailGroup(ThumbnailGroup::Enum
);
123 * Returns the thumbnail base dir, independent of the thumbnail size
125 static QString
thumbnailBaseDir();
128 * Sets the thumbnail base dir, useful for unit-testing
130 static void setThumbnailBaseDir(const QString
&);
133 * Returns the thumbnail base dir, for the @p group
135 static QString
thumbnailBaseDir(ThumbnailGroup::Enum group
);
139 * Delete the thumbnail for the @p url
141 static void deleteImageThumbnail(const KUrl
& url
);
145 * Emitted when the thumbnail for the @p item has been loaded
147 void thumbnailLoaded(const KFileItem
& item
, const QPixmap
&, const QSize
&);
150 virtual void slotResult( KJob
*job
);
153 void slotGotPreview(const KFileItem
&, const QPixmap
&);
154 void checkThumbnail();
155 void thumbnailReady(const QImage
& im
, const QSize
&);
156 void emitThumbnailLoadingFailed();
159 enum { STATE_STATORIG
, STATE_DOWNLOADORIG
, STATE_PREVIEWJOB
, STATE_NEXTTHUMB
} mState
;
161 KFileItemList mItems
;
162 KFileItem mCurrentItem
;
164 // The Url of the current item (always equivalent to m_items.first()->item()->url())
167 // The Uri of the original image (might be different from mCurrentUrl.url())
168 QString mOriginalUri
;
170 // The modification time of the original image
171 time_t mOriginalTime
;
173 // The thumbnail path
174 QString mThumbnailPath
;
176 // The temporary path for remote urls
180 ThumbnailGroup::Enum mThumbnailGroup
;
182 QPixmap mBrokenPixmap
;
184 ThumbnailThread mThumbnailThread
;
186 void determineNextIcon();
187 void startCreatingThumbnail(const QString
& path
);
189 void emitThumbnailLoaded(const QImage
& img
, const QSize
& size
);