summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views/kaddressbooktableview.cpp
Unidiff
Diffstat (limited to 'kaddressbook/views/kaddressbooktableview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp56
1 files changed, 30 insertions, 26 deletions
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index 272f2eb..7efaaa9 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -1,57 +1,61 @@
1// $Id$ 1// $Id$
2 2
3#include <qvbox.h> 3#include <q3vbox.h>
4#include <qlistbox.h> 4#include <q3listbox.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 <q3dragobject.h>
11#include <qevent.h> 11#include <qevent.h>
12#include <qurl.h> 12#include <q3url.h>
13#include <qpixmap.h> 13#include <qpixmap.h>
14//Added by qt3to4:
15#include <QDropEvent>
16#include <QKeyEvent>
17#include <Q3VBoxLayout>
14 18
15#include <kabc/addressbook.h> 19#include <kabc/addressbook.h>
16#include <kapplication.h> 20#include <kapplication.h>
17#include <kconfig.h> 21#include <kconfig.h>
18#include <kcolorbutton.h> 22#include <kcolorbutton.h>
19#include <kdebug.h> 23#include <kdebug.h>
20#include <kglobal.h> 24#include <kglobal.h>
21#include <kiconloader.h> 25#include <kiconloader.h>
22#include <klineedit.h> 26#include <klineedit.h>
23#include <klocale.h> 27#include <klocale.h>
24#include <kmessagebox.h> 28#include <kmessagebox.h>
25#include <kurl.h> 29#include <kurl.h>
26#include <kurlrequester.h> 30#include <kurlrequester.h>
27 31
28//US#include "configuretableviewdialog.h" 32//US#include "configuretableviewdialog.h"
29#include "contactlistview.h" 33#include "contactlistview.h"
30#include "kabprefs.h" 34#include "kabprefs.h"
31#include "undocmds.h" 35#include "undocmds.h"
32#include "viewmanager.h" 36#include "viewmanager.h"
33 37
34#include <qlayout.h> 38#include <qlayout.h>
35#include <qheader.h> 39#include <q3header.h>
36#include <qregexp.h> 40#include <qregexp.h>
37 41
38#include "kaddressbooktableview.h" 42#include "kaddressbooktableview.h"
39 43
40 44
41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, 45KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
42 QWidget *parent, const char *name ) 46 QWidget *parent, const char *name )
43 : KAddressBookView( ab, parent, name ) 47 : KAddressBookView( ab, parent, name )
44{ 48{
45 mainLayout = new QVBoxLayout( viewWidget(), 2 ); 49 mainLayout = new Q3VBoxLayout( viewWidget(), 2 );
46 50
47 // The list view will be created when the config is read. 51 // The list view will be created when the config is read.
48 mListView = 0; 52 mListView = 0;
49} 53}
50 54
51KAddressBookTableView::~KAddressBookTableView() 55KAddressBookTableView::~KAddressBookTableView()
52{ 56{
53} 57}
54void KAddressBookTableView::setFocusAV() 58void KAddressBookTableView::setFocusAV()
55{ 59{
56 if ( mListView ) 60 if ( mListView )
57 mListView->setFocus(); 61 mListView->setFocus();
@@ -68,75 +72,75 @@ void KAddressBookTableView::scrollDOWN()
68{ 72{
69 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 73 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
70 QApplication::postEvent( mListView, ev ); 74 QApplication::postEvent( mListView, ev );
71 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 ); 75 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 );
72 QApplication::postEvent( mListView, ev ); 76 QApplication::postEvent( mListView, ev );
73} 77}
74void KAddressBookTableView::reconstructListView() 78void KAddressBookTableView::reconstructListView()
75{ 79{
76 if (mListView) 80 if (mListView)
77 { 81 {
78 disconnect(mListView, SIGNAL(selectionChanged()), 82 disconnect(mListView, SIGNAL(selectionChanged()),
79 this, SLOT(addresseeSelected())); 83 this, SLOT(addresseeSelected()));
80 disconnect(mListView, SIGNAL(executed(QListViewItem*)), 84 disconnect(mListView, SIGNAL(executed(Q3ListViewItem*)),
81 this, SLOT(addresseeExecuted(QListViewItem*))); 85 this, SLOT(addresseeExecuted(Q3ListViewItem*)));
82 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 86 disconnect(mListView, SIGNAL(doubleClicked(Q3ListViewItem*)),
83 this, SLOT(addresseeExecuted(QListViewItem*))); 87 this, SLOT(addresseeExecuted(Q3ListViewItem*)));
84 disconnect(mListView, SIGNAL(startAddresseeDrag()), this, 88 disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
85 SIGNAL(startDrag())); 89 SIGNAL(startDrag()));
86 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), 90 disconnect(mListView, SIGNAL(returnPressed(Q3ListViewItem*)),
87 this, SLOT(addresseeExecuted(QListViewItem*))); 91 this, SLOT(addresseeExecuted(Q3ListViewItem*)));
88 92
89 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 93 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
90 SIGNAL(dropped(QDropEvent*))); 94 SIGNAL(dropped(QDropEvent*)));
91 delete mListView; 95 delete mListView;
92 } 96 }
93 97
94 mListView = new ContactListView( this, addressBook(), viewWidget() ); 98 mListView = new ContactListView( this, addressBook(), viewWidget() );
95 99
96 connect(this, SIGNAL(printView()), 100 connect(this, SIGNAL(printView()),
97 mListView , SLOT(printMe())); 101 mListView , SLOT(printMe()));
98 //US set singleClick manually, because it is no global configparameter in embedded space 102 //US set singleClick manually, because it is no global configparameter in embedded space
99 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick); 103 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick);
100 104
101 // Add the columns 105 // Add the columns
102 KABC::Field::List fieldList = fields(); 106 KABC::Field::List fieldList = fields();
103 KABC::Field::List::ConstIterator it; 107 KABC::Field::List::ConstIterator it;
104 108
105 int c = 0; 109 int c = 0;
106 for( it = fieldList.begin(); it != fieldList.end(); ++it ) { 110 for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
107 mListView->addColumn( (*it)->label() ); 111 mListView->addColumn( (*it)->label() );
108 mListView->setColumnWidthMode(c++, QListView::Manual); 112 mListView->setColumnWidthMode(c++, Q3ListView::Manual);
109//US 113//US
110 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); 114 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
111 } 115 }
112 116
113 connect(mListView, SIGNAL(selectionChanged()), 117 connect(mListView, SIGNAL(selectionChanged()),
114 this, SLOT(addresseeSelected())); 118 this, SLOT(addresseeSelected()));
115 connect(mListView, SIGNAL(startAddresseeDrag()), this, 119 connect(mListView, SIGNAL(startAddresseeDrag()), this,
116 SIGNAL(startDrag())); 120 SIGNAL(startDrag()));
117 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 121 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
118 SIGNAL(dropped(QDropEvent*))); 122 SIGNAL(dropped(QDropEvent*)));
119 123
120 if (KABPrefs::instance()->mHonorSingleClick) { 124 if (KABPrefs::instance()->mHonorSingleClick) {
121 // qDebug("KAddressBookTableView::reconstructListView single"); 125 // qDebug("KAddressBookTableView::reconstructListView single");
122 connect(mListView, SIGNAL(executed(QListViewItem*)), 126 connect(mListView, SIGNAL(executed(Q3ListViewItem*)),
123 this, SLOT(addresseeExecuted(QListViewItem*))); 127 this, SLOT(addresseeExecuted(Q3ListViewItem*)));
124 } else { 128 } else {
125 // qDebug("KAddressBookTableView::reconstructListView double"); 129 // qDebug("KAddressBookTableView::reconstructListView double");
126 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 130 connect(mListView, SIGNAL(doubleClicked(Q3ListViewItem*)),
127 this, SLOT(addresseeExecuted(QListViewItem*))); 131 this, SLOT(addresseeExecuted(Q3ListViewItem*)));
128 } 132 }
129 connect(mListView, SIGNAL(returnPressed(QListViewItem*)), 133 connect(mListView, SIGNAL(returnPressed(Q3ListViewItem*)),
130 this, SLOT(addresseeExecuted(QListViewItem*))); 134 this, SLOT(addresseeExecuted(Q3ListViewItem*)));
131 connect(mListView, SIGNAL(signalDelete()), 135 connect(mListView, SIGNAL(signalDelete()),
132 this, SLOT(addresseeDeleted())); 136 this, SLOT(addresseeDeleted()));
133 137
134//US performceimprovement. Refresh is done from the outside 138//US performceimprovement. Refresh is done from the outside
135//US refresh(); 139//US refresh();
136 140
137 mListView->setSorting( 0, true ); 141 mListView->setSorting( 0, true );
138 mainLayout->addWidget( mListView ); 142 mainLayout->addWidget( mListView );
139 mainLayout->activate(); 143 mainLayout->activate();
140 mListView->show(); 144 mListView->show();
141} 145}
142 146
@@ -335,47 +339,47 @@ void KAddressBookTableView::refresh(QString uid)
335 // of items. 339 // of items.
336 mListView->repaint(); 340 mListView->repaint();
337 if ( !currentItem ) 341 if ( !currentItem )
338 currentItem = (ContactListViewItem *)mListView->firstChild(); 342 currentItem = (ContactListViewItem *)mListView->firstChild();
339 if ( currentItem ) { 343 if ( currentItem ) {
340 mListView->setCurrentItem( currentItem ); 344 mListView->setCurrentItem( currentItem );
341 mListView->ensureItemVisible( currentItem ); 345 mListView->ensureItemVisible( currentItem );
342 mListView->setSelected( currentItem, true ); 346 mListView->setSelected( currentItem, true );
343 } 347 }
344 } else { 348 } else {
345 // Only need to update on entry. Iterate through and try to find it 349 // Only need to update on entry. Iterate through and try to find it
346 ContactListViewItem *ceItem; 350 ContactListViewItem *ceItem;
347 QListViewItemIterator it( mListView ); 351 Q3ListViewItemIterator it( mListView );
348 while ( it.current() ) { 352 while ( it.current() ) {
349#ifndef KAB_EMBEDDED 353#ifndef KAB_EMBEDDED
350 ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); 354 ceItem = dynamic_cast<ContactListViewItem*>( it.current() );
351#else //KAB_EMBEDDED 355#else //KAB_EMBEDDED
352 ceItem = (ContactListViewItem*)( it.current() ); 356 ceItem = (ContactListViewItem*)( it.current() );
353#endif //KAB_EMBEDDED 357#endif //KAB_EMBEDDED
354 358
355 if ( ceItem && ceItem->addressee().uid() == uid ) { 359 if ( ceItem && ceItem->addressee().uid() == uid ) {
356 ceItem->refresh(); 360 ceItem->refresh();
357 return; 361 return;
358 } 362 }
359 ++it; 363 ++it;
360 } 364 }
361 365
362 refresh( QString::null ); 366 refresh( QString::null );
363 } 367 }
364} 368}
365 369
366QStringList KAddressBookTableView::selectedUids() 370QStringList KAddressBookTableView::selectedUids()
367{ 371{
368 QStringList uidList; 372 QStringList uidList;
369 QListViewItem *item; 373 Q3ListViewItem *item;
370 ContactListViewItem *ceItem; 374 ContactListViewItem *ceItem;
371 375
372 for(item = mListView->firstChild(); item; item = item->itemBelow()) 376 for(item = mListView->firstChild(); item; item = item->itemBelow())
373 { 377 {
374 if (mListView->isSelected( item )) 378 if (mListView->isSelected( item ))
375 { 379 {
376#ifndef KAB_EMBEDDED 380#ifndef KAB_EMBEDDED
377 ceItem = dynamic_cast<ContactListViewItem*>(item); 381 ceItem = dynamic_cast<ContactListViewItem*>(item);
378#else //KAB_EMBEDDED 382#else //KAB_EMBEDDED
379 ceItem = (ContactListViewItem*)(item); 383 ceItem = (ContactListViewItem*)(item);
380#endif //KAB_EMBEDDED 384#endif //KAB_EMBEDDED
381 385
@@ -385,25 +389,25 @@ QStringList KAddressBookTableView::selectedUids()
385 } 389 }
386 if ( uidList.count() == 0 ) 390 if ( uidList.count() == 0 )
387 if ( mListView->currentItem() ) { 391 if ( mListView->currentItem() ) {
388 ceItem = (ContactListViewItem*)(mListView->currentItem()) ; 392 ceItem = (ContactListViewItem*)(mListView->currentItem()) ;
389 uidList << ceItem->addressee().uid(); 393 uidList << ceItem->addressee().uid();
390 } 394 }
391 395
392 return uidList; 396 return uidList;
393} 397}
394 398
395void KAddressBookTableView::setSelected(QString uid, bool selected) 399void KAddressBookTableView::setSelected(QString uid, bool selected)
396{ 400{
397 QListViewItem *item; 401 Q3ListViewItem *item;
398 ContactListViewItem *ceItem; 402 ContactListViewItem *ceItem;
399 403
400 if (uid.isNull()) 404 if (uid.isNull())
401 { 405 {
402 mListView->selectAll(selected); 406 mListView->selectAll(selected);
403 } 407 }
404 else 408 else
405 { 409 {
406 for(item = mListView->firstChild(); item; item = item->itemBelow()) 410 for(item = mListView->firstChild(); item; item = item->itemBelow())
407 { 411 {
408#ifndef KAB_EMBEDDED 412#ifndef KAB_EMBEDDED
409 ceItem = dynamic_cast<ContactListViewItem*>(item); 413 ceItem = dynamic_cast<ContactListViewItem*>(item);
@@ -420,49 +424,49 @@ void KAddressBookTableView::setSelected(QString uid, bool selected)
420 mListView->ensureItemVisible(item); 424 mListView->ensureItemVisible(item);
421 } 425 }
422 } 426 }
423 } 427 }
424} 428}
425 429
426void KAddressBookTableView::addresseeSelected() 430void KAddressBookTableView::addresseeSelected()
427{ 431{
428 // We need to try to find the first selected item. This might not be the 432 // We need to try to find the first selected item. This might not be the
429 // last selected item, but when QListView is in multiselection mode, 433 // last selected item, but when QListView is in multiselection mode,
430 // there is no way to figure out which one was 434 // there is no way to figure out which one was
431 // selected last. 435 // selected last.
432 QListViewItem *item; 436 Q3ListViewItem *item;
433 bool found =false; 437 bool found =false;
434 for (item = mListView->firstChild(); item && !found; 438 for (item = mListView->firstChild(); item && !found;
435 item = item->nextSibling()) 439 item = item->nextSibling())
436 { 440 {
437 if (item->isSelected()) 441 if (item->isSelected())
438 { 442 {
439 found = true; 443 found = true;
440#ifndef KAB_EMBEDDED 444#ifndef KAB_EMBEDDED
441 ContactListViewItem *ceItem 445 ContactListViewItem *ceItem
442 = dynamic_cast<ContactListViewItem*>(item); 446 = dynamic_cast<ContactListViewItem*>(item);
443#else //KAB_EMBEDDED 447#else //KAB_EMBEDDED
444 ContactListViewItem *ceItem 448 ContactListViewItem *ceItem
445 = (ContactListViewItem*)(item); 449 = (ContactListViewItem*)(item);
446#endif //KAB_EMBEDDED 450#endif //KAB_EMBEDDED
447 451
448 if ( ceItem ) emit selected(ceItem->addressee().uid()); 452 if ( ceItem ) emit selected(ceItem->addressee().uid());
449 } 453 }
450 } 454 }
451 455
452 if (!found) 456 if (!found)
453 emit selected(QString::null); 457 emit selected(QString::null);
454} 458}
455 459
456void KAddressBookTableView::addresseeExecuted(QListViewItem *item) 460void KAddressBookTableView::addresseeExecuted(Q3ListViewItem *item)
457{ 461{
458 if (item) 462 if (item)
459 { 463 {
460#ifndef KAB_EMBEDDED 464#ifndef KAB_EMBEDDED
461 ContactListViewItem *ceItem 465 ContactListViewItem *ceItem
462 = dynamic_cast<ContactListViewItem*>(item); 466 = dynamic_cast<ContactListViewItem*>(item);
463#else //KAB_EMBEDDED 467#else //KAB_EMBEDDED
464 ContactListViewItem *ceItem 468 ContactListViewItem *ceItem
465 = (ContactListViewItem*)(item); 469 = (ContactListViewItem*)(item);
466#endif //KAB_EMBEDDED 470#endif //KAB_EMBEDDED
467 471
468 if (ceItem) 472 if (ceItem)
@@ -478,15 +482,15 @@ void KAddressBookTableView::addresseeExecuted(QListViewItem *item)
478 482
479void KAddressBookTableView::addresseeDeleted() 483void KAddressBookTableView::addresseeDeleted()
480{ 484{
481 485
482 emit deleteRequest(); 486 emit deleteRequest();
483 487
484} 488}
485 489
486 490
487 491
488 492
489 493
490#ifndef KAB_EMBEDDED 494#ifndef KAB_EMBEDDED_
491#include "kaddressbooktableview.moc" 495#include "moc_kaddressbooktableview.cpp"
492#endif //KAB_EMBEDDED 496#endif //KAB_EMBEDDED