Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp') (more/less context) (show 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 | |||
@@ -36,21 +36,21 @@ | |||
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 | ||
@@ -61,13 +61,13 @@ bool OContactAccessBackend_VCard::load () | |||
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 ){ |
@@ -82,17 +82,17 @@ bool OContactAccessBackend_VCard::load () | |||
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 ) ) |
@@ -100,111 +100,111 @@ bool OContactAccessBackend_VCard::save() | |||
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 ); |
@@ -424,13 +424,13 @@ OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
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 | ||
@@ -530,13 +530,13 @@ VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | |||
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"... |
@@ -544,13 +544,13 @@ QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | |||
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 ); |
@@ -569,21 +569,21 @@ QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | |||
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 | } |