kitchensync

plugineditorwidget.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2004 Tobias Koenig <tokoe@kde.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., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <kcombobox.h>
00023 #include <kdialog.h>
00024 #include <klocale.h>
00025 
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qpushbutton.h>
00029 
00030 #include "konnectorconfigdialog.h"
00031 #include "konnectorpair.h"
00032 #include "plugineditorwidget.h"
00033 
00034 
00035 PluginEditorWidget::PluginEditorWidget( QWidget *parent, const char *name )
00036   : QWidget( parent, name )
00037 {
00038   initGUI();
00039 
00040   connect( mTypeBox, SIGNAL( activated( int ) ), SLOT( typeChanged( int ) ) );
00041   connect( mOptionButton, SIGNAL( clicked() ), SLOT( changeOptions() ) );
00042 }
00043 
00044 PluginEditorWidget::~PluginEditorWidget()
00045 {
00046 }
00047 
00048 void PluginEditorWidget::setLabel( const QString &label )
00049 {
00050   mLabel->setText( label );
00051 }
00052 
00053 void PluginEditorWidget::set( KonnectorPair *pair, KSync::Konnector *konnector )
00054 {
00055   mPair = pair;
00056   mOldKonnector = mKonnector = konnector;
00057 
00058   fillTypeBox();
00059 
00060   if ( !mKonnector )
00061     typeChanged( mTypeBox->currentItem() );
00062 
00063   if ( mKonnector ) {
00064     QStringList types = mPair->manager()->resourceTypeNames();
00065     int pos = types.findIndex( mKonnector->type() );
00066 
00067     mTypeBox->setCurrentItem( pos );
00068   }
00069 }
00070 
00071 void PluginEditorWidget::get( KonnectorPair *pair )
00072 {
00073   if ( mKonnector == mOldKonnector ) {
00074     if ( mKonnector )
00075       pair->manager()->change( mKonnector );
00076   } else {
00077     pair->manager()->remove( mOldKonnector );
00078     pair->manager()->add( mKonnector );
00079   }
00080 }
00081 
00082 void PluginEditorWidget::fillTypeBox()
00083 {
00084   mTypeBox->clear();
00085   mTypeBox->insertStringList( mPair->manager()->resourceTypeDescriptions() );
00086 }
00087 
00088 void PluginEditorWidget::typeChanged( int )
00089 {
00090   KSync::Konnector *konnector = mPair->manager()->createResource( currentType() );
00091   if ( konnector ) {
00092     konnector->initDefaultFilters();
00093     mKonnector = konnector;
00094   }
00095 }
00096 
00097 void PluginEditorWidget::changeOptions()
00098 {
00099   if ( mKonnector == 0 )
00100     return;
00101 
00102   KonnectorConfigDialog dlg( this, mKonnector );
00103 
00104   dlg.exec();
00105 }
00106 
00107 QString PluginEditorWidget::currentType() const
00108 {
00109   return mPair->manager()->resourceTypeNames()[ mTypeBox->currentItem() ];
00110 }
00111 
00112 void PluginEditorWidget::initGUI()
00113 {
00114   QGridLayout *layout = new QGridLayout( this, 2, 3, KDialog::marginHint(),
00115                                          KDialog::spacingHint() );
00116 
00117   mLabel = new QLabel( this );
00118   layout->addWidget( mLabel, 0, 0 );
00119 
00120   mTypeBox = new KComboBox( this );
00121   layout->addWidget( mTypeBox, 0, 1 );
00122 
00123   mLabel->setBuddy( mTypeBox );
00124 
00125   mOptionButton = new QPushButton( i18n( "Options" ), this );
00126   layout->addWidget( mOptionButton, 0, 2 );
00127 
00128   mInfoLabel = new QLabel( this );
00129   layout->addMultiCellWidget( mInfoLabel, 1, 1, 1, 2 );
00130 }
00131 
00132 #include "plugineditorwidget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys