summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2005-01-26 01:11:54 (UTC)
committer zautrix <zautrix>2005-01-26 01:11:54 (UTC)
commitab91893abef351f53275248a50032a6d5175132a (patch) (unidiff)
tree7ecb1aba3741dbffb34ad28787538db942e4d448 /kabc
parentc3ec0a5a43fb328f2d190b8adee1ef662746fb41 (diff)
downloadkdepimpi-ab91893abef351f53275248a50032a6d5175132a.zip
kdepimpi-ab91893abef351f53275248a50032a6d5175132a.tar.gz
kdepimpi-ab91893abef351f53275248a50032a6d5175132a.tar.bz2
fixes
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp10
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp4
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmconverter.cpp52
3 files changed, 12 insertions, 54 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 9e61261..f3744bc 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -547,276 +547,276 @@ void AddressBook::smplifyAddressees()
547{ 547{
548 Iterator ait; 548 Iterator ait;
549 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
550 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
551 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
552 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
553 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
554 } 554 }
555} 555}
556void AddressBook::removeSyncInfo( QString syncProfile) 556void AddressBook::removeSyncInfo( QString syncProfile)
557{ 557{
558 Iterator ait; 558 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) { 559 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile ); 560 (*ait).removeID( syncProfile );
561 } 561 }
562 if ( syncProfile.isEmpty() ) { 562 if ( syncProfile.isEmpty() ) {
563 Iterator it = begin(); 563 Iterator it = begin();
564 Iterator it2 ; 564 Iterator it2 ;
565 while ( it != end() ) { 565 while ( it != end() ) {
566 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 566 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
567 it2 = it; 567 it2 = it;
568 //qDebug("removing %s ",(*it).uid().latin1() ); 568 //qDebug("removing %s ",(*it).uid().latin1() );
569 ++it; 569 ++it;
570 removeAddressee( it2 ); 570 removeAddressee( it2 );
571 } else { 571 } else {
572 //qDebug("skipping %s ",(*it).uid().latin1() ); 572 //qDebug("skipping %s ",(*it).uid().latin1() );
573 ++it; 573 ++it;
574 } 574 }
575 } 575 }
576 } else { 576 } else {
577 Addressee lse; 577 Addressee lse;
578 lse = findByUid( "last-syncAddressee-"+ syncProfile ); 578 lse = findByUid( "last-syncAddressee-"+ syncProfile );
579 if ( ! lse.isEmpty() ) 579 if ( ! lse.isEmpty() )
580 removeAddressee( lse ); 580 removeAddressee( lse );
581 } 581 }
582 582
583} 583}
584void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 584void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
585{ 585{
586 Iterator ait; 586 Iterator ait;
587 for ( ait = begin(); ait != end(); ++ait ) { 587 for ( ait = begin(); ait != end(); ++ait ) {
588 QString id = (*ait).IDStr(); 588 QString id = (*ait).IDStr();
589 (*ait).setIDStr( ":"); 589 (*ait).setIDStr( ":");
590 (*ait).setExternalUID( id ); 590 (*ait).setExternalUID( id );
591 (*ait).setOriginalExternalUID( id ); 591 (*ait).setOriginalExternalUID( id );
592 if ( isPreSync ) 592 if ( isPreSync )
593 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 593 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
594 else { 594 else {
595 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 595 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
596 (*ait).setID( currentSyncDevice,id ); 596 (*ait).setID( currentSyncDevice,id );
597 597
598 } 598 }
599 } 599 }
600} 600}
601void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 601void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
602{ 602{
603 603
604 setUntagged(); 604 setUntagged();
605 KABC::Addressee::List list; 605 KABC::Addressee::List list;
606 QFile file( fileName ); 606 QFile file( fileName );
607 file.open( IO_ReadOnly ); 607 file.open( IO_ReadOnly );
608 QByteArray rawData = file.readAll(); 608 QByteArray rawData = file.readAll();
609 file.close(); 609 file.close();
610 QString data; 610 QString data;
611 611
612 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 612 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
613 KABC::VCardTool tool; 613 KABC::VCardTool tool;
614 list = tool.parseVCards( data ); 614 list = tool.parseVCards( data );
615 KABC::Addressee::List::Iterator it; 615 KABC::Addressee::List::Iterator it;
616 for ( it = list.begin(); it != list.end(); ++it ) { 616 for ( it = list.begin(); it != list.end(); ++it ) {
617 Iterator ait; 617 Iterator ait;
618 for ( ait = begin(); ait != end(); ++ait ) { 618 for ( ait = begin(); ait != end(); ++ait ) {
619 if ( !(*ait).tagged() ) { 619 if ( !(*ait).tagged() ) {
620 if ( (*ait).containsAdr(*it)) { 620 if ( (*ait).containsAdr(*it)) {
621 (*ait).setTagged(true); 621 (*ait).setTagged(true);
622 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 622 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
623 (*it).setIDStr( ":"); 623 (*it).setIDStr( ":");
624 (*it).setID( currentSyncDevice,id ); 624 (*it).setID( currentSyncDevice,id );
625 (*it).setExternalUID( id ); 625 (*it).setExternalUID( id );
626 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 626 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
627 (*it).setUid( ( (*ait).uid() )); 627 (*it).setUid( ( (*ait).uid() ));
628 break; 628 break;
629 } 629 }
630 } 630 }
631 631
632 } 632 }
633 if ( ait == end() ) 633 if ( ait == end() )
634 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 634 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
635 } 635 }
636 clear(); 636 clear();
637 for ( it = list.begin(); it != list.end(); ++it ) { 637 for ( it = list.begin(); it != list.end(); ++it ) {
638 insertAddressee( (*it) ); 638 insertAddressee( (*it) );
639 } 639 }
640} 640}
641 641
642bool AddressBook::saveABphone( QString fileName ) 642bool AddressBook::saveABphone( QString fileName )
643{ 643{
644 //smplifyAddressees(); 644 //smplifyAddressees();
645 qDebug("saveABphone:: saving AB... "); 645 qDebug("saveABphone:: saving AB... ");
646 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 646 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
647 return false; 647 return false;
648 qDebug("saveABphone:: writing to phone... "); 648 qDebug("saveABphone:: writing to phone... ");
649 if ( !PhoneAccess::writeToPhone( fileName) ) { 649 if ( !PhoneAccess::writeToPhone( fileName) ) {
650 return false; 650 return false;
651 } 651 }
652 qDebug("saveABphone:: re-reading from phone... "); 652 qDebug("saveABphone:: re-reading from phone... ");
653 if ( !PhoneAccess::readFromPhone( fileName) ) { 653 if ( !PhoneAccess::readFromPhone( fileName) ) {
654 return false; 654 return false;
655 } 655 }
656 return true; 656 return true;
657} 657}
658bool AddressBook::saveAB() 658bool AddressBook::saveAB()
659{ 659{
660 bool ok = true; 660 bool ok = true;
661 661
662 deleteRemovedAddressees(); 662 deleteRemovedAddressees();
663 Iterator ait; 663 Iterator ait;
664 for ( ait = begin(); ait != end(); ++ait ) { 664 for ( ait = begin(); ait != end(); ++ait ) {
665 if ( !(*ait).IDStr().isEmpty() ) { 665 if ( !(*ait).IDStr().isEmpty() ) {
666 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 666 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
667 } 667 }
668 } 668 }
669 KRES::Manager<Resource>::ActiveIterator it; 669 KRES::Manager<Resource>::ActiveIterator it;
670 KRES::Manager<Resource> *manager = d->mManager; 670 KRES::Manager<Resource> *manager = d->mManager;
671 qDebug("SaveAB::saving..." ); 671 qDebug("SaveAB::saving..." );
672 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 672 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
673 qDebug("SaveAB::checking resource..." ); 673 qDebug("SaveAB::checking resource..." );
674 if ( (*it)->readOnly() ) 674 if ( (*it)->readOnly() )
675 qDebug("resource is readonly." ); 675 qDebug("SaveAB::resource is readonly." );
676 if ( (*it)->isOpen() ) 676 if ( (*it)->isOpen() )
677 qDebug("resource is open" ); 677 qDebug("SaveAB::resource is open" );
678 678
679 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 679 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
680 Ticket *ticket = requestSaveTicket( *it ); 680 Ticket *ticket = requestSaveTicket( *it );
681 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 681 qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
682 if ( !ticket ) { 682 if ( !ticket ) {
683 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 683 qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." )
684 .arg( (*it)->resourceName() ) ); 684 .arg( (*it)->resourceName() ) );
685 return false; 685 return false;
686 } 686 }
687 687
688 //if ( !save( ticket ) ) 688 //if ( !save( ticket ) )
689 if ( ticket->resource() ) { 689 if ( ticket->resource() ) {
690 QString name = ticket->resource()->resourceName(); 690 QString name = ticket->resource()->resourceName();
691 if ( ! ticket->resource()->save( ticket ) ) 691 if ( ! ticket->resource()->save( ticket ) )
692 ok = false; 692 ok = false;
693 else 693 else
694 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 694 qDebug("SaveAB::resource saved '%s'", name.latin1() );
695 695
696 } else 696 } else
697 ok = false; 697 ok = false;
698 698
699 } 699 }
700 } 700 }
701 return ok; 701 return ok;
702} 702}
703 703
704AddressBook::Iterator AddressBook::begin() 704AddressBook::Iterator AddressBook::begin()
705{ 705{
706 Iterator it = Iterator(); 706 Iterator it = Iterator();
707 it.d->mIt = d->mAddressees.begin(); 707 it.d->mIt = d->mAddressees.begin();
708 return it; 708 return it;
709} 709}
710 710
711AddressBook::ConstIterator AddressBook::begin() const 711AddressBook::ConstIterator AddressBook::begin() const
712{ 712{
713 ConstIterator it = ConstIterator(); 713 ConstIterator it = ConstIterator();
714 it.d->mIt = d->mAddressees.begin(); 714 it.d->mIt = d->mAddressees.begin();
715 return it; 715 return it;
716} 716}
717 717
718AddressBook::Iterator AddressBook::end() 718AddressBook::Iterator AddressBook::end()
719{ 719{
720 Iterator it = Iterator(); 720 Iterator it = Iterator();
721 it.d->mIt = d->mAddressees.end(); 721 it.d->mIt = d->mAddressees.end();
722 return it; 722 return it;
723} 723}
724 724
725AddressBook::ConstIterator AddressBook::end() const 725AddressBook::ConstIterator AddressBook::end() const
726{ 726{
727 ConstIterator it = ConstIterator(); 727 ConstIterator it = ConstIterator();
728 it.d->mIt = d->mAddressees.end(); 728 it.d->mIt = d->mAddressees.end();
729 return it; 729 return it;
730} 730}
731 731
732void AddressBook::clear() 732void AddressBook::clear()
733{ 733{
734 d->mAddressees.clear(); 734 d->mAddressees.clear();
735} 735}
736 736
737Ticket *AddressBook::requestSaveTicket( Resource *resource ) 737Ticket *AddressBook::requestSaveTicket( Resource *resource )
738{ 738{
739 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 739 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
740 740
741 if ( !resource ) 741 if ( !resource )
742 { 742 {
743 qDebug("AddressBook::requestSaveTicket no resource" ); 743 qDebug("AddressBook::requestSaveTicket no resource" );
744 resource = standardResource(); 744 resource = standardResource();
745 } 745 }
746 746
747 KRES::Manager<Resource>::ActiveIterator it; 747 KRES::Manager<Resource>::ActiveIterator it;
748 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 748 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
749 if ( (*it) == resource ) { 749 if ( (*it) == resource ) {
750 if ( (*it)->readOnly() || !(*it)->isOpen() ) 750 if ( (*it)->readOnly() || !(*it)->isOpen() )
751 return 0; 751 return 0;
752 else 752 else
753 return (*it)->requestSaveTicket(); 753 return (*it)->requestSaveTicket();
754 } 754 }
755 } 755 }
756 756
757 return 0; 757 return 0;
758} 758}
759//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 759//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
760void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 760void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
761{ 761{
762 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 762 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
763 //qDebug("block insert "); 763 //qDebug("block insert ");
764 return; 764 return;
765 } 765 }
766 //qDebug("inserting.... %s ",a.uid().latin1() ); 766 //qDebug("inserting.... %s ",a.uid().latin1() );
767 bool found = false; 767 bool found = false;
768 Addressee::List::Iterator it; 768 Addressee::List::Iterator it;
769 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 769 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
770 if ( a.uid() == (*it).uid() ) { 770 if ( a.uid() == (*it).uid() ) {
771 771
772 bool changed = false; 772 bool changed = false;
773 Addressee addr = a; 773 Addressee addr = a;
774 if ( addr != (*it) ) 774 if ( addr != (*it) )
775 changed = true; 775 changed = true;
776 776
777 if ( takeResource ) { 777 if ( takeResource ) {
778 Resource * res = (*it).resource(); 778 Resource * res = (*it).resource();
779 (*it) = a; 779 (*it) = a;
780 (*it).setResource( res ); 780 (*it).setResource( res );
781 } else { 781 } else {
782 (*it) = a; 782 (*it) = a;
783 if ( (*it).resource() == 0 ) 783 if ( (*it).resource() == 0 )
784 (*it).setResource( standardResource() ); 784 (*it).setResource( standardResource() );
785 } 785 }
786 if ( changed ) { 786 if ( changed ) {
787 if ( setRev ) { 787 if ( setRev ) {
788 (*it).setRevision( QDateTime::currentDateTime() ); 788 (*it).setRevision( QDateTime::currentDateTime() );
789 } 789 }
790 (*it).setChanged( true ); 790 (*it).setChanged( true );
791 } 791 }
792 792
793 found = true; 793 found = true;
794 } else { 794 } else {
795 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 795 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
796 QString name = (*it).uid().mid( 19 ); 796 QString name = (*it).uid().mid( 19 );
797 Addressee b = a; 797 Addressee b = a;
798 QString id = b.getID( name ); 798 QString id = b.getID( name );
799 if ( ! id.isEmpty() ) { 799 if ( ! id.isEmpty() ) {
800 QString des = (*it).note(); 800 QString des = (*it).note();
801 int startN; 801 int startN;
802 if( (startN = des.find( id ) ) >= 0 ) { 802 if( (startN = des.find( id ) ) >= 0 ) {
803 int endN = des.find( ",", startN+1 ); 803 int endN = des.find( ",", startN+1 );
804 des = des.left( startN ) + des.mid( endN+1 ); 804 des = des.left( startN ) + des.mid( endN+1 );
805 (*it).setNote( des ); 805 (*it).setNote( des );
806 } 806 }
807 } 807 }
808 } 808 }
809 } 809 }
810 } 810 }
811 if ( found ) 811 if ( found )
812 return; 812 return;
813 813
814 d->mAddressees.append( a ); 814 d->mAddressees.append( a );
815 Addressee& addr = d->mAddressees.last(); 815 Addressee& addr = d->mAddressees.last();
816 if ( addr.resource() == 0 ) 816 if ( addr.resource() == 0 )
817 addr.setResource( standardResource() ); 817 addr.setResource( standardResource() );
818 addr.setChanged( true ); 818 addr.setChanged( true );
819} 819}
820 820
821void AddressBook::removeAddressee( const Addressee &a ) 821void AddressBook::removeAddressee( const Addressee &a )
822{ 822{
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 6413b42..e8f8bdd 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -13,262 +13,262 @@
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h> 48#include <libkdepim/ksyncprofile.h>
49 49
50#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
52 52
53#include "stdaddressbook.h" 53#include "stdaddressbook.h"
54 54
55#include "sharpdtmconverter.h" 55#include "sharpdtmconverter.h"
56//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
57using namespace KABC; 57using namespace KABC;
58extern "C" 58extern "C"
59{ 59{
60 void *init_microkabc_sharpdtm() 60 void *init_microkabc_sharpdtm()
61 { 61 {
62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); 62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
63 } 63 }
64} 64}
65 65
66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) 66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
67 : Resource( config ), mConverter (0) 67 : Resource( config ), mConverter (0)
68{ 68{
69 // we can not choose the filename. Therefore use the default to display 69 // we can not choose the filename. Therefore use the default to display
70 mAccess = 0; 70 mAccess = 0;
71 QString fileName = SlZDataBase::addressbookFileName(); 71 QString fileName = SlZDataBase::addressbookFileName();
72 init( fileName ); 72 init( fileName );
73} 73}
74 74
75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) 75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
76 : Resource( 0 ) 76 : Resource( 0 )
77{ 77{
78 mAccess = 0; 78 mAccess = 0;
79 init( fileName ); 79 init( fileName );
80} 80}
81 81
82void ResourceSharpDTM::init( const QString &fileName ) 82void ResourceSharpDTM::init( const QString &fileName )
83{ 83{
84 if (mConverter == 0) { 84 if (mConverter == 0) {
85 mConverter = new SharpDTMConverter(); 85 mConverter = new SharpDTMConverter();
86 bool res = mConverter->init(); 86 bool res = mConverter->init();
87 if ( !res ) 87 if ( !res )
88 { 88 {
89 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); 89 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
90 qDebug(msg); 90 qDebug(msg);
91 return; 91 return;
92 } 92 }
93 } 93 }
94 setFileName( fileName ); 94 setFileName( fileName );
95} 95}
96 96
97ResourceSharpDTM::~ResourceSharpDTM() 97ResourceSharpDTM::~ResourceSharpDTM()
98{ 98{
99 if (mConverter != 0) 99 if (mConverter != 0)
100 delete mConverter; 100 delete mConverter;
101 101
102 if(mAccess != 0) 102 if(mAccess != 0)
103 delete mAccess; 103 delete mAccess;
104} 104}
105 105
106void ResourceSharpDTM::writeConfig( KConfig *config ) 106void ResourceSharpDTM::writeConfig( KConfig *config )
107{ 107{
108 Resource::writeConfig( config ); 108 Resource::writeConfig( config );
109} 109}
110 110
111Ticket *ResourceSharpDTM::requestSaveTicket() 111Ticket *ResourceSharpDTM::requestSaveTicket()
112{ 112{
113 113
114 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 114 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
115 115
116 if ( !addressBook() ) return 0; 116 if ( !addressBook() ) return 0;
117 return createTicket( this ); 117 return createTicket( this );
118} 118}
119 119
120 120
121bool ResourceSharpDTM::doOpen() 121bool ResourceSharpDTM::doOpen()
122{ 122{
123 if (!mConverter) 123 if (!mConverter)
124 return false; 124 return false;
125 return true; 125 return true;
126} 126}
127 127
128void ResourceSharpDTM::doClose() 128void ResourceSharpDTM::doClose()
129{ 129{
130 return; 130 return;
131} 131}
132 132
133bool ResourceSharpDTM::load() 133bool ResourceSharpDTM::load()
134{ 134{
135 if (!mConverter) 135 if (!mConverter)
136 return false; 136 return false;
137 QString fileN = SlZDataBase::addressbookFileName(); 137 QString fileN = SlZDataBase::addressbookFileName();
138 if ( ! mAccess ) { 138 if ( ! mAccess ) {
139 mAccess = new SlZDataBase(fileN, 139 mAccess = new SlZDataBase(fileN,
140 SlZDataBase::addressbookItems(), 140 SlZDataBase::addressbookItems(),
141 0, false); 141 0, true);
142 } 142 }
143 if(mAccess == 0) 143 if(mAccess == 0)
144 return false; 144 return false;
145 145
146 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); 146 qDebug("ResourceSharpDTM:: %x load: %s",this, fileName().latin1());
147 bool res = false; 147 bool res = false;
148 CardId id; 148 CardId id;
149 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 149 for (bool res=mAccess->first(); res == true; res=mAccess->next())
150 { 150 {
151 id = mAccess->cardId(); 151 id = mAccess->cardId();
152 KABC::Addressee addressee; 152 KABC::Addressee addressee;
153 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 153 res = mConverter->sharpToAddressee( id, mAccess, addressee );
154 if ( !addressee.isEmpty() && res ) 154 if ( !addressee.isEmpty() && res )
155 { 155 {
156 addressee.setResource( this ); 156 addressee.setResource( this );
157 addressBook()->insertAddressee( addressee ); 157 addressBook()->insertAddressee( addressee );
158 } 158 }
159 } 159 }
160 if(mAccess != 0) 160 if(mAccess != 0)
161 delete mAccess; 161 delete mAccess;
162 mAccess = 0; 162 mAccess = 0;
163 163
164 return true; 164 return true;
165} 165}
166 166
167bool ResourceSharpDTM::save( Ticket *ticket ) 167bool ResourceSharpDTM::save( Ticket *ticket )
168{ 168{
169 if (!mConverter) 169 if (!mConverter)
170 return false; 170 return false;
171 QString fileN = SlZDataBase::addressbookFileName(); 171 QString fileN = SlZDataBase::addressbookFileName();
172 if ( ! mAccess ) { 172 if ( ! mAccess ) {
173 mAccess = new SlZDataBase(fileN, 173 mAccess = new SlZDataBase(fileN,
174 SlZDataBase::addressbookItems(), 174 SlZDataBase::addressbookItems(),
175 0, false); 175 0, false);
176 } 176 }
177 if(mAccess == 0) 177 if(mAccess == 0)
178 return false; 178 return false;
179 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 179 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
180 KABC::AddressBook::Iterator it; 180 KABC::AddressBook::Iterator it;
181 bool res; 181 bool res;
182 KABC::Addressee::List changedAddressees; 182 KABC::Addressee::List changedAddressees;
183 typedef QMap<int,QString> AddresseeMap; 183 typedef QMap<int,QString> AddresseeMap;
184 AddresseeMap map; 184 AddresseeMap map;
185 CardId id ; 185 CardId id ;
186 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 186 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
187 187
188 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 188 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
189 QString uid = (*it).originalExternalUID(); 189 QString uid = (*it).originalExternalUID();
190 bool res; 190 bool res;
191 if ( uid.isEmpty() ) 191 if ( uid.isEmpty() )
192 id = 0; 192 id = 0;
193 else 193 else
194 id = uid.toUInt(); 194 id = uid.toUInt();
195 KABC::Addressee addressee = (*it); 195 KABC::Addressee addressee = (*it);
196 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 196 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
197 res = mAccess->startEditCard(id); 197 res = mAccess->startEditCard(id);
198 if (res == true) 198 if (res == true)
199 { 199 {
200 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 200 res = mConverter->addresseeToSharp( (*it), mAccess, id );
201 if (res == true) 201 if (res == true)
202 { 202 {
203 res = mAccess->finishEditCard(&id);; 203 res = mAccess->finishEditCard(&id);;
204 mConverter->setCategories( (*it), mAccess, id ); 204 mConverter->setCategories( (*it), mAccess, id );
205 map.insert(id,(*it).uid()); 205 map.insert(id,(*it).uid());
206 if (res == false) 206 if (res == false)
207 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 207 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
208 208
209 } 209 }
210 else 210 else
211 { 211 {
212 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 212 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
213 mAccess->cancelEditCard(); 213 mAccess->cancelEditCard();
214 } 214 }
215 } 215 }
216 216
217 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 217 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
218 res = mAccess->deleteCard(&id); 218 res = mAccess->deleteCard(&id);
219 if ( !res ) 219 if ( !res )
220 qDebug("delete error "); 220 qDebug("delete error ");
221 221
222 222
223 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 223 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
224 //changed 224 //changed
225 res = mAccess->startEditCard(id); 225 res = mAccess->startEditCard(id);
226 if (res == true) 226 if (res == true)
227 { 227 {
228 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 228 res = mConverter->addresseeToSharp( (*it), mAccess, id );
229 if (res == true) 229 if (res == true)
230 { 230 {
231 res = mAccess->finishEditCard(&id); 231 res = mAccess->finishEditCard(&id);
232 mConverter->setCategories( (*it), mAccess, id ); 232 mConverter->setCategories( (*it), mAccess, id );
233 map.insert(id,(*it).uid()); 233 map.insert(id,(*it).uid());
234 if (res == false) 234 if (res == false)
235 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 235 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
236 } 236 }
237 else 237 else
238 { 238 {
239 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 239 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
240 mAccess->cancelEditCard(); 240 mAccess->cancelEditCard();
241 } 241 }
242 } 242 }
243 } 243 }
244 } 244 }
245 245
246 } 246 }
247 AddresseeMap::Iterator itam; 247 AddresseeMap::Iterator itam;
248 for ( res=mAccess->first(); res == true; res=mAccess->next()) 248 for ( res=mAccess->first(); res == true; res=mAccess->next())
249 { 249 {
250 id = mAccess->cardId(); 250 id = mAccess->cardId();
251 int idint = id; 251 int idint = id;
252 itam = map.find( idint ); 252 itam = map.find( idint );
253 if ( itam != map.end() ) { 253 if ( itam != map.end() ) {
254 KABC::Addressee addressee; 254 KABC::Addressee addressee;
255 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 255 res = mConverter->sharpToAddressee( id, mAccess, addressee );
256 256
257 if ( !addressee.isEmpty() && res ) 257 if ( !addressee.isEmpty() && res )
258 { 258 {
259 addressee.setResource( this ); 259 addressee.setResource( this );
260 addressee.setUid( itam.data() ); 260 addressee.setUid( itam.data() );
261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
262 addressBook()->insertAddressee( addressee , false ); 262 addressBook()->insertAddressee( addressee , false );
263 } 263 }
264 } 264 }
265 } 265 }
266 delete ticket; 266 delete ticket;
267 if(mAccess != 0) 267 if(mAccess != 0)
268 delete mAccess; 268 delete mAccess;
269 mAccess = 0; 269 mAccess = 0;
270 return true; 270 return true;
271} 271}
272 272
273bool ResourceSharpDTM::lock( const QString &lockfileName ) 273bool ResourceSharpDTM::lock( const QString &lockfileName )
274{ 274{
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
index 95e16b6..4adcae4 100644
--- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
+++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
@@ -295,192 +295,150 @@ bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* da
295 if ( !addr.familyName().isEmpty() ) { 295 if ( !addr.familyName().isEmpty() ) {
296 formattedName = addr.familyName(); 296 formattedName = addr.familyName();
297 if ( !addr.givenName().isEmpty() ) { 297 if ( !addr.givenName().isEmpty() ) {
298 formattedName += ", "; 298 formattedName += ", ";
299 formattedName += addr.givenName(); 299 formattedName += addr.givenName();
300 } 300 }
301 } else 301 } else
302 formattedName = addr.givenName(); 302 formattedName = addr.givenName();
303 } 303 }
304 database->writeField(ZdbAdrs::FileAs, formattedName); 304 database->writeField(ZdbAdrs::FileAs, formattedName);
305 database->writeField(ZdbAdrs::FullName, formattedName); 305 database->writeField(ZdbAdrs::FullName, formattedName);
306 306
307 // email 307 // email
308 //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); 308 //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!");
309 //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); 309 //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee");
310 QString emails = addr.emails().join(" "); 310 QString emails = addr.emails().join(" ");
311 database->writeField(ZdbAdrs::Emails, emails ); 311 database->writeField(ZdbAdrs::Emails, emails );
312 312
313 database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); 313 database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() );
314 // home 314 // home
315 const Address homeaddress = addr.address(Address::Home); 315 const Address homeaddress = addr.address(Address::Home);
316 database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); 316 database->writeField(ZdbAdrs::HomeStreet, homeaddress.street());
317 database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); 317 database->writeField(ZdbAdrs::HomeCity, homeaddress.locality());
318 database->writeField(ZdbAdrs::HomeState, homeaddress.region()); 318 database->writeField(ZdbAdrs::HomeState, homeaddress.region());
319 database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); 319 database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode());
320 database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); 320 database->writeField(ZdbAdrs::HomeCountry, homeaddress.country());
321 321
322 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); 322 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
323 database->writeField(ZdbAdrs::HomePhone, homephone.number()); 323 database->writeField(ZdbAdrs::HomePhone, homephone.number());
324 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); 324 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
325 database->writeField(ZdbAdrs::HomeFax, homefax.number()); 325 database->writeField(ZdbAdrs::HomeFax, homefax.number());
326 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); 326 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
327 database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); 327 database->writeField(ZdbAdrs::HomeMobile, homemobile.number());
328 if (!homemobile.number().isEmpty()) { 328 if (!homemobile.number().isEmpty()) {
329 cellHome = true; 329 cellHome = true;
330 } 330 }
331 database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); 331 database->writeField(ZdbAdrs::HomeWebPage, addr.url().url());
332 // business 332 // business
333 const Address businessaddress = addr.address(Address::Work); 333 const Address businessaddress = addr.address(Address::Work);
334 //qDebug("write business address "); 334 //qDebug("write business address ");
335 database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); 335 database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street());
336 database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); 336 database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality());
337 database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); 337 database->writeField(ZdbAdrs::BusinessState, businessaddress.region());
338 database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); 338 database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode());
339 database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); 339 database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country());
340 340
341 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); 341 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
342 database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); 342 database->writeField(ZdbAdrs::BusinessPhone, businessphone.number());
343 343
344 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); 344 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
345 database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); 345 database->writeField(ZdbAdrs::BusinessFax, businessfax.number());
346 346
347 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); 347 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
348 database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); 348 database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number());
349 if (!businessmobile.number().isEmpty()) { 349 if (!businessmobile.number().isEmpty()) {
350 cellWork = true; 350 cellWork = true;
351 } 351 }
352 PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); 352 PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell );
353 if (! mobile.number().isEmpty()) { 353 if (! mobile.number().isEmpty()) {
354 if ( ! cellHome ) 354 if ( ! cellHome )
355 database->writeField(ZdbAdrs::HomeMobile, mobile.number()); 355 database->writeField(ZdbAdrs::HomeMobile, mobile.number());
356 else if (! cellWork ) 356 else if (! cellWork )
357 database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); 357 database->writeField(ZdbAdrs::BusinessMobile, mobile.number());
358 } 358 }
359 359
360 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); 360 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
361 database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); 361 database->writeField(ZdbAdrs::BusinessPager, businesspager.number());
362 362
363 database->writeField(ZdbAdrs::JobTitle, addr.role()); 363 database->writeField(ZdbAdrs::JobTitle, addr.role());
364 database->writeField(ZdbAdrs::Company, addr.organization()); 364 database->writeField(ZdbAdrs::Company, addr.organization());
365 365
366 database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); 366 database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" ));
367 database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); 367 database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
368 database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); 368 database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" ));
369 database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); 369 database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
370 database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); 370 database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" ));
371 371
372 //personal 372 //personal
373 database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); 373 database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" ));
374 374
375 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); 375 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" );
376 //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); 376 //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1());
377 //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); 377 //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?");
378 //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); 378 //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee");
379 if (gt == "male") 379 if (gt == "male")
380 database->writeField(ZdbAdrs::Gender, "1"); 380 database->writeField(ZdbAdrs::Gender, "1");
381 else if (gt == "female") 381 else if (gt == "female")
382 database->writeField(ZdbAdrs::Gender, "2"); 382 database->writeField(ZdbAdrs::Gender, "2");
383 else 383 else
384 database->writeField(ZdbAdrs::Gender, ""); 384 database->writeField(ZdbAdrs::Gender, "");
385 385
386 QString dateS ; 386 QString dateS ;
387 QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate 387 QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
388 if ( dt.isValid() ) { 388 if ( dt.isValid() ) {
389 dateS = KGlobal::locale()->formatDate(dt, true ); 389 dateS = KGlobal::locale()->formatDate(dt, true );
390 } 390 }
391 database->writeField(ZdbAdrs::Anniversary, dateS ); 391 database->writeField(ZdbAdrs::Anniversary, dateS );
392 database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); 392 database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" ));
393 dt = addr.birthday().date(); 393 dt = addr.birthday().date();
394 dateS = ""; 394 dateS = "";
395 if ( dt.isValid() ) { 395 if ( dt.isValid() ) {
396 dateS = KGlobal::locale()->formatDate(dt, true ); 396 dateS = KGlobal::locale()->formatDate(dt, true );
397 } 397 }
398 database->writeField(ZdbAdrs::Birthday, dateS); 398 database->writeField(ZdbAdrs::Birthday, dateS);
399 database->writeField(ZdbAdrs::Nickname, addr.nickName()); 399 database->writeField(ZdbAdrs::Nickname, addr.nickName());
400 400
401 // other 401 // other
402 database->writeField(ZdbAdrs::Notes, addr.note()); 402 database->writeField(ZdbAdrs::Notes, addr.note());
403 403
404//US QString groups() const { return find( Qtopia::Groups ); } 404//US QString groups() const { return find( Qtopia::Groups ); }
405//US QStringList groupList() const; 405//US QStringList groupList() const;
406 406
407 407
408 //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); 408 //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works");
409 409
410 return true; 410 return true;
411} 411}
412 412
413 413
414bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ) 414bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact )
415{ 415{
416 QStringList list = addr.categories(); 416 QStringList list = addr.categories();
417 417
418 QArray<int> ids(list.count()); 418 QArray<int> ids(list.count());
419 uint index = 0; 419 uint index = 0;
420 for(uint i=0; i<ids.size(); i++){ 420 for(uint i=0; i<ids.size(); i++){
421 if(catDB->exists(list[i])){ 421 if(catDB->exists(list[i])){
422 ids[index] = catDB->id(list[i]); 422 ids[index] = catDB->id(list[i]);
423 qDebug("set ex cat %d %s ",ids[index] , list[i].latin1()); 423 //qDebug("set exist cat %d %s ",ids[index] , list[i].latin1());
424 index++; 424 index++;
425 } else { 425 } else {
426 ids[index] = catDB->addCategory(list[i]); 426 ids[index] = catDB->addCategory(list[i]);
427 qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); 427 //qDebug("add new cat %d %s ",ids[index] , list[i].latin1());
428 index++; 428 index++;
429 } 429 }
430 } 430 }
431 bool res ; 431 bool res ;
432 if ( res = database->updateCategories(contact, ids) ) 432
433 qDebug("cat updated "); 433 if ( !(res = database->updateCategories(contact, ids) ))
434 else 434 qDebug("SharpDTMConverter::Error updating categories");
435 qDebug("error cat updating ");
436 435
437 return res; 436 return res;
438} 437}
439 438
440#if 0
441 m_pCategories = new SlCategories;
442catDB
443
444 if(categories == QString::null) return true;
445 QStringList list = CSVParser::parse(categories);
446 QArray<int> ids(list.count());
447 uint index = 0;
448 for(uint i=0; i<ids.size(); i++){
449#if 0
450 bool ok;
451 ids[index] = list[i].toInt(&ok);
452 if(ok){
453 index++;
454 } else {
455 if(m_pCategories->exists(list[i])){
456 ids[index] = m_pCategories->id(list[i]);
457 index++;
458 }
459 }
460#else
461 if(m_pCategories->exists(list[i])){
462 ids[index] = m_pCategories->id(list[i]);
463 index++;
464 } else if(m_addCategory){
465 ids[index] = m_pCategories->addCategory(list[i]);
466 index++;
467 }
468#endif
469 }
470 if(ids.size() > 0 && index == 0){
471 return true;
472 } else if(index != ids.size()){
473 ids.resize(index);
474 }
475 if(!m_pZdb->updateCategories(id, ids)){
476 return false;
477 }
478 return true;
479#endif
480
481QDate SharpDTMConverter::convertDate( QString s) 439QDate SharpDTMConverter::convertDate( QString s)
482{ 440{
483 QDate dt = KGlobal::locale()->readDate( s ); 441 QDate dt = KGlobal::locale()->readDate( s );
484 return dt; 442 return dt;
485 return QDate (); 443 return QDate ();
486} 444}