From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kitchensync/src/configguisyncmlobex.cpp | 320 ++++++++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 kitchensync/src/configguisyncmlobex.cpp (limited to 'kitchensync/src/configguisyncmlobex.cpp') diff --git a/kitchensync/src/configguisyncmlobex.cpp b/kitchensync/src/configguisyncmlobex.cpp new file mode 100644 index 000000000..488a0d944 --- /dev/null +++ b/kitchensync/src/configguisyncmlobex.cpp @@ -0,0 +1,320 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher + Copyright (c) 2006 Daniel Gollub + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguisyncmlobex.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +ConfigGuiSyncmlObex::ConfigGuiSyncmlObex( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QTabWidget *tabWidget = new QTabWidget( this ); + topLayout()->addWidget( tabWidget ); + + // Connection + QVBox *connectionWidget = new QVBox( this ); + connectionWidget->setMargin( KDialog::marginHint() ); + connectionWidget->setSpacing( 5 ); + + tabWidget->addTab( connectionWidget, i18n( "Connection" ) ); + + mConnection = new KComboBox( connectionWidget ); + + connect( mConnection, SIGNAL (activated( int ) ), + this, SLOT( slotConnectionChanged ( int ) ) ); + + mConnectionTypes.append( ConnectionType( 2, i18n( "Bluetooth" ) ) ); + mConnectionTypes.append( ConnectionType( 5, i18n( "USB" ) ) ); + + ConnectionTypeList::ConstIterator it; + for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) + mConnection->insertItem( (*it).second ); + + mBluetooth = new BluetoothWidget( connectionWidget ); + mBluetooth->hide(); + + mUsb = new UsbWidget( connectionWidget ); + mUsb->hide(); + + connectionWidget->setStretchFactor( mBluetooth, 1 ); + connectionWidget->setStretchFactor( mUsb, 1 ); + + // Databases + QWidget *databaseWidget = new QWidget( tabWidget ); + QVBoxLayout *databaseLayout = new QVBoxLayout( databaseWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + tabWidget->addTab( databaseWidget, i18n( "Databases" ) ); + + mGridLayout = new QGridLayout( databaseLayout ); + addLineEdit( databaseWidget, i18n("Contact Database:"), &mContactDb, 0 ); + addLineEdit( databaseWidget, i18n("Calendar Database:"), &mCalendarDb, 1 ); + addLineEdit( databaseWidget, i18n("Note Database:"), &mNoteDb, 2 ); + + mContactDb->insertItem( "addressbook" ); + mContactDb->insertItem( "contacts" ); + + mCalendarDb->insertItem( "agenda" ); + mCalendarDb->insertItem( "calendar" ); + + mNoteDb->insertItem( "notes" ); + + // Options + QWidget *optionsWidget = new QWidget( tabWidget ); + QVBoxLayout *optionsLayout = new QVBoxLayout( optionsWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + tabWidget->addTab( optionsWidget, i18n( "Options" ) ); + + mGridLayout = new QGridLayout( optionsLayout ); + + QLabel *label = new QLabel( i18n("User name:"), optionsWidget ); + mGridLayout->addWidget( label, 0, 0 ); + + mUsername = new KLineEdit( optionsWidget ); + mGridLayout->addWidget( mUsername, 0, 1 ); + + label = new QLabel( i18n("Password:"), optionsWidget ); + mGridLayout->addWidget( label, 1, 0 ); + + mPassword = new KLineEdit( optionsWidget ); + mPassword->setEchoMode( QLineEdit::Password ); + mGridLayout->addWidget( mPassword, 1, 1 ); + + mUseStringTable = new QCheckBox( i18n("Use String Table"), optionsWidget ); + mGridLayout->addMultiCellWidget( mUseStringTable, 2, 2, 0, 1 ); + + mOnlyReplace = new QCheckBox( i18n("Only Replace Entries"), optionsWidget ); + mGridLayout->addMultiCellWidget( mOnlyReplace, 3, 3, 0, 1 ); + + // SynML Version + label = new QLabel( i18n("SyncML Version:"), optionsWidget ); + mGridLayout->addWidget( label, 4, 0 ); + + mSyncmlVersion = new QComboBox( optionsWidget ); + mGridLayout->addWidget( mSyncmlVersion, 4, 1 ); + + mSyncmlVersions.append( SyncmlVersion( 0, i18n( "1.0" ) ) ); + mSyncmlVersions.append( SyncmlVersion( 1, i18n( "1.1" ) ) ); + mSyncmlVersions.append( SyncmlVersion( 2, i18n( "1.2" ) ) ); + + SyncmlVersionList::ConstIterator itVersion; + for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ ) + mSyncmlVersion->insertItem( (*itVersion).second ); + + // WBXML + mWbxml = new QCheckBox( i18n("WAP Binary XML"), optionsWidget ); + mGridLayout->addMultiCellWidget( mWbxml, 12, 12, 0, 1 ); + + // Identifier + label = new QLabel( i18n("Software Identifier:"), optionsWidget ); + mGridLayout->addWidget( label, 13, 0 ); + + mIdentifier = new KComboBox( true, optionsWidget ); + mGridLayout->addWidget( mIdentifier, 13, 1 ); + + mIdentifier->insertItem( "" ); + mIdentifier->insertItem( "PC Suite" ); + + // recvLimit + label = new QLabel( i18n("Receive Limit:"), optionsWidget ); + mGridLayout->addWidget( label, 14, 0 ); + + mRecvLimit = new QSpinBox( optionsWidget ); + mRecvLimit->setMinValue( 1 ); + mRecvLimit->setMaxValue( 65536 ); + mGridLayout->addWidget( mRecvLimit, 14, 1 ); + + // maxObjSize + label = new QLabel( i18n("Maximum Object Size"), optionsWidget ); + mGridLayout->addWidget( label, 15, 0 ); + + mMaxObjSize = new QSpinBox( optionsWidget ); + mMaxObjSize->setMinValue( 1 ); + mMaxObjSize->setMaxValue( 65536 ); + mGridLayout->addWidget( mMaxObjSize, 15, 1 ); + + topLayout()->addStretch( 1 ); +} + +void ConfigGuiSyncmlObex::slotConnectionChanged( int pos ) +{ + mUsb->hide(); + mBluetooth->hide(); + + if ( pos == 0 ) + mBluetooth->show(); + else if ( pos == 1 ) + mUsb->show(); +} + +void ConfigGuiSyncmlObex::load( const QString &xml ) +{ + QDomDocument document; + document.setContent( xml ); + + QDomElement docElement = document.documentElement(); + + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "username" ) { + mUsername->setText( element.text() ); + } else if ( element.tagName() == "password" ) { + mPassword->setText( element.text() ); + } else if ( element.tagName() == "type" ) { + for ( uint i = 0; i < mConnectionTypes.count(); i++ ) { + if ( mConnectionTypes[i].first == element.text().toInt() ) { + mConnection->setCurrentItem( i ); + slotConnectionChanged( i ); + break; + } + } + } else if ( element.tagName() == "version" ) { + for ( uint i = 0; i < mSyncmlVersions.count(); i++ ) { + if ( mSyncmlVersions[i].first == element.text().toInt() ) { + mSyncmlVersion->setCurrentItem( i ); + break; + } + } + } else if ( element.tagName() == "bluetooth_address" ) { + if ( mBluetooth ) mBluetooth->setAddress( element.text() ); + } else if ( element.tagName() == "bluetooth_channel" ) { + if ( mBluetooth ) mBluetooth->setChannel( element.text() ); + } else if ( element.tagName() == "identifier" ) { + if ( mIdentifier ) mIdentifier->setCurrentText( element.text() ); + } else if ( element.tagName() == "interface" ) { + if ( mUsb ) mUsb->setInterface( element.text().toInt() ); + } else if ( element.tagName() == "wbxml" ) { + if ( mWbxml) mWbxml->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "recvLimit" ) { + if ( mRecvLimit ) mRecvLimit->setValue( element.text().toInt() ); + } else if ( element.tagName() == "maxObjSize" ) { + if ( mMaxObjSize ) mMaxObjSize->setValue( element.text().toInt() ); + } else if ( element.tagName() == "usestringtable" ) { + mUseStringTable->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "onlyreplace" ) { + mOnlyReplace->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "contact_db" ) { + mContactDb->setCurrentText( element.text() ); + } else if ( element.tagName() == "calendar_db" ) { + mCalendarDb->setCurrentText( element.text() ); + } else if ( element.tagName() == "note_db" ) { + mNoteDb->setCurrentText( element.text() ); + } + } +} + +QString ConfigGuiSyncmlObex::save() const +{ + QString xml; + xml = "\n"; + xml += "" + mUsername->text() + "\n"; + xml += "" + mPassword->text() + "\n"; + ConnectionTypeList::ConstIterator it; + for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) { + if ( mConnection->currentText() == (*it).second ) { + xml += "" + QString("%1").arg((*it).first) + "\n"; + break; + } + } + + // Bluetooth Address + xml += "" + mBluetooth->address() + "\n"; + + // Bluetooth Channel + xml += "" + mBluetooth->channel() + "\n"; + + // USB Interface + xml += "" + QString::number( mUsb->interface() ) +"\n"; + + // SyncML Version + SyncmlVersionList::ConstIterator itVersion; + for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ ) { + if ( mSyncmlVersion->currentText() == (*itVersion).second ) { + xml += "" + QString("%1").arg((*itVersion).first) + "\n"; + break; + } + } + + // (Software) Identifier + xml += "" + mIdentifier->currentText() + "\n"; + + // WBXML + xml += ""; + if ( mWbxml->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "\n"; + + // Receive Limit + xml += "" + QString::number( mRecvLimit->value() ) + "\n"; + + // Maximal Object Size + xml += "" + QString::number( mMaxObjSize->value() ) + "\n"; + + xml += ""; + if ( mUseStringTable->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "\n"; + + xml += ""; + if ( mOnlyReplace->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "\n"; + + xml += "" + mContactDb->currentText() + "\n"; + xml += "" + mCalendarDb->currentText() + "\n"; + xml += "" + mNoteDb->currentText() + "\n"; + xml += ""; + + return xml; +} + +void ConfigGuiSyncmlObex::addLineEdit( QWidget *parent, const QString &text, KComboBox **edit, int row ) +{ + QLabel *label = new QLabel( text, parent ); + mGridLayout->addWidget( label, row, 0 ); + + *edit = new KComboBox( true, parent ); + mGridLayout->addWidget( *edit, row, 1 ); +} + +#include "configguisyncmlobex.moc" -- cgit v1.2.1