1
//=============================================================================
3
// File : KviTextIconManager.cpp
4
// Creation date : Thu 15 May 2002 12:04:12 by Szymon Stefanek
6
// This file is part of the KVIrc irc client distribution
7
// Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) 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.
17
// See the 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 Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#define _KVI_TEXTICONMANAGER_CPP_
27
#include "KviTextIconManager.h"
28
#include "KviCString.h"
29
#include "KviPointerList.h"
30
#include "KviConfigurationFile.h"
31
#include "KviApplication.h"
32
#include "kvi_confignames.h"
33
#include "KviAnimatedPixmap.h"
34
#include "KviOptions.h"
39
static KviTextIconAssocEntry default_associations[]=
41
{ ":)" , KviIconManager::Smile },
42
{ ":*" , KviIconManager::Kiss },
43
{ ":D" , KviIconManager::BigGrin },
44
{ ":(" , KviIconManager::Ugly },
45
{ ":/" , KviIconManager::Angry },
46
{ ":O" , KviIconManager::Surprised2 },
47
{ ":P" , KviIconManager::Tongue },
48
{ ";)" , KviIconManager::Eye },
49
{ ":°)" , KviIconManager::TearSmile },
50
{ ":°" , KviIconManager::Cry },
51
{ ":S" , KviIconManager::Afraid },
52
{ ":|" , KviIconManager::Demoralized },
53
{ ":P°" , KviIconManager::Slurp },
57
KVIRC_API KviTextIconManager * g_pTextIconManager = 0;
59
KviTextIcon::KviTextIcon(KviIconManager::SmallIcon eIcon)
60
: m_eIcon(eIcon),m_pAnimatedPixmap(0)
64
KviTextIcon::KviTextIcon(QString szFile)
65
: m_eIcon(KviIconManager::None), m_szFileName(szFile)
69
if(g_pApp->findImage(szRetPath, szFile))
71
m_pAnimatedPixmap = new KviAnimatedPixmap(szRetPath);
72
#if 0 // this doesn't work anyway
73
if(KVI_OPTION_BOOL(KviOption_boolEnableAnimatedSmiles))
75
m_pAnimatedPixmap->start();
77
m_pAnimatedPixmap->stop();
81
m_pAnimatedPixmap = NULL;
85
KviTextIcon::KviTextIcon(KviTextIcon * pIcon)
87
m_eIcon = pIcon->id();
88
m_szFileName = pIcon->m_szFileName;
89
if(pIcon->m_pAnimatedPixmap)
91
m_pAnimatedPixmap = new KviAnimatedPixmap(*(pIcon->m_pAnimatedPixmap));
93
m_pAnimatedPixmap = NULL;
97
KviTextIcon::~KviTextIcon()
100
delete m_pAnimatedPixmap;
103
void KviTextIcon::setId(KviIconManager::SmallIcon eIcon)
106
m_szFileName = QString();
109
void KviTextIcon::setId(int iIcon)
111
m_eIcon = g_pIconManager->iconName(iIcon);
112
m_szFileName = QString();
115
void KviTextIcon::setFilename(QString szFileName)
117
m_eIcon = KviIconManager::None;
118
m_szFileName = szFileName;
121
QPixmap * KviTextIcon::pixmap()
124
return g_pIconManager->getSmallIcon(m_eIcon);
126
// This is actually wrong (at least for the current implementation).
127
// Users of this class expect the pointer to be permanent while
128
// g_pIconManager returns temporary pointers.
129
// KviIrcView will happily crash dereferencing a hollow pointer sooner or later
130
return g_pIconManager->getPixmap(m_szFileName);
133
KviTextIconManager::KviTextIconManager()
136
m_pTextIconDict = new KviPointerHashTable<QString,KviTextIcon>(47,false);
137
m_pTextIconDict->setAutoDelete(true);
140
KviTextIconManager::~KviTextIconManager()
142
delete m_pTextIconDict;
145
void KviTextIconManager::clear()
147
m_pTextIconDict->clear();
150
void KviTextIconManager::insert(const QString & szName, int iId)
152
m_pTextIconDict->replace(szName, new KviTextIcon(g_pIconManager->iconName(iId)));
156
void KviTextIconManager::insert(const QString & szName, KviTextIcon & icon)
158
m_pTextIconDict->replace(szName, new KviTextIcon(&icon));
162
void KviTextIconManager::checkDefaultAssociations()
164
for(int i=0; default_associations[i].name; i++)
166
if(!m_pTextIconDict->find(default_associations[i].name))
167
insert(QString::fromUtf8(default_associations[i].name),default_associations[i].iVal);
172
void KviTextIconManager::load()
176
if(g_pApp->getReadOnlyConfigPath(szTmp,KVI_CONFIGFILE_TEXTICONS))
178
iUpd = load(szTmp,false);
181
if(iUpd == TEXTICONMANAGER_CURRENT_CONFIG_UPDATE)
184
// do a merge of the texticons if we have a new config version
185
g_pApp->getGlobalKvircDirectory(szTmp,KviApplication::Config,KVI_CONFIGFILE_TEXTICONS);
187
if(QFile::exists(szTmp))
191
void KviTextIconManager::applyOptions()
194
KviTextIcon * pIcon = m_pTextIconDict->first();
196
pIcon = m_pTextIconDict->next()
199
if(pIcon->animatedPixmap())
201
if(KVI_OPTION_BOOL(KviOption_boolEnableAnimatedSmiles))
203
pIcon->animatedPixmap()->start();
205
pIcon->animatedPixmap()->stop();
211
void KviTextIconManager::save()
214
g_pApp->getLocalKvircDirectory(szTmp,KviApplication::Config,KVI_CONFIGFILE_TEXTICONS);
218
int KviTextIconManager::load(const QString & szFileName, bool bMerge)
220
if(!bMerge) m_pTextIconDict->clear();
222
KviConfigurationFile cfg(szFileName,KviConfigurationFile::Read);
224
cfg.setGroup("Manager");
225
int iUpd = cfg.readIntEntry("ConfigUpdate",0);
227
KviConfigurationFileGroup * pDict = cfg.dict()->find("TextIcons");
230
KviConfigurationFileGroupIterator it(*pDict);
232
KviPointerList<QString> names;
233
names.setAutoDelete(true);
237
names.append(new QString(it.currentKey()));
241
cfg.setGroup("TextIcons");
243
for(QString * s = names.first(); s; s = names.next())
245
int iId = cfg.readIntEntry(*s,-1);
248
//qDebug("%s %s %i %i",__FILE__,__FUNCTION__,__LINE__,id);
251
pix = g_pIconManager->getSmallIcon(iId);
253
szTmp = cfg.readEntry(*s);
254
pix=g_pIconManager->getPixmap(szTmp);
257
iId = KviIconManager::Help;
258
pix = g_pIconManager->getSmallIcon(iId);
266
if(!m_pTextIconDict->find(*s))
270
m_pTextIconDict->replace(*s,new KviTextIcon(g_pIconManager->iconName(iId)));
272
m_pTextIconDict->replace(*s,new KviTextIcon(szTmp));
278
m_pTextIconDict->replace(*s,new KviTextIcon(g_pIconManager->iconName(iId)));
280
m_pTextIconDict->replace(*s,new KviTextIcon(szTmp));
292
void KviTextIconManager::save(const QString & szFileName)
294
KviConfigurationFile cfg(szFileName,KviConfigurationFile::Write);
296
cfg.setGroup("Manager");
297
cfg.writeEntry("ConfigUpdate",TEXTICONMANAGER_CURRENT_CONFIG_UPDATE);
299
cfg.setGroup("TextIcons");
301
KviPointerHashTableIterator<QString,KviTextIcon> it(*m_pTextIconDict);
302
while(KviTextIcon * pIcon = it.current())
304
if(pIcon->id() != -1)
305
cfg.writeEntry(it.currentKey(),pIcon->id());
307
cfg.writeEntry(it.currentKey(),pIcon->filename());
312
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
313
#include "KviTextIconManager.moc"
314
#endif //COMPILE_USE_STANDALONE_MOC_SOURCES