kaddressbook
kaddressbookview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <tqlayout.h>
00025 #include <tqpopupmenu.h>
00026
00027 #include <tdeabc/addressbook.h>
00028 #include <tdeabc/distributionlistdialog.h>
00029 #include <tdeconfig.h>
00030 #include <kdebug.h>
00031 #include <tdelocale.h>
00032 #include <kxmlguifactory.h>
00033 #include <kxmlguiclient.h>
00034
00035 #include "core.h"
00036 #include "searchmanager.h"
00037
00038 #include "kaddressbookview.h"
00039
00040 KAddressBookView::KAddressBookView( KAB::Core *core, TQWidget *parent,
00041 const char *name )
00042 : TQWidget( parent, name ), mCore( core ), mFieldList()
00043 {
00044 initGUI();
00045
00046 connect( mCore->searchManager(), TQT_SIGNAL( contactsUpdated() ),
00047 TQT_SLOT( updateView() ) );
00048 }
00049
00050 KAddressBookView::~KAddressBookView()
00051 {
00052 kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - "
00053 << name() << endl;
00054 }
00055
00056 void KAddressBookView::readConfig( TDEConfig *config )
00057 {
00058 mFieldList = TDEABC::Field::restoreFields( config, "KABCFields" );
00059
00060 if ( mFieldList.isEmpty() )
00061 mFieldList = TDEABC::Field::defaultFields();
00062
00063 mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
00064 mDefaultFilterName = config->readEntry( "DefaultFilterName" );
00065 }
00066
00067 void KAddressBookView::writeConfig( TDEConfig* )
00068 {
00069
00070 }
00071
00072 TQString KAddressBookView::selectedEmails()
00073 {
00074 bool first = true;
00075 TQString emailAddrs;
00076 const TQStringList uidList = selectedUids();
00077 TDEABC::Addressee addr;
00078 TQString email;
00079
00080 TQStringList::ConstIterator it;
00081 for ( it = uidList.begin(); it != uidList.end(); ++it ) {
00082 addr = mCore->addressBook()->findByUid( *it );
00083
00084 if ( !addr.isEmpty() ) {
00085 TQString m = TQString();
00086
00087 if ( addr.emails().count() > 1 )
00088 m = TDEABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
00089
00090 email = addr.fullEmail( m );
00091
00092 if ( !first )
00093 emailAddrs += ", ";
00094 else
00095 first = false;
00096
00097 emailAddrs += email;
00098 }
00099 }
00100
00101 return emailAddrs;
00102 }
00103
00104 TDEABC::Addressee::List KAddressBookView::addressees()
00105 {
00106 if ( mFilter.isEmpty() )
00107 return mCore->searchManager()->contacts();
00108
00109 TDEABC::Addressee::List addresseeList;
00110 const TDEABC::Addressee::List contacts = mCore->searchManager()->contacts();
00111
00112 TDEABC::Addressee::List::ConstIterator it;
00113 TDEABC::Addressee::List::ConstIterator contactsEnd( contacts.end() );
00114 for ( it = contacts.begin(); it != contactsEnd; ++it ) {
00115 if ( mFilter.filterAddressee( *it ) )
00116 addresseeList.append( *it );
00117 }
00118
00119 return addresseeList;
00120 }
00121
00122 void KAddressBookView::initGUI()
00123 {
00124
00125 TQVBoxLayout *layout = new TQVBoxLayout( this );
00126
00127
00128 mViewWidget = new TQWidget( this );
00129 layout->addWidget( mViewWidget );
00130 }
00131
00132 TDEABC::Field::List KAddressBookView::fields() const
00133 {
00134 return mFieldList;
00135 }
00136
00137 void KAddressBookView::setFilter( const Filter &filter )
00138 {
00139 mFilter = filter;
00140 }
00141
00142 KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
00143 {
00144 return mDefaultFilterType;
00145 }
00146
00147 const TQString &KAddressBookView::defaultFilterName() const
00148 {
00149 return mDefaultFilterName;
00150 }
00151
00152 KAB::Core *KAddressBookView::core() const
00153 {
00154 return mCore;
00155 }
00156
00157 void KAddressBookView::popup( const TQPoint &point )
00158 {
00159 if ( !mCore->guiClient() ) {
00160 kdWarning() << "No GUI client set!" << endl;
00161 return;
00162 }
00163
00164 TQPopupMenu *menu = static_cast<TQPopupMenu*>( mCore->guiClient()->factory()->container( "RMBPopup",
00165 mCore->guiClient() ) );
00166 if ( menu )
00167 menu->popup( point );
00168 }
00169
00170 TQWidget *KAddressBookView::viewWidget()
00171 {
00172 return mViewWidget;
00173 }
00174
00175 void KAddressBookView::updateView()
00176 {
00177 const TQStringList uidList = selectedUids();
00178
00179 refresh();
00180
00181 if ( !uidList.isEmpty() ) {
00182
00183 TQStringList::ConstIterator it, uidListEnd( uidList.end() );
00184 for ( it = uidList.begin(); it != uidListEnd; ++it )
00185 setSelected( *it, true );
00186
00187 } else {
00188 const TDEABC::Addressee::List contacts = mCore->searchManager()->contacts();
00189 if ( !contacts.isEmpty() )
00190 setFirstSelected( true );
00191 else
00192 emit selected( TQString() );
00193 }
00194 }
00195
00196 ViewConfigureWidget *ViewFactory::configureWidget( TDEABC::AddressBook *ab,
00197 TQWidget *parent,
00198 const char *name )
00199 {
00200 return new ViewConfigureWidget( ab, parent, name );
00201 }
00202
00203 #include "kaddressbookview.moc"
|