QIcon CSmileyPack::getAsIcon(const QString &key) { QPixmap pm; pm.loadFromData(getCachedSmiley(key), "PNG"); return QIcon(pm); }
bool SmileyPack::load(const QString& filename) { // discard old data filenameTable.clear(); iconCache.clear(); emoticons.clear(); path.clear(); // open emoticons.xml QFile xmlFile(filename); if (!xmlFile.open(QIODevice::ReadOnly)) return false; // cannot open file /* parse the cfg file * sample: * <?xml version='1.0'?> * <messaging-emoticon-map> * <emoticon file="smile.png" > * <string>:)</string> * <string>:-)</string> * </emoticon> * <emoticon file="sad.png" > * <string>:(</string> * <string>:-(</string> * </emoticon> * </messaging-emoticon-map> */ path = QFileInfo(filename).absolutePath(); QDomDocument doc; doc.setContent(xmlFile.readAll()); QDomNodeList emoticonElements = doc.elementsByTagName("emoticon"); for (int i = 0; i < emoticonElements.size(); ++i) { QString file = emoticonElements.at(i).attributes().namedItem("file").nodeValue(); QDomElement stringElement = emoticonElements.at(i).firstChildElement("string"); QStringList emoticonSet; // { ":)", ":-)" } etc. while (!stringElement.isNull()) { QString emoticon = stringElement.text() .replace("<","<").replace(">",">"); filenameTable.insert(emoticon, file); cacheSmiley(file); // preload all smileys if (!getCachedSmiley(emoticon).isNull()) emoticonSet.push_back(emoticon); stringElement = stringElement.nextSibling().toElement(); } if (emoticonSet.size() > 0) emoticons.push_back(emoticonSet); } // success! return true; }
QIcon SmileyPack::getAsIcon(const QString &key) { return getCachedSmiley(key); }
QIcon SmileyPack::getAsIcon(const QString &key) { QMutexLocker locker(&loadingMutex); return getCachedSmiley(key); }
QString CSmileyPack::getAsRichText(const QString &key) { return "<img src=\"data:image/png;base64," % QString(getCachedSmiley(key).toBase64()) % "\">"; }