Diffstat (limited to 'core/pim/addressbook/ocontactfields.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/addressbook/ocontactfields.cpp | 101 |
1 files changed, 98 insertions, 3 deletions
diff --git a/core/pim/addressbook/ocontactfields.cpp b/core/pim/addressbook/ocontactfields.cpp index 0da6a4f..75a7641 100644 --- a/core/pim/addressbook/ocontactfields.cpp +++ b/core/pim/addressbook/ocontactfields.cpp | |||
@@ -1,20 +1,22 @@ | |||
1 | 1 | ||
2 | #include "ocontactfields.h" | 2 | #include "ocontactfields.h" |
3 | 3 | ||
4 | #include <qstringlist.h> | 4 | #include <qstringlist.h> |
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | 6 | ||
7 | // We should use our own enum in the future .. | 7 | // We should use our own enum in the future .. |
8 | #include <qpe/recordfields.h> | 8 | #include <qpe/recordfields.h> |
9 | #include <qpe/config.h> | ||
10 | #include <opie/ocontact.h> | ||
9 | 11 | ||
10 | /*! | 12 | /*! |
11 | \internal | 13 | \internal |
12 | Returns a list of details field names for a contact. | 14 | Returns a list of details field names for a contact. |
13 | */ | 15 | */ |
14 | QStringList OContactFields::untrdetailsfields( bool sorted ) | 16 | QStringList OContactFields::untrdetailsfields( bool sorted ) |
15 | { | 17 | { |
16 | QStringList list; | 18 | QStringList list; |
17 | 19 | ||
18 | list.append( "Office" ); | 20 | list.append( "Office" ); |
19 | list.append( "Profession" ); | 21 | list.append( "Profession" ); |
20 | list.append( "Assistant" ); | 22 | list.append( "Assistant" ); |
@@ -190,25 +192,25 @@ QStringList OContactFields::untrfields( bool sorted ) | |||
190 | list += untrdetailsfields( sorted ); | 192 | list += untrdetailsfields( sorted ); |
191 | 193 | ||
192 | list.append( "Notes" ); | 194 | list.append( "Notes" ); |
193 | list.append( "Groups" ); | 195 | list.append( "Groups" ); |
194 | 196 | ||
195 | if (sorted) list.sort(); | 197 | if (sorted) list.sort(); |
196 | 198 | ||
197 | return list; | 199 | return list; |
198 | } | 200 | } |
199 | QMap<int, QString> OContactFields::idToTrFields() | 201 | QMap<int, QString> OContactFields::idToTrFields() |
200 | { | 202 | { |
201 | QMap<int, QString> ret_map; | 203 | QMap<int, QString> ret_map; |
202 | 204 | ||
203 | ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") ); | 205 | ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") ); |
204 | ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); | 206 | ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); |
205 | ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); | 207 | ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); |
206 | ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); | 208 | ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); |
207 | ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" )); | 209 | ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" )); |
208 | ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); | 210 | ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); |
209 | 211 | ||
210 | ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); | 212 | ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); |
211 | ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); | 213 | ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); |
212 | ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); | 214 | ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); |
213 | ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); | 215 | ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); |
214 | ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); | 216 | ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); |
@@ -245,30 +247,123 @@ QMap<int, QString> OContactFields::idToTrFields() | |||
245 | ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) ); | 247 | ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) ); |
246 | 248 | ||
247 | //personal | 249 | //personal |
248 | ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) ); | 250 | ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) ); |
249 | ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) ); | 251 | ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) ); |
250 | ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) ); | 252 | ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) ); |
251 | ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) ); | 253 | ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) ); |
252 | ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) ); | 254 | ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) ); |
253 | ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) ); | 255 | ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) ); |
254 | 256 | ||
255 | // other | 257 | // other |
256 | ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) ); | 258 | ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) ); |
257 | 259 | ||
258 | 260 | ||
259 | return ret_map; | 261 | return ret_map; |
260 | } | 262 | } |
261 | 263 | ||
262 | QMap<QString, int> OContactFields::trFieldsToId() | 264 | QMap<QString, int> OContactFields::trFieldsToId() |
263 | { | 265 | { |
264 | QMap<int, QString> idtostr = idToTrFields(); | 266 | QMap<int, QString> idtostr = idToTrFields(); |
265 | QMap<QString, int> ret_map; | 267 | QMap<QString, int> ret_map; |
266 | 268 | ||
267 | 269 | ||
268 | QMap<int, QString>::Iterator it; | 270 | QMap<int, QString>::Iterator it; |
269 | for( it = idtostr.begin(); it != idtostr.end(); ++it ) | 271 | for( it = idtostr.begin(); it != idtostr.end(); ++it ) |
270 | ret_map.insert( *it, it.key() ); | 272 | ret_map.insert( *it, it.key() ); |
271 | 273 | ||
272 | 274 | ||
273 | return ret_map; | 275 | return ret_map; |
274 | } | 276 | } |
277 | |||
278 | OContactFields::OContactFields(): | ||
279 | fieldOrder( DEFAULT_FIELD_ORDER ), | ||
280 | changedFieldOrder( false ) | ||
281 | { | ||
282 | // Get the global field order from the config file and | ||
283 | // use it as a start pattern | ||
284 | Config cfg ( "AddressBook" ); | ||
285 | cfg.setGroup( "ContactFieldOrder" ); | ||
286 | globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); | ||
287 | } | ||
288 | |||
289 | OContactFields::~OContactFields(){ | ||
290 | |||
291 | // We will store the fieldorder into the config file | ||
292 | // to reuse it for the future.. | ||
293 | if ( changedFieldOrder ){ | ||
294 | Config cfg ( "AddressBook" ); | ||
295 | cfg.setGroup( "ContactFieldOrder" ); | ||
296 | cfg.writeEntry( "General", globalFieldOrder ); | ||
297 | } | ||
298 | } | ||
299 | |||
300 | |||
301 | |||
302 | void OContactFields::saveToRecord( OContact &cnt ){ | ||
303 | |||
304 | qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); | ||
305 | |||
306 | // Store fieldorder into this contact. | ||
307 | cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); | ||
308 | |||
309 | globalFieldOrder = fieldOrder; | ||
310 | changedFieldOrder = true; | ||
311 | |||
312 | } | ||
313 | |||
314 | void OContactFields::loadFromRecord( const OContact &cnt ){ | ||
315 | qDebug("ocontactfields loadFromRecord"); | ||
316 | qDebug("loading >%s<",cnt.fullName().latin1()); | ||
317 | |||
318 | // Get fieldorder for this contact. If none is defined, | ||
319 | // we will use the global one from the config file.. | ||
320 | |||
321 | fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); | ||
322 | |||
323 | qDebug("fieldOrder from contact>%s<",fieldOrder.latin1()); | ||
324 | |||
325 | if (fieldOrder.isEmpty()){ | ||
326 | fieldOrder = globalFieldOrder; | ||
327 | } | ||
328 | |||
329 | |||
330 | qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1()); | ||
331 | } | ||
332 | |||
333 | void OContactFields::setFieldOrder( int num, int index ){ | ||
334 | qDebug("qcontactfields setfieldorder pos %i -> %i",num,index); | ||
335 | |||
336 | fieldOrder[num] = QString::number( index )[0]; | ||
337 | |||
338 | // We will store this new fieldorder globally to | ||
339 | // remember it for contacts which have none | ||
340 | globalFieldOrder = fieldOrder; | ||
341 | changedFieldOrder = true; | ||
342 | |||
343 | qDebug("fieldOrder >%s<",fieldOrder.latin1()); | ||
344 | } | ||
345 | |||
346 | int OContactFields::getFieldOrder( int num, int defIndex ){ | ||
347 | qDebug("ocontactfields getFieldOrder"); | ||
348 | qDebug("fieldOrder >%s<",fieldOrder.latin1()); | ||
349 | |||
350 | // Get index of combo as char.. | ||
351 | QChar poschar = fieldOrder[num]; | ||
352 | |||
353 | bool ok; | ||
354 | int ret = 0; | ||
355 | // Convert char to number.. | ||
356 | if ( !( poschar == QChar::null ) ) | ||
357 | ret = QString( poschar ).toInt(&ok, 10); | ||
358 | else | ||
359 | ok = false; | ||
360 | |||
361 | // Return default value if index for | ||
362 | // num was not set or if anything else happened.. | ||
363 | if ( !ok ) ret = defIndex; | ||
364 | |||
365 | qDebug("returning >%i<",ret); | ||
366 | |||
367 | return ret; | ||
368 | |||
369 | } | ||