summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-08-22 15:42:41 (UTC)
committer zautrix <zautrix>2005-08-22 15:42:41 (UTC)
commit1d82d044bbdedd407f6d08305522187ffd256552 (patch) (side-by-side diff)
tree08f5651d72548b643ed012e5f6ad938b36d1ae3f
parentf516a558e6d18982a54152b28ca3da78fe76e3fc (diff)
downloadkdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.zip
kdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.tar.gz
kdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.tar.bz2
kapi search fix
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/address.cpp27
-rw-r--r--kabc/address.h2
-rw-r--r--kabc/addressee.cpp25
-rw-r--r--kabc/addressee.h4
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp18
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp39
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp16
7 files changed, 126 insertions, 5 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index 5ffe511..6151f9e 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -100,8 +100,35 @@ QStringList Address::asList()
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();
}
diff --git a/kabc/address.h b/kabc/address.h
index 37dd851..38ad20b 100644
--- a/kabc/address.h
+++ b/kabc/address.h
@@ -29,8 +29,9 @@ $Id$
#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
@@ -94,8 +95,9 @@ class 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;
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 155ce24..7e1e414 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -305,9 +305,34 @@ void Addressee::computeCsum(const QString &dev)
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
diff --git a/kabc/addressee.h b/kabc/addressee.h
index a2fbcf5..d1c07cb 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -30,8 +30,9 @@ $Id$
#define KABC_ADDRESSEE_H
#include <qdatetime.h>
#include <qstring.h>
+#include <qregexp.h>
#include <qstringlist.h>
#include <qvaluelist.h>
#include <ksharedptr.h>
@@ -649,8 +650,11 @@ class Addressee
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;
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
@@ -328,8 +328,9 @@ void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
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
@@ -337,8 +338,25 @@ void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
#endif
{
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;
}
}
}
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
@@ -149,9 +149,9 @@ class AddresseeIconViewItem : public QIconViewItem
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();
@@ -162,15 +162,28 @@ class AddresseeIconViewItem : public QIconViewItem
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:
@@ -282,16 +295,32 @@ void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
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;
}
}
}
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
@@ -169,8 +169,9 @@ void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
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
@@ -178,8 +179,23 @@ void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
#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;
}
}
}