configdialog.cpp
Go to the documentation of this file.
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 */ 00035 #include "configdialog.h" 00036 #include <klocale.h> 00037 #include <klineedit.h> 00038 #include <kmessagebox.h> 00039 00040 #include <QtGui/QGroupBox> 00041 #include <QtGui/QLabel> 00042 #include <QtGui/QLayout> 00043 #include <QtGui/QCheckBox> 00044 00045 #include "factory.h" 00046 00047 using namespace KRES; 00048 00049 class ConfigDialog::Private 00050 { 00051 public: 00052 ConfigWidget *mConfigWidget; 00053 Resource *mResource; 00054 KLineEdit *mName; 00055 QCheckBox *mReadOnly; 00056 }; 00057 00058 ConfigDialog::ConfigDialog( QWidget *parent, const QString &resourceFamily, 00059 Resource *resource ) 00060 : KDialog( parent ), d( new Private ) 00061 { 00062 setModal( true ); 00063 setCaption( i18nc( "@title:window", "Resource Configuration" ) ); 00064 setButtons( Ok | Cancel ); 00065 setDefaultButton( Ok ); 00066 showButtonSeparator( false ); 00067 00068 d->mResource = resource; 00069 Factory *factory = Factory::self( resourceFamily ); 00070 00071 QFrame *main = new QFrame( this ); 00072 setMainWidget( main ); 00073 00074 QVBoxLayout *mainLayout = new QVBoxLayout( main ); 00075 mainLayout->setMargin( 0 ); 00076 00077 QGroupBox *generalGroupBox = new QGroupBox( main ); 00078 QGridLayout *gbLayout = new QGridLayout; 00079 generalGroupBox->setLayout( gbLayout ); 00080 00081 generalGroupBox->setTitle( i18nc( "@title:group", "General Settings" ) ); 00082 00083 gbLayout->addWidget( new QLabel( i18nc( "@label resource name", "Name:" ), 00084 generalGroupBox ), 0, 0 ); 00085 00086 d->mName = new KLineEdit(); 00087 gbLayout->addWidget( d->mName, 0, 1 ); 00088 00089 d->mReadOnly = 00090 new QCheckBox( i18nc( "@option:check if resource is read-only", "Read-only" ), 00091 generalGroupBox ); 00092 gbLayout->addWidget( d->mReadOnly, 1, 0, 1, 2 ); 00093 00094 d->mName->setText( d->mResource->resourceName() ); 00095 d->mReadOnly->setChecked( d->mResource->readOnly() ); 00096 00097 mainLayout->addWidget( generalGroupBox ); 00098 00099 QGroupBox *resourceGroupBox = new QGroupBox( main ); 00100 QGridLayout *resourceLayout = new QGridLayout; 00101 resourceGroupBox->setLayout( resourceLayout ); 00102 00103 resourceGroupBox->setTitle( i18nc( "@title:group", "%1 Resource Settings", 00104 factory->typeName( resource->type() ) ) ); 00105 mainLayout->addWidget( resourceGroupBox ); 00106 00107 mainLayout->addStretch(); 00108 00109 d->mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox ); 00110 if ( d->mConfigWidget ) { 00111 resourceLayout->addWidget( d->mConfigWidget ); 00112 d->mConfigWidget->setInEditMode( false ); 00113 d->mConfigWidget->loadSettings( d->mResource ); 00114 d->mConfigWidget->show(); 00115 connect( d->mConfigWidget, SIGNAL(setReadOnly(bool)), 00116 SLOT(setReadOnly(bool)) ); 00117 } 00118 00119 connect( d->mName, SIGNAL(textChanged(QString)), 00120 SLOT(slotNameChanged(QString)) ); 00121 00122 slotNameChanged( d->mName->text() ); 00123 setMinimumSize( sizeHint() ); 00124 } 00125 00126 ConfigDialog::~ConfigDialog() 00127 { 00128 delete d; 00129 } 00130 00131 void ConfigDialog::setInEditMode( bool value ) 00132 { 00133 if ( d->mConfigWidget ) { 00134 d->mConfigWidget->setInEditMode( value ); 00135 } 00136 } 00137 00138 void ConfigDialog::slotNameChanged( const QString &text ) 00139 { 00140 enableButtonOk( !text.isEmpty() ); 00141 } 00142 00143 void ConfigDialog::setReadOnly( bool value ) 00144 { 00145 d->mReadOnly->setChecked( value ); 00146 } 00147 00148 void ConfigDialog::accept() 00149 { 00150 if ( d->mName->text().isEmpty() ) { 00151 KMessageBox::sorry( this, i18nc( "@info", "Please enter a resource name." ) ); 00152 return; 00153 } 00154 00155 d->mResource->setResourceName( d->mName->text() ); 00156 d->mResource->setReadOnly( d->mReadOnly->isChecked() ); 00157 00158 if ( d->mConfigWidget ) { 00159 // First save generic information 00160 // Also save setting of specific resource type 00161 d->mConfigWidget->saveSettings( d->mResource ); 00162 } 00163 00164 KDialog::accept(); 00165 } 00166 00167 #include "configdialog.moc"