libkcal
customproperties.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "customproperties.h"
00023
00024 #include <kdebug.h>
00025
00026 using namespace KCal;
00027
00028 CustomProperties::CustomProperties()
00029 {
00030 }
00031
00032 CustomProperties::CustomProperties(const CustomProperties &cp)
00033 : mProperties(cp.mProperties)
00034 {
00035 }
00036
00037 CustomProperties::~CustomProperties()
00038 {
00039 }
00040
00041 bool CustomProperties::operator==( const CustomProperties &other ) const
00042 {
00043 if ( mProperties.count() != other.mProperties.count() ) return false;
00044 QMap<QCString, QString>::ConstIterator it;
00045 for( it = mProperties.begin(); it != mProperties.end(); ++it ) {
00046 QMap<QCString, QString>::ConstIterator itOther =
00047 other.mProperties.find( it.key() );
00048
00049 if ( itOther == other.mProperties.end() ) {
00050 return false;
00051 }
00052 if ( itOther.data() != it.data() ) return false;
00053 }
00054
00055 return true;
00056 }
00057
00058 void CustomProperties::setCustomProperty(const QCString &app, const QCString &key,
00059 const QString &value)
00060 {
00061 if (value.isNull() || key.isEmpty() || app.isEmpty())
00062 return;
00063 QCString property = "X-KDE-" + app + "-" + key;
00064 if (!checkName(property))
00065 return;
00066 mProperties[property] = value;
00067 }
00068
00069 void CustomProperties::removeCustomProperty(const QCString &app, const QCString &key)
00070 {
00071 removeNonKDECustomProperty(QCString("X-KDE-" + app + "-" + key));
00072 }
00073
00074 QString CustomProperties::customProperty(const QCString &app, const QCString &key) const
00075 {
00076 return nonKDECustomProperty(QCString("X-KDE-" + app + "-" + key));
00077 }
00078
00079 void CustomProperties::setNonKDECustomProperty(const QCString &name, const QString &value)
00080 {
00081 if (value.isNull() || !checkName(name))
00082 return;
00083 mProperties[name] = value;
00084 }
00085
00086 void CustomProperties::removeNonKDECustomProperty(const QCString &name)
00087 {
00088 QMap<QCString, QString>::Iterator it = mProperties.find(name);
00089 if (it != mProperties.end())
00090 mProperties.remove(it);
00091 }
00092
00093 QString CustomProperties::nonKDECustomProperty(const QCString &name) const
00094 {
00095 QMap<QCString, QString>::ConstIterator it = mProperties.find(name);
00096 if (it == mProperties.end())
00097 return QString::null;
00098 return it.data();
00099 }
00100
00101 void CustomProperties::setCustomProperties(const QMap<QCString, QString> &properties)
00102 {
00103 for (QMap<QCString, QString>::ConstIterator it = properties.begin(); it != properties.end(); ++it) {
00104
00105 if (checkName(it.key())) {
00106 mProperties[it.key()] = it.data().isNull() ? QString("") : it.data();
00107 }
00108 }
00109 }
00110
00111 QMap<QCString, QString> CustomProperties::customProperties() const
00112 {
00113 return mProperties;
00114 }
00115
00116 bool CustomProperties::checkName(const QCString &name)
00117 {
00118
00119
00120 const char* n = name;
00121 int len = name.length();
00122 if (len < 2 || n[0] != 'X' || n[1] != '-')
00123 return false;
00124 for (int i = 2; i < len; ++i) {
00125 char ch = n[i];
00126 if (ch >= 'A' && ch <= 'Z'
00127 || ch >= 'a' && ch <= 'z'
00128 || ch >= '0' && ch <= '9'
00129 || ch == '-')
00130 continue;
00131 return false;
00132 }
00133 return true;
00134 }
|