00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "customfieldeditordialog.h"
00023
00024 #include <kcombobox.h>
00025 #include <klineedit.h>
00026 #include <klocale.h>
00027
00028 #include <QtGui/QCheckBox>
00029 #include <QtGui/QFormLayout>
00030 #include <QtGui/QRegExpValidator>
00031
00032 CustomFieldEditorDialog::CustomFieldEditorDialog( QWidget *parent )
00033 : KDialog( parent )
00034 {
00035 setCaption( i18n( "Edit Custom Field" ) );
00036 setButtons( Ok | Cancel | Details );
00037
00038 QWidget *widget = new QWidget( this );
00039 setMainWidget( widget );
00040
00041 QFormLayout *layout = new QFormLayout( widget );
00042
00043 mKey = new KLineEdit;
00044 mTitle = new KLineEdit;
00045 mType = new KComboBox;
00046 mScope = new QCheckBox( i18n( "Use field for all contacts" ) );
00047
00048 layout->addRow( i18nc( "The title of a custom field", "Title" ), mTitle );
00049 layout->addRow( i18nc( "The type of a custom field", "Type" ), mType );
00050 layout->addRow( QString(), mScope );
00051
00052 QWidget *detailsWidget = new QWidget;
00053 QFormLayout *detailsLayout = new QFormLayout( detailsWidget );
00054 detailsLayout->addRow( i18n( "Key" ), mKey );
00055
00056 setDetailsWidget( detailsWidget );
00057 setButtonText( Details, i18nc( "@label Opens the advanced dialog", "Advanced" ) );
00058
00059 mType->addItem( i18n( "Text" ), CustomField::TextType );
00060 mType->addItem( i18n( "Numeric" ), CustomField::NumericType );
00061 mType->addItem( i18n( "Boolean" ), CustomField::BooleanType );
00062 mType->addItem( i18n( "Date" ), CustomField::DateType );
00063 mType->addItem( i18n( "Time" ), CustomField::TimeType );
00064 mType->addItem( i18n( "DateTime" ), CustomField::DateTimeType );
00065
00066 mKey->setValidator( new QRegExpValidator( QRegExp( QLatin1String( "[a-zA-Z0-9\\-]+" ) ), this ) );
00067 }
00068
00069 void CustomFieldEditorDialog::setCustomField( const CustomField &field )
00070 {
00071 mCustomField = field;
00072
00073 mKey->setText( mCustomField.key() );
00074 mTitle->setText( mCustomField.title() );
00075 mType->setCurrentIndex( mType->findData( mCustomField.type() ) );
00076 mScope->setChecked( (mCustomField.scope() == CustomField::GlobalScope) );
00077 }
00078
00079 CustomField CustomFieldEditorDialog::customField() const
00080 {
00081 CustomField customField( mCustomField );
00082
00083 customField.setKey( mKey->text() );
00084 customField.setTitle( mTitle->text() );
00085 customField.setType( static_cast<CustomField::Type>( mType->itemData( mType->currentIndex() ).toInt() ) );
00086
00087 if ( customField.scope() != CustomField::ExternalScope ) {
00088
00089 customField.setScope( mScope->isChecked() ? CustomField::GlobalScope : CustomField::LocalScope );
00090 }
00091
00092 return customField;
00093 }