summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (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
@@ -1,96 +1,97 @@
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/*
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 );
81} 82}
82 83
83ResourceOpie::ResourceOpie( const QString &fileName ) 84ResourceOpie::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
90void ResourceOpie::init( const QString &fileName ) 91void 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() ) );
@@ -134,132 +135,136 @@ Ticket *ResourceOpie::requestSaveTicket()
134 } 135 }
135 return createTicket( this ); 136 return createTicket( this );
136} 137}
137 138
138 139
139bool ResourceOpie::doOpen() 140bool 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
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 );
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 );