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 <QtDBus/QDBusConnection>
00025 #include <QtDBus/QDBusMessage>
00026 #include <QtGui/QGridLayout>
00027 #include <QtGui/QGroupBox>
00028 #include <QtGui/QHBoxLayout>
00029 #include <QtGui/QLabel>
00030 #include <QtGui/QListWidget>
00031 #include <QtGui/QPushButton>
00032
00033 #include <kcombobox.h>
00034 #include <kconfig.h>
00035 #include <kdialog.h>
00036 #include <KDialogButtonBox>
00037 #include <kinputdialog.h>
00038 #include <klineedit.h>
00039 #include <klocale.h>
00040
00041 #include "addresseewidget.h"
00042
00043 NamePartWidget::NamePartWidget( const QString &title, const QString &label,
00044 QWidget *parent, const char *name )
00045 : QWidget( parent ), mTitle( title ), mLabel( label )
00046 {
00047 setObjectName( name );
00048 QHBoxLayout *layout = new QHBoxLayout( this );
00049 layout->setSpacing( KDialog::spacingHint() );
00050 layout->setMargin( 0 );
00051
00052 QGroupBox *group = new QGroupBox( title, this );
00053 QGridLayout *groupLayout = new QGridLayout();
00054 groupLayout->setSpacing( KDialog::spacingHint() );
00055 groupLayout->setMargin( KDialog::marginHint() );
00056 group->setLayout( groupLayout );
00057
00058 mBox = new QListWidget( group );
00059 mBox->setMaximumWidth( 100 );
00060 connect( mBox,
00061 SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ),
00062 SLOT( selectionChanged( QListWidgetItem * ) ) );
00063 groupLayout->addWidget( mBox, 0, 0 );
00064
00065 KDialogButtonBox *bbox = new KDialogButtonBox( group, Qt::Vertical );
00066 mAddButton = bbox->addButton( i18n( "Add..." ), QDialogButtonBox::ActionRole, this, SLOT( add() ) );
00067 mEditButton = bbox->addButton( i18n( "Edit..." ), QDialogButtonBox::ActionRole, this, SLOT( edit() ) );
00068 mEditButton->setEnabled( false );
00069 mRemoveButton = bbox->addButton( i18n( "Remove" ), QDialogButtonBox::ActionRole, this, SLOT( remove() ) );
00070 mRemoveButton->setEnabled( false );
00071 bbox->layout();
00072 groupLayout->addWidget( bbox, 0, 1 );
00073
00074 layout->addWidget( group );
00075 }
00076
00077 NamePartWidget::~NamePartWidget()
00078 {
00079 }
00080
00081 void NamePartWidget::setNameParts( const QStringList &list )
00082 {
00083 mBox->clear();
00084 mBox->addItems( list );
00085 }
00086
00087 QStringList NamePartWidget::nameParts() const
00088 {
00089 QStringList parts;
00090 for ( int i = 0; i < mBox->count(); ++i )
00091 parts.append( mBox->item( i )->text() );
00092
00093 return parts;
00094 }
00095
00096 void NamePartWidget::add()
00097 {
00098 bool ok;
00099
00100 QString namePart = KInputDialog::getText( i18n( "New" ), mLabel,
00101 QString(), &ok );
00102 if ( ok && !namePart.isEmpty() ) {
00103 mBox->addItem( namePart );
00104 emit modified();
00105 }
00106 }
00107
00108 void NamePartWidget::edit()
00109 {
00110 bool ok;
00111
00112 QListWidgetItem *item = mBox->currentItem();
00113 if ( !item )
00114 return;
00115
00116 QString namePart = KInputDialog::getText( i18n( "Edit" ), mLabel,
00117 item->text(), &ok );
00118 if ( ok && !namePart.isEmpty() ) {
00119 item->setText( namePart );
00120 emit modified();
00121 }
00122 }
00123
00124 void NamePartWidget::remove()
00125 {
00126 mBox->takeItem( mBox->currentRow() );
00127 if ( mBox->count() == 0 )
00128 selectionChanged( 0 );
00129
00130 emit modified();
00131 }
00132
00133 void NamePartWidget::selectionChanged( QListWidgetItem *item )
00134 {
00135 mEditButton->setEnabled( item );
00136 mRemoveButton->setEnabled( item );
00137 }
00138
00139
00140
00141 AddresseeWidget::AddresseeWidget( QWidget *parent, const char *name )
00142 : QWidget( parent )
00143 {
00144 setObjectName( name );
00145 QGridLayout *layout = new QGridLayout( this );
00146 layout->setSpacing( KDialog::spacingHint() );
00147 layout->setMargin( KDialog::marginHint() );
00148
00149 mPrefix = new NamePartWidget( i18n( "Prefixes"), i18n( "Enter prefix:" ), this );
00150 layout->addWidget( mPrefix, 0, 0 );
00151
00152 mInclusion = new NamePartWidget( i18n( "Inclusions"), i18n( "Enter inclusion:" ), this );
00153 layout->addWidget( mInclusion, 0, 1 );
00154
00155 mSuffix = new NamePartWidget( i18n( "Suffixes" ), i18n( "Enter suffix:" ), this );
00156 layout->addWidget( mSuffix, 0, 2 );
00157
00158 QLabel *label = new QLabel( i18n( "Default formatted name:" ), this );
00159 layout->addWidget( label, 1, 0 );
00160
00161 mFormattedNameCombo = new KComboBox( this );
00162 mFormattedNameCombo->addItem( i18n( "Empty" ) );
00163 mFormattedNameCombo->addItem( i18n( "Simple Name" ) );
00164 mFormattedNameCombo->addItem( i18n( "Full Name" ) );
00165 mFormattedNameCombo->addItem( i18n( "Reverse Name with Comma" ) );
00166 mFormattedNameCombo->addItem( i18n( "Reverse Name" ) );
00167 layout->addWidget( mFormattedNameCombo, 1, 1, 1, 2 );
00168
00169 connect( mPrefix, SIGNAL( modified() ), SIGNAL( modified() ) );
00170 connect( mInclusion, SIGNAL( modified() ), SIGNAL( modified() ) );
00171 connect( mSuffix, SIGNAL( modified() ), SIGNAL( modified() ) );
00172 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SIGNAL( modified() ) );
00173 }
00174
00175 AddresseeWidget::~AddresseeWidget()
00176 {
00177 }
00178
00179 void AddresseeWidget::restoreSettings()
00180 {
00181 KConfig _config( "kabcrc" );
00182 KConfigGroup config(&_config, "General" );
00183
00184 mPrefix->setNameParts( config.readEntry( "Prefixes" , QStringList() ) );
00185 mInclusion->setNameParts( config.readEntry( "Inclusions" , QStringList() ) );
00186 mSuffix->setNameParts( config.readEntry( "Suffixes" , QStringList() ) );
00187
00188 KConfig _cfg( "kaddressbookrc" );
00189 KConfigGroup cfg(&_cfg, "General" );
00190 mFormattedNameCombo->setCurrentIndex( cfg.readEntry( "FormattedNameType", 1 ) );
00191 }
00192
00193 void AddresseeWidget::saveSettings()
00194 {
00195 KConfig _config( "kabcrc" );
00196 KConfigGroup config(&_config, "General" );
00197
00198 config.writeEntry( "Prefixes", mPrefix->nameParts() );
00199 config.writeEntry( "Inclusions", mInclusion->nameParts() );
00200 config.writeEntry( "Suffixes", mSuffix->nameParts() );
00201
00202 KConfig _cfg( "kaddressbookrc" );
00203 KConfigGroup cfg(&_cfg, "General" );
00204 cfg.writeEntry( "FormattedNameType", mFormattedNameCombo->currentIndex() );
00205
00206 QDBusMessage message =
00207 QDBusMessage::createSignal( "/KABC", "org.kde.kabc.AddressBookConfig",
00208 "changed" );
00209 QDBusConnection::sessionBus().send( message );
00210 }
00211
00212 #include "addresseewidget.moc"