libkcal
customproperties.cppGo to the documentation of this file.00001
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 customPropertyUpdated();
00068 }
00069
00070 void CustomProperties::removeCustomProperty(const QCString &app, const QCString &key)
00071 {
00072 removeNonKDECustomProperty(QCString("X-KDE-" + app + "-" + key));
00073 }
00074
00075 QString CustomProperties::customProperty(const QCString &app, const QCString &key) const
00076 {
00077 return nonKDECustomProperty(QCString("X-KDE-" + app + "-" + key));
00078 }
00079
00080 void CustomProperties::setNonKDECustomProperty(const QCString &name, const QString &value)
00081 {
00082 if (value.isNull() || !checkName(name))
00083 return;
00084 mProperties[name] = value;
00085 customPropertyUpdated();
00086 }
00087
00088 void CustomProperties::removeNonKDECustomProperty(const QCString &name)
00089 {
00090 QMap<QCString, QString>::Iterator it = mProperties.find(name);
00091 if (it != mProperties.end()) {
00092 mProperties.remove(it);
00093 customPropertyUpdated();
00094 }
00095 }
00096
00097 QString CustomProperties::nonKDECustomProperty(const QCString &name) const
00098 {
00099 QMap<QCString, QString>::ConstIterator it = mProperties.find(name);
00100 if (it == mProperties.end())
00101 return QString::null;
00102 return it.data();
00103 }
00104
00105 void CustomProperties::setCustomProperties(const QMap<QCString, QString> &properties)
00106 {
00107 bool changed = false;
00108 for (QMap<QCString, QString>::ConstIterator it = properties.begin(); it != properties.end(); ++it) {
00109
00110 if (checkName(it.key())) {
00111 mProperties[it.key()] = it.data().isNull() ? QString("") : it.data();
00112 changed = true;
00113 }
00114 }
00115 if (changed)
00116 customPropertyUpdated();
00117 }
00118
00119 QMap<QCString, QString> CustomProperties::customProperties() const
00120 {
00121 return mProperties;
00122 }
00123
00124 bool CustomProperties::checkName(const QCString &name)
00125 {
00126
00127
00128 const char* n = name;
00129 int len = name.length();
00130 if (len < 2 || n[0] != 'X' || n[1] != '-')
00131 return false;
00132 for (int i = 2; i < len; ++i) {
00133 char ch = n[i];
00134 if (ch >= 'A' && ch <= 'Z'
00135 || ch >= 'a' && ch <= 'z'
00136 || ch >= '0' && ch <= '9'
00137 || ch == '-')
00138 continue;
00139 return false;
00140 }
00141 return true;
00142 }
|