36 #include <klocalizedstring.h>
37 #include <klineedit.h>
38 #include <kmessagebox.h>
49 class ConfigDialog::Private
58 ConfigDialog::ConfigDialog( QWidget *parent,
const QString &resourceFamily,
60 : KDialog( parent ), d( new Private )
63 setCaption( i18nc(
"@title:window",
"Resource Configuration" ) );
64 setButtons( Ok | Cancel );
65 setDefaultButton( Ok );
66 showButtonSeparator(
false );
68 d->mResource = resource;
69 Factory *factory = Factory::self( resourceFamily );
71 QFrame *main =
new QFrame(
this );
72 setMainWidget( main );
74 QVBoxLayout *mainLayout =
new QVBoxLayout( main );
75 mainLayout->setMargin( 0 );
77 QGroupBox *generalGroupBox =
new QGroupBox( main );
78 QGridLayout *gbLayout =
new QGridLayout;
79 generalGroupBox->setLayout( gbLayout );
81 generalGroupBox->setTitle( i18nc(
"@title:group",
"General Settings" ) );
83 gbLayout->addWidget(
new QLabel( i18nc(
"@label resource name",
"Name:" ),
84 generalGroupBox ), 0, 0 );
86 d->mName =
new KLineEdit();
87 gbLayout->addWidget( d->mName, 0, 1 );
90 new QCheckBox( i18nc(
"@option:check if resource is read-only",
"Read-only" ),
92 gbLayout->addWidget( d->mReadOnly, 1, 0, 1, 2 );
94 d->mName->setText( d->mResource->resourceName() );
95 d->mReadOnly->setChecked( d->mResource->readOnly() );
97 mainLayout->addWidget( generalGroupBox );
99 QGroupBox *resourceGroupBox =
new QGroupBox( main );
100 QGridLayout *resourceLayout =
new QGridLayout;
101 resourceGroupBox->setLayout( resourceLayout );
103 resourceGroupBox->setTitle( i18nc(
"@title:group",
"%1 Resource Settings",
105 mainLayout->addWidget( resourceGroupBox );
107 mainLayout->addStretch();
109 d->mConfigWidget = factory->
configWidget( resource->
type(), resourceGroupBox );
110 if ( d->mConfigWidget ) {
111 resourceLayout->addWidget( d->mConfigWidget );
113 d->mConfigWidget->loadSettings( d->mResource );
114 d->mConfigWidget->show();
115 connect( d->mConfigWidget, SIGNAL(setReadOnly(
bool)),
116 SLOT(setReadOnly(
bool)) );
119 connect( d->mName, SIGNAL(textChanged(QString)),
120 SLOT(slotNameChanged(QString)) );
122 slotNameChanged( d->mName->text() );
123 setMinimumSize( sizeHint() );
126 ConfigDialog::~ConfigDialog()
131 void ConfigDialog::setInEditMode(
bool value )
133 if ( d->mConfigWidget ) {
134 d->mConfigWidget->setInEditMode( value );
138 void ConfigDialog::slotNameChanged(
const QString &text )
140 enableButtonOk( !text.isEmpty() );
143 void ConfigDialog::setReadOnly(
bool value )
145 d->mReadOnly->setChecked( value );
148 void ConfigDialog::accept()
150 if ( d->mName->text().isEmpty() ) {
151 KMessageBox::sorry(
this, i18nc(
"@info",
"Please enter a resource name." ) );
155 d->mResource->setResourceName( d->mName->text() );
156 d->mResource->setReadOnly( d->mReadOnly->isChecked() );
158 if ( d->mConfigWidget ) {
161 d->mConfigWidget->saveSettings( d->mResource );
This file is part of the KDE resource framework and defines the ConfigDialog class.
QString type() const
Returns the type of this resource.
This class provides a resource which is managed in a general way.
This file is part of the KDE resource framework and defines the Factory class.
ConfigWidget * configWidget(const QString &type, QWidget *parent=0)
Returns the config widget for the given resource type, or a null pointer if resource type doesn't exi...
QString typeName(const QString &type) const
Returns the name for a special type.
A class for loading resource plugins.