summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/qtopia/resourceqtopia.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/qtopia/resourceqtopia.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 79ddaea..a36eb8f 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -10,49 +10,49 @@
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#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#ifndef _WIN32_ 29#ifndef _WIN32_
30#include <unistd.h> 30#include <unistd.h>
31#endif 31#endif
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qtextstream.h> 34#include <q3textstream.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qregexp.h> 36#include <qregexp.h>
37//US #include <qtimer.h> 37//US #include <qtimer.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <klocale.h> 42#include <klocale.h>
43//US #include <ksavefile.h> 43//US #include <ksavefile.h>
44#include <kstandarddirs.h> 44#include <kstandarddirs.h>
45#include <kmessagebox.h> 45#include <kmessagebox.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52 52
53#include "resourceqtopia.h" 53#include "resourceqtopia.h"
54 54
55using namespace KABC; 55using namespace KABC;
56 56
57extern "C" 57extern "C"
58#ifdef _WIN32_ 58#ifdef _WIN32_
@@ -135,101 +135,101 @@ bool ResourceQtopia::doOpen()
135 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 135 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
136 qDebug(msg); 136 qDebug(msg);
137 return false; 137 return false;
138 } 138 }
139 } 139 }
140 140
141 return true; 141 return true;
142} 142}
143 143
144void ResourceQtopia::doClose() 144void ResourceQtopia::doClose()
145{ 145{
146 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 146 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
147 147
148 148
149 // it seems so, that deletion of access deletes backend as well 149 // it seems so, that deletion of access deletes backend as well
150 //delete backend; 150 //delete backend;
151 151
152 return; 152 return;
153} 153}
154 154
155bool ResourceQtopia::load() 155bool ResourceQtopia::load()
156{ 156{
157 157
158 QFile file( fileName() ); 158 QFile file( fileName() );
159 if ( !file.open(IO_ReadOnly ) ) { 159 if ( !file.open(QIODevice::ReadOnly ) ) {
160 return false; 160 return false;
161 } 161 }
162 162
163 QDomDocument doc("mydocument" ); 163 QDomDocument doc("mydocument" );
164 if ( !doc.setContent( &file ) ) { 164 if ( !doc.setContent( &file ) ) {
165 file.close(); 165 file.close();
166 return false; 166 return false;
167 } 167 }
168 bool res; 168 bool res;
169 QDomElement docElem = doc.documentElement( ); 169 QDomElement docElem = doc.documentElement( );
170 QDomNode n = docElem.firstChild(); 170 QDomNode n = docElem.firstChild();
171 while ( !n.isNull() ) { 171 while ( !n.isNull() ) {
172 QDomElement e = n.toElement(); 172 QDomElement e = n.toElement();
173 if ( !e.isNull() ) { 173 if ( !e.isNull() ) {
174 if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { 174 if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) {
175 QDomNode no = e.firstChild(); 175 QDomNode no = e.firstChild();
176 while ( !no.isNull() ) { 176 while ( !no.isNull() ) {
177 QDomElement el = no.toElement(); 177 QDomElement el = no.toElement();
178 if ( !el.isNull() ) { 178 if ( !el.isNull() ) {
179 KABC::Addressee addressee; 179 KABC::Addressee addressee;
180 res = mConverter->qtopiaToAddressee( el, addressee ); 180 res = mConverter->qtopiaToAddressee( el, addressee );
181 if ( !addressee.isEmpty() && res ) 181 if ( !addressee.isEmpty() && res )
182 { 182 {
183 addressee.setResource( this ); 183 addressee.setResource( this );
184 addressBook()->insertAddressee( addressee ); 184 addressBook()->insertAddressee( addressee );
185 } 185 }
186 } 186 }
187 187
188 no = no.nextSibling(); 188 no = no.nextSibling();
189 } 189 }
190 } 190 }
191 } 191 }
192 192
193 n = n.nextSibling(); 193 n = n.nextSibling();
194 } 194 }
195 return true; 195 return true;
196} 196}
197 197
198bool ResourceQtopia::save( Ticket *ticket ) 198bool ResourceQtopia::save( Ticket *ticket )
199{ 199{
200#ifdef _USE_DIRWATCH_ 200#ifdef _USE_DIRWATCH_
201 mDirWatch.stopScan(); 201 mDirWatch.stopScan();
202#endif 202#endif
203 KABC::AddressBook::Iterator it; 203 KABC::AddressBook::Iterator it;
204 bool res; 204 bool res;
205 QFile file( fileName() ); 205 QFile file( fileName() );
206 if (!file.open( IO_WriteOnly ) ) { 206 if (!file.open( QIODevice::WriteOnly ) ) {
207 return false; 207 return false;
208 } 208 }
209 QTextStream ts( &file ); 209 Q3TextStream ts( &file );
210 QTextStream *stream = &ts; 210 Q3TextStream *stream = &ts;
211 stream->setEncoding( QTextStream::UnicodeUTF8 ); 211 stream->setEncoding( Q3TextStream::UnicodeUTF8 );
212 *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; 212 *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl;
213 *stream << " <Groups>" << endl; 213 *stream << " <Groups>" << endl;
214 *stream << " </Groups>" << endl; 214 *stream << " </Groups>" << endl;
215 *stream << " <Contacts> " << endl; 215 *stream << " <Contacts> " << endl;
216 // for all entries 216 // for all entries
217 KABC::Addressee ab; 217 KABC::Addressee ab;
218 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 218 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
219 KABC::Addressee addressee = (*it); 219 KABC::Addressee addressee = (*it);
220 res = mConverter->addresseeToQtopia( addressee, stream ); 220 res = mConverter->addresseeToQtopia( addressee, stream );
221 if (!res == true) 221 if (!res == true)
222 { 222 {
223 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 223 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
224 } 224 }
225 } 225 }
226 *stream << "</Contacts>" << endl; 226 *stream << "</Contacts>" << endl;
227 *stream << "</AddressBook>" << endl; 227 *stream << "</AddressBook>" << endl;
228 file.close(); 228 file.close();
229#ifdef _USE_DIRWATCH_ 229#ifdef _USE_DIRWATCH_
230 mDirWatch.startScan(); 230 mDirWatch.startScan();
231#endif 231#endif
232 delete ticket; 232 delete ticket;
233 unlock( fileName() ); 233 unlock( fileName() );
234 return true; 234 return true;
235} 235}
@@ -239,49 +239,49 @@ bool ResourceQtopia::lock( const QString &lockfileName )
239 //disabled 239 //disabled
240 return true; 240 return true;
241 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 241 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
242 QString fn = lockfileName; 242 QString fn = lockfileName;
243 243
244 KURL url(fn); 244 KURL url(fn);
245 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 245 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
246 246
247 if (QFile::exists( lockName )) 247 if (QFile::exists( lockName ))
248 { 248 {
249 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 249 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
250 return false; 250 return false;
251 } 251 }
252 252
253 QString lockUniqueName; 253 QString lockUniqueName;
254 lockUniqueName = fn + KApplication::randomString( 8 ); 254 lockUniqueName = fn + KApplication::randomString( 8 );
255 255
256 url = lockUniqueName; 256 url = lockUniqueName;
257//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 257//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
258 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 258 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
259 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 259 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
260 260
261 // Create unique file 261 // Create unique file
262 QFile file( mLockUniqueName ); 262 QFile file( mLockUniqueName );
263 file.open( IO_WriteOnly ); 263 file.open( QIODevice::WriteOnly );
264 file.close(); 264 file.close();
265 265
266 // Create lock file 266 // Create lock file
267 int result = 0; 267 int result = 0;
268#ifndef _WIN32_ 268#ifndef _WIN32_
269 result = ::link( QFile::encodeName( mLockUniqueName ), 269 result = ::link( QFile::encodeName( mLockUniqueName ),
270 QFile::encodeName( lockName ) ); 270 QFile::encodeName( lockName ) );
271#endif 271#endif
272 if ( result == 0 ) { 272 if ( result == 0 ) {
273 addressBook()->emitAddressBookLocked(); 273 addressBook()->emitAddressBookLocked();
274 return true; 274 return true;
275 } 275 }
276 276
277 // TODO: check stat 277 // TODO: check stat
278 278
279 return false; 279 return false;
280} 280}
281 281
282void ResourceQtopia::unlock( const QString &fileName ) 282void ResourceQtopia::unlock( const QString &fileName )
283{ 283{
284 //disabled 284 //disabled
285 return; 285 return;
286 qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); 286 qDebug("ResourceQtopia::unlock() %s", fileName.latin1());
287 287