summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-03 09:23:23 (UTC)
committer zautrix <zautrix>2004-09-03 09:23:23 (UTC)
commitd171ed3b09665db0f511310d6c84a23d75135f50 (patch) (side-by-side diff)
tree557b3fd423a022559971ceafa61def5adbb7e828
parentf6b72fd55671131cd81a3357940c9337ea5d7494 (diff)
downloadkdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.zip
kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.gz
kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.bz2
Much better search possibility in kapi
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/incsearchwidget.cpp7
-rw-r--r--kaddressbook/kabcore.cpp40
-rw-r--r--kaddressbook/viewmanager.cpp7
-rw-r--r--kaddressbook/viewmanager.h1
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp6
5 files changed, 47 insertions, 14 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp
index 94c37e7..2ffa357 100644
--- a/kaddressbook/incsearchwidget.cpp
+++ b/kaddressbook/incsearchwidget.cpp
@@ -22,102 +22,105 @@
*/
#include <qlabel.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qcombobox.h>
#include <kdialog.h>
#include <klineedit.h>
#include <klocale.h>
#include <kglobal.h>
#include "incsearchwidget.h"
IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
: QWidget( parent, name )
{
#ifndef KAB_EMBEDDED
//US setCaption( i18n( "Incremental Search" ) );
#endif //KAB_EMBEDDED
QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
#ifdef DESKTOP_VERSION
QLabel *label = new QLabel( i18n( "Search:" ), this );
label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
layout->addWidget( label );
#endif //KAB_EMBEDDED
mSearchText = new KLineEdit( this );
layout->addWidget( mSearchText );
// #ifdef KAB_EMBEDDED
// if (KGlobal::getOrientation() == KGlobal::Portrait)
// mSearchText->setMaximumWidth(30);
// #endif //KAB_EMBEDDED
mFieldCombo = new QComboBox( false, this );
layout->addWidget( mFieldCombo );
mFieldCombo->setMaximumHeight( 34 );
QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) );
// #ifndef KAB_EMBEDDED
// resize( QSize(420, 50).expandedTo( sizeHint() ) );
// #else //KAB_EMBEDDED
// resize( QSize(30, 10).expandedTo( sizeHint() ) );
// #endif //KAB_EMBEDDED
+#ifdef DESKTOP_VERSION
+ // for performance reasons, we do a search on the pda only after return is pressed
connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
SLOT( announceDoSearch() ) );
- connect( mSearchText, SIGNAL( returnPressed() ),
- SLOT( announceDoSearch() ) );
connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
SLOT( announceDoSearch() ) );
+#endif
+ connect( mSearchText, SIGNAL( returnPressed() ),
+ SLOT( announceDoSearch() ) );
connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
SLOT( announceFieldChanged() ) );
setFocusProxy( mSearchText );
}
IncSearchWidget::~IncSearchWidget()
{
}
void IncSearchWidget::announceDoSearch()
{
emit doSearch( mSearchText->text() );
}
void IncSearchWidget::announceFieldChanged()
{
emit fieldChanged();
}
void IncSearchWidget::setFields( const KABC::Field::List &list )
{
mFieldCombo->clear();
mFieldCombo->insertItem( i18n( "All Fields" ) );
QFontMetrics fm ( mFieldCombo->font() );
int wid = fm.width(i18n( "All Fields" ) );
int max = wid;
KABC::Field::List::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
mFieldCombo->insertItem( (*it)->label() );
// wid = fm.width((*it)->label() );
//if ( wid > max )
// max = wid;
}
mFieldList = list;
announceDoSearch();
announceFieldChanged();
mFieldCombo->setMaximumWidth( wid+60 );
}
KABC::Field::List IncSearchWidget::fields() const
{
return mFieldList;
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index f0f08f4..4299ebd 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -788,123 +788,145 @@ void KABCore::setCategories()
{
KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
if ( !dlg.exec() )
return;
bool merge = false;
QString msg = i18n( "Merge with existing categories?" );
if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
merge = true;
QStringList categories = dlg.selectedCategories();
QStringList uids = mViewManager->selectedUids();
QStringList::Iterator it;
for ( it = uids.begin(); it != uids.end(); ++it ) {
KABC::Addressee addr = mAddressBook->findByUid( *it );
if ( !addr.isEmpty() ) {
if ( !merge )
addr.setCategories( categories );
else {
QStringList addrCategories = addr.categories();
QStringList::Iterator catIt;
for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
if ( !addrCategories.contains( *catIt ) )
addrCategories.append( *catIt );
}
addr.setCategories( addrCategories );
}
mAddressBook->insertAddressee( addr );
}
}
if ( uids.count() > 0 )
setModified( true );
}
void KABCore::setSearchFields( const KABC::Field::List &fields )
{
mIncSearchWidget->setFields( fields );
}
void KABCore::incrementalSearch( const QString& text )
{
mViewManager->setSelected( QString::null, false );
if ( !text.isEmpty() ) {
KABC::Field *field = mIncSearchWidget->currentField();
-
- QString pattern = text.lower();
-
+ QString pattern = text.lower()+"*";
+ QRegExp re;
+ re.setWildcard(true); // most people understand these better.
+ re.setCaseSensitive(false);
+ re.setPattern( pattern );
+ QStringList foundUids;
+ if (!re.isValid())
+ return;
#if 1 //KDE_VERSION >= 319
KABC::AddresseeList list( mAddressBook->allAddressees() );
if ( field ) {
list.sortByField( field );
KABC::AddresseeList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
- if ( field->value( *it ).lower().startsWith( pattern ) ) {
- mViewManager->setSelected( (*it).uid(), true );
- return;
+
+#if QT_VERSION >= 300
+ if (re.search(field->value( *it ).lower()) != -1)
+#else
+ if (re.match(field->value( *it ).lower()) != -1)
+#endif
+ {
+ // if ( field->value( *it ).lower().startsWith( pattern ) ) {
+ //mViewManager->setSelected( (*it).uid(), true );
+ foundUids.append( (*it).uid() );
+ //return;
}
}
} else {
KABC::AddresseeList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
KABC::Field::List fieldList = mIncSearchWidget->fields();
KABC::Field::List::ConstIterator fieldIt;
for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
- if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
- mViewManager->setSelected( (*it).uid(), true );
- return;
+#if QT_VERSION >= 300
+ if (re.search((*fieldIt)->value( *it ).lower()) != -1)
+#else
+ if (re.match((*fieldIt)->value( *it ).lower()) != -1)
+#endif
+ {
+ // if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
+ //mViewManager->setSelected( (*it).uid(), true );
+ foundUids.append( (*it).uid() );
+ //return;
}
}
}
}
+ if ( foundUids.count() > 0 )
+ mViewManager->setListSelected( foundUids );
#else
KABC::AddressBook::Iterator it;
for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
if ( field ) {
if ( field->value( *it ).lower().startsWith( pattern ) ) {
mViewManager->setSelected( (*it).uid(), true );
return;
}
} else {
KABC::Field::List fieldList = mIncSearchWidget->fields();
KABC::Field::List::ConstIterator fieldIt;
for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
mViewManager->setSelected( (*it).uid(), true );
return;
}
}
}
}
#endif
}
}
void KABCore::setModified()
{
setModified( true );
}
void KABCore::setModifiedWOrefresh()
{
// qDebug("KABCore::setModifiedWOrefresh() ");
mModified = true;
mActionSave->setEnabled( mModified );
#ifdef DESKTOP_VERSION
mDetails->refreshView();
#endif
}
void KABCore::setModified( bool modified )
{
mModified = modified;
mActionSave->setEnabled( mModified );
if ( modified )
mJumpButtonBar->recreateButtons();
mViewManager->refreshView();
mDetails->refreshView();
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index 45c7b55..c93d51a 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -133,96 +133,103 @@ void ViewManager::saveSettings()
KABPrefs::instance()->mViewNames = mViewNameList;
KABPrefs::instance()->mCurrentView = mActiveView->caption();
}
QStringList ViewManager::selectedUids() const
{
if ( mActiveView )
return mActiveView->selectedUids();
else
return QStringList();
}
QStringList ViewManager::selectedEmails() const
{
if ( mActiveView )
return mActiveView->selectedEmails();
else
return QStringList();
}
KABC::Addressee::List ViewManager::selectedAddressees() const
{
KABC::Addressee::List list;
if ( mActiveView ) {
QStringList uids = mActiveView->selectedUids();
QStringList::Iterator it;
for ( it = uids.begin(); it != uids.end(); ++it ) {
KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
if ( !addr.isEmpty() )
list.append( addr );
}
}
return list;
}
//US added another method with no parameter, since my moc compiler does not support default parameters.
void ViewManager::setSelected()
{
setSelected( QString::null, true );
}
void ViewManager::setSelected( const QString &uid, bool selected )
{
if ( mActiveView )
mActiveView->setSelected( uid, selected );
}
+void ViewManager::setListSelected(QStringList list)
+{
+ int i, count = list.count();
+ for ( i = 0; i < count;++i )
+ setSelected( list[i], true );
+
+}
void ViewManager::unloadViews()
{
mViewDict.clear();
mActiveView = 0;
}
void ViewManager::setActiveView( const QString &name )
{
KAddressBookView *view = 0;
// Check that this isn't the same as the current active view
if ( mActiveView && ( mActiveView->caption() == name ) )
return;
// At this point we know the view that should be active is not
// currently active. We will try to find the new on in the list. If
// we can't find it, it means it hasn't been instantiated, so we will
// create it on demand.
view = mViewDict.find( name );
// Check if we found the view. If we didn't, then we need to create it
if ( view == 0 ) {
KConfig *config = mCore->config();
KConfigGroupSaver saver( config, name );
QString type = config->readEntry( "Type", "Table" );
kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
ViewFactory *factory = mViewFactoryDict.find( type );
if ( factory )
view = factory->view( mCore->addressBook(), mViewWidgetStack );
if ( view ) {
view->setCaption( name );
mViewDict.insert( name, view );
//US my version needs an int as second parameter to addWidget
mViewWidgetStack->addWidget( view, -1 );
view->readConfig( config );
// The manager just relays the signals
connect( view, SIGNAL( selected( const QString& ) ),
SIGNAL( selected( const QString & ) ) );
connect( view, SIGNAL( executed( const QString& ) ),
SIGNAL( executed( const QString& ) ) );
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h
index a18e87d..97c2275 100644
--- a/kaddressbook/viewmanager.h
+++ b/kaddressbook/viewmanager.h
@@ -17,96 +17,97 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#ifndef VIEWMANAGER_H
#define VIEWMANAGER_H
#include <qwidget.h>
#include <qstringlist.h>
#include <kaddressbookview.h>
#include <qdict.h>
class KAction;
class KSelectAction;
class KABCore;
class QWidgetStack;
class QDropEvent;
namespace KABC { class AddressBook; }
/**
The view manager manages the views and everything related to them. The
manager will load the views at startup and display a view when told to
make one active.
The view manager will also create and manage all dialogs directly related to
views (ie: AddView, ConfigureView, DeleteView, etc).
*/
class ViewManager : public QWidget
{
Q_OBJECT
public:
ViewManager( KABCore *core, QWidget *parent, const char *name = 0 );
~ViewManager();
void restoreSettings();
void saveSettings();
void unloadViews();
KSelectAction * getFilterAction() { return mActionSelectFilter; }
QStringList selectedUids() const;
QStringList selectedEmails() const;
KABC::Addressee::List selectedAddressees() const;
+ void setListSelected(QStringList);
public slots:
//US void setSelected( const QString &uid = QString::null, bool selected = true );
void setSelected( const QString &uid, bool);
//US added another method with no parameter, since my moc compiler does not support default parameters.
void setSelected();
//US added another method with no parameter, since my moc compiler does not support default parameters.
void refreshView();
void refreshView( const QString &uid);
void editView();
void deleteView();
void addView();
protected slots:
/**
Called whenever the user drops something in the active view.
This method will try to decode what was dropped, and if it was
a valid addressee, add it to the addressbook.
*/
void dropped( QDropEvent* );
/**
Called whenever the user attempts to start a drag in the view.
This method will convert all the selected addressees into text (vcard)
and create a drag object.
*/
void startDrag();
signals:
/**
Emitted whenever the user selects an entry in the view.
*/
void selected( const QString &uid );
void deleteRequest( );
/**
Emitted whenever the user activates an entry in the view.
*/
void executed( const QString &uid );
/**
Emitted whenever the address book is modified in some way.
*/
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index 66a3f0b..0847b64 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -77,144 +77,144 @@ void KAddressBookTableView::reconstructListView()
KABC::Field::List fieldList = fields();
KABC::Field::List::ConstIterator it;
int c = 0;
for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
mListView->addColumn( (*it)->label() );
mListView->setColumnWidthMode(c++, QListView::Manual);
//US
// qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
}
connect(mListView, SIGNAL(selectionChanged()),
this, SLOT(addresseeSelected()));
connect(mListView, SIGNAL(startAddresseeDrag()), this,
SIGNAL(startDrag()));
connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
SIGNAL(dropped(QDropEvent*)));
if (KABPrefs::instance()->mHonorSingleClick)
connect(mListView, SIGNAL(executed(QListViewItem*)),
this, SLOT(addresseeExecuted(QListViewItem*)));
else
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::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 ) );
c = p.color(QPalette::Normal, QColorGroup::Base );
p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) );
mListView->viewport()->setPalette( p );
}
else
{
// needed if turned off during a session.
mListView->viewport()->setPalette( mListView->palette() );
}
//custom fonts?
QFont f( font() );
if ( config->readBoolEntry( "EnableCustomFonts", false ) )
{
// mListView->setFont( config->readFontEntry( "TextFont", &f) );
f.setBold( true );
// mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
}
else
{
// mListView->setFont( f );
f.setBold( true );
// mListView->setHeaderFont( f );
}
- // The config could have changed the fields, so we need to reconstruct
- // the listview.
- reconstructListView();
// Set the list view options
mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
true));
mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
if (config->readBoolEntry("Background", false))
mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
// Restore the layout of the listview
mListView->restoreLayout(config, config->group());
}
void KAddressBookTableView::refresh(QString uid)
{
// For now just repopulate. In reality this method should
// check the value of uid, and if valid iterate through
// the listview to find the entry, then tell it to refresh.
if (uid.isNull()) {
// Clear the list view
QString currentUID, nextUID;
#ifndef KAB_EMBEDDED
ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
#else //KAB_EMBEDDED
ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
#endif //KAB_EMBEDDED
if ( currentItem ) {
#ifndef KAB_EMBEDDED
ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
#else //KAB_EMBEDDED
ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
#endif //KAB_EMBEDDED
if ( nextItem )
nextUID = nextItem->addressee().uid();
currentUID = currentItem->addressee().uid();
}
mListView->clear();
currentItem = 0;
KABC::Addressee::List addresseeList = addressees();
KABC::Addressee::List::Iterator it;
for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
if ( (*it).uid() == currentUID )