~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvirc/kernel/KviTextIconManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviTextIconManager.cpp
 
4
//   Creation date : Thu 15 May 2002 12:04:12 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
#define _KVI_TEXTICONMANAGER_CPP_
 
26
 
 
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"
 
35
 
 
36
#include <QPixmap>
 
37
#include <QFile>
 
38
 
 
39
static KviTextIconAssocEntry default_associations[]=
 
40
{
 
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       },
 
54
        { 0       , 0                         }
 
55
};
 
56
 
 
57
KVIRC_API KviTextIconManager * g_pTextIconManager = 0;
 
58
 
 
59
KviTextIcon::KviTextIcon(KviIconManager::SmallIcon eIcon)
 
60
: m_eIcon(eIcon),m_pAnimatedPixmap(0)
 
61
{
 
62
}
 
63
 
 
64
KviTextIcon::KviTextIcon(QString szFile)
 
65
: m_eIcon(KviIconManager::None), m_szFileName(szFile)
 
66
{
 
67
        QString szRetPath;
 
68
 
 
69
        if(g_pApp->findImage(szRetPath, szFile))
 
70
        {
 
71
                m_pAnimatedPixmap = new KviAnimatedPixmap(szRetPath);
 
72
#if 0 // this doesn't work anyway
 
73
                if(KVI_OPTION_BOOL(KviOption_boolEnableAnimatedSmiles))
 
74
                {
 
75
                        m_pAnimatedPixmap->start();
 
76
                } else {
 
77
                        m_pAnimatedPixmap->stop();
 
78
                }
 
79
#endif
 
80
        } else {
 
81
                m_pAnimatedPixmap = NULL;
 
82
        }
 
83
}
 
84
 
 
85
KviTextIcon::KviTextIcon(KviTextIcon * pIcon)
 
86
{
 
87
        m_eIcon = pIcon->id();
 
88
        m_szFileName = pIcon->m_szFileName;
 
89
        if(pIcon->m_pAnimatedPixmap)
 
90
        {
 
91
                m_pAnimatedPixmap = new KviAnimatedPixmap(*(pIcon->m_pAnimatedPixmap));
 
92
        } else {
 
93
                m_pAnimatedPixmap = NULL;
 
94
        }
 
95
}
 
96
 
 
97
KviTextIcon::~KviTextIcon()
 
98
{
 
99
        if(m_pAnimatedPixmap)
 
100
                delete m_pAnimatedPixmap;
 
101
}
 
102
 
 
103
void KviTextIcon::setId(KviIconManager::SmallIcon eIcon)
 
104
{
 
105
        m_eIcon = eIcon;
 
106
        m_szFileName = QString();
 
107
}
 
108
 
 
109
void KviTextIcon::setId(int iIcon)
 
110
{
 
111
        m_eIcon = g_pIconManager->iconName(iIcon);
 
112
        m_szFileName = QString();
 
113
}
 
114
 
 
115
void KviTextIcon::setFilename(QString szFileName)
 
116
{
 
117
        m_eIcon = KviIconManager::None;
 
118
        m_szFileName = szFileName;
 
119
}
 
120
 
 
121
QPixmap * KviTextIcon::pixmap()
 
122
{
 
123
        if(m_eIcon >= 0)
 
124
                return g_pIconManager->getSmallIcon(m_eIcon);
 
125
 
 
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);
 
131
}
 
132
 
 
133
KviTextIconManager::KviTextIconManager()
 
134
: QObject()
 
135
{
 
136
        m_pTextIconDict = new KviPointerHashTable<QString,KviTextIcon>(47,false);
 
137
        m_pTextIconDict->setAutoDelete(true);
 
138
}
 
139
 
 
140
KviTextIconManager::~KviTextIconManager()
 
141
{
 
142
        delete m_pTextIconDict;
 
143
}
 
144
 
 
145
void KviTextIconManager::clear()
 
146
{
 
147
        m_pTextIconDict->clear();
 
148
}
 
149
 
 
150
void KviTextIconManager::insert(const QString & szName, int iId)
 
151
{
 
152
        m_pTextIconDict->replace(szName, new KviTextIcon(g_pIconManager->iconName(iId)));
 
153
        emit changed();
 
154
}
 
155
 
 
156
void KviTextIconManager::insert(const QString & szName, KviTextIcon & icon)
 
157
{
 
158
        m_pTextIconDict->replace(szName, new KviTextIcon(&icon));
 
159
        emit changed();
 
160
}
 
161
 
 
162
void KviTextIconManager::checkDefaultAssociations()
 
163
{
 
164
        for(int i=0; default_associations[i].name; i++)
 
165
        {
 
166
                if(!m_pTextIconDict->find(default_associations[i].name))
 
167
                        insert(QString::fromUtf8(default_associations[i].name),default_associations[i].iVal);
 
168
        }
 
169
        emit changed();
 
170
}
 
171
 
 
172
void KviTextIconManager::load()
 
173
{
 
174
        QString szTmp;
 
175
        int iUpd = 0;
 
176
        if(g_pApp->getReadOnlyConfigPath(szTmp,KVI_CONFIGFILE_TEXTICONS))
 
177
        {
 
178
                iUpd = load(szTmp,false);
 
179
        }
 
180
 
 
181
        if(iUpd == TEXTICONMANAGER_CURRENT_CONFIG_UPDATE)
 
182
                return;
 
183
 
 
184
        // do a merge of the texticons if we have a new config version
 
185
        g_pApp->getGlobalKvircDirectory(szTmp,KviApplication::Config,KVI_CONFIGFILE_TEXTICONS);
 
186
 
 
187
        if(QFile::exists(szTmp))
 
188
                load(szTmp,true);
 
189
}
 
