34 #include <QDataStream>
36 using namespace KCalCore;
39 static bool checkName(
const QByteArray &name);
41 class CustomProperties::Private
45 QMap<QByteArray, QString> mProperties;
46 QMap<QByteArray, QString> mPropertyParameters;
50 QMap<QByteArray, QString> mVolatileProperties;
53 bool isVolatileProperty(
const QString &name)
const
55 return name.startsWith(
"X-KDE-VOLATILE");
59 bool CustomProperties::Private::operator==(
const CustomProperties::Private &other)
const
61 if (mProperties.count() != other.mProperties.count()) {
64 for (QMap<QByteArray, QString>::ConstIterator it = mProperties.begin();
65 it != mProperties.end(); ++it) {
66 QMap<QByteArray, QString>::ConstIterator itOther =
67 other.mProperties.find(it.key());
68 if (itOther == other.mProperties.end() || itOther.value() != it.value()) {
72 for (QMap<QByteArray, QString>::ConstIterator it = mPropertyParameters.begin();
73 it != mPropertyParameters.end(); ++it) {
74 QMap<QByteArray, QString>::ConstIterator itOther =
75 other.mPropertyParameters.find(it.key());
76 if (itOther == other.mPropertyParameters.end() || itOther.value() != it.value()) {
90 : d(new Private(*cp.d))
112 return *d == *other.d;
116 const QString &value)
118 if (value.isNull() || key.isEmpty() || app.isEmpty()) {
121 QByteArray
property =
"X-KDE-" + app +
'-' + key;
122 if (!checkName(property)) {
127 if (d->isVolatileProperty(property)) {
128 d->mVolatileProperties[property] = value;
130 d->mProperties[property] = value;
148 QByteArray property(
"X-KDE-" + app +
'-' + key);
149 if (!checkName(property)) {
156 const QString ¶meters)
158 if (value.isNull() || !checkName(name)) {
162 d->mProperties[name] = value;
163 d->mPropertyParameters[name] = parameters;
168 if (d->mProperties.contains(name)) {
170 d->mProperties.remove(name);
171 d->mPropertyParameters.remove(name);
173 }
else if (d->mVolatileProperties.contains(name)) {
175 d->mVolatileProperties.remove(name);
182 return d->isVolatileProperty(name) ? d->mVolatileProperties.value(name) : d->mProperties.value(name);
187 return d->mPropertyParameters.value(name);
192 bool changed =
false;
193 for (QMap<QByteArray, QString>::ConstIterator it = properties.begin();
194 it != properties.end(); ++it) {
196 if (checkName(it.key())) {
197 if (d->isVolatileProperty(it.key())) {
198 d->mVolatileProperties[it.key()] = it.value().isNull() ? QString(
"") : it.value();
200 d->mProperties[it.key()] = it.value().isNull() ? QString(
"") : it.value();
215 QMap<QByteArray, QString> result;
216 result.unite(d->mProperties);
217 result.unite(d->mVolatileProperties);
238 bool checkName(
const QByteArray &name)
242 const char *n = name;
243 int len = name.length();
244 if (len < 2 || n[0] !=
'X' || n[1] !=
'-') {
247 for (
int i = 2; i < len; ++i) {
249 if ((ch >=
'A' && ch <=
'Z') ||
250 (ch >=
'a' && ch <=
'z') ||
251 (ch >=
'0' && ch <=
'9') ||
264 return stream << properties.d->mProperties
265 << properties.d->mPropertyParameters;
271 properties.d->mVolatileProperties.clear();
272 return stream >> properties.d->mProperties
273 >> properties.d->mPropertyParameters;