21#include <QtCore/QFile>
22#include <QtCore/QFileInfo>
23#include <QtGui/QImageReader>
40 QString emoticon = QFileInfo(
emoticonsMap().key(emo.split(
' '))).fileName();
41 QDomElement fce = m_themeXml.firstChildElement(
"plist").firstChildElement(
"dict").firstChildElement(
"dict");
47 QDomNodeList nl = fce.childNodes();
48 for (uint i = 0; i < nl.length(); i++) {
49 QDomElement de = nl.item(i).toElement();
50 if (!de.isNull() && de.tagName() ==
"key" && (de.text() == emoticon)) {
51 QDomElement dict = de.nextSiblingElement();
52 if (!dict.isNull() && dict.tagName() ==
"dict") {
53 fce.removeChild(dict);
69 const QStringList splitted = text.split(
' ');
70 QDomElement fce = m_themeXml.firstChildElement(
"plist").firstChildElement(
"dict").firstChildElement(
"dict");
76 QDomElement emoticon = m_themeXml.createElement(
"key");
77 emoticon.appendChild(m_themeXml.createTextNode(QFileInfo(emo).
fileName()));
78 fce.appendChild(emoticon);
80 QDomElement dict = m_themeXml.createElement(
"dict");
81 QDomElement el = m_themeXml.createElement(
"key");
82 el.appendChild(m_themeXml.createTextNode(
"Equivalents"));
85 QDomElement arr = m_themeXml.createElement(
"array");
87 QStringList::const_iterator constIterator;
88 for (constIterator = splitted.begin(); constIterator != splitted.end(); ++constIterator) {
89 QDomElement emoText = m_themeXml.createElement(
"string");
90 QDomText txt = m_themeXml.createTextNode((*constIterator).trimmed());
91 emoText.appendChild(txt);
92 arr.appendChild(emoText);
95 dict.appendChild(arr);
97 el = m_themeXml.createElement(
"key");
98 el.appendChild(m_themeXml.createTextNode(
"Name"));
101 el = m_themeXml.createElement(
"string");
102 el.appendChild(m_themeXml.createTextNode(QFileInfo(emo).baseName()));
103 dict.appendChild(el);
105 fce.appendChild(dict);
117 kWarning() <<
fp.fileName() <<
"doesn't exist!";
121 if (!
fp.open(QIODevice::WriteOnly)) {
122 kWarning() <<
fp.fileName() <<
"can't open WriteOnly!";
126 QTextStream emoStream(&
fp);
127 emoStream.setCodec(
"UTF-8" );
128 emoStream << m_themeXml.toString(4);
139 kWarning() << path <<
"doesn't exist!";
143 if (!
fp.open(QIODevice::ReadOnly)) {
144 kWarning() <<
fp.fileName() <<
"can't open ReadOnly!";
150 if (!m_themeXml.setContent(&
fp, &error, &eli, &eco)) {
151 kWarning() <<
fp.fileName() <<
"can't copy to xml!";
152 kWarning() << error <<
"line:" << eli <<
"column:" << eco;
159 QDomElement fce = m_themeXml.firstChildElement(
"plist").firstChildElement(
"dict").firstChildElement(
"dict");
165 QDomNodeList nl = fce.childNodes();
169 for (uint i = 0; i < nl.length(); i++) {
170 QDomElement de = nl.item(i).toElement();
172 if (!de.isNull() && de.tagName() ==
"key") {
175 }
else if (!de.isNull() && de.tagName() ==
"dict") {
176 QDomElement arr = de.firstChildElement(
"array");
177 QDomNodeList snl = arr.childNodes();
180 for (uint k = 0; k < snl.length(); k++) {
181 QDomElement sde = snl.item(k).toElement();
183 if (!sde.isNull() && sde.tagName() ==
"string") {
187 if (!name.isEmpty()) {
202 QFile
fp(path +
'/' +
"Emoticons.plist");
204 if (!
fp.open(QIODevice::WriteOnly)) {
205 kWarning() <<
fp.fileName() <<
"can't open WriteOnly!";
209 QDomDocumentType ty = QDomImplementation().createDocumentType(
"plist",
"-//Apple Computer//DTD PLIST 1.0//EN",
"http://www.apple.com/DTDs/PropertyList-1.0.dtd");
210 QDomDocument doc(ty);
211 doc.appendChild(doc.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\""));
213 QDomElement plist = doc.createElement(
"plist");
214 plist.setAttribute(
"version",
"1.0");
215 doc.appendChild(plist);
217 QDomElement dict = doc.createElement(
"dict");
218 plist.appendChild(dict);
220 QDomElement el = doc.createElement(
"key");
221 el.appendChild(doc.createTextNode(
"AdiumSetVersion"));
222 dict.appendChild(el);
224 el = doc.createElement(
"integer");
225 el.appendChild(doc.createTextNode(
"1"));
226 dict.appendChild(el);
228 el = doc.createElement(
"key");
229 el.appendChild(doc.createTextNode(
"Emoticons"));
230 dict.appendChild(el);
232 dict.appendChild(doc.createElement(
"dict"));
235 QTextStream emoStream(&
fp);
236 emoStream.setCodec(
"UTF-8" );
237 emoStream << doc.toString(4);
void createNew()
Create a new theme.
bool removeEmoticon(const QString &emo)
Remove the emoticon emo, this will not delete the image file too.
AdiumEmoticons(QObject *parent, const QVariantList &args)
void save()
Save the emoticon theme.
bool addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option=DoNotCopy)
Add the emoticon emo with text text.
bool loadTheme(const QString &path)
Load the theme inside the directory path.
AddEmoticonOption
Options to pass to addEmoticon.
QString themePath() const
Returns the theme path.
void addEmoticonsMap(QString key, QStringList value)
Insert a new item in the emoticons map.
void addEmoticonIndex(const QString &path, const QStringList &emoList)
Add an emoticon to the index.
QString fileName() const
Returns the file name of the theme.
QString themeName() const
Returns the theme name.
void removeEmoticonIndex(const QString &path, const QStringList &emoList)
Remove an emoticon from the index.
virtual bool addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option=DoNotCopy)
Add the emoticon emo with text text.
void removeEmoticonsMap(QString key)
Remove an item from the emoticons map.
KEmoticonsProvider(QObject *parent=0)
Default constructor.
QHash< QString, QStringList > emoticonsMap() const
Returns a QHash that contains the emoticons path as keys and the text as values.
void clearEmoticonsMap()
Clears the emoticons map.
virtual bool loadTheme(const QString &path)
Load the theme inside the directory path.
#define K_EXPORT_PLUGIN(factory)
QString saveLocation(const char *type, const QString &suffix=QString(), bool create=true) const
QString findResource(const char *type, const QString &filename) const
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
K_PLUGIN_FACTORY(ProxyScoutFactory, registerPlugin< KPAC::ProxyScout >();) namespace KPAC