summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
authorulf69 <ulf69>2004-07-02 15:38:16 (UTC)
committer ulf69 <ulf69>2004-07-02 15:38:16 (UTC)
commit30988fc010930d5c43ca7bc51ba64d57210c3985 (patch) (unidiff)
tree360ccd0055cb11d669f03baa350843e864746785 /kabc/plugins
parentead0dcba2c607297137e2b47418eb17864e0caaa (diff)
downloadkdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.zip
kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.tar.gz
kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.tar.bz2
bugfix: choosen filenames where not used while import/export and for resources
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/opie/resourceopie.cpp9
1 files changed, 7 insertions, 2 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
@@ -17,64 +17,65 @@
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/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (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
58using namespace KABC; 59using namespace KABC;
59extern "C" 60extern "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
67ResourceOpie::ResourceOpie( const KConfig *config ) 68ResourceOpie::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 );
@@ -150,100 +151,104 @@ bool ResourceOpie::doOpen()
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
173void ResourceOpie::doClose() 174void ResourceOpie::doClose()
174{ 175{
175// qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); 176// qDebug("ResourceOpie::doClose() %s", mFileName.latin1());
176} 177}
177 178
178bool ResourceOpie::load() 179bool 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
222bool ResourceOpie::save( Ticket *ticket ) 227bool 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 );