00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include <qlayout.h>
00025
#include <qpopupmenu.h>
00026
00027
#include <kabc/addressbook.h>
00028
#include <kabc/distributionlistdialog.h>
00029
#include <kconfig.h>
00030
#include <kdebug.h>
00031
#include <klocale.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,
QWidget *parent,
00041
const char *name )
00042 :
QWidget( parent, name ), mCore( core ), mFieldList()
00043 {
00044 initGUI();
00045
00046 connect( mCore->searchManager(), SIGNAL( contactsUpdated() ),
00047 SLOT( updateView() ) );
00048 }
00049
00050 KAddressBookView::~KAddressBookView()
00051 {
00052 kdDebug(5720) <<
"KAddressBookView::~KAddressBookView: destroying - "
00053 << name() << endl;
00054 }
00055
00056 void KAddressBookView::readConfig( KConfig *config )
00057 {
00058 mFieldList = KABC::Field::restoreFields( config,
"KABCFields" );
00059
00060
if ( mFieldList.isEmpty() )
00061 mFieldList = KABC::Field::defaultFields();
00062
00063 mDefaultFilterType = (DefaultFilterType)config->readNumEntry(
"DefaultFilterType", 1 );
00064 mDefaultFilterName = config->readEntry(
"DefaultFilterName" );
00065 }
00066
00067 void KAddressBookView::writeConfig( KConfig* )
00068 {
00069
00070 }
00071
00072 QString KAddressBookView::selectedEmails()
00073 {
00074
bool first =
true;
00075
QString emailAddrs;
00076
QStringList uidList =
selectedUids();
00077 KABC::Addressee addr;
00078
QString email;
00079
00080 QStringList::Iterator it;
00081
for ( it = uidList.begin(); it != uidList.end(); ++it ) {
00082 addr = mCore->addressBook()->findByUid( *it );
00083
00084
if ( !addr.isEmpty() ) {
00085
QString m = QString::null;
00086
00087
if ( addr.emails().count() > 1 )
00088 m = KABC::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 KABC::Addressee::List
KAddressBookView::addressees()
00105 {
00106 KABC::Addressee::List addresseeList;
00107 KABC::Addressee::List contacts = mCore->searchManager()->contacts();
00108
00109 KABC::Addressee::List::Iterator it;
00110
for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00111
if ( mFilter.
filterAddressee( *it ) )
00112 addresseeList.append( *it );
00113 }
00114
00115
return addresseeList;
00116 }
00117
00118
void KAddressBookView::initGUI()
00119 {
00120
00121
QVBoxLayout *layout =
new QVBoxLayout(
this );
00122
00123
00124 mViewWidget =
new QWidget(
this );
00125 layout->addWidget( mViewWidget );
00126 }
00127
00128 KABC::Field::List
KAddressBookView::fields()
const
00129
{
00130
return mFieldList;
00131 }
00132
00133 void KAddressBookView::setFilter(
const Filter &filter )
00134 {
00135 mFilter = filter;
00136 }
00137
00138 KAddressBookView::DefaultFilterType
KAddressBookView::defaultFilterType()
const
00139
{
00140
return mDefaultFilterType;
00141 }
00142
00143 const QString &
KAddressBookView::defaultFilterName()
const
00144
{
00145
return mDefaultFilterName;
00146 }
00147
00148 KAB::Core *
KAddressBookView::core()
const
00149
{
00150
return mCore;
00151 }
00152
00153 void KAddressBookView::popup(
const QPoint &point )
00154 {
00155
if ( !mCore->guiClient() ) {
00156 kdWarning() <<
"No GUI client set!" << endl;
00157
return;
00158 }
00159
00160
QPopupMenu *menu = static_cast<QPopupMenu*>( mCore->guiClient()->factory()->container(
"RMBPopup",
00161 mCore->guiClient() ) );
00162
if ( menu )
00163 menu->popup( point );
00164 }
00165
00166 QWidget *
KAddressBookView::viewWidget()
00167 {
00168
return mViewWidget;
00169 }
00170
00171
void KAddressBookView::updateView()
00172 {
00173
QStringList uidList =
selectedUids();
00174
00175
refresh();
00176
00177
if ( !uidList.isEmpty() ) {
00178
00179
for( QStringList::Iterator it = uidList.begin(); it != uidList.end(); ++it ) {
00180
setSelected( *it,
true );
00181 }
00182 }
else {
00183 KABC::Addressee::List contacts = mCore->searchManager()->contacts();
00184
if ( !contacts.isEmpty() )
00185
setSelected( contacts.first().uid(),
true );
00186
else {
00187 emit
selected( QString::null );
00188 }
00189 }
00190 }
00191
00192
ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
00193
QWidget *parent,
00194
const char *name )
00195 {
00196
return new ViewConfigureWidget( ab, parent, name );
00197 }
00198
00199
#include "kaddressbookview.moc"