summaryrefslogtreecommitdiffabout
path: root/libkcal/customproperties.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkcal/customproperties.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'libkcal/customproperties.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/customproperties.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/libkcal/customproperties.cpp b/libkcal/customproperties.cpp
new file mode 100644
index 0000000..adc1710
--- a/dev/null
+++ b/libkcal/customproperties.cpp
@@ -0,0 +1,114 @@
1/*
2 This file is part of libkcal.
3 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include "customproperties.h"
22
23using namespace KCal;
24
25CustomProperties::CustomProperties()
26{
27}
28
29CustomProperties::CustomProperties(const CustomProperties &cp)
30 : mProperties(cp.mProperties)
31{
32}
33
34CustomProperties::~CustomProperties()
35{
36}
37
38void CustomProperties::setCustomProperty(const QCString &app, const QCString &key,
39 const QString &value)
40{
41 if (value.isNull() || key.isEmpty() || app.isEmpty())
42 return;
43 QCString property = "X-KDE-" + app + "-" + key;
44 if (!checkName(property))
45 return;
46 mProperties[property] = value;
47}
48
49void CustomProperties::removeCustomProperty(const QCString &app, const QCString &key)
50{
51 removeNonKDECustomProperty(QCString("X-KDE-" + app + "-" + key));
52}
53
54QString CustomProperties::customProperty(const QCString &app, const QCString &key) const
55{
56 return nonKDECustomProperty(QCString("X-KDE-" + app + "-" + key));
57}
58
59void CustomProperties::setNonKDECustomProperty(const QCString &name, const QString &value)
60{
61 if (value.isNull() || !checkName(name))
62 return;
63 mProperties[name] = value;
64}
65
66void CustomProperties::removeNonKDECustomProperty(const QCString &name)
67{
68 QMap<QCString, QString>::Iterator it = mProperties.find(name);
69 if (it != mProperties.end())
70 mProperties.remove(it);
71}
72
73QString CustomProperties::nonKDECustomProperty(const QCString &name) const
74{
75 QMap<QCString, QString>::ConstIterator it = mProperties.find(name);
76 if (it == mProperties.end())
77 return QString::null;
78 return it.data();
79}
80
81void CustomProperties::setCustomProperties(const QMap<QCString, QString> &properties)
82{
83 for (QMap<QCString, QString>::ConstIterator it = properties.begin(); it != properties.end(); ++it) {
84 // Validate the property name and convert any null string to empty string
85 if (checkName(it.key())) {
86 mProperties[it.key()] = it.data().isNull() ? QString("") : it.data();
87 }
88 }
89}
90
91QMap<QCString, QString> CustomProperties::customProperties() const
92{
93 return mProperties;
94}
95
96bool CustomProperties::checkName(const QCString &name)
97{
98 // Check that the property name starts with 'X-' and contains
99 // only the permitted characters
100 const char* n = name;
101 int len = name.length();
102 if (len < 2 || n[0] != 'X' || n[1] != '-')
103 return false;
104 for (int i = 2; i < len; ++i) {
105 char ch = n[i];
106 if (ch >= 'A' && ch <= 'Z'
107 || ch >= 'a' && ch <= 'z'
108 || ch >= '0' && ch <= '9'
109 || ch == '-')
110 continue;
111 return false; // invalid character found
112 }
113 return true;
114}