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
126
127
128
129
130
131
132
133
134
135
136
137
|
/***************************************************************************
emoticontheme.h - holds a collection of emoticons
-------------------
begin : Tue April 10 2007
copyright : (C) 2007 by Valerio Pilo
email : valerio@kmess.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef EMOTICONTHEME_H
#define EMOTICONTHEME_H
#include "emoticon.h"
#include <QHash>
/**
* @brief Data class for a group of emoticons
*
* This class represents an emoticon theme, which may be a default emoticon set, or
* a custom emoticon set. It can load, update, and save an emoticon theme.
* Themes are loaded from, and saved to, XML definition files - compatible with other
* clients like Kopete, even non-MSN ones.
*
* @author Michael Curtis, Diederik van der Boor, Valerio Pilo
* @ingroup Root
*/
class EmoticonTheme : public QObject
{
Q_OBJECT
public: // Public methods
// Constructor
EmoticonTheme();
// Copy constructor
EmoticonTheme( const EmoticonTheme &other );
// Destructor
virtual ~EmoticonTheme();
// Create a new emoticon and add it to the theme
void addEmoticon( const QString& pictureFile, const QStringList& shortcuts );
// Check if the theme contains a certain emoticon
bool contains( QString shortcut );
// Returns true if a custom emoticon has already been added
bool emoticonIsAdded( QString dataHash );
// Obtain an emoticon by its shortcut
const Emoticon *getEmoticon( QString shortcut ) const;
// Return the full list of emoticons
const QList<Emoticon*> & getEmoticons() const;
// Return the picture file names of all emoticons, mapped by their first shortcut code
const QHash<QString,QString> &getFileNames() const;
// Return a QHash to map shortcut to data hash
const QHash<QString,QString> &getHashes() const;
// Return the search pattern to find emoticons in an HTML text
const QRegExp &getHtmlPattern() const;
// Return the HTML replacement codes for all emoticons
const QHash<QString,QString> &getHtmlReplacements( bool isSmall = false ) const;
// Return a QStringList of emoticons
const QStringList &getList() const;
// Return the search pattern to find emoticons in a text
const QRegExp &getPattern() const;
// Return one replacement code for the given emoticon
QString getReplacement( const QString &code, bool isSmall = false ) const;
// Return the replacement codes for all emoticons
const QHash<QString,QString> &getReplacements( bool isSmall = false ) const;
// Return where the picture files for this theme are located
const QString &getThemePath();
// Load a theme, by creating it anew or by refreshing the current one
bool loadTheme( QString themeName, bool isCustomTheme );
// Delete a custom emoticon from the theme
bool removeEmoticon( QString shortcut );
// Change the shortcut and the tooltip of a custom emoticon
bool renameEmoticon( QString oldShortcut, QString newShortcut );
// Save the current theme to an XML theme definition file
bool saveTheme();
// Change the theme name
void setThemeName( const QString &newThemeName );
public: // Public static methods
// Return the full path of the first emoticon of the specified theme
static QString getThemeIcon( QString themeDir );
private: // Private methods
// Create the theme from nothing
bool createTheme( const QString& themeDir );
// Rebuild the search&replace caches
void updateCache();
// Update a standard theme with names for the standard MSN emoticons
void updateTitles();
// Update the currently loaded theme with new images
bool updateTheme( const QString& themeDir );
private: // Private properties
QList<Emoticon*> emoticons_;
// Are we loading a theme?
bool loadingTheme_;
// Is this a custom theme?
bool isCustomTheme_;
// The HTML replace codes for emoticons
QHash<QString,QString> largeHtmlReplacements_;
// The replace codes for emoticons
QHash<QString,QString> largeReplacements_;
// The list of emoticon codes
QStringList emoticonList_;
// The search pattern for html emoticon codes
QRegExp patternHtml_;
// The search pattern for text emoticon codes
QRegExp patternText_;
// The HTML replace codes for emoticons
QHash<QString,QString> smallHtmlReplacements_;
// The replace codes for emoticons
QHash<QString,QString> smallReplacements_;
// The hashes for all emoticons
QHash<QString,QString> hashes_;
// The full path to the currently loaded theme
QString themePath_;
// A mapping from code to emoticon picture filename
QHash<QString,QString> themeFileNames_;
signals:
// Signal that we've been changed and the UI needs to be refreshed
void updated();
};
#endif
|