author | eilers <eilers> | 2003-08-30 15:28:26 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-30 15:28:26 (UTC) |
commit | 9f07321949f8baf1a64db0e4caec58041d3f775f (patch) (unidiff) | |
tree | c80bf99717bd81ce4393aa40bbbdf11fbb3f7457 | |
parent | d9b5fcc45b1fef5ac11ef549a47561c7382ff451 (diff) | |
download | opie-9f07321949f8baf1a64db0e4caec58041d3f775f.zip opie-9f07321949f8baf1a64db0e4caec58041d3f775f.tar.gz opie-9f07321949f8baf1a64db0e4caec58041d3f775f.tar.bz2 |
Removed some unimportant debug output which causes slow down..
-rw-r--r-- | libopie/pim/ocontact.cpp | 4 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 4 |
4 files changed, 14 insertions, 8 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp index e34feeb..0f05b65 100644 --- a/libopie/pim/ocontact.cpp +++ b/libopie/pim/ocontact.cpp | |||
@@ -1062,112 +1062,112 @@ class QString OContact::recordField( int pos ) const | |||
1062 | QStringList SLFIELDS = fields(); // ?? why this ? (se) | 1062 | QStringList SLFIELDS = fields(); // ?? why this ? (se) |
1063 | return SLFIELDS[pos]; | 1063 | return SLFIELDS[pos]; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | // In future releases, we should store birthday and anniversary | 1066 | // In future releases, we should store birthday and anniversary |
1067 | // internally as QDate instead of QString ! | 1067 | // internally as QDate instead of QString ! |
1068 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) | 1068 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) |
1069 | 1069 | ||
1070 | /*! \fn void OContact::setBirthday( const QDate& date ) | 1070 | /*! \fn void OContact::setBirthday( const QDate& date ) |
1071 | Sets the birthday for the contact to \a date. If date is null | 1071 | Sets the birthday for the contact to \a date. If date is null |
1072 | the current stored date will be removed. | 1072 | the current stored date will be removed. |
1073 | */ | 1073 | */ |
1074 | void OContact::setBirthday( const QDate &v ) | 1074 | void OContact::setBirthday( const QDate &v ) |
1075 | { | 1075 | { |
1076 | if ( v.isNull() ){ | 1076 | if ( v.isNull() ){ |
1077 | qWarning( "Remove Birthday"); | 1077 | qWarning( "Remove Birthday"); |
1078 | replace( Qtopia::Birthday, QString::null ); | 1078 | replace( Qtopia::Birthday, QString::null ); |
1079 | return; | 1079 | return; |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | if ( v.isValid() ) | 1082 | if ( v.isValid() ) |
1083 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); | 1083 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); |
1084 | 1084 | ||
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | 1087 | ||
1088 | /*! \fn void OContact::setAnniversary( const QDate &date ) | 1088 | /*! \fn void OContact::setAnniversary( const QDate &date ) |
1089 | Sets the anniversary of the contact to \a date. If date is | 1089 | Sets the anniversary of the contact to \a date. If date is |
1090 | null, the current stored date will be removed. | 1090 | null, the current stored date will be removed. |
1091 | */ | 1091 | */ |
1092 | void OContact::setAnniversary( const QDate &v ) | 1092 | void OContact::setAnniversary( const QDate &v ) |
1093 | { | 1093 | { |
1094 | if ( v.isNull() ){ | 1094 | if ( v.isNull() ){ |
1095 | qWarning( "Remove Anniversary"); | 1095 | qWarning( "Remove Anniversary"); |
1096 | replace( Qtopia::Anniversary, QString::null ); | 1096 | replace( Qtopia::Anniversary, QString::null ); |
1097 | return; | 1097 | return; |
1098 | } | 1098 | } |
1099 | 1099 | ||
1100 | if ( v.isValid() ) | 1100 | if ( v.isValid() ) |
1101 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); | 1101 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); |
1102 | } | 1102 | } |
1103 | 1103 | ||
1104 | /*! \fn QDate OContact::birthday() const | 1104 | /*! \fn QDate OContact::birthday() const |
1105 | Returns the birthday of the contact. | 1105 | Returns the birthday of the contact. |
1106 | */ | 1106 | */ |
1107 | QDate OContact::birthday() const | 1107 | QDate OContact::birthday() const |
1108 | { | 1108 | { |
1109 | QString str = find( Qtopia::Birthday ); | 1109 | QString str = find( Qtopia::Birthday ); |
1110 | qWarning ("Birthday %s", str.latin1() ); | 1110 | // qWarning ("Birthday %s", str.latin1() ); |
1111 | if ( !str.isEmpty() ) | 1111 | if ( !str.isEmpty() ) |
1112 | return OConversion::dateFromString ( str ); | 1112 | return OConversion::dateFromString ( str ); |
1113 | else | 1113 | else |
1114 | return QDate(); | 1114 | return QDate(); |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | 1117 | ||
1118 | /*! \fn QDate OContact::anniversary() const | 1118 | /*! \fn QDate OContact::anniversary() const |
1119 | Returns the anniversary of the contact. | 1119 | Returns the anniversary of the contact. |
1120 | */ | 1120 | */ |
1121 | QDate OContact::anniversary() const | 1121 | QDate OContact::anniversary() const |
1122 | { | 1122 | { |
1123 | QDate empty; | 1123 | QDate empty; |
1124 | QString str = find( Qtopia::Anniversary ); | 1124 | QString str = find( Qtopia::Anniversary ); |
1125 | qWarning ("Anniversary %s", str.latin1() ); | 1125 | // qWarning ("Anniversary %s", str.latin1() ); |
1126 | if ( !str.isEmpty() ) | 1126 | if ( !str.isEmpty() ) |
1127 | return OConversion::dateFromString ( str ); | 1127 | return OConversion::dateFromString ( str ); |
1128 | else | 1128 | else |
1129 | return empty; | 1129 | return empty; |
1130 | } | 1130 | } |
1131 | 1131 | ||
1132 | 1132 | ||
1133 | void OContact::insertEmail( const QString &v ) | 1133 | void OContact::insertEmail( const QString &v ) |
1134 | { | 1134 | { |
1135 | //qDebug("insertEmail %s", v.latin1()); | 1135 | //qDebug("insertEmail %s", v.latin1()); |
1136 | QString e = v.simplifyWhiteSpace(); | 1136 | QString e = v.simplifyWhiteSpace(); |
1137 | QString def = defaultEmail(); | 1137 | QString def = defaultEmail(); |
1138 | 1138 | ||
1139 | // if no default, set it as the default email and don't insert | 1139 | // if no default, set it as the default email and don't insert |
1140 | if ( def.isEmpty() ) { | 1140 | if ( def.isEmpty() ) { |
1141 | setDefaultEmail( e ); // will insert into the list for us | 1141 | setDefaultEmail( e ); // will insert into the list for us |
1142 | return; | 1142 | return; |
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | // otherwise, insert assuming doesn't already exist | 1145 | // otherwise, insert assuming doesn't already exist |
1146 | QString emailsStr = find( Qtopia::Emails ); | 1146 | QString emailsStr = find( Qtopia::Emails ); |
1147 | if ( emailsStr.contains( e )) | 1147 | if ( emailsStr.contains( e )) |
1148 | return; | 1148 | return; |
1149 | if ( !emailsStr.isEmpty() ) | 1149 | if ( !emailsStr.isEmpty() ) |
1150 | emailsStr += emailSeparator(); | 1150 | emailsStr += emailSeparator(); |
1151 | emailsStr += e; | 1151 | emailsStr += e; |
1152 | replace( Qtopia::Emails, emailsStr ); | 1152 | replace( Qtopia::Emails, emailsStr ); |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | void OContact::removeEmail( const QString &v ) | 1155 | void OContact::removeEmail( const QString &v ) |
1156 | { | 1156 | { |
1157 | QString e = v.simplifyWhiteSpace(); | 1157 | QString e = v.simplifyWhiteSpace(); |
1158 | QString def = defaultEmail(); | 1158 | QString def = defaultEmail(); |
1159 | QString emailsStr = find( Qtopia::Emails ); | 1159 | QString emailsStr = find( Qtopia::Emails ); |
1160 | QStringList emails = emailList(); | 1160 | QStringList emails = emailList(); |
1161 | 1161 | ||
1162 | // otherwise, must first contain it | 1162 | // otherwise, must first contain it |
1163 | if ( !emailsStr.contains( e ) ) | 1163 | if ( !emailsStr.contains( e ) ) |
1164 | return; | 1164 | return; |
1165 | 1165 | ||
1166 | // remove it | 1166 | // remove it |
1167 | //qDebug(" removing email from list %s", e.latin1()); | 1167 | //qDebug(" removing email from list %s", e.latin1()); |
1168 | emails.remove( e ); | 1168 | emails.remove( e ); |
1169 | // reset the string | 1169 | // reset the string |
1170 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator | 1170 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator |
1171 | replace( Qtopia::Emails, emailsStr ); | 1171 | replace( Qtopia::Emails, emailsStr ); |
1172 | 1172 | ||
1173 | // if default, then replace the default email with the first one | 1173 | // if default, then replace the default email with the first one |
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp index 1c21619..1b5af2f 100644 --- a/libopie/pim/ocontactaccessbackend_xml.cpp +++ b/libopie/pim/ocontactaccessbackend_xml.cpp | |||
@@ -1,67 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.8 2003/08/30 15:28:26 eilers | ||
21 | * Removed some unimportant debug output which causes slow down.. | ||
22 | * | ||
20 | * Revision 1.7 2003/08/01 12:30:16 eilers | 23 | * Revision 1.7 2003/08/01 12:30:16 eilers |
21 | * Merging changes from BRANCH_1_0 to HEAD | 24 | * Merging changes from BRANCH_1_0 to HEAD |
22 | * | 25 | * |
23 | * Revision 1.6 2003/07/07 16:19:47 eilers | 26 | * Revision 1.6 2003/07/07 16:19:47 eilers |
24 | * Fixing serious bug in hasQuerySettings() | 27 | * Fixing serious bug in hasQuerySettings() |
25 | * | 28 | * |
26 | * Revision 1.5 2003/04/13 18:07:10 zecke | 29 | * Revision 1.5 2003/04/13 18:07:10 zecke |
27 | * More API doc | 30 | * More API doc |
28 | * QString -> const QString& | 31 | * QString -> const QString& |
29 | * QString = 0l -> QString::null | 32 | * QString = 0l -> QString::null |
30 | * | 33 | * |
31 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 34 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
32 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | 35 | * g++ compliance fix: default arguments belong into the declaration, but not the definition |
33 | * | 36 | * |
34 | * Revision 1.3 2003/03/21 12:26:28 eilers | 37 | * Revision 1.3 2003/03/21 12:26:28 eilers |
35 | * Fixing small bug: If we search a birthday from today to today, it returned | 38 | * Fixing small bug: If we search a birthday from today to today, it returned |
36 | * every contact .. | 39 | * every contact .. |
37 | * | 40 | * |
38 | * Revision 1.2 2003/03/21 10:33:09 eilers | 41 | * Revision 1.2 2003/03/21 10:33:09 eilers |
39 | * Merged speed optimized xml backend for contacts to main. | 42 | * Merged speed optimized xml backend for contacts to main. |
40 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 43 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
41 | * all Birthdays/Anniversaries between two dates. This should be used | 44 | * all Birthdays/Anniversaries between two dates. This should be used |
42 | * to show all birthdays in the datebook.. | 45 | * to show all birthdays in the datebook.. |
43 | * This change is sourcecode backward compatible but you have to upgrade | 46 | * This change is sourcecode backward compatible but you have to upgrade |
44 | * the binaries for today-addressbook. | 47 | * the binaries for today-addressbook. |
45 | * | 48 | * |
46 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 49 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
47 | * Speed optimization. Removed the sequential search loops. | 50 | * Speed optimization. Removed the sequential search loops. |
48 | * | 51 | * |
49 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 52 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
50 | * Writing offsets to debug output.. | 53 | * Writing offsets to debug output.. |
51 | * | 54 | * |
52 | * Revision 1.1 2003/02/09 15:05:01 eilers | 55 | * Revision 1.1 2003/02/09 15:05:01 eilers |
53 | * Nothing happened.. Just some cleanup before I will start.. | 56 | * Nothing happened.. Just some cleanup before I will start.. |
54 | * | 57 | * |
55 | * Revision 1.12 2003/01/03 16:58:03 eilers | 58 | * Revision 1.12 2003/01/03 16:58:03 eilers |
56 | * Reenable debug output | 59 | * Reenable debug output |
57 | * | 60 | * |
58 | * Revision 1.11 2003/01/03 12:31:28 eilers | 61 | * Revision 1.11 2003/01/03 12:31:28 eilers |
59 | * Bugfix for calculating data diffs.. | 62 | * Bugfix for calculating data diffs.. |
60 | * | 63 | * |
61 | * Revision 1.10 2003/01/02 14:27:12 eilers | 64 | * Revision 1.10 2003/01/02 14:27:12 eilers |
62 | * Improved query by example: Search by date is possible.. First step | 65 | * Improved query by example: Search by date is possible.. First step |
63 | * for a today plugin for birthdays.. | 66 | * for a today plugin for birthdays.. |
64 | * | 67 | * |
65 | * Revision 1.9 2002/12/08 12:48:57 eilers | 68 | * Revision 1.9 2002/12/08 12:48:57 eilers |
66 | * Moved journal-enum from ocontact into i the xml-backend.. | 69 | * Moved journal-enum from ocontact into i the xml-backend.. |
67 | * | 70 | * |
@@ -125,97 +128,97 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, c | |||
125 | // is removed. | 128 | // is removed. |
126 | m_contactList.setAutoDelete( true ); | 129 | m_contactList.setAutoDelete( true ); |
127 | m_uidToContact.setAutoDelete( false ); | 130 | m_uidToContact.setAutoDelete( false ); |
128 | 131 | ||
129 | m_appName = appname; | 132 | m_appName = appname; |
130 | 133 | ||
131 | /* Set journalfile name ... */ | 134 | /* Set journalfile name ... */ |
132 | m_journalName = getenv("HOME"); | 135 | m_journalName = getenv("HOME"); |
133 | m_journalName +="/.abjournal" + appname; | 136 | m_journalName +="/.abjournal" + appname; |
134 | 137 | ||
135 | /* Expecting to access the default filename if nothing else is set */ | 138 | /* Expecting to access the default filename if nothing else is set */ |
136 | if ( filename.isEmpty() ){ | 139 | if ( filename.isEmpty() ){ |
137 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 140 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
138 | } else | 141 | } else |
139 | m_fileName = filename; | 142 | m_fileName = filename; |
140 | 143 | ||
141 | /* Load Database now */ | 144 | /* Load Database now */ |
142 | load (); | 145 | load (); |
143 | } | 146 | } |
144 | 147 | ||
145 | bool OContactAccessBackend_XML::save() | 148 | bool OContactAccessBackend_XML::save() |
146 | { | 149 | { |
147 | 150 | ||
148 | if ( !m_changed ) | 151 | if ( !m_changed ) |
149 | return true; | 152 | return true; |
150 | 153 | ||
151 | QString strNewFile = m_fileName + ".new"; | 154 | QString strNewFile = m_fileName + ".new"; |
152 | QFile f( strNewFile ); | 155 | QFile f( strNewFile ); |
153 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 156 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
154 | return false; | 157 | return false; |
155 | 158 | ||
156 | int total_written; | 159 | int total_written; |
157 | int idx_offset = 0; | 160 | int idx_offset = 0; |
158 | QString out; | 161 | QString out; |
159 | 162 | ||
160 | // Write Header | 163 | // Write Header |
161 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 164 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
162 | " <Groups>\n" | 165 | " <Groups>\n" |
163 | " </Groups>\n" | 166 | " </Groups>\n" |
164 | " <Contacts>\n"; | 167 | " <Contacts>\n"; |
165 | QCString cstr = out.utf8(); | 168 | QCString cstr = out.utf8(); |
166 | f.writeBlock( cstr.data(), cstr.length() ); | 169 | f.writeBlock( cstr.data(), cstr.length() ); |
167 | idx_offset += cstr.length(); | 170 | idx_offset += cstr.length(); |
168 | out = ""; | 171 | out = ""; |
169 | 172 | ||
170 | // Write all contacts | 173 | // Write all contacts |
171 | QListIterator<OContact> it( m_contactList ); | 174 | QListIterator<OContact> it( m_contactList ); |
172 | for ( ; it.current(); ++it ) { | 175 | for ( ; it.current(); ++it ) { |
173 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); | 176 | // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); |
174 | out += "<Contact "; | 177 | out += "<Contact "; |
175 | (*it)->save( out ); | 178 | (*it)->save( out ); |
176 | out += "/>\n"; | 179 | out += "/>\n"; |
177 | cstr = out.utf8(); | 180 | cstr = out.utf8(); |
178 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 181 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
179 | idx_offset += cstr.length(); | 182 | idx_offset += cstr.length(); |
180 | if ( total_written != int(cstr.length()) ) { | 183 | if ( total_written != int(cstr.length()) ) { |
181 | f.close(); | 184 | f.close(); |
182 | QFile::remove( strNewFile ); | 185 | QFile::remove( strNewFile ); |
183 | return false; | 186 | return false; |
184 | } | 187 | } |
185 | out = ""; | 188 | out = ""; |
186 | } | 189 | } |
187 | out += " </Contacts>\n</AddressBook>\n"; | 190 | out += " </Contacts>\n</AddressBook>\n"; |
188 | 191 | ||
189 | // Write Footer | 192 | // Write Footer |
190 | cstr = out.utf8(); | 193 | cstr = out.utf8(); |
191 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 194 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
192 | if ( total_written != int( cstr.length() ) ) { | 195 | if ( total_written != int( cstr.length() ) ) { |
193 | f.close(); | 196 | f.close(); |
194 | QFile::remove( strNewFile ); | 197 | QFile::remove( strNewFile ); |
195 | return false; | 198 | return false; |
196 | } | 199 | } |
197 | f.close(); | 200 | f.close(); |
198 | 201 | ||
199 | // move the file over, I'm just going to use the system call | 202 | // move the file over, I'm just going to use the system call |
200 | // because, I don't feel like using QDir. | 203 | // because, I don't feel like using QDir. |
201 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 204 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
202 | qWarning( "problem renaming file %s to %s, errno: %d", | 205 | qWarning( "problem renaming file %s to %s, errno: %d", |
203 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 206 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
204 | // remove the tmp file... | 207 | // remove the tmp file... |
205 | QFile::remove( strNewFile ); | 208 | QFile::remove( strNewFile ); |
206 | } | 209 | } |
207 | 210 | ||
208 | /* The journalfile should be removed now... */ | 211 | /* The journalfile should be removed now... */ |
209 | removeJournal(); | 212 | removeJournal(); |
210 | 213 | ||
211 | m_changed = false; | 214 | m_changed = false; |
212 | return true; | 215 | return true; |
213 | } | 216 | } |
214 | 217 | ||
215 | bool OContactAccessBackend_XML::load () | 218 | bool OContactAccessBackend_XML::load () |
216 | { | 219 | { |
217 | m_contactList.clear(); | 220 | m_contactList.clear(); |
218 | m_uidToContact.clear(); | 221 | m_uidToContact.clear(); |
219 | 222 | ||
220 | /* Load XML-File and journal if it exists */ | 223 | /* Load XML-File and journal if it exists */ |
221 | if ( !load ( m_fileName, false ) ) | 224 | if ( !load ( m_fileName, false ) ) |
@@ -657,97 +660,97 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
657 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 660 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
658 | 661 | ||
659 | XMLElement *root = XMLElement::load( filename ); | 662 | XMLElement *root = XMLElement::load( filename ); |
660 | if(root != 0l ){ // start parsing | 663 | if(root != 0l ){ // start parsing |
661 | /* Parse all XML-Elements and put the data into the | 664 | /* Parse all XML-Elements and put the data into the |
662 | * Contact-Class | 665 | * Contact-Class |
663 | */ | 666 | */ |
664 | XMLElement *element = root->firstChild(); | 667 | XMLElement *element = root->firstChild(); |
665 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 668 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
666 | element = element->firstChild(); | 669 | element = element->firstChild(); |
667 | 670 | ||
668 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 671 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
669 | while( element && !isJournal ){ | 672 | while( element && !isJournal ){ |
670 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 673 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
671 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 674 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
672 | // element->tagName().latin1()); | 675 | // element->tagName().latin1()); |
673 | element = element->nextChild(); | 676 | element = element->nextChild(); |
674 | } else { | 677 | } else { |
675 | element = element->firstChild(); | 678 | element = element->firstChild(); |
676 | break; | 679 | break; |
677 | } | 680 | } |
678 | } | 681 | } |
679 | /* Parse all Contacts and ignore unknown tags */ | 682 | /* Parse all Contacts and ignore unknown tags */ |
680 | while( element ){ | 683 | while( element ){ |
681 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 684 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
682 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 685 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
683 | // element->tagName().latin1()); | 686 | // element->tagName().latin1()); |
684 | element = element->nextChild(); | 687 | element = element->nextChild(); |
685 | continue; | 688 | continue; |
686 | } | 689 | } |
687 | /* Found alement with tagname "contact", now parse and store all | 690 | /* Found alement with tagname "contact", now parse and store all |
688 | * attributes contained | 691 | * attributes contained |
689 | */ | 692 | */ |
690 | //qWarning("OContactDefBack::load element tagName() : %s", | 693 | //qWarning("OContactDefBack::load element tagName() : %s", |
691 | // element->tagName().latin1() ); | 694 | // element->tagName().latin1() ); |
692 | QString dummy; | 695 | QString dummy; |
693 | foundAction = false; | 696 | foundAction = false; |
694 | 697 | ||
695 | XMLElement::AttributeMap aMap = element->attributes(); | 698 | XMLElement::AttributeMap aMap = element->attributes(); |
696 | XMLElement::AttributeMap::Iterator it; | 699 | XMLElement::AttributeMap::Iterator it; |
697 | contactMap.clear(); | 700 | contactMap.clear(); |
698 | customMap.clear(); | 701 | customMap.clear(); |
699 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 702 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
700 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 703 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
701 | 704 | ||
702 | int *find = dict[ it.key() ]; | 705 | int *find = dict[ it.key() ]; |
703 | /* Unknown attributes will be stored as "Custom" elements */ | 706 | /* Unknown attributes will be stored as "Custom" elements */ |
704 | if ( !find ) { | 707 | if ( !find ) { |
705 | qWarning("Attribute %s not known.", it.key().latin1()); | 708 | // qWarning("Attribute %s not known.", it.key().latin1()); |
706 | //contact.setCustomField(it.key(), it.data()); | 709 | //contact.setCustomField(it.key(), it.data()); |
707 | customMap.insert( it.key(), it.data() ); | 710 | customMap.insert( it.key(), it.data() ); |
708 | continue; | 711 | continue; |
709 | } | 712 | } |
710 | 713 | ||
711 | /* Check if special conversion is needed and add attribute | 714 | /* Check if special conversion is needed and add attribute |
712 | * into Contact class | 715 | * into Contact class |
713 | */ | 716 | */ |
714 | switch( *find ) { | 717 | switch( *find ) { |
715 | /* | 718 | /* |
716 | case Qtopia::AddressUid: | 719 | case Qtopia::AddressUid: |
717 | contact.setUid( it.data().toInt() ); | 720 | contact.setUid( it.data().toInt() ); |
718 | break; | 721 | break; |
719 | case Qtopia::AddressCategory: | 722 | case Qtopia::AddressCategory: |
720 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 723 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
721 | break; | 724 | break; |
722 | */ | 725 | */ |
723 | case JOURNALACTION: | 726 | case JOURNALACTION: |
724 | action = journal_action(it.data().toInt()); | 727 | action = journal_action(it.data().toInt()); |
725 | foundAction = true; | 728 | foundAction = true; |
726 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 729 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
727 | break; | 730 | break; |
728 | case JOURNALROW: | 731 | case JOURNALROW: |
729 | journalKey = it.data().toInt(); | 732 | journalKey = it.data().toInt(); |
730 | break; | 733 | break; |
731 | default: // no conversion needed add them to the map | 734 | default: // no conversion needed add them to the map |
732 | contactMap.insert( *find, it.data() ); | 735 | contactMap.insert( *find, it.data() ); |
733 | break; | 736 | break; |
734 | } | 737 | } |
735 | } | 738 | } |
736 | /* now generate the Contact contact */ | 739 | /* now generate the Contact contact */ |
737 | OContact contact( contactMap ); | 740 | OContact contact( contactMap ); |
738 | 741 | ||
739 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 742 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
740 | contact.setCustomField( customIt.key(), customIt.data() ); | 743 | contact.setCustomField( customIt.key(), customIt.data() ); |
741 | } | 744 | } |
742 | 745 | ||
743 | if (foundAction){ | 746 | if (foundAction){ |
744 | foundAction = false; | 747 | foundAction = false; |
745 | switch ( action ) { | 748 | switch ( action ) { |
746 | case ACTION_ADD: | 749 | case ACTION_ADD: |
747 | addContact_p (contact); | 750 | addContact_p (contact); |
748 | break; | 751 | break; |
749 | case ACTION_REMOVE: | 752 | case ACTION_REMOVE: |
750 | if ( !remove (contact.uid()) ) | 753 | if ( !remove (contact.uid()) ) |
751 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 754 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
752 | contact.uid() ); | 755 | contact.uid() ); |
753 | break; | 756 | break; |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index 1c21619..1b5af2f 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -1,67 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.8 2003/08/30 15:28:26 eilers | ||
21 | * Removed some unimportant debug output which causes slow down.. | ||
22 | * | ||
20 | * Revision 1.7 2003/08/01 12:30:16 eilers | 23 | * Revision 1.7 2003/08/01 12:30:16 eilers |
21 | * Merging changes from BRANCH_1_0 to HEAD | 24 | * Merging changes from BRANCH_1_0 to HEAD |
22 | * | 25 | * |
23 | * Revision 1.6 2003/07/07 16:19:47 eilers | 26 | * Revision 1.6 2003/07/07 16:19:47 eilers |
24 | * Fixing serious bug in hasQuerySettings() | 27 | * Fixing serious bug in hasQuerySettings() |
25 | * | 28 | * |
26 | * Revision 1.5 2003/04/13 18:07:10 zecke | 29 | * Revision 1.5 2003/04/13 18:07:10 zecke |
27 | * More API doc | 30 | * More API doc |
28 | * QString -> const QString& | 31 | * QString -> const QString& |
29 | * QString = 0l -> QString::null | 32 | * QString = 0l -> QString::null |
30 | * | 33 | * |
31 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 34 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
32 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | 35 | * g++ compliance fix: default arguments belong into the declaration, but not the definition |
33 | * | 36 | * |
34 | * Revision 1.3 2003/03/21 12:26:28 eilers | 37 | * Revision 1.3 2003/03/21 12:26:28 eilers |
35 | * Fixing small bug: If we search a birthday from today to today, it returned | 38 | * Fixing small bug: If we search a birthday from today to today, it returned |
36 | * every contact .. | 39 | * every contact .. |
37 | * | 40 | * |
38 | * Revision 1.2 2003/03/21 10:33:09 eilers | 41 | * Revision 1.2 2003/03/21 10:33:09 eilers |
39 | * Merged speed optimized xml backend for contacts to main. | 42 | * Merged speed optimized xml backend for contacts to main. |
40 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 43 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
41 | * all Birthdays/Anniversaries between two dates. This should be used | 44 | * all Birthdays/Anniversaries between two dates. This should be used |
42 | * to show all birthdays in the datebook.. | 45 | * to show all birthdays in the datebook.. |
43 | * This change is sourcecode backward compatible but you have to upgrade | 46 | * This change is sourcecode backward compatible but you have to upgrade |
44 | * the binaries for today-addressbook. | 47 | * the binaries for today-addressbook. |
45 | * | 48 | * |
46 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 49 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
47 | * Speed optimization. Removed the sequential search loops. | 50 | * Speed optimization. Removed the sequential search loops. |
48 | * | 51 | * |
49 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 52 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
50 | * Writing offsets to debug output.. | 53 | * Writing offsets to debug output.. |
51 | * | 54 | * |
52 | * Revision 1.1 2003/02/09 15:05:01 eilers | 55 | * Revision 1.1 2003/02/09 15:05:01 eilers |
53 | * Nothing happened.. Just some cleanup before I will start.. | 56 | * Nothing happened.. Just some cleanup before I will start.. |
54 | * | 57 | * |
55 | * Revision 1.12 2003/01/03 16:58:03 eilers | 58 | * Revision 1.12 2003/01/03 16:58:03 eilers |
56 | * Reenable debug output | 59 | * Reenable debug output |
57 | * | 60 | * |
58 | * Revision 1.11 2003/01/03 12:31:28 eilers | 61 | * Revision 1.11 2003/01/03 12:31:28 eilers |
59 | * Bugfix for calculating data diffs.. | 62 | * Bugfix for calculating data diffs.. |
60 | * | 63 | * |
61 | * Revision 1.10 2003/01/02 14:27:12 eilers | 64 | * Revision 1.10 2003/01/02 14:27:12 eilers |
62 | * Improved query by example: Search by date is possible.. First step | 65 | * Improved query by example: Search by date is possible.. First step |
63 | * for a today plugin for birthdays.. | 66 | * for a today plugin for birthdays.. |
64 | * | 67 | * |
65 | * Revision 1.9 2002/12/08 12:48:57 eilers | 68 | * Revision 1.9 2002/12/08 12:48:57 eilers |
66 | * Moved journal-enum from ocontact into i the xml-backend.. | 69 | * Moved journal-enum from ocontact into i the xml-backend.. |
67 | * | 70 | * |
@@ -125,97 +128,97 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, c | |||
125 | // is removed. | 128 | // is removed. |
126 | m_contactList.setAutoDelete( true ); | 129 | m_contactList.setAutoDelete( true ); |
127 | m_uidToContact.setAutoDelete( false ); | 130 | m_uidToContact.setAutoDelete( false ); |
128 | 131 | ||
129 | m_appName = appname; | 132 | m_appName = appname; |
130 | 133 | ||
131 | /* Set journalfile name ... */ | 134 | /* Set journalfile name ... */ |
132 | m_journalName = getenv("HOME"); | 135 | m_journalName = getenv("HOME"); |
133 | m_journalName +="/.abjournal" + appname; | 136 | m_journalName +="/.abjournal" + appname; |
134 | 137 | ||
135 | /* Expecting to access the default filename if nothing else is set */ | 138 | /* Expecting to access the default filename if nothing else is set */ |
136 | if ( filename.isEmpty() ){ | 139 | if ( filename.isEmpty() ){ |
137 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 140 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
138 | } else | 141 | } else |
139 | m_fileName = filename; | 142 | m_fileName = filename; |
140 | 143 | ||
141 | /* Load Database now */ | 144 | /* Load Database now */ |
142 | load (); | 145 | load (); |
143 | } | 146 | } |
144 | 147 | ||
145 | bool OContactAccessBackend_XML::save() | 148 | bool OContactAccessBackend_XML::save() |
146 | { | 149 | { |
147 | 150 | ||
148 | if ( !m_changed ) | 151 | if ( !m_changed ) |
149 | return true; | 152 | return true; |
150 | 153 | ||
151 | QString strNewFile = m_fileName + ".new"; | 154 | QString strNewFile = m_fileName + ".new"; |
152 | QFile f( strNewFile ); | 155 | QFile f( strNewFile ); |
153 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 156 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
154 | return false; | 157 | return false; |
155 | 158 | ||
156 | int total_written; | 159 | int total_written; |
157 | int idx_offset = 0; | 160 | int idx_offset = 0; |
158 | QString out; | 161 | QString out; |
159 | 162 | ||
160 | // Write Header | 163 | // Write Header |
161 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 164 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
162 | " <Groups>\n" | 165 | " <Groups>\n" |
163 | " </Groups>\n" | 166 | " </Groups>\n" |
164 | " <Contacts>\n"; | 167 | " <Contacts>\n"; |
165 | QCString cstr = out.utf8(); | 168 | QCString cstr = out.utf8(); |
166 | f.writeBlock( cstr.data(), cstr.length() ); | 169 | f.writeBlock( cstr.data(), cstr.length() ); |
167 | idx_offset += cstr.length(); | 170 | idx_offset += cstr.length(); |
168 | out = ""; | 171 | out = ""; |
169 | 172 | ||
170 | // Write all contacts | 173 | // Write all contacts |
171 | QListIterator<OContact> it( m_contactList ); | 174 | QListIterator<OContact> it( m_contactList ); |
172 | for ( ; it.current(); ++it ) { | 175 | for ( ; it.current(); ++it ) { |
173 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); | 176 | // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); |
174 | out += "<Contact "; | 177 | out += "<Contact "; |
175 | (*it)->save( out ); | 178 | (*it)->save( out ); |
176 | out += "/>\n"; | 179 | out += "/>\n"; |
177 | cstr = out.utf8(); | 180 | cstr = out.utf8(); |
178 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 181 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
179 | idx_offset += cstr.length(); | 182 | idx_offset += cstr.length(); |
180 | if ( total_written != int(cstr.length()) ) { | 183 | if ( total_written != int(cstr.length()) ) { |
181 | f.close(); | 184 | f.close(); |
182 | QFile::remove( strNewFile ); | 185 | QFile::remove( strNewFile ); |
183 | return false; | 186 | return false; |
184 | } | 187 | } |
185 | out = ""; | 188 | out = ""; |
186 | } | 189 | } |
187 | out += " </Contacts>\n</AddressBook>\n"; | 190 | out += " </Contacts>\n</AddressBook>\n"; |
188 | 191 | ||
189 | // Write Footer | 192 | // Write Footer |
190 | cstr = out.utf8(); | 193 | cstr = out.utf8(); |
191 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 194 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
192 | if ( total_written != int( cstr.length() ) ) { | 195 | if ( total_written != int( cstr.length() ) ) { |
193 | f.close(); | 196 | f.close(); |
194 | QFile::remove( strNewFile ); | 197 | QFile::remove( strNewFile ); |
195 | return false; | 198 | return false; |
196 | } | 199 | } |
197 | f.close(); | 200 | f.close(); |
198 | 201 | ||
199 | // move the file over, I'm just going to use the system call | 202 | // move the file over, I'm just going to use the system call |
200 | // because, I don't feel like using QDir. | 203 | // because, I don't feel like using QDir. |
201 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 204 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
202 | qWarning( "problem renaming file %s to %s, errno: %d", | 205 | qWarning( "problem renaming file %s to %s, errno: %d", |
203 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 206 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
204 | // remove the tmp file... | 207 | // remove the tmp file... |
205 | QFile::remove( strNewFile ); | 208 | QFile::remove( strNewFile ); |
206 | } | 209 | } |
207 | 210 | ||
208 | /* The journalfile should be removed now... */ | 211 | /* The journalfile should be removed now... */ |
209 | removeJournal(); | 212 | removeJournal(); |
210 | 213 | ||
211 | m_changed = false; | 214 | m_changed = false; |
212 | return true; | 215 | return true; |
213 | } | 216 | } |
214 | 217 | ||
215 | bool OContactAccessBackend_XML::load () | 218 | bool OContactAccessBackend_XML::load () |
216 | { | 219 | { |
217 | m_contactList.clear(); | 220 | m_contactList.clear(); |
218 | m_uidToContact.clear(); | 221 | m_uidToContact.clear(); |
219 | 222 | ||
220 | /* Load XML-File and journal if it exists */ | 223 | /* Load XML-File and journal if it exists */ |
221 | if ( !load ( m_fileName, false ) ) | 224 | if ( !load ( m_fileName, false ) ) |
@@ -657,97 +660,97 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
657 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 660 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
658 | 661 | ||
659 | XMLElement *root = XMLElement::load( filename ); | 662 | XMLElement *root = XMLElement::load( filename ); |
660 | if(root != 0l ){ // start parsing | 663 | if(root != 0l ){ // start parsing |
661 | /* Parse all XML-Elements and put the data into the | 664 | /* Parse all XML-Elements and put the data into the |
662 | * Contact-Class | 665 | * Contact-Class |
663 | */ | 666 | */ |
664 | XMLElement *element = root->firstChild(); | 667 | XMLElement *element = root->firstChild(); |
665 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 668 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
666 | element = element->firstChild(); | 669 | element = element->firstChild(); |
667 | 670 | ||
668 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 671 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
669 | while( element && !isJournal ){ | 672 | while( element && !isJournal ){ |
670 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 673 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
671 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 674 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
672 | // element->tagName().latin1()); | 675 | // element->tagName().latin1()); |
673 | element = element->nextChild(); | 676 | element = element->nextChild(); |
674 | } else { | 677 | } else { |
675 | element = element->firstChild(); | 678 | element = element->firstChild(); |
676 | break; | 679 | break; |
677 | } | 680 | } |
678 | } | 681 | } |
679 | /* Parse all Contacts and ignore unknown tags */ | 682 | /* Parse all Contacts and ignore unknown tags */ |
680 | while( element ){ | 683 | while( element ){ |
681 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 684 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
682 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 685 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
683 | // element->tagName().latin1()); | 686 | // element->tagName().latin1()); |
684 | element = element->nextChild(); | 687 | element = element->nextChild(); |
685 | continue; | 688 | continue; |
686 | } | 689 | } |
687 | /* Found alement with tagname "contact", now parse and store all | 690 | /* Found alement with tagname "contact", now parse and store all |
688 | * attributes contained | 691 | * attributes contained |
689 | */ | 692 | */ |
690 | //qWarning("OContactDefBack::load element tagName() : %s", | 693 | //qWarning("OContactDefBack::load element tagName() : %s", |
691 | // element->tagName().latin1() ); | 694 | // element->tagName().latin1() ); |
692 | QString dummy; | 695 | QString dummy; |
693 | foundAction = false; | 696 | foundAction = false; |
694 | 697 | ||
695 | XMLElement::AttributeMap aMap = element->attributes(); | 698 | XMLElement::AttributeMap aMap = element->attributes(); |
696 | XMLElement::AttributeMap::Iterator it; | 699 | XMLElement::AttributeMap::Iterator it; |
697 | contactMap.clear(); | 700 | contactMap.clear(); |
698 | customMap.clear(); | 701 | customMap.clear(); |
699 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 702 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
700 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 703 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
701 | 704 | ||
702 | int *find = dict[ it.key() ]; | 705 | int *find = dict[ it.key() ]; |
703 | /* Unknown attributes will be stored as "Custom" elements */ | 706 | /* Unknown attributes will be stored as "Custom" elements */ |
704 | if ( !find ) { | 707 | if ( !find ) { |
705 | qWarning("Attribute %s not known.", it.key().latin1()); | 708 | // qWarning("Attribute %s not known.", it.key().latin1()); |
706 | //contact.setCustomField(it.key(), it.data()); | 709 | //contact.setCustomField(it.key(), it.data()); |
707 | customMap.insert( it.key(), it.data() ); | 710 | customMap.insert( it.key(), it.data() ); |
708 | continue; | 711 | continue; |
709 | } | 712 | } |
710 | 713 | ||
711 | /* Check if special conversion is needed and add attribute | 714 | /* Check if special conversion is needed and add attribute |
712 | * into Contact class | 715 | * into Contact class |
713 | */ | 716 | */ |
714 | switch( *find ) { | 717 | switch( *find ) { |
715 | /* | 718 | /* |
716 | case Qtopia::AddressUid: | 719 | case Qtopia::AddressUid: |
717 | contact.setUid( it.data().toInt() ); | 720 | contact.setUid( it.data().toInt() ); |
718 | break; | 721 | break; |
719 | case Qtopia::AddressCategory: | 722 | case Qtopia::AddressCategory: |
720 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 723 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
721 | break; | 724 | break; |
722 | */ | 725 | */ |
723 | case JOURNALACTION: | 726 | case JOURNALACTION: |
724 | action = journal_action(it.data().toInt()); | 727 | action = journal_action(it.data().toInt()); |
725 | foundAction = true; | 728 | foundAction = true; |
726 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 729 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
727 | break; | 730 | break; |
728 | case JOURNALROW: | 731 | case JOURNALROW: |
729 | journalKey = it.data().toInt(); | 732 | journalKey = it.data().toInt(); |
730 | break; | 733 | break; |
731 | default: // no conversion needed add them to the map | 734 | default: // no conversion needed add them to the map |
732 | contactMap.insert( *find, it.data() ); | 735 | contactMap.insert( *find, it.data() ); |
733 | break; | 736 | break; |
734 | } | 737 | } |
735 | } | 738 | } |
736 | /* now generate the Contact contact */ | 739 | /* now generate the Contact contact */ |
737 | OContact contact( contactMap ); | 740 | OContact contact( contactMap ); |
738 | 741 | ||
739 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 742 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
740 | contact.setCustomField( customIt.key(), customIt.data() ); | 743 | contact.setCustomField( customIt.key(), customIt.data() ); |
741 | } | 744 | } |
742 | 745 | ||
743 | if (foundAction){ | 746 | if (foundAction){ |
744 | foundAction = false; | 747 | foundAction = false; |
745 | switch ( action ) { | 748 | switch ( action ) { |
746 | case ACTION_ADD: | 749 | case ACTION_ADD: |
747 | addContact_p (contact); | 750 | addContact_p (contact); |
748 | break; | 751 | break; |
749 | case ACTION_REMOVE: | 752 | case ACTION_REMOVE: |
750 | if ( !remove (contact.uid()) ) | 753 | if ( !remove (contact.uid()) ) |
751 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 754 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
752 | contact.uid() ); | 755 | contact.uid() ); |
753 | break; | 756 | break; |
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index e34feeb..0f05b65 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp | |||
@@ -1062,112 +1062,112 @@ class QString OContact::recordField( int pos ) const | |||
1062 | QStringList SLFIELDS = fields(); // ?? why this ? (se) | 1062 | QStringList SLFIELDS = fields(); // ?? why this ? (se) |
1063 | return SLFIELDS[pos]; | 1063 | return SLFIELDS[pos]; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | // In future releases, we should store birthday and anniversary | 1066 | // In future releases, we should store birthday and anniversary |
1067 | // internally as QDate instead of QString ! | 1067 | // internally as QDate instead of QString ! |
1068 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) | 1068 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) |
1069 | 1069 | ||
1070 | /*! \fn void OContact::setBirthday( const QDate& date ) | 1070 | /*! \fn void OContact::setBirthday( const QDate& date ) |
1071 | Sets the birthday for the contact to \a date. If date is null | 1071 | Sets the birthday for the contact to \a date. If date is null |
1072 | the current stored date will be removed. | 1072 | the current stored date will be removed. |
1073 | */ | 1073 | */ |
1074 | void OContact::setBirthday( const QDate &v ) | 1074 | void OContact::setBirthday( const QDate &v ) |
1075 | { | 1075 | { |
1076 | if ( v.isNull() ){ | 1076 | if ( v.isNull() ){ |
1077 | qWarning( "Remove Birthday"); | 1077 | qWarning( "Remove Birthday"); |
1078 | replace( Qtopia::Birthday, QString::null ); | 1078 | replace( Qtopia::Birthday, QString::null ); |
1079 | return; | 1079 | return; |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | if ( v.isValid() ) | 1082 | if ( v.isValid() ) |
1083 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); | 1083 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); |
1084 | 1084 | ||
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | 1087 | ||
1088 | /*! \fn void OContact::setAnniversary( const QDate &date ) | 1088 | /*! \fn void OContact::setAnniversary( const QDate &date ) |
1089 | Sets the anniversary of the contact to \a date. If date is | 1089 | Sets the anniversary of the contact to \a date. If date is |
1090 | null, the current stored date will be removed. | 1090 | null, the current stored date will be removed. |
1091 | */ | 1091 | */ |
1092 | void OContact::setAnniversary( const QDate &v ) | 1092 | void OContact::setAnniversary( const QDate &v ) |
1093 | { | 1093 | { |
1094 | if ( v.isNull() ){ | 1094 | if ( v.isNull() ){ |
1095 | qWarning( "Remove Anniversary"); | 1095 | qWarning( "Remove Anniversary"); |
1096 | replace( Qtopia::Anniversary, QString::null ); | 1096 | replace( Qtopia::Anniversary, QString::null ); |
1097 | return; | 1097 | return; |
1098 | } | 1098 | } |
1099 | 1099 | ||
1100 | if ( v.isValid() ) | 1100 | if ( v.isValid() ) |
1101 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); | 1101 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); |
1102 | } | 1102 | } |
1103 | 1103 | ||
1104 | /*! \fn QDate OContact::birthday() const | 1104 | /*! \fn QDate OContact::birthday() const |
1105 | Returns the birthday of the contact. | 1105 | Returns the birthday of the contact. |
1106 | */ | 1106 | */ |
1107 | QDate OContact::birthday() const | 1107 | QDate OContact::birthday() const |
1108 | { | 1108 | { |
1109 | QString str = find( Qtopia::Birthday ); | 1109 | QString str = find( Qtopia::Birthday ); |
1110 | qWarning ("Birthday %s", str.latin1() ); | 1110 | // qWarning ("Birthday %s", str.latin1() ); |
1111 | if ( !str.isEmpty() ) | 1111 | if ( !str.isEmpty() ) |
1112 | return OConversion::dateFromString ( str ); | 1112 | return OConversion::dateFromString ( str ); |
1113 | else | 1113 | else |
1114 | return QDate(); | 1114 | return QDate(); |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | 1117 | ||
1118 | /*! \fn QDate OContact::anniversary() const | 1118 | /*! \fn QDate OContact::anniversary() const |
1119 | Returns the anniversary of the contact. | 1119 | Returns the anniversary of the contact. |
1120 | */ | 1120 | */ |
1121 | QDate OContact::anniversary() const | 1121 | QDate OContact::anniversary() const |
1122 | { | 1122 | { |
1123 | QDate empty; | 1123 | QDate empty; |
1124 | QString str = find( Qtopia::Anniversary ); | 1124 | QString str = find( Qtopia::Anniversary ); |
1125 | qWarning ("Anniversary %s", str.latin1() ); | 1125 | // qWarning ("Anniversary %s", str.latin1() ); |
1126 | if ( !str.isEmpty() ) | 1126 | if ( !str.isEmpty() ) |
1127 | return OConversion::dateFromString ( str ); | 1127 | return OConversion::dateFromString ( str ); |
1128 | else | 1128 | else |
1129 | return empty; | 1129 | return empty; |
1130 | } | 1130 | } |
1131 | 1131 | ||
1132 | 1132 | ||
1133 | void OContact::insertEmail( const QString &v ) | 1133 | void OContact::insertEmail( const QString &v ) |
1134 | { | 1134 | { |
1135 | //qDebug("insertEmail %s", v.latin1()); | 1135 | //qDebug("insertEmail %s", v.latin1()); |
1136 | QString e = v.simplifyWhiteSpace(); | 1136 | QString e = v.simplifyWhiteSpace(); |
1137 | QString def = defaultEmail(); | 1137 | QString def = defaultEmail(); |
1138 | 1138 | ||
1139 | // if no default, set it as the default email and don't insert | 1139 | // if no default, set it as the default email and don't insert |
1140 | if ( def.isEmpty() ) { | 1140 | if ( def.isEmpty() ) { |
1141 | setDefaultEmail( e ); // will insert into the list for us | 1141 | setDefaultEmail( e ); // will insert into the list for us |
1142 | return; | 1142 | return; |
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | // otherwise, insert assuming doesn't already exist | 1145 | // otherwise, insert assuming doesn't already exist |
1146 | QString emailsStr = find( Qtopia::Emails ); | 1146 | QString emailsStr = find( Qtopia::Emails ); |
1147 | if ( emailsStr.contains( e )) | 1147 | if ( emailsStr.contains( e )) |
1148 | return; | 1148 | return; |
1149 | if ( !emailsStr.isEmpty() ) | 1149 | if ( !emailsStr.isEmpty() ) |
1150 | emailsStr += emailSeparator(); | 1150 | emailsStr += emailSeparator(); |
1151 | emailsStr += e; | 1151 | emailsStr += e; |
1152 | replace( Qtopia::Emails, emailsStr ); | 1152 | replace( Qtopia::Emails, emailsStr ); |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | void OContact::removeEmail( const QString &v ) | 1155 | void OContact::removeEmail( const QString &v ) |
1156 | { | 1156 | { |
1157 | QString e = v.simplifyWhiteSpace(); | 1157 | QString e = v.simplifyWhiteSpace(); |
1158 | QString def = defaultEmail(); | 1158 | QString def = defaultEmail(); |
1159 | QString emailsStr = find( Qtopia::Emails ); | 1159 | QString emailsStr = find( Qtopia::Emails ); |
1160 | QStringList emails = emailList(); | 1160 | QStringList emails = emailList(); |
1161 | 1161 | ||
1162 | // otherwise, must first contain it | 1162 | // otherwise, must first contain it |
1163 | if ( !emailsStr.contains( e ) ) | 1163 | if ( !emailsStr.contains( e ) ) |
1164 | return; | 1164 | return; |
1165 | 1165 | ||
1166 | // remove it | 1166 | // remove it |
1167 | //qDebug(" removing email from list %s", e.latin1()); | 1167 | //qDebug(" removing email from list %s", e.latin1()); |
1168 | emails.remove( e ); | 1168 | emails.remove( e ); |
1169 | // reset the string | 1169 | // reset the string |
1170 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator | 1170 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator |
1171 | replace( Qtopia::Emails, emailsStr ); | 1171 | replace( Qtopia::Emails, emailsStr ); |
1172 | 1172 | ||
1173 | // if default, then replace the default email with the first one | 1173 | // if default, then replace the default email with the first one |