00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qcheckbox.h>
00024 #include <qgroupbox.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qlineedit.h>
00028
00029 #include <qcombobox.h>
00030
00031 #include <kapplication.h>
00032 #include <klocale.h>
00033
00034 #include "configpart.h"
00035
00036 using namespace KSync;
00037
00038 namespace {
00039 void setCurrent( const QString& str, QComboBox* box ) {
00040 if (str.isEmpty() ) return;
00041 uint b = box->count();
00042 for ( uint i = 0; i < b; i++ ) {
00043 if ( box->text(i) == str ) {
00044 box->setCurrentItem(i );
00045 return;
00046 }
00047 }
00048 box->insertItem( str );
00049 box->setCurrentItem( b );
00050 }
00051 }
00052
00053 ConfigPart::ConfigPart(const Kapabilities &kaps, QWidget *parent, const char *name )
00054 : ConfigWidget( parent, name )
00055 {
00056 init();
00057 initialize( kaps );
00058 m_kap = kaps;
00059 }
00060 ConfigPart::ConfigPart(const Kapabilities& kaps, const Kapabilities &src,
00061 QWidget* parent, const char* name )
00062 : ConfigWidget( parent, name ) {
00063 init();
00064 initialize( kaps );
00065 apply( src );
00066 m_kap = kaps;
00067 }
00068 ConfigPart::~ConfigPart() {
00069 }
00070 void ConfigPart::setCapabilities( const Kapabilities& caps) {
00071 apply( caps );
00072 }
00073 void ConfigPart::initialize(const Kapabilities &kaps ){
00074
00075 m_mainLayout = new QGridLayout( this, 6, 3 );
00076
00077 if ( kaps.supportsMetaSyncing() ) {
00078 m_ckbMetaSyncing = new QCheckBox(i18n( "Enable metasyncing"), this );
00079 m_mainLayout->addWidget(m_ckbMetaSyncing, 0, 0);
00080 m_ckbMetaSyncing->setChecked( kaps.isMetaSyncingEnabled() );
00081 }
00082
00083 QLabel *lbl;
00084 push = false;
00085 if ( kaps.supportsPushSync() ) {
00086 push = true;
00087 lbl = new QLabel(i18n("You can push syncs to this device"), this );
00088 }else
00089 lbl = new QLabel(i18n("You need to start the synchronization from your device"), this );
00090 m_mainLayout->addWidget(lbl, 1, 0 );
00091
00092 if ( kaps.canAutoHandle() )
00093 m_lblAutoHandle = new QLabel( i18n("This konnector establishes a connection to the device"), this );
00094 else
00095 m_lblAutoHandle = new QLabel( i18n("To function properly you need to establish a connection"), this );
00096 m_mainLayout->addWidget( m_lblAutoHandle, 2, 0 );
00097
00098
00099
00100 m_grpConnection = new QGroupBox( i18n("Connection"), this );
00101 m_conLayout = new QGridLayout(m_grpConnection, 4, 5);
00102
00103 if ( !kaps.needsNetworkConnection() || kaps.canAutoHandle() ) {
00104
00105 m_grpConnection->setEnabled( false );
00106 }else{
00107 m_grpConnection->setEnabled( true );
00108 }
00109
00110 m_conLayout->setMargin( 12 );
00111 QSpacerItem *iti1b = new QSpacerItem(2, 10, QSizePolicy::Fixed,
00112 QSizePolicy::Fixed );
00113 m_conLayout->addItem( iti1b, 0, 0);
00114
00115
00116 m_lblSrcIp = new QLabel(i18n("Source address: "), m_grpConnection);
00117 m_conSrcIp = new QComboBox(m_grpConnection);
00118 m_conSrcIp->setEditable( TRUE );
00119 m_lblSrcIp->setBuddy( m_conSrcIp );
00120 m_conLayout->addWidget(m_lblSrcIp, 1, 0 );
00121 m_conLayout->addWidget(m_conSrcIp, 1, 1 );
00122 if (!kaps.needsIPs() || !kaps.needsSrcIP() ) {
00123 m_lblSrcIp->setEnabled( false );
00124 m_conSrcIp->setEnabled( false );
00125 }else{
00126 m_conSrcIp->insertItem( kaps.srcIP() );
00127 }
00128
00129
00130 m_lblDestIp = new QLabel(i18n("Destination address: "), m_grpConnection );
00131 m_conDestIp = new QComboBox(m_grpConnection);
00132 m_conDestIp->setEditable( TRUE );
00133 m_lblDestIp->setBuddy( m_conDestIp );
00134 m_conLayout->addWidget( m_lblDestIp, 1, 3 );
00135 m_conLayout->addWidget( m_conDestIp, 1, 4 );
00136 if (!kaps.needsIPs() || !kaps.needsDestIP() ) {
00137 m_lblDestIp->setEnabled( false );
00138 m_conDestIp->setEnabled( false );
00139 }else{
00140 QStringList ips = kaps.ipProposals();
00141 QStringList::ConstIterator it;
00142 for ( it = ips.begin(); it != ips.end(); ++it ) {
00143 m_conDestIp->insertItem( (*it) );
00144 }
00145
00146 }
00147
00148 m_lblUser = new QLabel(i18n("User:"), m_grpConnection );
00149 m_conUser = new QComboBox(m_grpConnection );
00150 m_conUser->setEditable( TRUE );
00151 m_lblUser->setBuddy( m_conUser );
00152 m_conLayout->addWidget( m_lblUser, 2, 0 );
00153 m_conLayout->addWidget( m_conUser, 2, 1 );
00154
00155
00156 m_lblPass = new QLabel(i18n("Password:"), m_grpConnection );
00157 m_conPass = new QComboBox( m_grpConnection );
00158 m_conPass->setEditable( TRUE );
00159 m_lblPass->setBuddy( m_conPass );
00160 m_conLayout->addWidget( m_lblPass, 2, 3 );
00161 m_conLayout->addWidget( m_conPass, 2, 4 );
00162
00163 if ( kaps.needAuthentication() ) {
00164 QValueList<QPair<QString, QString> > list = kaps.userProposals();
00165 QValueList<QPair<QString, QString> >::ConstIterator it;
00166 for (it = list.begin(); it != list.end(); ++it ) {
00167 m_conUser->insertItem( (*it).first );
00168 m_conPass->insertItem( (*it).second);
00169 }
00170 m_conUser->insertItem(kaps.user(), 0);
00171 m_conPass->insertItem(kaps.password(), 0 );
00172 }else{
00173 m_lblPass->setEnabled( false );
00174 m_conPass->setEnabled( false );
00175 m_lblUser->setEnabled( false );
00176 m_conUser->setEnabled( false );
00177 }
00178
00179 m_lblPort = new QLabel( i18n("Port:"), m_grpConnection);
00180 m_conPort = new QComboBox( m_grpConnection );
00181 m_conPort->setEditable(TRUE);
00182 m_lblPort->setBuddy( m_conPort );
00183 m_conLayout->addWidget( m_lblPort, 3, 0 );
00184 m_conLayout->addWidget( m_conPort, 3, 1 );
00185 QMemArray<int> ints = kaps.ports();
00186 if ( ints.isEmpty() ) {
00187 m_lblPort->setEnabled( false );
00188 m_conPort->setEnabled( false );
00189 }else{
00190 for (uint i = 0; i < ints.size(); i++ ) {
00191 m_conPort->insertItem( QString::number( ints[i] ) );
00192 }
00193
00194 }
00195
00196
00197 m_mainLayout->addWidget( m_grpConnection, 3, 0 );
00198
00199
00200 m_grpModel = new QGroupBox( i18n("Model"), this );
00201 m_grpLayout = new QGridLayout( m_grpModel, 6, 2 );
00202
00203 m_grpLayout->setMargin( 12 );
00204 QSpacerItem *iti1c = new QSpacerItem(2, 10, QSizePolicy::Fixed,
00205 QSizePolicy::Fixed );
00206 m_grpLayout->addItem( iti1c, 0, 0);
00207
00208 m_lblDevice = new QLabel( i18n("Device: "), m_grpModel );
00209 m_cmbDevice = new QComboBox( m_grpModel );
00210 m_cmbDevice->setEditable( false );
00211 m_lblDevice->setBuddy( m_cmbDevice );
00212 m_grpLayout->addWidget( m_lblDevice, 1, 0 );
00213 m_grpLayout->addWidget( m_cmbDevice, 1, 1 );
00214 QStringList devices = kaps.models();
00215 if ( devices.isEmpty() ) {
00216 m_lblDevice->setEnabled( false );
00217 m_cmbDevice->setEnabled( false );
00218 }else{
00219 for ( QStringList::ConstIterator it = devices.begin(); it != devices.end(); ++it ) {
00220 m_cmbDevice->insertItem( (*it) );
00221 }
00222
00223 }
00224
00225 m_lblName = new QLabel( i18n("Name:"), m_grpModel );
00226 m_lneName = new QLineEdit(m_grpModel );
00227 m_lblName->setBuddy( m_lneName );
00228 m_lblName->setEnabled( kaps.needsModelName() );
00229 m_lneName->setEnabled( kaps.needsModelName() );
00230 m_grpLayout->addWidget( m_lblName, 2, 0 );
00231 m_grpLayout->addWidget( m_lneName, 2, 1 );
00232
00233
00234
00235 m_lblConnection = new QLabel( i18n("Connection:"), m_grpModel );
00236 m_cmbConnection = new QComboBox( m_grpModel );
00237 m_cmbConnection->setEditable( TRUE );
00238 m_lblConnection->setBuddy( m_cmbConnection );
00239 m_grpLayout->addWidget( m_lblConnection, 3, 0 );
00240 m_grpLayout->addWidget( m_cmbConnection, 3, 1 );
00241 QStringList conList = kaps.connectionModes();
00242 if ( conList.isEmpty() ) {
00243 m_lblConnection->setEnabled( false );
00244 m_cmbConnection->setEnabled( false );
00245 }else{
00246 for ( QStringList::ConstIterator it = conList.begin(); it != conList.end(); ++it ) {
00247 m_cmbConnection->insertItem( (*it) );
00248 }
00249
00250
00251 }
00252
00253 m_grpUser = new QLabel( i18n("User:"), m_grpModel );
00254 m_cmbUser = new QComboBox( m_grpModel );
00255 m_cmbUser->setEditable( TRUE );
00256 m_grpUser->setBuddy( m_cmbUser );
00257 m_grpLayout->addWidget(m_grpUser, 4, 0);
00258 m_grpLayout->addWidget(m_cmbUser, 4, 1);
00259 m_grpUser->setEnabled( false );
00260 m_cmbUser->setEnabled( false );
00261
00262
00263 m_grpPass = new QLabel( i18n("Pass:"), m_grpModel );
00264 m_cmbPass = new QComboBox( m_grpModel );
00265 m_grpPass->setBuddy( m_cmbPass );
00266 m_cmbPass->setEditable( TRUE );
00267 m_grpLayout->addWidget( m_grpPass, 5, 0 );
00268 m_grpLayout->addWidget( m_cmbPass, 5, 1 );
00269 m_grpPass->setEnabled( false );
00270 m_cmbPass->setEnabled( false );
00271
00272 m_mainLayout->addWidget( m_grpModel, 4, 0 );
00273
00274 QMap<QString, QString> specs = kaps.extras();
00275 if ( !specs.isEmpty() ) {
00276 m_grpDevice = new QGroupBox( i18n("Device Specific"), this );
00277 m_devLay = new QGridLayout(m_grpDevice, specs.count()+1, 2);
00278 QSpacerItem *iti1d = new QSpacerItem(4, 14, QSizePolicy::Fixed,
00279 QSizePolicy::Fixed );
00280 m_devLay->setMargin( 12 );
00281 m_devLay->addItem( iti1d, 0, 0 );
00282 int i = 0;
00283 QLabel *lbl;
00284 QLineEdit *edit;
00285 m_devGroup.clear();
00286 for ( QMap<QString, QString>::ConstIterator it = specs.begin(); it != specs.end(); ++it ) {
00287 lbl = new QLabel(it.key() , m_grpDevice );
00288 edit = new QLineEdit(m_grpDevice, it.key().latin1() );
00289 edit->setText( it.data() );
00290 lbl->setBuddy(edit);
00291 m_devGroup.insert(it.key(), edit);
00292
00293 m_devLay->addWidget( lbl, i, 0 );
00294 m_devLay->addWidget( edit, i, 1 );
00295 ++i;
00296 }
00297 m_mainLayout->addWidget( m_grpDevice, 5, 0 );
00298 }
00299 }
00300 Kapabilities ConfigPart::capabilities()const
00301 {
00302 Kapabilities kaps = m_kap;
00303
00304 if ( !m_devGroup.isEmpty() ) {
00305 for ( QMap<QString, QLineEdit*>::ConstIterator it = m_devGroup.begin(); it != m_devGroup.end(); ++it ) {
00306 kaps.setExtraOption( it.key(), it.data()->text() );
00307 }
00308 }
00309
00310 if ( m_ckbMetaSyncing != 0 ) {
00311 kaps.setMetaSyncingEnabled( m_ckbMetaSyncing->isChecked() );
00312 }
00313
00314 if ( m_grpConnection != 0 && m_grpConnection->isEnabled() ) {
00315 if ( m_conSrcIp->isEnabled() )
00316 kaps.setSrcIP( m_conSrcIp->currentText() );
00317 if ( m_conDestIp->isEnabled( ) )
00318 kaps.setDestIP(m_conDestIp->currentText() );
00319 if ( m_conUser->isEnabled() )
00320 kaps.setUser( m_conUser->currentText() );
00321 if ( m_conPass->isEnabled() )
00322 kaps.setPassword( m_conPass->currentText() );
00323 if ( m_conPort->isEnabled() )
00324 kaps.setCurrentPort( m_conPort->currentText().toInt() );
00325 }
00326 if ( m_cmbPass != 0 && m_cmbPass->isEnabled() )
00327 ;
00328 if ( m_cmbUser != 0 && m_cmbUser->isEnabled() )
00329 ;
00330 if ( m_cmbDevice != 0 && m_cmbDevice->isEnabled() )
00331 kaps.setCurrentModel(m_cmbDevice->currentText() );
00332 if ( m_cmbConnection != 0 && m_cmbConnection->isEnabled() )
00333 kaps.setCurrentConnectionMode( m_cmbConnection->currentText() );
00334
00335
00336 if ( m_lneName->isEnabled() ) {
00337 QString str = m_lneName->text().isEmpty() ? kapp->randomString(10): m_lneName->text();
00338 kaps.setModelName( str );
00339 }
00340
00341 return kaps;
00342 }
00343
00344 void ConfigPart::init()
00345 {
00346 m_ckbMetaSyncing = 0;
00347 m_mainLayout = 0;
00348 m_lblAutoHandle = 0;
00349 m_grpConnection = 0;
00350 m_conLayout = 0;
00351
00352 m_conSrcIp = 0;
00353 m_conDestIp = 0;
00354 m_conUser = 0;
00355 m_conPass = 0;
00356 m_conPort = 0;
00357
00358 m_lblSrcIp = 0;
00359 m_lblDestIp = 0;
00360 m_lblUser = 0;
00361 m_lblPass = 0;
00362 m_lblPort = 0;
00363
00364 m_grpModel = 0;
00365 m_grpLayout = 0;
00366 m_lblDevice = 0;
00367 m_lblConnection = 0;
00368 m_cmbDevice = 0;
00369 m_cmbConnection = 0;
00370
00371 m_grpDevice = 0;
00372 m_devLay = 0;
00373 m_grpFetch = 0;
00374 m_fetchAdd = 0;
00375
00376 m_fetchBrowse = 0;
00377 m_fetchRem = 0;
00378 m_view = 0;
00379
00380 m_lneName =0;
00381 m_lblName =0;
00382 }
00383
00384
00385
00386 void ConfigPart::apply( const Kapabilities& caps ) {
00387 if (m_kap.needsIPs() || m_kap.needsSrcIP() ) {
00388 setCurrent( caps.srcIP(), m_conSrcIp );
00389 }
00390 if (m_kap.needsIPs() || m_kap.needsDestIP() ) {
00391 setCurrent( caps.destIP(), m_conDestIp );
00392 }
00393 if (m_kap.needAuthentication() ) {
00394 setCurrent( caps.user(), m_conUser );
00395 setCurrent( caps.password(), m_conPass );
00396 }
00397 if ( !m_kap.models().isEmpty() ) {
00398 setCurrent( caps.currentModel(), m_cmbDevice );
00399 }
00400 if ( m_kap.needsModelName() ) {
00401 m_lneName->setText( caps.modelName() );
00402 }
00403 if ( !m_kap.connectionModes().isEmpty() ) {
00404 setCurrent( caps.currentConnectionMode(), m_cmbConnection );
00405 }
00406 QMap<QString, QString> specs = caps.extras();
00407 for ( QMap<QString, QString>::ConstIterator it = specs.begin(); it != specs.end(); ++it ) {
00408 if (!m_devGroup.contains( it.key() ) ) continue;
00409 QLineEdit* edit = m_devGroup[it.key()];
00410 if (edit)
00411 edit->setText( it.data() );
00412 }
00413 if (!m_kap.ports().isEmpty() ) {
00414 setCurrent( QString::number( caps.currentPort() ), m_conPort );
00415 }
00416 }