libkcal

customproperties.cpp
1/*
2 This file is part of libkcal.
3
4 Copyright (c) 2002,2006 David Jarvie <software@astrojar.org.uk>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "customproperties.h"
23
24#include <kdebug.h>
25
26using namespace KCal;
27
28CustomProperties::CustomProperties()
29{
30}
31
33 : mProperties(cp.mProperties)
34{
35}
36
37CustomProperties::~CustomProperties()
38{
39}
40
41bool CustomProperties::operator==( const CustomProperties &other ) const
42{
43 if ( mProperties.count() != other.mProperties.count() ) return false;
44 TQMap<TQCString, TQString>::ConstIterator it;
45 for( it = mProperties.begin(); it != mProperties.end(); ++it ) {
46 TQMap<TQCString, TQString>::ConstIterator itOther =
47 other.mProperties.find( it.key() );
48
49 if ( itOther == other.mProperties.end() ) {
50 return false;
51 }
52 if ( itOther.data() != it.data() ) return false;
53 }
54
55 return true;
56}
57
58void CustomProperties::setCustomProperty(const TQCString &app, const TQCString &key,
59 const TQString &value)
60{
61 if (value.isNull() || key.isEmpty() || app.isEmpty())
62 return;
63 TQCString property = "X-TDE-" + app + "-" + key;
64 if (!checkName(property))
65 return;
66 mProperties[property] = value;
68}
69
70void CustomProperties::removeCustomProperty(const TQCString &app, const TQCString &key)
71{
72 removeNonKDECustomProperty(TQCString("X-TDE-" + app + "-" + key));
73}
74
75TQString CustomProperties::customProperty(const TQCString &app, const TQCString &key) const
76{
77 return nonKDECustomProperty(TQCString("X-TDE-" + app + "-" + key));
78}
79
80void CustomProperties::setNonKDECustomProperty(const TQCString &name, const TQString &value)
81{
82 if (value.isNull() || !checkName(name))
83 return;
84 mProperties[name] = value;
86}
87
89{
90 TQMap<TQCString, TQString>::Iterator it = mProperties.find(name);
91 if (it != mProperties.end()) {
92 mProperties.remove(it);
94 }
95}
96
97TQString CustomProperties::nonKDECustomProperty(const TQCString &name) const
98{
99 TQMap<TQCString, TQString>::ConstIterator it = mProperties.find(name);
100 if (it == mProperties.end())
101 return TQString();
102 return it.data();
103}
104
105void CustomProperties::setCustomProperties(const TQMap<TQCString, TQString> &properties)
106{
107 bool changed = false;
108 for (TQMap<TQCString, TQString>::ConstIterator it = properties.begin(); it != properties.end(); ++it) {
109 // Validate the property name and convert any null string to empty string
110 if (checkName(it.key())) {
111 mProperties[it.key()] = it.data().isNull() ? TQString("") : it.data();
112 changed = true;
113 }
114 }
115 if (changed)
117}
118
119TQMap<TQCString, TQString> CustomProperties::customProperties() const
120{
121 return mProperties;
122}
123
124bool CustomProperties::checkName(const TQCString &name)
125{
126 // Check that the property name starts with 'X-' and contains
127 // only the permitted characters
128 const char* n = name;
129 int len = name.length();
130 if (len < 2 || n[0] != 'X' || n[1] != '-')
131 return false;
132 for (int i = 2; i < len; ++i) {
133 char ch = n[i];
134 if (ch >= 'A' && ch <= 'Z'
135 || ch >= 'a' && ch <= 'z'
136 || ch >= '0' && ch <= '9'
137 || ch == '-')
138 continue;
139 return false; // invalid character found
140 }
141 return true;
142}
This class represents custom calendar properties.
void setCustomProperties(const TQMap< TQCString, TQString > &properties)
Initialise the alarm's custom calendar properties to the specified key/value pairs.
void setNonKDECustomProperty(const TQCString &name, const TQString &value)
Create or modify a non-KDE or non-standard custom calendar property.
TQMap< TQCString, TQString > customProperties() const
Return all custom calendar property key/value pairs.
void removeNonKDECustomProperty(const TQCString &name)
Delete a non-KDE or non-standard custom calendar property.
void setCustomProperty(const TQCString &app, const TQCString &key, const TQString &value)
Create or modify a custom calendar property.
virtual void customPropertyUpdated()
Called when a custom property has been changed.
CustomProperties()
Construct a new empty custom properties instance.
TQString customProperty(const TQCString &app, const TQCString &key) const
Return the value of a custom calendar property.
void removeCustomProperty(const TQCString &app, const TQCString &key)
Delete a custom calendar property.
TQString nonKDECustomProperty(const TQCString &name) const
Return the value of a non-KDE or non-standard custom calendar property.
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38