-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 16 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopieconfig.cpp | 11 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopieconfig.h | 3 |
3 files changed, 16 insertions, 14 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index 3b2a6b7..a7d271f 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -1,395 +1,405 @@ | |||
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 | #include <opie/ocontactaccessbackend_xml.h> |
50 | 50 | ||
51 | #include "resource.h" | 51 | #include "resource.h" |
52 | #include "resourceopieconfig.h" | 52 | #include "resourceopieconfig.h" |
53 | #include "stdaddressbook.h" | 53 | #include "stdaddressbook.h" |
54 | 54 | ||
55 | #include "opieconverter.h" | 55 | #include "opieconverter.h" |
56 | 56 | ||
57 | #include "resourceopie.h" | 57 | #include "resourceopie.h" |
58 | 58 | ||
59 | using namespace KABC; | 59 | using namespace KABC; |
60 | extern "C" | 60 | extern "C" |
61 | { | 61 | { |
62 | void *init_microkabc_opie() | 62 | void *init_microkabc_opie() |
63 | { | 63 | { |
64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); | 64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | ResourceOpie::ResourceOpie( const KConfig *config ) | 68 | ResourceOpie::ResourceOpie( const KConfig *config ) |
69 | : Resource( config ), mConverter (0) | 69 | : Resource( config ), mConverter (0) |
70 | { | 70 | { |
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
72 | 72 | ||
73 | KConfig *cfg = (KConfig *)config; | 73 | KConfig *cfg = (KConfig *)config; |
74 | if ( cfg ) { | 74 | if ( cfg ) { |
75 | fileName = cfg->readEntry( "FileName", fileName ); | 75 | fileName = cfg->readEntry( "FileName", fileName ); |
76 | 76 | ||
77 | } | 77 | } |
78 | 78 | ||
79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | 79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); |
80 | 80 | ||
81 | init( fileName ); | 81 | init( fileName ); |
82 | } | 82 | } |
83 | 83 | ||
84 | ResourceOpie::ResourceOpie( const QString &fileName ) | 84 | ResourceOpie::ResourceOpie( const QString &fileName ) |
85 | : Resource( 0 ) | 85 | : Resource( 0 ) |
86 | { | 86 | { |
87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | 87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); |
88 | init( fileName ); | 88 | init( fileName ); |
89 | } | 89 | } |
90 | 90 | ||
91 | void ResourceOpie::init( const QString &fileName ) | 91 | void ResourceOpie::init( const QString &fileName ) |
92 | { | 92 | { |
93 | 93 | ||
94 | /*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 |
95 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 95 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
96 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 96 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
97 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 97 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
98 | */ | 98 | */ |
99 | //US opie addressbook is always readonly | 99 | //US opie addressbook is always readonly |
100 | setReadOnly( true ); | 100 | //US setReadOnly( true ); |
101 | 101 | ||
102 | setFileName( fileName ); | 102 | setFileName( fileName ); |
103 | 103 | ||
104 | } | 104 | } |
105 | 105 | ||
106 | ResourceOpie::~ResourceOpie() | 106 | ResourceOpie::~ResourceOpie() |
107 | { | 107 | { |
108 | if (mConverter != 0) | 108 | if (mConverter != 0) |
109 | delete mConverter; | 109 | delete mConverter; |
110 | } | 110 | } |
111 | 111 | ||
112 | void ResourceOpie::writeConfig( KConfig *config ) | 112 | void ResourceOpie::writeConfig( KConfig *config ) |
113 | { | 113 | { |
114 | //US opie addressbook is always readonly | 114 | //US opie addressbook is always readonly |
115 | setReadOnly( true ); | 115 | //US setReadOnly( true ); |
116 | 116 | ||
117 | Resource::writeConfig( config ); | 117 | Resource::writeConfig( config ); |
118 | 118 | ||
119 | config->writeEntry( "FileName", mFileName ); | 119 | config->writeEntry( "FileName", mFileName ); |
120 | 120 | ||
121 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 121 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | Ticket *ResourceOpie::requestSaveTicket() | 125 | Ticket *ResourceOpie::requestSaveTicket() |
126 | { | 126 | { |
127 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 127 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
128 | 128 | ||
129 | if ( !addressBook() ) return 0; | 129 | if ( !addressBook() ) return 0; |
130 | 130 | ||
131 | if ( !lock( mFileName ) ) { | 131 | if ( !lock( mFileName ) ) { |
132 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | 132 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" |
133 | << mFileName << "'" << endl; | 133 | << mFileName << "'" << endl; |
134 | return 0; | 134 | return 0; |
135 | } | 135 | } |
136 | return createTicket( this ); | 136 | return createTicket( this ); |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | bool ResourceOpie::doOpen() | 140 | bool ResourceOpie::doOpen() |
141 | { | 141 | { |
142 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); | 142 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); |
143 | /*US | 143 | /*US |
144 | QFile file( mFileName ); | 144 | QFile file( mFileName ); |
145 | 145 | ||
146 | if ( !file.exists() ) { | 146 | if ( !file.exists() ) { |
147 | // try to create the file | 147 | // try to create the file |
148 | bool ok = file.open( IO_WriteOnly ); | 148 | bool ok = file.open( IO_WriteOnly ); |
149 | if ( ok ) | 149 | if ( ok ) |
150 | file.close(); | 150 | file.close(); |
151 | 151 | ||
152 | return ok; | 152 | return ok; |
153 | } else { | 153 | } else { |
154 | if ( !file.open( IO_ReadWrite ) ) | 154 | if ( !file.open( IO_ReadWrite ) ) |
155 | return false; | 155 | return false; |
156 | 156 | ||
157 | if ( file.size() == 0 ) { | 157 | if ( file.size() == 0 ) { |
158 | file.close(); | 158 | file.close(); |
159 | return true; | 159 | return true; |
160 | } | 160 | } |
161 | 161 | ||
162 | //US bool ok = mFormat->checkFormat( &file ); | 162 | //US bool ok = mFormat->checkFormat( &file ); |
163 | bool ok = true; | 163 | bool ok = true; |
164 | 164 | ||
165 | file.close(); | 165 | file.close(); |
166 | 166 | ||
167 | return ok; | 167 | return ok; |
168 | } | 168 | } |
169 | */ | 169 | */ |
170 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); | 170 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); |
171 | return true; | 171 | return true; |
172 | } | 172 | } |
173 | 173 | ||
174 | void ResourceOpie::doClose() | 174 | void ResourceOpie::doClose() |
175 | { | 175 | { |
176 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); | 176 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); |
177 | } | 177 | } |
178 | 178 | ||
179 | bool ResourceOpie::load() | 179 | bool ResourceOpie::load() |
180 | { | 180 | { |
181 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); | 181 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); |
182 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; | 182 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; |
183 | 183 | ||
184 | qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); | 184 | qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); |
185 | 185 | ||
186 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); | 186 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); |
187 | OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); | 187 | OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); |
188 | 188 | ||
189 | if ( !access ) { | 189 | if ( !access ) { |
190 | qDebug("Unable to load file() %s", mFileName.latin1()); | 190 | qDebug("Unable to load file() %s", mFileName.latin1()); |
191 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | 191 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); |
192 | return false; | 192 | return false; |
193 | } | 193 | } |
194 | 194 | ||
195 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | 195 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available |
196 | 196 | ||
197 | bool res = false; | ||
197 | if (mConverter == 0) | 198 | if (mConverter == 0) |
199 | { | ||
198 | mConverter = new OpieConverter(); | 200 | mConverter = new OpieConverter(); |
201 | res = mConverter->init(); | ||
202 | if ( !res ) | ||
203 | { | ||
204 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); | ||
205 | addressBook()->error( i18n( "Unable to initialize opie converter. Most likely a problem with the category file" ) ); | ||
206 | delete access; | ||
207 | return false; | ||
208 | } | ||
209 | } | ||
199 | 210 | ||
200 | 211 | ||
201 | OContactAccess::List::Iterator it; | 212 | OContactAccess::List::Iterator it; |
202 | OContactAccess::List allList = access->allRecords(); | 213 | OContactAccess::List allList = access->allRecords(); |
203 | bool res = false; | ||
204 | for ( it = allList.begin(); it != allList.end(); ++it ) | 214 | for ( it = allList.begin(); it != allList.end(); ++it ) |
205 | { | 215 | { |
206 | OContact c = (*it); | 216 | OContact c = (*it); |
207 | 217 | ||
208 | KABC::Addressee addressee; | 218 | KABC::Addressee addressee; |
209 | 219 | ||
210 | res = mConverter->opieToAddressee( c, addressee ); | 220 | res = mConverter->opieToAddressee( c, addressee ); |
211 | 221 | ||
212 | if ( !addressee.isEmpty() && res ) | 222 | if ( !addressee.isEmpty() && res ) |
213 | { | 223 | { |
214 | addressee.setResource( this ); | 224 | addressee.setResource( this ); |
215 | addressBook()->insertAddressee( addressee ); | 225 | addressBook()->insertAddressee( addressee ); |
216 | } | 226 | } |
217 | 227 | ||
218 | // qDebug("found %s", c.fullName().latin1()); | 228 | // qDebug("found %s", c.fullName().latin1()); |
219 | } | 229 | } |
220 | 230 | ||
221 | delete access; | 231 | delete access; |
222 | // it seems so, that deletion of access deletes backend as well | 232 | // it seems so, that deletion of access deletes backend as well |
223 | //delete backend; | 233 | //delete backend; |
224 | 234 | ||
225 | return true; | 235 | return true; |
226 | } | 236 | } |
227 | 237 | ||
228 | bool ResourceOpie::save( Ticket *ticket ) | 238 | bool ResourceOpie::save( Ticket *ticket ) |
229 | { | 239 | { |
230 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); | 240 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); |
231 | /*US | 241 | /*US |
232 | 242 | ||
233 | qDebug("ResourceOpie::save %s", mFileName.latin1()); | 243 | qDebug("ResourceOpie::save %s", mFileName.latin1()); |
234 | kdDebug(5700) << "ResourceOpie::save()" << endl; | 244 | kdDebug(5700) << "ResourceOpie::save()" << endl; |
235 | 245 | ||
236 | // create backup file | 246 | // create backup file |
237 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 247 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
238 | */ | 248 | */ |
239 | /*US we use a simpler method to create a backupfile | 249 | /*US we use a simpler method to create a backupfile |
240 | 250 | ||
241 | (void) KSaveFile::backupFile( mFileName, QString::null | 251 | (void) KSaveFile::backupFile( mFileName, QString::null |
242 | ,extension ); | 252 | ,extension ); |
243 | 253 | ||
244 | KSaveFile saveFile( mFileName ); | 254 | KSaveFile saveFile( mFileName ); |
245 | bool ok = false; | 255 | bool ok = false; |
246 | if ( saveFile.status() == 0 && saveFile.file() ) | 256 | if ( saveFile.status() == 0 && saveFile.file() ) |
247 | { | 257 | { |
248 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 258 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
249 | ok = saveFile.close(); | 259 | ok = saveFile.close(); |
250 | } | 260 | } |
251 | */ | 261 | */ |
252 | /*US | 262 | /*US |
253 | //US ToDo: write backupfile | 263 | //US ToDo: write backupfile |
254 | QFile info; | 264 | QFile info; |
255 | info.setName( mFileName ); | 265 | info.setName( mFileName ); |
256 | bool ok = info.open( IO_WriteOnly ); | 266 | bool ok = info.open( IO_WriteOnly ); |
257 | if ( ok ) { | 267 | if ( ok ) { |
258 | //US mFormat->saveAll( addressBook(), this, &info ); | 268 | //US mFormat->saveAll( addressBook(), this, &info ); |
259 | 269 | ||
260 | info.close(); | 270 | info.close(); |
261 | ok = true; | 271 | ok = true; |
262 | } | 272 | } |
263 | else { | 273 | else { |
264 | 274 | ||
265 | } | 275 | } |
266 | 276 | ||
267 | if ( !ok ) | 277 | if ( !ok ) |
268 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 278 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
269 | 279 | ||
270 | delete ticket; | 280 | delete ticket; |
271 | unlock( mFileName ); | 281 | unlock( mFileName ); |
272 | 282 | ||
273 | return ok; | 283 | return ok; |
274 | 284 | ||
275 | qDebug("ResourceOpie::save has to be changed"); | 285 | qDebug("ResourceOpie::save has to be changed"); |
276 | */ | 286 | */ |
277 | return true; | 287 | return true; |
278 | 288 | ||
279 | } | 289 | } |
280 | 290 | ||
281 | bool ResourceOpie::lock( const QString &fileName ) | 291 | bool ResourceOpie::lock( const QString &fileName ) |
282 | { | 292 | { |
283 | qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); | 293 | qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); |
284 | 294 | ||
285 | /*US | 295 | /*US |
286 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); | 296 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); |
287 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | 297 | kdDebug(5700) << "ResourceOpie::lock()" << endl; |
288 | 298 | ||
289 | QString fn = fileName; | 299 | QString fn = fileName; |
290 | 300 | ||
291 | //US change the implementation how the lockfilename is getting created | 301 | //US change the implementation how the lockfilename is getting created |
292 | //US fn.replace( QRegExp("/"), "_" ); | 302 | //US fn.replace( QRegExp("/"), "_" ); |
293 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 303 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
294 | 304 | ||
295 | KURL url(fn); | 305 | KURL url(fn); |
296 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 306 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
297 | 307 | ||
298 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 308 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
299 | 309 | ||
300 | if (QFile::exists( lockName )) return false; | 310 | if (QFile::exists( lockName )) return false; |
301 | 311 | ||
302 | QString lockUniqueName; | 312 | QString lockUniqueName; |
303 | lockUniqueName = fn + KApplication::randomString( 8 ); | 313 | lockUniqueName = fn + KApplication::randomString( 8 ); |
304 | 314 | ||
305 | url = lockUniqueName; | 315 | url = lockUniqueName; |
306 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 316 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
307 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 317 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
308 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 318 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
309 | 319 | ||
310 | // Create unique file | 320 | // Create unique file |
311 | QFile file( mLockUniqueName ); | 321 | QFile file( mLockUniqueName ); |
312 | file.open( IO_WriteOnly ); | 322 | file.open( IO_WriteOnly ); |
313 | file.close(); | 323 | file.close(); |
314 | 324 | ||
315 | // Create lock file | 325 | // Create lock file |
316 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 326 | int result = ::link( QFile::encodeName( mLockUniqueName ), |
317 | QFile::encodeName( lockName ) ); | 327 | QFile::encodeName( lockName ) ); |
318 | 328 | ||
319 | if ( result == 0 ) { | 329 | if ( result == 0 ) { |
320 | addressBook()->emitAddressBookLocked(); | 330 | addressBook()->emitAddressBookLocked(); |
321 | return true; | 331 | return true; |
322 | } | 332 | } |
323 | 333 | ||
324 | // TODO: check stat | 334 | // TODO: check stat |
325 | 335 | ||
326 | return false; | 336 | return false; |
327 | */ | 337 | */ |
328 | 338 | ||
329 | return true; | 339 | return true; |
330 | } | 340 | } |
331 | 341 | ||
332 | void ResourceOpie::unlock( const QString &fileName ) | 342 | void ResourceOpie::unlock( const QString &fileName ) |
333 | { | 343 | { |
334 | qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1()); | 344 | qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1()); |
335 | /*US | 345 | /*US |
336 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | 346 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); |
337 | 347 | ||
338 | QString fn = fileName; | 348 | QString fn = fileName; |
339 | //US change the implementation how the lockfilename is getting created | 349 | //US change the implementation how the lockfilename is getting created |
340 | //US fn.replace( QRegExp( "/" ), "_" ); | 350 | //US fn.replace( QRegExp( "/" ), "_" ); |
341 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 351 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
342 | //US QString lockName = fn + ".lock"; | 352 | //US QString lockName = fn + ".lock"; |
343 | KURL url(fn); | 353 | KURL url(fn); |
344 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 354 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
345 | 355 | ||
346 | QFile::remove( lockName ); | 356 | QFile::remove( lockName ); |
347 | QFile::remove( mLockUniqueName ); | 357 | QFile::remove( mLockUniqueName ); |
348 | addressBook()->emitAddressBookUnlocked(); | 358 | addressBook()->emitAddressBookUnlocked(); |
349 | */ | 359 | */ |
350 | } | 360 | } |
351 | 361 | ||
352 | void ResourceOpie::setFileName( const QString &fileName ) | 362 | void ResourceOpie::setFileName( const QString &fileName ) |
353 | { | 363 | { |
354 | /*US ToDo: no synchronization so far. Has to be changed in the future | 364 | /*US ToDo: no synchronization so far. Has to be changed in the future |
355 | mDirWatch.stopScan(); | 365 | mDirWatch.stopScan(); |
356 | mDirWatch.removeFile( mFileName ); | 366 | mDirWatch.removeFile( mFileName ); |
357 | */ | 367 | */ |
358 | mFileName = fileName; | 368 | mFileName = fileName; |
359 | 369 | ||
360 | 370 | ||
361 | /*US ToDo: no synchronization so far. Has to be changed in the future | 371 | /*US ToDo: no synchronization so far. Has to be changed in the future |
362 | mDirWatch.addFile( mFileName ); | 372 | mDirWatch.addFile( mFileName ); |
363 | mDirWatch.startScan(); | 373 | mDirWatch.startScan(); |
364 | */ | 374 | */ |
365 | //US simulate KDirWatch event | 375 | //US simulate KDirWatch event |
366 | fileChanged(); | 376 | fileChanged(); |
367 | } | 377 | } |
368 | 378 | ||
369 | QString ResourceOpie::fileName() const | 379 | QString ResourceOpie::fileName() const |
370 | { | 380 | { |
371 | return mFileName; | 381 | return mFileName; |
372 | } | 382 | } |
373 | 383 | ||
374 | void ResourceOpie::fileChanged() | 384 | void ResourceOpie::fileChanged() |
375 | { | 385 | { |
376 | // There is a small theoretical chance that KDirWatch calls us before | 386 | // There is a small theoretical chance that KDirWatch calls us before |
377 | // we are fully constructed | 387 | // we are fully constructed |
378 | if (!addressBook()) | 388 | if (!addressBook()) |
379 | return; | 389 | return; |
380 | load(); | 390 | load(); |
381 | addressBook()->emitAddressBookChanged(); | 391 | addressBook()->emitAddressBookChanged(); |
382 | } | 392 | } |
383 | 393 | ||
384 | void ResourceOpie::removeAddressee( const Addressee &addr ) | 394 | void ResourceOpie::removeAddressee( const Addressee &addr ) |
385 | { | 395 | { |
386 | /*US | 396 | /*US |
387 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 397 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
388 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 398 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
389 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 399 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
390 | */ | 400 | */ |
391 | } | 401 | } |
392 | 402 | ||
393 | void ResourceOpie::cleanUp() | 403 | void ResourceOpie::cleanUp() |
394 | { | 404 | { |
395 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); | 405 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); |
diff --git a/kabc/plugins/opie/resourceopieconfig.cpp b/kabc/plugins/opie/resourceopieconfig.cpp index f4cc4f9..eef9cc9 100644 --- a/kabc/plugins/opie/resourceopieconfig.cpp +++ b/kabc/plugins/opie/resourceopieconfig.cpp | |||
@@ -1,112 +1,107 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 <qlabel.h> | 28 | #include <qlabel.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | #include <kstandarddirs.h> | 33 | #include <kstandarddirs.h> |
34 | #include <kdialog.h> | 34 | #include <kdialog.h> |
35 | 35 | ||
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | 37 | ||
38 | #include <qdir.h> | 38 | #include <qdir.h> |
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include "resourceopie.h" | 40 | #include "resourceopie.h" |
41 | //US #include <qpe/qpeapplication.h> | 41 | //US #include <qpe/qpeapplication.h> |
42 | 42 | ||
43 | //US #include "stdaddressbook.h" | 43 | //US #include "stdaddressbook.h" |
44 | 44 | ||
45 | #include "resourceopieconfig.h" | 45 | #include "resourceopieconfig.h" |
46 | 46 | ||
47 | using namespace KABC; | 47 | using namespace KABC; |
48 | 48 | ||
49 | ResourceOpieConfig::ResourceOpieConfig( QWidget* parent, const char* name ) | 49 | ResourceOpieConfig::ResourceOpieConfig( QWidget* parent, const char* name ) |
50 | : ConfigWidget( parent, name ) | 50 | : ConfigWidget( parent, name ) |
51 | { | 51 | { |
52 | //qDebug("ResourceFileConfig::ResourceFileConfig"); | 52 | //qDebug("ResourceFileConfig::ResourceFileConfig"); |
53 | 53 | ||
54 | QGridLayout *mainLayout = new QGridLayout( this, 1, 2, 0, | 54 | QGridLayout *mainLayout = new QGridLayout( this, 1, 2, 0, |
55 | KDialog::spacingHint() ); | 55 | KDialog::spacingHint() ); |
56 | 56 | ||
57 | QLabel *label = new QLabel( i18n( "Location:" ), this ); | 57 | QLabel *label = new QLabel( i18n( "Location:" ), this ); |
58 | mFileNameEdit = new KURLRequester( this ); | 58 | mFileNameEdit = new KURLRequester( this ); |
59 | 59 | ||
60 | connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), | 60 | connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), |
61 | SLOT( checkFilePermissions( const QString & ) ) ); | 61 | SLOT( checkFilePermissions( const QString & ) ) ); |
62 | 62 | ||
63 | mainLayout->addWidget( label, 0, 0 ); | 63 | mainLayout->addWidget( label, 0, 0 ); |
64 | mainLayout->addWidget( mFileNameEdit, 0, 1 ); | 64 | mainLayout->addWidget( mFileNameEdit, 0, 1 ); |
65 | |||
66 | //US mInEditMode = false; | ||
67 | } | ||
68 | /*US | ||
69 | void ResourceOpieConfig::setEditMode( bool value ) | ||
70 | { | ||
71 | mInEditMode = value; | ||
72 | } | 65 | } |
73 | */ | ||
74 | 66 | ||
75 | void ResourceOpieConfig::loadSettings( KRES::Resource *res ) | 67 | void ResourceOpieConfig::loadSettings( KRES::Resource *res ) |
76 | { | 68 | { |
77 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | 69 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); |
78 | ResourceOpie *resource = (ResourceOpie*)( res ); | 70 | ResourceOpie *resource = (ResourceOpie*)( res ); |
79 | 71 | ||
80 | if ( !resource ) { | 72 | if ( !resource ) { |
81 | kdDebug(5700) << "ResourceOpieConfig::loadSettings(): cast failed" << endl; | 73 | kdDebug(5700) << "ResourceOpieConfig::loadSettings(): cast failed" << endl; |
82 | return; | 74 | return; |
83 | } | 75 | } |
84 | 76 | ||
85 | mFileNameEdit->setURL( resource->fileName() ); | 77 | mFileNameEdit->setURL( resource->fileName() ); |
86 | if ( mFileNameEdit->url().isEmpty() ) | 78 | if ( mFileNameEdit->url().isEmpty() ) |
87 | mFileNameEdit->setURL( QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml" ); | 79 | mFileNameEdit->setURL( QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml" ); |
80 | |||
81 | //US Opie resources are ReadOnly by definition | ||
82 | emit setPersistentReadOnly( true ); | ||
88 | } | 83 | } |
89 | 84 | ||
90 | void ResourceOpieConfig::saveSettings( KRES::Resource *res ) | 85 | void ResourceOpieConfig::saveSettings( KRES::Resource *res ) |
91 | { | 86 | { |
92 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | 87 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); |
93 | ResourceOpie *resource = (ResourceOpie*)( res ); | 88 | ResourceOpie *resource = (ResourceOpie*)( res ); |
94 | 89 | ||
95 | if ( !resource ) { | 90 | if ( !resource ) { |
96 | kdDebug(5700) << "ResourceOpieConfig::saveSettings(): cast failed" << endl; | 91 | kdDebug(5700) << "ResourceOpieConfig::saveSettings(): cast failed" << endl; |
97 | return; | 92 | return; |
98 | } | 93 | } |
99 | 94 | ||
100 | resource->setFileName( mFileNameEdit->url() ); | 95 | resource->setFileName( mFileNameEdit->url() ); |
101 | } | 96 | } |
102 | 97 | ||
103 | void ResourceOpieConfig::checkFilePermissions( const QString& fileName ) | 98 | void ResourceOpieConfig::checkFilePermissions( const QString& fileName ) |
104 | { | 99 | { |
105 | // If file exist but is not writeable... | 100 | // If file exist but is not writeable... |
106 | /*US | 101 | /*US |
107 | if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) | 102 | if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) |
108 | emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); | 103 | emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); |
109 | */ | 104 | */ |
110 | } | 105 | } |
111 | 106 | ||
112 | //US #include "resourceopieconfig.moc" | 107 | //US #include "resourceopieconfig.moc" |
diff --git a/kabc/plugins/opie/resourceopieconfig.h b/kabc/plugins/opie/resourceopieconfig.h index 533b7f4..8cc192c 100644 --- a/kabc/plugins/opie/resourceopieconfig.h +++ b/kabc/plugins/opie/resourceopieconfig.h | |||
@@ -1,61 +1,58 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef RESOURCEOPIECONFIG_H | 29 | #ifndef RESOURCEOPIECONFIG_H |
30 | #define RESOURCEOPIECONFIG_H | 30 | #define RESOURCEOPIECONFIG_H |
31 | 31 | ||
32 | #include <kurlrequester.h> | 32 | #include <kurlrequester.h> |
33 | 33 | ||
34 | #include <kresources/configwidget.h> | 34 | #include <kresources/configwidget.h> |
35 | 35 | ||
36 | namespace KABC { | 36 | namespace KABC { |
37 | 37 | ||
38 | class ResourceOpieConfig : public KRES::ConfigWidget | 38 | class ResourceOpieConfig : public KRES::ConfigWidget |
39 | { | 39 | { |
40 | Q_OBJECT | 40 | Q_OBJECT |
41 | 41 | ||
42 | public: | 42 | public: |
43 | ResourceOpieConfig( QWidget* parent = 0, const char* name = 0 ); | 43 | ResourceOpieConfig( QWidget* parent = 0, const char* name = 0 ); |
44 | 44 | ||
45 | //US void setEditMode( bool value ); | ||
46 | |||
47 | public slots: | 45 | public slots: |
48 | void loadSettings( KRES::Resource *resource ); | 46 | void loadSettings( KRES::Resource *resource ); |
49 | void saveSettings( KRES::Resource *resource ); | 47 | void saveSettings( KRES::Resource *resource ); |
50 | 48 | ||
51 | protected slots: | 49 | protected slots: |
52 | void checkFilePermissions( const QString& fileName ); | 50 | void checkFilePermissions( const QString& fileName ); |
53 | 51 | ||
54 | private: | 52 | private: |
55 | KURLRequester* mFileNameEdit; | 53 | KURLRequester* mFileNameEdit; |
56 | //US bool mInEditMode; | ||
57 | }; | 54 | }; |
58 | 55 | ||
59 | } | 56 | } |
60 | 57 | ||
61 | #endif | 58 | #endif |