--- a/src/hbcore/utils/hbsmileytheme.cpp Mon Oct 04 17:49:30 2010 +0300
+++ b/src/hbcore/utils/hbsmileytheme.cpp Mon Oct 18 18:23:13 2010 +0300
@@ -30,6 +30,7 @@
#include <QHash>
#include <QSet>
+
class HbSmileyThemePrivate : public QSharedData
{
public:
@@ -42,6 +43,8 @@
QHash<QString,QSet<QString> > smileyToPatterns;
QHash <QString, QString> patternToSmiley;
+ mutable QRegExp regexp;
+ mutable bool dirty;
};
HbSmileyThemePrivate::HbSmileyThemePrivate()
@@ -50,7 +53,8 @@
HbSmileyThemePrivate::HbSmileyThemePrivate(const HbSmileyThemePrivate &other) : QSharedData(other),
smileyToPatterns(other.smileyToPatterns),
- patternToSmiley(other.patternToSmiley)
+ patternToSmiley(other.patternToSmiley),
+ dirty(true)
{
}
@@ -161,6 +165,9 @@
if (ret) {
*this = tmpTheme;
}
+
+ d->dirty = true;
+
return ret;
}
@@ -193,7 +200,8 @@
patterns << pattern;
d->smileyToPatterns[smiley] = patterns;
d->patternToSmiley[pattern] = smiley;
- }
+ d->dirty = true;
+ }
}
@@ -255,6 +263,7 @@
foreach(QString pattern, tmpPatterns) {
d->patternToSmiley.remove(pattern);
}
+ d->dirty = true;
}
}
@@ -278,6 +287,7 @@
d->smileyToPatterns[smiley] = tmpPatterns;
}
d->patternToSmiley.remove(pattern);
+ d->dirty = true;
}
}
}
@@ -294,7 +304,8 @@
if (!isNull()) {
d.detach();
d->smileyToPatterns.clear();
- d->patternToSmiley.clear();
+ d->patternToSmiley.clear();
+ d->dirty = true;
}
}
@@ -343,6 +354,26 @@
return d->patternToSmiley.keys();
}
+/*!
+* Returns the regular expression for matching the smiley patterns from the theme.
+*
+* \sa patterns()
+*/
+const QRegExp& HbSmileyTheme::regExp() const
+{
+ if (d->dirty) {
+ QString regexpStr;
+ foreach (QString pattern, patterns()) {
+ regexpStr += QRegExp::escape(pattern) + "|";
+ }
+ regexpStr.remove(regexpStr.count()-1, 1);
+
+ d->regexp.setPattern(regexpStr);
+ d->dirty = false;
+ }
+
+ return d->regexp;
+}
/*!
* Returns the smiley theme as a QVariant.