#ifndef _KVI_ICONMANAGER_H_
#define _KVI_ICONMANAGER_H_

//
//   File : kvi_iconmanager.h
//   Creation date : Sat Jun 24 2000 14:49:24 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
//
//   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 opinion) 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. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#include "kvi_settings.h"
#include "kvi_string.h"
#include "kvi_avatar.h"

#include <qpixmap.h>
#include <qobject.h>
#include <qwidget.h>
#include <qasciidict.h>
#include <time.h>

#define KVI_SMALLICON_NONE 0
#define KVI_SMALLICON_CLOSE 1
#define KVI_SMALLICON_MAXIMIZE 2
#define KVI_SMALLICON_MINIMIZE 3
#define KVI_SMALLICON_RESTORE 4
#define KVI_SMALLICON_DEFAULTICON 5
#define KVI_SMALLICON_DOCK 6
#define KVI_SMALLICON_UNDOCK 7
#define KVI_SMALLICON_QUITAPP 8
#define KVI_SMALLICON_CONSOLE 9
#define KVI_SMALLICON_FLOPPY 10
#define KVI_SMALLICON_PARSERERROR 11
#define KVI_SMALLICON_PARSERWARNING 12
#define KVI_SMALLICON_SERVER 13
#define KVI_SMALLICON_WORLD 14
#define KVI_SMALLICON_PROXY 15
#define KVI_SMALLICON_KVIRC 16
#define KVI_SMALLICON_CUT 17
#define KVI_SMALLICON_COPY 18
#define KVI_SMALLICON_PASTE 19
#define KVI_SMALLICON_OPTIONS 20
#define KVI_SMALLICON_SOCKETMESSAGE 21
#define KVI_SMALLICON_SOCKETWARNING 22
#define KVI_SMALLICON_SOCKETERROR 23
#define KVI_SMALLICON_SYSTEMERROR 24
#define KVI_SMALLICON_RAW 25
#define KVI_SMALLICON_SYSTEMWARNING 26
#define KVI_SMALLICON_SYSTEMMESSAGE 27
#define KVI_SMALLICON_UNHANDLED 28
#define KVI_SMALLICON_SERVERINFO 29
#define KVI_SMALLICON_MOTD 30
#define KVI_SMALLICON_CHANNEL 31
#define KVI_SMALLICON_HIDEDOUBLEVIEW 32
#define KVI_SMALLICON_SHOWDOUBLEVIEW 33
#define KVI_SMALLICON_OP 34
#define KVI_SMALLICON_VOICE 35
#define KVI_SMALLICON_SERVERPING 36
#define KVI_SMALLICON_SHOWLISTVIEW 37
#define KVI_SMALLICON_HIDELISTVIEW 38
#define KVI_SMALLICON_JOIN 39
#define KVI_SMALLICON_PART 40
#define KVI_SMALLICON_UNRECOGNIZED 41
#define KVI_SMALLICON_TOPIC 42
#define KVI_SMALLICON_ACCEPT 43
#define KVI_SMALLICON_DISCARD 44
#define KVI_SMALLICON_OWNPRIVMSG 45
#define KVI_SMALLICON_CHANPRIVMSG 46
#define KVI_SMALLICON_QUERY 47
#define KVI_SMALLICON_QUERYPRIVMSG 48
#define KVI_SMALLICON_HELP 49
#define KVI_SMALLICON_MDIHELP 50
#define KVI_SMALLICON_CTCPREPLY 51
#define KVI_SMALLICON_CTCPREQUESTREPLIED 52
#define KVI_SMALLICON_CTCPREQUESTIGNORED 53
#define KVI_SMALLICON_CTCPREQUESTFLOOD 54
#define KVI_SMALLICON_CTCPREQUESTUNKNOWN 55
#define KVI_SMALLICON_ACTION 56
#define KVI_SMALLICON_AVATAR 57
#define KVI_SMALLICON_QUIT 58
#define KVI_SMALLICON_SPLIT 59
#define KVI_SMALLICON_QUITSPLIT 60
#define KVI_SMALLICON_NICK 61
#define KVI_SMALLICON_DEOP 62
#define KVI_SMALLICON_DEVOICE 63
#define KVI_SMALLICON_MODE 64
#define KVI_SMALLICON_KEY 65
#define KVI_SMALLICON_LIMIT 66
#define KVI_SMALLICON_BAN 67
#define KVI_SMALLICON_UNBAN 68
#define KVI_SMALLICON_BANEXCEPT 69
#define KVI_SMALLICON_BANUNEXCEPT 70
#define KVI_SMALLICON_INVITEEXCEPT 71
#define KVI_SMALLICON_INVITEUNEXCEPT 72
#define KVI_SMALLICON_CHANMODE 73
#define KVI_SMALLICON_CHANMODEHIDE 74
#define KVI_SMALLICON_WHO 75
#define KVI_SMALLICON_EDITOR 76
#define KVI_SMALLICON_DCCREQUEST 77
#define KVI_SMALLICON_DCCMSG 78
#define KVI_SMALLICON_DCCERROR 79
#define KVI_SMALLICON_ICONMANAGER 80
#define KVI_SMALLICON_SCRIPTCENTER 81
#define KVI_SMALLICON_BOMB 82
#define KVI_SMALLICON_EVENT 83
#define KVI_SMALLICON_EVENTNOHANDLERS 84
#define KVI_SMALLICON_HANDLER 85
#define KVI_SMALLICON_HANDLERDISABLED 86
#define KVI_SMALLICON_NICKNAMEPROBLEM 87
#define KVI_SMALLICON_WHOISUSER 88
#define KVI_SMALLICON_WHOISCHANNELS 89
#define KVI_SMALLICON_WHOISIDLE 90
#define KVI_SMALLICON_WHOISSERVER 91
#define KVI_SMALLICON_WHOISOTHER 92
#define KVI_SMALLICON_TIME 93
#define KVI_SMALLICON_NOTIFYONLINE 94
#define KVI_SMALLICON_NOTIFYOFFLINE 95
#define KVI_SMALLICON_LOCKED 96
#define KVI_SMALLICON_UNLOCKED 97
#define KVI_SMALLICON_LOCKEDOFF 98
#define KVI_SMALLICON_UNLOCKEDOFF 99
#define KVI_SMALLICON_OWNPRIVMSGCRYPTED 100
#define KVI_SMALLICON_CHANPRIVMSGCRYPTED 101
#define KVI_SMALLICON_QUERYPRIVMSGCRYPTED 102
#define KVI_SMALLICON_DCCCHATMSG 103
#define KVI_SMALLICON_DCCCHATMSGCRYPTED 104
#define KVI_SMALLICON_IRC 105
#define KVI_SMALLICON_FOLDER 106
#define KVI_SMALLICON_HOME 107
#define KVI_SMALLICON_BOOKMARKS 108
#define KVI_SMALLICON_SPY 109
#define KVI_SMALLICON_KICK 110
#define KVI_SMALLICON_LINUX 111
#define KVI_SMALLICON_LINKS 112
#define KVI_SMALLICON_REGUSERS 113
#define KVI_SMALLICON_DOCKWIDGET 114
#define KVI_SMALLICON_CASCADEWINDOWS 115
#define KVI_SMALLICON_MAXVERTICAL 116
#define KVI_SMALLICON_MAXHORIZONTAL 117
#define KVI_SMALLICON_TILEWINDOWS 118
#define KVI_SMALLICON_LOG 119
#define KVI_SMALLICON_SPAM 120
#define KVI_SMALLICON_FILE 121
#define KVI_SMALLICON_ICQ 122
#define KVI_SMALLICON_ICQYELLOW 123
#define KVI_SMALLICON_ICQRED 124
#define KVI_SMALLICON_ICQBLUE 125
#define KVI_SMALLICON_ICQLIGHTGREEN 126
#define KVI_SMALLICON_ICQLIGHTYELLOW 127
#define KVI_SMALLICON_MESSAGE 128
#define KVI_SMALLICON_MESSAGESENT 129
#define KVI_SMALLICON_BLUESQUARE 130
#define KVI_SMALLICON_VIOLETSQUARE 131
#define KVI_SMALLICON_YELLOWSQUARE 132
#define KVI_SMALLICON_GREENSQUARE 133
#define KVI_SMALLICON_BLACKSQUARE 134
#define KVI_SMALLICON_REDSQUARE 135
#define KVI_SMALLICON_CYANSQUARE 136
#define KVI_SMALLICON_DKGREENSQUARE 137
#define KVI_SMALLICON_TERMINAL 138
#define KVI_SMALLICON_WALLOPS 139
#define KVI_SMALLICON_INVISIBLE 140
#define KVI_SMALLICON_SERVERNOTICE 141
#define KVI_SMALLICON_GNUTELLA 142
#define KVI_SMALLICON_SEARCH 143
#define KVI_SMALLICON_FILES 144
#define KVI_SMALLICON_TRANSFER 145
#define KVI_SMALLICON_PACKAGE 146
#define KVI_SMALLICON_RETRY 147
#define KVI_SMALLICON_IDEA 148
#define KVI_SMALLICON_COLORS 149
#define KVI_SMALLICON_GUI 150
#define KVI_SMALLICON_IRCVIEW 151
#define KVI_SMALLICON_ALIAS 152
#define KVI_SMALLICON_CHANNELNOTICE 153
#define KVI_SMALLICON_CHANNELNOTICECRYPTED 154
#define KVI_SMALLICON_QUERYNOTICE 155
#define KVI_SMALLICON_QUERYNOTICECRYPTED 156
// FIXME: rename the icon 157: it was colliding with 141
#define KVI_SMALLICON_SERVNOTICE 157
#define KVI_SMALLICON_POPUP 158
#define KVI_SMALLICON_PROLOGUE 159
#define KVI_SMALLICON_EPILOGUE 160
#define KVI_SMALLICON_OFFER 161
#define KVI_SMALLICON_CTCPREPLYUNKNOWN 162
#define KVI_SMALLICON_CANVAS 163
#define KVI_SMALLICON_NICKSERV 164
#define KVI_SMALLICON_CHANSERV 165
#define KVI_SMALLICON_DCCVOICE 166
#define KVI_SMALLICON_PLAY 167
#define KVI_SMALLICON_RECORD 168
#define KVI_SMALLICON_TILE_HOR_WINDOWS 169
#define KVI_SMALLICON_AWAY 170
#define KVI_SMALLICON_IDENT 171
#define KVI_SMALLICON_HOMEPAGE 172
#define KVI_SMALLICON_LIST 173
#define KVI_SMALLICON_HALFOP 174
#define KVI_SMALLICON_HALFDEOP 175
#define KVI_SMALLICON_INVITE 176
#define KVI_SMALLICON_MULTIMEDIA 177
#define KVI_SMALLICON_LOOK 178
#define KVI_SMALLICON_INPUT 179
#define KVI_SMALLICON_MESSAGES 180
#define KVI_SMALLICON_QUERYTRACE 181
#define KVI_SMALLICON_NOCHANNEL 182
#define KVI_SMALLICON_BROADCASTPRIVMSG 183
#define KVI_SMALLICON_BROADCASTNOTICE 184
#define KVI_SMALLICON_URL 185
#define KVI_SMALLICON_RAWEVENT 186
#define KVI_SMALLICON_RAWEVENTNOHANDLERS 187
#define KVI_SMALLICON_MEKICK 188
#define KVI_SMALLICON_MEOP 189
#define KVI_SMALLICON_MEVOICE 190
#define KVI_SMALLICON_MEDEOP 191
#define KVI_SMALLICON_MEDEVOICE 192
#define KVI_SMALLICON_MEHALFOP 193
#define KVI_SMALLICON_MEDEHALFOP 194
#define KVI_SMALLICON_MEBAN 195
#define KVI_SMALLICON_MEUNBAN 196
#define KVI_SMALLICON_MEBANEXCEPT 197
#define KVI_SMALLICON_MEBANUNEXCEPT 198
#define KVI_SMALLICON_MEINVITEEXCEPT 199
#define KVI_SMALLICON_MEINVITEUNEXCEPT 200
#define KVI_SMALLICON_CLASSICTASKBAR 201
#define KVI_SMALLICON_TREETASKBAR 202
#define KVI_SMALLICON_IGNORE 203
#define KVI_SMALLICON_USERLIST 204
#define KVI_SMALLICON_STATS 205
#define KVI_SMALLICON_LOUPE 206
#define KVI_SMALLICON_XY 207
#define KVI_SMALLICON_IRC0 208
#define KVI_SMALLICON_IRC1 209
#define KVI_SMALLICON_IRC2 210
#define KVI_SMALLICON_IRC3 211
#define KVI_SMALLICON_IRC4 212
#define KVI_SMALLICON_IRC5 213
#define KVI_SMALLICON_HEART 214
#define KVI_SMALLICON_HEARTBROKEN 215
#define KVI_SMALLICON_ROSE 216
#define KVI_SMALLICON_BIGGRIN 217
#define KVI_SMALLICON_BIGGRINGLASSES 218
#define KVI_SMALLICON_BIGGRINEYES 219
#define KVI_SMALLICON_TEXTEXCLAMATIVE 220
#define KVI_SMALLICON_TEXTPOINTS 221
#define KVI_SMALLICON_KISS 222
#define KVI_SMALLICON_SURPRISED1 223
#define KVI_SMALLICON_UGLY 224
#define KVI_SMALLICON_ANGRY 225
#define KVI_SMALLICON_SURPRISED2 226
#define KVI_SMALLICON_SMILE 227
#define KVI_SMALLICON_TONGUE 228
#define KVI_SMALLICON_SSL 229
#define KVI_SMALLICON_CRY 230
#define KVI_SMALLICON_EYE 231
#define KVI_SMALLICON_DEADCHANNEL 232
#define KVI_SMALLICON_DEADQUERY 233
#define KVI_SMALLICON_SOUND 234
#define KVI_SMALLICON_TOOLBAR 235
#define KVI_SMALLICON_TEXTENCODING 236
#define KVI_SMALLICON_NEWITEM 237
#define KVI_SMALLICON_NEWITEMBYWIZARD 238
#define KVI_SMALLICON_DELETEITEM 239
#define KVI_SMALLICON_EDITITEM 240

