author | zautrix <zautrix> | 2005-04-17 14:27:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-17 14:27:55 (UTC) |
commit | b411ec2d8961d07c3e2e9aefc9e04322b7851859 (patch) (unidiff) | |
tree | 79e2a70f1ad32562456b0bfa03aa2b916095fbb0 /kde2file/abdump | |
parent | 2d81c75c4ffb8f144ae58e90e68496500d07a19e (diff) | |
download | kdepimpi-b411ec2d8961d07c3e2e9aefc9e04322b7851859.zip kdepimpi-b411ec2d8961d07c3e2e9aefc9e04322b7851859.tar.gz kdepimpi-b411ec2d8961d07c3e2e9aefc9e04322b7851859.tar.bz2 |
qdebugcleanup
-rw-r--r-- | kde2file/abdump/main.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp index b359cfe..824d054 100644 --- a/kde2file/abdump/main.cpp +++ b/kde2file/abdump/main.cpp | |||
@@ -1,196 +1,197 @@ | |||
1 | /******************************************************************************* | 1 | /******************************************************************************* |
2 | * main.cpp * | 2 | * main.cpp * |
3 | * * | 3 | * * |
4 | * | 4 | * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * | 7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * | 8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * | 9 | * (at your option) any later version. * |
10 | * * | 10 | * * |
11 | * This program is distributed in the hope that it will be useful, * | 11 | * This program is distributed in the hope that it will be useful, * |
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 * | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * | 14 | * GNU General Public License for more details. * |
15 | * * | 15 | * * |
16 | * You should have received a copy of the GNU General Public License * | 16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * | 17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | * * | 19 | * * |
20 | * As a special exception, permission is given to link this program * | 20 | * As a special exception, permission is given to link this program * |
21 | * with any edition of Qt, and distribute the resulting executable, * | 21 | * with any edition of Qt, and distribute the resulting executable, * |
22 | * without including the source code for Qt in the source distribution. * | 22 | * without including the source code for Qt in the source distribution. * |
23 | * * | 23 | * * |
24 | ******************************************************************************/ | 24 | ******************************************************************************/ |
25 | 25 | ||
26 | #include <kcmdlineargs.h> | 26 | #include <kcmdlineargs.h> |
27 | #include <kaboutdata.h> | 27 | #include <kaboutdata.h> |
28 | #include <klocale.h> | 28 | #include <klocale.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <kconfig.h> | 30 | #include <kconfig.h> |
31 | #include <kstandarddirs.h> | 31 | #include <kstandarddirs.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | 33 | ||
34 | #include <kabc/addressbook.h> | 34 | #include <kabc/addressbook.h> |
35 | #include <kabc/stdaddressbook.h> | 35 | #include <kabc/stdaddressbook.h> |
36 | #include <kabc/resource.h> | 36 | #include <kabc/resource.h> |
37 | #include <kabc/vcardconverter.h> | 37 | #include <kabc/vcardconverter.h> |
38 | 38 | ||
39 | #include <qdatetime.h> | 39 | #include <qdatetime.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qdir.h> | 41 | #include <qdir.h> |
42 | #include <qapplication.h> | 42 | #include <qapplication.h> |
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 | if ( (*it).isEmpty() ) | ||
106 | continue; | 107 | continue; |
107 | KABC::Addressee a = ( *it ); | 108 | KABC::Addressee a = ( *it ); |
108 | QString vcard = converter.createVCard( a ); | 109 | QString vcard = converter.createVCard( a ); |
109 | vcard += QString("\r\n"); | 110 | vcard += QString("\r\n"); |
110 | datastream += vcard; | 111 | datastream += vcard; |
111 | } | 112 | } |
112 | QFile outFile(fileName); | 113 | QFile outFile(fileName); |
113 | if ( outFile.open(IO_WriteOnly) ) { | 114 | if ( outFile.open(IO_WriteOnly) ) { |
114 | QTextStream t( &outFile ); // use a text stream | 115 | QTextStream t( &outFile ); // use a text stream |
115 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 116 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
116 | t <<datastream; | 117 | t <<datastream; |
117 | t << "\r\n\r\n"; | 118 | t << "\r\n\r\n"; |
118 | outFile.close(); | 119 | outFile.close(); |
119 | } | 120 | } |
120 | } else { | 121 | } else { |
121 | //Addressee::List aList;//parseVCards( const QString& vcard ); | 122 | //Addressee::List aList;//parseVCards( const QString& vcard ); |
122 | KABC::Addressee::List list; | 123 | KABC::Addressee::List list; |
123 | int added = 0, changedC = 0, deleted = 0; | 124 | int added = 0, changedC = 0, deleted = 0; |
124 | QFile file( fileName ); | 125 | QFile file( fileName ); |
125 | if ( file.open( IO_ReadOnly ) ) { | 126 | if ( file.open( IO_ReadOnly ) ) { |
126 | QTextStream t( &file ); // use a text stream | 127 | QTextStream t( &file ); // use a text stream |
127 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 128 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
128 | QString data; | 129 | QString data; |
129 | data = t.read(); | 130 | data = t.read(); |
130 | file.close(); | 131 | file.close(); |
131 | KABC::VCardConverter converter; | 132 | KABC::VCardConverter converter; |
132 | list = converter.parseVCards( data ); | 133 | list = converter.parseVCards( data ); |
133 | qDebug("kdeABdump::file has %d entries", list.count()); | 134 | qDebug("kdeABdump::file has %d entries", list.count()); |
134 | 135 | ||
135 | KABC::Addressee::List::Iterator it; | 136 | KABC::Addressee::List::Iterator it; |
136 | for ( it = list.begin();it != list.end();++it) { | 137 | for ( it = list.begin();it != list.end();++it) { |
137 | (*it).setChanged( true ); | 138 | (*it).setChanged( true ); |
138 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); | 139 | bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); |
139 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 140 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
140 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); | 141 | //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); |
141 | if ( changed ) { | 142 | if ( changed ) { |
142 | //qDebug("changed Addressee found! "); | 143 | //qDebug("changed Addressee found! "); |
143 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 144 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
144 | if ( ! std.isEmpty() ) | 145 | if ( ! std.isEmpty() ) |
145 | (*it).setResource(std.resource()); | 146 | (*it).setResource(std.resource()); |
146 | standardAddressBook->insertAddressee( (*it) ); | 147 | standardAddressBook->insertAddressee( (*it) ); |
147 | ++changedC; | 148 | ++changedC; |
148 | } else { | 149 | } else { |
149 | //maybe added? | 150 | //maybe added? |
150 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); | 151 | KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); |
151 | if ( std.isEmpty() ) { | 152 | if ( std.isEmpty() ) { |
152 | standardAddressBook->insertAddressee( (*it) ); | 153 | standardAddressBook->insertAddressee( (*it) ); |
153 | ++added; | 154 | ++added; |
154 | } | 155 | } |
155 | } | 156 | } |
156 | } | 157 | } |
157 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); | 158 | KABC::AddressBook::Iterator itA = standardAddressBook->begin(); |
158 | KABC::AddressBook::Iterator it2 ; | 159 | KABC::AddressBook::Iterator it2 ; |
159 | while ( itA != standardAddressBook->end() ) { | 160 | while ( itA != standardAddressBook->end() ) { |
160 | bool found = false; | 161 | bool found = false; |
161 | KABC::Addressee::List::Iterator itL; | 162 | KABC::Addressee::List::Iterator itL; |
162 | for ( itL = list.begin();itL != list.end();++itL) { | 163 | for ( itL = list.begin();itL != list.end();++itL) { |
163 | if ( (*itL).uid() == (*itA).uid() ) { | 164 | if ( (*itL).uid() == (*itA).uid() ) { |
164 | found = true; | 165 | found = true; |
165 | break; | 166 | break; |
166 | } | 167 | } |
167 | } | 168 | } |
168 | if ( !found ) { | 169 | if ( !found ) { |
169 | it2 = itA; | 170 | it2 = itA; |
170 | ++itA; | 171 | ++itA; |
171 | standardAddressBook->removeAddressee( it2 ); | 172 | standardAddressBook->removeAddressee( it2 ); |
172 | ++deleted; | 173 | ++deleted; |
173 | } else { | 174 | } else { |
174 | ++itA; | 175 | ++itA; |
175 | } | 176 | } |
176 | } | 177 | } |
177 | 178 | ||
178 | //standardAddressBook->saveAll(); | 179 | //standardAddressBook->saveAll(); |
179 | standardAddressBook->setAutomaticSave( true ); | 180 | standardAddressBook->setAutomaticSave( true ); |
180 | qDebug("************************************* "); | 181 | qDebug("************************************* "); |
181 | qDebug("*************kdeABdump*************** "); | 182 | qDebug("*************kdeABdump*************** "); |
182 | qDebug("************************************* "); | 183 | qDebug("************************************* "); |
183 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); | 184 | qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); |
184 | } else | 185 | } else |
185 | qDebug("error open file "); | 186 | qDebug("error open file "); |
186 | } | 187 | } |
187 | standardAddressBook->close(); | 188 | standardAddressBook->close(); |
188 | // line not needed by KDE 3.4: | 189 | // line not needed by KDE 3.4: |
189 | // delete standardAddressBook; | 190 | // delete standardAddressBook; |
190 | 191 | ||
191 | 192 | ||
192 | //KABC::StdAddressBook::close(); | 193 | //KABC::StdAddressBook::close(); |
193 | //StdAddressBook::mSelf = 0; | 194 | //StdAddressBook::mSelf = 0; |
194 | qDebug("ente "); | 195 | qDebug("ente "); |
195 | return 0; | 196 | return 0; |
196 | } | 197 | } |