📄 contact.cpp
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.**** 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 "contact.h"#include <qtopia/private/vobject_p.h>#include <qtopia/private/qfiledirect_p.h>#include <qtopia/stringutil.h>#include <qtopia/timeconversion.h>#include <qtopia/timestring.h>#include <qtopia/config.h>#include <qtopia/pim/private/xmlio_p.h>#include <qobject.h>#include <qapplication.h>#include <qregexp.h>#include <qstylesheet.h>#include <qfileinfo.h>#include <qtextcodec.h>#include <stdio.h>QString emailSeparator() { return " "; }static QMap<int, int> *uniquenessMapPtr = 0;static QMap<QCString, int> *identifierToKeyMapPtr = 0;static QMap<int, QCString> *keyToIdentifierMapPtr = 0;static QMap<int, QString> * trFieldsMapPtr = 0;/*! \class PimContact \module qpepim \ingroup qpepim \brief The PimContact 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.*//*! \enum PimContact::ContactFields \internal*//*! \fn QMap<int,QString> PimContact::fields() const \internal*//*! Constructs a new PimContact.*/PimContact::PimContact() : PimRecord(), mMap(), d( 0 ){}/*! \internal*/void PimContact::fromMap( const QMap<int,QString> &m){ setFields( m );}/*! Destroys the contact.*/PimContact::~PimContact(){}/*! Returns a rich text formatted QString of the PimContact.*/QString PimContact::toRichText() const{ if (!keyToIdentifierMapPtr) initMaps(); QString text; QString value, comp, state; // name, jobtitle and company if ( !(value = fullName()).isEmpty() ) text += "<b>" + Qtopia::escapeString(value) + "</b><br>"; // also part of name is how to pronounce it. if ( !(value = firstNamePronunciation()).isEmpty() ) text += "<b>( " + Qtopia::escapeString(value) + " )</br><br>"; if ( !(value = lastNamePronunciation()).isEmpty() ) text += "<b>( " + Qtopia::escapeString(value) + " )</br><br>"; if ( !(value = jobTitle()).isEmpty() ) text += Qtopia::escapeString(value) + "<br>"; comp = company(); if ( !(value = department()).isEmpty() ) { text += Qtopia::escapeString(value); if ( comp ) text += ", "; else text += "<br>"; } if ( !comp.isEmpty() ) text += Qtopia::escapeString(comp) + "<br>"; if ( !(value = companyPronunciation()).isEmpty() ) text += "<b>( " + Qtopia::escapeString(value) + " )</br><br>"; // business address if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || !businessZip().isEmpty() || !businessCountry().isEmpty() ) { text += "<br>"; text += "<b>" + qApp->translate( "QtopiaPim", "Work Address: " ) + "</b>"; text += "<br>"; } if ( !(value = businessStreet()).isEmpty() ) text += Qtopia::escapeString(value) + "<br>"; state = businessState(); 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 = businessZip()).isEmpty() ) text += Qtopia::escapeString(value) + "<br>"; if ( !(value = businessCountry()).isEmpty() ) text += Qtopia::escapeString(value) + "<br>"; // home address if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || !homeZip().isEmpty() || !homeCountry().isEmpty() ) { text += "<br>"; text += "<b>" + qApp->translate( "QtopiaPim", "Home Address: " ) + "</b>"; text += "<br>"; } if ( !(value = homeStreet()).isEmpty() ) text += Qtopia::escapeString(value) + "<br>"; state = homeState(); 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 = homeZip()).isEmpty() ) text += Qtopia::escapeString(value) + "<br>"; if ( !(value = homeCountry()).isEmpty() ) text += Qtopia::escapeString(value) + "<br>"; // the others... QString str; str = emailList().join(", "); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim", "Email Addresses: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = homePhone(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Home Phone: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = homeFax(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Home Fax: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = homeMobile(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Home Mobile: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = homeWebpage(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Home Web Page: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = businessWebpage(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Business Web Page: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = office(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Office: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = businessPhone(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Business Phone: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = businessFax(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Business Fax: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = businessMobile(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Business Mobile: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = businessPager(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Business Pager: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = profession(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Profession: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = assistant(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Assistant: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = manager(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Manager: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; str = gender(); if ( !str.isEmpty() && str.toInt() != 0 ) { if ( str.toInt() == 1 ) str = qApp->translate( "QtopiaPim", "Male" ); else if ( str.toInt() == 2 ) str = qApp->translate( "QtopiaPim", "Female" ); text += "<b>" + qApp->translate( "QtopiaPim","Gender: ") + "</b>" + str + "<br>"; } str = spouse(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Spouse: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; if ( birthday().isValid() ) { str = TimeString::localYMD( birthday() ); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Birthday: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; } if ( anniversary().isValid() ) { str = TimeString::localYMD( anniversary() ); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Anniversary: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; } str = nickname(); if ( !str.isEmpty() ) text += "<b>" + qApp->translate( "QtopiaPim","Nickname: ") + "</b>" + Qtopia::escapeString(str) + "<br>"; // notes last if ( (value = notes()) ) { QRegExp reg("\n"); QString tmp = QStyleSheet::convertFromPlainText(value); text += "<br>" + tmp + "<br>"; } return text;}/*! \internal*/void PimContact::insert( int key, const QString &v ){ QString value = v.stripWhiteSpace(); if ( value.isEmpty() ) mMap.remove( key ); else mMap.insert( key, value );}/*! \internal*/void PimContact::setField(int key,const QString &s){ if (key < CommonFieldsEnd || key >= CustomFieldsStart) { PimRecord::setField(key,s); } else if (key > ContactFieldsEnd) { qDebug("unkown field"); } else { QString fixedStr = s; // // Replace ';' and ',' with appropriate separator. // if ( key == Emails ){ if ( fixedStr.contains(";") ) fixedStr.replace(QRegExp(";"), emailSeparator() ); else if ( fixedStr.contains(",") ) fixedStr.replace(QRegExp(","), emailSeparator() ); } mMap[key] = fixedStr; }}/*! \internal*/QString PimContact::field(int key) const{ if (key < CommonFieldsEnd || key >= CustomFieldsStart) { return PimRecord::field(key); } else if (key > ContactFieldsEnd) { qDebug("unkown field"); return QString::null; } else { return mMap[key]; }}QMap<int, QString> PimContact::fields() const{ QMap<int, QString> m = PimRecord::fields(); if (!keyToIdentifierMapPtr) initMaps(); QMap<int, QCString>::Iterator it; for (it = keyToIdentifierMapPtr->begin(); it != keyToIdentifierMapPtr->end(); ++it) { int i = it.key(); QString str = field(i); if (!str.isEmpty()) m.insert(i, str); } return m;}/*! \internal*/void PimContact::replace( int key, const QString & v ){ QString value = v.stripWhiteSpace(); if ( value.isEmpty() ) mMap.remove( key ); else mMap.replace( key, value );}/*! \internal*/QString PimContact::find( int key ) const{ return mMap[key];}/*! \internal*/QString PimContact::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;}/*! Returns the formated business address of the contact.*/QString PimContact::displayBusinessAddress() const{ return displayAddress( businessStreet(), businessCity(), businessState(), businessZip(), businessCountry() );}/*! Returns the formated home address of the contact.*/QString PimContact::displayHomeAddress() const{ return displayAddress( homeStreet(), homeCity(), homeState(), homeZip(), homeCountry() );}/*! Sets the persons gender to the enum value specified in \a g.*/void PimContact::setGender( GenderType g ){ switch( g ) { case Male: replace( Gender, QString::number( 1 ) ); break; case Female: replace( Gender, QString::number( 2 ) ); break; case UnspecifiedGender: default: mMap.remove( Gender ); break; }}/*! \enum PimContact::GenderType This enum describes the three possible choices for gender. \value UnspecifiedGender
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -