author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/field.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | kabc/field.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/kabc/field.cpp b/kabc/field.cpp index 7c6d7a9..203f696 100644 --- a/kabc/field.cpp +++ b/kabc/field.cpp | |||
@@ -12,48 +12,50 @@ | |||
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 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (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 | #include "resource.h" |
36 | //Added by qt3to4: | ||
37 | #include <Q3ValueList> | ||
36 | 38 | ||
37 | using namespace KABC; | 39 | using namespace KABC; |
38 | 40 | ||
39 | class Field::FieldImpl | 41 | class Field::FieldImpl |
40 | { | 42 | { |
41 | public: | 43 | public: |
42 | FieldImpl( int fieldId, int category = 0, | 44 | FieldImpl( int fieldId, int category = 0, |
43 | const QString &label = QString::null, | 45 | const QString &label = QString::null, |
44 | const QString &key = QString::null, | 46 | const QString &key = QString::null, |
45 | const QString &app = QString::null ) | 47 | const QString &app = QString::null ) |
46 | : mFieldId( fieldId ), mCategory( category ), mLabel( label ), | 48 | : mFieldId( fieldId ), mCategory( category ), mLabel( label ), |
47 | mKey( key ), mApp( app ) {} | 49 | mKey( key ), mApp( app ) {} |
48 | 50 | ||
49 | enum FieldId | 51 | enum FieldId |
50 | { | 52 | { |
51 | CustomField, | 53 | CustomField, |
52 | FormattedName, | 54 | FormattedName, |
53 | FamilyName, | 55 | FamilyName, |
54 | GivenName, | 56 | GivenName, |
55 | AdditionalName, | 57 | AdditionalName, |
56 | Prefix, | 58 | Prefix, |
57 | Suffix, | 59 | Suffix, |
58 | NickName, | 60 | NickName, |
59 | Birthday, | 61 | Birthday, |
@@ -356,49 +358,49 @@ bool Field::setValue( KABC::Addressee &a, const QString &value ) | |||
356 | case FieldImpl::NickName: | 358 | case FieldImpl::NickName: |
357 | a.setNickName( value ); | 359 | a.setNickName( value ); |
358 | return true; | 360 | return true; |
359 | case FieldImpl::Mailer: | 361 | case FieldImpl::Mailer: |
360 | a.setMailer( value ); | 362 | a.setMailer( value ); |
361 | return true; | 363 | return true; |
362 | case FieldImpl::Title: | 364 | case FieldImpl::Title: |
363 | a.setTitle( value ); | 365 | a.setTitle( value ); |
364 | return true; | 366 | return true; |
365 | case FieldImpl::Role: | 367 | case FieldImpl::Role: |
366 | a.setRole( value ); | 368 | a.setRole( value ); |
367 | return true; | 369 | return true; |
368 | case FieldImpl::Organization: | 370 | case FieldImpl::Organization: |
369 | a.setOrganization( value ); | 371 | a.setOrganization( value ); |
370 | return true; | 372 | return true; |
371 | case FieldImpl::Note: | 373 | case FieldImpl::Note: |
372 | a.setNote( value ); | 374 | a.setNote( value ); |
373 | return true; | 375 | return true; |
374 | case FieldImpl::Birthday: | 376 | case FieldImpl::Birthday: |
375 | //US | 377 | //US |
376 | //the generated code had the following format: return a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); | 378 | //the generated code had the following format: return a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); |
377 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? | 379 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? |
378 | { | 380 | { |
379 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate | 381 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate |
380 | a.setBirthday(dt); | 382 | a.setBirthday((QDateTime)dt); |
381 | } | 383 | } |
382 | return true; | 384 | return true; |
383 | case FieldImpl::CustomField: | 385 | case FieldImpl::CustomField: |
384 | a.insertCustom( mImpl->app(), mImpl->key(), value ); | 386 | a.insertCustom( mImpl->app(), mImpl->key(), value ); |
385 | //US never copy the resourcename back to the adressee. | 387 | //US never copy the resourcename back to the adressee. |
386 | case FieldImpl::Resource: | 388 | case FieldImpl::Resource: |
387 | default: | 389 | default: |
388 | return false; | 390 | return false; |
389 | } | 391 | } |
390 | } | 392 | } |
391 | 393 | ||
392 | bool Field::isCustom() | 394 | bool Field::isCustom() |
393 | { | 395 | { |
394 | return mImpl->fieldId() == FieldImpl::CustomField; | 396 | return mImpl->fieldId() == FieldImpl::CustomField; |
395 | } | 397 | } |
396 | 398 | ||
397 | Field::List Field::allFields() | 399 | Field::List Field::allFields() |
398 | { | 400 | { |
399 | if ( mAllFields.isEmpty() ) { | 401 | if ( mAllFields.isEmpty() ) { |
400 | createField( FieldImpl::FormattedName, Frequent ); | 402 | createField( FieldImpl::FormattedName, Frequent ); |
401 | createField( FieldImpl::FamilyName, Frequent ); | 403 | createField( FieldImpl::FamilyName, Frequent ); |
402 | createField( FieldImpl::GivenName, Frequent ); | 404 | createField( FieldImpl::GivenName, Frequent ); |
403 | createField( FieldImpl::AdditionalName ); | 405 | createField( FieldImpl::AdditionalName ); |
404 | createField( FieldImpl::Prefix ); | 406 | createField( FieldImpl::Prefix ); |
@@ -472,96 +474,96 @@ void Field::deleteFields() | |||
472 | mAllFields.clear(); | 474 | mAllFields.clear(); |
473 | 475 | ||
474 | for( it = mDefaultFields.begin(); it != mDefaultFields.end(); ++it ) { | 476 | for( it = mDefaultFields.begin(); it != mDefaultFields.end(); ++it ) { |
475 | delete (*it); | 477 | delete (*it); |
476 | } | 478 | } |
477 | mDefaultFields.clear(); | 479 | mDefaultFields.clear(); |
478 | 480 | ||
479 | for( it = mCustomFields.begin(); it != mCustomFields.end(); ++it ) { | 481 | for( it = mCustomFields.begin(); it != mCustomFields.end(); ++it ) { |
480 | delete (*it); | 482 | delete (*it); |
481 | } | 483 | } |
482 | mCustomFields.clear(); | 484 | mCustomFields.clear(); |
483 | } | 485 | } |
484 | 486 | ||
485 | void Field::saveFields( const QString &identifier, | 487 | void Field::saveFields( const QString &identifier, |
486 | const Field::List &fields ) | 488 | const Field::List &fields ) |
487 | { | 489 | { |
488 | KConfig *cfg = KGlobal::config(); | 490 | KConfig *cfg = KGlobal::config(); |
489 | KConfigGroupSaver( cfg, "KABCFields" ); | 491 | KConfigGroupSaver( cfg, "KABCFields" ); |
490 | saveFields( cfg, identifier, fields ); | 492 | saveFields( cfg, identifier, fields ); |
491 | } | 493 | } |
492 | 494 | ||
493 | void Field::saveFields( KConfig *cfg, const QString &identifier, | 495 | void Field::saveFields( KConfig *cfg, const QString &identifier, |
494 | const Field::List &fields ) | 496 | const Field::List &fields ) |
495 | { | 497 | { |
496 | QValueList<int> fieldIds; | 498 | Q3ValueList<int> fieldIds; |
497 | 499 | ||
498 | //US | 500 | //US |
499 | // qDebug("Field::saveFields to %s %s", cfg->getFileName().latin1(), identifier.latin1()); | 501 | // qDebug("Field::saveFields to %s %s", cfg->getFileName().latin1(), identifier.latin1()); |
500 | 502 | ||
501 | int custom = 0; | 503 | int custom = 0; |
502 | Field::List::ConstIterator it; | 504 | Field::List::ConstIterator it; |
503 | for( it = fields.begin(); it != fields.end(); ++it ) { | 505 | for( it = fields.begin(); it != fields.end(); ++it ) { |
504 | //US | 506 | //US |
505 | // qDebug("Field::saveFields field:%i", (*it)->mImpl->fieldId()); | 507 | // qDebug("Field::saveFields field:%i", (*it)->mImpl->fieldId()); |
506 | 508 | ||
507 | fieldIds.append( (*it)->mImpl->fieldId() ); | 509 | fieldIds.append( (*it)->mImpl->fieldId() ); |
508 | if( (*it)->isCustom() ) { | 510 | if( (*it)->isCustom() ) { |
509 | QStringList customEntry; | 511 | QStringList customEntry; |
510 | customEntry << (*it)->mImpl->label(); | 512 | customEntry << (*it)->mImpl->label(); |
511 | customEntry << (*it)->mImpl->key(); | 513 | customEntry << (*it)->mImpl->key(); |
512 | customEntry << (*it)->mImpl->app(); | 514 | customEntry << (*it)->mImpl->app(); |
513 | cfg->writeEntry( "KABC_CustomEntry_" + identifier + "_" + | 515 | cfg->writeEntry( "KABC_CustomEntry_" + identifier + "_" + |
514 | QString::number( custom++ ), customEntry ); | 516 | QString::number( custom++ ), customEntry ); |
515 | } | 517 | } |
516 | } | 518 | } |
517 | cfg->writeEntry( identifier, fieldIds ); | 519 | cfg->writeEntry( identifier, fieldIds ); |
518 | } | 520 | } |
519 | 521 | ||
520 | Field::List Field::restoreFields( const QString &identifier ) | 522 | Field::List Field::restoreFields( const QString &identifier ) |
521 | { | 523 | { |
522 | //US | 524 | //US |
523 | // qDebug("Field::restoreFields, identifier: %s", identifier.latin1()); | 525 | // qDebug("Field::restoreFields, identifier: %s", identifier.latin1()); |
524 | 526 | ||
525 | KConfig *cfg = KGlobal::config(); | 527 | KConfig *cfg = KGlobal::config(); |
526 | KConfigGroupSaver( cfg, "KABCFields" ); | 528 | KConfigGroupSaver( cfg, "KABCFields" ); |
527 | cfg->setGroup( "KABCFields" ); | 529 | cfg->setGroup( "KABCFields" ); |
528 | 530 | ||
529 | Field::List l = restoreFields( cfg, identifier ); | 531 | Field::List l = restoreFields( cfg, identifier ); |
530 | 532 | ||
531 | return l; | 533 | return l; |
532 | } | 534 | } |
533 | 535 | ||
534 | Field::List Field::restoreFields( KConfig *cfg, const QString &identifier ) | 536 | Field::List Field::restoreFields( KConfig *cfg, const QString &identifier ) |
535 | { | 537 | { |
536 | QValueList<int> fieldIds = cfg->readIntListEntry( identifier); | 538 | Q3ValueList<int> fieldIds = cfg->readIntListEntry( identifier); |
537 | //US | 539 | //US |
538 | // qDebug("Field::restoreFields from %s, identifier: %s", cfg->getFileName().latin1(), identifier.latin1()); | 540 | // qDebug("Field::restoreFields from %s, identifier: %s", cfg->getFileName().latin1(), identifier.latin1()); |
539 | 541 | ||
540 | Field::List fields; | 542 | Field::List fields; |
541 | 543 | ||
542 | int custom = 0; | 544 | int custom = 0; |
543 | QValueList<int>::ConstIterator it; | 545 | Q3ValueList<int>::ConstIterator it; |
544 | for( it = fieldIds.begin(); it != fieldIds.end(); ++it ) { | 546 | for( it = fieldIds.begin(); it != fieldIds.end(); ++it ) { |
545 | FieldImpl *f = 0; | 547 | FieldImpl *f = 0; |
546 | if ( (*it) == FieldImpl::CustomField ) { | 548 | if ( (*it) == FieldImpl::CustomField ) { |
547 | QStringList customEntry = cfg->readListEntry( "KABC_CustomEntry_" + | 549 | QStringList customEntry = cfg->readListEntry( "KABC_CustomEntry_" + |
548 | identifier + "_" + | 550 | identifier + "_" + |
549 | QString::number( custom++ ) ); | 551 | QString::number( custom++ ) ); |
550 | f = new FieldImpl( *it, CustomCategory, customEntry[ 0 ], | 552 | f = new FieldImpl( *it, CustomCategory, customEntry[ 0 ], |
551 | customEntry[ 1 ], customEntry[ 2 ] ); | 553 | customEntry[ 1 ], customEntry[ 2 ] ); |
552 | } else { | 554 | } else { |
553 | f = new FieldImpl( *it ); | 555 | f = new FieldImpl( *it ); |
554 | } | 556 | } |
555 | fields.append( new Field( f ) ); | 557 | fields.append( new Field( f ) ); |
556 | } | 558 | } |
557 | 559 | ||
558 | return fields; | 560 | return fields; |
559 | } | 561 | } |
560 | 562 | ||
561 | bool Field::equals( Field *field ) | 563 | bool Field::equals( Field *field ) |
562 | { | 564 | { |
563 | bool sameId = ( mImpl->fieldId() == field->mImpl->fieldId() ); | 565 | bool sameId = ( mImpl->fieldId() == field->mImpl->fieldId() ); |
564 | 566 | ||
565 | if ( !sameId ) return false; | 567 | if ( !sameId ) return false; |
566 | 568 | ||
567 | if ( mImpl->fieldId() != FieldImpl::CustomField ) return true; | 569 | if ( mImpl->fieldId() != FieldImpl::CustomField ) return true; |