~ubuntu-branches/ubuntu/warty/gwenview/warty

« back to all changes in this revision

Viewing changes to src/thumbnailloadjob.h

  • Committer: Bazaar Package Importer
  • Author(s): Christopher Martin
  • Date: 2004-06-13 18:55:04 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040613185504-net8ekxoswwvyxs9
Tags: 1.1.3-1
New upstream release. Translations now included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim: set tabstop=4 shiftwidth=4 noexpandtab
 
2
/*  Gwenview - A simple image viewer for KDE
 
3
    Copyright 2000-2004 Aur�lien G�teau
 
4
    This class is based on the ImagePreviewJob class from Konqueror.
 
5
    Original copyright follows.
 
6
*/
 
7
/*  This file is part of the KDE project
 
8
    Copyright (C) 2000 David Faure <faure@kde.org>
 
9
 
 
10
    This program is free software; you can redistribute it and/or modify
 
11
    it under the terms of the GNU General Public License as published by
 
12
    the Free Software Foundation; either version 2 of the License, or
 
13
    (at your option) any later version.
 
14
 
 
15
    This program is distributed in the hope that it will be useful,
 
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
    GNU General Public License for more details.
 
19
 
 
20
    You should have received a copy of the GNU General Public License
 
21
    along with this program; if not, write to the Free Software
 
22
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
23
*/
 
24
 
 
25
#ifndef THUMBNAILLOADJOB_H
 
26
#define THUMBNAILLOADJOB_H
 
27
 
 
28
// Qt includes
 
29
#include <qpixmap.h>
 
30
 
 
31
// KDE includes
 
32
#include <kio/job.h>
 
33
 
 
34
// Our includes
 
35
#include "tsthread/tsthread.h"
 
36
#include "tsthread/tswaitcondition.h"
 
37
#include "thumbnailsize.h"
 
38
 
 
39
class KFileItem;
 
40
 
 
41
typedef QPtrList<KFileItem> KFileItemList;
 
42
 
 
43
class ThumbnailThread : public TSThread {
 
44
Q_OBJECT
 
45
public:
 
46
        void load(
 
47
                const QString& originalURI,
 
48
                time_t originalTime,
 
49
                int originalSize,
 
50
                const QString& originalMimeType,
 
51
                const QString& pixPath,
 
52
                const QString& thumbnailPath);
 
53
protected:
 
54
        virtual void run();
 
55
signals:
 
56
        void done( const QImage& );
 
57
private:
 
58
        bool isJPEG(const QString& name);
 
59
        bool loadJPEG(const QString &pixPath, QImage&, int& width, int& height);
 
60
        void loadThumbnail();
 
61
        QImage mImage;
 
62
        QString mPixPath;
 
63
        QString mThumbnailPath;
 
64
        QString mOriginalURI;
 
65
        time_t mOriginalTime;
 
66
        int mOriginalSize;
 
67
        QString mOriginalMimeType;
 
68
        QMutex mMutex;
 
69
        TSWaitCondition mCond;
 
70
};
 
71
 
 
72
/**
 
73
 * A job that determines the thumbnails for the images in the current directory
 
74
 */
 
75
class ThumbnailLoadJob : public KIO::Job {
 
76
Q_OBJECT
 
77
public:
 
78
        /**
 
79
         * Create a job for determining the pixmaps of the images in the @p itemList
 
80
         */
 
81
        ThumbnailLoadJob( const KFileItemList* itemList,ThumbnailSize size);
 
82
        virtual ~ThumbnailLoadJob();
 
83
 
 
84
        /**
 
85
         * Call this to get started
 
86
         */
 
87
        void start();
 
88
 
 
89
        /**
 
90
         * To be called whenever an item is removed from the view
 
91
         */
 
92
        void itemRemoved(const KFileItem* item);
 
93
 
 
94
 
 
95
        /**
 
96
         * Add an item to a running job
 
97
         */
 
98
        void appendItem(const KFileItem* item);
 
99
 
 
100
        
 
101
        /**
 
102
         * Set item to be the next processed job. Returns false
 
103
         * if there's no such item in mItems
 
104
         */     
 
105
        bool setNextItem(const KFileItem* item);
 
106
 
 
107
        /**
 
108
         * Temporarily suspends loading. Used if there's a more
 
109
         * important action going on (loading an image etc.).
 
110
         */
 
111
        void suspend();
 
112
 
 
113
        /**
 
114
         * Resumes loading if suspended.
 
115
         */
 
116
        void resume();
 
117
 
 
118
        /**
 
119
         * Returns the thumbnail base dir
 
120
         */
 
121
        static QString thumbnailBaseDir();
 
122
 
 
123
 
 
124
        /**
 
125
         * Delete the thumbnail for the @p url
 
126
         */
 
127
        static void deleteImageThumbnail(const KURL& url);
 
128
        
 
129
signals:
 
130
        /**
 
131
         * Emitted when the thumbnail for the @p item has been loaded
 
132
         */
 
133
        void thumbnailLoaded(const KFileItem* item, const QPixmap&, const QSize&);
 
134
 
 
135
private slots:
 
136
        void slotResult( KIO::Job *job );
 
137
        void checkThumbnail();
 
138
        void thumbnailReady( const QImage& im );
 
139
 
 
140
private:
 
141
        enum { STATE_STATORIG, STATE_DOWNLOADORIG, STATE_DELETETEMP, STATE_CREATETHUMB, STATE_NEXTTHUMB } mState;
 
142
 
 
143
        // Our todo list :)
 
144
        KFileItemList mItems;
 
145
 
 
146
        // The current item
 
147
        const KFileItem *mCurrentItem;
 
148
 
 
149
        // The next item to be processed
 
150
        const KFileItem *mNextItem;
 
151
 
 
152
        // The URL of the current item (always equivalent to m_items.first()->item()->url())
 
153
        KURL mCurrentURL;
 
154
 
 
155
        // The URI of the original image (might be different from mCurrentURL.url())
 
156
        QString mOriginalURI;
 
157
        
 
158
        // The modification time of the original image
 
159
        time_t mOriginalTime;
 
160
 
 
161
        // The thumbnail path
 
162
        QString mThumbnailPath;
 
163
 
 
164
        // The URL of the temporary file for remote urls
 
165
        KURL mTempURL;
 
166
 
 
167
        // Thumbnail size
 
168
        ThumbnailSize mThumbnailSize;
 
169
 
 
170
        QPixmap mBrokenPixmap;
 
171
 
 
172
        bool mSuspended;
 
173
        
 
174
        ThumbnailThread mThumbnailThread;
 
175
 
 
176
        void determineNextIcon();
 
177
        void startCreatingThumbnail(const QString& path);
 
178
        
 
179
        void emitThumbnailLoaded(const QImage& img);
 
180
        void emitThumbnailLoadingFailed();
 
181
};
 
182
 
 
183
#endif