#define KVI_NUM_SMALL_ICONS 241


// FIXME: load ONLY the most used icons... the other should remain on disk
//        and be loaded only when necessary (switch ?)

#define KVI_BIGICON_CONNECT 0
#define KVI_BIGICON_CONNECTING 1
#define KVI_BIGICON_CONNECTED 2
#define KVI_BIGICON_HELPINDEX 3
#define KVI_BIGICON_HELPBACKWARD 4
#define KVI_BIGICON_HELPFORWARD 5
#define KVI_BIGICON_HELPSEARCH 6
#define KVI_BIGICON_HELPCLOSE 7
#define KVI_BIGICON_TOOLS 8
#define KVI_BIGICON_ACTIONS 9
#define KVI_BIGICON_CHANNELS 10
#define KVI_BIGICON_FOLDER 11

//#define KVI_BIGICON_FOLDER 10
//#define KVI_BIGICON_UNKNOWNFILE 11

#define KVI_NUM_BIG_ICONS 12

class KVIRC_API KviCachedPixmap
{
public:
	KviCachedPixmap(){ timestamp = 0; pPixmap = 0; };
	~KviCachedPixmap(){ if(pPixmap)delete pPixmap; };
public:
	time_t       timestamp;
	QPixmap    * pPixmap;
};

