libkcal Library API Documentation

customproperties.cpp

00001 /*
00002     This file is part of libkcal.
00003     Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
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     // Validate the property name and convert any null string to empty string
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   // Check that the property name starts with 'X-' and contains
00099   // only the permitted characters
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;   // invalid character found
00112   }
00113   return true;
00114 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:21 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003