author | zautrix <zautrix> | 2005-03-30 11:55:53 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-30 11:55:53 (UTC) |
commit | b5222dd7a607f78235b1ea39fea0f95a9c08ccd3 (patch) (unidiff) | |
tree | 4e4d334ae9d8805b7718c1610bd84af128fd8151 /kabc | |
parent | 597cad3a63e6c22855704bf8435db70e3c2b184f (diff) | |
download | kdepimpi-b5222dd7a607f78235b1ea39fea0f95a9c08ccd3.zip kdepimpi-b5222dd7a607f78235b1ea39fea0f95a9c08ccd3.tar.gz kdepimpi-b5222dd7a607f78235b1ea39fea0f95a9c08ccd3.tar.bz2 |
fixes
-rw-r--r-- | kabc/addresseeview.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 41 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.h | 2 |
3 files changed, 31 insertions, 14 deletions
diff --git a/kabc/addresseeview.cpp b/kabc/addresseeview.cpp index aa96210..9118c3d 100644 --- a/kabc/addresseeview.cpp +++ b/kabc/addresseeview.cpp | |||
@@ -170,257 +170,257 @@ void AddresseeView::setAddressee( const KABC::Addressee& mAddressee ) | |||
170 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) | 170 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) |
171 | .arg( type ) | 171 | .arg( type ) |
172 | .arg( name ) | 172 | .arg( name ) |
173 | .arg( *emailIt ) | 173 | .arg( *emailIt ) |
174 | .arg( *emailIt ); | 174 | .arg( *emailIt ); |
175 | } else { | 175 | } else { |
176 | dynamicPart += QString( | 176 | dynamicPart += QString( |
177 | "<tr><td align=\"right\"><b>%1</b></td>" | 177 | "<tr><td align=\"right\"><b>%1</b></td>" |
178 | "<td align=\"left\">%2</td></tr>" ) | 178 | "<td align=\"left\">%2</td></tr>" ) |
179 | .arg( type ) | 179 | .arg( type ) |
180 | .arg( *emailIt ); | 180 | .arg( *emailIt ); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | if ( !mAddressee.url().url().isEmpty() ) { | 184 | if ( !mAddressee.url().url().isEmpty() ) { |
185 | dynamicPart += QString( | 185 | dynamicPart += QString( |
186 | "<tr><td align=\"right\"><b>%1</b></td>" | 186 | "<tr><td align=\"right\"><b>%1</b></td>" |
187 | "<td align=\"left\">%2</td></tr>" ) | 187 | "<td align=\"left\">%2</td></tr>" ) |
188 | .arg( i18n( "Homepage" ) ) | 188 | .arg( i18n( "Homepage" ) ) |
189 | //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); | 189 | //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); |
190 | .arg( mAddressee.url().url() ); | 190 | .arg( mAddressee.url().url() ); |
191 | //qDebug("AddresseeView::setAddressee has to be verified."); | 191 | //qDebug("AddresseeView::setAddressee has to be verified."); |
192 | } | 192 | } |
193 | 193 | ||
194 | KABC::Address::List addresses = mAddressee.addresses(); | 194 | KABC::Address::List addresses = mAddressee.addresses(); |
195 | KABC::Address::List::ConstIterator addrIt; | 195 | KABC::Address::List::ConstIterator addrIt; |
196 | for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { | 196 | for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { |
197 | if ( true /*(*addrIt).label().isEmpty()*/ ) { | 197 | if ( true /*(*addrIt).label().isEmpty()*/ ) { |
198 | QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); | 198 | QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); |
199 | //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); | 199 | //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); |
200 | //qDebug("adresss %s ",formattedAddress.latin1() ); | 200 | //qDebug("adresss %s ",formattedAddress.latin1() ); |
201 | formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); | 201 | formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); |
202 | //qDebug("AddresseeView::setAddressee has to be verified."); | 202 | //qDebug("AddresseeView::setAddressee has to be verified."); |
203 | 203 | ||
204 | dynamicPart += QString( | 204 | dynamicPart += QString( |
205 | "<tr><td align=\"right\"><b>%1</b></td>" | 205 | "<tr><td align=\"right\"><b>%1</b></td>" |
206 | "<td align=\"left\">%2</td></tr>" ) | 206 | "<td align=\"left\">%2</td></tr>" ) |
207 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) | 207 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) |
208 | .arg( formattedAddress ); | 208 | .arg( formattedAddress ); |
209 | } else { | 209 | } else { |
210 | 210 | ||
211 | dynamicPart += QString( | 211 | dynamicPart += QString( |
212 | "<tr><td align=\"right\"><b>%1</b></td>" | 212 | "<tr><td align=\"right\"><b>%1</b></td>" |
213 | "<td align=\"left\">%2</td></tr>" ) | 213 | "<td align=\"left\">%2</td></tr>" ) |
214 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) | 214 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) |
215 | //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); | 215 | //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); |
216 | .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); | 216 | .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); |
217 | 217 | ||
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | QString notes; | 221 | QString notes; |
222 | if ( !mAddressee.note().isEmpty() ) { | 222 | if ( !mAddressee.note().isEmpty() ) { |
223 | notes = QString( | 223 | notes = QString( |
224 | "<tr>" | 224 | "<tr>" |
225 | "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label | 225 | "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label |
226 | "<td align=\"left\">%2</td>" // note | 226 | "<td align=\"left\">%2</td>" // note |
227 | "</tr>" ).arg( i18n( "Notes" ) ) | 227 | "</tr>" ).arg( i18n( "Notes" ) ) |
228 | //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); | 228 | //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); |
229 | .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); | 229 | .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); |
230 | //qDebug("AddresseeView::setAddressee has to be verified."); | 230 | //qDebug("AddresseeView::setAddressee has to be verified."); |
231 | } | 231 | } |
232 | 232 | ||
233 | QString aRole = ""; | 233 | QString aRole = ""; |
234 | QString aOrga = ""; | 234 | QString aOrga = ""; |
235 | if ( true /*!mAddressee.role().isEmpty()*/ ) { | 235 | if ( true /*!mAddressee.role().isEmpty()*/ ) { |
236 | aRole = "<tr>" | 236 | aRole = "<tr>" |
237 | "<td align=\"left\">" + mAddressee.role() + "</td>" | 237 | "<td align=\"left\">" + mAddressee.role() + "</td>" |
238 | "</tr>"; | 238 | "</tr>"; |
239 | } | 239 | } |
240 | if ( true /*!mAddressee.organization().isEmpty()*/ ) { | 240 | if ( true /*!mAddressee.organization().isEmpty()*/ ) { |
241 | aOrga = "<tr>" | 241 | aOrga = "<tr>" |
242 | "<td align=\"left\">" + mAddressee.organization() + "</td>" | 242 | "<td align=\"left\">" + mAddressee.organization() + "</td>" |
243 | "</tr>"; | 243 | "</tr>"; |
244 | } | 244 | } |
245 | mText = ""; | 245 | mText = ""; |
246 | QString picString = ""; | 246 | QString picString = ""; |
247 | KABC::Picture picture = mAddressee.photo(); | 247 | KABC::Picture picture = mAddressee.photo(); |
248 | bool picAvailintern = false; | 248 | bool picAvailintern = false; |
249 | bool picAvailUrl = false; | 249 | bool picAvailUrl = false; |
250 | if (! picture.undefined() ) { | 250 | if (! picture.undefined() ) { |
251 | picAvailintern = (picture.isIntern() && !picture.data().isNull()); | 251 | picAvailintern = (picture.isIntern() && !picture.data().isNull()); |
252 | picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); | 252 | picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); |
253 | } | 253 | } |
254 | if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { | 254 | if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { |
255 | picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; | 255 | picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; |
256 | if ( picAvailintern ) { | 256 | if ( picAvailintern ) { |
257 | QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); | 257 | QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); |
258 | } else { | 258 | } else { |
259 | if ( picAvailUrl ) { | 259 | if ( picAvailUrl ) { |
260 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); | 260 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); |
261 | } else { | 261 | } else { |
262 | if ( !mAddressee.custom( "KADDRESSBOOK", "X-Children" ).isEmpty() ) { | 262 | if ( !mAddressee.custom( "KADDRESSBOOK", "X-Children" ).isEmpty() ) { |
263 | static bool setDefaultImageChildren = false; | 263 | static bool setDefaultImageChildren = false; |
264 | if ( !setDefaultImageChildren ) { | 264 | if ( !setDefaultImageChildren ) { |
265 | QMimeSourceFactory::defaultFactory()->setPixmap( "familyIcon", KGlobal::iconLoader()->loadIcon( "ic_kids", KIcon::Desktop, 128 ) ); | 265 | QMimeSourceFactory::defaultFactory()->setPixmap( "familyIcon", KGlobal::iconLoader()->loadIcon( "ic_kids", KIcon::Desktop, 128 ) ); |
266 | setDefaultImageChildren = true; | 266 | setDefaultImageChildren = true; |
267 | } | 267 | } |
268 | picString = "<img src=\"familyIcon\" width=\"64\" height=\"64\">"; | 268 | picString = "<img src=\"familyIcon\" width=\"64\" height=\"64\">"; |
269 | 269 | ||
270 | } else if ( !mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ).isEmpty() ) { | 270 | } else if ( !mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ).isEmpty() ) { |
271 | static bool setDefaultImagepouses = false; | 271 | static bool setDefaultImagepouses = false; |
272 | if ( !setDefaultImagepouses ) { | 272 | if ( !setDefaultImagepouses ) { |
273 | QMimeSourceFactory::defaultFactory()->setPixmap( "SpousesIcon", KGlobal::iconLoader()->loadIcon( "ic_family", KIcon::Desktop, 128 ) ); | 273 | QMimeSourceFactory::defaultFactory()->setPixmap( "SpousesIcon", KGlobal::iconLoader()->loadIcon( "ic_family", KIcon::Desktop, 128 ) ); |
274 | setDefaultImagepouses = true; | 274 | setDefaultImagepouses = true; |
275 | } | 275 | } |
276 | picString = "<img src=\"SpousesIcon\" width=\"64\" height=\"64\">"; | 276 | picString = "<img src=\"SpousesIcon\" width=\"64\" height=\"64\">"; |
277 | } else { | 277 | } else { |
278 | QString gen = mAddressee.custom( "KADDRESSBOOK", "X-Gender" ); | 278 | QString gen = mAddressee.custom( "KADDRESSBOOK", "X-Gender" ); |
279 | if ( gen == "male" ) { | 279 | if ( gen == "male" ) { |
280 | static bool setDefaultImageMale = false; | 280 | static bool setDefaultImageMale = false; |
281 | if ( !setDefaultImageMale ) { | 281 | if ( !setDefaultImageMale ) { |
282 | QMimeSourceFactory::defaultFactory()->setPixmap( "MaleIcon", KGlobal::iconLoader()->loadIcon( "ic_male", KIcon::Desktop, 128 ) ); | 282 | QMimeSourceFactory::defaultFactory()->setPixmap( "MaleIcon", KGlobal::iconLoader()->loadIcon( "ic_male", KIcon::Desktop, 128 ) ); |
283 | setDefaultImageMale = true; | 283 | setDefaultImageMale = true; |
284 | } | 284 | } |
285 | picString = "<img src=\"MaleIcon\" width=\"64\" height=\"64\">"; | 285 | picString = "<img src=\"MaleIcon\" width=\"64\" height=\"64\">"; |
286 | 286 | ||
287 | } else if ( gen == "female" ) { | 287 | } else if ( gen == "female" ) { |
288 | static bool setDefaultImageFemale = false; | 288 | static bool setDefaultImageFemale = false; |
289 | if ( !setDefaultImageFemale ) { | 289 | if ( !setDefaultImageFemale ) { |
290 | QMimeSourceFactory::defaultFactory()->setPixmap( "FemaleIcon", KGlobal::iconLoader()->loadIcon( "ic_female", KIcon::Desktop, 128 ) ); | 290 | QMimeSourceFactory::defaultFactory()->setPixmap( "FemaleIcon", KGlobal::iconLoader()->loadIcon( "ic_female", KIcon::Desktop, 128 ) ); |
291 | setDefaultImageFemale = true; | 291 | setDefaultImageFemale = true; |
292 | } | 292 | } |
293 | picString = "<img src=\"FemaleIcon\" width=\"64\" height=\"64\">"; | 293 | picString = "<img src=\"FemaleIcon\" width=\"64\" height=\"64\">"; |
294 | 294 | ||
295 | } else { | 295 | } else { |
296 | static bool setDefaultImage = false; | 296 | static bool setDefaultImage = false; |
297 | if ( !setDefaultImage ) { | 297 | if ( !setDefaultImage ) { |
298 | qDebug("Setting default pixmap "); | 298 | //qDebug("Setting default pixmap "); |
299 | QMimeSourceFactory::defaultFactory()->setPixmap( "defaultIcon", KGlobal::iconLoader()->loadIcon( "ic_penguin", KIcon::Desktop, 128 ) ); | 299 | QMimeSourceFactory::defaultFactory()->setPixmap( "defaultIcon", KGlobal::iconLoader()->loadIcon( "ic_penguin", KIcon::Desktop, 128 ) ); |
300 | setDefaultImage = true; | 300 | setDefaultImage = true; |
301 | } | 301 | } |
302 | picString = "<img src=\"defaultIcon\" width=\"64\" height=\"64\">"; | 302 | picString = "<img src=\"defaultIcon\" width=\"64\" height=\"64\">"; |
303 | } | 303 | } |
304 | } | 304 | } |
305 | } | 305 | } |
306 | } | 306 | } |
307 | mText = QString::fromLatin1( | 307 | mText = QString::fromLatin1( |
308 | "<html>" | 308 | "<html>" |
309 | "<body text=\"%1\" bgcolor=\"%2\">" // text and background color | 309 | "<body text=\"%1\" bgcolor=\"%2\">" // text and background color |
310 | "<table>" | 310 | "<table>" |
311 | "<tr>" | 311 | "<tr>" |
312 | "<td rowspan=\"3\" align=\"right\" valign=\"top\">" | 312 | "<td rowspan=\"3\" align=\"right\" valign=\"top\">" |
313 | "%3" | 313 | "%3" |
314 | "</td>" | 314 | "</td>" |
315 | "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name | 315 | "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name |
316 | "</tr>" | 316 | "</tr>" |
317 | "%5" // role | 317 | "%5" // role |
318 | "%6" // organization | 318 | "%6" // organization |
319 | "<td colspan=\"2\"> </td>" | 319 | "<td colspan=\"2\"> </td>" |
320 | "%7" // dynamic part | 320 | "%7" // dynamic part |
321 | "%8" // notes | 321 | "%8" // notes |
322 | "</table>" | 322 | "</table>" |
323 | "</body>" | 323 | "</body>" |
324 | "</html>") | 324 | "</html>") |
325 | //US | 325 | //US |
326 | .arg( /*KGlobalSettings::textColor().name()*/ "black" ) | 326 | .arg( /*KGlobalSettings::textColor().name()*/ "black" ) |
327 | //US | 327 | //US |
328 | .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) | 328 | .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) |
329 | .arg( picString ) | 329 | .arg( picString ) |
330 | .arg( name ) | 330 | .arg( name ) |
331 | .arg( aRole ) | 331 | .arg( aRole ) |
332 | .arg( aOrga ) | 332 | .arg( aOrga ) |
333 | .arg( dynamicPart ) | 333 | .arg( dynamicPart ) |
334 | .arg( notes ); | 334 | .arg( notes ); |
335 | 335 | ||
336 | } else { // no picture! | 336 | } else { // no picture! |
337 | 337 | ||
338 | mText = "<table width=\"100%\">\n"; | 338 | mText = "<table width=\"100%\">\n"; |
339 | //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; | 339 | //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; |
340 | #ifdef DESKTOP_VERSION | 340 | #ifdef DESKTOP_VERSION |
341 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; | 341 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; |
342 | mText += "<font color=\"#FFFFFF\">" + name +"</font></h1>"; | 342 | mText += "<font color=\"#FFFFFF\">" + name +"</font></h1>"; |
343 | #else | 343 | #else |
344 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h3>"; | 344 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h3>"; |
345 | mText += "<font color=\"#FFFFFF\"> " + name +"</font></h3>"; | 345 | mText += "<font color=\"#FFFFFF\"> " + name +"</font></h3>"; |
346 | #endif | 346 | #endif |
347 | 347 | ||
348 | mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; | 348 | mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; |
349 | 349 | ||
350 | mText += "<table><td colspan=\"2\"> </td>"; | 350 | mText += "<table><td colspan=\"2\"> </td>"; |
351 | /* | 351 | /* |
352 | mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" | 352 | mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" |
353 | "<td align=\"left\"><b>%2</b></td></tr>" ) | 353 | "<td align=\"left\"><b>%2</b></td></tr>" ) |
354 | .arg( i18n(" ") ) | 354 | .arg( i18n(" ") ) |
355 | .arg( name ); | 355 | .arg( name ); |
356 | */ | 356 | */ |
357 | if ( ! mAddressee.role().isEmpty() ) | 357 | if ( ! mAddressee.role().isEmpty() ) |
358 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" | 358 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" |
359 | "<td align=\"left\">%2</td></tr>" ) | 359 | "<td align=\"left\">%2</td></tr>" ) |
360 | .arg( i18n(" ") ) | 360 | .arg( i18n(" ") ) |
361 | .arg( mAddressee.role()); | 361 | .arg( mAddressee.role()); |
362 | if ( ! mAddressee.organization().isEmpty() ) | 362 | if ( ! mAddressee.organization().isEmpty() ) |
363 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" | 363 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" |
364 | "<td align=\"left\">%2</td></tr>" ) | 364 | "<td align=\"left\">%2</td></tr>" ) |
365 | .arg( i18n(" ") ) | 365 | .arg( i18n(" ") ) |
366 | .arg( mAddressee.organization()); | 366 | .arg( mAddressee.organization()); |
367 | mText += dynamicPart; | 367 | mText += dynamicPart; |
368 | mText += notes; | 368 | mText += notes; |
369 | mText += "</table>"; | 369 | mText += "</table>"; |
370 | 370 | ||
371 | } | 371 | } |
372 | 372 | ||
373 | // at last display it... | 373 | // at last display it... |
374 | setText( mText ); | 374 | setText( mText ); |
375 | 375 | ||
376 | } | 376 | } |
377 | 377 | ||
378 | QString AddresseeView::getPhoneNumbers( KABC::PhoneNumber::List phones ,bool preferred ) | 378 | QString AddresseeView::getPhoneNumbers( KABC::PhoneNumber::List phones ,bool preferred ) |
379 | { | 379 | { |
380 | ExternalAppHandler* eah = ExternalAppHandler::instance(); | 380 | ExternalAppHandler* eah = ExternalAppHandler::instance(); |
381 | bool kphoneAvail = eah->isPhoneAppAvailable(); | 381 | bool kphoneAvail = eah->isPhoneAppAvailable(); |
382 | bool kfaxAvail = eah->isFaxAppAvailable(); | 382 | bool kfaxAvail = eah->isFaxAppAvailable(); |
383 | bool ksmsAvail = eah->isSMSAppAvailable(); | 383 | bool ksmsAvail = eah->isSMSAppAvailable(); |
384 | bool kpagerAvail = eah->isPagerAppAvailable(); | 384 | bool kpagerAvail = eah->isPagerAppAvailable(); |
385 | bool ksipAvail = eah->isSIPAppAvailable(); | 385 | bool ksipAvail = eah->isSIPAppAvailable(); |
386 | QString dynamicPart; | 386 | QString dynamicPart; |
387 | KABC::PhoneNumber::List::ConstIterator phoneIt; | 387 | KABC::PhoneNumber::List::ConstIterator phoneIt; |
388 | QString extension; | 388 | QString extension; |
389 | int phonetype; | 389 | int phonetype; |
390 | QString sms; | 390 | QString sms; |
391 | for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { | 391 | for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { |
392 | phonetype = (*phoneIt).type(); | 392 | phonetype = (*phoneIt).type(); |
393 | if ( ((phonetype & KABC::PhoneNumber::Pref) == 0 ) == preferred ) | 393 | if ( ((phonetype & KABC::PhoneNumber::Pref) == 0 ) == preferred ) |
394 | continue; | 394 | continue; |
395 | if (ksmsAvail && | 395 | if (ksmsAvail && |
396 | ( | 396 | ( |
397 | ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || | 397 | ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || |
398 | ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) | 398 | ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) |
399 | ) | 399 | ) |
400 | ) | 400 | ) |
401 | { | 401 | { |
402 | sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) | 402 | sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) |
403 | .arg( (*phoneIt).number() ); | 403 | .arg( (*phoneIt).number() ); |
404 | 404 | ||
405 | } | 405 | } |
406 | else | 406 | else |
407 | sms = ""; | 407 | sms = ""; |
408 | 408 | ||
409 | extension = QString::null; | 409 | extension = QString::null; |
410 | if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { | 410 | if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { |
411 | if (kfaxAvail) extension = "faxto:"; | 411 | if (kfaxAvail) extension = "faxto:"; |
412 | } | 412 | } |
413 | else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { | 413 | else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { |
414 | if (kpagerAvail) extension = "pagerto:"; | 414 | if (kpagerAvail) extension = "pagerto:"; |
415 | } | 415 | } |
416 | else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) { | 416 | else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) { |
417 | if (ksipAvail) extension = "sipto:"; | 417 | if (ksipAvail) extension = "sipto:"; |
418 | } | 418 | } |
419 | else if (kphoneAvail) { | 419 | else if (kphoneAvail) { |
420 | extension = "phoneto:"; | 420 | extension = "phoneto:"; |
421 | } | 421 | } |
422 | else | 422 | else |
423 | extension = QString::null; | 423 | extension = QString::null; |
424 | 424 | ||
425 | if ( !extension.isEmpty() ) { | 425 | if ( !extension.isEmpty() ) { |
426 | dynamicPart += QString( | 426 | dynamicPart += QString( |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index dc5932f..4ab7f02 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -1,404 +1,421 @@ | |||
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 | #ifndef _WIN32_ | 30 | #ifndef _WIN32_ |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qfileinfo.h> | 35 | #include <qfileinfo.h> |
36 | #include <qregexp.h> | 36 | #include <qregexp.h> |
37 | #include <qtimer.h> | 37 | #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 | #include "formatfactory.h" | 47 | #include "formatfactory.h" |
48 | 48 | ||
49 | #include "resource.h" | 49 | #include "resource.h" |
50 | #include "resourcefileconfig.h" | 50 | #include "resourcefileconfig.h" |
51 | #include "stdaddressbook.h" | 51 | #include "stdaddressbook.h" |
52 | #define NO_DIRWATCH | 52 | #define NO_DIRWATCH |
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | 54 | ||
55 | //#define ALLOW_LOCKING | 55 | //#define ALLOW_LOCKING |
56 | 56 | ||
57 | 57 | ||
58 | |||
59 | using namespace KABC; | 58 | using namespace KABC; |
60 | 59 | ||
61 | extern "C" | 60 | extern "C" |
62 | #ifdef _WIN32_ | 61 | #ifdef _WIN32_ |
63 | __declspec(dllexport) | 62 | __declspec(dllexport) |
64 | #else | 63 | #else |
65 | { | 64 | { |
66 | #endif | 65 | #endif |
67 | 66 | ||
68 | //US void *init_kabc_file() | 67 | //US void *init_kabc_file() |
69 | void *init_microkabc_file() | 68 | void *init_microkabc_file() |
70 | { | 69 | { |
71 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); | 70 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); |
72 | } | 71 | } |
73 | #ifndef _WIN32_ | 72 | #ifndef _WIN32_ |
74 | } | 73 | } |
75 | #endif | 74 | #endif |
76 | 75 | ||
77 | ResourceFile::ResourceFile( const KConfig *config ) | 76 | ResourceFile::ResourceFile( const KConfig *config ) |
78 | : Resource( config ) , mFormat( 0 ) | 77 | : Resource( config ) , mFormat( 0 ) |
79 | { | 78 | { |
80 | QString fileName, formatName, default_fileName; | 79 | QString fileName, formatName, default_fileName; |
81 | 80 | ||
82 | default_fileName = StdAddressBook::fileName(); | 81 | default_fileName = StdAddressBook::fileName(); |
83 | 82 | ||
84 | KConfig *cfg = (KConfig *)config; | 83 | KConfig *cfg = (KConfig *)config; |
85 | if ( cfg ) { | 84 | if ( cfg ) { |
86 | fileName = cfg->readEntry( "FileName", default_fileName ); | 85 | fileName = cfg->readEntry( "FileName", default_fileName ); |
87 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 86 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
88 | } else { | 87 | } else { |
89 | fileName = default_fileName; | 88 | fileName = default_fileName; |
90 | formatName = "vcard"; | 89 | formatName = "vcard"; |
91 | } | 90 | } |
92 | 91 | ||
93 | init( fileName, formatName ); | 92 | init( fileName, formatName ); |
94 | } | 93 | } |
95 | 94 | ||
96 | ResourceFile::ResourceFile( const QString &fileName , | 95 | ResourceFile::ResourceFile( const QString &fileName , |
97 | const QString &formatName ) | 96 | const QString &formatName ) |
98 | : Resource( 0 ) | 97 | : Resource( 0 ) |
99 | { | 98 | { |
100 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 99 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
100 | |||
101 | |||
102 | |||
101 | init( fileName, formatName ); | 103 | init( fileName, formatName ); |
102 | } | 104 | } |
103 | 105 | ||
104 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 106 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
105 | { | 107 | { |
106 | mFormatName = formatName; | 108 | mFormatName = formatName; |
107 | 109 | ||
108 | FormatFactory *factory = FormatFactory::self(); | 110 | FormatFactory *factory = FormatFactory::self(); |
109 | mFormat = factory->format( mFormatName ); | 111 | mFormat = factory->format( mFormatName ); |
110 | 112 | ||
111 | if ( !mFormat ) { | 113 | if ( !mFormat ) { |
112 | mFormatName = "vcard"; | 114 | mFormatName = "vcard"; |
113 | mFormat = factory->format( mFormatName ); | 115 | mFormat = factory->format( mFormatName ); |
114 | } | 116 | } |
115 | 117 | ||
116 | #ifndef NO_DIRWATCH | 118 | #ifndef NO_DIRWATCH |
117 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 119 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
118 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 120 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
119 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 121 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
120 | #endif | 122 | #endif |
123 | |||
124 | |||
125 | QString localKdeDir; | ||
126 | localKdeDir = readEnvPath("LOCALMICROKDEHOME"); | ||
127 | if ( ! localKdeDir.isEmpty() ) { | ||
128 | qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() ); | ||
129 | |||
130 | |||
131 | |||
132 | |||
133 | } | ||
134 | qDebug("RESOURCE: %s ", fileName.latin1()); | ||
135 | |||
136 | |||
137 | |||
121 | setFileName( fileName ); | 138 | setFileName( fileName ); |
122 | } | 139 | } |
123 | 140 | ||
124 | ResourceFile::~ResourceFile() | 141 | ResourceFile::~ResourceFile() |
125 | { | 142 | { |
126 | delete mFormat; | 143 | delete mFormat; |
127 | mFormat = 0; | 144 | mFormat = 0; |
128 | } | 145 | } |
129 | 146 | ||
130 | void ResourceFile::writeConfig( KConfig *config ) | 147 | void ResourceFile::writeConfig( KConfig *config ) |
131 | { | 148 | { |
132 | 149 | ||
133 | config->setGroup( "Resource_" + identifier() ); | 150 | config->setGroup( "Resource_" + identifier() ); |
134 | Resource::writeConfig( config ); | 151 | Resource::writeConfig( config ); |
135 | 152 | ||
136 | config->writeEntry( "FileName", mFileName ); | 153 | config->writeEntry( "FileName", fileName() ); |
137 | config->writeEntry( "FileFormat", mFormatName ); | 154 | config->writeEntry( "FileFormat", mFormatName ); |
138 | 155 | ||
139 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 156 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
140 | 157 | ||
141 | } | 158 | } |
142 | 159 | ||
143 | Ticket *ResourceFile::requestSaveTicket() | 160 | Ticket *ResourceFile::requestSaveTicket() |
144 | { | 161 | { |
145 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 162 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
146 | 163 | ||
147 | if ( !addressBook() ) return 0; | 164 | if ( !addressBook() ) return 0; |
148 | 165 | ||
149 | #ifdef ALLOW_LOCKING | 166 | #ifdef ALLOW_LOCKING |
150 | if ( !lock( mFileName ) ) { | 167 | if ( !lock( mFileName ) ) { |
151 | qDebug("unablt to lock file "); | 168 | qDebug("unablt to lock file "); |
152 | return 0; | 169 | return 0; |
153 | } | 170 | } |
154 | #endif | 171 | #endif |
155 | return createTicket( this ); | 172 | return createTicket( this ); |
156 | } | 173 | } |
157 | 174 | ||
158 | 175 | ||
159 | bool ResourceFile::doOpen() | 176 | bool ResourceFile::doOpen() |
160 | { | 177 | { |
161 | QFile file( mFileName ); | 178 | QFile file( fileName() ); |
162 | qDebug("ResourceFile::openfile %s ", mFileName.latin1()); | 179 | qDebug("ResourceFile::openfile %s ", fileName().latin1()); |
163 | 180 | ||
164 | if ( !file.exists() ) { | 181 | if ( !file.exists() ) { |
165 | // try to create the file | 182 | // try to create the file |
166 | bool ok = file.open( IO_WriteOnly ); | 183 | bool ok = file.open( IO_WriteOnly ); |
167 | if ( ok ) | 184 | if ( ok ) |
168 | file.close(); | 185 | file.close(); |
169 | 186 | ||
170 | return ok; | 187 | return ok; |
171 | } else { | 188 | } else { |
172 | if ( !file.open( IO_ReadWrite ) ) | 189 | if ( !file.open( IO_ReadWrite ) ) |
173 | return false; | 190 | return false; |
174 | 191 | ||
175 | if ( file.size() == 0 ) { | 192 | if ( file.size() == 0 ) { |
176 | file.close(); | 193 | file.close(); |
177 | return true; | 194 | return true; |
178 | } | 195 | } |
179 | 196 | ||
180 | bool ok = mFormat->checkFormat( &file ); | 197 | bool ok = mFormat->checkFormat( &file ); |
181 | file.close(); | 198 | file.close(); |
182 | 199 | ||
183 | return ok; | 200 | return ok; |
184 | } | 201 | } |
185 | } | 202 | } |
186 | 203 | ||
187 | void ResourceFile::doClose() | 204 | void ResourceFile::doClose() |
188 | { | 205 | { |
189 | } | 206 | } |
190 | 207 | ||
191 | bool ResourceFile::load() | 208 | bool ResourceFile::load() |
192 | { | 209 | { |
193 | 210 | ||
194 | QFile file( mFileName ); | 211 | QFile file( fileName() ); |
195 | if ( !file.open( IO_ReadOnly ) ) { | 212 | if ( !file.open( IO_ReadOnly ) ) { |
196 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 213 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) ); |
197 | return false; | 214 | return false; |
198 | } | 215 | } |
199 | 216 | ||
200 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 217 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
201 | 218 | ||
202 | return mFormat->loadAll( addressBook(), this, &file ); | 219 | return mFormat->loadAll( addressBook(), this, &file ); |
203 | } | 220 | } |
204 | 221 | ||
205 | bool ResourceFile::save( Ticket *ticket ) | 222 | bool ResourceFile::save( Ticket *ticket ) |
206 | { | 223 | { |
207 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 224 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
208 | 225 | ||
209 | 226 | ||
210 | // create backup file | 227 | // create backup file |
211 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 228 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
212 | 229 | ||
213 | /*US we use a simpler method to create a backupfile | 230 | /*US we use a simpler method to create a backupfile |
214 | 231 | ||
215 | (void) KSaveFile::backupFile( mFileName, QString::null | 232 | (void) KSaveFile::backupFile( mFileName, QString::null |
216 | ,extension ); | 233 | ,extension ); |
217 | 234 | ||
218 | KSaveFile saveFile( mFileName ); | 235 | KSaveFile saveFile( mFileName ); |
219 | bool ok = false; | 236 | bool ok = false; |
220 | if ( saveFile.status() == 0 && saveFile.file() ) | 237 | if ( saveFile.status() == 0 && saveFile.file() ) |
221 | { | 238 | { |
222 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 239 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
223 | ok = saveFile.close(); | 240 | ok = saveFile.close(); |
224 | } | 241 | } |
225 | */ | 242 | */ |
226 | 243 | ||
227 | //US ToDo: write backupfile | 244 | //US ToDo: write backupfile |
228 | #ifndef NO_DIRWATCH | 245 | #ifndef NO_DIRWATCH |
229 | mDirWatch.stopScan(); | 246 | mDirWatch.stopScan(); |
230 | #endif | 247 | #endif |
231 | QFile info; | 248 | QFile info; |
232 | info.setName( mFileName ); | 249 | info.setName( fileName() ); |
233 | bool ok = info.open( IO_WriteOnly ); | 250 | bool ok = info.open( IO_WriteOnly ); |
234 | if ( ok ) { | 251 | if ( ok ) { |
235 | mFormat->saveAll( addressBook(), this, &info ); | 252 | mFormat->saveAll( addressBook(), this, &info ); |
236 | 253 | ||
237 | info.close(); | 254 | info.close(); |
238 | ok = true; | 255 | ok = true; |
239 | } | 256 | } |
240 | else { | 257 | else { |
241 | 258 | ||
242 | } | 259 | } |
243 | 260 | ||
244 | if ( !ok ) | 261 | if ( !ok ) |
245 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 262 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) ); |
246 | #ifndef NO_DIRWATCH | 263 | #ifndef NO_DIRWATCH |
247 | mDirWatch.startScan(); | 264 | mDirWatch.startScan(); |
248 | #endif | 265 | #endif |
249 | delete ticket; | 266 | delete ticket; |
250 | #ifdef ALLOW_LOCKING | 267 | #ifdef ALLOW_LOCKING |
251 | unlock( mFileName ); | 268 | unlock( mFileName ); |
252 | #endif | 269 | #endif |
253 | 270 | ||
254 | return ok; | 271 | return ok; |
255 | } | 272 | } |
256 | 273 | ||
257 | bool ResourceFile::lock( const QString &fileName ) | 274 | bool ResourceFile::lock( const QString &fileName ) |
258 | { | 275 | { |
259 | #ifdef ALLOW_LOCKING | 276 | #ifdef ALLOW_LOCKING |
260 | 277 | ||
261 | 278 | ||
262 | QString fn = fileName; | 279 | QString fn = fileName; |
263 | 280 | ||
264 | //US change the implementation how the lockfilename is getting created | 281 | //US change the implementation how the lockfilename is getting created |
265 | //US fn.replace( QRegExp("/"), "_" ); | 282 | //US fn.replace( QRegExp("/"), "_" ); |
266 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 283 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
267 | 284 | ||
268 | KURL url(fn); | 285 | KURL url(fn); |
269 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 286 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
270 | 287 | ||
271 | 288 | ||
272 | 289 | ||
273 | if (QFile::exists( lockName )) return false; | 290 | if (QFile::exists( lockName )) return false; |
274 | 291 | ||
275 | QString lockUniqueName; | 292 | QString lockUniqueName; |
276 | lockUniqueName = fn + KApplication::randomString( 8 ); | 293 | lockUniqueName = fn + KApplication::randomString( 8 ); |
277 | 294 | ||
278 | url = lockUniqueName; | 295 | url = lockUniqueName; |
279 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 296 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
280 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 297 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
281 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 298 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
282 | 299 | ||
283 | // Create unique file | 300 | // Create unique file |
284 | QFile file( mLockUniqueName ); | 301 | QFile file( mLockUniqueName ); |
285 | file.open( IO_WriteOnly ); | 302 | file.open( IO_WriteOnly ); |
286 | file.close(); | 303 | file.close(); |
287 | 304 | ||
288 | // Create lock file | 305 | // Create lock file |
289 | int result = 0; | 306 | int result = 0; |
290 | #ifndef _WIN32_ | 307 | #ifndef _WIN32_ |
291 | result = ::link( QFile::encodeName( mLockUniqueName ), | 308 | result = ::link( QFile::encodeName( mLockUniqueName ), |
292 | QFile::encodeName( lockName ) ); | 309 | QFile::encodeName( lockName ) ); |
293 | #endif | 310 | #endif |
294 | if ( result == 0 ) { | 311 | if ( result == 0 ) { |
295 | addressBook()->emitAddressBookLocked(); | 312 | addressBook()->emitAddressBookLocked(); |
296 | return true; | 313 | return true; |
297 | } | 314 | } |
298 | 315 | ||
299 | // TODO: check stat | 316 | // TODO: check stat |
300 | 317 | ||
301 | return false; | 318 | return false; |
302 | #else | 319 | #else |
303 | return true; | 320 | return true; |
304 | #endif | 321 | #endif |
305 | } | 322 | } |
306 | 323 | ||
307 | void ResourceFile::unlock( const QString &fileName ) | 324 | void ResourceFile::unlock( const QString &fileName ) |
308 | { | 325 | { |
309 | #ifdef ALLOW_LOCKING | 326 | #ifdef ALLOW_LOCKING |
310 | QString fn = fileName; | 327 | QString fn = fileName; |
311 | //US change the implementation how the lockfilename is getting created | 328 | //US change the implementation how the lockfilename is getting created |
312 | //US fn.replace( QRegExp( "/" ), "_" ); | 329 | //US fn.replace( QRegExp( "/" ), "_" ); |
313 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 330 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
314 | //US QString lockName = fn + ".lock"; | 331 | //US QString lockName = fn + ".lock"; |
315 | KURL url(fn); | 332 | KURL url(fn); |
316 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 333 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
317 | 334 | ||
318 | QFile::remove( lockName ); | 335 | QFile::remove( lockName ); |
319 | QFile::remove( mLockUniqueName ); | 336 | QFile::remove( mLockUniqueName ); |
320 | addressBook()->emitAddressBookUnlocked(); | 337 | addressBook()->emitAddressBookUnlocked(); |
321 | #else | 338 | #else |
322 | return; | 339 | return; |
323 | #endif | 340 | #endif |
324 | } | 341 | } |
325 | 342 | ||
326 | void ResourceFile::setFileName( const QString &fileName ) | 343 | void ResourceFile::setFileName( const QString &fileName ) |
327 | { | 344 | { |
328 | #ifndef NO_DIRWATCH | 345 | #ifndef NO_DIRWATCH |
329 | mDirWatch.stopScan(); | 346 | mDirWatch.stopScan(); |
330 | mDirWatch.removeFile( mFileName ); | 347 | mDirWatch.removeFile( mFileName ); |
331 | mFileName = fileName; | 348 | mFileName = fileName; |
332 | 349 | ||
333 | 350 | ||
334 | mDirWatch.addFile( mFileName ); | 351 | mDirWatch.addFile( mFileName ); |
335 | mDirWatch.startScan(); | 352 | mDirWatch.startScan(); |
336 | #else | 353 | #else |
337 | mFileName = fileName; | 354 | mFileName2 = fileName; |
338 | #endif | 355 | #endif |
339 | 356 | ||
340 | //US simulate KDirWatch event | 357 | //US simulate KDirWatch event |
341 | //US fileChanged(); | 358 | //US fileChanged(); |
342 | } | 359 | } |
343 | 360 | ||
344 | QString ResourceFile::fileName() const | 361 | QString ResourceFile::fileName() const |
345 | { | 362 | { |
346 | return mFileName; | 363 | return mFileName2; |
347 | } | 364 | } |
348 | 365 | ||
349 | void ResourceFile::setFormat( const QString &format ) | 366 | void ResourceFile::setFormat( const QString &format ) |
350 | { | 367 | { |
351 | mFormatName = format; | 368 | mFormatName = format; |
352 | delete mFormat; | 369 | delete mFormat; |
353 | 370 | ||
354 | FormatFactory *factory = FormatFactory::self(); | 371 | FormatFactory *factory = FormatFactory::self(); |
355 | mFormat = factory->format( mFormatName ); | 372 | mFormat = factory->format( mFormatName ); |
356 | /*US | 373 | /*US |
357 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 374 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
358 | if (mFormatName == "vcard") { | 375 | if (mFormatName == "vcard") { |
359 | mFormat = new VCardFormatPlugin2(); | 376 | mFormat = new VCardFormatPlugin2(); |
360 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 377 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
361 | } | 378 | } |
362 | else if (mFormatName == "binary") { | 379 | else if (mFormatName == "binary") { |
363 | mFormat = new BinaryFormat(); | 380 | mFormat = new BinaryFormat(); |
364 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 381 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
365 | } | 382 | } |
366 | else | 383 | else |
367 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 384 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
368 | */ | 385 | */ |
369 | 386 | ||
370 | } | 387 | } |
371 | 388 | ||
372 | QString ResourceFile::format() const | 389 | QString ResourceFile::format() const |
373 | { | 390 | { |
374 | return mFormatName; | 391 | return mFormatName; |
375 | } | 392 | } |
376 | 393 | ||
377 | void ResourceFile::fileChanged() | 394 | void ResourceFile::fileChanged() |
378 | { | 395 | { |
379 | // There is a small theoretical chance that KDirWatch calls us before | 396 | // There is a small theoretical chance that KDirWatch calls us before |
380 | // we are fully constructed | 397 | // we are fully constructed |
381 | if (!addressBook()) | 398 | if (!addressBook()) |
382 | return; | 399 | return; |
383 | 400 | ||
384 | 401 | ||
385 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 402 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
386 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 403 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
387 | load(); | 404 | load(); |
388 | addressBook()->emitAddressBookChanged(); | 405 | addressBook()->emitAddressBookChanged(); |
389 | } | 406 | } |
390 | } | 407 | } |
391 | 408 | ||
392 | void ResourceFile::removeAddressee( const Addressee &addr ) | 409 | void ResourceFile::removeAddressee( const Addressee &addr ) |
393 | { | 410 | { |
394 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 411 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
395 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 412 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
396 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 413 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
397 | } | 414 | } |
398 | 415 | ||
399 | void ResourceFile::cleanUp() | 416 | void ResourceFile::cleanUp() |
400 | { | 417 | { |
401 | unlock( mFileName ); | 418 | unlock( fileName() ); |
402 | } | 419 | } |
403 | 420 | ||
404 | //US #include "resourcefile.moc" | 421 | //US #include "resourcefile.moc" |
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h index b4421b2..dd38a9d 100644 --- a/kabc/plugins/file/resourcefile.h +++ b/kabc/plugins/file/resourcefile.h | |||
@@ -22,142 +22,142 @@ | |||
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 | 28 | ||
29 | #ifndef KABC_RESOURCEFILE_H | 29 | #ifndef KABC_RESOURCEFILE_H |
30 | #define KABC_RESOURCEFILE_H | 30 | #define KABC_RESOURCEFILE_H |
31 | 31 | ||
32 | #include <kconfig.h> | 32 | #include <kconfig.h> |
33 | #include <kdirwatch.h> | 33 | #include <kdirwatch.h> |
34 | 34 | ||
35 | #include <sys/types.h> | 35 | #include <sys/types.h> |
36 | 36 | ||
37 | #include <resource.h> | 37 | #include <resource.h> |
38 | 38 | ||
39 | class QTimer; | 39 | class QTimer; |
40 | class FormatPlugin; | 40 | class FormatPlugin; |
41 | 41 | ||
42 | namespace KABC { | 42 | namespace KABC { |
43 | 43 | ||
44 | //US class FormatPlugin; | 44 | //US class FormatPlugin; |
45 | class ResourceConfigWidget; | 45 | class ResourceConfigWidget; |
46 | 46 | ||
47 | /** | 47 | /** |
48 | @internal | 48 | @internal |
49 | */ | 49 | */ |
50 | class ResourceFile : public Resource | 50 | class ResourceFile : public Resource |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | public: | 54 | public: |
55 | 55 | ||
56 | /** | 56 | /** |
57 | Constructor. | 57 | Constructor. |
58 | 58 | ||
59 | @param cfg The config object where custom resource settings are stored. | 59 | @param cfg The config object where custom resource settings are stored. |
60 | */ | 60 | */ |
61 | ResourceFile( const KConfig *cfg ); | 61 | ResourceFile( const KConfig *cfg ); |
62 | 62 | ||
63 | /** | 63 | /** |
64 | Construct file resource on file @arg fileName using format @arg formatName. | 64 | Construct file resource on file @arg fileName using format @arg formatName. |
65 | */ | 65 | */ |
66 | ResourceFile( const QString &fileName , const QString &formatName = "vcard" ); | 66 | ResourceFile( const QString &fileName , const QString &formatName = "vcard" ); |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Destructor. | 69 | * Destructor. |
70 | */ | 70 | */ |
71 | ~ResourceFile(); | 71 | ~ResourceFile(); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | Writes the config back. | 74 | Writes the config back. |
75 | */ | 75 | */ |
76 | virtual void writeConfig( KConfig *cfg ); | 76 | virtual void writeConfig( KConfig *cfg ); |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Tries to open the file and checks for the proper format. | 79 | * Tries to open the file and checks for the proper format. |
80 | * This method should be called before @ref load(). | 80 | * This method should be called before @ref load(). |
81 | */ | 81 | */ |
82 | virtual bool doOpen(); | 82 | virtual bool doOpen(); |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Closes the file again. | 85 | * Closes the file again. |
86 | */ | 86 | */ |
87 | virtual void doClose(); | 87 | virtual void doClose(); |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Requests a save ticket, that is used by @ref save() | 90 | * Requests a save ticket, that is used by @ref save() |
91 | */ | 91 | */ |
92 | virtual Ticket *requestSaveTicket(); | 92 | virtual Ticket *requestSaveTicket(); |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Loads all addressees from file to the address book. | 95 | * Loads all addressees from file to the address book. |
96 | * Returns true if all addressees could be loaded otherwise false. | 96 | * Returns true if all addressees could be loaded otherwise false. |
97 | */ | 97 | */ |
98 | virtual bool load(); | 98 | virtual bool load(); |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Saves all addresses from address book to file. | 101 | * Saves all addresses from address book to file. |
102 | * Returns true if all addressees could be saved otherwise false. | 102 | * Returns true if all addressees could be saved otherwise false. |
103 | * | 103 | * |
104 | * @param ticket The ticket returned by @ref requestSaveTicket() | 104 | * @param ticket The ticket returned by @ref requestSaveTicket() |
105 | */ | 105 | */ |
106 | virtual bool save( Ticket *ticket ); | 106 | virtual bool save( Ticket *ticket ); |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Set name of file to be used for saving. | 109 | * Set name of file to be used for saving. |
110 | */ | 110 | */ |
111 | void setFileName( const QString & ); | 111 | void setFileName( const QString & ); |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Return name of file used for loading and saving the address book. | 114 | * Return name of file used for loading and saving the address book. |
115 | */ | 115 | */ |
116 | QString fileName() const; | 116 | QString fileName() const; |
117 | 117 | ||
118 | /** | 118 | /** |
119 | Sets a new format by name. | 119 | Sets a new format by name. |
120 | */ | 120 | */ |
121 | void setFormat( const QString &name ); | 121 | void setFormat( const QString &name ); |
122 | 122 | ||
123 | /** | 123 | /** |
124 | Returns the format name. | 124 | Returns the format name. |
125 | */ | 125 | */ |
126 | QString format() const; | 126 | QString format() const; |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Remove a addressee from its source. | 129 | * Remove a addressee from its source. |
130 | * This method is mainly called by KABC::AddressBook. | 130 | * This method is mainly called by KABC::AddressBook. |
131 | */ | 131 | */ |
132 | virtual void removeAddressee( const Addressee& addr ); | 132 | virtual void removeAddressee( const Addressee& addr ); |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * This method is called by an error handler if the application | 135 | * This method is called by an error handler if the application |
136 | * crashed | 136 | * crashed |
137 | */ | 137 | */ |
138 | virtual void cleanUp(); | 138 | virtual void cleanUp(); |
139 | 139 | ||
140 | protected slots: | 140 | protected slots: |
141 | void fileChanged(); | 141 | void fileChanged(); |
142 | 142 | ||
143 | protected: | 143 | protected: |
144 | void init( const QString &fileName, const QString &format ); | 144 | void init( const QString &fileName, const QString &format ); |
145 | 145 | ||
146 | bool lock( const QString &fileName ); | 146 | bool lock( const QString &fileName ); |
147 | void unlock( const QString &fileName ); | 147 | void unlock( const QString &fileName ); |
148 | 148 | ||
149 | private: | 149 | private: |
150 | QString mFileName; | 150 | QString mFileName2; |
151 | QString mFormatName; | 151 | QString mFormatName; |
152 | 152 | ||
153 | FormatPlugin *mFormat; | 153 | FormatPlugin *mFormat; |
154 | 154 | ||
155 | QString mLockUniqueName; | 155 | QString mLockUniqueName; |
156 | #ifndef NO_DIRWATCH | 156 | #ifndef NO_DIRWATCH |
157 | KDirWatch mDirWatch; | 157 | KDirWatch mDirWatch; |
158 | #endif | 158 | #endif |
159 | }; | 159 | }; |
160 | 160 | ||
161 | } | 161 | } |
162 | 162 | ||
163 | #endif | 163 | #endif |