190
 
 
191
void KviTextIconManager::applyOptions()
 
192
{
 
193
        for(
 
194
                KviTextIcon * pIcon = m_pTextIconDict->first();
 
195
                pIcon;
 
196
                pIcon = m_pTextIconDict->next()
 
197
                )
 
198
        {
 
199
                if(pIcon->animatedPixmap())
 
200
                {
 
201
                        if(KVI_OPTION_BOOL(KviOption_boolEnableAnimatedSmiles))
 
202
                        {
 
203
                                pIcon->animatedPixmap()->start();
 
204
                        } else {
 
205
                                pIcon->animatedPixmap()->stop();
 
206
                        }
 
207
                }
 
208
        }
 
209
}
 
210
 
 
211
void KviTextIconManager::save()
 
212
{
 
213
        QString szTmp;
 
214
        g_pApp->getLocalKvircDirectory(szTmp,KviApplication::Config,KVI_CONFIGFILE_TEXTICONS);
 
215
        save(szTmp);
 
216
}
 
217
 
 
218
int KviTextIconManager::load(const QString & szFileName, bool bMerge)
 
219
{
 
220
        if(!bMerge) m_pTextIconDict->clear();
 
221
 
 
222
        KviConfigurationFile cfg(szFileName,KviConfigurationFile::Read);
 
223
 
 
224
        cfg.setGroup("Manager");
 
225
        int iUpd = cfg.readIntEntry("ConfigUpdate",0);
 
226
 
 
227
        KviConfigurationFileGroup * pDict = cfg.dict()->find("TextIcons");
 
228
        if(pDict)
 
229
        {
 
230
                KviConfigurationFileGroupIterator it(*pDict);
 
231
 
 
232
                KviPointerList<QString> names;
 
233
                names.setAutoDelete(true);
 
234
 
 
235
                while(it.current())
 
236
                {
 
237
                        names.append(new QString(it.currentKey()));
 
238
                        ++it;
 
239
                }
 
240
 
 
241
                cfg.setGroup("TextIcons");
 
242
 
 
243
                for(QString * s = names.first(); s; s = names.next())
 
244
                {
 
245
                        int iId = cfg.readIntEntry(*s,-1);
 
246
                        QString szTmp;
 
247
                        QPixmap * pix = 0;
 
248
                        //qDebug("%s %s %i %i",__FILE__,__FUNCTION__,__LINE__,id);
 
249
                        if(iId != -1)
 
250
                        {
 
251
                                pix = g_pIconManager->getSmallIcon(iId);
 
252
                        } else {
 
253
                                szTmp = cfg.readEntry(*s);
 
254
                                pix=g_pIconManager->getPixmap(szTmp);
 
255
                                if(!pix)
 
256
                                {
 
257
                                        iId = KviIconManager::Help;
 
258
                                        pix = g_pIconManager->getSmallIcon(iId);
 
259
                                }
 
260
                        }
 
261
 
 
262
                        if(pix)
 
263
                        {
 
264
                                if(bMerge)
 
265
                                {
 
266
                                        if(!m_pTextIconDict->find(*s))
 
267
                                        {
 
268
                                                if(iId != -1)
 
269
                                                {
 
270
                                                        m_pTextIconDict->replace(*s,new KviTextIcon(g_pIconManager->iconName(iId)));
 
271
                                                } else {
 
272
                                                        m_pTextIconDict->replace(*s,new KviTextIcon(szTmp));
 
273
                                                }
 
274
                                        }
 
275
                                } else {
 
276
                                        if(iId != -1)
 
277
                                        {
 
278
                                                m_pTextIconDict->replace(*s,new KviTextIcon(g_pIconManager->iconName(iId)));
 
279
                                        } else {
 
280
                                                m_pTextIconDict->replace(*s,new KviTextIcon(szTmp));
 
281
                                        }
 
282
                                }
 
283
                        }
 
284
                }
 
285
        }
 
286
 
 
287
        emit changed();
 
288
 
 
289
        return iUpd;
 
290
}
 
291
 
 
292
void KviTextIconManager::save(const QString & szFileName)
 
293
{
 
294
        KviConfigurationFile cfg(szFileName,KviConfigurationFile::Write);
 
295
 
 
296
        cfg.setGroup("Manager");
 
297
        cfg.writeEntry("ConfigUpdate",TEXTICONMANAGER_CURRENT_CONFIG_UPDATE);
 
298
 
 
299
        cfg.setGroup("TextIcons");
 
300
 
 
301
        KviPointerHashTableIterator<QString,KviTextIcon> it(*m_pTextIconDict);
 
302
        while(KviTextIcon * pIcon = it.current())
 
303
        {
 
304
                if(pIcon->id() != -1)
 
305
                        cfg.writeEntry(it.currentKey(),pIcon->id());
 
306
                else
 
307
                        cfg.writeEntry(it.currentKey(),pIcon->filename());
 
308
                ++it;
 
309
        }
 
310
}
 
311
 
 
312
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
 
313
#include "KviTextIconManager.moc"
 
314
#endif //COMPILE_USE_STANDALONE_MOC_SOURCES