summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-30 22:07:56 (UTC)
committer ulf69 <ulf69>2004-06-30 22:07:56 (UTC)
commit1b7b7755bfbedddc72293b784577ded4e684bd6f (patch) (unidiff)
treeff4eba9b8bb53401d2000d70e73a40f7c330d577
parentc6f3a3f49498dca52d10418d845f4a84c0c6d941 (diff)
downloadkdepimpi-1b7b7755bfbedddc72293b784577ded4e684bd6f.zip
kdepimpi-1b7b7755bfbedddc72293b784577ded4e684bd6f.tar.gz
kdepimpi-1b7b7755bfbedddc72293b784577ded4e684bd6f.tar.bz2
added a new field of type Resource. This allowes us to display in KAddressbook for each
Addressbookentry its location
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp6
-rw-r--r--kabc/addressee.h6
-rw-r--r--kabc/field.cpp24
3 files changed, 32 insertions, 4 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 5cb194a..d484073 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1486,48 +1486,54 @@ void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1486 // Check that we do not have any extra characters on the end of the 1486 // Check that we do not have any extra characters on the end of the
1487 // strings 1487 // strings
1488 len = fullName.length(); 1488 len = fullName.length();
1489 if (fullName[0]=='"' && fullName[len-1]=='"') 1489 if (fullName[0]=='"' && fullName[len-1]=='"')
1490 fullName = fullName.mid(1, len-2); 1490 fullName = fullName.mid(1, len-2);
1491 else if (fullName[0]=='<' && fullName[len-1]=='>') 1491 else if (fullName[0]=='<' && fullName[len-1]=='>')
1492 fullName = fullName.mid(1, len-2); 1492 fullName = fullName.mid(1, len-2);
1493 else if (fullName[0]=='(' && fullName[len-1]==')') 1493 else if (fullName[0]=='(' && fullName[len-1]==')')
1494 fullName = fullName.mid(1, len-2); 1494 fullName = fullName.mid(1, len-2);
1495 } 1495 }
1496 } 1496 }
1497} 1497}
1498 1498
1499void Addressee::setResource( Resource *resource ) 1499void Addressee::setResource( Resource *resource )
1500{ 1500{
1501 detach(); 1501 detach();
1502 mData->resource = resource; 1502 mData->resource = resource;
1503} 1503}
1504 1504
1505Resource *Addressee::resource() const 1505Resource *Addressee::resource() const
1506{ 1506{
1507 return mData->resource; 1507 return mData->resource;
1508} 1508}
1509 1509
1510//US
1511QString Addressee::resourceLabel()
1512{
1513 return i18n("Resource");
1514}
1515
1510void Addressee::setChanged( bool value ) 1516void Addressee::setChanged( bool value )
1511{ 1517{
1512 detach(); 1518 detach();
1513 mData->changed = value; 1519 mData->changed = value;
1514} 1520}
1515 1521
1516bool Addressee::changed() const 1522bool Addressee::changed() const
1517{ 1523{
1518 return mData->changed; 1524 return mData->changed;
1519} 1525}
1520 1526
1521QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 1527QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
1522{ 1528{
1523 if (!a.mData) return s; 1529 if (!a.mData) return s;
1524 1530
1525 s << a.uid(); 1531 s << a.uid();
1526 1532
1527 s << a.mData->name; 1533 s << a.mData->name;
1528 s << a.mData->formattedName; 1534 s << a.mData->formattedName;
1529 s << a.mData->familyName; 1535 s << a.mData->familyName;
1530 s << a.mData->givenName; 1536 s << a.mData->givenName;
1531 s << a.mData->additionalName; 1537 s << a.mData->additionalName;
1532 s << a.mData->prefix; 1538 s << a.mData->prefix;
1533 s << a.mData->suffix; 1539 s << a.mData->suffix;
diff --git a/kabc/addressee.h b/kabc/addressee.h
index ee98e03..393d1cc 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -771,47 +771,53 @@ class Addressee
771 static void parseEmailAddress( const QString &rawEmail, QString &fullName, 771 static void parseEmailAddress( const QString &rawEmail, QString &fullName,
772 QString &email ); 772 QString &email );
773 773
774 /** 774 /**
775 Debug output. 775 Debug output.
776 */ 776 */
777 void dump() const; 777 void dump() const;
778 778
779 /** 779 /**
780 Returns string representation of the addressee. 780 Returns string representation of the addressee.
781 */ 781 */
782 QString asString() const; 782 QString asString() const;
783 783
784 /** 784 /**
785 Set resource where the addressee is from. 785 Set resource where the addressee is from.
786 */ 786 */
787 void setResource( Resource *resource ); 787 void setResource( Resource *resource );
788 788
789 /** 789 /**
790 Return pointer to resource. 790 Return pointer to resource.
791 */ 791 */
792 Resource *resource() const; 792 Resource *resource() const;
793 793
794 /** 794 /**
795 Return resourcelabel.
796 */
797 //US
798 static QString resourceLabel();
799
800 /**
795 Mark addressee as changed. 801 Mark addressee as changed.
796 */ 802 */
797 void setChanged( bool value ); 803 void setChanged( bool value );
798 804
799 /** 805 /**
800 Return whether the addressee is changed. 806 Return whether the addressee is changed.
801 */ 807 */
802 bool changed() const; 808 bool changed() const;
803 809
804 private: 810 private:
805 Addressee copy(); 811 Addressee copy();
806 void detach(); 812 void detach();
807 813
808 struct AddresseeData; 814 struct AddresseeData;
809 mutable KSharedPtr<AddresseeData> mData; 815 mutable KSharedPtr<AddresseeData> mData;
810}; 816};
811 817
812QDataStream &operator<<( QDataStream &, const Addressee & ); 818QDataStream &operator<<( QDataStream &, const Addressee & );
813QDataStream &operator>>( QDataStream &, Addressee & ); 819QDataStream &operator>>( QDataStream &, Addressee & );
814 820
815} 821}
816 822
817#endif 823#endif
diff --git a/kabc/field.cpp b/kabc/field.cpp
index 41bbfde..bc2e176 100644
--- a/kabc/field.cpp
+++ b/kabc/field.cpp
@@ -11,48 +11,49 @@
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 <klocale.h> 29#include <klocale.h>
30#include <kconfig.h> 30#include <kconfig.h>
31#include <kconfigbase.h> 31#include <kconfigbase.h>
32#include <kglobal.h> 32#include <kglobal.h>
33 33
34#include "field.h" 34#include "field.h"
35#include "resource.h"
35 36
36using namespace KABC; 37using namespace KABC;
37 38
38class Field::FieldImpl 39class Field::FieldImpl
39{ 40{
40 public: 41 public:
41 FieldImpl( int fieldId, int category = 0, 42 FieldImpl( int fieldId, int category = 0,
42 const QString &label = QString::null, 43 const QString &label = QString::null,
43 const QString &key = QString::null, 44 const QString &key = QString::null,
44 const QString &app = QString::null ) 45 const QString &app = QString::null )
45 : mFieldId( fieldId ), mCategory( category ), mLabel( label ), 46 : mFieldId( fieldId ), mCategory( category ), mLabel( label ),
46 mKey( key ), mApp( app ) {} 47 mKey( key ), mApp( app ) {}
47 48
48 enum FieldId 49 enum FieldId
49 { 50 {
50 CustomField, 51 CustomField,
51 FormattedName, 52 FormattedName,
52 FamilyName, 53 FamilyName,
53 GivenName, 54 GivenName,
54 AdditionalName, 55 AdditionalName,
55 Prefix, 56 Prefix,
56 Suffix, 57 Suffix,
57 NickName, 58 NickName,
58 Birthday, 59 Birthday,
@@ -61,49 +62,50 @@ class Field::FieldImpl
61 HomeAddressRegion, 62 HomeAddressRegion,
62 HomeAddressPostalCode, 63 HomeAddressPostalCode,
63 HomeAddressCountry, 64 HomeAddressCountry,
64 HomeAddressLabel, 65 HomeAddressLabel,
65 BusinessAddressStreet, 66 BusinessAddressStreet,
66 BusinessAddressLocality, 67 BusinessAddressLocality,
67 BusinessAddressRegion, 68 BusinessAddressRegion,
68 BusinessAddressPostalCode, 69 BusinessAddressPostalCode,
69 BusinessAddressCountry, 70 BusinessAddressCountry,
70 BusinessAddressLabel, 71 BusinessAddressLabel,
71 HomePhone, 72 HomePhone,
72 BusinessPhone, 73 BusinessPhone,
73 MobilePhone, 74 MobilePhone,
74 HomeFax, 75 HomeFax,
75 BusinessFax, 76 BusinessFax,
76 CarPhone, 77 CarPhone,
77 Isdn, 78 Isdn,
78 Pager, 79 Pager,
79 Email, 80 Email,
80 Mailer, 81 Mailer,
81 Title, 82 Title,
82 Role, 83 Role,
83 Organization, 84 Organization,
84 Note, 85 Note,
85 Url 86 Url,
87 Resource
86 }; 88 };
87 89
88 int fieldId() { return mFieldId; } 90 int fieldId() { return mFieldId; }
89 int category() { return mCategory; } 91 int category() { return mCategory; }
90 92
91 QString label() { return mLabel; } 93 QString label() { return mLabel; }
92 QString key() { return mKey; } 94 QString key() { return mKey; }
93 QString app() { return mApp; } 95 QString app() { return mApp; }
94 96
95 private: 97 private:
96 int mFieldId; 98 int mFieldId;
97 int mCategory; 99 int mCategory;
98 100
99 QString mLabel; 101 QString mLabel;
100 QString mKey; 102 QString mKey;
101 QString mApp; 103 QString mApp;
102}; 104};
103 105
104 106
105Field::List Field::mAllFields; 107Field::List Field::mAllFields;
106Field::List Field::mDefaultFields; 108Field::List Field::mDefaultFields;
107Field::List Field::mCustomFields; 109Field::List Field::mCustomFields;
108 110
109 111
@@ -169,48 +171,50 @@ QString Field::label()
169 case FieldImpl::HomeFax: 171 case FieldImpl::HomeFax:
170 return Addressee::homeFaxLabel(); 172 return Addressee::homeFaxLabel();
171 case FieldImpl::BusinessFax: 173 case FieldImpl::BusinessFax:
172 return Addressee::businessFaxLabel(); 174 return Addressee::businessFaxLabel();
173 case FieldImpl::CarPhone: 175 case FieldImpl::CarPhone:
174 return Addressee::carPhoneLabel(); 176 return Addressee::carPhoneLabel();
175 case FieldImpl::Isdn: 177 case FieldImpl::Isdn:
176 return Addressee::isdnLabel(); 178 return Addressee::isdnLabel();
177 case FieldImpl::Pager: 179 case FieldImpl::Pager:
178 return Addressee::pagerLabel(); 180 return Addressee::pagerLabel();
179 case FieldImpl::Email: 181 case FieldImpl::Email:
180 return Addressee::emailLabel(); 182 return Addressee::emailLabel();
181 case FieldImpl::Mailer: 183 case FieldImpl::Mailer:
182 return Addressee::mailerLabel(); 184 return Addressee::mailerLabel();
183 case FieldImpl::Title: 185 case FieldImpl::Title:
184 return Addressee::titleLabel(); 186 return Addressee::titleLabel();
185 case FieldImpl::Role: 187 case FieldImpl::Role:
186 return Addressee::roleLabel(); 188 return Addressee::roleLabel();
187 case FieldImpl::Organization: 189 case FieldImpl::Organization:
188 return Addressee::organizationLabel(); 190 return Addressee::organizationLabel();
189 case FieldImpl::Note: 191 case FieldImpl::Note:
190 return Addressee::noteLabel(); 192 return Addressee::noteLabel();
191 case FieldImpl::Url: 193 case FieldImpl::Url:
192 return Addressee::urlLabel(); 194 return Addressee::urlLabel();
195 case FieldImpl::Resource:
196 return Addressee::resourceLabel();
193 case FieldImpl::CustomField: 197 case FieldImpl::CustomField:
194 return mImpl->label(); 198 return mImpl->label();
195 default: 199 default:
196 return i18n("Unknown Field"); 200 return i18n("Unknown Field");
197 } 201 }
198} 202}
199 203
200int Field::category() 204int Field::category()
201{ 205{
202 return mImpl->category(); 206 return mImpl->category();
203} 207}
204 208
205QString Field::categoryLabel( int category ) 209QString Field::categoryLabel( int category )
206{ 210{
207 switch ( category ) { 211 switch ( category ) {
208 case All: 212 case All:
209 return i18n("All"); 213 return i18n("All");
210 case Frequent: 214 case Frequent:
211 return i18n("Frequent"); 215 return i18n("Frequent");
212 case Address: 216 case Address:
213 return i18n("Address"); 217 return i18n("Address");
214 case Email: 218 case Email:
215 return i18n("Email"); 219 return i18n("Email");
216 case Personal: 220 case Personal:
@@ -246,48 +250,51 @@ QString Field::value( const KABC::Addressee &a )
246 case FieldImpl::Title: 250 case FieldImpl::Title:
247 return a.title(); 251 return a.title();
248 case FieldImpl::Role: 252 case FieldImpl::Role:
249 return a.role(); 253 return a.role();
250 case FieldImpl::Organization: 254 case FieldImpl::Organization:
251 return a.organization(); 255 return a.organization();
252 case FieldImpl::Note: 256 case FieldImpl::Note:
253 return a.note(); 257 return a.note();
254 case FieldImpl::Email: 258 case FieldImpl::Email:
255 return a.preferredEmail(); 259 return a.preferredEmail();
256 case FieldImpl::Birthday: 260 case FieldImpl::Birthday:
257 if ( a.birthday().isValid() ) { 261 if ( a.birthday().isValid() ) {
258//the generated code had the following format: return a.birthday().date().toString( Qt::ISODate ); 262//the generated code had the following format: return a.birthday().date().toString( Qt::ISODate );
259// But Qt::IsoDate was not specified. 263// But Qt::IsoDate was not specified.
260 QString _oldFormat = KGlobal::locale()->dateFormat(); 264 QString _oldFormat = KGlobal::locale()->dateFormat();
261 KGlobal::locale()->setDateFormat("%Y-%m-%d"); // = Qt::ISODate 265 KGlobal::locale()->setDateFormat("%Y-%m-%d"); // = Qt::ISODate
262 QString dt = KGlobal::locale()->formatDate(a.birthday().date(), false); 266 QString dt = KGlobal::locale()->formatDate(a.birthday().date(), false);
263 KGlobal::locale()->setDateFormat(_oldFormat); 267 KGlobal::locale()->setDateFormat(_oldFormat);
264 return dt; 268 return dt;
265 } 269 }
266 else 270 else
267 return QString::null; 271 return QString::null;
268 case FieldImpl::Url: 272 case FieldImpl::Url:
269 return a.url().prettyURL(); 273 return a.url().prettyURL();
274//US
275 case FieldImpl::Resource:
276 return a.resource()->resourceName();
270 case FieldImpl::HomePhone: 277 case FieldImpl::HomePhone:
271 return a.phoneNumber( PhoneNumber::Home ).number(); 278 return a.phoneNumber( PhoneNumber::Home ).number();
272 case FieldImpl::BusinessPhone: 279 case FieldImpl::BusinessPhone:
273 return a.phoneNumber( PhoneNumber::Work ).number(); 280 return a.phoneNumber( PhoneNumber::Work ).number();
274 case FieldImpl::MobilePhone: 281 case FieldImpl::MobilePhone:
275 return a.phoneNumber( PhoneNumber::Cell ).number(); 282 return a.phoneNumber( PhoneNumber::Cell ).number();
276 case FieldImpl::HomeFax: 283 case FieldImpl::HomeFax:
277 return a.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ).number(); 284 return a.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ).number();
278 case FieldImpl::BusinessFax: 285 case FieldImpl::BusinessFax:
279 return a.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ).number(); 286 return a.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ).number();
280 case FieldImpl::CarPhone: 287 case FieldImpl::CarPhone:
281 return a.phoneNumber( PhoneNumber::Car ).number(); 288 return a.phoneNumber( PhoneNumber::Car ).number();
282 case FieldImpl::Isdn: 289 case FieldImpl::Isdn:
283 return a.phoneNumber( PhoneNumber::Isdn ).number(); 290 return a.phoneNumber( PhoneNumber::Isdn ).number();
284 case FieldImpl::Pager: 291 case FieldImpl::Pager:
285 return a.phoneNumber( PhoneNumber::Pager ).number(); 292 return a.phoneNumber( PhoneNumber::Pager ).number();
286 case FieldImpl::HomeAddressStreet: 293 case FieldImpl::HomeAddressStreet:
287 return a.address( Address::Home ).street(); 294 return a.address( Address::Home ).street();
288 case FieldImpl::HomeAddressLocality: 295 case FieldImpl::HomeAddressLocality:
289 return a.address( Address::Home ).locality(); 296 return a.address( Address::Home ).locality();
290 case FieldImpl::HomeAddressRegion: 297 case FieldImpl::HomeAddressRegion:
291 return a.address( Address::Home ).region(); 298 return a.address( Address::Home ).region();
292 case FieldImpl::HomeAddressPostalCode: 299 case FieldImpl::HomeAddressPostalCode:
293 return a.address( Address::Home ).postalCode(); 300 return a.address( Address::Home ).postalCode();
@@ -339,96 +346,99 @@ bool Field::setValue( KABC::Addressee &a, const QString &value )
339 return true; 346 return true;
340 case FieldImpl::Title: 347 case FieldImpl::Title:
341 a.setTitle( value ); 348 a.setTitle( value );
342 return true; 349 return true;
343 case FieldImpl::Role: 350 case FieldImpl::Role:
344 a.setRole( value ); 351 a.setRole( value );
345 return true; 352 return true;
346 case FieldImpl::Organization: 353 case FieldImpl::Organization:
347 a.setOrganization( value ); 354 a.setOrganization( value );
348 return true; 355 return true;
349 case FieldImpl::Note: 356 case FieldImpl::Note:
350 a.setNote( value ); 357 a.setNote( value );
351 return true; 358 return true;
352 case FieldImpl::Birthday: 359 case FieldImpl::Birthday:
353//US 360//US
354//the generated code had the following format: return a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); 361//the generated code had the following format: return a.setBirthday( QDate::fromString( value, Qt::ISODate ) );
355// But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? 362// But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ?
356 { 363 {
357 QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate 364 QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate
358 a.setBirthday(dt); 365 a.setBirthday(dt);
359 } 366 }
360 return true; 367 return true;
361 case FieldImpl::CustomField: 368 case FieldImpl::CustomField:
362 a.insertCustom( mImpl->app(), mImpl->key(), value ); 369 a.insertCustom( mImpl->app(), mImpl->key(), value );
370//US never copy the resourcename back to the adressee.
371 case FieldImpl::Resource:
363 default: 372 default:
364 return false; 373 return false;
365 } 374 }
366} 375}
367 376
368bool Field::isCustom() 377bool Field::isCustom()
369{ 378{
370 return mImpl->fieldId() == FieldImpl::CustomField; 379 return mImpl->fieldId() == FieldImpl::CustomField;
371} 380}
372 381
373Field::List Field::allFields() 382Field::List Field::allFields()
374{ 383{
375 if ( mAllFields.isEmpty() ) { 384 if ( mAllFields.isEmpty() ) {
376 createField( FieldImpl::FormattedName, Frequent ); 385 createField( FieldImpl::FormattedName, Frequent );
377 createField( FieldImpl::FamilyName, Frequent ); 386 createField( FieldImpl::FamilyName, Frequent );
378 createField( FieldImpl::GivenName, Frequent ); 387 createField( FieldImpl::GivenName, Frequent );
379 createField( FieldImpl::AdditionalName ); 388 createField( FieldImpl::AdditionalName );
380 createField( FieldImpl::Prefix ); 389 createField( FieldImpl::Prefix );
381 createField( FieldImpl::Suffix ); 390 createField( FieldImpl::Suffix );
382 createField( FieldImpl::NickName, Personal ); 391 createField( FieldImpl::NickName, Personal );
383 createField( FieldImpl::Birthday, Personal ); 392 createField( FieldImpl::Birthday, Personal );
384 createField( FieldImpl::HomeAddressStreet, Address|Personal ); 393 createField( FieldImpl::HomeAddressStreet, Address|Personal );
385 createField( FieldImpl::HomeAddressLocality, Address|Personal ); 394 createField( FieldImpl::HomeAddressLocality, Address|Personal );
386 createField( FieldImpl::HomeAddressRegion, Address|Personal ); 395 createField( FieldImpl::HomeAddressRegion, Address|Personal );
387 createField( FieldImpl::HomeAddressPostalCode, Address|Personal ); 396 createField( FieldImpl::HomeAddressPostalCode, Address|Personal );
388 createField( FieldImpl::HomeAddressCountry, Address|Personal ); 397 createField( FieldImpl::HomeAddressCountry, Address|Personal );
389 createField( FieldImpl::HomeAddressLabel, Address|Personal ); 398 createField( FieldImpl::HomeAddressLabel, Address|Personal );
390 createField( FieldImpl::BusinessAddressStreet, Address|Organization ); 399 createField( FieldImpl::BusinessAddressStreet, Address|Organization );
391 createField( FieldImpl::BusinessAddressLocality, Address|Organization ); 400 createField( FieldImpl::BusinessAddressLocality, Address|Organization );
392 createField( FieldImpl::BusinessAddressRegion, Address|Organization ); 401 createField( FieldImpl::BusinessAddressRegion, Address|Organization );
393 createField( FieldImpl::BusinessAddressPostalCode, Address|Organization ); 402 createField( FieldImpl::BusinessAddressPostalCode, Address|Organization );
394 createField( FieldImpl::BusinessAddressCountry, Address|Organization ); 403 createField( FieldImpl::BusinessAddressCountry, Address|Organization );
395 createField( FieldImpl::BusinessAddressLabel, Address|Organization ); 404 createField( FieldImpl::BusinessAddressLabel, Address|Organization );
396 createField( FieldImpl::HomePhone, Personal|Frequent ); 405 createField( FieldImpl::HomePhone, Personal|Frequent );
397 createField( FieldImpl::BusinessPhone, Organization|Frequent ); 406 createField( FieldImpl::BusinessPhone, Organization|Frequent );
398 createField( FieldImpl::MobilePhone, Frequent ); 407 createField( FieldImpl::MobilePhone, Frequent );
399 createField( FieldImpl::HomeFax ); 408 createField( FieldImpl::HomeFax );
400 createField( FieldImpl::BusinessFax ); 409 createField( FieldImpl::BusinessFax );
401 createField( FieldImpl::CarPhone ); 410 createField( FieldImpl::CarPhone );
402 createField( FieldImpl::Isdn ); 411 createField( FieldImpl::Isdn );
403 createField( FieldImpl::Pager ); 412 createField( FieldImpl::Pager );
404 createField( FieldImpl::Email, Email|Frequent ); 413 createField( FieldImpl::Email, Email|Frequent );
405 createField( FieldImpl::Mailer, Email ); 414 createField( FieldImpl::Mailer, Email );
406 createField( FieldImpl::Title, Organization ); 415 createField( FieldImpl::Title, Organization );
407 createField( FieldImpl::Role, Organization ); 416 createField( FieldImpl::Role, Organization );
408 createField( FieldImpl::Organization, Organization ); 417 createField( FieldImpl::Organization, Organization );
409 createField( FieldImpl::Note ); 418 createField( FieldImpl::Note );
410 createField( FieldImpl::Url ); 419 createField( FieldImpl::Url );
420 createField( FieldImpl::Resource );
411 } 421 }
412 422
413 return mAllFields; 423 return mAllFields;
414} 424}
415 425
416Field::List Field::defaultFields() 426Field::List Field::defaultFields()
417{ 427{
418 if ( mDefaultFields.isEmpty() ) { 428 if ( mDefaultFields.isEmpty() ) {
419 createDefaultField( FieldImpl::GivenName ); 429 createDefaultField( FieldImpl::GivenName );
420 createDefaultField( FieldImpl::FamilyName ); 430 createDefaultField( FieldImpl::FamilyName );
421 createDefaultField( FieldImpl::Email ); 431 createDefaultField( FieldImpl::Email );
422 } 432 }
423 433
424 return mDefaultFields; 434 return mDefaultFields;
425} 435}
426 436
427void Field::createField( int id, int category ) 437void Field::createField( int id, int category )
428{ 438{
429 mAllFields.append( new Field( new FieldImpl( id, category ) ) ); 439 mAllFields.append( new Field( new FieldImpl( id, category ) ) );
430} 440}
431 441
432void Field::createDefaultField( int id, int category ) 442void Field::createDefaultField( int id, int category )
433{ 443{
434 mDefaultFields.append( new Field( new FieldImpl( id, category ) ) ); 444 mDefaultFields.append( new Field( new FieldImpl( id, category ) ) );
@@ -447,104 +457,110 @@ void Field::deleteFields()
447 delete (*it); 457 delete (*it);
448 } 458 }
449 mDefaultFields.clear(); 459 mDefaultFields.clear();
450 460
451 for( it = mCustomFields.begin(); it != mCustomFields.end(); ++it ) { 461 for( it = mCustomFields.begin(); it != mCustomFields.end(); ++it ) {
452 delete (*it); 462 delete (*it);
453 } 463 }
454 mCustomFields.clear(); 464 mCustomFields.clear();
455} 465}
456 466
457void Field::saveFields( const QString &identifier, 467void Field::saveFields( const QString &identifier,
458 const Field::List &fields ) 468 const Field::List &fields )
459{ 469{
460 KConfig *cfg = KGlobal::config(); 470 KConfig *cfg = KGlobal::config();
461 KConfigGroupSaver( cfg, "KABCFields" ); 471 KConfigGroupSaver( cfg, "KABCFields" );
462 saveFields( cfg, identifier, fields ); 472 saveFields( cfg, identifier, fields );
463} 473}
464 474
465void Field::saveFields( KConfig *cfg, const QString &identifier, 475void Field::saveFields( KConfig *cfg, const QString &identifier,
466 const Field::List &fields ) 476 const Field::List &fields )
467{ 477{
468 QValueList<int> fieldIds; 478 QValueList<int> fieldIds;
469 479
470//US 480//US
471//US qDebug("Field::saveFields to %s %s", cfg->getFileName().latin1(), identifier.latin1()); 481// qDebug("Field::saveFields to %s %s", cfg->getFileName().latin1(), identifier.latin1());
472 482
473 int custom = 0; 483 int custom = 0;
474 Field::List::ConstIterator it; 484 Field::List::ConstIterator it;
475 for( it = fields.begin(); it != fields.end(); ++it ) { 485 for( it = fields.begin(); it != fields.end(); ++it ) {
476//US 486//US
477//US qDebug("Field::saveFields field:%i", (*it)->mImpl->fieldId()); 487// qDebug("Field::saveFields field:%i", (*it)->mImpl->fieldId());
478 488
479 fieldIds.append( (*it)->mImpl->fieldId() ); 489 fieldIds.append( (*it)->mImpl->fieldId() );
480 if( (*it)->isCustom() ) { 490 if( (*it)->isCustom() ) {
481 QStringList customEntry; 491 QStringList customEntry;
482 customEntry << (*it)->mImpl->label(); 492 customEntry << (*it)->mImpl->label();
483 customEntry << (*it)->mImpl->key(); 493 customEntry << (*it)->mImpl->key();
484 customEntry << (*it)->mImpl->app(); 494 customEntry << (*it)->mImpl->app();
485 cfg->writeEntry( "KABC_CustomEntry_" + identifier + "_" + 495 cfg->writeEntry( "KABC_CustomEntry_" + identifier + "_" +
486 QString::number( custom++ ), customEntry ); 496 QString::number( custom++ ), customEntry );
487 } 497 }
488 } 498 }
489 cfg->writeEntry( identifier, fieldIds ); 499 cfg->writeEntry( identifier, fieldIds );
490} 500}
491 501
492Field::List Field::restoreFields( const QString &identifier ) 502Field::List Field::restoreFields( const QString &identifier )
493{ 503{
504//US
505// qDebug("Field::restoreFields, identifier: %s", identifier.latin1());
506
494 KConfig *cfg = KGlobal::config(); 507 KConfig *cfg = KGlobal::config();
495 KConfigGroupSaver( cfg, "KABCFields" ); 508 KConfigGroupSaver( cfg, "KABCFields" );
496 cfg->setGroup( "KABCFields" ); 509 cfg->setGroup( "KABCFields" );
497 510
498 Field::List l = restoreFields( cfg, identifier ); 511 Field::List l = restoreFields( cfg, identifier );
499 512
500 return l; 513 return l;
501} 514}
502 515
503Field::List Field::restoreFields( KConfig *cfg, const QString &identifier ) 516Field::List Field::restoreFields( KConfig *cfg, const QString &identifier )
504{ 517{
505 QValueList<int> fieldIds = cfg->readIntListEntry( identifier); 518 QValueList<int> fieldIds = cfg->readIntListEntry( identifier);
506//US 519//US
507 qDebug("Field::restoreFields from %s", cfg->getFileName().latin1()); 520// qDebug("Field::restoreFields from %s, identifier: %s", cfg->getFileName().latin1(), identifier.latin1());
508 521
509 Field::List fields; 522 Field::List fields;
510 523
511 int custom = 0; 524 int custom = 0;
512 QValueList<int>::ConstIterator it; 525 QValueList<int>::ConstIterator it;
513 for( it = fieldIds.begin(); it != fieldIds.end(); ++it ) { 526 for( it = fieldIds.begin(); it != fieldIds.end(); ++it ) {
514 FieldImpl *f = 0; 527 FieldImpl *f = 0;
515 if ( (*it) == FieldImpl::CustomField ) { 528 if ( (*it) == FieldImpl::CustomField ) {
516 QStringList customEntry = cfg->readListEntry( "KABC_CustomEntry_" + 529 QStringList customEntry = cfg->readListEntry( "KABC_CustomEntry_" +
517 identifier + "_" + 530 identifier + "_" +
518 QString::number( custom++ ) ); 531 QString::number( custom++ ) );
519 f = new FieldImpl( *it, CustomCategory, customEntry[ 0 ], 532 f = new FieldImpl( *it, CustomCategory, customEntry[ 0 ],
520 customEntry[ 1 ], customEntry[ 2 ] ); 533 customEntry[ 1 ], customEntry[ 2 ] );
521 } else { 534 } else {
522 f = new FieldImpl( *it ); 535 f = new FieldImpl( *it );
523 } 536 }
524 fields.append( new Field( f ) ); 537 fields.append( new Field( f ) );
525 } 538 }
526 539
527 return fields; 540 return fields;
528} 541}
529 542
530bool Field::equals( Field *field ) 543bool Field::equals( Field *field )
531{ 544{
532 bool sameId = ( mImpl->fieldId() == field->mImpl->fieldId() ); 545 bool sameId = ( mImpl->fieldId() == field->mImpl->fieldId() );
533 546
534 if ( !sameId ) return false; 547 if ( !sameId ) return false;
535 548
536 if ( mImpl->fieldId() != FieldImpl::CustomField ) return true; 549 if ( mImpl->fieldId() != FieldImpl::CustomField ) return true;
537 550
538 return mImpl->key() == field->mImpl->key(); 551 return mImpl->key() == field->mImpl->key();
539} 552}
540 553
541Field *Field::createCustomField( const QString &label, int category, 554Field *Field::createCustomField( const QString &label, int category,
542 const QString &key, const QString &app ) 555 const QString &key, const QString &app )
543{ 556{
544 Field *field = new Field( new FieldImpl( FieldImpl::CustomField, 557 Field *field = new Field( new FieldImpl( FieldImpl::CustomField,
545 category | CustomCategory, 558 category | CustomCategory,
546 label, key, app ) ); 559 label, key, app ) );
560//US
561// qDebug("Field::createCustomField label %s", label.latin1() );
562
547 mCustomFields.append( field ); 563 mCustomFields.append( field );
548 564
549 return field; 565 return field;
550} 566}