summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/ocontactfields.cpp
Unidiff
Diffstat (limited to 'core/pim/addressbook/ocontactfields.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/ocontactfields.cpp101
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
@@ -3,12 +3,14 @@
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*/
14QStringList OContactFields::untrdetailsfields( bool sorted ) 16QStringList OContactFields::untrdetailsfields( bool sorted )
@@ -196,13 +198,13 @@ QStringList OContactFields::untrfields( bool sorted )
196 198
197 return list; 199 return list;
198} 200}
199QMap<int, QString> OContactFields::idToTrFields() 201QMap<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" ) );
@@ -251,13 +253,13 @@ QMap<int, QString> OContactFields::idToTrFields()
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
262QMap<QString, int> OContactFields::trFieldsToId() 264QMap<QString, int> OContactFields::trFieldsToId()
263{ 265{
@@ -265,10 +267,103 @@ QMap<QString, int> OContactFields::trFieldsToId()
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
278OContactFields::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
289OContactFields::~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
302void 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
314void 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
333void 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
346int 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}