configdialog.cpp

00001 /*
00002     This file is part of libkresources.
00003 
00004     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00005     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00006     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include <klocale.h>
00025 #include <klineedit.h>
00026 #include <kmessagebox.h>
00027 
00028 #include <qgroupbox.h>
00029 #include <qlabel.h>
00030 #include <qlayout.h>
00031 #include <qcheckbox.h>
00032 
00033 #include "factory.h"
00034 #include "configdialog.h"
00035 
00036 using namespace KRES;
00037 
00038 ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily,
00039     /*const QString& type,*/ Resource* resource, /*KConfig *config, */const char *name )
00040   : KDialogBase( parent, name, true, i18n( "Resource Configuration" ),
00041     Ok|Cancel, Ok, false )/*, mConfig( config )*/, mResource( resource )
00042 {
00043   Factory *factory = Factory::self( resourceFamily );
00044 
00045   QFrame *main = makeMainWidget();
00046 
00047   QVBoxLayout *mainLayout = new QVBoxLayout( main, 0, spacingHint() );
00048 
00049   QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, main );
00050   generalGroupBox->layout()->setSpacing( spacingHint() );
00051   generalGroupBox->setTitle( i18n( "General Settings" ) );
00052 
00053   new QLabel( i18n( "Name:" ), generalGroupBox );
00054 
00055   mName = new KLineEdit( generalGroupBox );
00056 
00057   mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox );
00058 
00059   mName->setText( mResource->resourceName() );
00060   mReadOnly->setChecked( mResource->readOnly() );
00061 
00062   mainLayout->addWidget( generalGroupBox );
00063 
00064   QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal,  main );
00065   resourceGroupBox->layout()->setSpacing( spacingHint() );
00066   resourceGroupBox->setTitle( i18n( "%1 Resource Settings" )
00067                               .arg( factory->typeName( resource->type() ) ) );
00068   mainLayout->addWidget( resourceGroupBox );
00069 
00070   mainLayout->addStretch();
00071 
00072   mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox );
00073   if ( mConfigWidget ) {
00074     mConfigWidget->setInEditMode( false );
00075     mConfigWidget->loadSettings( mResource );
00076     mConfigWidget->show();
00077     connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ),
00078         SLOT( setReadOnly( bool ) ) );
00079   }
00080 
00081   connect( mName, SIGNAL( textChanged(const QString &)),
00082       SLOT( slotNameChanged(const QString &)));
00083 
00084   slotNameChanged( mName->text() );
00085   setMinimumSize( sizeHint() );
00086 }
00087 
00088 void ConfigDialog::setInEditMode( bool value )
00089 {
00090   if ( mConfigWidget )
00091     mConfigWidget->setInEditMode( value );
00092 }
00093 
00094 void ConfigDialog::slotNameChanged( const QString &text)
00095 {
00096   enableButtonOK( !text.isEmpty() );
00097 }
00098 
00099 void ConfigDialog::setReadOnly( bool value )
00100 {
00101   mReadOnly->setChecked( value );
00102 }
00103 
00104 void ConfigDialog::accept()
00105 {
00106   if ( mName->text().isEmpty() ) {
00107     KMessageBox::sorry( this, i18n( "Please enter a resource name." ) );
00108     return;
00109   }
00110 
00111   mResource->setResourceName( mName->text() );
00112   mResource->setReadOnly( mReadOnly->isChecked() );
00113 
00114   if ( mConfigWidget ) {
00115     // First save generic information
00116     // Also save setting of specific resource type
00117     mConfigWidget->saveSettings( mResource );
00118   }
00119 
00120   KDialog::accept();
00121 }
00122 
00123 #include "configdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys