author | ulf69 <ulf69> | 2004-07-02 15:38:16 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-02 15:38:16 (UTC) |
commit | 30988fc010930d5c43ca7bc51ba64d57210c3985 (patch) (unidiff) | |
tree | 360ccd0055cb11d669f03baa350843e864746785 | |
parent | ead0dcba2c607297137e2b47418eb17864e0caaa (diff) | |
download | kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.zip kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.tar.gz kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.tar.bz2 |
bugfix: choosen filenames where not used while import/export and for resources
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 9 | ||||
-rw-r--r-- | kaddressbook/xxport/opie/opie_xxport.cpp | 12 |
2 files changed, 16 insertions, 5 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index f992301..a4f8d8a 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -1,313 +1,318 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
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 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (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 | #include <qtimer.h> | 36 | #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 | 44 | ||
45 | //US #include "formatfactory.h" | 45 | //US #include "formatfactory.h" |
46 | //US #include <qpe/qpeapplication.h> | 46 | //US #include <qpe/qpeapplication.h> |
47 | 47 | ||
48 | #include <opie/ocontactaccess.h> | 48 | #include <opie/ocontactaccess.h> |
49 | #include <opie/ocontactaccessbackend_xml.h> | ||
49 | 50 | ||
50 | #include "resource.h" | 51 | #include "resource.h" |
51 | #include "resourceopieconfig.h" | 52 | #include "resourceopieconfig.h" |
52 | #include "stdaddressbook.h" | 53 | #include "stdaddressbook.h" |
53 | 54 | ||
54 | #include "opieconverter.h" | 55 | #include "opieconverter.h" |
55 | 56 | ||
56 | #include "resourceopie.h" | 57 | #include "resourceopie.h" |
57 | 58 | ||
58 | using namespace KABC; | 59 | using namespace KABC; |
59 | extern "C" | 60 | extern "C" |
60 | { | 61 | { |
61 | void *init_microkabc_opie() | 62 | void *init_microkabc_opie() |
62 | { | 63 | { |
63 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); | 64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
67 | ResourceOpie::ResourceOpie( const KConfig *config ) | 68 | ResourceOpie::ResourceOpie( const KConfig *config ) |
68 | : Resource( config ), mConverter (0) | 69 | : Resource( config ), mConverter (0) |
69 | { | 70 | { |
70 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
71 | 72 | ||
72 | KConfig *cfg = (KConfig *)config; | 73 | KConfig *cfg = (KConfig *)config; |
73 | if ( cfg ) { | 74 | if ( cfg ) { |
74 | fileName = cfg->readEntry( "FileName", fileName ); | 75 | fileName = cfg->readEntry( "FileName", fileName ); |
75 | 76 | ||
76 | } | 77 | } |
77 | 78 | ||
78 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | 79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); |
79 | 80 | ||
80 | init( fileName ); | 81 | init( fileName ); |
81 | } | 82 | } |
82 | 83 | ||
83 | ResourceOpie::ResourceOpie( const QString &fileName ) | 84 | ResourceOpie::ResourceOpie( const QString &fileName ) |
84 | : Resource( 0 ) | 85 | : Resource( 0 ) |
85 | { | 86 | { |
86 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | 87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); |
87 | init( fileName ); | 88 | init( fileName ); |
88 | } | 89 | } |
89 | 90 | ||
90 | void ResourceOpie::init( const QString &fileName ) | 91 | void ResourceOpie::init( const QString &fileName ) |
91 | { | 92 | { |
92 | 93 | ||
93 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | 94 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods |
94 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 95 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
95 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 96 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
96 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 97 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
97 | */ | 98 | */ |
98 | //US opie addressbook is always readonly | 99 | //US opie addressbook is always readonly |
99 | setReadOnly( true ); | 100 | setReadOnly( true ); |
100 | 101 | ||
101 | setFileName( fileName ); | 102 | setFileName( fileName ); |
102 | 103 | ||
103 | } | 104 | } |
104 | 105 | ||
105 | ResourceOpie::~ResourceOpie() | 106 | ResourceOpie::~ResourceOpie() |
106 | { | 107 | { |
107 | if (mConverter != 0) | 108 | if (mConverter != 0) |
108 | delete mConverter; | 109 | delete mConverter; |
109 | } | 110 | } |
110 | 111 | ||
111 | void ResourceOpie::writeConfig( KConfig *config ) | 112 | void ResourceOpie::writeConfig( KConfig *config ) |
112 | { | 113 | { |
113 | //US opie addressbook is always readonly | 114 | //US opie addressbook is always readonly |
114 | setReadOnly( true ); | 115 | setReadOnly( true ); |
115 | 116 | ||
116 | Resource::writeConfig( config ); | 117 | Resource::writeConfig( config ); |
117 | 118 | ||
118 | config->writeEntry( "FileName", mFileName ); | 119 | config->writeEntry( "FileName", mFileName ); |
119 | 120 | ||
120 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 121 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
121 | 122 | ||
122 | } | 123 | } |
123 | 124 | ||
124 | Ticket *ResourceOpie::requestSaveTicket() | 125 | Ticket *ResourceOpie::requestSaveTicket() |
125 | { | 126 | { |
126 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 127 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
127 | 128 | ||
128 | if ( !addressBook() ) return 0; | 129 | if ( !addressBook() ) return 0; |
129 | 130 | ||
130 | if ( !lock( mFileName ) ) { | 131 | if ( !lock( mFileName ) ) { |
131 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | 132 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" |
132 | << mFileName << "'" << endl; | 133 | << mFileName << "'" << endl; |
133 | return 0; | 134 | return 0; |
134 | } | 135 | } |
135 | return createTicket( this ); | 136 | return createTicket( this ); |
136 | } | 137 | } |
137 | 138 | ||
138 | 139 | ||
139 | bool ResourceOpie::doOpen() | 140 | bool ResourceOpie::doOpen() |
140 | { | 141 | { |
141 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); | 142 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); |
142 | /*US | 143 | /*US |
143 | QFile file( mFileName ); | 144 | QFile file( mFileName ); |
144 | 145 | ||
145 | if ( !file.exists() ) { | 146 | if ( !file.exists() ) { |
146 | // try to create the file | 147 | // try to create the file |
147 | bool ok = file.open( IO_WriteOnly ); | 148 | bool ok = file.open( IO_WriteOnly ); |
148 | if ( ok ) | 149 | if ( ok ) |
149 | file.close(); | 150 | file.close(); |
150 | 151 | ||
151 | return ok; | 152 | return ok; |
152 | } else { | 153 | } else { |
153 | if ( !file.open( IO_ReadWrite ) ) | 154 | if ( !file.open( IO_ReadWrite ) ) |
154 | return false; | 155 | return false; |
155 | 156 | ||
156 | if ( file.size() == 0 ) { | 157 | if ( file.size() == 0 ) { |
157 | file.close(); | 158 | file.close(); |
158 | return true; | 159 | return true; |
159 | } | 160 | } |
160 | 161 | ||
161 | //US bool ok = mFormat->checkFormat( &file ); | 162 | //US bool ok = mFormat->checkFormat( &file ); |
162 | bool ok = true; | 163 | bool ok = true; |
163 | 164 | ||
164 | file.close(); | 165 | file.close(); |
165 | 166 | ||
166 | return ok; | 167 | return ok; |
167 | } | 168 | } |
168 | */ | 169 | */ |
169 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); | 170 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); |
170 | return true; | 171 | return true; |
171 | } | 172 | } |
172 | 173 | ||
173 | void ResourceOpie::doClose() | 174 | void ResourceOpie::doClose() |
174 | { | 175 | { |
175 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); | 176 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); |
176 | } | 177 | } |
177 | 178 | ||
178 | bool ResourceOpie::load() | 179 | bool ResourceOpie::load() |
179 | { | 180 | { |
180 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); | 181 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); |
181 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; | 182 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; |
182 | 183 | ||
183 | OContactAccess* access = new OContactAccess("KDEPim/Pi", mFileName, 0l, false); | 184 | qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); |
185 | |||
186 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); | ||
187 | OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); | ||
184 | 188 | ||
185 | if ( !access ) { | 189 | if ( !access ) { |
186 | qDebug("Unable to load file() %s", mFileName.latin1()); | 190 | qDebug("Unable to load file() %s", mFileName.latin1()); |
187 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | 191 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); |
188 | return false; | 192 | return false; |
189 | } | 193 | } |
190 | 194 | ||
191 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | 195 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available |
192 | 196 | ||
193 | if (mConverter == 0) | 197 | if (mConverter == 0) |
194 | mConverter = new OpieConverter(); | 198 | mConverter = new OpieConverter(); |
195 | 199 | ||
196 | 200 | ||
197 | OContactAccess::List::Iterator it; | 201 | OContactAccess::List::Iterator it; |
198 | OContactAccess::List allList = access->allRecords(); | 202 | OContactAccess::List allList = access->allRecords(); |
199 | bool res = false; | 203 | bool res = false; |
200 | for ( it = allList.begin(); it != allList.end(); ++it ) | 204 | for ( it = allList.begin(); it != allList.end(); ++it ) |
201 | { | 205 | { |
202 | OContact c = (*it); | 206 | OContact c = (*it); |
203 | 207 | ||
204 | KABC::Addressee addressee; | 208 | KABC::Addressee addressee; |
205 | 209 | ||
206 | res = mConverter->opieToAddressee( c, addressee ); | 210 | res = mConverter->opieToAddressee( c, addressee ); |
207 | 211 | ||
208 | if ( !addressee.isEmpty() && res ) | 212 | if ( !addressee.isEmpty() && res ) |
209 | { | 213 | { |
210 | addressee.setResource( this ); | 214 | addressee.setResource( this ); |
211 | addressBook()->insertAddressee( addressee ); | 215 | addressBook()->insertAddressee( addressee ); |
212 | } | 216 | } |
213 | 217 | ||
214 | // qDebug("found %s", c.fullName().latin1()); | 218 | // qDebug("found %s", c.fullName().latin1()); |
215 | } | 219 | } |
216 | 220 | ||
217 | delete access; | 221 | delete access; |
222 | delete backend; | ||
218 | 223 | ||
219 | return true; | 224 | return true; |
220 | } | 225 | } |
221 | 226 | ||
222 | bool ResourceOpie::save( Ticket *ticket ) | 227 | bool ResourceOpie::save( Ticket *ticket ) |
223 | { | 228 | { |
224 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); | 229 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); |
225 | /*US | 230 | /*US |
226 | 231 | ||
227 | qDebug("ResourceOpie::save %s", mFileName.latin1()); | 232 | qDebug("ResourceOpie::save %s", mFileName.latin1()); |
228 | kdDebug(5700) << "ResourceOpie::save()" << endl; | 233 | kdDebug(5700) << "ResourceOpie::save()" << endl; |
229 | 234 | ||
230 | // create backup file | 235 | // create backup file |
231 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 236 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
232 | */ | 237 | */ |
233 | /*US we use a simpler method to create a backupfile | 238 | /*US we use a simpler method to create a backupfile |
234 | 239 | ||
235 | (void) KSaveFile::backupFile( mFileName, QString::null | 240 | (void) KSaveFile::backupFile( mFileName, QString::null |
236 | ,extension ); | 241 | ,extension ); |
237 | 242 | ||
238 | KSaveFile saveFile( mFileName ); | 243 | KSaveFile saveFile( mFileName ); |
239 | bool ok = false; | 244 | bool ok = false; |
240 | if ( saveFile.status() == 0 && saveFile.file() ) | 245 | if ( saveFile.status() == 0 && saveFile.file() ) |
241 | { | 246 | { |
242 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 247 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
243 | ok = saveFile.close(); | 248 | ok = saveFile.close(); |
244 | } | 249 | } |
245 | */ | 250 | */ |
246 | /*US | 251 | /*US |
247 | //US ToDo: write backupfile | 252 | //US ToDo: write backupfile |
248 | QFile info; | 253 | QFile info; |
249 | info.setName( mFileName ); | 254 | info.setName( mFileName ); |
250 | bool ok = info.open( IO_WriteOnly ); | 255 | bool ok = info.open( IO_WriteOnly ); |
251 | if ( ok ) { | 256 | if ( ok ) { |
252 | //US mFormat->saveAll( addressBook(), this, &info ); | 257 | //US mFormat->saveAll( addressBook(), this, &info ); |
253 | 258 | ||
254 | info.close(); | 259 | info.close(); |
255 | ok = true; | 260 | ok = true; |
256 | } | 261 | } |
257 | else { | 262 | else { |
258 | 263 | ||
259 | } | 264 | } |
260 | 265 | ||
261 | if ( !ok ) | 266 | if ( !ok ) |
262 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 267 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
263 | 268 | ||
264 | delete ticket; | 269 | delete ticket; |
265 | unlock( mFileName ); | 270 | unlock( mFileName ); |
266 | 271 | ||
267 | return ok; | 272 | return ok; |
268 | 273 | ||
269 | qDebug("ResourceOpie::save has to be changed"); | 274 | qDebug("ResourceOpie::save has to be changed"); |
270 | */ | 275 | */ |
271 | return true; | 276 | return true; |
272 | 277 | ||
273 | } | 278 | } |
274 | 279 | ||
275 | bool ResourceOpie::lock( const QString &fileName ) | 280 | bool ResourceOpie::lock( const QString &fileName ) |
276 | { | 281 | { |
277 | qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); | 282 | qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); |
278 | 283 | ||
279 | /*US | 284 | /*US |
280 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); | 285 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); |
281 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | 286 | kdDebug(5700) << "ResourceOpie::lock()" << endl; |
282 | 287 | ||
283 | QString fn = fileName; | 288 | QString fn = fileName; |
284 | 289 | ||
285 | //US change the implementation how the lockfilename is getting created | 290 | //US change the implementation how the lockfilename is getting created |
286 | //US fn.replace( QRegExp("/"), "_" ); | 291 | //US fn.replace( QRegExp("/"), "_" ); |
287 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 292 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
288 | 293 | ||
289 | KURL url(fn); | 294 | KURL url(fn); |
290 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 295 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
291 | 296 | ||
292 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 297 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
293 | 298 | ||
294 | if (QFile::exists( lockName )) return false; | 299 | if (QFile::exists( lockName )) return false; |
295 | 300 | ||
296 | QString lockUniqueName; | 301 | QString lockUniqueName; |
297 | lockUniqueName = fn + KApplication::randomString( 8 ); | 302 | lockUniqueName = fn + KApplication::randomString( 8 ); |
298 | 303 | ||
299 | url = lockUniqueName; | 304 | url = lockUniqueName; |
300 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 305 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
301 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 306 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
302 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 307 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
303 | 308 | ||
304 | // Create unique file | 309 | // Create unique file |
305 | QFile file( mLockUniqueName ); | 310 | QFile file( mLockUniqueName ); |
306 | file.open( IO_WriteOnly ); | 311 | file.open( IO_WriteOnly ); |
307 | file.close(); | 312 | file.close(); |
308 | 313 | ||
309 | // Create lock file | 314 | // Create lock file |
310 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 315 | int result = ::link( QFile::encodeName( mLockUniqueName ), |
311 | QFile::encodeName( lockName ) ); | 316 | QFile::encodeName( lockName ) ); |
312 | 317 | ||
313 | if ( result == 0 ) { | 318 | if ( result == 0 ) { |
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp index 90d05cd..f30a205 100644 --- a/kaddressbook/xxport/opie/opie_xxport.cpp +++ b/kaddressbook/xxport/opie/opie_xxport.cpp | |||
@@ -1,196 +1,202 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressbook. | 2 | This file is part of KAddressbook. |
3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | 32 | ||
33 | #include <kfiledialog.h> | 33 | #include <kfiledialog.h> |
34 | #include <kmessagebox.h> | 34 | #include <kmessagebox.h> |
35 | 35 | ||
36 | #include <opie/ocontactaccess.h> | 36 | #include <opie/ocontactaccess.h> |
37 | #include <opie/ocontactaccessbackend_xml.h> | ||
38 | |||
37 | #include "stdaddressbook.h" | 39 | #include "stdaddressbook.h" |
38 | 40 | ||
39 | /*US | 41 | /*US |
40 | #include <qfile.h> | 42 | #include <qfile.h> |
41 | #include <qtextstream.h> | 43 | #include <qtextstream.h> |
42 | 44 | ||
43 | #include <kabc/vcardconverter.h> | 45 | #include <kabc/vcardconverter.h> |
44 | #ifndef KAB_EMBEDDED | 46 | #ifndef KAB_EMBEDDED |
45 | #include <kio/netaccess.h> | 47 | #include <kio/netaccess.h> |
46 | #endif //KAB_EMBEDDED | 48 | #endif //KAB_EMBEDDED |
47 | 49 | ||
48 | #include <klocale.h> | 50 | #include <klocale.h> |
49 | #include <kmessagebox.h> | 51 | #include <kmessagebox.h> |
50 | #include <ktempfile.h> | 52 | #include <ktempfile.h> |
51 | #include <kurl.h> | 53 | #include <kurl.h> |
52 | */ | 54 | */ |
53 | 55 | ||
54 | #include "xxportmanager.h" | 56 | #include "xxportmanager.h" |
55 | #include "opieconverter.h" | 57 | #include "opieconverter.h" |
56 | 58 | ||
57 | #include "opie_xxport.h" | 59 | #include "opie_xxport.h" |
58 | 60 | ||
59 | 61 | ||
60 | class OpieXXPortFactory : public XXPortFactory | 62 | class OpieXXPortFactory : public XXPortFactory |
61 | { | 63 | { |
62 | public: | 64 | public: |
63 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 65 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
64 | { | 66 | { |
65 | return new OpieXXPort( ab, parent, name ); | 67 | return new OpieXXPort( ab, parent, name ); |
66 | } | 68 | } |
67 | }; | 69 | }; |
68 | 70 | ||
69 | 71 | ||
70 | extern "C" | 72 | extern "C" |
71 | { | 73 | { |
72 | void *init_kaddrbk_opie_xxport() | 74 | void *init_kaddrbk_opie_xxport() |
73 | { | 75 | { |
74 | return ( new OpieXXPortFactory() ); | 76 | return ( new OpieXXPortFactory() ); |
75 | } | 77 | } |
76 | } | 78 | } |
77 | 79 | ||
78 | 80 | ||
79 | OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 81 | OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
80 | : XXPortObject( ab, parent, name ) | 82 | : XXPortObject( ab, parent, name ) |
81 | { | 83 | { |
82 | createImportAction( i18n( "Import Opie..." ) ); | 84 | createImportAction( i18n( "Import Opie..." ) ); |
83 | createExportAction( i18n( "Export Opie..." ) ); | 85 | createExportAction( i18n( "Export Opie..." ) ); |
84 | } | 86 | } |
85 | 87 | ||
86 | bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | 88 | bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) |
87 | { | 89 | { |
88 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 90 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
89 | 91 | ||
90 | #ifndef KAB_EMBEDDED | 92 | #ifndef KAB_EMBEDDED |
91 | QString fileName = KFileDialog::getSaveFileName( name ); | 93 | QString fileName = KFileDialog::getSaveFileName( name ); |
92 | #else //KAB_EMBEDDED | 94 | #else //KAB_EMBEDDED |
93 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); | 95 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); |
94 | #endif //KAB_EMBEDDED | 96 | #endif //KAB_EMBEDDED |
95 | 97 | ||
96 | if ( fileName.isEmpty() ) | 98 | if ( fileName.isEmpty() ) |
97 | return true; | 99 | return true; |
98 | 100 | ||
99 | OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false); | 101 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); |
102 | OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); | ||
100 | 103 | ||
101 | if ( !access ) { | 104 | if ( !access ) { |
102 | qDebug("Unable to access file() %s", fileName.latin1()); | 105 | qDebug("Unable to access file() %s", fileName.latin1()); |
103 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | 106 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); |
104 | return false; | 107 | return false; |
105 | } | 108 | } |
106 | 109 | ||
107 | //Now check if the file has already entries, and ask the user if he wants to delete them first. | 110 | //Now check if the file has already entries, and ask the user if he wants to delete them first. |
108 | OContactAccess::List contactList = access->allRecords(); | 111 | OContactAccess::List contactList = access->allRecords(); |
109 | if (contactList.count() > 0) | 112 | if (contactList.count() > 0) |
110 | { | 113 | { |
111 | QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); | 114 | QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); |
112 | if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { | 115 | if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { |
113 | // Clean the database.. | 116 | // Clean the database.. |
114 | access->clear(); | 117 | access->clear(); |
115 | } | 118 | } |
116 | } | 119 | } |
117 | 120 | ||
118 | KABC::OpieConverter mConverter; | 121 | KABC::OpieConverter mConverter; |
119 | bool res; | 122 | bool res; |
120 | 123 | ||
121 | KABC::Addressee::List::ConstIterator it; | 124 | KABC::Addressee::List::ConstIterator it; |
122 | for ( it = list.begin(); it != list.end(); ++it ) { | 125 | for ( it = list.begin(); it != list.end(); ++it ) { |
123 | OContact c; | 126 | OContact c; |
124 | KABC::Addressee addressee = (*it); | 127 | KABC::Addressee addressee = (*it); |
125 | 128 | ||
126 | res = mConverter.addresseeToOpie( *it, c ); | 129 | res = mConverter.addresseeToOpie( *it, c ); |
127 | if (res == true) | 130 | if (res == true) |
128 | { | 131 | { |
129 | res = access->add(c); | 132 | res = access->add(c); |
130 | if (res == false) | 133 | if (res == false) |
131 | qDebug("Unable to append Contact %s", c.fullName().latin1()); | 134 | qDebug("Unable to append Contact %s", c.fullName().latin1()); |
132 | } | 135 | } |
133 | else | 136 | else |
134 | { | 137 | { |
135 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | 138 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
136 | } | 139 | } |
137 | } | 140 | } |
138 | 141 | ||
139 | access->save(); | 142 | access->save(); |
140 | 143 | ||
141 | delete access; | 144 | delete access; |
142 | 145 | delete backend; | |
146 | |||
143 | return true; | 147 | return true; |
144 | } | 148 | } |
145 | 149 | ||
146 | KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const | 150 | KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const |
147 | { | 151 | { |
148 | KABC::AddresseeList adrlst; | 152 | KABC::AddresseeList adrlst; |
149 | 153 | ||
150 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 154 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
151 | 155 | ||
152 | #ifndef KAB_EMBEDDED | 156 | #ifndef KAB_EMBEDDED |
153 | QString fileName = KFileDialog::getOpenFileName( name ); | 157 | QString fileName = KFileDialog::getOpenFileName( name ); |
154 | #else //KAB_EMBEDDED | 158 | #else //KAB_EMBEDDED |
155 | QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); | 159 | QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); |
156 | #endif //KAB_EMBEDDED | 160 | #endif //KAB_EMBEDDED |
157 | 161 | ||
158 | if ( fileName.isEmpty() ) | 162 | if ( fileName.isEmpty() ) |
159 | return KABC::AddresseeList(); | 163 | return KABC::AddresseeList(); |
160 | 164 | ||
161 | OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false); | 165 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); |
166 | OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); | ||
162 | 167 | ||
163 | if ( !access ) { | 168 | if ( !access ) { |
164 | qDebug("Unable to access file() %s", fileName.latin1()); | 169 | qDebug("Unable to access file() %s", fileName.latin1()); |
165 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | 170 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); |
166 | return KABC::AddresseeList(); | 171 | return KABC::AddresseeList(); |
167 | } | 172 | } |
168 | 173 | ||
169 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | 174 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available |
170 | 175 | ||
171 | KABC::OpieConverter mConverter; | 176 | KABC::OpieConverter mConverter; |
172 | bool res = false; | 177 | bool res = false; |
173 | 178 | ||
174 | 179 | ||
175 | OContactAccess::List::Iterator it; | 180 | OContactAccess::List::Iterator it; |
176 | OContactAccess::List allList = access->allRecords(); | 181 | OContactAccess::List allList = access->allRecords(); |
177 | for ( it = allList.begin(); it != allList.end(); ++it ) | 182 | for ( it = allList.begin(); it != allList.end(); ++it ) |
178 | { | 183 | { |
179 | OContact c = (*it); | 184 | OContact c = (*it); |
180 | 185 | ||
181 | KABC::Addressee addressee; | 186 | KABC::Addressee addressee; |
182 | 187 | ||
183 | res = mConverter.opieToAddressee( c, addressee ); | 188 | res = mConverter.opieToAddressee( c, addressee ); |
184 | 189 | ||
185 | if ( !addressee.isEmpty() && res ) { | 190 | if ( !addressee.isEmpty() && res ) { |
186 | adrlst.append( addressee ); | 191 | adrlst.append( addressee ); |
187 | } | 192 | } |
188 | 193 | ||
189 | // qDebug("found %s", c.fullName().latin1()); | 194 | // qDebug("found %s", c.fullName().latin1()); |
190 | } | 195 | } |
191 | 196 | ||
192 | delete access; | 197 | delete access; |
198 | delete backend; | ||
193 | 199 | ||
194 | return adrlst; | 200 | return adrlst; |
195 | 201 | ||
196 | } | 202 | } |