-rw-r--r-- | kabc/addresseeview.cpp | 135 | ||||
-rw-r--r-- | kabc/addresseeview.h | 1 | ||||
-rw-r--r-- | kabc/phonenumber.cpp | 4 | ||||
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 6 |
4 files changed, 78 insertions, 68 deletions
diff --git a/kabc/addresseeview.cpp b/kabc/addresseeview.cpp index 2dda968..af149a0 100644 --- a/kabc/addresseeview.cpp +++ b/kabc/addresseeview.cpp @@ -81,43 +81,41 @@ void AddresseeView::setSource(const QString& n) else if ( n.left( 5 ) == "smsto" ) ExternalAppHandler::instance()->callBySMS( n.mid(6) ); else if ( n.left( 7 ) == "pagerto" ) ExternalAppHandler::instance()->callByPager( n.mid(8) ); else if ( n.left( 5 ) == "sipto" ) ExternalAppHandler::instance()->callBySIP( n.mid(6) ); } void AddresseeView::setAddressee( const KABC::Addressee& addr ) { ExternalAppHandler* eah = ExternalAppHandler::instance(); bool kemailAvail = eah->isEmailAppAvailable(); - bool kphoneAvail = eah->isPhoneAppAvailable(); - bool kfaxAvail = eah->isFaxAppAvailable(); - bool ksmsAvail = eah->isSMSAppAvailable(); - bool kpagerAvail = eah->isPagerAppAvailable(); - bool ksipAvail = eah->isSIPAppAvailable(); + mAddressee = addr; // clear view setText( QString::null ); if ( mAddressee.isEmpty() ) return; QString name = ( mAddressee.assembledName().isEmpty() ? mAddressee.formattedName() : mAddressee.assembledName() ); QString dynamicPart; + dynamicPart += getPhoneNumbers( true ); + qDebug("dynamic preferred %s ",dynamicPart.latin1() ); QStringList emails = mAddressee.emails(); QStringList::ConstIterator emailIt; QString type = i18n( "Email" ); emailIt = emails.begin(); if ( emailIt != emails.end() ) { if ( kemailAvail ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) .arg( type ) .arg( name ) .arg( *emailIt ) @@ -130,81 +128,25 @@ void AddresseeView::setAddressee( const KABC::Addressee& addr ) .arg( type ) .arg( *emailIt ); ++emailIt; } } if ( mAddressee.birthday().date().isValid() ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( i18n ("Birthday") ) .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); } - KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); - KABC::PhoneNumber::List::ConstIterator phoneIt; - QString extension; - int phonetype; - QString sms; - for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { - phonetype = (*phoneIt).type(); - if (ksmsAvail && - ( - ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || - ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) - ) - ) - { - sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) - .arg( (*phoneIt).number() ); - - } - else - sms = ""; - - extension = QString::null; - if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { - if (kfaxAvail) extension = "faxto:"; - } - else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { - if (kpagerAvail) extension = "pagerto:"; - } - else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) { - if (ksipAvail) extension = "sipto:"; - } - else if (kphoneAvail) { - extension = "phoneto:"; - } - else - extension = QString::null; - - if ( !extension.isEmpty() ) { - dynamicPart += QString( - "<tr><td align=\"right\"><b>%1</b></td>" - "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) - .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) - .arg( extension ) - .arg( (*phoneIt).number() ) - .arg( (*phoneIt).number() ) - .arg( sms ); - - } else { - dynamicPart += QString( - "<tr><td align=\"right\"><b>%1</b></td>" - "<td align=\"left\">%2 %3</td></tr>" ) - .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) - .arg( (*phoneIt).number() ) - .arg( sms ); - } - } - + dynamicPart += getPhoneNumbers( false ); for ( ; emailIt != emails.end(); ++emailIt ) { if ( kemailAvail ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) .arg( type ) .arg( name ) .arg( *emailIt ) .arg( *emailIt ); } else { dynamicPart += QString( @@ -361,24 +303,93 @@ mText = "<table width=\"100%\">\n"; .arg( mAddressee.organization()); mText += dynamicPart; mText += notes; mText += "</table>"; } // at last display it... setText( mText ); } +QString AddresseeView::getPhoneNumbers( bool preferred ) +{ + ExternalAppHandler* eah = ExternalAppHandler::instance(); + bool kphoneAvail = eah->isPhoneAppAvailable(); + bool kfaxAvail = eah->isFaxAppAvailable(); + bool ksmsAvail = eah->isSMSAppAvailable(); + bool kpagerAvail = eah->isPagerAppAvailable(); + bool ksipAvail = eah->isSIPAppAvailable(); + QString dynamicPart; + KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); + KABC::PhoneNumber::List::ConstIterator phoneIt; + QString extension; + int phonetype; + QString sms; + for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { + phonetype = (*phoneIt).type(); + if ( ((phonetype & KABC::PhoneNumber::Pref) == 0 ) == preferred ) + continue; + if (ksmsAvail && + ( + ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || + ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) + ) + ) + { + sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) + .arg( (*phoneIt).number() ); + + } + else + sms = ""; + + extension = QString::null; + if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { + if (kfaxAvail) extension = "faxto:"; + } + else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { + if (kpagerAvail) extension = "pagerto:"; + } + else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) { + if (ksipAvail) extension = "sipto:"; + } + else if (kphoneAvail) { + extension = "phoneto:"; + } + else + extension = QString::null; + + if ( !extension.isEmpty() ) { + dynamicPart += QString( + "<tr><td align=\"right\"><b>%1</b></td>" + "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) + .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) + .arg( extension ) + .arg( (*phoneIt).number() ) + .arg( (*phoneIt).number() ) + .arg( sms ); + + } else { + dynamicPart += QString( + "<tr><td align=\"right\"><b>%1</b></td>" + "<td align=\"left\">%2 %3</td></tr>" ) + .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) + .arg( (*phoneIt).number() ) + .arg( sms ); + } + } + return dynamicPart; +} KABC::Addressee AddresseeView::addressee() const { return mAddressee; } void AddresseeView::addTag(const QString & tag,const QString & text) { if ( text.isEmpty() ) return; int number=text.contains("\n"); QString str = "<" + tag + ">"; QString tmpText=text; QString tmpStr=str; diff --git a/kabc/addresseeview.h b/kabc/addresseeview.h index 689d997..d8a13ee 100644 --- a/kabc/addresseeview.h +++ b/kabc/addresseeview.h @@ -42,24 +42,25 @@ class AddresseeView : public QTextBrowser @param addr The addressee object. */ void setAddressee( const KABC::Addressee& addr ); void setSource(const QString& n); /** Returns the current addressee object. */ KABC::Addressee addressee() const; private: KABC::Addressee mAddressee; QString mText; + QString getPhoneNumbers( bool preferred ); void addTag(const QString & tag,const QString & text); class AddresseeViewPrivate; AddresseeViewPrivate *d; }; class AddresseeChooser : public KDialogBase { Q_OBJECT public: AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); int executeD( bool local ); diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index 6e94c7e..d7e3925 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp @@ -189,28 +189,28 @@ QString PhoneNumber::typeLabel( int type ) else if ((type & Isdn) == Isdn) typeString += i18n("ISDN"); else if ((type & Pcs) == Pcs) typeString += i18n("PCS"); else if ((type & Pager) == Pager) typeString += i18n("Pager"); else if ((type & Sip) == Sip) typeString += i18n("SIP"); // add the prefered flag if (!typeString.isEmpty()) typeString += " "; - + /* if ((type & Pref) == Pref) typeString += i18n("(p)"); - + */ //if we still have no match, return "other" if (typeString.isEmpty()) return i18n("Other"); return typeString; } QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) { return s << phone.mId << phone.mType << phone.mNumber; } diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index 78b9941..19bb676 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp @@ -206,24 +206,25 @@ KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() return retList; } void PhoneEditWidget::edit() { PhoneEditDialog dlg( mPhoneList, this ); if ( dlg.exec() ) { if ( dlg.changed() ) { mPhoneList = dlg.phoneNumbers(); updateCombos(); + updateLineEdits(); emit modified(); } } } void PhoneEditWidget::updatePrefEdit() { updateEdit( mPrefCombo ); } void PhoneEditWidget::updateSecondEdit() { @@ -280,28 +281,25 @@ void PhoneEditWidget::slotFourthEditChanged() { updatePhoneNumber( mFourthCombo ); } void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) { QLineEdit *edit = combo->lineEdit(); if ( !edit ) return; PhoneNumber::List::Iterator it = combo->selectedElement(); if ( it != mPhoneList.end() ) { (*it).setNumber( edit->text() ); - } else { - kdDebug(5720) << "PhoneEditWidget::updatePhoneNumber(): no selected element" - << endl; - } + } updateOtherEdit( combo, mPrefCombo ); updateOtherEdit( combo, mSecondCombo ); updateOtherEdit( combo, mThirdCombo ); updateOtherEdit( combo, mFourthCombo ); emit modified(); } void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) { if ( combo == otherCombo ) return; |