author | zautrix <zautrix> | 2004-10-09 16:58:08 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-09 16:58:08 (UTC) |
commit | 59ed933d6c43ecb0ddd3dec53cc289ee8aa68482 (patch) (unidiff) | |
tree | 8b1cbcf9c420e7dffd1e1293bcfa69e8e821f3fa /kabc | |
parent | b80a099d9432bdc3d4eea778b1813b82b2680ecf (diff) | |
download | kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.zip kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.gz kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.bz2 |
fixed sync bug
-rw-r--r-- | kabc/addressbook.cpp | 72 | ||||
-rw-r--r-- | kabc/addressbook.h | 4 | ||||
-rw-r--r-- | kabc/addressee.cpp | 12 | ||||
-rw-r--r-- | kabc/addressee.h | 5 |
4 files changed, 65 insertions, 28 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 1050f55..ff05f7e 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -390,60 +390,80 @@ void AddressBook::export2File( QString fileName ) | |||
390 | Iterator it; | 390 | Iterator it; |
391 | KABC::VCardConverter::Version version; | 391 | KABC::VCardConverter::Version version; |
392 | version = KABC::VCardConverter::v3_0; | 392 | version = KABC::VCardConverter::v3_0; |
393 | for ( it = begin(); it != end(); ++it ) { | 393 | for ( it = begin(); it != end(); ++it ) { |
394 | if ( !(*it).IDStr().isEmpty() ) { | 394 | if ( !(*it).IDStr().isEmpty() ) { |
395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
396 | } | 396 | } |
397 | KABC::VCardConverter converter; | 397 | KABC::VCardConverter converter; |
398 | QString vcard; | 398 | QString vcard; |
399 | //Resource *resource() const; | 399 | //Resource *resource() const; |
400 | converter.addresseeToVCard( *it, vcard, version ); | 400 | converter.addresseeToVCard( *it, vcard, version ); |
401 | t << vcard << "\r\n"; | 401 | t << vcard << "\r\n"; |
402 | } | 402 | } |
403 | t << "\r\n\r\n"; | 403 | t << "\r\n\r\n"; |
404 | outFile.close(); | 404 | outFile.close(); |
405 | } | 405 | } |
406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) | 406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
407 | { | 407 | { |
408 | 408 | ||
409 | KABC::Addressee::List list; | 409 | if ( removeOld ) |
410 | QFile file( fileName ); | 410 | setUntagged(); |
411 | 411 | KABC::Addressee::List list; | |
412 | file.open( IO_ReadOnly ); | 412 | QFile file( fileName ); |
413 | QByteArray rawData = file.readAll(); | 413 | file.open( IO_ReadOnly ); |
414 | file.close(); | 414 | QByteArray rawData = file.readAll(); |
415 | QString data; | 415 | file.close(); |
416 | if ( replaceLabel ) { | 416 | QString data; |
417 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 417 | if ( replaceLabel ) { |
418 | data.replace ( QRegExp("LABEL") , "ADR" ); | 418 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
419 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 419 | data.replace ( QRegExp("LABEL") , "ADR" ); |
420 | } else | 420 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
421 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 421 | } else |
422 | KABC::VCardTool tool; | 422 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
423 | list = tool.parseVCards( data ); | 423 | KABC::VCardTool tool; |
424 | KABC::Addressee::List::Iterator it; | 424 | list = tool.parseVCards( data ); |
425 | for ( it = list.begin(); it != list.end(); ++it ) { | 425 | KABC::Addressee::List::Iterator it; |
426 | (*it).setResource( 0 ); | 426 | for ( it = list.begin(); it != list.end(); ++it ) { |
427 | if ( replaceLabel ) | 427 | (*it).setResource( 0 ); |
428 | (*it).removeVoice(); | 428 | if ( replaceLabel ) |
429 | insertAddressee( (*it), false, true ); | 429 | (*it).removeVoice(); |
430 | if ( removeOld ) | ||
431 | (*it).setTagged( true ); | ||
432 | insertAddressee( (*it), false, true ); | ||
433 | } | ||
434 | if ( removeOld ) | ||
435 | removeUntagged(); | ||
436 | } | ||
437 | void AddressBook::setUntagged() | ||
438 | { | ||
439 | Iterator ait; | ||
440 | for ( ait = begin(); ait != end(); ++ait ) { | ||
441 | (*ait).setTagged( false ); | ||
442 | } | ||
443 | } | ||
444 | void AddressBook::removeUntagged() | ||
445 | { | ||
446 | Iterator ait; | ||
447 | for ( ait = begin(); ait != end(); ++ait ) { | ||
448 | if (!(*ait).tagged()) | ||
449 | removeAddressee( ait ); | ||
430 | } | 450 | } |
431 | 451 | ||
452 | deleteRemovedAddressees(); | ||
432 | } | 453 | } |
433 | |||
434 | bool AddressBook::saveAB() | 454 | bool AddressBook::saveAB() |
435 | { | 455 | { |
436 | bool ok = true; | 456 | bool ok = true; |
437 | 457 | ||
438 | deleteRemovedAddressees(); | 458 | deleteRemovedAddressees(); |
439 | Iterator ait; | 459 | Iterator ait; |
440 | for ( ait = begin(); ait != end(); ++ait ) { | 460 | for ( ait = begin(); ait != end(); ++ait ) { |
441 | if ( !(*ait).IDStr().isEmpty() ) { | 461 | if ( !(*ait).IDStr().isEmpty() ) { |
442 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 462 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
443 | } | 463 | } |
444 | } | 464 | } |
445 | KRES::Manager<Resource>::ActiveIterator it; | 465 | KRES::Manager<Resource>::ActiveIterator it; |
446 | KRES::Manager<Resource> *manager = d->mManager; | 466 | KRES::Manager<Resource> *manager = d->mManager; |
447 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 467 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
448 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 468 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
449 | Ticket *ticket = requestSaveTicket( *it ); | 469 | Ticket *ticket = requestSaveTicket( *it ); |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index cea1b03..532e05d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -130,33 +130,35 @@ class AddressBook : public QObject | |||
130 | Ticket *requestSaveTicket( Resource *resource=0 ); | 130 | Ticket *requestSaveTicket( Resource *resource=0 ); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Load address book from file. | 133 | Load address book from file. |
134 | */ | 134 | */ |
135 | bool load(); | 135 | bool load(); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Save address book. The address book is saved to the file, the Ticket | 138 | Save address book. The address book is saved to the file, the Ticket |
139 | object has been requested for by @ref requestSaveTicket(). | 139 | object has been requested for by @ref requestSaveTicket(). |
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | void export2File( QString fileName ); | 145 | void export2File( QString fileName ); |
146 | void importFromFile( QString fileName, bool replaceLabel = false ); | 146 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
147 | void setUntagged(); | ||
148 | void removeUntagged(); | ||
147 | /** | 149 | /** |
148 | Returns a iterator for first entry of address book. | 150 | Returns a iterator for first entry of address book. |
149 | */ | 151 | */ |
150 | Iterator begin(); | 152 | Iterator begin(); |
151 | 153 | ||
152 | /** | 154 | /** |
153 | Returns a const iterator for first entry of address book. | 155 | Returns a const iterator for first entry of address book. |
154 | */ | 156 | */ |
155 | ConstIterator begin() const; | 157 | ConstIterator begin() const; |
156 | 158 | ||
157 | /** | 159 | /** |
158 | Returns a iterator for first entry of address book. | 160 | Returns a iterator for first entry of address book. |
159 | */ | 161 | */ |
160 | Iterator end(); | 162 | Iterator end(); |
161 | 163 | ||
162 | /** | 164 | /** |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 3f3d5c0..607ae26 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -75,32 +75,33 @@ struct Addressee::AddresseeData : public KShared | |||
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 | }; | 92 | }; |
92 | 93 | ||
93 | Addressee::Addressee() | 94 | Addressee::Addressee() |
94 | { | 95 | { |
95 | mData = new AddresseeData; | 96 | mData = new AddresseeData; |
96 | mData->empty = true; | 97 | mData->empty = true; |
97 | mData->changed = false; | 98 | mData->changed = false; |
98 | mData->resource = 0; | 99 | mData->resource = 0; |
99 | mData->mExternalId = ":"; | 100 | mData->mExternalId = ":"; |
100 | mData->revision = QDateTime ( QDate( 2003,1,1)); | 101 | mData->revision = QDateTime ( QDate( 2003,1,1)); |
101 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
102 | } | 103 | } |
103 | 104 | ||
104 | Addressee::~Addressee() | 105 | Addressee::~Addressee() |
105 | { | 106 | { |
106 | } | 107 | } |
@@ -1808,32 +1809,43 @@ Resource *Addressee::resource() const | |||
1808 | QString Addressee::resourceLabel() | 1809 | QString Addressee::resourceLabel() |
1809 | { | 1810 | { |
1810 | return i18n("Resource"); | 1811 | return i18n("Resource"); |
1811 | } | 1812 | } |
1812 | 1813 | ||
1813 | void Addressee::setChanged( bool value ) | 1814 | void Addressee::setChanged( bool value ) |
1814 | { | 1815 | { |
1815 | detach(); | 1816 | detach(); |
1816 | mData->changed = value; | 1817 | mData->changed = value; |
1817 | } | 1818 | } |
1818 | 1819 | ||
1819 | bool Addressee::changed() const | 1820 | bool Addressee::changed() const |
1820 | { | 1821 | { |
1821 | return mData->changed; | 1822 | return mData->changed; |
1822 | } | 1823 | } |
1823 | 1824 | ||
1825 | void Addressee::setTagged( bool value ) | ||
1826 | { | ||
1827 | detach(); | ||
1828 | mData->tagged = value; | ||
1829 | } | ||
1830 | |||
1831 | bool Addressee::tagged() const | ||
1832 | { | ||
1833 | return mData->tagged; | ||
1834 | } | ||
1835 | |||
1824 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) | 1836 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) |
1825 | { | 1837 | { |
1826 | if (!a.mData) return s; | 1838 | if (!a.mData) return s; |
1827 | 1839 | ||
1828 | s << a.uid(); | 1840 | s << a.uid(); |
1829 | 1841 | ||
1830 | s << a.mData->name; | 1842 | s << a.mData->name; |
1831 | s << a.mData->formattedName; | 1843 | s << a.mData->formattedName; |
1832 | s << a.mData->familyName; | 1844 | s << a.mData->familyName; |
1833 | s << a.mData->givenName; | 1845 | s << a.mData->givenName; |
1834 | s << a.mData->additionalName; | 1846 | s << a.mData->additionalName; |
1835 | s << a.mData->prefix; | 1847 | s << a.mData->prefix; |
1836 | s << a.mData->suffix; | 1848 | s << a.mData->suffix; |
1837 | s << a.mData->nickName; | 1849 | s << a.mData->nickName; |
1838 | s << a.mData->birthday; | 1850 | s << a.mData->birthday; |
1839 | s << a.mData->mailer; | 1851 | s << a.mData->mailer; |
diff --git a/kabc/addressee.h b/kabc/addressee.h index 9336edc..0aa2c51 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h | |||
@@ -818,32 +818,35 @@ class Addressee | |||
818 | Resource *resource() const; | 818 | Resource *resource() const; |
819 | 819 | ||
820 | /** | 820 | /** |
821 | Return resourcelabel. | 821 | Return resourcelabel. |
822 | */ | 822 | */ |
823 | //US | 823 | //US |
824 | static QString resourceLabel(); | 824 | static QString resourceLabel(); |
825 | 825 | ||
826 | /** | 826 | /** |
827 | Mark addressee as changed. | 827 | Mark addressee as changed. |
828 | */ | 828 | */ |
829 | void setChanged( bool value ); | 829 | void setChanged( bool value ); |
830 | 830 | ||
831 | /** | 831 | /** |
832 | Return whether the addressee is changed. | 832 | Return whether the addressee is changed. |
833 | */ | 833 | */ |
834 | bool changed() const; | 834 | bool changed() const; |
835 | |||
836 | void setTagged( bool value ); | ||
837 | bool tagged() const; | ||
835 | 838 | ||
836 | private: | 839 | private: |
837 | Addressee copy(); | 840 | Addressee copy(); |
838 | void detach(); | 841 | void detach(); |
839 | 842 | ||
840 | struct AddresseeData; | 843 | struct AddresseeData; |
841 | mutable KSharedPtr<AddresseeData> mData; | 844 | mutable KSharedPtr<AddresseeData> mData; |
842 | }; | 845 | }; |
843 | 846 | ||
844 | QDataStream &operator<<( QDataStream &, const Addressee & ); | 847 | QDataStream &operator<<( QDataStream &, const Addressee & ); |
845 | QDataStream &operator>>( QDataStream &, Addressee & ); | 848 | QDataStream &operator>>( QDataStream &, Addressee & ); |
846 | 849 | ||
847 | } | 850 | } |
848 | 851 | ||
849 | #endif | 852 | #endif |