OSDN Git Service

1996e3df4520f9a8f6ab2db5de3ef694564bb254
[kita/kita.git] / kita / src / libkita / imgmanager.h
1 /***************************************************************************
2 *   Copyright (C) 2004 by Kita Developers                                 *
3 *   ikemo@users.sourceforge.jp                                            *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 ***************************************************************************/
10
11 #ifndef KITAIMGMANAGER_H
12 #define KITAIMGMANAGER_H
13
14 #include "event.h"
15
16 #include <kurl.h>
17
18 #include <qobject.h>
19 #include <qdict.h>
20 #include <qmutex.h>
21 #include <qevent.h>
22 #include <qstringlist.h>
23
24 struct IMGDAT
25 {
26     int code;
27     bool mosaic;
28     int width;
29     int height;
30     unsigned int size;
31     KURL datURL;
32 };
33
34
35 /*----------------------------------------------------------*/
36
37 namespace Kita
38 {
39     class LoaderData;
40     
41     class ImgManager : public QObject
42     {
43         Q_OBJECT
44
45         static ImgManager* instance;
46         static QMutex m_mutex;
47         QDict< IMGDAT > m_imgDatDict;
48         QWidget* m_mainwidget;
49         QStringList m_urlList;  
50
51     public:
52         ImgManager( QWidget* mainwidget );
53         ~ImgManager();
54
55         static void setup( QWidget* mainwidget );
56         static void deleteInstance();
57         static ImgManager* getInstance();
58         static bool isImgFile( const KURL& url, bool use_mimetype );
59         static bool isAnimationGIF( const KURL& url );
60         static bool isBMP( const KURL& url );
61
62         static bool load( const KURL& url, const KURL& datURL );
63         static void stop( const KURL& url );
64         static QString getPath( const KURL& url );
65         static bool isLoadingNow( const KURL& url );
66         static bool deleteCache( const KURL& url, QWidget* parent );
67         static bool copyCache( const KURL& url, QWidget* parent );
68
69         static bool mosaic( const KURL& url );
70         static void setMosaic( const KURL& url, bool status );
71         static int code( const KURL& url );
72         static int width( const KURL& url );
73         static int height( const KURL& url );
74         static unsigned int size( const KURL& url );
75         static QPixmap icon( const KURL& url );
76         static KURL datURL( const KURL& url );
77
78     private:
79         bool isImgFilePrivate( const KURL& url, bool use_mimetype );
80         bool loadPrivate( const KURL& url, const KURL& datURL );
81         bool deleteCachePrivate( const KURL& url, QWidget* parent );
82         bool copyCachePrivate( const KURL& url, QWidget* parent );
83         void setMosaicPrivate( const KURL& url, bool status );
84
85         void createImgDat( const KURL& url, int code );
86         IMGDAT* getImgDat( const KURL& url );
87         void deleteImgDat( const KURL& url );
88         void getSize( const KURL& url );
89         bool cacheExists( const KURL& url );
90
91     private slots:
92         void slotData( const Kita::LoaderData&, const QByteArray& );
93         void slotResult( const Kita::LoaderData& );
94
95     protected:
96         virtual void customEvent( QCustomEvent * e );
97
98     signals:
99         void receiveImgData( const KURL&, unsigned int, unsigned int );
100         void finishImgLoad( const KURL& );
101         void cacheDeleted( const KURL& );
102     };
103
104
105     /* finish event */
106     class EmitFinishEvent : public QCustomEvent
107     {
108         KURL m_url;
109
110       public:
111         EmitFinishEvent( KURL url ) : QCustomEvent( EVENT_EmitFinigh ), m_url( url ) {}
112
113         KURL url() const { return m_url; }
114     };
115
116 }
117
118 #endif