24 #include <tqapplication.h>
28 #include <tqlistbox.h>
32 #include <tqcombobox.h>
33 #include <tqapplication.h>
34 #include <tqdragobject.h>
39 #include <tdeabc/addressbook.h>
40 #include <tdeapplication.h>
41 #include <tdeconfig.h>
42 #include <kcolorbutton.h>
44 #include <tdeglobal.h>
45 #include <kiconloader.h>
46 #include <klineedit.h>
47 #include <tdelocale.h>
48 #include <tdemessagebox.h>
50 #include <kurlrequester.h>
51 #include <tdeimproxy.h>
53 #include "configuretableviewdialog.h"
54 #include "contactlistview.h"
59 #include "kaddressbooktableview.h"
61 class TableViewFactory :
public ViewFactory
64 KAddressBookView *view( KAB::Core *core, TQWidget *parent,
const char *name )
69 TQString type()
const {
return I18N_NOOP(
"Table" ); }
71 TQString description()
const {
return i18n(
"A listing of contacts in a table. Each cell of "
72 "the table holds a field of the contact." ); }
75 const char *name = 0 )
82 void *init_libkaddrbk_tableview()
84 return (
new TableViewFactory );
88 KAddressBookTableView::KAddressBookTableView( KAB::Core *core,
89 TQWidget *parent,
const char *name )
92 mMainLayout =
new TQVBoxLayout( viewWidget(), 2 );
99 KAddressBookTableView::~KAddressBookTableView()
103 void KAddressBookTableView::reconstructListView()
106 disconnect( mListView, TQT_SIGNAL( selectionChanged() ),
108 disconnect( mListView, TQT_SIGNAL(
executed( TQListViewItem* ) ),
110 disconnect( mListView, TQT_SIGNAL( doubleClicked( TQListViewItem* ) ),
112 disconnect( mListView, TQT_SIGNAL( startAddresseeDrag() ),
114 disconnect( mListView, TQT_SIGNAL( addresseeDropped( TQDropEvent* ) ),
115 this, TQT_SIGNAL(
dropped( TQDropEvent* ) ) );
119 mListView =
new ContactListView(
this,
core()->addressBook(),
viewWidget() );
121 mListView->setShowIM( mIMProxy != 0 );
124 const TDEABC::Field::List fieldList(
fields() );
125 TDEABC::Field::List::ConstIterator it;
128 for ( it = fieldList.begin(); it != fieldList.end(); ++it ) {
129 mListView->addColumn( (*it)->label() );
130 mListView->setColumnWidthMode( c++, TQListView::Manual );
133 if ( mListView->showIM() ) {
138 mListView->addColumn( i18n(
"Presence" ) );
139 mListView->setIMColumn( c++ );
142 mListView->setFullWidth(
true );
144 connect( mListView, TQT_SIGNAL( selectionChanged() ),
146 connect( mListView, TQT_SIGNAL( startAddresseeDrag() ),
148 connect( mListView, TQT_SIGNAL( addresseeDropped( TQDropEvent* ) ),
149 this, TQT_SIGNAL(
dropped( TQDropEvent* ) ) );
150 connect( mListView, TQT_SIGNAL( contextMenu( TDEListView*, TQListViewItem*,
const TQPoint& ) ),
151 this, TQT_SLOT(
rmbClicked( TDEListView*, TQListViewItem*,
const TQPoint& ) ) );
152 connect( mListView->header(), TQT_SIGNAL( clicked(
int ) ),
155 if ( KABPrefs::instance()->honorSingleClick() )
156 connect( mListView, TQT_SIGNAL(
executed( TQListViewItem* ) ),
159 connect( mListView, TQT_SIGNAL( doubleClicked( TQListViewItem* ) ),
164 mListView->setSorting( 0,
true );
165 mMainLayout->addWidget( mListView );
166 mMainLayout->activate();
173 return ( mListView->sortColumn() == -1 ?
fields()[ 0 ] :
fields()[ mListView->sortColumn() ] );
180 mListView->saveLayout( config, config->group() );
187 if ( config->readBoolEntry(
"InstantMessagingPresence",
false ) ) {
189 mIMProxy = KIMProxy::instance( kapp->dcopClient() );
190 connect( mIMProxy, TQT_SIGNAL( sigContactPresenceChanged(
const TQString& ) ),
195 disconnect( mIMProxy, TQT_SIGNAL( sigContactPresenceChanged(
const TQString& ) ),
203 reconstructListView();
206 mListView->setAlternateBackgroundEnabled( config->readBoolEntry(
"ABackground",
true ) );
207 mListView->setSingleLineEnabled( config->readBoolEntry(
"SingleLine",
false ) );
208 mListView->setToolTipsEnabled( config->readBoolEntry(
"ToolTips",
true ) );
210 if ( config->readBoolEntry(
"Background",
false ) )
211 mListView->setBackgroundPixmap( config->readPathEntry(
"BackgroundName" ) );
214 mListView->restoreLayout( config, config->group() );
219 if ( uid.isEmpty() ) {
221 TQString currentUID, nextUID;
222 ContactListViewItem *currentItem =
dynamic_cast<ContactListViewItem*
>( mListView->currentItem() );
224 ContactListViewItem *nextItem =
dynamic_cast<ContactListViewItem*
>( currentItem->itemBelow() );
226 nextUID = nextItem->addressee().uid();
227 currentUID = currentItem->addressee().uid();
233 const TDEABC::Addressee::List addresseeList(
addressees() );
234 TDEABC::Addressee::List::ConstIterator it( addresseeList.begin() );
235 const TDEABC::Addressee::List::ConstIterator endIt( addresseeList.end() );
236 for ( ; it != endIt; ++it ) {
237 ContactListViewItem *item =
new ContactListViewItem( *it, mListView,
239 if ( (*it).uid() == currentUID )
241 else if ( (*it).uid() == nextUID && !currentItem )
247 mListView->repaint();
250 mListView->setCurrentItem( currentItem );
251 mListView->ensureItemVisible( currentItem );
255 ContactListViewItem *ceItem;
256 TQPtrList<TQListViewItem> selectedItems( mListView->selectedItems() );
258 for ( it = selectedItems.first(); it; it = selectedItems.next() ) {
259 ceItem =
dynamic_cast<ContactListViewItem*
>( it );
260 if ( ceItem && ceItem->addressee().uid() == uid ) {
271 TQStringList uidList;
272 ContactListViewItem *item;
274 TQListViewItemIterator it( mListView, TQListViewItemIterator::Selected );
275 while ( it.current() ) {
276 item =
dynamic_cast<ContactListViewItem*
>( it.current() );
278 uidList << item->addressee().uid();
289 mListView->selectAll( selected );
291 TQListViewItemIterator it( mListView );
292 while ( it.current() ) {
293 ContactListViewItem *item =
dynamic_cast<ContactListViewItem*
>( it.current() );
294 if ( item && (item->addressee().uid() == uid) ) {
295 mListView->setSelected( item, selected );
298 mListView->ensureItemVisible( item );
308 if ( mListView->firstChild() ) {
309 mListView->setSelected( mListView->firstChild(),
selected );
310 mListView->ensureItemVisible( mListView->firstChild() );
322 TQListViewItemIterator it( mListView, TQListViewItemIterator::Selected );
323 while ( it.current() && !found ) {
325 ContactListViewItem *item =
dynamic_cast<ContactListViewItem*
>( it.current() );
327 emit
selected( item->addressee().uid() );
339 ContactListViewItem *ceItem =
dynamic_cast<ContactListViewItem*
>( item );
342 emit
executed( ceItem->addressee().uid() );
358 TQListViewItem *item;
359 ContactListViewItem *ceItem;
360 for ( item = mListView->firstChild(); item; item = item->itemBelow() ) {
361 ceItem =
dynamic_cast<ContactListViewItem*
>( item );
362 if ( ( ceItem != 0L ) && ( ceItem->addressee().uid() == uid ) ) {
363 ceItem->setHasIM(
true );
369 if ( mListView->sortColumn() == mListView->imColumn() )
373 void KAddressBookTableView::scrollUp()
375 TQApplication::postEvent( mListView,
new TQKeyEvent( TQEvent::KeyPress, TQt::Key_Up, 0, 0 ) );
378 void KAddressBookTableView::scrollDown()
380 TQApplication::postEvent( mListView,
new TQKeyEvent( TQEvent::KeyPress, TQt::Key_Down, 0, 0 ) );
384 #include "kaddressbooktableview.moc"
virtual TDEABC::Field * sortField() const
void addresseeExecuted(TQListViewItem *)
Called whenever the user executes an addressee.
TDEABC::Addressee::List addressees()
Returns a list of the addressees that should be displayed.
void selected(const TQString &uid)
This signal should be emitted by a subclass whenever an addressee is selected.
void executed(const TQString &uid)
This signal should be emitted by a subclass whenever an addressee is executed.
virtual void refresh(const TQString &uid=TQString())
Must be overloaded in subclasses to refresh the view.
virtual void setSelected(const TQString &uid=TQString(), bool selected=false)
This method must be overloaded in subclasses.
virtual void writeConfig(TDEConfig *)
Called whenever this view should write the config.
virtual void readConfig(TDEConfig *config)
Called whenever this view should read the config.
void addresseeSelected()
Called whenever the user selects an addressee in the list view.
Base class for all views in kaddressbook.
void rmbClicked(TDEListView *, TQListViewItem *, const TQPoint &)
RBM menu called.
virtual void setFirstSelected(bool selected=true)
Selects the first contact in the view.
virtual TQStringList selectedUids()
Must be overloaded in subclasses.
void dropped(TQDropEvent *)
This signal is emitted whenever the user drops something on the view.
This class is the table view for kaddressbook.
void sortFieldChanged()
This signal is emitted whenever the sort field changed.
void startDrag()
This signal is emitted whenever a user attempts to start a drag in the view.
virtual void writeConfig(TDEConfig *config)
Called whenever this view should write the config.
TDEABC::Field::List fields() const
Returns a list of the fields that should be displayed.
virtual void readConfig(TDEConfig *config)
Called whenever this view should read the config.
TQWidget * viewWidget()
This method returns the widget that should be used as the parent for all view components.
void popup(const TQPoint &point)
Call this slot to popup a rmb menu.
void updatePresence(const TQString &uid)
Called to update the presence of a single item.