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 <qcstring.h>
00025
#include <qgroupbox.h>
00026
#include <qlabel.h>
00027
#include <qlayout.h>
00028
#include <qlistbox.h>
00029
#include <qpushbutton.h>
00030
00031
#include <dcopclient.h>
00032
00033
#include <kbuttonbox.h>
00034
#include <kcombobox.h>
00035
#include <kconfig.h>
00036
#include <kdialog.h>
00037
#include <klocale.h>
00038
#include <klineedit.h>
00039
00040
#include "addresseewidget.h"
00041
00042 NamePartWidget::NamePartWidget(
const QString &title,
QWidget *parent,
00043
const char *name )
00044 :
QWidget( parent, name )
00045 {
00046
QHBoxLayout *layout =
new QHBoxLayout(
this );
00047
00048
QGroupBox *group =
new QGroupBox( 0, Qt::Vertical, title,
this );
00049
QGridLayout *groupLayout =
new QGridLayout( group->layout(), 2, 2,
00050 KDialog::spacingHint() );
00051
00052 mBox =
new QListBox( group );
00053 connect( mBox, SIGNAL( selectionChanged(
QListBoxItem* ) ),
00054 SLOT( selectionChanged(
QListBoxItem* ) ) );
00055 groupLayout->addWidget( mBox, 0, 0 );
00056
00057 KButtonBox *bbox =
new KButtonBox( group, Qt::Vertical );
00058 mAddButton = bbox->addButton( i18n(
"Add" ),
this, SLOT( add() ) );
00059 mAddButton->setEnabled(
false );
00060 mRemoveButton = bbox->addButton( i18n(
"Remove" ),
this, SLOT( remove() ) );
00061 mRemoveButton->setEnabled(
false );
00062 bbox->layout();
00063 groupLayout->addWidget( bbox, 0, 1 );
00064
00065 mEdit =
new KLineEdit( group );
00066 connect( mEdit, SIGNAL( textChanged(
const QString& ) ),
00067 SLOT( textChanged(
const QString& ) ) );
00068 connect( mEdit, SIGNAL( returnPressed() ), SLOT( add() ) );
00069 groupLayout->addMultiCellWidget( mEdit, 1, 1, 0, 1 );
00070 layout->addWidget( group );
00071 }
00072
00073 NamePartWidget::~NamePartWidget()
00074 {
00075 }
00076
00077
void NamePartWidget::setNameParts(
const QStringList &list )
00078 {
00079 mBox->clear();
00080 mBox->insertStringList( list );
00081 }
00082
00083
QStringList NamePartWidget::nameParts()
const
00084
{
00085
QStringList parts;
00086
for ( uint i = 0; i < mBox->count(); ++i )
00087 parts.append( mBox->text( i ) );
00088
00089
return parts;
00090 }
00091
00092
void NamePartWidget::add()
00093 {
00094
if ( !mEdit->text().isEmpty() ) {
00095 mBox->insertItem( mEdit->text() );
00096 emit modified();
00097 }
00098
00099 mEdit->setText(
"" );
00100 }
00101
00102
void NamePartWidget::remove()
00103 {
00104 mBox->removeItem( mBox->currentItem() );
00105
if ( mBox->count() == 0 )
00106 selectionChanged( 0 );
00107
00108 emit modified();
00109 }
00110
00111
void NamePartWidget::selectionChanged(
QListBoxItem *item )
00112 {
00113 mRemoveButton->setEnabled( item != 0 );
00114 }
00115
00116
void NamePartWidget::textChanged(
const QString& text )
00117 {
00118 mAddButton->setEnabled( !text.isEmpty() );
00119 }
00120
00121
00122 AddresseeWidget::AddresseeWidget(
QWidget *parent,
const char *name )
00123 :
QWidget( parent, name )
00124 {
00125
QGridLayout *layout =
new QGridLayout(
this, 2, 3, KDialog::marginHint(),
00126 KDialog::spacingHint() );
00127
00128 mPrefix =
new NamePartWidget( i18n(
"Prefixes" ),
this );
00129 layout->addWidget( mPrefix, 0, 0 );
00130
00131 mInclusion =
new NamePartWidget( i18n(
"Inclusions" ),
this );
00132 layout->addWidget( mInclusion, 0, 1 );
00133
00134 mSuffix =
new NamePartWidget( i18n(
"Suffixes" ),
this );
00135 layout->addWidget( mSuffix, 0, 2 );
00136
00137
QLabel *label =
new QLabel( i18n(
"Default formatted name:" ),
this );
00138 layout->addWidget( label, 1, 0 );
00139
00140 mFormattedNameCombo =
new KComboBox(
this );
00141 mFormattedNameCombo->insertItem( i18n(
"Empty" ) );
00142 mFormattedNameCombo->insertItem( i18n(
"Simple Name" ) );
00143 mFormattedNameCombo->insertItem( i18n(
"Full Name" ) );
00144 mFormattedNameCombo->insertItem( i18n(
"Reverse Name with Comma" ) );
00145 mFormattedNameCombo->insertItem( i18n(
"Reverse Name" ) );
00146 layout->addMultiCellWidget( mFormattedNameCombo, 1, 1, 1, 2 );
00147
00148 connect( mPrefix, SIGNAL( modified() ), SIGNAL( modified() ) );
00149 connect( mInclusion, SIGNAL( modified() ), SIGNAL( modified() ) );
00150 connect( mSuffix, SIGNAL( modified() ), SIGNAL( modified() ) );
00151 connect( mFormattedNameCombo, SIGNAL( activated(
int ) ), SIGNAL( modified() ) );
00152 }
00153
00154 AddresseeWidget::~AddresseeWidget()
00155 {
00156 }
00157
00158
void AddresseeWidget::restoreSettings()
00159 {
00160 KConfig config(
"kabcrc" );
00161 config.setGroup(
"General" );
00162
00163 mPrefix->setNameParts( config.readListEntry(
"Prefixes" ) );
00164 mInclusion->setNameParts( config.readListEntry(
"Inclusions" ) );
00165 mSuffix->setNameParts( config.readListEntry(
"Suffixes" ) );
00166
00167 KConfig cfg(
"kaddressbookrc" );
00168 cfg.setGroup(
"General" );
00169 mFormattedNameCombo->setCurrentItem( cfg.readNumEntry(
"FormattedNameType", 1 ) );
00170 }
00171
00172
void AddresseeWidget::saveSettings()
00173 {
00174 KConfig config(
"kabcrc" );
00175 config.setGroup(
"General" );
00176
00177 config.writeEntry(
"Prefixes", mPrefix->nameParts() );
00178 config.writeEntry(
"Inclusions", mInclusion->nameParts() );
00179 config.writeEntry(
"Suffixes", mSuffix->nameParts() );
00180
00181 KConfig cfg(
"kaddressbookrc" );
00182 cfg.setGroup(
"General" );
00183 cfg.writeEntry(
"FormattedNameType", mFormattedNameCombo->currentItem() );
00184
00185 DCOPClient *client = DCOPClient::mainClient();
00186
if ( client )
00187 client->emitDCOPSignal(
"KABC::AddressBookConfig",
"changed()",
QByteArray() );
00188 }
00189
00190
#include "addresseewidget.moc"