summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-01-27 14:46:38 (UTC)
committer zautrix <zautrix>2005-01-27 14:46:38 (UTC)
commit3a6e3862e0b813965f633a51e9a116e5f8f26b23 (patch) (unidiff)
treeea53a2b248257a2a50aee4f6df98749b13401df1
parentcd1b9287f2bcd59652ef66186d00dcf5ff8a2a46 (diff)
downloadkdepimpi-3a6e3862e0b813965f633a51e9a116e5f8f26b23.zip
kdepimpi-3a6e3862e0b813965f633a51e9a116e5f8f26b23.tar.gz
kdepimpi-3a6e3862e0b813965f633a51e9a116e5f8f26b23.tar.bz2
fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kaddressbookview.cpp20
-rw-r--r--kaddressbook/kaddressbookview.h2
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp6
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp6
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp6
5 files changed, 23 insertions, 17 deletions
diff --git a/kaddressbook/kaddressbookview.cpp b/kaddressbook/kaddressbookview.cpp
index 424d52a..09859c2 100644
--- a/kaddressbook/kaddressbookview.cpp
+++ b/kaddressbook/kaddressbookview.cpp
@@ -1,170 +1,186 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef KAB_EMBEDDED 24#ifndef KAB_EMBEDDED
25#include <qapplication.h> 25#include <qapplication.h>
26 26
27#include <kabc/distributionlistdialog.h> 27#include <kabc/distributionlistdialog.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <klocale.h> 29#include <klocale.h>
30 30
31#include "viewmanager.h" 31#include "viewmanager.h"
32 32
33#endif //KAB_EMBEDDED 33#endif //KAB_EMBEDDED
34#include <qlayout.h> 34#include <qlayout.h>
35 35
36#include <kabc/distributionlistdialog.h> 36#include <kabc/distributionlistdialog.h>
37#include <kabc/addressbook.h> 37#include <kabc/addressbook.h>
38#include <kdebug.h> 38#include <kdebug.h>
39 39
40#include "kaddressbookview.h" 40#include "kaddressbookview.h"
41 41
42KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent, 42KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent,
43 const char *name ) 43 const char *name )
44 : QWidget( parent, name ), mAddressBook( ab ), mFieldList() 44 : QWidget( parent, name ), mAddressBook( ab ), mFieldList()
45{ 45{
46 46
47 initGUI(); 47 initGUI();
48} 48}
49 49
50KAddressBookView::~KAddressBookView() 50KAddressBookView::~KAddressBookView()
51{ 51{
52 kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - " 52
53 << name() << endl;
54} 53}
55 54
55QRegExp KAddressBookView::getRegExp( const QString s )
56{
57 QRegExp re;
58
59 if ( s.length() == 3 && s.mid(1,1) == "-" ) {
60 QString pattern = "^[" + s.lower() +"]";
61 re.setCaseSensitive(false);
62 re.setPattern( pattern );
63 } else {
64 QString pattern = s.lower()+"*";
65 re.setWildcard(true); // most people understand these better.
66 re.setCaseSensitive(false);
67 re.setPattern( pattern );
68 }
69 return re;
70}
71
56void KAddressBookView::readConfig( KConfig *config ) 72void KAddressBookView::readConfig( KConfig *config )
57{ 73{
58 mFieldList = KABC::Field::restoreFields( config, "KABCFields" ); 74 mFieldList = KABC::Field::restoreFields( config, "KABCFields" );
59 75
60 if ( mFieldList.isEmpty() ) 76 if ( mFieldList.isEmpty() )
61 mFieldList = KABC::Field::defaultFields(); 77 mFieldList = KABC::Field::defaultFields();
62 78
63 mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 ); 79 mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
64 mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null ); 80 mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null );
65} 81}
66 82
67void KAddressBookView::writeConfig( KConfig* ) 83void KAddressBookView::writeConfig( KConfig* )
68{ 84{
69 // Most of writing the config is handled by the ConfigureViewDialog 85 // Most of writing the config is handled by the ConfigureViewDialog
70} 86}
71 87
72QString KAddressBookView::selectedEmails() 88QString KAddressBookView::selectedEmails()
73{ 89{
74 bool first = true; 90 bool first = true;
75 QString emailAddrs; 91 QString emailAddrs;
76 QStringList uidList = selectedUids(); 92 QStringList uidList = selectedUids();
77 KABC::Addressee addr; 93 KABC::Addressee addr;
78 QString email; 94 QString email;
79 95
80 QStringList::Iterator it; 96 QStringList::Iterator it;
81 for ( it = uidList.begin(); it != uidList.end(); ++it ) { 97 for ( it = uidList.begin(); it != uidList.end(); ++it ) {
82 addr = mAddressBook->findByUid( *it ); 98 addr = mAddressBook->findByUid( *it );
83 99
84 if ( !addr.isEmpty() ) { 100 if ( !addr.isEmpty() ) {
85 QString m = QString::null; 101 QString m = QString::null;
86 102
87 if ( addr.emails().count() > 1 ) 103 if ( addr.emails().count() > 1 )
88 m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this ); 104 m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
89 105
90 email = addr.fullEmail( m ); 106 email = addr.fullEmail( m );
91 107
92 if ( !first ) 108 if ( !first )
93 emailAddrs += ", "; 109 emailAddrs += ", ";
94 else 110 else
95 first = false; 111 first = false;
96 112
97 emailAddrs += email; 113 emailAddrs += email;
98 } 114 }
99 } 115 }
100 116
101 return emailAddrs; 117 return emailAddrs;
102} 118}
103 119
104KABC::Addressee::List KAddressBookView::addressees() 120KABC::Addressee::List KAddressBookView::addressees()
105{ 121{
106 KABC::Addressee::List addresseeList; 122 KABC::Addressee::List addresseeList;
107 123
108 KABC::AddressBook::Iterator it; 124 KABC::AddressBook::Iterator it;
109 for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 125 for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
110 if ( mFilter.filterAddressee( *it ) ) 126 if ( mFilter.filterAddressee( *it ) )
111 addresseeList.append( *it ); 127 addresseeList.append( *it );
112 } 128 }
113 129
114 return addresseeList; 130 return addresseeList;
115} 131}
116 132
117void KAddressBookView::initGUI() 133void KAddressBookView::initGUI()
118{ 134{
119 // Create the layout 135 // Create the layout
120 QVBoxLayout *layout = new QVBoxLayout( this ); 136 QVBoxLayout *layout = new QVBoxLayout( this );
121 137
122 // Add the view widget 138 // Add the view widget
123 mViewWidget = new QWidget( this ); 139 mViewWidget = new QWidget( this );
124 layout->addWidget( mViewWidget ); 140 layout->addWidget( mViewWidget );
125} 141}
126 142
127KABC::Field::List KAddressBookView::fields() const 143KABC::Field::List KAddressBookView::fields() const
128{ 144{
129 return mFieldList; 145 return mFieldList;
130} 146}
131KABC::Field::List KAddressBookView::allFields() const 147KABC::Field::List KAddressBookView::allFields() const
132{ 148{
133 return KABC::Field::allFields(); 149 return KABC::Field::allFields();
134} 150}
135 151
136void KAddressBookView::setFilter( const Filter &filter ) 152void KAddressBookView::setFilter( const Filter &filter )
137{ 153{
138 mFilter = filter; 154 mFilter = filter;
139} 155}
140 156
141KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const 157KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
142{ 158{
143 return mDefaultFilterType; 159 return mDefaultFilterType;
144} 160}
145 161
146const QString &KAddressBookView::defaultFilterName() const 162const QString &KAddressBookView::defaultFilterName() const
147{ 163{
148 return mDefaultFilterName; 164 return mDefaultFilterName;
149} 165}
150 166
151KABC::AddressBook *KAddressBookView::addressBook() const 167KABC::AddressBook *KAddressBookView::addressBook() const
152{ 168{
153 return mAddressBook; 169 return mAddressBook;
154} 170}
155 171
156QWidget *KAddressBookView::viewWidget() 172QWidget *KAddressBookView::viewWidget()
157{ 173{
158 return mViewWidget; 174 return mViewWidget;
159} 175}
160 176
161ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab, 177ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
162 QWidget *parent, 178 QWidget *parent,
163 const char *name ) 179 const char *name )
164{ 180{
165 return new ViewConfigureWidget( ab, parent, name ); 181 return new ViewConfigureWidget( ab, parent, name );
166} 182}
167 183
168#ifndef KAB_EMBEDDED 184#ifndef KAB_EMBEDDED
169#include "kaddressbookview.moc" 185#include "kaddressbookview.moc"
170#endif //KAB_EMBEDDED 186#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h
index 8f31910..6bbb9c2 100644
--- a/kaddressbook/kaddressbookview.h
+++ b/kaddressbook/kaddressbookview.h
@@ -1,310 +1,312 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef KADDRESSBOOKVIEW_H 24#ifndef KADDRESSBOOKVIEW_H
25#define KADDRESSBOOKVIEW_H 25#define KADDRESSBOOKVIEW_H
26 26
27#ifndef KAB_EMBEDDED 27#ifndef KAB_EMBEDDED
28#include <klibloader.h> 28#include <klibloader.h>
29#endif //KAB_EMBEDDED 29#endif //KAB_EMBEDDED
30 30
31class KConfig; 31class KConfig;
32class QDropEvent; 32class QDropEvent;
33 33
34#include <qstringlist.h> 34#include <qstringlist.h>
35#include <kabc/field.h> 35#include <kabc/field.h>
36#include <qwidget.h> 36#include <qwidget.h>
37#include <qregexp.h>
37 38
38#include "viewconfigurewidget.h" 39#include "viewconfigurewidget.h"
39#include "filter.h" 40#include "filter.h"
40 41
41#ifdef DESKTOP_VERSION 42#ifdef DESKTOP_VERSION
42#include <qpaintdevicemetrics.h> 43#include <qpaintdevicemetrics.h>
43#include <qprinter.h> 44#include <qprinter.h>
44#include <qpainter.h> 45#include <qpainter.h>
45#endif 46#endif
46 47
47namespace KABC { class AddressBook; } 48namespace KABC { class AddressBook; }
48 49
49/** 50/**
50 Base class for all views in kaddressbook. This class implements 51 Base class for all views in kaddressbook. This class implements
51 all the common methods needed to provide a view to the user. 52 all the common methods needed to provide a view to the user.
52 53
53 To implement a specific view (table, card, etc), just inherit from 54 To implement a specific view (table, card, etc), just inherit from
54 this class and implement all the pure virtuals. 55 this class and implement all the pure virtuals.
55 56
56 @author Mike Pilone <mpilone@slac.com> 57 @author Mike Pilone <mpilone@slac.com>
57 */ 58 */
58class KAddressBookView : public QWidget 59class KAddressBookView : public QWidget
59{ 60{
60 Q_OBJECT 61 Q_OBJECT
61 62
62 public: 63 public:
63 enum DefaultFilterType { None = 0, Active = 1, Specific = 2 }; 64 enum DefaultFilterType { None = 0, Active = 1, Specific = 2 };
64 65
65 KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name ); 66 KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name );
66 virtual ~KAddressBookView(); 67 virtual ~KAddressBookView();
67 68
68 /** 69 /**
69 Must be overloaded in subclasses. Should return a list of 70 Must be overloaded in subclasses. Should return a list of
70 all the uids of selected contacts. 71 all the uids of selected contacts.
71 */ 72 */
72 virtual QStringList selectedUids() = 0; 73 virtual QStringList selectedUids() = 0;
73 virtual void doSearch( const QString& s ,KABC::Field *field ) = 0; 74 virtual void doSearch( const QString& s ,KABC::Field *field ) = 0;
74 virtual void scrollUP() = 0; 75 virtual void scrollUP() = 0;
75 virtual void scrollDOWN() = 0; 76 virtual void scrollDOWN() = 0;
76 virtual void setFocusAV() = 0; 77 virtual void setFocusAV() = 0;
77 78
78 /** 79 /**
79 Called whenever this view should read the config. This can be used 80 Called whenever this view should read the config. This can be used
80 as a sign that the config has changed, therefore the view should 81 as a sign that the config has changed, therefore the view should
81 assume the worst and rebuild itself if necessary. For example, 82 assume the worst and rebuild itself if necessary. For example,
82 in a table view this method may be called when the user adds or 83 in a table view this method may be called when the user adds or
83 removes columns from the view. 84 removes columns from the view.
84 85
85 If overloaded in the subclass, do not forget to call super class's 86 If overloaded in the subclass, do not forget to call super class's
86 method. 87 method.
87 88
88 @param config The KConfig object to read from. The group will already 89 @param config The KConfig object to read from. The group will already
89 be set, so do not change the group. 90 be set, so do not change the group.
90 */ 91 */
91 virtual void readConfig( KConfig *config ); 92 virtual void readConfig( KConfig *config );
92 93
93 /** 94 /**
94 Called whenever this view should write the config. The view should not 95 Called whenever this view should write the config. The view should not
95 write out information handled by the application, such as which fields 96 write out information handled by the application, such as which fields
96 are visible. The view should only write out information specific 97 are visible. The view should only write out information specific
97 to itself (i.e.: All information in the ViewConfigWidget) 98 to itself (i.e.: All information in the ViewConfigWidget)
98 99
99 If overloaded in the subclass, do not forget to call the super class's 100 If overloaded in the subclass, do not forget to call the super class's
100 method. 101 method.
101 102
102 @param config The KConfig object to read from. The group will already 103 @param config The KConfig object to read from. The group will already
103 be set, so do not change the group. 104 be set, so do not change the group.
104 */ 105 */
105 virtual void writeConfig( KConfig *config ); 106 virtual void writeConfig( KConfig *config );
106 107
107 /** 108 /**
108 Returns a QString with all the selected email addresses concatenated 109 Returns a QString with all the selected email addresses concatenated
109 together with a ',' seperator. 110 together with a ',' seperator.
110 */ 111 */
111 virtual QString selectedEmails(); 112 virtual QString selectedEmails();
112 113
113 /** 114 /**
114 Return the type of the view: Icon, Table, etc. Please make sure that 115 Return the type of the view: Icon, Table, etc. Please make sure that
115 this is the same value that ViewWrapper::type() will return for your 116 this is the same value that ViewWrapper::type() will return for your
116 view. 117 view.
117 */ 118 */
118 virtual QString type() const = 0; 119 virtual QString type() const = 0;
119 120
120 /** 121 /**
121 Returns a list of the fields that should be displayed. The list 122 Returns a list of the fields that should be displayed. The list
122 is composed of the fields proper names (ie: Home Address), so 123 is composed of the fields proper names (ie: Home Address), so
123 the view may need to translate them in order to get the 124 the view may need to translate them in order to get the
124 value from the addressee. 125 value from the addressee.
125 126
126 This list is generated from the config file, so it is advisable to call 127 This list is generated from the config file, so it is advisable to call
127 this method whenever a readConfig() is called in order to get the newest 128 this method whenever a readConfig() is called in order to get the newest
128 list of fields. 129 list of fields.
129 */ 130 */
130 KABC::Field::List fields() const; 131 KABC::Field::List fields() const;
131 132
132 KABC::Field::List allFields() const; 133 KABC::Field::List allFields() const;
133 134
134 /** 135 /**
135 Sets the active filter. This filter will be used for filtering 136 Sets the active filter. This filter will be used for filtering
136 the list of addressees to display. The view will <b>not</b> 137 the list of addressees to display. The view will <b>not</b>
137 automatically refresh itself, so in most cases you will want to call 138 automatically refresh itself, so in most cases you will want to call
138 KAddressBookView::refresh() after this method. 139 KAddressBookView::refresh() after this method.
139 */ 140 */
140 void setFilter( const Filter& ); 141 void setFilter( const Filter& );
141 142
142 /** 143 /**
143 @return The default filter type selection. If the selection 144 @return The default filter type selection. If the selection
144 is SpecificFilter, the name of the filter can be retrieved with 145 is SpecificFilter, the name of the filter can be retrieved with
145 defaultFilterName() 146 defaultFilterName()
146 */ 147 */
147 DefaultFilterType defaultFilterType() const; 148 DefaultFilterType defaultFilterType() const;
148 149
149 /** 150 /**
150 @return The name of the default filter. This string is 151 @return The name of the default filter. This string is
151 only valid if defaultFilterType() is returning SpecificFilter. 152 only valid if defaultFilterType() is returning SpecificFilter.
152 */ 153 */
153 const QString &defaultFilterName() const; 154 const QString &defaultFilterName() const;
154 155
155 /** 156 /**
156 @return The address book. 157 @return The address book.
157 */ 158 */
158 KABC::AddressBook *addressBook() const; 159 KABC::AddressBook *addressBook() const;
159 void printMyView() { emit printView() ;} 160 void printMyView() { emit printView() ;}
160 161
161 public slots: 162 public slots:
162 /** 163 /**
163 Must be overloaded in subclasses to refresh the view. 164 Must be overloaded in subclasses to refresh the view.
164 Refreshing includes updating the view to ensure that only items 165 Refreshing includes updating the view to ensure that only items
165 in the document are visible. If <i>uid</i> is valid, only the 166 in the document are visible. If <i>uid</i> is valid, only the
166 addressee with uid needs to be refreshed. This is an optimization 167 addressee with uid needs to be refreshed. This is an optimization
167 only. 168 only.
168 */ 169 */
169 virtual void refresh( QString uid = QString::null ) = 0; 170 virtual void refresh( QString uid = QString::null ) = 0;
170 171
171 /** 172 /**
172 This method must be overloaded in subclasses. Select (highlight) 173 This method must be overloaded in subclasses. Select (highlight)
173 the addressee matching <i>uid</i>. If uid 174 the addressee matching <i>uid</i>. If uid
174 is equal to QString::null, then all addressees should be selected. 175 is equal to QString::null, then all addressees should be selected.
175 */ 176 */
176#ifndef KAB_EMBEDDED 177#ifndef KAB_EMBEDDED
177//MOC_SKIP_BEGIN 178//MOC_SKIP_BEGIN
178 virtual void setSelected( QString uid = QString::null, bool selected = true ) = 0; 179 virtual void setSelected( QString uid = QString::null, bool selected = true ) = 0;
179//MOC_SKIP_END 180//MOC_SKIP_END
180#else //KAB_EMBEDDED 181#else //KAB_EMBEDDED
181 //US my moc can not handle the default parameters. Is this a problem ??? 182 //US my moc can not handle the default parameters. Is this a problem ???
182 virtual void setSelected( QString uid, bool selected) = 0; 183 virtual void setSelected( QString uid, bool selected) = 0;
183#endif //KAB_EMBEDDED 184#endif //KAB_EMBEDDED
184 185
185 signals: 186 signals:
186 187
187 void printView(); 188 void printView();
188 /** 189 /**
189 This signal should be emitted by a subclass whenever an addressee 190 This signal should be emitted by a subclass whenever an addressee
190 is modified. 191 is modified.
191 */ 192 */
192 void modified(); 193 void modified();
193 194
194 /** 195 /**
195 This signal should be emitted by a subclass whenever an addressee 196 This signal should be emitted by a subclass whenever an addressee
196 is selected. Selected means that the addressee was given the focus. 197 is selected. Selected means that the addressee was given the focus.
197 Some widgets may call this 'highlighted'. The view is responsible for 198 Some widgets may call this 'highlighted'. The view is responsible for
198 emitting this signal multiple times if multiple items are selected, 199 emitting this signal multiple times if multiple items are selected,
199 with the last item selected being the last emit. 200 with the last item selected being the last emit.
200 201
201 @param uid The uid of the selected addressee. 202 @param uid The uid of the selected addressee.
202 203
203 @see KListView 204 @see KListView
204 */ 205 */
205 void selected( const QString &uid ); 206 void selected( const QString &uid );
206 void deleteRequest(); 207 void deleteRequest();
207 /** 208 /**
208 This signal should be emitted by a subclass whenever an addressee 209 This signal should be emitted by a subclass whenever an addressee
209 is executed. This is defined by the KDE system wide config, but it 210 is executed. This is defined by the KDE system wide config, but it
210 either means single or doubleclicked. 211 either means single or doubleclicked.
211 212
212 @param ui The uid of the selected addressee 213 @param ui The uid of the selected addressee
213 214
214 @see KListView 215 @see KListView
215 */ 216 */
216 void executed( const QString &uid ); 217 void executed( const QString &uid );
217 218
218 /** 219 /**
219 This signal is emitted whenever a user attempts to start a drag 220 This signal is emitted whenever a user attempts to start a drag
220 in the view. The slot connected to this signal would usually want 221 in the view. The slot connected to this signal would usually want
221 to create a QDragObject. 222 to create a QDragObject.
222 */ 223 */
223 void startDrag(); 224 void startDrag();
224 225
225 /** 226 /**
226 This signal is emitted whenever the user drops something on the 227 This signal is emitted whenever the user drops something on the
227 view. The individual view should handle checking if the item is 228 view. The individual view should handle checking if the item is
228 droppable (ie: if it is a vcard). 229 droppable (ie: if it is a vcard).
229 */ 230 */
230 void dropped( QDropEvent* ); 231 void dropped( QDropEvent* );
231 232
232 protected: 233 protected:
233 /** 234 /**
234 Returns a list of the addressees that should be displayed. This method 235 Returns a list of the addressees that should be displayed. This method
235 should always be used by the subclass to get a list of addressees. This 236 should always be used by the subclass to get a list of addressees. This
236 method internally takes many factors into account, including the current 237 method internally takes many factors into account, including the current
237 filter. 238 filter.
238 */ 239 */
239 KABC::Addressee::List addressees(); 240 KABC::Addressee::List addressees();
240 241
241 /** 242 /**
242 This method returns the widget that should be used as the parent for 243 This method returns the widget that should be used as the parent for
243 all view components. By using this widget as the parent and not 244 all view components. By using this widget as the parent and not
244 'this', the view subclass has the option of placing other widgets 245 'this', the view subclass has the option of placing other widgets
245 around the view (ie: search fields, etc). Do not delete this widget! 246 around the view (ie: search fields, etc). Do not delete this widget!
246 */ 247 */
247 QWidget *viewWidget(); 248 QWidget *viewWidget();
249 QRegExp getRegExp( const QString );
248 250
249 private: 251 private:
250 void initGUI(); 252 void initGUI();
251 253
252 DefaultFilterType mDefaultFilterType; 254 DefaultFilterType mDefaultFilterType;
253 Filter mFilter; 255 Filter mFilter;
254 QString mDefaultFilterName; 256 QString mDefaultFilterName;
255 KABC::AddressBook *mAddressBook; 257 KABC::AddressBook *mAddressBook;
256 KABC::Field::List mFieldList; 258 KABC::Field::List mFieldList;
257 259
258 QWidget *mViewWidget; 260 QWidget *mViewWidget;
259}; 261};
260 262
261#ifndef KAB_EMBEDDED 263#ifndef KAB_EMBEDDED
262//MOC_SKIP_BEGIN 264//MOC_SKIP_BEGIN
263class ViewFactory : public KLibFactory 265class ViewFactory : public KLibFactory
264//MOC_SKIP_END 266//MOC_SKIP_END
265#else //KAB_EMBEDDED 267#else //KAB_EMBEDDED
266class ViewFactory 268class ViewFactory
267#endif //KAB_EMBEDDED 269#endif //KAB_EMBEDDED
268{ 270{
269 271
270 public: 272 public:
271 virtual KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, 273 virtual KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent,
272 const char *name = 0 ) = 0; 274 const char *name = 0 ) = 0;
273 275
274 /** 276 /**
275 @return The type of the view. This is normally a small one word 277 @return The type of the view. This is normally a small one word
276 string (ie: Table, Icon, Tree, etc). 278 string (ie: Table, Icon, Tree, etc).
277 */ 279 */
278 virtual QString type() const = 0; 280 virtual QString type() const = 0;
279 281
280 /** 282 /**
281 @return The description of the view. This should be a 3 to 283 @return The description of the view. This should be a 3 to
282 4 line string (don't actually use return characters in the string) 284 4 line string (don't actually use return characters in the string)
283 describing the features offered by the view. 285 describing the features offered by the view.
284 */ 286 */
285 virtual QString description() const = 0; 287 virtual QString description() const = 0;
286 288
287 /** 289 /**
288 Creates a config dialog for the view type. The default 290 Creates a config dialog for the view type. The default
289 implementation will return a ViewConfigDialog. This default 291 implementation will return a ViewConfigDialog. This default
290 dialog will allow the user to set the visible fields only. If 292 dialog will allow the user to set the visible fields only. If
291 you need more config options (as most views will), this method 293 you need more config options (as most views will), this method
292 can be overloaded to return your sublcass of ViewConfigDialog. 294 can be overloaded to return your sublcass of ViewConfigDialog.
293 If this method is over loaded the base classes method should 295 If this method is over loaded the base classes method should
294 <B>not</B> be called. 296 <B>not</B> be called.
295 */ 297 */
296 virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, 298 virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab,
297 QWidget *parent, 299 QWidget *parent,
298 const char *name = 0 ); 300 const char *name = 0 );
299 301
300 protected: 302 protected:
301 virtual QObject* createObject( QObject*, const char*, const char*, 303 virtual QObject* createObject( QObject*, const char*, const char*,
302 const QStringList & ) 304 const QStringList & )
303 { 305 {
304 return 0; 306 return 0;
305 } 307 }
306 308
307}; 309};
308 310
309 311
310#endif 312#endif
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 9d8c5ce..2b40909 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -1,507 +1,503 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qdragobject.h> 24#include <qdragobject.h>
25#include <qevent.h> 25#include <qevent.h>
26#include <qiconview.h> 26#include <qiconview.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <qregexp.h> 29#include <qregexp.h>
30#include <qapplication.h> 30#include <qapplication.h>
31 31
32#include <kabc/addressbook.h> 32#include <kabc/addressbook.h>
33#include <kabc/addressee.h> 33#include <kabc/addressee.h>
34#include <kconfig.h> 34#include <kconfig.h>
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37 37
38#include "kabprefs.h" 38#include "kabprefs.h"
39#include "viewmanager.h" 39#include "viewmanager.h"
40 40
41 41
42#include "kaddressbookcardview.h" 42#include "kaddressbookcardview.h"
43 43
44#ifndef KAB_EMBEDDED 44#ifndef KAB_EMBEDDED
45extern "C" { 45extern "C" {
46 void *init_libkaddrbk_cardview() 46 void *init_libkaddrbk_cardview()
47 { 47 {
48 return ( new CardViewFactory ); 48 return ( new CardViewFactory );
49 } 49 }
50} 50}
51#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
52 52
53//////////////////////////////// 53////////////////////////////////
54// AddresseeCardViewItem (internal class) 54// AddresseeCardViewItem (internal class)
55class AddresseeCardViewItem : public CardViewItem 55class AddresseeCardViewItem : public CardViewItem
56{ 56{
57 public: 57 public:
58 AddresseeCardViewItem(const KABC::Field::List &fields, 58 AddresseeCardViewItem(const KABC::Field::List &fields,
59 bool showEmptyFields, 59 bool showEmptyFields,
60 KABC::AddressBook *doc, const KABC::Addressee &a, 60 KABC::AddressBook *doc, const KABC::Addressee &a,
61 CardView *parent) 61 CardView *parent)
62 : CardViewItem(parent, a.formattedName()), 62 : CardViewItem(parent, a.formattedName()),
63 mFields( fields ), mShowEmptyFields(showEmptyFields), 63 mFields( fields ), mShowEmptyFields(showEmptyFields),
64 mDocument(doc), mAddressee(a) 64 mDocument(doc), mAddressee(a)
65 { 65 {
66 if ( mFields.isEmpty() ) { 66 if ( mFields.isEmpty() ) {
67 mFields = KABC::Field::defaultFields(); 67 mFields = KABC::Field::defaultFields();
68 } 68 }
69 refresh(); 69 refresh();
70 } 70 }
71 71
72 const KABC::Addressee &addressee() const { return mAddressee; } 72 const KABC::Addressee &addressee() const { return mAddressee; }
73 73
74 void refresh() 74 void refresh()
75 { 75 {
76 // Update our addressee, since it may have changed elsewhere 76 // Update our addressee, since it may have changed elsewhere
77 mAddressee = mDocument->findByUid(mAddressee.uid()); 77 mAddressee = mDocument->findByUid(mAddressee.uid());
78 78
79 if (!mAddressee.isEmpty()) 79 if (!mAddressee.isEmpty())
80 { 80 {
81 clearFields(); 81 clearFields();
82 82
83 // Try all the selected fields until we find one with text. 83 // Try all the selected fields until we find one with text.
84 // This will limit the number of unlabeled icons in the view 84 // This will limit the number of unlabeled icons in the view
85 KABC::Field::List::Iterator iter; 85 KABC::Field::List::Iterator iter;
86 for (iter = mFields.begin(); iter != mFields.end(); ++iter) 86 for (iter = mFields.begin(); iter != mFields.end(); ++iter)
87 { 87 {
88 // insert empty fields or not? not doing so saves a bit of memory and CPU 88 // insert empty fields or not? not doing so saves a bit of memory and CPU
89 // (during geometry calculations), but prevents having equally 89 // (during geometry calculations), but prevents having equally
90 // wide label columns in all cards, unless CardViewItem/CardView search 90 // wide label columns in all cards, unless CardViewItem/CardView search
91 // globally for the widest label. (anders) 91 // globally for the widest label. (anders)
92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) 92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
93 insertField((*iter)->label(), (*iter)->value( mAddressee )); 93 insertField((*iter)->label(), (*iter)->value( mAddressee ));
94 } 94 }
95 95
96 // We might want to make this the first field. hmm... -mpilone 96 // We might want to make this the first field. hmm... -mpilone
97 setCaption( mAddressee.realName() ); 97 setCaption( mAddressee.realName() );
98 } 98 }
99 } 99 }
100 100
101 private: 101 private:
102 KABC::Field::List mFields; 102 KABC::Field::List mFields;
103 bool mShowEmptyFields; 103 bool mShowEmptyFields;
104 KABC::AddressBook *mDocument; 104 KABC::AddressBook *mDocument;
105 KABC::Addressee mAddressee; 105 KABC::Addressee mAddressee;
106}; 106};
107 107
108/////////////////////////////// 108///////////////////////////////
109// AddresseeCardView 109// AddresseeCardView
110 110
111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
112 : CardView(parent, name) 112 : CardView(parent, name)
113{ 113{
114 setAcceptDrops(true); 114 setAcceptDrops(true);
115} 115}
116 116
117AddresseeCardView::~AddresseeCardView() 117AddresseeCardView::~AddresseeCardView()
118{ 118{
119} 119}
120void AddresseeCardView::printMe() 120void AddresseeCardView::printMe()
121{ 121{
122#ifdef DESKTOP_VERSION 122#ifdef DESKTOP_VERSION
123 QPrinter printer; 123 QPrinter printer;
124 if (!printer.setup() ) 124 if (!printer.setup() )
125 return; 125 return;
126 QPainter p; 126 QPainter p;
127 p.begin ( &printer ); 127 p.begin ( &printer );
128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
129 float dx, dy; 129 float dx, dy;
130 int wid = (m.width() * 9)/10; 130 int wid = (m.width() * 9)/10;
131 dx = (float) wid/(float)contentsWidth (); 131 dx = (float) wid/(float)contentsWidth ();
132 dy = (float)(m.height()) / (float)contentsHeight (); 132 dy = (float)(m.height()) / (float)contentsHeight ();
133 float scale; 133 float scale;
134 // scale to fit the width or height of the paper 134 // scale to fit the width or height of the paper
135 if ( dx < dy ) 135 if ( dx < dy )
136 scale = dx; 136 scale = dx;
137 else 137 else
138 scale = dy; 138 scale = dy;
139 p.translate( m.width()/10,0 ); 139 p.translate( m.width()/10,0 );
140 p.scale( scale, scale ); 140 p.scale( scale, scale );
141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); 141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
142 p.end(); 142 p.end();
143 repaint(); 143 repaint();
144#endif 144#endif
145} 145}
146 146
147 147
148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
149{ 149{
150#ifndef KAB_EMBEDDED 150#ifndef KAB_EMBEDDED
151 if (QTextDrag::canDecode(e)) 151 if (QTextDrag::canDecode(e))
152 e->accept(); 152 e->accept();
153#else //KAB_EMBEDDED 153#else //KAB_EMBEDDED
154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
155#endif //KAB_EMBEDDED 155#endif //KAB_EMBEDDED
156} 156}
157 157
158void AddresseeCardView::dropEvent(QDropEvent *e) 158void AddresseeCardView::dropEvent(QDropEvent *e)
159{ 159{
160 emit addresseeDropped(e); 160 emit addresseeDropped(e);
161} 161}
162 162
163void AddresseeCardView::startDrag() 163void AddresseeCardView::startDrag()
164{ 164{
165 emit startAddresseeDrag(); 165 emit startAddresseeDrag();
166} 166}
167 167
168 168
169/////////////////////////////// 169///////////////////////////////
170// KAddressBookCardView 170// KAddressBookCardView
171 171
172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, 172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
173 QWidget *parent, const char *name ) 173 QWidget *parent, const char *name )
174 : KAddressBookView( ab, parent, name ) 174 : KAddressBookView( ab, parent, name )
175{ 175{
176 mShowEmptyFields = false; 176 mShowEmptyFields = false;
177 177
178 // Init the GUI 178 // Init the GUI
179 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 179 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
180 180
181 mCardView = new AddresseeCardView(viewWidget(), "mCardView"); 181 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
182 mCardView->setSelectionMode(CardView::Extended); 182 mCardView->setSelectionMode(CardView::Extended);
183 layout->addWidget(mCardView); 183 layout->addWidget(mCardView);
184 184
185 // Connect up the signals 185 // Connect up the signals
186 connect(mCardView, SIGNAL(executed(CardViewItem *)), 186 connect(mCardView, SIGNAL(executed(CardViewItem *)),
187 this, SLOT(addresseeExecuted(CardViewItem *))); 187 this, SLOT(addresseeExecuted(CardViewItem *)));
188 connect(mCardView, SIGNAL(selectionChanged()), 188 connect(mCardView, SIGNAL(selectionChanged()),
189 this, SLOT(addresseeSelected())); 189 this, SLOT(addresseeSelected()));
190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), 190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
191 this, SIGNAL(dropped(QDropEvent*))); 191 this, SIGNAL(dropped(QDropEvent*)));
192 connect(mCardView, SIGNAL(startAddresseeDrag()), 192 connect(mCardView, SIGNAL(startAddresseeDrag()),
193 this, SIGNAL(startDrag())); 193 this, SIGNAL(startDrag()));
194 connect(this, SIGNAL(printView()), 194 connect(this, SIGNAL(printView()),
195 mCardView , SLOT(printMe())); 195 mCardView , SLOT(printMe()));
196} 196}
197 197
198KAddressBookCardView::~KAddressBookCardView() 198KAddressBookCardView::~KAddressBookCardView()
199{ 199{
200} 200}
201void KAddressBookCardView::setFocusAV() 201void KAddressBookCardView::setFocusAV()
202{ 202{
203 if ( mCardView ) 203 if ( mCardView )
204 mCardView->setFocus(); 204 mCardView->setFocus();
205 205
206} 206}
207void KAddressBookCardView::scrollUP() 207void KAddressBookCardView::scrollUP()
208{ 208{
209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
210 QApplication::postEvent( mCardView, ev ); 210 QApplication::postEvent( mCardView, ev );
211 211
212} 212}
213void KAddressBookCardView::scrollDOWN() 213void KAddressBookCardView::scrollDOWN()
214{ 214{
215 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 215 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
216 QApplication::postEvent( mCardView, ev ); 216 QApplication::postEvent( mCardView, ev );
217} 217}
218void KAddressBookCardView::readConfig(KConfig *config) 218void KAddressBookCardView::readConfig(KConfig *config)
219{ 219{
220 KAddressBookView::readConfig(config); 220 KAddressBookView::readConfig(config);
221 221
222 // costum colors? 222 // costum colors?
223 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 223 if ( config->readBoolEntry( "EnableCustomColors", false ) )
224 { 224 {
225 QPalette p( mCardView->palette() ); 225 QPalette p( mCardView->palette() );
226 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 226 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
227 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 227 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
228 c = p.color(QPalette::Normal, QColorGroup::Text ); 228 c = p.color(QPalette::Normal, QColorGroup::Text );
229 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 229 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
230 c = p.color(QPalette::Normal, QColorGroup::Button ); 230 c = p.color(QPalette::Normal, QColorGroup::Button );
231 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 231 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
232 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 232 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
233 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 233 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
234 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 234 c = p.color(QPalette::Normal, QColorGroup::Highlight );
235 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 235 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
236 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 236 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
237 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 237 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
238 mCardView->viewport()->setPalette( p ); 238 mCardView->viewport()->setPalette( p );
239 } 239 }
240 else 240 else
241 { 241 {
242 // needed if turned off during a session. 242 // needed if turned off during a session.
243 mCardView->viewport()->setPalette( mCardView->palette() ); 243 mCardView->viewport()->setPalette( mCardView->palette() );
244 } 244 }
245 245
246 //custom fonts? 246 //custom fonts?
247 QFont f( font() ); 247 QFont f( font() );
248 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 248 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
249 { 249 {
250 mCardView->setFont( config->readFontEntry( "TextFont", &f) ); 250 mCardView->setFont( config->readFontEntry( "TextFont", &f) );
251 f.setBold( true ); 251 f.setBold( true );
252 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 252 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
253 } 253 }
254 else 254 else
255 { 255 {
256 mCardView->setFont( f ); 256 mCardView->setFont( f );
257 f.setBold( true ); 257 f.setBold( true );
258 mCardView->setHeaderFont( f ); 258 mCardView->setHeaderFont( f );
259 } 259 }
260 260
261 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); 261 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
262 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", 262 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
263 true)); 263 true));
264 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); 264 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
265 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); 265 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
266 266
267 mCardView->setShowEmptyFields( mShowEmptyFields ); 267 mCardView->setShowEmptyFields( mShowEmptyFields );
268 268
269 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); 269 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
270 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); 270 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
271 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); 271 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
272 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); 272 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
273 273
274#if 0 274#if 0
275 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven 275 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven
276 disconnect(mCardView, SIGNAL(executed(CardViewItem *)), 276 disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
277 this, SLOT(addresseeExecuted(CardViewItem *))); 277 this, SLOT(addresseeExecuted(CardViewItem *)));
278 278
279 if (KABPrefs::instance()->mHonorSingleClick) 279 if (KABPrefs::instance()->mHonorSingleClick)
280 connect(mCardView, SIGNAL(executed(CardViewItem *)), 280 connect(mCardView, SIGNAL(executed(CardViewItem *)),
281 this, SLOT(addresseeExecuted(CardViewItem *))); 281 this, SLOT(addresseeExecuted(CardViewItem *)));
282 else 282 else
283 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 283 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
284 this, SLOT(addresseeExecuted(CardViewItem *))); 284 this, SLOT(addresseeExecuted(CardViewItem *)));
285#endif 285#endif
286 286
287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
288 this, SLOT(addresseeExecuted(CardViewItem *))); 288 this, SLOT(addresseeExecuted(CardViewItem *)));
289} 289}
290 290
291void KAddressBookCardView::writeConfig( KConfig *config ) 291void KAddressBookCardView::writeConfig( KConfig *config )
292{ 292{
293 config->writeEntry( "ItemWidth", mCardView->itemWidth() ); 293 config->writeEntry( "ItemWidth", mCardView->itemWidth() );
294 KAddressBookView::writeConfig( config ); 294 KAddressBookView::writeConfig( config );
295} 295}
296void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) 296void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
297{ 297{
298 mCardView->clear(); 298 mCardView->clear();
299 if ( s.isEmpty() || s == "*" ) { 299 if ( s.isEmpty() || s == "*" ) {
300 refresh(); 300 refresh();
301 return; 301 return;
302 } 302 }
303 QString pattern = s.lower()+"*"; 303 QRegExp re = getRegExp( s );
304 QRegExp re;
305 re.setWildcard(true); // most people understand these better.
306 re.setCaseSensitive(false);
307 re.setPattern( pattern );
308 if (!re.isValid()) 304 if (!re.isValid())
309 return; 305 return;
310 mCardView->viewport()->setUpdatesEnabled( false ); 306 mCardView->viewport()->setUpdatesEnabled( false );
311 KABC::Addressee::List addresseeList = addressees(); 307 KABC::Addressee::List addresseeList = addressees();
312 KABC::Addressee::List::Iterator it; 308 KABC::Addressee::List::Iterator it;
313 if ( field ) { 309 if ( field ) {
314 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 310 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
315 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 311 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
316 continue; 312 continue;
317#if QT_VERSION >= 0x030000 313#if QT_VERSION >= 0x030000
318 if (re.search(field->value( *it ).lower()) != -1) 314 if (re.search(field->value( *it ).lower()) != -1)
319#else 315#else
320 if (re.match(field->value( *it ).lower()) != -1) 316 if (re.match(field->value( *it ).lower()) != -1)
321#endif 317#endif
322 new AddresseeCardViewItem(fields(), mShowEmptyFields, 318 new AddresseeCardViewItem(fields(), mShowEmptyFields,
323 addressBook(), *it, mCardView); 319 addressBook(), *it, mCardView);
324 320
325 } 321 }
326 } else { 322 } else {
327 KABC::Field::List fieldList = allFields(); 323 KABC::Field::List fieldList = allFields();
328 KABC::Field::List::ConstIterator fieldIt; 324 KABC::Field::List::ConstIterator fieldIt;
329 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 325 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
330 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 326 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
331 continue; 327 continue;
332 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 328 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
333#if QT_VERSION >= 0x030000 329#if QT_VERSION >= 0x030000
334 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 330 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
335#else 331#else
336 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 332 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
337#endif 333#endif
338 { 334 {
339 new AddresseeCardViewItem(fields(), mShowEmptyFields, 335 new AddresseeCardViewItem(fields(), mShowEmptyFields,
340 addressBook(), *it, mCardView); 336 addressBook(), *it, mCardView);
341 break; 337 break;
342 } 338 }
343 } 339 }
344 } 340 }
345 } 341 }
346 mCardView->viewport()->setUpdatesEnabled( true ); 342 mCardView->viewport()->setUpdatesEnabled( true );
347 mCardView->viewport()->update(); 343 mCardView->viewport()->update();
348 if ( mCardView->firstItem() ) { 344 if ( mCardView->firstItem() ) {
349 mCardView->setCurrentItem ( mCardView->firstItem() ); 345 mCardView->setCurrentItem ( mCardView->firstItem() );
350 mCardView->setSelected ( mCardView->firstItem() , true ); 346 mCardView->setSelected ( mCardView->firstItem() , true );
351 } 347 }
352 else 348 else
353 emit selected(QString::null); 349 emit selected(QString::null);
354} 350}
355QStringList KAddressBookCardView::selectedUids() 351QStringList KAddressBookCardView::selectedUids()
356{ 352{
357 QStringList uidList; 353 QStringList uidList;
358 CardViewItem *item; 354 CardViewItem *item;
359 AddresseeCardViewItem *aItem; 355 AddresseeCardViewItem *aItem;
360 356
361 for (item = mCardView->firstItem(); item; item = item->nextItem()) 357 for (item = mCardView->firstItem(); item; item = item->nextItem())
362 { 358 {
363 if (item->isSelected()) 359 if (item->isSelected())
364 { 360 {
365#ifndef KAB_EMBEDDED 361#ifndef KAB_EMBEDDED
366 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 362 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
367#else //KAB_EMBEDDED 363#else //KAB_EMBEDDED
368 aItem = (AddresseeCardViewItem*)(item); 364 aItem = (AddresseeCardViewItem*)(item);
369#endif //KAB_EMBEDDED 365#endif //KAB_EMBEDDED
370 if (aItem) 366 if (aItem)
371 uidList << aItem->addressee().uid(); 367 uidList << aItem->addressee().uid();
372 } 368 }
373 } 369 }
374 370
375 return uidList; 371 return uidList;
376} 372}
377 373
378void KAddressBookCardView::refresh(QString uid) 374void KAddressBookCardView::refresh(QString uid)
379{ 375{
380 CardViewItem *item; 376 CardViewItem *item;
381 AddresseeCardViewItem *aItem; 377 AddresseeCardViewItem *aItem;
382 378
383 if (uid.isNull()) 379 if (uid.isNull())
384 { 380 {
385 // Rebuild the view 381 // Rebuild the view
386 mCardView->viewport()->setUpdatesEnabled( false ); 382 mCardView->viewport()->setUpdatesEnabled( false );
387 mCardView->clear(); 383 mCardView->clear();
388 384
389 KABC::Addressee::List addresseeList = addressees(); 385 KABC::Addressee::List addresseeList = addressees();
390 KABC::Addressee::List::Iterator iter; 386 KABC::Addressee::List::Iterator iter;
391 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) 387 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
392 { 388 {
393 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) 389 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
394 continue; 390 continue;
395 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, 391 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
396 addressBook(), *iter, mCardView); 392 addressBook(), *iter, mCardView);
397 } 393 }
398 mCardView->viewport()->setUpdatesEnabled( true ); 394 mCardView->viewport()->setUpdatesEnabled( true );
399 mCardView->viewport()->update(); 395 mCardView->viewport()->update();
400 396
401 // by default nothing is selected 397 // by default nothing is selected
402 emit selected(QString::null); 398 emit selected(QString::null);
403 } 399 }
404 else 400 else
405 { 401 {
406 // Try to find the one to refresh 402 // Try to find the one to refresh
407 bool found = false; 403 bool found = false;
408 for (item = mCardView->firstItem(); item && !found; 404 for (item = mCardView->firstItem(); item && !found;
409 item = item->nextItem()) 405 item = item->nextItem())
410 { 406 {
411#ifndef KAB_EMBEDDED 407#ifndef KAB_EMBEDDED
412 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 408 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
413#else //KAB_EMBEDDED 409#else //KAB_EMBEDDED
414 aItem = (AddresseeCardViewItem*)(item); 410 aItem = (AddresseeCardViewItem*)(item);
415#endif //KAB_EMBEDDED 411#endif //KAB_EMBEDDED
416 412
417 if ((aItem) && (aItem->addressee().uid() == uid)) 413 if ((aItem) && (aItem->addressee().uid() == uid))
418 { 414 {
419 aItem->refresh(); 415 aItem->refresh();
420 found = true; 416 found = true;
421 } 417 }
422 } 418 }
423 } 419 }
424} 420}
425 421
426void KAddressBookCardView::setSelected(QString uid, bool selected) 422void KAddressBookCardView::setSelected(QString uid, bool selected)
427{ 423{
428 CardViewItem *item; 424 CardViewItem *item;
429 AddresseeCardViewItem *aItem; 425 AddresseeCardViewItem *aItem;
430 426
431 if (uid.isNull()) 427 if (uid.isNull())
432 { 428 {
433 mCardView->selectAll(selected); 429 mCardView->selectAll(selected);
434 } 430 }
435 else 431 else
436 { 432 {
437 bool found = false; 433 bool found = false;
438 for (item = mCardView->firstItem(); item && !found; 434 for (item = mCardView->firstItem(); item && !found;
439 item = item->nextItem()) 435 item = item->nextItem())
440 { 436 {
441#ifndef KAB_EMBEDDED 437#ifndef KAB_EMBEDDED
442 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 438 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
443#else //KAB_EMBEDDED 439#else //KAB_EMBEDDED
444 aItem = (AddresseeCardViewItem*)(item); 440 aItem = (AddresseeCardViewItem*)(item);
445#endif //KAB_EMBEDDED 441#endif //KAB_EMBEDDED
446 442
447 if ((aItem) && (aItem->addressee().uid() == uid)) 443 if ((aItem) && (aItem->addressee().uid() == uid))
448 { 444 {
449 mCardView->setSelected(aItem, selected); 445 mCardView->setSelected(aItem, selected);
450 mCardView->ensureItemVisible(item); 446 mCardView->ensureItemVisible(item);
451 found = true; 447 found = true;
452 } 448 }
453 } 449 }
454 } 450 }
455} 451}
456 452
457//US added an additional method without parameter 453//US added an additional method without parameter
458void KAddressBookCardView::setSelected() 454void KAddressBookCardView::setSelected()
459{ 455{
460 setSelected(QString::null, true); 456 setSelected(QString::null, true);
461} 457}
462 458
463void KAddressBookCardView::addresseeExecuted(CardViewItem *item) 459void KAddressBookCardView::addresseeExecuted(CardViewItem *item)
464{ 460{
465#ifndef KAB_EMBEDDED 461#ifndef KAB_EMBEDDED
466 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); 462 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item);
467#else //KAB_EMBEDDED 463#else //KAB_EMBEDDED
468 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); 464 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item);
469#endif //KAB_EMBEDDED 465#endif //KAB_EMBEDDED
470 if (aItem) 466 if (aItem)
471 { 467 {
472 //kdDebug()<<"... even has a valid item:)"<<endl; 468 //kdDebug()<<"... even has a valid item:)"<<endl;
473 emit executed(aItem->addressee().uid()); 469 emit executed(aItem->addressee().uid());
474 } 470 }
475} 471}
476 472
477void KAddressBookCardView::addresseeSelected() 473void KAddressBookCardView::addresseeSelected()
478{ 474{
479 CardViewItem *item; 475 CardViewItem *item;
480 AddresseeCardViewItem *aItem; 476 AddresseeCardViewItem *aItem;
481 477
482 bool found = false; 478 bool found = false;
483 for (item = mCardView->firstItem(); item && !found; 479 for (item = mCardView->firstItem(); item && !found;
484 item = item->nextItem()) 480 item = item->nextItem())
485 { 481 {
486 if (item->isSelected()) 482 if (item->isSelected())
487 { 483 {
488#ifndef KAB_EMBEDDED 484#ifndef KAB_EMBEDDED
489 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 485 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
490#else //KAB_EMBEDDED 486#else //KAB_EMBEDDED
491 aItem = (AddresseeCardViewItem*)(item); 487 aItem = (AddresseeCardViewItem*)(item);
492#endif //KAB_EMBEDDED 488#endif //KAB_EMBEDDED
493 if ( aItem ) 489 if ( aItem )
494 { 490 {
495 emit selected(aItem->addressee().uid()); 491 emit selected(aItem->addressee().uid());
496 found = true; 492 found = true;
497 } 493 }
498 } 494 }
499 } 495 }
500 496
501 if (!found) 497 if (!found)
502 emit selected(QString::null); 498 emit selected(QString::null);
503 499
504} 500}
505#ifndef KAB_EMBEDDED 501#ifndef KAB_EMBEDDED
506#include "kaddressbookcardview.moc" 502#include "kaddressbookcardview.moc"
507#endif //KAB_EMBEDDED 503#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp
index fb53215..3bdfd1a 100644
--- a/kaddressbook/views/kaddressbookiconview.cpp
+++ b/kaddressbook/views/kaddressbookiconview.cpp
@@ -1,456 +1,452 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef KAB_EMBEDDED 24#ifndef KAB_EMBEDDED
25#include <qiconview.h> 25#include <qiconview.h>
26#include <qstringlist.h> 26#include <qstringlist.h>
27 27
28#include <kabc/addressee.h> 28#include <kabc/addressee.h>
29#include <kconfig.h> 29#include <kconfig.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kiconloader.h> 32#include <kiconloader.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#else //KAB_EMBEDDED 35#else //KAB_EMBEDDED
36#endif //KAB_EMBEDDED 36#endif //KAB_EMBEDDED
37 37
38#include <kabc/addressbook.h> 38#include <kabc/addressbook.h>
39#include "kabprefs.h" 39#include "kabprefs.h"
40#include "viewmanager.h" 40#include "viewmanager.h"
41#include "kaddressbookiconview.h" 41#include "kaddressbookiconview.h"
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qapplication.h> 44#include <qapplication.h>
45#include <kglobal.h> 45#include <kglobal.h>
46/*US transfered to the headerfile 46/*US transfered to the headerfile
47class IconViewFactory : public ViewFactory 47class IconViewFactory : public ViewFactory
48{ 48{
49 public: 49 public:
50 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) 50 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
51 { 51 {
52 return new KAddressBookIconView( ab, parent, name ); 52 return new KAddressBookIconView( ab, parent, name );
53 } 53 }
54 54
55 QString type() const { return "Icon"; } 55 QString type() const { return "Icon"; }
56 56
57 QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } 57 QString description() const { return i18n( "Icons represent contacts. Very simple view." ); }
58}; 58};
59 59
60*/ 60*/
61 61
62extern "C" { 62extern "C" {
63 void *init_libkaddrbk_iconview() 63 void *init_libkaddrbk_iconview()
64 { 64 {
65 return ( new IconViewFactory ); 65 return ( new IconViewFactory );
66 } 66 }
67} 67}
68 68
69//////////////////////////////// 69////////////////////////////////
70// AddresseeIconView (internal class) 70// AddresseeIconView (internal class)
71#ifndef KAB_EMBEDDED 71#ifndef KAB_EMBEDDED
72AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) 72AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
73 : KIconView(parent, name) 73 : KIconView(parent, name)
74#else //KAB_EMBEDDED 74#else //KAB_EMBEDDED
75AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) 75AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
76 : QIconView(parent, name) 76 : QIconView(parent, name)
77#endif //KAB_EMBEDDED 77#endif //KAB_EMBEDDED
78 78
79{ 79{
80 setSelectionMode( QIconView::Extended ); 80 setSelectionMode( QIconView::Extended );
81 setResizeMode( QIconView::Adjust ); 81 setResizeMode( QIconView::Adjust );
82 setWordWrapIconText( true ); 82 setWordWrapIconText( true );
83 setGridX( 100 ); 83 setGridX( 100 );
84 setItemsMovable(false); 84 setItemsMovable(false);
85 setSorting(true, true); 85 setSorting(true, true);
86 86
87 87
88//US ??? setMode( KIconView::Select ); 88//US ??? setMode( KIconView::Select );
89 89
90#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
91 91
92 connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)), 92 connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)),
93 this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&))); 93 this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&)));
94#endif //KAB_EMBEDDED 94#endif //KAB_EMBEDDED
95} 95}
96 96
97AddresseeIconView::~AddresseeIconView() 97AddresseeIconView::~AddresseeIconView()
98{ 98{
99} 99}
100 100
101 101
102void AddresseeIconView::itemDropped(QDropEvent *e, 102void AddresseeIconView::itemDropped(QDropEvent *e,
103 const QValueList<QIconDragItem> &) 103 const QValueList<QIconDragItem> &)
104{ 104{
105 emit addresseeDropped(e); 105 emit addresseeDropped(e);
106} 106}
107 107
108QDragObject *AddresseeIconView::dragObject() 108QDragObject *AddresseeIconView::dragObject()
109{ 109{
110 emit startAddresseeDrag(); 110 emit startAddresseeDrag();
111 111
112 // We never want IconView to start the drag 112 // We never want IconView to start the drag
113 return 0; 113 return 0;
114} 114}
115//////////////////////////////// 115////////////////////////////////
116// AddresseeIconViewItem (internal class) 116// AddresseeIconViewItem (internal class)
117#ifndef KAB_EMBEDDED 117#ifndef KAB_EMBEDDED
118class AddresseeIconViewItem : public KIconViewItem 118class AddresseeIconViewItem : public KIconViewItem
119#else //KAB_EMBEDDED 119#else //KAB_EMBEDDED
120class AddresseeIconViewItem : public QIconViewItem 120class AddresseeIconViewItem : public QIconViewItem
121#endif //KAB_EMBEDDED 121#endif //KAB_EMBEDDED
122{ 122{
123 public: 123 public:
124#ifndef KAB_EMBEDDED 124#ifndef KAB_EMBEDDED
125 AddresseeIconViewItem(const KABC::Field::List &fields, 125 AddresseeIconViewItem(const KABC::Field::List &fields,
126 KABC::AddressBook *doc, const KABC::Addressee &a, 126 KABC::AddressBook *doc, const KABC::Addressee &a,
127 QIconView *parent) 127 QIconView *parent)
128 : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) 128 : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
129#else //KAB_EMBEDDED 129#else //KAB_EMBEDDED
130 AddresseeIconViewItem(const KABC::Field::List &fields, 130 AddresseeIconViewItem(const KABC::Field::List &fields,
131 KABC::AddressBook *doc, const KABC::Addressee &a, 131 KABC::AddressBook *doc, const KABC::Addressee &a,
132 QIconView *parent) 132 QIconView *parent)
133 : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) 133 : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
134#endif //KAB_EMBEDDED 134#endif //KAB_EMBEDDED
135 { 135 {
136 if ( mFields.isEmpty() ) { 136 if ( mFields.isEmpty() ) {
137 mFields = KABC::Field::defaultFields(); 137 mFields = KABC::Field::defaultFields();
138 } 138 }
139 refresh(); 139 refresh();
140 } 140 }
141 141
142 const KABC::Addressee &addressee() const { return mAddressee; } 142 const KABC::Addressee &addressee() const { return mAddressee; }
143 143
144 void refresh() 144 void refresh()
145 { 145 {
146 // Update our addressee, since it may have changed elsewhere 146 // Update our addressee, since it may have changed elsewhere
147 mAddressee = mDocument->findByUid(mAddressee.uid()); 147 mAddressee = mDocument->findByUid(mAddressee.uid());
148 148
149 if (!mAddressee.isEmpty()) 149 if (!mAddressee.isEmpty())
150 setText( mAddressee.givenName() + " " + mAddressee.familyName() ); 150 setText( mAddressee.givenName() + " " + mAddressee.familyName() );
151 151
152 QPixmap icon; 152 QPixmap icon;
153 QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) ); 153 QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) );
154 KABC::Picture pic = mAddressee.photo(); 154 KABC::Picture pic = mAddressee.photo();
155 if ( pic.data().isNull() ) 155 if ( pic.data().isNull() )
156 pic = mAddressee.logo(); 156 pic = mAddressee.logo();
157 157
158 if ( pic.isIntern() && !pic.data().isNull() ) { 158 if ( pic.isIntern() && !pic.data().isNull() ) {
159 QImage img = pic.data(); 159 QImage img = pic.data();
160#ifndef KAB_EMBEDDED 160#ifndef KAB_EMBEDDED
161 if ( img.width() > img.height() ) 161 if ( img.width() > img.height() )
162 icon = img.scaleWidth( 32 ); 162 icon = img.scaleWidth( 32 );
163 else 163 else
164 icon = img.scaleHeight( 32 ); 164 icon = img.scaleHeight( 32 );
165#else //KAB_EMBEDDED 165#else //KAB_EMBEDDED
166 qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor"); 166 qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor");
167 icon.convertFromImage(img.smoothScale(32, 32)); 167 icon.convertFromImage(img.smoothScale(32, 32));
168#endif //KAB_EMBEDDED 168#endif //KAB_EMBEDDED
169 169
170 } else 170 } else
171 icon = defaultIcon; 171 icon = defaultIcon;
172 172
173 setPixmap( icon ); 173 setPixmap( icon );
174 } 174 }
175 175
176 private: 176 private:
177 KABC::Field::List mFields; 177 KABC::Field::List mFields;
178 KABC::AddressBook *mDocument; 178 KABC::AddressBook *mDocument;
179 KABC::Addressee mAddressee; 179 KABC::Addressee mAddressee;
180}; 180};
181 181
182/////////////////////////////// 182///////////////////////////////
183// KAddressBookView 183// KAddressBookView
184 184
185KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab, 185KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
186 QWidget *parent, const char *name) 186 QWidget *parent, const char *name)
187 : KAddressBookView( ab, parent, name ) 187 : KAddressBookView( ab, parent, name )
188{ 188{
189 // Init the GUI 189 // Init the GUI
190 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 190 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
191 191
192 mIconView = new AddresseeIconView(viewWidget(), "mIconView"); 192 mIconView = new AddresseeIconView(viewWidget(), "mIconView");
193 layout->addWidget(mIconView); 193 layout->addWidget(mIconView);
194 194
195 // Connect up the signals 195 // Connect up the signals
196 196
197//US method executed is part of KIconView 197//US method executed is part of KIconView
198//US connect(mIconView, SIGNAL(executed(QIconViewItem *)), 198//US connect(mIconView, SIGNAL(executed(QIconViewItem *)),
199//US this, SLOT(addresseeExecuted(QIconViewItem *))); 199//US this, SLOT(addresseeExecuted(QIconViewItem *)));
200 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 200 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
201 this, SLOT(addresseeExecuted(QIconViewItem *))); 201 this, SLOT(addresseeExecuted(QIconViewItem *)));
202 202
203 connect(mIconView, SIGNAL(selectionChanged()), 203 connect(mIconView, SIGNAL(selectionChanged()),
204 this, SLOT(addresseeSelected())); 204 this, SLOT(addresseeSelected()));
205 connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)), 205 connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)),
206 this, SIGNAL(dropped(QDropEvent*))); 206 this, SIGNAL(dropped(QDropEvent*)));
207 connect(mIconView, SIGNAL(startAddresseeDrag()), 207 connect(mIconView, SIGNAL(startAddresseeDrag()),
208 this, SIGNAL(startDrag())); 208 this, SIGNAL(startDrag()));
209} 209}
210 210
211KAddressBookIconView::~KAddressBookIconView() 211KAddressBookIconView::~KAddressBookIconView()
212{ 212{
213} 213}
214void KAddressBookIconView::setFocusAV() 214void KAddressBookIconView::setFocusAV()
215{ 215{
216 if ( mIconView ) 216 if ( mIconView )
217 mIconView->setFocus(); 217 mIconView->setFocus();
218} 218}
219 219
220 220
221void KAddressBookIconView::scrollUP() 221void KAddressBookIconView::scrollUP()
222{ 222{
223 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 223 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
224 QApplication::postEvent( mIconView, ev ); 224 QApplication::postEvent( mIconView, ev );
225} 225}
226void KAddressBookIconView::scrollDOWN() 226void KAddressBookIconView::scrollDOWN()
227{ 227{
228 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 228 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
229 QApplication::postEvent( mIconView, ev ); 229 QApplication::postEvent( mIconView, ev );
230} 230}
231void KAddressBookIconView::readConfig(KConfig *config) 231void KAddressBookIconView::readConfig(KConfig *config)
232{ 232{
233 KAddressBookView::readConfig(config); 233 KAddressBookView::readConfig(config);
234 234
235//US method executed is part of KIconView 235//US method executed is part of KIconView
236//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), 236//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)),
237//US this, SLOT(addresseeExecuted(QIconViewItem *))); 237//US this, SLOT(addresseeExecuted(QIconViewItem *)));
238 disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 238 disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
239 this, SLOT(addresseeExecuted(QIconViewItem *))); 239 this, SLOT(addresseeExecuted(QIconViewItem *)));
240 240
241//US method executed is part of KIconView. Use selectionChanged instead 241//US method executed is part of KIconView. Use selectionChanged instead
242/*US 242/*US
243 if (KABPrefs::instance()->mHonorSingleClick) 243 if (KABPrefs::instance()->mHonorSingleClick)
244 connect(mIconView, SIGNAL(executed(QIconViewItem *)), 244 connect(mIconView, SIGNAL(executed(QIconViewItem *)),
245 this, SLOT(addresseeExecuted(QIconViewItem *))); 245 this, SLOT(addresseeExecuted(QIconViewItem *)));
246 else 246 else
247 connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), 247 connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)),
248 this, SLOT(addresseeExecuted(QIconViewItem *))); 248 this, SLOT(addresseeExecuted(QIconViewItem *)));
249*/ 249*/
250 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 250 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
251 this, SLOT(addresseeExecuted(QIconViewItem *))); 251 this, SLOT(addresseeExecuted(QIconViewItem *)));
252 252
253} 253}
254void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) 254void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
255{ 255{
256 mIconView->clear(); 256 mIconView->clear();
257 mIconList.clear(); 257 mIconList.clear();
258 if ( s.isEmpty() || s == "*" ) { 258 if ( s.isEmpty() || s == "*" ) {
259 refresh(); 259 refresh();
260 return; 260 return;
261 } 261 }
262 QString pattern = s.lower()+"*"; 262 QRegExp re = getRegExp( s );
263 QRegExp re;
264 re.setWildcard(true); // most people understand these better.
265 re.setCaseSensitive(false);
266 re.setPattern( pattern );
267 if (!re.isValid()) 263 if (!re.isValid())
268 return; 264 return;
269 KABC::Addressee::List addresseeList = addressees(); 265 KABC::Addressee::List addresseeList = addressees();
270 KABC::Addressee::List::Iterator it; 266 KABC::Addressee::List::Iterator it;
271 if ( field ) { 267 if ( field ) {
272 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 268 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
273 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 269 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
274 continue; 270 continue;
275#if QT_VERSION >= 0x030000 271#if QT_VERSION >= 0x030000
276 if (re.search(field->value( *it ).lower()) != -1) 272 if (re.search(field->value( *it ).lower()) != -1)
277#else 273#else
278 if (re.match(field->value( *it ).lower()) != -1) 274 if (re.match(field->value( *it ).lower()) != -1)
279#endif 275#endif
280 mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); 276 mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
281 277
282 278
283 } 279 }
284 } else { 280 } else {
285 KABC::Field::List fieldList = allFields(); 281 KABC::Field::List fieldList = allFields();
286 KABC::Field::List::ConstIterator fieldIt; 282 KABC::Field::List::ConstIterator fieldIt;
287 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 283 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
288 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 284 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
289 continue; 285 continue;
290 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 286 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
291#if QT_VERSION >= 0x030000 287#if QT_VERSION >= 0x030000
292 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 288 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
293#else 289#else
294 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 290 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
295#endif 291#endif
296 { 292 {
297 mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); 293 mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
298 break; 294 break;
299 } 295 }
300 } 296 }
301 } 297 }
302 } 298 }
303 mIconView->arrangeItemsInGrid( true ); 299 mIconView->arrangeItemsInGrid( true );
304 if ( mIconView->firstItem() ) { 300 if ( mIconView->firstItem() ) {
305 mIconView->setCurrentItem ( mIconView->firstItem() ); 301 mIconView->setCurrentItem ( mIconView->firstItem() );
306 mIconView->setSelected ( mIconView->firstItem() , true ); 302 mIconView->setSelected ( mIconView->firstItem() , true );
307 } 303 }
308 else 304 else
309 emit selected(QString::null); 305 emit selected(QString::null);
310} 306}
311QStringList KAddressBookIconView::selectedUids() 307QStringList KAddressBookIconView::selectedUids()
312{ 308{
313 QStringList uidList; 309 QStringList uidList;
314 QIconViewItem *item; 310 QIconViewItem *item;
315 AddresseeIconViewItem *aItem; 311 AddresseeIconViewItem *aItem;
316 312
317 for (item = mIconView->firstItem(); item; item = item->nextItem()) 313 for (item = mIconView->firstItem(); item; item = item->nextItem())
318 { 314 {
319 if (item->isSelected()) 315 if (item->isSelected())
320 { 316 {
321#ifndef KAB_EMBEDDED 317#ifndef KAB_EMBEDDED
322 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 318 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
323#else //KAB_EMBEDDED 319#else //KAB_EMBEDDED
324 aItem = (AddresseeIconViewItem*)(item); 320 aItem = (AddresseeIconViewItem*)(item);
325#endif //KAB_EMBEDDED 321#endif //KAB_EMBEDDED
326 if (aItem) 322 if (aItem)
327 uidList << aItem->addressee().uid(); 323 uidList << aItem->addressee().uid();
328 } 324 }
329 } 325 }
330 326
331 return uidList; 327 return uidList;
332} 328}
333 329
334void KAddressBookIconView::refresh(QString uid) 330void KAddressBookIconView::refresh(QString uid)
335{ 331{
336 QIconViewItem *item; 332 QIconViewItem *item;
337 AddresseeIconViewItem *aItem; 333 AddresseeIconViewItem *aItem;
338 334
339 if ( uid.isNull() ) { 335 if ( uid.isNull() ) {
340 // Rebuild the view 336 // Rebuild the view
341 mIconView->clear(); 337 mIconView->clear();
342 mIconList.clear(); 338 mIconList.clear();
343 339
344 KABC::Addressee::List addresseeList = addressees(); 340 KABC::Addressee::List addresseeList = addressees();
345 KABC::Addressee::List::Iterator iter; 341 KABC::Addressee::List::Iterator iter;
346 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) { 342 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) {
347 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) 343 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
348 continue; 344 continue;
349 aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView ); 345 aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView );
350 } 346 }
351 347
352 mIconView->arrangeItemsInGrid( true ); 348 mIconView->arrangeItemsInGrid( true );
353 349
354 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) 350 for ( item = mIconView->firstItem(); item; item = item->nextItem() )
355 { 351 {
356#ifndef KAB_EMBEDDED 352#ifndef KAB_EMBEDDED
357 AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item ); 353 AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item );
358#else //KAB_EMBEDDED 354#else //KAB_EMBEDDED
359 AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item ); 355 AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item );
360#endif //KAB_EMBEDDED 356#endif //KAB_EMBEDDED
361 mIconList.append( aivi ); 357 mIconList.append( aivi );
362 } 358 }
363 359
364 } else { 360 } else {
365 // Try to find the one to refresh 361 // Try to find the one to refresh
366 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { 362 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) {
367#ifndef KAB_EMBEDDED 363#ifndef KAB_EMBEDDED
368 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 364 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
369#else //KAB_EMBEDDED 365#else //KAB_EMBEDDED
370 aItem = (AddresseeIconViewItem*)(item); 366 aItem = (AddresseeIconViewItem*)(item);
371#endif //KAB_EMBEDDED 367#endif //KAB_EMBEDDED
372 if ((aItem) && (aItem->addressee().uid() == uid)) { 368 if ((aItem) && (aItem->addressee().uid() == uid)) {
373 aItem->refresh(); 369 aItem->refresh();
374 mIconView->arrangeItemsInGrid( true ); 370 mIconView->arrangeItemsInGrid( true );
375 return; 371 return;
376 } 372 }
377 } 373 }
378 refresh( QString::null ); 374 refresh( QString::null );
379 } 375 }
380} 376}
381 377
382void KAddressBookIconView::setSelected(QString uid, bool selected) 378void KAddressBookIconView::setSelected(QString uid, bool selected)
383{ 379{
384 QIconViewItem *item; 380 QIconViewItem *item;
385 AddresseeIconViewItem *aItem; 381 AddresseeIconViewItem *aItem;
386 382
387 if (uid.isNull()) 383 if (uid.isNull())
388 { 384 {
389 mIconView->selectAll(selected); 385 mIconView->selectAll(selected);
390 } 386 }
391 else 387 else
392 { 388 {
393 bool found = false; 389 bool found = false;
394 for (item = mIconView->firstItem(); item && !found; 390 for (item = mIconView->firstItem(); item && !found;
395 item = item->nextItem()) 391 item = item->nextItem())
396 { 392 {
397#ifndef KAB_EMBEDDED 393#ifndef KAB_EMBEDDED
398 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 394 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
399#else //KAB_EMBEDDED 395#else //KAB_EMBEDDED
400 aItem = (AddresseeIconViewItem*)(item); 396 aItem = (AddresseeIconViewItem*)(item);
401#endif //KAB_EMBEDDED 397#endif //KAB_EMBEDDED
402 398
403 if ((aItem) && (aItem->addressee().uid() == uid)) 399 if ((aItem) && (aItem->addressee().uid() == uid))
404 { 400 {
405 mIconView->setSelected(aItem, selected); 401 mIconView->setSelected(aItem, selected);
406 mIconView->ensureItemVisible( aItem ); 402 mIconView->ensureItemVisible( aItem );
407 found = true; 403 found = true;
408 } 404 }
409 } 405 }
410 } 406 }
411} 407}
412 408
413void KAddressBookIconView::addresseeExecuted(QIconViewItem *item) 409void KAddressBookIconView::addresseeExecuted(QIconViewItem *item)
414{ 410{
415#ifndef KAB_EMBEDDED 411#ifndef KAB_EMBEDDED
416 AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item); 412 AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item);
417#else //KAB_EMBEDDED 413#else //KAB_EMBEDDED
418 AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item); 414 AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item);
419#endif //KAB_EMBEDDED 415#endif //KAB_EMBEDDED
420 416
421 if (aItem) { 417 if (aItem) {
422 emit executed(aItem->addressee().uid()); 418 emit executed(aItem->addressee().uid());
423 } 419 }
424} 420}
425 421
426void KAddressBookIconView::addresseeSelected() 422void KAddressBookIconView::addresseeSelected()
427{ 423{
428 QIconViewItem *item; 424 QIconViewItem *item;
429 AddresseeIconViewItem *aItem; 425 AddresseeIconViewItem *aItem;
430 426
431 bool found = false; 427 bool found = false;
432 for (item = mIconView->firstItem(); item && !found; 428 for (item = mIconView->firstItem(); item && !found;
433 item = item->nextItem()) 429 item = item->nextItem())
434 { 430 {
435 if (item->isSelected()) 431 if (item->isSelected())
436 { 432 {
437#ifndef KAB_EMBEDDED 433#ifndef KAB_EMBEDDED
438 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 434 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
439#else //KAB_EMBEDDED 435#else //KAB_EMBEDDED
440 aItem = (AddresseeIconViewItem*)(item); 436 aItem = (AddresseeIconViewItem*)(item);
441#endif //KAB_EMBEDDED 437#endif //KAB_EMBEDDED
442 if (aItem) 438 if (aItem)
443 { 439 {
444 emit selected(aItem->addressee().uid()); 440 emit selected(aItem->addressee().uid());
445 found = true; 441 found = true;
446 } 442 }
447 } 443 }
448 } 444 }
449 445
450 if (!found) 446 if (!found)
451 emit selected(QString::null); 447 emit selected(QString::null);
452} 448}
453 449
454#ifndef KAB_EMBEDDED 450#ifndef KAB_EMBEDDED
455#include "kaddressbookiconview.moc" 451#include "kaddressbookiconview.moc"
456#endif //KAB_EMBEDDED 452#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index b73ceaa..f4b008c 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -1,474 +1,470 @@
1// $Id$ 1// $Id$
2 2
3#include <qvbox.h> 3#include <qvbox.h>
4#include <qlistbox.h> 4#include <qlistbox.h>
5#include <qwidget.h> 5#include <qwidget.h>
6#include <qfile.h> 6#include <qfile.h>
7#include <qimage.h> 7#include <qimage.h>
8#include <qcombobox.h> 8#include <qcombobox.h>
9#include <qapplication.h> 9#include <qapplication.h>
10#include <qdragobject.h> 10#include <qdragobject.h>
11#include <qevent.h> 11#include <qevent.h>
12#include <qurl.h> 12#include <qurl.h>
13#include <qpixmap.h> 13#include <qpixmap.h>
14 14
15#include <kabc/addressbook.h> 15#include <kabc/addressbook.h>
16#include <kapplication.h> 16#include <kapplication.h>
17#include <kconfig.h> 17#include <kconfig.h>
18#include <kcolorbutton.h> 18#include <kcolorbutton.h>
19#include <kdebug.h> 19#include <kdebug.h>
20#include <kglobal.h> 20#include <kglobal.h>
21#include <kiconloader.h> 21#include <kiconloader.h>
22#include <klineedit.h> 22#include <klineedit.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kmessagebox.h> 24#include <kmessagebox.h>
25#include <kurl.h> 25#include <kurl.h>
26#include <kurlrequester.h> 26#include <kurlrequester.h>
27 27
28//US#include "configuretableviewdialog.h" 28//US#include "configuretableviewdialog.h"
29#include "contactlistview.h" 29#include "contactlistview.h"
30#include "kabprefs.h" 30#include "kabprefs.h"
31#include "undocmds.h" 31#include "undocmds.h"
32#include "viewmanager.h" 32#include "viewmanager.h"
33 33
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qheader.h> 35#include <qheader.h>
36#include <qregexp.h> 36#include <qregexp.h>
37 37
38#include "kaddressbooktableview.h" 38#include "kaddressbooktableview.h"
39 39
40 40
41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, 41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
42 QWidget *parent, const char *name ) 42 QWidget *parent, const char *name )
43 : KAddressBookView( ab, parent, name ) 43 : KAddressBookView( ab, parent, name )
44{ 44{
45 mainLayout = new QVBoxLayout( viewWidget(), 2 ); 45 mainLayout = new QVBoxLayout( viewWidget(), 2 );
46 46
47 // The list view will be created when the config is read. 47 // The list view will be created when the config is read.
48 mListView = 0; 48 mListView = 0;
49} 49}
50 50
51KAddressBookTableView::~KAddressBookTableView() 51KAddressBookTableView::~KAddressBookTableView()
52{ 52{
53} 53}
54void KAddressBookTableView::setFocusAV() 54void KAddressBookTableView::setFocusAV()
55{ 55{
56 if ( mListView ) 56 if ( mListView )
57 mListView->setFocus(); 57 mListView->setFocus();
58 58
59} 59}
60void KAddressBookTableView::scrollUP() 60void KAddressBookTableView::scrollUP()
61{ 61{
62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
63 QApplication::postEvent( mListView, ev ); 63 QApplication::postEvent( mListView, ev );
64} 64}
65void KAddressBookTableView::scrollDOWN() 65void KAddressBookTableView::scrollDOWN()
66{ 66{
67 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 67 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
68 QApplication::postEvent( mListView, ev ); 68 QApplication::postEvent( mListView, ev );
69} 69}
70void KAddressBookTableView::reconstructListView() 70void KAddressBookTableView::reconstructListView()
71{ 71{
72 if (mListView) 72 if (mListView)
73 { 73 {
74 disconnect(mListView, SIGNAL(selectionChanged()), 74 disconnect(mListView, SIGNAL(selectionChanged()),
75 this, SLOT(addresseeSelected())); 75 this, SLOT(addresseeSelected()));
76 disconnect(mListView, SIGNAL(executed(QListViewItem*)), 76 disconnect(mListView, SIGNAL(executed(QListViewItem*)),
77 this, SLOT(addresseeExecuted(QListViewItem*))); 77 this, SLOT(addresseeExecuted(QListViewItem*)));
78 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 78 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
79 this, SLOT(addresseeExecuted(QListViewItem*))); 79 this, SLOT(addresseeExecuted(QListViewItem*)));
80 disconnect(mListView, SIGNAL(startAddresseeDrag()), this, 80 disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
81 SIGNAL(startDrag())); 81 SIGNAL(startDrag()));
82 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), 82 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
83 this, SLOT(addresseeExecuted(QListViewItem*))); 83 this, SLOT(addresseeExecuted(QListViewItem*)));
84 84
85 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 85 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
86 SIGNAL(dropped(QDropEvent*))); 86 SIGNAL(dropped(QDropEvent*)));
87 delete mListView; 87 delete mListView;
88 } 88 }
89 89
90 mListView = new ContactListView( this, addressBook(), viewWidget() ); 90 mListView = new ContactListView( this, addressBook(), viewWidget() );
91 91
92 connect(this, SIGNAL(printView()), 92 connect(this, SIGNAL(printView()),
93 mListView , SLOT(printMe())); 93 mListView , SLOT(printMe()));
94 //US set singleClick manually, because it is no global configparameter in embedded space 94 //US set singleClick manually, because it is no global configparameter in embedded space
95 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick); 95 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick);
96 96
97 // Add the columns 97 // Add the columns
98 KABC::Field::List fieldList = fields(); 98 KABC::Field::List fieldList = fields();
99 KABC::Field::List::ConstIterator it; 99 KABC::Field::List::ConstIterator it;
100 100
101 int c = 0; 101 int c = 0;
102 for( it = fieldList.begin(); it != fieldList.end(); ++it ) { 102 for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
103 mListView->addColumn( (*it)->label() ); 103 mListView->addColumn( (*it)->label() );
104 mListView->setColumnWidthMode(c++, QListView::Manual); 104 mListView->setColumnWidthMode(c++, QListView::Manual);
105//US 105//US
106 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); 106 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
107 } 107 }
108 108
109 connect(mListView, SIGNAL(selectionChanged()), 109 connect(mListView, SIGNAL(selectionChanged()),
110 this, SLOT(addresseeSelected())); 110 this, SLOT(addresseeSelected()));
111 connect(mListView, SIGNAL(startAddresseeDrag()), this, 111 connect(mListView, SIGNAL(startAddresseeDrag()), this,
112 SIGNAL(startDrag())); 112 SIGNAL(startDrag()));
113 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 113 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
114 SIGNAL(dropped(QDropEvent*))); 114 SIGNAL(dropped(QDropEvent*)));
115 115
116 if (KABPrefs::instance()->mHonorSingleClick) { 116 if (KABPrefs::instance()->mHonorSingleClick) {
117 // qDebug("KAddressBookTableView::reconstructListView single"); 117 // qDebug("KAddressBookTableView::reconstructListView single");
118 connect(mListView, SIGNAL(executed(QListViewItem*)), 118 connect(mListView, SIGNAL(executed(QListViewItem*)),
119 this, SLOT(addresseeExecuted(QListViewItem*))); 119 this, SLOT(addresseeExecuted(QListViewItem*)));
120 } else { 120 } else {
121 // qDebug("KAddressBookTableView::reconstructListView double"); 121 // qDebug("KAddressBookTableView::reconstructListView double");
122 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 122 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
123 this, SLOT(addresseeExecuted(QListViewItem*))); 123 this, SLOT(addresseeExecuted(QListViewItem*)));
124 } 124 }
125 connect(mListView, SIGNAL(returnPressed(QListViewItem*)), 125 connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
126 this, SLOT(addresseeExecuted(QListViewItem*))); 126 this, SLOT(addresseeExecuted(QListViewItem*)));
127 connect(mListView, SIGNAL(signalDelete()), 127 connect(mListView, SIGNAL(signalDelete()),
128 this, SLOT(addresseeDeleted())); 128 this, SLOT(addresseeDeleted()));
129 129
130//US performceimprovement. Refresh is done from the outside 130//US performceimprovement. Refresh is done from the outside
131//US refresh(); 131//US refresh();
132 132
133 mListView->setSorting( 0, true ); 133 mListView->setSorting( 0, true );
134 mainLayout->addWidget( mListView ); 134 mainLayout->addWidget( mListView );
135 mainLayout->activate(); 135 mainLayout->activate();
136 mListView->show(); 136 mListView->show();
137} 137}
138 138
139void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) 139void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
140{ 140{
141 mListView->clear(); 141 mListView->clear();
142 if ( s.isEmpty() || s == "*" ) { 142 if ( s.isEmpty() || s == "*" ) {
143 refresh(); 143 refresh();
144 return; 144 return;
145 } 145 }
146 QString pattern = s.lower()+"*"; 146 QRegExp re = getRegExp( s );
147 QRegExp re;
148 re.setWildcard(true); // most people understand these better.
149 re.setCaseSensitive(false);
150 re.setPattern( pattern );
151 if (!re.isValid()) 147 if (!re.isValid())
152 return; 148 return;
153 KABC::Addressee::List addresseeList = addressees(); 149 KABC::Addressee::List addresseeList = addressees();
154 KABC::Addressee::List::Iterator it; 150 KABC::Addressee::List::Iterator it;
155 if ( field ) { 151 if ( field ) {
156 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 152 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
157 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 153 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
158 continue; 154 continue;
159#if QT_VERSION >= 0x030000 155#if QT_VERSION >= 0x030000
160 if (re.search(field->value( *it ).lower()) == 0) 156 if (re.search(field->value( *it ).lower()) == 0)
161#else 157#else
162 if (re.match(field->value( *it ).lower()) != -1) 158 if (re.match(field->value( *it ).lower()) != -1)
163#endif 159#endif
164 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 160 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
165 161
166 } 162 }
167 } else { 163 } else {
168 KABC::Field::List fieldList = allFields(); 164 KABC::Field::List fieldList = allFields();
169 KABC::Field::List::ConstIterator fieldIt; 165 KABC::Field::List::ConstIterator fieldIt;
170 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 166 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
171 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 167 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
172 continue; 168 continue;
173 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 169 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
174#if QT_VERSION >= 0x030000 170#if QT_VERSION >= 0x030000
175 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 171 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
176#else 172#else
177 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 173 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
178#endif 174#endif
179 { 175 {
180 //qDebug("match %s %s %s", pattern.latin1(), (*fieldIt)->value( *it ).latin1(), (*fieldIt)->label().latin1() ); 176 //qDebug("match %s %s %s", pattern.latin1(), (*fieldIt)->value( *it ).latin1(), (*fieldIt)->label().latin1() );
181 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 177 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
182 break; 178 break;
183 } 179 }
184 } 180 }
185 } 181 }
186 } 182 }
187 // Sometimes the background pixmap gets messed up when we add lots 183 // Sometimes the background pixmap gets messed up when we add lots
188 // of items. 184 // of items.
189 mListView->repaint(); 185 mListView->repaint();
190 if ( mListView->firstChild() ) { 186 if ( mListView->firstChild() ) {
191 mListView->setCurrentItem ( mListView->firstChild() ); 187 mListView->setCurrentItem ( mListView->firstChild() );
192 mListView->setSelected ( mListView->firstChild(), true ); 188 mListView->setSelected ( mListView->firstChild(), true );
193 } 189 }
194 else 190 else
195 emit selected(QString::null); 191 emit selected(QString::null);
196 192
197} 193}
198void KAddressBookTableView::writeConfig(KConfig *config) 194void KAddressBookTableView::writeConfig(KConfig *config)
199{ 195{
200 KAddressBookView::writeConfig(config); 196 KAddressBookView::writeConfig(config);
201 197
202 mListView->saveLayout(config, config->group()); 198 mListView->saveLayout(config, config->group());
203} 199}
204 200
205void KAddressBookTableView::readConfig(KConfig *config) 201void KAddressBookTableView::readConfig(KConfig *config)
206{ 202{
207 KAddressBookView::readConfig( config ); 203 KAddressBookView::readConfig( config );
208 // The config could have changed the fields, so we need to reconstruct 204 // The config could have changed the fields, so we need to reconstruct
209 // the listview. 205 // the listview.
210 reconstructListView(); 206 reconstructListView();
211 207
212 // costum colors? 208 // costum colors?
213 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 209 if ( config->readBoolEntry( "EnableCustomColors", false ) )
214 { 210 {
215 QPalette p( mListView->palette() ); 211 QPalette p( mListView->palette() );
216 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 212 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
217 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 213 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
218 c = p.color(QPalette::Normal, QColorGroup::Text ); 214 c = p.color(QPalette::Normal, QColorGroup::Text );
219 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 215 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
220 c = p.color(QPalette::Normal, QColorGroup::Button ); 216 c = p.color(QPalette::Normal, QColorGroup::Button );
221 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 217 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
222 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 218 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
223 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 219 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
224 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 220 c = p.color(QPalette::Normal, QColorGroup::Highlight );
225 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 221 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
226 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 222 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
227 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 223 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
228#ifndef KAB_EMBEDDED 224#ifndef KAB_EMBEDDED
229 c = KGlobalSettings::alternateBackgroundColor(); 225 c = KGlobalSettings::alternateBackgroundColor();
230#else //KAB_EMBEDDED 226#else //KAB_EMBEDDED
231 c = QColor(240, 240, 240); 227 c = QColor(240, 240, 240);
232#endif //KAB_EMBEDDED 228#endif //KAB_EMBEDDED
233 c = config->readColorEntry ("AlternatingBackgroundColor", &c); 229 c = config->readColorEntry ("AlternatingBackgroundColor", &c);
234 mListView->setAlternateColor(c); 230 mListView->setAlternateColor(c);
235 231
236 232
237 //US mListView->viewport()->setPalette( p ); 233 //US mListView->viewport()->setPalette( p );
238 mListView->setPalette( p ); 234 mListView->setPalette( p );
239 } 235 }
240 else 236 else
241 { 237 {
242 // needed if turned off during a session. 238 // needed if turned off during a session.
243 //US mListView->viewport()->setPalette( mListView->palette() ); 239 //US mListView->viewport()->setPalette( mListView->palette() );
244 mListView->setPalette( mListView->palette() ); 240 mListView->setPalette( mListView->palette() );
245 } 241 }
246 242
247 //custom fonts? 243 //custom fonts?
248 QFont f( font() ); 244 QFont f( font() );
249 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 245 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
250 { 246 {
251 mListView->setFont( config->readFontEntry( "TextFont", &f) ); 247 mListView->setFont( config->readFontEntry( "TextFont", &f) );
252 f.setBold( true ); 248 f.setBold( true );
253 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 249 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
254 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); 250 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) );
255 } 251 }
256 else 252 else
257 { 253 {
258 mListView->setFont( f ); 254 mListView->setFont( f );
259 f.setBold( true ); 255 f.setBold( true );
260 //US mListView->setHeaderFont( f ); 256 //US mListView->setHeaderFont( f );
261 mListView->header()->setFont( f ); 257 mListView->header()->setFont( f );
262 } 258 }
263 259
264 // Set the list view options 260 // Set the list view options
265 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", 261 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
266 true)); 262 true));
267 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); 263 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
268 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); 264 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
269 265
270 if (config->readBoolEntry("Background", false)) 266 if (config->readBoolEntry("Background", false))
271 mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); 267 mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
272 268
273 // Restore the layout of the listview 269 // Restore the layout of the listview
274 mListView->restoreLayout(config, config->group()); 270 mListView->restoreLayout(config, config->group());
275} 271}
276 272
277void KAddressBookTableView::refresh(QString uid) 273void KAddressBookTableView::refresh(QString uid)
278{ 274{
279 // For now just repopulate. In reality this method should 275 // For now just repopulate. In reality this method should
280 // check the value of uid, and if valid iterate through 276 // check the value of uid, and if valid iterate through
281 // the listview to find the entry, then tell it to refresh. 277 // the listview to find the entry, then tell it to refresh.
282 278
283 if (uid.isNull()) { 279 if (uid.isNull()) {
284 // Clear the list view 280 // Clear the list view
285 QString currentUID, nextUID; 281 QString currentUID, nextUID;
286#ifndef KAB_EMBEDDED 282#ifndef KAB_EMBEDDED
287 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); 283 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
288#else //KAB_EMBEDDED 284#else //KAB_EMBEDDED
289 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); 285 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
290#endif //KAB_EMBEDDED 286#endif //KAB_EMBEDDED
291 287
292 if ( currentItem ) { 288 if ( currentItem ) {
293#ifndef KAB_EMBEDDED 289#ifndef KAB_EMBEDDED
294 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); 290 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
295#else //KAB_EMBEDDED 291#else //KAB_EMBEDDED
296 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); 292 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
297#endif //KAB_EMBEDDED 293#endif //KAB_EMBEDDED
298 if ( nextItem ) 294 if ( nextItem )
299 nextUID = nextItem->addressee().uid(); 295 nextUID = nextItem->addressee().uid();
300 currentUID = currentItem->addressee().uid(); 296 currentUID = currentItem->addressee().uid();
301 } 297 }
302 298
303 mListView->clear(); 299 mListView->clear();
304 300
305 currentItem = 0; 301 currentItem = 0;
306 KABC::Addressee::List addresseeList = addressees(); 302 KABC::Addressee::List addresseeList = addressees();
307 KABC::Addressee::List::Iterator it; 303 KABC::Addressee::List::Iterator it;
308 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 304 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
309 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 305 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
310 continue; 306 continue;
311 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 307 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
312 if ( (*it).uid() == currentUID ) 308 if ( (*it).uid() == currentUID )
313 currentItem = item; 309 currentItem = item;
314 else if ( (*it).uid() == nextUID && !currentItem ) 310 else if ( (*it).uid() == nextUID && !currentItem )
315 currentItem = item; 311 currentItem = item;
316 } 312 }
317 313
318 // Sometimes the background pixmap gets messed up when we add lots 314 // Sometimes the background pixmap gets messed up when we add lots
319 // of items. 315 // of items.
320 mListView->repaint(); 316 mListView->repaint();
321 317
322 if ( currentItem ) { 318 if ( currentItem ) {
323 mListView->setCurrentItem( currentItem ); 319 mListView->setCurrentItem( currentItem );
324 mListView->ensureItemVisible( currentItem ); 320 mListView->ensureItemVisible( currentItem );
325 } 321 }
326 } else { 322 } else {
327 // Only need to update on entry. Iterate through and try to find it 323 // Only need to update on entry. Iterate through and try to find it
328 ContactListViewItem *ceItem; 324 ContactListViewItem *ceItem;
329 QListViewItemIterator it( mListView ); 325 QListViewItemIterator it( mListView );
330 while ( it.current() ) { 326 while ( it.current() ) {
331#ifndef KAB_EMBEDDED 327#ifndef KAB_EMBEDDED
332 ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); 328 ceItem = dynamic_cast<ContactListViewItem*>( it.current() );
333#else //KAB_EMBEDDED 329#else //KAB_EMBEDDED
334 ceItem = (ContactListViewItem*)( it.current() ); 330 ceItem = (ContactListViewItem*)( it.current() );
335#endif //KAB_EMBEDDED 331#endif //KAB_EMBEDDED
336 332
337 if ( ceItem && ceItem->addressee().uid() == uid ) { 333 if ( ceItem && ceItem->addressee().uid() == uid ) {
338 ceItem->refresh(); 334 ceItem->refresh();
339 return; 335 return;
340 } 336 }
341 ++it; 337 ++it;
342 } 338 }
343 339
344 refresh( QString::null ); 340 refresh( QString::null );
345 } 341 }
346} 342}
347 343
348QStringList KAddressBookTableView::selectedUids() 344QStringList KAddressBookTableView::selectedUids()
349{ 345{
350 QStringList uidList; 346 QStringList uidList;
351 QListViewItem *item; 347 QListViewItem *item;
352 ContactListViewItem *ceItem; 348 ContactListViewItem *ceItem;
353 349
354 for(item = mListView->firstChild(); item; item = item->itemBelow()) 350 for(item = mListView->firstChild(); item; item = item->itemBelow())
355 { 351 {
356 if (mListView->isSelected( item )) 352 if (mListView->isSelected( item ))
357 { 353 {
358#ifndef KAB_EMBEDDED 354#ifndef KAB_EMBEDDED
359 ceItem = dynamic_cast<ContactListViewItem*>(item); 355 ceItem = dynamic_cast<ContactListViewItem*>(item);
360#else //KAB_EMBEDDED 356#else //KAB_EMBEDDED
361 ceItem = (ContactListViewItem*)(item); 357 ceItem = (ContactListViewItem*)(item);
362#endif //KAB_EMBEDDED 358#endif //KAB_EMBEDDED
363 359
364 if (ceItem != 0L) 360 if (ceItem != 0L)
365 uidList << ceItem->addressee().uid(); 361 uidList << ceItem->addressee().uid();
366 } 362 }
367 } 363 }
368 if ( uidList.count() == 0 ) 364 if ( uidList.count() == 0 )
369 if ( mListView->currentItem() ) { 365 if ( mListView->currentItem() ) {
370 ceItem = (ContactListViewItem*)(mListView->currentItem()) ; 366 ceItem = (ContactListViewItem*)(mListView->currentItem()) ;
371 uidList << ceItem->addressee().uid(); 367 uidList << ceItem->addressee().uid();
372 } 368 }
373 369
374 return uidList; 370 return uidList;
375} 371}
376 372
377void KAddressBookTableView::setSelected(QString uid, bool selected) 373void KAddressBookTableView::setSelected(QString uid, bool selected)
378{ 374{
379 QListViewItem *item; 375 QListViewItem *item;
380 ContactListViewItem *ceItem; 376 ContactListViewItem *ceItem;
381 377
382 if (uid.isNull()) 378 if (uid.isNull())
383 { 379 {
384 mListView->selectAll(selected); 380 mListView->selectAll(selected);
385 } 381 }
386 else 382 else
387 { 383 {
388 for(item = mListView->firstChild(); item; item = item->itemBelow()) 384 for(item = mListView->firstChild(); item; item = item->itemBelow())
389 { 385 {
390#ifndef KAB_EMBEDDED 386#ifndef KAB_EMBEDDED
391 ceItem = dynamic_cast<ContactListViewItem*>(item); 387 ceItem = dynamic_cast<ContactListViewItem*>(item);
392#else //KAB_EMBEDDED 388#else //KAB_EMBEDDED
393 ceItem = (ContactListViewItem*)(item); 389 ceItem = (ContactListViewItem*)(item);
394#endif //KAB_EMBEDDED 390#endif //KAB_EMBEDDED
395 391
396 392
397 if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) 393 if ((ceItem != 0L) && (ceItem->addressee().uid() == uid))
398 { 394 {
399 mListView->setSelected(item, selected); 395 mListView->setSelected(item, selected);
400 396
401 if (selected) 397 if (selected)
402 mListView->ensureItemVisible(item); 398 mListView->ensureItemVisible(item);
403 } 399 }
404 } 400 }
405 } 401 }
406} 402}
407 403
408void KAddressBookTableView::addresseeSelected() 404void KAddressBookTableView::addresseeSelected()
409{ 405{
410 // We need to try to find the first selected item. This might not be the 406 // We need to try to find the first selected item. This might not be the
411 // last selected item, but when QListView is in multiselection mode, 407 // last selected item, but when QListView is in multiselection mode,
412 // there is no way to figure out which one was 408 // there is no way to figure out which one was
413 // selected last. 409 // selected last.
414 QListViewItem *item; 410 QListViewItem *item;
415 bool found =false; 411 bool found =false;
416 for (item = mListView->firstChild(); item && !found; 412 for (item = mListView->firstChild(); item && !found;
417 item = item->nextSibling()) 413 item = item->nextSibling())
418 { 414 {
419 if (item->isSelected()) 415 if (item->isSelected())
420 { 416 {
421 found = true; 417 found = true;
422#ifndef KAB_EMBEDDED 418#ifndef KAB_EMBEDDED
423 ContactListViewItem *ceItem 419 ContactListViewItem *ceItem
424 = dynamic_cast<ContactListViewItem*>(item); 420 = dynamic_cast<ContactListViewItem*>(item);
425#else //KAB_EMBEDDED 421#else //KAB_EMBEDDED
426 ContactListViewItem *ceItem 422 ContactListViewItem *ceItem
427 = (ContactListViewItem*)(item); 423 = (ContactListViewItem*)(item);
428#endif //KAB_EMBEDDED 424#endif //KAB_EMBEDDED
429 425
430 if ( ceItem ) emit selected(ceItem->addressee().uid()); 426 if ( ceItem ) emit selected(ceItem->addressee().uid());
431 } 427 }
432 } 428 }
433 429
434 if (!found) 430 if (!found)
435 emit selected(QString::null); 431 emit selected(QString::null);
436} 432}
437 433
438void KAddressBookTableView::addresseeExecuted(QListViewItem *item) 434void KAddressBookTableView::addresseeExecuted(QListViewItem *item)
439{ 435{
440 if (item) 436 if (item)
441 { 437 {
442#ifndef KAB_EMBEDDED 438#ifndef KAB_EMBEDDED
443 ContactListViewItem *ceItem 439 ContactListViewItem *ceItem
444 = dynamic_cast<ContactListViewItem*>(item); 440 = dynamic_cast<ContactListViewItem*>(item);
445#else //KAB_EMBEDDED 441#else //KAB_EMBEDDED
446 ContactListViewItem *ceItem 442 ContactListViewItem *ceItem
447 = (ContactListViewItem*)(item); 443 = (ContactListViewItem*)(item);
448#endif //KAB_EMBEDDED 444#endif //KAB_EMBEDDED
449 445
450 if (ceItem) 446 if (ceItem)
451 { 447 {
452 emit executed(ceItem->addressee().uid()); 448 emit executed(ceItem->addressee().uid());
453 } 449 }
454 } 450 }
455 else 451 else
456 { 452 {
457 emit executed(QString::null); 453 emit executed(QString::null);
458 } 454 }
459} 455}
460 456
461void KAddressBookTableView::addresseeDeleted() 457void KAddressBookTableView::addresseeDeleted()
462{ 458{
463 459
464 emit deleteRequest(); 460 emit deleteRequest();
465 461
466} 462}
467 463
468 464
469 465
470 466
471 467
472#ifndef KAB_EMBEDDED 468#ifndef KAB_EMBEDDED
473#include "kaddressbooktableview.moc" 469#include "kaddressbooktableview.moc"
474#endif //KAB_EMBEDDED 470#endif //KAB_EMBEDDED