summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
Unidiff
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 242e0c6..5565580 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -110,210 +110,210 @@ Ticket *ResourceQtopia::requestSaveTicket()
110 110
111 if ( !lock( fileName() ) ) { 111 if ( !lock( fileName() ) ) {
112 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 112 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
113 << fileName() << "'" << endl; 113 << fileName() << "'" << endl;
114 return 0; 114 return 0;
115 } 115 }
116 return createTicket( this ); 116 return createTicket( this );
117} 117}
118 118
119 119
120bool ResourceQtopia::doOpen() 120bool ResourceQtopia::doOpen()
121{ 121{
122 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); 122 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
123 123
124 mAccess = new AddressBookAccess(); 124 mAccess = new AddressBookAccess();
125 125
126 if ( !mAccess ) { 126 if ( !mAccess ) {
127 qDebug("Unable to load file() %s", fileName().latin1()); 127 qDebug("Unable to load file() %s", fileName().latin1());
128 return false; 128 return false;
129 } 129 }
130 130
131 131
132 if (mConverter == 0) 132 if (mConverter == 0)
133 { 133 {
134 mConverter = new QtopiaConverter(); 134 mConverter = new QtopiaConverter();
135 bool res = mConverter->init(); 135 bool res = mConverter->init();
136 if ( !res ) 136 if ( !res )
137 { 137 {
138 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 138 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
139 qDebug(msg); 139 qDebug(msg);
140 delete mAccess; 140 delete mAccess;
141 mAccess = 0; 141 mAccess = 0;
142 return false; 142 return false;
143 } 143 }
144 } 144 }
145 145
146 return true; 146 return true;
147} 147}
148 148
149void ResourceQtopia::doClose() 149void ResourceQtopia::doClose()
150{ 150{
151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
152 152
153 if(mAccess) 153 if(mAccess)
154 { 154 {
155 delete mAccess; 155 delete mAccess;
156 mAccess = 0; 156 mAccess = 0;
157 } 157 }
158 // it seems so, that deletion of access deletes backend as well 158 // it seems so, that deletion of access deletes backend as well
159 //delete backend; 159 //delete backend;
160 160
161 return; 161 return;
162} 162}
163 163
164bool ResourceQtopia::load() 164bool ResourceQtopia::load()
165{ 165{
166 qDebug("ResourceQtopia::load: %s", fileName().latin1()); 166 qDebug("ResourceQtopia::load: %s", fileName().latin1());
167 167
168 AddressBookIterator it(*mAccess); 168 AddressBookIterator it(*mAccess);
169 const PimContact* contact; 169 const PimContact* contact;
170 bool res; 170 bool res;
171 171
172 for (contact=it.toFirst(); it.current(); ++it) 172 for (contact=it.toFirst(); it.current(); ++it)
173 { 173 {
174 contact = it.current(); 174 contact = it.current();
175 175
176 KABC::Addressee addressee; 176 KABC::Addressee addressee;
177 177
178 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 178 res = mConverter->qtopiaToAddressee( (*contact), addressee );
179 179
180 if ( !addressee.isEmpty() && res ) 180 if ( !addressee.isEmpty() && res )
181 { 181 {
182 addressee.setResource( this ); 182 addressee.setResource( this );
183 addressBook()->insertAddressee( addressee ); 183 addressBook()->insertAddressee( addressee );
184 } 184 }
185 } 185 }
186 186
187 return true; 187 return true;
188} 188}
189 189
190bool ResourceQtopia::save( Ticket *ticket ) 190bool ResourceQtopia::save( Ticket *ticket )
191{ 191{
192 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 192 qDebug("ResourceQtopia::save: %s", fileName().latin1());
193 193
194 194
195 KABC::AddressBook::Iterator it; 195 KABC::AddressBook::Iterator it;
196 bool res; 196 bool res;
197 197
198 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 198 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
199 PimContact c; 199 PimContact c;
200 KABC::Addressee addressee = (*it); 200 KABC::Addressee addressee = (*it);
201 201
202 res = mConverter->addresseeToQtopia( *it, c ); 202 res = mConverter->addresseeToQtopia( *it, c );
203 if (res == true) 203 if (res == true)
204 { 204 {
205 mAccess->addContact(c); 205 mAccess->addContact(c);
206// if (res == false) 206// if (res == false)
207// qDebug("Unable to append Contact %s", c.fullName().latin1()); 207// qDebug("Unable to append Contact %s", c.fullName().latin1());
208 } 208 }
209 else 209 else
210 { 210 {
211 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 211 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
212 } 212 }
213 } 213 }
214 214
215// mAccess->addressBookUpdated(); 215// mAccess->addressBookUpdated();
216 216
217 delete ticket; 217 delete ticket;
218 unlock( fileName() ); 218 unlock( fileName() );
219 219
220 return true; 220 return true;
221} 221}
222 222
223bool ResourceQtopia::lock( const QString &lockfileName ) 223bool ResourceQtopia::lock( const QString &lockfileName )
224{ 224{
225 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 225 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
226 226
227 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 227 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
228 228
229 QString fn = lockfileName; 229 QString fn = lockfileName;
230 230
231 KURL url(fn); 231 KURL url(fn);
232 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 232 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
233 233
234 kdDebug(5700) << "-- lock name: " << lockName << endl; 234 kdDebug(5700) << "-- lock name: " << lockName << endl;
235 235
236 if (QFile::exists( lockName )) 236 if (QFile::exists( lockName ))
237 { 237 {
238 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); 238 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
239 return false; 239 return false;
240 } 240 }
241 241
242 QString lockUniqueName; 242 QString lockUniqueName;
243 lockUniqueName = fn + KApplication::randomString( 8 ); 243 lockUniqueName = fn + KApplication::randomString( 8 );
244 244
245 url = lockUniqueName; 245 url = lockUniqueName;
246//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 246//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
247 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 247 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
248 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 248 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
249 249
250 // Create unique file 250 // Create unique file
251 QFile file( mLockUniqueName ); 251 QFile file( mLockUniqueName );
252 file.open( IO_WriteOnly ); 252 file.open( IO_WriteOnly );
253 file.close(); 253 file.close();
254 254
255 // Create lock file 255 // Create lock file
256 int result = 0; 256 int result = 0;
257#ifndef _WIN32_ 257#ifndef _WIN32_
258 result = ::link( QFile::encodeName( mLockUniqueName ), 258 result = ::link( QFile::encodeName( mLockUniqueName ),
259 QFile::encodeName( lockName ) ); 259 QFile::encodeName( lockName ) );
260#endif 260#endif
261 if ( result == 0 ) { 261 if ( result == 0 ) {
262 addressBook()->emitAddressBookLocked(); 262 addressBook()->emitAddressBookLocked();
263 return true; 263 return true;
264 } 264 }
265 265
266 // TODO: check stat 266 // TODO: check stat
267 267
268 return false; 268 return false;
269} 269}
270 270
271void ResourceQtopia::unlock( const QString &fileName ) 271void ResourceQtopia::unlock( const QString &fileName )
272{ 272{
273 qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); 273 qDebug("ResourceQtopia::unlock() %s", fileName.latin1());
274 274
275 QString fn = fileName; 275 QString fn = fileName;
276 KURL url(fn); 276 KURL url(fn);
277 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 277 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
278 278
279 QFile::remove( lockName ); 279 QFile::remove( lockName );
280 QFile::remove( mLockUniqueName ); 280 QFile::remove( mLockUniqueName );
281 addressBook()->emitAddressBookUnlocked(); 281 addressBook()->emitAddressBookUnlocked();
282} 282}
283 283
284void ResourceQtopia::setFileName( const QString &newFileName ) 284void ResourceQtopia::setFileName( const QString &newFileName )
285{ 285{
286 mDirWatch.stopScan(); 286 mDirWatch.stopScan();
287 mDirWatch.removeFile( fileName() ); 287 mDirWatch.removeFile( fileName() );
288 288
289 Resource::setFileName( newFileName ); 289 Resource::setFileName( newFileName );
290 290
291 mDirWatch.addFile( fileName() ); 291 mDirWatch.addFile( fileName() );
292 mDirWatch.startScan(); 292 mDirWatch.startScan();
293} 293}
294 294
295 295
296void ResourceQtopia::fileChanged() 296void ResourceQtopia::fileChanged()
297{ 297{
298 // There is a small theoretical chance that KDirWatch calls us before 298 // There is a small theoretical chance that KDirWatch calls us before
299 // we are fully constructed 299 // we are fully constructed
300 if (!addressBook()) 300 if (!addressBook())
301 return; 301 return;
302 302
303 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 303 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
304 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 304 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
305 load(); 305 load();
306 addressBook()->emitAddressBookChanged(); 306 addressBook()->emitAddressBookChanged();
307 } 307 }
308} 308}
309 309
310void ResourceQtopia::removeAddressee( const Addressee &addr ) 310void ResourceQtopia::removeAddressee( const Addressee &addr )
311{ 311{
312} 312}
313 313
314void ResourceQtopia::cleanUp() 314void ResourceQtopia::cleanUp()
315{ 315{
316 unlock( fileName() ); 316 unlock( fileName() );
317} 317}
318 318
319//US #include "resourceqtopia.moc" 319//US #include "resourceqtopia.moc"