resourceconfigdlg.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <klocale.h>
00022 #include <kmessagebox.h>
00023
00024 #include <qgroupbox.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qpushbutton.h>
00028
00029 #include "resourcefactory.h"
00030 #include "resourceconfigdlg.h"
00031
00032 ResourceConfigDlg::ResourceConfigDlg( QWidget *parent, const QString& type,
00033 KConfig *config, const char *name )
00034 : KDialog( parent, name, true ), mConfig( config )
00035 {
00036 KABC::ResourceFactory *factory = KABC::ResourceFactory::self();
00037
00038 setCaption( i18n( "Resource Configuration" ) );
00039 resize( 250, 240 );
00040
00041 QVBoxLayout *mainLayout = new QVBoxLayout( this, marginHint(), spacingHint() );
00042
00043 QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, this );
00044 generalGroupBox->setTitle( i18n( "General Settings" ) );
00045
00046 new QLabel( i18n( "Name:" ), generalGroupBox );
00047
00048 mName = new KLineEdit( generalGroupBox );
00049
00050 mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox );
00051
00052 mFast = new QCheckBox( i18n( "Fast resource" ), generalGroupBox );
00053
00054 mFast->hide();
00055
00056 mainLayout->addWidget( generalGroupBox );
00057
00058 QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal, this );
00059 resourceGroupBox->setTitle( i18n( "Resource Settings" ) );
00060
00061 mainLayout->addSpacing( 10 );
00062 mainLayout->addWidget( resourceGroupBox );
00063 mainLayout->addSpacing( 10 );
00064
00065 mConfigWidget = factory->configWidget( type, resourceGroupBox );
00066 if ( mConfigWidget && mConfig ) {
00067 mConfigWidget->setEditMode( false );
00068 mConfigWidget->loadSettings( mConfig );
00069 mConfigWidget->show();
00070 connect( mConfigWidget, SIGNAL( setResourceName( const QString & ) ), SLOT( setResourceName( const QString & ) ) );
00071 connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ), SLOT( setReadOnly( bool ) ) );
00072 connect( mConfigWidget, SIGNAL( setFast( bool ) ), SLOT( setFast( bool ) ) );
00073 }
00074
00075 mButtonBox = new KButtonBox( this );
00076
00077 mButtonBox->addStretch();
00078 mButtonBox->addButton( i18n( "&OK" ), this, SLOT( accept() ) )->setFocus();
00079 mButtonBox->addButton( i18n( "&Cancel" ), this, SLOT( reject() ) );
00080 mButtonBox->layout();
00081
00082 mainLayout->addWidget( mButtonBox );
00083 }
00084
00085 int ResourceConfigDlg::exec()
00086 {
00087 return QDialog::exec();
00088 }
00089
00090 bool ResourceConfigDlg::readOnly()
00091 {
00092 return mReadOnly->isChecked();
00093 }
00094
00095 bool ResourceConfigDlg::fast()
00096 {
00097 return mFast->isChecked();
00098 }
00099
00100 QString ResourceConfigDlg::resourceName()
00101 {
00102 return mName->text();
00103 }
00104
00105 void ResourceConfigDlg::setReadOnly( bool value )
00106 {
00107 mReadOnly->setChecked( value );
00108 }
00109
00110 void ResourceConfigDlg::setFast( bool value )
00111 {
00112 mFast->setChecked( value );
00113 }
00114
00115 void ResourceConfigDlg::setResourceName( const QString &name )
00116 {
00117 mName->setText( name );
00118 }
00119
00120 void ResourceConfigDlg::setEditMode( bool value )
00121 {
00122 if ( mConfigWidget )
00123 mConfigWidget->setEditMode( value );
00124 }
00125
00126 void ResourceConfigDlg::accept()
00127 {
00128 if ( mName->text().isEmpty() ) {
00129 KMessageBox::sorry( this, i18n( "Please enter a resource name" ) );
00130 return;
00131 }
00132
00133 if ( mConfigWidget && mConfig )
00134 mConfigWidget->saveSettings( mConfig );
00135
00136 QDialog::accept();
00137 }
00138
00139 #include "resourceconfigdlg.moc"
This file is part of the documentation for kdelibs Version 3.1.5.