libkdepim Library API Documentation

resourceconfigdlg.cpp

00001 /*
00002     This file is part of libkdepim.
00003     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00004     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <klocale.h>
00023 #include <kmessagebox.h>
00024 
00025 #include <qgroupbox.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qpushbutton.h>
00029 
00030 #include "resourcefactory.h"
00031 #include "resourceconfigdlg.h"
00032 
00033 using namespace KPIM;
00034 
00035 ResourceConfigDlg::ResourceConfigDlg( QWidget *parent, const QString& resourceType,
00036     const QString& type, KConfig *config, const char *name )
00037   : KDialog( parent, name, true ), mConfig( config )
00038 {
00039   ResourceFactory *factory = ResourceFactory::self( resourceType );
00040 
00041   setCaption( i18n( "Resource Configuration" ) );
00042   resize( 250, 240 );
00043 
00044   QVBoxLayout *mainLayout = new QVBoxLayout( this, marginHint(), spacingHint() );
00045     
00046   QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal,  this );
00047   generalGroupBox->setTitle( i18n( "General Settings" ) );
00048 
00049   new QLabel( i18n( "Name:" ), generalGroupBox );
00050 
00051   mName = new KLineEdit( generalGroupBox );
00052 
00053   mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox );
00054 
00055   mFast = new QCheckBox( i18n( "Fast resource" ), generalGroupBox );
00056   // we hide this checkbox until we find a meanigfull name :)
00057   mFast->hide();
00058 
00059   mainLayout->addWidget( generalGroupBox );
00060 
00061   QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal,  this );
00062   resourceGroupBox->setTitle( i18n( "Resource Settings" ) );
00063 
00064   mainLayout->addSpacing( 10 );
00065   mainLayout->addWidget( resourceGroupBox );
00066   mainLayout->addSpacing( 10 );
00067 
00068   mConfigWidget = factory->configWidget( type, resourceGroupBox );
00069   if ( mConfigWidget && mConfig ) {
00070     mConfigWidget->loadSettings( mConfig );
00071     mConfigWidget->show();
00072     connect( mConfigWidget, SIGNAL( setResourceName( const QString & ) ), SLOT( setResourceName( const QString & ) ) );
00073     connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ), SLOT( setReadOnly( bool ) ) );
00074     connect( mConfigWidget, SIGNAL( setFast( bool ) ), SLOT( setFast( bool ) ) );
00075   }
00076 
00077   mButtonBox = new KButtonBox( this );
00078 
00079   mButtonBox->addStretch();    
00080   mButtonBox->addButton( i18n( "&OK" ), this, SLOT( accept() ) )->setFocus();
00081   mButtonBox->addButton( i18n( "&Cancel" ), this, SLOT( reject() ) );
00082   mButtonBox->layout();
00083 
00084   mainLayout->addWidget( mButtonBox );
00085 }
00086 
00087 int ResourceConfigDlg::exec()
00088 {
00089   return QDialog::exec();
00090 }
00091 
00092 bool ResourceConfigDlg::readOnly()
00093 {
00094   return mReadOnly->isChecked();
00095 }
00096 
00097 bool ResourceConfigDlg::fast()
00098 {
00099   return mFast->isChecked();
00100 }
00101 
00102 QString ResourceConfigDlg::resourceName()
00103 {
00104   return mName->text();
00105 }
00106 
00107 void ResourceConfigDlg::setReadOnly( bool value )
00108 {
00109   mReadOnly->setChecked( value );
00110 }
00111 
00112 void ResourceConfigDlg::setFast( bool value )
00113 {
00114   mFast->setChecked( value );
00115 }
00116 
00117 void ResourceConfigDlg::setResourceName( const QString &name )
00118 {
00119   mName->setText( name );
00120 }
00121 
00122 void ResourceConfigDlg::accept()
00123 {
00124   if ( mName->text().isEmpty() ) {
00125     KMessageBox::sorry( this, i18n( "Please enter a resource name" ) );
00126     return;
00127   }
00128 
00129   if ( mConfigWidget && mConfig )
00130     mConfigWidget->saveSettings( mConfig );
00131 
00132   QDialog::accept();
00133 }
00134 
00135 #include "resourceconfigdlg.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:00 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001