kitchensync

configguisyncmlobex.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2006 Daniel Gollub <dgollub@suse.de>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program 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
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00020     USA.
00021 */
00022 
00023 #include "configguisyncmlobex.h"
00024 
00025 #include <kcombobox.h>
00026 #include <kdialog.h>
00027 #include <klineedit.h>
00028 #include <klocale.h>
00029 #include <kurlrequester.h>
00030 
00031 #include <qlayout.h>
00032 #include <qcheckbox.h>
00033 #include <qcombobox.h>
00034 #include <qlabel.h>
00035 #include <qdom.h>
00036 #include <qspinbox.h>
00037 #include <qtabwidget.h>
00038 #include <qvbox.h>
00039 
00040 ConfigGuiSyncmlObex::ConfigGuiSyncmlObex( const QSync::Member &member, QWidget *parent )
00041   : ConfigGui( member, parent )
00042 {
00043   QTabWidget *tabWidget = new QTabWidget( this );
00044   topLayout()->addWidget( tabWidget );
00045 
00046   // Connection
00047   QVBox *connectionWidget = new QVBox( this );
00048   connectionWidget->setMargin( KDialog::marginHint() );
00049   connectionWidget->setSpacing( 5 );
00050 
00051   tabWidget->addTab( connectionWidget, i18n( "Connection" ) );
00052 
00053   mConnection = new KComboBox( connectionWidget );
00054 
00055   connect( mConnection, SIGNAL (activated( int ) ),
00056            this, SLOT( slotConnectionChanged ( int ) ) );
00057 
00058   mConnectionTypes.append( ConnectionType( 2, i18n( "Bluetooth" ) ) );
00059   mConnectionTypes.append( ConnectionType( 5, i18n( "USB" ) ) );
00060 
00061   ConnectionTypeList::ConstIterator it;
00062   for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ )
00063     mConnection->insertItem( (*it).second );
00064 
00065   mBluetooth = new BluetoothWidget( connectionWidget );
00066   mBluetooth->hide();
00067 
00068   mUsb = new UsbWidget( connectionWidget );
00069   mUsb->hide();
00070 
00071   connectionWidget->setStretchFactor( mBluetooth, 1 );
00072   connectionWidget->setStretchFactor( mUsb, 1 );
00073 
00074   // Databases
00075   QWidget *databaseWidget = new QWidget( tabWidget );
00076   QVBoxLayout *databaseLayout = new QVBoxLayout( databaseWidget,
00077                                                  KDialog::marginHint(), KDialog::spacingHint() );
00078 
00079   tabWidget->addTab( databaseWidget, i18n( "Databases" ) );
00080 
00081   mGridLayout = new QGridLayout( databaseLayout );
00082   addLineEdit( databaseWidget, i18n("Contact Database:"), &mContactDb, 0 );
00083   addLineEdit( databaseWidget, i18n("Calendar Database:"), &mCalendarDb, 1 );
00084   addLineEdit( databaseWidget, i18n("Note Database:"), &mNoteDb, 2 );
00085 
00086   mContactDb->insertItem( "addressbook" );
00087   mContactDb->insertItem( "contacts" );
00088 
00089   mCalendarDb->insertItem( "agenda" );
00090   mCalendarDb->insertItem( "calendar" );
00091 
00092   mNoteDb->insertItem( "notes" );
00093 
00094   // Options
00095   QWidget *optionsWidget = new QWidget( tabWidget );
00096   QVBoxLayout *optionsLayout = new QVBoxLayout( optionsWidget,
00097                                                 KDialog::marginHint(), KDialog::spacingHint() );
00098 
00099   tabWidget->addTab( optionsWidget, i18n( "Options" ) );
00100 
00101   mGridLayout = new QGridLayout( optionsLayout );
00102 
00103   QLabel *label = new QLabel( i18n("User name:"), optionsWidget );
00104   mGridLayout->addWidget( label, 0, 0 );
00105 
00106   mUsername = new KLineEdit( optionsWidget );
00107   mGridLayout->addWidget( mUsername, 0, 1 );
00108 
00109   label = new QLabel( i18n("Password:"), optionsWidget );
00110   mGridLayout->addWidget( label, 1, 0 );
00111 
00112   mPassword = new KLineEdit( optionsWidget );
00113   mPassword->setEchoMode( QLineEdit::Password );
00114   mGridLayout->addWidget( mPassword, 1, 1 );
00115 
00116   mUseStringTable = new QCheckBox( i18n("Use String Table"), optionsWidget );
00117   mGridLayout->addMultiCellWidget( mUseStringTable, 2, 2, 0, 1 );
00118 
00119   mOnlyReplace = new QCheckBox( i18n("Only Replace Entries"), optionsWidget );
00120   mGridLayout->addMultiCellWidget( mOnlyReplace, 3, 3, 0, 1 );
00121 
00122   // SynML Version
00123   label = new QLabel( i18n("SyncML Version:"), optionsWidget );
00124   mGridLayout->addWidget( label, 4, 0 );
00125 
00126   mSyncmlVersion = new QComboBox( optionsWidget );
00127   mGridLayout->addWidget( mSyncmlVersion, 4, 1 );
00128 
00129   mSyncmlVersions.append( SyncmlVersion( 0,  i18n( "1.0" ) ) );
00130   mSyncmlVersions.append( SyncmlVersion( 1,  i18n( "1.1" ) ) );
00131   mSyncmlVersions.append( SyncmlVersion( 2,  i18n( "1.2" ) ) );
00132 
00133   SyncmlVersionList::ConstIterator itVersion;
00134   for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ )
00135     mSyncmlVersion->insertItem( (*itVersion).second );
00136 
00137   // WBXML
00138   mWbxml = new QCheckBox( i18n("WAP Binary XML"), optionsWidget );
00139   mGridLayout->addMultiCellWidget( mWbxml, 12, 12, 0, 1 );
00140 
00141   // Identifier
00142   label = new QLabel( i18n("Software Identifier:"), optionsWidget );
00143   mGridLayout->addWidget( label, 13, 0 );
00144 
00145   mIdentifier = new KComboBox( true, optionsWidget );
00146   mGridLayout->addWidget( mIdentifier, 13, 1 );
00147 
00148   mIdentifier->insertItem( "" );
00149   mIdentifier->insertItem( "PC Suite" );
00150 
00151   // recvLimit
00152   label = new QLabel( i18n("Receive Limit:"), optionsWidget );
00153   mGridLayout->addWidget( label, 14, 0 );
00154 
00155   mRecvLimit = new QSpinBox( optionsWidget );
00156   mRecvLimit->setMinValue( 1 );
00157   mRecvLimit->setMaxValue( 65536 );
00158   mGridLayout->addWidget( mRecvLimit, 14, 1 );
00159 
00160   // maxObjSize
00161   label = new QLabel( i18n("Maximum Object Size"), optionsWidget );
00162   mGridLayout->addWidget( label, 15, 0 );
00163 
00164   mMaxObjSize = new QSpinBox( optionsWidget );
00165   mMaxObjSize->setMinValue( 1 );
00166   mMaxObjSize->setMaxValue( 65536 );
00167   mGridLayout->addWidget( mMaxObjSize, 15, 1 );
00168 
00169   topLayout()->addStretch( 1 );
00170 }
00171 
00172 void ConfigGuiSyncmlObex::slotConnectionChanged( int pos )
00173 {
00174   mUsb->hide();
00175   mBluetooth->hide();
00176 
00177   if ( pos == 0 )
00178     mBluetooth->show();
00179   else if ( pos == 1 )
00180     mUsb->show();
00181 }
00182 
00183 void ConfigGuiSyncmlObex::load( const QString &xml )
00184 {
00185   QDomDocument document;
00186   document.setContent( xml );
00187 
00188   QDomElement docElement = document.documentElement();
00189 
00190   QDomNode node;
00191   for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
00192     QDomElement element = node.toElement();
00193     if ( element.tagName() == "username" ) {
00194       mUsername->setText( element.text() );
00195     } else if ( element.tagName() == "password" ) {
00196       mPassword->setText( element.text() );
00197     } else if ( element.tagName() == "type" ) {
00198       for ( uint i = 0; i < mConnectionTypes.count(); i++ ) {
00199         if ( mConnectionTypes[i].first == element.text().toInt() ) {
00200           mConnection->setCurrentItem( i );
00201           slotConnectionChanged( i );
00202           break;
00203         }
00204       }
00205     } else if ( element.tagName() == "version" ) {
00206       for ( uint i = 0; i < mSyncmlVersions.count(); i++ ) {
00207         if ( mSyncmlVersions[i].first == element.text().toInt() ) {
00208           mSyncmlVersion->setCurrentItem( i );
00209           break;
00210         }
00211       }
00212     } else if ( element.tagName() == "bluetooth_address" ) {
00213       if ( mBluetooth ) mBluetooth->setAddress( element.text() );
00214     } else if ( element.tagName() == "bluetooth_channel" ) {
00215       if ( mBluetooth ) mBluetooth->setChannel( element.text() );
00216     } else if ( element.tagName() == "identifier" ) {
00217       if ( mIdentifier ) mIdentifier->setCurrentText( element.text() );
00218     } else if ( element.tagName() == "interface" ) {
00219       if ( mUsb ) mUsb->setInterface( element.text().toInt() );
00220     } else if ( element.tagName() == "wbxml" ) {
00221       if ( mWbxml) mWbxml->setChecked( element.text() == "1" );
00222     } else if ( element.tagName() == "recvLimit" ) {
00223       if ( mRecvLimit ) mRecvLimit->setValue( element.text().toInt() );
00224     } else if ( element.tagName() == "maxObjSize" ) {
00225       if ( mMaxObjSize ) mMaxObjSize->setValue( element.text().toInt() );
00226     } else if ( element.tagName() == "usestringtable" ) {
00227       mUseStringTable->setChecked( element.text() == "1" );
00228     } else if ( element.tagName() == "onlyreplace" ) {
00229       mOnlyReplace->setChecked( element.text() == "1" );
00230     } else if ( element.tagName() == "contact_db" ) {
00231       mContactDb->setCurrentText( element.text() );
00232     } else if ( element.tagName() == "calendar_db" ) {
00233       mCalendarDb->setCurrentText( element.text() );
00234     } else if ( element.tagName() == "note_db" ) {
00235       mNoteDb->setCurrentText( element.text() );
00236     }
00237   }
00238 }
00239 
00240 QString ConfigGuiSyncmlObex::save()
00241 {
00242   QString xml;
00243   xml = "<config>\n";
00244   xml += "<username>" + mUsername->text() + "</username>\n";
00245   xml += "<password>" + mPassword->text() + "</password>\n";
00246   ConnectionTypeList::ConstIterator it;
00247   for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) {
00248     if ( mConnection->currentText() == (*it).second ) {
00249       xml += "<type>" + QString("%1").arg((*it).first) + "</type>\n";
00250       break;
00251     }
00252   }
00253 
00254   // Bluetooth Address
00255   xml += "<bluetooth_address>" + mBluetooth->address() + "</bluetooth_address>\n";
00256 
00257   // Bluetooth Channel
00258   xml += "<bluetooth_channel>" + mBluetooth->channel() + "</bluetooth_channel>\n";
00259 
00260   // USB Interface
00261   xml += "<interface>" + QString::number( mUsb->interface() ) +"</interface>\n";
00262 
00263   // SyncML Version
00264   SyncmlVersionList::ConstIterator itVersion;
00265   for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ ) {
00266     if ( mSyncmlVersion->currentText() == (*itVersion).second ) {
00267       xml += "<version>" + QString("%1").arg((*itVersion).first) + "</version>\n";
00268       break;
00269     }
00270   }
00271 
00272   // (Software) Identifier
00273   xml += "<identifier>" + mIdentifier->currentText() + "</identifier>\n";
00274 
00275   // WBXML
00276   xml += "<wbxml>";
00277   if ( mWbxml->isChecked() )
00278     xml += "1";
00279   else
00280     xml += "0";
00281   xml += "</wbxml>\n";
00282 
00283   // Receive Limit
00284   xml += "<recvLimit>" + QString::number( mRecvLimit->value() ) + "</recvLimit>\n";
00285 
00286   // Maximal Object Size
00287   xml += "<maxObjSize>" + QString::number( mMaxObjSize->value() ) + "</maxObjSize>\n";
00288 
00289   xml += "<usestringtable>";
00290   if ( mUseStringTable->isChecked() )
00291     xml += "1";
00292   else
00293     xml += "0";
00294   xml += "</usestringtable>\n";
00295 
00296   xml += "<onlyreplace>";
00297   if ( mOnlyReplace->isChecked() )
00298     xml += "1";
00299   else
00300     xml += "0";
00301   xml += "</onlyreplace>\n";
00302 
00303   xml += "<contact_db>" + mContactDb->currentText() + "</contact_db>\n";
00304   xml += "<calendar_db>" + mCalendarDb->currentText() + "</calendar_db>\n";
00305   xml += "<note_db>" + mNoteDb->currentText() + "</note_db>\n";
00306   xml += "</config>";
00307 
00308   return xml;
00309 }
00310 
00311 void ConfigGuiSyncmlObex::addLineEdit( QWidget *parent, const QString &text, KComboBox **edit, int row )
00312 {
00313   QLabel *label = new QLabel( text, parent );
00314   mGridLayout->addWidget( label, row, 0 );
00315 
00316   *edit = new KComboBox( true, parent );
00317   mGridLayout->addWidget( *edit, row, 1 );
00318 }
00319 
00320 #include "configguisyncmlobex.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys