24 #include <tqcstring.h>
25 #include <tqgroupbox.h>
28 #include <tqlistbox.h>
29 #include <tqpushbutton.h>
31 #include <dcopclient.h>
33 #include <kbuttonbox.h>
34 #include <kcombobox.h>
35 #include <tdeconfig.h>
37 #include <kinputdialog.h>
38 #include <tdelocale.h>
39 #include <klineedit.h>
41 #include "addresseewidget.h"
43 NamePartWidget::NamePartWidget(
const TQString &title,
const TQString &label,
44 TQWidget *parent,
const char *name )
45 : TQWidget( parent, name ), mTitle( title ), mLabel( label )
47 TQHBoxLayout *layout =
new TQHBoxLayout(
this );
49 TQGroupBox *group =
new TQGroupBox( 0, TQt::Vertical, title,
this );
50 TQGridLayout *groupLayout =
new TQGridLayout( group->layout(), 2, 2,
51 KDialog::spacingHint() );
53 mBox =
new TQListBox( group );
54 connect( mBox, TQ_SIGNAL( selectionChanged( TQListBoxItem* ) ),
55 TQ_SLOT( selectionChanged( TQListBoxItem* ) ) );
56 groupLayout->addWidget( mBox, 0, 0 );
58 KButtonBox *bbox =
new KButtonBox( group, TQt::Vertical );
59 mAddButton = bbox->addButton( i18n(
"Add..." ),
this, TQ_SLOT( add() ) );
60 mEditButton = bbox->addButton( i18n(
"Edit..." ),
this, TQ_SLOT( edit() ) );
61 mEditButton->setEnabled(
false );
62 mRemoveButton = bbox->addButton( i18n(
"Remove" ),
this, TQ_SLOT( remove() ) );
63 mRemoveButton->setEnabled(
false );
65 groupLayout->addWidget( bbox, 0, 1 );
67 layout->addWidget( group );
70 NamePartWidget::~NamePartWidget()
74 void NamePartWidget::setNameParts(
const TQStringList &list )
77 mBox->insertStringList( list );
80 TQStringList NamePartWidget::nameParts()
const
83 for ( uint i = 0; i < mBox->count(); ++i )
84 parts.append( mBox->text( i ) );
89 void NamePartWidget::add()
93 TQString namePart = KInputDialog::getText( i18n(
"New" ), mLabel,
95 if ( ok && !namePart.isEmpty() ) {
96 mBox->insertItem( namePart );
101 void NamePartWidget::edit()
105 int index = mBox->currentItem();
109 TQString namePart = KInputDialog::getText( i18n(
"Edit" ), mLabel,
110 mBox->text( index ), &ok );
111 if ( ok && !namePart.isEmpty() ) {
112 mBox->changeItem( namePart, index );
117 void NamePartWidget::remove()
119 mBox->removeItem( mBox->currentItem() );
120 if ( mBox->count() == 0 )
121 selectionChanged( 0 );
126 void NamePartWidget::selectionChanged( TQListBoxItem *item )
128 mEditButton->setEnabled( item != 0 );
129 mRemoveButton->setEnabled( item != 0 );
134 AddresseeWidget::AddresseeWidget( TQWidget *parent,
const char *name )
135 : TQWidget( parent, name )
137 TQGridLayout *layout =
new TQGridLayout(
this, 2, 3, KDialog::marginHint(),
138 KDialog::spacingHint() );
140 mPrefix =
new NamePartWidget( i18n(
"Prefixes"), i18n(
"Enter prefix:" ),
this );
141 layout->addWidget( mPrefix, 0, 0 );
143 mInclusion =
new NamePartWidget( i18n(
"Inclusions"), i18n(
"Enter inclusion:" ),
this );
144 layout->addWidget( mInclusion, 0, 1 );
146 mSuffix =
new NamePartWidget( i18n(
"Suffixes" ), i18n(
"Enter suffix:" ),
this );
147 layout->addWidget( mSuffix, 0, 2 );
149 TQLabel *label =
new TQLabel( i18n(
"Default formatted name:" ),
this );
150 layout->addWidget( label, 1, 0 );
152 mFormattedNameCombo =
new KComboBox(
this );
153 mFormattedNameCombo->insertItem( i18n(
"Empty" ) );
154 mFormattedNameCombo->insertItem( i18n(
"Simple Name" ) );
155 mFormattedNameCombo->insertItem( i18n(
"Full Name" ) );
156 mFormattedNameCombo->insertItem( i18n(
"Reverse Name with Comma" ) );
157 mFormattedNameCombo->insertItem( i18n(
"Reverse Name" ) );
158 layout->addMultiCellWidget( mFormattedNameCombo, 1, 1, 1, 2 );
160 connect( mPrefix, TQ_SIGNAL( modified() ), TQ_SIGNAL( modified() ) );
161 connect( mInclusion, TQ_SIGNAL( modified() ), TQ_SIGNAL( modified() ) );
162 connect( mSuffix, TQ_SIGNAL( modified() ), TQ_SIGNAL( modified() ) );
163 connect( mFormattedNameCombo, TQ_SIGNAL( activated(
int ) ), TQ_SIGNAL( modified() ) );
166 AddresseeWidget::~AddresseeWidget()
170 void AddresseeWidget::restoreSettings()
172 TDEConfig config(
"tdeabcrc" );
173 config.setGroup(
"General" );
175 mPrefix->setNameParts( config.readListEntry(
"Prefixes" ) );
176 mInclusion->setNameParts( config.readListEntry(
"Inclusions" ) );
177 mSuffix->setNameParts( config.readListEntry(
"Suffixes" ) );
179 TDEConfig cfg(
"kaddressbookrc" );
180 cfg.setGroup(
"General" );
181 mFormattedNameCombo->setCurrentItem( cfg.readNumEntry(
"FormattedNameType", 1 ) );
184 void AddresseeWidget::saveSettings()
186 TDEConfig config(
"tdeabcrc" );
187 config.setGroup(
"General" );
189 config.writeEntry(
"Prefixes", mPrefix->nameParts() );
190 config.writeEntry(
"Inclusions", mInclusion->nameParts() );
191 config.writeEntry(
"Suffixes", mSuffix->nameParts() );
193 TDEConfig cfg(
"kaddressbookrc" );
194 cfg.setGroup(
"General" );
195 cfg.writeEntry(
"FormattedNameType", mFormattedNameCombo->currentItem() );
197 DCOPClient *client = DCOPClient::mainClient();
199 client->emitDCOPSignal(
"TDEABC::AddressBookConfig",
"changed()", TQByteArray() );
202 #include "addresseewidget.moc"