polish
[kdegraphics.git] / gwenview / lib / thumbnailloadjob.h
blob0cdb6b2fe6017cf91b26ef8d7ed60e24ae5ff926
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.
5 */
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>
29 // Qt
30 #include <QImage>
31 #include <QPixmap>
32 #include <QMutex>
33 #include <QThread>
34 #include <QWaitCondition>
36 // KDE
37 #include <kio/job.h>
38 #include <kfileitem.h>
40 // Local
41 #include <lib/thumbnailgroup.h>
43 namespace Gwenview {
44 class ThumbnailThread : public QThread {
45 Q_OBJECT
46 public:
47 ThumbnailThread();
49 void load(
50 const QString& originalUri,
51 time_t originalTime,
52 int originalSize,
53 const QString& originalMimeType,
54 const QString& pixPath,
55 const QString& thumbnailPath,
56 ThumbnailGroup::Enum group);
58 void cancel();
60 protected:
61 virtual void run();
63 Q_SIGNALS:
64 void done( const QImage&, const QSize&);
66 private:
67 bool testCancel();
68 void loadThumbnail();
69 void storeThumbnailInCache();
70 QImage mImage;
71 QString mPixPath;
72 QString mThumbnailPath;
73 QString mOriginalUri;
74 time_t mOriginalTime;
75 int mOriginalSize;
76 QString mOriginalMimeType;
77 int mOriginalWidth;
78 int mOriginalHeight;
79 QMutex mMutex;
80 QWaitCondition mCond;
81 ThumbnailGroup::Enum mThumbnailGroup;
82 bool mCancel;
85 /**
86 * A job that determines the thumbnails for the images in the current directory
88 class GWENVIEWLIB_EXPORT ThumbnailLoadJob : public KIO::Job {
89 Q_OBJECT
90 public:
91 /**
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();
97 /**
98 * Call this to get started
100 void start();
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);
143 Q_SIGNALS:
145 * Emitted when the thumbnail for the @p item has been loaded
147 void thumbnailLoaded(const KFileItem& item, const QPixmap&, const QSize&);
149 protected:
150 virtual void slotResult( KJob *job );
152 private Q_SLOTS:
153 void slotGotPreview(const KFileItem&, const QPixmap&);
154 void checkThumbnail();
155 void thumbnailReady(const QImage& im, const QSize&);
156 void emitThumbnailLoadingFailed();
158 private:
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())
165 KUrl mCurrentUrl;
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
177 QString mTempPath;
179 // Thumbnail group
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);
192 } // namespace
193 #endif