author | zautrix <zautrix> | 2004-10-27 21:34:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-27 21:34:55 (UTC) |
commit | 9c88346fc757fd1dc54b3fca151a2a610159d8cf (patch) (unidiff) | |
tree | 4a5de97ba71ce66eea914d55923d88aff3515c93 /kaddressbook/views | |
parent | 7f3cc07fab5f5f6ddd402c458341f1df3a144e2c (diff) | |
download | kdepimpi-9c88346fc757fd1dc54b3fca151a2a610159d8cf.zip kdepimpi-9c88346fc757fd1dc54b3fca151a2a610159d8cf.tar.gz kdepimpi-9c88346fc757fd1dc54b3fca151a2a610159d8cf.tar.bz2 |
several fixes
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 5 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.cpp | 6 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 6 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.h | 1 |
6 files changed, 20 insertions, 0 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index a7bf6c9..7f33bb4 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp | |||
@@ -1,464 +1,469 @@ | |||
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 | #include "kaddressbookcardview.h" | 41 | #include "kaddressbookcardview.h" |
42 | 42 | ||
43 | #ifndef KAB_EMBEDDED | 43 | #ifndef KAB_EMBEDDED |
44 | extern "C" { | 44 | extern "C" { |
45 | void *init_libkaddrbk_cardview() | 45 | void *init_libkaddrbk_cardview() |
46 | { | 46 | { |
47 | return ( new CardViewFactory ); | 47 | return ( new CardViewFactory ); |
48 | } | 48 | } |
49 | } | 49 | } |
50 | #endif //KAB_EMBEDDED | 50 | #endif //KAB_EMBEDDED |
51 | 51 | ||
52 | //////////////////////////////// | 52 | //////////////////////////////// |
53 | // AddresseeCardViewItem (internal class) | 53 | // AddresseeCardViewItem (internal class) |
54 | class AddresseeCardViewItem : public CardViewItem | 54 | class AddresseeCardViewItem : public CardViewItem |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | AddresseeCardViewItem(const KABC::Field::List &fields, | 57 | AddresseeCardViewItem(const KABC::Field::List &fields, |
58 | bool showEmptyFields, | 58 | bool showEmptyFields, |
59 | KABC::AddressBook *doc, const KABC::Addressee &a, | 59 | KABC::AddressBook *doc, const KABC::Addressee &a, |
60 | CardView *parent) | 60 | CardView *parent) |
61 | : CardViewItem(parent, a.formattedName()), | 61 | : CardViewItem(parent, a.formattedName()), |
62 | mFields( fields ), mShowEmptyFields(showEmptyFields), | 62 | mFields( fields ), mShowEmptyFields(showEmptyFields), |
63 | mDocument(doc), mAddressee(a) | 63 | mDocument(doc), mAddressee(a) |
64 | { | 64 | { |
65 | if ( mFields.isEmpty() ) { | 65 | if ( mFields.isEmpty() ) { |
66 | mFields = KABC::Field::defaultFields(); | 66 | mFields = KABC::Field::defaultFields(); |
67 | } | 67 | } |
68 | refresh(); | 68 | refresh(); |
69 | } | 69 | } |
70 | 70 | ||
71 | const KABC::Addressee &addressee() const { return mAddressee; } | 71 | const KABC::Addressee &addressee() const { return mAddressee; } |
72 | 72 | ||
73 | void refresh() | 73 | void refresh() |
74 | { | 74 | { |
75 | // Update our addressee, since it may have changed elsewhere | 75 | // Update our addressee, since it may have changed elsewhere |
76 | mAddressee = mDocument->findByUid(mAddressee.uid()); | 76 | mAddressee = mDocument->findByUid(mAddressee.uid()); |
77 | 77 | ||
78 | if (!mAddressee.isEmpty()) | 78 | if (!mAddressee.isEmpty()) |
79 | { | 79 | { |
80 | clearFields(); | 80 | clearFields(); |
81 | 81 | ||
82 | // Try all the selected fields until we find one with text. | 82 | // Try all the selected fields until we find one with text. |
83 | // This will limit the number of unlabeled icons in the view | 83 | // This will limit the number of unlabeled icons in the view |
84 | KABC::Field::List::Iterator iter; | 84 | KABC::Field::List::Iterator iter; |
85 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) | 85 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) |
86 | { | 86 | { |
87 | // insert empty fields or not? not doing so saves a bit of memory and CPU | 87 | // insert empty fields or not? not doing so saves a bit of memory and CPU |
88 | // (during geometry calculations), but prevents having equally | 88 | // (during geometry calculations), but prevents having equally |
89 | // wide label columns in all cards, unless CardViewItem/CardView search | 89 | // wide label columns in all cards, unless CardViewItem/CardView search |
90 | // globally for the widest label. (anders) | 90 | // globally for the widest label. (anders) |
91 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) | 91 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) |
92 | insertField((*iter)->label(), (*iter)->value( mAddressee )); | 92 | insertField((*iter)->label(), (*iter)->value( mAddressee )); |
93 | } | 93 | } |
94 | 94 | ||
95 | // We might want to make this the first field. hmm... -mpilone | 95 | // We might want to make this the first field. hmm... -mpilone |
96 | setCaption( mAddressee.realName() ); | 96 | setCaption( mAddressee.realName() ); |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | private: | 100 | private: |
101 | KABC::Field::List mFields; | 101 | KABC::Field::List mFields; |
102 | bool mShowEmptyFields; | 102 | bool mShowEmptyFields; |
103 | KABC::AddressBook *mDocument; | 103 | KABC::AddressBook *mDocument; |
104 | KABC::Addressee mAddressee; | 104 | KABC::Addressee mAddressee; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | /////////////////////////////// | 107 | /////////////////////////////// |
108 | // AddresseeCardView | 108 | // AddresseeCardView |
109 | 109 | ||
110 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) | 110 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) |
111 | : CardView(parent, name) | 111 | : CardView(parent, name) |
112 | { | 112 | { |
113 | setAcceptDrops(true); | 113 | setAcceptDrops(true); |
114 | } | 114 | } |
115 | 115 | ||
116 | AddresseeCardView::~AddresseeCardView() | 116 | AddresseeCardView::~AddresseeCardView() |
117 | { | 117 | { |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) | 121 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) |
122 | { | 122 | { |
123 | #ifndef KAB_EMBEDDED | 123 | #ifndef KAB_EMBEDDED |
124 | if (QTextDrag::canDecode(e)) | 124 | if (QTextDrag::canDecode(e)) |
125 | e->accept(); | 125 | e->accept(); |
126 | #else //KAB_EMBEDDED | 126 | #else //KAB_EMBEDDED |
127 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); | 127 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); |
128 | #endif //KAB_EMBEDDED | 128 | #endif //KAB_EMBEDDED |
129 | } | 129 | } |
130 | 130 | ||
131 | void AddresseeCardView::dropEvent(QDropEvent *e) | 131 | void AddresseeCardView::dropEvent(QDropEvent *e) |
132 | { | 132 | { |
133 | emit addresseeDropped(e); | 133 | emit addresseeDropped(e); |
134 | } | 134 | } |
135 | 135 | ||
136 | void AddresseeCardView::startDrag() | 136 | void AddresseeCardView::startDrag() |
137 | { | 137 | { |
138 | emit startAddresseeDrag(); | 138 | emit startAddresseeDrag(); |
139 | } | 139 | } |
140 | 140 | ||
141 | 141 | ||
142 | /////////////////////////////// | 142 | /////////////////////////////// |
143 | // KAddressBookCardView | 143 | // KAddressBookCardView |
144 | 144 | ||
145 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, | 145 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, |
146 | QWidget *parent, const char *name ) | 146 | QWidget *parent, const char *name ) |
147 | : KAddressBookView( ab, parent, name ) | 147 | : KAddressBookView( ab, parent, name ) |
148 | { | 148 | { |
149 | mShowEmptyFields = false; | 149 | mShowEmptyFields = false; |
150 | 150 | ||
151 | // Init the GUI | 151 | // Init the GUI |
152 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); | 152 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); |
153 | 153 | ||
154 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); | 154 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); |
155 | mCardView->setSelectionMode(CardView::Extended); | 155 | mCardView->setSelectionMode(CardView::Extended); |
156 | layout->addWidget(mCardView); | 156 | layout->addWidget(mCardView); |
157 | 157 | ||
158 | // Connect up the signals | 158 | // Connect up the signals |
159 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 159 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
160 | this, SLOT(addresseeExecuted(CardViewItem *))); | 160 | this, SLOT(addresseeExecuted(CardViewItem *))); |
161 | connect(mCardView, SIGNAL(selectionChanged()), | 161 | connect(mCardView, SIGNAL(selectionChanged()), |
162 | this, SLOT(addresseeSelected())); | 162 | this, SLOT(addresseeSelected())); |
163 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), | 163 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), |
164 | this, SIGNAL(dropped(QDropEvent*))); | 164 | this, SIGNAL(dropped(QDropEvent*))); |
165 | connect(mCardView, SIGNAL(startAddresseeDrag()), | 165 | connect(mCardView, SIGNAL(startAddresseeDrag()), |
166 | this, SIGNAL(startDrag())); | 166 | this, SIGNAL(startDrag())); |
167 | } | 167 | } |
168 | 168 | ||
169 | KAddressBookCardView::~KAddressBookCardView() | 169 | KAddressBookCardView::~KAddressBookCardView() |
170 | { | 170 | { |
171 | } | 171 | } |
172 | void KAddressBookCardView::setFocusAV() | ||
173 | { | ||
174 | if ( mCardView ) | ||
175 | mCardView->setFocus(); | ||
172 | 176 | ||
177 | } | ||
173 | void KAddressBookCardView::scrollUP() | 178 | void KAddressBookCardView::scrollUP() |
174 | { | 179 | { |
175 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | 180 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); |
176 | QApplication::postEvent( mCardView, ev ); | 181 | QApplication::postEvent( mCardView, ev ); |
177 | 182 | ||
178 | } | 183 | } |
179 | void KAddressBookCardView::scrollDOWN() | 184 | void KAddressBookCardView::scrollDOWN() |
180 | { | 185 | { |
181 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | 186 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); |
182 | QApplication::postEvent( mCardView, ev ); | 187 | QApplication::postEvent( mCardView, ev ); |
183 | } | 188 | } |
184 | void KAddressBookCardView::readConfig(KConfig *config) | 189 | void KAddressBookCardView::readConfig(KConfig *config) |
185 | { | 190 | { |
186 | KAddressBookView::readConfig(config); | 191 | KAddressBookView::readConfig(config); |
187 | 192 | ||
188 | // costum colors? | 193 | // costum colors? |
189 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 194 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
190 | { | 195 | { |
191 | QPalette p( mCardView->palette() ); | 196 | QPalette p( mCardView->palette() ); |
192 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 197 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
193 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 198 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
194 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 199 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
195 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 200 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
196 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 201 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
197 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 202 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
198 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 203 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
199 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 204 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
200 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 205 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
201 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 206 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
202 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 207 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
203 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 208 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
204 | mCardView->viewport()->setPalette( p ); | 209 | mCardView->viewport()->setPalette( p ); |
205 | } | 210 | } |
206 | else | 211 | else |
207 | { | 212 | { |
208 | // needed if turned off during a session. | 213 | // needed if turned off during a session. |
209 | mCardView->viewport()->setPalette( mCardView->palette() ); | 214 | mCardView->viewport()->setPalette( mCardView->palette() ); |
210 | } | 215 | } |
211 | 216 | ||
212 | //custom fonts? | 217 | //custom fonts? |
213 | QFont f( font() ); | 218 | QFont f( font() ); |
214 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 219 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
215 | { | 220 | { |
216 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); | 221 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); |
217 | f.setBold( true ); | 222 | f.setBold( true ); |
218 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 223 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
219 | } | 224 | } |
220 | else | 225 | else |
221 | { | 226 | { |
222 | mCardView->setFont( f ); | 227 | mCardView->setFont( f ); |
223 | f.setBold( true ); | 228 | f.setBold( true ); |
224 | mCardView->setHeaderFont( f ); | 229 | mCardView->setHeaderFont( f ); |
225 | } | 230 | } |
226 | 231 | ||
227 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); | 232 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); |
228 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", | 233 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", |
229 | true)); | 234 | true)); |
230 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); | 235 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); |
231 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); | 236 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); |
232 | 237 | ||
233 | mCardView->setShowEmptyFields( mShowEmptyFields ); | 238 | mCardView->setShowEmptyFields( mShowEmptyFields ); |
234 | 239 | ||
235 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); | 240 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); |
236 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); | 241 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); |
237 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); | 242 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); |
238 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); | 243 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); |
239 | 244 | ||
240 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), | 245 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), |
241 | this, SLOT(addresseeExecuted(CardViewItem *))); | 246 | this, SLOT(addresseeExecuted(CardViewItem *))); |
242 | 247 | ||
243 | if (KABPrefs::instance()->mHonorSingleClick) | 248 | if (KABPrefs::instance()->mHonorSingleClick) |
244 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 249 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
245 | this, SLOT(addresseeExecuted(CardViewItem *))); | 250 | this, SLOT(addresseeExecuted(CardViewItem *))); |
246 | else | 251 | else |
247 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), | 252 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), |
248 | this, SLOT(addresseeExecuted(CardViewItem *))); | 253 | this, SLOT(addresseeExecuted(CardViewItem *))); |
249 | 254 | ||
250 | } | 255 | } |
251 | 256 | ||
252 | void KAddressBookCardView::writeConfig( KConfig *config ) | 257 | void KAddressBookCardView::writeConfig( KConfig *config ) |
253 | { | 258 | { |
254 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); | 259 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); |
255 | KAddressBookView::writeConfig( config ); | 260 | KAddressBookView::writeConfig( config ); |
256 | } | 261 | } |
257 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) | 262 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) |
258 | { | 263 | { |
259 | mCardView->clear(); | 264 | mCardView->clear(); |
260 | if ( s.isEmpty() || s == "*" ) { | 265 | if ( s.isEmpty() || s == "*" ) { |
261 | refresh(); | 266 | refresh(); |
262 | return; | 267 | return; |
263 | } | 268 | } |
264 | QString pattern = s.lower()+"*"; | 269 | QString pattern = s.lower()+"*"; |
265 | QRegExp re; | 270 | QRegExp re; |
266 | re.setWildcard(true); // most people understand these better. | 271 | re.setWildcard(true); // most people understand these better. |
267 | re.setCaseSensitive(false); | 272 | re.setCaseSensitive(false); |
268 | re.setPattern( pattern ); | 273 | re.setPattern( pattern ); |
269 | if (!re.isValid()) | 274 | if (!re.isValid()) |
270 | return; | 275 | return; |
271 | mCardView->viewport()->setUpdatesEnabled( false ); | 276 | mCardView->viewport()->setUpdatesEnabled( false ); |
272 | KABC::Addressee::List addresseeList = addressees(); | 277 | KABC::Addressee::List addresseeList = addressees(); |
273 | KABC::Addressee::List::Iterator it; | 278 | KABC::Addressee::List::Iterator it; |
274 | if ( field ) { | 279 | if ( field ) { |
275 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 280 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
276 | #if QT_VERSION >= 300 | 281 | #if QT_VERSION >= 300 |
277 | if (re.search(field->value( *it ).lower()) != -1) | 282 | if (re.search(field->value( *it ).lower()) != -1) |
278 | #else | 283 | #else |
279 | if (re.match(field->value( *it ).lower()) != -1) | 284 | if (re.match(field->value( *it ).lower()) != -1) |
280 | #endif | 285 | #endif |
281 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 286 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
282 | addressBook(), *it, mCardView); | 287 | addressBook(), *it, mCardView); |
283 | 288 | ||
284 | } | 289 | } |
285 | } else { | 290 | } else { |
286 | KABC::Field::List fieldList = fields(); | 291 | KABC::Field::List fieldList = fields(); |
287 | KABC::Field::List::ConstIterator fieldIt; | 292 | KABC::Field::List::ConstIterator fieldIt; |
288 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 293 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
289 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 294 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
290 | #if QT_VERSION >= 300 | 295 | #if QT_VERSION >= 300 |
291 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | 296 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
292 | #else | 297 | #else |
293 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | 298 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) |
294 | #endif | 299 | #endif |
295 | { | 300 | { |
296 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 301 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
297 | addressBook(), *it, mCardView); | 302 | addressBook(), *it, mCardView); |
298 | continue; | 303 | continue; |
299 | } | 304 | } |
300 | } | 305 | } |
301 | } | 306 | } |
302 | } | 307 | } |
303 | mCardView->viewport()->setUpdatesEnabled( true ); | 308 | mCardView->viewport()->setUpdatesEnabled( true ); |
304 | mCardView->viewport()->update(); | 309 | mCardView->viewport()->update(); |
305 | if ( mCardView->firstItem() ) { | 310 | if ( mCardView->firstItem() ) { |
306 | mCardView->setCurrentItem ( mCardView->firstItem() ); | 311 | mCardView->setCurrentItem ( mCardView->firstItem() ); |
307 | mCardView->setSelected ( mCardView->firstItem() , true ); | 312 | mCardView->setSelected ( mCardView->firstItem() , true ); |
308 | } | 313 | } |
309 | else | 314 | else |
310 | emit selected(QString::null); | 315 | emit selected(QString::null); |
311 | } | 316 | } |
312 | QStringList KAddressBookCardView::selectedUids() | 317 | QStringList KAddressBookCardView::selectedUids() |
313 | { | 318 | { |
314 | QStringList uidList; | 319 | QStringList uidList; |
315 | CardViewItem *item; | 320 | CardViewItem *item; |
316 | AddresseeCardViewItem *aItem; | 321 | AddresseeCardViewItem *aItem; |
317 | 322 | ||
318 | for (item = mCardView->firstItem(); item; item = item->nextItem()) | 323 | for (item = mCardView->firstItem(); item; item = item->nextItem()) |
319 | { | 324 | { |
320 | if (item->isSelected()) | 325 | if (item->isSelected()) |
321 | { | 326 | { |
322 | #ifndef KAB_EMBEDDED | 327 | #ifndef KAB_EMBEDDED |
323 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 328 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
324 | #else //KAB_EMBEDDED | 329 | #else //KAB_EMBEDDED |
325 | aItem = (AddresseeCardViewItem*)(item); | 330 | aItem = (AddresseeCardViewItem*)(item); |
326 | #endif //KAB_EMBEDDED | 331 | #endif //KAB_EMBEDDED |
327 | if (aItem) | 332 | if (aItem) |
328 | uidList << aItem->addressee().uid(); | 333 | uidList << aItem->addressee().uid(); |
329 | } | 334 | } |
330 | } | 335 | } |
331 | 336 | ||
332 | return uidList; | 337 | return uidList; |
333 | } | 338 | } |
334 | 339 | ||
335 | void KAddressBookCardView::refresh(QString uid) | 340 | void KAddressBookCardView::refresh(QString uid) |
336 | { | 341 | { |
337 | CardViewItem *item; | 342 | CardViewItem *item; |
338 | AddresseeCardViewItem *aItem; | 343 | AddresseeCardViewItem *aItem; |
339 | 344 | ||
340 | if (uid.isNull()) | 345 | if (uid.isNull()) |
341 | { | 346 | { |
342 | // Rebuild the view | 347 | // Rebuild the view |
343 | mCardView->viewport()->setUpdatesEnabled( false ); | 348 | mCardView->viewport()->setUpdatesEnabled( false ); |
344 | mCardView->clear(); | 349 | mCardView->clear(); |
345 | 350 | ||
346 | KABC::Addressee::List addresseeList = addressees(); | 351 | KABC::Addressee::List addresseeList = addressees(); |
347 | KABC::Addressee::List::Iterator iter; | 352 | KABC::Addressee::List::Iterator iter; |
348 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) | 353 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) |
349 | { | 354 | { |
350 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) | 355 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) |
351 | continue; | 356 | continue; |
352 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, | 357 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, |
353 | addressBook(), *iter, mCardView); | 358 | addressBook(), *iter, mCardView); |
354 | } | 359 | } |
355 | mCardView->viewport()->setUpdatesEnabled( true ); | 360 | mCardView->viewport()->setUpdatesEnabled( true ); |
356 | mCardView->viewport()->update(); | 361 | mCardView->viewport()->update(); |
357 | 362 | ||
358 | // by default nothing is selected | 363 | // by default nothing is selected |
359 | emit selected(QString::null); | 364 | emit selected(QString::null); |
360 | } | 365 | } |
361 | else | 366 | else |
362 | { | 367 | { |
363 | // Try to find the one to refresh | 368 | // Try to find the one to refresh |
364 | bool found = false; | 369 | bool found = false; |
365 | for (item = mCardView->firstItem(); item && !found; | 370 | for (item = mCardView->firstItem(); item && !found; |
366 | item = item->nextItem()) | 371 | item = item->nextItem()) |
367 | { | 372 | { |
368 | #ifndef KAB_EMBEDDED | 373 | #ifndef KAB_EMBEDDED |
369 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 374 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
370 | #else //KAB_EMBEDDED | 375 | #else //KAB_EMBEDDED |
371 | aItem = (AddresseeCardViewItem*)(item); | 376 | aItem = (AddresseeCardViewItem*)(item); |
372 | #endif //KAB_EMBEDDED | 377 | #endif //KAB_EMBEDDED |
373 | 378 | ||
374 | if ((aItem) && (aItem->addressee().uid() == uid)) | 379 | if ((aItem) && (aItem->addressee().uid() == uid)) |
375 | { | 380 | { |
376 | aItem->refresh(); | 381 | aItem->refresh(); |
377 | found = true; | 382 | found = true; |
378 | } | 383 | } |
379 | } | 384 | } |
380 | } | 385 | } |
381 | } | 386 | } |
382 | 387 | ||
383 | void KAddressBookCardView::setSelected(QString uid, bool selected) | 388 | void KAddressBookCardView::setSelected(QString uid, bool selected) |
384 | { | 389 | { |
385 | CardViewItem *item; | 390 | CardViewItem *item; |
386 | AddresseeCardViewItem *aItem; | 391 | AddresseeCardViewItem *aItem; |
387 | 392 | ||
388 | if (uid.isNull()) | 393 | if (uid.isNull()) |
389 | { | 394 | { |
390 | mCardView->selectAll(selected); | 395 | mCardView->selectAll(selected); |
391 | } | 396 | } |
392 | else | 397 | else |
393 | { | 398 | { |
394 | bool found = false; | 399 | bool found = false; |
395 | for (item = mCardView->firstItem(); item && !found; | 400 | for (item = mCardView->firstItem(); item && !found; |
396 | item = item->nextItem()) | 401 | item = item->nextItem()) |
397 | { | 402 | { |
398 | #ifndef KAB_EMBEDDED | 403 | #ifndef KAB_EMBEDDED |
399 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 404 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
400 | #else //KAB_EMBEDDED | 405 | #else //KAB_EMBEDDED |
401 | aItem = (AddresseeCardViewItem*)(item); | 406 | aItem = (AddresseeCardViewItem*)(item); |
402 | #endif //KAB_EMBEDDED | 407 | #endif //KAB_EMBEDDED |
403 | 408 | ||
404 | if ((aItem) && (aItem->addressee().uid() == uid)) | 409 | if ((aItem) && (aItem->addressee().uid() == uid)) |
405 | { | 410 | { |
406 | mCardView->setSelected(aItem, selected); | 411 | mCardView->setSelected(aItem, selected); |
407 | mCardView->ensureItemVisible(item); | 412 | mCardView->ensureItemVisible(item); |
408 | found = true; | 413 | found = true; |
409 | } | 414 | } |
410 | } | 415 | } |
411 | } | 416 | } |
412 | } | 417 | } |
413 | 418 | ||
414 | //US added an additional method without parameter | 419 | //US added an additional method without parameter |
415 | void KAddressBookCardView::setSelected() | 420 | void KAddressBookCardView::setSelected() |
416 | { | 421 | { |
417 | setSelected(QString::null, true); | 422 | setSelected(QString::null, true); |
418 | } | 423 | } |
419 | 424 | ||
420 | void KAddressBookCardView::addresseeExecuted(CardViewItem *item) | 425 | void KAddressBookCardView::addresseeExecuted(CardViewItem *item) |
421 | { | 426 | { |
422 | #ifndef KAB_EMBEDDED | 427 | #ifndef KAB_EMBEDDED |
423 | AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 428 | AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
424 | #else //KAB_EMBEDDED | 429 | #else //KAB_EMBEDDED |
425 | AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); | 430 | AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); |
426 | #endif //KAB_EMBEDDED | 431 | #endif //KAB_EMBEDDED |
427 | if (aItem) | 432 | if (aItem) |
428 | { | 433 | { |
429 | //kdDebug()<<"... even has a valid item:)"<<endl; | 434 | //kdDebug()<<"... even has a valid item:)"<<endl; |
430 | emit executed(aItem->addressee().uid()); | 435 | emit executed(aItem->addressee().uid()); |
431 | } | 436 | } |
432 | } | 437 | } |
433 | 438 | ||
434 | void KAddressBookCardView::addresseeSelected() | 439 | void KAddressBookCardView::addresseeSelected() |
435 | { | 440 | { |
436 | CardViewItem *item; | 441 | CardViewItem *item; |
437 | AddresseeCardViewItem *aItem; | 442 | AddresseeCardViewItem *aItem; |
438 | 443 | ||
439 | bool found = false; | 444 | bool found = false; |
440 | for (item = mCardView->firstItem(); item && !found; | 445 | for (item = mCardView->firstItem(); item && !found; |
441 | item = item->nextItem()) | 446 | item = item->nextItem()) |
442 | { | 447 | { |
443 | if (item->isSelected()) | 448 | if (item->isSelected()) |
444 | { | 449 | { |
445 | #ifndef KAB_EMBEDDED | 450 | #ifndef KAB_EMBEDDED |
446 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 451 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
447 | #else //KAB_EMBEDDED | 452 | #else //KAB_EMBEDDED |
448 | aItem = (AddresseeCardViewItem*)(item); | 453 | aItem = (AddresseeCardViewItem*)(item); |
449 | #endif //KAB_EMBEDDED | 454 | #endif //KAB_EMBEDDED |
450 | if ( aItem ) | 455 | if ( aItem ) |
451 | { | 456 | { |
452 | emit selected(aItem->addressee().uid()); | 457 | emit selected(aItem->addressee().uid()); |
453 | found = true; | 458 | found = true; |
454 | } | 459 | } |
455 | } | 460 | } |
456 | } | 461 | } |
457 | 462 | ||
458 | if (!found) | 463 | if (!found) |
459 | emit selected(QString::null); | 464 | emit selected(QString::null); |
460 | 465 | ||
461 | } | 466 | } |
462 | #ifndef KAB_EMBEDDED | 467 | #ifndef KAB_EMBEDDED |
463 | #include "kaddressbookcardview.moc" | 468 | #include "kaddressbookcardview.moc" |
464 | #endif //KAB_EMBEDDED | 469 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h index 45a9781..8f22d54 100644 --- a/kaddressbook/views/kaddressbookcardview.h +++ b/kaddressbook/views/kaddressbookcardview.h | |||
@@ -1,119 +1,120 @@ | |||
1 | #ifndef KADDRESSBOOKCARDVIEW_H | 1 | #ifndef KADDRESSBOOKCARDVIEW_H |
2 | #define KADDRESSBOOKCARDVIEW_H | 2 | #define KADDRESSBOOKCARDVIEW_H |
3 | 3 | ||
4 | /* | 4 | /* |
5 | This file is part of KAddressBook. | 5 | This file is part of KAddressBook. |
6 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 6 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
7 | 7 | ||
8 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | 11 | (at your option) any later version. |
12 | 12 | ||
13 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. | 16 | GNU General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | 19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 | 21 | ||
22 | As a special exception, permission is given to link this program | 22 | As a special exception, permission is given to link this program |
23 | with any edition of Qt, and distribute the resulting executable, | 23 | with any edition of Qt, and distribute the resulting executable, |
24 | without including the source code for Qt in the source distribution. | 24 | without including the source code for Qt in the source distribution. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include <qstring.h> | 27 | #include <qstring.h> |
28 | #ifndef KAB_EMBEDDED | 28 | #ifndef KAB_EMBEDDED |
29 | #include <kiconview.h> | 29 | #include <kiconview.h> |
30 | #else //KAB_EMBEDDED | 30 | #else //KAB_EMBEDDED |
31 | #include <klocale.h> | 31 | #include <klocale.h> |
32 | #endif //KAB_EMBEDDED | 32 | #endif //KAB_EMBEDDED |
33 | 33 | ||
34 | #include "cardview.h" | 34 | #include "cardview.h" |
35 | #include "kaddressbookview.h" | 35 | #include "kaddressbookview.h" |
36 | #include "configurecardviewdialog.h" | 36 | #include "configurecardviewdialog.h" |
37 | 37 | ||
38 | class QDragEnterEvent; | 38 | class QDragEnterEvent; |
39 | class QDragEntryEvent; | 39 | class QDragEntryEvent; |
40 | class QDropEvent; | 40 | class QDropEvent; |
41 | class KConfig; | 41 | class KConfig; |
42 | class AddresseeCardView; | 42 | class AddresseeCardView; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | This view uses the CardView class to create a card view. At some | 45 | This view uses the CardView class to create a card view. At some |
46 | point in the future I think this will be the default view of | 46 | point in the future I think this will be the default view of |
47 | KAddressBook. | 47 | KAddressBook. |
48 | */ | 48 | */ |
49 | class KAddressBookCardView : public KAddressBookView | 49 | class KAddressBookCardView : public KAddressBookView |
50 | { | 50 | { |
51 | Q_OBJECT | 51 | Q_OBJECT |
52 | 52 | ||
53 | public: | 53 | public: |
54 | KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent, | 54 | KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent, |
55 | const char *name = 0 ); | 55 | const char *name = 0 ); |
56 | virtual ~KAddressBookCardView(); | 56 | virtual ~KAddressBookCardView(); |
57 | void doSearch( const QString& s,KABC::Field *field ); | 57 | void doSearch( const QString& s,KABC::Field *field ); |
58 | virtual QStringList selectedUids(); | 58 | virtual QStringList selectedUids(); |
59 | virtual QString type() const { return "Card"; } | 59 | virtual QString type() const { return "Card"; } |
60 | 60 | ||
61 | virtual void readConfig(KConfig *config); | 61 | virtual void readConfig(KConfig *config); |
62 | virtual void writeConfig(KConfig *); | 62 | virtual void writeConfig(KConfig *); |
63 | virtual void scrollUP(); | 63 | virtual void scrollUP(); |
64 | virtual void scrollDOWN(); | 64 | virtual void scrollDOWN(); |
65 | virtual void setFocusAV(); | ||
65 | 66 | ||
66 | public slots: | 67 | public slots: |
67 | void refresh(QString uid = QString::null); | 68 | void refresh(QString uid = QString::null); |
68 | void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/); | 69 | void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/); |
69 | //US added an additional method without parameter | 70 | //US added an additional method without parameter |
70 | void setSelected(); | 71 | void setSelected(); |
71 | 72 | ||
72 | protected slots: | 73 | protected slots: |
73 | void addresseeExecuted(CardViewItem *item); | 74 | void addresseeExecuted(CardViewItem *item); |
74 | void addresseeSelected(); | 75 | void addresseeSelected(); |
75 | 76 | ||
76 | private: | 77 | private: |
77 | AddresseeCardView *mCardView; | 78 | AddresseeCardView *mCardView; |
78 | bool mShowEmptyFields; | 79 | bool mShowEmptyFields; |
79 | }; | 80 | }; |
80 | 81 | ||
81 | class AddresseeCardView : public CardView | 82 | class AddresseeCardView : public CardView |
82 | { | 83 | { |
83 | Q_OBJECT | 84 | Q_OBJECT |
84 | public: | 85 | public: |
85 | AddresseeCardView(QWidget *parent, const char *name = 0); | 86 | AddresseeCardView(QWidget *parent, const char *name = 0); |
86 | ~AddresseeCardView(); | 87 | ~AddresseeCardView(); |
87 | 88 | ||
88 | signals: | 89 | signals: |
89 | void startAddresseeDrag(); | 90 | void startAddresseeDrag(); |
90 | void addresseeDropped(QDropEvent *); | 91 | void addresseeDropped(QDropEvent *); |
91 | 92 | ||
92 | protected: | 93 | protected: |
93 | virtual void dragEnterEvent(QDragEnterEvent *); | 94 | virtual void dragEnterEvent(QDragEnterEvent *); |
94 | virtual void dropEvent(QDropEvent *); | 95 | virtual void dropEvent(QDropEvent *); |
95 | virtual void startDrag(); | 96 | virtual void startDrag(); |
96 | }; | 97 | }; |
97 | 98 | ||
98 | 99 | ||
99 | class CardViewFactory : public ViewFactory | 100 | class CardViewFactory : public ViewFactory |
100 | { | 101 | { |
101 | public: | 102 | public: |
102 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 103 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
103 | { | 104 | { |
104 | return new KAddressBookCardView( ab, parent, name ); | 105 | return new KAddressBookCardView( ab, parent, name ); |
105 | } | 106 | } |
106 | 107 | ||
107 | QString type() const { return "Card"; } | 108 | QString type() const { return "Card"; } |
108 | 109 | ||
109 | QString description() const { return i18n( "Rolodex style cards represent contacts." ); } | 110 | QString description() const { return i18n( "Rolodex style cards represent contacts." ); } |
110 | 111 | ||
111 | ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, | 112 | ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, |
112 | const char *name = 0 ) | 113 | const char *name = 0 ) |
113 | { | 114 | { |
114 | return new ConfigureCardViewWidget( ab, parent, name ); | 115 | return new ConfigureCardViewWidget( ab, parent, name ); |
115 | } | 116 | } |
116 | }; | 117 | }; |
117 | 118 | ||
118 | 119 | ||
119 | #endif | 120 | #endif |
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp index f4c68b8..41c3cb2 100644 --- a/kaddressbook/views/kaddressbookiconview.cpp +++ b/kaddressbook/views/kaddressbookiconview.cpp | |||
@@ -1,446 +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 |
47 | class IconViewFactory : public ViewFactory | 47 | class 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 | ||
62 | extern "C" { | 62 | extern "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 |
72 | AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) | 72 | AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) |
73 | : KIconView(parent, name) | 73 | : KIconView(parent, name) |
74 | #else //KAB_EMBEDDED | 74 | #else //KAB_EMBEDDED |
75 | AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) | 75 | AddresseeIconView::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 | ||
97 | AddresseeIconView::~AddresseeIconView() | 97 | AddresseeIconView::~AddresseeIconView() |
98 | { | 98 | { |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | void AddresseeIconView::itemDropped(QDropEvent *e, | 102 | void 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 | ||
108 | QDragObject *AddresseeIconView::dragObject() | 108 | QDragObject *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 |
118 | class AddresseeIconViewItem : public KIconViewItem | 118 | class AddresseeIconViewItem : public KIconViewItem |
119 | #else //KAB_EMBEDDED | 119 | #else //KAB_EMBEDDED |
120 | class AddresseeIconViewItem : public QIconViewItem | 120 | class 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 | ||
185 | KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab, | 185 | KAddressBookIconView::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 | ||
211 | KAddressBookIconView::~KAddressBookIconView() | 211 | KAddressBookIconView::~KAddressBookIconView() |
212 | { | 212 | { |
213 | } | 213 | } |
214 | void KAddressBookIconView::setFocusAV() | ||
215 | { | ||
216 | if ( mIconView ) | ||
217 | mIconView->setFocus(); | ||
218 | } | ||
219 | |||
214 | 220 | ||
215 | void KAddressBookIconView::scrollUP() | 221 | void KAddressBookIconView::scrollUP() |
216 | { | 222 | { |
217 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | 223 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); |
218 | QApplication::postEvent( mIconView, ev ); | 224 | QApplication::postEvent( mIconView, ev ); |
219 | } | 225 | } |
220 | void KAddressBookIconView::scrollDOWN() | 226 | void KAddressBookIconView::scrollDOWN() |
221 | { | 227 | { |
222 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | 228 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); |
223 | QApplication::postEvent( mIconView, ev ); | 229 | QApplication::postEvent( mIconView, ev ); |
224 | } | 230 | } |
225 | void KAddressBookIconView::readConfig(KConfig *config) | 231 | void KAddressBookIconView::readConfig(KConfig *config) |
226 | { | 232 | { |
227 | KAddressBookView::readConfig(config); | 233 | KAddressBookView::readConfig(config); |
228 | 234 | ||
229 | //US method executed is part of KIconView | 235 | //US method executed is part of KIconView |
230 | //US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), | 236 | //US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), |
231 | //US this, SLOT(addresseeExecuted(QIconViewItem *))); | 237 | //US this, SLOT(addresseeExecuted(QIconViewItem *))); |
232 | disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), | 238 | disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), |
233 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 239 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
234 | 240 | ||
235 | //US method executed is part of KIconView. Use selectionChanged instead | 241 | //US method executed is part of KIconView. Use selectionChanged instead |
236 | /*US | 242 | /*US |
237 | if (KABPrefs::instance()->mHonorSingleClick) | 243 | if (KABPrefs::instance()->mHonorSingleClick) |
238 | connect(mIconView, SIGNAL(executed(QIconViewItem *)), | 244 | connect(mIconView, SIGNAL(executed(QIconViewItem *)), |
239 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 245 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
240 | else | 246 | else |
241 | connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), | 247 | connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), |
242 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 248 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
243 | */ | 249 | */ |
244 | connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), | 250 | connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), |
245 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 251 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
246 | 252 | ||
247 | } | 253 | } |
248 | void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) | 254 | void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) |
249 | { | 255 | { |
250 | mIconView->clear(); | 256 | mIconView->clear(); |
251 | mIconList.clear(); | 257 | mIconList.clear(); |
252 | if ( s.isEmpty() || s == "*" ) { | 258 | if ( s.isEmpty() || s == "*" ) { |
253 | refresh(); | 259 | refresh(); |
254 | return; | 260 | return; |
255 | } | 261 | } |
256 | QString pattern = s.lower()+"*"; | 262 | QString pattern = s.lower()+"*"; |
257 | QRegExp re; | 263 | QRegExp re; |
258 | re.setWildcard(true); // most people understand these better. | 264 | re.setWildcard(true); // most people understand these better. |
259 | re.setCaseSensitive(false); | 265 | re.setCaseSensitive(false); |
260 | re.setPattern( pattern ); | 266 | re.setPattern( pattern ); |
261 | if (!re.isValid()) | 267 | if (!re.isValid()) |
262 | return; | 268 | return; |
263 | KABC::Addressee::List addresseeList = addressees(); | 269 | KABC::Addressee::List addresseeList = addressees(); |
264 | KABC::Addressee::List::Iterator it; | 270 | KABC::Addressee::List::Iterator it; |
265 | if ( field ) { | 271 | if ( field ) { |
266 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 272 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
267 | #if QT_VERSION >= 300 | 273 | #if QT_VERSION >= 300 |
268 | if (re.search(field->value( *it ).lower()) != -1) | 274 | if (re.search(field->value( *it ).lower()) != -1) |
269 | #else | 275 | #else |
270 | if (re.match(field->value( *it ).lower()) != -1) | 276 | if (re.match(field->value( *it ).lower()) != -1) |
271 | #endif | 277 | #endif |
272 | mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); | 278 | mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); |
273 | 279 | ||
274 | 280 | ||
275 | } | 281 | } |
276 | } else { | 282 | } else { |
277 | KABC::Field::List fieldList = fields(); | 283 | KABC::Field::List fieldList = fields(); |
278 | KABC::Field::List::ConstIterator fieldIt; | 284 | KABC::Field::List::ConstIterator fieldIt; |
279 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 285 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
280 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 286 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
281 | #if QT_VERSION >= 300 | 287 | #if QT_VERSION >= 300 |
282 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | 288 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
283 | #else | 289 | #else |
284 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | 290 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) |
285 | #endif | 291 | #endif |
286 | { | 292 | { |
287 | mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); | 293 | mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); |
288 | continue; | 294 | continue; |
289 | } | 295 | } |
290 | } | 296 | } |
291 | } | 297 | } |
292 | } | 298 | } |
293 | mIconView->arrangeItemsInGrid( true ); | 299 | mIconView->arrangeItemsInGrid( true ); |
294 | if ( mIconView->firstItem() ) { | 300 | if ( mIconView->firstItem() ) { |
295 | mIconView->setCurrentItem ( mIconView->firstItem() ); | 301 | mIconView->setCurrentItem ( mIconView->firstItem() ); |
296 | mIconView->setSelected ( mIconView->firstItem() , true ); | 302 | mIconView->setSelected ( mIconView->firstItem() , true ); |
297 | } | 303 | } |
298 | else | 304 | else |
299 | emit selected(QString::null); | 305 | emit selected(QString::null); |
300 | } | 306 | } |
301 | QStringList KAddressBookIconView::selectedUids() | 307 | QStringList KAddressBookIconView::selectedUids() |
302 | { | 308 | { |
303 | QStringList uidList; | 309 | QStringList uidList; |
304 | QIconViewItem *item; | 310 | QIconViewItem *item; |
305 | AddresseeIconViewItem *aItem; | 311 | AddresseeIconViewItem *aItem; |
306 | 312 | ||
307 | for (item = mIconView->firstItem(); item; item = item->nextItem()) | 313 | for (item = mIconView->firstItem(); item; item = item->nextItem()) |
308 | { | 314 | { |
309 | if (item->isSelected()) | 315 | if (item->isSelected()) |
310 | { | 316 | { |
311 | #ifndef KAB_EMBEDDED | 317 | #ifndef KAB_EMBEDDED |
312 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 318 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
313 | #else //KAB_EMBEDDED | 319 | #else //KAB_EMBEDDED |
314 | aItem = (AddresseeIconViewItem*)(item); | 320 | aItem = (AddresseeIconViewItem*)(item); |
315 | #endif //KAB_EMBEDDED | 321 | #endif //KAB_EMBEDDED |
316 | if (aItem) | 322 | if (aItem) |
317 | uidList << aItem->addressee().uid(); | 323 | uidList << aItem->addressee().uid(); |
318 | } | 324 | } |
319 | } | 325 | } |
320 | 326 | ||
321 | return uidList; | 327 | return uidList; |
322 | } | 328 | } |
323 | 329 | ||
324 | void KAddressBookIconView::refresh(QString uid) | 330 | void KAddressBookIconView::refresh(QString uid) |
325 | { | 331 | { |
326 | QIconViewItem *item; | 332 | QIconViewItem *item; |
327 | AddresseeIconViewItem *aItem; | 333 | AddresseeIconViewItem *aItem; |
328 | 334 | ||
329 | if ( uid.isNull() ) { | 335 | if ( uid.isNull() ) { |
330 | // Rebuild the view | 336 | // Rebuild the view |
331 | mIconView->clear(); | 337 | mIconView->clear(); |
332 | mIconList.clear(); | 338 | mIconList.clear(); |
333 | 339 | ||
334 | KABC::Addressee::List addresseeList = addressees(); | 340 | KABC::Addressee::List addresseeList = addressees(); |
335 | KABC::Addressee::List::Iterator iter; | 341 | KABC::Addressee::List::Iterator iter; |
336 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) { | 342 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) { |
337 | 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-") ) |
338 | continue; | 344 | continue; |
339 | aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView ); | 345 | aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView ); |
340 | } | 346 | } |
341 | 347 | ||
342 | mIconView->arrangeItemsInGrid( true ); | 348 | mIconView->arrangeItemsInGrid( true ); |
343 | 349 | ||
344 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) | 350 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) |
345 | { | 351 | { |
346 | #ifndef KAB_EMBEDDED | 352 | #ifndef KAB_EMBEDDED |
347 | AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item ); | 353 | AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item ); |
348 | #else //KAB_EMBEDDED | 354 | #else //KAB_EMBEDDED |
349 | AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item ); | 355 | AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item ); |
350 | #endif //KAB_EMBEDDED | 356 | #endif //KAB_EMBEDDED |
351 | mIconList.append( aivi ); | 357 | mIconList.append( aivi ); |
352 | } | 358 | } |
353 | 359 | ||
354 | } else { | 360 | } else { |
355 | // Try to find the one to refresh | 361 | // Try to find the one to refresh |
356 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { | 362 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { |
357 | #ifndef KAB_EMBEDDED | 363 | #ifndef KAB_EMBEDDED |
358 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 364 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
359 | #else //KAB_EMBEDDED | 365 | #else //KAB_EMBEDDED |
360 | aItem = (AddresseeIconViewItem*)(item); | 366 | aItem = (AddresseeIconViewItem*)(item); |
361 | #endif //KAB_EMBEDDED | 367 | #endif //KAB_EMBEDDED |
362 | if ((aItem) && (aItem->addressee().uid() == uid)) { | 368 | if ((aItem) && (aItem->addressee().uid() == uid)) { |
363 | aItem->refresh(); | 369 | aItem->refresh(); |
364 | mIconView->arrangeItemsInGrid( true ); | 370 | mIconView->arrangeItemsInGrid( true ); |
365 | return; | 371 | return; |
366 | } | 372 | } |
367 | } | 373 | } |
368 | refresh( QString::null ); | 374 | refresh( QString::null ); |
369 | } | 375 | } |
370 | } | 376 | } |
371 | 377 | ||
372 | void KAddressBookIconView::setSelected(QString uid, bool selected) | 378 | void KAddressBookIconView::setSelected(QString uid, bool selected) |
373 | { | 379 | { |
374 | QIconViewItem *item; | 380 | QIconViewItem *item; |
375 | AddresseeIconViewItem *aItem; | 381 | AddresseeIconViewItem *aItem; |
376 | 382 | ||
377 | if (uid.isNull()) | 383 | if (uid.isNull()) |
378 | { | 384 | { |
379 | mIconView->selectAll(selected); | 385 | mIconView->selectAll(selected); |
380 | } | 386 | } |
381 | else | 387 | else |
382 | { | 388 | { |
383 | bool found = false; | 389 | bool found = false; |
384 | for (item = mIconView->firstItem(); item && !found; | 390 | for (item = mIconView->firstItem(); item && !found; |
385 | item = item->nextItem()) | 391 | item = item->nextItem()) |
386 | { | 392 | { |
387 | #ifndef KAB_EMBEDDED | 393 | #ifndef KAB_EMBEDDED |
388 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 394 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
389 | #else //KAB_EMBEDDED | 395 | #else //KAB_EMBEDDED |
390 | aItem = (AddresseeIconViewItem*)(item); | 396 | aItem = (AddresseeIconViewItem*)(item); |
391 | #endif //KAB_EMBEDDED | 397 | #endif //KAB_EMBEDDED |
392 | 398 | ||
393 | if ((aItem) && (aItem->addressee().uid() == uid)) | 399 | if ((aItem) && (aItem->addressee().uid() == uid)) |
394 | { | 400 | { |
395 | mIconView->setSelected(aItem, selected); | 401 | mIconView->setSelected(aItem, selected); |
396 | mIconView->ensureItemVisible( aItem ); | 402 | mIconView->ensureItemVisible( aItem ); |
397 | found = true; | 403 | found = true; |
398 | } | 404 | } |
399 | } | 405 | } |
400 | } | 406 | } |
401 | } | 407 | } |
402 | 408 | ||
403 | void KAddressBookIconView::addresseeExecuted(QIconViewItem *item) | 409 | void KAddressBookIconView::addresseeExecuted(QIconViewItem *item) |
404 | { | 410 | { |
405 | #ifndef KAB_EMBEDDED | 411 | #ifndef KAB_EMBEDDED |
406 | AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 412 | AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
407 | #else //KAB_EMBEDDED | 413 | #else //KAB_EMBEDDED |
408 | AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item); | 414 | AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item); |
409 | #endif //KAB_EMBEDDED | 415 | #endif //KAB_EMBEDDED |
410 | 416 | ||
411 | if (aItem) { | 417 | if (aItem) { |
412 | emit executed(aItem->addressee().uid()); | 418 | emit executed(aItem->addressee().uid()); |
413 | } | 419 | } |
414 | } | 420 | } |
415 | 421 | ||
416 | void KAddressBookIconView::addresseeSelected() | 422 | void KAddressBookIconView::addresseeSelected() |
417 | { | 423 | { |
418 | QIconViewItem *item; | 424 | QIconViewItem *item; |
419 | AddresseeIconViewItem *aItem; | 425 | AddresseeIconViewItem *aItem; |
420 | 426 | ||
421 | bool found = false; | 427 | bool found = false; |
422 | for (item = mIconView->firstItem(); item && !found; | 428 | for (item = mIconView->firstItem(); item && !found; |
423 | item = item->nextItem()) | 429 | item = item->nextItem()) |
424 | { | 430 | { |
425 | if (item->isSelected()) | 431 | if (item->isSelected()) |
426 | { | 432 | { |
427 | #ifndef KAB_EMBEDDED | 433 | #ifndef KAB_EMBEDDED |
428 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 434 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
429 | #else //KAB_EMBEDDED | 435 | #else //KAB_EMBEDDED |
430 | aItem = (AddresseeIconViewItem*)(item); | 436 | aItem = (AddresseeIconViewItem*)(item); |
431 | #endif //KAB_EMBEDDED | 437 | #endif //KAB_EMBEDDED |
432 | if (aItem) | 438 | if (aItem) |
433 | { | 439 | { |
434 | emit selected(aItem->addressee().uid()); | 440 | emit selected(aItem->addressee().uid()); |
435 | found = true; | 441 | found = true; |
436 | } | 442 | } |
437 | } | 443 | } |
438 | } | 444 | } |
439 | 445 | ||
440 | if (!found) | 446 | if (!found) |
441 | emit selected(QString::null); | 447 | emit selected(QString::null); |
442 | } | 448 | } |
443 | 449 | ||
444 | #ifndef KAB_EMBEDDED | 450 | #ifndef KAB_EMBEDDED |
445 | #include "kaddressbookiconview.moc" | 451 | #include "kaddressbookiconview.moc" |
446 | #endif //KAB_EMBEDDED | 452 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h index acfcd71..b0b9fea 100644 --- a/kaddressbook/views/kaddressbookiconview.h +++ b/kaddressbook/views/kaddressbookiconview.h | |||
@@ -1,133 +1,134 @@ | |||
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 KADDRESSBOOKICONVIEW_H | 24 | #ifndef KADDRESSBOOKICONVIEW_H |
25 | #define KADDRESSBOOKICONVIEW_H | 25 | #define KADDRESSBOOKICONVIEW_H |
26 | 26 | ||
27 | #include <qstring.h> | 27 | #include <qstring.h> |
28 | #ifndef KAB_EMBEDDED | 28 | #ifndef KAB_EMBEDDED |
29 | #include <kiconview.h> | 29 | #include <kiconview.h> |
30 | #else //KAB_EMBEDDED | 30 | #else //KAB_EMBEDDED |
31 | #include <qiconview.h> | 31 | #include <qiconview.h> |
32 | #include <qptrlist.h> | 32 | #include <qptrlist.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | #endif //KAB_EMBEDDED | 34 | #endif //KAB_EMBEDDED |
35 | #include "kaddressbookview.h" | 35 | #include "kaddressbookview.h" |
36 | 36 | ||
37 | class QIconViewItem; | 37 | class QIconViewItem; |
38 | class KConfig; | 38 | class KConfig; |
39 | class AddresseeIconView; | 39 | class AddresseeIconView; |
40 | class AddresseeIconViewItem; | 40 | class AddresseeIconViewItem; |
41 | class QIconDragItem; | 41 | class QIconDragItem; |
42 | class KAddressBookIconView; | 42 | class KAddressBookIconView; |
43 | 43 | ||
44 | namespace KABC { class AddressBook; } | 44 | namespace KABC { class AddressBook; } |
45 | 45 | ||
46 | /** This is an example kaddressbook view that is implemented using | 46 | /** This is an example kaddressbook view that is implemented using |
47 | * KIconView. This view is not the most useful view, but it displays | 47 | * KIconView. This view is not the most useful view, but it displays |
48 | * how simple implementing a new view can be. | 48 | * how simple implementing a new view can be. |
49 | */ | 49 | */ |
50 | class KAddressBookIconView : public KAddressBookView | 50 | class KAddressBookIconView : public KAddressBookView |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | public: | 54 | public: |
55 | KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent, | 55 | KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent, |
56 | const char *name = 0 ); | 56 | const char *name = 0 ); |
57 | virtual ~KAddressBookIconView(); | 57 | virtual ~KAddressBookIconView(); |
58 | 58 | ||
59 | virtual QStringList selectedUids(); | 59 | virtual QStringList selectedUids(); |
60 | virtual QString type() const { return "Icon"; } | 60 | virtual QString type() const { return "Icon"; } |
61 | void doSearch( const QString& s ,KABC::Field *field ); | 61 | void doSearch( const QString& s ,KABC::Field *field ); |
62 | 62 | ||
63 | virtual void readConfig(KConfig *config); | 63 | virtual void readConfig(KConfig *config); |
64 | virtual void scrollUP(); | 64 | virtual void scrollUP(); |
65 | virtual void scrollDOWN(); | 65 | virtual void scrollDOWN(); |
66 | virtual void setFocusAV(); | ||
66 | 67 | ||
67 | public slots: | 68 | public slots: |
68 | void refresh(QString uid = QString::null); | 69 | void refresh(QString uid = QString::null); |
69 | #ifndef KAB_EMBEDDED | 70 | #ifndef KAB_EMBEDDED |
70 | //MOC_SKIP_BEGIN | 71 | //MOC_SKIP_BEGIN |
71 | void setSelected(QString uid = QString::null, bool selected = true); | 72 | void setSelected(QString uid = QString::null, bool selected = true); |
72 | //MOC_SKIP_END | 73 | //MOC_SKIP_END |
73 | #else //KAB_EMBEDDED | 74 | #else //KAB_EMBEDDED |
74 | //US my MOC do not like default parameters ??? | 75 | //US my MOC do not like default parameters ??? |
75 | void setSelected(QString uid, bool selected); | 76 | void setSelected(QString uid, bool selected); |
76 | #endif //KAB_EMBEDDED | 77 | #endif //KAB_EMBEDDED |
77 | 78 | ||
78 | protected slots: | 79 | protected slots: |
79 | void addresseeExecuted(QIconViewItem *item); | 80 | void addresseeExecuted(QIconViewItem *item); |
80 | void addresseeSelected(); | 81 | void addresseeSelected(); |
81 | 82 | ||
82 | private: | 83 | private: |
83 | AddresseeIconView *mIconView; | 84 | AddresseeIconView *mIconView; |
84 | QPtrList<AddresseeIconViewItem> mIconList; | 85 | QPtrList<AddresseeIconViewItem> mIconList; |
85 | }; | 86 | }; |
86 | 87 | ||
87 | 88 | ||
88 | #ifndef KAB_EMBEDDED | 89 | #ifndef KAB_EMBEDDED |
89 | //MOC_SKIP_BEGIN | 90 | //MOC_SKIP_BEGIN |
90 | class AddresseeIconView : public KIconView | 91 | class AddresseeIconView : public KIconView |
91 | //MOC_SKIP_END | 92 | //MOC_SKIP_END |
92 | #else //KAB_EMBEDDED | 93 | #else //KAB_EMBEDDED |
93 | class AddresseeIconView : public QIconView | 94 | class AddresseeIconView : public QIconView |
94 | #endif //KAB_EMBEDDED | 95 | #endif //KAB_EMBEDDED |
95 | { | 96 | { |
96 | Q_OBJECT | 97 | Q_OBJECT |
97 | 98 | ||
98 | public: | 99 | public: |
99 | AddresseeIconView(QWidget *parent, const char *name); | 100 | AddresseeIconView(QWidget *parent, const char *name); |
100 | ~AddresseeIconView(); | 101 | ~AddresseeIconView(); |
101 | 102 | ||
102 | signals: | 103 | signals: |
103 | void addresseeDropped(QDropEvent *); | 104 | void addresseeDropped(QDropEvent *); |
104 | void startAddresseeDrag(); | 105 | void startAddresseeDrag(); |
105 | 106 | ||
106 | protected: | 107 | protected: |
107 | virtual QDragObject *dragObject(); | 108 | virtual QDragObject *dragObject(); |
108 | 109 | ||
109 | protected slots: | 110 | protected slots: |
110 | void itemDropped(QDropEvent *, const QValueList<QIconDragItem> &); | 111 | void itemDropped(QDropEvent *, const QValueList<QIconDragItem> &); |
111 | }; | 112 | }; |
112 | 113 | ||
113 | class IconViewFactory : public ViewFactory | 114 | class IconViewFactory : public ViewFactory |
114 | { | 115 | { |
115 | public: | 116 | public: |
116 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 117 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
117 | { | 118 | { |
118 | return new KAddressBookIconView( ab, parent, name ); | 119 | return new KAddressBookIconView( ab, parent, name ); |
119 | } | 120 | } |
120 | 121 | ||
121 | QString type() const { return "Icon"; } | 122 | QString type() const { return "Icon"; } |
122 | 123 | ||
123 | QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } | 124 | QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } |
124 | }; | 125 | }; |
125 | /* | 126 | /* |
126 | extern "C" { | 127 | extern "C" { |
127 | void *init_libkaddrbk_iconview() | 128 | void *init_libkaddrbk_iconview() |
128 | { | 129 | { |
129 | return ( new IconViewFactory ); | 130 | return ( new IconViewFactory ); |
130 | } | 131 | } |
131 | } | 132 | } |
132 | */ | 133 | */ |
133 | #endif | 134 | #endif |
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index 2412170..e40eb9e 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp | |||
@@ -1,459 +1,465 @@ | |||
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 | ||
41 | KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, | 41 | KAddressBookTableView::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 | ||
51 | KAddressBookTableView::~KAddressBookTableView() | 51 | KAddressBookTableView::~KAddressBookTableView() |
52 | { | 52 | { |
53 | } | 53 | } |
54 | void KAddressBookTableView::setFocusAV() | ||
55 | { | ||
56 | if ( mListView ) | ||
57 | mListView->setFocus(); | ||
58 | |||
59 | } | ||
54 | void KAddressBookTableView::scrollUP() | 60 | void KAddressBookTableView::scrollUP() |
55 | { | 61 | { |
56 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | 62 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); |
57 | QApplication::postEvent( mListView, ev ); | 63 | QApplication::postEvent( mListView, ev ); |
58 | } | 64 | } |
59 | void KAddressBookTableView::scrollDOWN() | 65 | void KAddressBookTableView::scrollDOWN() |
60 | { | 66 | { |
61 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | 67 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); |
62 | QApplication::postEvent( mListView, ev ); | 68 | QApplication::postEvent( mListView, ev ); |
63 | } | 69 | } |
64 | void KAddressBookTableView::reconstructListView() | 70 | void KAddressBookTableView::reconstructListView() |
65 | { | 71 | { |
66 | if (mListView) | 72 | if (mListView) |
67 | { | 73 | { |
68 | disconnect(mListView, SIGNAL(selectionChanged()), | 74 | disconnect(mListView, SIGNAL(selectionChanged()), |
69 | this, SLOT(addresseeSelected())); | 75 | this, SLOT(addresseeSelected())); |
70 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), | 76 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), |
71 | this, SLOT(addresseeExecuted(QListViewItem*))); | 77 | this, SLOT(addresseeExecuted(QListViewItem*))); |
72 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 78 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
73 | this, SLOT(addresseeExecuted(QListViewItem*))); | 79 | this, SLOT(addresseeExecuted(QListViewItem*))); |
74 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, | 80 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, |
75 | SIGNAL(startDrag())); | 81 | SIGNAL(startDrag())); |
76 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 82 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
77 | this, SLOT(addresseeExecuted(QListViewItem*))); | 83 | this, SLOT(addresseeExecuted(QListViewItem*))); |
78 | 84 | ||
79 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 85 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
80 | SIGNAL(dropped(QDropEvent*))); | 86 | SIGNAL(dropped(QDropEvent*))); |
81 | delete mListView; | 87 | delete mListView; |
82 | } | 88 | } |
83 | 89 | ||
84 | mListView = new ContactListView( this, addressBook(), viewWidget() ); | 90 | mListView = new ContactListView( this, addressBook(), viewWidget() ); |
85 | 91 | ||
86 | // Add the columns | 92 | // Add the columns |
87 | KABC::Field::List fieldList = fields(); | 93 | KABC::Field::List fieldList = fields(); |
88 | KABC::Field::List::ConstIterator it; | 94 | KABC::Field::List::ConstIterator it; |
89 | 95 | ||
90 | int c = 0; | 96 | int c = 0; |
91 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { | 97 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { |
92 | mListView->addColumn( (*it)->label() ); | 98 | mListView->addColumn( (*it)->label() ); |
93 | mListView->setColumnWidthMode(c++, QListView::Manual); | 99 | mListView->setColumnWidthMode(c++, QListView::Manual); |
94 | //US | 100 | //US |
95 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); | 101 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); |
96 | } | 102 | } |
97 | 103 | ||
98 | connect(mListView, SIGNAL(selectionChanged()), | 104 | connect(mListView, SIGNAL(selectionChanged()), |
99 | this, SLOT(addresseeSelected())); | 105 | this, SLOT(addresseeSelected())); |
100 | connect(mListView, SIGNAL(startAddresseeDrag()), this, | 106 | connect(mListView, SIGNAL(startAddresseeDrag()), this, |
101 | SIGNAL(startDrag())); | 107 | SIGNAL(startDrag())); |
102 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 108 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
103 | SIGNAL(dropped(QDropEvent*))); | 109 | SIGNAL(dropped(QDropEvent*))); |
104 | 110 | ||
105 | if (KABPrefs::instance()->mHonorSingleClick) | 111 | if (KABPrefs::instance()->mHonorSingleClick) |
106 | connect(mListView, SIGNAL(executed(QListViewItem*)), | 112 | connect(mListView, SIGNAL(executed(QListViewItem*)), |
107 | this, SLOT(addresseeExecuted(QListViewItem*))); | 113 | this, SLOT(addresseeExecuted(QListViewItem*))); |
108 | else | 114 | else |
109 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 115 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
110 | this, SLOT(addresseeExecuted(QListViewItem*))); | 116 | this, SLOT(addresseeExecuted(QListViewItem*))); |
111 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 117 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
112 | this, SLOT(addresseeExecuted(QListViewItem*))); | 118 | this, SLOT(addresseeExecuted(QListViewItem*))); |
113 | connect(mListView, SIGNAL(signalDelete()), | 119 | connect(mListView, SIGNAL(signalDelete()), |
114 | this, SLOT(addresseeDeleted())); | 120 | this, SLOT(addresseeDeleted())); |
115 | 121 | ||
116 | //US performceimprovement. Refresh is done from the outside | 122 | //US performceimprovement. Refresh is done from the outside |
117 | //US refresh(); | 123 | //US refresh(); |
118 | 124 | ||
119 | mListView->setSorting( 0, true ); | 125 | mListView->setSorting( 0, true ); |
120 | mainLayout->addWidget( mListView ); | 126 | mainLayout->addWidget( mListView ); |
121 | mainLayout->activate(); | 127 | mainLayout->activate(); |
122 | mListView->show(); | 128 | mListView->show(); |
123 | } | 129 | } |
124 | 130 | ||
125 | void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) | 131 | void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) |
126 | { | 132 | { |
127 | mListView->clear(); | 133 | mListView->clear(); |
128 | if ( s.isEmpty() || s == "*" ) { | 134 | if ( s.isEmpty() || s == "*" ) { |
129 | refresh(); | 135 | refresh(); |
130 | return; | 136 | return; |
131 | } | 137 | } |
132 | QString pattern = s.lower()+"*"; | 138 | QString pattern = s.lower()+"*"; |
133 | QRegExp re; | 139 | QRegExp re; |
134 | re.setWildcard(true); // most people understand these better. | 140 | re.setWildcard(true); // most people understand these better. |
135 | re.setCaseSensitive(false); | 141 | re.setCaseSensitive(false); |
136 | re.setPattern( pattern ); | 142 | re.setPattern( pattern ); |
137 | if (!re.isValid()) | 143 | if (!re.isValid()) |
138 | return; | 144 | return; |
139 | KABC::Addressee::List addresseeList = addressees(); | 145 | KABC::Addressee::List addresseeList = addressees(); |
140 | KABC::Addressee::List::Iterator it; | 146 | KABC::Addressee::List::Iterator it; |
141 | if ( field ) { | 147 | if ( field ) { |
142 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 148 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
143 | #if QT_VERSION >= 300 | 149 | #if QT_VERSION >= 300 |
144 | if (re.search(field->value( *it ).lower()) != -1) | 150 | if (re.search(field->value( *it ).lower()) != -1) |
145 | #else | 151 | #else |
146 | if (re.match(field->value( *it ).lower()) != -1) | 152 | if (re.match(field->value( *it ).lower()) != -1) |
147 | #endif | 153 | #endif |
148 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 154 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
149 | 155 | ||
150 | } | 156 | } |
151 | } else { | 157 | } else { |
152 | KABC::Field::List fieldList = fields(); | 158 | KABC::Field::List fieldList = fields(); |
153 | KABC::Field::List::ConstIterator fieldIt; | 159 | KABC::Field::List::ConstIterator fieldIt; |
154 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 160 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
155 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 161 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
156 | #if QT_VERSION >= 300 | 162 | #if QT_VERSION >= 300 |
157 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | 163 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
158 | #else | 164 | #else |
159 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | 165 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) |
160 | #endif | 166 | #endif |
161 | { | 167 | { |
162 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 168 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
163 | break; | 169 | break; |
164 | } | 170 | } |
165 | } | 171 | } |
166 | } | 172 | } |
167 | } | 173 | } |
168 | // Sometimes the background pixmap gets messed up when we add lots | 174 | // Sometimes the background pixmap gets messed up when we add lots |
169 | // of items. | 175 | // of items. |
170 | mListView->repaint(); | 176 | mListView->repaint(); |
171 | if ( mListView->firstChild() ) { | 177 | if ( mListView->firstChild() ) { |
172 | mListView->setCurrentItem ( mListView->firstChild() ); | 178 | mListView->setCurrentItem ( mListView->firstChild() ); |
173 | mListView->setSelected ( mListView->firstChild(), true ); | 179 | mListView->setSelected ( mListView->firstChild(), true ); |
174 | } | 180 | } |
175 | else | 181 | else |
176 | emit selected(QString::null); | 182 | emit selected(QString::null); |
177 | 183 | ||
178 | } | 184 | } |
179 | void KAddressBookTableView::writeConfig(KConfig *config) | 185 | void KAddressBookTableView::writeConfig(KConfig *config) |
180 | { | 186 | { |
181 | KAddressBookView::writeConfig(config); | 187 | KAddressBookView::writeConfig(config); |
182 | 188 | ||
183 | mListView->saveLayout(config, config->group()); | 189 | mListView->saveLayout(config, config->group()); |
184 | } | 190 | } |
185 | 191 | ||
186 | void KAddressBookTableView::readConfig(KConfig *config) | 192 | void KAddressBookTableView::readConfig(KConfig *config) |
187 | { | 193 | { |
188 | KAddressBookView::readConfig( config ); | 194 | KAddressBookView::readConfig( config ); |
189 | // The config could have changed the fields, so we need to reconstruct | 195 | // The config could have changed the fields, so we need to reconstruct |
190 | // the listview. | 196 | // the listview. |
191 | reconstructListView(); | 197 | reconstructListView(); |
192 | 198 | ||
193 | // costum colors? | 199 | // costum colors? |
194 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 200 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
195 | { | 201 | { |
196 | QPalette p( mListView->palette() ); | 202 | QPalette p( mListView->palette() ); |
197 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 203 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
198 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 204 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
199 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 205 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
200 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 206 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
201 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 207 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
202 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 208 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
203 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 209 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
204 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 210 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
205 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 211 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
206 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 212 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
207 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 213 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
208 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 214 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
209 | #ifndef KAB_EMBEDDED | 215 | #ifndef KAB_EMBEDDED |
210 | c = KGlobalSettings::alternateBackgroundColor(); | 216 | c = KGlobalSettings::alternateBackgroundColor(); |
211 | #else //KAB_EMBEDDED | 217 | #else //KAB_EMBEDDED |
212 | c = QColor(240, 240, 240); | 218 | c = QColor(240, 240, 240); |
213 | #endif //KAB_EMBEDDED | 219 | #endif //KAB_EMBEDDED |
214 | c = config->readColorEntry ("AlternatingBackgroundColor", &c); | 220 | c = config->readColorEntry ("AlternatingBackgroundColor", &c); |
215 | mListView->setAlternateColor(c); | 221 | mListView->setAlternateColor(c); |
216 | 222 | ||
217 | 223 | ||
218 | //US mListView->viewport()->setPalette( p ); | 224 | //US mListView->viewport()->setPalette( p ); |
219 | mListView->setPalette( p ); | 225 | mListView->setPalette( p ); |
220 | } | 226 | } |
221 | else | 227 | else |
222 | { | 228 | { |
223 | // needed if turned off during a session. | 229 | // needed if turned off during a session. |
224 | //US mListView->viewport()->setPalette( mListView->palette() ); | 230 | //US mListView->viewport()->setPalette( mListView->palette() ); |
225 | mListView->setPalette( mListView->palette() ); | 231 | mListView->setPalette( mListView->palette() ); |
226 | } | 232 | } |
227 | 233 | ||
228 | //custom fonts? | 234 | //custom fonts? |
229 | QFont f( font() ); | 235 | QFont f( font() ); |
230 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 236 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
231 | { | 237 | { |
232 | mListView->setFont( config->readFontEntry( "TextFont", &f) ); | 238 | mListView->setFont( config->readFontEntry( "TextFont", &f) ); |
233 | f.setBold( true ); | 239 | f.setBold( true ); |
234 | //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 240 | //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
235 | mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); | 241 | mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); |
236 | } | 242 | } |
237 | else | 243 | else |
238 | { | 244 | { |
239 | mListView->setFont( f ); | 245 | mListView->setFont( f ); |
240 | f.setBold( true ); | 246 | f.setBold( true ); |
241 | //US mListView->setHeaderFont( f ); | 247 | //US mListView->setHeaderFont( f ); |
242 | mListView->header()->setFont( f ); | 248 | mListView->header()->setFont( f ); |
243 | } | 249 | } |
244 | 250 | ||
245 | 251 | ||
246 | 252 | ||
247 | 253 | ||
248 | 254 | ||
249 | // Set the list view options | 255 | // Set the list view options |
250 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", | 256 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", |
251 | true)); | 257 | true)); |
252 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); | 258 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); |
253 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); | 259 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); |
254 | 260 | ||
255 | if (config->readBoolEntry("Background", false)) | 261 | if (config->readBoolEntry("Background", false)) |
256 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); | 262 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); |
257 | 263 | ||
258 | // Restore the layout of the listview | 264 | // Restore the layout of the listview |
259 | mListView->restoreLayout(config, config->group()); | 265 | mListView->restoreLayout(config, config->group()); |
260 | } | 266 | } |
261 | 267 | ||
262 | void KAddressBookTableView::refresh(QString uid) | 268 | void KAddressBookTableView::refresh(QString uid) |
263 | { | 269 | { |
264 | // For now just repopulate. In reality this method should | 270 | // For now just repopulate. In reality this method should |
265 | // check the value of uid, and if valid iterate through | 271 | // check the value of uid, and if valid iterate through |
266 | // the listview to find the entry, then tell it to refresh. | 272 | // the listview to find the entry, then tell it to refresh. |
267 | 273 | ||
268 | if (uid.isNull()) { | 274 | if (uid.isNull()) { |
269 | // Clear the list view | 275 | // Clear the list view |
270 | QString currentUID, nextUID; | 276 | QString currentUID, nextUID; |
271 | #ifndef KAB_EMBEDDED | 277 | #ifndef KAB_EMBEDDED |
272 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); | 278 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); |
273 | #else //KAB_EMBEDDED | 279 | #else //KAB_EMBEDDED |
274 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); | 280 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); |
275 | #endif //KAB_EMBEDDED | 281 | #endif //KAB_EMBEDDED |
276 | 282 | ||
277 | if ( currentItem ) { | 283 | if ( currentItem ) { |
278 | #ifndef KAB_EMBEDDED | 284 | #ifndef KAB_EMBEDDED |
279 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); | 285 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); |
280 | #else //KAB_EMBEDDED | 286 | #else //KAB_EMBEDDED |
281 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); | 287 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); |
282 | #endif //KAB_EMBEDDED | 288 | #endif //KAB_EMBEDDED |
283 | if ( nextItem ) | 289 | if ( nextItem ) |
284 | nextUID = nextItem->addressee().uid(); | 290 | nextUID = nextItem->addressee().uid(); |
285 | currentUID = currentItem->addressee().uid(); | 291 | currentUID = currentItem->addressee().uid(); |
286 | } | 292 | } |
287 | 293 | ||
288 | mListView->clear(); | 294 | mListView->clear(); |
289 | 295 | ||
290 | currentItem = 0; | 296 | currentItem = 0; |
291 | KABC::Addressee::List addresseeList = addressees(); | 297 | KABC::Addressee::List addresseeList = addressees(); |
292 | KABC::Addressee::List::Iterator it; | 298 | KABC::Addressee::List::Iterator it; |
293 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 299 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
294 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) | 300 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) |
295 | continue; | 301 | continue; |
296 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 302 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
297 | if ( (*it).uid() == currentUID ) | 303 | if ( (*it).uid() == currentUID ) |
298 | currentItem = item; | 304 | currentItem = item; |
299 | else if ( (*it).uid() == nextUID && !currentItem ) | 305 | else if ( (*it).uid() == nextUID && !currentItem ) |
300 | currentItem = item; | 306 | currentItem = item; |
301 | } | 307 | } |
302 | 308 | ||
303 | // Sometimes the background pixmap gets messed up when we add lots | 309 | // Sometimes the background pixmap gets messed up when we add lots |
304 | // of items. | 310 | // of items. |
305 | mListView->repaint(); | 311 | mListView->repaint(); |
306 | 312 | ||
307 | if ( currentItem ) { | 313 | if ( currentItem ) { |
308 | mListView->setCurrentItem( currentItem ); | 314 | mListView->setCurrentItem( currentItem ); |
309 | mListView->ensureItemVisible( currentItem ); | 315 | mListView->ensureItemVisible( currentItem ); |
310 | } | 316 | } |
311 | } else { | 317 | } else { |
312 | // Only need to update on entry. Iterate through and try to find it | 318 | // Only need to update on entry. Iterate through and try to find it |
313 | ContactListViewItem *ceItem; | 319 | ContactListViewItem *ceItem; |
314 | QListViewItemIterator it( mListView ); | 320 | QListViewItemIterator it( mListView ); |
315 | while ( it.current() ) { | 321 | while ( it.current() ) { |
316 | #ifndef KAB_EMBEDDED | 322 | #ifndef KAB_EMBEDDED |
317 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); | 323 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); |
318 | #else //KAB_EMBEDDED | 324 | #else //KAB_EMBEDDED |
319 | ceItem = (ContactListViewItem*)( it.current() ); | 325 | ceItem = (ContactListViewItem*)( it.current() ); |
320 | #endif //KAB_EMBEDDED | 326 | #endif //KAB_EMBEDDED |
321 | 327 | ||
322 | if ( ceItem && ceItem->addressee().uid() == uid ) { | 328 | if ( ceItem && ceItem->addressee().uid() == uid ) { |
323 | ceItem->refresh(); | 329 | ceItem->refresh(); |
324 | return; | 330 | return; |
325 | } | 331 | } |
326 | ++it; | 332 | ++it; |
327 | } | 333 | } |
328 | 334 | ||
329 | refresh( QString::null ); | 335 | refresh( QString::null ); |
330 | } | 336 | } |
331 | } | 337 | } |
332 | 338 | ||
333 | QStringList KAddressBookTableView::selectedUids() | 339 | QStringList KAddressBookTableView::selectedUids() |
334 | { | 340 | { |
335 | QStringList uidList; | 341 | QStringList uidList; |
336 | QListViewItem *item; | 342 | QListViewItem *item; |
337 | ContactListViewItem *ceItem; | 343 | ContactListViewItem *ceItem; |
338 | 344 | ||
339 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 345 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
340 | { | 346 | { |
341 | if (mListView->isSelected( item )) | 347 | if (mListView->isSelected( item )) |
342 | { | 348 | { |
343 | #ifndef KAB_EMBEDDED | 349 | #ifndef KAB_EMBEDDED |
344 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 350 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
345 | #else //KAB_EMBEDDED | 351 | #else //KAB_EMBEDDED |
346 | ceItem = (ContactListViewItem*)(item); | 352 | ceItem = (ContactListViewItem*)(item); |
347 | #endif //KAB_EMBEDDED | 353 | #endif //KAB_EMBEDDED |
348 | 354 | ||
349 | if (ceItem != 0L) | 355 | if (ceItem != 0L) |
350 | uidList << ceItem->addressee().uid(); | 356 | uidList << ceItem->addressee().uid(); |
351 | } | 357 | } |
352 | } | 358 | } |
353 | if ( uidList.count() == 0 ) | 359 | if ( uidList.count() == 0 ) |
354 | if ( mListView->currentItem() ) { | 360 | if ( mListView->currentItem() ) { |
355 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; | 361 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; |
356 | uidList << ceItem->addressee().uid(); | 362 | uidList << ceItem->addressee().uid(); |
357 | } | 363 | } |
358 | 364 | ||
359 | return uidList; | 365 | return uidList; |
360 | } | 366 | } |
361 | 367 | ||
362 | void KAddressBookTableView::setSelected(QString uid, bool selected) | 368 | void KAddressBookTableView::setSelected(QString uid, bool selected) |
363 | { | 369 | { |
364 | QListViewItem *item; | 370 | QListViewItem *item; |
365 | ContactListViewItem *ceItem; | 371 | ContactListViewItem *ceItem; |
366 | 372 | ||
367 | if (uid.isNull()) | 373 | if (uid.isNull()) |
368 | { | 374 | { |
369 | mListView->selectAll(selected); | 375 | mListView->selectAll(selected); |
370 | } | 376 | } |
371 | else | 377 | else |
372 | { | 378 | { |
373 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 379 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
374 | { | 380 | { |
375 | #ifndef KAB_EMBEDDED | 381 | #ifndef KAB_EMBEDDED |
376 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 382 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
377 | #else //KAB_EMBEDDED | 383 | #else //KAB_EMBEDDED |
378 | ceItem = (ContactListViewItem*)(item); | 384 | ceItem = (ContactListViewItem*)(item); |
379 | #endif //KAB_EMBEDDED | 385 | #endif //KAB_EMBEDDED |
380 | 386 | ||
381 | 387 | ||
382 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) | 388 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) |
383 | { | 389 | { |
384 | mListView->setSelected(item, selected); | 390 | mListView->setSelected(item, selected); |
385 | 391 | ||
386 | if (selected) | 392 | if (selected) |
387 | mListView->ensureItemVisible(item); | 393 | mListView->ensureItemVisible(item); |
388 | } | 394 | } |
389 | } | 395 | } |
390 | } | 396 | } |
391 | } | 397 | } |
392 | 398 | ||
393 | void KAddressBookTableView::addresseeSelected() | 399 | void KAddressBookTableView::addresseeSelected() |
394 | { | 400 | { |
395 | // We need to try to find the first selected item. This might not be the | 401 | // We need to try to find the first selected item. This might not be the |
396 | // last selected item, but when QListView is in multiselection mode, | 402 | // last selected item, but when QListView is in multiselection mode, |
397 | // there is no way to figure out which one was | 403 | // there is no way to figure out which one was |
398 | // selected last. | 404 | // selected last. |
399 | QListViewItem *item; | 405 | QListViewItem *item; |
400 | bool found =false; | 406 | bool found =false; |
401 | for (item = mListView->firstChild(); item && !found; | 407 | for (item = mListView->firstChild(); item && !found; |
402 | item = item->nextSibling()) | 408 | item = item->nextSibling()) |
403 | { | 409 | { |
404 | if (item->isSelected()) | 410 | if (item->isSelected()) |
405 | { | 411 | { |
406 | found = true; | 412 | found = true; |
407 | #ifndef KAB_EMBEDDED | 413 | #ifndef KAB_EMBEDDED |
408 | ContactListViewItem *ceItem | 414 | ContactListViewItem *ceItem |
409 | = dynamic_cast<ContactListViewItem*>(item); | 415 | = dynamic_cast<ContactListViewItem*>(item); |
410 | #else //KAB_EMBEDDED | 416 | #else //KAB_EMBEDDED |
411 | ContactListViewItem *ceItem | 417 | ContactListViewItem *ceItem |
412 | = (ContactListViewItem*)(item); | 418 | = (ContactListViewItem*)(item); |
413 | #endif //KAB_EMBEDDED | 419 | #endif //KAB_EMBEDDED |
414 | 420 | ||
415 | if ( ceItem ) emit selected(ceItem->addressee().uid()); | 421 | if ( ceItem ) emit selected(ceItem->addressee().uid()); |
416 | } | 422 | } |
417 | } | 423 | } |
418 | 424 | ||
419 | if (!found) | 425 | if (!found) |
420 | emit selected(QString::null); | 426 | emit selected(QString::null); |
421 | } | 427 | } |
422 | 428 | ||
423 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) | 429 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) |
424 | { | 430 | { |
425 | if (item) | 431 | if (item) |
426 | { | 432 | { |
427 | #ifndef KAB_EMBEDDED | 433 | #ifndef KAB_EMBEDDED |
428 | ContactListViewItem *ceItem | 434 | ContactListViewItem *ceItem |
429 | = dynamic_cast<ContactListViewItem*>(item); | 435 | = dynamic_cast<ContactListViewItem*>(item); |
430 | #else //KAB_EMBEDDED | 436 | #else //KAB_EMBEDDED |
431 | ContactListViewItem *ceItem | 437 | ContactListViewItem *ceItem |
432 | = (ContactListViewItem*)(item); | 438 | = (ContactListViewItem*)(item); |
433 | #endif //KAB_EMBEDDED | 439 | #endif //KAB_EMBEDDED |
434 | 440 | ||
435 | if (ceItem) | 441 | if (ceItem) |
436 | { | 442 | { |
437 | emit executed(ceItem->addressee().uid()); | 443 | emit executed(ceItem->addressee().uid()); |
438 | } | 444 | } |
439 | } | 445 | } |
440 | else | 446 | else |
441 | { | 447 | { |
442 | emit executed(QString::null); | 448 | emit executed(QString::null); |
443 | } | 449 | } |
444 | } | 450 | } |
445 | 451 | ||
446 | void KAddressBookTableView::addresseeDeleted() | 452 | void KAddressBookTableView::addresseeDeleted() |
447 | { | 453 | { |
448 | 454 | ||
449 | emit deleteRequest(); | 455 | emit deleteRequest(); |
450 | 456 | ||
451 | } | 457 | } |
452 | 458 | ||
453 | 459 | ||
454 | 460 | ||
455 | 461 | ||
456 | 462 | ||
457 | #ifndef KAB_EMBEDDED | 463 | #ifndef KAB_EMBEDDED |
458 | #include "kaddressbooktableview.moc" | 464 | #include "kaddressbooktableview.moc" |
459 | #endif //KAB_EMBEDDED | 465 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h index 865f8d5..38db7b4 100644 --- a/kaddressbook/views/kaddressbooktableview.h +++ b/kaddressbook/views/kaddressbooktableview.h | |||
@@ -1,117 +1,118 @@ | |||
1 | #ifndef KADDRESSBOOKTABLEVIEW_H | 1 | #ifndef KADDRESSBOOKTABLEVIEW_H |
2 | #define KADDRESSBOOKTABLEVIEW_H | 2 | #define KADDRESSBOOKTABLEVIEW_H |
3 | 3 | ||
4 | 4 | ||
5 | #ifndef KAB_EMBEDDED | 5 | #ifndef KAB_EMBEDDED |
6 | 6 | ||
7 | 7 | ||
8 | #ifdef HAVE_CONFIG_H | 8 | #ifdef HAVE_CONFIG_H |
9 | #include <config.h> | 9 | #include <config.h> |
10 | #endif | 10 | #endif |
11 | 11 | ||
12 | #include <qwidget.h> | 12 | #include <qwidget.h> |
13 | #include <qlistview.h> | 13 | #include <qlistview.h> |
14 | #include <qstring.h> | 14 | #include <qstring.h> |
15 | #include <qdialog.h> | 15 | #include <qdialog.h> |
16 | #include <qtabdialog.h> | 16 | #include <qtabdialog.h> |
17 | #include <qstringlist.h> | 17 | #include <qstringlist.h> |
18 | #include <qvaluelist.h> | 18 | #include <qvaluelist.h> |
19 | 19 | ||
20 | #include "undo.h" | 20 | #include "undo.h" |
21 | 21 | ||
22 | #else //KAB_EMBEDDED | 22 | #else //KAB_EMBEDDED |
23 | #include "views/configuretableviewdialog.h" | 23 | #include "views/configuretableviewdialog.h" |
24 | #endif //KAB_EMBEDDED | 24 | #endif //KAB_EMBEDDED |
25 | 25 | ||
26 | #include "klocale.h" | 26 | #include "klocale.h" |
27 | #include "kaddressbookview.h" | 27 | #include "kaddressbookview.h" |
28 | 28 | ||
29 | class QListViewItem; | 29 | class QListViewItem; |
30 | class QListBox; | 30 | class QListBox; |
31 | class QVBoxLayout; | 31 | class QVBoxLayout; |
32 | class KConfig; | 32 | class KConfig; |
33 | 33 | ||
34 | class ContactListViewItem; | 34 | class ContactListViewItem; |
35 | class ContactListView; | 35 | class ContactListView; |
36 | 36 | ||
37 | 37 | ||
38 | namespace KABC { class AddressBook; } | 38 | namespace KABC { class AddressBook; } |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * This class is the table view for kaddressbook. This view is a KListView | 41 | * This class is the table view for kaddressbook. This view is a KListView |
42 | * with multiple columns for the selected fields. | 42 | * with multiple columns for the selected fields. |
43 | * | 43 | * |
44 | * @short Table View | 44 | * @short Table View |
45 | * @author Don Sanders <dsanders@kde.org> | 45 | * @author Don Sanders <dsanders@kde.org> |
46 | * @version 0.1 | 46 | * @version 0.1 |
47 | */ | 47 | */ |
48 | class KAddressBookTableView : public KAddressBookView | 48 | class KAddressBookTableView : public KAddressBookView |
49 | { | 49 | { |
50 | friend class ContactListView; | 50 | friend class ContactListView; |
51 | 51 | ||
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | public: | 54 | public: |
55 | KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent, | 55 | KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent, |
56 | const char *name = 0 ); | 56 | const char *name = 0 ); |
57 | virtual ~KAddressBookTableView(); | 57 | virtual ~KAddressBookTableView(); |
58 | 58 | ||
59 | virtual void refresh(QString uid = QString::null); | 59 | virtual void refresh(QString uid = QString::null); |
60 | virtual QStringList selectedUids(); | 60 | virtual QStringList selectedUids(); |
61 | virtual void setSelected(QString uid = QString::null, bool selected = false); | 61 | virtual void setSelected(QString uid = QString::null, bool selected = false); |
62 | virtual void readConfig(KConfig *config); | 62 | virtual void readConfig(KConfig *config); |
63 | virtual void writeConfig(KConfig *config); | 63 | virtual void writeConfig(KConfig *config); |
64 | virtual QString type() const { return "Table"; } | 64 | virtual QString type() const { return "Table"; } |
65 | void doSearch( const QString& s ,KABC::Field *field ); | 65 | void doSearch( const QString& s ,KABC::Field *field ); |
66 | virtual void scrollUP(); | 66 | virtual void scrollUP(); |
67 | virtual void scrollDOWN(); | 67 | virtual void scrollDOWN(); |
68 | virtual void setFocusAV(); | ||
68 | 69 | ||
69 | public slots: | 70 | public slots: |
70 | virtual void reconstructListView(); | 71 | virtual void reconstructListView(); |
71 | 72 | ||
72 | protected slots: | 73 | protected slots: |
73 | /** Called whenever the user selects an addressee in the list view. | 74 | /** Called whenever the user selects an addressee in the list view. |
74 | */ | 75 | */ |
75 | void addresseeSelected(); | 76 | void addresseeSelected(); |
76 | void addresseeDeleted(); | 77 | void addresseeDeleted(); |
77 | 78 | ||
78 | /** Called whenever the user executes an addressee. In terms of the | 79 | /** Called whenever the user executes an addressee. In terms of the |
79 | * list view, this is probably a double click | 80 | * list view, this is probably a double click |
80 | */ | 81 | */ |
81 | void addresseeExecuted(QListViewItem*); | 82 | void addresseeExecuted(QListViewItem*); |
82 | 83 | ||
83 | private: | 84 | private: |
84 | QVBoxLayout *mainLayout; | 85 | QVBoxLayout *mainLayout; |
85 | ContactListView *mListView; | 86 | ContactListView *mListView; |
86 | }; | 87 | }; |
87 | 88 | ||
88 | 89 | ||
89 | class TableViewFactory : public ViewFactory | 90 | class TableViewFactory : public ViewFactory |
90 | { | 91 | { |
91 | public: | 92 | public: |
92 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 93 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
93 | { | 94 | { |
94 | return new KAddressBookTableView( ab, parent, name ); | 95 | return new KAddressBookTableView( ab, parent, name ); |
95 | } | 96 | } |
96 | 97 | ||
97 | QString type() const { return "Table"; } | 98 | QString type() const { return "Table"; } |
98 | 99 | ||
99 | QString description() const { return i18n( "A listing of contacts in a table. Each cell of " | 100 | QString description() const { return i18n( "A listing of contacts in a table. Each cell of " |
100 | "the table holds a field of the contact." ); } | 101 | "the table holds a field of the contact." ); } |
101 | 102 | ||
102 | ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, | 103 | ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, |
103 | const char *name = 0 ) | 104 | const char *name = 0 ) |
104 | { | 105 | { |
105 | return new ConfigureTableViewWidget( ab, parent, name ); | 106 | return new ConfigureTableViewWidget( ab, parent, name ); |
106 | } | 107 | } |
107 | }; | 108 | }; |
108 | /*US | 109 | /*US |
109 | extern "C" { | 110 | extern "C" { |
110 | void *init_libkaddrbk_tableview() | 111 | void *init_libkaddrbk_tableview() |
111 | { | 112 | { |
112 | return ( new TableViewFactory ); | 113 | return ( new TableViewFactory ); |
113 | } | 114 | } |
114 | } | 115 | } |
115 | */ | 116 | */ |
116 | 117 | ||
117 | #endif | 118 | #endif |