kitchensync
plugineditorwidget.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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"
|