kitchensync

paireditorwidget.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 <klineedit.h>
00025 #include <klocale.h>
00026 
00027 #include <qcheckbox.h>
00028 #include <qbuttongroup.h>
00029 #include <qlabel.h>
00030 #include <qlayout.h>
00031 #include <qpushbutton.h>
00032 #include <qradiobutton.h>
00033 #include <qtabwidget.h>
00034 
00035 #include "konnectorpair.h"
00036 #include "plugineditorwidget.h"
00037 
00038 #include "paireditorwidget.h"
00039 
00040 PairEditorWidget::PairEditorWidget( QWidget *parent, const char *name )
00041   : QWidget( parent, name )
00042 {
00043   initGUI();
00044 }
00045 
00046 PairEditorWidget::~PairEditorWidget()
00047 {
00048 }
00049 
00050 void PairEditorWidget::setPair( KonnectorPair *pair )
00051 {
00052   mPair = pair;
00053 
00054   mPairNameEdit->setText( mPair->name() );
00055 
00056   switch ( mPair->resolveStrategy() ) {
00057     case KonnectorPair::ResolveManually:
00058       mResolveManually->setChecked( true );
00059       break;
00060     case KonnectorPair::ResolveFirst:
00061       mResolveFirst->setChecked( true );
00062       break;
00063     case KonnectorPair::ResolveSecond:
00064       mResolveSecond->setChecked( true );
00065       break;
00066     case KonnectorPair::ResolveBoth:
00067       mResolveBoth->setChecked( true );
00068       break;
00069   }
00070 
00071   KonnectorManager *manager = mPair->manager();
00072   KonnectorManager::Iterator it = manager->begin();
00073 
00074   KSync::Konnector *konnector;
00075   if ( it != manager->end() )
00076     konnector = *it;
00077   else
00078     konnector = 0;
00079   it++;
00080 
00081   mEditorWidgets[ 0 ]->set( mPair, konnector );
00082 
00083   if ( it != manager->end() )
00084     konnector = *it;
00085   else
00086     konnector = 0;
00087 
00088   mEditorWidgets[ 1 ]->set( mPair, konnector );
00089 }
00090 
00091 KonnectorPair *PairEditorWidget::pair() const
00092 {
00093   mPair->setName( mPairNameEdit->text() );
00094   mEditorWidgets[ 0 ]->get( mPair );
00095   mEditorWidgets[ 1 ]->get( mPair );
00096 
00097   if ( mResolveManually->isChecked() )
00098     mPair->setResolveStrategy( KonnectorPair::ResolveManually );
00099   else if ( mResolveFirst->isChecked() )
00100     mPair->setResolveStrategy( KonnectorPair::ResolveFirst );
00101   else if ( mResolveSecond->isChecked() )
00102     mPair->setResolveStrategy( KonnectorPair::ResolveSecond );
00103   else if ( mResolveBoth->isChecked() )
00104     mPair->setResolveStrategy( KonnectorPair::ResolveBoth );
00105 
00106   return mPair;
00107 }
00108 
00109 void PairEditorWidget::initGUI()
00110 {
00111   QVBoxLayout *layout = new QVBoxLayout( this );
00112 
00113   QTabWidget *tabWidget = new QTabWidget( this );
00114   layout->addWidget( tabWidget );
00115 
00116   tabWidget->addTab( createPluginTab(), i18n( "Plugins" ) );
00117   tabWidget->addTab( createSyncOptionTab(), i18n( "Synchronize Options" ) );
00118 }
00119 
00120 QWidget *PairEditorWidget::createPluginTab()
00121 {
00122   QWidget *widget = new QWidget( this );
00123   QVBoxLayout *layout = new QVBoxLayout( widget, KDialog::marginHint(), KDialog::spacingHint() );
00124 
00125   QLabel *label = new QLabel( "<h2><b>" + i18n( "Synchronization Plugins" ) + "</b></h2>", widget );
00126   layout->addWidget( label );
00127 
00128   QVBoxLayout *pluginLayout = new QVBoxLayout( 0, KDialog::marginHint(), KDialog::spacingHint() );
00129 
00130   PluginEditorWidget *firstPlugin = new PluginEditorWidget( widget );
00131   firstPlugin->setLabel( i18n( "First plugin:" ) );
00132 
00133   PluginEditorWidget *secondPlugin = new PluginEditorWidget( widget );
00134   secondPlugin->setLabel( i18n( "Second plugin:" ) );
00135 
00136   mEditorWidgets.append( firstPlugin );
00137   mEditorWidgets.append( secondPlugin );
00138 
00139   pluginLayout->addWidget( firstPlugin );
00140   pluginLayout->addWidget( secondPlugin );
00141 
00142   QHBoxLayout *displayLayout = new QHBoxLayout( 0, KDialog::marginHint(), KDialog::spacingHint() );
00143   label = new QLabel( i18n( "Display name:" ), widget );
00144   displayLayout->addWidget( label );
00145 
00146   mPairNameEdit = new KLineEdit( widget );
00147   displayLayout->addWidget( mPairNameEdit );
00148 
00149   pluginLayout->addLayout( displayLayout );
00150 
00151   layout->addLayout( pluginLayout );
00152 
00153   layout->addStretch( 10 );
00154 
00155   return widget;
00156 }
00157 
00158 QWidget *PairEditorWidget::createSyncOptionTab()
00159 {
00160   QWidget *widget = new QWidget( this );
00161   QVBoxLayout *layout = new QVBoxLayout( widget, KDialog::marginHint(), KDialog::spacingHint() );
00162 
00163   QLabel *label = new QLabel( "<h2><b>" + i18n( "Conflicts &amp; Near Duplicates" ) + "</b></h2>", widget );
00164   layout->addWidget( label );
00165 
00166   QVBoxLayout *groupLayout = new QVBoxLayout( 0, KDialog::marginHint(), KDialog::spacingHint() );
00167 
00168   QButtonGroup *group = new QButtonGroup( 1, Qt::Horizontal, widget );
00169   group->setRadioButtonExclusive( true );
00170 
00171   mResolveManually = new QRadioButton( i18n( "Resolve it manually" ), group );
00172   mResolveFirst = new QRadioButton( i18n( "Always use the entry from the first plugin" ), group );
00173   mResolveSecond = new QRadioButton( i18n( "Always use the entry from the second plugin" ), group );
00174   mResolveBoth = new QRadioButton( i18n( "Always put both entries on both sides" ), group );
00175 
00176   groupLayout->addWidget( group );
00177 
00178   layout->addLayout( groupLayout );
00179 
00180   layout->addStretch( 10 );
00181 
00182   return widget;
00183 }
00184 
00185 #include "paireditorwidget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys