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 | |||
@@ -6,6 +6,8 @@ | |||
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 |
@@ -199,7 +201,7 @@ QStringList OContactFields::untrfields( bool sorted ) | |||
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" ) ); |
@@ -254,7 +256,7 @@ QMap<int, QString> OContactFields::idToTrFields() | |||
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 | } |
@@ -268,7 +270,100 @@ QMap<QString, int> OContactFields::trFieldsToId() | |||
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 | } | ||