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