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

opimcontact.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #define QTOPIA_INTERNAL_CONTACT_MRE
00031 
00032 #include "opimcontact.h"
00033 
00034 /* OPIE */
00035 #include <opie2/opimresolver.h>
00036 #include <opie2/opimdateconversion.h>
00037 #include <opie2/odebug.h>
00038 
00039 #include <qpe/stringutil.h>
00040 #include <qpe/timestring.h>
00041 #include <qpe/config.h>
00042 
00043 /* QT */
00044 #include <qstylesheet.h>
00045 
00046 /* STD */
00047 #include <stdio.h>
00048 
00061 namespace Opie
00062 {
00066 OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
00067 {}
00068 
00074 OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 )
00075 {
00076     QString cats = mMap[ Qtopia::AddressCategory ];
00077     if ( !cats.isEmpty() )
00078         setCategories( idsFromString( cats ) );
00079 
00080     QString uidStr = find( Qtopia::AddressUid );
00081 
00082     if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
00083     {
00084         setUid( uidGen().generate() );
00085     }
00086     else
00087         setUid( uidStr.toInt() );
00088 
00089     //     if ( !uidStr.isEmpty() )
00090     //  setUid( uidStr.toInt() );
00091 }
00092 
00096 OPimContact::~OPimContact()
00097 {}
00098 
00433 QMap<int, QString> OPimContact::toMap() const
00434 {
00435     QMap<int, QString> map = mMap;
00436     QString cats = idsToString( categories() );
00437     if ( !cats.isEmpty() )
00438         map.insert( Qtopia::AddressCategory, cats );
00439     return map;
00440 }
00441 
00445 QString OPimContact::toRichText() const
00446 {
00447     QString text;
00448     QString value, comp, state;
00449     QString str;
00450     bool marker = false;
00451 
00452     Config cfg( "qpe" );
00453     cfg.setGroup( "Appearance" );
00454     int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State );
00455 
00456     // name, jobtitle and company
00457     if ( !( value = fullName() ).isEmpty() )
00458         text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString( value ) + "</h3></b>";
00459 
00460     if ( !( value = jobTitle() ).isEmpty() )
00461         text += Qtopia::escapeString( value ) + " ";
00462 
00463     comp = company();
00464     if ( !( value = department() ).isEmpty() )
00465     {
00466         text += Qtopia::escapeString( value );
00467         if ( comp )
00468             text += ", " + Qtopia::escapeString( comp );
00469     }
00470     else if ( comp )
00471         text += "<br>" + Qtopia::escapeString( comp );
00472     text += "<br><hr>";
00473 
00474     // defailt email
00475     QString defEmail = defaultEmail();
00476     if ( !defEmail.isEmpty() )
00477     {
00478         text += "<b><img src=\"addressbook/email\"> " + QObject::tr( "Default Email: " ) + "</b>"
00479                 + Qtopia::escapeString( defEmail );
00480         marker = true;
00481     }
00482 
00483     // business address
00484     if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
00485             !businessZip().isEmpty() || !businessCountry().isEmpty() )
00486     {
00487         text += QObject::tr( "<br><b>Work Address:</b>" );
00488         marker = true;
00489     }
00490 
00491     if ( !( value = businessStreet() ).isEmpty() )
00492     {
00493         text += "<br>" + Qtopia::escapeString( value );
00494         marker = true;
00495     }
00496 
00497     switch ( addressformat )
00498     {
00499     case Zip_City_State:
00500         { //  Zip_Code City, State
00501             state = businessState();
00502             if ( !( value = businessZip() ).isEmpty() )
00503             {
00504                 text += "<br>" + Qtopia::escapeString( value ) + " ";
00505                 marker = true;
00506 
00507             }
00508             if ( !( value = businessCity() ).isEmpty() )
00509             {
00510                 marker = true;
00511                 if ( businessZip().isEmpty() && !businessStreet().isEmpty() )
00512                     text += "<br>";
00513                 text += Qtopia::escapeString( value );
00514                 if ( state )
00515                     text += ", " + Qtopia::escapeString( state );
00516             }
00517             else if ( !state.isEmpty() )
00518             {
00519                 text += "<br>" + Qtopia::escapeString( state );
00520                 marker = true;
00521             }
00522             break;
00523         }
00524     case City_State_Zip:
00525         { // City, State Zip_Code
00526             state = businessState();
00527             if ( !( value = businessCity() ).isEmpty() )
00528             {
00529                 marker = true;
00530                 text += "<br>" + Qtopia::escapeString( value );
00531                 if ( state )
00532                     text += ", " + Qtopia::escapeString( state );
00533             }
00534             else if ( !state.isEmpty() )
00535             {
00536                 text += "<br>" + Qtopia::escapeString( state );
00537                 marker = true;
00538             }
00539             if ( !( value = businessZip() ).isEmpty() )
00540             {
00541                 text += " " + Qtopia::escapeString( value );
00542                 marker = true;
00543             }
00544             break;
00545         }
00546     }
00547 
00548     if ( !( value = businessCountry() ).isEmpty() )
00549     {
00550         text += "<br>" + Qtopia::escapeString( value );
00551         marker = true;
00552     }
00553 
00554     // rest of Business data
00555     str = office();
00556     if ( !str.isEmpty() )
00557     {
00558         text += "<br><b>" + QObject::tr( "Office: " ) + "</b>"
00559                 + Qtopia::escapeString( str );
00560         marker = true;
00561     }
00562     str = businessWebpage();
00563     if ( !str.isEmpty() )
00564     {
00565         text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr( "Business Web Page: " ) + "</b>"
00566                 + Qtopia::escapeString( str );
00567         marker = true;
00568     }
00569     str = businessPhone();
00570     if ( !str.isEmpty() )
00571     {
00572         text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr( "Business Phone: " ) + "</b>"
00573                 + Qtopia::escapeString( str );
00574         marker = true;
00575     }
00576     str = businessFax();
00577     if ( !str.isEmpty() )
00578     {
00579         text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr( "Business Fax: " ) + "</b>"
00580                 + Qtopia::escapeString( str );
00581         marker = true;
00582     }
00583     str = businessMobile();
00584     if ( !str.isEmpty() )
00585     {
00586         text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr( "Business Mobile: " ) + "</b>"
00587                 + Qtopia::escapeString( str );
00588         marker = true;
00589     }
00590     str = businessPager();
00591     if ( !str.isEmpty() )
00592     {
00593         text += "<br><b>" + QObject::tr( "Business Pager: " ) + "</b>"
00594                 + Qtopia::escapeString( str );
00595         marker = true;
00596     }
00597 
00598     // text += "<br>";
00599 
00600     // home address
00601     if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
00602             !homeZip().isEmpty() || !homeCountry().isEmpty() )
00603     {
00604         text += QObject::tr( "<br><b>Home Address:</b>" );
00605         marker = true;
00606     }
00607 
00608     if ( !( value = homeStreet() ).isEmpty() )
00609     {
00610         text += "<br>" + Qtopia::escapeString( value );
00611         marker = true;
00612     }
00613 
00614     switch ( addressformat )
00615     {
00616     case Zip_City_State:
00617         { //  Zip_Code City, State
00618             state = homeState();
00619             if ( !( value = homeZip() ).isEmpty() )
00620             {
00621                 text += "<br>" + Qtopia::escapeString( value ) + " ";
00622                 marker = true;
00623             }
00624             if ( !( value = homeCity() ).isEmpty() )
00625             {
00626                 marker = true;
00627                 if ( homeZip().isEmpty() && !homeStreet().isEmpty() )
00628                     text += "<br>";
00629                 text += Qtopia::escapeString( value );
00630                 if ( !state.isEmpty() )
00631                     text += ", " + Qtopia::escapeString( state );
00632             }
00633             else if ( !state.isEmpty() )
00634             {
00635                 text += "<br>" + Qtopia::escapeString( state );
00636                 marker = true;
00637             }
00638             break;
00639         }
00640     case City_State_Zip:
00641         { // City, State Zip_Code
00642             state = homeState();
00643             if ( !( value = homeCity() ).isEmpty() )
00644             {
00645                 marker = true;
00646                 text += "<br>" + Qtopia::escapeString( value );
00647                 if ( state )
00648                     text += ", " + Qtopia::escapeString( state );
00649             }
00650             else if ( !state.isEmpty() )
00651             {
00652                 text += "<br>" + Qtopia::escapeString( state );
00653                 marker = true;
00654             }
00655             if ( !( value = homeZip() ).isEmpty() )
00656             {
00657                 text += " " + Qtopia::escapeString( value );
00658                 marker = true;
00659             }
00660             break;
00661         }
00662     }
00663 
00664     if ( !( value = homeCountry() ).isEmpty() )
00665     {
00666         text += "<br>" + Qtopia::escapeString( value );
00667         marker = true;
00668     }
00669 
00670     // rest of Home data
00671     str = homeWebpage();
00672     if ( !str.isEmpty() )
00673     {
00674         text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr( "Home Web Page: " ) + "</b>"
00675                 + Qtopia::escapeString( str );
00676         marker = true;
00677     }
00678     str = homePhone();
00679     if ( !str.isEmpty() )
00680     {
00681         text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>"
00682                 + Qtopia::escapeString( str );
00683         marker = true;
00684     }
00685     str = homeFax();
00686     if ( !str.isEmpty() )
00687     {
00688         text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr( "Home Fax: " ) + "</b>"
00689                 + Qtopia::escapeString( str );
00690         marker = true;
00691     }
00692     str = homeMobile();
00693     if ( !str.isEmpty() )
00694     {
00695         text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>"
00696                 + Qtopia::escapeString( str );
00697         marker = true;
00698     }
00699 
00700     if ( marker )
00701         text += "<br><hr>";
00702 
00703     // the rest...
00704     str = emails();
00705     if ( !str.isEmpty() && ( str != defEmail ) )
00706         text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>"
00707                 + Qtopia::escapeString( str );
00708     str = profession();
00709     if ( !str.isEmpty() )
00710         text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>"
00711                 + Qtopia::escapeString( str );
00712     str = assistant();
00713     if ( !str.isEmpty() )
00714         text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>"
00715                 + Qtopia::escapeString( str );
00716     str = manager();
00717     if ( !str.isEmpty() )
00718         text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>"
00719                 + Qtopia::escapeString( str );
00720     str = gender();
00721     if ( !str.isEmpty() && str.toInt() != 0 )
00722     {
00723         text += "<br>";
00724         if ( str.toInt() == 1 )
00725             str = QObject::tr( "Male" );
00726         else if ( str.toInt() == 2 )
00727             str = QObject::tr( "Female" );
00728         text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str;
00729     }
00730     str = spouse();
00731     if ( !str.isEmpty() )
00732         text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>"
00733                 + Qtopia::escapeString( str );
00734     if ( birthday().isValid() )
00735     {
00736         str = TimeString::numberDateString( birthday() );
00737         text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>"
00738                 + Qtopia::escapeString( str );
00739     }
00740     if ( anniversary().isValid() )
00741     {
00742         str = TimeString::numberDateString( anniversary() );
00743         text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>"
00744                 + Qtopia::escapeString( str );
00745     }
00746     str = children();
00747     if ( !str.isEmpty() )
00748         text += "<br><b>" + QObject::tr( "Children: " ) + "</b>"
00749                 + Qtopia::escapeString( str );
00750 
00751     str = nickname();
00752     if ( !str.isEmpty() )
00753         text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>"
00754                 + Qtopia::escapeString( str );
00755 
00756     // categories
00757     if ( categoryNames( "Contacts" ).count() )
00758     {
00759         text += "<br><b>" + QObject::tr( "Category:" ) + "</b> ";
00760         text += categoryNames( "Contacts" ).join( ", " );
00761     }
00762 
00763     // notes last
00764     if ( !( value = notes() ).isEmpty() )
00765     {
00766         text += "<br><hr><b>" + QObject::tr( "Notes:" ) + "</b> ";
00767         QRegExp reg( "\n" );
00768 
00769         //QString tmp = Qtopia::escapeString(value);
00770         QString tmp = QStyleSheet::convertFromPlainText( value );
00771         //tmp.replace( reg, "<br>" );
00772         text += "<br>" + tmp + "<br>";
00773     }
00774     return text;
00775 }
00776 
00780 void OPimContact::insert( int key, const QString &v )
00781 {
00782     QString value = v.stripWhiteSpace();
00783     if ( value.isEmpty() )
00784         mMap.remove( key );
00785     else
00786         mMap.insert( key, value );
00787 }
00788 
00792 void OPimContact::replace( int key, const QString & v )
00793 {
00794     QString value = v.stripWhiteSpace();
00795     if ( value.isEmpty() )
00796         mMap.remove( key );
00797     else
00798         mMap.replace( key, value );
00799 }
00800 
00804 QString OPimContact::find( int key ) const
00805 {
00806     return mMap[ key ];
00807 }
00808 
00812 QString OPimContact::displayAddress( const QString &street,
00813                                   const QString &city,
00814                                   const QString &state,
00815                                   const QString &zip,
00816                                   const QString &country ) const
00817 {
00818     QString s = street;
00819     if ( !street.isEmpty() )
00820         s += "\n";
00821     s += city;
00822     if ( !city.isEmpty() && !state.isEmpty() )
00823         s += ", ";
00824     s += state;
00825     if ( !state.isEmpty() && !zip.isEmpty() )
00826         s += "  ";
00827     s += zip;
00828     if ( !country.isEmpty() && !s.isEmpty() )
00829         s += "\n";
00830     s += country;
00831     return s;
00832 }
00833 
00837 QString OPimContact::displayBusinessAddress() const
00838 {
00839     return displayAddress( businessStreet(), businessCity(),
00840                            businessState(), businessZip(),
00841                            businessCountry() );
00842 }
00843 
00847 QString OPimContact::displayHomeAddress() const
00848 {
00849     return displayAddress( homeStreet(), homeCity(),
00850                            homeState(), homeZip(),
00851                            homeCountry() );
00852 }
00853 
00857 QString OPimContact::fullName() const
00858 {
00859     QString title = find( Qtopia::Title );
00860     QString firstName = find( Qtopia::FirstName );
00861     QString middleName = find( Qtopia::MiddleName );
00862     QString lastName = find( Qtopia::LastName );
00863     QString suffix = find( Qtopia::Suffix );
00864 
00865     QString name = title;
00866     if ( !firstName.isEmpty() )
00867     {
00868         if ( !name.isEmpty() )
00869             name += " ";
00870         name += firstName;
00871     }
00872     if ( !middleName.isEmpty() )
00873     {
00874         if ( !name.isEmpty() )
00875             name += " ";
00876         name += middleName;
00877     }
00878     if ( !lastName.isEmpty() )
00879     {
00880         if ( !name.isEmpty() )
00881             name += " ";
00882         name += lastName;
00883     }
00884     if ( !suffix.isEmpty() )
00885     {
00886         if ( !name.isEmpty() )
00887             name += " ";
00888         name += suffix;
00889     }
00890     return name.simplifyWhiteSpace();
00891 }
00892 
00896 QStringList OPimContact::childrenList() const
00897 {
00898     return QStringList::split( " ", find( Qtopia::Children ) );
00899 }
00900 
00928 QStringList OPimContact::emailList() const
00929 {
00930     QString emailStr = emails();
00931 
00932     QStringList r;
00933     if ( !emailStr.isEmpty() )
00934     {
00935         odebug << " emailstr " << oendl;
00936         QStringList l = QStringList::split( emailSeparator(), emailStr );
00937         for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
00938             r += ( *it ).simplifyWhiteSpace();
00939     }
00940 
00941     return r;
00942 }
00943 
00950 void OPimContact::setFileAs()
00951 {
00952     QString lastName, firstName, middleName, fileas;
00953 
00954     lastName = find( Qtopia::LastName );
00955     firstName = find( Qtopia::FirstName );
00956     middleName = find( Qtopia::MiddleName );
00957     if ( !lastName.isEmpty() && !firstName.isEmpty()
00958             && !middleName.isEmpty() )
00959         fileas = lastName + ", " + firstName + " " + middleName;
00960     else if ( !lastName.isEmpty() && !firstName.isEmpty() )
00961         fileas = lastName + ", " + firstName;
00962     else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
00963               !middleName.isEmpty() )
00964         fileas = firstName + ( firstName.isEmpty() ? "" : " " )
00965                  + middleName + ( middleName.isEmpty() ? "" : " " )
00966                  + lastName;
00967 
00968     replace( Qtopia::FileAs, fileas );
00969 }
00970 
00975 void OPimContact::save( QString &buf ) const
00976 {
00977     static const QStringList SLFIELDS = fields();
00978     // I'm expecting "<Contact " in front of this...
00979     for ( QMap<int, QString>::ConstIterator it = mMap.begin();
00980             it != mMap.end(); ++it )
00981     {
00982         const QString &value = it.data();
00983         int key = it.key();
00984         if ( !value.isEmpty() )
00985         {
00986             if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid )
00987                 continue;
00988 
00989             key -= Qtopia::AddressCategory + 1;
00990             buf += SLFIELDS[ key ];
00991             buf += "=\"" + Qtopia::escapeString( value ) + "\" ";
00992         }
00993     }
00994     buf += customToXml();
00995     if ( categories().count() > 0 )
00996         buf += "Categories=\"" + idsToString( categories() ) + "\" ";
00997     buf += "Uid=\"" + QString::number( uid() ) + "\" ";
00998     // You need to close this yourself
00999 }
01000 
01001 
01008 QStringList OPimContact::fields()
01009 {
01010     QStringList list;
01011 
01012     list.append( "Title" );  // Not Used!
01013     list.append( "FirstName" );
01014     list.append( "MiddleName" );
01015     list.append( "LastName" );
01016     list.append( "Suffix" );
01017     list.append( "FileAs" );
01018 
01019     list.append( "JobTitle" );
01020     list.append( "Department" );
01021     list.append( "Company" );
01022     list.append( "BusinessPhone" );
01023     list.append( "BusinessFax" );
01024     list.append( "BusinessMobile" );
01025 
01026     list.append( "DefaultEmail" );
01027     list.append( "Emails" );
01028 
01029     list.append( "HomePhone" );
01030     list.append( "HomeFax" );
01031     list.append( "HomeMobile" );
01032 
01033     list.append( "BusinessStreet" );
01034     list.append( "BusinessCity" );
01035     list.append( "BusinessState" );
01036     list.append( "BusinessZip" );
01037     list.append( "BusinessCountry" );
01038     list.append( "BusinessPager" );
01039     list.append( "BusinessWebPage" );
01040 
01041     list.append( "Office" );
01042     list.append( "Profession" );
01043     list.append( "Assistant" );
01044     list.append( "Manager" );
01045 
01046     list.append( "HomeStreet" );
01047     list.append( "HomeCity" );
01048     list.append( "HomeState" );
01049     list.append( "HomeZip" );
01050     list.append( "HomeCountry" );
01051     list.append( "HomeWebPage" );
01052 
01053     list.append( "Spouse" );
01054     list.append( "Gender" );
01055     list.append( "Birthday" );
01056     list.append( "Anniversary" );
01057     list.append( "Nickname" );
01058     list.append( "Children" );
01059 
01060     list.append( "Notes" );
01061     list.append( "Groups" );
01062 
01063     return list;
01064 }
01065 
01066 
01071 void OPimContact::setEmails( const QString &str )
01072 {
01073     replace( Qtopia::Emails, str );
01074     if ( str.isEmpty() )
01075         setDefaultEmail( QString::null );
01076 }
01077 
01081 void OPimContact::setChildren( const QString &str )
01082 {
01083     replace( Qtopia::Children, str );
01084 }
01085 
01091 bool OPimContact::match( const QRegExp &r ) const
01092 {
01093     setLastHitField( -1 );
01094     bool match;
01095     match = false;
01096     QMap<int, QString>::ConstIterator it;
01097     for ( it = mMap.begin(); it != mMap.end(); ++it )
01098     {
01099         if ( ( *it ).find( r ) > -1 )
01100         {
01101             setLastHitField( it.key() );
01102             match = true;
01103             break;
01104         }
01105     }
01106     return match;
01107 }
01108 
01109 
01110 QString OPimContact::toShortText() const
01111 {
01112     return ( fullName() );
01113 }
01114 
01115 
01116 QString OPimContact::type() const
01117 {
01118     return QString::fromLatin1( "OPimContact" );
01119 }
01120 
01121 
01122 class QString OPimContact::recordField( int pos ) const
01123 {
01124     QStringList SLFIELDS = fields(); // ?? why this ? (se)
01125     return SLFIELDS[ pos ];
01126 }
01127 
01128 // In future releases, we should store birthday and anniversary
01129 // internally as QDate instead of QString !
01130 // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
01131 
01136 void OPimContact::setBirthday( const QDate &v )
01137 {
01138     if ( v.isNull() )
01139     {
01140         replace( Qtopia::Birthday, QString::null );
01141         return ;
01142     }
01143 
01144     if ( v.isValid() )
01145         replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
01146 
01147 }
01148 
01149 
01154 void OPimContact::setAnniversary( const QDate &v )
01155 {
01156     if ( v.isNull() )
01157     {
01158         replace( Qtopia::Anniversary, QString::null );
01159         return ;
01160     }
01161 
01162     if ( v.isValid() )
01163         replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
01164 }
01165 
01166 
01170 QDate OPimContact::birthday() const
01171 {
01172     QString str = find( Qtopia::Birthday );
01173     if ( !str.isEmpty() )
01174         return OPimDateConversion::dateFromString ( str );
01175     else
01176         return QDate();
01177 }
01178 
01179 
01183 QDate OPimContact::anniversary() const
01184 {
01185     QDate empty;
01186     QString str = find( Qtopia::Anniversary );
01187     if ( !str.isEmpty() )
01188         return OPimDateConversion::dateFromString ( str );
01189     else
01190         return empty;
01191 }
01192 
01193 
01194 void OPimContact::insertEmail( const QString &v )
01195 {
01196     //odebug << "insertEmail " << v << "" << oendl;
01197     QString e = v.simplifyWhiteSpace();
01198     QString def = defaultEmail();
01199 
01200     // if no default, set it as the default email and don't insert
01201     if ( def.isEmpty() )
01202     {
01203         setDefaultEmail( e ); // will insert into the list for us
01204         return ;
01205     }
01206 
01207     // otherwise, insert assuming doesn't already exist
01208     QString emailsStr = find( Qtopia::Emails );
01209     if ( emailsStr.contains( e ) )
01210         return ;
01211     if ( !emailsStr.isEmpty() )
01212         emailsStr += emailSeparator();
01213     emailsStr += e;
01214     replace( Qtopia::Emails, emailsStr );
01215 }
01216 
01217 
01218         void OPimContact::removeEmail( const QString &v )
01219 {
01220     QString e = v.simplifyWhiteSpace();
01221     QString def = defaultEmail();
01222     QString emailsStr = find( Qtopia::Emails );
01223     QStringList emails = emailList();
01224 
01225     // otherwise, must first contain it
01226     if ( !emailsStr.contains( e ) )
01227         return ;
01228 
01229     // remove it
01230     //odebug << " removing email from list " << e << "" << oendl;
01231     emails.remove( e );
01232     // reset the string
01233     emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
01234     replace( Qtopia::Emails, emailsStr );
01235 
01236     // if default, then replace the default email with the first one
01237     if ( def == e )
01238     {
01239         //odebug << "removeEmail is default; setting new default" << oendl;
01240         if ( !emails.count() )
01241             clearEmails();
01242         else // setDefaultEmail will remove e from the list
01243             setDefaultEmail( emails.first() );
01244     }
01245 }
01246 
01247 
01248 void OPimContact::clearEmails()
01249 {
01250     mMap.remove( Qtopia::DefaultEmail );
01251     mMap.remove( Qtopia::Emails );
01252 }
01253 
01254 
01255 void OPimContact::setDefaultEmail( const QString &v )
01256 {
01257     QString e = v.simplifyWhiteSpace();
01258 
01259     //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl;
01260     replace( Qtopia::DefaultEmail, e );
01261 
01262     if ( !e.isEmpty() )
01263         insertEmail( e );
01264 
01265 }
01266 
01267 
01268 void OPimContact::insertEmails( const QStringList &v )
01269 {
01270     for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
01271         insertEmail( *it );
01272 }
01273 
01274 
01275 int OPimContact::rtti() const
01276 {
01277     return OPimResolver::AddressBook;
01278 }
01279 
01293 OPimContact* OPimContact::safeCast( const OPimRecord* rec ) {
01294     return( rec && rec->rtti() == OPimResolver::AddressBook ) ?
01295         static_cast<OPimContact*>( const_cast<OPimRecord*>(rec) ) :
01296         0l;
01297 }
01298 
01299 
01300 void OPimContact::setUid( int i )
01301 {
01302     OPimRecord::setUid( i );
01303     replace( Qtopia::AddressUid , QString::number( i ) );
01304 }
01305 }

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