author | eilers <eilers> | 2003-08-01 12:30:16 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-01 12:30:16 (UTC) |
commit | 6c715b67a8f0e32a4edca5be91332622834c8d91 (patch) (side-by-side diff) | |
tree | ae2d660e1fd9c990c2d725c075ce6c42480b0af8 /libopie2/opiepim/ocontact.cpp | |
parent | cb45aa10043fdd6fddcab42ef0e07ddafc3d506d (diff) | |
download | opie-6c715b67a8f0e32a4edca5be91332622834c8d91.zip opie-6c715b67a8f0e32a4edca5be91332622834c8d91.tar.gz opie-6c715b67a8f0e32a4edca5be91332622834c8d91.tar.bz2 |
Merging changes from BRANCH_1_0 to HEAD
Diffstat (limited to 'libopie2/opiepim/ocontact.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 253 |
1 files changed, 163 insertions, 90 deletions
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index be4ce0a..3473baa 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp @@ -1,123 +1,124 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_CONTACT_MRE #include "ocontact.h" #include "opimresolver.h" +#include "oconversion.h" #include <qpe/stringutil.h> -#include "oconversion.h" #include <qpe/timestring.h> +#include <qpe/config.h> #include <qobject.h> #include <qregexp.h> #include <qstylesheet.h> #include <qfileinfo.h> #include <qmap.h> #include <stdio.h> /*! \class Contact contact.h \brief The Contact class holds the data of an address book entry. This data includes information the name of the person, contact information, and business information such as deparment and job title. \ingroup qtopiaemb \ingroup qtopiadesktop */ /*! Creates a new, empty contact. */ OContact::OContact() : OPimRecord(), mMap(), d( 0 ) { } /*! \internal Creates a new contact. The properties of the contact are set from \a fromMap. */ OContact::OContact( const QMap<int, QString> &fromMap ) : OPimRecord(), mMap( fromMap ), d( 0 ) { QString cats = mMap[ Qtopia::AddressCategory ]; if ( !cats.isEmpty() ) setCategories( idsFromString( cats ) ); QString uidStr = find( Qtopia::AddressUid ); if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ qWarning( "Invalid UID found. Generate new one.." ); setUid( uidGen().generate() ); }else setUid( uidStr.toInt() ); // if ( !uidStr.isEmpty() ) // setUid( uidStr.toInt() ); } /*! Destroys a contact. */ OContact::~OContact() { } /*! \fn void OContact::setTitle( const QString &str ) Sets the title of the contact to \a str. */ /*! \fn void OContact::setFirstName( const QString &str ) Sets the first name of the contact to \a str. */ /*! \fn void OContact::setMiddleName( const QString &str ) Sets the middle name of the contact to \a str. */ /*! \fn void OContact::setLastName( const QString &str ) Sets the last name of the contact to \a str. */ /*! \fn void OContact::setSuffix( const QString &str ) Sets the suffix of the contact to \a str. */ /*! \fn void OContact::setFileAs( const QString &str ) Sets the contact to filed as \a str. */ /*! \fn void OContact::setDefaultEmail( const QString &str ) Sets the default email of the contact to \a str. */ /*! \fn void OContact::setHomeStreet( const QString &str ) Sets the home street address of the contact to \a str. */ /*! \fn void OContact::setHomeCity( const QString &str ) Sets the home city of the contact to \a str. */ @@ -345,388 +346,460 @@ OContact::~OContact() /*! \fn QString OContact::businessZip() const Returns the business zip of the contact. */ /*! \fn QString OContact::businessCountry() const Returns the business country of the contact. */ /*! \fn QString OContact::businessPhone() const Returns the business phone number of the contact. */ /*! \fn QString OContact::businessFax() const Returns the business fax number of the contact. */ /*! \fn QString OContact::businessMobile() const Returns the business mobile number of the contact. */ /*! \fn QString OContact::businessPager() const Returns the business pager number of the contact. */ /*! \fn QString OContact::businessWebpage() const Returns the business webpage of the contact. */ /*! \fn QString OContact::spouse() const Returns the spouse of the contact. */ /*! \fn QString OContact::gender() const Returns the gender of the contact. */ /*! \fn QString OContact::nickname() const Returns the nickname of the contact. */ /*! \fn QString OContact::children() const Returns the children of the contact. */ /*! \fn QString OContact::notes() const Returns the notes relating to the the contact. */ /*! \fn QString OContact::groups() const \internal Returns the groups for the contact. */ /*! \fn QStringList OContact::groupList() const \internal */ /*! \fn QString OContact::field(int) const \internal */ /*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) \internal */ /*! \fn void OContact::setUid( int id ) \internal Sets the uid for this record to \a id. */ /*! \enum OContact::journal_action \internal */ /*! \internal */ QMap<int, QString> OContact::toMap() const { QMap<int, QString> map = mMap; QString cats = idsToString( categories() ); if ( !cats.isEmpty() ) map.insert( Qtopia::AddressCategory, cats ); return map; } /*! Returns a rich text formatted QString representing the contents the contact. */ QString OContact::toRichText() const { QString text; QString value, comp, state; QString str; bool marker = false; + Config cfg("qpe"); + cfg.setGroup("Appearance"); + int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State ); + // name, jobtitle and company if ( !(value = fullName()).isEmpty() ) - text += "<b><h3><img src=\"addressbook/AddressBook\">" + Qtopia::escapeString(value) + "</h3></b>"; - + text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString(value) + "</h3></b>"; + if ( !(value = jobTitle()).isEmpty() ) - text += Qtopia::escapeString(value) + "<br>"; + text += Qtopia::escapeString(value); comp = company(); if ( !(value = department()).isEmpty() ) { text += Qtopia::escapeString(value); if ( comp ) text += ", "; else text += "<br>"; } if ( !comp.isEmpty() ) - text += Qtopia::escapeString(comp) + "<br>"; + text += Qtopia::escapeString(comp); - text += "<hr><br>"; + text += "<br><hr>"; // defailt email QString defEmail = defaultEmail(); - if ( !defEmail.isEmpty() ) - text += "<b><img src=\"addressbook/email\">" + QObject::tr("Default Email: ") + "</b>" - + Qtopia::escapeString(defEmail) + "<br>"; - - text += "<br>"; + if ( !defEmail.isEmpty() ){ + text += "<b><img src=\"addressbook/email\"> " + QObject::tr("Default Email: ") + "</b>" + + Qtopia::escapeString(defEmail); + marker = true; + } // business address if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || !businessZip().isEmpty() || !businessCountry().isEmpty() ) { - text += QObject::tr( "<b>Work Address:</b>" ); - text += "<br>"; + text += QObject::tr( "<br><br><b>Work Address:</b>" ); marker = true; } - if ( !(value = businessStreet()).isEmpty() ) - text += Qtopia::escapeString(value) + "<br>"; - state = businessState(); - if ( !(value = businessZip()).isEmpty() ) - text += Qtopia::escapeString(value) + " "; - if ( !(value = businessCity()).isEmpty() ) { - text += Qtopia::escapeString(value); - if ( state ) - text += ", " + Qtopia::escapeString(state); - text += "<br>"; - } else if ( !state.isEmpty() ) - text += Qtopia::escapeString(state) + "<br>"; + if ( !(value = businessStreet()).isEmpty() ){ + text += "<br>" + Qtopia::escapeString(value); + marker = true; + } + + switch( addressformat ){ + case Zip_City_State:{ // Zip_Code City, State + state = businessState(); + if ( !(value = businessZip()).isEmpty() ){ + text += "<br>" + Qtopia::escapeString(value) + " "; + marker = true; + + } else + text += "<br>"; + + if ( !(value = businessCity()).isEmpty() ) { + marker = true; + text += Qtopia::escapeString(value); + if ( state ) + text += ", " + Qtopia::escapeString(state); + } else if ( !state.isEmpty() ){ + text += "<br>" + Qtopia::escapeString(state); + marker = true; + } + break; + } + case City_State_Zip:{ // City, State Zip_Code + state = businessState(); + if ( !(value = businessCity()).isEmpty() ) { + marker = true; + text += "<br>" + Qtopia::escapeString(value); + if ( state ) + text += ", " + Qtopia::escapeString(state); + } else if ( !state.isEmpty() ){ + text += "<br>" + Qtopia::escapeString(state); + marker = true; + } + if ( !(value = businessZip()).isEmpty() ){ + text += " " + Qtopia::escapeString(value); + marker = true; + } + break; + } + } - if ( !(value = businessCountry()).isEmpty() ) - text += Qtopia::escapeString(value) + "<br>"; + if ( !(value = businessCountry()).isEmpty() ){ + text += "<br>" + Qtopia::escapeString(value); + marker = true; + } // rest of Business data str = office(); if ( !str.isEmpty() ){ - text += "<b>" + QObject::tr("Office: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Office: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = businessWebpage(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/webpagework\">" + QObject::tr("Business Web Page: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr("Business Web Page: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = businessPhone(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/phonework\">" + QObject::tr("Business Phone: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr("Business Phone: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = businessFax(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/faxwork\">" + QObject::tr("Business Fax: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr("Business Fax: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = businessMobile(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/mobilework\">" + QObject::tr("Business Mobile: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr("Business Mobile: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = businessPager(); if ( !str.isEmpty() ){ - text += "<b>" + QObject::tr("Business Pager: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Business Pager: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } text += "<br>"; // home address if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || !homeZip().isEmpty() || !homeCountry().isEmpty() ) { - text += QObject::tr( "<b>Home Address:</b>" ); - text += "<br>"; + text += QObject::tr( "<br><br><b>Home Address:</b>" ); + marker = true; } - if ( !(value = homeStreet()).isEmpty() ) - text += Qtopia::escapeString(value) + "<br>"; - state = homeState(); - if ( !(value = homeZip()).isEmpty() ) - text += Qtopia::escapeString(value) + " "; - if ( !(value = homeCity()).isEmpty() ) { - text += Qtopia::escapeString(value); - if ( !state.isEmpty() ) - text += ", " + Qtopia::escapeString(state); - text += "<br>"; - } else if (!state.isEmpty()) - text += Qtopia::escapeString(state) + "<br>"; - if ( !(value = homeCountry()).isEmpty() ) - text += Qtopia::escapeString(value) + "<br>"; + if ( !(value = homeStreet()).isEmpty() ){ + text += "<br>" + Qtopia::escapeString(value); + marker = true; + } + + switch( addressformat ){ + case Zip_City_State:{ // Zip_Code City, State + state = homeState(); + if ( !(value = homeZip()).isEmpty() ){ + text += "<br>" + Qtopia::escapeString(value) + " "; + marker = true; + } else + text += "<br>"; + + if ( !(value = homeCity()).isEmpty() ) { + marker = true; + text += Qtopia::escapeString(value); + if ( !state.isEmpty() ) + text += ", " + Qtopia::escapeString(state); + } else if (!state.isEmpty()) { + text += "<br>" + Qtopia::escapeString(state); + marker = true; + } + break; + } + case City_State_Zip:{ // City, State Zip_Code + state = homeState(); + if ( !(value = homeCity()).isEmpty() ) { + marker = true; + text += "<br>" + Qtopia::escapeString(value); + if ( state ) + text += ", " + Qtopia::escapeString(state); + } else if ( !state.isEmpty() ){ + text += "<br>" + Qtopia::escapeString(state); + marker = true; + } + if ( !(value = homeZip()).isEmpty() ){ + text += " " + Qtopia::escapeString(value); + marker = true; + } + break; + } + } + + if ( !(value = homeCountry()).isEmpty() ){ + text += "<br>" + Qtopia::escapeString(value); + marker = true; + } // rest of Home data str = homeWebpage(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/webpagehome\">" + QObject::tr("Home Web Page: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr("Home Web Page: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = homePhone(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/phonehome\">" + QObject::tr("Home Phone: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr("Home Phone: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = homeFax(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/faxhome\">" + QObject::tr("Home Fax: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr("Home Fax: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } str = homeMobile(); if ( !str.isEmpty() ){ - text += "<b><img src=\"addressbook/mobilehome\">" + QObject::tr("Home Mobile: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr("Home Mobile: ") + "</b>" + + Qtopia::escapeString(str); marker = true; } if ( marker ) - text += "<br><hr><br>"; - // the others... + text += "<br><hr>"; + + // the rest... str = emails(); if ( !str.isEmpty() && ( str != defEmail ) ) - text += "<b>" + QObject::tr("All Emails: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("All Emails: ") + "</b>" + + Qtopia::escapeString(str); str = profession(); if ( !str.isEmpty() ) - text += "<b>" + QObject::tr("Profession: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Profession: ") + "</b>" + + Qtopia::escapeString(str); str = assistant(); if ( !str.isEmpty() ) - text += "<b>" + QObject::tr("Assistant: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Assistant: ") + "</b>" + + Qtopia::escapeString(str); str = manager(); if ( !str.isEmpty() ) - text += "<b>" + QObject::tr("Manager: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Manager: ") + "</b>" + + Qtopia::escapeString(str); str = gender(); if ( !str.isEmpty() && str.toInt() != 0 ) { - if ( str.toInt() == 1 ) - str = QObject::tr( "Male" ); - else if ( str.toInt() == 2 ) - str = QObject::tr( "Female" ); - text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; + text += "<br>"; + if ( str.toInt() == 1 ) + str = QObject::tr( "Male" ); + else if ( str.toInt() == 2 ) + str = QObject::tr( "Female" ); + text += "<b>" + QObject::tr("Gender: ") + "</b>" + str; } str = spouse(); if ( !str.isEmpty() ) - text += "<b>" + QObject::tr("Spouse: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Spouse: ") + "</b>" + + Qtopia::escapeString(str); if ( birthday().isValid() ){ str = TimeString::numberDateString( birthday() ); - text += "<b>" + QObject::tr("Birthday: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Birthday: ") + "</b>" + + Qtopia::escapeString(str); } if ( anniversary().isValid() ){ str = TimeString::numberDateString( anniversary() ); - text += "<b>" + QObject::tr("Anniversary: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Anniversary: ") + "</b>" + + Qtopia::escapeString(str); } str = children(); if ( !str.isEmpty() ) - text += "<b>" + QObject::tr("Children: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Children: ") + "</b>" + + Qtopia::escapeString(str); str = nickname(); if ( !str.isEmpty() ) - text += "<b>" + QObject::tr("Nickname: ") + "</b>" - + Qtopia::escapeString(str) + "<br>"; + text += "<br><b>" + QObject::tr("Nickname: ") + "</b>" + + Qtopia::escapeString(str); // categories if ( categoryNames("Contacts").count() ){ - text += "<b>" + QObject::tr( "Category:") + "</b> "; + text += "<br><b>" + QObject::tr( "Category:") + "</b> "; text += categoryNames("Contacts").join(", "); - text += "<br>"; } // notes last if ( !(value = notes()).isEmpty() ) { text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; QRegExp reg("\n"); //QString tmp = Qtopia::escapeString(value); QString tmp = QStyleSheet::convertFromPlainText(value); //tmp.replace( reg, "<br>" ); text += "<br>" + tmp + "<br>"; } return text; } /*! \internal */ void OContact::insert( int key, const QString &v ) { QString value = v.stripWhiteSpace(); if ( value.isEmpty() ) mMap.remove( key ); else mMap.insert( key, value ); } /*! \internal */ void OContact::replace( int key, const QString & v ) { QString value = v.stripWhiteSpace(); if ( value.isEmpty() ) mMap.remove( key ); else mMap.replace( key, value ); } /*! \internal */ QString OContact::find( int key ) const { return mMap[key]; } /*! \internal */ QString OContact::displayAddress( const QString &street, const QString &city, const QString &state, const QString &zip, const QString &country ) const { QString s = street; if ( !street.isEmpty() ) s+= "\n"; s += city; if ( !city.isEmpty() && !state.isEmpty() ) s += ", "; s += state; if ( !state.isEmpty() && !zip.isEmpty() ) s += " "; s += zip; if ( !country.isEmpty() && !s.isEmpty() ) s += "\n"; s += country; return s; } /*! \internal */ QString OContact::displayBusinessAddress() const { return displayAddress( businessStreet(), businessCity(), businessState(), businessZip(), businessCountry() ); } /*! \internal */ QString OContact::displayHomeAddress() const { return displayAddress( homeStreet(), homeCity(), homeState(), homeZip(), homeCountry() ); } /*! Returns the full name of the contact */ QString OContact::fullName() const |