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;
49 bool CustomProperties::Private::operator==(
const CustomProperties::Private &other )
const
51 if ( mProperties.count() != other.mProperties.count() ) {
54 for ( QMap<QByteArray, QString>::ConstIterator it = mProperties.begin();
55 it != mProperties.end(); ++it ) {
56 QMap<QByteArray, QString>::ConstIterator itOther =
57 other.mProperties.find( it.key() );
58 if ( itOther == other.mProperties.end() || itOther.value() != it.value() ) {
62 for ( QMap<QByteArray, QString>::ConstIterator it = mPropertyParameters.begin();
63 it != mPropertyParameters.end(); ++it ) {
64 QMap<QByteArray, QString>::ConstIterator itOther =
65 other.mPropertyParameters.find( it.key() );
66 if ( itOther == other.mPropertyParameters.end() || itOther.value() != it.value() ) {
80 : d( new Private( *cp.d ) )
87 if ( &other ==
this ) {
102 return *d == *other.d;
106 const QString &value )
108 if ( value.isNull() || key.isEmpty() || app.isEmpty() ) {
111 QByteArray
property =
"X-KDE-" + app +
'-' + key;
112 if ( !checkName( property ) ) {
116 d->mProperties[property] = value;
132 QByteArray property(
"X-KDE-" + app +
'-' + key );
133 if ( !checkName( property ) ) {
140 const QString ¶meters )
142 if ( value.isNull() || !checkName( name ) ) {
146 d->mProperties[name] = value;
147 d->mPropertyParameters[name] = parameters;
152 if ( d->mProperties.contains( name ) ) {
154 d->mProperties.remove( name );
155 d->mPropertyParameters.remove( name );
162 return d->mProperties.value( name );
167 return d->mPropertyParameters.value( name );
172 bool changed =
false;
173 for ( QMap<QByteArray, QString>::ConstIterator it = properties.begin();
174 it != properties.end(); ++it ) {
176 if ( checkName( it.key() ) ) {
177 d->mProperties[it.key()] = it.value().isNull() ? QString(
"" ) : it.value();
191 return d->mProperties;
210 bool checkName(
const QByteArray &name )
214 const char *n = name;
215 int len = name.length();
216 if ( len < 2 || n[0] !=
'X' || n[1] !=
'-' ) {
219 for (
int i = 2; i < len; ++i ) {
221 if ( ( ch >=
'A' && ch <=
'Z' ) ||
222 ( ch >=
'a' && ch <=
'z' ) ||
223 ( ch >=
'0' && ch <=
'9' ) ||
236 return stream << properties.d->mProperties
237 << properties.d->mPropertyParameters;
243 return stream >> properties.d->mProperties
244 >> properties.d->mPropertyParameters;