kitchensync

konnectorconfigdialog.cpp

00001 /*
00002     This file is part of KitchenSync.
00003     Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
00004 
00005     Based on the code of KRES::ConfigDialog from kdelibs
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <klineedit.h>
00024 #include <klocale.h>
00025 #include <kmessagebox.h>
00026 
00027 #include <qcheckbox.h>
00028 #include <qgroupbox.h>
00029 #include <qlabel.h>
00030 #include <qlayout.h>
00031 #include <qtabwidget.h>
00032 
00033 #include <kresources/factory.h>
00034 
00035 #include "konnector.h"
00036 
00037 #include "konnectorconfigdialog.h"
00038 
00039 KonnectorConfigDialog::KonnectorConfigDialog( QWidget *parent, KSync::Konnector *konnector )
00040   : KDialogBase( Plain, i18n( "Konnector Configuration" ), Ok | Cancel, Ok,
00041                  parent, "KonnectorConfigDialog", true, true ),
00042     mKonnector( konnector )
00043 {
00044   QFrame *page = plainPage();
00045 
00046   QVBoxLayout *layout = new QVBoxLayout( page, 0, spacingHint() );
00047 
00048   QTabWidget *tab = new QTabWidget( page );
00049   tab->addTab( createGeneralPage( tab ), i18n( "General" ) );
00050   tab->addTab( createFilterPage( tab ), i18n( "Filter" ) );
00051 
00052   layout->addWidget( tab );
00053 
00054   setMinimumSize( sizeHint() );
00055 }
00056 
00057 void KonnectorConfigDialog::setInEditMode( bool value )
00058 {
00059   if ( mConfigWidget )
00060     mConfigWidget->setInEditMode( value );
00061 }
00062 
00063 void KonnectorConfigDialog::slotNameChanged( const QString &text)
00064 {
00065   enableButtonOK( !text.isEmpty() );
00066 }
00067 
00068 void KonnectorConfigDialog::setReadOnly( bool value )
00069 {
00070   mReadOnly->setChecked( value );
00071 }
00072 
00073 void KonnectorConfigDialog::accept()
00074 {
00075   if ( mName->text().isEmpty() ) {
00076     KMessageBox::sorry( this, i18n( "Please enter a resource name." ) );
00077     return;
00078   }
00079 
00080   mKonnector->setResourceName( mName->text() );
00081   mKonnector->setReadOnly( mReadOnly->isChecked() );
00082 
00083   if ( mConfigWidget ) {
00084     // First save generic information
00085     // Also save setting of specific resource type
00086     mConfigWidget->saveSettings( mKonnector );
00087   }
00088 
00089   KDialog::accept();
00090 }
00091 
00092 QWidget *KonnectorConfigDialog::createGeneralPage( QWidget *parent )
00093 {
00094   QWidget *page = new QWidget( parent );
00095   QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() );
00096 
00097   KRES::Factory *factory = KRES::Factory::self( "konnector" );
00098 
00099   QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, page );
00100   generalGroupBox->layout()->setSpacing( spacingHint() );
00101   generalGroupBox->setTitle( i18n( "General Settings" ) );
00102 
00103   new QLabel( i18n( "Name:" ), generalGroupBox );
00104 
00105   mName = new KLineEdit( generalGroupBox );
00106 
00107   mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox );
00108 
00109   mName->setText( mKonnector->resourceName() );
00110   mReadOnly->setChecked( mKonnector->readOnly() );
00111 
00112   layout->addWidget( generalGroupBox );
00113 
00114   QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal,  page );
00115   resourceGroupBox->layout()->setSpacing( spacingHint() );
00116   resourceGroupBox->setTitle( i18n( "%1 Settings" )
00117                               .arg( factory->typeName( mKonnector->type() ) ) );
00118   layout->addWidget( resourceGroupBox );
00119 
00120   layout->addStretch();
00121 
00122   mConfigWidget = factory->configWidget( mKonnector->type(), resourceGroupBox );
00123   if ( mConfigWidget ) {
00124     mConfigWidget->setInEditMode( false );
00125     mConfigWidget->loadSettings( mKonnector );
00126     mConfigWidget->show();
00127     connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ),
00128              this, SLOT( setReadOnly( bool ) ) );
00129   }
00130 
00131   connect( mName, SIGNAL( textChanged( const QString& ) ),
00132            this, SLOT( slotNameChanged( const QString& ) ) );
00133 
00134   slotNameChanged( mName->text() );
00135 
00136   return page;
00137 }
00138 
00139 QWidget *KonnectorConfigDialog::createFilterPage( QWidget *parent )
00140 {
00141   QWidget *page = new QWidget( parent );
00142   QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() );
00143 
00144   const KSync::Filter::List filters = mKonnector->filters();
00145   KSync::Filter::List::ConstIterator it;
00146   for ( it = filters.begin(); it != filters.end(); ++it ) {
00147     QWidget *wdg = (*it)->configWidget( page );
00148     layout->addWidget( wdg );
00149   }
00150 
00151   return page;
00152 }
00153 
00154 #include "konnectorconfigdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys