Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ocontactfields.cpp

Go to the documentation of this file.
00001 
00002 #include "ocontactfields.h"
00003 
00004 #include <qstringlist.h>
00005 #include <qobject.h>
00006 
00007 // We should use our own enum in the future ..
00008 #include <qpe/recordfields.h>
00009 #include <qpe/config.h>
00010 #include <opie/ocontact.h>
00011 
00016 QStringList OContactFields::personalfields( bool sorted, bool translated )
00017 {
00018     QStringList list;
00019     QMap<int, QString> mapIdToStr;
00020     if ( translated )
00021             mapIdToStr = idToTrFields();
00022     else
00023             mapIdToStr = idToUntrFields();
00024 
00025     list.append( mapIdToStr[ Qtopia::AddressUid ] );
00026     list.append( mapIdToStr[ Qtopia::AddressCategory ] );
00027 
00028     list.append( mapIdToStr[ Qtopia::Title ] );
00029     list.append( mapIdToStr[ Qtopia::FirstName ] );
00030     list.append( mapIdToStr[ Qtopia::MiddleName ] );
00031     list.append( mapIdToStr[ Qtopia::LastName ] );
00032     list.append( mapIdToStr[ Qtopia::Suffix ] );
00033     list.append( mapIdToStr[ Qtopia::FileAs ] );
00034 
00035     list.append( mapIdToStr[ Qtopia::JobTitle ] );
00036     list.append( mapIdToStr[ Qtopia::Department ] );
00037     list.append( mapIdToStr[ Qtopia::Company ] );
00038 
00039     list.append( mapIdToStr[ Qtopia::Notes ] );
00040     list.append( mapIdToStr[ Qtopia::Groups ] );
00041 
00042     if (sorted) list.sort();
00043     return list;
00044 }
00045 
00050 QStringList OContactFields::detailsfields( bool sorted, bool translated )
00051 {
00052     QStringList list;
00053     QMap<int, QString> mapIdToStr;
00054     if ( translated )
00055             mapIdToStr = idToTrFields();
00056     else
00057             mapIdToStr = idToUntrFields();
00058 
00059     list.append( mapIdToStr[ Qtopia::Office ] );
00060     list.append( mapIdToStr[ Qtopia::Profession ] );
00061     list.append( mapIdToStr[ Qtopia::Assistant ] );
00062     list.append( mapIdToStr[ Qtopia::Manager ] );
00063 
00064     list.append( mapIdToStr[ Qtopia::Spouse ] );
00065     list.append( mapIdToStr[ Qtopia::Gender ] );
00066     list.append( mapIdToStr[ Qtopia::Birthday ] );
00067     list.append( mapIdToStr[ Qtopia::Anniversary ] );
00068     list.append( mapIdToStr[ Qtopia::Nickname ] );
00069     list.append( mapIdToStr[ Qtopia::Children ] );
00070 
00071     if (sorted) list.sort();
00072     return list;
00073 }
00074 
00079 QStringList OContactFields::phonefields( bool sorted, bool translated )
00080 {
00081     QStringList list;
00082     QMap<int, QString> mapIdToStr;
00083     if ( translated )
00084             mapIdToStr = idToTrFields();
00085     else
00086             mapIdToStr = idToUntrFields();
00087 
00088     list.append( mapIdToStr[Qtopia::BusinessPhone] );
00089     list.append( mapIdToStr[Qtopia::BusinessFax] );
00090     list.append( mapIdToStr[Qtopia::BusinessMobile] ); 
00091     list.append( mapIdToStr[Qtopia::BusinessPager] );
00092     list.append( mapIdToStr[Qtopia::BusinessWebPage] );
00093 
00094     list.append( mapIdToStr[Qtopia::DefaultEmail] );
00095     list.append( mapIdToStr[Qtopia::Emails] );
00096 
00097     list.append( mapIdToStr[Qtopia::HomePhone] );
00098     list.append( mapIdToStr[Qtopia::HomeFax] );
00099     list.append( mapIdToStr[Qtopia::HomeMobile] );
00100     // list.append( mapIdToStr[Qtopia::HomePager] );
00101     list.append( mapIdToStr[Qtopia::HomeWebPage] );
00102 
00103     if (sorted) list.sort();
00104 
00105     return list;
00106 }
00107 
00112 QStringList OContactFields::fields( bool sorted, bool translated )
00113 {
00114     QStringList list;
00115     QMap<int, QString> mapIdToStr;
00116     if ( translated )
00117             mapIdToStr = idToTrFields();
00118     else
00119             mapIdToStr = idToUntrFields();
00120 
00121     list += personalfields( sorted, translated );
00122 
00123     list += phonefields( sorted, translated );
00124 
00125     list.append( mapIdToStr[Qtopia::BusinessStreet] );
00126     list.append( mapIdToStr[Qtopia::BusinessCity] );
00127     list.append( mapIdToStr[Qtopia::BusinessState] );
00128     list.append( mapIdToStr[Qtopia::BusinessZip] );
00129     list.append( mapIdToStr[Qtopia::BusinessCountry] );
00130 
00131     list.append( mapIdToStr[Qtopia::HomeStreet] );
00132     list.append( mapIdToStr[Qtopia::HomeCity] );
00133     list.append( mapIdToStr[Qtopia::HomeState] );
00134     list.append( mapIdToStr[Qtopia::HomeZip] );
00135     list.append( mapIdToStr[Qtopia::HomeCountry] );
00136 
00137     list += detailsfields( sorted, translated );
00138 
00139     if (sorted) list.sort();
00140 
00141     return list;
00142 }
00143 
00144 
00149 QStringList OContactFields::untrpersonalfields( bool sorted )
00150 {
00151         return personalfields( sorted, false );
00152 }
00153 
00154 
00159 QStringList OContactFields::trpersonalfields( bool sorted )
00160 {
00161         return personalfields( sorted, true );
00162 }
00163 
00164 
00169 QStringList OContactFields::untrdetailsfields( bool sorted )
00170 {
00171         return detailsfields( sorted, false );
00172 }
00173 
00174 
00179 QStringList OContactFields::trdetailsfields( bool sorted )
00180 {
00181         return detailsfields( sorted, true );
00182 }
00183 
00184 
00189 QStringList OContactFields::trphonefields( bool sorted )
00190 {
00191         return phonefields( sorted, true );
00192 }
00193 
00198 QStringList OContactFields::untrphonefields( bool sorted )
00199 {
00200         return phonefields( sorted, false );
00201 }
00202 
00203 
00208 QStringList OContactFields::trfields( bool sorted )
00209 {
00210         return fields( sorted, true );
00211 }
00212 
00217 QStringList OContactFields::untrfields( bool sorted )
00218 {
00219     return fields( sorted, false );
00220 }
00221 
00222 QMap<int, QString> OContactFields::idToTrFields()
00223 {
00224         QMap<int, QString> ret_map;
00225 
00226         ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) );
00227         ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) );
00228 
00229         ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") );
00230         ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) );
00231         ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) );
00232         ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) );
00233         ret_map.insert( Qtopia::Suffix,  QObject::tr( "Suffix" ));
00234         ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) );
00235 
00236         ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) );
00237         ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) );
00238         ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) );
00239         ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) );
00240         ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) );
00241         ret_map.insert( Qtopia::BusinessMobile,  QObject::tr( "Business Mobile" ));
00242 
00243         // email
00244         ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) );
00245         ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) );
00246 
00247         ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) );
00248         ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) );
00249         ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) );
00250 
00251         // business
00252         ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) );
00253         ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) );
00254         ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) );
00255         ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) );
00256         ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) );
00257         ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) );
00258         ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) );
00259 
00260         ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) );
00261         ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) );
00262         ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) );
00263         ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) );
00264 
00265         // home
00266         ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) );
00267         ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) );
00268         ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) );
00269         ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) );
00270         ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) );
00271         ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) );
00272 
00273         //personal
00274         ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) );
00275         ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) );
00276         ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) );
00277         ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) );
00278         ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) );
00279         ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) );
00280 
00281         // other
00282         ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) );
00283 
00284 
00285         return ret_map;
00286 }
00287 
00288 QMap<int, QString> OContactFields::idToUntrFields()
00289 {
00290         QMap<int, QString> ret_map;
00291 
00292         ret_map.insert( Qtopia::AddressUid, "User Id" );
00293         ret_map.insert( Qtopia::AddressCategory, "Categories" );
00294 
00295         ret_map.insert( Qtopia::Title, "Name Title" );
00296         ret_map.insert( Qtopia::FirstName, "First Name" );
00297         ret_map.insert( Qtopia::MiddleName, "Middle Name" );
00298         ret_map.insert( Qtopia::LastName, "Last Name" );
00299         ret_map.insert( Qtopia::Suffix, "Suffix" );
00300         ret_map.insert( Qtopia::FileAs, "File As" );
00301 
00302         ret_map.insert( Qtopia::JobTitle, "Job Title" );
00303         ret_map.insert( Qtopia::Department, "Department" );
00304         ret_map.insert( Qtopia::Company, "Company" );
00305         ret_map.insert( Qtopia::BusinessPhone, "Business Phone" );
00306         ret_map.insert( Qtopia::BusinessFax, "Business Fax" );
00307         ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" );
00308 
00309         // email
00310         ret_map.insert( Qtopia::DefaultEmail, "Default Email" );
00311         ret_map.insert( Qtopia::Emails, "Emails" );
00312 
00313         ret_map.insert( Qtopia::HomePhone, "Home Phone" );
00314         ret_map.insert( Qtopia::HomeFax, "Home Fax" );
00315         ret_map.insert( Qtopia::HomeMobile, "Home Mobile" );
00316 
00317         // business
00318         ret_map.insert( Qtopia::BusinessStreet, "Business Street" );
00319         ret_map.insert( Qtopia::BusinessCity, "Business City" );
00320         ret_map.insert( Qtopia::BusinessState, "Business State" );
00321         ret_map.insert( Qtopia::BusinessZip, "Business Zip" );
00322         ret_map.insert( Qtopia::BusinessCountry, "Business Country" );
00323         ret_map.insert( Qtopia::BusinessPager, "Business Pager" );
00324         ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" );
00325 
00326         ret_map.insert( Qtopia::Office, "Office" );
00327         ret_map.insert( Qtopia::Profession, "Profession" );
00328         ret_map.insert( Qtopia::Assistant, "Assistant" );
00329         ret_map.insert( Qtopia::Manager, "Manager" );
00330 
00331         // home
00332         ret_map.insert( Qtopia::HomeStreet, "Home Street" );
00333         ret_map.insert( Qtopia::HomeCity, "Home City" );
00334         ret_map.insert( Qtopia::HomeState, "Home State" );
00335         ret_map.insert( Qtopia::HomeZip, "Home Zip" );
00336         ret_map.insert( Qtopia::HomeCountry, "Home Country" );
00337         ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" );
00338 
00339         //personal
00340         ret_map.insert( Qtopia::Spouse, "Spouse" );
00341         ret_map.insert( Qtopia::Gender, "Gender" );
00342         ret_map.insert( Qtopia::Birthday, "Birthday" );
00343         ret_map.insert( Qtopia::Anniversary, "Anniversary" );
00344         ret_map.insert( Qtopia::Nickname, "Nickname" );
00345         ret_map.insert( Qtopia::Children, "Children" );
00346 
00347         // other
00348         ret_map.insert( Qtopia::Notes, "Notes" );
00349         ret_map.insert( Qtopia::Groups, "Groups" );
00350 
00351 
00352         return ret_map;
00353 }
00354 
00355 QMap<QString, int> OContactFields::trFieldsToId()
00356 {
00357         QMap<int, QString> idtostr = idToTrFields();
00358         QMap<QString, int> ret_map;
00359 
00360 
00361         QMap<int, QString>::Iterator it;
00362         for( it = idtostr.begin(); it != idtostr.end(); ++it )
00363                 ret_map.insert( *it, it.key() );
00364 
00365 
00366         return ret_map;
00367 }
00368 
00369 /* ======================================================================= */
00370 
00371 QMap<QString, int> OContactFields::untrFieldsToId()
00372 {
00373         QMap<int, QString> idtostr = idToUntrFields();
00374         QMap<QString, int> ret_map;
00375 
00376 
00377         QMap<int, QString>::Iterator it;
00378         for( it = idtostr.begin(); it != idtostr.end(); ++it )
00379                 ret_map.insert( *it, it.key() );
00380 
00381 
00382         return ret_map;
00383 }
00384 
00385 
00386 OContactFields::OContactFields():
00387         fieldOrder( DEFAULT_FIELD_ORDER ),
00388         changedFieldOrder( false )
00389 {
00390         // Get the global field order from the config file and
00391         // use it as a start pattern
00392         Config cfg ( "AddressBook" );
00393         cfg.setGroup( "ContactFieldOrder" );
00394         globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER );
00395 }
00396 
00397 OContactFields::~OContactFields(){
00398 
00399         // We will store the fieldorder into the config file
00400         // to reuse it for the future.. 
00401         if ( changedFieldOrder ){
00402                 Config cfg ( "AddressBook" );
00403                 cfg.setGroup( "ContactFieldOrder" );
00404                 cfg.writeEntry( "General", globalFieldOrder );
00405         }
00406 }
00407 
00408 
00409 
00410 void OContactFields::saveToRecord( OContact &cnt ){
00411 
00412         qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1());
00413 
00414         // Store fieldorder into this contact.
00415         cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder );
00416 
00417         globalFieldOrder = fieldOrder;
00418         changedFieldOrder = true;
00419 
00420 }
00421 
00422 void OContactFields::loadFromRecord( const OContact &cnt ){
00423         qDebug("ocontactfields loadFromRecord");
00424         qDebug("loading >%s<",cnt.fullName().latin1());
00425 
00426         // Get fieldorder for this contact. If none is defined,
00427         // we will use the global one from the config file..
00428 
00429         fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME );
00430 
00431         qDebug("fieldOrder from contact>%s<",fieldOrder.latin1());
00432 
00433         if (fieldOrder.isEmpty()){
00434                 fieldOrder = globalFieldOrder;
00435         }
00436 
00437 
00438         qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1());
00439 }
00440 
00441 void OContactFields::setFieldOrder( int num, int index ){
00442         qDebug("qcontactfields setfieldorder pos %i -> %i",num,index);
00443 
00444         fieldOrder[num] = QString::number( index, 16 )[0];
00445 
00446         // We will store this new fieldorder globally to 
00447         // remember it for contacts which have none
00448         globalFieldOrder = fieldOrder;
00449         changedFieldOrder = true;
00450 
00451         qDebug("fieldOrder >%s<",fieldOrder.latin1());
00452 }
00453 
00454 int OContactFields::getFieldOrder( int num, int defIndex ){
00455         qDebug("ocontactfields getFieldOrder");
00456         qDebug("fieldOrder >%s<",fieldOrder.latin1());
00457 
00458         // Get index of combo as char..
00459         QChar poschar = fieldOrder[num];
00460 
00461         bool ok;
00462         int ret = 0;
00463         // Convert char to number..
00464         if ( !( poschar == QChar::null ) )
00465                 ret = QString( poschar ).toInt(&ok, 16);
00466         else
00467                 ok = false;
00468 
00469         // Return default value if index for
00470         // num was not set or if anything else happened..
00471         if ( !ok ) ret = defIndex;
00472 
00473         qDebug("returning >%i<",ret);
00474 
00475         return ret;
00476 
00477 }

Generated on Sat Nov 5 16:18:04 2005 for OPIE by  doxygen 1.4.2