summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimcontact.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimcontact.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index 36e9a93..64f195b 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -36,97 +36,96 @@
36#include <opie2/opimdateconversion.h> 36#include <opie2/opimdateconversion.h>
37#include <opie2/odebug.h> 37#include <opie2/odebug.h>
38 38
39#include <qpe/stringutil.h> 39#include <qpe/stringutil.h>
40#include <qpe/timestring.h> 40#include <qpe/timestring.h>
41#include <qpe/config.h> 41#include <qpe/config.h>
42 42
43/* QT */ 43/* QT */
44#include <qstylesheet.h> 44#include <qstylesheet.h>
45 45
46/* STD */ 46/* STD */
47#include <stdio.h> 47#include <stdio.h>
48 48
49/*! 49/*!
50 \class Contact contact.h 50 \class Contact contact.h
51 \brief The Contact class holds the data of an address book entry. 51 \brief The Contact class holds the data of an address book entry.
52 52
53 This data includes information the name of the person, contact 53 This data includes information the name of the person, contact
54 information, and business information such as deparment and job title. 54 information, and business information such as deparment and job title.
55 55
56 \ingroup qtopiaemb 56 \ingroup qtopiaemb
57 \ingroup qtopiadesktop 57 \ingroup qtopiadesktop
58*/ 58*/
59 59
60 60
61namespace Opie 61namespace Opie
62{ 62{
63/*! 63/*!
64 Creates a new, empty contact. 64 Creates a new, empty contact.
65*/ 65*/
66OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 ) 66OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
67{} 67{}
68 68
69/*! 69/*!
70 \internal 70 \internal
71 Creates a new contact. The properties of the contact are 71 Creates a new contact. The properties of the contact are
72 set from \a fromMap. 72 set from \a fromMap.
73*/ 73*/
74OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 ) 74OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 )
75{ 75{
76 QString cats = mMap[ Qtopia::AddressCategory ]; 76 QString cats = mMap[ Qtopia::AddressCategory ];
77 if ( !cats.isEmpty() ) 77 if ( !cats.isEmpty() )
78 setCategories( idsFromString( cats ) ); 78 setCategories( idsFromString( cats ) );
79 79
80 QString uidStr = find( Qtopia::AddressUid ); 80 QString uidStr = find( Qtopia::AddressUid );
81 81
82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) 82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
83 { 83 {
84 owarn << "Invalid UID found. Generate new one.." << oendl;
85 setUid( uidGen().generate() ); 84 setUid( uidGen().generate() );
86 } 85 }
87 else 86 else
88 setUid( uidStr.toInt() ); 87 setUid( uidStr.toInt() );
89 88
90 // if ( !uidStr.isEmpty() ) 89 // if ( !uidStr.isEmpty() )
91 // setUid( uidStr.toInt() ); 90 // setUid( uidStr.toInt() );
92} 91}
93 92
94/*! 93/*!
95 Destroys a contact. 94 Destroys a contact.
96*/ 95*/
97OPimContact::~OPimContact() 96OPimContact::~OPimContact()
98{} 97{}
99 98
100/*! \fn void OPimContact::setTitle( const QString &str ) 99/*! \fn void OPimContact::setTitle( const QString &str )
101 Sets the title of the contact to \a str. 100 Sets the title of the contact to \a str.
102*/ 101*/
103 102
104/*! \fn void OPimContact::setFirstName( const QString &str ) 103/*! \fn void OPimContact::setFirstName( const QString &str )
105 Sets the first name of the contact to \a str. 104 Sets the first name of the contact to \a str.
106*/ 105*/
107 106
108/*! \fn void OPimContact::setMiddleName( const QString &str ) 107/*! \fn void OPimContact::setMiddleName( const QString &str )
109 Sets the middle name of the contact to \a str. 108 Sets the middle name of the contact to \a str.
110*/ 109*/
111 110
112/*! \fn void OPimContact::setLastName( const QString &str ) 111/*! \fn void OPimContact::setLastName( const QString &str )
113 Sets the last name of the contact to \a str. 112 Sets the last name of the contact to \a str.
114*/ 113*/
115 114
116/*! \fn void OPimContact::setSuffix( const QString &str ) 115/*! \fn void OPimContact::setSuffix( const QString &str )
117 Sets the suffix of the contact to \a str. 116 Sets the suffix of the contact to \a str.
118*/ 117*/
119 118
120/*! \fn void OPimContact::setFileAs( const QString &str ) 119/*! \fn void OPimContact::setFileAs( const QString &str )
121 Sets the contact to filed as \a str. 120 Sets the contact to filed as \a str.
122*/ 121*/
123 122
124/*! \fn void OPimContact::setDefaultEmail( const QString &str ) 123/*! \fn void OPimContact::setDefaultEmail( const QString &str )
125 Sets the default email of the contact to \a str. 124 Sets the default email of the contact to \a str.
126*/ 125*/
127 126
128/*! \fn void OPimContact::setHomeStreet( const QString &str ) 127/*! \fn void OPimContact::setHomeStreet( const QString &str )
129 Sets the home street address of the contact to \a str. 128 Sets the home street address of the contact to \a str.
130*/ 129*/
131 130
132/*! \fn void OPimContact::setHomeCity( const QString &str ) 131/*! \fn void OPimContact::setHomeCity( const QString &str )
@@ -1093,199 +1092,214 @@ bool OPimContact::match( const QRegExp &r ) const
1093{ 1092{
1094 setLastHitField( -1 ); 1093 setLastHitField( -1 );
1095 bool match; 1094 bool match;
1096 match = false; 1095 match = false;
1097 QMap<int, QString>::ConstIterator it; 1096 QMap<int, QString>::ConstIterator it;
1098 for ( it = mMap.begin(); it != mMap.end(); ++it ) 1097 for ( it = mMap.begin(); it != mMap.end(); ++it )
1099 { 1098 {
1100 if ( ( *it ).find( r ) > -1 ) 1099 if ( ( *it ).find( r ) > -1 )
1101 { 1100 {
1102 setLastHitField( it.key() ); 1101 setLastHitField( it.key() );
1103 match = true; 1102 match = true;
1104 break; 1103 break;
1105 } 1104 }
1106 } 1105 }
1107 return match; 1106 return match;
1108} 1107}
1109 1108
1110 1109
1111QString OPimContact::toShortText() const 1110QString OPimContact::toShortText() const
1112{ 1111{
1113 return ( fullName() ); 1112 return ( fullName() );
1114} 1113}
1115 1114
1116 1115
1117QString OPimContact::type() const 1116QString OPimContact::type() const
1118{ 1117{
1119 return QString::fromLatin1( "OPimContact" ); 1118 return QString::fromLatin1( "OPimContact" );
1120} 1119}
1121 1120
1122 1121
1123class QString OPimContact::recordField( int pos ) const 1122class QString OPimContact::recordField( int pos ) const
1124{ 1123{
1125 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1124 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1126 return SLFIELDS[ pos ]; 1125 return SLFIELDS[ pos ];
1127} 1126}
1128 1127
1129// In future releases, we should store birthday and anniversary 1128// In future releases, we should store birthday and anniversary
1130// internally as QDate instead of QString ! 1129// internally as QDate instead of QString !
1131// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1130// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1132 1131
1133/*! \fn void OPimContact::setBirthday( const QDate& date ) 1132/*! \fn void OPimContact::setBirthday( const QDate& date )
1134 Sets the birthday for the contact to \a date. If date is null 1133 Sets the birthday for the contact to \a date. If date is null
1135 the current stored date will be removed. 1134 the current stored date will be removed.
1136*/ 1135*/
1137void OPimContact::setBirthday( const QDate &v ) 1136void OPimContact::setBirthday( const QDate &v )
1138{ 1137{
1139 if ( v.isNull() ) 1138 if ( v.isNull() )
1140 { 1139 {
1141 owarn << "Remove Birthday" << oendl;
1142 replace( Qtopia::Birthday, QString::null ); 1140 replace( Qtopia::Birthday, QString::null );
1143 return ; 1141 return ;
1144 } 1142 }
1145 1143
1146 if ( v.isValid() ) 1144 if ( v.isValid() )
1147 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) ); 1145 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
1148 1146
1149} 1147}
1150 1148
1151 1149
1152/*! \fn void OPimContact::setAnniversary( const QDate &date ) 1150/*! \fn void OPimContact::setAnniversary( const QDate &date )
1153 Sets the anniversary of the contact to \a date. If date is 1151 Sets the anniversary of the contact to \a date. If date is
1154 null, the current stored date will be removed. 1152 null, the current stored date will be removed.
1155*/ 1153*/
1156void OPimContact::setAnniversary( const QDate &v ) 1154void OPimContact::setAnniversary( const QDate &v )
1157{ 1155{
1158 if ( v.isNull() ) 1156 if ( v.isNull() )
1159 { 1157 {
1160 owarn << "Remove Anniversary" << oendl;
1161 replace( Qtopia::Anniversary, QString::null ); 1158 replace( Qtopia::Anniversary, QString::null );
1162 return ; 1159 return ;
1163 } 1160 }
1164 1161
1165 if ( v.isValid() ) 1162 if ( v.isValid() )
1166 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) ); 1163 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
1167} 1164}
1168 1165
1169 1166
1170/*! \fn QDate OPimContact::birthday() const 1167/*! \fn QDate OPimContact::birthday() const
1171 Returns the birthday of the contact. 1168 Returns the birthday of the contact.
1172*/ 1169*/
1173QDate OPimContact::birthday() const 1170QDate OPimContact::birthday() const
1174{ 1171{
1175 QString str = find( Qtopia::Birthday ); 1172 QString str = find( Qtopia::Birthday );
1176 // owarn << "Birthday " << str << oendl;
1177 if ( !str.isEmpty() ) 1173 if ( !str.isEmpty() )
1178 return OPimDateConversion::dateFromString ( str ); 1174 return OPimDateConversion::dateFromString ( str );
1179 else 1175 else
1180 return QDate(); 1176 return QDate();
1181} 1177}
1182 1178
1183 1179
1184/*! \fn QDate OPimContact::anniversary() const 1180/*! \fn QDate OPimContact::anniversary() const
1185 Returns the anniversary of the contact. 1181 Returns the anniversary of the contact.
1186*/ 1182*/
1187QDate OPimContact::anniversary() const 1183QDate OPimContact::anniversary() const
1188{ 1184{
1189 QDate empty; 1185 QDate empty;
1190 QString str = find( Qtopia::Anniversary ); 1186 QString str = find( Qtopia::Anniversary );
1191 // owarn << "Anniversary " << str << oendl;
1192 if ( !str.isEmpty() ) 1187 if ( !str.isEmpty() )
1193 return OPimDateConversion::dateFromString ( str ); 1188 return OPimDateConversion::dateFromString ( str );
1194 else 1189 else
1195 return empty; 1190 return empty;
1196} 1191}
1197 1192
1198 1193
1199void OPimContact::insertEmail( const QString &v ) 1194void OPimContact::insertEmail( const QString &v )
1200{ 1195{
1201 //odebug << "insertEmail " << v << "" << oendl; 1196 //odebug << "insertEmail " << v << "" << oendl;
1202 QString e = v.simplifyWhiteSpace(); 1197 QString e = v.simplifyWhiteSpace();
1203 QString def = defaultEmail(); 1198 QString def = defaultEmail();
1204 1199
1205 // if no default, set it as the default email and don't insert 1200 // if no default, set it as the default email and don't insert
1206 if ( def.isEmpty() ) 1201 if ( def.isEmpty() )
1207 { 1202 {
1208 setDefaultEmail( e ); // will insert into the list for us 1203 setDefaultEmail( e ); // will insert into the list for us
1209 return ; 1204 return ;
1210 } 1205 }
1211 1206
1212 // otherwise, insert assuming doesn't already exist 1207 // otherwise, insert assuming doesn't already exist
1213 QString emailsStr = find( Qtopia::Emails ); 1208 QString emailsStr = find( Qtopia::Emails );
1214 if ( emailsStr.contains( e ) ) 1209 if ( emailsStr.contains( e ) )
1215 return ; 1210 return ;
1216 if ( !emailsStr.isEmpty() ) 1211 if ( !emailsStr.isEmpty() )
1217 emailsStr += emailSeparator(); 1212 emailsStr += emailSeparator();
1218 emailsStr += e; 1213 emailsStr += e;
1219 replace( Qtopia::Emails, emailsStr ); 1214 replace( Qtopia::Emails, emailsStr );
1220} 1215}
1221 1216
1222 1217
1223 void OPimContact::removeEmail( const QString &v ) 1218 void OPimContact::removeEmail( const QString &v )
1224{ 1219{
1225 QString e = v.simplifyWhiteSpace(); 1220 QString e = v.simplifyWhiteSpace();
1226 QString def = defaultEmail(); 1221 QString def = defaultEmail();
1227 QString emailsStr = find( Qtopia::Emails ); 1222 QString emailsStr = find( Qtopia::Emails );
1228 QStringList emails = emailList(); 1223 QStringList emails = emailList();
1229 1224
1230 // otherwise, must first contain it 1225 // otherwise, must first contain it
1231 if ( !emailsStr.contains( e ) ) 1226 if ( !emailsStr.contains( e ) )
1232 return ; 1227 return ;
1233 1228
1234 // remove it 1229 // remove it
1235 //odebug << " removing email from list " << e << "" << oendl; 1230 //odebug << " removing email from list " << e << "" << oendl;
1236 emails.remove( e ); 1231 emails.remove( e );
1237 // reset the string 1232 // reset the string
1238 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator 1233 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
1239 replace( Qtopia::Emails, emailsStr ); 1234 replace( Qtopia::Emails, emailsStr );
1240 1235
1241 // if default, then replace the default email with the first one 1236 // if default, then replace the default email with the first one
1242 if ( def == e ) 1237 if ( def == e )
1243 { 1238 {
1244 //odebug << "removeEmail is default; setting new default" << oendl; 1239 //odebug << "removeEmail is default; setting new default" << oendl;
1245 if ( !emails.count() ) 1240 if ( !emails.count() )
1246 clearEmails(); 1241 clearEmails();
1247 else // setDefaultEmail will remove e from the list 1242 else // setDefaultEmail will remove e from the list
1248 setDefaultEmail( emails.first() ); 1243 setDefaultEmail( emails.first() );
1249 } 1244 }
1250} 1245}
1251 1246
1252 1247
1253void OPimContact::clearEmails() 1248void OPimContact::clearEmails()
1254{ 1249{
1255 mMap.remove( Qtopia::DefaultEmail ); 1250 mMap.remove( Qtopia::DefaultEmail );
1256 mMap.remove( Qtopia::Emails ); 1251 mMap.remove( Qtopia::Emails );
1257} 1252}
1258 1253
1259 1254
1260void OPimContact::setDefaultEmail( const QString &v ) 1255void OPimContact::setDefaultEmail( const QString &v )
1261{ 1256{
1262 QString e = v.simplifyWhiteSpace(); 1257 QString e = v.simplifyWhiteSpace();
1263 1258
1264 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl; 1259 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl;
1265 replace( Qtopia::DefaultEmail, e ); 1260 replace( Qtopia::DefaultEmail, e );
1266 1261
1267 if ( !e.isEmpty() ) 1262 if ( !e.isEmpty() )
1268 insertEmail( e ); 1263 insertEmail( e );
1269 1264
1270} 1265}
1271 1266
1272 1267
1273void OPimContact::insertEmails( const QStringList &v ) 1268void OPimContact::insertEmails( const QStringList &v )
1274{ 1269{
1275 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1270 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1276 insertEmail( *it ); 1271 insertEmail( *it );
1277} 1272}
1278 1273
1279 1274
1280int OPimContact::rtti() const 1275int OPimContact::rtti() const
1281{ 1276{
1282 return OPimResolver::AddressBook; 1277 return OPimResolver::AddressBook;
1283} 1278}
1284 1279
1280/**
1281 * \brief Cast to OPimContact or on failure return 0l
1282 *
1283 * This method tries to cast from a OPimRecord to a
1284 * OPimContact it uses. If the OPimRecord is from type
1285 * OPimContact the case will suceed and a pointer to
1286 * OPimContact is returned otherwise a Null Pointer is returned.
1287 *
1288 *
1289 * @see OPimTodo::safeCast()
1290 * @see OPimEvent::safeCast()
1291 * @return Return a OPimContact or a Null Pointer
1292 */
1293OPimContact* OPimContact::safeCast( const OPimRecord* rec ) {
1294 return( rec && rec->rtti() == OPimResolver::AddressBook ) ?
1295 static_cast<OPimContact*>( const_cast<OPimRecord*>(rec) ) :
1296 0l;
1297}
1298
1285 1299
1286void OPimContact::setUid( int i ) 1300void OPimContact::setUid( int i )
1287{ 1301{
1288 OPimRecord::setUid( i ); 1302 OPimRecord::setUid( i );
1289 replace( Qtopia::AddressUid , QString::number( i ) ); 1303 replace( Qtopia::AddressUid , QString::number( i ) );
1290} 1304}
1291} 1305}