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