class QTimer;

class KVIRC_API KviIconWidget : public QWidget
{
	Q_OBJECT
public:
	KviIconWidget();
	KviIconWidget(QWidget * par);
	~KviIconWidget();
protected:
	void init();
	virtual void closeEvent(QCloseEvent *e);
	virtual bool eventFilter(QObject * o,QEvent *e);
signals:
	void closed();
	void selected(int iIcon);
};



class KVIRC_API KviIconManager : public QObject
{
	Q_OBJECT
public:
	KviIconManager();
	~KviIconManager();
private:
	QPixmap                     * m_smallIcons[KVI_NUM_SMALL_ICONS];
	QPixmap                     * m_bigIcons[KVI_NUM_BIG_ICONS];
	QAsciiDict<KviCachedPixmap> * m_pCachedImages;
	QTimer                      * m_pCleanupTimer;
	KviIconWidget               * m_pIconWidget;
public:
	QPixmap * getSmallIcon(int idx);
	QPixmap * getBigIcon(int idx);
	// WARNING: Don't store this pointer!
	// id == filename | number that indicates an internal pixmap
	// 0 stands for "any"
	QPixmap * getImage(const char * id,bool bCanBeNumber = true,KviStr * pRetPath = 0);
	// 0 stands for "any"
	KviAvatar * getAvatar(const char * fName);
public slots:
	void showIconWidget();
protected slots:
	void cleanup();
	void iconWidgetClosed();
};

inline QPixmap * KviIconManager::getSmallIcon(int idx){ return m_smallIcons[idx]; };
inline QPixmap * KviIconManager::getBigIcon(int idx){ return m_bigIcons[idx]; };

extern KVIRC_API KviIconManager * g_pIconManager;

#endif //_KVI_ICONMANAGER_H_
