summaryrefslogtreecommitdiffabout
path: root/kaddressbook
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 /kaddressbook
parentf516a558e6d18982a54152b28ca3da78fe76e3fc (diff)
downloadkdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.zip
kdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.tar.gz
kdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.tar.bz2
kapi search fix
Diffstat (limited to 'kaddressbook') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp18
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp39
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp16
3 files changed, 68 insertions, 5 deletions
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
@@ -284,105 +284,123 @@ void KAddressBookCardView::readConfig(KConfig *config)
connect(mCardView, SIGNAL(executed(CardViewItem *)),
this, SLOT(addresseeExecuted(CardViewItem *)));
else
connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
this, SLOT(addresseeExecuted(CardViewItem *)));
#endif
connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
this, SLOT(addresseeExecuted(CardViewItem *)));
}
void KAddressBookCardView::writeConfig( KConfig *config )
{
config->writeEntry( "ItemWidth", mCardView->itemWidth() );
KAddressBookView::writeConfig( config );
}
void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
{
mCardView->clear();
if ( s.isEmpty() || s == "*" ) {
refresh();
return;
}
QRegExp re = getRegExp( s );
if (!re.isValid())
return;
mCardView->viewport()->setUpdatesEnabled( false );
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
if ( field ) {
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
continue;
#if QT_VERSION >= 0x030000
if (re.search(field->value( *it ).lower()) == 0)
#else
if (re.match(field->value( *it ).lower()) == 0)
#endif
new AddresseeCardViewItem(fields(), mShowEmptyFields,
addressBook(), *it, mCardView);
}
} 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);
+ 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 );
}
else
emit selected(QString::null);
}
QStringList KAddressBookCardView::selectedUids()
{
QStringList uidList;
CardViewItem *item;
AddresseeCardViewItem *aItem;
for (item = mCardView->firstItem(); item; item = item->nextItem())
{
if (item->isSelected())
{
#ifndef KAB_EMBEDDED
aItem = dynamic_cast<AddresseeCardViewItem*>(item);
#else //KAB_EMBEDDED
aItem = (AddresseeCardViewItem*)(item);
#endif //KAB_EMBEDDED
if (aItem)
uidList << aItem->addressee().uid();
}
}
return uidList;
}
void KAddressBookCardView::refresh(QString uid)
{
CardViewItem *item;
AddresseeCardViewItem *aItem;
if (uid.isNull())
{
// Rebuild the view
mCardView->viewport()->setUpdatesEnabled( false );
mCardView->clear();
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
@@ -105,116 +105,129 @@ void AddresseeIconView::itemDropped(QDropEvent *e,
emit addresseeDropped(e);
}
QDragObject *AddresseeIconView::dragObject()
{
emit startAddresseeDrag();
// We never want IconView to start the drag
return 0;
}
////////////////////////////////
// AddresseeIconViewItem (internal class)
#ifndef KAB_EMBEDDED
class AddresseeIconViewItem : public KIconViewItem
#else //KAB_EMBEDDED
class AddresseeIconViewItem : public QIconViewItem
#endif //KAB_EMBEDDED
{
public:
#ifndef KAB_EMBEDDED
AddresseeIconViewItem(const KABC::Field::List &fields,
KABC::AddressBook *doc, const KABC::Addressee &a,
QIconView *parent)
: KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
#else //KAB_EMBEDDED
AddresseeIconViewItem(const KABC::Field::List &fields,
KABC::AddressBook *doc, const KABC::Addressee &a,
QIconView *parent)
: QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
#endif //KAB_EMBEDDED
{
if ( mFields.isEmpty() ) {
mFields = KABC::Field::defaultFields();
}
refresh();
}
const KABC::Addressee &addressee() const { return mAddressee; }
void refresh()
{
// 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;
};
///////////////////////////////
// KAddressBookView
KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
QWidget *parent, const char *name)
: KAddressBookView( ab, parent, name )
{
// Init the GUI
QVBoxLayout *layout = new QVBoxLayout(viewWidget());
mIconView = new AddresseeIconView(viewWidget(), "mIconView");
layout->addWidget(mIconView);
// Connect up the signals
//US method executed is part of KIconView
//US connect(mIconView, SIGNAL(executed(QIconViewItem *)),
//US this, SLOT(addresseeExecuted(QIconViewItem *)));
connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
connect(mIconView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)),
this, SIGNAL(dropped(QDropEvent*)));
connect(mIconView, SIGNAL(startAddresseeDrag()),
this, SIGNAL(startDrag()));
}
KAddressBookIconView::~KAddressBookIconView()
{
}
void KAddressBookIconView::setFocusAV()
{
if ( mIconView )
mIconView->setFocus();
}
@@ -238,104 +251,120 @@ void KAddressBookIconView::readConfig(KConfig *config)
disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
//US method executed is part of KIconView. Use selectionChanged instead
/*US
if (KABPrefs::instance()->mHonorSingleClick)
connect(mIconView, SIGNAL(executed(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
else
connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
*/
connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
this, SLOT(addresseeExecuted(QIconViewItem *)));
}
void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
{
mIconView->clear();
mIconList.clear();
if ( s.isEmpty() || s == "*" ) {
refresh();
return;
}
QRegExp re = getRegExp( s );
if (!re.isValid())
return;
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
if ( field ) {
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
continue;
#if QT_VERSION >= 0x030000
if (re.search(field->value( *it ).lower()) == 0)
#else
if (re.match(field->value( *it ).lower()) == 0)
#endif
mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
}
} 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 );
}
else
emit selected(QString::null);
}
QStringList KAddressBookIconView::selectedUids()
{
QStringList uidList;
QIconViewItem *item;
AddresseeIconViewItem *aItem;
for (item = mIconView->firstItem(); item; item = item->nextItem())
{
if (item->isSelected())
{
#ifndef KAB_EMBEDDED
aItem = dynamic_cast<AddresseeIconViewItem*>(item);
#else //KAB_EMBEDDED
aItem = (AddresseeIconViewItem*)(item);
#endif //KAB_EMBEDDED
if (aItem)
uidList << aItem->addressee().uid();
}
}
return uidList;
}
void KAddressBookIconView::refresh(QString uid)
{
QIconViewItem *item;
AddresseeIconViewItem *aItem;
if ( uid.isNull() ) {
// Rebuild the view
mIconView->clear();
mIconList.clear();
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator iter;
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
@@ -125,105 +125,121 @@ void KAddressBookTableView::reconstructListView()
// qDebug("KAddressBookTableView::reconstructListView double");
connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
}
connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
connect(mListView, SIGNAL(signalDelete()),
this, SLOT(addresseeDeleted()));
//US performceimprovement. Refresh is done from the outside
//US refresh();
mListView->setSorting( 0, true );
mainLayout->addWidget( mListView );
mainLayout->activate();
mListView->show();
}
void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
{
mListView->clear();
if ( s.isEmpty() || s == "*" ) {
refresh();
return;
}
QRegExp re = getRegExp( s );
if (!re.isValid())
return;
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
if ( field ) {
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
continue;
#if QT_VERSION >= 0x030000
if (re.search(field->value( *it ).lower()) == 0)
#else
if (re.match(field->value( *it ).lower()) == 0)
#endif
ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
}
} 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 );
}
else
emit selected(QString::null);
}
void KAddressBookTableView::writeConfig(KConfig *config)
{
KAddressBookView::writeConfig(config);
mListView->saveLayout(config, config->group());
}
void KAddressBookTableView::readConfig(KConfig *config)
{
KAddressBookView::readConfig( config );
// The config could have changed the fields, so we need to reconstruct
// the listview.
reconstructListView();
// costum colors?
if ( config->readBoolEntry( "EnableCustomColors", false ) )
{
QPalette p( mListView->palette() );
QColor c = p.color(QPalette::Normal, QColorGroup::Base );
p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::Text );
p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::Button );
p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::ButtonText );
p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::Highlight );
p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
#ifndef KAB_EMBEDDED
c = KGlobalSettings::alternateBackgroundColor();