• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

kresources

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->setSpacing( spacingHint() );
00076   mainLayout->setMargin( 0 );
00077 
00078   QGroupBox *generalGroupBox = new QGroupBox( main );
00079   QGridLayout *gbLayout = new QGridLayout;
00080   gbLayout->setSpacing( spacingHint() );
00081   generalGroupBox->setLayout( gbLayout );
00082 
00083   generalGroupBox->setTitle( i18nc( "@title:group", "General Settings" ) );
00084 
00085   gbLayout->addWidget( new QLabel( i18nc( "@label resource name", "Name:" ),
00086                                    generalGroupBox ), 0, 0 );
00087 
00088   d->mName = new KLineEdit();
00089   gbLayout->addWidget( d->mName, 0, 1 );
00090 
00091   d->mReadOnly =
00092     new QCheckBox( i18nc( "@option:check if resource is read-only", "Read-only" ),
00093                    generalGroupBox );
00094   gbLayout->addWidget( d->mReadOnly, 1, 0, 1, 2 );
00095 
00096   d->mName->setText( d->mResource->resourceName() );
00097   d->mReadOnly->setChecked( d->mResource->readOnly() );
00098 
00099   mainLayout->addWidget( generalGroupBox );
00100 
00101   QGroupBox *resourceGroupBox = new QGroupBox( main );
00102   QGridLayout *resourceLayout = new QGridLayout;
00103   resourceLayout->setSpacing( spacingHint() );
00104   resourceLayout->setMargin( marginHint() );
00105   resourceGroupBox->setLayout( resourceLayout );
00106 
00107   resourceGroupBox->setTitle( i18nc( "@title:group", "%1 Resource Settings",
00108                                     factory->typeName( resource->type() ) ) );
00109   mainLayout->addWidget( resourceGroupBox );
00110 
00111   mainLayout->addStretch();
00112 
00113   d->mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox );
00114   if ( d->mConfigWidget ) {
00115     resourceLayout->addWidget( d->mConfigWidget );
00116     d->mConfigWidget->setInEditMode( false );
00117     d->mConfigWidget->loadSettings( d->mResource );
00118     d->mConfigWidget->show();
00119     connect( d->mConfigWidget, SIGNAL( setReadOnly( bool ) ),
00120              SLOT( setReadOnly( bool ) ) );
00121   }
00122 
00123   connect( d->mName, SIGNAL( textChanged(const QString &) ),
00124            SLOT( slotNameChanged(const QString &) ) );
00125 
00126   slotNameChanged( d->mName->text() );
00127   setMinimumSize( sizeHint() );
00128 }
00129 
00130 ConfigDialog::~ConfigDialog()
00131 {
00132   delete d;
00133 }
00134 
00135 void ConfigDialog::setInEditMode( bool value )
00136 {
00137   if ( d->mConfigWidget ) {
00138     d->mConfigWidget->setInEditMode( value );
00139   }
00140 }
00141 
00142 void ConfigDialog::slotNameChanged( const QString &text )
00143 {
00144   enableButtonOk( !text.isEmpty() );
00145 }
00146 
00147 void ConfigDialog::setReadOnly( bool value )
00148 {
00149   d->mReadOnly->setChecked( value );
00150 }
00151 
00152 void ConfigDialog::accept()
00153 {
00154   if ( d->mName->text().isEmpty() ) {
00155     KMessageBox::sorry( this, i18nc( "@info", "Please enter a resource name." ) );
00156     return;
00157   }
00158 
00159   d->mResource->setResourceName( d->mName->text() );
00160   d->mResource->setReadOnly( d->mReadOnly->isChecked() );
00161 
00162   if ( d->mConfigWidget ) {
00163     // First save generic information
00164     // Also save setting of specific resource type
00165     d->mConfigWidget->saveSettings( d->mResource );
00166   }
00167 
00168   KDialog::accept();
00169 }
00170 
00171 #include "configdialog.moc"

kresources

Skip menu "kresources"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal