-rw-r--r-- | kabc/address.cpp | 27 | ||||
-rw-r--r-- | kabc/address.h | 2 | ||||
-rw-r--r-- | kabc/addressee.cpp | 25 | ||||
-rw-r--r-- | kabc/addressee.h | 4 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 22 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.cpp | 39 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 16 |
7 files changed, 128 insertions, 7 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp index 5ffe511..6151f9e 100644 --- a/kabc/address.cpp +++ b/kabc/address.cpp @@ -96,16 +96,43 @@ QStringList Address::asList() if ( ! mStreet.isEmpty())result.append(mStreet); if ( ! mLocality.isEmpty() )result.append(mLocality); if ( ! mRegion.isEmpty())result.append(mRegion); if ( ! mPostalCode.isEmpty())result.append(mPostalCode); if ( ! mCountry.isEmpty())result.append(mCountry); if ( ! mLabel.isEmpty() )result.append(mLabel); return result; } + +bool Address::matchAddress( QRegExp* re ) const +{ + +#if QT_VERSION >= 0x030000 + if (re->search( mPostOfficeBox ) == 0) return true; + if (re->search( mExtended ) == 0) return true; + if (re->search( mStreet ) == 0) return true; + if (re->search( mLocality ) == 0) return true; + if (re->search( mRegion ) == 0) return true; + if (re->search( mPostalCode ) == 0) return true; + if (re->search( mCountry ) == 0) return true; + if (re->search( mLabel ) == 0) return true; +#else + if (re->match( mPostOfficeBox ) == 0) return true; + if (re->match( mExtended ) == 0) return true; + if (re->match( mStreet ) == 0) return true; + if (re->match( mLocality ) == 0) return true; + if (re->match( mRegion ) == 0) return true; + if (re->match( mPostalCode ) == 0) return true; + if (re->match( mCountry ) == 0) return true; + if (re->match( mLabel ) == 0) return true; +#endif + + return false; +} + void Address::clear() { *this = Address(); } void Address::setId( const QString &id ) { mEmpty = false; diff --git a/kabc/address.h b/kabc/address.h index 37dd851..38ad20b 100644 --- a/kabc/address.h +++ b/kabc/address.h @@ -25,16 +25,17 @@ Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_ADDRESS_H #define KABC_ADDRESS_H #include <qmap.h> #include <qstring.h> +#include <qregexp.h> #include <qstringlist.h> #include <qvaluelist.h> // template tags for address formatting localization #define KABC_FMTTAG_realname QString("%n") #define KABC_FMTTAG_REALNAME QString("%N") #define KABC_FMTTAG_company QString("%cm") #define KABC_FMTTAG_COMPANY QString("%CM") @@ -90,16 +91,17 @@ class Address */ Address(); /** This is like @ref Address() just above, with the difference that you can specify the type. */ Address( int ); + bool matchAddress( QRegExp* searchExp ) const; bool operator==( const Address & ) const; bool operator!=( const Address & ) const; /** Returns true, if the address is empty. */ bool isEmpty() const; diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 155ce24..7e1e414 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -301,17 +301,42 @@ void Addressee::computeCsum(const QString &dev) for ( iii = 0; iii < l.count(); ++iii) qDebug("%d***%s***",iii,l[iii].latin1()); qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); #endif setCsum( dev, QString::number (cs )); } +bool Addressee::matchAddress( QRegExp* re ) const +{ + KABC::Address::List::Iterator addressIter; + for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); + ++addressIter ) { + if ( (*addressIter).matchAddress( re ) ) + return true; + } + return false; +} +bool Addressee::matchPhoneNumber( QRegExp* re ) const +{ + KABC::PhoneNumber::List::Iterator phoneIter; + + for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) { +#if QT_VERSION >= 0x030000 + if (re->search( (*phoneIter).number() ) == 0) +#else + if (re->match( (*phoneIter).number() ) == 0) +#endif + return true; + } + return false; + +} void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) { // merge all standard non-outlook fields. //if isSubSet (e.g. mobile phone sync) merge all fields detach(); if ( isSubSet ) { if ( mData->name.isEmpty() ) mData->name = ad.mData->name; diff --git a/kabc/addressee.h b/kabc/addressee.h index a2fbcf5..d1c07cb 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -26,16 +26,17 @@ Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_ADDRESSEE_H #define KABC_ADDRESSEE_H #include <qdatetime.h> #include <qstring.h> +#include <qregexp.h> #include <qstringlist.h> #include <qvaluelist.h> #include <ksharedptr.h> #include <kurl.h> #include "address.h" #include "agent.h" @@ -645,16 +646,19 @@ class Addressee */ void removePhoneNumber( const PhoneNumber &phoneNumber ); /** Return phone number, which matches the given type. */ PhoneNumber phoneNumber( int type ) const; + bool matchPhoneNumber( QRegExp* searchExp ) const; + bool matchAddress( QRegExp* searchExp ) const; + /** Return list of all phone numbers. */ PhoneNumber::List phoneNumbers() const; /** Return list of phone numbers with a special type. */ diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index ca21016..b503652 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp @@ -324,28 +324,46 @@ void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) } } else { KABC::Field::List fieldList = allFields(); KABC::Field::List::ConstIterator fieldIt; for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) continue; + bool match = false; for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { #if QT_VERSION >= 0x030000 if (re.search((*fieldIt)->value( *it ).lower()) == 0) #else if (re.match((*fieldIt)->value( *it ).lower()) == 0) #endif { - new AddresseeCardViewItem(fields(), mShowEmptyFields, - addressBook(), *it, mCardView); + new AddresseeCardViewItem(fields(), mShowEmptyFields, + addressBook(), *it, mCardView); + match = true; break; } } + if ( ! match ) { + if ( (*it).matchPhoneNumber( &re ) ) { + new AddresseeCardViewItem(fields(), mShowEmptyFields, + addressBook(), *it, mCardView); + match = true; + break; + } + } + if ( ! match ) { + if ( (*it).matchAddress( &re ) ) { + new AddresseeCardViewItem(fields(), mShowEmptyFields, + addressBook(), *it, mCardView); + match = true; + break; + } + } } } mCardView->viewport()->setUpdatesEnabled( true ); mCardView->viewport()->update(); if ( mCardView->firstItem() ) { mCardView->setCurrentItem ( mCardView->firstItem() ); mCardView->setSelected ( mCardView->firstItem() , true ); } diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp index 4bbdf1d..d6ddec3 100644 --- a/kaddressbook/views/kaddressbookiconview.cpp +++ b/kaddressbook/views/kaddressbookiconview.cpp @@ -145,36 +145,49 @@ class AddresseeIconViewItem : public QIconViewItem { // Update our addressee, since it may have changed elsewhere mAddressee = mDocument->findByUid(mAddressee.uid()); if (!mAddressee.isEmpty()) setText( mAddressee.givenName() + " " + mAddressee.familyName() ); QPixmap icon; - QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) ); + KABC::Picture pic = mAddressee.photo(); if ( pic.data().isNull() ) pic = mAddressee.logo(); if ( pic.isIntern() && !pic.data().isNull() ) { QImage img = pic.data(); #ifndef KAB_EMBEDDED if ( img.width() > img.height() ) icon = img.scaleWidth( 32 ); else icon = img.scaleHeight( 32 ); #else //KAB_EMBEDDED + + int wid = pic.data().width(); + int hei = pic.data().height(); + int max = 48; + if ( wid > max || hei > max ) { + if ( wid > hei ) { + hei = (hei*max)/wid; + wid = max; + } else { + wid = (wid*max)/hei; + hei = max; + } + } qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor"); - icon.convertFromImage(img.smoothScale(32, 32)); + icon.convertFromImage(img.smoothScale(wid, hei)); #endif //KAB_EMBEDDED - } else - icon = defaultIcon; - + } else { + icon = KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ); + } setPixmap( icon ); } private: KABC::Field::List mFields; KABC::AddressBook *mDocument; KABC::Addressee mAddressee; }; @@ -278,26 +291,42 @@ void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) } } else { KABC::Field::List fieldList = allFields(); KABC::Field::List::ConstIterator fieldIt; for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) continue; + bool match = false; for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { #if QT_VERSION >= 0x030000 if (re.search((*fieldIt)->value( *it ).lower()) == 0) #else if (re.match((*fieldIt)->value( *it ).lower()) == 0) #endif { mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); + match = true; break; } + } + if ( ! match ) { + if ( (*it).matchPhoneNumber( &re ) ) { + mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); + match = true; + break; + } + } + if ( ! match ) { + if ( (*it).matchAddress( &re ) ) { + mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); + match = true; + break; + } } } } mIconView->arrangeItemsInGrid( true ); if ( mIconView->firstItem() ) { mIconView->setCurrentItem ( mIconView->firstItem() ); mIconView->setSelected ( mIconView->firstItem() , true ); } diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index 348f491..02fc40a 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp @@ -165,28 +165,44 @@ void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) } } else { KABC::Field::List fieldList = allFields(); KABC::Field::List::ConstIterator fieldIt; for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) continue; + bool match = false; for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { #if QT_VERSION >= 0x030000 if (re.search((*fieldIt)->value( *it ).lower()) == 0) #else if (re.match((*fieldIt)->value( *it ).lower()) == 0) #endif { //qDebug("match %s %s %s", pattern.latin1(), (*fieldIt)->value( *it ).latin1(), (*fieldIt)->label().latin1() ); ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); + match = true; break; } } + if ( ! match ) { + if ( (*it).matchPhoneNumber( &re ) ) { + ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); + match = true; + break; + } + } + if ( ! match ) { + if ( (*it).matchAddress( &re ) ) { + ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); + match = true; + break; + } + } } } // Sometimes the background pixmap gets messed up when we add lots // of items. //mListView->repaint(); if ( mListView->firstChild() ) { mListView->setCurrentItem ( mListView->firstChild() ); mListView->setSelected ( mListView->firstChild(), true ); |