kitchensync

configguisyncmlobex.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (c) 2006 Daniel Gollub <dgollub@suse.de>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20  USA.
21 */
22 
23 #include "configguisyncmlobex.h"
24 
25 #include <kcombobox.h>
26 #include <kdialog.h>
27 #include <klineedit.h>
28 #include <tdelocale.h>
29 #include <kurlrequester.h>
30 
31 #include <tqlayout.h>
32 #include <tqcheckbox.h>
33 #include <tqcombobox.h>
34 #include <tqlabel.h>
35 #include <tqdom.h>
36 #include <tqspinbox.h>
37 #include <tqtabwidget.h>
38 #include <tqvbox.h>
39 
40 ConfigGuiSyncmlObex::ConfigGuiSyncmlObex( const QSync::Member &member, TQWidget *parent )
41  : ConfigGui( member, parent )
42 {
43  TQTabWidget *tabWidget = new TQTabWidget( this );
44  topLayout()->addWidget( tabWidget );
45 
46  // Connection
47  TQVBox *connectionWidget = new TQVBox( this );
48  connectionWidget->setMargin( KDialog::marginHint() );
49  connectionWidget->setSpacing( 5 );
50 
51  tabWidget->addTab( connectionWidget, i18n( "Connection" ) );
52 
53  mConnection = new KComboBox( connectionWidget );
54 
55  connect( mConnection, TQT_SIGNAL (activated( int ) ),
56  this, TQT_SLOT( slotConnectionChanged ( int ) ) );
57 
58  mConnectionTypes.append( ConnectionType( 2, i18n( "Bluetooth" ) ) );
59  mConnectionTypes.append( ConnectionType( 5, i18n( "USB" ) ) );
60 
61  ConnectionTypeList::ConstIterator it;
62  for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ )
63  mConnection->insertItem( (*it).second );
64 
65  mBluetooth = new BluetoothWidget( connectionWidget );
66  mBluetooth->hide();
67 
68  mUsb = new UsbWidget( connectionWidget );
69  mUsb->hide();
70 
71  connectionWidget->setStretchFactor( mBluetooth, 1 );
72  connectionWidget->setStretchFactor( mUsb, 1 );
73 
74  // Databases
75  TQWidget *databaseWidget = new TQWidget( tabWidget );
76  TQVBoxLayout *databaseLayout = new TQVBoxLayout( databaseWidget,
77  KDialog::marginHint(), KDialog::spacingHint() );
78 
79  tabWidget->addTab( databaseWidget, i18n( "Databases" ) );
80 
81  mGridLayout = new TQGridLayout( databaseLayout );
82  addLineEdit( databaseWidget, i18n("Contact Database:"), &mContactDb, 0 );
83  addLineEdit( databaseWidget, i18n("Calendar Database:"), &mCalendarDb, 1 );
84  addLineEdit( databaseWidget, i18n("Note Database:"), &mNoteDb, 2 );
85 
86  mContactDb->insertItem( "addressbook" );
87  mContactDb->insertItem( "contacts" );
88 
89  mCalendarDb->insertItem( "agenda" );
90  mCalendarDb->insertItem( "calendar" );
91 
92  mNoteDb->insertItem( "notes" );
93 
94  // Options
95  TQWidget *optionsWidget = new TQWidget( tabWidget );
96  TQVBoxLayout *optionsLayout = new TQVBoxLayout( optionsWidget,
97  KDialog::marginHint(), KDialog::spacingHint() );
98 
99  tabWidget->addTab( optionsWidget, i18n( "Options" ) );
100 
101  mGridLayout = new TQGridLayout( optionsLayout );
102 
103  TQLabel *label = new TQLabel( i18n("User name:"), optionsWidget );
104  mGridLayout->addWidget( label, 0, 0 );
105 
106  mUsername = new KLineEdit( optionsWidget );
107  mGridLayout->addWidget( mUsername, 0, 1 );
108 
109  label = new TQLabel( i18n("Password:"), optionsWidget );
110  mGridLayout->addWidget( label, 1, 0 );
111 
112  mPassword = new KLineEdit( optionsWidget );
113  mPassword->setEchoMode( TQLineEdit::Password );
114  mGridLayout->addWidget( mPassword, 1, 1 );
115 
116  mUseStringTable = new TQCheckBox( i18n("Use String Table"), optionsWidget );
117  mGridLayout->addMultiCellWidget( mUseStringTable, 2, 2, 0, 1 );
118 
119  mOnlyReplace = new TQCheckBox( i18n("Only Replace Entries"), optionsWidget );
120  mGridLayout->addMultiCellWidget( mOnlyReplace, 3, 3, 0, 1 );
121 
122  // SynML Version
123  label = new TQLabel( i18n("SyncML Version:"), optionsWidget );
124  mGridLayout->addWidget( label, 4, 0 );
125 
126  mSyncmlVersion = new TQComboBox( optionsWidget );
127  mGridLayout->addWidget( mSyncmlVersion, 4, 1 );
128 
129  mSyncmlVersions.append( SyncmlVersion( 0, i18n( "1.0" ) ) );
130  mSyncmlVersions.append( SyncmlVersion( 1, i18n( "1.1" ) ) );
131  mSyncmlVersions.append( SyncmlVersion( 2, i18n( "1.2" ) ) );
132 
133  SyncmlVersionList::ConstIterator itVersion;
134  for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ )
135  mSyncmlVersion->insertItem( (*itVersion).second );
136 
137  // WBXML
138  mWbxml = new TQCheckBox( i18n("WAP Binary XML"), optionsWidget );
139  mGridLayout->addMultiCellWidget( mWbxml, 12, 12, 0, 1 );
140 
141  // Identifier
142  label = new TQLabel( i18n("Software Identifier:"), optionsWidget );
143  mGridLayout->addWidget( label, 13, 0 );
144 
145  mIdentifier = new KComboBox( true, optionsWidget );
146  mGridLayout->addWidget( mIdentifier, 13, 1 );
147 
148  mIdentifier->insertItem( "" );
149  mIdentifier->insertItem( "PC Suite" );
150 
151  // recvLimit
152  label = new TQLabel( i18n("Receive Limit:"), optionsWidget );
153  mGridLayout->addWidget( label, 14, 0 );
154 
155  mRecvLimit = new TQSpinBox( optionsWidget );
156  mRecvLimit->setMinValue( 1 );
157  mRecvLimit->setMaxValue( 65536 );
158  mGridLayout->addWidget( mRecvLimit, 14, 1 );
159 
160  // maxObjSize
161  label = new TQLabel( i18n("Maximum Object Size"), optionsWidget );
162  mGridLayout->addWidget( label, 15, 0 );
163 
164  mMaxObjSize = new TQSpinBox( optionsWidget );
165  mMaxObjSize->setMinValue( 1 );
166  mMaxObjSize->setMaxValue( 65536 );
167  mGridLayout->addWidget( mMaxObjSize, 15, 1 );
168 
169  topLayout()->addStretch( 1 );
170 }
171 
172 void ConfigGuiSyncmlObex::slotConnectionChanged( int pos )
173 {
174  mUsb->hide();
175  mBluetooth->hide();
176 
177  if ( pos == 0 )
178  mBluetooth->show();
179  else if ( pos == 1 )
180  mUsb->show();
181 }
182 
183 void ConfigGuiSyncmlObex::load( const TQString &xml )
184 {
185  TQDomDocument document;
186  document.setContent( xml );
187 
188  TQDomElement docElement = document.documentElement();
189 
190  TQDomNode node;
191  for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
192  TQDomElement element = node.toElement();
193  if ( element.tagName() == "username" ) {
194  mUsername->setText( element.text() );
195  } else if ( element.tagName() == "password" ) {
196  mPassword->setText( element.text() );
197  } else if ( element.tagName() == "type" ) {
198  for ( uint i = 0; i < mConnectionTypes.count(); i++ ) {
199  if ( mConnectionTypes[i].first == element.text().toInt() ) {
200  mConnection->setCurrentItem( i );
201  slotConnectionChanged( i );
202  break;
203  }
204  }
205  } else if ( element.tagName() == "version" ) {
206  for ( uint i = 0; i < mSyncmlVersions.count(); i++ ) {
207  if ( mSyncmlVersions[i].first == element.text().toInt() ) {
208  mSyncmlVersion->setCurrentItem( i );
209  break;
210  }
211  }
212  } else if ( element.tagName() == "bluetooth_address" ) {
213  if ( mBluetooth ) mBluetooth->setAddress( element.text() );
214  } else if ( element.tagName() == "bluetooth_channel" ) {
215  if ( mBluetooth ) mBluetooth->setChannel( element.text() );
216  } else if ( element.tagName() == "identifier" ) {
217  if ( mIdentifier ) mIdentifier->setCurrentText( element.text() );
218  } else if ( element.tagName() == "interface" ) {
219  if ( mUsb ) mUsb->setInterface( element.text().toInt() );
220  } else if ( element.tagName() == "wbxml" ) {
221  if ( mWbxml) mWbxml->setChecked( element.text() == "1" );
222  } else if ( element.tagName() == "recvLimit" ) {
223  if ( mRecvLimit ) mRecvLimit->setValue( element.text().toInt() );
224  } else if ( element.tagName() == "maxObjSize" ) {
225  if ( mMaxObjSize ) mMaxObjSize->setValue( element.text().toInt() );
226  } else if ( element.tagName() == "usestringtable" ) {
227  mUseStringTable->setChecked( element.text() == "1" );
228  } else if ( element.tagName() == "onlyreplace" ) {
229  mOnlyReplace->setChecked( element.text() == "1" );
230  } else if ( element.tagName() == "contact_db" ) {
231  mContactDb->setCurrentText( element.text() );
232  } else if ( element.tagName() == "calendar_db" ) {
233  mCalendarDb->setCurrentText( element.text() );
234  } else if ( element.tagName() == "note_db" ) {
235  mNoteDb->setCurrentText( element.text() );
236  }
237  }
238 }
239 
240 TQString ConfigGuiSyncmlObex::save() const
241 {
242  TQString xml;
243  xml = "<config>\n";
244  xml += "<username>" + mUsername->text() + "</username>\n";
245  xml += "<password>" + mPassword->text() + "</password>\n";
246  ConnectionTypeList::ConstIterator it;
247  for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) {
248  if ( mConnection->currentText() == (*it).second ) {
249  xml += "<type>" + TQString("%1").arg((*it).first) + "</type>\n";
250  break;
251  }
252  }
253 
254  // Bluetooth Address
255  xml += "<bluetooth_address>" + mBluetooth->address() + "</bluetooth_address>\n";
256 
257  // Bluetooth Channel
258  xml += "<bluetooth_channel>" + mBluetooth->channel() + "</bluetooth_channel>\n";
259 
260  // USB Interface
261  xml += "<interface>" + TQString::number( mUsb->interface() ) +"</interface>\n";
262 
263  // SyncML Version
264  SyncmlVersionList::ConstIterator itVersion;
265  for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ ) {
266  if ( mSyncmlVersion->currentText() == (*itVersion).second ) {
267  xml += "<version>" + TQString("%1").arg((*itVersion).first) + "</version>\n";
268  break;
269  }
270  }
271 
272  // (Software) Identifier
273  xml += "<identifier>" + mIdentifier->currentText() + "</identifier>\n";
274 
275  // WBXML
276  xml += "<wbxml>";
277  if ( mWbxml->isChecked() )
278  xml += "1";
279  else
280  xml += "0";
281  xml += "</wbxml>\n";
282 
283  // Receive Limit
284  xml += "<recvLimit>" + TQString::number( mRecvLimit->value() ) + "</recvLimit>\n";
285 
286  // Maximal Object Size
287  xml += "<maxObjSize>" + TQString::number( mMaxObjSize->value() ) + "</maxObjSize>\n";
288 
289  xml += "<usestringtable>";
290  if ( mUseStringTable->isChecked() )
291  xml += "1";
292  else
293  xml += "0";
294  xml += "</usestringtable>\n";
295 
296  xml += "<onlyreplace>";
297  if ( mOnlyReplace->isChecked() )
298  xml += "1";
299  else
300  xml += "0";
301  xml += "</onlyreplace>\n";
302 
303  xml += "<contact_db>" + mContactDb->currentText() + "</contact_db>\n";
304  xml += "<calendar_db>" + mCalendarDb->currentText() + "</calendar_db>\n";
305  xml += "<note_db>" + mNoteDb->currentText() + "</note_db>\n";
306  xml += "</config>";
307 
308  return xml;
309 }
310 
311 void ConfigGuiSyncmlObex::addLineEdit( TQWidget *parent, const TQString &text, KComboBox **edit, int row )
312 {
313  TQLabel *label = new TQLabel( text, parent );
314  mGridLayout->addWidget( label, row, 0 );
315 
316  *edit = new KComboBox( true, parent );
317  mGridLayout->addWidget( *edit, row, 1 );
318 }
319 
320 #include "configguisyncmlobex.moc"