author | zecke <zecke> | 2002-11-03 17:56:17 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-11-03 17:56:17 (UTC) |
commit | 2981b8f55f4a33860452f4571ef9f04781267489 (patch) (unidiff) | |
tree | 3d0fe68318c23efdbcf72acfae94b3e76e2b4a14 | |
parent | 3bc2ff91e60f23dd235599b3d83471bde8be1c8a (diff) | |
download | opie-2981b8f55f4a33860452f4571ef9f04781267489.zip opie-2981b8f55f4a33860452f4571ef9f04781267489.tar.gz opie-2981b8f55f4a33860452f4571ef9f04781267489.tar.bz2 |
Oh OContact what a sucker ;)
first of all UID generation belongs to OPimRecord
and was removed from OContact
then setUid now actually calls OPimRecord::setUid instead
of Record::setUid
This finally fixes the problem with wrong uids
after beaming... At least locally on my machine
-rw-r--r-- | libopie/pim/ocontact.cpp | 5 | ||||
-rw-r--r-- | libopie/pim/ocontact.h | 6 | ||||
-rw-r--r-- | libopie/pim/opimrecord.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.h | 6 |
6 files changed, 8 insertions, 18 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp index cd238ef..8a0930b 100644 --- a/libopie/pim/ocontact.cpp +++ b/libopie/pim/ocontact.cpp | |||
@@ -19,65 +19,64 @@ | |||
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #define QTOPIA_INTERNAL_CONTACT_MRE | 22 | #define QTOPIA_INTERNAL_CONTACT_MRE |
23 | 23 | ||
24 | #include "ocontact.h" | 24 | #include "ocontact.h" |
25 | #include "../../library/backend/vobject_p.h" | 25 | #include "../../library/backend/vobject_p.h" |
26 | #include "../../library/backend/qfiledirect_p.h" | 26 | #include "../../library/backend/qfiledirect_p.h" |
27 | 27 | ||
28 | #include <qpe/stringutil.h> | 28 | #include <qpe/stringutil.h> |
29 | #include <qpe/timeconversion.h> | 29 | #include <qpe/timeconversion.h> |
30 | #include <qpe/timestring.h> | 30 | #include <qpe/timestring.h> |
31 | 31 | ||
32 | #include <qobject.h> | 32 | #include <qobject.h> |
33 | #include <qregexp.h> | 33 | #include <qregexp.h> |
34 | #include <qstylesheet.h> | 34 | #include <qstylesheet.h> |
35 | #include <qfileinfo.h> | 35 | #include <qfileinfo.h> |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | 37 | ||
38 | #include <stdio.h> | 38 | #include <stdio.h> |
39 | 39 | ||
40 | /*! | 40 | /*! |
41 | \class Contact contact.h | 41 | \class Contact contact.h |
42 | \brief The Contact class holds the data of an address book entry. | 42 | \brief The Contact class holds the data of an address book entry. |
43 | 43 | ||
44 | This data includes information the name of the person, contact | 44 | This data includes information the name of the person, contact |
45 | information, and business information such as deparment and job title. | 45 | information, and business information such as deparment and job title. |
46 | 46 | ||
47 | \ingroup qtopiaemb | 47 | \ingroup qtopiaemb |
48 | \ingroup qtopiadesktop | 48 | \ingroup qtopiadesktop |
49 | */ | 49 | */ |
50 | 50 | ||
51 | Qtopia::UidGen OContact::sUidGen( Qtopia::UidGen::Qtopia ); | ||
52 | 51 | ||
53 | /*! | 52 | /*! |
54 | Creates a new, empty contact. | 53 | Creates a new, empty contact. |
55 | */ | 54 | */ |
56 | OContact::OContact() | 55 | OContact::OContact() |
57 | : OPimRecord(), mMap(), d( 0 ) | 56 | : OPimRecord(), mMap(), d( 0 ) |
58 | { | 57 | { |
59 | } | 58 | } |
60 | 59 | ||
61 | /*! | 60 | /*! |
62 | \internal | 61 | \internal |
63 | Creates a new contact. The properties of the contact are | 62 | Creates a new contact. The properties of the contact are |
64 | set from \a fromMap. | 63 | set from \a fromMap. |
65 | */ | 64 | */ |
66 | OContact::OContact( const QMap<int, QString> &fromMap ) : | 65 | OContact::OContact( const QMap<int, QString> &fromMap ) : |
67 | OPimRecord(), mMap( fromMap ), d( 0 ) | 66 | OPimRecord(), mMap( fromMap ), d( 0 ) |
68 | { | 67 | { |
69 | QString cats = mMap[ Qtopia::AddressCategory ]; | 68 | QString cats = mMap[ Qtopia::AddressCategory ]; |
70 | if ( !cats.isEmpty() ) | 69 | if ( !cats.isEmpty() ) |
71 | setCategories( idsFromString( cats ) ); | 70 | setCategories( idsFromString( cats ) ); |
72 | 71 | ||
73 | QString uidStr = find( Qtopia::AddressUid ); | 72 | QString uidStr = find( Qtopia::AddressUid ); |
74 | 73 | ||
75 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ | 74 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ |
76 | qWarning( "Invalid UID found. Generate new one.." ); | 75 | qWarning( "Invalid UID found. Generate new one.." ); |
77 | setUid( uidGen().generate() ); | 76 | setUid( uidGen().generate() ); |
78 | }else | 77 | }else |
79 | setUid( uidStr.toInt() ); | 78 | setUid( uidStr.toInt() ); |
80 | 79 | ||
81 | // if ( !uidStr.isEmpty() ) | 80 | // if ( !uidStr.isEmpty() ) |
82 | // setUid( uidStr.toInt() ); | 81 | // setUid( uidStr.toInt() ); |
83 | } | 82 | } |
@@ -1441,66 +1440,68 @@ void OContact::writeVCard( const QString &filename, const OContact &contact) | |||
1441 | QFileDirect f( filename.utf8().data() ); | 1440 | QFileDirect f( filename.utf8().data() ); |
1442 | if ( !f.open( IO_WriteOnly ) ) { | 1441 | if ( !f.open( IO_WriteOnly ) ) { |
1443 | qWarning("Unable to open vcard write"); | 1442 | qWarning("Unable to open vcard write"); |
1444 | return; | 1443 | return; |
1445 | } | 1444 | } |
1446 | 1445 | ||
1447 | VObject *obj = createVObject( contact ); | 1446 | VObject *obj = createVObject( contact ); |
1448 | writeVObject( f.directHandle() , obj ); | 1447 | writeVObject( f.directHandle() , obj ); |
1449 | cleanVObject( obj ); | 1448 | cleanVObject( obj ); |
1450 | 1449 | ||
1451 | cleanStrTbl(); | 1450 | cleanStrTbl(); |
1452 | } | 1451 | } |
1453 | 1452 | ||
1454 | /*! | 1453 | /*! |
1455 | Returns the set of contacts read as VCards from the file \a filename. | 1454 | Returns the set of contacts read as VCards from the file \a filename. |
1456 | */ | 1455 | */ |
1457 | QValueList<OContact> OContact::readVCard( const QString &filename ) | 1456 | QValueList<OContact> OContact::readVCard( const QString &filename ) |
1458 | { | 1457 | { |
1459 | qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); | 1458 | qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); |
1460 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); | 1459 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); |
1461 | 1460 | ||
1462 | qDebug("vobject = %p", obj ); | 1461 | qDebug("vobject = %p", obj ); |
1463 | 1462 | ||
1464 | QValueList<OContact> contacts; | 1463 | QValueList<OContact> contacts; |
1465 | 1464 | ||
1466 | while ( obj ) { | 1465 | while ( obj ) { |
1467 | OContact con = parseVObject( obj ); | 1466 | OContact con = parseVObject( obj ); |
1468 | /* | 1467 | /* |
1469 | * if uid is 0 assign a new one | 1468 | * if uid is 0 assign a new one |
1470 | * this at least happens on | 1469 | * this at least happens on |
1471 | * Nokia6210 | 1470 | * Nokia6210 |
1472 | */ | 1471 | */ |
1473 | if ( con.uid() == 0 ) | 1472 | if ( con.uid() == 0 ){ |
1474 | con.setUid( 1 ); | 1473 | con.setUid( 1 ); |
1474 | qWarning("assigned new uid %d",con.uid() ); | ||
1475 | } | ||
1475 | 1476 | ||
1476 | contacts.append(con ); | 1477 | contacts.append(con ); |
1477 | 1478 | ||
1478 | VObject *t = obj; | 1479 | VObject *t = obj; |
1479 | obj = nextVObjectInList(obj); | 1480 | obj = nextVObjectInList(obj); |
1480 | cleanVObject( t ); | 1481 | cleanVObject( t ); |
1481 | } | 1482 | } |
1482 | 1483 | ||
1483 | return contacts; | 1484 | return contacts; |
1484 | } | 1485 | } |
1485 | 1486 | ||
1486 | /*! | 1487 | /*! |
1487 | Returns TRUE if the contact matches the regular expression \a regexp. | 1488 | Returns TRUE if the contact matches the regular expression \a regexp. |
1488 | Otherwise returns FALSE. | 1489 | Otherwise returns FALSE. |
1489 | */ | 1490 | */ |
1490 | bool OContact::match( const QString ®exp ) const | 1491 | bool OContact::match( const QString ®exp ) const |
1491 | { | 1492 | { |
1492 | return match(QRegExp(regexp)); | 1493 | return match(QRegExp(regexp)); |
1493 | } | 1494 | } |
1494 | 1495 | ||
1495 | /*! | 1496 | /*! |
1496 | \overload | 1497 | \overload |
1497 | Returns TRUE if the contact matches the regular expression \a regexp. | 1498 | Returns TRUE if the contact matches the regular expression \a regexp. |
1498 | Otherwise returns FALSE. | 1499 | Otherwise returns FALSE. |
1499 | */ | 1500 | */ |
1500 | bool OContact::match( const QRegExp &r ) const | 1501 | bool OContact::match( const QRegExp &r ) const |
1501 | { | 1502 | { |
1502 | bool match; | 1503 | bool match; |
1503 | match = false; | 1504 | match = false; |
1504 | QMap<int, QString>::ConstIterator it; | 1505 | QMap<int, QString>::ConstIterator it; |
1505 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { | 1506 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { |
1506 | if ( (*it).find( r ) > -1 ) { | 1507 | if ( (*it).find( r ) > -1 ) { |
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h index 038a59f..81ac1c1 100644 --- a/libopie/pim/ocontact.h +++ b/libopie/pim/ocontact.h | |||
@@ -171,72 +171,68 @@ public: | |||
171 | //personal | 171 | //personal |
172 | QString spouse() const { return find( Qtopia::Spouse ); } | 172 | QString spouse() const { return find( Qtopia::Spouse ); } |
173 | QString gender() const { return find( Qtopia::Gender ); } | 173 | QString gender() const { return find( Qtopia::Gender ); } |
174 | QDate birthday() const; | 174 | QDate birthday() const; |
175 | QDate anniversary() const; | 175 | QDate anniversary() const; |
176 | QString nickname() const { return find( Qtopia::Nickname ); } | 176 | QString nickname() const { return find( Qtopia::Nickname ); } |
177 | QString children() const { return find( Qtopia::Children ); } | 177 | QString children() const { return find( Qtopia::Children ); } |
178 | QStringList childrenList() const; | 178 | QStringList childrenList() const; |
179 | 179 | ||
180 | // other | 180 | // other |
181 | QString notes() const { return find( Qtopia::Notes ); } | 181 | QString notes() const { return find( Qtopia::Notes ); } |
182 | QString groups() const { return find( Qtopia::Groups ); } | 182 | QString groups() const { return find( Qtopia::Groups ); } |
183 | QStringList groupList() const; | 183 | QStringList groupList() const; |
184 | 184 | ||
185 | // // custom | 185 | // // custom |
186 | // const QString &customField( const QString &key ) | 186 | // const QString &customField( const QString &key ) |
187 | // { return find( Custom- + key ); } | 187 | // { return find( Custom- + key ); } |
188 | 188 | ||
189 | static QStringList fields(); | 189 | static QStringList fields(); |
190 | static QStringList trfields(); | 190 | static QStringList trfields(); |
191 | static QStringList untrfields(); | 191 | static QStringList untrfields(); |
192 | 192 | ||
193 | QString toRichText() const; | 193 | QString toRichText() const; |
194 | QMap<int, QString> toMap() const; | 194 | QMap<int, QString> toMap() const; |
195 | QString field( int key ) const { return find( key ); } | 195 | QString field( int key ) const { return find( key ); } |
196 | 196 | ||
197 | 197 | ||
198 | // journaling... | 198 | // journaling... |
199 | void saveJournal( journal_action action, const QString &key = QString::null ); | 199 | void saveJournal( journal_action action, const QString &key = QString::null ); |
200 | void save( QString &buf ) const; | 200 | void save( QString &buf ) const; |
201 | 201 | ||
202 | void setUid( int i ) | 202 | void setUid( int i ) |
203 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } | 203 | { OPimRecord::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } |
204 | 204 | ||
205 | QString toShortText()const; | 205 | QString toShortText()const; |
206 | QString OContact::type()const; | 206 | QString OContact::type()const; |
207 | QMap<QString,QString> OContact::toExtraMap() const; | 207 | QMap<QString,QString> OContact::toExtraMap() const; |
208 | class QString OContact::recordField(int) const; | 208 | class QString OContact::recordField(int) const; |
209 | 209 | ||
210 | // Why private ? (eilers,se) | 210 | // Why private ? (eilers,se) |
211 | QString emailSeparator() const { return " "; } | 211 | QString emailSeparator() const { return " "; } |
212 | // the emails should be seperated by a comma | 212 | // the emails should be seperated by a comma |
213 | void setEmails( const QString &v ); | 213 | void setEmails( const QString &v ); |
214 | QString emails() const { return find( Qtopia::Emails ); } | 214 | QString emails() const { return find( Qtopia::Emails ); } |
215 | 215 | ||
216 | 216 | ||
217 | private: | 217 | private: |
218 | friend class AbEditor; | 218 | friend class AbEditor; |
219 | friend class AbTable; | 219 | friend class AbTable; |
220 | friend class AddressBookAccessPrivate; | 220 | friend class AddressBookAccessPrivate; |
221 | friend class XMLIO; | 221 | friend class XMLIO; |
222 | 222 | ||
223 | void insert( int key, const QString &value ); | 223 | void insert( int key, const QString &value ); |
224 | void replace( int key, const QString &value ); | 224 | void replace( int key, const QString &value ); |
225 | QString find( int key ) const; | 225 | QString find( int key ) const; |
226 | 226 | ||
227 | QString displayAddress( const QString &street, | 227 | QString displayAddress( const QString &street, |
228 | const QString &city, | 228 | const QString &city, |
229 | const QString &state, | 229 | const QString &state, |
230 | const QString &zip, | 230 | const QString &zip, |
231 | const QString &country ) const; | 231 | const QString &country ) const; |
232 | 232 | ||
233 | Qtopia::UidGen &uidGen() { return sUidGen; } | ||
234 | |||
235 | |||
236 | static Qtopia::UidGen sUidGen; | ||
237 | QMap<int, QString> mMap; | 233 | QMap<int, QString> mMap; |
238 | ContactPrivate *d; | 234 | ContactPrivate *d; |
239 | }; | 235 | }; |
240 | 236 | ||
241 | 237 | ||
242 | #endif | 238 | #endif |
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp index 62dc353..21cf131 100644 --- a/libopie/pim/opimrecord.cpp +++ b/libopie/pim/opimrecord.cpp | |||
@@ -93,42 +93,40 @@ void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { | |||
93 | QArray<int> tmp; | 93 | QArray<int> tmp; |
94 | 94 | ||
95 | it = m_relations.find( app); | 95 | it = m_relations.find( app); |
96 | if ( it == m_relations.end() ) { | 96 | if ( it == m_relations.end() ) { |
97 | tmp = ids; | 97 | tmp = ids; |
98 | }else{ | 98 | }else{ |
99 | tmp = it.data(); | 99 | tmp = it.data(); |
100 | int offset = tmp.size()-1; | 100 | int offset = tmp.size()-1; |
101 | tmp.resize( tmp.size() + ids.size() ); | 101 | tmp.resize( tmp.size() + ids.size() ); |
102 | for (uint i = 0; i < ids.size(); i++ ) { | 102 | for (uint i = 0; i < ids.size(); i++ ) { |
103 | tmp[offset+i] = ids[i]; | 103 | tmp[offset+i] = ids[i]; |
104 | } | 104 | } |
105 | 105 | ||
106 | } | 106 | } |
107 | m_relations.replace( app, tmp ); | 107 | m_relations.replace( app, tmp ); |
108 | } | 108 | } |
109 | QString OPimRecord::crossToString()const { | 109 | QString OPimRecord::crossToString()const { |
110 | QString str; | 110 | QString str; |
111 | QMap<QString, QArray<int> >::ConstIterator it; | 111 | QMap<QString, QArray<int> >::ConstIterator it; |
112 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { | 112 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { |
113 | QArray<int> id = it.data(); | 113 | QArray<int> id = it.data(); |
114 | for ( uint i = 0; i < id.size(); ++i ) { | 114 | for ( uint i = 0; i < id.size(); ++i ) { |
115 | str += it.key() + "," + QString::number( i ) + ";"; | 115 | str += it.key() + "," + QString::number( i ) + ";"; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | str = str.remove( str.length()-1, 1); // strip the ; | 118 | str = str.remove( str.length()-1, 1); // strip the ; |
119 | //qWarning("IDS " + str ); | 119 | //qWarning("IDS " + str ); |
120 | 120 | ||
121 | return str; | 121 | return str; |
122 | } | 122 | } |
123 | /* if uid = 1 assign a new one */ | 123 | /* if uid = 1 assign a new one */ |
124 | void OPimRecord::setUid( int uid ) { | 124 | void OPimRecord::setUid( int uid ) { |
125 | // qWarning("setting uid" ); | ||
126 | if ( uid == 1) | 125 | if ( uid == 1) |
127 | uid = uidGen().generate(); | 126 | uid = uidGen().generate(); |
128 | 127 | ||
129 | // qWarning(" uid %d", uid); | ||
130 | Qtopia::Record::setUid( uid ); | 128 | Qtopia::Record::setUid( uid ); |
131 | }; | 129 | }; |
132 | Qtopia::UidGen &OPimRecord::uidGen() { | 130 | Qtopia::UidGen &OPimRecord::uidGen() { |
133 | return m_uidGen; | 131 | return m_uidGen; |
134 | } | 132 | } |
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp index 62dc353..21cf131 100644 --- a/libopie2/opiepim/core/opimrecord.cpp +++ b/libopie2/opiepim/core/opimrecord.cpp | |||
@@ -93,42 +93,40 @@ void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { | |||
93 | QArray<int> tmp; | 93 | QArray<int> tmp; |
94 | 94 | ||
95 | it = m_relations.find( app); | 95 | it = m_relations.find( app); |
96 | if ( it == m_relations.end() ) { | 96 | if ( it == m_relations.end() ) { |
97 | tmp = ids; | 97 | tmp = ids; |
98 | }else{ | 98 | }else{ |
99 | tmp = it.data(); | 99 | tmp = it.data(); |
100 | int offset = tmp.size()-1; | 100 | int offset = tmp.size()-1; |
101 | tmp.resize( tmp.size() + ids.size() ); | 101 | tmp.resize( tmp.size() + ids.size() ); |
102 | for (uint i = 0; i < ids.size(); i++ ) { | 102 | for (uint i = 0; i < ids.size(); i++ ) { |
103 | tmp[offset+i] = ids[i]; | 103 | tmp[offset+i] = ids[i]; |
104 | } | 104 | } |
105 | 105 | ||
106 | } | 106 | } |
107 | m_relations.replace( app, tmp ); | 107 | m_relations.replace( app, tmp ); |
108 | } | 108 | } |
109 | QString OPimRecord::crossToString()const { | 109 | QString OPimRecord::crossToString()const { |
110 | QString str; | 110 | QString str; |
111 | QMap<QString, QArray<int> >::ConstIterator it; | 111 | QMap<QString, QArray<int> >::ConstIterator it; |
112 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { | 112 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { |
113 | QArray<int> id = it.data(); | 113 | QArray<int> id = it.data(); |
114 | for ( uint i = 0; i < id.size(); ++i ) { | 114 | for ( uint i = 0; i < id.size(); ++i ) { |
115 | str += it.key() + "," + QString::number( i ) + ";"; | 115 | str += it.key() + "," + QString::number( i ) + ";"; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | str = str.remove( str.length()-1, 1); // strip the ; | 118 | str = str.remove( str.length()-1, 1); // strip the ; |
119 | //qWarning("IDS " + str ); | 119 | //qWarning("IDS " + str ); |
120 | 120 | ||
121 | return str; | 121 | return str; |
122 | } | 122 | } |
123 | /* if uid = 1 assign a new one */ | 123 | /* if uid = 1 assign a new one */ |
124 | void OPimRecord::setUid( int uid ) { | 124 | void OPimRecord::setUid( int uid ) { |
125 | // qWarning("setting uid" ); | ||
126 | if ( uid == 1) | 125 | if ( uid == 1) |
127 | uid = uidGen().generate(); | 126 | uid = uidGen().generate(); |
128 | 127 | ||
129 | // qWarning(" uid %d", uid); | ||
130 | Qtopia::Record::setUid( uid ); | 128 | Qtopia::Record::setUid( uid ); |
131 | }; | 129 | }; |
132 | Qtopia::UidGen &OPimRecord::uidGen() { | 130 | Qtopia::UidGen &OPimRecord::uidGen() { |
133 | return m_uidGen; | 131 | return m_uidGen; |
134 | } | 132 | } |
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index cd238ef..8a0930b 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp | |||
@@ -19,65 +19,64 @@ | |||
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #define QTOPIA_INTERNAL_CONTACT_MRE | 22 | #define QTOPIA_INTERNAL_CONTACT_MRE |
23 | 23 | ||
24 | #include "ocontact.h" | 24 | #include "ocontact.h" |
25 | #include "../../library/backend/vobject_p.h" | 25 | #include "../../library/backend/vobject_p.h" |
26 | #include "../../library/backend/qfiledirect_p.h" | 26 | #include "../../library/backend/qfiledirect_p.h" |
27 | 27 | ||
28 | #include <qpe/stringutil.h> | 28 | #include <qpe/stringutil.h> |
29 | #include <qpe/timeconversion.h> | 29 | #include <qpe/timeconversion.h> |
30 | #include <qpe/timestring.h> | 30 | #include <qpe/timestring.h> |
31 | 31 | ||
32 | #include <qobject.h> | 32 | #include <qobject.h> |
33 | #include <qregexp.h> | 33 | #include <qregexp.h> |
34 | #include <qstylesheet.h> | 34 | #include <qstylesheet.h> |
35 | #include <qfileinfo.h> | 35 | #include <qfileinfo.h> |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | 37 | ||
38 | #include <stdio.h> | 38 | #include <stdio.h> |
39 | 39 | ||
40 | /*! | 40 | /*! |
41 | \class Contact contact.h | 41 | \class Contact contact.h |
42 | \brief The Contact class holds the data of an address book entry. | 42 | \brief The Contact class holds the data of an address book entry. |
43 | 43 | ||
44 | This data includes information the name of the person, contact | 44 | This data includes information the name of the person, contact |
45 | information, and business information such as deparment and job title. | 45 | information, and business information such as deparment and job title. |
46 | 46 | ||
47 | \ingroup qtopiaemb | 47 | \ingroup qtopiaemb |
48 | \ingroup qtopiadesktop | 48 | \ingroup qtopiadesktop |
49 | */ | 49 | */ |
50 | 50 | ||
51 | Qtopia::UidGen OContact::sUidGen( Qtopia::UidGen::Qtopia ); | ||
52 | 51 | ||
53 | /*! | 52 | /*! |
54 | Creates a new, empty contact. | 53 | Creates a new, empty contact. |
55 | */ | 54 | */ |
56 | OContact::OContact() | 55 | OContact::OContact() |
57 | : OPimRecord(), mMap(), d( 0 ) | 56 | : OPimRecord(), mMap(), d( 0 ) |
58 | { | 57 | { |
59 | } | 58 | } |
60 | 59 | ||
61 | /*! | 60 | /*! |
62 | \internal | 61 | \internal |
63 | Creates a new contact. The properties of the contact are | 62 | Creates a new contact. The properties of the contact are |
64 | set from \a fromMap. | 63 | set from \a fromMap. |
65 | */ | 64 | */ |
66 | OContact::OContact( const QMap<int, QString> &fromMap ) : | 65 | OContact::OContact( const QMap<int, QString> &fromMap ) : |
67 | OPimRecord(), mMap( fromMap ), d( 0 ) | 66 | OPimRecord(), mMap( fromMap ), d( 0 ) |
68 | { | 67 | { |
69 | QString cats = mMap[ Qtopia::AddressCategory ]; | 68 | QString cats = mMap[ Qtopia::AddressCategory ]; |
70 | if ( !cats.isEmpty() ) | 69 | if ( !cats.isEmpty() ) |
71 | setCategories( idsFromString( cats ) ); | 70 | setCategories( idsFromString( cats ) ); |
72 | 71 | ||
73 | QString uidStr = find( Qtopia::AddressUid ); | 72 | QString uidStr = find( Qtopia::AddressUid ); |
74 | 73 | ||
75 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ | 74 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ |
76 | qWarning( "Invalid UID found. Generate new one.." ); | 75 | qWarning( "Invalid UID found. Generate new one.." ); |
77 | setUid( uidGen().generate() ); | 76 | setUid( uidGen().generate() ); |
78 | }else | 77 | }else |
79 | setUid( uidStr.toInt() ); | 78 | setUid( uidStr.toInt() ); |
80 | 79 | ||
81 | // if ( !uidStr.isEmpty() ) | 80 | // if ( !uidStr.isEmpty() ) |
82 | // setUid( uidStr.toInt() ); | 81 | // setUid( uidStr.toInt() ); |
83 | } | 82 | } |
@@ -1441,66 +1440,68 @@ void OContact::writeVCard( const QString &filename, const OContact &contact) | |||
1441 | QFileDirect f( filename.utf8().data() ); | 1440 | QFileDirect f( filename.utf8().data() ); |
1442 | if ( !f.open( IO_WriteOnly ) ) { | 1441 | if ( !f.open( IO_WriteOnly ) ) { |
1443 | qWarning("Unable to open vcard write"); | 1442 | qWarning("Unable to open vcard write"); |
1444 | return; | 1443 | return; |
1445 | } | 1444 | } |
1446 | 1445 | ||
1447 | VObject *obj = createVObject( contact ); | 1446 | VObject *obj = createVObject( contact ); |
1448 | writeVObject( f.directHandle() , obj ); | 1447 | writeVObject( f.directHandle() , obj ); |
1449 | cleanVObject( obj ); | 1448 | cleanVObject( obj ); |
1450 | 1449 | ||
1451 | cleanStrTbl(); | 1450 | cleanStrTbl(); |
1452 | } | 1451 | } |
1453 | 1452 | ||
1454 | /*! | 1453 | /*! |
1455 | Returns the set of contacts read as VCards from the file \a filename. | 1454 | Returns the set of contacts read as VCards from the file \a filename. |
1456 | */ | 1455 | */ |
1457 | QValueList<OContact> OContact::readVCard( const QString &filename ) | 1456 | QValueList<OContact> OContact::readVCard( const QString &filename ) |
1458 | { | 1457 | { |
1459 | qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); | 1458 | qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); |
1460 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); | 1459 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); |
1461 | 1460 | ||
1462 | qDebug("vobject = %p", obj ); | 1461 | qDebug("vobject = %p", obj ); |
1463 | 1462 | ||
1464 | QValueList<OContact> contacts; | 1463 | QValueList<OContact> contacts; |
1465 | 1464 | ||
1466 | while ( obj ) { | 1465 | while ( obj ) { |
1467 | OContact con = parseVObject( obj ); | 1466 | OContact con = parseVObject( obj ); |
1468 | /* | 1467 | /* |
1469 | * if uid is 0 assign a new one | 1468 | * if uid is 0 assign a new one |
1470 | * this at least happens on | 1469 | * this at least happens on |
1471 | * Nokia6210 | 1470 | * Nokia6210 |
1472 | */ | 1471 | */ |
1473 | if ( con.uid() == 0 ) | 1472 | if ( con.uid() == 0 ){ |
1474 | con.setUid( 1 ); | 1473 | con.setUid( 1 ); |
1474 | qWarning("assigned new uid %d",con.uid() ); | ||
1475 | } | ||
1475 | 1476 | ||
1476 | contacts.append(con ); | 1477 | contacts.append(con ); |
1477 | 1478 | ||
1478 | VObject *t = obj; | 1479 | VObject *t = obj; |
1479 | obj = nextVObjectInList(obj); | 1480 | obj = nextVObjectInList(obj); |
1480 | cleanVObject( t ); | 1481 | cleanVObject( t ); |
1481 | } | 1482 | } |
1482 | 1483 | ||
1483 | return contacts; | 1484 | return contacts; |
1484 | } | 1485 | } |
1485 | 1486 | ||
1486 | /*! | 1487 | /*! |
1487 | Returns TRUE if the contact matches the regular expression \a regexp. | 1488 | Returns TRUE if the contact matches the regular expression \a regexp. |
1488 | Otherwise returns FALSE. | 1489 | Otherwise returns FALSE. |
1489 | */ | 1490 | */ |
1490 | bool OContact::match( const QString ®exp ) const | 1491 | bool OContact::match( const QString ®exp ) const |
1491 | { | 1492 | { |
1492 | return match(QRegExp(regexp)); | 1493 | return match(QRegExp(regexp)); |
1493 | } | 1494 | } |
1494 | 1495 | ||
1495 | /*! | 1496 | /*! |
1496 | \overload | 1497 | \overload |
1497 | Returns TRUE if the contact matches the regular expression \a regexp. | 1498 | Returns TRUE if the contact matches the regular expression \a regexp. |
1498 | Otherwise returns FALSE. | 1499 | Otherwise returns FALSE. |
1499 | */ | 1500 | */ |
1500 | bool OContact::match( const QRegExp &r ) const | 1501 | bool OContact::match( const QRegExp &r ) const |
1501 | { | 1502 | { |
1502 | bool match; | 1503 | bool match; |
1503 | match = false; | 1504 | match = false; |
1504 | QMap<int, QString>::ConstIterator it; | 1505 | QMap<int, QString>::ConstIterator it; |
1505 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { | 1506 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { |
1506 | if ( (*it).find( r ) > -1 ) { | 1507 | if ( (*it).find( r ) > -1 ) { |
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h index 038a59f..81ac1c1 100644 --- a/libopie2/opiepim/ocontact.h +++ b/libopie2/opiepim/ocontact.h | |||
@@ -171,72 +171,68 @@ public: | |||
171 | //personal | 171 | //personal |
172 | QString spouse() const { return find( Qtopia::Spouse ); } | 172 | QString spouse() const { return find( Qtopia::Spouse ); } |
173 | QString gender() const { return find( Qtopia::Gender ); } | 173 | QString gender() const { return find( Qtopia::Gender ); } |
174 | QDate birthday() const; | 174 | QDate birthday() const; |
175 | QDate anniversary() const; | 175 | QDate anniversary() const; |
176 | QString nickname() const { return find( Qtopia::Nickname ); } | 176 | QString nickname() const { return find( Qtopia::Nickname ); } |
177 | QString children() const { return find( Qtopia::Children ); } | 177 | QString children() const { return find( Qtopia::Children ); } |
178 | QStringList childrenList() const; | 178 | QStringList childrenList() const; |
179 | 179 | ||
180 | // other | 180 | // other |
181 | QString notes() const { return find( Qtopia::Notes ); } | 181 | QString notes() const { return find( Qtopia::Notes ); } |
182 | QString groups() const { return find( Qtopia::Groups ); } | 182 | QString groups() const { return find( Qtopia::Groups ); } |
183 | QStringList groupList() const; | 183 | QStringList groupList() const; |
184 | 184 | ||
185 | // // custom | 185 | // // custom |
186 | // const QString &customField( const QString &key ) | 186 | // const QString &customField( const QString &key ) |
187 | // { return find( Custom- + key ); } | 187 | // { return find( Custom- + key ); } |
188 | 188 | ||
189 | static QStringList fields(); | 189 | static QStringList fields(); |
190 | static QStringList trfields(); | 190 | static QStringList trfields(); |
191 | static QStringList untrfields(); | 191 | static QStringList untrfields(); |
192 | 192 | ||
193 | QString toRichText() const; | 193 | QString toRichText() const; |
194 | QMap<int, QString> toMap() const; | 194 | QMap<int, QString> toMap() const; |
195 | QString field( int key ) const { return find( key ); } | 195 | QString field( int key ) const { return find( key ); } |
196 | 196 | ||
197 | 197 | ||
198 | // journaling... | 198 | // journaling... |
199 | void saveJournal( journal_action action, const QString &key = QString::null ); | 199 | void saveJournal( journal_action action, const QString &key = QString::null ); |
200 | void save( QString &buf ) const; | 200 | void save( QString &buf ) const; |
201 | 201 | ||
202 | void setUid( int i ) | 202 | void setUid( int i ) |
203 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } | 203 | { OPimRecord::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } |
204 | 204 | ||
205 | QString toShortText()const; | 205 | QString toShortText()const; |
206 | QString OContact::type()const; | 206 | QString OContact::type()const; |
207 | QMap<QString,QString> OContact::toExtraMap() const; | 207 | QMap<QString,QString> OContact::toExtraMap() const; |
208 | class QString OContact::recordField(int) const; | 208 | class QString OContact::recordField(int) const; |
209 | 209 | ||
210 | // Why private ? (eilers,se) | 210 | // Why private ? (eilers,se) |
211 | QString emailSeparator() const { return " "; } | 211 | QString emailSeparator() const { return " "; } |
212 | // the emails should be seperated by a comma | 212 | // the emails should be seperated by a comma |
213 | void setEmails( const QString &v ); | 213 | void setEmails( const QString &v ); |
214 | QString emails() const { return find( Qtopia::Emails ); } | 214 | QString emails() const { return find( Qtopia::Emails ); } |
215 | 215 | ||
216 | 216 | ||
217 | private: | 217 | private: |
218 | friend class AbEditor; | 218 | friend class AbEditor; |
219 | friend class AbTable; | 219 | friend class AbTable; |
220 | friend class AddressBookAccessPrivate; | 220 | friend class AddressBookAccessPrivate; |
221 | friend class XMLIO; | 221 | friend class XMLIO; |
222 | 222 | ||
223 | void insert( int key, const QString &value ); | 223 | void insert( int key, const QString &value ); |
224 | void replace( int key, const QString &value ); | 224 | void replace( int key, const QString &value ); |
225 | QString find( int key ) const; | 225 | QString find( int key ) const; |
226 | 226 | ||
227 | QString displayAddress( const QString &street, | 227 | QString displayAddress( const QString &street, |
228 | const QString &city, | 228 | const QString &city, |
229 | const QString &state, | 229 | const QString &state, |
230 | const QString &zip, | 230 | const QString &zip, |
231 | const QString &country ) const; | 231 | const QString &country ) const; |
232 | 232 | ||
233 | Qtopia::UidGen &uidGen() { return sUidGen; } | ||
234 | |||
235 | |||
236 | static Qtopia::UidGen sUidGen; | ||
237 | QMap<int, QString> mMap; | 233 | QMap<int, QString> mMap; |
238 | ContactPrivate *d; | 234 | ContactPrivate *d; |
239 | }; | 235 | }; |
240 | 236 | ||
241 | 237 | ||
242 | #endif | 238 | #endif |