author | mickeyl <mickeyl> | 2004-02-24 12:46:23 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-02-24 12:46:23 (UTC) |
commit | 911473db35a9fce5f3589f03c27210456faaba86 (patch) (unidiff) | |
tree | 7d55b6117b24de6ab18747b00a4641d38001c0ed /libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |
parent | a2ead23c3614fe581261455cb4c3f31cee2098f3 (diff) | |
download | opie-911473db35a9fce5f3589f03c27210456faaba86.zip opie-911473db35a9fce5f3589f03c27210456faaba86.tar.gz opie-911473db35a9fce5f3589f03c27210456faaba86.tar.bz2 |
*phew* here is the class and file rename patch. not converted yet: backend,
but that will be not visible to application classes so we can change it later.
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index f85cf38..b569f8b 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -30,187 +30,187 @@ | |||
30 | * VCard Backend for the OPIE-Contact Database. | 30 | * VCard Backend for the OPIE-Contact Database. |
31 | */ | 31 | */ |
32 | #include <opie2/ocontactaccessbackend_vcard.h> | 32 | #include <opie2/ocontactaccessbackend_vcard.h> |
33 | #include "../../../../library/backend/vobject_p.h" | 33 | #include "../../../../library/backend/vobject_p.h" |
34 | #include "../../../../library/backend/qfiledirect_p.h" | 34 | #include "../../../../library/backend/qfiledirect_p.h" |
35 | 35 | ||
36 | #include <qpe/timeconversion.h> | 36 | #include <qpe/timeconversion.h> |
37 | 37 | ||
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | 39 | ||
40 | namespace Opie { | 40 | namespace Opie { |
41 | 41 | ||
42 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): | 42 | OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): |
43 | m_dirty( false ), | 43 | m_dirty( false ), |
44 | m_file( filename ) | 44 | m_file( filename ) |
45 | { | 45 | { |
46 | load(); | 46 | load(); |
47 | } | 47 | } |
48 | 48 | ||
49 | 49 | ||
50 | bool OContactAccessBackend_VCard::load () | 50 | bool OPimContactAccessBackend_VCard::load () |
51 | { | 51 | { |
52 | m_map.clear(); | 52 | m_map.clear(); |
53 | m_dirty = false; | 53 | m_dirty = false; |
54 | 54 | ||
55 | VObject* obj = 0l; | 55 | VObject* obj = 0l; |
56 | 56 | ||
57 | if ( QFile::exists(m_file) ){ | 57 | if ( QFile::exists(m_file) ){ |
58 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 58 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
59 | if ( !obj ) | 59 | if ( !obj ) |
60 | return false; | 60 | return false; |
61 | }else{ | 61 | }else{ |
62 | qWarning("File \"%s\" not found !", m_file.latin1() ); | 62 | qWarning("File \"%s\" not found !", m_file.latin1() ); |
63 | return false; | 63 | return false; |
64 | } | 64 | } |
65 | 65 | ||
66 | while ( obj ) { | 66 | while ( obj ) { |
67 | OContact con = parseVObject( obj ); | 67 | OPimContact con = parseVObject( obj ); |
68 | /* | 68 | /* |
69 | * if uid is 0 assign a new one | 69 | * if uid is 0 assign a new one |
70 | * this at least happens on | 70 | * this at least happens on |
71 | * Nokia6210 | 71 | * Nokia6210 |
72 | */ | 72 | */ |
73 | if ( con.uid() == 0 ){ | 73 | if ( con.uid() == 0 ){ |
74 | con.setUid( 1 ); | 74 | con.setUid( 1 ); |
75 | qWarning("assigned new uid %d",con.uid() ); | 75 | qWarning("assigned new uid %d",con.uid() ); |
76 | } | 76 | } |
77 | 77 | ||
78 | m_map.insert( con.uid(), con ); | 78 | m_map.insert( con.uid(), con ); |
79 | 79 | ||
80 | VObject *t = obj; | 80 | VObject *t = obj; |
81 | obj = nextVObjectInList(obj); | 81 | obj = nextVObjectInList(obj); |
82 | cleanVObject( t ); | 82 | cleanVObject( t ); |
83 | } | 83 | } |
84 | 84 | ||
85 | return true; | 85 | return true; |
86 | 86 | ||
87 | } | 87 | } |
88 | bool OContactAccessBackend_VCard::reload() | 88 | bool OPimContactAccessBackend_VCard::reload() |
89 | { | 89 | { |
90 | return load(); | 90 | return load(); |
91 | } | 91 | } |
92 | bool OContactAccessBackend_VCard::save() | 92 | bool OPimContactAccessBackend_VCard::save() |
93 | { | 93 | { |
94 | if (!m_dirty ) | 94 | if (!m_dirty ) |
95 | return true; | 95 | return true; |
96 | 96 | ||
97 | QFileDirect file( m_file ); | 97 | QFileDirect file( m_file ); |
98 | if (!file.open(IO_WriteOnly ) ) | 98 | if (!file.open(IO_WriteOnly ) ) |
99 | return false; | 99 | return false; |
100 | 100 | ||
101 | VObject *obj; | 101 | VObject *obj; |
102 | obj = newVObject( VCCalProp ); | 102 | obj = newVObject( VCCalProp ); |
103 | addPropValue( obj, VCVersionProp, "1.0" ); | 103 | addPropValue( obj, VCVersionProp, "1.0" ); |
104 | 104 | ||
105 | VObject *vo; | 105 | VObject *vo; |
106 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 106 | for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
107 | vo = createVObject( *it ); | 107 | vo = createVObject( *it ); |
108 | writeVObject( file.directHandle() , vo ); | 108 | writeVObject( file.directHandle() , vo ); |
109 | cleanVObject( vo ); | 109 | cleanVObject( vo ); |
110 | } | 110 | } |
111 | cleanStrTbl(); | 111 | cleanStrTbl(); |
112 | deleteVObject( obj ); | 112 | deleteVObject( obj ); |
113 | 113 | ||
114 | m_dirty = false; | 114 | m_dirty = false; |
115 | return true; | 115 | return true; |
116 | 116 | ||
117 | 117 | ||
118 | } | 118 | } |
119 | void OContactAccessBackend_VCard::clear () | 119 | void OPimContactAccessBackend_VCard::clear () |
120 | { | 120 | { |
121 | m_map.clear(); | 121 | m_map.clear(); |
122 | m_dirty = true; // ??? sure ? (se) | 122 | m_dirty = true; // ??? sure ? (se) |
123 | } | 123 | } |
124 | 124 | ||
125 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 125 | bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact ) |
126 | { | 126 | { |
127 | m_map.insert( newcontact.uid(), newcontact ); | 127 | m_map.insert( newcontact.uid(), newcontact ); |
128 | m_dirty = true; | 128 | m_dirty = true; |
129 | return true; | 129 | return true; |
130 | } | 130 | } |
131 | 131 | ||
132 | bool OContactAccessBackend_VCard::remove ( int uid ) | 132 | bool OPimContactAccessBackend_VCard::remove ( int uid ) |
133 | { | 133 | { |
134 | m_map.remove( uid ); | 134 | m_map.remove( uid ); |
135 | m_dirty = true; | 135 | m_dirty = true; |
136 | return true; | 136 | return true; |
137 | } | 137 | } |
138 | 138 | ||
139 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 139 | bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact ) |
140 | { | 140 | { |
141 | m_map.replace( contact.uid(), contact ); | 141 | m_map.replace( contact.uid(), contact ); |
142 | m_dirty = true; | 142 | m_dirty = true; |
143 | return true; | 143 | return true; |
144 | } | 144 | } |
145 | 145 | ||
146 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 146 | OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const |
147 | { | 147 | { |
148 | return m_map[uid]; | 148 | return m_map[uid]; |
149 | } | 149 | } |
150 | 150 | ||
151 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 151 | QArray<int> OPimContactAccessBackend_VCard::allRecords() const |
152 | { | 152 | { |
153 | QArray<int> ar( m_map.count() ); | 153 | QArray<int> ar( m_map.count() ); |
154 | QMap<int, OContact>::ConstIterator it; | 154 | QMap<int, OPimContact>::ConstIterator it; |
155 | int i = 0; | 155 | int i = 0; |
156 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 156 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
157 | ar[i] = it.key(); | 157 | ar[i] = it.key(); |
158 | i++; | 158 | i++; |
159 | } | 159 | } |
160 | return ar; | 160 | return ar; |
161 | } | 161 | } |
162 | 162 | ||
163 | // Not implemented | 163 | // Not implemented |
164 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int, const QDateTime& ) | 164 | QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& ) |
165 | { | 165 | { |
166 | QArray<int> ar(0); | 166 | QArray<int> ar(0); |
167 | return ar; | 167 | return ar; |
168 | } | 168 | } |
169 | 169 | ||
170 | // Not implemented | 170 | // Not implemented |
171 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 171 | QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
172 | { | 172 | { |
173 | QArray<int> ar(0); | 173 | QArray<int> ar(0); |
174 | return ar; | 174 | return ar; |
175 | } | 175 | } |
176 | 176 | ||
177 | const uint OContactAccessBackend_VCard::querySettings() | 177 | const uint OPimContactAccessBackend_VCard::querySettings() |
178 | { | 178 | { |
179 | return 0; // No search possible | 179 | return 0; // No search possible |
180 | } | 180 | } |
181 | 181 | ||
182 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 182 | bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const |
183 | { | 183 | { |
184 | return false; // No search possible, therefore all settings invalid ;) | 184 | return false; // No search possible, therefore all settings invalid ;) |
185 | } | 185 | } |
186 | 186 | ||
187 | bool OContactAccessBackend_VCard::wasChangedExternally() | 187 | bool OPimContactAccessBackend_VCard::wasChangedExternally() |
188 | { | 188 | { |
189 | return false; // Don't expect concurrent access | 189 | return false; // Don't expect concurrent access |
190 | } | 190 | } |
191 | 191 | ||
192 | // Not implemented | 192 | // Not implemented |
193 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | 193 | QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int ) |
194 | { | 194 | { |
195 | QArray<int> ar(0); | 195 | QArray<int> ar(0); |
196 | return ar; | 196 | return ar; |
197 | } | 197 | } |
198 | 198 | ||
199 | // *** Private stuff *** | 199 | // *** Private stuff *** |
200 | 200 | ||
201 | 201 | ||
202 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 202 | OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) |
203 | { | 203 | { |
204 | OContact c; | 204 | OPimContact c; |
205 | 205 | ||
206 | VObjectIterator it; | 206 | VObjectIterator it; |
207 | initPropIterator( &it, obj ); | 207 | initPropIterator( &it, obj ); |
208 | while( moreIteration( &it ) ) { | 208 | while( moreIteration( &it ) ) { |
209 | VObject *o = nextVObject( &it ); | 209 | VObject *o = nextVObject( &it ); |
210 | QCString name = vObjectName( o ); | 210 | QCString name = vObjectName( o ); |
211 | QCString value = vObjectStringZValue( o ); | 211 | QCString value = vObjectStringZValue( o ); |
212 | if ( name == VCNameProp ) { | 212 | if ( name == VCNameProp ) { |
213 | VObjectIterator nit; | 213 | VObjectIterator nit; |
214 | initPropIterator( &nit, o ); | 214 | initPropIterator( &nit, o ); |
215 | while( moreIteration( &nit ) ) { | 215 | while( moreIteration( &nit ) ) { |
216 | VObject *o = nextVObject( &nit ); | 216 | VObject *o = nextVObject( &nit ); |
@@ -418,25 +418,25 @@ OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
418 | QCString name = vObjectName( o ); | 418 | QCString name = vObjectName( o ); |
419 | QString value = vObjectStringZValue( o ); | 419 | QString value = vObjectStringZValue( o ); |
420 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 420 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | #endif | 423 | #endif |
424 | } | 424 | } |
425 | c.setFileAs(); | 425 | c.setFileAs(); |
426 | return c; | 426 | return c; |
427 | } | 427 | } |
428 | 428 | ||
429 | 429 | ||
430 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | 430 | VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) |
431 | { | 431 | { |
432 | VObject *vcard = newVObject( VCCardProp ); | 432 | VObject *vcard = newVObject( VCCardProp ); |
433 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 433 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
434 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 434 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
435 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | 435 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); |
436 | 436 | ||
437 | // full name | 437 | // full name |
438 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | 438 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); |
439 | 439 | ||
440 | // name properties | 440 | // name properties |
441 | VObject *name = safeAddProp( vcard, VCNameProp ); | 441 | VObject *name = safeAddProp( vcard, VCNameProp ); |
442 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | 442 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); |
@@ -524,68 +524,68 @@ VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | |||
524 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | 524 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); |
525 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | 525 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); |
526 | if ( c.anniversary().isValid() ){ | 526 | if ( c.anniversary().isValid() ){ |
527 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); | 527 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); |
528 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); | 528 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); |
529 | } | 529 | } |
530 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | 530 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); |
531 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | 531 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); |
532 | 532 | ||
533 | return vcard; | 533 | return vcard; |
534 | } | 534 | } |
535 | 535 | ||
536 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | 536 | QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const |
537 | { | 537 | { |
538 | QString str_rfc2425 = QString("%1-%2-%3") | 538 | QString str_rfc2425 = QString("%1-%2-%3") |
539 | .arg( d.year() ) | 539 | .arg( d.year() ) |
540 | .arg( d.month(), 2 ) | 540 | .arg( d.month(), 2 ) |
541 | .arg( d.day(), 2 ); | 541 | .arg( d.day(), 2 ); |
542 | // Now replace spaces with "0"... | 542 | // Now replace spaces with "0"... |
543 | int pos = 0; | 543 | int pos = 0; |
544 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) | 544 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) |
545 | str_rfc2425.replace( pos, 1, "0" ); | 545 | str_rfc2425.replace( pos, 1, "0" ); |
546 | 546 | ||
547 | return str_rfc2425; | 547 | return str_rfc2425; |
548 | } | 548 | } |
549 | 549 | ||
550 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | 550 | QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) |
551 | { | 551 | { |
552 | int monthPos = datestr.find('-'); | 552 | int monthPos = datestr.find('-'); |
553 | int dayPos = datestr.find('-', monthPos+1 ); | 553 | int dayPos = datestr.find('-', monthPos+1 ); |
554 | int sep_ignore = 1; | 554 | int sep_ignore = 1; |
555 | if ( monthPos == -1 || dayPos == -1 ) { | 555 | if ( monthPos == -1 || dayPos == -1 ) { |
556 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 556 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
557 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) | 557 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) |
558 | if ( datestr.length() == 8 ){ | 558 | if ( datestr.length() == 8 ){ |
559 | monthPos = 4; | 559 | monthPos = 4; |
560 | dayPos = 6; | 560 | dayPos = 6; |
561 | sep_ignore = 0; | 561 | sep_ignore = 0; |
562 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 562 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
563 | } else { | 563 | } else { |
564 | return QDate(); | 564 | return QDate(); |
565 | } | 565 | } |
566 | } | 566 | } |
567 | int y = datestr.left( monthPos ).toInt(); | 567 | int y = datestr.left( monthPos ).toInt(); |
568 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); | 568 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); |
569 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); | 569 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); |
570 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); | 570 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); |
571 | QDate date ( y,m,d ); | 571 | QDate date ( y,m,d ); |
572 | return date; | 572 | return date; |
573 | } | 573 | } |
574 | 574 | ||
575 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 575 | VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
576 | { | 576 | { |
577 | VObject *ret = 0; | 577 | VObject *ret = 0; |
578 | if ( o && !value.isEmpty() ) | 578 | if ( o && !value.isEmpty() ) |
579 | ret = addPropValue( o, prop, value.latin1() ); | 579 | ret = addPropValue( o, prop, value.latin1() ); |
580 | return ret; | 580 | return ret; |
581 | } | 581 | } |
582 | 582 | ||
583 | VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) | 583 | VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) |
584 | { | 584 | { |
585 | VObject *ret = 0; | 585 | VObject *ret = 0; |
586 | if ( o ) | 586 | if ( o ) |
587 | ret = addProp( o, prop ); | 587 | ret = addProp( o, prop ); |
588 | return ret; | 588 | return ret; |
589 | } | 589 | } |
590 | 590 | ||
591 | } | 591 | } |