summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorzautrix <zautrix>2004-09-09 20:39:55 (UTC)
committer zautrix <zautrix>2004-09-09 20:39:55 (UTC)
commit480ffef4859d24cc0a936377f8983fd59312d4b6 (patch) (unidiff)
tree9661e8b5e892ef653ffc2ed630dbe89acfeb4851 /kaddressbook
parent880518b6f1d4b06e3df45224c244d9c62f6fb7a9 (diff)
downloadkdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.zip
kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.gz
kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.bz2
Added senseful searching in Kapi
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp75
-rw-r--r--kaddressbook/kaddressbookview.h1
-rw-r--r--kaddressbook/viewmanager.cpp5
-rw-r--r--kaddressbook/viewmanager.h1
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp53
-rw-r--r--kaddressbook/views/kaddressbookcardview.h2
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp47
-rw-r--r--kaddressbook/views/kaddressbookiconview.h1
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp49
-rw-r--r--kaddressbook/views/kaddressbooktableview.h1
10 files changed, 159 insertions, 76 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 1a1bcff..2a2f904 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -820,138 +820,65 @@ void KABCore::setCategories()
820 QStringList uids = mViewManager->selectedUids(); 820 QStringList uids = mViewManager->selectedUids();
821 QStringList::Iterator it; 821 QStringList::Iterator it;
822 for ( it = uids.begin(); it != uids.end(); ++it ) { 822 for ( it = uids.begin(); it != uids.end(); ++it ) {
823 KABC::Addressee addr = mAddressBook->findByUid( *it ); 823 KABC::Addressee addr = mAddressBook->findByUid( *it );
824 if ( !addr.isEmpty() ) { 824 if ( !addr.isEmpty() ) {
825 if ( !merge ) 825 if ( !merge )
826 addr.setCategories( categories ); 826 addr.setCategories( categories );
827 else { 827 else {
828 QStringList addrCategories = addr.categories(); 828 QStringList addrCategories = addr.categories();
829 QStringList::Iterator catIt; 829 QStringList::Iterator catIt;
830 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 830 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
831 if ( !addrCategories.contains( *catIt ) ) 831 if ( !addrCategories.contains( *catIt ) )
832 addrCategories.append( *catIt ); 832 addrCategories.append( *catIt );
833 } 833 }
834 addr.setCategories( addrCategories ); 834 addr.setCategories( addrCategories );
835 } 835 }
836 836
837 mAddressBook->insertAddressee( addr ); 837 mAddressBook->insertAddressee( addr );
838 } 838 }
839 } 839 }
840 840
841 if ( uids.count() > 0 ) 841 if ( uids.count() > 0 )
842 setModified( true ); 842 setModified( true );
843} 843}
844 844
845void KABCore::setSearchFields( const KABC::Field::List &fields ) 845void KABCore::setSearchFields( const KABC::Field::List &fields )
846{ 846{
847 mIncSearchWidget->setFields( fields ); 847 mIncSearchWidget->setFields( fields );
848} 848}
849 849
850void KABCore::incrementalSearch( const QString& text ) 850void KABCore::incrementalSearch( const QString& text )
851{ 851{
852 mViewManager->setSelected( QString::null, false ); 852 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
853
854 if ( !text.isEmpty() ) {
855 KABC::Field *field = mIncSearchWidget->currentField();
856 QString pattern = text.lower()+"*";
857 QRegExp re;
858 re.setWildcard(true); // most people understand these better.
859 re.setCaseSensitive(false);
860 re.setPattern( pattern );
861 QStringList foundUids;
862 if (!re.isValid())
863 return;
864#if 1 //KDE_VERSION >= 319
865 KABC::AddresseeList list( mAddressBook->allAddressees() );
866 if ( field ) {
867 list.sortByField( field );
868 KABC::AddresseeList::Iterator it;
869 for ( it = list.begin(); it != list.end(); ++it ) {
870
871#if QT_VERSION >= 300
872 if (re.search(field->value( *it ).lower()) != -1)
873#else
874 if (re.match(field->value( *it ).lower()) != -1)
875#endif
876 {
877 // if ( field->value( *it ).lower().startsWith( pattern ) ) {
878 //mViewManager->setSelected( (*it).uid(), true );
879 foundUids.append( (*it).uid() );
880 //return;
881 }
882 }
883 } else {
884 KABC::AddresseeList::Iterator it;
885 for ( it = list.begin(); it != list.end(); ++it ) {
886 KABC::Field::List fieldList = mIncSearchWidget->fields();
887 KABC::Field::List::ConstIterator fieldIt;
888 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
889#if QT_VERSION >= 300
890 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
891#else
892 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
893#endif
894 {
895 // if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
896 //mViewManager->setSelected( (*it).uid(), true );
897 foundUids.append( (*it).uid() );
898 //return;
899 }
900 }
901 }
902 }
903 if ( foundUids.count() > 0 )
904 mViewManager->setListSelected( foundUids );
905#else
906 KABC::AddressBook::Iterator it;
907 for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
908 if ( field ) {
909 if ( field->value( *it ).lower().startsWith( pattern ) ) {
910 mViewManager->setSelected( (*it).uid(), true );
911 return;
912 }
913 } else {
914 KABC::Field::List fieldList = mIncSearchWidget->fields();
915 KABC::Field::List::ConstIterator fieldIt;
916 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
917 if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
918 mViewManager->setSelected( (*it).uid(), true );
919 return;
920 }
921 }
922 }
923 }
924#endif
925 }
926} 853}
927 854
928void KABCore::setModified() 855void KABCore::setModified()
929{ 856{
930 setModified( true ); 857 setModified( true );
931} 858}
932 859
933void KABCore::setModifiedWOrefresh() 860void KABCore::setModifiedWOrefresh()
934{ 861{
935 // qDebug("KABCore::setModifiedWOrefresh() "); 862 // qDebug("KABCore::setModifiedWOrefresh() ");
936 mModified = true; 863 mModified = true;
937 mActionSave->setEnabled( mModified ); 864 mActionSave->setEnabled( mModified );
938#ifdef DESKTOP_VERSION 865#ifdef DESKTOP_VERSION
939 mDetails->refreshView(); 866 mDetails->refreshView();
940#endif 867#endif
941 868
942} 869}
943void KABCore::setModified( bool modified ) 870void KABCore::setModified( bool modified )
944{ 871{
945 mModified = modified; 872 mModified = modified;
946 mActionSave->setEnabled( mModified ); 873 mActionSave->setEnabled( mModified );
947 874
948 if ( modified ) 875 if ( modified )
949 mJumpButtonBar->recreateButtons(); 876 mJumpButtonBar->recreateButtons();
950 877
951 mViewManager->refreshView(); 878 mViewManager->refreshView();
952 mDetails->refreshView(); 879 mDetails->refreshView();
953 880
954} 881}
955 882
956bool KABCore::modified() const 883bool KABCore::modified() const
957{ 884{
diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h
index 7457080..17106e8 100644
--- a/kaddressbook/kaddressbookview.h
+++ b/kaddressbook/kaddressbookview.h
@@ -35,64 +35,65 @@ class QDropEvent;
35#include <kabc/field.h> 35#include <kabc/field.h>
36#include <qwidget.h> 36#include <qwidget.h>
37 37
38#include "viewconfigurewidget.h" 38#include "viewconfigurewidget.h"
39#include "filter.h" 39#include "filter.h"
40 40
41namespace KABC { class AddressBook; } 41namespace KABC { class AddressBook; }
42 42
43/** 43/**
44 Base class for all views in kaddressbook. This class implements 44 Base class for all views in kaddressbook. This class implements
45 all the common methods needed to provide a view to the user. 45 all the common methods needed to provide a view to the user.
46 46
47 To implement a specific view (table, card, etc), just inherit from 47 To implement a specific view (table, card, etc), just inherit from
48 this class and implement all the pure virtuals. 48 this class and implement all the pure virtuals.
49 49
50 @author Mike Pilone <mpilone@slac.com> 50 @author Mike Pilone <mpilone@slac.com>
51 */ 51 */
52class KAddressBookView : public QWidget 52class KAddressBookView : public QWidget
53{ 53{
54 Q_OBJECT 54 Q_OBJECT
55 55
56 public: 56 public:
57 enum DefaultFilterType { None = 0, Active = 1, Specific = 2 }; 57 enum DefaultFilterType { None = 0, Active = 1, Specific = 2 };
58 58
59 KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name ); 59 KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name );
60 virtual ~KAddressBookView(); 60 virtual ~KAddressBookView();
61 61
62 /** 62 /**
63 Must be overloaded in subclasses. Should return a list of 63 Must be overloaded in subclasses. Should return a list of
64 all the uids of selected contacts. 64 all the uids of selected contacts.
65 */ 65 */
66 virtual QStringList selectedUids() = 0; 66 virtual QStringList selectedUids() = 0;
67 virtual void doSearch( const QString& s ,KABC::Field *field ) = 0;
67 68
68 /** 69 /**
69 Called whenever this view should read the config. This can be used 70 Called whenever this view should read the config. This can be used
70 as a sign that the config has changed, therefore the view should 71 as a sign that the config has changed, therefore the view should
71 assume the worst and rebuild itself if necessary. For example, 72 assume the worst and rebuild itself if necessary. For example,
72 in a table view this method may be called when the user adds or 73 in a table view this method may be called when the user adds or
73 removes columns from the view. 74 removes columns from the view.
74 75
75 If overloaded in the subclass, do not forget to call super class's 76 If overloaded in the subclass, do not forget to call super class's
76 method. 77 method.
77 78
78 @param config The KConfig object to read from. The group will already 79 @param config The KConfig object to read from. The group will already
79 be set, so do not change the group. 80 be set, so do not change the group.
80 */ 81 */
81 virtual void readConfig( KConfig *config ); 82 virtual void readConfig( KConfig *config );
82 83
83 /** 84 /**
84 Called whenever this view should write the config. The view should not 85 Called whenever this view should write the config. The view should not
85 write out information handled by the application, such as which fields 86 write out information handled by the application, such as which fields
86 are visible. The view should only write out information specific 87 are visible. The view should only write out information specific
87 to itself (i.e.: All information in the ViewConfigWidget) 88 to itself (i.e.: All information in the ViewConfigWidget)
88 89
89 If overloaded in the subclass, do not forget to call the super class's 90 If overloaded in the subclass, do not forget to call the super class's
90 method. 91 method.
91 92
92 @param config The KConfig object to read from. The group will already 93 @param config The KConfig object to read from. The group will already
93 be set, so do not change the group. 94 be set, so do not change the group.
94 */ 95 */
95 virtual void writeConfig( KConfig *config ); 96 virtual void writeConfig( KConfig *config );
96 97
97 /** 98 /**
98 Returns a QString with all the selected email addresses concatenated 99 Returns a QString with all the selected email addresses concatenated
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index c93d51a..c6baeac 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -517,65 +517,70 @@ void ViewManager::startDrag()
517{ 517{
518 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; 518 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
519 519
520#ifndef KAB_EMBEDDED 520#ifndef KAB_EMBEDDED
521 521
522 // Get the list of all the selected addressees 522 // Get the list of all the selected addressees
523 KABC::Addressee::List addrList; 523 KABC::Addressee::List addrList;
524 QStringList uidList = selectedUids(); 524 QStringList uidList = selectedUids();
525 QStringList::Iterator iter; 525 QStringList::Iterator iter;
526 for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) 526 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
527 addrList.append( mCore->addressBook()->findByUid( *iter ) ); 527 addrList.append( mCore->addressBook()->findByUid( *iter ) );
528 528
529 KMultipleDrag *drag = new KMultipleDrag( this ); 529 KMultipleDrag *drag = new KMultipleDrag( this );
530 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); 530 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
531 KABC::Addressee::List::Iterator it; 531 KABC::Addressee::List::Iterator it;
532 QStringList vcards; 532 QStringList vcards;
533 for ( it = addrList.begin(); it != addrList.end(); ++it ) { 533 for ( it = addrList.begin(); it != addrList.end(); ++it ) {
534 QString vcard = QString::null; 534 QString vcard = QString::null;
535 KABC::VCardConverter converter; 535 KABC::VCardConverter converter;
536 if ( converter.addresseeToVCard( *it, vcard ) ) 536 if ( converter.addresseeToVCard( *it, vcard ) )
537 vcards.append( vcard ); 537 vcards.append( vcard );
538 } 538 }
539 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); 539 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
540 540
541 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); 541 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
542 drag->dragCopy(); 542 drag->dragCopy();
543 543
544#else //KAB_EMBEDDED 544#else //KAB_EMBEDDED
545qDebug("ViewManager::startDrag() has to be changed!!" ); 545qDebug("ViewManager::startDrag() has to be changed!!" );
546#endif //KAB_EMBEDDED 546#endif //KAB_EMBEDDED
547 547
548} 548}
549void ViewManager::doSearch( const QString& s,KABC::Field *field )
550{
551 if ( mActiveView )
552 mActiveView->doSearch( s, field );
549 553
554}
550void ViewManager::setActiveFilter( int index ) 555void ViewManager::setActiveFilter( int index )
551{ 556{
552 Filter currentFilter; 557 Filter currentFilter;
553 558
554 if ( ( index - 1 ) < 0 ) 559 if ( ( index - 1 ) < 0 )
555 currentFilter = Filter(); 560 currentFilter = Filter();
556 else 561 else
557 currentFilter = mFilterList[ index - 1 ]; 562 currentFilter = mFilterList[ index - 1 ];
558 563
559 // Check if we have a view. Since the filter combo is created before 564 // Check if we have a view. Since the filter combo is created before
560 // the view, this slot could be called before there is a valid view. 565 // the view, this slot could be called before there is a valid view.
561 if ( mActiveView ) { 566 if ( mActiveView ) {
562 mActiveView->setFilter( currentFilter ); 567 mActiveView->setFilter( currentFilter );
563 mActiveView->refresh(); 568 mActiveView->refresh();
564 emit selected( QString::null ); 569 emit selected( QString::null );
565 } 570 }
566} 571}
567 572
568void ViewManager::configureFilters() 573void ViewManager::configureFilters()
569{ 574{
570 FilterDialog dlg( this ); 575 FilterDialog dlg( this );
571 576
572 dlg.setFilters( mFilterList ); 577 dlg.setFilters( mFilterList );
573 578
574 if ( dlg.exec() ) 579 if ( dlg.exec() )
575 mFilterList = dlg.filters(); 580 mFilterList = dlg.filters();
576 581
577 uint pos = mActionSelectFilter->currentItem(); 582 uint pos = mActionSelectFilter->currentItem();
578 mActionSelectFilter->setItems( filterNames() ); 583 mActionSelectFilter->setItems( filterNames() );
579 mActionSelectFilter->setCurrentItem( pos ); 584 mActionSelectFilter->setCurrentItem( pos );
580 setActiveFilter( pos ); 585 setActiveFilter( pos );
581} 586}
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h
index 97c2275..6def6b6 100644
--- a/kaddressbook/viewmanager.h
+++ b/kaddressbook/viewmanager.h
@@ -26,64 +26,65 @@
26 26
27#include <qwidget.h> 27#include <qwidget.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <kaddressbookview.h> 29#include <kaddressbookview.h>
30#include <qdict.h> 30#include <qdict.h>
31 31
32class KAction; 32class KAction;
33class KSelectAction; 33class KSelectAction;
34 34
35class KABCore; 35class KABCore;
36class QWidgetStack; 36class QWidgetStack;
37class QDropEvent; 37class QDropEvent;
38 38
39namespace KABC { class AddressBook; } 39namespace KABC { class AddressBook; }
40 40
41/** 41/**
42 The view manager manages the views and everything related to them. The 42 The view manager manages the views and everything related to them. The
43 manager will load the views at startup and display a view when told to 43 manager will load the views at startup and display a view when told to
44 make one active. 44 make one active.
45 45
46 The view manager will also create and manage all dialogs directly related to 46 The view manager will also create and manage all dialogs directly related to
47 views (ie: AddView, ConfigureView, DeleteView, etc). 47 views (ie: AddView, ConfigureView, DeleteView, etc).
48 */ 48 */
49class ViewManager : public QWidget 49class ViewManager : public QWidget
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 public: 52 public:
53 ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); 53 ViewManager( KABCore *core, QWidget *parent, const char *name = 0 );
54 ~ViewManager(); 54 ~ViewManager();
55 55
56 void restoreSettings(); 56 void restoreSettings();
57 void saveSettings(); 57 void saveSettings();
58 void doSearch( const QString& s ,KABC::Field *field );
58 59
59 void unloadViews(); 60 void unloadViews();
60 KSelectAction * getFilterAction() { return mActionSelectFilter; } 61 KSelectAction * getFilterAction() { return mActionSelectFilter; }
61 62
62 QStringList selectedUids() const; 63 QStringList selectedUids() const;
63 QStringList selectedEmails() const; 64 QStringList selectedEmails() const;
64 KABC::Addressee::List selectedAddressees() const; 65 KABC::Addressee::List selectedAddressees() const;
65 void setListSelected(QStringList); 66 void setListSelected(QStringList);
66 67
67 public slots: 68 public slots:
68 69
69//US void setSelected( const QString &uid = QString::null, bool selected = true ); 70//US void setSelected( const QString &uid = QString::null, bool selected = true );
70 void setSelected( const QString &uid, bool); 71 void setSelected( const QString &uid, bool);
71//US added another method with no parameter, since my moc compiler does not support default parameters. 72//US added another method with no parameter, since my moc compiler does not support default parameters.
72 void setSelected(); 73 void setSelected();
73 74
74 75
75 76
76//US added another method with no parameter, since my moc compiler does not support default parameters. 77//US added another method with no parameter, since my moc compiler does not support default parameters.
77 void refreshView(); 78 void refreshView();
78 void refreshView( const QString &uid); 79 void refreshView( const QString &uid);
79 80
80 void editView(); 81 void editView();
81 void deleteView(); 82 void deleteView();
82 void addView(); 83 void addView();
83 84
84 protected slots: 85 protected slots:
85 /** 86 /**
86 Called whenever the user drops something in the active view. 87 Called whenever the user drops something in the active view.
87 This method will try to decode what was dropped, and if it was 88 This method will try to decode what was dropped, and if it was
88 a valid addressee, add it to the addressbook. 89 a valid addressee, add it to the addressbook.
89 */ 90 */
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 239429f..49c0691 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -86,64 +86,65 @@ class AddresseeCardViewItem : public CardViewItem
86 // (during geometry calculations), but prevents having equally 86 // (during geometry calculations), but prevents having equally
87 // wide label columns in all cards, unless CardViewItem/CardView search 87 // wide label columns in all cards, unless CardViewItem/CardView search
88 // globally for the widest label. (anders) 88 // globally for the widest label. (anders)
89 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) 89 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
90 insertField((*iter)->label(), (*iter)->value( mAddressee )); 90 insertField((*iter)->label(), (*iter)->value( mAddressee ));
91 } 91 }
92 92
93 // We might want to make this the first field. hmm... -mpilone 93 // We might want to make this the first field. hmm... -mpilone
94 setCaption( mAddressee.realName() ); 94 setCaption( mAddressee.realName() );
95 } 95 }
96 } 96 }
97 97
98 private: 98 private:
99 KABC::Field::List mFields; 99 KABC::Field::List mFields;
100 bool mShowEmptyFields; 100 bool mShowEmptyFields;
101 KABC::AddressBook *mDocument; 101 KABC::AddressBook *mDocument;
102 KABC::Addressee mAddressee; 102 KABC::Addressee mAddressee;
103}; 103};
104 104
105/////////////////////////////// 105///////////////////////////////
106// AddresseeCardView 106// AddresseeCardView
107 107
108AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 108AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
109 : CardView(parent, name) 109 : CardView(parent, name)
110{ 110{
111 setAcceptDrops(true); 111 setAcceptDrops(true);
112} 112}
113 113
114AddresseeCardView::~AddresseeCardView() 114AddresseeCardView::~AddresseeCardView()
115{ 115{
116} 116}
117 117
118
118void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 119void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
119{ 120{
120#ifndef KAB_EMBEDDED 121#ifndef KAB_EMBEDDED
121 if (QTextDrag::canDecode(e)) 122 if (QTextDrag::canDecode(e))
122 e->accept(); 123 e->accept();
123#else //KAB_EMBEDDED 124#else //KAB_EMBEDDED
124qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 125qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
125#endif //KAB_EMBEDDED 126#endif //KAB_EMBEDDED
126} 127}
127 128
128void AddresseeCardView::dropEvent(QDropEvent *e) 129void AddresseeCardView::dropEvent(QDropEvent *e)
129{ 130{
130 emit addresseeDropped(e); 131 emit addresseeDropped(e);
131} 132}
132 133
133void AddresseeCardView::startDrag() 134void AddresseeCardView::startDrag()
134{ 135{
135 emit startAddresseeDrag(); 136 emit startAddresseeDrag();
136} 137}
137 138
138 139
139/////////////////////////////// 140///////////////////////////////
140// KAddressBookCardView 141// KAddressBookCardView
141 142
142KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, 143KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
143 QWidget *parent, const char *name ) 144 QWidget *parent, const char *name )
144 : KAddressBookView( ab, parent, name ) 145 : KAddressBookView( ab, parent, name )
145{ 146{
146 mShowEmptyFields = false; 147 mShowEmptyFields = false;
147 148
148 // Init the GUI 149 // Init the GUI
149 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 150 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
@@ -211,65 +212,115 @@ void KAddressBookCardView::readConfig(KConfig *config)
211 } 212 }
212 213
213 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); 214 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
214 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", 215 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
215 true)); 216 true));
216 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); 217 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
217 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); 218 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
218 219
219 mCardView->setShowEmptyFields( mShowEmptyFields ); 220 mCardView->setShowEmptyFields( mShowEmptyFields );
220 221
221 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); 222 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
222 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); 223 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
223 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); 224 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
224 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); 225 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
225 226
226 disconnect(mCardView, SIGNAL(executed(CardViewItem *)), 227 disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
227 this, SLOT(addresseeExecuted(CardViewItem *))); 228 this, SLOT(addresseeExecuted(CardViewItem *)));
228 229
229 if (KABPrefs::instance()->mHonorSingleClick) 230 if (KABPrefs::instance()->mHonorSingleClick)
230 connect(mCardView, SIGNAL(executed(CardViewItem *)), 231 connect(mCardView, SIGNAL(executed(CardViewItem *)),
231 this, SLOT(addresseeExecuted(CardViewItem *))); 232 this, SLOT(addresseeExecuted(CardViewItem *)));
232 else 233 else
233 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 234 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
234 this, SLOT(addresseeExecuted(CardViewItem *))); 235 this, SLOT(addresseeExecuted(CardViewItem *)));
235 236
236} 237}
237 238
238void KAddressBookCardView::writeConfig( KConfig *config ) 239void KAddressBookCardView::writeConfig( KConfig *config )
239{ 240{
240 config->writeEntry( "ItemWidth", mCardView->itemWidth() ); 241 config->writeEntry( "ItemWidth", mCardView->itemWidth() );
241 KAddressBookView::writeConfig( config ); 242 KAddressBookView::writeConfig( config );
242} 243}
243 244void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
245{
246 mCardView->clear();
247 if ( s.isEmpty() || s == "*" ) {
248 refresh();
249 return;
250 }
251 QString pattern = s.lower()+"*";
252 QRegExp re;
253 re.setWildcard(true); // most people understand these better.
254 re.setCaseSensitive(false);
255 re.setPattern( pattern );
256 if (!re.isValid())
257 return;
258 mCardView->viewport()->setUpdatesEnabled( false );
259 KABC::Addressee::List addresseeList = addressees();
260 KABC::Addressee::List::Iterator it;
261 if ( field ) {
262 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
263#if QT_VERSION >= 300
264 if (re.search(field->value( *it ).lower()) != -1)
265#else
266 if (re.match(field->value( *it ).lower()) != -1)
267#endif
268 new AddresseeCardViewItem(fields(), mShowEmptyFields,
269 addressBook(), *it, mCardView);
270
271 }
272 } else {
273 KABC::Field::List fieldList = fields();
274 KABC::Field::List::ConstIterator fieldIt;
275 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
276 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
277#if QT_VERSION >= 300
278 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
279#else
280 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
281#endif
282 {
283 new AddresseeCardViewItem(fields(), mShowEmptyFields,
284 addressBook(), *it, mCardView);
285 continue;
286 }
287 }
288 }
289 }
290 mCardView->viewport()->setUpdatesEnabled( true );
291 mCardView->viewport()->update();
292 // by default nothing is selected
293 emit selected(QString::null);
294}
244QStringList KAddressBookCardView::selectedUids() 295QStringList KAddressBookCardView::selectedUids()
245{ 296{
246 QStringList uidList; 297 QStringList uidList;
247 CardViewItem *item; 298 CardViewItem *item;
248 AddresseeCardViewItem *aItem; 299 AddresseeCardViewItem *aItem;
249 300
250 for (item = mCardView->firstItem(); item; item = item->nextItem()) 301 for (item = mCardView->firstItem(); item; item = item->nextItem())
251 { 302 {
252 if (item->isSelected()) 303 if (item->isSelected())
253 { 304 {
254#ifndef KAB_EMBEDDED 305#ifndef KAB_EMBEDDED
255 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 306 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
256#else //KAB_EMBEDDED 307#else //KAB_EMBEDDED
257 aItem = (AddresseeCardViewItem*)(item); 308 aItem = (AddresseeCardViewItem*)(item);
258#endif //KAB_EMBEDDED 309#endif //KAB_EMBEDDED
259 if (aItem) 310 if (aItem)
260 uidList << aItem->addressee().uid(); 311 uidList << aItem->addressee().uid();
261 } 312 }
262 } 313 }
263 314
264 return uidList; 315 return uidList;
265} 316}
266 317
267void KAddressBookCardView::refresh(QString uid) 318void KAddressBookCardView::refresh(QString uid)
268{ 319{
269 CardViewItem *item; 320 CardViewItem *item;
270 AddresseeCardViewItem *aItem; 321 AddresseeCardViewItem *aItem;
271 322
272 if (uid.isNull()) 323 if (uid.isNull())
273 { 324 {
274 // Rebuild the view 325 // Rebuild the view
275 mCardView->viewport()->setUpdatesEnabled( false ); 326 mCardView->viewport()->setUpdatesEnabled( false );
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h
index cd70371..b8efb01 100644
--- a/kaddressbook/views/kaddressbookcardview.h
+++ b/kaddressbook/views/kaddressbookcardview.h
@@ -25,65 +25,65 @@
25*/ 25*/
26 26
27#include <qstring.h> 27#include <qstring.h>
28#ifndef KAB_EMBEDDED 28#ifndef KAB_EMBEDDED
29#include <kiconview.h> 29#include <kiconview.h>
30#else //KAB_EMBEDDED 30#else //KAB_EMBEDDED
31#include <klocale.h> 31#include <klocale.h>
32#endif //KAB_EMBEDDED 32#endif //KAB_EMBEDDED
33 33
34#include "cardview.h" 34#include "cardview.h"
35#include "kaddressbookview.h" 35#include "kaddressbookview.h"
36#include "configurecardviewdialog.h" 36#include "configurecardviewdialog.h"
37 37
38class QDragEnterEvent; 38class QDragEnterEvent;
39class QDragEntryEvent; 39class QDragEntryEvent;
40class QDropEvent; 40class QDropEvent;
41class KConfig; 41class KConfig;
42class AddresseeCardView; 42class AddresseeCardView;
43 43
44/** 44/**
45 This view uses the CardView class to create a card view. At some 45 This view uses the CardView class to create a card view. At some
46 point in the future I think this will be the default view of 46 point in the future I think this will be the default view of
47 KAddressBook. 47 KAddressBook.
48 */ 48 */
49class KAddressBookCardView : public KAddressBookView 49class KAddressBookCardView : public KAddressBookView
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 52
53 public: 53 public:
54 KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent, 54 KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent,
55 const char *name = 0 ); 55 const char *name = 0 );
56 virtual ~KAddressBookCardView(); 56 virtual ~KAddressBookCardView();
57 57 void doSearch( const QString& s,KABC::Field *field );
58 virtual QStringList selectedUids(); 58 virtual QStringList selectedUids();
59 virtual QString type() const { return "Card"; } 59 virtual QString type() const { return "Card"; }
60 60
61 virtual void readConfig(KConfig *config); 61 virtual void readConfig(KConfig *config);
62 virtual void writeConfig(KConfig *); 62 virtual void writeConfig(KConfig *);
63 63
64 public slots: 64 public slots:
65 void refresh(QString uid = QString::null); 65 void refresh(QString uid = QString::null);
66 void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/); 66 void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/);
67//US added an additional method without parameter 67//US added an additional method without parameter
68 void setSelected(); 68 void setSelected();
69 69
70 protected slots: 70 protected slots:
71 void addresseeExecuted(CardViewItem *item); 71 void addresseeExecuted(CardViewItem *item);
72 void addresseeSelected(); 72 void addresseeSelected();
73 73
74 private: 74 private:
75 AddresseeCardView *mCardView; 75 AddresseeCardView *mCardView;
76 bool mShowEmptyFields; 76 bool mShowEmptyFields;
77}; 77};
78 78
79class AddresseeCardView : public CardView 79class AddresseeCardView : public CardView
80{ 80{
81 Q_OBJECT 81 Q_OBJECT
82 public: 82 public:
83 AddresseeCardView(QWidget *parent, const char *name = 0); 83 AddresseeCardView(QWidget *parent, const char *name = 0);
84 ~AddresseeCardView(); 84 ~AddresseeCardView();
85 85
86 signals: 86 signals:
87 void startAddresseeDrag(); 87 void startAddresseeDrag();
88 void addresseeDropped(QDropEvent *); 88 void addresseeDropped(QDropEvent *);
89 89
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp
index 50ff285..78d63b0 100644
--- a/kaddressbook/views/kaddressbookiconview.cpp
+++ b/kaddressbook/views/kaddressbookiconview.cpp
@@ -67,64 +67,65 @@ extern "C" {
67//////////////////////////////// 67////////////////////////////////
68// AddresseeIconView (internal class) 68// AddresseeIconView (internal class)
69#ifndef KAB_EMBEDDED 69#ifndef KAB_EMBEDDED
70AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) 70AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
71 : KIconView(parent, name) 71 : KIconView(parent, name)
72#else //KAB_EMBEDDED 72#else //KAB_EMBEDDED
73AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) 73AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
74 : QIconView(parent, name) 74 : QIconView(parent, name)
75#endif //KAB_EMBEDDED 75#endif //KAB_EMBEDDED
76 76
77{ 77{
78 setSelectionMode( QIconView::Extended ); 78 setSelectionMode( QIconView::Extended );
79 setResizeMode( QIconView::Adjust ); 79 setResizeMode( QIconView::Adjust );
80 setWordWrapIconText( true ); 80 setWordWrapIconText( true );
81 setGridX( 100 ); 81 setGridX( 100 );
82 setItemsMovable(false); 82 setItemsMovable(false);
83 setSorting(true, true); 83 setSorting(true, true);
84 84
85 85
86//US ??? setMode( KIconView::Select ); 86//US ??? setMode( KIconView::Select );
87 87
88#ifndef KAB_EMBEDDED 88#ifndef KAB_EMBEDDED
89 89
90 connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)), 90 connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)),
91 this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&))); 91 this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&)));
92#endif //KAB_EMBEDDED 92#endif //KAB_EMBEDDED
93} 93}
94 94
95AddresseeIconView::~AddresseeIconView() 95AddresseeIconView::~AddresseeIconView()
96{ 96{
97} 97}
98 98
99
99void AddresseeIconView::itemDropped(QDropEvent *e, 100void AddresseeIconView::itemDropped(QDropEvent *e,
100 const QValueList<QIconDragItem> &) 101 const QValueList<QIconDragItem> &)
101{ 102{
102 emit addresseeDropped(e); 103 emit addresseeDropped(e);
103} 104}
104 105
105QDragObject *AddresseeIconView::dragObject() 106QDragObject *AddresseeIconView::dragObject()
106{ 107{
107 emit startAddresseeDrag(); 108 emit startAddresseeDrag();
108 109
109 // We never want IconView to start the drag 110 // We never want IconView to start the drag
110 return 0; 111 return 0;
111} 112}
112//////////////////////////////// 113////////////////////////////////
113// AddresseeIconViewItem (internal class) 114// AddresseeIconViewItem (internal class)
114#ifndef KAB_EMBEDDED 115#ifndef KAB_EMBEDDED
115class AddresseeIconViewItem : public KIconViewItem 116class AddresseeIconViewItem : public KIconViewItem
116#else //KAB_EMBEDDED 117#else //KAB_EMBEDDED
117class AddresseeIconViewItem : public QIconViewItem 118class AddresseeIconViewItem : public QIconViewItem
118#endif //KAB_EMBEDDED 119#endif //KAB_EMBEDDED
119{ 120{
120 public: 121 public:
121#ifndef KAB_EMBEDDED 122#ifndef KAB_EMBEDDED
122 AddresseeIconViewItem(const KABC::Field::List &fields, 123 AddresseeIconViewItem(const KABC::Field::List &fields,
123 KABC::AddressBook *doc, const KABC::Addressee &a, 124 KABC::AddressBook *doc, const KABC::Addressee &a,
124 QIconView *parent) 125 QIconView *parent)
125 : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) 126 : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
126#else //KAB_EMBEDDED 127#else //KAB_EMBEDDED
127 AddresseeIconViewItem(const KABC::Field::List &fields, 128 AddresseeIconViewItem(const KABC::Field::List &fields,
128 KABC::AddressBook *doc, const KABC::Addressee &a, 129 KABC::AddressBook *doc, const KABC::Addressee &a,
129 QIconView *parent) 130 QIconView *parent)
130 : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) 131 : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
@@ -203,65 +204,111 @@ KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
203 this, SIGNAL(dropped(QDropEvent*))); 204 this, SIGNAL(dropped(QDropEvent*)));
204 connect(mIconView, SIGNAL(startAddresseeDrag()), 205 connect(mIconView, SIGNAL(startAddresseeDrag()),
205 this, SIGNAL(startDrag())); 206 this, SIGNAL(startDrag()));
206} 207}
207 208
208KAddressBookIconView::~KAddressBookIconView() 209KAddressBookIconView::~KAddressBookIconView()
209{ 210{
210} 211}
211 212
212void KAddressBookIconView::readConfig(KConfig *config) 213void KAddressBookIconView::readConfig(KConfig *config)
213{ 214{
214 KAddressBookView::readConfig(config); 215 KAddressBookView::readConfig(config);
215 216
216//US method executed is part of KIconView 217//US method executed is part of KIconView
217//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), 218//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)),
218//US this, SLOT(addresseeExecuted(QIconViewItem *))); 219//US this, SLOT(addresseeExecuted(QIconViewItem *)));
219 disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 220 disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
220 this, SLOT(addresseeExecuted(QIconViewItem *))); 221 this, SLOT(addresseeExecuted(QIconViewItem *)));
221 222
222//US method executed is part of KIconView. Use selectionChanged instead 223//US method executed is part of KIconView. Use selectionChanged instead
223/*US 224/*US
224 if (KABPrefs::instance()->mHonorSingleClick) 225 if (KABPrefs::instance()->mHonorSingleClick)
225 connect(mIconView, SIGNAL(executed(QIconViewItem *)), 226 connect(mIconView, SIGNAL(executed(QIconViewItem *)),
226 this, SLOT(addresseeExecuted(QIconViewItem *))); 227 this, SLOT(addresseeExecuted(QIconViewItem *)));
227 else 228 else
228 connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), 229 connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)),
229 this, SLOT(addresseeExecuted(QIconViewItem *))); 230 this, SLOT(addresseeExecuted(QIconViewItem *)));
230*/ 231*/
231 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 232 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
232 this, SLOT(addresseeExecuted(QIconViewItem *))); 233 this, SLOT(addresseeExecuted(QIconViewItem *)));
233 234
234} 235}
236void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
237{
238 mIconView->clear();
239 mIconList.clear();
240 if ( s.isEmpty() || s == "*" ) {
241 refresh();
242 return;
243 }
244 QString pattern = s.lower()+"*";
245 QRegExp re;
246 re.setWildcard(true); // most people understand these better.
247 re.setCaseSensitive(false);
248 re.setPattern( pattern );
249 if (!re.isValid())
250 return;
251 KABC::Addressee::List addresseeList = addressees();
252 KABC::Addressee::List::Iterator it;
253 if ( field ) {
254 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
255#if QT_VERSION >= 300
256 if (re.search(field->value( *it ).lower()) != -1)
257#else
258 if (re.match(field->value( *it ).lower()) != -1)
259#endif
260 mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
261
235 262
263 }
264 } else {
265 KABC::Field::List fieldList = fields();
266 KABC::Field::List::ConstIterator fieldIt;
267 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
268 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
269#if QT_VERSION >= 300
270 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
271#else
272 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
273#endif
274 {
275 mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
276 continue;
277 }
278 }
279 }
280 }
281 mIconView->arrangeItemsInGrid( true );
282}
236QStringList KAddressBookIconView::selectedUids() 283QStringList KAddressBookIconView::selectedUids()
237{ 284{
238 QStringList uidList; 285 QStringList uidList;
239 QIconViewItem *item; 286 QIconViewItem *item;
240 AddresseeIconViewItem *aItem; 287 AddresseeIconViewItem *aItem;
241 288
242 for (item = mIconView->firstItem(); item; item = item->nextItem()) 289 for (item = mIconView->firstItem(); item; item = item->nextItem())
243 { 290 {
244 if (item->isSelected()) 291 if (item->isSelected())
245 { 292 {
246#ifndef KAB_EMBEDDED 293#ifndef KAB_EMBEDDED
247 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 294 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
248#else //KAB_EMBEDDED 295#else //KAB_EMBEDDED
249 aItem = (AddresseeIconViewItem*)(item); 296 aItem = (AddresseeIconViewItem*)(item);
250#endif //KAB_EMBEDDED 297#endif //KAB_EMBEDDED
251 if (aItem) 298 if (aItem)
252 uidList << aItem->addressee().uid(); 299 uidList << aItem->addressee().uid();
253 } 300 }
254 } 301 }
255 302
256 return uidList; 303 return uidList;
257} 304}
258 305
259void KAddressBookIconView::refresh(QString uid) 306void KAddressBookIconView::refresh(QString uid)
260{ 307{
261 QIconViewItem *item; 308 QIconViewItem *item;
262 AddresseeIconViewItem *aItem; 309 AddresseeIconViewItem *aItem;
263 310
264 if ( uid.isNull() ) { 311 if ( uid.isNull() ) {
265 // Rebuild the view 312 // Rebuild the view
266 mIconView->clear(); 313 mIconView->clear();
267 mIconList.clear(); 314 mIconList.clear();
diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h
index 3afada3..963ee7c 100644
--- a/kaddressbook/views/kaddressbookiconview.h
+++ b/kaddressbook/views/kaddressbookiconview.h
@@ -29,64 +29,65 @@
29#include <kiconview.h> 29#include <kiconview.h>
30#else //KAB_EMBEDDED 30#else //KAB_EMBEDDED
31#include <qiconview.h> 31#include <qiconview.h>
32#include <qptrlist.h> 32#include <qptrlist.h>
33#include <klocale.h> 33#include <klocale.h>
34#endif //KAB_EMBEDDED 34#endif //KAB_EMBEDDED
35#include "kaddressbookview.h" 35#include "kaddressbookview.h"
36 36
37class QIconViewItem; 37class QIconViewItem;
38class KConfig; 38class KConfig;
39class AddresseeIconView; 39class AddresseeIconView;
40class AddresseeIconViewItem; 40class AddresseeIconViewItem;
41class QIconDragItem; 41class QIconDragItem;
42class KAddressBookIconView; 42class KAddressBookIconView;
43 43
44namespace KABC { class AddressBook; } 44namespace KABC { class AddressBook; }
45 45
46/** This is an example kaddressbook view that is implemented using 46/** This is an example kaddressbook view that is implemented using
47* KIconView. This view is not the most useful view, but it displays 47* KIconView. This view is not the most useful view, but it displays
48* how simple implementing a new view can be. 48* how simple implementing a new view can be.
49*/ 49*/
50class KAddressBookIconView : public KAddressBookView 50class KAddressBookIconView : public KAddressBookView
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 public: 54 public:
55 KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent, 55 KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent,
56 const char *name = 0 ); 56 const char *name = 0 );
57 virtual ~KAddressBookIconView(); 57 virtual ~KAddressBookIconView();
58 58
59 virtual QStringList selectedUids(); 59 virtual QStringList selectedUids();
60 virtual QString type() const { return "Icon"; } 60 virtual QString type() const { return "Icon"; }
61 void doSearch( const QString& s ,KABC::Field *field );
61 62
62 virtual void readConfig(KConfig *config); 63 virtual void readConfig(KConfig *config);
63 64
64 public slots: 65 public slots:
65 void refresh(QString uid = QString::null); 66 void refresh(QString uid = QString::null);
66#ifndef KAB_EMBEDDED 67#ifndef KAB_EMBEDDED
67//MOC_SKIP_BEGIN 68//MOC_SKIP_BEGIN
68 void setSelected(QString uid = QString::null, bool selected = true); 69 void setSelected(QString uid = QString::null, bool selected = true);
69//MOC_SKIP_END 70//MOC_SKIP_END
70#else //KAB_EMBEDDED 71#else //KAB_EMBEDDED
71//US my MOC do not like default parameters ??? 72//US my MOC do not like default parameters ???
72 void setSelected(QString uid, bool selected); 73 void setSelected(QString uid, bool selected);
73#endif //KAB_EMBEDDED 74#endif //KAB_EMBEDDED
74 75
75 protected slots: 76 protected slots:
76 void addresseeExecuted(QIconViewItem *item); 77 void addresseeExecuted(QIconViewItem *item);
77 void addresseeSelected(); 78 void addresseeSelected();
78 79
79 private: 80 private:
80 AddresseeIconView *mIconView; 81 AddresseeIconView *mIconView;
81 QPtrList<AddresseeIconViewItem> mIconList; 82 QPtrList<AddresseeIconViewItem> mIconList;
82}; 83};
83 84
84 85
85#ifndef KAB_EMBEDDED 86#ifndef KAB_EMBEDDED
86//MOC_SKIP_BEGIN 87//MOC_SKIP_BEGIN
87class AddresseeIconView : public KIconView 88class AddresseeIconView : public KIconView
88//MOC_SKIP_END 89//MOC_SKIP_END
89#else //KAB_EMBEDDED 90#else //KAB_EMBEDDED
90class AddresseeIconView : public QIconView 91class AddresseeIconView : public QIconView
91#endif //KAB_EMBEDDED 92#endif //KAB_EMBEDDED
92{ 93{
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index ab11e2a..12f7c27 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -83,64 +83,113 @@ void KAddressBookTableView::reconstructListView()
83 mListView->setColumnWidthMode(c++, QListView::Manual); 83 mListView->setColumnWidthMode(c++, QListView::Manual);
84//US 84//US
85 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); 85 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
86 } 86 }
87 87
88 connect(mListView, SIGNAL(selectionChanged()), 88 connect(mListView, SIGNAL(selectionChanged()),
89 this, SLOT(addresseeSelected())); 89 this, SLOT(addresseeSelected()));
90 connect(mListView, SIGNAL(startAddresseeDrag()), this, 90 connect(mListView, SIGNAL(startAddresseeDrag()), this,
91 SIGNAL(startDrag())); 91 SIGNAL(startDrag()));
92 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 92 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
93 SIGNAL(dropped(QDropEvent*))); 93 SIGNAL(dropped(QDropEvent*)));
94 94
95 if (KABPrefs::instance()->mHonorSingleClick) 95 if (KABPrefs::instance()->mHonorSingleClick)
96 connect(mListView, SIGNAL(executed(QListViewItem*)), 96 connect(mListView, SIGNAL(executed(QListViewItem*)),
97 this, SLOT(addresseeExecuted(QListViewItem*))); 97 this, SLOT(addresseeExecuted(QListViewItem*)));
98 else 98 else
99 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 99 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
100 this, SLOT(addresseeExecuted(QListViewItem*))); 100 this, SLOT(addresseeExecuted(QListViewItem*)));
101 connect(mListView, SIGNAL(returnPressed(QListViewItem*)), 101 connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
102 this, SLOT(addresseeExecuted(QListViewItem*))); 102 this, SLOT(addresseeExecuted(QListViewItem*)));
103 connect(mListView, SIGNAL(signalDelete()), 103 connect(mListView, SIGNAL(signalDelete()),
104 this, SLOT(addresseeDeleted())); 104 this, SLOT(addresseeDeleted()));
105 105
106//US performceimprovement. Refresh is done from the outside 106//US performceimprovement. Refresh is done from the outside
107//US refresh(); 107//US refresh();
108 108
109 mListView->setSorting( 0, true ); 109 mListView->setSorting( 0, true );
110 mainLayout->addWidget( mListView ); 110 mainLayout->addWidget( mListView );
111 mainLayout->activate(); 111 mainLayout->activate();
112 mListView->show(); 112 mListView->show();
113} 113}
114 114
115void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
116{
117 mListView->clear();
118 if ( s.isEmpty() || s == "*" ) {
119 refresh();
120 return;
121 }
122 QString pattern = s.lower()+"*";
123 QRegExp re;
124 re.setWildcard(true); // most people understand these better.
125 re.setCaseSensitive(false);
126 re.setPattern( pattern );
127 if (!re.isValid())
128 return;
129 KABC::Addressee::List addresseeList = addressees();
130 KABC::Addressee::List::Iterator it;
131 if ( field ) {
132 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
133#if QT_VERSION >= 300
134 if (re.search(field->value( *it ).lower()) != -1)
135#else
136 if (re.match(field->value( *it ).lower()) != -1)
137#endif
138 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
139
140 }
141 } else {
142 KABC::Field::List fieldList = fields();
143 KABC::Field::List::ConstIterator fieldIt;
144 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
145 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
146#if QT_VERSION >= 300
147 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
148#else
149 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
150#endif
151 {
152 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
153 continue;
154 }
155 }
156 }
157 }
158 // Sometimes the background pixmap gets messed up when we add lots
159 // of items.
160 mListView->repaint();
161 emit selected(QString::null);
162
163}
115void KAddressBookTableView::writeConfig(KConfig *config) 164void KAddressBookTableView::writeConfig(KConfig *config)
116{ 165{
117 KAddressBookView::writeConfig(config); 166 KAddressBookView::writeConfig(config);
118 167
119 mListView->saveLayout(config, config->group()); 168 mListView->saveLayout(config, config->group());
120} 169}
121 170
122void KAddressBookTableView::readConfig(KConfig *config) 171void KAddressBookTableView::readConfig(KConfig *config)
123{ 172{
124 KAddressBookView::readConfig( config ); 173 KAddressBookView::readConfig( config );
125 // The config could have changed the fields, so we need to reconstruct 174 // The config could have changed the fields, so we need to reconstruct
126 // the listview. 175 // the listview.
127 reconstructListView(); 176 reconstructListView();
128 177
129 // costum colors? 178 // costum colors?
130 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 179 if ( config->readBoolEntry( "EnableCustomColors", false ) )
131 { 180 {
132 QPalette p( mListView->palette() ); 181 QPalette p( mListView->palette() );
133 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 182 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
134 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 183 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
135 c = p.color(QPalette::Normal, QColorGroup::Text ); 184 c = p.color(QPalette::Normal, QColorGroup::Text );
136 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 185 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
137 c = p.color(QPalette::Normal, QColorGroup::Button ); 186 c = p.color(QPalette::Normal, QColorGroup::Button );
138 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 187 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
139 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 188 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
140 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 189 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
141 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 190 c = p.color(QPalette::Normal, QColorGroup::Highlight );
142 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 191 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
143 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 192 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
144 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 193 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
145#ifndef KAB_EMBEDDED 194#ifndef KAB_EMBEDDED
146 c = KGlobalSettings::alternateBackgroundColor(); 195 c = KGlobalSettings::alternateBackgroundColor();
diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h
index bb991bc..ecfe7a1 100644
--- a/kaddressbook/views/kaddressbooktableview.h
+++ b/kaddressbook/views/kaddressbooktableview.h
@@ -33,64 +33,65 @@ class KConfig;
33 33
34class ContactListViewItem; 34class ContactListViewItem;
35class ContactListView; 35class ContactListView;
36 36
37 37
38namespace KABC { class AddressBook; } 38namespace KABC { class AddressBook; }
39 39
40/** 40/**
41 * This class is the table view for kaddressbook. This view is a KListView 41 * This class is the table view for kaddressbook. This view is a KListView
42 * with multiple columns for the selected fields. 42 * with multiple columns for the selected fields.
43 * 43 *
44 * @short Table View 44 * @short Table View
45 * @author Don Sanders <dsanders@kde.org> 45 * @author Don Sanders <dsanders@kde.org>
46 * @version 0.1 46 * @version 0.1
47 */ 47 */
48class KAddressBookTableView : public KAddressBookView 48class KAddressBookTableView : public KAddressBookView
49{ 49{
50friend class ContactListView; 50friend class ContactListView;
51 51
52 Q_OBJECT 52 Q_OBJECT
53 53
54 public: 54 public:
55 KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent, 55 KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent,
56 const char *name = 0 ); 56 const char *name = 0 );
57 virtual ~KAddressBookTableView(); 57 virtual ~KAddressBookTableView();
58 58
59 virtual void refresh(QString uid = QString::null); 59 virtual void refresh(QString uid = QString::null);
60 virtual QStringList selectedUids(); 60 virtual QStringList selectedUids();
61 virtual void setSelected(QString uid = QString::null, bool selected = false); 61 virtual void setSelected(QString uid = QString::null, bool selected = false);
62 virtual void readConfig(KConfig *config); 62 virtual void readConfig(KConfig *config);
63 virtual void writeConfig(KConfig *config); 63 virtual void writeConfig(KConfig *config);
64 virtual QString type() const { return "Table"; } 64 virtual QString type() const { return "Table"; }
65 void doSearch( const QString& s ,KABC::Field *field );
65 66
66 public slots: 67 public slots:
67 virtual void reconstructListView(); 68 virtual void reconstructListView();
68 69
69 protected slots: 70 protected slots:
70 /** Called whenever the user selects an addressee in the list view. 71 /** Called whenever the user selects an addressee in the list view.
71 */ 72 */
72 void addresseeSelected(); 73 void addresseeSelected();
73 void addresseeDeleted(); 74 void addresseeDeleted();
74 75
75 /** Called whenever the user executes an addressee. In terms of the 76 /** Called whenever the user executes an addressee. In terms of the
76 * list view, this is probably a double click 77 * list view, this is probably a double click
77 */ 78 */
78 void addresseeExecuted(QListViewItem*); 79 void addresseeExecuted(QListViewItem*);
79 80
80 private: 81 private:
81 QVBoxLayout *mainLayout; 82 QVBoxLayout *mainLayout;
82 ContactListView *mListView; 83 ContactListView *mListView;
83}; 84};
84 85
85 86
86class TableViewFactory : public ViewFactory 87class TableViewFactory : public ViewFactory
87{ 88{
88 public: 89 public:
89 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) 90 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
90 { 91 {
91 return new KAddressBookTableView( ab, parent, name ); 92 return new KAddressBookTableView( ab, parent, name );
92 } 93 }
93 94
94 QString type() const { return "Table"; } 95 QString type() const { return "Table"; }
95 96
96 QString description() const { return i18n( "A listing of contacts in a table. Each cell of " 97 QString description() const { return i18n( "A listing of contacts in a table. Each cell of "