summaryrefslogtreecommitdiffstats
path: root/src/gvcore/imageloader.h
blob: ae9b7f829031e04c6c981aa2849b54a93a4dd461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// vim: set tabstop=4 shiftwidth=4 noexpandtab
/*
Gwenview - A simple image viewer for TDE
Copyright 2000-2004 Aurélien Gâteau
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
*/
#ifndef IMAGELOADER_H
#define IMAGELOADER_H

// TQt
#include <tqasyncimageio.h>
#include <tqbuffer.h>
#include <tqcstring.h>

// KDE
#include <kio/job.h>

// Local 
#include "tsthread/tsthread.h"
#include "imageframe.h"
#include "busylevelmanager.h"
#include "mimetypeutils.h"

#include "libgwenview_export.h"
namespace Gwenview {
class DecoderThread : public TSThread {
Q_OBJECT
  
public:
	void setRawData(const TQByteArray&);
	TQImage popLoadedImage();
	
signals:
	void failed();
	void succeeded();
	
protected:
	void run();

private:
	TQMutex mMutex;
	TQByteArray mRawData;
	TQImage mImage;
};

class ImageLoaderPrivate;

class LIBGWENVIEW_EXPORT ImageLoader : public TQObject, public TQImageConsumer {
Q_OBJECT
  
public:
	static ImageLoader* loader( const KURL& url, const TQObject* owner, BusyLevel priority ); // use this instead of ctor
	void release( const TQObject* owner ); // use this instead of dtor

	TQImage processedImage() const;
	ImageFrames frames() const;
	TQCString imageFormat() const;
	TQByteArray rawData() const;
	TQString mimeType() const;
	MimeTypeUtils::Kind urlKind() const;
	KURL url() const;
	TQRegion loadedRegion() const; // valid parts of processedImage()
	bool completed() const;

signals:
	void urlKindDetermined();
	void sizeLoaded(int, int);
	void imageChanged(const TQRect&);
	void imageLoaded( bool ok );

private slots:
	void slotStatResult(KIO::Job*);
	void slotDataReceived(KIO::Job*, const TQByteArray& chunk);
	void slotGetResult(KIO::Job*);
	void decodeChunk();
	void slotDecoderThreadFailed();
	void slotDecoderThreadSucceeded();
	void slotBusyLevelChanged( BusyLevel );
	void ownerDestroyed();
	void startLoading();
	void callFinish();

private:
	ImageLoader();
	~ImageLoader();
	void ref( const TQObject* owner, BusyLevel priority );
	void deref( const TQObject* owner );
	void suspendLoading();
	void resumeLoading();
	void finish( bool ok );
	void startThread();
	void setURL( const KURL& url );
	void checkPendingStat();
	void checkPendingGet();
	BusyLevel priority() const;
	
	// TQImageConsumer methods
	void end();
	void changed(const TQRect&);
	void frameDone();
	void frameDone(const TQPoint& offset, const TQRect& rect);
	void setLooping(int);
	void setFramePeriod(int milliseconds);
	void setSize(int, int);

	ImageLoaderPrivate* d;
};

} // namespace
#endif /* IMAGELOADER_H */