summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-30 10:41:33 (UTC)
committer zautrix <zautrix>2005-03-30 10:41:33 (UTC)
commit597cad3a63e6c22855704bf8435db70e3c2b184f (patch) (unidiff)
treef7093b331be9a52a07d01a6f2f5c1f26daf42d50
parent889d2102fcfe2fb0786b3f8f406dc32b42e38c7a (diff)
downloadkdepimpi-597cad3a63e6c22855704bf8435db70e3c2b184f.zip
kdepimpi-597cad3a63e6c22855704bf8435db70e3c2b184f.tar.gz
kdepimpi-597cad3a63e6c22855704bf8435db70e3c2b184f.tar.bz2
fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp3
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp2
-rw-r--r--microkde/kdecore/kstandarddirs.cpp10
3 files changed, 13 insertions, 2 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 18b4d58..39d14bb 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,2196 +1,2197 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 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 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46static bool matchBinaryPatternA( int value, int pattern ); 46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern ); 47static bool matchBinaryPatternP( int value, int pattern );
48 48
49struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
50{ 50{
51 QString uid; 51 QString uid;
52 QString name; 52 QString name;
53 QString formattedName; 53 QString formattedName;
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1; 91 bool tagged :1;
92}; 92};
93 93
94Addressee::Addressee() 94Addressee::Addressee()
95{ 95{
96 mData = new AddresseeData; 96 mData = new AddresseeData;
97 mData->empty = true; 97 mData->empty = true;
98 mData->changed = false; 98 mData->changed = false;
99 mData->resource = 0; 99 mData->resource = 0;
100 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
101 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
103} 103}
104 104
105Addressee::~Addressee() 105Addressee::~Addressee()
106{ 106{
107} 107}
108 108
109Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
110{ 110{
111 mData = a.mData; 111 mData = a.mData;
112} 112}
113 113
114Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
115{ 115{
116 mData = a.mData; 116 mData = a.mData;
117 return (*this); 117 return (*this);
118} 118}
119 119
120Addressee Addressee::copy() 120Addressee Addressee::copy()
121{ 121{
122 Addressee a; 122 Addressee a;
123 *(a.mData) = *mData; 123 *(a.mData) = *mData;
124 return a; 124 return a;
125} 125}
126 126
127void Addressee::detach() 127void Addressee::detach()
128{ 128{
129 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
130 *this = copy(); 130 *this = copy();
131} 131}
132 132
133bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
134{ 134{
135 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
136 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
137 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
138 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
139 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
140 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
141 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
142 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
143 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
144 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
145 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
146 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
147 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
148 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
149 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
150 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
151 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
152 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
153 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
154 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
155 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
156 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
157 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
158 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
159 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
161 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
163 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
164 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
165 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
166 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
167 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
168 168
169 return true; 169 return true;
170} 170}
171 171
172bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
173{ 173{
174 return !( a == *this ); 174 return !( a == *this );
175} 175}
176 176
177bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
178{ 178{
179 return mData->empty; 179 return mData->empty;
180} 180}
181ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
182{ 182{
183 int max = attList.count(); 183 int max = attList.count();
184 ulong cSum = 0; 184 ulong cSum = 0;
185 int j,k,i; 185 int j,k,i;
186 int add; 186 int add;
187 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
188 QString s = attList[i]; 188 QString s = attList[i];
189 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
190 j = s.length(); 190 j = s.length();
191 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
192 int mul = k +1; 192 int mul = k +1;
193 add = s[k].unicode (); 193 add = s[k].unicode ();
194 if ( k < 16 ) 194 if ( k < 16 )
195 mul = mul * mul; 195 mul = mul * mul;
196 int ii = i+1; 196 int ii = i+1;
197 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
198 cSum += add; 198 cSum += add;
199 //qDebug("csum: %d %d %d", i,k,cSum); 199 //qDebug("csum: %d %d %d", i,k,cSum);
200 } 200 }
201 } 201 }
202 202
203 } 203 }
204 //QString dump = attList.join(","); 204 //QString dump = attList.join(",");
205 //qDebug("csum: %d %s", cSum,dump.latin1()); 205 //qDebug("csum: %d %s", cSum,dump.latin1());
206 206
207 return cSum; 207 return cSum;
208 208
209} 209}
210void Addressee::computeCsum(const QString &dev) 210void Addressee::computeCsum(const QString &dev)
211{ 211{
212 QStringList l; 212 QStringList l;
213 //if ( !mData->name.isEmpty() ) l.append(mData->name); 213 //if ( !mData->name.isEmpty() ) l.append(mData->name);
214 //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 214 //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
215 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 215 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
216 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 216 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
217 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); 217 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName );
218 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 218 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
219 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 219 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
220 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 220 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
221 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 221 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
222 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 222 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
223 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 223 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
224 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 224 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
225 if ( !mData->title .isEmpty() ) l.append( mData->title ); 225 if ( !mData->title .isEmpty() ) l.append( mData->title );
226 if ( !mData->role.isEmpty() ) l.append( mData->role ); 226 if ( !mData->role.isEmpty() ) l.append( mData->role );
227 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 227 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
228 if ( !mData->note.isEmpty() ) l.append( mData->note ); 228 if ( !mData->note.isEmpty() ) l.append( mData->note );
229 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 229 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
230 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 230 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
231 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 231 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
232 if ( !mData->logo.undefined() ) { 232 if ( !mData->logo.undefined() ) {
233 if ( !mData->logo.isIntern() ) 233 if ( !mData->logo.isIntern() )
234 l.append( mData->logo.url() ); 234 l.append( mData->logo.url() );
235 else 235 else
236 l.append( QString::number(mData->logo.data().width()* mData->logo.data().height())); 236 l.append( QString::number(mData->logo.data().width()* mData->logo.data().height()));
237 } else { 237 } else {
238 l.append( "nologo"); 238 l.append( "nologo");
239 } 239 }
240 if ( !mData->photo.undefined() ) { 240 if ( !mData->photo.undefined() ) {
241 if ( !mData->photo.isIntern() ) 241 if ( !mData->photo.isIntern() )
242 l.append( mData->photo.url() ); 242 l.append( mData->photo.url() );
243 else 243 else
244 l.append( QString::number(mData->photo.data().width()* mData->photo.data().height())); 244 l.append( QString::number(mData->photo.data().width()* mData->photo.data().height()));
245 } else { 245 } else {
246 l.append( "nophoto"); 246 l.append( "nophoto");
247 } 247 }
248#if 0 248#if 0
249 if ( !mData->sound.undefined() ) { 249 if ( !mData->sound.undefined() ) {
250 if ( !mData->sound.isIntern() ) 250 if ( !mData->sound.isIntern() )
251 l.append( mData->sound.url() ); 251 l.append( mData->sound.url() );
252 else 252 else
253 l.append( QString(mData->sound.data().with()* mData->sound.data().height())); 253 l.append( QString(mData->sound.data().with()* mData->sound.data().height()));
254 } else { 254 } else {
255 l.append( "nosound"); 255 l.append( "nosound");
256 } 256 }
257#endif 257#endif
258 //if ( !mData->agent.isEmpty() ) l.append( ); 258 //if ( !mData->agent.isEmpty() ) l.append( );
259 if ( mData->url.isValid() ) 259 if ( mData->url.isValid() )
260 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 260 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
261 KABC::PhoneNumber::List phoneNumbers; 261 KABC::PhoneNumber::List phoneNumbers;
262 KABC::PhoneNumber::List::Iterator phoneIter; 262 KABC::PhoneNumber::List::Iterator phoneIter;
263 263
264 QStringList t; 264 QStringList t;
265 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 265 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
266 ++phoneIter ) 266 ++phoneIter )
267 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 267 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
268 t.sort(); 268 t.sort();
269 uint iii; 269 uint iii;
270 for ( iii = 0; iii < t.count(); ++iii) 270 for ( iii = 0; iii < t.count(); ++iii)
271 l.append( t[iii] ); 271 l.append( t[iii] );
272 t = mData->emails; 272 t = mData->emails;
273 t.sort(); 273 t.sort();
274 for ( iii = 0; iii < t.count(); ++iii) 274 for ( iii = 0; iii < t.count(); ++iii)
275 l.append( t[iii] ); 275 l.append( t[iii] );
276 t = mData->categories; 276 t = mData->categories;
277 t.sort(); 277 t.sort();
278 for ( iii = 0; iii < t.count(); ++iii) 278 for ( iii = 0; iii < t.count(); ++iii)
279 l.append( t[iii] ); 279 l.append( t[iii] );
280 t = mData->custom; 280 t = mData->custom;
281 t.sort(); 281 t.sort();
282 for ( iii = 0; iii < t.count(); ++iii) 282 for ( iii = 0; iii < t.count(); ++iii)
283 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { 283 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) {
284 int find = t[iii].find (':')+1; 284 int find = t[iii].find (':')+1;
285 //qDebug("lennnn %d %d ", find, t[iii].length()); 285 //qDebug("lennnn %d %d ", find, t[iii].length());
286 if ( find < t[iii].length()) 286 if ( find < t[iii].length())
287 l.append( t[iii] ); 287 l.append( t[iii] );
288 288
289 } 289 }
290 KABC::Address::List::Iterator addressIter; 290 KABC::Address::List::Iterator addressIter;
291 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 291 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
292 ++addressIter ) { 292 ++addressIter ) {
293 t = (*addressIter).asList(); 293 t = (*addressIter).asList();
294 t.sort(); 294 t.sort();
295 for ( iii = 0; iii < t.count(); ++iii) 295 for ( iii = 0; iii < t.count(); ++iii)
296 l.append( t[iii] ); 296 l.append( t[iii] );
297 } 297 }
298 uint cs = getCsum4List(l); 298 uint cs = getCsum4List(l);
299 299
300#if 0 300#if 0
301 for ( iii = 0; iii < l.count(); ++iii) 301 for ( iii = 0; iii < l.count(); ++iii)
302 qDebug("%d***%s***",iii,l[iii].latin1()); 302 qDebug("%d***%s***",iii,l[iii].latin1());
303 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 303 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
304#endif 304#endif
305 305
306 306
307 setCsum( dev, QString::number (cs )); 307 setCsum( dev, QString::number (cs ));
308} 308}
309 309
310void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 310void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
311{ 311{
312 // merge all standard non-outlook fields. 312 // merge all standard non-outlook fields.
313 //if isSubSet (e.g. mobile phone sync) merge all fields 313 //if isSubSet (e.g. mobile phone sync) merge all fields
314 314
315 detach(); 315 detach();
316 if ( isSubSet ) { 316 if ( isSubSet ) {
317 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 317 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
318 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 318 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
319 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 319 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
320 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 320 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
321 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 321 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
322 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 322 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
323 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 323 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
324 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 324 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
325 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 325 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
326 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 326 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
327 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 327 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
328 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 328 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
329 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 329 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
330 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 330 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
331 if ( !mData->birthday.isValid() ) 331 if ( !mData->birthday.isValid() )
332 if ( ad.mData->birthday.isValid()) 332 if ( ad.mData->birthday.isValid())
333 mData->birthday = ad.mData->birthday; 333 mData->birthday = ad.mData->birthday;
334 334
335 } 335 }
336 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 336 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
337 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 337 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
338 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 338 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
339 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 339 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
340 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 340 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
341 QStringList t; 341 QStringList t;
342 QStringList tAD; 342 QStringList tAD;
343 uint iii; 343 uint iii;
344 344
345 // ********** phone numbers 345 // ********** phone numbers
346 if ( isSubSet ) { 346 if ( isSubSet ) {
347 PhoneNumber::List phoneAD = ad.phoneNumbers(); 347 PhoneNumber::List phoneAD = ad.phoneNumbers();
348 PhoneNumber::List::Iterator phoneItAD; 348 PhoneNumber::List::Iterator phoneItAD;
349 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 349 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
350 bool found = false; 350 bool found = false;
351 PhoneNumber::List::Iterator it; 351 PhoneNumber::List::Iterator it;
352 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 352 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
353 if ( ( *phoneItAD ).contains( (*it) ) ) { 353 if ( ( *phoneItAD ).contains( (*it) ) ) {
354 found = true; 354 found = true;
355 (*it).setType( ( *phoneItAD ).type() ); 355 (*it).setType( ( *phoneItAD ).type() );
356 (*it).setNumber( ( *phoneItAD ).number() ); 356 (*it).setNumber( ( *phoneItAD ).number() );
357 break; 357 break;
358 } 358 }
359 } 359 }
360 // if ( isSubSet && ! found ) 360 // if ( isSubSet && ! found )
361 if ( ! found ) // LR try this one... 361 if ( ! found ) // LR try this one...
362 mData->phoneNumbers.append( *phoneItAD ); 362 mData->phoneNumbers.append( *phoneItAD );
363 } 363 }
364 } else { 364 } else {
365 PhoneNumber::List phoneAD = ad.phoneNumbers(); 365 PhoneNumber::List phoneAD = ad.phoneNumbers();
366 PhoneNumber::List::Iterator phoneItAD; 366 PhoneNumber::List::Iterator phoneItAD;
367 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 367 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
368 bool found = false; 368 bool found = false;
369 PhoneNumber::List::Iterator it; 369 PhoneNumber::List::Iterator it;
370 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 370 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
371 if ( ( *phoneItAD ).contains( (*it) ) ) { 371 if ( ( *phoneItAD ).contains( (*it) ) ) {
372 found = true; 372 found = true;
373 (*it).setType( ( *phoneItAD ).type() ); 373 (*it).setType( ( *phoneItAD ).type() );
374 (*it).setNumber( ( *phoneItAD ).number() ); 374 (*it).setNumber( ( *phoneItAD ).number() );
375 break; 375 break;
376 } 376 }
377 } 377 }
378 if ( ! found ) { // append numbers which do not have work or home type 378 if ( ! found ) { // append numbers which do not have work or home type
379 if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) ) 379 if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) )
380 mData->phoneNumbers.append( *phoneItAD ); 380 mData->phoneNumbers.append( *phoneItAD );
381 } 381 }
382 } 382 }
383 } 383 }
384 if ( isSubSet ) { 384 if ( isSubSet ) {
385 // ************* emails; 385 // ************* emails;
386 t = mData->emails; 386 t = mData->emails;
387 tAD = ad.mData->emails; 387 tAD = ad.mData->emails;
388 for ( iii = 0; iii < tAD.count(); ++iii) 388 for ( iii = 0; iii < tAD.count(); ++iii)
389 if ( !t.contains(tAD[iii] ) ) 389 if ( !t.contains(tAD[iii] ) )
390 mData->emails.append( tAD[iii] ); 390 mData->emails.append( tAD[iii] );
391 } 391 }
392 392
393 // ************* categories; 393 // ************* categories;
394 if ( isSubSet ) { 394 if ( isSubSet ) {
395 t = mData->categories; 395 t = mData->categories;
396 tAD = ad.mData->categories; 396 tAD = ad.mData->categories;
397 for ( iii = 0; iii < tAD.count(); ++iii) 397 for ( iii = 0; iii < tAD.count(); ++iii)
398 if ( !t.contains(tAD[iii] ) ) 398 if ( !t.contains(tAD[iii] ) )
399 mData->categories.append( tAD[iii] ); 399 mData->categories.append( tAD[iii] );
400 } 400 }
401 QStringList::ConstIterator it; 401 QStringList::ConstIterator it;
402 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { 402 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
403 QString qualifiedName = (*it).left( (*it).find( ":" )); 403 QString qualifiedName = (*it).left( (*it).find( ":" ));
404 bool found = false; 404 bool found = false;
405 QStringList::ConstIterator itL; 405 QStringList::ConstIterator itL;
406 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 406 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
407 if ( (*itL).startsWith( qualifiedName ) ) { 407 if ( (*itL).startsWith( qualifiedName ) ) {
408 found = true; 408 found = true;
409 break; 409 break;
410 } 410 }
411 } 411 }
412 if ( ! found ) { 412 if ( ! found ) {
413 mData->custom.append( *it ); 413 mData->custom.append( *it );
414 } 414 }
415 } 415 }
416 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 416 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
417 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 417 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
418 if ( !mData->sound.isIntern() ) { 418 if ( !mData->sound.isIntern() ) {
419 if ( mData->sound.url().isEmpty() ) { 419 if ( mData->sound.url().isEmpty() ) {
420 mData->sound = ad.mData->sound; 420 mData->sound = ad.mData->sound;
421 } 421 }
422 } 422 }
423 if ( !mData->agent.isIntern() ) { 423 if ( !mData->agent.isIntern() ) {
424 if ( mData->agent.url().isEmpty() ) { 424 if ( mData->agent.url().isEmpty() ) {
425 mData->agent = ad.mData->agent; 425 mData->agent = ad.mData->agent;
426 } 426 }
427 } 427 }
428 { 428 {
429 Key::List::Iterator itA; 429 Key::List::Iterator itA;
430 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 430 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
431 bool found = false; 431 bool found = false;
432 Key::List::Iterator it; 432 Key::List::Iterator it;
433 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 433 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
434 if ( (*it) == (*itA)) { 434 if ( (*it) == (*itA)) {
435 found = true; 435 found = true;
436 break; 436 break;
437 437
438 } 438 }
439 } 439 }
440 if ( ! found ) { 440 if ( ! found ) {
441 mData->keys.append( *itA ); 441 mData->keys.append( *itA );
442 } 442 }
443 } 443 }
444 } 444 }
445 if ( isSubSet ) { 445 if ( isSubSet ) {
446 KABC::Address::List::Iterator addressIterA; 446 KABC::Address::List::Iterator addressIterA;
447 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { 447 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
448 bool found = false; 448 bool found = false;
449 KABC::Address::List::Iterator addressIter; 449 KABC::Address::List::Iterator addressIter;
450 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 450 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
451 ++addressIter ) { 451 ++addressIter ) {
452 if ( (*addressIter) == (*addressIterA)) { 452 if ( (*addressIter) == (*addressIterA)) {
453 found = true; 453 found = true;
454 (*addressIter).setType( (*addressIterA).type() ); 454 (*addressIter).setType( (*addressIterA).type() );
455 break; 455 break;
456 } 456 }
457 457
458 } 458 }
459 if ( isSubSet && ! found ) { 459 if ( isSubSet && ! found ) {
460 mData->addresses.append( *addressIterA ); 460 mData->addresses.append( *addressIterA );
461 } 461 }
462 } 462 }
463 } 463 }
464 //qDebug("merge contact %s ", ad.uid().latin1()); 464 //qDebug("merge contact %s ", ad.uid().latin1());
465 setUid( ad.uid() ); 465 setUid( ad.uid() );
466 setRevision( ad.revision() ); 466 setRevision( ad.revision() );
467} 467}
468 468
469bool Addressee::removeVoice() 469bool Addressee::removeVoice()
470{ 470{
471 PhoneNumber::List phoneN = phoneNumbers(); 471 PhoneNumber::List phoneN = phoneNumbers();
472 PhoneNumber::List::Iterator phoneIt; 472 PhoneNumber::List::Iterator phoneIt;
473 bool found = false; 473 bool found = false;
474 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 474 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
475 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 475 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
476 if ((*phoneIt).type() - PhoneNumber::Voice ) { 476 if ((*phoneIt).type() - PhoneNumber::Voice ) {
477 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 477 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
478 insertPhoneNumber( (*phoneIt) ); 478 insertPhoneNumber( (*phoneIt) );
479 found = true; 479 found = true;
480 } 480 }
481 } 481 }
482 482
483 } 483 }
484 return found; 484 return found;
485} 485}
486 486
487bool Addressee::containsAdr(const Addressee& ad ) 487bool Addressee::containsAdr(const Addressee& ad )
488{ 488{
489 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; 489 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
490 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; 490 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
491 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; 491 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
492 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; 492 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
493 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; 493 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
494 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; 494 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
495 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; 495 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
496 496
497 // compare phone numbers 497 // compare phone numbers
498 PhoneNumber::List phoneN = ad.phoneNumbers(); 498 PhoneNumber::List phoneN = ad.phoneNumbers();
499 PhoneNumber::List::Iterator phoneIt; 499 PhoneNumber::List::Iterator phoneIt;
500 bool found = false; 500 bool found = false;
501 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 501 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
502 bool found = false; 502 bool found = false;
503 PhoneNumber::List phoneL = ad.phoneNumbers(); 503 PhoneNumber::List phoneL = ad.phoneNumbers();
504 PhoneNumber::List::Iterator phoneItL; 504 PhoneNumber::List::Iterator phoneItL;
505 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 505 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
506 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 506 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
507 found = true; 507 found = true;
508 break; 508 break;
509 } 509 }
510 } 510 }
511 if ( ! found ) 511 if ( ! found )
512 return false; 512 return false;
513 } 513 }
514 return true; 514 return true;
515 515
516} 516}
517void Addressee::simplifyAddresses() 517void Addressee::simplifyAddresses()
518{ 518{
519 519
520 520
521 Address::List list; 521 Address::List list;
522 Address::List::Iterator it; 522 Address::List::Iterator it;
523 Address::List::Iterator it2; 523 Address::List::Iterator it2;
524 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 524 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
525 it2 = it; 525 it2 = it;
526 ++it2; 526 ++it2;
527 for( ; it2 != mData->addresses.end(); ++it2 ) { 527 for( ; it2 != mData->addresses.end(); ++it2 ) {
528 if ( (*it) == (*it2) ) { 528 if ( (*it) == (*it2) ) {
529 list.append( *it ); 529 list.append( *it );
530 break; 530 break;
531 } 531 }
532 } 532 }
533 } 533 }
534 for( it = list.begin(); it != list.end(); ++it ) { 534 for( it = list.begin(); it != list.end(); ++it ) {
535 removeAddress( (*it) ); 535 removeAddress( (*it) );
536 } 536 }
537 537
538 list.clear(); 538 list.clear();
539 int max = 2; 539 int max = 2;
540 if ( mData->url.isValid() ) 540 if ( mData->url.isValid() )
541 max = 1; 541 max = 1;
542 if ( mData->addresses.count() <= max ) return ; 542 if ( mData->addresses.count() <= max ) return ;
543 int count = 0; 543 int count = 0;
544 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 544 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
545 if ( count >= max ) 545 if ( count >= max )
546 list.append( *it ); 546 list.append( *it );
547 ++count; 547 ++count;
548 } 548 }
549 for( it = list.begin(); it != list.end(); ++it ) { 549 for( it = list.begin(); it != list.end(); ++it ) {
550 removeAddress( (*it) ); 550 removeAddress( (*it) );
551 } 551 }
552} 552}
553 553
554// removes all emails but the first 554// removes all emails but the first
555// needed by phone sync 555// needed by phone sync
556void Addressee::simplifyEmails() 556void Addressee::simplifyEmails()
557{ 557{
558 if ( mData->emails.count() == 0 ) return ; 558 if ( mData->emails.count() == 0 ) return ;
559 QString email = mData->emails.first(); 559 QString email = mData->emails.first();
560 detach(); 560 detach();
561 mData->emails.clear(); 561 mData->emails.clear();
562 mData->emails.append( email ); 562 mData->emails.append( email );
563} 563}
564 564
565void Addressee::simplifyPhoneNumbers() 565void Addressee::simplifyPhoneNumbers()
566{ 566{
567 int max = 4; 567 int max = 4;
568 int inList = mData->phoneNumbers.count(); 568 int inList = mData->phoneNumbers.count();
569 KABC::PhoneNumber::List removeNumbers; 569 KABC::PhoneNumber::List removeNumbers;
570 KABC::PhoneNumber::List::Iterator phoneIter; 570 KABC::PhoneNumber::List::Iterator phoneIter;
571 if ( inList > max ) { 571 if ( inList > max ) {
572 // delete non-preferred numbers 572 // delete non-preferred numbers
573 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 573 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
574 ++phoneIter ) { 574 ++phoneIter ) {
575 if ( inList > max ) { 575 if ( inList > max ) {
576 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { 576 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
577 removeNumbers.append( ( *phoneIter ) ); 577 removeNumbers.append( ( *phoneIter ) );
578 --inList; 578 --inList;
579 } 579 }
580 } else 580 } else
581 break; 581 break;
582 } 582 }
583 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 583 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
584 ++phoneIter ) { 584 ++phoneIter ) {
585 removePhoneNumber(( *phoneIter )); 585 removePhoneNumber(( *phoneIter ));
586 } 586 }
587 // delete preferred numbers 587 // delete preferred numbers
588 if ( inList > max ) { 588 if ( inList > max ) {
589 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 589 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
590 ++phoneIter ) { 590 ++phoneIter ) {
591 if ( inList > max ) { 591 if ( inList > max ) {
592 removeNumbers.append( ( *phoneIter ) ); 592 removeNumbers.append( ( *phoneIter ) );
593 --inList; 593 --inList;
594 } else 594 } else
595 break; 595 break;
596 } 596 }
597 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 597 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
598 ++phoneIter ) { 598 ++phoneIter ) {
599 removePhoneNumber(( *phoneIter )); 599 removePhoneNumber(( *phoneIter ));
600 } 600 }
601 } 601 }
602 } 602 }
603 // remove non-numeric characters 603 // remove non-numeric characters
604 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 604 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
605 ++phoneIter ) { 605 ++phoneIter ) {
606 if ( ! ( *phoneIter ).simplifyNumber() ) 606 if ( ! ( *phoneIter ).simplifyNumber() )
607 removeNumbers.append( ( *phoneIter ) ); 607 removeNumbers.append( ( *phoneIter ) );
608 } 608 }
609 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 609 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
610 ++phoneIter ) { 610 ++phoneIter ) {
611 removePhoneNumber(( *phoneIter )); 611 removePhoneNumber(( *phoneIter ));
612 } 612 }
613} 613}
614void Addressee::simplifyPhoneNumberTypes() 614void Addressee::simplifyPhoneNumberTypes()
615{ 615{
616 KABC::PhoneNumber::List::Iterator phoneIter; 616 KABC::PhoneNumber::List::Iterator phoneIter;
617 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 617 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
618 ++phoneIter ) 618 ++phoneIter )
619 ( *phoneIter ).simplifyType(); 619 ( *phoneIter ).simplifyType();
620} 620}
621void Addressee::removeID(const QString &prof) 621void Addressee::removeID(const QString &prof)
622{ 622{
623 detach(); 623 detach();
624 if ( prof.isEmpty() ) 624 if ( prof.isEmpty() )
625 mData->mExternalId = ":"; 625 mData->mExternalId = ":";
626 else 626 else
627 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 627 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
628 628
629} 629}
630void Addressee::setID( const QString & prof , const QString & id ) 630void Addressee::setID( const QString & prof , const QString & id )
631{ 631{
632 detach(); 632 detach();
633 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 633 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
634 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 634 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
635} 635}
636void Addressee::setTempSyncStat( int id ) 636void Addressee::setTempSyncStat( int id )
637{ 637{
638 if ( mData->mTempSyncStat == id ) return; 638 if ( mData->mTempSyncStat == id ) return;
639 detach(); 639 detach();
640 mData->mTempSyncStat = id; 640 mData->mTempSyncStat = id;
641} 641}
642int Addressee::tempSyncStat() const 642int Addressee::tempSyncStat() const
643{ 643{
644 return mData->mTempSyncStat; 644 return mData->mTempSyncStat;
645} 645}
646 646
647const QString Addressee::getID( const QString & prof) const 647const QString Addressee::getID( const QString & prof) const
648{ 648{
649 return KIdManager::getId ( mData->mExternalId, prof ); 649 return KIdManager::getId ( mData->mExternalId, prof );
650} 650}
651 651
652void Addressee::setCsum( const QString & prof , const QString & id ) 652void Addressee::setCsum( const QString & prof , const QString & id )
653{ 653{
654 detach(); 654 detach();
655 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 655 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
656 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 656 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
657 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 657 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
658} 658}
659 659
660const QString Addressee::getCsum( const QString & prof) const 660const QString Addressee::getCsum( const QString & prof) const
661{ 661{
662 return KIdManager::getCsum ( mData->mExternalId, prof ); 662 return KIdManager::getCsum ( mData->mExternalId, prof );
663} 663}
664 664
665void Addressee::setIDStr( const QString & s ) 665void Addressee::setIDStr( const QString & s )
666{ 666{
667 detach(); 667 detach();
668 mData->mExternalId = s; 668 mData->mExternalId = s;
669} 669}
670 670
671const QString Addressee::IDStr() const 671const QString Addressee::IDStr() const
672{ 672{
673 return mData->mExternalId; 673 return mData->mExternalId;
674} 674}
675 675
676void Addressee::setExternalUID( const QString &id ) 676void Addressee::setExternalUID( const QString &id )
677{ 677{
678 if ( id == mData->externalUID ) return; 678 if ( id == mData->externalUID ) return;
679 detach(); 679 detach();
680 mData->empty = false; 680 mData->empty = false;
681 mData->externalUID = id; 681 mData->externalUID = id;
682} 682}
683 683
684const QString Addressee::externalUID() const 684const QString Addressee::externalUID() const
685{ 685{
686 return mData->externalUID; 686 return mData->externalUID;
687} 687}
688void Addressee::setOriginalExternalUID( const QString &id ) 688void Addressee::setOriginalExternalUID( const QString &id )
689{ 689{
690 if ( id == mData->originalExternalUID ) return; 690 if ( id == mData->originalExternalUID ) return;
691 detach(); 691 detach();
692 mData->empty = false; 692 mData->empty = false;
693 //qDebug("*******Set orig uid %s ", id.latin1()); 693 //qDebug("*******Set orig uid %s ", id.latin1());
694 mData->originalExternalUID = id; 694 mData->originalExternalUID = id;
695} 695}
696 696
697QString Addressee::originalExternalUID() const 697QString Addressee::originalExternalUID() const
698{ 698{
699 return mData->originalExternalUID; 699 return mData->originalExternalUID;
700} 700}
701 701
702void Addressee::setUid( const QString &id ) 702void Addressee::setUid( const QString &id )
703{ 703{
704 if ( id == mData->uid ) return; 704 if ( id == mData->uid ) return;
705 detach(); 705 detach();
706 //qDebug("****setuid %s ", id.latin1()); 706 //qDebug("****setuid %s ", id.latin1());
707 mData->empty = false; 707 mData->empty = false;
708 mData->uid = id; 708 mData->uid = id;
709} 709}
710 710
711const QString Addressee::uid() const 711const QString Addressee::uid() const
712{ 712{
713 if ( mData->uid.isEmpty() ) 713 if ( mData->uid.isEmpty() )
714 mData->uid = KApplication::randomString( 10 ); 714 mData->uid = KApplication::randomString( 10 );
715 715
716 return mData->uid; 716 return mData->uid;
717} 717}
718 718
719QString Addressee::uidLabel() 719QString Addressee::uidLabel()
720{ 720{
721 return i18n("Unique Identifier"); 721 return i18n("Unique Identifier");
722} 722}
723 723
724void Addressee::setName( const QString &name ) 724void Addressee::setName( const QString &name )
725{ 725{
726 if ( name == mData->name ) return; 726 if ( name == mData->name ) return;
727 detach(); 727 detach();
728 mData->empty = false; 728 mData->empty = false;
729 mData->name = name; 729 mData->name = name;
730} 730}
731 731
732QString Addressee::name() const 732QString Addressee::name() const
733{ 733{
734 return mData->name; 734 return mData->name;
735} 735}
736 736
737QString Addressee::nameLabel() 737QString Addressee::nameLabel()
738{ 738{
739 return i18n("Name"); 739 return i18n("Name");
740} 740}
741 741
742 742
743void Addressee::setFormattedName( const QString &formattedName ) 743void Addressee::setFormattedName( const QString &formattedName )
744{ 744{
745 if ( formattedName == mData->formattedName ) return; 745 if ( formattedName == mData->formattedName ) return;
746 detach(); 746 detach();
747 mData->empty = false; 747 mData->empty = false;
748 mData->formattedName = formattedName; 748 mData->formattedName = formattedName;
749} 749}
750 750
751QString Addressee::formattedName() const 751QString Addressee::formattedName() const
752{ 752{
753 return mData->formattedName; 753 return mData->formattedName;
754} 754}
755 755
756QString Addressee::formattedNameLabel() 756QString Addressee::formattedNameLabel()
757{ 757{
758 return i18n("Formatted Name"); 758 return i18n("Formatted Name");
759} 759}
760 760
761 761
762void Addressee::setFamilyName( const QString &familyName ) 762void Addressee::setFamilyName( const QString &familyName )
763{ 763{
764 if ( familyName == mData->familyName ) return; 764 if ( familyName == mData->familyName ) return;
765 detach(); 765 detach();
766 mData->empty = false; 766 mData->empty = false;
767 mData->familyName = familyName; 767 mData->familyName = familyName;
768} 768}
769 769
770QString Addressee::familyName() const 770QString Addressee::familyName() const
771{ 771{
772 return mData->familyName; 772 return mData->familyName;
773} 773}
774 774
775QString Addressee::familyNameLabel() 775QString Addressee::familyNameLabel()
776{ 776{
777 return i18n("Family Name"); 777 return i18n("Family Name");
778} 778}
779 779
780 780
781void Addressee::setGivenName( const QString &givenName ) 781void Addressee::setGivenName( const QString &givenName )
782{ 782{
783 if ( givenName == mData->givenName ) return; 783 if ( givenName == mData->givenName ) return;
784 detach(); 784 detach();
785 mData->empty = false; 785 mData->empty = false;
786 mData->givenName = givenName; 786 mData->givenName = givenName;
787} 787}
788 788
789QString Addressee::givenName() const 789QString Addressee::givenName() const
790{ 790{
791 return mData->givenName; 791 return mData->givenName;
792} 792}
793 793
794QString Addressee::givenNameLabel() 794QString Addressee::givenNameLabel()
795{ 795{
796 return i18n("Given Name"); 796 return i18n("Given Name");
797} 797}
798 798
799 799
800void Addressee::setAdditionalName( const QString &additionalName ) 800void Addressee::setAdditionalName( const QString &additionalName )
801{ 801{
802 if ( additionalName == mData->additionalName ) return; 802 if ( additionalName == mData->additionalName ) return;
803 detach(); 803 detach();
804 mData->empty = false; 804 mData->empty = false;
805 mData->additionalName = additionalName; 805 mData->additionalName = additionalName;
806} 806}
807 807
808QString Addressee::additionalName() const 808QString Addressee::additionalName() const
809{ 809{
810 return mData->additionalName; 810 return mData->additionalName;
811} 811}
812 812
813QString Addressee::additionalNameLabel() 813QString Addressee::additionalNameLabel()
814{ 814{
815 return i18n("Additional Names"); 815 return i18n("Additional Names");
816} 816}
817 817
818 818
819void Addressee::setPrefix( const QString &prefix ) 819void Addressee::setPrefix( const QString &prefix )
820{ 820{
821 if ( prefix == mData->prefix ) return; 821 if ( prefix == mData->prefix ) return;
822 detach(); 822 detach();
823 mData->empty = false; 823 mData->empty = false;
824 mData->prefix = prefix; 824 mData->prefix = prefix;
825} 825}
826 826
827QString Addressee::prefix() const 827QString Addressee::prefix() const
828{ 828{
829 return mData->prefix; 829 return mData->prefix;
830} 830}
831 831
832QString Addressee::prefixLabel() 832QString Addressee::prefixLabel()
833{ 833{
834 return i18n("Honorific Prefixes"); 834 return i18n("Honorific Prefixes");
835} 835}
836 836
837 837
838void Addressee::setSuffix( const QString &suffix ) 838void Addressee::setSuffix( const QString &suffix )
839{ 839{
840 if ( suffix == mData->suffix ) return; 840 if ( suffix == mData->suffix ) return;
841 detach(); 841 detach();
842 mData->empty = false; 842 mData->empty = false;
843 mData->suffix = suffix; 843 mData->suffix = suffix;
844} 844}
845 845
846QString Addressee::suffix() const 846QString Addressee::suffix() const
847{ 847{
848 return mData->suffix; 848 return mData->suffix;
849} 849}
850 850
851QString Addressee::suffixLabel() 851QString Addressee::suffixLabel()
852{ 852{
853 return i18n("Honorific Suffixes"); 853 return i18n("Honorific Suffixes");
854} 854}
855 855
856 856
857void Addressee::setNickName( const QString &nickName ) 857void Addressee::setNickName( const QString &nickName )
858{ 858{
859 if ( nickName == mData->nickName ) return; 859 if ( nickName == mData->nickName ) return;
860 detach(); 860 detach();
861 mData->empty = false; 861 mData->empty = false;
862 mData->nickName = nickName; 862 mData->nickName = nickName;
863} 863}
864 864
865QString Addressee::nickName() const 865QString Addressee::nickName() const
866{ 866{
867 return mData->nickName; 867 return mData->nickName;
868} 868}
869 869
870QString Addressee::nickNameLabel() 870QString Addressee::nickNameLabel()
871{ 871{
872 return i18n("Nick Name"); 872 return i18n("Nick Name");
873} 873}
874 874
875 875
876void Addressee::setBirthday( const QDateTime &birthday ) 876void Addressee::setBirthday( const QDateTime &birthday )
877{ 877{
878 if ( birthday == mData->birthday ) return; 878 if ( birthday == mData->birthday ) return;
879 detach(); 879 detach();
880 mData->empty = false; 880 mData->empty = false;
881 mData->birthday = birthday; 881 mData->birthday = birthday;
882} 882}
883 883
884QDateTime Addressee::birthday() const 884QDateTime Addressee::birthday() const
885{ 885{
886 return mData->birthday; 886 return mData->birthday;
887} 887}
888 888
889QString Addressee::birthdayLabel() 889QString Addressee::birthdayLabel()
890{ 890{
891 return i18n("Birthday"); 891 return i18n("Birthday");
892} 892}
893 893
894 894
895QString Addressee::homeAddressStreetLabel() 895QString Addressee::homeAddressStreetLabel()
896{ 896{
897 return i18n("Home Address Street"); 897 return i18n("Home Address Street");
898} 898}
899 899
900 900
901QString Addressee::homeAddressLocalityLabel() 901QString Addressee::homeAddressLocalityLabel()
902{ 902{
903 return i18n("Home Address Locality"); 903 return i18n("Home Address Locality");
904} 904}
905 905
906 906
907QString Addressee::homeAddressRegionLabel() 907QString Addressee::homeAddressRegionLabel()
908{ 908{
909 return i18n("Home Address Region"); 909 return i18n("Home Address Region");
910} 910}
911 911
912 912
913QString Addressee::homeAddressPostalCodeLabel() 913QString Addressee::homeAddressPostalCodeLabel()
914{ 914{
915 return i18n("Home Address Postal Code"); 915 return i18n("Home Address Postal Code");
916} 916}
917 917
918 918
919QString Addressee::homeAddressCountryLabel() 919QString Addressee::homeAddressCountryLabel()
920{ 920{
921 return i18n("Home Address Country"); 921 return i18n("Home Address Country");
922} 922}
923 923
924 924
925QString Addressee::homeAddressLabelLabel() 925QString Addressee::homeAddressLabelLabel()
926{ 926{
927 return i18n("Home Address Label"); 927 return i18n("Home Address Label");
928} 928}
929 929
930 930
931QString Addressee::businessAddressStreetLabel() 931QString Addressee::businessAddressStreetLabel()
932{ 932{
933 return i18n("Business Address Street"); 933 return i18n("Business Address Street");
934} 934}
935 935
936 936
937QString Addressee::businessAddressLocalityLabel() 937QString Addressee::businessAddressLocalityLabel()
938{ 938{
939 return i18n("Business Address Locality"); 939 return i18n("Business Address Locality");
940} 940}
941 941
942 942
943QString Addressee::businessAddressRegionLabel() 943QString Addressee::businessAddressRegionLabel()
944{ 944{
945 return i18n("Business Address Region"); 945 return i18n("Business Address Region");
946} 946}
947 947
948 948
949QString Addressee::businessAddressPostalCodeLabel() 949QString Addressee::businessAddressPostalCodeLabel()
950{ 950{
951 return i18n("Business Address Postal Code"); 951 return i18n("Business Address Postal Code");
952} 952}
953 953
954 954
955QString Addressee::businessAddressCountryLabel() 955QString Addressee::businessAddressCountryLabel()
956{ 956{
957 return i18n("Business Address Country"); 957 return i18n("Business Address Country");
958} 958}
959 959
960 960
961QString Addressee::businessAddressLabelLabel() 961QString Addressee::businessAddressLabelLabel()
962{ 962{
963 return i18n("Business Address Label"); 963 return i18n("Business Address Label");
964} 964}
965 965
966 966
967QString Addressee::homePhoneLabel() 967QString Addressee::homePhoneLabel()
968{ 968{
969 return i18n("Home Phone"); 969 return i18n("Home Phone");
970} 970}
971 971
972 972
973QString Addressee::businessPhoneLabel() 973QString Addressee::businessPhoneLabel()
974{ 974{
975 return i18n("Business Phone"); 975 return i18n("Business Phone");
976} 976}
977 977
978 978
979QString Addressee::mobilePhoneLabel() 979QString Addressee::mobilePhoneLabel()
980{ 980{
981 return i18n("Mobile Phone"); 981 return i18n("Mobile Phone");
982} 982}
983 983
984 984
985QString Addressee::homeFaxLabel() 985QString Addressee::homeFaxLabel()
986{ 986{
987 return i18n("Home Fax"); 987 return i18n("Home Fax");
988} 988}
989 989
990 990
991QString Addressee::businessFaxLabel() 991QString Addressee::businessFaxLabel()
992{ 992{
993 return i18n("Business Fax"); 993 return i18n("Business Fax");
994} 994}
995 995
996 996
997QString Addressee::carPhoneLabel() 997QString Addressee::carPhoneLabel()
998{ 998{
999 return i18n("Car Phone"); 999 return i18n("Car Phone");
1000} 1000}
1001 1001
1002 1002
1003QString Addressee::isdnLabel() 1003QString Addressee::isdnLabel()
1004{ 1004{
1005 return i18n("ISDN"); 1005 return i18n("ISDN");
1006} 1006}
1007 1007
1008 1008
1009QString Addressee::pagerLabel() 1009QString Addressee::pagerLabel()
1010{ 1010{
1011 return i18n("Pager"); 1011 return i18n("Pager");
1012} 1012}
1013 1013
1014QString Addressee::sipLabel() 1014QString Addressee::sipLabel()
1015{ 1015{
1016 return i18n("SIP"); 1016 return i18n("SIP");
1017} 1017}
1018 1018
1019QString Addressee::emailLabel() 1019QString Addressee::emailLabel()
1020{ 1020{
1021 return i18n("Email Address"); 1021 return i18n("Email Address");
1022} 1022}
1023 1023
1024 1024
1025void Addressee::setMailer( const QString &mailer ) 1025void Addressee::setMailer( const QString &mailer )
1026{ 1026{
1027 if ( mailer == mData->mailer ) return; 1027 if ( mailer == mData->mailer ) return;
1028 detach(); 1028 detach();
1029 mData->empty = false; 1029 mData->empty = false;
1030 mData->mailer = mailer; 1030 mData->mailer = mailer;
1031} 1031}
1032 1032
1033QString Addressee::mailer() const 1033QString Addressee::mailer() const
1034{ 1034{
1035 return mData->mailer; 1035 return mData->mailer;
1036} 1036}
1037 1037
1038QString Addressee::mailerLabel() 1038QString Addressee::mailerLabel()
1039{ 1039{
1040 return i18n("Mail Client"); 1040 return i18n("Mail Client");
1041} 1041}
1042 1042
1043 1043
1044void Addressee::setTimeZone( const TimeZone &timeZone ) 1044void Addressee::setTimeZone( const TimeZone &timeZone )
1045{ 1045{
1046 if ( timeZone == mData->timeZone ) return; 1046 if ( timeZone == mData->timeZone ) return;
1047 detach(); 1047 detach();
1048 mData->empty = false; 1048 mData->empty = false;
1049 mData->timeZone = timeZone; 1049 mData->timeZone = timeZone;
1050} 1050}
1051 1051
1052TimeZone Addressee::timeZone() const 1052TimeZone Addressee::timeZone() const
1053{ 1053{
1054 return mData->timeZone; 1054 return mData->timeZone;
1055} 1055}
1056 1056
1057QString Addressee::timeZoneLabel() 1057QString Addressee::timeZoneLabel()
1058{ 1058{
1059 return i18n("Time Zone"); 1059 return i18n("Time Zone");
1060} 1060}
1061 1061
1062 1062
1063void Addressee::setGeo( const Geo &geo ) 1063void Addressee::setGeo( const Geo &geo )
1064{ 1064{
1065 if ( geo == mData->geo ) return; 1065 if ( geo == mData->geo ) return;
1066 detach(); 1066 detach();
1067 mData->empty = false; 1067 mData->empty = false;
1068 mData->geo = geo; 1068 mData->geo = geo;
1069} 1069}
1070 1070
1071Geo Addressee::geo() const 1071Geo Addressee::geo() const
1072{ 1072{
1073 return mData->geo; 1073 return mData->geo;
1074} 1074}
1075 1075
1076QString Addressee::geoLabel() 1076QString Addressee::geoLabel()
1077{ 1077{
1078 return i18n("Geographic Position"); 1078 return i18n("Geographic Position");
1079} 1079}
1080 1080
1081 1081
1082void Addressee::setTitle( const QString &title ) 1082void Addressee::setTitle( const QString &title )
1083{ 1083{
1084 if ( title == mData->title ) return; 1084 if ( title == mData->title ) return;
1085 detach(); 1085 detach();
1086 mData->empty = false; 1086 mData->empty = false;
1087 mData->title = title; 1087 mData->title = title;
1088} 1088}
1089 1089
1090QString Addressee::title() const 1090QString Addressee::title() const
1091{ 1091{
1092 return mData->title; 1092 return mData->title;
1093} 1093}
1094 1094
1095QString Addressee::titleLabel() 1095QString Addressee::titleLabel()
1096{ 1096{
1097 return i18n("Title"); 1097 return i18n("Title");
1098} 1098}
1099 1099
1100 1100
1101void Addressee::setRole( const QString &role ) 1101void Addressee::setRole( const QString &role )
1102{ 1102{
1103 if ( role == mData->role ) return; 1103 if ( role == mData->role ) return;
1104 detach(); 1104 detach();
1105 mData->empty = false; 1105 mData->empty = false;
1106 mData->role = role; 1106 mData->role = role;
1107} 1107}
1108 1108
1109QString Addressee::role() const 1109QString Addressee::role() const
1110{ 1110{
1111 return mData->role; 1111 return mData->role;
1112} 1112}
1113 1113
1114QString Addressee::roleLabel() 1114QString Addressee::roleLabel()
1115{ 1115{
1116 return i18n("Role"); 1116 return i18n("Role");
1117} 1117}
1118 1118
1119 1119
1120void Addressee::setOrganization( const QString &organization ) 1120void Addressee::setOrganization( const QString &organization )
1121{ 1121{
1122 if ( organization == mData->organization ) return; 1122 if ( organization == mData->organization ) return;
1123 detach(); 1123 detach();
1124 mData->empty = false; 1124 mData->empty = false;
1125 mData->organization = organization; 1125 mData->organization = organization;
1126} 1126}
1127 1127
1128QString Addressee::organization() const 1128QString Addressee::organization() const
1129{ 1129{
1130 return mData->organization; 1130 return mData->organization;
1131} 1131}
1132 1132
1133QString Addressee::organizationLabel() 1133QString Addressee::organizationLabel()
1134{ 1134{
1135 return i18n("Organization"); 1135 return i18n("Organization");
1136} 1136}
1137 1137
1138 1138
1139void Addressee::setNote( const QString &note ) 1139void Addressee::setNote( const QString &note )
1140{ 1140{
1141 if ( note == mData->note ) return; 1141 if ( note == mData->note ) return;
1142 detach(); 1142 detach();
1143 mData->empty = false; 1143 mData->empty = false;
1144 mData->note = note; 1144 mData->note = note;
1145} 1145}
1146 1146
1147QString Addressee::note() const 1147QString Addressee::note() const
1148{ 1148{
1149 return mData->note; 1149 return mData->note;
1150} 1150}
1151 1151
1152QString Addressee::noteLabel() 1152QString Addressee::noteLabel()
1153{ 1153{
1154 return i18n("Note"); 1154 return i18n("Note");
1155} 1155}
1156 1156
1157 1157
1158void Addressee::setProductId( const QString &productId ) 1158void Addressee::setProductId( const QString &productId )
1159{ 1159{
1160 if ( productId == mData->productId ) return; 1160 if ( productId == mData->productId ) return;
1161 detach(); 1161 detach();
1162 mData->empty = false; 1162 mData->empty = false;
1163 mData->productId = productId; 1163 mData->productId = productId;
1164} 1164}
1165 1165
1166QString Addressee::productId() const 1166QString Addressee::productId() const
1167{ 1167{
1168 return mData->productId; 1168 return mData->productId;
1169} 1169}
1170 1170
1171QString Addressee::productIdLabel() 1171QString Addressee::productIdLabel()
1172{ 1172{
1173 return i18n("Product Identifier"); 1173 return i18n("Product Identifier");
1174} 1174}
1175 1175
1176 1176
1177void Addressee::setRevision( const QDateTime &revision ) 1177void Addressee::setRevision( const QDateTime &revision )
1178{ 1178{
1179 if ( revision == mData->revision ) return; 1179 if ( revision == mData->revision ) return;
1180 detach(); 1180 detach();
1181 mData->empty = false; 1181 mData->empty = false;
1182 mData->revision = QDateTime( revision.date(), 1182 mData->revision = QDateTime( revision.date(),
1183 QTime (revision.time().hour(), 1183 QTime (revision.time().hour(),
1184 revision.time().minute(), 1184 revision.time().minute(),
1185 revision.time().second())); 1185 revision.time().second()));
1186} 1186}
1187 1187
1188QDateTime Addressee::revision() const 1188QDateTime Addressee::revision() const
1189{ 1189{
1190 return mData->revision; 1190 return mData->revision;
1191} 1191}
1192 1192
1193QString Addressee::revisionLabel() 1193QString Addressee::revisionLabel()
1194{ 1194{
1195 return i18n("Revision Date"); 1195 return i18n("Revision Date");
1196} 1196}
1197 1197
1198 1198
1199void Addressee::setSortString( const QString &sortString ) 1199void Addressee::setSortString( const QString &sortString )
1200{ 1200{
1201 if ( sortString == mData->sortString ) return; 1201 if ( sortString == mData->sortString ) return;
1202 detach(); 1202 detach();
1203 mData->empty = false; 1203 mData->empty = false;
1204 mData->sortString = sortString; 1204 mData->sortString = sortString;
1205} 1205}
1206 1206
1207QString Addressee::sortString() const 1207QString Addressee::sortString() const
1208{ 1208{
1209 return mData->sortString; 1209 return mData->sortString;
1210} 1210}
1211 1211
1212QString Addressee::sortStringLabel() 1212QString Addressee::sortStringLabel()
1213{ 1213{
1214 return i18n("Sort String"); 1214 return i18n("Sort String");
1215} 1215}
1216 1216
1217 1217
1218void Addressee::setUrl( const KURL &url ) 1218void Addressee::setUrl( const KURL &url )
1219{ 1219{
1220 if ( url == mData->url ) return; 1220 if ( url == mData->url ) return;
1221 detach(); 1221 detach();
1222 mData->empty = false; 1222 mData->empty = false;
1223 mData->url = url; 1223 mData->url = url;
1224} 1224}
1225 1225
1226KURL Addressee::url() const 1226KURL Addressee::url() const
1227{ 1227{
1228 return mData->url; 1228 return mData->url;
1229} 1229}
1230 1230
1231QString Addressee::urlLabel() 1231QString Addressee::urlLabel()
1232{ 1232{
1233 return i18n("URL"); 1233 return i18n("URL");
1234} 1234}
1235 1235
1236 1236
1237void Addressee::setSecrecy( const Secrecy &secrecy ) 1237void Addressee::setSecrecy( const Secrecy &secrecy )
1238{ 1238{
1239 if ( secrecy == mData->secrecy ) return; 1239 if ( secrecy == mData->secrecy ) return;
1240 detach(); 1240 detach();
1241 mData->empty = false; 1241 mData->empty = false;
1242 mData->secrecy = secrecy; 1242 mData->secrecy = secrecy;
1243} 1243}
1244 1244
1245Secrecy Addressee::secrecy() const 1245Secrecy Addressee::secrecy() const
1246{ 1246{
1247 return mData->secrecy; 1247 return mData->secrecy;
1248} 1248}
1249 1249
1250QString Addressee::secrecyLabel() 1250QString Addressee::secrecyLabel()
1251{ 1251{
1252 return i18n("Security Class"); 1252 return i18n("Security Class");
1253} 1253}
1254 1254
1255 1255
1256void Addressee::setLogo( const Picture &logo ) 1256void Addressee::setLogo( const Picture &logo )
1257{ 1257{
1258 if ( logo == mData->logo ) return; 1258 if ( logo == mData->logo ) return;
1259 detach(); 1259 detach();
1260 mData->empty = false; 1260 mData->empty = false;
1261 mData->logo = logo; 1261 mData->logo = logo;
1262} 1262}
1263 1263
1264Picture Addressee::logo() const 1264Picture Addressee::logo() const
1265{ 1265{
1266 return mData->logo; 1266 return mData->logo;
1267} 1267}
1268 1268
1269QString Addressee::logoLabel() 1269QString Addressee::logoLabel()
1270{ 1270{
1271 return i18n("Logo"); 1271 return i18n("Logo");
1272} 1272}
1273 1273
1274 1274
1275void Addressee::setPhoto( const Picture &photo ) 1275void Addressee::setPhoto( const Picture &photo )
1276{ 1276{
1277 if ( photo == mData->photo ) return; 1277 if ( photo == mData->photo ) return;
1278 detach(); 1278 detach();
1279 mData->empty = false; 1279 mData->empty = false;
1280 mData->photo = photo; 1280 mData->photo = photo;
1281} 1281}
1282 1282
1283Picture Addressee::photo() const 1283Picture Addressee::photo() const
1284{ 1284{
1285 return mData->photo; 1285 return mData->photo;
1286} 1286}
1287 1287
1288QString Addressee::photoLabel() 1288QString Addressee::photoLabel()
1289{ 1289{
1290 return i18n("Photo"); 1290 return i18n("Photo");
1291} 1291}
1292 1292
1293 1293
1294void Addressee::setSound( const Sound &sound ) 1294void Addressee::setSound( const Sound &sound )
1295{ 1295{
1296 if ( sound == mData->sound ) return; 1296 if ( sound == mData->sound ) return;
1297 detach(); 1297 detach();
1298 mData->empty = false; 1298 mData->empty = false;
1299 mData->sound = sound; 1299 mData->sound = sound;
1300} 1300}
1301 1301
1302Sound Addressee::sound() const 1302Sound Addressee::sound() const
1303{ 1303{
1304 return mData->sound; 1304 return mData->sound;
1305} 1305}
1306 1306
1307QString Addressee::soundLabel() 1307QString Addressee::soundLabel()
1308{ 1308{
1309 return i18n("Sound"); 1309 return i18n("Sound");
1310} 1310}
1311 1311
1312 1312
1313void Addressee::setAgent( const Agent &agent ) 1313void Addressee::setAgent( const Agent &agent )
1314{ 1314{
1315 if ( agent == mData->agent ) return; 1315 if ( agent == mData->agent ) return;
1316 detach(); 1316 detach();
1317 mData->empty = false; 1317 mData->empty = false;
1318 mData->agent = agent; 1318 mData->agent = agent;
1319} 1319}
1320 1320
1321Agent Addressee::agent() const 1321Agent Addressee::agent() const
1322{ 1322{
1323 return mData->agent; 1323 return mData->agent;
1324} 1324}
1325 1325
1326QString Addressee::agentLabel() 1326QString Addressee::agentLabel()
1327{ 1327{
1328 return i18n("Agent"); 1328 return i18n("Agent");
1329} 1329}
1330 1330
1331 1331
1332 1332
1333void Addressee::setNameFromString( const QString &str ) 1333void Addressee::setNameFromString( const QString &str )
1334{ 1334{
1335 setFormattedName( str ); 1335 setFormattedName( str );
1336 setName( str ); 1336 setName( str );
1337 1337
1338 static bool first = true; 1338 static bool first = true;
1339 static QStringList titles; 1339 static QStringList titles;
1340 static QStringList suffixes; 1340 static QStringList suffixes;
1341 static QStringList prefixes; 1341 static QStringList prefixes;
1342 1342
1343 if ( first ) { 1343 if ( first ) {
1344 first = false; 1344 first = false;
1345 titles += i18n( "Dr." ); 1345 titles += i18n( "Dr." );
1346 titles += i18n( "Miss" ); 1346 titles += i18n( "Miss" );
1347 titles += i18n( "Mr." ); 1347 titles += i18n( "Mr." );
1348 titles += i18n( "Mrs." ); 1348 titles += i18n( "Mrs." );
1349 titles += i18n( "Ms." ); 1349 titles += i18n( "Ms." );
1350 titles += i18n( "Prof." ); 1350 titles += i18n( "Prof." );
1351 1351
1352 suffixes += i18n( "I" ); 1352 suffixes += i18n( "I" );
1353 suffixes += i18n( "II" ); 1353 suffixes += i18n( "II" );
1354 suffixes += i18n( "III" ); 1354 suffixes += i18n( "III" );
1355 suffixes += i18n( "Jr." ); 1355 suffixes += i18n( "Jr." );
1356 suffixes += i18n( "Sr." ); 1356 suffixes += i18n( "Sr." );
1357 1357
1358 prefixes += "van"; 1358 prefixes += "van";
1359 prefixes += "von"; 1359 prefixes += "von";
1360 prefixes += "de"; 1360 prefixes += "de";
1361 1361
1362 KConfig config( locateLocal( "config", "kabcrc") ); 1362 KConfig config( locateLocal( "config", "kabcrc") );
1363 config.setGroup( "General" ); 1363 config.setGroup( "General" );
1364 titles += config.readListEntry( "Prefixes" ); 1364 titles += config.readListEntry( "Prefixes" );
1365 titles.remove( "" ); 1365 titles.remove( "" );
1366 prefixes += config.readListEntry( "Inclusions" ); 1366 prefixes += config.readListEntry( "Inclusions" );
1367 prefixes.remove( "" ); 1367 prefixes.remove( "" );
1368 suffixes += config.readListEntry( "Suffixes" ); 1368 suffixes += config.readListEntry( "Suffixes" );
1369 suffixes.remove( "" ); 1369 suffixes.remove( "" );
1370 } 1370 }
1371 1371
1372 // clear all name parts 1372 // clear all name parts
1373 setPrefix( "" ); 1373 setPrefix( "" );
1374 setGivenName( "" ); 1374 setGivenName( "" );
1375 setAdditionalName( "" ); 1375 setAdditionalName( "" );
1376 setFamilyName( "" ); 1376 setFamilyName( "" );
1377 setSuffix( "" ); 1377 setSuffix( "" );
1378 1378
1379 if ( str.isEmpty() ) 1379 if ( str.isEmpty() )
1380 return; 1380 return;
1381 1381
1382 int i = str.find(','); 1382 int i = str.find(',');
1383 if( i < 0 ) { 1383 if( i < 0 ) {
1384 QStringList parts = QStringList::split( " ", str ); 1384 QStringList parts = QStringList::split( " ", str );
1385 int leftOffset = 0; 1385 int leftOffset = 0;
1386 int rightOffset = parts.count() - 1; 1386 int rightOffset = parts.count() - 1;
1387 1387
1388 QString suffix; 1388 QString suffix;
1389 while ( rightOffset >= 0 ) { 1389 while ( rightOffset >= 0 ) {
1390 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1390 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1391 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1391 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1392 rightOffset--; 1392 rightOffset--;
1393 } else 1393 } else
1394 break; 1394 break;
1395 } 1395 }
1396 setSuffix( suffix ); 1396 setSuffix( suffix );
1397 1397
1398 if ( rightOffset < 0 ) 1398 if ( rightOffset < 0 )
1399 return; 1399 return;
1400 1400
1401 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1401 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1402 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1402 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1403 rightOffset--; 1403 rightOffset--;
1404 } else 1404 } else
1405 setFamilyName( parts[ rightOffset ] ); 1405 setFamilyName( parts[ rightOffset ] );
1406 1406
1407 QString prefix; 1407 QString prefix;
1408 while ( leftOffset < rightOffset ) { 1408 while ( leftOffset < rightOffset ) {
1409 if ( titles.contains( parts[ leftOffset ] ) ) { 1409 if ( titles.contains( parts[ leftOffset ] ) ) {
1410 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1410 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1411 leftOffset++; 1411 leftOffset++;
1412 } else 1412 } else
1413 break; 1413 break;
1414 } 1414 }
1415 setPrefix( prefix ); 1415 setPrefix( prefix );
1416 1416
1417 if ( leftOffset < rightOffset ) { 1417 if ( leftOffset < rightOffset ) {
1418 setGivenName( parts[ leftOffset ] ); 1418 setGivenName( parts[ leftOffset ] );
1419 leftOffset++; 1419 leftOffset++;
1420 } 1420 }
1421 1421
1422 QString additionalName; 1422 QString additionalName;
1423 while ( leftOffset < rightOffset ) { 1423 while ( leftOffset < rightOffset ) {
1424 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1424 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1425 leftOffset++; 1425 leftOffset++;
1426 } 1426 }
1427 setAdditionalName( additionalName ); 1427 setAdditionalName( additionalName );
1428 } else { 1428 } else {
1429 QString part1 = str.left( i ); 1429 QString part1 = str.left( i );
1430 QString part2 = str.mid( i + 1 ); 1430 QString part2 = str.mid( i + 1 );
1431 1431
1432 QStringList parts = QStringList::split( " ", part1 ); 1432 QStringList parts = QStringList::split( " ", part1 );
1433 int leftOffset = 0; 1433 int leftOffset = 0;
1434 int rightOffset = parts.count() - 1; 1434 int rightOffset = parts.count() - 1;
1435 1435
1436 QString suffix; 1436 QString suffix;
1437 while ( rightOffset >= 0 ) { 1437 while ( rightOffset >= 0 ) {
1438 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1438 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1439 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1439 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1440 rightOffset--; 1440 rightOffset--;
1441 } else 1441 } else
1442 break; 1442 break;
1443 } 1443 }
1444 setSuffix( suffix ); 1444 setSuffix( suffix );
1445 1445
1446 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1446 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1447 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1447 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1448 rightOffset--; 1448 rightOffset--;
1449 } else 1449 } else
1450 setFamilyName( parts[ rightOffset ] ); 1450 setFamilyName( parts[ rightOffset ] );
1451 1451
1452 QString prefix; 1452 QString prefix;
1453 while ( leftOffset < rightOffset ) { 1453 while ( leftOffset < rightOffset ) {
1454 if ( titles.contains( parts[ leftOffset ] ) ) { 1454 if ( titles.contains( parts[ leftOffset ] ) ) {
1455 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1455 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1456 leftOffset++; 1456 leftOffset++;
1457 } else 1457 } else
1458 break; 1458 break;
1459 } 1459 }
1460 1460
1461 parts = QStringList::split( " ", part2 ); 1461 parts = QStringList::split( " ", part2 );
1462 1462
1463 leftOffset = 0; 1463 leftOffset = 0;
1464 rightOffset = parts.count(); 1464 rightOffset = parts.count();
1465 1465
1466 while ( leftOffset < rightOffset ) { 1466 while ( leftOffset < rightOffset ) {
1467 if ( titles.contains( parts[ leftOffset ] ) ) { 1467 if ( titles.contains( parts[ leftOffset ] ) ) {
1468 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1468 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1469 leftOffset++; 1469 leftOffset++;
1470 } else 1470 } else
1471 break; 1471 break;
1472 } 1472 }
1473 setPrefix( prefix ); 1473 setPrefix( prefix );
1474 1474
1475 if ( leftOffset < rightOffset ) { 1475 if ( leftOffset < rightOffset ) {
1476 setGivenName( parts[ leftOffset ] ); 1476 setGivenName( parts[ leftOffset ] );
1477 leftOffset++; 1477 leftOffset++;
1478 } 1478 }
1479 1479
1480 QString additionalName; 1480 QString additionalName;
1481 while ( leftOffset < rightOffset ) { 1481 while ( leftOffset < rightOffset ) {
1482 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1482 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1483 leftOffset++; 1483 leftOffset++;
1484 } 1484 }
1485 setAdditionalName( additionalName ); 1485 setAdditionalName( additionalName );
1486 } 1486 }
1487} 1487}
1488 1488
1489QString Addressee::realName() const 1489QString Addressee::realName() const
1490{ 1490{
1491 if ( !formattedName().isEmpty() ) 1491 if ( !formattedName().isEmpty() )
1492 return formattedName(); 1492 return formattedName();
1493 1493
1494 QString n = assembledName(); 1494 QString n = assembledName();
1495 1495
1496 if ( n.isEmpty() ) 1496 if ( n.isEmpty() )
1497 n = name(); 1497 n = name();
1498 1498 if ( n.isEmpty() )
1499 n = organization();
1499 return n; 1500 return n;
1500} 1501}
1501 1502
1502QString Addressee::assembledName() const 1503QString Addressee::assembledName() const
1503{ 1504{
1504 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1505 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1505 familyName() + " " + suffix(); 1506 familyName() + " " + suffix();
1506 1507
1507 return name.simplifyWhiteSpace(); 1508 return name.simplifyWhiteSpace();
1508} 1509}
1509 1510
1510QString Addressee::fullEmail( const QString &email ) const 1511QString Addressee::fullEmail( const QString &email ) const
1511{ 1512{
1512 QString e; 1513 QString e;
1513 if ( email.isNull() ) { 1514 if ( email.isNull() ) {
1514 e = preferredEmail(); 1515 e = preferredEmail();
1515 } else { 1516 } else {
1516 e = email; 1517 e = email;
1517 } 1518 }
1518 if ( e.isEmpty() ) return QString::null; 1519 if ( e.isEmpty() ) return QString::null;
1519 1520
1520 QString text; 1521 QString text;
1521 if ( realName().isEmpty() ) 1522 if ( realName().isEmpty() )
1522 text = e; 1523 text = e;
1523 else 1524 else
1524 text = assembledName() + " <" + e + ">"; 1525 text = assembledName() + " <" + e + ">";
1525 1526
1526 return text; 1527 return text;
1527} 1528}
1528 1529
1529void Addressee::insertEmail( const QString &email, bool preferred ) 1530void Addressee::insertEmail( const QString &email, bool preferred )
1530{ 1531{
1531 detach(); 1532 detach();
1532 1533
1533 QStringList::Iterator it = mData->emails.find( email ); 1534 QStringList::Iterator it = mData->emails.find( email );
1534 1535
1535 if ( it != mData->emails.end() ) { 1536 if ( it != mData->emails.end() ) {
1536 if ( !preferred || it == mData->emails.begin() ) return; 1537 if ( !preferred || it == mData->emails.begin() ) return;
1537 mData->emails.remove( it ); 1538 mData->emails.remove( it );
1538 mData->emails.prepend( email ); 1539 mData->emails.prepend( email );
1539 } else { 1540 } else {
1540 if ( preferred ) { 1541 if ( preferred ) {
1541 mData->emails.prepend( email ); 1542 mData->emails.prepend( email );
1542 } else { 1543 } else {
1543 mData->emails.append( email ); 1544 mData->emails.append( email );
1544 } 1545 }
1545 } 1546 }
1546} 1547}
1547 1548
1548void Addressee::removeEmail( const QString &email ) 1549void Addressee::removeEmail( const QString &email )
1549{ 1550{
1550 detach(); 1551 detach();
1551 1552
1552 QStringList::Iterator it = mData->emails.find( email ); 1553 QStringList::Iterator it = mData->emails.find( email );
1553 if ( it == mData->emails.end() ) return; 1554 if ( it == mData->emails.end() ) return;
1554 1555
1555 mData->emails.remove( it ); 1556 mData->emails.remove( it );
1556} 1557}
1557 1558
1558QString Addressee::preferredEmail() const 1559QString Addressee::preferredEmail() const
1559{ 1560{
1560 if ( mData->emails.count() == 0 ) return QString::null; 1561 if ( mData->emails.count() == 0 ) return QString::null;
1561 else return mData->emails.first(); 1562 else return mData->emails.first();
1562} 1563}
1563 1564
1564QStringList Addressee::emails() const 1565QStringList Addressee::emails() const
1565{ 1566{
1566 return mData->emails; 1567 return mData->emails;
1567} 1568}
1568void Addressee::setEmails( const QStringList& emails ) { 1569void Addressee::setEmails( const QStringList& emails ) {
1569 detach(); 1570 detach();
1570 mData->emails = emails; 1571 mData->emails = emails;
1571} 1572}
1572void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1573void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1573{ 1574{
1574 detach(); 1575 detach();
1575 mData->empty = false; 1576 mData->empty = false;
1576 1577
1577 PhoneNumber::List::Iterator it; 1578 PhoneNumber::List::Iterator it;
1578 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1579 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1579 if ( (*it).id() == phoneNumber.id() ) { 1580 if ( (*it).id() == phoneNumber.id() ) {
1580 *it = phoneNumber; 1581 *it = phoneNumber;
1581 return; 1582 return;
1582 } 1583 }
1583 } 1584 }
1584 mData->phoneNumbers.append( phoneNumber ); 1585 mData->phoneNumbers.append( phoneNumber );
1585} 1586}
1586 1587
1587void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1588void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1588{ 1589{
1589 detach(); 1590 detach();
1590 1591
1591 PhoneNumber::List::Iterator it; 1592 PhoneNumber::List::Iterator it;
1592 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1593 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1593 if ( (*it).id() == phoneNumber.id() ) { 1594 if ( (*it).id() == phoneNumber.id() ) {
1594 mData->phoneNumbers.remove( it ); 1595 mData->phoneNumbers.remove( it );
1595 return; 1596 return;
1596 } 1597 }
1597 } 1598 }
1598} 1599}
1599 1600
1600PhoneNumber Addressee::phoneNumber( int type ) const 1601PhoneNumber Addressee::phoneNumber( int type ) const
1601{ 1602{
1602 PhoneNumber phoneNumber( "", type ); 1603 PhoneNumber phoneNumber( "", type );
1603 PhoneNumber::List::ConstIterator it; 1604 PhoneNumber::List::ConstIterator it;
1604 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1605 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1605 if ( matchBinaryPatternP( (*it).type(), type ) ) { 1606 if ( matchBinaryPatternP( (*it).type(), type ) ) {
1606 if ( (*it).type() & PhoneNumber::Pref ) 1607 if ( (*it).type() & PhoneNumber::Pref )
1607 return (*it); 1608 return (*it);
1608 else if ( phoneNumber.number().isEmpty() ) 1609 else if ( phoneNumber.number().isEmpty() )
1609 phoneNumber = (*it); 1610 phoneNumber = (*it);
1610 } 1611 }
1611 } 1612 }
1612 1613
1613 return phoneNumber; 1614 return phoneNumber;
1614} 1615}
1615 1616
1616PhoneNumber::List Addressee::phoneNumbers() const 1617PhoneNumber::List Addressee::phoneNumbers() const
1617{ 1618{
1618 return mData->phoneNumbers; 1619 return mData->phoneNumbers;
1619} 1620}
1620 1621
1621PhoneNumber::List Addressee::phoneNumbers( int type ) const 1622PhoneNumber::List Addressee::phoneNumbers( int type ) const
1622{ 1623{
1623 PhoneNumber::List list; 1624 PhoneNumber::List list;
1624 1625
1625 PhoneNumber::List::ConstIterator it; 1626 PhoneNumber::List::ConstIterator it;
1626 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1627 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1627 if ( matchBinaryPattern( (*it).type(), type ) ) { 1628 if ( matchBinaryPattern( (*it).type(), type ) ) {
1628 list.append( *it ); 1629 list.append( *it );
1629 } 1630 }
1630 } 1631 }
1631 return list; 1632 return list;
1632} 1633}
1633 1634
1634PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1635PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1635{ 1636{
1636 PhoneNumber::List::ConstIterator it; 1637 PhoneNumber::List::ConstIterator it;
1637 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1638 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1638 if ( (*it).id() == id ) { 1639 if ( (*it).id() == id ) {
1639 return *it; 1640 return *it;
1640 } 1641 }
1641 } 1642 }
1642 return PhoneNumber(); 1643 return PhoneNumber();
1643} 1644}
1644 1645
1645void Addressee::insertKey( const Key &key ) 1646void Addressee::insertKey( const Key &key )
1646{ 1647{
1647 detach(); 1648 detach();
1648 mData->empty = false; 1649 mData->empty = false;
1649 1650
1650 Key::List::Iterator it; 1651 Key::List::Iterator it;
1651 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1652 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1652 if ( (*it).id() == key.id() ) { 1653 if ( (*it).id() == key.id() ) {
1653 *it = key; 1654 *it = key;
1654 return; 1655 return;
1655 } 1656 }
1656 } 1657 }
1657 mData->keys.append( key ); 1658 mData->keys.append( key );
1658} 1659}
1659 1660
1660void Addressee::removeKey( const Key &key ) 1661void Addressee::removeKey( const Key &key )
1661{ 1662{
1662 detach(); 1663 detach();
1663 1664
1664 Key::List::Iterator it; 1665 Key::List::Iterator it;
1665 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1666 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1666 if ( (*it).id() == key.id() ) { 1667 if ( (*it).id() == key.id() ) {
1667 mData->keys.remove( key ); 1668 mData->keys.remove( key );
1668 return; 1669 return;
1669 } 1670 }
1670 } 1671 }
1671} 1672}
1672 1673
1673Key Addressee::key( int type, QString customTypeString ) const 1674Key Addressee::key( int type, QString customTypeString ) const
1674{ 1675{
1675 Key::List::ConstIterator it; 1676 Key::List::ConstIterator it;
1676 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1677 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1677 if ( (*it).type() == type ) { 1678 if ( (*it).type() == type ) {
1678 if ( type == Key::Custom ) { 1679 if ( type == Key::Custom ) {
1679 if ( customTypeString.isEmpty() ) { 1680 if ( customTypeString.isEmpty() ) {
1680 return *it; 1681 return *it;
1681 } else { 1682 } else {
1682 if ( (*it).customTypeString() == customTypeString ) 1683 if ( (*it).customTypeString() == customTypeString )
1683 return (*it); 1684 return (*it);
1684 } 1685 }
1685 } else { 1686 } else {
1686 return *it; 1687 return *it;
1687 } 1688 }
1688 } 1689 }
1689 } 1690 }
1690 return Key( QString(), type ); 1691 return Key( QString(), type );
1691} 1692}
1692void Addressee::setKeys( const Key::List& list ) { 1693void Addressee::setKeys( const Key::List& list ) {
1693 detach(); 1694 detach();
1694 mData->keys = list; 1695 mData->keys = list;
1695} 1696}
1696 1697
1697Key::List Addressee::keys() const 1698Key::List Addressee::keys() const
1698{ 1699{
1699 return mData->keys; 1700 return mData->keys;
1700} 1701}
1701 1702
1702Key::List Addressee::keys( int type, QString customTypeString ) const 1703Key::List Addressee::keys( int type, QString customTypeString ) const
1703{ 1704{
1704 Key::List list; 1705 Key::List list;
1705 1706
1706 Key::List::ConstIterator it; 1707 Key::List::ConstIterator it;
1707 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1708 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1708 if ( (*it).type() == type ) { 1709 if ( (*it).type() == type ) {
1709 if ( type == Key::Custom ) { 1710 if ( type == Key::Custom ) {
1710 if ( customTypeString.isEmpty() ) { 1711 if ( customTypeString.isEmpty() ) {
1711 list.append(*it); 1712 list.append(*it);
1712 } else { 1713 } else {
1713 if ( (*it).customTypeString() == customTypeString ) 1714 if ( (*it).customTypeString() == customTypeString )
1714 list.append(*it); 1715 list.append(*it);
1715 } 1716 }
1716 } else { 1717 } else {
1717 list.append(*it); 1718 list.append(*it);
1718 } 1719 }
1719 } 1720 }
1720 } 1721 }
1721 return list; 1722 return list;
1722} 1723}
1723 1724
1724Key Addressee::findKey( const QString &id ) const 1725Key Addressee::findKey( const QString &id ) const
1725{ 1726{
1726 Key::List::ConstIterator it; 1727 Key::List::ConstIterator it;
1727 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1728 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1728 if ( (*it).id() == id ) { 1729 if ( (*it).id() == id ) {
1729 return *it; 1730 return *it;
1730 } 1731 }
1731 } 1732 }
1732 return Key(); 1733 return Key();
1733} 1734}
1734 1735
1735QString Addressee::asString() const 1736QString Addressee::asString() const
1736{ 1737{
1737 return "Smith, agent Smith..."; 1738 return "Smith, agent Smith...";
1738} 1739}
1739 1740
1740void Addressee::dump() const 1741void Addressee::dump() const
1741{ 1742{
1742 return; 1743 return;
1743#if 0 1744#if 0
1744 kdDebug(5700) << "Addressee {" << endl; 1745 kdDebug(5700) << "Addressee {" << endl;
1745 1746
1746 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1747 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1747 1748
1748 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1749 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1749 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1750 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1750 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1751 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1751 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1752 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1752 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1753 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1753 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1754 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1754 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1755 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1755 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1756 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1756 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1757 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1757 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1758 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1758 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1759 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1759 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1760 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1760 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1761 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1761 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1762 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1762 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1763 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1763 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1764 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1764 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1765 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1765 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1766 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1766 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1767 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1767 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1768 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1768 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1769 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1769 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1770 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1770 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1771 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1771 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1772 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1772 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1773 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1773 1774
1774 kdDebug(5700) << " Emails {" << endl; 1775 kdDebug(5700) << " Emails {" << endl;
1775 QStringList e = emails(); 1776 QStringList e = emails();
1776 QStringList::ConstIterator it; 1777 QStringList::ConstIterator it;
1777 for( it = e.begin(); it != e.end(); ++it ) { 1778 for( it = e.begin(); it != e.end(); ++it ) {
1778 kdDebug(5700) << " " << (*it) << endl; 1779 kdDebug(5700) << " " << (*it) << endl;
1779 } 1780 }
1780 kdDebug(5700) << " }" << endl; 1781 kdDebug(5700) << " }" << endl;
1781 1782
1782 kdDebug(5700) << " PhoneNumbers {" << endl; 1783 kdDebug(5700) << " PhoneNumbers {" << endl;
1783 PhoneNumber::List p = phoneNumbers(); 1784 PhoneNumber::List p = phoneNumbers();
1784 PhoneNumber::List::ConstIterator it2; 1785 PhoneNumber::List::ConstIterator it2;
1785 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1786 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1786 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1787 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1787 } 1788 }
1788 kdDebug(5700) << " }" << endl; 1789 kdDebug(5700) << " }" << endl;
1789 1790
1790 Address::List a = addresses(); 1791 Address::List a = addresses();
1791 Address::List::ConstIterator it3; 1792 Address::List::ConstIterator it3;
1792 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1793 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1793 (*it3).dump(); 1794 (*it3).dump();
1794 } 1795 }
1795 1796
1796 kdDebug(5700) << " Keys {" << endl; 1797 kdDebug(5700) << " Keys {" << endl;
1797 Key::List k = keys(); 1798 Key::List k = keys();
1798 Key::List::ConstIterator it4; 1799 Key::List::ConstIterator it4;
1799 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1800 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1800 kdDebug(5700) << " Type: " << int((*it4).type()) << 1801 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1801 " Key: " << (*it4).textData() << 1802 " Key: " << (*it4).textData() <<
1802 " CustomString: " << (*it4).customTypeString() << endl; 1803 " CustomString: " << (*it4).customTypeString() << endl;
1803 } 1804 }
1804 kdDebug(5700) << " }" << endl; 1805 kdDebug(5700) << " }" << endl;
1805 1806
1806 kdDebug(5700) << "}" << endl; 1807 kdDebug(5700) << "}" << endl;
1807#endif 1808#endif
1808} 1809}
1809 1810
1810 1811
1811void Addressee::insertAddress( const Address &address ) 1812void Addressee::insertAddress( const Address &address )
1812{ 1813{
1813 detach(); 1814 detach();
1814 mData->empty = false; 1815 mData->empty = false;
1815 1816
1816 Address::List::Iterator it; 1817 Address::List::Iterator it;
1817 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1818 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1818 if ( (*it).id() == address.id() ) { 1819 if ( (*it).id() == address.id() ) {
1819 *it = address; 1820 *it = address;
1820 return; 1821 return;
1821 } 1822 }
1822 } 1823 }
1823 mData->addresses.append( address ); 1824 mData->addresses.append( address );
1824} 1825}
1825 1826
1826void Addressee::removeAddress( const Address &address ) 1827void Addressee::removeAddress( const Address &address )
1827{ 1828{
1828 detach(); 1829 detach();
1829 1830
1830 Address::List::Iterator it; 1831 Address::List::Iterator it;
1831 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1832 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1832 if ( (*it).id() == address.id() ) { 1833 if ( (*it).id() == address.id() ) {
1833 mData->addresses.remove( it ); 1834 mData->addresses.remove( it );
1834 return; 1835 return;
1835 } 1836 }
1836 } 1837 }
1837} 1838}
1838 1839
1839Address Addressee::address( int type ) const 1840Address Addressee::address( int type ) const
1840{ 1841{
1841 Address address( type ); 1842 Address address( type );
1842 Address::List::ConstIterator it; 1843 Address::List::ConstIterator it;
1843 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1844 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1844 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1845 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1845 if ( (*it).type() & Address::Pref ) 1846 if ( (*it).type() & Address::Pref )
1846 return (*it); 1847 return (*it);
1847 else if ( address.isEmpty() ) 1848 else if ( address.isEmpty() )
1848 address = (*it); 1849 address = (*it);
1849 } 1850 }
1850 } 1851 }
1851 1852
1852 return address; 1853 return address;
1853} 1854}
1854 1855
1855Address::List Addressee::addresses() const 1856Address::List Addressee::addresses() const
1856{ 1857{
1857 return mData->addresses; 1858 return mData->addresses;
1858} 1859}
1859 1860
1860Address::List Addressee::addresses( int type ) const 1861Address::List Addressee::addresses( int type ) const
1861{ 1862{
1862 Address::List list; 1863 Address::List list;
1863 1864
1864 Address::List::ConstIterator it; 1865 Address::List::ConstIterator it;
1865 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1866 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1866 if ( matchBinaryPattern( (*it).type(), type ) ) { 1867 if ( matchBinaryPattern( (*it).type(), type ) ) {
1867 list.append( *it ); 1868 list.append( *it );
1868 } 1869 }
1869 } 1870 }
1870 1871
1871 return list; 1872 return list;
1872} 1873}
1873 1874
1874Address Addressee::findAddress( const QString &id ) const 1875Address Addressee::findAddress( const QString &id ) const
1875{ 1876{
1876 Address::List::ConstIterator it; 1877 Address::List::ConstIterator it;
1877 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1878 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1878 if ( (*it).id() == id ) { 1879 if ( (*it).id() == id ) {
1879 return *it; 1880 return *it;
1880 } 1881 }
1881 } 1882 }
1882 return Address(); 1883 return Address();
1883} 1884}
1884 1885
1885void Addressee::insertCategory( const QString &c ) 1886void Addressee::insertCategory( const QString &c )
1886{ 1887{
1887 detach(); 1888 detach();
1888 mData->empty = false; 1889 mData->empty = false;
1889 1890
1890 if ( mData->categories.contains( c ) ) return; 1891 if ( mData->categories.contains( c ) ) return;
1891 1892
1892 mData->categories.append( c ); 1893 mData->categories.append( c );
1893} 1894}
1894 1895
1895void Addressee::removeCategory( const QString &c ) 1896void Addressee::removeCategory( const QString &c )
1896{ 1897{
1897 detach(); 1898 detach();
1898 1899
1899 QStringList::Iterator it = mData->categories.find( c ); 1900 QStringList::Iterator it = mData->categories.find( c );
1900 if ( it == mData->categories.end() ) return; 1901 if ( it == mData->categories.end() ) return;
1901 1902
1902 mData->categories.remove( it ); 1903 mData->categories.remove( it );
1903} 1904}
1904 1905
1905bool Addressee::hasCategory( const QString &c ) const 1906bool Addressee::hasCategory( const QString &c ) const
1906{ 1907{
1907 return ( mData->categories.contains( c ) ); 1908 return ( mData->categories.contains( c ) );
1908} 1909}
1909 1910
1910void Addressee::setCategories( const QStringList &c ) 1911void Addressee::setCategories( const QStringList &c )
1911{ 1912{
1912 detach(); 1913 detach();
1913 mData->empty = false; 1914 mData->empty = false;
1914 1915
1915 mData->categories = c; 1916 mData->categories = c;
1916} 1917}
1917 1918
1918QStringList Addressee::categories() const 1919QStringList Addressee::categories() const
1919{ 1920{
1920 return mData->categories; 1921 return mData->categories;
1921} 1922}
1922 1923
1923void Addressee::insertCustom( const QString &app, const QString &name, 1924void Addressee::insertCustom( const QString &app, const QString &name,
1924 const QString &value ) 1925 const QString &value )
1925{ 1926{
1926 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1927 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1927 1928
1928 detach(); 1929 detach();
1929 mData->empty = false; 1930 mData->empty = false;
1930 1931
1931 QString qualifiedName = app + "-" + name + ":"; 1932 QString qualifiedName = app + "-" + name + ":";
1932 1933
1933 QStringList::Iterator it; 1934 QStringList::Iterator it;
1934 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1935 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1935 if ( (*it).startsWith( qualifiedName ) ) { 1936 if ( (*it).startsWith( qualifiedName ) ) {
1936 (*it) = qualifiedName + value; 1937 (*it) = qualifiedName + value;
1937 return; 1938 return;
1938 } 1939 }
1939 } 1940 }
1940 mData->custom.append( qualifiedName + value ); 1941 mData->custom.append( qualifiedName + value );
1941} 1942}
1942 1943
1943void Addressee::removeCustom( const QString &app, const QString &name) 1944void Addressee::removeCustom( const QString &app, const QString &name)
1944{ 1945{
1945 detach(); 1946 detach();
1946 1947
1947 QString qualifiedName = app + "-" + name + ":"; 1948 QString qualifiedName = app + "-" + name + ":";
1948 1949
1949 QStringList::Iterator it; 1950 QStringList::Iterator it;
1950 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1951 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1951 if ( (*it).startsWith( qualifiedName ) ) { 1952 if ( (*it).startsWith( qualifiedName ) ) {
1952 mData->custom.remove( it ); 1953 mData->custom.remove( it );
1953 return; 1954 return;
1954 } 1955 }
1955 } 1956 }
1956} 1957}
1957 1958
1958QString Addressee::custom( const QString &app, const QString &name ) const 1959QString Addressee::custom( const QString &app, const QString &name ) const
1959{ 1960{
1960 QString qualifiedName = app + "-" + name + ":"; 1961 QString qualifiedName = app + "-" + name + ":";
1961 QString value; 1962 QString value;
1962 1963
1963 QStringList::ConstIterator it; 1964 QStringList::ConstIterator it;
1964 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1965 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1965 if ( (*it).startsWith( qualifiedName ) ) { 1966 if ( (*it).startsWith( qualifiedName ) ) {
1966 value = (*it).mid( (*it).find( ":" ) + 1 ); 1967 value = (*it).mid( (*it).find( ":" ) + 1 );
1967 break; 1968 break;
1968 } 1969 }
1969 } 1970 }
1970 1971
1971 return value; 1972 return value;
1972} 1973}
1973 1974
1974void Addressee::setCustoms( const QStringList &l ) 1975void Addressee::setCustoms( const QStringList &l )
1975{ 1976{
1976 detach(); 1977 detach();
1977 mData->empty = false; 1978 mData->empty = false;
1978 1979
1979 mData->custom = l; 1980 mData->custom = l;
1980} 1981}
1981 1982
1982QStringList Addressee::customs() const 1983QStringList Addressee::customs() const
1983{ 1984{
1984 return mData->custom; 1985 return mData->custom;
1985} 1986}
1986 1987
1987void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1988void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1988 QString &email) 1989 QString &email)
1989{ 1990{
1990 int startPos, endPos, len; 1991 int startPos, endPos, len;
1991 QString partA, partB, result; 1992 QString partA, partB, result;
1992 char endCh = '>'; 1993 char endCh = '>';
1993 1994
1994 startPos = rawEmail.find('<'); 1995 startPos = rawEmail.find('<');
1995 if (startPos < 0) 1996 if (startPos < 0)
1996 { 1997 {
1997 startPos = rawEmail.find('('); 1998 startPos = rawEmail.find('(');
1998 endCh = ')'; 1999 endCh = ')';
1999 } 2000 }
2000 if (startPos < 0) 2001 if (startPos < 0)
2001 { 2002 {
2002 // We couldn't find any separators, so we assume the whole string 2003 // We couldn't find any separators, so we assume the whole string
2003 // is the email address 2004 // is the email address
2004 email = rawEmail; 2005 email = rawEmail;
2005 fullName = ""; 2006 fullName = "";
2006 } 2007 }
2007 else 2008 else
2008 { 2009 {
2009 // We have a start position, try to find an end 2010 // We have a start position, try to find an end
2010 endPos = rawEmail.find(endCh, startPos+1); 2011 endPos = rawEmail.find(endCh, startPos+1);
2011 2012
2012 if (endPos < 0) 2013 if (endPos < 0)
2013 { 2014 {
2014 // We couldn't find the end of the email address. We can only 2015 // We couldn't find the end of the email address. We can only
2015 // assume the entire string is the email address. 2016 // assume the entire string is the email address.
2016 email = rawEmail; 2017 email = rawEmail;
2017 fullName = ""; 2018 fullName = "";
2018 } 2019 }
2019 else 2020 else
2020 { 2021 {
2021 // We have a start and end to the email address 2022 // We have a start and end to the email address
2022 2023
2023 // Grab the name part 2024 // Grab the name part
2024 fullName = rawEmail.left(startPos).stripWhiteSpace(); 2025 fullName = rawEmail.left(startPos).stripWhiteSpace();
2025 2026
2026 // grab the email part 2027 // grab the email part
2027 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 2028 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
2028 2029
2029 // Check that we do not have any extra characters on the end of the 2030 // Check that we do not have any extra characters on the end of the
2030 // strings 2031 // strings
2031 len = fullName.length(); 2032 len = fullName.length();
2032 if (fullName[0]=='"' && fullName[len-1]=='"') 2033 if (fullName[0]=='"' && fullName[len-1]=='"')
2033 fullName = fullName.mid(1, len-2); 2034 fullName = fullName.mid(1, len-2);
2034 else if (fullName[0]=='<' && fullName[len-1]=='>') 2035 else if (fullName[0]=='<' && fullName[len-1]=='>')
2035 fullName = fullName.mid(1, len-2); 2036 fullName = fullName.mid(1, len-2);
2036 else if (fullName[0]=='(' && fullName[len-1]==')') 2037 else if (fullName[0]=='(' && fullName[len-1]==')')
2037 fullName = fullName.mid(1, len-2); 2038 fullName = fullName.mid(1, len-2);
2038 } 2039 }
2039 } 2040 }
2040} 2041}
2041 2042
2042void Addressee::setResource( Resource *resource ) 2043void Addressee::setResource( Resource *resource )
2043{ 2044{
2044 detach(); 2045 detach();
2045 mData->resource = resource; 2046 mData->resource = resource;
2046} 2047}
2047 2048
2048Resource *Addressee::resource() const 2049Resource *Addressee::resource() const
2049{ 2050{
2050 return mData->resource; 2051 return mData->resource;
2051} 2052}
2052 2053
2053//US 2054//US
2054QString Addressee::resourceLabel() 2055QString Addressee::resourceLabel()
2055{ 2056{
2056 return i18n("Resource"); 2057 return i18n("Resource");
2057} 2058}
2058QString Addressee::categoryLabel() 2059QString Addressee::categoryLabel()
2059{ 2060{
2060 return i18n("Category"); 2061 return i18n("Category");
2061} 2062}
2062 2063
2063void Addressee::setChanged( bool value ) 2064void Addressee::setChanged( bool value )
2064{ 2065{
2065 detach(); 2066 detach();
2066 mData->changed = value; 2067 mData->changed = value;
2067} 2068}
2068 2069
2069bool Addressee::changed() const 2070bool Addressee::changed() const
2070{ 2071{
2071 return mData->changed; 2072 return mData->changed;
2072} 2073}
2073 2074
2074void Addressee::setTagged( bool value ) 2075void Addressee::setTagged( bool value )
2075{ 2076{
2076 detach(); 2077 detach();
2077 mData->tagged = value; 2078 mData->tagged = value;
2078} 2079}
2079 2080
2080bool Addressee::tagged() const 2081bool Addressee::tagged() const
2081{ 2082{
2082 return mData->tagged; 2083 return mData->tagged;
2083} 2084}
2084 2085
2085QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 2086QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
2086{ 2087{
2087 if (!a.mData) return s; 2088 if (!a.mData) return s;
2088 2089
2089 s << a.uid(); 2090 s << a.uid();
2090 2091
2091 s << a.mData->name; 2092 s << a.mData->name;
2092 s << a.mData->formattedName; 2093 s << a.mData->formattedName;
2093 s << a.mData->familyName; 2094 s << a.mData->familyName;
2094 s << a.mData->givenName; 2095 s << a.mData->givenName;
2095 s << a.mData->additionalName; 2096 s << a.mData->additionalName;
2096 s << a.mData->prefix; 2097 s << a.mData->prefix;
2097 s << a.mData->suffix; 2098 s << a.mData->suffix;
2098 s << a.mData->nickName; 2099 s << a.mData->nickName;
2099 s << a.mData->birthday; 2100 s << a.mData->birthday;
2100 s << a.mData->mailer; 2101 s << a.mData->mailer;
2101 s << a.mData->timeZone; 2102 s << a.mData->timeZone;
2102 s << a.mData->geo; 2103 s << a.mData->geo;
2103 s << a.mData->title; 2104 s << a.mData->title;
2104 s << a.mData->role; 2105 s << a.mData->role;
2105 s << a.mData->organization; 2106 s << a.mData->organization;
2106 s << a.mData->note; 2107 s << a.mData->note;
2107 s << a.mData->productId; 2108 s << a.mData->productId;
2108 s << a.mData->revision; 2109 s << a.mData->revision;
2109 s << a.mData->sortString; 2110 s << a.mData->sortString;
2110 s << a.mData->url; 2111 s << a.mData->url;
2111 s << a.mData->secrecy; 2112 s << a.mData->secrecy;
2112 s << a.mData->logo; 2113 s << a.mData->logo;
2113 s << a.mData->photo; 2114 s << a.mData->photo;
2114 s << a.mData->sound; 2115 s << a.mData->sound;
2115 s << a.mData->agent; 2116 s << a.mData->agent;
2116 s << a.mData->phoneNumbers; 2117 s << a.mData->phoneNumbers;
2117 s << a.mData->addresses; 2118 s << a.mData->addresses;
2118 s << a.mData->emails; 2119 s << a.mData->emails;
2119 s << a.mData->categories; 2120 s << a.mData->categories;
2120 s << a.mData->custom; 2121 s << a.mData->custom;
2121 s << a.mData->keys; 2122 s << a.mData->keys;
2122 return s; 2123 return s;
2123} 2124}
2124 2125
2125QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 2126QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
2126{ 2127{
2127 if (!a.mData) return s; 2128 if (!a.mData) return s;
2128 2129
2129 s >> a.mData->uid; 2130 s >> a.mData->uid;
2130 2131
2131 s >> a.mData->name; 2132 s >> a.mData->name;
2132 s >> a.mData->formattedName; 2133 s >> a.mData->formattedName;
2133 s >> a.mData->familyName; 2134 s >> a.mData->familyName;
2134 s >> a.mData->givenName; 2135 s >> a.mData->givenName;
2135 s >> a.mData->additionalName; 2136 s >> a.mData->additionalName;
2136 s >> a.mData->prefix; 2137 s >> a.mData->prefix;
2137 s >> a.mData->suffix; 2138 s >> a.mData->suffix;
2138 s >> a.mData->nickName; 2139 s >> a.mData->nickName;
2139 s >> a.mData->birthday; 2140 s >> a.mData->birthday;
2140 s >> a.mData->mailer; 2141 s >> a.mData->mailer;
2141 s >> a.mData->timeZone; 2142 s >> a.mData->timeZone;
2142 s >> a.mData->geo; 2143 s >> a.mData->geo;
2143 s >> a.mData->title; 2144 s >> a.mData->title;
2144 s >> a.mData->role; 2145 s >> a.mData->role;
2145 s >> a.mData->organization; 2146 s >> a.mData->organization;
2146 s >> a.mData->note; 2147 s >> a.mData->note;
2147 s >> a.mData->productId; 2148 s >> a.mData->productId;
2148 s >> a.mData->revision; 2149 s >> a.mData->revision;
2149 s >> a.mData->sortString; 2150 s >> a.mData->sortString;
2150 s >> a.mData->url; 2151 s >> a.mData->url;
2151 s >> a.mData->secrecy; 2152 s >> a.mData->secrecy;
2152 s >> a.mData->logo; 2153 s >> a.mData->logo;
2153 s >> a.mData->photo; 2154 s >> a.mData->photo;
2154 s >> a.mData->sound; 2155 s >> a.mData->sound;
2155 s >> a.mData->agent; 2156 s >> a.mData->agent;
2156 s >> a.mData->phoneNumbers; 2157 s >> a.mData->phoneNumbers;
2157 s >> a.mData->addresses; 2158 s >> a.mData->addresses;
2158 s >> a.mData->emails; 2159 s >> a.mData->emails;
2159 s >> a.mData->categories; 2160 s >> a.mData->categories;
2160 s >> a.mData->custom; 2161 s >> a.mData->custom;
2161 s >> a.mData->keys; 2162 s >> a.mData->keys;
2162 2163
2163 a.mData->empty = false; 2164 a.mData->empty = false;
2164 2165
2165 return s; 2166 return s;
2166} 2167}
2167bool matchBinaryPattern( int value, int pattern ) 2168bool matchBinaryPattern( int value, int pattern )
2168{ 2169{
2169 /** 2170 /**
2170 We want to match all telephonnumbers/addresses which have the bits in the 2171 We want to match all telephonnumbers/addresses which have the bits in the
2171 pattern set. More are allowed. 2172 pattern set. More are allowed.
2172 if pattern == 0 we have a special handling, then we want only those with 2173 if pattern == 0 we have a special handling, then we want only those with
2173 exactly no bit set. 2174 exactly no bit set.
2174 */ 2175 */
2175 if ( pattern == 0 ) 2176 if ( pattern == 0 )
2176 return ( value == 0 ); 2177 return ( value == 0 );
2177 else 2178 else
2178 return ( pattern == ( pattern & value ) ); 2179 return ( pattern == ( pattern & value ) );
2179} 2180}
2180 2181
2181bool matchBinaryPatternP( int value, int pattern ) 2182bool matchBinaryPatternP( int value, int pattern )
2182{ 2183{
2183 2184
2184 if ( pattern == 0 ) 2185 if ( pattern == 0 )
2185 return ( value == 0 ); 2186 return ( value == 0 );
2186 else 2187 else
2187 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); 2188 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
2188} 2189}
2189bool matchBinaryPatternA( int value, int pattern ) 2190bool matchBinaryPatternA( int value, int pattern )
2190{ 2191{
2191 2192
2192 if ( pattern == 0 ) 2193 if ( pattern == 0 )
2193 return ( value == 0 ); 2194 return ( value == 0 );
2194 else 2195 else
2195 return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); 2196 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
2196} 2197}
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 2b40909..cce68b9 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -1,503 +1,503 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qdragobject.h> 24#include <qdragobject.h>
25#include <qevent.h> 25#include <qevent.h>
26#include <qiconview.h> 26#include <qiconview.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <qregexp.h> 29#include <qregexp.h>
30#include <qapplication.h> 30#include <qapplication.h>
31 31
32#include <kabc/addressbook.h> 32#include <kabc/addressbook.h>
33#include <kabc/addressee.h> 33#include <kabc/addressee.h>
34#include <kconfig.h> 34#include <kconfig.h>
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37 37
38#include "kabprefs.h" 38#include "kabprefs.h"
39#include "viewmanager.h" 39#include "viewmanager.h"
40 40
41 41
42#include "kaddressbookcardview.h" 42#include "kaddressbookcardview.h"
43 43
44#ifndef KAB_EMBEDDED 44#ifndef KAB_EMBEDDED
45extern "C" { 45extern "C" {
46 void *init_libkaddrbk_cardview() 46 void *init_libkaddrbk_cardview()
47 { 47 {
48 return ( new CardViewFactory ); 48 return ( new CardViewFactory );
49 } 49 }
50} 50}
51#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
52 52
53//////////////////////////////// 53////////////////////////////////
54// AddresseeCardViewItem (internal class) 54// AddresseeCardViewItem (internal class)
55class AddresseeCardViewItem : public CardViewItem 55class AddresseeCardViewItem : public CardViewItem
56{ 56{
57 public: 57 public:
58 AddresseeCardViewItem(const KABC::Field::List &fields, 58 AddresseeCardViewItem(const KABC::Field::List &fields,
59 bool showEmptyFields, 59 bool showEmptyFields,
60 KABC::AddressBook *doc, const KABC::Addressee &a, 60 KABC::AddressBook *doc, const KABC::Addressee &a,
61 CardView *parent) 61 CardView *parent)
62 : CardViewItem(parent, a.formattedName()), 62 : CardViewItem(parent, a.realName() ),
63 mFields( fields ), mShowEmptyFields(showEmptyFields), 63 mFields( fields ), mShowEmptyFields(showEmptyFields),
64 mDocument(doc), mAddressee(a) 64 mDocument(doc), mAddressee(a)
65 { 65 {
66 if ( mFields.isEmpty() ) { 66 if ( mFields.isEmpty() ) {
67 mFields = KABC::Field::defaultFields(); 67 mFields = KABC::Field::defaultFields();
68 } 68 }
69 refresh(); 69 refresh();
70 } 70 }
71 71
72 const KABC::Addressee &addressee() const { return mAddressee; } 72 const KABC::Addressee &addressee() const { return mAddressee; }
73 73
74 void refresh() 74 void refresh()
75 { 75 {
76 // Update our addressee, since it may have changed elsewhere 76 // Update our addressee, since it may have changed elsewhere
77 mAddressee = mDocument->findByUid(mAddressee.uid()); 77 mAddressee = mDocument->findByUid(mAddressee.uid());
78 78
79 if (!mAddressee.isEmpty()) 79 if (!mAddressee.isEmpty())
80 { 80 {
81 clearFields(); 81 clearFields();
82 82
83 // Try all the selected fields until we find one with text. 83 // Try all the selected fields until we find one with text.
84 // This will limit the number of unlabeled icons in the view 84 // This will limit the number of unlabeled icons in the view
85 KABC::Field::List::Iterator iter; 85 KABC::Field::List::Iterator iter;
86 for (iter = mFields.begin(); iter != mFields.end(); ++iter) 86 for (iter = mFields.begin(); iter != mFields.end(); ++iter)
87 { 87 {
88 // insert empty fields or not? not doing so saves a bit of memory and CPU 88 // insert empty fields or not? not doing so saves a bit of memory and CPU
89 // (during geometry calculations), but prevents having equally 89 // (during geometry calculations), but prevents having equally
90 // wide label columns in all cards, unless CardViewItem/CardView search 90 // wide label columns in all cards, unless CardViewItem/CardView search
91 // globally for the widest label. (anders) 91 // globally for the widest label. (anders)
92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) 92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
93 insertField((*iter)->label(), (*iter)->value( mAddressee )); 93 insertField((*iter)->label(), (*iter)->value( mAddressee ));
94 } 94 }
95 95
96 // We might want to make this the first field. hmm... -mpilone 96 // We might want to make this the first field. hmm... -mpilone
97 setCaption( mAddressee.realName() ); 97 setCaption( mAddressee.realName() );
98 } 98 }
99 } 99 }
100 100
101 private: 101 private:
102 KABC::Field::List mFields; 102 KABC::Field::List mFields;
103 bool mShowEmptyFields; 103 bool mShowEmptyFields;
104 KABC::AddressBook *mDocument; 104 KABC::AddressBook *mDocument;
105 KABC::Addressee mAddressee; 105 KABC::Addressee mAddressee;
106}; 106};
107 107
108/////////////////////////////// 108///////////////////////////////
109// AddresseeCardView 109// AddresseeCardView
110 110
111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
112 : CardView(parent, name) 112 : CardView(parent, name)
113{ 113{
114 setAcceptDrops(true); 114 setAcceptDrops(true);
115} 115}
116 116
117AddresseeCardView::~AddresseeCardView() 117AddresseeCardView::~AddresseeCardView()
118{ 118{
119} 119}
120void AddresseeCardView::printMe() 120void AddresseeCardView::printMe()
121{ 121{
122#ifdef DESKTOP_VERSION 122#ifdef DESKTOP_VERSION
123 QPrinter printer; 123 QPrinter printer;
124 if (!printer.setup() ) 124 if (!printer.setup() )
125 return; 125 return;
126 QPainter p; 126 QPainter p;
127 p.begin ( &printer ); 127 p.begin ( &printer );
128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
129 float dx, dy; 129 float dx, dy;
130 int wid = (m.width() * 9)/10; 130 int wid = (m.width() * 9)/10;
131 dx = (float) wid/(float)contentsWidth (); 131 dx = (float) wid/(float)contentsWidth ();
132 dy = (float)(m.height()) / (float)contentsHeight (); 132 dy = (float)(m.height()) / (float)contentsHeight ();
133 float scale; 133 float scale;
134 // scale to fit the width or height of the paper 134 // scale to fit the width or height of the paper
135 if ( dx < dy ) 135 if ( dx < dy )
136 scale = dx; 136 scale = dx;
137 else 137 else
138 scale = dy; 138 scale = dy;
139 p.translate( m.width()/10,0 ); 139 p.translate( m.width()/10,0 );
140 p.scale( scale, scale ); 140 p.scale( scale, scale );
141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); 141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
142 p.end(); 142 p.end();
143 repaint(); 143 repaint();
144#endif 144#endif
145} 145}
146 146
147 147
148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
149{ 149{
150#ifndef KAB_EMBEDDED 150#ifndef KAB_EMBEDDED
151 if (QTextDrag::canDecode(e)) 151 if (QTextDrag::canDecode(e))
152 e->accept(); 152 e->accept();
153#else //KAB_EMBEDDED 153#else //KAB_EMBEDDED
154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
155#endif //KAB_EMBEDDED 155#endif //KAB_EMBEDDED
156} 156}
157 157
158void AddresseeCardView::dropEvent(QDropEvent *e) 158void AddresseeCardView::dropEvent(QDropEvent *e)
159{ 159{
160 emit addresseeDropped(e); 160 emit addresseeDropped(e);
161} 161}
162 162
163void AddresseeCardView::startDrag() 163void AddresseeCardView::startDrag()
164{ 164{
165 emit startAddresseeDrag(); 165 emit startAddresseeDrag();
166} 166}
167 167
168 168
169/////////////////////////////// 169///////////////////////////////
170// KAddressBookCardView 170// KAddressBookCardView
171 171
172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, 172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
173 QWidget *parent, const char *name ) 173 QWidget *parent, const char *name )
174 : KAddressBookView( ab, parent, name ) 174 : KAddressBookView( ab, parent, name )
175{ 175{
176 mShowEmptyFields = false; 176 mShowEmptyFields = false;
177 177
178 // Init the GUI 178 // Init the GUI
179 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 179 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
180 180
181 mCardView = new AddresseeCardView(viewWidget(), "mCardView"); 181 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
182 mCardView->setSelectionMode(CardView::Extended); 182 mCardView->setSelectionMode(CardView::Extended);
183 layout->addWidget(mCardView); 183 layout->addWidget(mCardView);
184 184
185 // Connect up the signals 185 // Connect up the signals
186 connect(mCardView, SIGNAL(executed(CardViewItem *)), 186 connect(mCardView, SIGNAL(executed(CardViewItem *)),
187 this, SLOT(addresseeExecuted(CardViewItem *))); 187 this, SLOT(addresseeExecuted(CardViewItem *)));
188 connect(mCardView, SIGNAL(selectionChanged()), 188 connect(mCardView, SIGNAL(selectionChanged()),
189 this, SLOT(addresseeSelected())); 189 this, SLOT(addresseeSelected()));
190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), 190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
191 this, SIGNAL(dropped(QDropEvent*))); 191 this, SIGNAL(dropped(QDropEvent*)));
192 connect(mCardView, SIGNAL(startAddresseeDrag()), 192 connect(mCardView, SIGNAL(startAddresseeDrag()),
193 this, SIGNAL(startDrag())); 193 this, SIGNAL(startDrag()));
194 connect(this, SIGNAL(printView()), 194 connect(this, SIGNAL(printView()),
195 mCardView , SLOT(printMe())); 195 mCardView , SLOT(printMe()));
196} 196}
197 197
198KAddressBookCardView::~KAddressBookCardView() 198KAddressBookCardView::~KAddressBookCardView()
199{ 199{
200} 200}
201void KAddressBookCardView::setFocusAV() 201void KAddressBookCardView::setFocusAV()
202{ 202{
203 if ( mCardView ) 203 if ( mCardView )
204 mCardView->setFocus(); 204 mCardView->setFocus();
205 205
206} 206}
207void KAddressBookCardView::scrollUP() 207void KAddressBookCardView::scrollUP()
208{ 208{
209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
210 QApplication::postEvent( mCardView, ev ); 210 QApplication::postEvent( mCardView, ev );
211 211
212} 212}
213void KAddressBookCardView::scrollDOWN() 213void KAddressBookCardView::scrollDOWN()
214{ 214{
215 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 215 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
216 QApplication::postEvent( mCardView, ev ); 216 QApplication::postEvent( mCardView, ev );
217} 217}
218void KAddressBookCardView::readConfig(KConfig *config) 218void KAddressBookCardView::readConfig(KConfig *config)
219{ 219{
220 KAddressBookView::readConfig(config); 220 KAddressBookView::readConfig(config);
221 221
222 // costum colors? 222 // costum colors?
223 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 223 if ( config->readBoolEntry( "EnableCustomColors", false ) )
224 { 224 {
225 QPalette p( mCardView->palette() ); 225 QPalette p( mCardView->palette() );
226 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 226 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
227 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 227 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
228 c = p.color(QPalette::Normal, QColorGroup::Text ); 228 c = p.color(QPalette::Normal, QColorGroup::Text );
229 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 229 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
230 c = p.color(QPalette::Normal, QColorGroup::Button ); 230 c = p.color(QPalette::Normal, QColorGroup::Button );
231 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 231 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
232 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 232 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
233 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 233 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
234 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 234 c = p.color(QPalette::Normal, QColorGroup::Highlight );
235 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 235 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
236 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 236 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
237 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 237 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
238 mCardView->viewport()->setPalette( p ); 238 mCardView->viewport()->setPalette( p );
239 } 239 }
240 else 240 else
241 { 241 {
242 // needed if turned off during a session. 242 // needed if turned off during a session.
243 mCardView->viewport()->setPalette( mCardView->palette() ); 243 mCardView->viewport()->setPalette( mCardView->palette() );
244 } 244 }
245 245
246 //custom fonts? 246 //custom fonts?
247 QFont f( font() ); 247 QFont f( font() );
248 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 248 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
249 { 249 {
250 mCardView->setFont( config->readFontEntry( "TextFont", &f) ); 250 mCardView->setFont( config->readFontEntry( "TextFont", &f) );
251 f.setBold( true ); 251 f.setBold( true );
252 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 252 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
253 } 253 }
254 else 254 else
255 { 255 {
256 mCardView->setFont( f ); 256 mCardView->setFont( f );
257 f.setBold( true ); 257 f.setBold( true );
258 mCardView->setHeaderFont( f ); 258 mCardView->setHeaderFont( f );
259 } 259 }
260 260
261 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); 261 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
262 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", 262 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
263 true)); 263 true));
264 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); 264 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
265 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); 265 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
266 266
267 mCardView->setShowEmptyFields( mShowEmptyFields ); 267 mCardView->setShowEmptyFields( mShowEmptyFields );
268 268
269 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); 269 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
270 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); 270 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
271 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); 271 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
272 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); 272 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
273 273
274#if 0 274#if 0
275 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven 275 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven
276 disconnect(mCardView, SIGNAL(executed(CardViewItem *)), 276 disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
277 this, SLOT(addresseeExecuted(CardViewItem *))); 277 this, SLOT(addresseeExecuted(CardViewItem *)));
278 278
279 if (KABPrefs::instance()->mHonorSingleClick) 279 if (KABPrefs::instance()->mHonorSingleClick)
280 connect(mCardView, SIGNAL(executed(CardViewItem *)), 280 connect(mCardView, SIGNAL(executed(CardViewItem *)),
281 this, SLOT(addresseeExecuted(CardViewItem *))); 281 this, SLOT(addresseeExecuted(CardViewItem *)));
282 else 282 else
283 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 283 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
284 this, SLOT(addresseeExecuted(CardViewItem *))); 284 this, SLOT(addresseeExecuted(CardViewItem *)));
285#endif 285#endif
286 286
287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
288 this, SLOT(addresseeExecuted(CardViewItem *))); 288 this, SLOT(addresseeExecuted(CardViewItem *)));
289} 289}
290 290
291void KAddressBookCardView::writeConfig( KConfig *config ) 291void KAddressBookCardView::writeConfig( KConfig *config )
292{ 292{
293 config->writeEntry( "ItemWidth", mCardView->itemWidth() ); 293 config->writeEntry( "ItemWidth", mCardView->itemWidth() );
294 KAddressBookView::writeConfig( config ); 294 KAddressBookView::writeConfig( config );
295} 295}
296void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) 296void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
297{ 297{
298 mCardView->clear(); 298 mCardView->clear();
299 if ( s.isEmpty() || s == "*" ) { 299 if ( s.isEmpty() || s == "*" ) {
300 refresh(); 300 refresh();
301 return; 301 return;
302 } 302 }
303 QRegExp re = getRegExp( s ); 303 QRegExp re = getRegExp( s );
304 if (!re.isValid()) 304 if (!re.isValid())
305 return; 305 return;
306 mCardView->viewport()->setUpdatesEnabled( false ); 306 mCardView->viewport()->setUpdatesEnabled( false );
307 KABC::Addressee::List addresseeList = addressees(); 307 KABC::Addressee::List addresseeList = addressees();
308 KABC::Addressee::List::Iterator it; 308 KABC::Addressee::List::Iterator it;
309 if ( field ) { 309 if ( field ) {
310 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 310 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
311 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 311 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
312 continue; 312 continue;
313#if QT_VERSION >= 0x030000 313#if QT_VERSION >= 0x030000
314 if (re.search(field->value( *it ).lower()) != -1) 314 if (re.search(field->value( *it ).lower()) != -1)
315#else 315#else
316 if (re.match(field->value( *it ).lower()) != -1) 316 if (re.match(field->value( *it ).lower()) != -1)
317#endif 317#endif
318 new AddresseeCardViewItem(fields(), mShowEmptyFields, 318 new AddresseeCardViewItem(fields(), mShowEmptyFields,
319 addressBook(), *it, mCardView); 319 addressBook(), *it, mCardView);
320 320
321 } 321 }
322 } else { 322 } else {
323 KABC::Field::List fieldList = allFields(); 323 KABC::Field::List fieldList = allFields();
324 KABC::Field::List::ConstIterator fieldIt; 324 KABC::Field::List::ConstIterator fieldIt;
325 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 325 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
326 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 326 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
327 continue; 327 continue;
328 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 328 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
329#if QT_VERSION >= 0x030000 329#if QT_VERSION >= 0x030000
330 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 330 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
331#else 331#else
332 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 332 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
333#endif 333#endif
334 { 334 {
335 new AddresseeCardViewItem(fields(), mShowEmptyFields, 335 new AddresseeCardViewItem(fields(), mShowEmptyFields,
336 addressBook(), *it, mCardView); 336 addressBook(), *it, mCardView);
337 break; 337 break;
338 } 338 }
339 } 339 }
340 } 340 }
341 } 341 }
342 mCardView->viewport()->setUpdatesEnabled( true ); 342 mCardView->viewport()->setUpdatesEnabled( true );
343 mCardView->viewport()->update(); 343 mCardView->viewport()->update();
344 if ( mCardView->firstItem() ) { 344 if ( mCardView->firstItem() ) {
345 mCardView->setCurrentItem ( mCardView->firstItem() ); 345 mCardView->setCurrentItem ( mCardView->firstItem() );
346 mCardView->setSelected ( mCardView->firstItem() , true ); 346 mCardView->setSelected ( mCardView->firstItem() , true );
347 } 347 }
348 else 348 else
349 emit selected(QString::null); 349 emit selected(QString::null);
350} 350}
351QStringList KAddressBookCardView::selectedUids() 351QStringList KAddressBookCardView::selectedUids()
352{ 352{
353 QStringList uidList; 353 QStringList uidList;
354 CardViewItem *item; 354 CardViewItem *item;
355 AddresseeCardViewItem *aItem; 355 AddresseeCardViewItem *aItem;
356 356
357 for (item = mCardView->firstItem(); item; item = item->nextItem()) 357 for (item = mCardView->firstItem(); item; item = item->nextItem())
358 { 358 {
359 if (item->isSelected()) 359 if (item->isSelected())
360 { 360 {
361#ifndef KAB_EMBEDDED 361#ifndef KAB_EMBEDDED
362 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 362 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
363#else //KAB_EMBEDDED 363#else //KAB_EMBEDDED
364 aItem = (AddresseeCardViewItem*)(item); 364 aItem = (AddresseeCardViewItem*)(item);
365#endif //KAB_EMBEDDED 365#endif //KAB_EMBEDDED
366 if (aItem) 366 if (aItem)
367 uidList << aItem->addressee().uid(); 367 uidList << aItem->addressee().uid();
368 } 368 }
369 } 369 }
370 370
371 return uidList; 371 return uidList;
372} 372}
373 373
374void KAddressBookCardView::refresh(QString uid) 374void KAddressBookCardView::refresh(QString uid)
375{ 375{
376 CardViewItem *item; 376 CardViewItem *item;
377 AddresseeCardViewItem *aItem; 377 AddresseeCardViewItem *aItem;
378 378
379 if (uid.isNull()) 379 if (uid.isNull())
380 { 380 {
381 // Rebuild the view 381 // Rebuild the view
382 mCardView->viewport()->setUpdatesEnabled( false ); 382 mCardView->viewport()->setUpdatesEnabled( false );
383 mCardView->clear(); 383 mCardView->clear();
384 384
385 KABC::Addressee::List addresseeList = addressees(); 385 KABC::Addressee::List addresseeList = addressees();
386 KABC::Addressee::List::Iterator iter; 386 KABC::Addressee::List::Iterator iter;
387 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) 387 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
388 { 388 {
389 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) 389 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
390 continue; 390 continue;
391 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, 391 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
392 addressBook(), *iter, mCardView); 392 addressBook(), *iter, mCardView);
393 } 393 }
394 mCardView->viewport()->setUpdatesEnabled( true ); 394 mCardView->viewport()->setUpdatesEnabled( true );
395 mCardView->viewport()->update(); 395 mCardView->viewport()->update();
396 396
397 // by default nothing is selected 397 // by default nothing is selected
398 emit selected(QString::null); 398 emit selected(QString::null);
399 } 399 }
400 else 400 else
401 { 401 {
402 // Try to find the one to refresh 402 // Try to find the one to refresh
403 bool found = false; 403 bool found = false;
404 for (item = mCardView->firstItem(); item && !found; 404 for (item = mCardView->firstItem(); item && !found;
405 item = item->nextItem()) 405 item = item->nextItem())
406 { 406 {
407#ifndef KAB_EMBEDDED 407#ifndef KAB_EMBEDDED
408 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 408 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
409#else //KAB_EMBEDDED 409#else //KAB_EMBEDDED
410 aItem = (AddresseeCardViewItem*)(item); 410 aItem = (AddresseeCardViewItem*)(item);
411#endif //KAB_EMBEDDED 411#endif //KAB_EMBEDDED
412 412
413 if ((aItem) && (aItem->addressee().uid() == uid)) 413 if ((aItem) && (aItem->addressee().uid() == uid))
414 { 414 {
415 aItem->refresh(); 415 aItem->refresh();
416 found = true; 416 found = true;
417 } 417 }
418 } 418 }
419 } 419 }
420} 420}
421 421
422void KAddressBookCardView::setSelected(QString uid, bool selected) 422void KAddressBookCardView::setSelected(QString uid, bool selected)
423{ 423{
424 CardViewItem *item; 424 CardViewItem *item;
425 AddresseeCardViewItem *aItem; 425 AddresseeCardViewItem *aItem;
426 426
427 if (uid.isNull()) 427 if (uid.isNull())
428 { 428 {
429 mCardView->selectAll(selected); 429 mCardView->selectAll(selected);
430 } 430 }
431 else 431 else
432 { 432 {
433 bool found = false; 433 bool found = false;
434 for (item = mCardView->firstItem(); item && !found; 434 for (item = mCardView->firstItem(); item && !found;
435 item = item->nextItem()) 435 item = item->nextItem())
436 { 436 {
437#ifndef KAB_EMBEDDED 437#ifndef KAB_EMBEDDED
438 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 438 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
439#else //KAB_EMBEDDED 439#else //KAB_EMBEDDED
440 aItem = (AddresseeCardViewItem*)(item); 440 aItem = (AddresseeCardViewItem*)(item);
441#endif //KAB_EMBEDDED 441#endif //KAB_EMBEDDED
442 442
443 if ((aItem) && (aItem->addressee().uid() == uid)) 443 if ((aItem) && (aItem->addressee().uid() == uid))
444 { 444 {
445 mCardView->setSelected(aItem, selected); 445 mCardView->setSelected(aItem, selected);
446 mCardView->ensureItemVisible(item); 446 mCardView->ensureItemVisible(item);
447 found = true; 447 found = true;
448 } 448 }
449 } 449 }
450 } 450 }
451} 451}
452 452
453//US added an additional method without parameter 453//US added an additional method without parameter
454void KAddressBookCardView::setSelected() 454void KAddressBookCardView::setSelected()
455{ 455{
456 setSelected(QString::null, true); 456 setSelected(QString::null, true);
457} 457}
458 458
459void KAddressBookCardView::addresseeExecuted(CardViewItem *item) 459void KAddressBookCardView::addresseeExecuted(CardViewItem *item)
460{ 460{
461#ifndef KAB_EMBEDDED 461#ifndef KAB_EMBEDDED
462 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); 462 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item);
463#else //KAB_EMBEDDED 463#else //KAB_EMBEDDED
464 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); 464 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item);
465#endif //KAB_EMBEDDED 465#endif //KAB_EMBEDDED
466 if (aItem) 466 if (aItem)
467 { 467 {
468 //kdDebug()<<"... even has a valid item:)"<<endl; 468 //kdDebug()<<"... even has a valid item:)"<<endl;
469 emit executed(aItem->addressee().uid()); 469 emit executed(aItem->addressee().uid());
470 } 470 }
471} 471}
472 472
473void KAddressBookCardView::addresseeSelected() 473void KAddressBookCardView::addresseeSelected()
474{ 474{
475 CardViewItem *item; 475 CardViewItem *item;
476 AddresseeCardViewItem *aItem; 476 AddresseeCardViewItem *aItem;
477 477
478 bool found = false; 478 bool found = false;
479 for (item = mCardView->firstItem(); item && !found; 479 for (item = mCardView->firstItem(); item && !found;
480 item = item->nextItem()) 480 item = item->nextItem())
481 { 481 {
482 if (item->isSelected()) 482 if (item->isSelected())
483 { 483 {
484#ifndef KAB_EMBEDDED 484#ifndef KAB_EMBEDDED
485 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 485 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
486#else //KAB_EMBEDDED 486#else //KAB_EMBEDDED
487 aItem = (AddresseeCardViewItem*)(item); 487 aItem = (AddresseeCardViewItem*)(item);
488#endif //KAB_EMBEDDED 488#endif //KAB_EMBEDDED
489 if ( aItem ) 489 if ( aItem )
490 { 490 {
491 emit selected(aItem->addressee().uid()); 491 emit selected(aItem->addressee().uid());
492 found = true; 492 found = true;
493 } 493 }
494 } 494 }
495 } 495 }
496 496
497 if (!found) 497 if (!found)
498 emit selected(QString::null); 498 emit selected(QString::null);
499 499
500} 500}
501#ifndef KAB_EMBEDDED 501#ifndef KAB_EMBEDDED
502#include "kaddressbookcardview.moc" 502#include "kaddressbookcardview.moc"
503#endif //KAB_EMBEDDED 503#endif //KAB_EMBEDDED
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index cf0d1ee..810c889 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -1,1676 +1,1686 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> 2 Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org>
3 Copyright (C) 1999 Stephan Kulow <coolo@kde.org> 3 Copyright (C) 1999 Stephan Kulow <coolo@kde.org>
4 Copyright (C) 1999 Waldo Bastian <bastian@kde.org> 4 Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation. 8 License version 2 as published by the Free Software Foundation.
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/*
22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> 22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org>
23 * Version:$Id$ 23 * Version:$Id$
24 * Generated:Thu Mar 5 16:05:28 EST 1998 24 * Generated:Thu Mar 5 16:05:28 EST 1998
25 */ 25 */
26 26
27//US #include "config.h" 27//US #include "config.h"
28 28
29#include <stdlib.h> 29#include <stdlib.h>
30#include <assert.h> 30#include <assert.h>
31//US#include <errno.h> 31//US#include <errno.h>
32//US #ifdef HAVE_SYS_STAT_H 32//US #ifdef HAVE_SYS_STAT_H
33//US #include <sys/stat.h> 33//US #include <sys/stat.h>
34//US #endif 34//US #endif
35//US#include <sys/types.h> 35//US#include <sys/types.h>
36//US#include <dirent.h> 36//US#include <dirent.h>
37//US#include <pwd.h> 37//US#include <pwd.h>
38 38
39#include <qregexp.h> 39#include <qregexp.h>
40#include <qasciidict.h> 40#include <qasciidict.h>
41#include <qdict.h> 41#include <qdict.h>
42#include <qdir.h> 42#include <qdir.h>
43#include <qfileinfo.h> 43#include <qfileinfo.h>
44#include <qstring.h> 44#include <qstring.h>
45#include <qmessagebox.h> 45#include <qmessagebox.h>
46#include <qapplication.h> 46#include <qapplication.h>
47 47
48#include <qstringlist.h> 48#include <qstringlist.h>
49 49
50#include "kstandarddirs.h" 50#include "kstandarddirs.h"
51#include "kconfig.h" 51#include "kconfig.h"
52#include "kdebug.h" 52#include "kdebug.h"
53//US #include "kinstance.h" 53//US #include "kinstance.h"
54#include "kshell.h" 54#include "kshell.h"
55//US#include <sys/param.h> 55//US#include <sys/param.h>
56//US#include <unistd.h> 56//US#include <unistd.h>
57 57
58//US 58//US
59QString KStandardDirs::mAppDir = QString::null; 59QString KStandardDirs::mAppDir = QString::null;
60 60
61 61
62template class QDict<QStringList>; 62template class QDict<QStringList>;
63 63
64#if 0 64#if 0
65#include <qtextedit.h> 65#include <qtextedit.h>
66void ddd( QString op ) 66void ddd( QString op )
67{ 67{
68 static QTextEdit * dot = 0; 68 static QTextEdit * dot = 0;
69 if ( ! dot ) 69 if ( ! dot )
70 dot = new QTextEdit(); 70 dot = new QTextEdit();
71 71
72 dot->show(); 72 dot->show();
73 73
74 dot->append( op ); 74 dot->append( op );
75 75
76} 76}
77#endif 77#endif
78class KStandardDirs::KStandardDirsPrivate 78class KStandardDirs::KStandardDirsPrivate
79{ 79{
80public: 80public:
81 KStandardDirsPrivate() 81 KStandardDirsPrivate()
82 : restrictionsActive(false), 82 : restrictionsActive(false),
83 dataRestrictionActive(false) 83 dataRestrictionActive(false)
84 { } 84 { }
85 85
86 bool restrictionsActive; 86 bool restrictionsActive;
87 bool dataRestrictionActive; 87 bool dataRestrictionActive;
88 QAsciiDict<bool> restrictions; 88 QAsciiDict<bool> restrictions;
89 QStringList xdgdata_prefixes; 89 QStringList xdgdata_prefixes;
90 QStringList xdgconf_prefixes; 90 QStringList xdgconf_prefixes;
91}; 91};
92 92
93static const char* const types[] = {"html", "icon", "apps", "sound", 93static const char* const types[] = {"html", "icon", "apps", "sound",
94 "data", "locale", "services", "mime", 94 "data", "locale", "services", "mime",
95 "servicetypes", "config", "exe", "tmp", 95 "servicetypes", "config", "exe", "tmp",
96 "wallpaper", "lib", "pixmap", "templates", 96 "wallpaper", "lib", "pixmap", "templates",
97 "module", "qtplugins", 97 "module", "qtplugins",
98 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; 98 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 };
99 99
100static int tokenize( QStringList& token, const QString& str, 100static int tokenize( QStringList& token, const QString& str,
101 const QString& delim ); 101 const QString& delim );
102 102
103KStandardDirs::KStandardDirs( ) : addedCustoms(false) 103KStandardDirs::KStandardDirs( ) : addedCustoms(false)
104{ 104{
105 d = new KStandardDirsPrivate; 105 d = new KStandardDirsPrivate;
106 dircache.setAutoDelete(true); 106 dircache.setAutoDelete(true);
107 relatives.setAutoDelete(true); 107 relatives.setAutoDelete(true);
108 absolutes.setAutoDelete(true); 108 absolutes.setAutoDelete(true);
109 savelocations.setAutoDelete(true); 109 savelocations.setAutoDelete(true);
110 addKDEDefaults(); 110 addKDEDefaults();
111} 111}
112 112
113KStandardDirs::~KStandardDirs() 113KStandardDirs::~KStandardDirs()
114{ 114{
115 delete d; 115 delete d;
116} 116}
117 117
118bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const 118bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const
119{ 119{
120 if (!d || !d->restrictionsActive) 120 if (!d || !d->restrictionsActive)
121 return false; 121 return false;
122 122
123 if (d->restrictions[type]) 123 if (d->restrictions[type])
124 return true; 124 return true;
125 125
126 if (strcmp(type, "data")==0) 126 if (strcmp(type, "data")==0)
127 { 127 {
128 applyDataRestrictions(relPath); 128 applyDataRestrictions(relPath);
129 if (d->dataRestrictionActive) 129 if (d->dataRestrictionActive)
130 { 130 {
131 d->dataRestrictionActive = false; 131 d->dataRestrictionActive = false;
132 return true; 132 return true;
133 } 133 }
134 } 134 }
135 return false; 135 return false;
136} 136}
137 137
138void KStandardDirs::applyDataRestrictions(const QString &relPath) const 138void KStandardDirs::applyDataRestrictions(const QString &relPath) const
139{ 139{
140 QString key; 140 QString key;
141 int i = relPath.find('/'); 141 int i = relPath.find('/');
142 if (i != -1) 142 if (i != -1)
143 key = "data_"+relPath.left(i); 143 key = "data_"+relPath.left(i);
144 else 144 else
145 key = "data_"+relPath; 145 key = "data_"+relPath;
146 146
147 if (d && d->restrictions[key.latin1()]) 147 if (d && d->restrictions[key.latin1()])
148 d->dataRestrictionActive = true; 148 d->dataRestrictionActive = true;
149} 149}
150 150
151 151
152QStringList KStandardDirs::allTypes() const 152QStringList KStandardDirs::allTypes() const
153{ 153{
154 QStringList list; 154 QStringList list;
155 for (int i = 0; types[i] != 0; ++i) 155 for (int i = 0; types[i] != 0; ++i)
156 list.append(QString::fromLatin1(types[i])); 156 list.append(QString::fromLatin1(types[i]));
157 return list; 157 return list;
158} 158}
159 159
160void KStandardDirs::addPrefix( const QString& _dir ) 160void KStandardDirs::addPrefix( const QString& _dir )
161{ 161{
162 if (_dir.isNull()) 162 if (_dir.isNull())
163 return; 163 return;
164 164
165 QString dir = _dir; 165 QString dir = _dir;
166 if (dir.at(dir.length() - 1) != '/') 166 if (dir.at(dir.length() - 1) != '/')
167 dir += '/'; 167 dir += '/';
168 168
169 if (!prefixes.contains(dir)) { 169 if (!prefixes.contains(dir)) {
170 prefixes.append(dir); 170 prefixes.append(dir);
171 dircache.clear(); 171 dircache.clear();
172 } 172 }
173} 173}
174 174
175void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) 175void KStandardDirs::addXdgConfigPrefix( const QString& _dir )
176{ 176{
177 if (_dir.isNull()) 177 if (_dir.isNull())
178 return; 178 return;
179 179
180 QString dir = _dir; 180 QString dir = _dir;
181 if (dir.at(dir.length() - 1) != '/') 181 if (dir.at(dir.length() - 1) != '/')
182 dir += '/'; 182 dir += '/';
183 183
184 if (!d->xdgconf_prefixes.contains(dir)) { 184 if (!d->xdgconf_prefixes.contains(dir)) {
185 d->xdgconf_prefixes.append(dir); 185 d->xdgconf_prefixes.append(dir);
186 dircache.clear(); 186 dircache.clear();
187 } 187 }
188} 188}
189 189
190void KStandardDirs::addXdgDataPrefix( const QString& _dir ) 190void KStandardDirs::addXdgDataPrefix( const QString& _dir )
191{ 191{
192 if (_dir.isNull()) 192 if (_dir.isNull())
193 return; 193 return;
194 194
195 QString dir = _dir; 195 QString dir = _dir;
196 if (dir.at(dir.length() - 1) != '/') 196 if (dir.at(dir.length() - 1) != '/')
197 dir += '/'; 197 dir += '/';
198 198
199 if (!d->xdgdata_prefixes.contains(dir)) { 199 if (!d->xdgdata_prefixes.contains(dir)) {
200 d->xdgdata_prefixes.append(dir); 200 d->xdgdata_prefixes.append(dir);
201 dircache.clear(); 201 dircache.clear();
202 } 202 }
203} 203}
204 204
205 205
206QString KStandardDirs::kfsstnd_prefixes() 206QString KStandardDirs::kfsstnd_prefixes()
207{ 207{
208 return prefixes.join(":"); 208 return prefixes.join(":");
209} 209}
210 210
211bool KStandardDirs::addResourceType( const char *type, 211bool KStandardDirs::addResourceType( const char *type,
212 const QString& relativename ) 212 const QString& relativename )
213{ 213{
214 if (relativename.isNull()) 214 if (relativename.isNull())
215 return false; 215 return false;
216 216
217 QStringList *rels = relatives.find(type); 217 QStringList *rels = relatives.find(type);
218 if (!rels) { 218 if (!rels) {
219 rels = new QStringList(); 219 rels = new QStringList();
220 relatives.insert(type, rels); 220 relatives.insert(type, rels);
221 } 221 }
222 QString copy = relativename; 222 QString copy = relativename;
223 if (copy.at(copy.length() - 1) != '/') 223 if (copy.at(copy.length() - 1) != '/')
224 copy += '/'; 224 copy += '/';
225 if (!rels->contains(copy)) { 225 if (!rels->contains(copy)) {
226 rels->prepend(copy); 226 rels->prepend(copy);
227 dircache.remove(type); // clean the cache 227 dircache.remove(type); // clean the cache
228 return true; 228 return true;
229 } 229 }
230 return false; 230 return false;
231} 231}
232 232
233bool KStandardDirs::addResourceDir( const char *type, 233bool KStandardDirs::addResourceDir( const char *type,
234 const QString& absdir) 234 const QString& absdir)
235{ 235{
236 QStringList *paths = absolutes.find(type); 236 QStringList *paths = absolutes.find(type);
237 if (!paths) { 237 if (!paths) {
238 paths = new QStringList(); 238 paths = new QStringList();
239 absolutes.insert(type, paths); 239 absolutes.insert(type, paths);
240 } 240 }
241 QString copy = absdir; 241 QString copy = absdir;
242 if (copy.at(copy.length() - 1) != '/') 242 if (copy.at(copy.length() - 1) != '/')
243 copy += '/'; 243 copy += '/';
244 244
245 if (!paths->contains(copy)) { 245 if (!paths->contains(copy)) {
246 paths->append(copy); 246 paths->append(copy);
247 dircache.remove(type); // clean the cache 247 dircache.remove(type); // clean the cache
248 return true; 248 return true;
249 } 249 }
250 return false; 250 return false;
251} 251}
252 252
253QString KStandardDirs::findResource( const char *type, 253QString KStandardDirs::findResource( const char *type,
254 const QString& filename ) const 254 const QString& filename ) const
255{ 255{
256 if (filename.at(0) == '/') 256 if (filename.at(0) == '/')
257 return filename; // absolute dirs are absolute dirs, right? :-/ 257 return filename; // absolute dirs are absolute dirs, right? :-/
258 258
259#if 0 259#if 0
260kdDebug() << "Find resource: " << type << endl; 260kdDebug() << "Find resource: " << type << endl;
261for (QStringList::ConstIterator pit = prefixes.begin(); 261for (QStringList::ConstIterator pit = prefixes.begin();
262 pit != prefixes.end(); 262 pit != prefixes.end();
263 pit++) 263 pit++)
264{ 264{
265 kdDebug() << "Prefix: " << *pit << endl; 265 kdDebug() << "Prefix: " << *pit << endl;
266} 266}
267#endif 267#endif
268 268
269 QString dir = findResourceDir(type, filename); 269 QString dir = findResourceDir(type, filename);
270 if (dir.isNull()) 270 if (dir.isNull())
271 return dir; 271 return dir;
272 else return dir + filename; 272 else return dir + filename;
273} 273}
274/*US 274/*US
275static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash) 275static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash)
276{ 276{
277 QCString cFile = QFile::encodeName(file); 277 QCString cFile = QFile::encodeName(file);
278//US struct stat buff; 278//US struct stat buff;
279//US if ((access(cFile, R_OK) == 0) && 279//US if ((access(cFile, R_OK) == 0) &&
280//US (stat( cFile, &buff ) == 0) && 280//US (stat( cFile, &buff ) == 0) &&
281//US (S_ISREG( buff.st_mode ))) 281//US (S_ISREG( buff.st_mode )))
282 QFileInfo pathfnInfo(cFile); 282 QFileInfo pathfnInfo(cFile);
283 if (( pathfnInfo.isReadable() == true ) && 283 if (( pathfnInfo.isReadable() == true ) &&
284 ( pathfnInfo.isFile()) ) 284 ( pathfnInfo.isFile()) )
285 { 285 {
286//US hash = hash + (Q_UINT32) buff.st_ctime; 286//US hash = hash + (Q_UINT32) buff.st_ctime;
287 hash = hash + (Q_UINT32) pathfnInfo.lastModified(); 287 hash = hash + (Q_UINT32) pathfnInfo.lastModified();
288 } 288 }
289 return hash; 289 return hash;
290} 290}
291*/ 291*/
292/*US 292/*US
293Q_UINT32 KStandardDirs::calcResourceHash( const char *type, 293Q_UINT32 KStandardDirs::calcResourceHash( const char *type,
294 const QString& filename, bool deep) const 294 const QString& filename, bool deep) const
295{ 295{
296 Q_UINT32 hash = 0; 296 Q_UINT32 hash = 0;
297 297
298 if (filename.at(0) == '/') 298 if (filename.at(0) == '/')
299 { 299 {
300 // absolute dirs are absolute dirs, right? :-/ 300 // absolute dirs are absolute dirs, right? :-/
301 return updateHash(filename, hash); 301 return updateHash(filename, hash);
302 } 302 }
303 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 303 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
304 applyDataRestrictions(filename); 304 applyDataRestrictions(filename);
305 QStringList candidates = resourceDirs(type); 305 QStringList candidates = resourceDirs(type);
306 QString fullPath; 306 QString fullPath;
307 307
308 for (QStringList::ConstIterator it = candidates.begin(); 308 for (QStringList::ConstIterator it = candidates.begin();
309 it != candidates.end(); it++) 309 it != candidates.end(); it++)
310 { 310 {
311 hash = updateHash(*it + filename, hash); 311 hash = updateHash(*it + filename, hash);
312 if (!deep && hash) 312 if (!deep && hash)
313 return hash; 313 return hash;
314 } 314 }
315 return hash; 315 return hash;
316} 316}
317*/ 317*/
318 318
319QStringList KStandardDirs::findDirs( const char *type, 319QStringList KStandardDirs::findDirs( const char *type,
320 const QString& reldir ) const 320 const QString& reldir ) const
321{ 321{
322 QStringList list; 322 QStringList list;
323 323
324 checkConfig(); 324 checkConfig();
325 325
326 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 326 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
327 applyDataRestrictions(reldir); 327 applyDataRestrictions(reldir);
328 QStringList candidates = resourceDirs(type); 328 QStringList candidates = resourceDirs(type);
329 QDir testdir; 329 QDir testdir;
330 330
331 for (QStringList::ConstIterator it = candidates.begin(); 331 for (QStringList::ConstIterator it = candidates.begin();
332 it != candidates.end(); it++) { 332 it != candidates.end(); it++) {
333 testdir.setPath(*it + reldir); 333 testdir.setPath(*it + reldir);
334 if (testdir.exists()) 334 if (testdir.exists())
335 list.append(testdir.absPath() + '/'); 335 list.append(testdir.absPath() + '/');
336 } 336 }
337 337
338 return list; 338 return list;
339} 339}
340 340
341QString KStandardDirs::findResourceDir( const char *type, 341QString KStandardDirs::findResourceDir( const char *type,
342 const QString& filename) const 342 const QString& filename) const
343{ 343{
344#ifndef NDEBUG 344#ifndef NDEBUG
345 if (filename.isEmpty()) { 345 if (filename.isEmpty()) {
346 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl; 346 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl;
347 return QString::null; 347 return QString::null;
348 } 348 }
349#endif 349#endif
350 350
351 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 351 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
352 applyDataRestrictions(filename); 352 applyDataRestrictions(filename);
353 QStringList candidates = resourceDirs(type); 353 QStringList candidates = resourceDirs(type);
354 QString fullPath; 354 QString fullPath;
355#ifdef DESKTOP_VERSION 355#ifdef DESKTOP_VERSION
356#ifdef _WIN32_ 356#ifdef _WIN32_
357 candidates.prepend( qApp->applicationDirPath () +"\\"); 357 candidates.prepend( qApp->applicationDirPath () +"\\");
358#else 358#else
359 candidates.prepend( qApp->applicationDirPath () +"/"); 359 candidates.prepend( qApp->applicationDirPath () +"/");
360#endif 360#endif
361#endif 361#endif
362 for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) 362 for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++)
363 { 363 {
364 //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1()); 364 //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1());
365 if (exists(*it + filename)) 365 if (exists(*it + filename))
366 return *it; 366 return *it;
367 } 367 }
368 368
369#ifndef NDEBUG 369#ifndef NDEBUG
370 if(false && type != "locale") 370 if(false && type != "locale")
371 qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1()); 371 qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1());
372 372
373#endif 373#endif
374 374
375 return QString::null; 375 return QString::null;
376} 376}
377 377
378bool KStandardDirs::exists(const QString &fullPath) 378bool KStandardDirs::exists(const QString &fullPath)
379{ 379{
380//US struct stat buff; 380//US struct stat buff;
381 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 381 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
382 382
383//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) 383//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable())
384 if (fullPathInfo.isReadable()) 384 if (fullPathInfo.isReadable())
385 { 385 {
386 if (fullPath.at(fullPath.length() - 1) != '/') { 386 if (fullPath.at(fullPath.length() - 1) != '/') {
387 //US if (S_ISREG( buff.st_mode )) 387 //US if (S_ISREG( buff.st_mode ))
388 if (fullPathInfo.isFile()) 388 if (fullPathInfo.isFile())
389 return true; 389 return true;
390 } 390 }
391 else { 391 else {
392 //US if (S_ISDIR( buff.st_mode )) 392 //US if (S_ISDIR( buff.st_mode ))
393 if (fullPathInfo.isDir()) 393 if (fullPathInfo.isDir())
394 return true; 394 return true;
395 } 395 }
396 } 396 }
397 return false; 397 return false;
398} 398}
399 399
400static void lookupDirectory(const QString& path, const QString &relPart, 400static void lookupDirectory(const QString& path, const QString &relPart,
401 const QRegExp &regexp, 401 const QRegExp &regexp,
402 QStringList& list, 402 QStringList& list,
403 QStringList& relList, 403 QStringList& relList,
404 bool recursive, bool uniq) 404 bool recursive, bool uniq)
405{ 405{
406 QString pattern = regexp.pattern(); 406 QString pattern = regexp.pattern();
407 if (recursive || pattern.contains('?') || pattern.contains('*')) 407 if (recursive || pattern.contains('?') || pattern.contains('*'))
408 { 408 {
409 // We look for a set of files. 409 // We look for a set of files.
410//US DIR *dp = opendir( QFile::encodeName(path)); 410//US DIR *dp = opendir( QFile::encodeName(path));
411 QDir dp(QFile::encodeName(path)); 411 QDir dp(QFile::encodeName(path));
412 412
413 if (!dp.exists()) 413 if (!dp.exists())
414 return; 414 return;
415 static int iii = 0; 415 static int iii = 0;
416 ++iii; 416 ++iii;
417 if ( iii == 5 ) 417 if ( iii == 5 )
418 abort(); 418 abort();
419 assert(path.at(path.length() - 1) == '/'); 419 assert(path.at(path.length() - 1) == '/');
420 420
421//US struct dirent *ep; 421//US struct dirent *ep;
422//US struct stat buff; 422//US struct stat buff;
423 423
424 QString _dot("."); 424 QString _dot(".");
425 QString _dotdot(".."); 425 QString _dotdot("..");
426 426
427//US while( ( ep = readdir( dp ) ) != 0L ) 427//US while( ( ep = readdir( dp ) ) != 0L )
428 QStringList direntries = dp.entryList(); 428 QStringList direntries = dp.entryList();
429 QStringList::Iterator it = direntries.begin(); 429 QStringList::Iterator it = direntries.begin();
430 430
431 while ( it != list.end() ) // for each file... 431 while ( it != list.end() ) // for each file...
432 { 432 {
433 433
434//US QString fn( QFile::decodeName(ep->d_name)); 434//US QString fn( QFile::decodeName(ep->d_name));
435 QString fn = (*it); // dp.entryList already decodes 435 QString fn = (*it); // dp.entryList already decodes
436 it++; 436 it++;
437 if ( fn.isNull() ) 437 if ( fn.isNull() )
438 break; 438 break;
439 439
440 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) 440 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' )
441 continue; 441 continue;
442 442
443/*US 443/*US
444 if (!recursive && !regexp.exactMatch(fn)) 444 if (!recursive && !regexp.exactMatch(fn))
445 continue; // No match 445 continue; // No match
446*/ 446*/
447//US this should do the same: 447//US this should do the same:
448 int pos = regexp.match(fn); 448 int pos = regexp.match(fn);
449 if (!recursive && !pos == 0) 449 if (!recursive && !pos == 0)
450 continue; // No match 450 continue; // No match
451 451
452 QString pathfn = path + fn; 452 QString pathfn = path + fn;
453/*US 453/*US
454 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { 454 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) {
455 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 455 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
456 continue; // Couldn't stat (e.g. no read permissions) 456 continue; // Couldn't stat (e.g. no read permissions)
457 } 457 }
458 458
459 if ( recursive ) 459 if ( recursive )
460 { 460 {
461 if ( S_ISDIR( buff.st_mode )) { 461 if ( S_ISDIR( buff.st_mode )) {
462 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 462 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
463 } 463 }
464*/ 464*/
465//US replacement: 465//US replacement:
466 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 466 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
467 if ( pathfnInfo.isReadable() == false ) 467 if ( pathfnInfo.isReadable() == false )
468 { 468 {
469//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 469//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
470 continue; // Couldn't stat (e.g. no read permissions) 470 continue; // Couldn't stat (e.g. no read permissions)
471 } 471 }
472 472
473 if ( recursive ) 473 if ( recursive )
474 { 474 {
475 if ( pathfnInfo.isDir()) { 475 if ( pathfnInfo.isDir()) {
476 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 476 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
477 } 477 }
478 478
479 479
480/*US 480/*US
481 if (!regexp.exactMatch(fn)) 481 if (!regexp.exactMatch(fn))
482 continue; // No match 482 continue; // No match
483*/ 483*/
484//US this should do the same: 484//US this should do the same:
485 pos = regexp.match(fn); 485 pos = regexp.match(fn);
486 if (!pos == 0) 486 if (!pos == 0)
487 continue; // No match 487 continue; // No match
488 } 488 }
489 489
490//US if ( S_ISREG( buff.st_mode)) 490//US if ( S_ISREG( buff.st_mode))
491 if ( pathfnInfo.isFile()) 491 if ( pathfnInfo.isFile())
492 { 492 {
493 if (!uniq || !relList.contains(relPart + fn)) 493 if (!uniq || !relList.contains(relPart + fn))
494 { 494 {
495 list.append( pathfn ); 495 list.append( pathfn );
496 relList.append( relPart + fn ); 496 relList.append( relPart + fn );
497 } 497 }
498 } 498 }
499 } 499 }
500//US closedir( dp ); 500//US closedir( dp );
501 } 501 }
502 else 502 else
503 { 503 {
504 // We look for a single file. 504 // We look for a single file.
505 QString fn = pattern; 505 QString fn = pattern;
506 QString pathfn = path + fn; 506 QString pathfn = path + fn;
507//US struct stat buff; 507//US struct stat buff;
508 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 508 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
509 509
510 510
511//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) 511//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 )
512 if ( pathfnInfo.isReadable() == false ) 512 if ( pathfnInfo.isReadable() == false )
513 return; // File not found 513 return; // File not found
514 514
515//US if ( S_ISREG( buff.st_mode)) 515//US if ( S_ISREG( buff.st_mode))
516 if ( pathfnInfo.isFile()) 516 if ( pathfnInfo.isFile())
517 { 517 {
518 if (!uniq || !relList.contains(relPart + fn)) 518 if (!uniq || !relList.contains(relPart + fn))
519 { 519 {
520 list.append( pathfn ); 520 list.append( pathfn );
521 relList.append( relPart + fn ); 521 relList.append( relPart + fn );
522 } 522 }
523 } 523 }
524 } 524 }
525} 525}
526 526
527static void lookupPrefix(const QString& prefix, const QString& relpath, 527static void lookupPrefix(const QString& prefix, const QString& relpath,
528 const QString& relPart, 528 const QString& relPart,
529 const QRegExp &regexp, 529 const QRegExp &regexp,
530 QStringList& list, 530 QStringList& list,
531 QStringList& relList, 531 QStringList& relList,
532 bool recursive, bool uniq) 532 bool recursive, bool uniq)
533{ 533{
534 if (relpath.isNull()) { 534 if (relpath.isNull()) {
535 lookupDirectory(prefix, relPart, regexp, list, 535 lookupDirectory(prefix, relPart, regexp, list,
536 relList, recursive, uniq); 536 relList, recursive, uniq);
537 return; 537 return;
538 } 538 }
539 QString path; 539 QString path;
540 QString rest; 540 QString rest;
541 541
542 if (relpath.length()) 542 if (relpath.length())
543 { 543 {
544 int slash = relpath.find('/'); 544 int slash = relpath.find('/');
545 if (slash < 0) 545 if (slash < 0)
546 rest = relpath.left(relpath.length() - 1); 546 rest = relpath.left(relpath.length() - 1);
547 else { 547 else {
548 path = relpath.left(slash); 548 path = relpath.left(slash);
549 rest = relpath.mid(slash + 1); 549 rest = relpath.mid(slash + 1);
550 } 550 }
551 } 551 }
552 assert(prefix.at(prefix.length() - 1) == '/'); 552 assert(prefix.at(prefix.length() - 1) == '/');
553 553
554//US struct stat buff; 554//US struct stat buff;
555 555
556 if (path.contains('*') || path.contains('?')) { 556 if (path.contains('*') || path.contains('?')) {
557 QRegExp pathExp(path, true, true); 557 QRegExp pathExp(path, true, true);
558 //USDIR *dp = opendir( QFile::encodeName(prefix) ); 558 //USDIR *dp = opendir( QFile::encodeName(prefix) );
559 QDir dp(QFile::encodeName(prefix)); 559 QDir dp(QFile::encodeName(prefix));
560 560
561 //USif (!dp) 561 //USif (!dp)
562 if (!dp.exists()) 562 if (!dp.exists())
563 { 563 {
564 return; 564 return;
565 } 565 }
566 566
567 //USstruct dirent *ep; 567 //USstruct dirent *ep;
568 568
569 QString _dot("."); 569 QString _dot(".");
570 QString _dotdot(".."); 570 QString _dotdot("..");
571 571
572 //USwhile( ( ep = readdir( dp ) ) != 0L ) 572 //USwhile( ( ep = readdir( dp ) ) != 0L )
573 QStringList direntries = dp.entryList(); 573 QStringList direntries = dp.entryList();
574 QStringList::Iterator it = direntries.begin(); 574 QStringList::Iterator it = direntries.begin();
575 575
576 while ( it != list.end() ) // for each file... 576 while ( it != list.end() ) // for each file...
577 { 577 {
578//US QString fn( QFile::decodeName(ep->d_name)); 578//US QString fn( QFile::decodeName(ep->d_name));
579 QString fn = (*it); // dp.entryList() already encodes the strings 579 QString fn = (*it); // dp.entryList() already encodes the strings
580 it++; 580 it++;
581 581
582 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') 582 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~')
583 continue; 583 continue;
584 584
585#ifdef DESKTOP_VERSION 585#ifdef DESKTOP_VERSION
586 586
587 if (pathExp.search(fn) == -1) 587 if (pathExp.search(fn) == -1)
588 continue; // No match 588 continue; // No match
589 589
590#else 590#else
591//US this should do the same: 591//US this should do the same:
592 if (pathExp.find(fn, 0) == -1) 592 if (pathExp.find(fn, 0) == -1)
593 continue; // No match 593 continue; // No match
594#endif 594#endif
595 QString rfn = relPart+fn; 595 QString rfn = relPart+fn;
596 fn = prefix + fn; 596 fn = prefix + fn;
597//US if ( stat( QFile::encodeName(fn), &buff ) != 0 ) 597//US if ( stat( QFile::encodeName(fn), &buff ) != 0 )
598 QFileInfo fnInfo(QFile::encodeName(fn)); 598 QFileInfo fnInfo(QFile::encodeName(fn));
599 if ( fnInfo.isReadable() == false ) 599 if ( fnInfo.isReadable() == false )
600 { 600 {
601//US kdDebug() << "Error statting " << fn << " : " << perror << endl; 601//US kdDebug() << "Error statting " << fn << " : " << perror << endl;
602 continue; // Couldn't stat (e.g. no permissions) 602 continue; // Couldn't stat (e.g. no permissions)
603 } 603 }
604 //US if ( S_ISDIR( buff.st_mode )) 604 //US if ( S_ISDIR( buff.st_mode ))
605 if ( fnInfo.isDir() ) 605 if ( fnInfo.isDir() )
606 606
607 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq); 607 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq);
608 } 608 }
609 609
610 //USclosedir( dp ); 610 //USclosedir( dp );
611 } else { 611 } else {
612 // Don't stat, if the dir doesn't exist we will find out 612 // Don't stat, if the dir doesn't exist we will find out
613 // when we try to open it. 613 // when we try to open it.
614 lookupPrefix(prefix + path + '/', rest, 614 lookupPrefix(prefix + path + '/', rest,
615 relPart + path + '/', regexp, list, 615 relPart + path + '/', regexp, list,
616 relList, recursive, uniq); 616 relList, recursive, uniq);
617 } 617 }
618} 618}
619 619
620QStringList 620QStringList
621KStandardDirs::findAllResources( const char *type, 621KStandardDirs::findAllResources( const char *type,
622 const QString& filter, 622 const QString& filter,
623 bool recursive, 623 bool recursive,
624 bool uniq, 624 bool uniq,
625 QStringList &relList) const 625 QStringList &relList) const
626{ 626{
627 QStringList list; 627 QStringList list;
628 if (filter.at(0) == '/') // absolute paths we return 628 if (filter.at(0) == '/') // absolute paths we return
629 { 629 {
630 list.append( filter); 630 list.append( filter);
631 return list; 631 return list;
632 } 632 }
633 633
634 QString filterPath; 634 QString filterPath;
635 QString filterFile; 635 QString filterFile;
636 636
637 if (filter.length()) 637 if (filter.length())
638 { 638 {
639 int slash = filter.findRev('/'); 639 int slash = filter.findRev('/');
640 if (slash < 0) 640 if (slash < 0)
641 filterFile = filter; 641 filterFile = filter;
642 else { 642 else {
643 filterPath = filter.left(slash + 1); 643 filterPath = filter.left(slash + 1);
644 filterFile = filter.mid(slash + 1); 644 filterFile = filter.mid(slash + 1);
645 } 645 }
646 } 646 }
647 checkConfig(); 647 checkConfig();
648 648
649 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 649 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
650 applyDataRestrictions(filter); 650 applyDataRestrictions(filter);
651 QStringList candidates = resourceDirs(type); 651 QStringList candidates = resourceDirs(type);
652 if (filterFile.isEmpty()) 652 if (filterFile.isEmpty())
653 filterFile = "*"; 653 filterFile = "*";
654 654
655 QRegExp regExp(filterFile, true, true); 655 QRegExp regExp(filterFile, true, true);
656 for (QStringList::ConstIterator it = candidates.begin(); 656 for (QStringList::ConstIterator it = candidates.begin();
657 it != candidates.end(); it++) 657 it != candidates.end(); it++)
658 { 658 {
659 lookupPrefix(*it, filterPath, "", regExp, list, 659 lookupPrefix(*it, filterPath, "", regExp, list,
660 relList, recursive, uniq); 660 relList, recursive, uniq);
661 } 661 }
662 return list; 662 return list;
663} 663}
664 664
665QStringList 665QStringList
666KStandardDirs::findAllResources( const char *type, 666KStandardDirs::findAllResources( const char *type,
667 const QString& filter, 667 const QString& filter,
668 bool recursive, 668 bool recursive,
669 bool uniq) const 669 bool uniq) const
670{ 670{
671 QStringList relList; 671 QStringList relList;
672 return findAllResources(type, filter, recursive, uniq, relList); 672 return findAllResources(type, filter, recursive, uniq, relList);
673} 673}
674 674
675QString 675QString
676KStandardDirs::realPath(const QString &dirname) 676KStandardDirs::realPath(const QString &dirname)
677{ 677{
678#ifdef _WIN32_ 678#ifdef _WIN32_
679 return dirname; 679 return dirname;
680#else 680#else
681//US char realpath_buffer[MAXPATHLEN + 1]; 681//US char realpath_buffer[MAXPATHLEN + 1];
682//US memset(realpath_buffer, 0, MAXPATHLEN + 1); 682//US memset(realpath_buffer, 0, MAXPATHLEN + 1);
683 char realpath_buffer[250 + 1]; 683 char realpath_buffer[250 + 1];
684 memset(realpath_buffer, 0, 250 + 1); 684 memset(realpath_buffer, 0, 250 + 1);
685 685
686 /* If the path contains symlinks, get the real name */ 686 /* If the path contains symlinks, get the real name */
687 if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) { 687 if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) {
688 // succes, use result from realpath 688 // succes, use result from realpath
689 int len = strlen(realpath_buffer); 689 int len = strlen(realpath_buffer);
690 realpath_buffer[len] = '/'; 690 realpath_buffer[len] = '/';
691 realpath_buffer[len+1] = 0; 691 realpath_buffer[len+1] = 0;
692 return QFile::decodeName(realpath_buffer); 692 return QFile::decodeName(realpath_buffer);
693 } 693 }
694 694
695 return dirname; 695 return dirname;
696#endif 696#endif
697} 697}
698/*US 698/*US
699void KStandardDirs::createSpecialResource(const char *type) 699void KStandardDirs::createSpecialResource(const char *type)
700{ 700{
701 char hostname[256]; 701 char hostname[256];
702 hostname[0] = 0; 702 hostname[0] = 0;
703 gethostname(hostname, 255); 703 gethostname(hostname, 255);
704 QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); 704 QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname);
705 char link[1024]; 705 char link[1024];
706 link[1023] = 0; 706 link[1023] = 0;
707 int result = readlink(QFile::encodeName(dir).data(), link, 1023); 707 int result = readlink(QFile::encodeName(dir).data(), link, 1023);
708 if ((result == -1) && (errno == ENOENT)) 708 if ((result == -1) && (errno == ENOENT))
709 { 709 {
710 QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); 710 QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin"));
711 if (srv.isEmpty()) 711 if (srv.isEmpty())
712 srv = findExe(QString::fromLatin1("lnusertemp")); 712 srv = findExe(QString::fromLatin1("lnusertemp"));
713 if (!srv.isEmpty()) 713 if (!srv.isEmpty())
714 { 714 {
715 system(QFile::encodeName(srv)+" "+type); 715 system(QFile::encodeName(srv)+" "+type);
716 result = readlink(QFile::encodeName(dir).data(), link, 1023); 716 result = readlink(QFile::encodeName(dir).data(), link, 1023);
717 } 717 }
718 } 718 }
719 if (result > 0) 719 if (result > 0)
720 { 720 {
721 link[result] = 0; 721 link[result] = 0;
722 if (link[0] == '/') 722 if (link[0] == '/')
723 dir = QFile::decodeName(link); 723 dir = QFile::decodeName(link);
724 else 724 else
725 dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); 725 dir = QDir::cleanDirPath(dir+QFile::decodeName(link));
726 } 726 }
727 addResourceDir(type, dir+'/'); 727 addResourceDir(type, dir+'/');
728} 728}
729*/ 729*/
730 730
731QStringList KStandardDirs::resourceDirs(const char *type) const 731QStringList KStandardDirs::resourceDirs(const char *type) const
732{ 732{
733 QStringList *candidates = dircache.find(type); 733 QStringList *candidates = dircache.find(type);
734 734
735 if (!candidates) { // filling cache 735 if (!candidates) { // filling cache
736/*US 736/*US
737 if (strcmp(type, "socket") == 0) 737 if (strcmp(type, "socket") == 0)
738 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 738 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
739 else if (strcmp(type, "tmp") == 0) 739 else if (strcmp(type, "tmp") == 0)
740 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 740 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
741 else if (strcmp(type, "cache") == 0) 741 else if (strcmp(type, "cache") == 0)
742 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 742 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
743*/ 743*/
744 QDir testdir; 744 QDir testdir;
745 745
746 candidates = new QStringList(); 746 candidates = new QStringList();
747 QStringList *dirs; 747 QStringList *dirs;
748 748
749 bool restrictionActive = false; 749 bool restrictionActive = false;
750 if (d && d->restrictionsActive) 750 if (d && d->restrictionsActive)
751 { 751 {
752 if (d->dataRestrictionActive) 752 if (d->dataRestrictionActive)
753 restrictionActive = true; 753 restrictionActive = true;
754 else if (d->restrictions["all"]) 754 else if (d->restrictions["all"])
755 restrictionActive = true; 755 restrictionActive = true;
756 else if (d->restrictions[type]) 756 else if (d->restrictions[type])
757 restrictionActive = true; 757 restrictionActive = true;
758 d->dataRestrictionActive = false; // Reset 758 d->dataRestrictionActive = false; // Reset
759 } 759 }
760 760
761 dirs = relatives.find(type); 761 dirs = relatives.find(type);
762 if (dirs) 762 if (dirs)
763 { 763 {
764 bool local = true; 764 bool local = true;
765 const QStringList *prefixList = 0; 765 const QStringList *prefixList = 0;
766 if (strncmp(type, "xdgdata-", 8) == 0) 766 if (strncmp(type, "xdgdata-", 8) == 0)
767 prefixList = &(d->xdgdata_prefixes); 767 prefixList = &(d->xdgdata_prefixes);
768 else if (strncmp(type, "xdgconf-", 8) == 0) 768 else if (strncmp(type, "xdgconf-", 8) == 0)
769 prefixList = &(d->xdgconf_prefixes); 769 prefixList = &(d->xdgconf_prefixes);
770 else 770 else
771 prefixList = &prefixes; 771 prefixList = &prefixes;
772 772
773 for (QStringList::ConstIterator pit = prefixList->begin(); 773 for (QStringList::ConstIterator pit = prefixList->begin();
774 pit != prefixList->end(); 774 pit != prefixList->end();
775 pit++) 775 pit++)
776 { 776 {
777 for (QStringList::ConstIterator it = dirs->begin(); 777 for (QStringList::ConstIterator it = dirs->begin();
778 it != dirs->end(); ++it) { 778 it != dirs->end(); ++it) {
779 QString path = realPath(*pit + *it); 779 QString path = realPath(*pit + *it);
780 testdir.setPath(path); 780 testdir.setPath(path);
781 if (local && restrictionActive) 781 if (local && restrictionActive)
782 continue; 782 continue;
783 if ((local || testdir.exists()) && !candidates->contains(path)) 783 if ((local || testdir.exists()) && !candidates->contains(path))
784 candidates->append(path); 784 candidates->append(path);
785 } 785 }
786 local = false; 786 local = false;
787 } 787 }
788 } 788 }
789 dirs = absolutes.find(type); 789 dirs = absolutes.find(type);
790 if (dirs) 790 if (dirs)
791 for (QStringList::ConstIterator it = dirs->begin(); 791 for (QStringList::ConstIterator it = dirs->begin();
792 it != dirs->end(); ++it) 792 it != dirs->end(); ++it)
793 { 793 {
794 testdir.setPath(*it); 794 testdir.setPath(*it);
795 if (testdir.exists()) 795 if (testdir.exists())
796 { 796 {
797 QString filename = realPath(*it); 797 QString filename = realPath(*it);
798 if (!candidates->contains(filename)) 798 if (!candidates->contains(filename))
799 candidates->append(filename); 799 candidates->append(filename);
800 } 800 }
801 } 801 }
802 dircache.insert(type, candidates); 802 dircache.insert(type, candidates);
803 } 803 }
804 804
805#if 0 805#if 0
806 kdDebug() << "found dirs for resource " << type << ":" << endl; 806 kdDebug() << "found dirs for resource " << type << ":" << endl;
807 for (QStringList::ConstIterator pit = candidates->begin(); 807 for (QStringList::ConstIterator pit = candidates->begin();
808 pit != candidates->end(); 808 pit != candidates->end();
809 pit++) 809 pit++)
810 { 810 {
811 fprintf(stderr, "%s\n", (*pit).latin1()); 811 fprintf(stderr, "%s\n", (*pit).latin1());
812 } 812 }
813#endif 813#endif
814 814
815 815
816 return *candidates; 816 return *candidates;
817} 817}
818 818
819/*US 819/*US
820QString KStandardDirs::findExe( const QString& appname, 820QString KStandardDirs::findExe( const QString& appname,
821 const QString& pstr, bool ignore) 821 const QString& pstr, bool ignore)
822{ 822{
823 QFileInfo info; 823 QFileInfo info;
824 824
825 // absolute path ? 825 // absolute path ?
826 if (appname.startsWith(QString::fromLatin1("/"))) 826 if (appname.startsWith(QString::fromLatin1("/")))
827 { 827 {
828 info.setFile( appname ); 828 info.setFile( appname );
829 if( info.exists() && ( ignore || info.isExecutable() ) 829 if( info.exists() && ( ignore || info.isExecutable() )
830 && info.isFile() ) { 830 && info.isFile() ) {
831 return appname; 831 return appname;
832 } 832 }
833 return QString::null; 833 return QString::null;
834 } 834 }
835 835
836//US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname); 836//US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname);
837 QString p = QString("%1/%2").arg(appname).arg(appname); 837 QString p = QString("%1/%2").arg(appname).arg(appname);
838 qDebug("KStandardDirs::findExe this is probably wrong"); 838 qDebug("KStandardDirs::findExe this is probably wrong");
839 839
840 info.setFile( p ); 840 info.setFile( p );
841 if( info.exists() && ( ignore || info.isExecutable() ) 841 if( info.exists() && ( ignore || info.isExecutable() )
842 && ( info.isFile() || info.isSymLink() ) ) { 842 && ( info.isFile() || info.isSymLink() ) ) {
843 return p; 843 return p;
844 } 844 }
845 845
846 QStringList tokens; 846 QStringList tokens;
847 p = pstr; 847 p = pstr;
848 848
849 if( p.isNull() ) { 849 if( p.isNull() ) {
850 p = getenv( "PATH" ); 850 p = getenv( "PATH" );
851 } 851 }
852 852
853 tokenize( tokens, p, ":\b" ); 853 tokenize( tokens, p, ":\b" );
854 854
855 // split path using : or \b as delimiters 855 // split path using : or \b as delimiters
856 for( unsigned i = 0; i < tokens.count(); i++ ) { 856 for( unsigned i = 0; i < tokens.count(); i++ ) {
857 p = tokens[ i ]; 857 p = tokens[ i ];
858 858
859 if ( p[ 0 ] == '~' ) 859 if ( p[ 0 ] == '~' )
860 { 860 {
861 int len = p.find( '/' ); 861 int len = p.find( '/' );
862 if ( len == -1 ) 862 if ( len == -1 )
863 len = p.length(); 863 len = p.length();
864 if ( len == 1 ) 864 if ( len == 1 )
865 p.replace( 0, 1, QDir::homeDirPath() ); 865 p.replace( 0, 1, QDir::homeDirPath() );
866 else 866 else
867 { 867 {
868 QString user = p.mid( 1, len - 1 ); 868 QString user = p.mid( 1, len - 1 );
869 struct passwd *dir = getpwnam( user.local8Bit().data() ); 869 struct passwd *dir = getpwnam( user.local8Bit().data() );
870 if ( dir && strlen( dir->pw_dir ) ) 870 if ( dir && strlen( dir->pw_dir ) )
871 p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) ); 871 p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) );
872 } 872 }
873 } 873 }
874 874
875 p += "/"; 875 p += "/";
876 p += appname; 876 p += appname;
877 877
878 // Check for executable in this tokenized path 878 // Check for executable in this tokenized path
879 info.setFile( p ); 879 info.setFile( p );
880 880
881 if( info.exists() && ( ignore || info.isExecutable() ) 881 if( info.exists() && ( ignore || info.isExecutable() )
882 && ( info.isFile() || info.isSymLink() ) ) { 882 && ( info.isFile() || info.isSymLink() ) ) {
883 return p; 883 return p;
884 } 884 }
885 } 885 }
886 886
887 // If we reach here, the executable wasn't found. 887 // If we reach here, the executable wasn't found.
888 // So return empty string. 888 // So return empty string.
889 889
890 return QString::null; 890 return QString::null;
891} 891}
892 892
893int KStandardDirs::findAllExe( QStringList& list, const QString& appname, 893int KStandardDirs::findAllExe( QStringList& list, const QString& appname,
894 const QString& pstr, bool ignore ) 894 const QString& pstr, bool ignore )
895{ 895{
896 QString p = pstr; 896 QString p = pstr;
897 QFileInfo info; 897 QFileInfo info;
898 QStringList tokens; 898 QStringList tokens;
899 899
900 if( p.isNull() ) { 900 if( p.isNull() ) {
901 p = getenv( "PATH" ); 901 p = getenv( "PATH" );
902 } 902 }
903 903
904 list.clear(); 904 list.clear();
905 tokenize( tokens, p, ":\b" ); 905 tokenize( tokens, p, ":\b" );
906 906
907 for ( unsigned i = 0; i < tokens.count(); i++ ) { 907 for ( unsigned i = 0; i < tokens.count(); i++ ) {
908 p = tokens[ i ]; 908 p = tokens[ i ];
909 p += "/"; 909 p += "/";
910 p += appname; 910 p += appname;
911 911
912 info.setFile( p ); 912 info.setFile( p );
913 913
914 if( info.exists() && (ignore || info.isExecutable()) 914 if( info.exists() && (ignore || info.isExecutable())
915 && info.isFile() ) { 915 && info.isFile() ) {
916 list.append( p ); 916 list.append( p );
917 } 917 }
918 918
919 } 919 }
920 920
921 return list.count(); 921 return list.count();
922} 922}
923*/ 923*/
924 924
925static int tokenize( QStringList& tokens, const QString& str, 925static int tokenize( QStringList& tokens, const QString& str,
926 const QString& delim ) 926 const QString& delim )
927{ 927{
928 int len = str.length(); 928 int len = str.length();
929 QString token = ""; 929 QString token = "";
930 930
931 for( int index = 0; index < len; index++) 931 for( int index = 0; index < len; index++)
932 { 932 {
933 if ( delim.find( str[ index ] ) >= 0 ) 933 if ( delim.find( str[ index ] ) >= 0 )
934 { 934 {
935 tokens.append( token ); 935 tokens.append( token );
936 token = ""; 936 token = "";
937 } 937 }
938 else 938 else
939 { 939 {
940 token += str[ index ]; 940 token += str[ index ];
941 } 941 }
942 } 942 }
943 if ( token.length() > 0 ) 943 if ( token.length() > 0 )
944 { 944 {
945 tokens.append( token ); 945 tokens.append( token );
946 } 946 }
947 947
948 return tokens.count(); 948 return tokens.count();
949} 949}
950 950
951QString KStandardDirs::kde_default(const char *type) { 951QString KStandardDirs::kde_default(const char *type) {
952 if (!strcmp(type, "data")) 952 if (!strcmp(type, "data"))
953 return "apps/"; 953 return "apps/";
954 if (!strcmp(type, "html")) 954 if (!strcmp(type, "html"))
955 return "share/doc/HTML/"; 955 return "share/doc/HTML/";
956 if (!strcmp(type, "icon")) 956 if (!strcmp(type, "icon"))
957 return "share/icons/"; 957 return "share/icons/";
958 if (!strcmp(type, "config")) 958 if (!strcmp(type, "config"))
959 return "config/"; 959 return "config/";
960 if (!strcmp(type, "pixmap")) 960 if (!strcmp(type, "pixmap"))
961 return "share/pixmaps/"; 961 return "share/pixmaps/";
962 if (!strcmp(type, "apps")) 962 if (!strcmp(type, "apps"))
963 return "share/applnk/"; 963 return "share/applnk/";
964 if (!strcmp(type, "sound")) 964 if (!strcmp(type, "sound"))
965 return "share/sounds/"; 965 return "share/sounds/";
966 if (!strcmp(type, "locale")) 966 if (!strcmp(type, "locale"))
967 return "share/locale/"; 967 return "share/locale/";
968 if (!strcmp(type, "services")) 968 if (!strcmp(type, "services"))
969 return "share/services/"; 969 return "share/services/";
970 if (!strcmp(type, "servicetypes")) 970 if (!strcmp(type, "servicetypes"))
971 return "share/servicetypes/"; 971 return "share/servicetypes/";
972 if (!strcmp(type, "mime")) 972 if (!strcmp(type, "mime"))
973 return "share/mimelnk/"; 973 return "share/mimelnk/";
974 if (!strcmp(type, "cgi")) 974 if (!strcmp(type, "cgi"))
975 return "cgi-bin/"; 975 return "cgi-bin/";
976 if (!strcmp(type, "wallpaper")) 976 if (!strcmp(type, "wallpaper"))
977 return "share/wallpapers/"; 977 return "share/wallpapers/";
978 if (!strcmp(type, "templates")) 978 if (!strcmp(type, "templates"))
979 return "share/templates/"; 979 return "share/templates/";
980 if (!strcmp(type, "exe")) 980 if (!strcmp(type, "exe"))
981 return "bin/"; 981 return "bin/";
982 if (!strcmp(type, "lib")) 982 if (!strcmp(type, "lib"))
983 return "lib/"; 983 return "lib/";
984 if (!strcmp(type, "module")) 984 if (!strcmp(type, "module"))
985 return "lib/kde3/"; 985 return "lib/kde3/";
986 if (!strcmp(type, "qtplugins")) 986 if (!strcmp(type, "qtplugins"))
987 return "lib/kde3/plugins"; 987 return "lib/kde3/plugins";
988 if (!strcmp(type, "xdgdata-apps")) 988 if (!strcmp(type, "xdgdata-apps"))
989 return "applications/"; 989 return "applications/";
990 if (!strcmp(type, "xdgdata-dirs")) 990 if (!strcmp(type, "xdgdata-dirs"))
991 return "desktop-directories/"; 991 return "desktop-directories/";
992 if (!strcmp(type, "xdgconf-menu")) 992 if (!strcmp(type, "xdgconf-menu"))
993 return "menus/"; 993 return "menus/";
994 if (!strcmp(type, "tmp")) 994 if (!strcmp(type, "tmp"))
995 return "tmp/"; 995 return "tmp/";
996 996
997 qFatal("unknown resource type %s", type); 997 qFatal("unknown resource type %s", type);
998 return QString::null; 998 return QString::null;
999} 999}
1000 1000
1001QString KStandardDirs::saveLocation(const char *type, 1001QString KStandardDirs::saveLocation(const char *type,
1002 const QString& suffix, 1002 const QString& suffix,
1003 bool create) const 1003 bool create) const
1004{ 1004{
1005 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); 1005 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() );
1006 //return ""; 1006 //return "";
1007 checkConfig(); 1007 checkConfig();
1008 1008
1009 QString *pPath = savelocations.find(type); 1009 QString *pPath = savelocations.find(type);
1010 if (!pPath) 1010 if (!pPath)
1011 { 1011 {
1012 QStringList *dirs = relatives.find(type); 1012 QStringList *dirs = relatives.find(type);
1013 if (!dirs && ( 1013 if (!dirs && (
1014 (strcmp(type, "socket") == 0) || 1014 (strcmp(type, "socket") == 0) ||
1015 (strcmp(type, "tmp") == 0) || 1015 (strcmp(type, "tmp") == 0) ||
1016 (strcmp(type, "cache") == 0) )) 1016 (strcmp(type, "cache") == 0) ))
1017 { 1017 {
1018 (void) resourceDirs(type); // Generate socket|tmp|cache resource. 1018 (void) resourceDirs(type); // Generate socket|tmp|cache resource.
1019 dirs = relatives.find(type); // Search again. 1019 dirs = relatives.find(type); // Search again.
1020 } 1020 }
1021 if (dirs) 1021 if (dirs)
1022 { 1022 {
1023 // Check for existance of typed directory + suffix 1023 // Check for existance of typed directory + suffix
1024 if (strncmp(type, "xdgdata-", 8) == 0) 1024 if (strncmp(type, "xdgdata-", 8) == 0)
1025 pPath = new QString(realPath(localxdgdatadir() + dirs->last())); 1025 pPath = new QString(realPath(localxdgdatadir() + dirs->last()));
1026 else if (strncmp(type, "xdgconf-", 8) == 0) 1026 else if (strncmp(type, "xdgconf-", 8) == 0)
1027 pPath = new QString(realPath(localxdgconfdir() + dirs->last())); 1027 pPath = new QString(realPath(localxdgconfdir() + dirs->last()));
1028 else 1028 else
1029 pPath = new QString(realPath(localkdedir() + dirs->last())); 1029 pPath = new QString(realPath(localkdedir() + dirs->last()));
1030 } 1030 }
1031 else { 1031 else {
1032 dirs = absolutes.find(type); 1032 dirs = absolutes.find(type);
1033 if (!dirs) 1033 if (!dirs)
1034 qFatal("KStandardDirs: The resource type %s is not registered", type); 1034 qFatal("KStandardDirs: The resource type %s is not registered", type);
1035 pPath = new QString(realPath(dirs->last())); 1035 pPath = new QString(realPath(dirs->last()));
1036 } 1036 }
1037 1037
1038 savelocations.insert(type, pPath); 1038 savelocations.insert(type, pPath);
1039 } 1039 }
1040 1040
1041 QString fullPath = *pPath + suffix; 1041 QString fullPath = *pPath + suffix;
1042//US struct stat st; 1042//US struct stat st;
1043//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) 1043//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode)))
1044 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 1044 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
1045 if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) 1045 if (fullPathInfo.isReadable() || !fullPathInfo.isDir())
1046 1046
1047 1047
1048 { 1048 {
1049 if(!create) { 1049 if(!create) {
1050#ifndef NDEBUG 1050#ifndef NDEBUG
1051 qDebug("save location %s doesn't exist", fullPath.latin1()); 1051 qDebug("save location %s doesn't exist", fullPath.latin1());
1052#endif 1052#endif
1053 return fullPath; 1053 return fullPath;
1054 } 1054 }
1055 if(!makeDir(fullPath, 0700)) { 1055 if(!makeDir(fullPath, 0700)) {
1056 qWarning("failed to create %s", fullPath.latin1()); 1056 qWarning("failed to create %s", fullPath.latin1());
1057 return fullPath; 1057 return fullPath;
1058 } 1058 }
1059 dircache.remove(type); 1059 dircache.remove(type);
1060 } 1060 }
1061 return fullPath; 1061 return fullPath;
1062} 1062}
1063 1063
1064QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) 1064QString KStandardDirs::relativeLocation(const char *type, const QString &absPath)
1065{ 1065{
1066 QString fullPath = absPath; 1066 QString fullPath = absPath;
1067 int i = absPath.findRev('/'); 1067 int i = absPath.findRev('/');
1068 if (i != -1) 1068 if (i != -1)
1069 { 1069 {
1070 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize 1070 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize
1071 } 1071 }
1072 1072
1073 QStringList candidates = resourceDirs(type); 1073 QStringList candidates = resourceDirs(type);
1074 1074
1075 for (QStringList::ConstIterator it = candidates.begin(); 1075 for (QStringList::ConstIterator it = candidates.begin();
1076 it != candidates.end(); it++) 1076 it != candidates.end(); it++)
1077 if (fullPath.startsWith(*it)) 1077 if (fullPath.startsWith(*it))
1078 { 1078 {
1079 return fullPath.mid((*it).length()); 1079 return fullPath.mid((*it).length());
1080 } 1080 }
1081 1081
1082 return absPath; 1082 return absPath;
1083} 1083}
1084 1084
1085 1085
1086bool KStandardDirs::makeDir(const QString& dir2, int mode) 1086bool KStandardDirs::makeDir(const QString& dir2, int mode)
1087{ 1087{
1088 QString dir = QDir::convertSeparators( dir2 ); 1088 QString dir = QDir::convertSeparators( dir2 );
1089#if 0 1089#if 0
1090 //LR 1090 //LR
1091 1091
1092 // we want an absolute path 1092 // we want an absolute path
1093 if (dir.at(0) != '/') 1093 if (dir.at(0) != '/')
1094 return false; 1094 return false;
1095 1095
1096 QString target = dir; 1096 QString target = dir;
1097 uint len = target.length(); 1097 uint len = target.length();
1098 1098
1099 // append trailing slash if missing 1099 // append trailing slash if missing
1100 if (dir.at(len - 1) != '/') 1100 if (dir.at(len - 1) != '/')
1101 target += '/'; 1101 target += '/';
1102 1102
1103 QString base(""); 1103 QString base("");
1104 uint i = 1; 1104 uint i = 1;
1105 1105
1106 while( i < len ) 1106 while( i < len )
1107 { 1107 {
1108//US struct stat st; 1108//US struct stat st;
1109 int pos = target.find('/', i); 1109 int pos = target.find('/', i);
1110 base += target.mid(i - 1, pos - i + 1); 1110 base += target.mid(i - 1, pos - i + 1);
1111 QCString baseEncoded = QFile::encodeName(base); 1111 QCString baseEncoded = QFile::encodeName(base);
1112 // bail out if we encountered a problem 1112 // bail out if we encountered a problem
1113//US if (stat(baseEncoded, &st) != 0) 1113//US if (stat(baseEncoded, &st) != 0)
1114 QFileInfo baseEncodedInfo(baseEncoded); 1114 QFileInfo baseEncodedInfo(baseEncoded);
1115 if (!baseEncodedInfo.exists()) 1115 if (!baseEncodedInfo.exists())
1116 { 1116 {
1117 // Directory does not exist.... 1117 // Directory does not exist....
1118 // Or maybe a dangling symlink ? 1118 // Or maybe a dangling symlink ?
1119//US if (lstat(baseEncoded, &st) == 0) 1119//US if (lstat(baseEncoded, &st) == 0)
1120 if (baseEncodedInfo.isSymLink()) { 1120 if (baseEncodedInfo.isSymLink()) {
1121//US (void)unlink(baseEncoded); // try removing 1121//US (void)unlink(baseEncoded); // try removing
1122 QFile(baseEncoded).remove(); 1122 QFile(baseEncoded).remove();
1123 } 1123 }
1124 1124
1125 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) 1125 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0)
1126 QDir dirObj; 1126 QDir dirObj;
1127 if ( dirObj.mkdir(baseEncoded) != true ) 1127 if ( dirObj.mkdir(baseEncoded) != true )
1128 { 1128 {
1129 //US perror("trying to create local folder"); 1129 //US perror("trying to create local folder");
1130 return false; // Couldn't create it :-( 1130 return false; // Couldn't create it :-(
1131 } 1131 }
1132 } 1132 }
1133 i = pos + 1; 1133 i = pos + 1;
1134 } 1134 }
1135 return true; 1135 return true;
1136#endif 1136#endif
1137 1137
1138 // ******************************************** 1138 // ********************************************
1139 // new code for WIN32 1139 // new code for WIN32
1140 QDir dirObj; 1140 QDir dirObj;
1141 1141
1142 1142
1143 // we want an absolute path 1143 // we want an absolute path
1144#ifndef _WIN32_ 1144#ifndef _WIN32_
1145 if (dir.at(0) != '/') 1145 if (dir.at(0) != '/')
1146 return false; 1146 return false;
1147#endif 1147#endif
1148 1148
1149 QString target = dir; 1149 QString target = dir;
1150 uint len = target.length(); 1150 uint len = target.length();
1151#ifndef _WIN32_ 1151#ifndef _WIN32_
1152 // append trailing slash if missing 1152 // append trailing slash if missing
1153 if (dir.at(len - 1) != '/') 1153 if (dir.at(len - 1) != '/')
1154 target += '/'; 1154 target += '/';
1155#endif 1155#endif
1156 1156
1157 QString base(""); 1157 QString base("");
1158 uint i = 1; 1158 uint i = 1;
1159 1159
1160 while( i < len ) 1160 while( i < len )
1161 { 1161 {
1162//US struct stat st; 1162//US struct stat st;
1163#ifndef _WIN32_ 1163#ifndef _WIN32_
1164 int pos = target.find('/', i); 1164 int pos = target.find('/', i);
1165#else 1165#else
1166 int pos = target.find('\\', i); 1166 int pos = target.find('\\', i);
1167#endif 1167#endif
1168 if ( pos < 0 ) 1168 if ( pos < 0 )
1169 return true; 1169 return true;
1170 base += target.mid(i - 1, pos - i + 1); 1170 base += target.mid(i - 1, pos - i + 1);
1171 //QMessageBox::information( 0,"cap111", base, 1 ); 1171 //QMessageBox::information( 0,"cap111", base, 1 );
1172/*US 1172/*US
1173 QCString baseEncoded = QFile::encodeName(base); 1173 QCString baseEncoded = QFile::encodeName(base);
1174 // bail out if we encountered a problem 1174 // bail out if we encountered a problem
1175 if (stat(baseEncoded, &st) != 0) 1175 if (stat(baseEncoded, &st) != 0)
1176 { 1176 {
1177 // Directory does not exist.... 1177 // Directory does not exist....
1178 // Or maybe a dangling symlink ? 1178 // Or maybe a dangling symlink ?
1179 if (lstat(baseEncoded, &st) == 0) 1179 if (lstat(baseEncoded, &st) == 0)
1180 (void)unlink(baseEncoded); // try removing 1180 (void)unlink(baseEncoded); // try removing
1181 1181
1182 1182
1183 if ( mkdir(baseEncoded, (mode_t) mode) != 0) { 1183 if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
1184 perror("trying to create local folder"); 1184 perror("trying to create local folder");
1185 return false; // Couldn't create it :-( 1185 return false; // Couldn't create it :-(
1186 } 1186 }
1187 } 1187 }
1188*/ 1188*/
1189 1189
1190 if (dirObj.exists(base) == false) 1190 if (dirObj.exists(base) == false)
1191 { 1191 {
1192 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); 1192 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
1193 if (dirObj.mkdir(base) != true) 1193 if (dirObj.mkdir(base) != true)
1194 { 1194 {
1195 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); 1195 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
1196 return false; 1196 return false;
1197 } 1197 }
1198 } 1198 }
1199 1199
1200 i = pos + 1; 1200 i = pos + 1;
1201 } 1201 }
1202 return true; 1202 return true;
1203 1203
1204} 1204}
1205 1205
1206static QString readEnvPath(const char *env) 1206static QString readEnvPath(const char *env)
1207{ 1207{
1208 //#ifdef _WIN32_ 1208 //#ifdef _WIN32_
1209 // return ""; 1209 // return "";
1210 //#else 1210 //#else
1211 QCString c_path; 1211 QCString c_path;
1212 if ( getenv(env) != NULL ) 1212 if ( getenv(env) != NULL )
1213 c_path = QString ( getenv(env) ); 1213 c_path = QString ( getenv(env) );
1214 if (c_path.isEmpty()) 1214 if (c_path.isEmpty())
1215 return QString::null; 1215 return QString::null;
1216 return QFile::decodeName(c_path); 1216 return QFile::decodeName(c_path);
1217 //#endif 1217 //#endif
1218 1218
1219} 1219}
1220 1220
1221void KStandardDirs::addKDEDefaults() 1221void KStandardDirs::addKDEDefaults()
1222{ 1222{
1223 1223
1224 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); 1224 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
1225 //return; 1225 //return;
1226 QStringList kdedirList; 1226 QStringList kdedirList;
1227 1227
1228 // begin KDEDIRS 1228 // begin KDEDIRS
1229 QString kdedirs = readEnvPath("MICROKDEDIRS"); 1229 QString kdedirs = readEnvPath("MICROKDEDIRS");
1230 if (!kdedirs.isEmpty()) 1230 if (!kdedirs.isEmpty())
1231 { 1231 {
1232 tokenize(kdedirList, kdedirs, ":"); 1232 tokenize(kdedirList, kdedirs, ":");
1233 } 1233 }
1234 else 1234 else
1235 { 1235 {
1236 QString kdedir = readEnvPath("MICROKDEDIR"); 1236 QString kdedir = readEnvPath("MICROKDEDIR");
1237 if (!kdedir.isEmpty()) 1237 if (!kdedir.isEmpty())
1238 { 1238 {
1239 kdedir = KShell::tildeExpand(kdedir); 1239 kdedir = KShell::tildeExpand(kdedir);
1240 kdedirList.append(kdedir); 1240 kdedirList.append(kdedir);
1241 } 1241 }
1242 } 1242 }
1243//US kdedirList.append(KDEDIR); 1243//US kdedirList.append(KDEDIR);
1244//US for embedded, add qtopia dir as kdedir 1244//US for embedded, add qtopia dir as kdedir
1245 1245
1246#ifndef DESKTOP_VERSION 1246#ifndef DESKTOP_VERSION
1247 QString tmp = readEnvPath("QPEDIR"); 1247 QString tmp = readEnvPath("QPEDIR");
1248 if (!tmp.isEmpty()) 1248 if (!tmp.isEmpty())
1249 kdedirList.append(tmp); 1249 kdedirList.append(tmp);
1250 1250
1251 tmp = readEnvPath("QTDIR"); 1251 tmp = readEnvPath("QTDIR");
1252 if (!tmp.isEmpty()) 1252 if (!tmp.isEmpty())
1253 kdedirList.append(tmp); 1253 kdedirList.append(tmp);
1254 1254
1255 tmp = readEnvPath("OPIEDIR"); 1255 tmp = readEnvPath("OPIEDIR");
1256 if (!tmp.isEmpty()) 1256 if (!tmp.isEmpty())
1257 kdedirList.append(tmp); 1257 kdedirList.append(tmp);
1258 1258
1259#endif 1259#endif
1260 1260
1261#ifdef __KDE_EXECPREFIX 1261#ifdef __KDE_EXECPREFIX
1262 QString execPrefix(__KDE_EXECPREFIX); 1262 QString execPrefix(__KDE_EXECPREFIX);
1263 if (execPrefix!="NONE") 1263 if (execPrefix!="NONE")
1264 kdedirList.append(execPrefix); 1264 kdedirList.append(execPrefix);
1265#endif 1265#endif
1266 1266
1267 QString localKdeDir; 1267 QString localKdeDir;
1268 1268
1269//US if (getuid()) 1269//US if (getuid())
1270 if (true) 1270 if (true)
1271 { 1271 {
1272 localKdeDir = readEnvPath("MICROKDEHOME"); 1272 localKdeDir = readEnvPath("MICROKDEHOME");
1273 if (!localKdeDir.isEmpty()) 1273 if (!localKdeDir.isEmpty())
1274 { 1274 {
1275#ifdef _WIN32_ 1275#ifdef _WIN32_
1276 if (localKdeDir.at(localKdeDir.length()-1) != '\\') 1276 if (localKdeDir.at(localKdeDir.length()-1) != '\\')
1277 localKdeDir += '\\'; 1277 localKdeDir += '\\';
1278#else 1278#else
1279 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1279 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1280 localKdeDir += '/'; 1280 localKdeDir += '/';
1281#endif 1281#endif
1282 //QMessageBox::information( 0,"localKdeDir",localKdeDir, 1 ); 1282 //QMessageBox::information( 0,"localKdeDir",localKdeDir, 1 );
1283 } 1283 }
1284 else 1284 else
1285 { 1285 {
1286 QString confFile; 1286 QString confFile;
1287#ifdef DESKTOP_VERSION 1287#ifdef DESKTOP_VERSION
1288 confFile = qApp->applicationDirPath ()+ "/.microkdehome" ; 1288 confFile = qApp->applicationDirPath ()+ "/.microkdehome" ;
1289 QFileInfo fi ( confFile ); 1289 QFileInfo fi ( confFile );
1290 if ( !fi.exists() ) 1290 if ( !fi.exists() )
1291 confFile = QDir::homeDirPath() + "/.microkdehome"; 1291 confFile = QDir::homeDirPath() + "/.microkdehome";
1292 else 1292 else
1293 qDebug("Loading path info from " + confFile ); 1293 qDebug("Loading path info from " + confFile );
1294 1294
1295#else 1295#else
1296 confFile = QDir::homeDirPath() + "/.microkdehome"; 1296 confFile = QDir::homeDirPath() + "/.microkdehome";
1297#endif 1297#endif
1298 KConfig cfg ( confFile ); 1298 KConfig cfg ( confFile );
1299 cfg.setGroup("Global"); 1299 cfg.setGroup("Global");
1300 localKdeDir = cfg.readEntry( "MICROKDEHOME", QDir::homeDirPath() + "/kdepim/" ); 1300 localKdeDir = cfg.readEntry( "MICROKDEHOME", QDir::homeDirPath() + "/kdepim/" );
1301#ifdef DESKTOP_VERSION
1302 if ( localKdeDir.startsWith( "LOCAL:" ) ) {
1303#ifdef _WIN32_
1304 localKdeDir = qApp->applicationDirPath () + "\\"+ localKdeDir.mid( 6 );
1305#else
1306 localKdeDir = qApp->applicationDirPath () + "/"+ localKdeDir.mid( 6 );
1307#endif
1308 qDebug("Using local conf dir %s ",localKdeDir.latin1() );
1309 }
1310#endif
1301 } 1311 }
1302 } 1312 }
1303 else 1313 else
1304 { 1314 {
1305 // We treat root different to prevent root messing up the 1315 // We treat root different to prevent root messing up the
1306 // file permissions in the users home directory. 1316 // file permissions in the users home directory.
1307 localKdeDir = readEnvPath("MICROKDEROOTHOME"); 1317 localKdeDir = readEnvPath("MICROKDEROOTHOME");
1308 if (!localKdeDir.isEmpty()) 1318 if (!localKdeDir.isEmpty())
1309 { 1319 {
1310 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1320 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1311 localKdeDir += '/'; 1321 localKdeDir += '/';
1312 } 1322 }
1313 else 1323 else
1314 { 1324 {
1315//US struct passwd *pw = getpwuid(0); 1325//US struct passwd *pw = getpwuid(0);
1316//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; 1326//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/";
1317 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); 1327 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed");
1318 } 1328 }
1319 1329
1320 } 1330 }
1321 1331
1322//US localKdeDir = appDir(); 1332//US localKdeDir = appDir();
1323 1333
1324//US 1334//US
1325// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); 1335// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1());
1326 if (localKdeDir != "-/") 1336 if (localKdeDir != "-/")
1327 { 1337 {
1328 localKdeDir = KShell::tildeExpand(localKdeDir); 1338 localKdeDir = KShell::tildeExpand(localKdeDir);
1329 addPrefix(localKdeDir); 1339 addPrefix(localKdeDir);
1330 } 1340 }
1331 1341
1332 for (QStringList::ConstIterator it = kdedirList.begin(); 1342 for (QStringList::ConstIterator it = kdedirList.begin();
1333 it != kdedirList.end(); it++) 1343 it != kdedirList.end(); it++)
1334 { 1344 {
1335 QString dir = KShell::tildeExpand(*it); 1345 QString dir = KShell::tildeExpand(*it);
1336 addPrefix(dir); 1346 addPrefix(dir);
1337 } 1347 }
1338 // end KDEDIRS 1348 // end KDEDIRS
1339 1349
1340 // begin XDG_CONFIG_XXX 1350 // begin XDG_CONFIG_XXX
1341 QStringList xdgdirList; 1351 QStringList xdgdirList;
1342 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); 1352 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS");
1343 if (!xdgdirs.isEmpty()) 1353 if (!xdgdirs.isEmpty())
1344 { 1354 {
1345 tokenize(xdgdirList, xdgdirs, ":"); 1355 tokenize(xdgdirList, xdgdirs, ":");
1346 } 1356 }
1347 else 1357 else
1348 { 1358 {
1349 xdgdirList.clear(); 1359 xdgdirList.clear();
1350 xdgdirList.append("/etc/xdg"); 1360 xdgdirList.append("/etc/xdg");
1351 } 1361 }
1352 1362
1353 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); 1363 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME");
1354 if (!localXdgDir.isEmpty()) 1364 if (!localXdgDir.isEmpty())
1355 { 1365 {
1356 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1366 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1357 localXdgDir += '/'; 1367 localXdgDir += '/';
1358 } 1368 }
1359 else 1369 else
1360 { 1370 {
1361//US if (getuid()) 1371//US if (getuid())
1362 if (true) 1372 if (true)
1363 { 1373 {
1364 localXdgDir = QDir::homeDirPath() + "/.config/"; 1374 localXdgDir = QDir::homeDirPath() + "/.config/";
1365 } 1375 }
1366 else 1376 else
1367 { 1377 {
1368//US struct passwd *pw = getpwuid(0); 1378//US struct passwd *pw = getpwuid(0);
1369//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; 1379//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/";
1370 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); 1380 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed");
1371 } 1381 }
1372 } 1382 }
1373 1383
1374 localXdgDir = KShell::tildeExpand(localXdgDir); 1384 localXdgDir = KShell::tildeExpand(localXdgDir);
1375 addXdgConfigPrefix(localXdgDir); 1385 addXdgConfigPrefix(localXdgDir);
1376 1386
1377 for (QStringList::ConstIterator it = xdgdirList.begin(); 1387 for (QStringList::ConstIterator it = xdgdirList.begin();
1378 it != xdgdirList.end(); it++) 1388 it != xdgdirList.end(); it++)
1379 { 1389 {
1380 QString dir = KShell::tildeExpand(*it); 1390 QString dir = KShell::tildeExpand(*it);
1381 addXdgConfigPrefix(dir); 1391 addXdgConfigPrefix(dir);
1382 } 1392 }
1383 // end XDG_CONFIG_XXX 1393 // end XDG_CONFIG_XXX
1384 1394
1385 // begin XDG_DATA_XXX 1395 // begin XDG_DATA_XXX
1386 xdgdirs = readEnvPath("XDG_DATA_DIRS"); 1396 xdgdirs = readEnvPath("XDG_DATA_DIRS");
1387 if (!xdgdirs.isEmpty()) 1397 if (!xdgdirs.isEmpty())
1388 { 1398 {
1389 tokenize(xdgdirList, xdgdirs, ":"); 1399 tokenize(xdgdirList, xdgdirs, ":");
1390 } 1400 }
1391 else 1401 else
1392 { 1402 {
1393 xdgdirList.clear(); 1403 xdgdirList.clear();
1394 for (QStringList::ConstIterator it = kdedirList.begin(); 1404 for (QStringList::ConstIterator it = kdedirList.begin();
1395 it != kdedirList.end(); it++) 1405 it != kdedirList.end(); it++)
1396 { 1406 {
1397 QString dir = *it; 1407 QString dir = *it;
1398 if (dir.at(dir.length()-1) != '/') 1408 if (dir.at(dir.length()-1) != '/')
1399 dir += '/'; 1409 dir += '/';
1400 xdgdirList.append(dir+"share/"); 1410 xdgdirList.append(dir+"share/");
1401 } 1411 }
1402 1412
1403 xdgdirList.append("/usr/local/share/"); 1413 xdgdirList.append("/usr/local/share/");
1404 xdgdirList.append("/usr/share/"); 1414 xdgdirList.append("/usr/share/");
1405 } 1415 }
1406 1416
1407 localXdgDir = readEnvPath("XDG_DATA_HOME"); 1417 localXdgDir = readEnvPath("XDG_DATA_HOME");
1408 if (!localXdgDir.isEmpty()) 1418 if (!localXdgDir.isEmpty())
1409 { 1419 {
1410 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1420 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1411 localXdgDir += '/'; 1421 localXdgDir += '/';
1412 } 1422 }
1413 else 1423 else
1414 { 1424 {
1415//US if (getuid()) 1425//US if (getuid())
1416 if (true) 1426 if (true)
1417 { 1427 {
1418 localXdgDir = QDir::homeDirPath() + "/.local/share/"; 1428 localXdgDir = QDir::homeDirPath() + "/.local/share/";
1419 } 1429 }
1420 else 1430 else
1421 { 1431 {
1422//US struct passwd *pw = getpwuid(0); 1432//US struct passwd *pw = getpwuid(0);
1423//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; 1433//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/";
1424 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); 1434 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed");
1425 } 1435 }
1426 } 1436 }
1427 1437
1428 localXdgDir = KShell::tildeExpand(localXdgDir); 1438 localXdgDir = KShell::tildeExpand(localXdgDir);
1429 addXdgDataPrefix(localXdgDir); 1439 addXdgDataPrefix(localXdgDir);
1430 1440
1431 for (QStringList::ConstIterator it = xdgdirList.begin(); 1441 for (QStringList::ConstIterator it = xdgdirList.begin();
1432 it != xdgdirList.end(); it++) 1442 it != xdgdirList.end(); it++)
1433 { 1443 {
1434 QString dir = KShell::tildeExpand(*it); 1444 QString dir = KShell::tildeExpand(*it);
1435 1445
1436 addXdgDataPrefix(dir); 1446 addXdgDataPrefix(dir);
1437 } 1447 }
1438 // end XDG_DATA_XXX 1448 // end XDG_DATA_XXX
1439 1449
1440 1450
1441 uint index = 0; 1451 uint index = 0;
1442 while (types[index] != 0) { 1452 while (types[index] != 0) {
1443 addResourceType(types[index], kde_default(types[index])); 1453 addResourceType(types[index], kde_default(types[index]));
1444 index++; 1454 index++;
1445 } 1455 }
1446 1456
1447 addResourceDir("home", QDir::homeDirPath()); 1457 addResourceDir("home", QDir::homeDirPath());
1448} 1458}
1449 1459
1450void KStandardDirs::checkConfig() const 1460void KStandardDirs::checkConfig() const
1451{ 1461{
1452/*US 1462/*US
1453 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) 1463 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config)
1454 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); 1464 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config);
1455*/ 1465*/
1456 if (!addedCustoms && KGlobal::config()) 1466 if (!addedCustoms && KGlobal::config())
1457 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); 1467 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config());
1458} 1468}
1459 1469
1460bool KStandardDirs::addCustomized(KConfig *config) 1470bool KStandardDirs::addCustomized(KConfig *config)
1461{ 1471{
1462 if (addedCustoms) // there are already customized entries 1472 if (addedCustoms) // there are already customized entries
1463 return false; // we just quite and hope they are the right ones 1473 return false; // we just quite and hope they are the right ones
1464 1474
1465 // save the numbers of config directories. If this changes, 1475 // save the numbers of config directories. If this changes,
1466 // we will return true to give KConfig a chance to reparse 1476 // we will return true to give KConfig a chance to reparse
1467 uint configdirs = resourceDirs("config").count(); 1477 uint configdirs = resourceDirs("config").count();
1468 1478
1469 // reading the prefixes in 1479 // reading the prefixes in
1470 QString oldGroup = config->group(); 1480 QString oldGroup = config->group();
1471 config->setGroup("Directories"); 1481 config->setGroup("Directories");
1472 1482
1473 QStringList list; 1483 QStringList list;
1474 QStringList::ConstIterator it; 1484 QStringList::ConstIterator it;
1475 list = config->readListEntry("prefixes"); 1485 list = config->readListEntry("prefixes");
1476 for (it = list.begin(); it != list.end(); it++) 1486 for (it = list.begin(); it != list.end(); it++)
1477 addPrefix(*it); 1487 addPrefix(*it);
1478 1488
1479 // iterating over all entries in the group Directories 1489 // iterating over all entries in the group Directories
1480 // to find entries that start with dir_$type 1490 // to find entries that start with dir_$type
1481/*US 1491/*US
1482 QMap<QString, QString> entries = config->entryMap("Directories"); 1492 QMap<QString, QString> entries = config->entryMap("Directories");
1483 1493
1484 QMap<QString, QString>::ConstIterator it2; 1494 QMap<QString, QString>::ConstIterator it2;
1485 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1495 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1486 { 1496 {
1487 QString key = it2.key(); 1497 QString key = it2.key();
1488 if (key.left(4) == "dir_") { 1498 if (key.left(4) == "dir_") {
1489 // generate directory list, there may be more than 1. 1499 // generate directory list, there may be more than 1.
1490 QStringList dirs = QStringList::split(',', *it2); 1500 QStringList dirs = QStringList::split(',', *it2);
1491 QStringList::Iterator sIt(dirs.begin()); 1501 QStringList::Iterator sIt(dirs.begin());
1492 QString resType = key.mid(4, key.length()); 1502 QString resType = key.mid(4, key.length());
1493 for (; sIt != dirs.end(); ++sIt) { 1503 for (; sIt != dirs.end(); ++sIt) {
1494 addResourceDir(resType.latin1(), *sIt); 1504 addResourceDir(resType.latin1(), *sIt);
1495 } 1505 }
1496 } 1506 }
1497 } 1507 }
1498 1508
1499 // Process KIOSK restrictions. 1509 // Process KIOSK restrictions.
1500 config->setGroup("KDE Resource Restrictions"); 1510 config->setGroup("KDE Resource Restrictions");
1501 entries = config->entryMap("KDE Resource Restrictions"); 1511 entries = config->entryMap("KDE Resource Restrictions");
1502 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1512 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1503 { 1513 {
1504 QString key = it2.key(); 1514 QString key = it2.key();
1505 if (!config->readBoolEntry(key, true)) 1515 if (!config->readBoolEntry(key, true))
1506 { 1516 {
1507 d->restrictionsActive = true; 1517 d->restrictionsActive = true;
1508 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do 1518 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do
1509 dircache.remove(key.latin1()); 1519 dircache.remove(key.latin1());
1510 } 1520 }
1511 } 1521 }
1512*/ 1522*/
1513 // save it for future calls - that will return 1523 // save it for future calls - that will return
1514 addedCustoms = true; 1524 addedCustoms = true;
1515 config->setGroup(oldGroup); 1525 config->setGroup(oldGroup);
1516 1526
1517 // return true if the number of config dirs changed 1527 // return true if the number of config dirs changed
1518 return (resourceDirs("config").count() != configdirs); 1528 return (resourceDirs("config").count() != configdirs);
1519} 1529}
1520 1530
1521QString KStandardDirs::localkdedir() const 1531QString KStandardDirs::localkdedir() const
1522{ 1532{
1523 // Return the prefix to use for saving 1533 // Return the prefix to use for saving
1524 return prefixes.first(); 1534 return prefixes.first();
1525} 1535}
1526 1536
1527QString KStandardDirs::localxdgdatadir() const 1537QString KStandardDirs::localxdgdatadir() const
1528{ 1538{
1529 // Return the prefix to use for saving 1539 // Return the prefix to use for saving
1530 return d->xdgdata_prefixes.first(); 1540 return d->xdgdata_prefixes.first();
1531} 1541}
1532 1542
1533QString KStandardDirs::localxdgconfdir() const 1543QString KStandardDirs::localxdgconfdir() const
1534{ 1544{
1535 // Return the prefix to use for saving 1545 // Return the prefix to use for saving
1536 return d->xdgconf_prefixes.first(); 1546 return d->xdgconf_prefixes.first();
1537} 1547}
1538 1548
1539void KStandardDirs::setAppDir( const QString &appDir ) 1549void KStandardDirs::setAppDir( const QString &appDir )
1540{ 1550{
1541 mAppDir = appDir; 1551 mAppDir = appDir;
1542 1552
1543 if ( mAppDir.right( 1 ) != "/" ) 1553 if ( mAppDir.right( 1 ) != "/" )
1544 mAppDir += "/"; 1554 mAppDir += "/";
1545} 1555}
1546 1556
1547QString KStandardDirs::appDir() 1557QString KStandardDirs::appDir()
1548{ 1558{
1549 return mAppDir; 1559 return mAppDir;
1550} 1560}
1551 1561
1552// just to make code more readable without macros 1562// just to make code more readable without macros
1553QString locate( const char *type, 1563QString locate( const char *type,
1554 const QString& filename/*US , const KInstance* inst*/ ) 1564 const QString& filename/*US , const KInstance* inst*/ )
1555{ 1565{
1556//US return inst->dirs()->findResource(type, filename); 1566//US return inst->dirs()->findResource(type, filename);
1557 return KGlobal::dirs()->findResource(type, filename); 1567 return KGlobal::dirs()->findResource(type, filename);
1558} 1568}
1559 1569
1560QString locateLocal( const char *type, 1570QString locateLocal( const char *type,
1561 const QString& filename/*US , const KInstance* inst*/ ) 1571 const QString& filename/*US , const KInstance* inst*/ )
1562{ 1572{
1563 1573
1564 QString path = locateLocal(type, filename, true /*US, inst*/); 1574 QString path = locateLocal(type, filename, true /*US, inst*/);
1565 1575
1566 1576
1567/* 1577/*
1568 static int ccc = 0; 1578 static int ccc = 0;
1569 ++ccc; 1579 ++ccc;
1570 if ( ccc > 13 ) 1580 if ( ccc > 13 )
1571 abort(); 1581 abort();
1572*/ 1582*/
1573 //qDebug("locatelocal: %s" , path.latin1()); 1583 //qDebug("locatelocal: %s" , path.latin1());
1574 return path; 1584 return path;
1575 1585
1576/*US why do we put all files into one directory. It is quit complicated. 1586/*US why do we put all files into one directory. It is quit complicated.
1577why not staying with the original directorystructure ? 1587why not staying with the original directorystructure ?
1578 1588
1579 1589
1580 QString escapedFilename = filename; 1590 QString escapedFilename = filename;
1581 escapedFilename.replace( QRegExp( "/" ), "_" ); 1591 escapedFilename.replace( QRegExp( "/" ), "_" );
1582 1592
1583 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; 1593 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename;
1584 1594
1585 kdDebug() << "locate: '" << path << "'" << endl; 1595 kdDebug() << "locate: '" << path << "'" << endl;
1586 qDebug("locate: %s" , path.latin1()); 1596 qDebug("locate: %s" , path.latin1());
1587 return path; 1597 return path;
1588*/ 1598*/
1589//US so my proposal is this: 1599//US so my proposal is this:
1590 1600
1591// QString escapedFilename = filename; 1601// QString escapedFilename = filename;
1592// escapedFilename.replace( QRegExp( "/" ), "_" ); 1602// escapedFilename.replace( QRegExp( "/" ), "_" );
1593 1603
1594#if 0 1604#if 0
1595#ifdef _WIN32_ 1605#ifdef _WIN32_
1596 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); 1606 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename);
1597#else 1607#else
1598 QString path = KStandardDirs::appDir() + type + "/" + filename; 1608 QString path = KStandardDirs::appDir() + type + "/" + filename;
1599#endif 1609#endif
1600 1610
1601 //US Create the containing dir if needed 1611 //US Create the containing dir if needed
1602 QFileInfo fi ( path ); 1612 QFileInfo fi ( path );
1603 1613
1604 // QString dir=pathurl.directory(); 1614 // QString dir=pathurl.directory();
1605 //QMessageBox::information( 0,"path", path, 1 ); 1615 //QMessageBox::information( 0,"path", path, 1 );
1606 1616
1607#ifdef _WIN32_ 1617#ifdef _WIN32_
1608 KStandardDirs::makeDir(path); 1618 KStandardDirs::makeDir(path);
1609#else 1619#else
1610 KStandardDirs::makeDir(fi.dirPath( true )); 1620 KStandardDirs::makeDir(fi.dirPath( true ));
1611#endif 1621#endif
1612 1622
1613 qDebug("locate22: %s" , path.latin1()); 1623 qDebug("locate22: %s" , path.latin1());
1614 return path; 1624 return path;
1615 1625
1616#endif 1626#endif
1617 1627
1618} 1628}
1619 1629
1620QString locateLocal( const char *type, 1630QString locateLocal( const char *type,
1621 const QString& filename, bool createDir/*US , const KInstance* inst*/ ) 1631 const QString& filename, bool createDir/*US , const KInstance* inst*/ )
1622{ 1632{
1623 // try to find slashes. If there are some, we have to 1633 // try to find slashes. If there are some, we have to
1624 // create the subdir first 1634 // create the subdir first
1625 int slash = filename.findRev('/')+1; 1635 int slash = filename.findRev('/')+1;
1626 if (!slash) // only one filename 1636 if (!slash) // only one filename
1627 //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename; 1637 //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename;
1628 return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename; 1638 return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename;
1629 1639
1630 // split path from filename 1640 // split path from filename
1631 QString dir = filename.left(slash); 1641 QString dir = filename.left(slash);
1632 QString file = filename.mid(slash); 1642 QString file = filename.mid(slash);
1633//US return inst->dirs()->saveLocation(type, dir, createDir) + file; 1643//US return inst->dirs()->saveLocation(type, dir, createDir) + file;
1634 return KGlobal::dirs()->saveLocation(type, dir, createDir) + file; 1644 return KGlobal::dirs()->saveLocation(type, dir, createDir) + file;
1635 1645
1636 // *************************************************************** 1646 // ***************************************************************
1637#if 0 1647#if 0
1638 1648
1639/*US why do we put all files into one directory. It is quit complicated. 1649/*US why do we put all files into one directory. It is quit complicated.
1640why not staying with the original directorystructure ? 1650why not staying with the original directorystructure ?
1641 1651
1642 1652
1643 QString escapedFilename = filename; 1653 QString escapedFilename = filename;
1644 escapedFilename.replace( QRegExp( "/" ), "_" ); 1654 escapedFilename.replace( QRegExp( "/" ), "_" );
1645 1655
1646 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; 1656 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename;
1647 1657
1648 kdDebug() << "locate: '" << path << "'" << endl; 1658 kdDebug() << "locate: '" << path << "'" << endl;
1649 qDebug("locate: %s" , path.latin1()); 1659 qDebug("locate: %s" , path.latin1());
1650 return path; 1660 return path;
1651*/ 1661*/
1652//US so my proposal is this: 1662//US so my proposal is this:
1653 1663
1654// QString escapedFilename = filename; 1664// QString escapedFilename = filename;
1655// escapedFilename.replace( QRegExp( "/" ), "_" ); 1665// escapedFilename.replace( QRegExp( "/" ), "_" );
1656 1666
1657#ifdef _WIN32_ 1667#ifdef _WIN32_
1658 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); 1668 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename);
1659#else 1669#else
1660 QString path = KStandardDirs::appDir() + type + "/" + filename; 1670 QString path = KStandardDirs::appDir() + type + "/" + filename;
1661#endif 1671#endif
1662 1672
1663 //US Create the containing dir if needed 1673 //US Create the containing dir if needed
1664 KURL pathurl; 1674 KURL pathurl;
1665 pathurl.setPath(path); 1675 pathurl.setPath(path);
1666 QString dir=pathurl.directory(); 1676 QString dir=pathurl.directory();
1667 //QMessageBox::information( 0,"path", path, 1 ); 1677 //QMessageBox::information( 0,"path", path, 1 );
1668#ifdef _WIN32_ 1678#ifdef _WIN32_
1669 KStandardDirs::makeDir(path); 1679 KStandardDirs::makeDir(path);
1670#else 1680#else
1671 KStandardDirs::makeDir(dir); 1681 KStandardDirs::makeDir(dir);
1672#endif 1682#endif
1673 1683
1674 return path; 1684 return path;
1675#endif 1685#endif
1676} 1686}