summaryrefslogtreecommitdiffabout
path: root/kabc/address.cpp
Unidiff
Diffstat (limited to 'kabc/address.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index 5ffe511..6151f9e 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -8,192 +8,219 @@
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/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28//US added kglobal.h 28//US added kglobal.h
29#include <kglobal.h> 29#include <kglobal.h>
30 30
31#include <kapplication.h> 31#include <kapplication.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <ksimpleconfig.h> 34#include <ksimpleconfig.h>
35#include <kstandarddirs.h> 35#include <kstandarddirs.h>
36 36
37#include <qfile.h> 37#include <qfile.h>
38 38
39#include "address.h" 39#include "address.h"
40 40
41using namespace KABC; 41using namespace KABC;
42 42
43QMap<QString, QString> Address::mISOMap; 43QMap<QString, QString> Address::mISOMap;
44 44
45Address::Address() : 45Address::Address() :
46 mEmpty( true ), mType( 0 ) 46 mEmpty( true ), mType( 0 )
47{ 47{
48 mId = KApplication::randomString( 10 ); 48 mId = KApplication::randomString( 10 );
49} 49}
50 50
51Address::Address( int type ) : 51Address::Address( int type ) :
52 mEmpty( true ), mType( type ) 52 mEmpty( true ), mType( type )
53{ 53{
54 mId = KApplication::randomString( 10 ); 54 mId = KApplication::randomString( 10 );
55} 55}
56 56
57bool Address::operator==( const Address &a ) const 57bool Address::operator==( const Address &a ) const
58{ 58{
59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false; 59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false;
60 if ( mExtended != a.mExtended ) return false; 60 if ( mExtended != a.mExtended ) return false;
61 if ( mStreet != a.mStreet ) return false; 61 if ( mStreet != a.mStreet ) return false;
62 if ( mLocality != a.mLocality ) return false; 62 if ( mLocality != a.mLocality ) return false;
63 if ( mRegion != a.mRegion ) return false; 63 if ( mRegion != a.mRegion ) return false;
64 if ( mPostalCode != a.mPostalCode ) return false; 64 if ( mPostalCode != a.mPostalCode ) return false;
65 if ( mCountry != a.mCountry ) return false; 65 if ( mCountry != a.mCountry ) return false;
66 if ( mLabel != a.mLabel ) return false; 66 if ( mLabel != a.mLabel ) return false;
67 67
68 return true; 68 return true;
69} 69}
70 70
71bool Address::operator!=( const Address &a ) const 71bool Address::operator!=( const Address &a ) const
72{ 72{
73 return !( a == *this ); 73 return !( a == *this );
74} 74}
75 75
76bool Address::isEmpty() const 76bool Address::isEmpty() const
77{ 77{
78 if ( mPostOfficeBox.isEmpty() && 78 if ( mPostOfficeBox.isEmpty() &&
79 mExtended.isEmpty() && 79 mExtended.isEmpty() &&
80 mStreet.isEmpty() && 80 mStreet.isEmpty() &&
81 mLocality.isEmpty() && 81 mLocality.isEmpty() &&
82 mRegion.isEmpty() && 82 mRegion.isEmpty() &&
83 mPostalCode.isEmpty() && 83 mPostalCode.isEmpty() &&
84 mCountry.isEmpty() && 84 mCountry.isEmpty() &&
85 mLabel.isEmpty() ) { 85 mLabel.isEmpty() ) {
86 return true; 86 return true;
87 } 87 }
88 return false; 88 return false;
89} 89}
90 90
91QStringList Address::asList() 91QStringList Address::asList()
92{ 92{
93 QStringList result; 93 QStringList result;
94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox); 94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox);
95 if ( ! mExtended.isEmpty())result.append(mExtended); 95 if ( ! mExtended.isEmpty())result.append(mExtended);
96 if ( ! mStreet.isEmpty())result.append(mStreet); 96 if ( ! mStreet.isEmpty())result.append(mStreet);
97 if ( ! mLocality.isEmpty() )result.append(mLocality); 97 if ( ! mLocality.isEmpty() )result.append(mLocality);
98 if ( ! mRegion.isEmpty())result.append(mRegion); 98 if ( ! mRegion.isEmpty())result.append(mRegion);
99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode); 99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode);
100 if ( ! mCountry.isEmpty())result.append(mCountry); 100 if ( ! mCountry.isEmpty())result.append(mCountry);
101 if ( ! mLabel.isEmpty() )result.append(mLabel); 101 if ( ! mLabel.isEmpty() )result.append(mLabel);
102 return result; 102 return result;
103} 103}
104
105bool Address::matchAddress( QRegExp* re ) const
106{
107
108#if QT_VERSION >= 0x030000
109 if (re->search( mPostOfficeBox ) == 0) return true;
110 if (re->search( mExtended ) == 0) return true;
111 if (re->search( mStreet ) == 0) return true;
112 if (re->search( mLocality ) == 0) return true;
113 if (re->search( mRegion ) == 0) return true;
114 if (re->search( mPostalCode ) == 0) return true;
115 if (re->search( mCountry ) == 0) return true;
116 if (re->search( mLabel ) == 0) return true;
117#else
118 if (re->match( mPostOfficeBox ) == 0) return true;
119 if (re->match( mExtended ) == 0) return true;
120 if (re->match( mStreet ) == 0) return true;
121 if (re->match( mLocality ) == 0) return true;
122 if (re->match( mRegion ) == 0) return true;
123 if (re->match( mPostalCode ) == 0) return true;
124 if (re->match( mCountry ) == 0) return true;
125 if (re->match( mLabel ) == 0) return true;
126#endif
127
128 return false;
129}
130
104void Address::clear() 131void Address::clear()
105{ 132{
106 *this = Address(); 133 *this = Address();
107} 134}
108 135
109void Address::setId( const QString &id ) 136void Address::setId( const QString &id )
110{ 137{
111 mEmpty = false; 138 mEmpty = false;
112 139
113 mId = id; 140 mId = id;
114} 141}
115 142
116QString Address::id() const 143QString Address::id() const
117{ 144{
118 return mId; 145 return mId;
119} 146}
120 147
121void Address::setType( int type ) 148void Address::setType( int type )
122{ 149{
123 mEmpty = false; 150 mEmpty = false;
124 151
125 mType = type; 152 mType = type;
126} 153}
127 154
128int Address::type() const 155int Address::type() const
129{ 156{
130 return mType; 157 return mType;
131} 158}
132 159
133QString Address::typeLabel() const 160QString Address::typeLabel() const
134{ 161{
135 QString label; 162 QString label;
136 bool first = true; 163 bool first = true;
137 164
138 TypeList list = typeList(); 165 TypeList list = typeList();
139 166
140 TypeList::Iterator it; 167 TypeList::Iterator it;
141 for ( it = list.begin(); it != list.end(); ++it ) { 168 for ( it = list.begin(); it != list.end(); ++it ) {
142 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 169 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
143 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 170 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
144 if ( first ) 171 if ( first )
145 first = false; 172 first = false;
146 } 173 }
147 } 174 }
148 175
149 return label; 176 return label;
150} 177}
151 178
152void Address::setPostOfficeBox( const QString &s ) 179void Address::setPostOfficeBox( const QString &s )
153{ 180{
154 mEmpty = false; 181 mEmpty = false;
155 182
156 mPostOfficeBox = s; 183 mPostOfficeBox = s;
157} 184}
158 185
159QString Address::postOfficeBox() const 186QString Address::postOfficeBox() const
160{ 187{
161 return mPostOfficeBox; 188 return mPostOfficeBox;
162} 189}
163 190
164QString Address::postOfficeBoxLabel() 191QString Address::postOfficeBoxLabel()
165{ 192{
166 return i18n("Post Office Box"); 193 return i18n("Post Office Box");
167} 194}
168 195
169 196
170void Address::setExtended( const QString &s ) 197void Address::setExtended( const QString &s )
171{ 198{
172 mEmpty = false; 199 mEmpty = false;
173 200
174 mExtended = s; 201 mExtended = s;
175} 202}
176 203
177QString Address::extended() const 204QString Address::extended() const
178{ 205{
179 return mExtended; 206 return mExtended;
180} 207}
181 208
182QString Address::extendedLabel() 209QString Address::extendedLabel()
183{ 210{
184 return i18n("Extended Address Information"); 211 return i18n("Extended Address Information");
185} 212}
186 213
187 214
188void Address::setStreet( const QString &s ) 215void Address::setStreet( const QString &s )
189{ 216{
190 mEmpty = false; 217 mEmpty = false;
191 218
192 mStreet = s; 219 mStreet = s;
193} 220}
194 221
195QString Address::street() const 222QString Address::street() const
196{ 223{
197 return mStreet; 224 return mStreet;
198} 225}
199 226