author | zautrix <zautrix> | 2004-10-27 17:50:52 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-27 17:50:52 (UTC) |
commit | 85a0e0d9b1d60805cb4947be1c296c18e73c82b8 (patch) (unidiff) | |
tree | 64920209dc3cded8b3241d44138b1a82afb300cf /kde2file/abdump | |
parent | 1df6fe03fe931bfbc83e855e47472a80ec4ba08e (diff) | |
download | kdepimpi-85a0e0d9b1d60805cb4947be1c296c18e73c82b8.zip kdepimpi-85a0e0d9b1d60805cb4947be1c296c18e73c82b8.tar.gz kdepimpi-85a0e0d9b1d60805cb4947be1c296c18e73c82b8.tar.bz2 |
sync fixes
-rw-r--r-- | kde2file/abdump/main.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp index d452ee9..1ee64f5 100644 --- a/kde2file/abdump/main.cpp +++ b/kde2file/abdump/main.cpp | |||
@@ -43,151 +43,153 @@ | |||
43 | 43 | ||
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | #include <iostream> | 45 | #include <iostream> |
46 | 46 | ||
47 | using namespace std; | 47 | using namespace std; |
48 | 48 | ||
49 | static const char progName[] = "kdecalendar"; | 49 | static const char progName[] = "kdecalendar"; |
50 | static const char progDisplay[] = "KDE_Addressbook"; | 50 | static const char progDisplay[] = "KDE_Addressbook"; |
51 | static const char progVersion[] = "33.1/3"; | 51 | static const char progVersion[] = "33.1/3"; |
52 | static const char progDesc[] = "A command line interface to KDE addressbooks"; | 52 | static const char progDesc[] = "A command line interface to KDE addressbooks"; |
53 | 53 | ||
54 | 54 | ||
55 | static KCmdLineOptions options[] = | 55 | static KCmdLineOptions options[] = |
56 | { | 56 | { |
57 | { "dump", | 57 | { "dump", |
58 | I18N_NOOP( "Dumps addressbook" ), 0 }, | 58 | I18N_NOOP( "Dumps addressbook" ), 0 }, |
59 | { "read", | 59 | { "read", |
60 | I18N_NOOP( "Reads addressbook" ), 0 }, | 60 | I18N_NOOP( "Reads addressbook" ), 0 }, |
61 | KCmdLineLastOption | 61 | KCmdLineLastOption |
62 | }; | 62 | }; |
63 | 63 | ||
64 | int main( int argc, char *argv[] ) | 64 | int main( int argc, char *argv[] ) |
65 | { | 65 | { |
66 | KAboutData aboutData( | 66 | KAboutData aboutData( |
67 | progName, // internal program name | 67 | progName, // internal program name |
68 | I18N_NOOP( progDisplay ), // displayable program name. | 68 | I18N_NOOP( progDisplay ), // displayable program name. |
69 | progVersion, // version string | 69 | progVersion, // version string |
70 | I18N_NOOP( progDesc ), // short porgram description | 70 | I18N_NOOP( progDesc ), // short porgram description |
71 | KAboutData::License_GPL, // license type | 71 | KAboutData::License_GPL, // license type |
72 | "(c) 2004, Lutz Rogowski", // copyright statement | 72 | "(c) 2004, Lutz Rogowski", // copyright statement |
73 | 0, // any free form text | 73 | 0, // any free form text |
74 | "", // program home page address | 74 | "", // program home page address |
75 | "bugs.kde.org" // bug report email address | 75 | "bugs.kde.org" // bug report email address |
76 | ); | 76 | ); |
77 | 77 | ||
78 | 78 | ||
79 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options | 79 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options |
80 | // for QApplication/KApplication (no KDE or Qt options) | 80 | // for QApplication/KApplication (no KDE or Qt options) |
81 | KCmdLineArgs::init( argc, argv, &aboutData, true ); | 81 | KCmdLineArgs::init( argc, argv, &aboutData, true ); |
82 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. | 82 | KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. |
83 | 83 | ||
84 | KInstance ins ( progName ); | 84 | KInstance ins ( progName ); |
85 | 85 | ||
86 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); | 86 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); |
87 | 87 | ||
88 | bool read = false; | 88 | bool read = false; |
89 | if ( args->isSet( "read" ) ) { | 89 | if ( args->isSet( "read" ) ) { |
90 | read = true; | 90 | read = true; |
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 | if ( (*it).resource()->readOnly() ) | 107 | if ( (*it).resource()->readOnly() ) |
108 | continue; | 108 | continue; |
109 | KABC::Addressee a = ( *it ); | 109 | KABC::Addressee a = ( *it ); |
110 | QString vcard = converter.createVCard( a ); | 110 | QString vcard = converter.createVCard( a ); |
111 | vcard += QString("\r\n"); | 111 | vcard += QString("\r\n"); |
112 | datastream += vcard; | 112 | datastream += vcard; |
113 | } | 113 | } |
114 | QFile outFile(fileName); | 114 | QFile outFile(fileName); |
115 | if ( outFile.open(IO_WriteOnly) ) { | 115 | if ( outFile.open(IO_WriteOnly) ) { |
116 | QTextStream t( &outFile ); // use a text stream | 116 | QTextStream t( &outFile ); // use a text stream |
117 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 117 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
118 | t <<datastream; | 118 | t <<datastream; |
119 | t << "\r\n\r\n"; | 119 | t << "\r\n\r\n"; |
120 | outFile.close(); | 120 | outFile.close(); |
121 | } | 121 | } |
122 | } else { | 122 | } else { |
123 | //Addressee::List aList;//parseVCards( const QString& vcard ); | 123 | //Addressee::List aList;//parseVCards( const QString& vcard ); |
124 | KABC::Addressee::List list; | 124 | KABC::Addressee::List list; |
125 | int added = 0, changedC = 0, deleted = 0; | 125 | int added = 0, changedC = 0, deleted = 0; |
126 | QFile file( fileName ); | 126 | QFile file( fileName ); |
127 | if ( file.open( IO_ReadOnly ) ) { | 127 | if ( file.open( IO_ReadOnly ) ) { |
128 | QTextStream t( &file ); // use a text stream | 128 | QTextStream t( &file ); // use a text stream |
129 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 129 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
130 | QString data; | 130 | QString data; |
131 | data = t.read(); | 131 | data = t.read(); |
132 | file.close(); | 132 | file.close(); |
133 | KABC::VCardConverter converter; | 133 | KABC::VCardConverter converter; |
134 | list = converter.parseVCards( data ); | 134 | list = converter.parseVCards( data ); |
135 | qDebug("kdeABdump::file has %d entries", list.count()); | 135 | qDebug("kdeABdump::file has %d entries", list.count()); |
136 | 136 | ||
137 | KABC::Addressee::List::Iterator it; | 137 | KABC::Addressee::List::Iterator it; |
138 | for ( it = list.begin();it != list.end();++it) { | 138 | for ( it = list.begin();it != list.end();++it) { |
139 | (*it).setChanged( true ); | ||
139 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); | 140 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); |
140 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 141 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
141 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); | 142 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); |
142 | if ( changed ) { | 143 | if ( changed ) { |
143 | //qDebug("changed Addressee found! "); | 144 | //qDebug("changed Addressee found! "); |
144 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 145 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
145 | if ( ! std.isEmpty() ) | 146 | if ( ! std.isEmpty() ) |
146 | (*it).setResource(std.resource()); | 147 | (*it).setResource(std.resource()); |
147 | standardAddressBook->insertAddressee( (*it) ); | 148 | standardAddressBook->insertAddressee( (*it) ); |
148 | ++changedC; | 149 | ++changedC; |
149 | } else { | 150 | } else { |
150 | //maybe added? | 151 | //maybe added? |
151 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 152 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
152 | if ( std.isEmpty() ) { | 153 | if ( std.isEmpty() ) { |
153 | standardAddressBook->insertAddressee( (*it) ); | 154 | standardAddressBook->insertAddressee( (*it) ); |
154 | ++added; | 155 | ++added; |
155 | } | 156 | } |
156 | } | 157 | } |
157 | } | 158 | } |
158 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); | 159 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); |
159 | KABC::AddressBook::Iterator it2 ; | 160 | KABC::AddressBook::Iterator it2 ; |
160 | while ( itA != standardAddressBook->end() ) { | 161 | while ( itA != standardAddressBook->end() ) { |
161 | bool found = false; | 162 | bool found = false; |
162 | KABC::Addressee::List::Iterator itL; | 163 | KABC::Addressee::List::Iterator itL; |
163 | for ( itL = list.begin();itL != list.end();++itL) { | 164 | for ( itL = list.begin();itL != list.end();++itL) { |
164 | if ( (*itL).uid() == (*itA).uid() ) { | 165 | if ( (*itL).uid() == (*itA).uid() ) { |
165 | found = true; | 166 | found = true; |
166 | break; | 167 | break; |
167 | } | 168 | } |
168 | } | 169 | } |
169 | if ( !found ) { | 170 | if ( !found ) { |
170 | it2 = itA; | 171 | it2 = itA; |
171 | ++itA; | 172 | ++itA; |
172 | standardAddressBook->removeAddressee( it2 ); | 173 | standardAddressBook->removeAddressee( it2 ); |
173 | ++deleted; | 174 | ++deleted; |
174 | } else { | 175 | } else { |
175 | ++itA; | 176 | ++itA; |
176 | } | 177 | } |
177 | } | 178 | } |
178 | 179 | ||
179 | //standardAddressBook->saveAll(); | 180 | //standardAddressBook->saveAll(); |
180 | standardAddressBook->setAutomaticSave( true ); | 181 | standardAddressBook->setAutomaticSave( true ); |
181 | qDebug("************************************* "); | 182 | qDebug("************************************* "); |
182 | qDebug("*************kdeABdump*************** "); | 183 | qDebug("*************kdeABdump*************** "); |
183 | qDebug("************************************* "); | 184 | qDebug("************************************* "); |
184 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); | 185 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); |
185 | } else | 186 | } else |
186 | qDebug("error open file "); | 187 | qDebug("error open file "); |
187 | } | 188 | } |
188 | 189 | ||
189 | KABC::StdAddressBook::close(); | 190 | delete standardAddressBook; |
190 | 191 | //KABC::StdAddressBook::close(); | |
192 | //StdAddressBook::mSelf = 0; | ||
191 | qDebug("ente "); | 193 | qDebug("ente "); |
192 | return 0; | 194 | return 0; |
193 | } | 195 | } |