00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "opimcontactfields.h"
00031
00032
00033 #include <opie2/opimcontact.h>
00034 #include <opie2/odebug.h>
00035
00036 #include <qpe/config.h>
00037
00038
00039 #include <qobject.h>
00040
00041
00042 namespace Opie
00043 {
00048 QStringList OPimContactFields::personalfields( bool sorted, bool translated )
00049 {
00050 QStringList list;
00051 QMap<int, QString> mapIdToStr;
00052 if ( translated )
00053 mapIdToStr = idToTrFields();
00054 else
00055 mapIdToStr = idToUntrFields();
00056
00057 list.append( mapIdToStr[ Qtopia::AddressUid ] );
00058 list.append( mapIdToStr[ Qtopia::AddressCategory ] );
00059
00060 list.append( mapIdToStr[ Qtopia::Title ] );
00061 list.append( mapIdToStr[ Qtopia::FirstName ] );
00062 list.append( mapIdToStr[ Qtopia::MiddleName ] );
00063 list.append( mapIdToStr[ Qtopia::LastName ] );
00064 list.append( mapIdToStr[ Qtopia::Suffix ] );
00065 list.append( mapIdToStr[ Qtopia::FileAs ] );
00066
00067 list.append( mapIdToStr[ Qtopia::JobTitle ] );
00068 list.append( mapIdToStr[ Qtopia::Department ] );
00069 list.append( mapIdToStr[ Qtopia::Company ] );
00070
00071 list.append( mapIdToStr[ Qtopia::Notes ] );
00072 list.append( mapIdToStr[ Qtopia::Groups ] );
00073
00074 if ( sorted ) list.sort();
00075 return list;
00076 }
00077
00082 QStringList OPimContactFields::detailsfields( bool sorted, bool translated )
00083 {
00084 QStringList list;
00085 QMap<int, QString> mapIdToStr;
00086 if ( translated )
00087 mapIdToStr = idToTrFields();
00088 else
00089 mapIdToStr = idToUntrFields();
00090
00091 list.append( mapIdToStr[ Qtopia::Office ] );
00092 list.append( mapIdToStr[ Qtopia::Profession ] );
00093 list.append( mapIdToStr[ Qtopia::Assistant ] );
00094 list.append( mapIdToStr[ Qtopia::Manager ] );
00095
00096 list.append( mapIdToStr[ Qtopia::Spouse ] );
00097 list.append( mapIdToStr[ Qtopia::Gender ] );
00098 list.append( mapIdToStr[ Qtopia::Birthday ] );
00099 list.append( mapIdToStr[ Qtopia::Anniversary ] );
00100 list.append( mapIdToStr[ Qtopia::Nickname ] );
00101 list.append( mapIdToStr[ Qtopia::Children ] );
00102
00103 if ( sorted ) list.sort();
00104 return list;
00105 }
00106
00111 QStringList OPimContactFields::phonefields( bool sorted, bool translated )
00112 {
00113 QStringList list;
00114 QMap<int, QString> mapIdToStr;
00115 if ( translated )
00116 mapIdToStr = idToTrFields();
00117 else
00118 mapIdToStr = idToUntrFields();
00119
00120 list.append( mapIdToStr[ Qtopia::BusinessPhone ] );
00121 list.append( mapIdToStr[ Qtopia::BusinessFax ] );
00122 list.append( mapIdToStr[ Qtopia::BusinessMobile ] );
00123 list.append( mapIdToStr[ Qtopia::BusinessPager ] );
00124 list.append( mapIdToStr[ Qtopia::BusinessWebPage ] );
00125
00126 list.append( mapIdToStr[ Qtopia::DefaultEmail ] );
00127 list.append( mapIdToStr[ Qtopia::Emails ] );
00128
00129 list.append( mapIdToStr[ Qtopia::HomePhone ] );
00130 list.append( mapIdToStr[ Qtopia::HomeFax ] );
00131 list.append( mapIdToStr[ Qtopia::HomeMobile ] );
00132
00133 list.append( mapIdToStr[ Qtopia::HomeWebPage ] );
00134
00135 if ( sorted ) list.sort();
00136
00137 return list;
00138 }
00139
00144 QStringList OPimContactFields::fields( bool sorted, bool translated )
00145 {
00146 QStringList list;
00147 QMap<int, QString> mapIdToStr;
00148 if ( translated )
00149 mapIdToStr = idToTrFields();
00150 else
00151 mapIdToStr = idToUntrFields();
00152
00153 list += personalfields( sorted, translated );
00154
00155 list += phonefields( sorted, translated );
00156
00157 list.append( mapIdToStr[ Qtopia::BusinessStreet ] );
00158 list.append( mapIdToStr[ Qtopia::BusinessCity ] );
00159 list.append( mapIdToStr[ Qtopia::BusinessState ] );
00160 list.append( mapIdToStr[ Qtopia::BusinessZip ] );
00161 list.append( mapIdToStr[ Qtopia::BusinessCountry ] );
00162
00163 list.append( mapIdToStr[ Qtopia::HomeStreet ] );
00164 list.append( mapIdToStr[ Qtopia::HomeCity ] );
00165 list.append( mapIdToStr[ Qtopia::HomeState ] );
00166 list.append( mapIdToStr[ Qtopia::HomeZip ] );
00167 list.append( mapIdToStr[ Qtopia::HomeCountry ] );
00168
00169 list += detailsfields( sorted, translated );
00170
00171 if ( sorted ) list.sort();
00172
00173 return list;
00174 }
00175
00176
00181 QStringList OPimContactFields::untrpersonalfields( bool sorted )
00182 {
00183 return personalfields( sorted, false );
00184 }
00185
00186
00191 QStringList OPimContactFields::trpersonalfields( bool sorted )
00192 {
00193 return personalfields( sorted, true );
00194 }
00195
00196
00201 QStringList OPimContactFields::untrdetailsfields( bool sorted )
00202 {
00203 return detailsfields( sorted, false );
00204 }
00205
00206
00211 QStringList OPimContactFields::trdetailsfields( bool sorted )
00212 {
00213 return detailsfields( sorted, true );
00214 }
00215
00216
00221 QStringList OPimContactFields::trphonefields( bool sorted )
00222 {
00223 return phonefields( sorted, true );
00224 }
00225
00230 QStringList OPimContactFields::untrphonefields( bool sorted )
00231 {
00232 return phonefields( sorted, false );
00233 }
00234
00235
00240 QStringList OPimContactFields::trfields( bool sorted )
00241 {
00242 return fields( sorted, true );
00243 }
00244
00249 QStringList OPimContactFields::untrfields( bool sorted )
00250 {
00251 return fields( sorted, false );
00252 }
00253
00254 QMap<int, QString> OPimContactFields::idToTrFields()
00255 {
00256 QMap<int, QString> ret_map;
00257
00258 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) );
00259 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) );
00260
00261 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title" ) );
00262 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) );
00263 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) );
00264 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) );
00265 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ) );
00266 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) );
00267
00268 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) );
00269 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) );
00270 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) );
00271 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) );
00272 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) );
00273 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ) );
00274
00275
00276 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) );
00277 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) );
00278
00279 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) );
00280 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) );
00281 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) );
00282
00283
00284 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) );
00285 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) );
00286 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) );
00287 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) );
00288 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) );
00289 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) );
00290 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) );
00291
00292 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) );
00293 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) );
00294 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) );
00295 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) );
00296
00297
00298 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) );
00299 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) );
00300 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) );
00301 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) );
00302 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) );
00303 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) );
00304
00305
00306 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) );
00307 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) );
00308 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) );
00309 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) );
00310 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) );
00311 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) );
00312
00313
00314 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) );
00315
00316
00317 return ret_map;
00318 }
00319
00320 QMap<int, QString> OPimContactFields::idToUntrFields()
00321 {
00322 QMap<int, QString> ret_map;
00323
00324 ret_map.insert( Qtopia::AddressUid, "User Id" );
00325 ret_map.insert( Qtopia::AddressCategory, "Categories" );
00326
00327 ret_map.insert( Qtopia::Title, "Name Title" );
00328 ret_map.insert( Qtopia::FirstName, "First Name" );
00329 ret_map.insert( Qtopia::MiddleName, "Middle Name" );
00330 ret_map.insert( Qtopia::LastName, "Last Name" );
00331 ret_map.insert( Qtopia::Suffix, "Suffix" );
00332 ret_map.insert( Qtopia::FileAs, "File As" );
00333
00334 ret_map.insert( Qtopia::JobTitle, "Job Title" );
00335 ret_map.insert( Qtopia::Department, "Department" );
00336 ret_map.insert( Qtopia::Company, "Company" );
00337 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" );
00338 ret_map.insert( Qtopia::BusinessFax, "Business Fax" );
00339 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" );
00340
00341
00342 ret_map.insert( Qtopia::DefaultEmail, "Default Email" );
00343 ret_map.insert( Qtopia::Emails, "Emails" );
00344
00345 ret_map.insert( Qtopia::HomePhone, "Home Phone" );
00346 ret_map.insert( Qtopia::HomeFax, "Home Fax" );
00347 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" );
00348
00349
00350 ret_map.insert( Qtopia::BusinessStreet, "Business Street" );
00351 ret_map.insert( Qtopia::BusinessCity, "Business City" );
00352 ret_map.insert( Qtopia::BusinessState, "Business State" );
00353 ret_map.insert( Qtopia::BusinessZip, "Business Zip" );
00354 ret_map.insert( Qtopia::BusinessCountry, "Business Country" );
00355 ret_map.insert( Qtopia::BusinessPager, "Business Pager" );
00356 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" );
00357
00358 ret_map.insert( Qtopia::Office, "Office" );
00359 ret_map.insert( Qtopia::Profession, "Profession" );
00360 ret_map.insert( Qtopia::Assistant, "Assistant" );
00361 ret_map.insert( Qtopia::Manager, "Manager" );
00362
00363
00364 ret_map.insert( Qtopia::HomeStreet, "Home Street" );
00365 ret_map.insert( Qtopia::HomeCity, "Home City" );
00366 ret_map.insert( Qtopia::HomeState, "Home State" );
00367 ret_map.insert( Qtopia::HomeZip, "Home Zip" );
00368 ret_map.insert( Qtopia::HomeCountry, "Home Country" );
00369 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" );
00370
00371
00372 ret_map.insert( Qtopia::Spouse, "Spouse" );
00373 ret_map.insert( Qtopia::Gender, "Gender" );
00374 ret_map.insert( Qtopia::Birthday, "Birthday" );
00375 ret_map.insert( Qtopia::Anniversary, "Anniversary" );
00376 ret_map.insert( Qtopia::Nickname, "Nickname" );
00377 ret_map.insert( Qtopia::Children, "Children" );
00378
00379
00380 ret_map.insert( Qtopia::Notes, "Notes" );
00381 ret_map.insert( Qtopia::Groups, "Groups" );
00382
00383
00384 return ret_map;
00385 }
00386
00387 QMap<QString, int> OPimContactFields::trFieldsToId()
00388 {
00389 QMap<int, QString> idtostr = idToTrFields();
00390 QMap<QString, int> ret_map;
00391
00392
00393 QMap<int, QString>::Iterator it;
00394 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
00395 ret_map.insert( *it, it.key() );
00396
00397
00398 return ret_map;
00399 }
00400
00401
00402
00403 QMap<QString, int> OPimContactFields::untrFieldsToId()
00404 {
00405 QMap<int, QString> idtostr = idToUntrFields();
00406 QMap<QString, int> ret_map;
00407
00408
00409 QMap<int, QString>::Iterator it;
00410 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
00411 ret_map.insert( *it, it.key() );
00412
00413
00414 return ret_map;
00415 }
00416
00417
00418 OPimContactFields::OPimContactFields() :
00419 fieldOrder( DEFAULT_FIELD_ORDER ),
00420 changedFieldOrder( false )
00421 {
00422
00423
00424 Config cfg ( "AddressBook" );
00425 cfg.setGroup( "ContactFieldOrder" );
00426 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER );
00427 }
00428
00429 OPimContactFields::~OPimContactFields()
00430 {
00431
00432
00433
00434 if ( changedFieldOrder )
00435 {
00436 Config cfg ( "AddressBook" );
00437 cfg.setGroup( "ContactFieldOrder" );
00438 cfg.writeEntry( "General", globalFieldOrder );
00439 }
00440 }
00441
00442
00443
00444 void OPimContactFields::saveToRecord( OPimContact &cnt )
00445 {
00446
00447 odebug << "ocontactfields saveToRecord: >" << fieldOrder << "<" << oendl;
00448
00449
00450 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder );
00451
00452 globalFieldOrder = fieldOrder;
00453 changedFieldOrder = true;
00454
00455 }
00456
00457 void OPimContactFields::loadFromRecord( const OPimContact &cnt )
00458 {
00459 odebug << "ocontactfields loadFromRecord" << oendl;
00460 odebug << "loading >" << cnt.fullName() << "<" << oendl;
00461
00462
00463
00464
00465 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME );
00466
00467 odebug << "fieldOrder from contact>" << fieldOrder << "<" << oendl;
00468
00469 if ( fieldOrder.isEmpty() )
00470 {
00471 fieldOrder = globalFieldOrder;
00472 }
00473
00474
00475 odebug << "effective fieldOrder in loadFromRecord >" << fieldOrder << "<" << oendl;
00476 }
00477
00478 void OPimContactFields::setFieldOrder( int num, int index )
00479 {
00480 odebug << "qcontactfields setfieldorder pos " << num << " -> " << index << "" << oendl;
00481
00482 fieldOrder[ num ] = QString::number( index, 16 ) [ 0 ];
00483
00484
00485
00486 globalFieldOrder = fieldOrder;
00487 changedFieldOrder = true;
00488
00489 odebug << "fieldOrder >" << fieldOrder << "<" << oendl;
00490 }
00491
00492 int OPimContactFields::getFieldOrder( int num, int defIndex )
00493 {
00494 odebug << "ocontactfields getFieldOrder" << oendl;
00495 odebug << "fieldOrder >" << fieldOrder << "<" << oendl;
00496
00497
00498 QChar poschar = fieldOrder[ num ];
00499
00500 bool ok;
00501 int ret = 0;
00502
00503 if ( !( poschar == QChar::null ) )
00504 ret = QString( poschar ).toInt( &ok, 16 );
00505 else
00506 ok = false;
00507
00508
00509
00510 if ( !ok ) ret = defIndex;
00511
00512 odebug << "returning >" << ret << "<" << oendl;
00513
00514 return ret;
00515
00516 }
00517
00518 }