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

ocontact.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de)
00004 **
00005 ** This file may be distributed and/or modified under the terms of the
00006 ** GNU General Public License version 2 as published by the Free Software
00007 ** Foundation and appearing in the file LICENSE.GPL included in the
00008 ** packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00014 **
00015 ** Contact info@trolltech.com if any conditions of this licensing are
00016 ** not clear to you.
00017 **
00018 **********************************************************************/
00019 
00020 #define QTOPIA_INTERNAL_CONTACT_MRE
00021 
00022 #include "ocontact.h"
00023 #include "opimresolver.h"
00024 #include "oconversion.h"
00025 
00026 #include <qpe/stringutil.h>
00027 #include <qpe/timestring.h>
00028 #include <qpe/config.h>
00029 
00030 #include <qobject.h>
00031 #include <qregexp.h>
00032 #include <qstylesheet.h>
00033 #include <qfileinfo.h>
00034 #include <qmap.h>
00035 
00036 #include <stdio.h>
00037 
00053 OContact::OContact()
00054     : OPimRecord(), mMap(), d( 0 )
00055 {
00056 }
00057 
00063 OContact::OContact( const QMap<int, QString> &fromMap ) :
00064     OPimRecord(), mMap( fromMap ), d( 0 )
00065 {
00066     QString cats = mMap[ Qtopia::AddressCategory ];
00067     if ( !cats.isEmpty() )
00068         setCategories( idsFromString( cats ) );
00069 
00070     QString uidStr = find( Qtopia::AddressUid );
00071 
00072     if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
00073             qWarning( "Invalid UID found. Generate new one.." );
00074         setUid( uidGen().generate() );
00075     }else
00076         setUid( uidStr.toInt() );
00077 
00078 //     if ( !uidStr.isEmpty() )
00079 //      setUid( uidStr.toInt() );
00080 }
00081 
00085 OContact::~OContact()
00086 {
00087 }
00088 
00423 QMap<int, QString> OContact::toMap() const
00424 {
00425     QMap<int, QString> map = mMap;
00426     QString cats = idsToString( categories() );
00427     if ( !cats.isEmpty() )
00428         map.insert( Qtopia::AddressCategory, cats );
00429     return map;
00430 }
00431 
00435 QString OContact::toRichText() const
00436 {
00437     QString text;
00438     QString value, comp, state;
00439     QString str;
00440     bool marker = false;
00441 
00442     Config cfg("qpe");
00443     cfg.setGroup("Appearance");
00444     int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State );
00445 
00446     // name, jobtitle and company
00447     if ( !(value = fullName()).isEmpty() )
00448         text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString(value) + "</h3></b>";
00449     
00450     if ( !(value = jobTitle()).isEmpty() )
00451         text += Qtopia::escapeString(value) + " ";
00452 
00453     comp = company();
00454     if ( !(value = department()).isEmpty() ) {
00455         text += Qtopia::escapeString(value);
00456         if ( comp )
00457                 text += ", " + Qtopia::escapeString(comp);
00458     }else if ( comp )
00459             text += "<br>" + Qtopia::escapeString(comp);
00460     text += "<br><hr>";
00461 
00462     // defailt email
00463     QString defEmail = defaultEmail();
00464     if ( !defEmail.isEmpty() ){
00465         text += "<b><img src=\"addressbook/email\"> " + QObject::tr("Default Email: ") + "</b>"
00466                 + Qtopia::escapeString(defEmail);
00467         marker = true;
00468     }
00469 
00470     // business address
00471     if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
00472          !businessZip().isEmpty() || !businessCountry().isEmpty() ) {
00473         text += QObject::tr( "<br><b>Work Address:</b>" );
00474         marker = true;
00475     }
00476 
00477     if ( !(value = businessStreet()).isEmpty() ){
00478             text += "<br>" + Qtopia::escapeString(value);
00479             marker = true;
00480     }
00481 
00482     switch( addressformat ){
00483     case Zip_City_State:{ //  Zip_Code City, State
00484             state =  businessState();
00485             if ( !(value = businessZip()).isEmpty() ){
00486                     text += "<br>" + Qtopia::escapeString(value) + " ";
00487                     marker = true;
00488                     
00489             }
00490             if ( !(value = businessCity()).isEmpty() ) {
00491                     marker = true;
00492                     if ( businessZip().isEmpty() && !businessStreet().isEmpty() )
00493                             text += "<br>";
00494                     text += Qtopia::escapeString(value);
00495                     if ( state )
00496                             text += ", " + Qtopia::escapeString(state);
00497             } else if ( !state.isEmpty() ){
00498                     text += "<br>" + Qtopia::escapeString(state);
00499                     marker = true;
00500             }
00501             break;
00502     }
00503     case City_State_Zip:{ // City, State Zip_Code 
00504             state =  businessState();
00505             if ( !(value = businessCity()).isEmpty() ) {
00506                     marker = true;
00507                     text += "<br>" + Qtopia::escapeString(value);
00508                     if ( state )
00509                             text += ", " + Qtopia::escapeString(state);
00510             } else if ( !state.isEmpty() ){
00511                     text += "<br>" + Qtopia::escapeString(state);
00512                     marker = true;
00513             }
00514             if ( !(value = businessZip()).isEmpty() ){
00515                     text += " " + Qtopia::escapeString(value);
00516                     marker = true;
00517             }
00518             break;
00519     }
00520     }
00521 
00522     if ( !(value = businessCountry()).isEmpty() ){
00523         text += "<br>" + Qtopia::escapeString(value);
00524         marker = true;
00525     }
00526 
00527     // rest of Business data
00528     str = office();
00529     if ( !str.isEmpty() ){
00530         text += "<br><b>" + QObject::tr("Office: ") + "</b>"
00531                 + Qtopia::escapeString(str);
00532         marker = true;
00533     }
00534     str = businessWebpage();
00535     if ( !str.isEmpty() ){
00536         text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr("Business Web Page: ") + "</b>"
00537                 + Qtopia::escapeString(str);
00538         marker = true;
00539     }
00540     str = businessPhone();
00541     if ( !str.isEmpty() ){
00542         text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr("Business Phone: ") + "</b>"
00543                 + Qtopia::escapeString(str);
00544         marker = true;
00545     }
00546     str = businessFax();
00547     if ( !str.isEmpty() ){
00548         text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr("Business Fax: ") + "</b>"
00549                 + Qtopia::escapeString(str);
00550         marker = true;
00551     }
00552     str = businessMobile();
00553     if ( !str.isEmpty() ){
00554         text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr("Business Mobile: ") + "</b>"
00555                 + Qtopia::escapeString(str);
00556         marker = true;
00557     }
00558     str = businessPager();
00559     if ( !str.isEmpty() ){
00560         text += "<br><b>" + QObject::tr("Business Pager: ") + "</b>"
00561                 + Qtopia::escapeString(str);
00562         marker = true;
00563     }
00564 
00565     // text += "<br>";
00566 
00567     // home address
00568     if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
00569          !homeZip().isEmpty() || !homeCountry().isEmpty() ) {
00570         text += QObject::tr( "<br><b>Home Address:</b>" );
00571         marker = true;
00572     }
00573 
00574     if ( !(value = homeStreet()).isEmpty() ){
00575         text += "<br>" + Qtopia::escapeString(value);
00576         marker = true;
00577     }
00578 
00579     switch( addressformat ){
00580     case Zip_City_State:{ //  Zip_Code City, State
00581             state =  homeState();
00582             if ( !(value = homeZip()).isEmpty() ){
00583                     text += "<br>" + Qtopia::escapeString(value) + " ";
00584                     marker = true;
00585             }
00586             if ( !(value = homeCity()).isEmpty() ) {
00587                     marker = true;
00588                     if ( homeZip().isEmpty() && !homeStreet().isEmpty() )
00589                             text += "<br>";
00590                     text += Qtopia::escapeString(value);
00591                     if ( !state.isEmpty() )
00592                             text += ", " + Qtopia::escapeString(state);
00593             } else if (!state.isEmpty()) {
00594                     text += "<br>" + Qtopia::escapeString(state);
00595                     marker = true;
00596             }
00597             break;
00598     }
00599     case City_State_Zip:{ // City, State Zip_Code 
00600             state =  homeState();
00601             if ( !(value = homeCity()).isEmpty() ) {
00602                     marker = true;
00603                     text += "<br>" + Qtopia::escapeString(value);
00604                     if ( state )
00605                             text += ", " + Qtopia::escapeString(state);
00606             } else if ( !state.isEmpty() ){
00607                     text += "<br>" + Qtopia::escapeString(state);
00608                     marker = true;
00609             }
00610             if ( !(value = homeZip()).isEmpty() ){
00611                     text += " " + Qtopia::escapeString(value);
00612                     marker = true;
00613             }
00614             break;
00615     }
00616     }
00617             
00618     if ( !(value = homeCountry()).isEmpty() ){
00619         text += "<br>" + Qtopia::escapeString(value);
00620         marker = true;
00621     }
00622 
00623     // rest of Home data
00624     str = homeWebpage();
00625     if ( !str.isEmpty() ){
00626         text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr("Home Web Page: ") + "</b>"
00627                 + Qtopia::escapeString(str);
00628         marker = true;
00629     }
00630     str = homePhone();
00631     if ( !str.isEmpty() ){
00632         text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr("Home Phone: ") + "</b>"
00633                 + Qtopia::escapeString(str);
00634         marker = true;
00635     }
00636     str = homeFax();
00637     if ( !str.isEmpty() ){
00638         text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr("Home Fax: ") + "</b>"
00639                 + Qtopia::escapeString(str);
00640         marker = true;
00641     }
00642     str = homeMobile();
00643     if ( !str.isEmpty() ){
00644         text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr("Home Mobile: ") + "</b>"
00645                 + Qtopia::escapeString(str);
00646         marker = true;
00647     }
00648 
00649     if ( marker )
00650             text += "<br><hr>";
00651 
00652     // the rest...
00653     str = emails();
00654     if ( !str.isEmpty() && ( str != defEmail ) )
00655         text += "<br><b>" + QObject::tr("All Emails: ") + "</b>"
00656                 + Qtopia::escapeString(str);
00657     str = profession();
00658     if ( !str.isEmpty() )
00659         text += "<br><b>" + QObject::tr("Profession: ") + "</b>"
00660                 + Qtopia::escapeString(str);
00661     str = assistant();
00662     if ( !str.isEmpty() )
00663         text += "<br><b>" + QObject::tr("Assistant: ") + "</b>"
00664                 + Qtopia::escapeString(str);
00665     str = manager();
00666     if ( !str.isEmpty() )
00667         text += "<br><b>" + QObject::tr("Manager: ") + "</b>"
00668                 + Qtopia::escapeString(str);
00669     str = gender();
00670     if ( !str.isEmpty() && str.toInt() != 0 ) {
00671             text += "<br>";
00672             if ( str.toInt() == 1 )
00673                     str = QObject::tr( "Male" );
00674             else if ( str.toInt() == 2 )
00675                     str = QObject::tr( "Female" );
00676             text += "<b>" + QObject::tr("Gender: ") + "</b>" + str;
00677     }
00678     str = spouse();
00679     if ( !str.isEmpty() )
00680         text += "<br><b>" + QObject::tr("Spouse: ") + "</b>"
00681                 + Qtopia::escapeString(str);
00682     if ( birthday().isValid() ){
00683             str = TimeString::numberDateString( birthday() );
00684             text += "<br><b>" + QObject::tr("Birthday: ") + "</b>"
00685                     + Qtopia::escapeString(str);
00686     }
00687     if ( anniversary().isValid() ){
00688             str = TimeString::numberDateString( anniversary() );
00689             text += "<br><b>" + QObject::tr("Anniversary: ") + "</b>"
00690                     + Qtopia::escapeString(str);
00691     }
00692     str = children();
00693     if ( !str.isEmpty() )
00694         text += "<br><b>" + QObject::tr("Children: ") + "</b>"
00695                 + Qtopia::escapeString(str);
00696 
00697     str = nickname();
00698     if ( !str.isEmpty() )
00699         text += "<br><b>" + QObject::tr("Nickname: ") + "</b>"
00700                 + Qtopia::escapeString(str);
00701 
00702     // categories
00703     if ( categoryNames("Contacts").count() ){
00704             text += "<br><b>" + QObject::tr( "Category:") + "</b> ";
00705             text += categoryNames("Contacts").join(", ");
00706     }
00707 
00708     // notes last
00709     if ( !(value = notes()).isEmpty() ) {
00710             text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> ";
00711             QRegExp reg("\n");
00712 
00713             //QString tmp = Qtopia::escapeString(value);
00714             QString tmp = QStyleSheet::convertFromPlainText(value);
00715             //tmp.replace( reg, "<br>" );
00716             text += "<br>" + tmp + "<br>";
00717     }
00718     return text;
00719 }
00720 
00724 void OContact::insert( int key, const QString &v )
00725 {
00726     QString value = v.stripWhiteSpace();
00727     if ( value.isEmpty() )
00728         mMap.remove( key );
00729     else
00730         mMap.insert( key, value );
00731 }
00732 
00736 void OContact::replace( int key, const QString & v )
00737 {
00738     QString value = v.stripWhiteSpace();
00739     if ( value.isEmpty() )
00740         mMap.remove( key );
00741     else
00742         mMap.replace( key, value );
00743 }
00744 
00748 QString OContact::find( int key ) const
00749 {
00750     return mMap[key];
00751 }
00752 
00756 QString OContact::displayAddress( const QString &street,
00757                                  const QString &city,
00758                                  const QString &state,
00759                                  const QString &zip,
00760                                  const QString &country ) const
00761 {
00762     QString s = street;
00763     if ( !street.isEmpty() )
00764         s+= "\n";
00765     s += city;
00766     if ( !city.isEmpty() && !state.isEmpty() )
00767         s += ", ";
00768     s += state;
00769     if ( !state.isEmpty() && !zip.isEmpty() )
00770         s += "  ";
00771     s += zip;
00772     if ( !country.isEmpty() && !s.isEmpty() )
00773         s += "\n";
00774     s += country;
00775     return s;
00776 }
00777 
00781 QString OContact::displayBusinessAddress() const
00782 {
00783     return displayAddress( businessStreet(), businessCity(),
00784                            businessState(), businessZip(),
00785                            businessCountry() );
00786 }
00787 
00791 QString OContact::displayHomeAddress() const
00792 {
00793     return displayAddress( homeStreet(), homeCity(),
00794                            homeState(), homeZip(),
00795                            homeCountry() );
00796 }
00797 
00801 QString OContact::fullName() const
00802 {
00803     QString title = find( Qtopia::Title );
00804     QString firstName = find( Qtopia::FirstName );
00805     QString middleName = find( Qtopia::MiddleName );
00806     QString lastName = find( Qtopia::LastName );
00807     QString suffix = find( Qtopia::Suffix );
00808 
00809     QString name = title;
00810     if ( !firstName.isEmpty() ) {
00811         if ( !name.isEmpty() )
00812             name += " ";
00813         name += firstName;
00814     }
00815     if ( !middleName.isEmpty() ) {
00816         if ( !name.isEmpty() )
00817             name += " ";
00818         name += middleName;
00819     }
00820     if ( !lastName.isEmpty() ) {
00821         if ( !name.isEmpty() )
00822             name += " ";
00823         name += lastName;
00824     }
00825     if ( !suffix.isEmpty() ) {
00826         if ( !name.isEmpty() )
00827             name += " ";
00828         name += suffix;
00829     }
00830     return name.simplifyWhiteSpace();
00831 }
00832 
00836 QStringList OContact::childrenList() const
00837 {
00838     return QStringList::split( " ", find( Qtopia::Children ) );
00839 }
00840 
00868 QStringList OContact::emailList() const
00869 {
00870     QString emailStr = emails();
00871 
00872     QStringList r;
00873     if ( !emailStr.isEmpty() ) {
00874         qDebug(" emailstr ");
00875         QStringList l = QStringList::split( emailSeparator(), emailStr );
00876         for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
00877             r += (*it).simplifyWhiteSpace();
00878     }
00879 
00880     return r;
00881 }
00882 
00889 void OContact::setFileAs()
00890 {
00891     QString lastName, firstName, middleName, fileas;
00892 
00893     lastName = find( Qtopia::LastName );
00894     firstName = find( Qtopia::FirstName );
00895     middleName = find( Qtopia::MiddleName );
00896     if ( !lastName.isEmpty() && !firstName.isEmpty()
00897          && !middleName.isEmpty() )
00898         fileas = lastName + ", " + firstName + " " + middleName;
00899     else if ( !lastName.isEmpty() && !firstName.isEmpty() )
00900         fileas = lastName + ", " + firstName;
00901     else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
00902               !middleName.isEmpty() )
00903         fileas = firstName + ( firstName.isEmpty() ? "" : " " )
00904                  + middleName + ( middleName.isEmpty() ? "" : " " )
00905                  + lastName;
00906 
00907     replace( Qtopia::FileAs, fileas );
00908 }
00909 
00914 void OContact::save( QString &buf ) const
00915 {
00916     static const QStringList SLFIELDS = fields();
00917     // I'm expecting "<Contact " in front of this...
00918     for ( QMap<int, QString>::ConstIterator it = mMap.begin();
00919           it != mMap.end(); ++it ) {
00920         const QString &value = it.data();
00921         int key = it.key();
00922         if ( !value.isEmpty() ) {
00923             if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
00924                 continue;
00925 
00926             key -= Qtopia::AddressCategory+1;
00927             buf += SLFIELDS[key];
00928             buf += "=\"" + Qtopia::escapeString(value) + "\" ";
00929         }
00930     }
00931     buf += customToXml();
00932     if ( categories().count() > 0 )
00933         buf += "Categories=\"" + idsToString( categories() ) + "\" ";
00934     buf += "Uid=\"" + QString::number( uid() ) + "\" ";
00935     // You need to close this yourself
00936 }
00937 
00938 
00945 QStringList OContact::fields()
00946 {
00947     QStringList list;
00948 
00949     list.append( "Title" );  // Not Used!
00950     list.append( "FirstName" );
00951     list.append( "MiddleName" );
00952     list.append( "LastName" );
00953     list.append( "Suffix" );
00954     list.append( "FileAs" );
00955 
00956     list.append( "JobTitle" );
00957     list.append( "Department" );
00958     list.append( "Company" );
00959     list.append( "BusinessPhone" );
00960     list.append( "BusinessFax" );
00961     list.append( "BusinessMobile" );
00962 
00963     list.append( "DefaultEmail" );
00964     list.append( "Emails" );
00965 
00966     list.append( "HomePhone" );
00967     list.append( "HomeFax" );
00968     list.append( "HomeMobile" );
00969 
00970     list.append( "BusinessStreet" );
00971     list.append( "BusinessCity" );
00972     list.append( "BusinessState" );
00973     list.append( "BusinessZip" );
00974     list.append( "BusinessCountry" );
00975     list.append( "BusinessPager" );
00976     list.append( "BusinessWebPage" );
00977 
00978     list.append( "Office" );
00979     list.append( "Profession" );
00980     list.append( "Assistant" );
00981     list.append( "Manager" );
00982 
00983     list.append( "HomeStreet" );
00984     list.append( "HomeCity" );
00985     list.append( "HomeState" );
00986     list.append( "HomeZip" );
00987     list.append( "HomeCountry" );
00988     list.append( "HomeWebPage" );
00989 
00990     list.append( "Spouse" );
00991     list.append( "Gender" );
00992     list.append( "Birthday" );
00993     list.append( "Anniversary" );
00994     list.append( "Nickname" );
00995     list.append( "Children" );
00996 
00997     list.append( "Notes" );
00998     list.append( "Groups" );
00999 
01000     return list;
01001 }
01002 
01003 
01008 void OContact::setEmails( const QString &str )
01009 {
01010     replace( Qtopia::Emails, str );
01011     if ( str.isEmpty() )
01012         setDefaultEmail( QString::null );
01013 }
01014 
01018 void OContact::setChildren( const QString &str )
01019 {
01020     replace( Qtopia::Children, str );
01021 }
01022 
01028 bool OContact::match( const QRegExp &r ) const
01029 {
01030     setLastHitField( -1 );
01031     bool match;
01032     match = false;
01033     QMap<int, QString>::ConstIterator it;
01034     for ( it = mMap.begin(); it != mMap.end(); ++it ) {
01035         if ( (*it).find( r ) > -1 ) {
01036             setLastHitField( it.key() );
01037             match = true;
01038             break;
01039         }
01040     }
01041     return match;
01042 }
01043 
01044 
01045 QString OContact::toShortText() const
01046 {
01047         return ( fullName() );
01048 }
01049 QString OContact::type() const
01050 {
01051         return QString::fromLatin1( "OContact" );
01052 }
01053 
01054 
01055 
01056 class QString OContact::recordField( int pos ) const
01057 {
01058         QStringList SLFIELDS = fields(); // ?? why this ? (se)
01059         return SLFIELDS[pos];
01060 }
01061 
01062 // In future releases, we should store birthday and anniversary
01063 // internally as QDate instead of QString !
01064 // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
01065 
01070 void OContact::setBirthday( const QDate &v )
01071 {
01072         if ( v.isNull() ){
01073                 qWarning( "Remove Birthday");
01074                 replace( Qtopia::Birthday, QString::null );
01075                 return;
01076         }
01077 
01078         if ( v.isValid() )
01079                 replace( Qtopia::Birthday, OConversion::dateToString( v ) );
01080 
01081 }
01082 
01083 
01088 void OContact::setAnniversary( const QDate &v )
01089 {
01090         if ( v.isNull() ){
01091                 qWarning( "Remove Anniversary");
01092                 replace( Qtopia::Anniversary, QString::null );
01093                 return;
01094         }
01095 
01096         if ( v.isValid() )
01097                 replace( Qtopia::Anniversary, OConversion::dateToString( v ) );
01098 }
01099 
01103 QDate OContact::birthday() const
01104 {
01105         QString str = find( Qtopia::Birthday );
01106         // qWarning ("Birthday %s", str.latin1() );
01107         if ( !str.isEmpty() )
01108                 return  OConversion::dateFromString ( str );
01109         else
01110                 return QDate();
01111 }
01112 
01113 
01117 QDate OContact::anniversary() const
01118 {
01119         QDate empty;
01120         QString str = find( Qtopia::Anniversary );
01121         // qWarning ("Anniversary %s", str.latin1() );
01122         if ( !str.isEmpty() )
01123                 return OConversion::dateFromString ( str );
01124         else
01125                 return empty;
01126 }
01127 
01128 
01129 void OContact::insertEmail( const QString &v )
01130 {
01131     //qDebug("insertEmail %s", v.latin1());
01132     QString e = v.simplifyWhiteSpace();
01133     QString def = defaultEmail();
01134 
01135     // if no default, set it as the default email and don't insert
01136     if ( def.isEmpty() ) {
01137         setDefaultEmail( e ); // will insert into the list for us
01138         return;
01139     }
01140 
01141     // otherwise, insert assuming doesn't already exist
01142     QString emailsStr = find( Qtopia::Emails );
01143     if ( emailsStr.contains( e ))
01144         return;
01145     if ( !emailsStr.isEmpty() )
01146         emailsStr += emailSeparator();
01147     emailsStr += e;
01148     replace( Qtopia::Emails, emailsStr );
01149 }
01150 
01151 void OContact::removeEmail( const QString &v )
01152 {
01153     QString e = v.simplifyWhiteSpace();
01154     QString def = defaultEmail();
01155     QString emailsStr = find( Qtopia::Emails );
01156     QStringList emails = emailList();
01157 
01158     // otherwise, must first contain it
01159     if ( !emailsStr.contains( e ) )
01160         return;
01161 
01162     // remove it
01163     //qDebug(" removing email from list %s", e.latin1());
01164     emails.remove( e );
01165     // reset the string
01166     emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
01167     replace( Qtopia::Emails, emailsStr );
01168 
01169     // if default, then replace the default email with the first one
01170     if ( def == e ) {
01171         //qDebug("removeEmail is default; setting new default");
01172         if ( !emails.count() )
01173             clearEmails();
01174         else // setDefaultEmail will remove e from the list
01175             setDefaultEmail( emails.first() );
01176     }
01177 }
01178 void OContact::clearEmails()
01179 {
01180     mMap.remove( Qtopia::DefaultEmail );
01181     mMap.remove( Qtopia::Emails );
01182 }
01183 void OContact::setDefaultEmail( const QString &v )
01184 {
01185     QString e = v.simplifyWhiteSpace();
01186 
01187     //qDebug("OContact::setDefaultEmail %s", e.latin1());
01188     replace( Qtopia::DefaultEmail, e );
01189 
01190     if ( !e.isEmpty() )
01191         insertEmail( e );
01192 
01193 }
01194 
01195 void OContact::insertEmails( const QStringList &v )
01196 {
01197     for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
01198         insertEmail( *it );
01199 }
01200 int OContact::rtti() {
01201     return OPimResolver::AddressBook;
01202 }
01203 void OContact::setUid( int i )
01204 {
01205         OPimRecord::setUid(i);
01206         replace( Qtopia::AddressUid , QString::number(i));
01207 }

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