author | zautrix <zautrix> | 2005-03-18 17:56:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-18 17:56:55 (UTC) |
commit | d6438efc4c7cff39024b65bfd1d2f810212da544 (patch) (unidiff) | |
tree | badb4c48d83477dd1027af1807cb2b6ed09db52a /kde2file | |
parent | f9f521c487143641b2cf077d04fe1c475001bce2 (diff) | |
download | kdepimpi-d6438efc4c7cff39024b65bfd1d2f810212da544.zip kdepimpi-d6438efc4c7cff39024b65bfd1d2f810212da544.tar.gz kdepimpi-d6438efc4c7cff39024b65bfd1d2f810212da544.tar.bz2 |
kde sync fixes
-rw-r--r-- | kde2file/abdump/main.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp index 9ad78e5..b359cfe 100644 --- a/kde2file/abdump/main.cpp +++ b/kde2file/abdump/main.cpp | |||
@@ -91,103 +91,106 @@ int main( int argc, char *argv[] ) | |||
91 | qDebug("read "); | 91 | qDebug("read "); |
92 | } | 92 | } |
93 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 93 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
94 | 94 | ||
95 | KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self(); | 95 | KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self(); |
96 | standardAddressBook->setAutomaticSave( false ); | 96 | standardAddressBook->setAutomaticSave( false ); |
97 | qDebug("************************************* "); | 97 | qDebug("************************************* "); |
98 | qDebug("***************kdeABdump************* "); | 98 | qDebug("***************kdeABdump************* "); |
99 | qDebug("************************************* "); | 99 | qDebug("************************************* "); |
100 | if ( !read ) { | 100 | if ( !read ) { |
101 | KABC::AddressBook::Iterator it; | 101 | KABC::AddressBook::Iterator it; |
102 | KABC::VCardConverter converter; | 102 | KABC::VCardConverter converter; |
103 | QString datastream; | 103 | QString datastream; |
104 | for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) { | 104 | for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) { |
105 | if ( (*it).isEmpty() || ! (*it).resource() ) | 105 | if ( (*it).isEmpty() || ! (*it).resource() ) |
106 | continue; | 106 | continue; |
107 | KABC::Addressee a = ( *it ); | 107 | KABC::Addressee a = ( *it ); |
108 | QString vcard = converter.createVCard( a ); | 108 | QString vcard = converter.createVCard( a ); |
109 | vcard += QString("\r\n"); | 109 | vcard += QString("\r\n"); |
110 | datastream += vcard; | 110 | datastream += vcard; |
111 | } | 111 | } |
112 | QFile outFile(fileName); | 112 | QFile outFile(fileName); |
113 | if ( outFile.open(IO_WriteOnly) ) { | 113 | if ( outFile.open(IO_WriteOnly) ) { |
114 | QTextStream t( &outFile ); // use a text stream | 114 | QTextStream t( &outFile ); // use a text stream |
115 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 115 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
116 | t <<datastream; | 116 | t <<datastream; |
117 | t << "\r\n\r\n"; | 117 | t << "\r\n\r\n"; |
118 | outFile.close(); | 118 | outFile.close(); |
119 | } | 119 | } |
120 | } else { | 120 | } else { |
121 | //Addressee::List aList;//parseVCards( const QString& vcard ); | 121 | //Addressee::List aList;//parseVCards( const QString& vcard ); |
122 | KABC::Addressee::List list; | 122 | KABC::Addressee::List list; |
123 | int added = 0, changedC = 0, deleted = 0; | 123 | int added = 0, changedC = 0, deleted = 0; |
124 | QFile file( fileName ); | 124 | QFile file( fileName ); |
125 | if ( file.open( IO_ReadOnly ) ) { | 125 | if ( file.open( IO_ReadOnly ) ) { |
126 | QTextStream t( &file ); // use a text stream | 126 | QTextStream t( &file ); // use a text stream |
127 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 127 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
128 | QString data; | 128 | QString data; |
129 | data = t.read(); | 129 | data = t.read(); |
130 | file.close(); | 130 | file.close(); |
131 | KABC::VCardConverter converter; | 131 | KABC::VCardConverter converter; |
132 | list = converter.parseVCards( data ); | 132 | list = converter.parseVCards( data ); |
133 | qDebug("kdeABdump::file has %d entries", list.count()); | 133 | qDebug("kdeABdump::file has %d entries", list.count()); |
134 | 134 | ||
135 | KABC::Addressee::List::Iterator it; | 135 | KABC::Addressee::List::Iterator it; |
136 | for ( it = list.begin();it != list.end();++it) { | 136 | for ( it = list.begin();it != list.end();++it) { |
137 | (*it).setChanged( true ); | 137 | (*it).setChanged( true ); |
138 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); | 138 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); |
139 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 139 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
140 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); | 140 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); |
141 | if ( changed ) { | 141 | if ( changed ) { |
142 | //qDebug("changed Addressee found! "); | 142 | //qDebug("changed Addressee found! "); |
143 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 143 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
144 | if ( ! std.isEmpty() ) | 144 | if ( ! std.isEmpty() ) |
145 | (*it).setResource(std.resource()); | 145 | (*it).setResource(std.resource()); |
146 | standardAddressBook->insertAddressee( (*it) ); | 146 | standardAddressBook->insertAddressee( (*it) ); |
147 | ++changedC; | 147 | ++changedC; |
148 | } else { | 148 | } else { |
149 | //maybe added? | 149 | //maybe added? |
150 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 150 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
151 | if ( std.isEmpty() ) { | 151 | if ( std.isEmpty() ) { |
152 | standardAddressBook->insertAddressee( (*it) ); | 152 | standardAddressBook->insertAddressee( (*it) ); |
153 | ++added; | 153 | ++added; |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); | 157 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); |
158 | KABC::AddressBook::Iterator it2 ; | 158 | KABC::AddressBook::Iterator it2 ; |
159 | while ( itA != standardAddressBook->end() ) { | 159 | while ( itA != standardAddressBook->end() ) { |
160 | bool found = false; | 160 | bool found = false; |
161 | KABC::Addressee::List::Iterator itL; | 161 | KABC::Addressee::List::Iterator itL; |
162 | for ( itL = list.begin();itL != list.end();++itL) { | 162 | for ( itL = list.begin();itL != list.end();++itL) { |
163 | if ( (*itL).uid() == (*itA).uid() ) { | 163 | if ( (*itL).uid() == (*itA).uid() ) { |
164 | found = true; | 164 | found = true; |
165 | break; | 165 | break; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | if ( !found ) { | 168 | if ( !found ) { |
169 | it2 = itA; | 169 | it2 = itA; |
170 | ++itA; | 170 | ++itA; |
171 | standardAddressBook->removeAddressee( it2 ); | 171 | standardAddressBook->removeAddressee( it2 ); |
172 | ++deleted; | 172 | ++deleted; |
173 | } else { | 173 | } else { |
174 | ++itA; | 174 | ++itA; |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | //standardAddressBook->saveAll(); | 178 | //standardAddressBook->saveAll(); |
179 | standardAddressBook->setAutomaticSave( true ); | 179 | standardAddressBook->setAutomaticSave( true ); |
180 | qDebug("************************************* "); | 180 | qDebug("************************************* "); |
181 | qDebug("*************kdeABdump*************** "); | 181 | qDebug("*************kdeABdump*************** "); |
182 | qDebug("************************************* "); | 182 | qDebug("************************************* "); |
183 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); | 183 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); |
184 | } else | 184 | } else |
185 | qDebug("error open file "); | 185 | qDebug("error open file "); |
186 | } | 186 | } |
187 | standardAddressBook->close(); | ||
188 | // line not needed by KDE 3.4: | ||
189 | // delete standardAddressBook; | ||
190 | |||
187 | 191 | ||
188 | delete standardAddressBook; | ||
189 | //KABC::StdAddressBook::close(); | 192 | //KABC::StdAddressBook::close(); |
190 | //StdAddressBook::mSelf = 0; | 193 | //StdAddressBook::mSelf = 0; |
191 | qDebug("ente "); | 194 | qDebug("ente "); |
192 | return 0; | 195 | return 0; |
193 | } | 196 | } |