Diffstat (limited to 'kaddressbook/views/kaddressbooktableview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index fbfddba..2412170 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp | |||
@@ -1,258 +1,272 @@ | |||
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 | 54 | void KAddressBookTableView::scrollUP() | |
55 | { | ||
56 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | ||
57 | QApplication::postEvent( mListView, ev ); | ||
58 | } | ||
59 | void KAddressBookTableView::scrollDOWN() | ||
60 | { | ||
61 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | ||
62 | QApplication::postEvent( mListView, ev ); | ||
63 | } | ||
55 | void KAddressBookTableView::reconstructListView() | 64 | void KAddressBookTableView::reconstructListView() |
56 | { | 65 | { |
57 | if (mListView) | 66 | if (mListView) |
58 | { | 67 | { |
59 | disconnect(mListView, SIGNAL(selectionChanged()), | 68 | disconnect(mListView, SIGNAL(selectionChanged()), |
60 | this, SLOT(addresseeSelected())); | 69 | this, SLOT(addresseeSelected())); |
61 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), | 70 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), |
62 | this, SLOT(addresseeExecuted(QListViewItem*))); | 71 | this, SLOT(addresseeExecuted(QListViewItem*))); |
63 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 72 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
64 | this, SLOT(addresseeExecuted(QListViewItem*))); | 73 | this, SLOT(addresseeExecuted(QListViewItem*))); |
65 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, | 74 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, |
66 | SIGNAL(startDrag())); | 75 | SIGNAL(startDrag())); |
67 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 76 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
68 | this, SLOT(addresseeExecuted(QListViewItem*))); | 77 | this, SLOT(addresseeExecuted(QListViewItem*))); |
69 | 78 | ||
70 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 79 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
71 | SIGNAL(dropped(QDropEvent*))); | 80 | SIGNAL(dropped(QDropEvent*))); |
72 | delete mListView; | 81 | delete mListView; |
73 | } | 82 | } |
74 | 83 | ||
75 | mListView = new ContactListView( this, addressBook(), viewWidget() ); | 84 | mListView = new ContactListView( this, addressBook(), viewWidget() ); |
76 | 85 | ||
77 | // Add the columns | 86 | // Add the columns |
78 | KABC::Field::List fieldList = fields(); | 87 | KABC::Field::List fieldList = fields(); |
79 | KABC::Field::List::ConstIterator it; | 88 | KABC::Field::List::ConstIterator it; |
80 | 89 | ||
81 | int c = 0; | 90 | int c = 0; |
82 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { | 91 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { |
83 | mListView->addColumn( (*it)->label() ); | 92 | mListView->addColumn( (*it)->label() ); |
84 | mListView->setColumnWidthMode(c++, QListView::Manual); | 93 | mListView->setColumnWidthMode(c++, QListView::Manual); |
85 | //US | 94 | //US |
86 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); | 95 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); |
87 | } | 96 | } |
88 | 97 | ||
89 | connect(mListView, SIGNAL(selectionChanged()), | 98 | connect(mListView, SIGNAL(selectionChanged()), |
90 | this, SLOT(addresseeSelected())); | 99 | this, SLOT(addresseeSelected())); |
91 | connect(mListView, SIGNAL(startAddresseeDrag()), this, | 100 | connect(mListView, SIGNAL(startAddresseeDrag()), this, |
92 | SIGNAL(startDrag())); | 101 | SIGNAL(startDrag())); |
93 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 102 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
94 | SIGNAL(dropped(QDropEvent*))); | 103 | SIGNAL(dropped(QDropEvent*))); |
95 | 104 | ||
96 | if (KABPrefs::instance()->mHonorSingleClick) | 105 | if (KABPrefs::instance()->mHonorSingleClick) |
97 | connect(mListView, SIGNAL(executed(QListViewItem*)), | 106 | connect(mListView, SIGNAL(executed(QListViewItem*)), |
98 | this, SLOT(addresseeExecuted(QListViewItem*))); | 107 | this, SLOT(addresseeExecuted(QListViewItem*))); |
99 | else | 108 | else |
100 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 109 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
101 | this, SLOT(addresseeExecuted(QListViewItem*))); | 110 | this, SLOT(addresseeExecuted(QListViewItem*))); |
102 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 111 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
103 | this, SLOT(addresseeExecuted(QListViewItem*))); | 112 | this, SLOT(addresseeExecuted(QListViewItem*))); |
104 | connect(mListView, SIGNAL(signalDelete()), | 113 | connect(mListView, SIGNAL(signalDelete()), |
105 | this, SLOT(addresseeDeleted())); | 114 | this, SLOT(addresseeDeleted())); |
106 | 115 | ||
107 | //US performceimprovement. Refresh is done from the outside | 116 | //US performceimprovement. Refresh is done from the outside |
108 | //US refresh(); | 117 | //US refresh(); |
109 | 118 | ||
110 | mListView->setSorting( 0, true ); | 119 | mListView->setSorting( 0, true ); |
111 | mainLayout->addWidget( mListView ); | 120 | mainLayout->addWidget( mListView ); |
112 | mainLayout->activate(); | 121 | mainLayout->activate(); |
113 | mListView->show(); | 122 | mListView->show(); |
114 | } | 123 | } |
115 | 124 | ||
116 | void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) | 125 | void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) |
117 | { | 126 | { |
118 | mListView->clear(); | 127 | mListView->clear(); |
119 | if ( s.isEmpty() || s == "*" ) { | 128 | if ( s.isEmpty() || s == "*" ) { |
120 | refresh(); | 129 | refresh(); |
121 | return; | 130 | return; |
122 | } | 131 | } |
123 | QString pattern = s.lower()+"*"; | 132 | QString pattern = s.lower()+"*"; |
124 | QRegExp re; | 133 | QRegExp re; |
125 | re.setWildcard(true); // most people understand these better. | 134 | re.setWildcard(true); // most people understand these better. |
126 | re.setCaseSensitive(false); | 135 | re.setCaseSensitive(false); |
127 | re.setPattern( pattern ); | 136 | re.setPattern( pattern ); |
128 | if (!re.isValid()) | 137 | if (!re.isValid()) |
129 | return; | 138 | return; |
130 | KABC::Addressee::List addresseeList = addressees(); | 139 | KABC::Addressee::List addresseeList = addressees(); |
131 | KABC::Addressee::List::Iterator it; | 140 | KABC::Addressee::List::Iterator it; |
132 | if ( field ) { | 141 | if ( field ) { |
133 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 142 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
134 | #if QT_VERSION >= 300 | 143 | #if QT_VERSION >= 300 |
135 | if (re.search(field->value( *it ).lower()) != -1) | 144 | if (re.search(field->value( *it ).lower()) != -1) |
136 | #else | 145 | #else |
137 | if (re.match(field->value( *it ).lower()) != -1) | 146 | if (re.match(field->value( *it ).lower()) != -1) |
138 | #endif | 147 | #endif |
139 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 148 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
140 | 149 | ||
141 | } | 150 | } |
142 | } else { | 151 | } else { |
143 | KABC::Field::List fieldList = fields(); | 152 | KABC::Field::List fieldList = fields(); |
144 | KABC::Field::List::ConstIterator fieldIt; | 153 | KABC::Field::List::ConstIterator fieldIt; |
145 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 154 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
146 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 155 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
147 | #if QT_VERSION >= 300 | 156 | #if QT_VERSION >= 300 |
148 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | 157 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
149 | #else | 158 | #else |
150 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | 159 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) |
151 | #endif | 160 | #endif |
152 | { | 161 | { |
153 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 162 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
154 | break; | 163 | break; |
155 | } | 164 | } |
156 | } | 165 | } |
157 | } | 166 | } |
158 | } | 167 | } |
159 | // Sometimes the background pixmap gets messed up when we add lots | 168 | // Sometimes the background pixmap gets messed up when we add lots |
160 | // of items. | 169 | // of items. |
161 | mListView->repaint(); | 170 | mListView->repaint(); |
162 | emit selected(QString::null); | 171 | if ( mListView->firstChild() ) { |
172 | mListView->setCurrentItem ( mListView->firstChild() ); | ||
173 | mListView->setSelected ( mListView->firstChild(), true ); | ||
174 | } | ||
175 | else | ||
176 | emit selected(QString::null); | ||
163 | 177 | ||
164 | } | 178 | } |
165 | void KAddressBookTableView::writeConfig(KConfig *config) | 179 | void KAddressBookTableView::writeConfig(KConfig *config) |
166 | { | 180 | { |
167 | KAddressBookView::writeConfig(config); | 181 | KAddressBookView::writeConfig(config); |
168 | 182 | ||
169 | mListView->saveLayout(config, config->group()); | 183 | mListView->saveLayout(config, config->group()); |
170 | } | 184 | } |
171 | 185 | ||
172 | void KAddressBookTableView::readConfig(KConfig *config) | 186 | void KAddressBookTableView::readConfig(KConfig *config) |
173 | { | 187 | { |
174 | KAddressBookView::readConfig( config ); | 188 | KAddressBookView::readConfig( config ); |
175 | // The config could have changed the fields, so we need to reconstruct | 189 | // The config could have changed the fields, so we need to reconstruct |
176 | // the listview. | 190 | // the listview. |
177 | reconstructListView(); | 191 | reconstructListView(); |
178 | 192 | ||
179 | // costum colors? | 193 | // costum colors? |
180 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 194 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
181 | { | 195 | { |
182 | QPalette p( mListView->palette() ); | 196 | QPalette p( mListView->palette() ); |
183 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 197 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
184 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 198 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
185 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 199 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
186 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 200 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
187 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 201 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
188 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 202 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
189 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 203 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
190 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 204 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
191 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 205 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
192 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 206 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
193 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 207 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
194 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 208 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
195 | #ifndef KAB_EMBEDDED | 209 | #ifndef KAB_EMBEDDED |
196 | c = KGlobalSettings::alternateBackgroundColor(); | 210 | c = KGlobalSettings::alternateBackgroundColor(); |
197 | #else //KAB_EMBEDDED | 211 | #else //KAB_EMBEDDED |
198 | c = QColor(240, 240, 240); | 212 | c = QColor(240, 240, 240); |
199 | #endif //KAB_EMBEDDED | 213 | #endif //KAB_EMBEDDED |
200 | c = config->readColorEntry ("AlternatingBackgroundColor", &c); | 214 | c = config->readColorEntry ("AlternatingBackgroundColor", &c); |
201 | mListView->setAlternateColor(c); | 215 | mListView->setAlternateColor(c); |
202 | 216 | ||
203 | 217 | ||
204 | //US mListView->viewport()->setPalette( p ); | 218 | //US mListView->viewport()->setPalette( p ); |
205 | mListView->setPalette( p ); | 219 | mListView->setPalette( p ); |
206 | } | 220 | } |
207 | else | 221 | else |
208 | { | 222 | { |
209 | // needed if turned off during a session. | 223 | // needed if turned off during a session. |
210 | //US mListView->viewport()->setPalette( mListView->palette() ); | 224 | //US mListView->viewport()->setPalette( mListView->palette() ); |
211 | mListView->setPalette( mListView->palette() ); | 225 | mListView->setPalette( mListView->palette() ); |
212 | } | 226 | } |
213 | 227 | ||
214 | //custom fonts? | 228 | //custom fonts? |
215 | QFont f( font() ); | 229 | QFont f( font() ); |
216 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 230 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
217 | { | 231 | { |
218 | mListView->setFont( config->readFontEntry( "TextFont", &f) ); | 232 | mListView->setFont( config->readFontEntry( "TextFont", &f) ); |
219 | f.setBold( true ); | 233 | f.setBold( true ); |
220 | //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 234 | //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
221 | mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); | 235 | mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); |
222 | } | 236 | } |
223 | else | 237 | else |
224 | { | 238 | { |
225 | mListView->setFont( f ); | 239 | mListView->setFont( f ); |
226 | f.setBold( true ); | 240 | f.setBold( true ); |
227 | //US mListView->setHeaderFont( f ); | 241 | //US mListView->setHeaderFont( f ); |
228 | mListView->header()->setFont( f ); | 242 | mListView->header()->setFont( f ); |
229 | } | 243 | } |
230 | 244 | ||
231 | 245 | ||
232 | 246 | ||
233 | 247 | ||
234 | 248 | ||
235 | // Set the list view options | 249 | // Set the list view options |
236 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", | 250 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", |
237 | true)); | 251 | true)); |
238 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); | 252 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); |
239 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); | 253 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); |
240 | 254 | ||
241 | if (config->readBoolEntry("Background", false)) | 255 | if (config->readBoolEntry("Background", false)) |
242 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); | 256 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); |
243 | 257 | ||
244 | // Restore the layout of the listview | 258 | // Restore the layout of the listview |
245 | mListView->restoreLayout(config, config->group()); | 259 | mListView->restoreLayout(config, config->group()); |
246 | } | 260 | } |
247 | 261 | ||
248 | void KAddressBookTableView::refresh(QString uid) | 262 | void KAddressBookTableView::refresh(QString uid) |
249 | { | 263 | { |
250 | // For now just repopulate. In reality this method should | 264 | // For now just repopulate. In reality this method should |
251 | // check the value of uid, and if valid iterate through | 265 | // check the value of uid, and if valid iterate through |
252 | // the listview to find the entry, then tell it to refresh. | 266 | // the listview to find the entry, then tell it to refresh. |
253 | 267 | ||
254 | if (uid.isNull()) { | 268 | if (uid.isNull()) { |
255 | // Clear the list view | 269 | // Clear the list view |
256 | QString currentUID, nextUID; | 270 | QString currentUID, nextUID; |
257 | #ifndef KAB_EMBEDDED | 271 | #ifndef KAB_EMBEDDED |
258 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); | 272 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); |