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.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index c1e06c8..48a74d0 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -13,101 +13,103 @@
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#define QTOPIA_INTERNAL_CONTACT_MRE 30#define QTOPIA_INTERNAL_CONTACT_MRE
31 31
32#include "opimcontact.h" 32#include "opimcontact.h"
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/opimresolver.h> 35#include <opie2/opimresolver.h>
36#include <opie2/opimdateconversion.h> 36#include <opie2/opimdateconversion.h>
37#include <opie2/odebug.h>
38
37#include <qpe/stringutil.h> 39#include <qpe/stringutil.h>
38#include <qpe/timestring.h> 40#include <qpe/timestring.h>
39#include <qpe/config.h> 41#include <qpe/config.h>
40 42
41/* QT */ 43/* QT */
42#include <qstylesheet.h> 44#include <qstylesheet.h>
43 45
44/* STD */ 46/* STD */
45#include <stdio.h> 47#include <stdio.h>
46 48
47/*! 49/*!
48 \class Contact contact.h 50 \class Contact contact.h
49 \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.
50 52
51 This data includes information the name of the person, contact 53 This data includes information the name of the person, contact
52 information, and business information such as deparment and job title. 54 information, and business information such as deparment and job title.
53 55
54 \ingroup qtopiaemb 56 \ingroup qtopiaemb
55 \ingroup qtopiadesktop 57 \ingroup qtopiadesktop
56*/ 58*/
57 59
58 60
59namespace Opie 61namespace Opie
60{ 62{
61/*! 63/*!
62 Creates a new, empty contact. 64 Creates a new, empty contact.
63*/ 65*/
64OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 ) 66OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
65{} 67{}
66 68
67/*! 69/*!
68 \internal 70 \internal
69 Creates a new contact. The properties of the contact are 71 Creates a new contact. The properties of the contact are
70 set from \a fromMap. 72 set from \a fromMap.
71*/ 73*/
72OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 ) 74OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 )
73{ 75{
74 QString cats = mMap[ Qtopia::AddressCategory ]; 76 QString cats = mMap[ Qtopia::AddressCategory ];
75 if ( !cats.isEmpty() ) 77 if ( !cats.isEmpty() )
76 setCategories( idsFromString( cats ) ); 78 setCategories( idsFromString( cats ) );
77 79
78 QString uidStr = find( Qtopia::AddressUid ); 80 QString uidStr = find( Qtopia::AddressUid );
79 81
80 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) 82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
81 { 83 {
82 qWarning( "Invalid UID found. Generate new one.." ); 84 owarn << "Invalid UID found. Generate new one.." << oendl;
83 setUid( uidGen().generate() ); 85 setUid( uidGen().generate() );
84 } 86 }
85 else 87 else
86 setUid( uidStr.toInt() ); 88 setUid( uidStr.toInt() );
87 89
88 // if ( !uidStr.isEmpty() ) 90 // if ( !uidStr.isEmpty() )
89 // setUid( uidStr.toInt() ); 91 // setUid( uidStr.toInt() );
90} 92}
91 93
92/*! 94/*!
93 Destroys a contact. 95 Destroys a contact.
94*/ 96*/
95OPimContact::~OPimContact() 97OPimContact::~OPimContact()
96{} 98{}
97 99
98/*! \fn void OPimContact::setTitle( const QString &str ) 100/*! \fn void OPimContact::setTitle( const QString &str )
99 Sets the title of the contact to \a str. 101 Sets the title of the contact to \a str.
100*/ 102*/
101 103
102/*! \fn void OPimContact::setFirstName( const QString &str ) 104/*! \fn void OPimContact::setFirstName( const QString &str )
103 Sets the first name of the contact to \a str. 105 Sets the first name of the contact to \a str.
104*/ 106*/
105 107
106/*! \fn void OPimContact::setMiddleName( const QString &str ) 108/*! \fn void OPimContact::setMiddleName( const QString &str )
107 Sets the middle name of the contact to \a str. 109 Sets the middle name of the contact to \a str.
108*/ 110*/
109 111
110/*! \fn void OPimContact::setLastName( const QString &str ) 112/*! \fn void OPimContact::setLastName( const QString &str )
111 Sets the last name of the contact to \a str. 113 Sets the last name of the contact to \a str.
112*/ 114*/
113 115
@@ -910,49 +912,49 @@ QStringList OPimContact::childrenList() const
910 email list 912 email list
911*/ 913*/
912 914
913/*! \fn void OPimContact::clearEmails() 915/*! \fn void OPimContact::clearEmails()
914 916
915 Clears the email list. 917 Clears the email list.
916 */ 918 */
917 919
918/*! \fn void OPimContact::insertEmails( const QStringList &emailList ) 920/*! \fn void OPimContact::insertEmails( const QStringList &emailList )
919 921
920 Appends the \a emailList to the exiting email list 922 Appends the \a emailList to the exiting email list
921 */ 923 */
922 924
923/*! 925/*!
924 Returns a list of email addresses belonging to the contact, including 926 Returns a list of email addresses belonging to the contact, including
925 the default email address. 927 the default email address.
926*/ 928*/
927QStringList OPimContact::emailList() const 929QStringList OPimContact::emailList() const
928{ 930{
929 QString emailStr = emails(); 931 QString emailStr = emails();
930 932
931 QStringList r; 933 QStringList r;
932 if ( !emailStr.isEmpty() ) 934 if ( !emailStr.isEmpty() )
933 { 935 {
934 qDebug( " emailstr " ); 936 odebug << " emailstr " << oendl;
935 QStringList l = QStringList::split( emailSeparator(), emailStr ); 937 QStringList l = QStringList::split( emailSeparator(), emailStr );
936 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 938 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
937 r += ( *it ).simplifyWhiteSpace(); 939 r += ( *it ).simplifyWhiteSpace();
938 } 940 }
939 941
940 return r; 942 return r;
941} 943}
942 944
943/*! 945/*!
944 \overload 946 \overload
945 947
946 Generates the string for the contact to be filed as from the first, 948 Generates the string for the contact to be filed as from the first,
947 middle and last name of the contact. 949 middle and last name of the contact.
948*/ 950*/
949void OPimContact::setFileAs() 951void OPimContact::setFileAs()
950{ 952{
951 QString lastName, firstName, middleName, fileas; 953 QString lastName, firstName, middleName, fileas;
952 954
953 lastName = find( Qtopia::LastName ); 955 lastName = find( Qtopia::LastName );
954 firstName = find( Qtopia::FirstName ); 956 firstName = find( Qtopia::FirstName );
955 middleName = find( Qtopia::MiddleName ); 957 middleName = find( Qtopia::MiddleName );
956 if ( !lastName.isEmpty() && !firstName.isEmpty() 958 if ( !lastName.isEmpty() && !firstName.isEmpty()
957 && !middleName.isEmpty() ) 959 && !middleName.isEmpty() )
958 fileas = lastName + ", " + firstName + " " + middleName; 960 fileas = lastName + ", " + firstName + " " + middleName;
@@ -1115,172 +1117,172 @@ QString OPimContact::toShortText() const
1115QString OPimContact::type() const 1117QString OPimContact::type() const
1116{ 1118{
1117 return QString::fromLatin1( "OPimContact" ); 1119 return QString::fromLatin1( "OPimContact" );
1118} 1120}
1119 1121
1120 1122
1121class QString OPimContact::recordField( int pos ) const 1123class QString OPimContact::recordField( int pos ) const
1122{ 1124{
1123 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1125 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1124 return SLFIELDS[ pos ]; 1126 return SLFIELDS[ pos ];
1125} 1127}
1126 1128
1127// In future releases, we should store birthday and anniversary 1129// In future releases, we should store birthday and anniversary
1128// internally as QDate instead of QString ! 1130// internally as QDate instead of QString !
1129// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1131// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1130 1132
1131/*! \fn void OPimContact::setBirthday( const QDate& date ) 1133/*! \fn void OPimContact::setBirthday( const QDate& date )
1132 Sets the birthday for the contact to \a date. If date is null 1134 Sets the birthday for the contact to \a date. If date is null
1133 the current stored date will be removed. 1135 the current stored date will be removed.
1134*/ 1136*/
1135void OPimContact::setBirthday( const QDate &v ) 1137void OPimContact::setBirthday( const QDate &v )
1136{ 1138{
1137 if ( v.isNull() ) 1139 if ( v.isNull() )
1138 { 1140 {
1139 qWarning( "Remove Birthday" ); 1141 owarn << "Remove Birthday" << oendl;
1140 replace( Qtopia::Birthday, QString::null ); 1142 replace( Qtopia::Birthday, QString::null );
1141 return ; 1143 return ;
1142 } 1144 }
1143 1145
1144 if ( v.isValid() ) 1146 if ( v.isValid() )
1145 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) ); 1147 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
1146 1148
1147} 1149}
1148 1150
1149 1151
1150/*! \fn void OPimContact::setAnniversary( const QDate &date ) 1152/*! \fn void OPimContact::setAnniversary( const QDate &date )
1151 Sets the anniversary of the contact to \a date. If date is 1153 Sets the anniversary of the contact to \a date. If date is
1152 null, the current stored date will be removed. 1154 null, the current stored date will be removed.
1153*/ 1155*/
1154void OPimContact::setAnniversary( const QDate &v ) 1156void OPimContact::setAnniversary( const QDate &v )
1155{ 1157{
1156 if ( v.isNull() ) 1158 if ( v.isNull() )
1157 { 1159 {
1158 qWarning( "Remove Anniversary" ); 1160 owarn << "Remove Anniversary" << oendl;
1159 replace( Qtopia::Anniversary, QString::null ); 1161 replace( Qtopia::Anniversary, QString::null );
1160 return ; 1162 return ;
1161 } 1163 }
1162 1164
1163 if ( v.isValid() ) 1165 if ( v.isValid() )
1164 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) ); 1166 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
1165} 1167}
1166 1168
1167 1169
1168/*! \fn QDate OPimContact::birthday() const 1170/*! \fn QDate OPimContact::birthday() const
1169 Returns the birthday of the contact. 1171 Returns the birthday of the contact.
1170*/ 1172*/
1171QDate OPimContact::birthday() const 1173QDate OPimContact::birthday() const
1172{ 1174{
1173 QString str = find( Qtopia::Birthday ); 1175 QString str = find( Qtopia::Birthday );
1174 // qWarning ("Birthday %s", str.latin1() ); 1176 // qWarning ("Birthday %s", str.latin1() );
1175 if ( !str.isEmpty() ) 1177 if ( !str.isEmpty() )
1176 return OPimDateConversion::dateFromString ( str ); 1178 return OPimDateConversion::dateFromString ( str );
1177 else 1179 else
1178 return QDate(); 1180 return QDate();
1179} 1181}
1180 1182
1181 1183
1182/*! \fn QDate OPimContact::anniversary() const 1184/*! \fn QDate OPimContact::anniversary() const
1183 Returns the anniversary of the contact. 1185 Returns the anniversary of the contact.
1184*/ 1186*/
1185QDate OPimContact::anniversary() const 1187QDate OPimContact::anniversary() const
1186{ 1188{
1187 QDate empty; 1189 QDate empty;
1188 QString str = find( Qtopia::Anniversary ); 1190 QString str = find( Qtopia::Anniversary );
1189 // qWarning ("Anniversary %s", str.latin1() ); 1191 // qWarning ("Anniversary %s", str.latin1() );
1190 if ( !str.isEmpty() ) 1192 if ( !str.isEmpty() )
1191 return OPimDateConversion::dateFromString ( str ); 1193 return OPimDateConversion::dateFromString ( str );
1192 else 1194 else
1193 return empty; 1195 return empty;
1194} 1196}
1195 1197
1196 1198
1197void OPimContact::insertEmail( const QString &v ) 1199void OPimContact::insertEmail( const QString &v )
1198{ 1200{
1199 //qDebug("insertEmail %s", v.latin1()); 1201 //odebug << "insertEmail " << v << "" << oendl;
1200 QString e = v.simplifyWhiteSpace(); 1202 QString e = v.simplifyWhiteSpace();
1201 QString def = defaultEmail(); 1203 QString def = defaultEmail();
1202 1204
1203 // if no default, set it as the default email and don't insert 1205 // if no default, set it as the default email and don't insert
1204 if ( def.isEmpty() ) 1206 if ( def.isEmpty() )
1205 { 1207 {
1206 setDefaultEmail( e ); // will insert into the list for us 1208 setDefaultEmail( e ); // will insert into the list for us
1207 return ; 1209 return ;
1208 } 1210 }
1209 1211
1210 // otherwise, insert assuming doesn't already exist 1212 // otherwise, insert assuming doesn't already exist
1211 QString emailsStr = find( Qtopia::Emails ); 1213 QString emailsStr = find( Qtopia::Emails );
1212 if ( emailsStr.contains( e ) ) 1214 if ( emailsStr.contains( e ) )
1213 return ; 1215 return ;
1214 if ( !emailsStr.isEmpty() ) 1216 if ( !emailsStr.isEmpty() )
1215 emailsStr += emailSeparator(); 1217 emailsStr += emailSeparator();
1216 emailsStr += e; 1218 emailsStr += e;
1217 replace( Qtopia::Emails, emailsStr ); 1219 replace( Qtopia::Emails, emailsStr );
1218} 1220}
1219 1221
1220 1222
1221 void OPimContact::removeEmail( const QString &v ) 1223 void OPimContact::removeEmail( const QString &v )
1222{ 1224{
1223 QString e = v.simplifyWhiteSpace(); 1225 QString e = v.simplifyWhiteSpace();
1224 QString def = defaultEmail(); 1226 QString def = defaultEmail();
1225 QString emailsStr = find( Qtopia::Emails ); 1227 QString emailsStr = find( Qtopia::Emails );
1226 QStringList emails = emailList(); 1228 QStringList emails = emailList();
1227 1229
1228 // otherwise, must first contain it 1230 // otherwise, must first contain it
1229 if ( !emailsStr.contains( e ) ) 1231 if ( !emailsStr.contains( e ) )
1230 return ; 1232 return ;
1231 1233
1232 // remove it 1234 // remove it
1233 //qDebug(" removing email from list %s", e.latin1()); 1235 //odebug << " removing email from list " << e << "" << oendl;
1234 emails.remove( e ); 1236 emails.remove( e );
1235 // reset the string 1237 // reset the string
1236 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator 1238 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
1237 replace( Qtopia::Emails, emailsStr ); 1239 replace( Qtopia::Emails, emailsStr );
1238 1240
1239 // if default, then replace the default email with the first one 1241 // if default, then replace the default email with the first one
1240 if ( def == e ) 1242 if ( def == e )
1241 { 1243 {
1242 //qDebug("removeEmail is default; setting new default"); 1244 //odebug << "removeEmail is default; setting new default" << oendl;
1243 if ( !emails.count() ) 1245 if ( !emails.count() )
1244 clearEmails(); 1246 clearEmails();
1245 else // setDefaultEmail will remove e from the list 1247 else // setDefaultEmail will remove e from the list
1246 setDefaultEmail( emails.first() ); 1248 setDefaultEmail( emails.first() );
1247 } 1249 }
1248} 1250}
1249 1251
1250 1252
1251void OPimContact::clearEmails() 1253void OPimContact::clearEmails()
1252{ 1254{
1253 mMap.remove( Qtopia::DefaultEmail ); 1255 mMap.remove( Qtopia::DefaultEmail );
1254 mMap.remove( Qtopia::Emails ); 1256 mMap.remove( Qtopia::Emails );
1255} 1257}
1256 1258
1257 1259
1258void OPimContact::setDefaultEmail( const QString &v ) 1260void OPimContact::setDefaultEmail( const QString &v )
1259{ 1261{
1260 QString e = v.simplifyWhiteSpace(); 1262 QString e = v.simplifyWhiteSpace();
1261 1263
1262 //qDebug("OPimContact::setDefaultEmail %s", e.latin1()); 1264 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl;
1263 replace( Qtopia::DefaultEmail, e ); 1265 replace( Qtopia::DefaultEmail, e );
1264 1266
1265 if ( !e.isEmpty() ) 1267 if ( !e.isEmpty() )
1266 insertEmail( e ); 1268 insertEmail( e );
1267 1269
1268} 1270}
1269 1271
1270 1272
1271void OPimContact::insertEmails( const QStringList &v ) 1273void OPimContact::insertEmails( const QStringList &v )
1272{ 1274{
1273 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1275 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1274 insertEmail( *it ); 1276 insertEmail( *it );
1275} 1277}
1276 1278
1277 1279
1278int OPimContact::rtti() const 1280int OPimContact::rtti() const
1279{ 1281{
1280 return OPimResolver::AddressBook; 1282 return OPimResolver::AddressBook;
1281} 1283}
1282 1284
1283 1285
1284void OPimContact::setUid( int i ) 1286void OPimContact::setUid( int i )
1285{ 1287{
1286 OPimRecord::setUid( i ); 1288 OPimRecord::setUid( i );