author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/plugins/qtopia/qtopiaconverter.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'kabc/plugins/qtopia/qtopiaconverter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index 9693a68..9b3903b 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp | |||
@@ -21,33 +21,35 @@ | |||
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 | //US | 28 | //US |
29 | #include "kglobal.h" | 29 | #include "kglobal.h" |
30 | #include "klocale.h" | 30 | #include "klocale.h" |
31 | 31 | ||
32 | 32 | ||
33 | #include "qtopiaconverter.h" | 33 | #include "qtopiaconverter.h" |
34 | 34 | ||
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qdir.h> | 36 | #include <qdir.h> |
37 | #include <qtextstream.h> | 37 | #include <q3textstream.h> |
38 | //Added by qt3to4: | ||
39 | #include <Q3ValueList> | ||
38 | //#include <.h> | 40 | //#include <.h> |
39 | 41 | ||
40 | #include <libkdepim/ksyncprofile.h> | 42 | #include <libkdepim/ksyncprofile.h> |
41 | 43 | ||
42 | 44 | ||
43 | using namespace KABC; | 45 | using namespace KABC; |
44 | 46 | ||
45 | QtopiaConverter::QtopiaConverter() | 47 | QtopiaConverter::QtopiaConverter() |
46 | { | 48 | { |
47 | m_edit = 0; | 49 | m_edit = 0; |
48 | } | 50 | } |
49 | 51 | ||
50 | QtopiaConverter::~QtopiaConverter() | 52 | QtopiaConverter::~QtopiaConverter() |
51 | { | 53 | { |
52 | deinit(); | 54 | deinit(); |
53 | } | 55 | } |
@@ -58,34 +60,34 @@ bool QtopiaConverter::init() | |||
58 | m_edit = new CategoryEdit( fn); | 60 | m_edit = new CategoryEdit( fn); |
59 | return true; | 61 | return true; |
60 | } | 62 | } |
61 | 63 | ||
62 | void QtopiaConverter::deinit() | 64 | void QtopiaConverter::deinit() |
63 | { | 65 | { |
64 | if (m_edit) | 66 | if (m_edit) |
65 | { | 67 | { |
66 | delete m_edit; | 68 | delete m_edit; |
67 | m_edit = 0; | 69 | m_edit = 0; |
68 | } | 70 | } |
69 | } | 71 | } |
70 | QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app ) | 72 | QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app ) |
71 | { | 73 | { |
72 | startover: | 74 | startover: |
73 | QStringList dummy; | 75 | QStringList dummy; |
74 | QValueList<OpieCategories>::ConstIterator catIt; | 76 | Q3ValueList<OpieCategories>::ConstIterator catIt; |
75 | QValueList<OpieCategories> categories = m_edit->categories(); | 77 | Q3ValueList<OpieCategories> categories = m_edit->categories(); |
76 | bool found = false; | 78 | bool found = false; |
77 | for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) { | 79 | for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) { |
78 | /* skip empty category name */ | 80 | /* skip empty category name */ |
79 | if ( (*listIt).isEmpty() ) continue; | 81 | if ( (*listIt).isEmpty() ) continue; |
80 | 82 | ||
81 | found = false; | 83 | found = false; |
82 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 84 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
83 | /* | 85 | /* |
84 | * We currently do not take app into account | 86 | * We currently do not take app into account |
85 | * if name matches and the id isn't already in dummy we'll add it | 87 | * if name matches and the id isn't already in dummy we'll add it |
86 | */ | 88 | */ |
87 | if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name | 89 | if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name |
88 | found= true; | 90 | found= true; |
89 | dummy << (*catIt).id(); | 91 | dummy << (*catIt).id(); |
90 | } | 92 | } |
91 | } | 93 | } |
@@ -179,33 +181,33 @@ QString QtopiaConverter::dateToString( const QDate &d ) | |||
179 | return str; | 181 | return str; |
180 | } | 182 | } |
181 | 183 | ||
182 | bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) | 184 | bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) |
183 | { | 185 | { |
184 | { //LR | 186 | { //LR |
185 | 187 | ||
186 | adr.setUid( el.attribute("Uid" ) ); | 188 | adr.setUid( el.attribute("Uid" ) ); |
187 | adr.setFamilyName( el.attribute( "LastName" ) ); | 189 | adr.setFamilyName( el.attribute( "LastName" ) ); |
188 | adr.setGivenName( el.attribute( "FirstName" ) ); | 190 | adr.setGivenName( el.attribute( "FirstName" ) ); |
189 | adr.setAdditionalName( el.attribute( "MiddleName" ) ); | 191 | adr.setAdditionalName( el.attribute( "MiddleName" ) ); |
190 | adr.setSuffix( el.attribute( "Suffix" ) ); | 192 | adr.setSuffix( el.attribute( "Suffix" ) ); |
191 | adr.setNickName( el.attribute( "Nickname" ) ); | 193 | adr.setNickName( el.attribute( "Nickname" ) ); |
192 | 194 | ||
193 | QDate date = dateFromString( el.attribute( "Birthday" ) ); | 195 | QDate date = dateFromString( el.attribute( "Birthday" ) ); |
194 | if ( date.isValid() ) | 196 | if ( date.isValid() ) |
195 | adr.setBirthday( date ); | 197 | adr.setBirthday( (QDateTime)date ); |
196 | 198 | ||
197 | adr.setRole( el.attribute( "JobTitle" ) ); | 199 | adr.setRole( el.attribute( "JobTitle" ) ); |
198 | if ( !el.attribute( "FileAs" ).isEmpty() ) | 200 | if ( !el.attribute( "FileAs" ).isEmpty() ) |
199 | adr.setFormattedName( el.attribute( "FileAs" ) ); | 201 | adr.setFormattedName( el.attribute( "FileAs" ) ); |
200 | 202 | ||
201 | adr.setOrganization( el.attribute( "Company" ) ); | 203 | adr.setOrganization( el.attribute( "Company" ) ); |
202 | 204 | ||
203 | KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ), | 205 | KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ), |
204 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); | 206 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); |
205 | KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ), | 207 | KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ), |
206 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); | 208 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); |
207 | KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ), | 209 | KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ), |
208 | KABC::PhoneNumber::Car ); | 210 | KABC::PhoneNumber::Car ); |
209 | KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ), | 211 | KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ), |
210 | KABC::PhoneNumber::Pager ); | 212 | KABC::PhoneNumber::Pager ); |
211 | if ( !businessPhoneNum.number().isEmpty() ) | 213 | if ( !businessPhoneNum.number().isEmpty() ) |
@@ -304,33 +306,33 @@ bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) | |||
304 | if ( !el.attribute( "Children" ).isEmpty() ) | 306 | if ( !el.attribute( "Children" ).isEmpty() ) |
305 | adr.insertCustom("KADDRESSBOOK", "X-Children", el.attribute("Children") ); | 307 | adr.insertCustom("KADDRESSBOOK", "X-Children", el.attribute("Children") ); |
306 | if ( !el.attribute( "Office" ).isEmpty() ) | 308 | if ( !el.attribute( "Office" ).isEmpty() ) |
307 | adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") ); | 309 | adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") ); |
308 | if ( !el.attribute( "Profession" ).isEmpty() ) | 310 | if ( !el.attribute( "Profession" ).isEmpty() ) |
309 | adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") ); | 311 | adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") ); |
310 | if ( !el.attribute( "Assistant" ).isEmpty() ) | 312 | if ( !el.attribute( "Assistant" ).isEmpty() ) |
311 | adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") ); | 313 | adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") ); |
312 | if ( !el.attribute( "Manager" ).isEmpty() ) | 314 | if ( !el.attribute( "Manager" ).isEmpty() ) |
313 | adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") ); | 315 | adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") ); |
314 | 316 | ||
315 | 317 | ||
316 | } | 318 | } |
317 | return true; | 319 | return true; |
318 | } | 320 | } |
319 | 321 | ||
320 | bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, QTextStream *stream ) | 322 | bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, Q3TextStream *stream ) |
321 | { | 323 | { |
322 | *stream << "<Contact "; | 324 | *stream << "<Contact "; |
323 | *stream << "FirstName=\"" << escape(ab.givenName()) << "\" "; | 325 | *stream << "FirstName=\"" << escape(ab.givenName()) << "\" "; |
324 | *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" "; | 326 | *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" "; |
325 | *stream << "LastName=\"" << escape(ab.familyName()) << "\" "; | 327 | *stream << "LastName=\"" << escape(ab.familyName()) << "\" "; |
326 | *stream << "Suffix=\"" << escape(ab.suffix()) << "\" "; | 328 | *stream << "Suffix=\"" << escape(ab.suffix()) << "\" "; |
327 | 329 | ||
328 | QString sortStr; | 330 | QString sortStr; |
329 | sortStr = ab.formattedName(); | 331 | sortStr = ab.formattedName(); |
330 | /* is formattedName is empty we use the assembled name as fallback */ | 332 | /* is formattedName is empty we use the assembled name as fallback */ |
331 | if (sortStr.isEmpty() ) | 333 | if (sortStr.isEmpty() ) |
332 | sortStr = ab.assembledName(); | 334 | sortStr = ab.assembledName(); |
333 | *stream << "FileAs=\"" << escape(sortStr) << "\" "; | 335 | *stream << "FileAs=\"" << escape(sortStr) << "\" "; |
334 | 336 | ||
335 | *stream << "JobTitle=\"" << escape(ab.role()) << "\" "; | 337 | *stream << "JobTitle=\"" << escape(ab.role()) << "\" "; |
336 | *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" "; | 338 | *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" "; |
@@ -471,39 +473,39 @@ QStringList AddressBook::attributes()const { | |||
471 | 473 | ||
472 | 474 | ||
473 | 475 | ||
474 | #endif | 476 | #endif |
475 | 477 | ||
476 | 478 | ||
477 | CategoryEdit::CategoryEdit(){ | 479 | CategoryEdit::CategoryEdit(){ |
478 | } | 480 | } |
479 | CategoryEdit::CategoryEdit(const QString &fileName){ | 481 | CategoryEdit::CategoryEdit(const QString &fileName){ |
480 | parse( fileName ); | 482 | parse( fileName ); |
481 | } | 483 | } |
482 | CategoryEdit::~CategoryEdit(){ | 484 | CategoryEdit::~CategoryEdit(){ |
483 | } | 485 | } |
484 | void CategoryEdit::save(const QString& fileName)const{ | 486 | void CategoryEdit::save(const QString& fileName)const{ |
485 | QFile file( fileName ); | 487 | QFile file( fileName ); |
486 | QString endl = "\n"; | 488 | QString endl = "\n"; |
487 | if ( file.open( IO_WriteOnly ) ) { | 489 | if ( file.open( QIODevice::WriteOnly ) ) { |
488 | QTextStream stream( &file ); | 490 | Q3TextStream stream( &file ); |
489 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | 491 | stream.setEncoding( Q3TextStream::UnicodeUTF8 ); |
490 | stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; | 492 | stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; |
491 | stream << "<!DOCTYPE CategoryList>" << endl; | 493 | stream << "<!DOCTYPE CategoryList>" << endl; |
492 | stream << "<Categories>" << endl; | 494 | stream << "<Categories>" << endl; |
493 | for ( QValueList<OpieCategories>::ConstIterator it = m_categories.begin(); | 495 | for ( Q3ValueList<OpieCategories>::ConstIterator it = m_categories.begin(); |
494 | it != m_categories.end(); ++it ) | 496 | it != m_categories.end(); ++it ) |
495 | { | 497 | { |
496 | stream << "<Category id=\""<< ( (*it).id() ) << "\" "; | 498 | stream << "<Category id=\""<< ( (*it).id() ) << "\" "; |
497 | 499 | ||
498 | if ( !(*it).app().isEmpty() ) | 500 | if ( !(*it).app().isEmpty() ) |
499 | stream << " app=\""<< ( (*it).app() ) << "\" "; | 501 | stream << " app=\""<< ( (*it).app() ) << "\" "; |
500 | 502 | ||
501 | stream << "name=\"" << ( (*it).name() ) << "\" "; | 503 | stream << "name=\"" << ( (*it).name() ) << "\" "; |
502 | stream << " />" << endl; | 504 | stream << " />" << endl; |
503 | } | 505 | } |
504 | stream << "</Categories>" << endl; | 506 | stream << "</Categories>" << endl; |
505 | file.close(); | 507 | file.close(); |
506 | } | 508 | } |
507 | } | 509 | } |
508 | int CategoryEdit::addCategory( const QString &name, int id ){ | 510 | int CategoryEdit::addCategory( const QString &name, int id ){ |
509 | return addCategory( QString::null, name, id ); | 511 | return addCategory( QString::null, name, id ); |
@@ -524,33 +526,33 @@ int CategoryEdit::addCategory( const QString &appName, const QString &name, in | |||
524 | OpieCategories categories(QString::number(id), name, appName); | 526 | OpieCategories categories(QString::number(id), name, appName); |
525 | //pending FIXME LR m_categories.remove( categories); | 527 | //pending FIXME LR m_categories.remove( categories); |
526 | m_categories.append( categories); | 528 | m_categories.append( categories); |
527 | return id; | 529 | return id; |
528 | } | 530 | } |
529 | /* | 531 | /* |
530 | * we parse the simple Category File here | 532 | * we parse the simple Category File here |
531 | * We also keep track of global Cats | 533 | * We also keep track of global Cats |
532 | * and Of Organizer and Contact cats and then | 534 | * and Of Organizer and Contact cats and then |
533 | * we will add them to the kde side... | 535 | * we will add them to the kde side... |
534 | */ | 536 | */ |
535 | void CategoryEdit::parse( const QString &tempFile ){ | 537 | void CategoryEdit::parse( const QString &tempFile ){ |
536 | clear(); | 538 | clear(); |
537 | 539 | ||
538 | QDomDocument doc( "mydocument" ); | 540 | QDomDocument doc( "mydocument" ); |
539 | QFile f( tempFile ); | 541 | QFile f( tempFile ); |
540 | if ( !f.open( IO_ReadOnly ) ) | 542 | if ( !f.open( QIODevice::ReadOnly ) ) |
541 | return; | 543 | return; |
542 | 544 | ||
543 | if ( !doc.setContent( &f ) ) { | 545 | if ( !doc.setContent( &f ) ) { |
544 | f.close(); | 546 | f.close(); |
545 | return; | 547 | return; |
546 | } | 548 | } |
547 | f.close(); | 549 | f.close(); |
548 | 550 | ||
549 | QStringList global, contact, organizer; | 551 | QStringList global, contact, organizer; |
550 | 552 | ||
551 | // print out the element names of all elements that are a direct child | 553 | // print out the element names of all elements that are a direct child |
552 | // of the outermost element. | 554 | // of the outermost element. |
553 | QDomElement docElem = doc.documentElement(); | 555 | QDomElement docElem = doc.documentElement(); |
554 | QDomNode n = docElem.firstChild(); | 556 | QDomNode n = docElem.firstChild(); |
555 | if( docElem.nodeName() == QString::fromLatin1("Categories") ){ | 557 | if( docElem.nodeName() == QString::fromLatin1("Categories") ){ |
556 | while( !n.isNull() ) { | 558 | while( !n.isNull() ) { |
@@ -574,33 +576,33 @@ void CategoryEdit::parse( const QString &tempFile ){ | |||
574 | m_categories.append( category ); // cheater | 576 | m_categories.append( category ); // cheater |
575 | } | 577 | } |
576 | n = n.nextSibling(); | 578 | n = n.nextSibling(); |
577 | } | 579 | } |
578 | } | 580 | } |
579 | updateKDE( "kaddressbookrc", global + contact ); | 581 | updateKDE( "kaddressbookrc", global + contact ); |
580 | updateKDE( "korganizerrc", global + organizer ); | 582 | updateKDE( "korganizerrc", global + organizer ); |
581 | 583 | ||
582 | } | 584 | } |
583 | void CategoryEdit::clear() | 585 | void CategoryEdit::clear() |
584 | { | 586 | { |
585 | ids.clear(); | 587 | ids.clear(); |
586 | m_categories.clear(); | 588 | m_categories.clear(); |
587 | } | 589 | } |
588 | QString CategoryEdit::categoryById( const QString &id, const QString &app )const | 590 | QString CategoryEdit::categoryById( const QString &id, const QString &app )const |
589 | { | 591 | { |
590 | QValueList<OpieCategories>::ConstIterator it; | 592 | Q3ValueList<OpieCategories>::ConstIterator it; |
591 | QString category; | 593 | QString category; |
592 | QString fallback; | 594 | QString fallback; |
593 | for( it = m_categories.begin(); it != m_categories.end(); ++it ){ | 595 | for( it = m_categories.begin(); it != m_categories.end(); ++it ){ |
594 | if( id.stripWhiteSpace() == (*it).id().stripWhiteSpace() ){ | 596 | if( id.stripWhiteSpace() == (*it).id().stripWhiteSpace() ){ |
595 | if( app == (*it).app() ){ | 597 | if( app == (*it).app() ){ |
596 | category = (*it).name(); | 598 | category = (*it).name(); |
597 | break; | 599 | break; |
598 | }else{ | 600 | }else{ |
599 | fallback = (*it).name(); | 601 | fallback = (*it).name(); |
600 | } | 602 | } |
601 | } | 603 | } |
602 | } | 604 | } |
603 | return category.isEmpty() ? fallback : category; | 605 | return category.isEmpty() ? fallback : category; |
604 | } | 606 | } |
605 | QStringList CategoryEdit::categoriesByIds( const QStringList& ids, | 607 | QStringList CategoryEdit::categoriesByIds( const QStringList& ids, |
606 | const QString& app) { | 608 | const QString& app) { |