summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.cpp41
-rw-r--r--libopie/pim/opimrecord.h4
-rw-r--r--libopie/pim/opimstate.cpp64
-rw-r--r--libopie/pim/opimstate.h44
-rw-r--r--libopie/pim/orecordlist.h2
-rw-r--r--libopie/pim/orecur.cpp9
-rw-r--r--libopie/pim/orecur.h2
-rw-r--r--libopie/pim/otodo.cpp23
-rw-r--r--libopie/pim/otodo.h27
-rw-r--r--libopie2/opiepim/core/opimrecord.h4
-rw-r--r--libopie2/opiepim/core/opimstate.cpp64
-rw-r--r--libopie2/opiepim/core/opimstate.h44
-rw-r--r--libopie2/opiepim/core/orecur.cpp9
-rw-r--r--libopie2/opiepim/core/orecur.h2
-rw-r--r--libopie2/opiepim/ocontact.cpp41
-rw-r--r--libopie2/opiepim/orecordlist.h2
-rw-r--r--libopie2/opiepim/otodo.cpp23
-rw-r--r--libopie2/opiepim/otodo.h27
18 files changed, 388 insertions, 44 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index acd65c4..cd238ef 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -938,716 +938,725 @@ QStringList OContact::trfields()
938 list.append( QObject::tr( "Notes" ) ); 938 list.append( QObject::tr( "Notes" ) );
939 list.append( QObject::tr( "Groups" ) ); 939 list.append( QObject::tr( "Groups" ) );
940 940
941 return list; 941 return list;
942} 942}
943 943
944/*! 944/*!
945 \internal 945 \internal
946 Returns an untranslated list of field names for a contact. 946 Returns an untranslated list of field names for a contact.
947*/ 947*/
948QStringList OContact::untrfields() 948QStringList OContact::untrfields()
949{ 949{
950 QStringList list; 950 QStringList list;
951 951
952 list.append( "Name Title" ); 952 list.append( "Name Title" );
953 list.append( "First Name" ); 953 list.append( "First Name" );
954 list.append( "Middle Name" ); 954 list.append( "Middle Name" );
955 list.append( "Last Name" ); 955 list.append( "Last Name" );
956 list.append( "Suffix" ); 956 list.append( "Suffix" );
957 list.append( "File As" ); 957 list.append( "File As" );
958 958
959 list.append( "Job Title" ); 959 list.append( "Job Title" );
960 list.append( "Department" ); 960 list.append( "Department" );
961 list.append( "Company" ); 961 list.append( "Company" );
962 list.append( "Business Phone" ); 962 list.append( "Business Phone" );
963 list.append( "Business Fax" ); 963 list.append( "Business Fax" );
964 list.append( "Business Mobile" ); 964 list.append( "Business Mobile" );
965 965
966 list.append( "Default Email" ); 966 list.append( "Default Email" );
967 list.append( "Emails" ); 967 list.append( "Emails" );
968 968
969 list.append( "Home Phone" ); 969 list.append( "Home Phone" );
970 list.append( "Home Fax" ); 970 list.append( "Home Fax" );
971 list.append( "Home Mobile" ); 971 list.append( "Home Mobile" );
972 972
973 list.append( "Business Street" ); 973 list.append( "Business Street" );
974 list.append( "Business City" ); 974 list.append( "Business City" );
975 list.append( "Business State" ); 975 list.append( "Business State" );
976 list.append( "Business Zip" ); 976 list.append( "Business Zip" );
977 list.append( "Business Country" ); 977 list.append( "Business Country" );
978 list.append( "Business Pager" ); 978 list.append( "Business Pager" );
979 list.append( "Business WebPage" ); 979 list.append( "Business WebPage" );
980 980
981 list.append( "Office" ); 981 list.append( "Office" );
982 list.append( "Profession" ); 982 list.append( "Profession" );
983 list.append( "Assistant" ); 983 list.append( "Assistant" );
984 list.append( "Manager" ); 984 list.append( "Manager" );
985 985
986 list.append( "Home Street" ); 986 list.append( "Home Street" );
987 list.append( "Home City" ); 987 list.append( "Home City" );
988 list.append( "Home State" ); 988 list.append( "Home State" );
989 list.append( "Home Zip" ); 989 list.append( "Home Zip" );
990 list.append( "Home Country" ); 990 list.append( "Home Country" );
991 list.append( "Home Web Page" ); 991 list.append( "Home Web Page" );
992 992
993 list.append( "Spouse" ); 993 list.append( "Spouse" );
994 list.append( "Gender" ); 994 list.append( "Gender" );
995 list.append( "Birthday" ); 995 list.append( "Birthday" );
996 list.append( "Anniversary" ); 996 list.append( "Anniversary" );
997 list.append( "Nickname" ); 997 list.append( "Nickname" );
998 list.append( "Children" ); 998 list.append( "Children" );
999 999
1000 list.append( "Notes" ); 1000 list.append( "Notes" );
1001 list.append( "Groups" ); 1001 list.append( "Groups" );
1002 1002
1003 return list; 1003 return list;
1004} 1004}
1005 1005
1006/*! 1006/*!
1007 Sets the list of email address for contact to those contained in \a str. 1007 Sets the list of email address for contact to those contained in \a str.
1008 Email address should be separated by ';'s. 1008 Email address should be separated by ';'s.
1009*/ 1009*/
1010void OContact::setEmails( const QString &str ) 1010void OContact::setEmails( const QString &str )
1011{ 1011{
1012 replace( Qtopia::Emails, str ); 1012 replace( Qtopia::Emails, str );
1013 if ( str.isEmpty() ) 1013 if ( str.isEmpty() )
1014 setDefaultEmail( QString::null ); 1014 setDefaultEmail( QString::null );
1015} 1015}
1016 1016
1017/*! 1017/*!
1018 Sets the list of children for the contact to those contained in \a str. 1018 Sets the list of children for the contact to those contained in \a str.
1019*/ 1019*/
1020void OContact::setChildren( const QString &str ) 1020void OContact::setChildren( const QString &str )
1021{ 1021{
1022 replace( Qtopia::Children, str ); 1022 replace( Qtopia::Children, str );
1023} 1023}
1024 1024
1025// vcard conversion code 1025// vcard conversion code
1026/*! 1026/*!
1027 \internal 1027 \internal
1028*/ 1028*/
1029static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 1029static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
1030{ 1030{
1031 VObject *ret = 0; 1031 VObject *ret = 0;
1032 if ( o && !value.isEmpty() ) 1032 if ( o && !value.isEmpty() )
1033 ret = addPropValue( o, prop, value.latin1() ); 1033 ret = addPropValue( o, prop, value.latin1() );
1034 return ret; 1034 return ret;
1035} 1035}
1036 1036
1037/*! 1037/*!
1038 \internal 1038 \internal
1039*/ 1039*/
1040static inline VObject *safeAddProp( VObject *o, const char *prop) 1040static inline VObject *safeAddProp( VObject *o, const char *prop)
1041{ 1041{
1042 VObject *ret = 0; 1042 VObject *ret = 0;
1043 if ( o ) 1043 if ( o )
1044 ret = addProp( o, prop ); 1044 ret = addProp( o, prop );
1045 return ret; 1045 return ret;
1046} 1046}
1047 1047
1048/*! 1048/*!
1049 \internal 1049 \internal
1050*/ 1050*/
1051static VObject *createVObject( const OContact &c ) 1051static VObject *createVObject( const OContact &c )
1052{ 1052{
1053 VObject *vcard = newVObject( VCCardProp ); 1053 VObject *vcard = newVObject( VCCardProp );
1054 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 1054 safeAddPropValue( vcard, VCVersionProp, "2.1" );
1055 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 1055 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
1056 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 1056 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
1057 1057
1058 // full name 1058 // full name
1059 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 1059 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
1060 1060
1061 // name properties 1061 // name properties
1062 VObject *name = safeAddProp( vcard, VCNameProp ); 1062 VObject *name = safeAddProp( vcard, VCNameProp );
1063 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 1063 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
1064 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 1064 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
1065 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 1065 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
1066 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 1066 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
1067 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 1067 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
1068 1068
1069 // home properties 1069 // home properties
1070 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 1070 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
1071 safeAddProp( home_adr, VCHomeProp ); 1071 safeAddProp( home_adr, VCHomeProp );
1072 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 1072 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
1073 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 1073 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
1074 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 1074 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
1075 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 1075 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
1076 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 1076 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
1077 1077
1078 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 1078 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
1079 safeAddProp( home_phone, VCHomeProp ); 1079 safeAddProp( home_phone, VCHomeProp );
1080 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 1080 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
1081 safeAddProp( home_phone, VCHomeProp ); 1081 safeAddProp( home_phone, VCHomeProp );
1082 safeAddProp( home_phone, VCCellularProp ); 1082 safeAddProp( home_phone, VCCellularProp );
1083 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 1083 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
1084 safeAddProp( home_phone, VCHomeProp ); 1084 safeAddProp( home_phone, VCHomeProp );
1085 safeAddProp( home_phone, VCFaxProp ); 1085 safeAddProp( home_phone, VCFaxProp );
1086 1086
1087 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 1087 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
1088 safeAddProp( url, VCHomeProp ); 1088 safeAddProp( url, VCHomeProp );
1089 1089
1090 // work properties 1090 // work properties
1091 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 1091 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
1092 safeAddProp( work_adr, VCWorkProp ); 1092 safeAddProp( work_adr, VCWorkProp );
1093 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 1093 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
1094 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 1094 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
1095 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 1095 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
1096 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 1096 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
1097 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 1097 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
1098 1098
1099 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 1099 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
1100 safeAddProp( work_phone, VCWorkProp ); 1100 safeAddProp( work_phone, VCWorkProp );
1101 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 1101 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
1102 safeAddProp( work_phone, VCWorkProp ); 1102 safeAddProp( work_phone, VCWorkProp );
1103 safeAddProp( work_phone, VCCellularProp ); 1103 safeAddProp( work_phone, VCCellularProp );
1104 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 1104 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
1105 safeAddProp( work_phone, VCWorkProp ); 1105 safeAddProp( work_phone, VCWorkProp );
1106 safeAddProp( work_phone, VCFaxProp ); 1106 safeAddProp( work_phone, VCFaxProp );
1107 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 1107 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
1108 safeAddProp( work_phone, VCWorkProp ); 1108 safeAddProp( work_phone, VCWorkProp );
1109 safeAddProp( work_phone, VCPagerProp ); 1109 safeAddProp( work_phone, VCPagerProp );
1110 1110
1111 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 1111 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
1112 safeAddProp( url, VCWorkProp ); 1112 safeAddProp( url, VCWorkProp );
1113 1113
1114 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 1114 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
1115 safeAddProp( title, VCWorkProp ); 1115 safeAddProp( title, VCWorkProp );
1116 1116
1117 1117
1118 QStringList emails = c.emailList(); 1118 QStringList emails = c.emailList();
1119 emails.prepend( c.defaultEmail() ); 1119 emails.prepend( c.defaultEmail() );
1120 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 1120 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
1121 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 1121 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
1122 safeAddProp( email, VCInternetProp ); 1122 safeAddProp( email, VCInternetProp );
1123 } 1123 }
1124 1124
1125 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 1125 safeAddPropValue( vcard, VCNoteProp, c.notes() );
1126 1126
1127 // Exporting Birthday regarding RFC 2425 (5.8.4) 1127 // Exporting Birthday regarding RFC 2425 (5.8.4)
1128 if ( c.birthday().isValid() ){ 1128 if ( c.birthday().isValid() ){
1129 QString birthd_rfc2425 = QString("%1-%2-%3") 1129 QString birthd_rfc2425 = QString("%1-%2-%3")
1130 .arg( c.birthday().year() ) 1130 .arg( c.birthday().year() )
1131 .arg( c.birthday().month(), 2 ) 1131 .arg( c.birthday().month(), 2 )
1132 .arg( c.birthday().day(), 2 ); 1132 .arg( c.birthday().day(), 2 );
1133 // Now replace spaces with "0"... 1133 // Now replace spaces with "0"...
1134 int pos = 0; 1134 int pos = 0;
1135 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) 1135 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
1136 birthd_rfc2425.replace( pos, 1, "0" ); 1136 birthd_rfc2425.replace( pos, 1, "0" );
1137 1137
1138 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); 1138 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
1139 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); 1139 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
1140 } 1140 }
1141 1141
1142 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 1142 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
1143 VObject *org = safeAddProp( vcard, VCOrgProp ); 1143 VObject *org = safeAddProp( vcard, VCOrgProp );
1144 safeAddPropValue( org, VCOrgNameProp, c.company() ); 1144 safeAddPropValue( org, VCOrgNameProp, c.company() );
1145 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 1145 safeAddPropValue( org, VCOrgUnitProp, c.department() );
1146 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 1146 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
1147 } 1147 }
1148 1148
1149 // some values we have to export as custom fields 1149 // some values we have to export as custom fields
1150 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 1150 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
1151 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 1151 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
1152 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1152 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
1153 1153
1154 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1154 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
1155 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1155 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
1156 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); 1156 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
1157 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1157 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
1158 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1158 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
1159 1159
1160 return vcard; 1160 return vcard;
1161} 1161}
1162 1162
1163 1163
1164/*! 1164/*!
1165 \internal 1165 \internal
1166*/ 1166*/
1167static QDate convVCardDateToDate( const QString& datestr ) 1167static QDate convVCardDateToDate( const QString& datestr )
1168{ 1168{
1169 int monthPos = datestr.find('-'); 1169 int monthPos = datestr.find('-');
1170 int dayPos = datestr.find('-', monthPos+1 ); 1170 int dayPos = datestr.find('-', monthPos+1 );
1171 int sep_ignore = 1; 1171 int sep_ignore = 1;
1172 if ( monthPos == -1 || dayPos == -1 ) { 1172 if ( monthPos == -1 || dayPos == -1 ) {
1173 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1173 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1174 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 1174 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
1175 if ( datestr.length() == 8 ){ 1175 if ( datestr.length() == 8 ){
1176 monthPos = 4; 1176 monthPos = 4;
1177 dayPos = 6; 1177 dayPos = 6;
1178 sep_ignore = 0; 1178 sep_ignore = 0;
1179 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1179 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1180 } else { 1180 } else {
1181 return QDate(); 1181 return QDate();
1182 } 1182 }
1183 } 1183 }
1184 int y = datestr.left( monthPos ).toInt(); 1184 int y = datestr.left( monthPos ).toInt();
1185 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 1185 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
1186 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 1186 int d = datestr.mid( dayPos + sep_ignore ).toInt();
1187 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 1187 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
1188 QDate date ( y,m,d ); 1188 QDate date ( y,m,d );
1189 return date; 1189 return date;
1190} 1190}
1191 1191
1192static OContact parseVObject( VObject *obj ) 1192static OContact parseVObject( VObject *obj )
1193{ 1193{
1194 OContact c; 1194 OContact c;
1195 1195
1196 VObjectIterator it; 1196 VObjectIterator it;
1197 initPropIterator( &it, obj ); 1197 initPropIterator( &it, obj );
1198 while( moreIteration( &it ) ) { 1198 while( moreIteration( &it ) ) {
1199 VObject *o = nextVObject( &it ); 1199 VObject *o = nextVObject( &it );
1200 QCString name = vObjectName( o ); 1200 QCString name = vObjectName( o );
1201 QCString value = vObjectStringZValue( o ); 1201 QCString value = vObjectStringZValue( o );
1202 if ( name == VCNameProp ) { 1202 if ( name == VCNameProp ) {
1203 VObjectIterator nit; 1203 VObjectIterator nit;
1204 initPropIterator( &nit, o ); 1204 initPropIterator( &nit, o );
1205 while( moreIteration( &nit ) ) { 1205 while( moreIteration( &nit ) ) {
1206 VObject *o = nextVObject( &nit ); 1206 VObject *o = nextVObject( &nit );
1207 QCString name = vObjectTypeInfo( o ); 1207 QCString name = vObjectTypeInfo( o );
1208 QString value = vObjectStringZValue( o ); 1208 QString value = vObjectStringZValue( o );
1209 if ( name == VCNamePrefixesProp ) 1209 if ( name == VCNamePrefixesProp )
1210 c.setTitle( value ); 1210 c.setTitle( value );
1211 else if ( name == VCNameSuffixesProp ) 1211 else if ( name == VCNameSuffixesProp )
1212 c.setSuffix( value ); 1212 c.setSuffix( value );
1213 else if ( name == VCFamilyNameProp ) 1213 else if ( name == VCFamilyNameProp )
1214 c.setLastName( value ); 1214 c.setLastName( value );
1215 else if ( name == VCGivenNameProp ) 1215 else if ( name == VCGivenNameProp )
1216 c.setFirstName( value ); 1216 c.setFirstName( value );
1217 else if ( name == VCAdditionalNamesProp ) 1217 else if ( name == VCAdditionalNamesProp )
1218 c.setMiddleName( value ); 1218 c.setMiddleName( value );
1219 } 1219 }
1220 } 1220 }
1221 else if ( name == VCAdrProp ) { 1221 else if ( name == VCAdrProp ) {
1222 bool work = TRUE; // default address is work address 1222 bool work = TRUE; // default address is work address
1223 QString street; 1223 QString street;
1224 QString city; 1224 QString city;
1225 QString region; 1225 QString region;
1226 QString postal; 1226 QString postal;
1227 QString country; 1227 QString country;
1228 1228
1229 VObjectIterator nit; 1229 VObjectIterator nit;
1230 initPropIterator( &nit, o ); 1230 initPropIterator( &nit, o );
1231 while( moreIteration( &nit ) ) { 1231 while( moreIteration( &nit ) ) {
1232 VObject *o = nextVObject( &nit ); 1232 VObject *o = nextVObject( &nit );
1233 QCString name = vObjectName( o ); 1233 QCString name = vObjectName( o );
1234 QString value = vObjectStringZValue( o ); 1234 QString value = vObjectStringZValue( o );
1235 if ( name == VCHomeProp ) 1235 if ( name == VCHomeProp )
1236 work = FALSE; 1236 work = FALSE;
1237 else if ( name == VCWorkProp ) 1237 else if ( name == VCWorkProp )
1238 work = TRUE; 1238 work = TRUE;
1239 else if ( name == VCStreetAddressProp ) 1239 else if ( name == VCStreetAddressProp )
1240 street = value; 1240 street = value;
1241 else if ( name == VCCityProp ) 1241 else if ( name == VCCityProp )
1242 city = value; 1242 city = value;
1243 else if ( name == VCRegionProp ) 1243 else if ( name == VCRegionProp )
1244 region = value; 1244 region = value;
1245 else if ( name == VCPostalCodeProp ) 1245 else if ( name == VCPostalCodeProp )
1246 postal = value; 1246 postal = value;
1247 else if ( name == VCCountryNameProp ) 1247 else if ( name == VCCountryNameProp )
1248 country = value; 1248 country = value;
1249 } 1249 }
1250 if ( work ) { 1250 if ( work ) {
1251 c.setBusinessStreet( street ); 1251 c.setBusinessStreet( street );
1252 c.setBusinessCity( city ); 1252 c.setBusinessCity( city );
1253 c.setBusinessCountry( country ); 1253 c.setBusinessCountry( country );
1254 c.setBusinessZip( postal ); 1254 c.setBusinessZip( postal );
1255 c.setBusinessState( region ); 1255 c.setBusinessState( region );
1256 } else { 1256 } else {
1257 c.setHomeStreet( street ); 1257 c.setHomeStreet( street );
1258 c.setHomeCity( city ); 1258 c.setHomeCity( city );
1259 c.setHomeCountry( country ); 1259 c.setHomeCountry( country );
1260 c.setHomeZip( postal ); 1260 c.setHomeZip( postal );
1261 c.setHomeState( region ); 1261 c.setHomeState( region );
1262 } 1262 }
1263 } 1263 }
1264 else if ( name == VCTelephoneProp ) { 1264 else if ( name == VCTelephoneProp ) {
1265 enum { 1265 enum {
1266 HOME = 0x01, 1266 HOME = 0x01,
1267 WORK = 0x02, 1267 WORK = 0x02,
1268 VOICE = 0x04, 1268 VOICE = 0x04,
1269 CELL = 0x08, 1269 CELL = 0x08,
1270 FAX = 0x10, 1270 FAX = 0x10,
1271 PAGER = 0x20, 1271 PAGER = 0x20,
1272 UNKNOWN = 0x80 1272 UNKNOWN = 0x80
1273 }; 1273 };
1274 int type = 0; 1274 int type = 0;
1275 1275
1276 VObjectIterator nit; 1276 VObjectIterator nit;
1277 initPropIterator( &nit, o ); 1277 initPropIterator( &nit, o );
1278 while( moreIteration( &nit ) ) { 1278 while( moreIteration( &nit ) ) {
1279 VObject *o = nextVObject( &nit ); 1279 VObject *o = nextVObject( &nit );
1280 QCString name = vObjectTypeInfo( o ); 1280 QCString name = vObjectTypeInfo( o );
1281 if ( name == VCHomeProp ) 1281 if ( name == VCHomeProp )
1282 type |= HOME; 1282 type |= HOME;
1283 else if ( name == VCWorkProp ) 1283 else if ( name == VCWorkProp )
1284 type |= WORK; 1284 type |= WORK;
1285 else if ( name == VCVoiceProp ) 1285 else if ( name == VCVoiceProp )
1286 type |= VOICE; 1286 type |= VOICE;
1287 else if ( name == VCCellularProp ) 1287 else if ( name == VCCellularProp )
1288 type |= CELL; 1288 type |= CELL;
1289 else if ( name == VCFaxProp ) 1289 else if ( name == VCFaxProp )
1290 type |= FAX; 1290 type |= FAX;
1291 else if ( name == VCPagerProp ) 1291 else if ( name == VCPagerProp )
1292 type |= PAGER; 1292 type |= PAGER;
1293 else if ( name == VCPreferredProp ) 1293 else if ( name == VCPreferredProp )
1294 ; 1294 ;
1295 else 1295 else
1296 type |= UNKNOWN; 1296 type |= UNKNOWN;
1297 } 1297 }
1298 if ( (type & UNKNOWN) != UNKNOWN ) { 1298 if ( (type & UNKNOWN) != UNKNOWN ) {
1299 if ( ( type & (HOME|WORK) ) == 0 ) // default 1299 if ( ( type & (HOME|WORK) ) == 0 ) // default
1300 type |= HOME; 1300 type |= HOME;
1301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 1301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
1302 type |= VOICE; 1302 type |= VOICE;
1303 1303
1304 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 1304 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
1305 c.setHomePhone( value ); 1305 c.setHomePhone( value );
1306 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 1306 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
1307 c.setHomeFax( value ); 1307 c.setHomeFax( value );
1308 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 1308 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
1309 c.setHomeMobile( value ); 1309 c.setHomeMobile( value );
1310 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 1310 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
1311 c.setBusinessPhone( value ); 1311 c.setBusinessPhone( value );
1312 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 1312 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
1313 c.setBusinessFax( value ); 1313 c.setBusinessFax( value );
1314 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 1314 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
1315 c.setBusinessMobile( value ); 1315 c.setBusinessMobile( value );
1316 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 1316 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
1317 c.setBusinessPager( value ); 1317 c.setBusinessPager( value );
1318 } 1318 }
1319 } 1319 }
1320 else if ( name == VCEmailAddressProp ) { 1320 else if ( name == VCEmailAddressProp ) {
1321 QString email = vObjectStringZValue( o ); 1321 QString email = vObjectStringZValue( o );
1322 bool valid = TRUE; 1322 bool valid = TRUE;
1323 VObjectIterator nit; 1323 VObjectIterator nit;
1324 initPropIterator( &nit, o ); 1324 initPropIterator( &nit, o );
1325 while( moreIteration( &nit ) ) { 1325 while( moreIteration( &nit ) ) {
1326 VObject *o = nextVObject( &nit ); 1326 VObject *o = nextVObject( &nit );
1327 QCString name = vObjectTypeInfo( o ); 1327 QCString name = vObjectTypeInfo( o );
1328 if ( name != VCInternetProp && name != VCHomeProp && 1328 if ( name != VCInternetProp && name != VCHomeProp &&
1329 name != VCWorkProp && 1329 name != VCWorkProp &&
1330 name != VCPreferredProp ) 1330 name != VCPreferredProp )
1331 // ### preffered should map to default email 1331 // ### preffered should map to default email
1332 valid = FALSE; 1332 valid = FALSE;
1333 } 1333 }
1334 if ( valid ) { 1334 if ( valid ) {
1335 c.insertEmail( email ); 1335 c.insertEmail( email );
1336 } 1336 }
1337 } 1337 }
1338 else if ( name == VCURLProp ) { 1338 else if ( name == VCURLProp ) {
1339 VObjectIterator nit; 1339 VObjectIterator nit;
1340 initPropIterator( &nit, o ); 1340 initPropIterator( &nit, o );
1341 while( moreIteration( &nit ) ) { 1341 while( moreIteration( &nit ) ) {
1342 VObject *o = nextVObject( &nit ); 1342 VObject *o = nextVObject( &nit );
1343 QCString name = vObjectTypeInfo( o ); 1343 QCString name = vObjectTypeInfo( o );
1344 if ( name == VCHomeProp ) 1344 if ( name == VCHomeProp )
1345 c.setHomeWebpage( value ); 1345 c.setHomeWebpage( value );
1346 else if ( name == VCWorkProp ) 1346 else if ( name == VCWorkProp )
1347 c.setBusinessWebpage( value ); 1347 c.setBusinessWebpage( value );
1348 } 1348 }
1349 } 1349 }
1350 else if ( name == VCOrgProp ) { 1350 else if ( name == VCOrgProp ) {
1351 VObjectIterator nit; 1351 VObjectIterator nit;
1352 initPropIterator( &nit, o ); 1352 initPropIterator( &nit, o );
1353 while( moreIteration( &nit ) ) { 1353 while( moreIteration( &nit ) ) {
1354 VObject *o = nextVObject( &nit ); 1354 VObject *o = nextVObject( &nit );
1355 QCString name = vObjectName( o ); 1355 QCString name = vObjectName( o );
1356 QString value = vObjectStringZValue( o ); 1356 QString value = vObjectStringZValue( o );
1357 if ( name == VCOrgNameProp ) 1357 if ( name == VCOrgNameProp )
1358 c.setCompany( value ); 1358 c.setCompany( value );
1359 else if ( name == VCOrgUnitProp ) 1359 else if ( name == VCOrgUnitProp )
1360 c.setDepartment( value ); 1360 c.setDepartment( value );
1361 else if ( name == VCOrgUnit2Prop ) 1361 else if ( name == VCOrgUnit2Prop )
1362 c.setOffice( value ); 1362 c.setOffice( value );
1363 } 1363 }
1364 } 1364 }
1365 else if ( name == VCTitleProp ) { 1365 else if ( name == VCTitleProp ) {
1366 c.setJobTitle( value ); 1366 c.setJobTitle( value );
1367 } 1367 }
1368 else if ( name == "X-Qtopia-Profession" ) { 1368 else if ( name == "X-Qtopia-Profession" ) {
1369 c.setProfession( value ); 1369 c.setProfession( value );
1370 } 1370 }
1371 else if ( name == "X-Qtopia-Manager" ) { 1371 else if ( name == "X-Qtopia-Manager" ) {
1372 c.setManager( value ); 1372 c.setManager( value );
1373 } 1373 }
1374 else if ( name == "X-Qtopia-Assistant" ) { 1374 else if ( name == "X-Qtopia-Assistant" ) {
1375 c.setAssistant( value ); 1375 c.setAssistant( value );
1376 } 1376 }
1377 else if ( name == "X-Qtopia-Spouse" ) { 1377 else if ( name == "X-Qtopia-Spouse" ) {
1378 c.setSpouse( value ); 1378 c.setSpouse( value );
1379 } 1379 }
1380 else if ( name == "X-Qtopia-Gender" ) { 1380 else if ( name == "X-Qtopia-Gender" ) {
1381 c.setGender( value ); 1381 c.setGender( value );
1382 } 1382 }
1383 else if ( name == "X-Qtopia-Anniversary" ) { 1383 else if ( name == "X-Qtopia-Anniversary" ) {
1384 c.setAnniversary( TimeConversion::fromString( value ) ); 1384 c.setAnniversary( TimeConversion::fromString( value ) );
1385 } 1385 }
1386 else if ( name == "X-Qtopia-Nickname" ) { 1386 else if ( name == "X-Qtopia-Nickname" ) {
1387 c.setNickname( value ); 1387 c.setNickname( value );
1388 } 1388 }
1389 else if ( name == "X-Qtopia-Children" ) { 1389 else if ( name == "X-Qtopia-Children" ) {
1390 c.setChildren( value ); 1390 c.setChildren( value );
1391 } 1391 }
1392 else if ( name == VCBirthDateProp ) { 1392 else if ( name == VCBirthDateProp ) {
1393 // Reading Birthdate regarding RFC 2425 (5.8.4) 1393 // Reading Birthdate regarding RFC 2425 (5.8.4)
1394 c.setBirthday( convVCardDateToDate( value ) ); 1394 c.setBirthday( convVCardDateToDate( value ) );
1395 1395
1396 } 1396 }
1397 1397
1398#if 0 1398#if 0
1399 else { 1399 else {
1400 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1400 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
1401 VObjectIterator nit; 1401 VObjectIterator nit;
1402 initPropIterator( &nit, o ); 1402 initPropIterator( &nit, o );
1403 while( moreIteration( &nit ) ) { 1403 while( moreIteration( &nit ) ) {
1404 VObject *o = nextVObject( &nit ); 1404 VObject *o = nextVObject( &nit );
1405 QCString name = vObjectName( o ); 1405 QCString name = vObjectName( o );
1406 QString value = vObjectStringZValue( o ); 1406 QString value = vObjectStringZValue( o );
1407 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1407 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
1408 } 1408 }
1409 } 1409 }
1410#endif 1410#endif
1411 } 1411 }
1412 c.setFileAs(); 1412 c.setFileAs();
1413 return c; 1413 return c;
1414} 1414}
1415 1415
1416/*! 1416/*!
1417 Writes the list of \a contacts as a set of VCards to the file \a filename. 1417 Writes the list of \a contacts as a set of VCards to the file \a filename.
1418*/ 1418*/
1419void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) 1419void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts)
1420{ 1420{
1421 QFileDirect f( filename.utf8().data() ); 1421 QFileDirect f( filename.utf8().data() );
1422 if ( !f.open( IO_WriteOnly ) ) { 1422 if ( !f.open( IO_WriteOnly ) ) {
1423 qWarning("Unable to open vcard write"); 1423 qWarning("Unable to open vcard write");
1424 return; 1424 return;
1425 } 1425 }
1426 1426
1427 QValueList<OContact>::ConstIterator it; 1427 QValueList<OContact>::ConstIterator it;
1428 for( it = contacts.begin(); it != contacts.end(); ++it ) { 1428 for( it = contacts.begin(); it != contacts.end(); ++it ) {
1429 VObject *obj = createVObject( *it ); 1429 VObject *obj = createVObject( *it );
1430 writeVObject(f.directHandle() , obj ); 1430 writeVObject(f.directHandle() , obj );
1431 cleanVObject( obj ); 1431 cleanVObject( obj );
1432 } 1432 }
1433 cleanStrTbl(); 1433 cleanStrTbl();
1434} 1434}
1435 1435
1436/*! 1436/*!
1437 writes \a contact as a VCard to the file \a filename. 1437 writes \a contact as a VCard to the file \a filename.
1438*/ 1438*/
1439void OContact::writeVCard( const QString &filename, const OContact &contact) 1439void OContact::writeVCard( const QString &filename, const OContact &contact)
1440{ 1440{
1441 QFileDirect f( filename.utf8().data() ); 1441 QFileDirect f( filename.utf8().data() );
1442 if ( !f.open( IO_WriteOnly ) ) { 1442 if ( !f.open( IO_WriteOnly ) ) {
1443 qWarning("Unable to open vcard write"); 1443 qWarning("Unable to open vcard write");
1444 return; 1444 return;
1445 } 1445 }
1446 1446
1447 VObject *obj = createVObject( contact ); 1447 VObject *obj = createVObject( contact );
1448 writeVObject( f.directHandle() , obj ); 1448 writeVObject( f.directHandle() , obj );
1449 cleanVObject( obj ); 1449 cleanVObject( obj );
1450 1450
1451 cleanStrTbl(); 1451 cleanStrTbl();
1452} 1452}
1453 1453
1454/*! 1454/*!
1455 Returns the set of contacts read as VCards from the file \a filename. 1455 Returns the set of contacts read as VCards from the file \a filename.
1456*/ 1456*/
1457QValueList<OContact> OContact::readVCard( const QString &filename ) 1457QValueList<OContact> OContact::readVCard( const QString &filename )
1458{ 1458{
1459 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); 1459 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() ); 1460 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1461 1461
1462 qDebug("vobject = %p", obj ); 1462 qDebug("vobject = %p", obj );
1463 1463
1464 QValueList<OContact> contacts; 1464 QValueList<OContact> contacts;
1465 1465
1466 while ( obj ) { 1466 while ( obj ) {
1467 contacts.append( parseVObject( obj ) ); 1467 OContact con = parseVObject( obj );
1468 /*
1469 * if uid is 0 assign a new one
1470 * this at least happens on
1471 * Nokia6210
1472 */
1473 if ( con.uid() == 0 )
1474 con.setUid( 1 );
1475
1476 contacts.append(con );
1468 1477
1469 VObject *t = obj; 1478 VObject *t = obj;
1470 obj = nextVObjectInList(obj); 1479 obj = nextVObjectInList(obj);
1471 cleanVObject( t ); 1480 cleanVObject( t );
1472 } 1481 }
1473 1482
1474 return contacts; 1483 return contacts;
1475} 1484}
1476 1485
1477/*! 1486/*!
1478 Returns TRUE if the contact matches the regular expression \a regexp. 1487 Returns TRUE if the contact matches the regular expression \a regexp.
1479 Otherwise returns FALSE. 1488 Otherwise returns FALSE.
1480*/ 1489*/
1481bool OContact::match( const QString &regexp ) const 1490bool OContact::match( const QString &regexp ) const
1482{ 1491{
1483 return match(QRegExp(regexp)); 1492 return match(QRegExp(regexp));
1484} 1493}
1485 1494
1486/*! 1495/*!
1487 \overload 1496 \overload
1488 Returns TRUE if the contact matches the regular expression \a regexp. 1497 Returns TRUE if the contact matches the regular expression \a regexp.
1489 Otherwise returns FALSE. 1498 Otherwise returns FALSE.
1490*/ 1499*/
1491bool OContact::match( const QRegExp &r ) const 1500bool OContact::match( const QRegExp &r ) const
1492{ 1501{
1493 bool match; 1502 bool match;
1494 match = false; 1503 match = false;
1495 QMap<int, QString>::ConstIterator it; 1504 QMap<int, QString>::ConstIterator it;
1496 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 1505 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
1497 if ( (*it).find( r ) > -1 ) { 1506 if ( (*it).find( r ) > -1 ) {
1498 match = true; 1507 match = true;
1499 break; 1508 break;
1500 } 1509 }
1501 } 1510 }
1502 return match; 1511 return match;
1503} 1512}
1504 1513
1505 1514
1506QString OContact::toShortText() const 1515QString OContact::toShortText() const
1507{ 1516{
1508 return ( fullName() ); 1517 return ( fullName() );
1509} 1518}
1510QString OContact::type() const 1519QString OContact::type() const
1511{ 1520{
1512 return QString::fromLatin1( "OContact" ); 1521 return QString::fromLatin1( "OContact" );
1513} 1522}
1514 1523
1515// Definition is missing ! (se) 1524// Definition is missing ! (se)
1516QMap<QString,QString> OContact::toExtraMap() const 1525QMap<QString,QString> OContact::toExtraMap() const
1517{ 1526{
1518 qWarning ("Function not implemented: OContact::toExtraMap()"); 1527 qWarning ("Function not implemented: OContact::toExtraMap()");
1519 QMap <QString,QString> useless; 1528 QMap <QString,QString> useless;
1520 return useless; 1529 return useless;
1521} 1530}
1522 1531
1523class QString OContact::recordField( int pos ) const 1532class QString OContact::recordField( int pos ) const
1524{ 1533{
1525 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1534 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1526 return SLFIELDS[pos]; 1535 return SLFIELDS[pos];
1527} 1536}
1528 1537
1529// In future releases, we should store birthday and anniversary 1538// In future releases, we should store birthday and anniversary
1530// internally as QDate instead of QString ! 1539// internally as QDate instead of QString !
1531// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1540// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1532 1541
1533/*! \fn void OContact::setBirthday( const QDate& date ) 1542/*! \fn void OContact::setBirthday( const QDate& date )
1534 Sets the birthday for the contact to \a date. 1543 Sets the birthday for the contact to \a date.
1535*/ 1544*/
1536void OContact::setBirthday( const QDate &v ) 1545void OContact::setBirthday( const QDate &v )
1537{ 1546{
1538 if ( ( !v.isNull() ) && ( v.isValid() ) ) 1547 if ( ( !v.isNull() ) && ( v.isValid() ) )
1539 replace( Qtopia::Birthday, TimeConversion::toString( v ) ); 1548 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
1540 1549
1541} 1550}
1542 1551
1543 1552
1544/*! \fn void OContact::setAnniversary( const QDate &date ) 1553/*! \fn void OContact::setAnniversary( const QDate &date )
1545 Sets the anniversary of the contact to \a date. 1554 Sets the anniversary of the contact to \a date.
1546*/ 1555*/
1547void OContact::setAnniversary( const QDate &v ) 1556void OContact::setAnniversary( const QDate &v )
1548{ 1557{
1549 if ( ( !v.isNull() ) && ( v.isValid() ) ) 1558 if ( ( !v.isNull() ) && ( v.isValid() ) )
1550 replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); 1559 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
1551} 1560}
1552 1561
1553/*! \fn QDate OContact::birthday() const 1562/*! \fn QDate OContact::birthday() const
1554 Returns the birthday of the contact. 1563 Returns the birthday of the contact.
1555*/ 1564*/
1556QDate OContact::birthday() const 1565QDate OContact::birthday() const
1557{ 1566{
1558 QString str = find( Qtopia::Birthday ); 1567 QString str = find( Qtopia::Birthday );
1559 qWarning ("Birthday %s", str.latin1() ); 1568 qWarning ("Birthday %s", str.latin1() );
1560 if ( !str.isEmpty() ) 1569 if ( !str.isEmpty() )
1561 return TimeConversion::fromString ( str ); 1570 return TimeConversion::fromString ( str );
1562 else 1571 else
1563 return QDate(); 1572 return QDate();
1564} 1573}
1565 1574
1566 1575
1567/*! \fn QDate OContact::anniversary() const 1576/*! \fn QDate OContact::anniversary() const
1568 Returns the anniversary of the contact. 1577 Returns the anniversary of the contact.
1569*/ 1578*/
1570QDate OContact::anniversary() const 1579QDate OContact::anniversary() const
1571{ 1580{
1572 QDate empty; 1581 QDate empty;
1573 QString str = find( Qtopia::Anniversary ); 1582 QString str = find( Qtopia::Anniversary );
1574 qWarning ("Anniversary %s", str.latin1() ); 1583 qWarning ("Anniversary %s", str.latin1() );
1575 if ( !str.isEmpty() ) 1584 if ( !str.isEmpty() )
1576 return TimeConversion::fromString ( str ); 1585 return TimeConversion::fromString ( str );
1577 else 1586 else
1578 return empty; 1587 return empty;
1579} 1588}
1580 1589
1581 1590
1582void OContact::insertEmail( const QString &v ) 1591void OContact::insertEmail( const QString &v )
1583{ 1592{
1584 //qDebug("insertEmail %s", v.latin1()); 1593 //qDebug("insertEmail %s", v.latin1());
1585 QString e = v.simplifyWhiteSpace(); 1594 QString e = v.simplifyWhiteSpace();
1586 QString def = defaultEmail(); 1595 QString def = defaultEmail();
1587 1596
1588 // if no default, set it as the default email and don't insert 1597 // if no default, set it as the default email and don't insert
1589 if ( def.isEmpty() ) { 1598 if ( def.isEmpty() ) {
1590 setDefaultEmail( e ); // will insert into the list for us 1599 setDefaultEmail( e ); // will insert into the list for us
1591 return; 1600 return;
1592 } 1601 }
1593 1602
1594 // otherwise, insert assuming doesn't already exist 1603 // otherwise, insert assuming doesn't already exist
1595 QString emailsStr = find( Qtopia::Emails ); 1604 QString emailsStr = find( Qtopia::Emails );
1596 if ( emailsStr.contains( e )) 1605 if ( emailsStr.contains( e ))
1597 return; 1606 return;
1598 if ( !emailsStr.isEmpty() ) 1607 if ( !emailsStr.isEmpty() )
1599 emailsStr += emailSeparator(); 1608 emailsStr += emailSeparator();
1600 emailsStr += e; 1609 emailsStr += e;
1601 replace( Qtopia::Emails, emailsStr ); 1610 replace( Qtopia::Emails, emailsStr );
1602} 1611}
1603 1612
1604void OContact::removeEmail( const QString &v ) 1613void OContact::removeEmail( const QString &v )
1605{ 1614{
1606 QString e = v.simplifyWhiteSpace(); 1615 QString e = v.simplifyWhiteSpace();
1607 QString def = defaultEmail(); 1616 QString def = defaultEmail();
1608 QString emailsStr = find( Qtopia::Emails ); 1617 QString emailsStr = find( Qtopia::Emails );
1609 QStringList emails = emailList(); 1618 QStringList emails = emailList();
1610 1619
1611 // otherwise, must first contain it 1620 // otherwise, must first contain it
1612 if ( !emailsStr.contains( e ) ) 1621 if ( !emailsStr.contains( e ) )
1613 return; 1622 return;
1614 1623
1615 // remove it 1624 // remove it
1616 //qDebug(" removing email from list %s", e.latin1()); 1625 //qDebug(" removing email from list %s", e.latin1());
1617 emails.remove( e ); 1626 emails.remove( e );
1618 // reset the string 1627 // reset the string
1619 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1628 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1620 replace( Qtopia::Emails, emailsStr ); 1629 replace( Qtopia::Emails, emailsStr );
1621 1630
1622 // if default, then replace the default email with the first one 1631 // if default, then replace the default email with the first one
1623 if ( def == e ) { 1632 if ( def == e ) {
1624 //qDebug("removeEmail is default; setting new default"); 1633 //qDebug("removeEmail is default; setting new default");
1625 if ( !emails.count() ) 1634 if ( !emails.count() )
1626 clearEmails(); 1635 clearEmails();
1627 else // setDefaultEmail will remove e from the list 1636 else // setDefaultEmail will remove e from the list
1628 setDefaultEmail( emails.first() ); 1637 setDefaultEmail( emails.first() );
1629 } 1638 }
1630} 1639}
1631void OContact::clearEmails() 1640void OContact::clearEmails()
1632{ 1641{
1633 mMap.remove( Qtopia::DefaultEmail ); 1642 mMap.remove( Qtopia::DefaultEmail );
1634 mMap.remove( Qtopia::Emails ); 1643 mMap.remove( Qtopia::Emails );
1635} 1644}
1636void OContact::setDefaultEmail( const QString &v ) 1645void OContact::setDefaultEmail( const QString &v )
1637{ 1646{
1638 QString e = v.simplifyWhiteSpace(); 1647 QString e = v.simplifyWhiteSpace();
1639 1648
1640 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1649 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1641 replace( Qtopia::DefaultEmail, e ); 1650 replace( Qtopia::DefaultEmail, e );
1642 1651
1643 if ( !e.isEmpty() ) 1652 if ( !e.isEmpty() )
1644 insertEmail( e ); 1653 insertEmail( e );
1645 1654
1646} 1655}
1647 1656
1648void OContact::insertEmails( const QStringList &v ) 1657void OContact::insertEmails( const QStringList &v )
1649{ 1658{
1650 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1659 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1651 insertEmail( *it ); 1660 insertEmail( *it );
1652} 1661}
1653 1662
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h
index dbb94ed..d9ccad4 100644
--- a/libopie/pim/opimrecord.h
+++ b/libopie/pim/opimrecord.h
@@ -1,133 +1,133 @@
1#ifndef OPIE_PIM_RECORD_H 1#ifndef OPIE_PIM_RECORD_H
2#define OPIE_PIM_RECORD_H 2#define OPIE_PIM_RECORD_H
3 3
4#include <qmap.h> 4#include <qmap.h>
5#include <qstring.h> 5#include <qstring.h>
6#include <qstringlist.h> 6#include <qstringlist.h>
7 7
8#include <qpe/palmtoprecord.h> 8#include <qpe/palmtoprecord.h>
9 9
10 10
11/** 11/**
12 * This is the base class for 12 * This is the base class for
13 * all PIM Records 13 * all PIM Records
14 * 14 *
15 */ 15 */
16class OPimRecord : public Qtopia::Record { 16class OPimRecord : public Qtopia::Record {
17public: 17public:
18 /** 18 /**
19 * c'tor 19 * c'tor
20 * uid of 0 isEmpty 20 * uid of 0 isEmpty
21 * uid of 1 will be assigned a new one 21 * uid of 1 will be assigned a new one
22 */ 22 */
23 OPimRecord(int uid = 0); 23 OPimRecord(int uid = 0);
24 ~OPimRecord(); 24 ~OPimRecord();
25 25
26 /** 26 /**
27 * copy c'tor 27 * copy c'tor
28 */ 28 */
29 OPimRecord( const OPimRecord& rec ); 29 OPimRecord( const OPimRecord& rec );
30 30
31 /** 31 /**
32 * copy operator 32 * copy operator
33 */ 33 */
34 OPimRecord &operator=( const OPimRecord& ); 34 OPimRecord &operator=( const OPimRecord& );
35 35
36 /** 36 /**
37 * category names resolved 37 * category names resolved
38 */ 38 */
39 QStringList categoryNames()const; 39 QStringList categoryNames()const;
40 40
41 /** 41 /**
42 * set category names they will be resolved 42 * set category names they will be resolved
43 */ 43 */
44 void setCategoryNames( const QStringList& ); 44 void setCategoryNames( const QStringList& );
45 45
46 /** 46 /**
47 * addCategoryName adds a name 47 * addCategoryName adds a name
48 * to the internal category list 48 * to the internal category list
49 */ 49 */
50 void addCategoryName( const QString& ); 50 void addCategoryName( const QString& );
51 51
52 /** 52 /**
53 * if a Record isEmpty 53 * if a Record isEmpty
54 * it's empty if it's 0 54 * it's empty if it's 0
55 */ 55 */
56 virtual bool isEmpty()const; 56 virtual bool isEmpty()const;
57 57
58 /** 58 /**
59 * toRichText summary 59 * toRichText summary
60 */ 60 */
61 virtual QString toRichText()const = 0; 61 virtual QString toRichText()const = 0;
62 62
63 /** 63 /**
64 * a small one line summary 64 * a small one line summary
65 */ 65 */
66 virtual QString toShortText()const = 0; 66 virtual QString toShortText()const = 0;
67 67
68 /** 68 /**
69 * the name of the Record 69 * the name of the Record
70 */ 70 */
71 virtual QString type()const = 0; 71 virtual QString type()const = 0;
72 72
73 /** 73 /**
74 * converts the internal structure to a map 74 * converts the internal structure to a map
75 */ 75 */
76 virtual QMap<int, QString> toMap()const = 0; 76 virtual QMap<int, QString> toMap()const = 0;
77 77
78 /** 78 /**
79 * key value representation of extra items 79 * key value representation of extra items
80 */ 80 */
81 virtual QMap<QString, QString> toExtraMap()const = 0; 81 virtual QMap<QString, QString> toExtraMap()const = 0;
82 82
83 /** 83 /**
84 * the name for a recordField 84 * the name for a recordField
85 */ 85 */
86 virtual QString recordField(int)const = 0; 86 virtual QString recordField(int)const = 0;
87 87
88 /** 88 /**
89 * the related apps names 89 * the related apps names
90 */ 90 */
91 QStringList relatedApps()const; 91 QStringList relatedApps()const;
92 92
93 /** 93 /**
94 * the realtions between an app 94 * the realtions between an app
95 */ 95 */
96 QArray<int> relations( const QString& app )const; 96 QArray<int> relations( const QString& app )const;
97 97
98 /** 98 /**
99 * clear the relations for all relations 99 * clear the relations for all relations
100 * with app 100 * with app
101 */ 101 */
102 void clearRelation( const QString& app ); 102 void clearRelation( const QString& app );
103 103
104 /** 104 /**
105 * add a relation 105 * add a relation
106 */ 106 */
107 void addRelation( const QString& app, int id ); 107 void addRelation( const QString& app, int id );
108 108
109 /** 109 /**
110 * set the relations for an app 110 * set the relations for an app
111 */ 111 */
112 void setRelations( const QString&, QArray<int> ids ); 112 void setRelations( const QString&, QArray<int> ids );
113 113
114 /** 114 /**
115 * set the uid 115 * set the uid
116 */ 116 */
117 virtual void setUid( int uid ); 117 virtual void setUid( int uid );
118 118
119protected: 119protected:
120 Qtopia::UidGen &uidGen(); 120 Qtopia::UidGen &uidGen();
121 QString crossToString()const; 121 QString crossToString()const;
122 122
123private: 123private:
124 class OPimRecordPrivate; 124 class OPimRecordPrivate;
125 OPimRecordPrivate *d; 125 OPimRecordPrivate *d;
126 QMap<QString, QArray<int> > m_relations; 126 QMap<QString, QArray<int> > m_relations;
127 static Qtopia::UidGen m_uidGen; 127 static Qtopia::UidGen m_uidGen;
128 128
129}; 129};
130 130
131 131
132 132
133#endif 133#endif
diff --git a/libopie/pim/opimstate.cpp b/libopie/pim/opimstate.cpp
new file mode 100644
index 0000000..6fb2feb
--- a/dev/null
+++ b/libopie/pim/opimstate.cpp
@@ -0,0 +1,64 @@
1#include <qshared.h>
2
3#include "opimstate.h"
4
5/*
6 * for one int this does not make
7 * much sense but never the less
8 * we will do it for the future
9 */
10struct OPimState::Data : public QShared {
11 Data() : QShared(),state(Undefined) {
12 }
13 int state;
14};
15
16OPimState::OPimState( int state ) {
17 data = new Data;
18 data->state = state;
19}
20OPimState::OPimState( const OPimState& st) :
21 data( st.data ) {
22 /* ref up */
23 data->ref();
24}
25OPimState::~OPimState() {
26 if ( data->deref() ) {
27 delete data ;
28 data = 0;
29 }
30}
31bool OPimState::operator==( const OPimState& st) {
32 if ( data->state == st.data->state ) return true;
33
34 return false;
35}
36OPimState &OPimState::operator=( const OPimState& st) {
37 st.data->ref();
38 deref();
39 data = st.data;
40
41 return *this;
42}
43void OPimState::setState( int st) {
44 copyInternally();
45 data->state = st;
46}
47int OPimState::state()const {
48 return data->state;
49}
50void OPimState::deref() {
51 if ( data->deref() ) {
52 delete data;
53 data = 0l;
54 }
55}
56void OPimState::copyInternally() {
57 /* we need to change it */
58 if ( data->count != 1 ) {
59 data->deref();
60 Data* d2 = new Data;
61 d2->state = data->state;
62 data = d2;
63 }
64}
diff --git a/libopie/pim/opimstate.h b/libopie/pim/opimstate.h
new file mode 100644
index 0000000..731181e
--- a/dev/null
+++ b/libopie/pim/opimstate.h
@@ -0,0 +1,44 @@
1#ifndef OPIE_PIM_STATE_H
2#define OPIE_PIM_STATE_H
3
4#include <qstring.h>
5
6/**
7 * The State of a Task
8 * This class encapsules the state of a todo
9 * and it's shared too
10 */
11/*
12 * in c a simple struct would be enough ;)
13 * g_new_state();
14 * g_do_some_thing( state_t* );
15 * ;)
16 */
17class OPimState {
18public:
19 enum State {
20 Started = 0,
21 Postponed,
22 Finished,
23 NotStarted,
24 Undefined
25 };
26 OPimState( int state = Undefined );
27 OPimState( const OPimState& );
28 ~OPimState();
29
30 bool operator==( const OPimState& );
31 OPimState &operator=( const OPimState& );
32 void setState( int state);
33 int state()const;
34private:
35 void deref();
36 inline void copyInternally();
37 struct Data;
38 Data* data;
39 class Private;
40 Private *d;
41};
42
43
44#endif
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index 2f4a5d3..8ed41e2 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -45,256 +45,256 @@ public:
45 ORecordListIterator &operator--(); 45 ORecordListIterator &operator--();
46 46
47 bool operator==( const ORecordListIterator& it ); 47 bool operator==( const ORecordListIterator& it );
48 bool operator!=( const ORecordListIterator& it ); 48 bool operator!=( const ORecordListIterator& it );
49 49
50 /** 50 /**
51 * the current item 51 * the current item
52 */ 52 */
53 uint current()const; 53 uint current()const;
54 54
55 /** 55 /**
56 * the number of items 56 * the number of items
57 */ 57 */
58 uint count()const; 58 uint count()const;
59 59
60 /** 60 /**
61 * sets the current item 61 * sets the current item
62 */ 62 */
63 void setCurrent( uint cur ); 63 void setCurrent( uint cur );
64 64
65private: 65private:
66 QArray<int> m_uids; 66 QArray<int> m_uids;
67 uint m_current; 67 uint m_current;
68 const Base* m_temp; 68 const Base* m_temp;
69 bool m_end : 1; 69 bool m_end : 1;
70 T m_record; 70 T m_record;
71 bool m_direction :1; 71 bool m_direction :1;
72 72
73 /* d pointer for future versions */ 73 /* d pointer for future versions */
74 class IteratorPrivate; 74 class IteratorPrivate;
75 IteratorPrivate *d; 75 IteratorPrivate *d;
76}; 76};
77/** 77/**
78 * The recordlist used as a return type 78 * The recordlist used as a return type
79 * from OPimAccessTemplate 79 * from OPimAccessTemplate
80 */ 80 */
81template <class T = OPimRecord > 81template <class T = OPimRecord >
82class ORecordList { 82class ORecordList {
83public: 83public:
84 typedef OTemplateBase<T> Base; 84 typedef OTemplateBase<T> Base;
85 typedef ORecordListIterator<T> Iterator; 85 typedef ORecordListIterator<T> Iterator;
86 86
87 /** 87 /**
88 * c'tor 88 * c'tor
89 */ 89 */
90 ORecordList () { 90 ORecordList () {
91 } 91 }
92ORecordList( const QArray<int>& ids, 92ORecordList( const QArray<int>& ids,
93 const Base* ); 93 const Base* );
94 ~ORecordList(); 94 ~ORecordList();
95 95
96 /** 96 /**
97 * the first iterator 97 * the first iterator
98 */ 98 */
99 Iterator begin(); 99 Iterator begin();
100 100
101 /** 101 /**
102 * the end 102 * the end
103 */ 103 */
104 Iterator end(); 104 Iterator end();
105 105
106 /** 106 /**
107 * the number of items in the list 107 * the number of items in the list
108 */ 108 */
109 uint count()const; 109 uint count()const;
110 110
111 T operator[]( uint i ); 111 T operator[]( uint i );
112 int uidAt(uint i ); 112 int uidAt(uint i );
113 113
114 /** 114 /**
115 * Remove the contact with given uid 115 * Remove the contact with given uid
116 */ 116 */
117 bool remove( int uid ); 117 bool remove( int uid );
118 118
119 /* 119 /*
120 ConstIterator begin()const; 120 ConstIterator begin()const;
121 ConstIterator end()const; 121 ConstIterator end()const;
122 */ 122 */
123private: 123private:
124 QArray<int> m_ids; 124 QArray<int> m_ids;
125 const Base* m_acc; 125 const Base* m_acc;
126}; 126};
127 127
128/* ok now implement it */ 128/* ok now implement it */
129template <class T> 129template <class T>
130ORecordListIterator<T>::ORecordListIterator() { 130ORecordListIterator<T>::ORecordListIterator() {
131 m_current = 0; 131 m_current = 0;
132 m_temp = 0l; 132 m_temp = 0l;
133 m_end = true; 133 m_end = true;
134 m_record = T(); 134 m_record = T();
135 /* forward */ 135 /* forward */
136 m_direction = TRUE; 136 m_direction = TRUE;
137} 137}
138template <class T> 138template <class T>
139ORecordListIterator<T>::~ORecordListIterator() { 139ORecordListIterator<T>::~ORecordListIterator() {
140/* nothing to delete */ 140/* nothing to delete */
141} 141}
142 142
143template <class T> 143template <class T>
144ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { 144ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
145// qWarning("ORecordListIterator copy c'tor"); 145// qWarning("ORecordListIterator copy c'tor");
146 m_uids = it.m_uids; 146 m_uids = it.m_uids;
147 m_current = it.m_current; 147 m_current = it.m_current;
148 m_temp = it.m_temp; 148 m_temp = it.m_temp;
149 m_end = it.m_end; 149 m_end = it.m_end;
150 m_record = it.m_record; 150 m_record = it.m_record;
151 m_direction = it.m_direction; 151 m_direction = it.m_direction;
152} 152}
153 153
154template <class T> 154template <class T>
155ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { 155ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
156 m_uids = it.m_uids; 156 m_uids = it.m_uids;
157 m_current = it.m_current; 157 m_current = it.m_current;
158 m_temp = it.m_temp; 158 m_temp = it.m_temp;
159 m_end = it.m_end; 159 m_end = it.m_end;
160 m_record = it.m_record; 160 m_record = it.m_record;
161 161
162 return *this; 162 return *this;
163} 163}
164 164
165template <class T> 165template <class T>
166T ORecordListIterator<T>::operator*() { 166T ORecordListIterator<T>::operator*() {
167 //qWarning("operator* %d %d", m_current, m_uids[m_current] ); 167 //qWarning("operator* %d %d", m_current, m_uids[m_current] );
168 if (!m_end ) 168 if (!m_end )
169 m_record = m_temp->find( m_uids[m_current], m_uids, m_current, 169 m_record = m_temp->find( m_uids[m_current], m_uids, m_current,
170 m_direction ? Base::Forward : 170 m_direction ? Base::Forward :
171 Base::Reverse ); 171 Base::Reverse );
172 else 172 else
173 m_record = T(); 173 m_record = T();
174 174
175 return m_record; 175 return m_record;
176} 176}
177 177
178template <class T> 178template <class T>
179ORecordListIterator<T> &ORecordListIterator<T>::operator++() { 179ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
180 m_direction = true; 180 m_direction = true;
181 if (m_current < m_uids.count() ) { 181 if (m_current < m_uids.count() ) {
182 m_end = false; 182 m_end = false;
183 ++m_current; 183 ++m_current;
184 }else 184 }else
185 m_end = true; 185 m_end = true;
186 186
187 return *this; 187 return *this;
188} 188}
189template <class T> 189template <class T>
190ORecordListIterator<T> &ORecordListIterator<T>::operator--() { 190ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
191 m_direction = false; 191 m_direction = false;
192 if ( m_current > 0 ) { 192 if ( m_current > 0 ) {
193 --m_current; 193 --m_current;
194 m_end = false; 194 m_end = false;
195 } else 195 } else
196 m_end = true; 196 m_end = true;
197 197
198 return *this; 198 return *this;
199} 199}
200 200
201template <class T> 201template <class T>
202bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { 202bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
203 203
204 /* if both are at we're the same.... */ 204 /* if both are at we're the same.... */
205 if ( m_end == it.m_end ) return true; 205 if ( m_end == it.m_end ) return true;
206 206
207 if ( m_uids != it.m_uids ) return false; 207 if ( m_uids != it.m_uids ) return false;
208 if ( m_current != it.m_current ) return false; 208 if ( m_current != it.m_current ) return false;
209 if ( m_temp != it.m_temp ) return false; 209 if ( m_temp != it.m_temp ) return false;
210 210
211 return true; 211 return true;
212} 212}
213template <class T> 213template <class T>
214bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 214bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
215 return !(*this == it ); 215 return !(*this == it );
216} 216}
217template <class T> 217template <class T>
218ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, 218ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids,
219 const Base* t ) 219 const Base* t )
220 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), 220 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ),
221 m_direction( false ) 221 m_direction( false )
222{ 222{
223} 223}
224template <class T> 224template <class T>
225uint ORecordListIterator<T>::current()const { 225uint ORecordListIterator<T>::current()const {
226 return m_current; 226 return m_current;
227} 227}
228template <class T> 228template <class T>
229void ORecordListIterator<T>::setCurrent( uint cur ) { 229void ORecordListIterator<T>::setCurrent( uint cur ) {
230 if( cur < m_uids.count() ) { 230 if( cur < m_uids.count() ) {
231 m_end = false; 231 m_end = false;
232 m_current= cur; 232 m_current= cur;
233 } 233 }
234} 234}
235template <class T> 235template <class T>
236uint ORecordListIterator<T>::count()const { 236uint ORecordListIterator<T>::count()const {
237 return m_uids.count(); 237 return m_uids.count();
238} 238}
239template <class T> 239template <class T>
240ORecordList<T>::ORecordList( const QArray<int>& ids, 240ORecordList<T>::ORecordList( const QArray<int>& ids,
241 const Base* acc ) 241 const Base* acc )
242 : m_ids( ids ), m_acc( acc ) 242 : m_ids( ids ), m_acc( acc )
243{ 243{
244} 244}
245template <class T> 245template <class T>
246ORecordList<T>::~ORecordList() { 246ORecordList<T>::~ORecordList() {
247/* nothing to do here */ 247/* nothing to do here */
248} 248}
249template <class T> 249template <class T>
250ORecordList<T>::Iterator ORecordList<T>::begin() { 250ORecordList<T>::Iterator ORecordList<T>::begin() {
251 Iterator it( m_ids, m_acc ); 251 Iterator it( m_ids, m_acc );
252 return it; 252 return it;
253} 253}
254template <class T> 254template <class T>
255ORecordList<T>::Iterator ORecordList<T>::end() { 255ORecordList<T>::Iterator ORecordList<T>::end() {
256 Iterator it( m_ids, m_acc ); 256 Iterator it( m_ids, m_acc );
257 it.m_end = true; 257 it.m_end = true;
258 it.m_current = m_ids.count(); 258 it.m_current = m_ids.count();
259 259
260 return it; 260 return it;
261} 261}
262template <class T> 262template <class T>
263uint ORecordList<T>::count()const { 263uint ORecordList<T>::count()const {
264return m_ids.count(); 264return m_ids.count();
265} 265}
266template <class T> 266template <class T>
267T ORecordList<T>::operator[]( uint i ) { 267T ORecordList<T>::operator[]( uint i ) {
268 if ( i < 0 || (i+1) > m_ids.count() ) 268 if ( i < 0 || (i+1) > m_ids.count() )
269 return T(); 269 return T();
270 /* forward */ 270 /* forward */
271 return m_acc->find( m_ids[i], m_ids, i ); 271 return m_acc->find( m_ids[i], m_ids, i );
272} 272}
273template <class T> 273template <class T>
274int ORecordList<T>::uidAt( uint i ) { 274int ORecordList<T>::uidAt( uint i ) {
275 return m_ids[i]; 275 return m_ids[i];
276} 276}
277 277
278template <class T> 278template <class T>
279bool ORecordList<T>::remove( int uid ) { 279bool ORecordList<T>::remove( int uid ) {
280 QArray<int> copy( m_ids.count() ); 280 QArray<int> copy( m_ids.count() );
281 int counter = 0; 281 int counter = 0;
282 bool ret_val = false; 282 bool ret_val = false;
283 283
284 for (uint i = 0; i < m_ids.count(); i++){ 284 for (uint i = 0; i < m_ids.count(); i++){
285 if ( m_ids[i] != uid ){ 285 if ( m_ids[i] != uid ){
286 copy[counter++] = m_ids[i]; 286 copy[counter++] = m_ids[i];
287 287
288 }else 288 }else
289 ret_val = true; 289 ret_val = true;
290 } 290 }
291 291
292 copy.resize( counter ); 292 copy.resize( counter );
293 m_ids = copy; 293 m_ids = copy;
294 294
295 295
296 return ret_val; 296 return ret_val;
297} 297}
298 298
299 299
300#endif 300#endif
diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp
index 6c81f8f..257d4fd 100644
--- a/libopie/pim/orecur.cpp
+++ b/libopie/pim/orecur.cpp
@@ -1,127 +1,136 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qtopia/timeconversion.h> 3#include <qtopia/timeconversion.h>
4 4
5#include "orecur.h" 5#include "orecur.h"
6 6
7struct ORecur::Data : public QShared { 7struct ORecur::Data : public QShared {
8 Data() : QShared() { 8 Data() : QShared() {
9 type = ORecur::NoRepeat; 9 type = ORecur::NoRepeat;
10 freq = -1; 10 freq = -1;
11 days = 0; 11 days = 0;
12 pos = 0; 12 pos = 0;
13 create = -1; 13 create = -1;
14 hasEnd = FALSE; 14 hasEnd = FALSE;
15 end = 0; 15 end = 0;
16 } 16 }
17 char days; // Q_UINT8 for 8 seven days;) 17 char days; // Q_UINT8 for 8 seven days;)
18 ORecur::RepeatType type; 18 ORecur::RepeatType type;
19 int freq; 19 int freq;
20 int pos; 20 int pos;
21 bool hasEnd : 1; 21 bool hasEnd : 1;
22 time_t end; 22 time_t end;
23 time_t create; 23 time_t create;
24 int rep;
24}; 25};
25 26
26 27
27ORecur::ORecur() { 28ORecur::ORecur() {
28 data = new Data; 29 data = new Data;
29} 30}
30ORecur::ORecur( const ORecur& rec) 31ORecur::ORecur( const ORecur& rec)
31 : data( rec.data ) 32 : data( rec.data )
32{ 33{
33 data->ref(); 34 data->ref();
34} 35}
35ORecur::~ORecur() { 36ORecur::~ORecur() {
36 if ( data->deref() ) { 37 if ( data->deref() ) {
37 delete data; 38 delete data;
38 data = 0l; 39 data = 0l;
39 } 40 }
40} 41}
41void ORecur::deref() { 42void ORecur::deref() {
42 if ( data->deref() ) { 43 if ( data->deref() ) {
43 delete data; 44 delete data;
44 data = 0l; 45 data = 0l;
45 } 46 }
46} 47}
47bool ORecur::operator==( const ORecur& )const { 48bool ORecur::operator==( const ORecur& )const {
48 return false; 49 return false;
49} 50}
50ORecur &ORecur::operator=( const ORecur& re) { 51ORecur &ORecur::operator=( const ORecur& re) {
51 re.data->ref(); 52 re.data->ref();
52 deref(); 53 deref();
53 data = re.data; 54 data = re.data;
54 55
55 return *this; 56 return *this;
56} 57}
57ORecur::RepeatType ORecur::type()const{ 58ORecur::RepeatType ORecur::type()const{
58 return data->type; 59 return data->type;
59} 60}
60int ORecur::frequency()const { 61int ORecur::frequency()const {
61 return data->freq; 62 return data->freq;
62} 63}
63int ORecur::position()const { 64int ORecur::position()const {
64 return data->pos; 65 return data->pos;
65} 66}
66char ORecur::days() const{ 67char ORecur::days() const{
67 return data->days; 68 return data->days;
68} 69}
69bool ORecur::hasEndDate()const { 70bool ORecur::hasEndDate()const {
70 return data->hasEnd; 71 return data->hasEnd;
71} 72}
72QDate ORecur::endDate()const { 73QDate ORecur::endDate()const {
73 return TimeConversion::fromUTC( data->end ).date(); 74 return TimeConversion::fromUTC( data->end ).date();
74} 75}
75time_t ORecur::endDateUTC()const { 76time_t ORecur::endDateUTC()const {
76 return data->end; 77 return data->end;
77} 78}
78time_t ORecur::createTime()const { 79time_t ORecur::createTime()const {
79 return data->create; 80 return data->create;
80} 81}
82int ORecur::repetition()const {
83 return data->rep;
84}
81void ORecur::setType( const RepeatType& z) { 85void ORecur::setType( const RepeatType& z) {
82 checkOrModify(); 86 checkOrModify();
83 data->type = z; 87 data->type = z;
84} 88}
85void ORecur::setFrequency( int freq ) { 89void ORecur::setFrequency( int freq ) {
86 checkOrModify(); 90 checkOrModify();
87 data->freq = freq; 91 data->freq = freq;
88} 92}
89void ORecur::setPosition( int pos ) { 93void ORecur::setPosition( int pos ) {
90 checkOrModify(); 94 checkOrModify();
91 data->pos = pos; 95 data->pos = pos;
92} 96}
93void ORecur::setDays( char c ) { 97void ORecur::setDays( char c ) {
94 checkOrModify(); 98 checkOrModify();
95 data->days = c; 99 data->days = c;
96} 100}
97void ORecur::setEndDate( const QDate& dt) { 101void ORecur::setEndDate( const QDate& dt) {
98 checkOrModify(); 102 checkOrModify();
99 data->end = TimeConversion::toUTC( dt ); 103 data->end = TimeConversion::toUTC( dt );
100} 104}
101void ORecur::setEndDateUTC( time_t t) { 105void ORecur::setEndDateUTC( time_t t) {
102 checkOrModify(); 106 checkOrModify();
103 data->end = t; 107 data->end = t;
104} 108}
105void ORecur::setCreateTime( time_t t) { 109void ORecur::setCreateTime( time_t t) {
106 checkOrModify(); 110 checkOrModify();
107 data->create = t; 111 data->create = t;
108} 112}
109void ORecur::setHasEndDate( bool b) { 113void ORecur::setHasEndDate( bool b) {
110 checkOrModify(); 114 checkOrModify();
111 data->hasEnd = b; 115 data->hasEnd = b;
112} 116}
117void ORecur::setRepitition( int rep ) {
118 checkOrModify();
119 data->rep = rep;
120}
113void ORecur::checkOrModify() { 121void ORecur::checkOrModify() {
114 if ( data->count != 1 ) { 122 if ( data->count != 1 ) {
115 data->deref(); 123 data->deref();
116 Data* d2 = new Data; 124 Data* d2 = new Data;
117 d2->days = data->days; 125 d2->days = data->days;
118 d2->type = data->type; 126 d2->type = data->type;
119 d2->freq = data->freq; 127 d2->freq = data->freq;
120 d2->pos = data->pos; 128 d2->pos = data->pos;
121 d2->hasEnd = data->hasEnd; 129 d2->hasEnd = data->hasEnd;
122 d2->end = data->end; 130 d2->end = data->end;
123 d2->create = data->create; 131 d2->create = data->create;
132 d2->rep = data->rep;
124 data = d2; 133 data = d2;
125 } 134 }
126} 135}
127 136
diff --git a/libopie/pim/orecur.h b/libopie/pim/orecur.h
index 89258f8..d24d72d 100644
--- a/libopie/pim/orecur.h
+++ b/libopie/pim/orecur.h
@@ -1,54 +1,56 @@
1/* 1/*
2 * GPL from TT 2 * GPL from TT
3 */ 3 */
4 4
5#ifndef OPIE_RECUR_H 5#ifndef OPIE_RECUR_H
6#define OPIE_RECUR_H 6#define OPIE_RECUR_H
7 7
8#include <sys/types.h> 8#include <sys/types.h>
9 9
10#include <qdatetime.h> 10#include <qdatetime.h>
11 11
12 12
13 13
14class ORecur { 14class ORecur {
15public: 15public:
16 enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, 16 enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay,
17 MonthlyDate, Yearly }; 17 MonthlyDate, Yearly };
18 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, 18 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
19 FRI = 0x10, SAT = 0x20, SUN = 0x40 }; 19 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
20 ORecur(); 20 ORecur();
21 ORecur( const ORecur& ); 21 ORecur( const ORecur& );
22 ~ORecur(); 22 ~ORecur();
23 23
24 ORecur &operator=( const ORecur& ); 24 ORecur &operator=( const ORecur& );
25 bool operator==(const ORecur& )const; 25 bool operator==(const ORecur& )const;
26 RepeatType type()const; 26 RepeatType type()const;
27 int frequency()const; 27 int frequency()const;
28 int position()const; 28 int position()const;
29 char days()const; 29 char days()const;
30 bool hasEndDate()const; 30 bool hasEndDate()const;
31 QDate endDate()const; 31 QDate endDate()const;
32 time_t endDateUTC()const; 32 time_t endDateUTC()const;
33 time_t createTime()const; 33 time_t createTime()const;
34 int repetition()const;
34 35
35 void setType( const RepeatType& ); 36 void setType( const RepeatType& );
36 void setFrequency( int freq ); 37 void setFrequency( int freq );
37 void setPosition( int pos ); 38 void setPosition( int pos );
38 void setDays( char c); 39 void setDays( char c);
39 void setEndDate( const QDate& dt ); 40 void setEndDate( const QDate& dt );
40 void setEndDateUTC( time_t ); 41 void setEndDateUTC( time_t );
41 void setCreateTime( time_t ); 42 void setCreateTime( time_t );
42 void setHasEndDate( bool b ); 43 void setHasEndDate( bool b );
44 void setRepitition(int );
43private: 45private:
44 void deref(); 46 void deref();
45 inline void checkOrModify(); 47 inline void checkOrModify();
46 48
47 49
48 class Data; 50 class Data;
49 Data* data; 51 Data* data;
50 class ORecurPrivate; 52 class ORecurPrivate;
51 ORecurPrivate *d; 53 ORecurPrivate *d;
52}; 54};
53 55
54#endif 56#endif
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index 765d5a9..0d5b1d3 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,386 +1,405 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15 15#include "opimstate.h"
16#include "orecur.h"
16#include "otodo.h" 17#include "otodo.h"
17 18
18 19
19struct OTodo::OTodoData : public QShared { 20struct OTodo::OTodoData : public QShared {
20 OTodoData() : QShared() { 21 OTodoData() : QShared() {
21 }; 22 };
22 23
23 QDate date; 24 QDate date;
24 bool isCompleted:1; 25 bool isCompleted:1;
25 bool hasDate:1; 26 bool hasDate:1;
26 int priority; 27 int priority;
27 QString desc; 28 QString desc;
28 QString sum; 29 QString sum;
29 QMap<QString, QString> extra; 30 QMap<QString, QString> extra;
30 ushort prog; 31 ushort prog;
31 bool hasAlarmDateTime :1; 32 bool hasAlarmDateTime :1;
32 QDateTime alarmDateTime; 33 QDateTime alarmDateTime;
34 OPimState state;
35 ORecur recur;
33}; 36};
34 37
35OTodo::OTodo(const OTodo &event ) 38OTodo::OTodo(const OTodo &event )
36 : OPimRecord( event ), data( event.data ) 39 : OPimRecord( event ), data( event.data )
37{ 40{
38 data->ref(); 41 data->ref();
39// qWarning("ref up"); 42// qWarning("ref up");
40} 43}
41OTodo::~OTodo() { 44OTodo::~OTodo() {
42 45
43// qWarning("~OTodo " ); 46// qWarning("~OTodo " );
44 if ( data->deref() ) { 47 if ( data->deref() ) {
45// qWarning("OTodo::dereffing"); 48// qWarning("OTodo::dereffing");
46 delete data; 49 delete data;
47 data = 0l; 50 data = 0l;
48 } 51 }
49} 52}
50OTodo::OTodo(bool completed, int priority, 53OTodo::OTodo(bool completed, int priority,
51 const QArray<int> &category, 54 const QArray<int> &category,
52 const QString& summary, 55 const QString& summary,
53 const QString &description, 56 const QString &description,
54 ushort progress, 57 ushort progress,
55 bool hasDate, QDate date, int uid ) 58 bool hasDate, QDate date, int uid )
56 : OPimRecord( uid ) 59 : OPimRecord( uid )
57{ 60{
58// qWarning("OTodoData " + summary); 61// qWarning("OTodoData " + summary);
59 setCategories( category ); 62 setCategories( category );
60 63
61 data = new OTodoData; 64 data = new OTodoData;
62 65
63 data->date = date; 66 data->date = date;
64 data->isCompleted = completed; 67 data->isCompleted = completed;
65 data->hasDate = hasDate; 68 data->hasDate = hasDate;
66 data->priority = priority; 69 data->priority = priority;
67 data->sum = summary; 70 data->sum = summary;
68 data->prog = progress; 71 data->prog = progress;
69 data->desc = Qtopia::simplifyMultiLineSpace(description ); 72 data->desc = Qtopia::simplifyMultiLineSpace(description );
70 data->hasAlarmDateTime = false; 73 data->hasAlarmDateTime = false;
71 74
72} 75}
73OTodo::OTodo(bool completed, int priority, 76OTodo::OTodo(bool completed, int priority,
74 const QStringList &category, 77 const QStringList &category,
75 const QString& summary, 78 const QString& summary,
76 const QString &description, 79 const QString &description,
77 ushort progress, 80 ushort progress,
78 bool hasDate, QDate date, int uid ) 81 bool hasDate, QDate date, int uid )
79 : OPimRecord( uid ) 82 : OPimRecord( uid )
80{ 83{
81// qWarning("OTodoData" + summary); 84// qWarning("OTodoData" + summary);
82 setCategories( idsFromString( category.join(";") ) ); 85 setCategories( idsFromString( category.join(";") ) );
83 86
84 data = new OTodoData; 87 data = new OTodoData;
85 88
86 data->date = date; 89 data->date = date;
87 data->isCompleted = completed; 90 data->isCompleted = completed;
88 data->hasDate = hasDate; 91 data->hasDate = hasDate;
89 data->priority = priority; 92 data->priority = priority;
90 data->sum = summary; 93 data->sum = summary;
91 data->prog = progress; 94 data->prog = progress;
92 data->desc = Qtopia::simplifyMultiLineSpace(description ); 95 data->desc = Qtopia::simplifyMultiLineSpace(description );
93 data->hasAlarmDateTime = false; 96 data->hasAlarmDateTime = false;
94 97
95} 98}
96bool OTodo::match( const QRegExp &regExp )const 99bool OTodo::match( const QRegExp &regExp )const
97{ 100{
98 if( QString::number( data->priority ).find( regExp ) != -1 ){ 101 if( QString::number( data->priority ).find( regExp ) != -1 ){
99 return true; 102 return true;
100 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 103 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
101 return true; 104 return true;
102 }else if(data->desc.find( regExp ) != -1 ){ 105 }else if(data->desc.find( regExp ) != -1 ){
103 return true; 106 return true;
104 }else if(data->sum.find( regExp ) != -1 ) { 107 }else if(data->sum.find( regExp ) != -1 ) {
105 return true; 108 return true;
106 } 109 }
107 return false; 110 return false;
108} 111}
109bool OTodo::isCompleted() const 112bool OTodo::isCompleted() const
110{ 113{
111 return data->isCompleted; 114 return data->isCompleted;
112} 115}
113bool OTodo::hasDueDate() const 116bool OTodo::hasDueDate() const
114{ 117{
115 return data->hasDate; 118 return data->hasDate;
116} 119}
117bool OTodo::hasAlarmDateTime() const 120bool OTodo::hasAlarmDateTime() const
118{ 121{
119 return data->hasAlarmDateTime; 122 return data->hasAlarmDateTime;
120} 123}
121int OTodo::priority()const 124int OTodo::priority()const
122{ 125{
123 return data->priority; 126 return data->priority;
124} 127}
125QString OTodo::summary() const 128QString OTodo::summary() const
126{ 129{
127 return data->sum; 130 return data->sum;
128} 131}
129ushort OTodo::progress() const 132ushort OTodo::progress() const
130{ 133{
131 return data->prog; 134 return data->prog;
132} 135}
133QDate OTodo::dueDate()const 136QDate OTodo::dueDate()const
134{ 137{
135 return data->date; 138 return data->date;
136} 139}
137 140
138QDateTime OTodo::alarmDateTime() const 141QDateTime OTodo::alarmDateTime() const
139{ 142{
140 return data->alarmDateTime; 143 return data->alarmDateTime;
141} 144}
142 145
143QString OTodo::description()const 146QString OTodo::description()const
144{ 147{
145 return data->desc; 148 return data->desc;
146} 149}
150OPimState OTodo::state()const {
151 return data->state;
152}
153ORecur OTodo::recurrence()const {
154 return data->recur;
155}
147void OTodo::setCompleted( bool completed ) 156void OTodo::setCompleted( bool completed )
148{ 157{
149 changeOrModify(); 158 changeOrModify();
150 data->isCompleted = completed; 159 data->isCompleted = completed;
151} 160}
152void OTodo::setHasDueDate( bool hasDate ) 161void OTodo::setHasDueDate( bool hasDate )
153{ 162{
154 changeOrModify(); 163 changeOrModify();
155 data->hasDate = hasDate; 164 data->hasDate = hasDate;
156} 165}
157void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) 166void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime )
158{ 167{
159 changeOrModify(); 168 changeOrModify();
160 data->hasAlarmDateTime = hasAlarmDateTime; 169 data->hasAlarmDateTime = hasAlarmDateTime;
161} 170}
162void OTodo::setDescription(const QString &desc ) 171void OTodo::setDescription(const QString &desc )
163{ 172{
164// qWarning( "desc " + desc ); 173// qWarning( "desc " + desc );
165 changeOrModify(); 174 changeOrModify();
166 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 175 data->desc = Qtopia::simplifyMultiLineSpace(desc );
167} 176}
168void OTodo::setSummary( const QString& sum ) 177void OTodo::setSummary( const QString& sum )
169{ 178{
170 changeOrModify(); 179 changeOrModify();
171 data->sum = sum; 180 data->sum = sum;
172} 181}
173void OTodo::setPriority(int prio ) 182void OTodo::setPriority(int prio )
174{ 183{
175 changeOrModify(); 184 changeOrModify();
176 data->priority = prio; 185 data->priority = prio;
177} 186}
178void OTodo::setDueDate( QDate date ) 187void OTodo::setDueDate( QDate date )
179{ 188{
180 changeOrModify(); 189 changeOrModify();
181 data->date = date; 190 data->date = date;
182} 191}
183void OTodo::setAlarmDateTime( const QDateTime& alarm ) 192void OTodo::setAlarmDateTime( const QDateTime& alarm )
184{ 193{
185 changeOrModify(); 194 changeOrModify();
186 data->alarmDateTime = alarm; 195 data->alarmDateTime = alarm;
187} 196}
197void OTodo::setState( const OPimState& state ) {
198 changeOrModify();
199 data->state = state;
200}
201void OTodo::setRecurrence( const ORecur& rec) {
202 changeOrModify();
203 data->recur = rec;
204}
188bool OTodo::isOverdue( ) 205bool OTodo::isOverdue( )
189{ 206{
190 if( data->hasDate && !data->isCompleted) 207 if( data->hasDate && !data->isCompleted)
191 return QDate::currentDate() > data->date; 208 return QDate::currentDate() > data->date;
192 return false; 209 return false;
193} 210}
194void OTodo::setProgress(ushort progress ) 211void OTodo::setProgress(ushort progress )
195{ 212{
196 changeOrModify(); 213 changeOrModify();
197 data->prog = progress; 214 data->prog = progress;
198} 215}
199QString OTodo::toShortText() const { 216QString OTodo::toShortText() const {
200 return summary(); 217 return summary();
201} 218}
202/*! 219/*!
203 Returns a richt text string 220 Returns a richt text string
204*/ 221*/
205QString OTodo::toRichText() const 222QString OTodo::toRichText() const
206{ 223{
207 QString text; 224 QString text;
208 QStringList catlist; 225 QStringList catlist;
209 226
210 // Description of the todo 227 // Description of the todo
211 if ( !summary().isEmpty() ) { 228 if ( !summary().isEmpty() ) {
212 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 229 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
213 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 230 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
214 } 231 }
215 if( !description().isEmpty() ){ 232 if( !description().isEmpty() ){
216 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 233 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
217 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 234 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
218 } 235 }
219 text += "<br><br><br>"; 236 text += "<br><br><br>";
220 237
221 text += "<b>" + QObject::tr( "Priority:") +" </b>" 238 text += "<b>" + QObject::tr( "Priority:") +" </b>"
222 + QString::number( priority() ) + " <br>"; 239 + QString::number( priority() ) + " <br>";
223 text += "<b>" + QObject::tr( "Progress:") + " </b>" 240 text += "<b>" + QObject::tr( "Progress:") + " </b>"
224 + QString::number( progress() ) + " %<br>"; 241 + QString::number( progress() ) + " %<br>";
225 if (hasDueDate() ){ 242 if (hasDueDate() ){
226 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 243 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
227 text += dueDate().toString(); 244 text += dueDate().toString();
228 text += "<br>"; 245 text += "<br>";
229 } 246 }
230 if (hasAlarmDateTime() ){ 247 if (hasAlarmDateTime() ){
231 text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>"; 248 text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>";
232 text += alarmDateTime().toString(); 249 text += alarmDateTime().toString();
233 text += "<br>"; 250 text += "<br>";
234 } 251 }
235 252
236 text += "<b>" + QObject::tr( "Category:") + "</b> "; 253 text += "<b>" + QObject::tr( "Category:") + "</b> ";
237 text += categoryNames().join(", "); 254 text += categoryNames().join(", ");
238 text += "<br>"; 255 text += "<br>";
239 256
240 return text; 257 return text;
241} 258}
242 259
243bool OTodo::operator<( const OTodo &toDoEvent )const{ 260bool OTodo::operator<( const OTodo &toDoEvent )const{
244 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 261 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
245 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 262 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
246 if( hasDueDate() && toDoEvent.hasDueDate() ){ 263 if( hasDueDate() && toDoEvent.hasDueDate() ){
247 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 264 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
248 return priority() < toDoEvent.priority(); 265 return priority() < toDoEvent.priority();
249 }else{ 266 }else{
250 return dueDate() < toDoEvent.dueDate(); 267 return dueDate() < toDoEvent.dueDate();
251 } 268 }
252 } 269 }
253 return false; 270 return false;
254} 271}
255bool OTodo::operator<=(const OTodo &toDoEvent )const 272bool OTodo::operator<=(const OTodo &toDoEvent )const
256{ 273{
257 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 274 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
258 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 275 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
259 if( hasDueDate() && toDoEvent.hasDueDate() ){ 276 if( hasDueDate() && toDoEvent.hasDueDate() ){
260 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 277 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
261 return priority() <= toDoEvent.priority(); 278 return priority() <= toDoEvent.priority();
262 }else{ 279 }else{
263 return dueDate() <= toDoEvent.dueDate(); 280 return dueDate() <= toDoEvent.dueDate();
264 } 281 }
265 } 282 }
266 return true; 283 return true;
267} 284}
268bool OTodo::operator>(const OTodo &toDoEvent )const 285bool OTodo::operator>(const OTodo &toDoEvent )const
269{ 286{
270 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 287 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
271 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 288 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
272 if( hasDueDate() && toDoEvent.hasDueDate() ){ 289 if( hasDueDate() && toDoEvent.hasDueDate() ){
273 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 290 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
274 return priority() > toDoEvent.priority(); 291 return priority() > toDoEvent.priority();
275 }else{ 292 }else{
276 return dueDate() > toDoEvent.dueDate(); 293 return dueDate() > toDoEvent.dueDate();
277 } 294 }
278 } 295 }
279 return false; 296 return false;
280} 297}
281bool OTodo::operator>=(const OTodo &toDoEvent )const 298bool OTodo::operator>=(const OTodo &toDoEvent )const
282{ 299{
283 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 300 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
284 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 301 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
285 if( hasDueDate() && toDoEvent.hasDueDate() ){ 302 if( hasDueDate() && toDoEvent.hasDueDate() ){
286 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 303 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
287 return priority() > toDoEvent.priority(); 304 return priority() > toDoEvent.priority();
288 }else{ 305 }else{
289 return dueDate() > toDoEvent.dueDate(); 306 return dueDate() > toDoEvent.dueDate();
290 } 307 }
291 } 308 }
292 return true; 309 return true;
293} 310}
294bool OTodo::operator==(const OTodo &toDoEvent )const 311bool OTodo::operator==(const OTodo &toDoEvent )const
295{ 312{
296 if ( data->priority != toDoEvent.data->priority ) return false; 313 if ( data->priority != toDoEvent.data->priority ) return false;
297 if ( data->priority != toDoEvent.data->prog ) return false; 314 if ( data->priority != toDoEvent.data->prog ) return false;
298 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 315 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
299 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 316 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
300 if ( data->date != toDoEvent.data->date ) return false; 317 if ( data->date != toDoEvent.data->date ) return false;
301 if ( data->sum != toDoEvent.data->sum ) return false; 318 if ( data->sum != toDoEvent.data->sum ) return false;
302 if ( data->desc != toDoEvent.data->desc ) return false; 319 if ( data->desc != toDoEvent.data->desc ) return false;
303 if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime ) 320 if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime )
304 return false; 321 return false;
305 if ( data->alarmDateTime != toDoEvent.data->alarmDateTime ) 322 if ( data->alarmDateTime != toDoEvent.data->alarmDateTime )
306 return false; 323 return false;
307 324
308 return OPimRecord::operator==( toDoEvent ); 325 return OPimRecord::operator==( toDoEvent );
309} 326}
310void OTodo::deref() { 327void OTodo::deref() {
311 328
312// qWarning("deref in ToDoEvent"); 329// qWarning("deref in ToDoEvent");
313 if ( data->deref() ) { 330 if ( data->deref() ) {
314// qWarning("deleting"); 331// qWarning("deleting");
315 delete data; 332 delete data;
316 data= 0; 333 data= 0;
317 } 334 }
318} 335}
319OTodo &OTodo::operator=(const OTodo &item ) 336OTodo &OTodo::operator=(const OTodo &item )
320{ 337{
321 OPimRecord::operator=( item ); 338 OPimRecord::operator=( item );
322 //qWarning("operator= ref "); 339 //qWarning("operator= ref ");
323 item.data->ref(); 340 item.data->ref();
324 deref(); 341 deref();
325 data = item.data; 342 data = item.data;
326 343
327 return *this; 344 return *this;
328} 345}
329 346
330QMap<int, QString> OTodo::toMap() const { 347QMap<int, QString> OTodo::toMap() const {
331 QMap<int, QString> map; 348 QMap<int, QString> map;
332 349
333 map.insert( Uid, QString::number( uid() ) ); 350 map.insert( Uid, QString::number( uid() ) );
334 map.insert( Category, idsToString( categories() ) ); 351 map.insert( Category, idsToString( categories() ) );
335 map.insert( HasDate, QString::number( data->hasDate ) ); 352 map.insert( HasDate, QString::number( data->hasDate ) );
336 map.insert( Completed, QString::number( data->isCompleted ) ); 353 map.insert( Completed, QString::number( data->isCompleted ) );
337 map.insert( Description, data->desc ); 354 map.insert( Description, data->desc );
338 map.insert( Summary, data->sum ); 355 map.insert( Summary, data->sum );
339 map.insert( Priority, QString::number( data->priority ) ); 356 map.insert( Priority, QString::number( data->priority ) );
340 map.insert( DateDay, QString::number( data->date.day() ) ); 357 map.insert( DateDay, QString::number( data->date.day() ) );
341 map.insert( DateMonth, QString::number( data->date.month() ) ); 358 map.insert( DateMonth, QString::number( data->date.month() ) );
342 map.insert( DateYear, QString::number( data->date.year() ) ); 359 map.insert( DateYear, QString::number( data->date.year() ) );
343 map.insert( Progress, QString::number( data->prog ) ); 360 map.insert( Progress, QString::number( data->prog ) );
344 map.insert( CrossReference, crossToString() ); 361 map.insert( CrossReference, crossToString() );
345 map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); 362 map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) );
346 map.insert( AlarmDateTime, data->alarmDateTime.toString() ); 363 map.insert( AlarmDateTime, data->alarmDateTime.toString() );
347 364
348 return map; 365 return map;
349} 366}
350 367
351QMap<QString, QString> OTodo::toExtraMap()const { 368QMap<QString, QString> OTodo::toExtraMap()const {
352 return data->extra; 369 return data->extra;
353} 370}
354/** 371/**
355 * change or modify looks at the ref count and either 372 * change or modify looks at the ref count and either
356 * creates a new QShared Object or it can modify it 373 * creates a new QShared Object or it can modify it
357 * right in place 374 * right in place
358 */ 375 */
359void OTodo::changeOrModify() { 376void OTodo::changeOrModify() {
360 if ( data->count != 1 ) { 377 if ( data->count != 1 ) {
361// qWarning("changeOrModify"); 378 qWarning("changeOrModify");
362 data->deref(); 379 data->deref();
363 OTodoData* d2 = new OTodoData(); 380 OTodoData* d2 = new OTodoData();
364 copy(data, d2 ); 381 copy(data, d2 );
365 data = d2; 382 data = d2;
366 } 383 }
367} 384}
368void OTodo::copy( OTodoData* src, OTodoData* dest ) { 385void OTodo::copy( OTodoData* src, OTodoData* dest ) {
369 dest->date = src->date; 386 dest->date = src->date;
370 dest->isCompleted = src->isCompleted; 387 dest->isCompleted = src->isCompleted;
371 dest->hasDate = src->hasDate; 388 dest->hasDate = src->hasDate;
372 dest->priority = src->priority; 389 dest->priority = src->priority;
373 dest->desc = src->desc; 390 dest->desc = src->desc;
374 dest->sum = src->sum; 391 dest->sum = src->sum;
375 dest->extra = src->extra; 392 dest->extra = src->extra;
376 dest->prog = src->prog; 393 dest->prog = src->prog;
377 dest->hasAlarmDateTime = src->hasAlarmDateTime; 394 dest->hasAlarmDateTime = src->hasAlarmDateTime;
378 dest->alarmDateTime = src->alarmDateTime; 395 dest->alarmDateTime = src->alarmDateTime;
396 dest->state = src->state;
397 dest->recur = src->recur;
379} 398}
380QString OTodo::type() const { 399QString OTodo::type() const {
381 return QString::fromLatin1("OTodo"); 400 return QString::fromLatin1("OTodo");
382} 401}
383QString OTodo::recordField(int id )const { 402QString OTodo::recordField(int id )const {
384 return QString::null; 403 return QString::null;
385} 404}
386 405
diff --git a/libopie/pim/otodo.h b/libopie/pim/otodo.h
index 5bd91d6..2cdc587 100644
--- a/libopie/pim/otodo.h
+++ b/libopie/pim/otodo.h
@@ -1,209 +1,234 @@
1 1
2#ifndef OPIE_TODO_EVENT_H 2#ifndef OPIE_TODO_EVENT_H
3#define OPIE_TODO_EVENT_H 3#define OPIE_TODO_EVENT_H
4 4
5 5
6#include <qarray.h> 6#include <qarray.h>
7#include <qmap.h> 7#include <qmap.h>
8#include <qregexp.h> 8#include <qregexp.h>
9#include <qstringlist.h> 9#include <qstringlist.h>
10#include <qdatetime.h> 10#include <qdatetime.h>
11#include <qvaluelist.h> 11#include <qvaluelist.h>
12 12
13#include <qpe/recordfields.h> 13#include <qpe/recordfields.h>
14#include <qpe/palmtopuidgen.h> 14#include <qpe/palmtopuidgen.h>
15 15
16#include <opie/opimrecord.h> 16#include <opie/opimrecord.h>
17 17
18 18
19class OPimState;
20class ORecur;
19class OTodo : public OPimRecord { 21class OTodo : public OPimRecord {
20public: 22public:
21 typedef QValueList<OTodo> ValueList; 23 typedef QValueList<OTodo> ValueList;
22 enum RecordFields { 24 enum RecordFields {
23 Uid = Qtopia::UID_ID, 25 Uid = Qtopia::UID_ID,
24 Category = Qtopia::CATEGORY_ID, 26 Category = Qtopia::CATEGORY_ID,
25 HasDate, 27 HasDate,
26 Completed, 28 Completed,
27 Description, 29 Description,
28 Summary, 30 Summary,
29 Priority, 31 Priority,
30 DateDay, 32 DateDay,
31 DateMonth, 33 DateMonth,
32 DateYear, 34 DateYear,
33 Progress, 35 Progress,
34 CrossReference, 36 CrossReference,
35 HasAlarmDateTime, 37 HasAlarmDateTime,
36 AlarmDateTime 38 AlarmDateTime,
39 State,
40 Recurrance,
41 Alarms,
42 Reminders,
43 Notifiers
37 }; 44 };
38 public: 45 public:
39 // priorities from Very low to very high 46 // priorities from Very low to very high
40 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; 47 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow };
41 48
42 /* Constructs a new ToDoEvent 49 /* Constructs a new ToDoEvent
43 @param completed Is the TodoEvent completed 50 @param completed Is the TodoEvent completed
44 @param priority What is the priority of this ToDoEvent 51 @param priority What is the priority of this ToDoEvent
45 @param category Which category does it belong( uid ) 52 @param category Which category does it belong( uid )
46 @param summary A small summary of the todo 53 @param summary A small summary of the todo
47 @param description What is this ToDoEvent about 54 @param description What is this ToDoEvent about
48 @param hasDate Does this Event got a deadline 55 @param hasDate Does this Event got a deadline
49 @param date what is the deadline? 56 @param date what is the deadline?
50 @param uid what is the UUID of this Event 57 @param uid what is the UUID of this Event
51 **/ 58 **/
52 OTodo( bool completed = false, int priority = Normal, 59 OTodo( bool completed = false, int priority = Normal,
53 const QStringList &category = QStringList(), 60 const QStringList &category = QStringList(),
54 const QString &summary = QString::null , 61 const QString &summary = QString::null ,
55 const QString &description = QString::null, 62 const QString &description = QString::null,
56 ushort progress = 0, 63 ushort progress = 0,
57 bool hasDate = false, QDate date = QDate::currentDate(), 64 bool hasDate = false, QDate date = QDate::currentDate(),
58 int uid = 0 /*empty*/ ); 65 int uid = 0 /*empty*/ );
59 66
60 OTodo( bool completed, int priority, 67 OTodo( bool completed, int priority,
61 const QArray<int>& category, 68 const QArray<int>& category,
62 const QString& summary = QString::null, 69 const QString& summary = QString::null,
63 const QString& description = QString::null, 70 const QString& description = QString::null,
64 ushort progress = 0, 71 ushort progress = 0,
65 bool hasDate = false, QDate date = QDate::currentDate(), 72 bool hasDate = false, QDate date = QDate::currentDate(),
66 int uid = 0 /* empty */ ); 73 int uid = 0 /* empty */ );
67 74
68 /* Copy c'tor 75 /* Copy c'tor
69 76
70 **/ 77 **/
71 OTodo(const OTodo & ); 78 OTodo(const OTodo & );
72 79
73 /** 80 /**
74 *destructor 81 *destructor
75 */ 82 */
76 ~OTodo(); 83 ~OTodo();
77 84
78 /** 85 /**
79 * Is this event completed? 86 * Is this event completed?
80 */ 87 */
81 bool isCompleted() const; 88 bool isCompleted() const;
82 89
83 /** 90 /**
84 * Does this Event have a deadline 91 * Does this Event have a deadline
85 */ 92 */
86 bool hasDueDate() const; 93 bool hasDueDate() const;
87 94
88 /** 95 /**
89 * Does this Event has an alarm time ? 96 * Does this Event has an alarm time ?
90 */ 97 */
91 bool hasAlarmDateTime() const; 98 bool hasAlarmDateTime() const;
92 99
93 /** 100 /**
94 * What is the priority? 101 * What is the priority?
95 */ 102 */
96 int priority()const ; 103 int priority()const ;
97 104
98 /** 105 /**
99 * progress as ushort 0, 20, 40, 60, 80 or 100% 106 * progress as ushort 0, 20, 40, 60, 80 or 100%
100 */ 107 */
101 ushort progress() const; 108 ushort progress() const;
102 109
103 /** 110 /**
104 * The due Date 111 * The due Date
105 */ 112 */
106 QDate dueDate()const; 113 QDate dueDate()const;
107 114
108 /** 115 /**
109 * Alarm Date and Time 116 * Alarm Date and Time
110 */ 117 */
111 QDateTime alarmDateTime()const; 118 QDateTime alarmDateTime()const;
112 119
113 /** 120 /**
121 * What is the state of this OTodo?
122 */
123 OPimState state()const;
124
125 /**
126 * the recurrance of this
127 */
128 ORecur recurrence()const;
129
130 /**
114 * The description of the todo 131 * The description of the todo
115 */ 132 */
116 QString description()const; 133 QString description()const;
117 134
118 /** 135 /**
119 * A small summary of the todo 136 * A small summary of the todo
120 */ 137 */
121 QString summary() const; 138 QString summary() const;
122 139
123 /** 140 /**
124 * @reimplemented 141 * @reimplemented
125 * Return this todoevent in a RichText formatted QString 142 * Return this todoevent in a RichText formatted QString
126 */ 143 */
127 QString toRichText() const; 144 QString toRichText() const;
128 145
129 /** 146 /**
130 * reimplementation 147 * reimplementation
131 */ 148 */
132 QString type()const; 149 QString type()const;
133 QString toShortText()const; 150 QString toShortText()const;
134 QMap<QString, QString> toExtraMap()const; 151 QMap<QString, QString> toExtraMap()const;
135 QString recordField(int id )const; 152 QString recordField(int id )const;
136 153
137 /** 154 /**
138 * toMap puts all data into the map. int relates 155 * toMap puts all data into the map. int relates
139 * to ToDoEvent RecordFields enum 156 * to ToDoEvent RecordFields enum
140 */ 157 */
141 QMap<int, QString> toMap()const; 158 QMap<int, QString> toMap()const;
142 159
143 /** 160 /**
144 * Set if this Todo is completed 161 * Set if this Todo is completed
145 */ 162 */
146 void setCompleted(bool completed ); 163 void setCompleted(bool completed );
147 164
148 /** 165 /**
149 * set if this todo got an end data 166 * set if this todo got an end data
150 */ 167 */
151 void setHasDueDate( bool hasDate ); 168 void setHasDueDate( bool hasDate );
152 169
153 /** 170 /**
154 * set if this todo has an alarm time and date 171 * set if this todo has an alarm time and date
155 */ 172 */
156 void setHasAlarmDateTime ( bool hasAlarm ); 173 void setHasAlarmDateTime ( bool hasAlarm );
157 174
158 /** 175 /**
159 * Set the priority of the Todo 176 * Set the priority of the Todo
160 */ 177 */
161 void setPriority(int priority ); 178 void setPriority(int priority );
162 179
163 /** 180 /**
164 * Set the progress. 181 * Set the progress.
165 */ 182 */
166 void setProgress( ushort progress ); 183 void setProgress( ushort progress );
167 184
168 /** 185 /**
169 * set the end date 186 * set the end date
170 */ 187 */
171 void setDueDate( QDate date ); 188 void setDueDate( QDate date );
172 189
190
191 void setRecurrence( const ORecur& );
173 /** 192 /**
174 * set the alarm time 193 * set the alarm time
175 */ 194 */
176 void setAlarmDateTime ( const QDateTime& alarm ); 195 void setAlarmDateTime ( const QDateTime& alarm );
177 196
178 void setDescription(const QString& ); 197 void setDescription(const QString& );
179 void setSummary(const QString& ); 198 void setSummary(const QString& );
199
200 /**
201 * set the state of a Todo
202 * @param state State what the todo should take
203 */
204 void setState( const OPimState& state);
180 bool isOverdue(); 205 bool isOverdue();
181 206
182 207
183 bool match( const QRegExp &r )const; 208 bool match( const QRegExp &r )const;
184 209
185 bool operator<(const OTodo &toDoEvent )const; 210 bool operator<(const OTodo &toDoEvent )const;
186 bool operator<=(const OTodo &toDoEvent )const; 211 bool operator<=(const OTodo &toDoEvent )const;
187 bool operator!=(const OTodo &toDoEvent )const; 212 bool operator!=(const OTodo &toDoEvent )const;
188 bool operator>(const OTodo &toDoEvent )const; 213 bool operator>(const OTodo &toDoEvent )const;
189 bool operator>=(const OTodo &toDoEvent)const; 214 bool operator>=(const OTodo &toDoEvent)const;
190 bool operator==(const OTodo &toDoEvent )const; 215 bool operator==(const OTodo &toDoEvent )const;
191 OTodo &operator=(const OTodo &toDoEvent ); 216 OTodo &operator=(const OTodo &toDoEvent );
192 217
193 private: 218 private:
194 class OTodoPrivate; 219 class OTodoPrivate;
195 struct OTodoData; 220 struct OTodoData;
196 221
197 void deref(); 222 void deref();
198 inline void changeOrModify(); 223 inline void changeOrModify();
199 void copy( OTodoData* src, OTodoData* dest ); 224 void copy( OTodoData* src, OTodoData* dest );
200 OTodoPrivate *d; 225 OTodoPrivate *d;
201 OTodoData *data; 226 OTodoData *data;
202 227
203}; 228};
204inline bool OTodo::operator!=(const OTodo &toDoEvent )const { 229inline bool OTodo::operator!=(const OTodo &toDoEvent )const {
205 return !(*this == toDoEvent); 230 return !(*this == toDoEvent);
206} 231}
207 232
208 233
209#endif 234#endif
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index dbb94ed..d9ccad4 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -1,133 +1,133 @@
1#ifndef OPIE_PIM_RECORD_H 1#ifndef OPIE_PIM_RECORD_H
2#define OPIE_PIM_RECORD_H 2#define OPIE_PIM_RECORD_H
3 3
4#include <qmap.h> 4#include <qmap.h>
5#include <qstring.h> 5#include <qstring.h>
6#include <qstringlist.h> 6#include <qstringlist.h>
7 7
8#include <qpe/palmtoprecord.h> 8#include <qpe/palmtoprecord.h>
9 9
10 10
11/** 11/**
12 * This is the base class for 12 * This is the base class for
13 * all PIM Records 13 * all PIM Records
14 * 14 *
15 */ 15 */
16class OPimRecord : public Qtopia::Record { 16class OPimRecord : public Qtopia::Record {
17public: 17public:
18 /** 18 /**
19 * c'tor 19 * c'tor
20 * uid of 0 isEmpty 20 * uid of 0 isEmpty
21 * uid of 1 will be assigned a new one 21 * uid of 1 will be assigned a new one
22 */ 22 */
23 OPimRecord(int uid = 0); 23 OPimRecord(int uid = 0);
24 ~OPimRecord(); 24 ~OPimRecord();
25 25
26 /** 26 /**
27 * copy c'tor 27 * copy c'tor
28 */ 28 */
29 OPimRecord( const OPimRecord& rec ); 29 OPimRecord( const OPimRecord& rec );
30 30
31 /** 31 /**
32 * copy operator 32 * copy operator
33 */ 33 */
34 OPimRecord &operator=( const OPimRecord& ); 34 OPimRecord &operator=( const OPimRecord& );
35 35
36 /** 36 /**
37 * category names resolved 37 * category names resolved
38 */ 38 */
39 QStringList categoryNames()const; 39 QStringList categoryNames()const;
40 40
41 /** 41 /**
42 * set category names they will be resolved 42 * set category names they will be resolved
43 */ 43 */
44 void setCategoryNames( const QStringList& ); 44 void setCategoryNames( const QStringList& );
45 45
46 /** 46 /**
47 * addCategoryName adds a name 47 * addCategoryName adds a name
48 * to the internal category list 48 * to the internal category list
49 */ 49 */
50 void addCategoryName( const QString& ); 50 void addCategoryName( const QString& );
51 51
52 /** 52 /**
53 * if a Record isEmpty 53 * if a Record isEmpty
54 * it's empty if it's 0 54 * it's empty if it's 0
55 */ 55 */
56 virtual bool isEmpty()const; 56 virtual bool isEmpty()const;
57 57
58 /** 58 /**
59 * toRichText summary 59 * toRichText summary
60 */ 60 */
61 virtual QString toRichText()const = 0; 61 virtual QString toRichText()const = 0;
62 62
63 /** 63 /**
64 * a small one line summary 64 * a small one line summary
65 */ 65 */
66 virtual QString toShortText()const = 0; 66 virtual QString toShortText()const = 0;
67 67
68 /** 68 /**
69 * the name of the Record 69 * the name of the Record
70 */ 70 */
71 virtual QString type()const = 0; 71 virtual QString type()const = 0;
72 72
73 /** 73 /**
74 * converts the internal structure to a map 74 * converts the internal structure to a map
75 */ 75 */
76 virtual QMap<int, QString> toMap()const = 0; 76 virtual QMap<int, QString> toMap()const = 0;
77 77
78 /** 78 /**
79 * key value representation of extra items 79 * key value representation of extra items
80 */ 80 */
81 virtual QMap<QString, QString> toExtraMap()const = 0; 81 virtual QMap<QString, QString> toExtraMap()const = 0;
82 82
83 /** 83 /**
84 * the name for a recordField 84 * the name for a recordField
85 */ 85 */
86 virtual QString recordField(int)const = 0; 86 virtual QString recordField(int)const = 0;
87 87
88 /** 88 /**
89 * the related apps names 89 * the related apps names
90 */ 90 */
91 QStringList relatedApps()const; 91 QStringList relatedApps()const;
92 92
93 /** 93 /**
94 * the realtions between an app 94 * the realtions between an app
95 */ 95 */
96 QArray<int> relations( const QString& app )const; 96 QArray<int> relations( const QString& app )const;
97 97
98 /** 98 /**
99 * clear the relations for all relations 99 * clear the relations for all relations
100 * with app 100 * with app
101 */ 101 */
102 void clearRelation( const QString& app ); 102 void clearRelation( const QString& app );
103 103
104 /** 104 /**
105 * add a relation 105 * add a relation
106 */ 106 */
107 void addRelation( const QString& app, int id ); 107 void addRelation( const QString& app, int id );
108 108
109 /** 109 /**
110 * set the relations for an app 110 * set the relations for an app
111 */ 111 */
112 void setRelations( const QString&, QArray<int> ids ); 112 void setRelations( const QString&, QArray<int> ids );
113 113
114 /** 114 /**
115 * set the uid 115 * set the uid
116 */ 116 */
117 virtual void setUid( int uid ); 117 virtual void setUid( int uid );
118 118
119protected: 119protected:
120 Qtopia::UidGen &uidGen(); 120 Qtopia::UidGen &uidGen();
121 QString crossToString()const; 121 QString crossToString()const;
122 122
123private: 123private:
124 class OPimRecordPrivate; 124 class OPimRecordPrivate;
125 OPimRecordPrivate *d; 125 OPimRecordPrivate *d;
126 QMap<QString, QArray<int> > m_relations; 126 QMap<QString, QArray<int> > m_relations;
127 static Qtopia::UidGen m_uidGen; 127 static Qtopia::UidGen m_uidGen;
128 128
129}; 129};
130 130
131 131
132 132
133#endif 133#endif
diff --git a/libopie2/opiepim/core/opimstate.cpp b/libopie2/opiepim/core/opimstate.cpp
new file mode 100644
index 0000000..6fb2feb
--- a/dev/null
+++ b/libopie2/opiepim/core/opimstate.cpp
@@ -0,0 +1,64 @@
1#include <qshared.h>
2
3#include "opimstate.h"
4
5/*
6 * for one int this does not make
7 * much sense but never the less
8 * we will do it for the future
9 */
10struct OPimState::Data : public QShared {
11 Data() : QShared(),state(Undefined) {
12 }
13 int state;
14};
15
16OPimState::OPimState( int state ) {
17 data = new Data;
18 data->state = state;
19}
20OPimState::OPimState( const OPimState& st) :
21 data( st.data ) {
22 /* ref up */
23 data->ref();
24}
25OPimState::~OPimState() {
26 if ( data->deref() ) {
27 delete data ;
28 data = 0;
29 }
30}
31bool OPimState::operator==( const OPimState& st) {
32 if ( data->state == st.data->state ) return true;
33
34 return false;
35}
36OPimState &OPimState::operator=( const OPimState& st) {
37 st.data->ref();
38 deref();
39 data = st.data;
40
41 return *this;
42}
43void OPimState::setState( int st) {
44 copyInternally();
45 data->state = st;
46}
47int OPimState::state()const {
48 return data->state;
49}
50void OPimState::deref() {
51 if ( data->deref() ) {
52 delete data;
53 data = 0l;
54 }
55}
56void OPimState::copyInternally() {
57 /* we need to change it */
58 if ( data->count != 1 ) {
59 data->deref();
60 Data* d2 = new Data;
61 d2->state = data->state;
62 data = d2;
63 }
64}
diff --git a/libopie2/opiepim/core/opimstate.h b/libopie2/opiepim/core/opimstate.h
new file mode 100644
index 0000000..731181e
--- a/dev/null
+++ b/libopie2/opiepim/core/opimstate.h
@@ -0,0 +1,44 @@
1#ifndef OPIE_PIM_STATE_H
2#define OPIE_PIM_STATE_H
3
4#include <qstring.h>
5
6/**
7 * The State of a Task
8 * This class encapsules the state of a todo
9 * and it's shared too
10 */
11/*
12 * in c a simple struct would be enough ;)
13 * g_new_state();
14 * g_do_some_thing( state_t* );
15 * ;)
16 */
17class OPimState {
18public:
19 enum State {
20 Started = 0,
21 Postponed,
22 Finished,
23 NotStarted,
24 Undefined
25 };
26 OPimState( int state = Undefined );
27 OPimState( const OPimState& );
28 ~OPimState();
29
30 bool operator==( const OPimState& );
31 OPimState &operator=( const OPimState& );
32 void setState( int state);
33 int state()const;
34private:
35 void deref();
36 inline void copyInternally();
37 struct Data;
38 Data* data;
39 class Private;
40 Private *d;
41};
42
43
44#endif
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp
index 6c81f8f..257d4fd 100644
--- a/libopie2/opiepim/core/orecur.cpp
+++ b/libopie2/opiepim/core/orecur.cpp
@@ -1,127 +1,136 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qtopia/timeconversion.h> 3#include <qtopia/timeconversion.h>
4 4
5#include "orecur.h" 5#include "orecur.h"
6 6
7struct ORecur::Data : public QShared { 7struct ORecur::Data : public QShared {
8 Data() : QShared() { 8 Data() : QShared() {
9 type = ORecur::NoRepeat; 9 type = ORecur::NoRepeat;
10 freq = -1; 10 freq = -1;
11 days = 0; 11 days = 0;
12 pos = 0; 12 pos = 0;
13 create = -1; 13 create = -1;
14 hasEnd = FALSE; 14 hasEnd = FALSE;
15 end = 0; 15 end = 0;
16 } 16 }
17 char days; // Q_UINT8 for 8 seven days;) 17 char days; // Q_UINT8 for 8 seven days;)
18 ORecur::RepeatType type; 18 ORecur::RepeatType type;
19 int freq; 19 int freq;
20 int pos; 20 int pos;
21 bool hasEnd : 1; 21 bool hasEnd : 1;
22 time_t end; 22 time_t end;
23 time_t create; 23 time_t create;
24 int rep;
24}; 25};
25 26
26 27
27ORecur::ORecur() { 28ORecur::ORecur() {
28 data = new Data; 29 data = new Data;
29} 30}
30ORecur::ORecur( const ORecur& rec) 31ORecur::ORecur( const ORecur& rec)
31 : data( rec.data ) 32 : data( rec.data )
32{ 33{
33 data->ref(); 34 data->ref();
34} 35}
35ORecur::~ORecur() { 36ORecur::~ORecur() {
36 if ( data->deref() ) { 37 if ( data->deref() ) {
37 delete data; 38 delete data;
38 data = 0l; 39 data = 0l;
39 } 40 }
40} 41}
41void ORecur::deref() { 42void ORecur::deref() {
42 if ( data->deref() ) { 43 if ( data->deref() ) {
43 delete data; 44 delete data;
44 data = 0l; 45 data = 0l;
45 } 46 }
46} 47}
47bool ORecur::operator==( const ORecur& )const { 48bool ORecur::operator==( const ORecur& )const {
48 return false; 49 return false;
49} 50}
50ORecur &ORecur::operator=( const ORecur& re) { 51ORecur &ORecur::operator=( const ORecur& re) {
51 re.data->ref(); 52 re.data->ref();
52 deref(); 53 deref();
53 data = re.data; 54 data = re.data;
54 55
55 return *this; 56 return *this;
56} 57}
57ORecur::RepeatType ORecur::type()const{ 58ORecur::RepeatType ORecur::type()const{
58 return data->type; 59 return data->type;
59} 60}
60int ORecur::frequency()const { 61int ORecur::frequency()const {
61 return data->freq; 62 return data->freq;
62} 63}
63int ORecur::position()const { 64int ORecur::position()const {
64 return data->pos; 65 return data->pos;
65} 66}
66char ORecur::days() const{ 67char ORecur::days() const{
67 return data->days; 68 return data->days;
68} 69}
69bool ORecur::hasEndDate()const { 70bool ORecur::hasEndDate()const {
70 return data->hasEnd; 71 return data->hasEnd;
71} 72}
72QDate ORecur::endDate()const { 73QDate ORecur::endDate()const {
73 return TimeConversion::fromUTC( data->end ).date(); 74 return TimeConversion::fromUTC( data->end ).date();
74} 75}
75time_t ORecur::endDateUTC()const { 76time_t ORecur::endDateUTC()const {
76 return data->end; 77 return data->end;
77} 78}
78time_t ORecur::createTime()const { 79time_t ORecur::createTime()const {
79 return data->create; 80 return data->create;
80} 81}
82int ORecur::repetition()const {
83 return data->rep;
84}
81void ORecur::setType( const RepeatType& z) { 85void ORecur::setType( const RepeatType& z) {
82 checkOrModify(); 86 checkOrModify();
83 data->type = z; 87 data->type = z;
84} 88}
85void ORecur::setFrequency( int freq ) { 89void ORecur::setFrequency( int freq ) {
86 checkOrModify(); 90 checkOrModify();
87 data->freq = freq; 91 data->freq = freq;
88} 92}
89void ORecur::setPosition( int pos ) { 93void ORecur::setPosition( int pos ) {
90 checkOrModify(); 94 checkOrModify();
91 data->pos = pos; 95 data->pos = pos;
92} 96}
93void ORecur::setDays( char c ) { 97void ORecur::setDays( char c ) {
94 checkOrModify(); 98 checkOrModify();
95 data->days = c; 99 data->days = c;
96} 100}
97void ORecur::setEndDate( const QDate& dt) { 101void ORecur::setEndDate( const QDate& dt) {
98 checkOrModify(); 102 checkOrModify();
99 data->end = TimeConversion::toUTC( dt ); 103 data->end = TimeConversion::toUTC( dt );
100} 104}
101void ORecur::setEndDateUTC( time_t t) { 105void ORecur::setEndDateUTC( time_t t) {
102 checkOrModify(); 106 checkOrModify();
103 data->end = t; 107 data->end = t;
104} 108}
105void ORecur::setCreateTime( time_t t) { 109void ORecur::setCreateTime( time_t t) {
106 checkOrModify(); 110 checkOrModify();
107 data->create = t; 111 data->create = t;
108} 112}
109void ORecur::setHasEndDate( bool b) { 113void ORecur::setHasEndDate( bool b) {
110 checkOrModify(); 114 checkOrModify();
111 data->hasEnd = b; 115 data->hasEnd = b;
112} 116}
117void ORecur::setRepitition( int rep ) {
118 checkOrModify();
119 data->rep = rep;
120}
113void ORecur::checkOrModify() { 121void ORecur::checkOrModify() {
114 if ( data->count != 1 ) { 122 if ( data->count != 1 ) {
115 data->deref(); 123 data->deref();
116 Data* d2 = new Data; 124 Data* d2 = new Data;
117 d2->days = data->days; 125 d2->days = data->days;
118 d2->type = data->type; 126 d2->type = data->type;
119 d2->freq = data->freq; 127 d2->freq = data->freq;
120 d2->pos = data->pos; 128 d2->pos = data->pos;
121 d2->hasEnd = data->hasEnd; 129 d2->hasEnd = data->hasEnd;
122 d2->end = data->end; 130 d2->end = data->end;
123 d2->create = data->create; 131 d2->create = data->create;
132 d2->rep = data->rep;
124 data = d2; 133 data = d2;
125 } 134 }
126} 135}
127 136
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h
index 89258f8..d24d72d 100644
--- a/libopie2/opiepim/core/orecur.h
+++ b/libopie2/opiepim/core/orecur.h
@@ -1,54 +1,56 @@
1/* 1/*
2 * GPL from TT 2 * GPL from TT
3 */ 3 */
4 4
5#ifndef OPIE_RECUR_H 5#ifndef OPIE_RECUR_H
6#define OPIE_RECUR_H 6#define OPIE_RECUR_H
7 7
8#include <sys/types.h> 8#include <sys/types.h>
9 9
10#include <qdatetime.h> 10#include <qdatetime.h>
11 11
12 12
13 13
14class ORecur { 14class ORecur {
15public: 15public:
16 enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, 16 enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay,
17 MonthlyDate, Yearly }; 17 MonthlyDate, Yearly };
18 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, 18 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
19 FRI = 0x10, SAT = 0x20, SUN = 0x40 }; 19 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
20 ORecur(); 20 ORecur();
21 ORecur( const ORecur& ); 21 ORecur( const ORecur& );
22 ~ORecur(); 22 ~ORecur();
23 23
24 ORecur &operator=( const ORecur& ); 24 ORecur &operator=( const ORecur& );
25 bool operator==(const ORecur& )const; 25 bool operator==(const ORecur& )const;
26 RepeatType type()const; 26 RepeatType type()const;
27 int frequency()const; 27 int frequency()const;
28 int position()const; 28 int position()const;
29 char days()const; 29 char days()const;
30 bool hasEndDate()const; 30 bool hasEndDate()const;
31 QDate endDate()const; 31 QDate endDate()const;
32 time_t endDateUTC()const; 32 time_t endDateUTC()const;
33 time_t createTime()const; 33 time_t createTime()const;
34 int repetition()const;
34 35
35 void setType( const RepeatType& ); 36 void setType( const RepeatType& );
36 void setFrequency( int freq ); 37 void setFrequency( int freq );
37 void setPosition( int pos ); 38 void setPosition( int pos );
38 void setDays( char c); 39 void setDays( char c);
39 void setEndDate( const QDate& dt ); 40 void setEndDate( const QDate& dt );
40 void setEndDateUTC( time_t ); 41 void setEndDateUTC( time_t );
41 void setCreateTime( time_t ); 42 void setCreateTime( time_t );
42 void setHasEndDate( bool b ); 43 void setHasEndDate( bool b );
44 void setRepitition(int );
43private: 45private:
44 void deref(); 46 void deref();
45 inline void checkOrModify(); 47 inline void checkOrModify();
46 48
47 49
48 class Data; 50 class Data;
49 Data* data; 51 Data* data;
50 class ORecurPrivate; 52 class ORecurPrivate;
51 ORecurPrivate *d; 53 ORecurPrivate *d;
52}; 54};
53 55
54#endif 56#endif
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index acd65c4..cd238ef 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -938,716 +938,725 @@ QStringList OContact::trfields()
938 list.append( QObject::tr( "Notes" ) ); 938 list.append( QObject::tr( "Notes" ) );
939 list.append( QObject::tr( "Groups" ) ); 939 list.append( QObject::tr( "Groups" ) );
940 940
941 return list; 941 return list;
942} 942}
943 943
944/*! 944/*!
945 \internal 945 \internal
946 Returns an untranslated list of field names for a contact. 946 Returns an untranslated list of field names for a contact.
947*/ 947*/
948QStringList OContact::untrfields() 948QStringList OContact::untrfields()
949{ 949{
950 QStringList list; 950 QStringList list;
951 951
952 list.append( "Name Title" ); 952 list.append( "Name Title" );
953 list.append( "First Name" ); 953 list.append( "First Name" );
954 list.append( "Middle Name" ); 954 list.append( "Middle Name" );
955 list.append( "Last Name" ); 955 list.append( "Last Name" );
956 list.append( "Suffix" ); 956 list.append( "Suffix" );
957 list.append( "File As" ); 957 list.append( "File As" );
958 958
959 list.append( "Job Title" ); 959 list.append( "Job Title" );
960 list.append( "Department" ); 960 list.append( "Department" );
961 list.append( "Company" ); 961 list.append( "Company" );
962 list.append( "Business Phone" ); 962 list.append( "Business Phone" );
963 list.append( "Business Fax" ); 963 list.append( "Business Fax" );
964 list.append( "Business Mobile" ); 964 list.append( "Business Mobile" );
965 965
966 list.append( "Default Email" ); 966 list.append( "Default Email" );
967 list.append( "Emails" ); 967 list.append( "Emails" );
968 968
969 list.append( "Home Phone" ); 969 list.append( "Home Phone" );
970 list.append( "Home Fax" ); 970 list.append( "Home Fax" );
971 list.append( "Home Mobile" ); 971 list.append( "Home Mobile" );
972 972
973 list.append( "Business Street" ); 973 list.append( "Business Street" );
974 list.append( "Business City" ); 974 list.append( "Business City" );
975 list.append( "Business State" ); 975 list.append( "Business State" );
976 list.append( "Business Zip" ); 976 list.append( "Business Zip" );
977 list.append( "Business Country" ); 977 list.append( "Business Country" );
978 list.append( "Business Pager" ); 978 list.append( "Business Pager" );
979 list.append( "Business WebPage" ); 979 list.append( "Business WebPage" );
980 980
981 list.append( "Office" ); 981 list.append( "Office" );
982 list.append( "Profession" ); 982 list.append( "Profession" );
983 list.append( "Assistant" ); 983 list.append( "Assistant" );
984 list.append( "Manager" ); 984 list.append( "Manager" );
985 985
986 list.append( "Home Street" ); 986 list.append( "Home Street" );
987 list.append( "Home City" ); 987 list.append( "Home City" );
988 list.append( "Home State" ); 988 list.append( "Home State" );
989 list.append( "Home Zip" ); 989 list.append( "Home Zip" );
990 list.append( "Home Country" ); 990 list.append( "Home Country" );
991 list.append( "Home Web Page" ); 991 list.append( "Home Web Page" );
992 992
993 list.append( "Spouse" ); 993 list.append( "Spouse" );
994 list.append( "Gender" ); 994 list.append( "Gender" );
995 list.append( "Birthday" ); 995 list.append( "Birthday" );
996 list.append( "Anniversary" ); 996 list.append( "Anniversary" );
997 list.append( "Nickname" ); 997 list.append( "Nickname" );
998 list.append( "Children" ); 998 list.append( "Children" );
999 999
1000 list.append( "Notes" ); 1000 list.append( "Notes" );
1001 list.append( "Groups" ); 1001 list.append( "Groups" );
1002 1002
1003 return list; 1003 return list;
1004} 1004}
1005 1005
1006/*! 1006/*!
1007 Sets the list of email address for contact to those contained in \a str. 1007 Sets the list of email address for contact to those contained in \a str.
1008 Email address should be separated by ';'s. 1008 Email address should be separated by ';'s.
1009*/ 1009*/
1010void OContact::setEmails( const QString &str ) 1010void OContact::setEmails( const QString &str )
1011{ 1011{
1012 replace( Qtopia::Emails, str ); 1012 replace( Qtopia::Emails, str );
1013 if ( str.isEmpty() ) 1013 if ( str.isEmpty() )
1014 setDefaultEmail( QString::null ); 1014 setDefaultEmail( QString::null );
1015} 1015}
1016 1016
1017/*! 1017/*!
1018 Sets the list of children for the contact to those contained in \a str. 1018 Sets the list of children for the contact to those contained in \a str.
1019*/ 1019*/
1020void OContact::setChildren( const QString &str ) 1020void OContact::setChildren( const QString &str )
1021{ 1021{
1022 replace( Qtopia::Children, str ); 1022 replace( Qtopia::Children, str );
1023} 1023}
1024 1024
1025// vcard conversion code 1025// vcard conversion code
1026/*! 1026/*!
1027 \internal 1027 \internal
1028*/ 1028*/
1029static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 1029static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
1030{ 1030{
1031 VObject *ret = 0; 1031 VObject *ret = 0;
1032 if ( o && !value.isEmpty() ) 1032 if ( o && !value.isEmpty() )
1033 ret = addPropValue( o, prop, value.latin1() ); 1033 ret = addPropValue( o, prop, value.latin1() );
1034 return ret; 1034 return ret;
1035} 1035}
1036 1036
1037/*! 1037/*!
1038 \internal 1038 \internal
1039*/ 1039*/
1040static inline VObject *safeAddProp( VObject *o, const char *prop) 1040static inline VObject *safeAddProp( VObject *o, const char *prop)
1041{ 1041{
1042 VObject *ret = 0; 1042 VObject *ret = 0;
1043 if ( o ) 1043 if ( o )
1044 ret = addProp( o, prop ); 1044 ret = addProp( o, prop );
1045 return ret; 1045 return ret;
1046} 1046}
1047 1047
1048/*! 1048/*!
1049 \internal 1049 \internal
1050*/ 1050*/
1051static VObject *createVObject( const OContact &c ) 1051static VObject *createVObject( const OContact &c )
1052{ 1052{
1053 VObject *vcard = newVObject( VCCardProp ); 1053 VObject *vcard = newVObject( VCCardProp );
1054 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 1054 safeAddPropValue( vcard, VCVersionProp, "2.1" );
1055 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 1055 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
1056 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 1056 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
1057 1057
1058 // full name 1058 // full name
1059 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 1059 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
1060 1060
1061 // name properties 1061 // name properties
1062 VObject *name = safeAddProp( vcard, VCNameProp ); 1062 VObject *name = safeAddProp( vcard, VCNameProp );
1063 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 1063 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
1064 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 1064 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
1065 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 1065 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
1066 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 1066 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
1067 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 1067 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
1068 1068
1069 // home properties 1069 // home properties
1070 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 1070 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
1071 safeAddProp( home_adr, VCHomeProp ); 1071 safeAddProp( home_adr, VCHomeProp );
1072 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 1072 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
1073 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 1073 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
1074 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 1074 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
1075 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 1075 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
1076 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 1076 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
1077 1077
1078 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 1078 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
1079 safeAddProp( home_phone, VCHomeProp ); 1079 safeAddProp( home_phone, VCHomeProp );
1080 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 1080 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
1081 safeAddProp( home_phone, VCHomeProp ); 1081 safeAddProp( home_phone, VCHomeProp );
1082 safeAddProp( home_phone, VCCellularProp ); 1082 safeAddProp( home_phone, VCCellularProp );
1083 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 1083 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
1084 safeAddProp( home_phone, VCHomeProp ); 1084 safeAddProp( home_phone, VCHomeProp );
1085 safeAddProp( home_phone, VCFaxProp ); 1085 safeAddProp( home_phone, VCFaxProp );
1086 1086
1087 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 1087 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
1088 safeAddProp( url, VCHomeProp ); 1088 safeAddProp( url, VCHomeProp );
1089 1089
1090 // work properties 1090 // work properties
1091 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 1091 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
1092 safeAddProp( work_adr, VCWorkProp ); 1092 safeAddProp( work_adr, VCWorkProp );
1093 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 1093 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
1094 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 1094 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
1095 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 1095 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
1096 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 1096 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
1097 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 1097 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
1098 1098
1099 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 1099 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
1100 safeAddProp( work_phone, VCWorkProp ); 1100 safeAddProp( work_phone, VCWorkProp );
1101 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 1101 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
1102 safeAddProp( work_phone, VCWorkProp ); 1102 safeAddProp( work_phone, VCWorkProp );
1103 safeAddProp( work_phone, VCCellularProp ); 1103 safeAddProp( work_phone, VCCellularProp );
1104 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 1104 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
1105 safeAddProp( work_phone, VCWorkProp ); 1105 safeAddProp( work_phone, VCWorkProp );
1106 safeAddProp( work_phone, VCFaxProp ); 1106 safeAddProp( work_phone, VCFaxProp );
1107 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 1107 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
1108 safeAddProp( work_phone, VCWorkProp ); 1108 safeAddProp( work_phone, VCWorkProp );
1109 safeAddProp( work_phone, VCPagerProp ); 1109 safeAddProp( work_phone, VCPagerProp );
1110 1110
1111 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 1111 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
1112 safeAddProp( url, VCWorkProp ); 1112 safeAddProp( url, VCWorkProp );
1113 1113
1114 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 1114 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
1115 safeAddProp( title, VCWorkProp ); 1115 safeAddProp( title, VCWorkProp );
1116 1116
1117 1117
1118 QStringList emails = c.emailList(); 1118 QStringList emails = c.emailList();
1119 emails.prepend( c.defaultEmail() ); 1119 emails.prepend( c.defaultEmail() );
1120 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 1120 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
1121 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 1121 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
1122 safeAddProp( email, VCInternetProp ); 1122 safeAddProp( email, VCInternetProp );
1123 } 1123 }
1124 1124
1125 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 1125 safeAddPropValue( vcard, VCNoteProp, c.notes() );
1126 1126
1127 // Exporting Birthday regarding RFC 2425 (5.8.4) 1127 // Exporting Birthday regarding RFC 2425 (5.8.4)
1128 if ( c.birthday().isValid() ){ 1128 if ( c.birthday().isValid() ){
1129 QString birthd_rfc2425 = QString("%1-%2-%3") 1129 QString birthd_rfc2425 = QString("%1-%2-%3")
1130 .arg( c.birthday().year() ) 1130 .arg( c.birthday().year() )
1131 .arg( c.birthday().month(), 2 ) 1131 .arg( c.birthday().month(), 2 )
1132 .arg( c.birthday().day(), 2 ); 1132 .arg( c.birthday().day(), 2 );
1133 // Now replace spaces with "0"... 1133 // Now replace spaces with "0"...
1134 int pos = 0; 1134 int pos = 0;
1135 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) 1135 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
1136 birthd_rfc2425.replace( pos, 1, "0" ); 1136 birthd_rfc2425.replace( pos, 1, "0" );
1137 1137
1138 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); 1138 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
1139 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); 1139 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
1140 } 1140 }
1141 1141
1142 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 1142 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
1143 VObject *org = safeAddProp( vcard, VCOrgProp ); 1143 VObject *org = safeAddProp( vcard, VCOrgProp );
1144 safeAddPropValue( org, VCOrgNameProp, c.company() ); 1144 safeAddPropValue( org, VCOrgNameProp, c.company() );
1145 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 1145 safeAddPropValue( org, VCOrgUnitProp, c.department() );
1146 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 1146 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
1147 } 1147 }
1148 1148
1149 // some values we have to export as custom fields 1149 // some values we have to export as custom fields
1150 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 1150 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
1151 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 1151 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
1152 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1152 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
1153 1153
1154 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1154 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
1155 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1155 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
1156 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); 1156 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
1157 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1157 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
1158 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1158 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
1159 1159
1160 return vcard; 1160 return vcard;
1161} 1161}
1162 1162
1163 1163
1164/*! 1164/*!
1165 \internal 1165 \internal
1166*/ 1166*/
1167static QDate convVCardDateToDate( const QString& datestr ) 1167static QDate convVCardDateToDate( const QString& datestr )
1168{ 1168{
1169 int monthPos = datestr.find('-'); 1169 int monthPos = datestr.find('-');
1170 int dayPos = datestr.find('-', monthPos+1 ); 1170 int dayPos = datestr.find('-', monthPos+1 );
1171 int sep_ignore = 1; 1171 int sep_ignore = 1;
1172 if ( monthPos == -1 || dayPos == -1 ) { 1172 if ( monthPos == -1 || dayPos == -1 ) {
1173 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1173 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1174 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 1174 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
1175 if ( datestr.length() == 8 ){ 1175 if ( datestr.length() == 8 ){
1176 monthPos = 4; 1176 monthPos = 4;
1177 dayPos = 6; 1177 dayPos = 6;
1178 sep_ignore = 0; 1178 sep_ignore = 0;
1179 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1179 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1180 } else { 1180 } else {
1181 return QDate(); 1181 return QDate();
1182 } 1182 }
1183 } 1183 }
1184 int y = datestr.left( monthPos ).toInt(); 1184 int y = datestr.left( monthPos ).toInt();
1185 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 1185 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
1186 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 1186 int d = datestr.mid( dayPos + sep_ignore ).toInt();
1187 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 1187 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
1188 QDate date ( y,m,d ); 1188 QDate date ( y,m,d );
1189 return date; 1189 return date;
1190} 1190}
1191 1191
1192static OContact parseVObject( VObject *obj ) 1192static OContact parseVObject( VObject *obj )
1193{ 1193{
1194 OContact c; 1194 OContact c;
1195 1195
1196 VObjectIterator it; 1196 VObjectIterator it;
1197 initPropIterator( &it, obj ); 1197 initPropIterator( &it, obj );
1198 while( moreIteration( &it ) ) { 1198 while( moreIteration( &it ) ) {
1199 VObject *o = nextVObject( &it ); 1199 VObject *o = nextVObject( &it );
1200 QCString name = vObjectName( o ); 1200 QCString name = vObjectName( o );
1201 QCString value = vObjectStringZValue( o ); 1201 QCString value = vObjectStringZValue( o );
1202 if ( name == VCNameProp ) { 1202 if ( name == VCNameProp ) {
1203 VObjectIterator nit; 1203 VObjectIterator nit;
1204 initPropIterator( &nit, o ); 1204 initPropIterator( &nit, o );
1205 while( moreIteration( &nit ) ) { 1205 while( moreIteration( &nit ) ) {
1206 VObject *o = nextVObject( &nit ); 1206 VObject *o = nextVObject( &nit );
1207 QCString name = vObjectTypeInfo( o ); 1207 QCString name = vObjectTypeInfo( o );
1208 QString value = vObjectStringZValue( o ); 1208 QString value = vObjectStringZValue( o );
1209 if ( name == VCNamePrefixesProp ) 1209 if ( name == VCNamePrefixesProp )
1210 c.setTitle( value ); 1210 c.setTitle( value );
1211 else if ( name == VCNameSuffixesProp ) 1211 else if ( name == VCNameSuffixesProp )
1212 c.setSuffix( value ); 1212 c.setSuffix( value );
1213 else if ( name == VCFamilyNameProp ) 1213 else if ( name == VCFamilyNameProp )
1214 c.setLastName( value ); 1214 c.setLastName( value );
1215 else if ( name == VCGivenNameProp ) 1215 else if ( name == VCGivenNameProp )
1216 c.setFirstName( value ); 1216 c.setFirstName( value );
1217 else if ( name == VCAdditionalNamesProp ) 1217 else if ( name == VCAdditionalNamesProp )
1218 c.setMiddleName( value ); 1218 c.setMiddleName( value );
1219 } 1219 }
1220 } 1220 }
1221 else if ( name == VCAdrProp ) { 1221 else if ( name == VCAdrProp ) {
1222 bool work = TRUE; // default address is work address 1222 bool work = TRUE; // default address is work address
1223 QString street; 1223 QString street;
1224 QString city; 1224 QString city;
1225 QString region; 1225 QString region;
1226 QString postal; 1226 QString postal;
1227 QString country; 1227 QString country;
1228 1228
1229 VObjectIterator nit; 1229 VObjectIterator nit;
1230 initPropIterator( &nit, o ); 1230 initPropIterator( &nit, o );
1231 while( moreIteration( &nit ) ) { 1231 while( moreIteration( &nit ) ) {
1232 VObject *o = nextVObject( &nit ); 1232 VObject *o = nextVObject( &nit );
1233 QCString name = vObjectName( o ); 1233 QCString name = vObjectName( o );
1234 QString value = vObjectStringZValue( o ); 1234 QString value = vObjectStringZValue( o );
1235 if ( name == VCHomeProp ) 1235 if ( name == VCHomeProp )
1236 work = FALSE; 1236 work = FALSE;
1237 else if ( name == VCWorkProp ) 1237 else if ( name == VCWorkProp )
1238 work = TRUE; 1238 work = TRUE;
1239 else if ( name == VCStreetAddressProp ) 1239 else if ( name == VCStreetAddressProp )
1240 street = value; 1240 street = value;
1241 else if ( name == VCCityProp ) 1241 else if ( name == VCCityProp )
1242 city = value; 1242 city = value;
1243 else if ( name == VCRegionProp ) 1243 else if ( name == VCRegionProp )
1244 region = value; 1244 region = value;
1245 else if ( name == VCPostalCodeProp ) 1245 else if ( name == VCPostalCodeProp )
1246 postal = value; 1246 postal = value;
1247 else if ( name == VCCountryNameProp ) 1247 else if ( name == VCCountryNameProp )
1248 country = value; 1248 country = value;
1249 } 1249 }
1250 if ( work ) { 1250 if ( work ) {
1251 c.setBusinessStreet( street ); 1251 c.setBusinessStreet( street );
1252 c.setBusinessCity( city ); 1252 c.setBusinessCity( city );
1253 c.setBusinessCountry( country ); 1253 c.setBusinessCountry( country );
1254 c.setBusinessZip( postal ); 1254 c.setBusinessZip( postal );
1255 c.setBusinessState( region ); 1255 c.setBusinessState( region );
1256 } else { 1256 } else {
1257 c.setHomeStreet( street ); 1257 c.setHomeStreet( street );
1258 c.setHomeCity( city ); 1258 c.setHomeCity( city );
1259 c.setHomeCountry( country ); 1259 c.setHomeCountry( country );
1260 c.setHomeZip( postal ); 1260 c.setHomeZip( postal );
1261 c.setHomeState( region ); 1261 c.setHomeState( region );
1262 } 1262 }
1263 } 1263 }
1264 else if ( name == VCTelephoneProp ) { 1264 else if ( name == VCTelephoneProp ) {
1265 enum { 1265 enum {
1266 HOME = 0x01, 1266 HOME = 0x01,
1267 WORK = 0x02, 1267 WORK = 0x02,
1268 VOICE = 0x04, 1268 VOICE = 0x04,
1269 CELL = 0x08, 1269 CELL = 0x08,
1270 FAX = 0x10, 1270 FAX = 0x10,
1271 PAGER = 0x20, 1271 PAGER = 0x20,
1272 UNKNOWN = 0x80 1272 UNKNOWN = 0x80
1273 }; 1273 };
1274 int type = 0; 1274 int type = 0;
1275 1275
1276 VObjectIterator nit; 1276 VObjectIterator nit;
1277 initPropIterator( &nit, o ); 1277 initPropIterator( &nit, o );
1278 while( moreIteration( &nit ) ) { 1278 while( moreIteration( &nit ) ) {
1279 VObject *o = nextVObject( &nit ); 1279 VObject *o = nextVObject( &nit );
1280 QCString name = vObjectTypeInfo( o ); 1280 QCString name = vObjectTypeInfo( o );
1281 if ( name == VCHomeProp ) 1281 if ( name == VCHomeProp )
1282 type |= HOME; 1282 type |= HOME;
1283 else if ( name == VCWorkProp ) 1283 else if ( name == VCWorkProp )
1284 type |= WORK; 1284 type |= WORK;
1285 else if ( name == VCVoiceProp ) 1285 else if ( name == VCVoiceProp )
1286 type |= VOICE; 1286 type |= VOICE;
1287 else if ( name == VCCellularProp ) 1287 else if ( name == VCCellularProp )
1288 type |= CELL; 1288 type |= CELL;
1289 else if ( name == VCFaxProp ) 1289 else if ( name == VCFaxProp )
1290 type |= FAX; 1290 type |= FAX;
1291 else if ( name == VCPagerProp ) 1291 else if ( name == VCPagerProp )
1292 type |= PAGER; 1292 type |= PAGER;
1293 else if ( name == VCPreferredProp ) 1293 else if ( name == VCPreferredProp )
1294 ; 1294 ;
1295 else 1295 else
1296 type |= UNKNOWN; 1296 type |= UNKNOWN;
1297 } 1297 }
1298 if ( (type & UNKNOWN) != UNKNOWN ) { 1298 if ( (type & UNKNOWN) != UNKNOWN ) {
1299 if ( ( type & (HOME|WORK) ) == 0 ) // default 1299 if ( ( type & (HOME|WORK) ) == 0 ) // default
1300 type |= HOME; 1300 type |= HOME;
1301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 1301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
1302 type |= VOICE; 1302 type |= VOICE;
1303 1303
1304 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 1304 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
1305 c.setHomePhone( value ); 1305 c.setHomePhone( value );
1306 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 1306 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
1307 c.setHomeFax( value ); 1307 c.setHomeFax( value );
1308 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 1308 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
1309 c.setHomeMobile( value ); 1309 c.setHomeMobile( value );
1310 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 1310 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
1311 c.setBusinessPhone( value ); 1311 c.setBusinessPhone( value );
1312 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 1312 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
1313 c.setBusinessFax( value ); 1313 c.setBusinessFax( value );
1314 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 1314 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
1315 c.setBusinessMobile( value ); 1315 c.setBusinessMobile( value );
1316 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 1316 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
1317 c.setBusinessPager( value ); 1317 c.setBusinessPager( value );
1318 } 1318 }
1319 } 1319 }
1320 else if ( name == VCEmailAddressProp ) { 1320 else if ( name == VCEmailAddressProp ) {
1321 QString email = vObjectStringZValue( o ); 1321 QString email = vObjectStringZValue( o );
1322 bool valid = TRUE; 1322 bool valid = TRUE;
1323 VObjectIterator nit; 1323 VObjectIterator nit;
1324 initPropIterator( &nit, o ); 1324 initPropIterator( &nit, o );
1325 while( moreIteration( &nit ) ) { 1325 while( moreIteration( &nit ) ) {
1326 VObject *o = nextVObject( &nit ); 1326 VObject *o = nextVObject( &nit );
1327 QCString name = vObjectTypeInfo( o ); 1327 QCString name = vObjectTypeInfo( o );
1328 if ( name != VCInternetProp && name != VCHomeProp && 1328 if ( name != VCInternetProp && name != VCHomeProp &&
1329 name != VCWorkProp && 1329 name != VCWorkProp &&
1330 name != VCPreferredProp ) 1330 name != VCPreferredProp )
1331 // ### preffered should map to default email 1331 // ### preffered should map to default email
1332 valid = FALSE; 1332 valid = FALSE;
1333 } 1333 }
1334 if ( valid ) { 1334 if ( valid ) {
1335 c.insertEmail( email ); 1335 c.insertEmail( email );
1336 } 1336 }
1337 } 1337 }
1338 else if ( name == VCURLProp ) { 1338 else if ( name == VCURLProp ) {
1339 VObjectIterator nit; 1339 VObjectIterator nit;
1340 initPropIterator( &nit, o ); 1340 initPropIterator( &nit, o );
1341 while( moreIteration( &nit ) ) { 1341 while( moreIteration( &nit ) ) {
1342 VObject *o = nextVObject( &nit ); 1342 VObject *o = nextVObject( &nit );
1343 QCString name = vObjectTypeInfo( o ); 1343 QCString name = vObjectTypeInfo( o );
1344 if ( name == VCHomeProp ) 1344 if ( name == VCHomeProp )
1345 c.setHomeWebpage( value ); 1345 c.setHomeWebpage( value );
1346 else if ( name == VCWorkProp ) 1346 else if ( name == VCWorkProp )
1347 c.setBusinessWebpage( value ); 1347 c.setBusinessWebpage( value );
1348 } 1348 }
1349 } 1349 }
1350 else if ( name == VCOrgProp ) { 1350 else if ( name == VCOrgProp ) {
1351 VObjectIterator nit; 1351 VObjectIterator nit;
1352 initPropIterator( &nit, o ); 1352 initPropIterator( &nit, o );
1353 while( moreIteration( &nit ) ) { 1353 while( moreIteration( &nit ) ) {
1354 VObject *o = nextVObject( &nit ); 1354 VObject *o = nextVObject( &nit );
1355 QCString name = vObjectName( o ); 1355 QCString name = vObjectName( o );
1356 QString value = vObjectStringZValue( o ); 1356 QString value = vObjectStringZValue( o );
1357 if ( name == VCOrgNameProp ) 1357 if ( name == VCOrgNameProp )
1358 c.setCompany( value ); 1358 c.setCompany( value );
1359 else if ( name == VCOrgUnitProp ) 1359 else if ( name == VCOrgUnitProp )
1360 c.setDepartment( value ); 1360 c.setDepartment( value );
1361 else if ( name == VCOrgUnit2Prop ) 1361 else if ( name == VCOrgUnit2Prop )
1362 c.setOffice( value ); 1362 c.setOffice( value );
1363 } 1363 }
1364 } 1364 }
1365 else if ( name == VCTitleProp ) { 1365 else if ( name == VCTitleProp ) {
1366 c.setJobTitle( value ); 1366 c.setJobTitle( value );
1367 } 1367 }
1368 else if ( name == "X-Qtopia-Profession" ) { 1368 else if ( name == "X-Qtopia-Profession" ) {
1369 c.setProfession( value ); 1369 c.setProfession( value );
1370 } 1370 }
1371 else if ( name == "X-Qtopia-Manager" ) { 1371 else if ( name == "X-Qtopia-Manager" ) {
1372 c.setManager( value ); 1372 c.setManager( value );
1373 } 1373 }
1374 else if ( name == "X-Qtopia-Assistant" ) { 1374 else if ( name == "X-Qtopia-Assistant" ) {
1375 c.setAssistant( value ); 1375 c.setAssistant( value );
1376 } 1376 }
1377 else if ( name == "X-Qtopia-Spouse" ) { 1377 else if ( name == "X-Qtopia-Spouse" ) {
1378 c.setSpouse( value ); 1378 c.setSpouse( value );
1379 } 1379 }
1380 else if ( name == "X-Qtopia-Gender" ) { 1380 else if ( name == "X-Qtopia-Gender" ) {
1381 c.setGender( value ); 1381 c.setGender( value );
1382 } 1382 }
1383 else if ( name == "X-Qtopia-Anniversary" ) { 1383 else if ( name == "X-Qtopia-Anniversary" ) {
1384 c.setAnniversary( TimeConversion::fromString( value ) ); 1384 c.setAnniversary( TimeConversion::fromString( value ) );
1385 } 1385 }
1386 else if ( name == "X-Qtopia-Nickname" ) { 1386 else if ( name == "X-Qtopia-Nickname" ) {
1387 c.setNickname( value ); 1387 c.setNickname( value );
1388 } 1388 }
1389 else if ( name == "X-Qtopia-Children" ) { 1389 else if ( name == "X-Qtopia-Children" ) {
1390 c.setChildren( value ); 1390 c.setChildren( value );
1391 } 1391 }
1392 else if ( name == VCBirthDateProp ) { 1392 else if ( name == VCBirthDateProp ) {
1393 // Reading Birthdate regarding RFC 2425 (5.8.4) 1393 // Reading Birthdate regarding RFC 2425 (5.8.4)
1394 c.setBirthday( convVCardDateToDate( value ) ); 1394 c.setBirthday( convVCardDateToDate( value ) );
1395 1395
1396 } 1396 }
1397 1397
1398#if 0 1398#if 0
1399 else { 1399 else {
1400 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1400 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
1401 VObjectIterator nit; 1401 VObjectIterator nit;
1402 initPropIterator( &nit, o ); 1402 initPropIterator( &nit, o );
1403 while( moreIteration( &nit ) ) { 1403 while( moreIteration( &nit ) ) {
1404 VObject *o = nextVObject( &nit ); 1404 VObject *o = nextVObject( &nit );
1405 QCString name = vObjectName( o ); 1405 QCString name = vObjectName( o );
1406 QString value = vObjectStringZValue( o ); 1406 QString value = vObjectStringZValue( o );
1407 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1407 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
1408 } 1408 }
1409 } 1409 }
1410#endif 1410#endif
1411 } 1411 }
1412 c.setFileAs(); 1412 c.setFileAs();
1413 return c; 1413 return c;
1414} 1414}
1415 1415
1416/*! 1416/*!
1417 Writes the list of \a contacts as a set of VCards to the file \a filename. 1417 Writes the list of \a contacts as a set of VCards to the file \a filename.
1418*/ 1418*/
1419void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) 1419void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts)
1420{ 1420{
1421 QFileDirect f( filename.utf8().data() ); 1421 QFileDirect f( filename.utf8().data() );
1422 if ( !f.open( IO_WriteOnly ) ) { 1422 if ( !f.open( IO_WriteOnly ) ) {
1423 qWarning("Unable to open vcard write"); 1423 qWarning("Unable to open vcard write");
1424 return; 1424 return;
1425 } 1425 }
1426 1426
1427 QValueList<OContact>::ConstIterator it; 1427 QValueList<OContact>::ConstIterator it;
1428 for( it = contacts.begin(); it != contacts.end(); ++it ) { 1428 for( it = contacts.begin(); it != contacts.end(); ++it ) {
1429 VObject *obj = createVObject( *it ); 1429 VObject *obj = createVObject( *it );
1430 writeVObject(f.directHandle() , obj ); 1430 writeVObject(f.directHandle() , obj );
1431 cleanVObject( obj ); 1431 cleanVObject( obj );
1432 } 1432 }
1433 cleanStrTbl(); 1433 cleanStrTbl();
1434} 1434}
1435 1435
1436/*! 1436/*!
1437 writes \a contact as a VCard to the file \a filename. 1437 writes \a contact as a VCard to the file \a filename.
1438*/ 1438*/
1439void OContact::writeVCard( const QString &filename, const OContact &contact) 1439void OContact::writeVCard( const QString &filename, const OContact &contact)
1440{ 1440{
1441 QFileDirect f( filename.utf8().data() ); 1441 QFileDirect f( filename.utf8().data() );
1442 if ( !f.open( IO_WriteOnly ) ) { 1442 if ( !f.open( IO_WriteOnly ) ) {
1443 qWarning("Unable to open vcard write"); 1443 qWarning("Unable to open vcard write");
1444 return; 1444 return;
1445 } 1445 }
1446 1446
1447 VObject *obj = createVObject( contact ); 1447 VObject *obj = createVObject( contact );
1448 writeVObject( f.directHandle() , obj ); 1448 writeVObject( f.directHandle() , obj );
1449 cleanVObject( obj ); 1449 cleanVObject( obj );
1450 1450
1451 cleanStrTbl(); 1451 cleanStrTbl();
1452} 1452}
1453 1453
1454/*! 1454/*!
1455 Returns the set of contacts read as VCards from the file \a filename. 1455 Returns the set of contacts read as VCards from the file \a filename.
1456*/ 1456*/
1457QValueList<OContact> OContact::readVCard( const QString &filename ) 1457QValueList<OContact> OContact::readVCard( const QString &filename )
1458{ 1458{
1459 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); 1459 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() ); 1460 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1461 1461
1462 qDebug("vobject = %p", obj ); 1462 qDebug("vobject = %p", obj );
1463 1463
1464 QValueList<OContact> contacts; 1464 QValueList<OContact> contacts;
1465 1465
1466 while ( obj ) { 1466 while ( obj ) {
1467 contacts.append( parseVObject( obj ) ); 1467 OContact con = parseVObject( obj );
1468 /*
1469 * if uid is 0 assign a new one
1470 * this at least happens on
1471 * Nokia6210
1472 */
1473 if ( con.uid() == 0 )
1474 con.setUid( 1 );
1475
1476 contacts.append(con );
1468 1477
1469 VObject *t = obj; 1478 VObject *t = obj;
1470 obj = nextVObjectInList(obj); 1479 obj = nextVObjectInList(obj);
1471 cleanVObject( t ); 1480 cleanVObject( t );
1472 } 1481 }
1473 1482
1474 return contacts; 1483 return contacts;
1475} 1484}
1476 1485
1477/*! 1486/*!
1478 Returns TRUE if the contact matches the regular expression \a regexp. 1487 Returns TRUE if the contact matches the regular expression \a regexp.
1479 Otherwise returns FALSE. 1488 Otherwise returns FALSE.
1480*/ 1489*/
1481bool OContact::match( const QString &regexp ) const 1490bool OContact::match( const QString &regexp ) const
1482{ 1491{
1483 return match(QRegExp(regexp)); 1492 return match(QRegExp(regexp));
1484} 1493}
1485 1494
1486/*! 1495/*!
1487 \overload 1496 \overload
1488 Returns TRUE if the contact matches the regular expression \a regexp. 1497 Returns TRUE if the contact matches the regular expression \a regexp.
1489 Otherwise returns FALSE. 1498 Otherwise returns FALSE.
1490*/ 1499*/
1491bool OContact::match( const QRegExp &r ) const 1500bool OContact::match( const QRegExp &r ) const
1492{ 1501{
1493 bool match; 1502 bool match;
1494 match = false; 1503 match = false;
1495 QMap<int, QString>::ConstIterator it; 1504 QMap<int, QString>::ConstIterator it;
1496 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 1505 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
1497 if ( (*it).find( r ) > -1 ) { 1506 if ( (*it).find( r ) > -1 ) {
1498 match = true; 1507 match = true;
1499 break; 1508 break;
1500 } 1509 }
1501 } 1510 }
1502 return match; 1511 return match;
1503} 1512}
1504 1513
1505 1514
1506QString OContact::toShortText() const 1515QString OContact::toShortText() const
1507{ 1516{
1508 return ( fullName() ); 1517 return ( fullName() );
1509} 1518}
1510QString OContact::type() const 1519QString OContact::type() const
1511{ 1520{
1512 return QString::fromLatin1( "OContact" ); 1521 return QString::fromLatin1( "OContact" );
1513} 1522}
1514 1523
1515// Definition is missing ! (se) 1524// Definition is missing ! (se)
1516QMap<QString,QString> OContact::toExtraMap() const 1525QMap<QString,QString> OContact::toExtraMap() const
1517{ 1526{
1518 qWarning ("Function not implemented: OContact::toExtraMap()"); 1527 qWarning ("Function not implemented: OContact::toExtraMap()");
1519 QMap <QString,QString> useless; 1528 QMap <QString,QString> useless;
1520 return useless; 1529 return useless;
1521} 1530}
1522 1531
1523class QString OContact::recordField( int pos ) const 1532class QString OContact::recordField( int pos ) const
1524{ 1533{
1525 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1534 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1526 return SLFIELDS[pos]; 1535 return SLFIELDS[pos];
1527} 1536}
1528 1537
1529// In future releases, we should store birthday and anniversary 1538// In future releases, we should store birthday and anniversary
1530// internally as QDate instead of QString ! 1539// internally as QDate instead of QString !
1531// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1540// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1532 1541
1533/*! \fn void OContact::setBirthday( const QDate& date ) 1542/*! \fn void OContact::setBirthday( const QDate& date )
1534 Sets the birthday for the contact to \a date. 1543 Sets the birthday for the contact to \a date.
1535*/ 1544*/
1536void OContact::setBirthday( const QDate &v ) 1545void OContact::setBirthday( const QDate &v )
1537{ 1546{
1538 if ( ( !v.isNull() ) && ( v.isValid() ) ) 1547 if ( ( !v.isNull() ) && ( v.isValid() ) )
1539 replace( Qtopia::Birthday, TimeConversion::toString( v ) ); 1548 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
1540 1549
1541} 1550}
1542 1551
1543 1552
1544/*! \fn void OContact::setAnniversary( const QDate &date ) 1553/*! \fn void OContact::setAnniversary( const QDate &date )
1545 Sets the anniversary of the contact to \a date. 1554 Sets the anniversary of the contact to \a date.
1546*/ 1555*/
1547void OContact::setAnniversary( const QDate &v ) 1556void OContact::setAnniversary( const QDate &v )
1548{ 1557{
1549 if ( ( !v.isNull() ) && ( v.isValid() ) ) 1558 if ( ( !v.isNull() ) && ( v.isValid() ) )
1550 replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); 1559 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
1551} 1560}
1552 1561
1553/*! \fn QDate OContact::birthday() const 1562/*! \fn QDate OContact::birthday() const
1554 Returns the birthday of the contact. 1563 Returns the birthday of the contact.
1555*/ 1564*/
1556QDate OContact::birthday() const 1565QDate OContact::birthday() const
1557{ 1566{
1558 QString str = find( Qtopia::Birthday ); 1567 QString str = find( Qtopia::Birthday );
1559 qWarning ("Birthday %s", str.latin1() ); 1568 qWarning ("Birthday %s", str.latin1() );
1560 if ( !str.isEmpty() ) 1569 if ( !str.isEmpty() )
1561 return TimeConversion::fromString ( str ); 1570 return TimeConversion::fromString ( str );
1562 else 1571 else
1563 return QDate(); 1572 return QDate();
1564} 1573}
1565 1574
1566 1575
1567/*! \fn QDate OContact::anniversary() const 1576/*! \fn QDate OContact::anniversary() const
1568 Returns the anniversary of the contact. 1577 Returns the anniversary of the contact.
1569*/ 1578*/
1570QDate OContact::anniversary() const 1579QDate OContact::anniversary() const
1571{ 1580{
1572 QDate empty; 1581 QDate empty;
1573 QString str = find( Qtopia::Anniversary ); 1582 QString str = find( Qtopia::Anniversary );
1574 qWarning ("Anniversary %s", str.latin1() ); 1583 qWarning ("Anniversary %s", str.latin1() );
1575 if ( !str.isEmpty() ) 1584 if ( !str.isEmpty() )
1576 return TimeConversion::fromString ( str ); 1585 return TimeConversion::fromString ( str );
1577 else 1586 else
1578 return empty; 1587 return empty;
1579} 1588}
1580 1589
1581 1590
1582void OContact::insertEmail( const QString &v ) 1591void OContact::insertEmail( const QString &v )
1583{ 1592{
1584 //qDebug("insertEmail %s", v.latin1()); 1593 //qDebug("insertEmail %s", v.latin1());
1585 QString e = v.simplifyWhiteSpace(); 1594 QString e = v.simplifyWhiteSpace();
1586 QString def = defaultEmail(); 1595 QString def = defaultEmail();
1587 1596
1588 // if no default, set it as the default email and don't insert 1597 // if no default, set it as the default email and don't insert
1589 if ( def.isEmpty() ) { 1598 if ( def.isEmpty() ) {
1590 setDefaultEmail( e ); // will insert into the list for us 1599 setDefaultEmail( e ); // will insert into the list for us
1591 return; 1600 return;
1592 } 1601 }
1593 1602
1594 // otherwise, insert assuming doesn't already exist 1603 // otherwise, insert assuming doesn't already exist
1595 QString emailsStr = find( Qtopia::Emails ); 1604 QString emailsStr = find( Qtopia::Emails );
1596 if ( emailsStr.contains( e )) 1605 if ( emailsStr.contains( e ))
1597 return; 1606 return;
1598 if ( !emailsStr.isEmpty() ) 1607 if ( !emailsStr.isEmpty() )
1599 emailsStr += emailSeparator(); 1608 emailsStr += emailSeparator();
1600 emailsStr += e; 1609 emailsStr += e;
1601 replace( Qtopia::Emails, emailsStr ); 1610 replace( Qtopia::Emails, emailsStr );
1602} 1611}
1603 1612
1604void OContact::removeEmail( const QString &v ) 1613void OContact::removeEmail( const QString &v )
1605{ 1614{
1606 QString e = v.simplifyWhiteSpace(); 1615 QString e = v.simplifyWhiteSpace();
1607 QString def = defaultEmail(); 1616 QString def = defaultEmail();
1608 QString emailsStr = find( Qtopia::Emails ); 1617 QString emailsStr = find( Qtopia::Emails );
1609 QStringList emails = emailList(); 1618 QStringList emails = emailList();
1610 1619
1611 // otherwise, must first contain it 1620 // otherwise, must first contain it
1612 if ( !emailsStr.contains( e ) ) 1621 if ( !emailsStr.contains( e ) )
1613 return; 1622 return;
1614 1623
1615 // remove it 1624 // remove it
1616 //qDebug(" removing email from list %s", e.latin1()); 1625 //qDebug(" removing email from list %s", e.latin1());
1617 emails.remove( e ); 1626 emails.remove( e );
1618 // reset the string 1627 // reset the string
1619 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1628 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1620 replace( Qtopia::Emails, emailsStr ); 1629 replace( Qtopia::Emails, emailsStr );
1621 1630
1622 // if default, then replace the default email with the first one 1631 // if default, then replace the default email with the first one
1623 if ( def == e ) { 1632 if ( def == e ) {
1624 //qDebug("removeEmail is default; setting new default"); 1633 //qDebug("removeEmail is default; setting new default");
1625 if ( !emails.count() ) 1634 if ( !emails.count() )
1626 clearEmails(); 1635 clearEmails();
1627 else // setDefaultEmail will remove e from the list 1636 else // setDefaultEmail will remove e from the list
1628 setDefaultEmail( emails.first() ); 1637 setDefaultEmail( emails.first() );
1629 } 1638 }
1630} 1639}
1631void OContact::clearEmails() 1640void OContact::clearEmails()
1632{ 1641{
1633 mMap.remove( Qtopia::DefaultEmail ); 1642 mMap.remove( Qtopia::DefaultEmail );
1634 mMap.remove( Qtopia::Emails ); 1643 mMap.remove( Qtopia::Emails );
1635} 1644}
1636void OContact::setDefaultEmail( const QString &v ) 1645void OContact::setDefaultEmail( const QString &v )
1637{ 1646{
1638 QString e = v.simplifyWhiteSpace(); 1647 QString e = v.simplifyWhiteSpace();
1639 1648
1640 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1649 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1641 replace( Qtopia::DefaultEmail, e ); 1650 replace( Qtopia::DefaultEmail, e );
1642 1651
1643 if ( !e.isEmpty() ) 1652 if ( !e.isEmpty() )
1644 insertEmail( e ); 1653 insertEmail( e );
1645 1654
1646} 1655}
1647 1656
1648void OContact::insertEmails( const QStringList &v ) 1657void OContact::insertEmails( const QStringList &v )
1649{ 1658{
1650 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1659 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1651 insertEmail( *it ); 1660 insertEmail( *it );
1652} 1661}
1653 1662
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h
index 2f4a5d3..8ed41e2 100644
--- a/libopie2/opiepim/orecordlist.h
+++ b/libopie2/opiepim/orecordlist.h
@@ -45,256 +45,256 @@ public:
45 ORecordListIterator &operator--(); 45 ORecordListIterator &operator--();
46 46
47 bool operator==( const ORecordListIterator& it ); 47 bool operator==( const ORecordListIterator& it );
48 bool operator!=( const ORecordListIterator& it ); 48 bool operator!=( const ORecordListIterator& it );
49 49
50 /** 50 /**
51 * the current item 51 * the current item
52 */ 52 */
53 uint current()const; 53 uint current()const;
54 54
55 /** 55 /**
56 * the number of items 56 * the number of items
57 */ 57 */
58 uint count()const; 58 uint count()const;
59 59
60 /** 60 /**
61 * sets the current item 61 * sets the current item
62 */ 62 */
63 void setCurrent( uint cur ); 63 void setCurrent( uint cur );
64 64
65private: 65private:
66 QArray<int> m_uids; 66 QArray<int> m_uids;
67 uint m_current; 67 uint m_current;
68 const Base* m_temp; 68 const Base* m_temp;
69 bool m_end : 1; 69 bool m_end : 1;
70 T m_record; 70 T m_record;
71 bool m_direction :1; 71 bool m_direction :1;
72 72
73 /* d pointer for future versions */ 73 /* d pointer for future versions */
74 class IteratorPrivate; 74 class IteratorPrivate;
75 IteratorPrivate *d; 75 IteratorPrivate *d;
76}; 76};
77/** 77/**
78 * The recordlist used as a return type 78 * The recordlist used as a return type
79 * from OPimAccessTemplate 79 * from OPimAccessTemplate
80 */ 80 */
81template <class T = OPimRecord > 81template <class T = OPimRecord >
82class ORecordList { 82class ORecordList {
83public: 83public:
84 typedef OTemplateBase<T> Base; 84 typedef OTemplateBase<T> Base;
85 typedef ORecordListIterator<T> Iterator; 85 typedef ORecordListIterator<T> Iterator;
86 86
87 /** 87 /**
88 * c'tor 88 * c'tor
89 */ 89 */
90 ORecordList () { 90 ORecordList () {
91 } 91 }
92ORecordList( const QArray<int>& ids, 92ORecordList( const QArray<int>& ids,
93 const Base* ); 93 const Base* );
94 ~ORecordList(); 94 ~ORecordList();
95 95
96 /** 96 /**
97 * the first iterator 97 * the first iterator
98 */ 98 */
99 Iterator begin(); 99 Iterator begin();
100 100
101 /** 101 /**
102 * the end 102 * the end
103 */ 103 */
104 Iterator end(); 104 Iterator end();
105 105
106 /** 106 /**
107 * the number of items in the list 107 * the number of items in the list
108 */ 108 */
109 uint count()const; 109 uint count()const;
110 110
111 T operator[]( uint i ); 111 T operator[]( uint i );
112 int uidAt(uint i ); 112 int uidAt(uint i );
113 113
114 /** 114 /**
115 * Remove the contact with given uid 115 * Remove the contact with given uid
116 */ 116 */
117 bool remove( int uid ); 117 bool remove( int uid );
118 118
119 /* 119 /*
120 ConstIterator begin()const; 120 ConstIterator begin()const;
121 ConstIterator end()const; 121 ConstIterator end()const;
122 */ 122 */
123private: 123private:
124 QArray<int> m_ids; 124 QArray<int> m_ids;
125 const Base* m_acc; 125 const Base* m_acc;
126}; 126};
127 127
128/* ok now implement it */ 128/* ok now implement it */
129template <class T> 129template <class T>
130ORecordListIterator<T>::ORecordListIterator() { 130ORecordListIterator<T>::ORecordListIterator() {
131 m_current = 0; 131 m_current = 0;
132 m_temp = 0l; 132 m_temp = 0l;
133 m_end = true; 133 m_end = true;
134 m_record = T(); 134 m_record = T();
135 /* forward */ 135 /* forward */
136 m_direction = TRUE; 136 m_direction = TRUE;
137} 137}
138template <class T> 138template <class T>
139ORecordListIterator<T>::~ORecordListIterator() { 139ORecordListIterator<T>::~ORecordListIterator() {
140/* nothing to delete */ 140/* nothing to delete */
141} 141}
142 142
143template <class T> 143template <class T>
144ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { 144ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
145// qWarning("ORecordListIterator copy c'tor"); 145// qWarning("ORecordListIterator copy c'tor");
146 m_uids = it.m_uids; 146 m_uids = it.m_uids;
147 m_current = it.m_current; 147 m_current = it.m_current;
148 m_temp = it.m_temp; 148 m_temp = it.m_temp;
149 m_end = it.m_end; 149 m_end = it.m_end;
150 m_record = it.m_record; 150 m_record = it.m_record;
151 m_direction = it.m_direction; 151 m_direction = it.m_direction;
152} 152}
153 153
154template <class T> 154template <class T>
155ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { 155ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
156 m_uids = it.m_uids; 156 m_uids = it.m_uids;
157 m_current = it.m_current; 157 m_current = it.m_current;
158 m_temp = it.m_temp; 158 m_temp = it.m_temp;
159 m_end = it.m_end; 159 m_end = it.m_end;
160 m_record = it.m_record; 160 m_record = it.m_record;
161 161
162 return *this; 162 return *this;
163} 163}
164 164
165template <class T> 165template <class T>
166T ORecordListIterator<T>::operator*() { 166T ORecordListIterator<T>::operator*() {
167 //qWarning("operator* %d %d", m_current, m_uids[m_current] ); 167 //qWarning("operator* %d %d", m_current, m_uids[m_current] );
168 if (!m_end ) 168 if (!m_end )
169 m_record = m_temp->find( m_uids[m_current], m_uids, m_current, 169 m_record = m_temp->find( m_uids[m_current], m_uids, m_current,
170 m_direction ? Base::Forward : 170 m_direction ? Base::Forward :
171 Base::Reverse ); 171 Base::Reverse );
172 else 172 else
173 m_record = T(); 173 m_record = T();
174 174
175 return m_record; 175 return m_record;
176} 176}
177 177
178template <class T> 178template <class T>
179ORecordListIterator<T> &ORecordListIterator<T>::operator++() { 179ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
180 m_direction = true; 180 m_direction = true;
181 if (m_current < m_uids.count() ) { 181 if (m_current < m_uids.count() ) {
182 m_end = false; 182 m_end = false;
183 ++m_current; 183 ++m_current;
184 }else 184 }else
185 m_end = true; 185 m_end = true;
186 186
187 return *this; 187 return *this;
188} 188}
189template <class T> 189template <class T>
190ORecordListIterator<T> &ORecordListIterator<T>::operator--() { 190ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
191 m_direction = false; 191 m_direction = false;
192 if ( m_current > 0 ) { 192 if ( m_current > 0 ) {
193 --m_current; 193 --m_current;
194 m_end = false; 194 m_end = false;
195 } else 195 } else
196 m_end = true; 196 m_end = true;
197 197
198 return *this; 198 return *this;
199} 199}
200 200
201template <class T> 201template <class T>
202bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { 202bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
203 203
204 /* if both are at we're the same.... */ 204 /* if both are at we're the same.... */
205 if ( m_end == it.m_end ) return true; 205 if ( m_end == it.m_end ) return true;
206 206
207 if ( m_uids != it.m_uids ) return false; 207 if ( m_uids != it.m_uids ) return false;
208 if ( m_current != it.m_current ) return false; 208 if ( m_current != it.m_current ) return false;
209 if ( m_temp != it.m_temp ) return false; 209 if ( m_temp != it.m_temp ) return false;
210 210
211 return true; 211 return true;
212} 212}
213template <class T> 213template <class T>
214bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 214bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
215 return !(*this == it ); 215 return !(*this == it );
216} 216}
217template <class T> 217template <class T>
218ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, 218ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids,
219 const Base* t ) 219 const Base* t )
220 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), 220 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ),
221 m_direction( false ) 221 m_direction( false )
222{ 222{
223} 223}
224template <class T> 224template <class T>
225uint ORecordListIterator<T>::current()const { 225uint ORecordListIterator<T>::current()const {
226 return m_current; 226 return m_current;
227} 227}
228template <class T> 228template <class T>
229void ORecordListIterator<T>::setCurrent( uint cur ) { 229void ORecordListIterator<T>::setCurrent( uint cur ) {
230 if( cur < m_uids.count() ) { 230 if( cur < m_uids.count() ) {
231 m_end = false; 231 m_end = false;
232 m_current= cur; 232 m_current= cur;
233 } 233 }
234} 234}
235template <class T> 235template <class T>
236uint ORecordListIterator<T>::count()const { 236uint ORecordListIterator<T>::count()const {
237 return m_uids.count(); 237 return m_uids.count();
238} 238}
239template <class T> 239template <class T>
240ORecordList<T>::ORecordList( const QArray<int>& ids, 240ORecordList<T>::ORecordList( const QArray<int>& ids,
241 const Base* acc ) 241 const Base* acc )
242 : m_ids( ids ), m_acc( acc ) 242 : m_ids( ids ), m_acc( acc )
243{ 243{
244} 244}
245template <class T> 245template <class T>
246ORecordList<T>::~ORecordList() { 246ORecordList<T>::~ORecordList() {
247/* nothing to do here */ 247/* nothing to do here */
248} 248}
249template <class T> 249template <class T>
250ORecordList<T>::Iterator ORecordList<T>::begin() { 250ORecordList<T>::Iterator ORecordList<T>::begin() {
251 Iterator it( m_ids, m_acc ); 251 Iterator it( m_ids, m_acc );
252 return it; 252 return it;
253} 253}
254template <class T> 254template <class T>
255ORecordList<T>::Iterator ORecordList<T>::end() { 255ORecordList<T>::Iterator ORecordList<T>::end() {
256 Iterator it( m_ids, m_acc ); 256 Iterator it( m_ids, m_acc );
257 it.m_end = true; 257 it.m_end = true;
258 it.m_current = m_ids.count(); 258 it.m_current = m_ids.count();
259 259
260 return it; 260 return it;
261} 261}
262template <class T> 262template <class T>
263uint ORecordList<T>::count()const { 263uint ORecordList<T>::count()const {
264return m_ids.count(); 264return m_ids.count();
265} 265}
266template <class T> 266template <class T>
267T ORecordList<T>::operator[]( uint i ) { 267T ORecordList<T>::operator[]( uint i ) {
268 if ( i < 0 || (i+1) > m_ids.count() ) 268 if ( i < 0 || (i+1) > m_ids.count() )
269 return T(); 269 return T();
270 /* forward */ 270 /* forward */
271 return m_acc->find( m_ids[i], m_ids, i ); 271 return m_acc->find( m_ids[i], m_ids, i );
272} 272}
273template <class T> 273template <class T>
274int ORecordList<T>::uidAt( uint i ) { 274int ORecordList<T>::uidAt( uint i ) {
275 return m_ids[i]; 275 return m_ids[i];
276} 276}
277 277
278template <class T> 278template <class T>
279bool ORecordList<T>::remove( int uid ) { 279bool ORecordList<T>::remove( int uid ) {
280 QArray<int> copy( m_ids.count() ); 280 QArray<int> copy( m_ids.count() );
281 int counter = 0; 281 int counter = 0;
282 bool ret_val = false; 282 bool ret_val = false;
283 283
284 for (uint i = 0; i < m_ids.count(); i++){ 284 for (uint i = 0; i < m_ids.count(); i++){
285 if ( m_ids[i] != uid ){ 285 if ( m_ids[i] != uid ){
286 copy[counter++] = m_ids[i]; 286 copy[counter++] = m_ids[i];
287 287
288 }else 288 }else
289 ret_val = true; 289 ret_val = true;
290 } 290 }
291 291
292 copy.resize( counter ); 292 copy.resize( counter );
293 m_ids = copy; 293 m_ids = copy;
294 294
295 295
296 return ret_val; 296 return ret_val;
297} 297}
298 298
299 299
300#endif 300#endif
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp
index 765d5a9..0d5b1d3 100644
--- a/libopie2/opiepim/otodo.cpp
+++ b/libopie2/opiepim/otodo.cpp
@@ -1,386 +1,405 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15 15#include "opimstate.h"
16#include "orecur.h"
16#include "otodo.h" 17#include "otodo.h"
17 18
18 19
19struct OTodo::OTodoData : public QShared { 20struct OTodo::OTodoData : public QShared {
20 OTodoData() : QShared() { 21 OTodoData() : QShared() {
21 }; 22 };
22 23
23 QDate date; 24 QDate date;
24 bool isCompleted:1; 25 bool isCompleted:1;
25 bool hasDate:1; 26 bool hasDate:1;
26 int priority; 27 int priority;
27 QString desc; 28 QString desc;
28 QString sum; 29 QString sum;
29 QMap<QString, QString> extra; 30 QMap<QString, QString> extra;
30 ushort prog; 31 ushort prog;
31 bool hasAlarmDateTime :1; 32 bool hasAlarmDateTime :1;
32 QDateTime alarmDateTime; 33 QDateTime alarmDateTime;
34 OPimState state;
35 ORecur recur;
33}; 36};
34 37
35OTodo::OTodo(const OTodo &event ) 38OTodo::OTodo(const OTodo &event )
36 : OPimRecord( event ), data( event.data ) 39 : OPimRecord( event ), data( event.data )
37{ 40{
38 data->ref(); 41 data->ref();
39// qWarning("ref up"); 42// qWarning("ref up");
40} 43}
41OTodo::~OTodo() { 44OTodo::~OTodo() {
42 45
43// qWarning("~OTodo " ); 46// qWarning("~OTodo " );
44 if ( data->deref() ) { 47 if ( data->deref() ) {
45// qWarning("OTodo::dereffing"); 48// qWarning("OTodo::dereffing");
46 delete data; 49 delete data;
47 data = 0l; 50 data = 0l;
48 } 51 }
49} 52}
50OTodo::OTodo(bool completed, int priority, 53OTodo::OTodo(bool completed, int priority,
51 const QArray<int> &category, 54 const QArray<int> &category,
52 const QString& summary, 55 const QString& summary,
53 const QString &description, 56 const QString &description,
54 ushort progress, 57 ushort progress,
55 bool hasDate, QDate date, int uid ) 58 bool hasDate, QDate date, int uid )
56 : OPimRecord( uid ) 59 : OPimRecord( uid )
57{ 60{
58// qWarning("OTodoData " + summary); 61// qWarning("OTodoData " + summary);
59 setCategories( category ); 62 setCategories( category );
60 63
61 data = new OTodoData; 64 data = new OTodoData;
62 65
63 data->date = date; 66 data->date = date;
64 data->isCompleted = completed; 67 data->isCompleted = completed;
65 data->hasDate = hasDate; 68 data->hasDate = hasDate;
66 data->priority = priority; 69 data->priority = priority;
67 data->sum = summary; 70 data->sum = summary;
68 data->prog = progress; 71 data->prog = progress;
69 data->desc = Qtopia::simplifyMultiLineSpace(description ); 72 data->desc = Qtopia::simplifyMultiLineSpace(description );
70 data->hasAlarmDateTime = false; 73 data->hasAlarmDateTime = false;
71 74
72} 75}
73OTodo::OTodo(bool completed, int priority, 76OTodo::OTodo(bool completed, int priority,
74 const QStringList &category, 77 const QStringList &category,
75 const QString& summary, 78 const QString& summary,
76 const QString &description, 79 const QString &description,
77 ushort progress, 80 ushort progress,
78 bool hasDate, QDate date, int uid ) 81 bool hasDate, QDate date, int uid )
79 : OPimRecord( uid ) 82 : OPimRecord( uid )
80{ 83{
81// qWarning("OTodoData" + summary); 84// qWarning("OTodoData" + summary);
82 setCategories( idsFromString( category.join(";") ) ); 85 setCategories( idsFromString( category.join(";") ) );
83 86
84 data = new OTodoData; 87 data = new OTodoData;
85 88
86 data->date = date; 89 data->date = date;
87 data->isCompleted = completed; 90 data->isCompleted = completed;
88 data->hasDate = hasDate; 91 data->hasDate = hasDate;
89 data->priority = priority; 92 data->priority = priority;
90 data->sum = summary; 93 data->sum = summary;
91 data->prog = progress; 94 data->prog = progress;
92 data->desc = Qtopia::simplifyMultiLineSpace(description ); 95 data->desc = Qtopia::simplifyMultiLineSpace(description );
93 data->hasAlarmDateTime = false; 96 data->hasAlarmDateTime = false;
94 97
95} 98}
96bool OTodo::match( const QRegExp &regExp )const 99bool OTodo::match( const QRegExp &regExp )const
97{ 100{
98 if( QString::number( data->priority ).find( regExp ) != -1 ){ 101 if( QString::number( data->priority ).find( regExp ) != -1 ){
99 return true; 102 return true;
100 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 103 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
101 return true; 104 return true;
102 }else if(data->desc.find( regExp ) != -1 ){ 105 }else if(data->desc.find( regExp ) != -1 ){
103 return true; 106 return true;
104 }else if(data->sum.find( regExp ) != -1 ) { 107 }else if(data->sum.find( regExp ) != -1 ) {
105 return true; 108 return true;
106 } 109 }
107 return false; 110 return false;
108} 111}
109bool OTodo::isCompleted() const 112bool OTodo::isCompleted() const
110{ 113{
111 return data->isCompleted; 114 return data->isCompleted;
112} 115}
113bool OTodo::hasDueDate() const 116bool OTodo::hasDueDate() const
114{ 117{
115 return data->hasDate; 118 return data->hasDate;
116} 119}
117bool OTodo::hasAlarmDateTime() const 120bool OTodo::hasAlarmDateTime() const
118{ 121{
119 return data->hasAlarmDateTime; 122 return data->hasAlarmDateTime;
120} 123}
121int OTodo::priority()const 124int OTodo::priority()const
122{ 125{
123 return data->priority; 126 return data->priority;
124} 127}
125QString OTodo::summary() const 128QString OTodo::summary() const
126{ 129{
127 return data->sum; 130 return data->sum;
128} 131}
129ushort OTodo::progress() const 132ushort OTodo::progress() const
130{ 133{
131 return data->prog; 134 return data->prog;
132} 135}
133QDate OTodo::dueDate()const 136QDate OTodo::dueDate()const
134{ 137{
135 return data->date; 138 return data->date;
136} 139}
137 140
138QDateTime OTodo::alarmDateTime() const 141QDateTime OTodo::alarmDateTime() const
139{ 142{
140 return data->alarmDateTime; 143 return data->alarmDateTime;
141} 144}
142 145
143QString OTodo::description()const 146QString OTodo::description()const
144{ 147{
145 return data->desc; 148 return data->desc;
146} 149}
150OPimState OTodo::state()const {
151 return data->state;
152}
153ORecur OTodo::recurrence()const {
154 return data->recur;
155}
147void OTodo::setCompleted( bool completed ) 156void OTodo::setCompleted( bool completed )
148{ 157{
149 changeOrModify(); 158 changeOrModify();
150 data->isCompleted = completed; 159 data->isCompleted = completed;
151} 160}
152void OTodo::setHasDueDate( bool hasDate ) 161void OTodo::setHasDueDate( bool hasDate )
153{ 162{
154 changeOrModify(); 163 changeOrModify();
155 data->hasDate = hasDate; 164 data->hasDate = hasDate;
156} 165}
157void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) 166void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime )
158{ 167{
159 changeOrModify(); 168 changeOrModify();
160 data->hasAlarmDateTime = hasAlarmDateTime; 169 data->hasAlarmDateTime = hasAlarmDateTime;
161} 170}
162void OTodo::setDescription(const QString &desc ) 171void OTodo::setDescription(const QString &desc )
163{ 172{
164// qWarning( "desc " + desc ); 173// qWarning( "desc " + desc );
165 changeOrModify(); 174 changeOrModify();
166 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 175 data->desc = Qtopia::simplifyMultiLineSpace(desc );
167} 176}
168void OTodo::setSummary( const QString& sum ) 177void OTodo::setSummary( const QString& sum )
169{ 178{
170 changeOrModify(); 179 changeOrModify();
171 data->sum = sum; 180 data->sum = sum;
172} 181}
173void OTodo::setPriority(int prio ) 182void OTodo::setPriority(int prio )
174{ 183{
175 changeOrModify(); 184 changeOrModify();
176 data->priority = prio; 185 data->priority = prio;
177} 186}
178void OTodo::setDueDate( QDate date ) 187void OTodo::setDueDate( QDate date )
179{ 188{
180 changeOrModify(); 189 changeOrModify();
181 data->date = date; 190 data->date = date;
182} 191}
183void OTodo::setAlarmDateTime( const QDateTime& alarm ) 192void OTodo::setAlarmDateTime( const QDateTime& alarm )
184{ 193{
185 changeOrModify(); 194 changeOrModify();
186 data->alarmDateTime = alarm; 195 data->alarmDateTime = alarm;
187} 196}
197void OTodo::setState( const OPimState& state ) {
198 changeOrModify();
199 data->state = state;
200}
201void OTodo::setRecurrence( const ORecur& rec) {
202 changeOrModify();
203 data->recur = rec;
204}
188bool OTodo::isOverdue( ) 205bool OTodo::isOverdue( )
189{ 206{
190 if( data->hasDate && !data->isCompleted) 207 if( data->hasDate && !data->isCompleted)
191 return QDate::currentDate() > data->date; 208 return QDate::currentDate() > data->date;
192 return false; 209 return false;
193} 210}
194void OTodo::setProgress(ushort progress ) 211void OTodo::setProgress(ushort progress )
195{ 212{
196 changeOrModify(); 213 changeOrModify();
197 data->prog = progress; 214 data->prog = progress;
198} 215}
199QString OTodo::toShortText() const { 216QString OTodo::toShortText() const {
200 return summary(); 217 return summary();
201} 218}
202/*! 219/*!
203 Returns a richt text string 220 Returns a richt text string
204*/ 221*/
205QString OTodo::toRichText() const 222QString OTodo::toRichText() const
206{ 223{
207 QString text; 224 QString text;
208 QStringList catlist; 225 QStringList catlist;
209 226
210 // Description of the todo 227 // Description of the todo
211 if ( !summary().isEmpty() ) { 228 if ( !summary().isEmpty() ) {
212 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 229 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
213 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 230 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
214 } 231 }
215 if( !description().isEmpty() ){ 232 if( !description().isEmpty() ){
216 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 233 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
217 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 234 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
218 } 235 }
219 text += "<br><br><br>"; 236 text += "<br><br><br>";
220 237
221 text += "<b>" + QObject::tr( "Priority:") +" </b>" 238 text += "<b>" + QObject::tr( "Priority:") +" </b>"
222 + QString::number( priority() ) + " <br>"; 239 + QString::number( priority() ) + " <br>";
223 text += "<b>" + QObject::tr( "Progress:") + " </b>" 240 text += "<b>" + QObject::tr( "Progress:") + " </b>"
224 + QString::number( progress() ) + " %<br>"; 241 + QString::number( progress() ) + " %<br>";
225 if (hasDueDate() ){ 242 if (hasDueDate() ){
226 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 243 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
227 text += dueDate().toString(); 244 text += dueDate().toString();
228 text += "<br>"; 245 text += "<br>";
229 } 246 }
230 if (hasAlarmDateTime() ){ 247 if (hasAlarmDateTime() ){
231 text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>"; 248 text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>";
232 text += alarmDateTime().toString(); 249 text += alarmDateTime().toString();
233 text += "<br>"; 250 text += "<br>";
234 } 251 }
235 252
236 text += "<b>" + QObject::tr( "Category:") + "</b> "; 253 text += "<b>" + QObject::tr( "Category:") + "</b> ";
237 text += categoryNames().join(", "); 254 text += categoryNames().join(", ");
238 text += "<br>"; 255 text += "<br>";
239 256
240 return text; 257 return text;
241} 258}
242 259
243bool OTodo::operator<( const OTodo &toDoEvent )const{ 260bool OTodo::operator<( const OTodo &toDoEvent )const{
244 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 261 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
245 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 262 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
246 if( hasDueDate() && toDoEvent.hasDueDate() ){ 263 if( hasDueDate() && toDoEvent.hasDueDate() ){
247 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 264 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
248 return priority() < toDoEvent.priority(); 265 return priority() < toDoEvent.priority();
249 }else{ 266 }else{
250 return dueDate() < toDoEvent.dueDate(); 267 return dueDate() < toDoEvent.dueDate();
251 } 268 }
252 } 269 }
253 return false; 270 return false;
254} 271}
255bool OTodo::operator<=(const OTodo &toDoEvent )const 272bool OTodo::operator<=(const OTodo &toDoEvent )const
256{ 273{
257 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 274 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
258 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 275 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
259 if( hasDueDate() && toDoEvent.hasDueDate() ){ 276 if( hasDueDate() && toDoEvent.hasDueDate() ){
260 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 277 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
261 return priority() <= toDoEvent.priority(); 278 return priority() <= toDoEvent.priority();
262 }else{ 279 }else{
263 return dueDate() <= toDoEvent.dueDate(); 280 return dueDate() <= toDoEvent.dueDate();
264 } 281 }
265 } 282 }
266 return true; 283 return true;
267} 284}
268bool OTodo::operator>(const OTodo &toDoEvent )const 285bool OTodo::operator>(const OTodo &toDoEvent )const
269{ 286{
270 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 287 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
271 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 288 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
272 if( hasDueDate() && toDoEvent.hasDueDate() ){ 289 if( hasDueDate() && toDoEvent.hasDueDate() ){
273 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 290 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
274 return priority() > toDoEvent.priority(); 291 return priority() > toDoEvent.priority();
275 }else{ 292 }else{
276 return dueDate() > toDoEvent.dueDate(); 293 return dueDate() > toDoEvent.dueDate();
277 } 294 }
278 } 295 }
279 return false; 296 return false;
280} 297}
281bool OTodo::operator>=(const OTodo &toDoEvent )const 298bool OTodo::operator>=(const OTodo &toDoEvent )const
282{ 299{
283 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 300 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
284 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 301 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
285 if( hasDueDate() && toDoEvent.hasDueDate() ){ 302 if( hasDueDate() && toDoEvent.hasDueDate() ){
286 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 303 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
287 return priority() > toDoEvent.priority(); 304 return priority() > toDoEvent.priority();
288 }else{ 305 }else{
289 return dueDate() > toDoEvent.dueDate(); 306 return dueDate() > toDoEvent.dueDate();
290 } 307 }
291 } 308 }
292 return true; 309 return true;
293} 310}
294bool OTodo::operator==(const OTodo &toDoEvent )const 311bool OTodo::operator==(const OTodo &toDoEvent )const
295{ 312{
296 if ( data->priority != toDoEvent.data->priority ) return false; 313 if ( data->priority != toDoEvent.data->priority ) return false;
297 if ( data->priority != toDoEvent.data->prog ) return false; 314 if ( data->priority != toDoEvent.data->prog ) return false;
298 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 315 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
299 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 316 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
300 if ( data->date != toDoEvent.data->date ) return false; 317 if ( data->date != toDoEvent.data->date ) return false;
301 if ( data->sum != toDoEvent.data->sum ) return false; 318 if ( data->sum != toDoEvent.data->sum ) return false;
302 if ( data->desc != toDoEvent.data->desc ) return false; 319 if ( data->desc != toDoEvent.data->desc ) return false;
303 if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime ) 320 if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime )
304 return false; 321 return false;
305 if ( data->alarmDateTime != toDoEvent.data->alarmDateTime ) 322 if ( data->alarmDateTime != toDoEvent.data->alarmDateTime )
306 return false; 323 return false;
307 324
308 return OPimRecord::operator==( toDoEvent ); 325 return OPimRecord::operator==( toDoEvent );
309} 326}
310void OTodo::deref() { 327void OTodo::deref() {
311 328
312// qWarning("deref in ToDoEvent"); 329// qWarning("deref in ToDoEvent");
313 if ( data->deref() ) { 330 if ( data->deref() ) {
314// qWarning("deleting"); 331// qWarning("deleting");
315 delete data; 332 delete data;
316 data= 0; 333 data= 0;
317 } 334 }
318} 335}
319OTodo &OTodo::operator=(const OTodo &item ) 336OTodo &OTodo::operator=(const OTodo &item )
320{ 337{
321 OPimRecord::operator=( item ); 338 OPimRecord::operator=( item );
322 //qWarning("operator= ref "); 339 //qWarning("operator= ref ");
323 item.data->ref(); 340 item.data->ref();
324 deref(); 341 deref();
325 data = item.data; 342 data = item.data;
326 343
327 return *this; 344 return *this;
328} 345}
329 346
330QMap<int, QString> OTodo::toMap() const { 347QMap<int, QString> OTodo::toMap() const {
331 QMap<int, QString> map; 348 QMap<int, QString> map;
332 349
333 map.insert( Uid, QString::number( uid() ) ); 350 map.insert( Uid, QString::number( uid() ) );
334 map.insert( Category, idsToString( categories() ) ); 351 map.insert( Category, idsToString( categories() ) );
335 map.insert( HasDate, QString::number( data->hasDate ) ); 352 map.insert( HasDate, QString::number( data->hasDate ) );
336 map.insert( Completed, QString::number( data->isCompleted ) ); 353 map.insert( Completed, QString::number( data->isCompleted ) );
337 map.insert( Description, data->desc ); 354 map.insert( Description, data->desc );
338 map.insert( Summary, data->sum ); 355 map.insert( Summary, data->sum );
339 map.insert( Priority, QString::number( data->priority ) ); 356 map.insert( Priority, QString::number( data->priority ) );
340 map.insert( DateDay, QString::number( data->date.day() ) ); 357 map.insert( DateDay, QString::number( data->date.day() ) );
341 map.insert( DateMonth, QString::number( data->date.month() ) ); 358 map.insert( DateMonth, QString::number( data->date.month() ) );
342 map.insert( DateYear, QString::number( data->date.year() ) ); 359 map.insert( DateYear, QString::number( data->date.year() ) );
343 map.insert( Progress, QString::number( data->prog ) ); 360 map.insert( Progress, QString::number( data->prog ) );
344 map.insert( CrossReference, crossToString() ); 361 map.insert( CrossReference, crossToString() );
345 map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); 362 map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) );
346 map.insert( AlarmDateTime, data->alarmDateTime.toString() ); 363 map.insert( AlarmDateTime, data->alarmDateTime.toString() );
347 364
348 return map; 365 return map;
349} 366}
350 367
351QMap<QString, QString> OTodo::toExtraMap()const { 368QMap<QString, QString> OTodo::toExtraMap()const {
352 return data->extra; 369 return data->extra;
353} 370}
354/** 371/**
355 * change or modify looks at the ref count and either 372 * change or modify looks at the ref count and either
356 * creates a new QShared Object or it can modify it 373 * creates a new QShared Object or it can modify it
357 * right in place 374 * right in place
358 */ 375 */
359void OTodo::changeOrModify() { 376void OTodo::changeOrModify() {
360 if ( data->count != 1 ) { 377 if ( data->count != 1 ) {
361// qWarning("changeOrModify"); 378 qWarning("changeOrModify");
362 data->deref(); 379 data->deref();
363 OTodoData* d2 = new OTodoData(); 380 OTodoData* d2 = new OTodoData();
364 copy(data, d2 ); 381 copy(data, d2 );
365 data = d2; 382 data = d2;
366 } 383 }
367} 384}
368void OTodo::copy( OTodoData* src, OTodoData* dest ) { 385void OTodo::copy( OTodoData* src, OTodoData* dest ) {
369 dest->date = src->date; 386 dest->date = src->date;
370 dest->isCompleted = src->isCompleted; 387 dest->isCompleted = src->isCompleted;
371 dest->hasDate = src->hasDate; 388 dest->hasDate = src->hasDate;
372 dest->priority = src->priority; 389 dest->priority = src->priority;
373 dest->desc = src->desc; 390 dest->desc = src->desc;
374 dest->sum = src->sum; 391 dest->sum = src->sum;
375 dest->extra = src->extra; 392 dest->extra = src->extra;
376 dest->prog = src->prog; 393 dest->prog = src->prog;
377 dest->hasAlarmDateTime = src->hasAlarmDateTime; 394 dest->hasAlarmDateTime = src->hasAlarmDateTime;
378 dest->alarmDateTime = src->alarmDateTime; 395 dest->alarmDateTime = src->alarmDateTime;
396 dest->state = src->state;
397 dest->recur = src->recur;
379} 398}
380QString OTodo::type() const { 399QString OTodo::type() const {
381 return QString::fromLatin1("OTodo"); 400 return QString::fromLatin1("OTodo");
382} 401}
383QString OTodo::recordField(int id )const { 402QString OTodo::recordField(int id )const {
384 return QString::null; 403 return QString::null;
385} 404}
386 405
diff --git a/libopie2/opiepim/otodo.h b/libopie2/opiepim/otodo.h
index 5bd91d6..2cdc587 100644
--- a/libopie2/opiepim/otodo.h
+++ b/libopie2/opiepim/otodo.h
@@ -1,209 +1,234 @@
1 1
2#ifndef OPIE_TODO_EVENT_H 2#ifndef OPIE_TODO_EVENT_H
3#define OPIE_TODO_EVENT_H 3#define OPIE_TODO_EVENT_H
4 4
5 5
6#include <qarray.h> 6#include <qarray.h>
7#include <qmap.h> 7#include <qmap.h>
8#include <qregexp.h> 8#include <qregexp.h>
9#include <qstringlist.h> 9#include <qstringlist.h>
10#include <qdatetime.h> 10#include <qdatetime.h>
11#include <qvaluelist.h> 11#include <qvaluelist.h>
12 12
13#include <qpe/recordfields.h> 13#include <qpe/recordfields.h>
14#include <qpe/palmtopuidgen.h> 14#include <qpe/palmtopuidgen.h>
15 15
16#include <opie/opimrecord.h> 16#include <opie/opimrecord.h>
17 17
18 18
19class OPimState;
20class ORecur;
19class OTodo : public OPimRecord { 21class OTodo : public OPimRecord {
20public: 22public:
21 typedef QValueList<OTodo> ValueList; 23 typedef QValueList<OTodo> ValueList;
22 enum RecordFields { 24 enum RecordFields {
23 Uid = Qtopia::UID_ID, 25 Uid = Qtopia::UID_ID,
24 Category = Qtopia::CATEGORY_ID, 26 Category = Qtopia::CATEGORY_ID,
25 HasDate, 27 HasDate,
26 Completed, 28 Completed,
27 Description, 29 Description,
28 Summary, 30 Summary,
29 Priority, 31 Priority,
30 DateDay, 32 DateDay,
31 DateMonth, 33 DateMonth,
32 DateYear, 34 DateYear,
33 Progress, 35 Progress,
34 CrossReference, 36 CrossReference,
35 HasAlarmDateTime, 37 HasAlarmDateTime,
36 AlarmDateTime 38 AlarmDateTime,
39 State,
40 Recurrance,
41 Alarms,
42 Reminders,
43 Notifiers
37 }; 44 };
38 public: 45 public:
39 // priorities from Very low to very high 46 // priorities from Very low to very high
40 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; 47 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow };
41 48
42 /* Constructs a new ToDoEvent 49 /* Constructs a new ToDoEvent
43 @param completed Is the TodoEvent completed 50 @param completed Is the TodoEvent completed
44 @param priority What is the priority of this ToDoEvent 51 @param priority What is the priority of this ToDoEvent
45 @param category Which category does it belong( uid ) 52 @param category Which category does it belong( uid )
46 @param summary A small summary of the todo 53 @param summary A small summary of the todo
47 @param description What is this ToDoEvent about 54 @param description What is this ToDoEvent about
48 @param hasDate Does this Event got a deadline 55 @param hasDate Does this Event got a deadline
49 @param date what is the deadline? 56 @param date what is the deadline?
50 @param uid what is the UUID of this Event 57 @param uid what is the UUID of this Event
51 **/ 58 **/
52 OTodo( bool completed = false, int priority = Normal, 59 OTodo( bool completed = false, int priority = Normal,
53 const QStringList &category = QStringList(), 60 const QStringList &category = QStringList(),
54 const QString &summary = QString::null , 61 const QString &summary = QString::null ,
55 const QString &description = QString::null, 62 const QString &description = QString::null,
56 ushort progress = 0, 63 ushort progress = 0,
57 bool hasDate = false, QDate date = QDate::currentDate(), 64 bool hasDate = false, QDate date = QDate::currentDate(),
58 int uid = 0 /*empty*/ ); 65 int uid = 0 /*empty*/ );
59 66
60 OTodo( bool completed, int priority, 67 OTodo( bool completed, int priority,
61 const QArray<int>& category, 68 const QArray<int>& category,
62 const QString& summary = QString::null, 69 const QString& summary = QString::null,
63 const QString& description = QString::null, 70 const QString& description = QString::null,
64 ushort progress = 0, 71 ushort progress = 0,
65 bool hasDate = false, QDate date = QDate::currentDate(), 72 bool hasDate = false, QDate date = QDate::currentDate(),
66 int uid = 0 /* empty */ ); 73 int uid = 0 /* empty */ );
67 74
68 /* Copy c'tor 75 /* Copy c'tor
69 76
70 **/ 77 **/
71 OTodo(const OTodo & ); 78 OTodo(const OTodo & );
72 79
73 /** 80 /**
74 *destructor 81 *destructor
75 */ 82 */
76 ~OTodo(); 83 ~OTodo();
77 84
78 /** 85 /**
79 * Is this event completed? 86 * Is this event completed?
80 */ 87 */
81 bool isCompleted() const; 88 bool isCompleted() const;
82 89
83 /** 90 /**
84 * Does this Event have a deadline 91 * Does this Event have a deadline
85 */ 92 */
86 bool hasDueDate() const; 93 bool hasDueDate() const;
87 94
88 /** 95 /**
89 * Does this Event has an alarm time ? 96 * Does this Event has an alarm time ?
90 */ 97 */
91 bool hasAlarmDateTime() const; 98 bool hasAlarmDateTime() const;
92 99
93 /** 100 /**
94 * What is the priority? 101 * What is the priority?
95 */ 102 */
96 int priority()const ; 103 int priority()const ;
97 104
98 /** 105 /**
99 * progress as ushort 0, 20, 40, 60, 80 or 100% 106 * progress as ushort 0, 20, 40, 60, 80 or 100%
100 */ 107 */
101 ushort progress() const; 108 ushort progress() const;
102 109
103 /** 110 /**
104 * The due Date 111 * The due Date
105 */ 112 */
106 QDate dueDate()const; 113 QDate dueDate()const;
107 114
108 /** 115 /**
109 * Alarm Date and Time 116 * Alarm Date and Time
110 */ 117 */
111 QDateTime alarmDateTime()const; 118 QDateTime alarmDateTime()const;
112 119
113 /** 120 /**
121 * What is the state of this OTodo?
122 */
123 OPimState state()const;
124
125 /**
126 * the recurrance of this
127 */
128 ORecur recurrence()const;
129
130 /**
114 * The description of the todo 131 * The description of the todo
115 */ 132 */
116 QString description()const; 133 QString description()const;
117 134
118 /** 135 /**
119 * A small summary of the todo 136 * A small summary of the todo
120 */ 137 */
121 QString summary() const; 138 QString summary() const;
122 139
123 /** 140 /**
124 * @reimplemented 141 * @reimplemented
125 * Return this todoevent in a RichText formatted QString 142 * Return this todoevent in a RichText formatted QString
126 */ 143 */
127 QString toRichText() const; 144 QString toRichText() const;
128 145
129 /** 146 /**
130 * reimplementation 147 * reimplementation
131 */ 148 */
132 QString type()const; 149 QString type()const;
133 QString toShortText()const; 150 QString toShortText()const;
134 QMap<QString, QString> toExtraMap()const; 151 QMap<QString, QString> toExtraMap()const;
135 QString recordField(int id )const; 152 QString recordField(int id )const;
136 153
137 /** 154 /**
138 * toMap puts all data into the map. int relates 155 * toMap puts all data into the map. int relates
139 * to ToDoEvent RecordFields enum 156 * to ToDoEvent RecordFields enum
140 */ 157 */
141 QMap<int, QString> toMap()const; 158 QMap<int, QString> toMap()const;
142 159
143 /** 160 /**
144 * Set if this Todo is completed 161 * Set if this Todo is completed
145 */ 162 */
146 void setCompleted(bool completed ); 163 void setCompleted(bool completed );
147 164
148 /** 165 /**
149 * set if this todo got an end data 166 * set if this todo got an end data
150 */ 167 */
151 void setHasDueDate( bool hasDate ); 168 void setHasDueDate( bool hasDate );
152 169
153 /** 170 /**
154 * set if this todo has an alarm time and date 171 * set if this todo has an alarm time and date
155 */ 172 */
156 void setHasAlarmDateTime ( bool hasAlarm ); 173 void setHasAlarmDateTime ( bool hasAlarm );
157 174
158 /** 175 /**
159 * Set the priority of the Todo 176 * Set the priority of the Todo
160 */ 177 */
161 void setPriority(int priority ); 178 void setPriority(int priority );
162 179
163 /** 180 /**
164 * Set the progress. 181 * Set the progress.
165 */ 182 */
166 void setProgress( ushort progress ); 183 void setProgress( ushort progress );
167 184
168 /** 185 /**
169 * set the end date 186 * set the end date
170 */ 187 */
171 void setDueDate( QDate date ); 188 void setDueDate( QDate date );
172 189
190
191 void setRecurrence( const ORecur& );
173 /** 192 /**
174 * set the alarm time 193 * set the alarm time
175 */ 194 */
176 void setAlarmDateTime ( const QDateTime& alarm ); 195 void setAlarmDateTime ( const QDateTime& alarm );
177 196
178 void setDescription(const QString& ); 197 void setDescription(const QString& );
179 void setSummary(const QString& ); 198 void setSummary(const QString& );
199
200 /**
201 * set the state of a Todo
202 * @param state State what the todo should take
203 */
204 void setState( const OPimState& state);
180 bool isOverdue(); 205 bool isOverdue();
181 206
182 207
183 bool match( const QRegExp &r )const; 208 bool match( const QRegExp &r )const;
184 209
185 bool operator<(const OTodo &toDoEvent )const; 210 bool operator<(const OTodo &toDoEvent )const;
186 bool operator<=(const OTodo &toDoEvent )const; 211 bool operator<=(const OTodo &toDoEvent )const;
187 bool operator!=(const OTodo &toDoEvent )const; 212 bool operator!=(const OTodo &toDoEvent )const;
188 bool operator>(const OTodo &toDoEvent )const; 213 bool operator>(const OTodo &toDoEvent )const;
189 bool operator>=(const OTodo &toDoEvent)const; 214 bool operator>=(const OTodo &toDoEvent)const;
190 bool operator==(const OTodo &toDoEvent )const; 215 bool operator==(const OTodo &toDoEvent )const;
191 OTodo &operator=(const OTodo &toDoEvent ); 216 OTodo &operator=(const OTodo &toDoEvent );
192 217
193 private: 218 private:
194 class OTodoPrivate; 219 class OTodoPrivate;
195 struct OTodoData; 220 struct OTodoData;
196 221
197 void deref(); 222 void deref();
198 inline void changeOrModify(); 223 inline void changeOrModify();
199 void copy( OTodoData* src, OTodoData* dest ); 224 void copy( OTodoData* src, OTodoData* dest );
200 OTodoPrivate *d; 225 OTodoPrivate *d;
201 OTodoData *data; 226 OTodoData *data;
202 227
203}; 228};
204inline bool OTodo::operator!=(const OTodo &toDoEvent )const { 229inline bool OTodo::operator!=(const OTodo &toDoEvent )const {
205 return !(*this == toDoEvent); 230 return !(*this == toDoEvent);
206} 231}
207 232
208 233
209#endif 234#endif