kitchensync

configguiirmc.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19  USA.
20 */
21 
22 #include <kcombobox.h>
23 #include <kdialog.h>
24 #include <tdeglobal.h>
25 #include <kiconloader.h>
26 #include <kinputdialog.h>
27 #include <klineedit.h>
28 #include <tdelocale.h>
29 #include <tdemessagebox.h>
30 
31 #include <kdebug.h>
32 
33 #include <tqapplication.h>
34 #include <tqeventloop.h>
35 #include <tqlabel.h>
36 #include <tqlayout.h>
37 #include <tqpushbutton.h>
38 #include <tqspinbox.h>
39 #include <tqtabwidget.h>
40 #include <tqtooltip.h>
41 #include <tqvbox.h>
42 
43 #include "configguiirmc.h"
44 
45 ConfigGuiIRMC::ConfigGuiIRMC( const QSync::Member &member, TQWidget *parent )
46  : ConfigGui( member, parent )
47 {
48  initGUI();
49 
50  mConnectionType->insertItem( i18n( "Bluetooth" ) );
51  mConnectionType->insertItem( i18n( "InfraRed (IR)" ) );
52  mConnectionType->insertItem( i18n( "Cable" ) );
53 
54  connect( mConnectionType, TQT_SIGNAL( activated( int ) ),
55  this, TQT_SLOT( connectionTypeChanged( int ) ) );
56 
57  connectionTypeChanged( 0 );
58 }
59 
60 void ConfigGuiIRMC::load( const TQString &xml )
61 {
62  TQDomDocument doc;
63  doc.setContent( xml );
64  TQDomElement docElement = doc.documentElement();
65  TQDomNode node;
66  for ( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
67  TQDomElement element = node.toElement();
68  if ( element.tagName() == "connectmedium" ) {
69  if ( element.text() == "bluetooth" ) {
70  mConnectionType->setCurrentItem( 0 );
71  connectionTypeChanged( 0 );
72  } else if ( element.text() == "ir" ) {
73  mConnectionType->setCurrentItem( 1 );
74  connectionTypeChanged( 1 );
75  } else if ( element.text() == "cable" ) {
76  mConnectionType->setCurrentItem( 2 );
77  connectionTypeChanged( 2 );
78  }
79  } else if (element.tagName() == "btunit" ) {
80  mBluetoothWidget->setAddress( element.text() );
81  } else if (element.tagName() == "btchannel" ) {
82  mBluetoothWidget->setChannel( element.text() );
83  } else if (element.tagName() == "donttellsync" ) {
84  mDontTellSync->setChecked( element.text() == "true" );
85  }
86 
87 
88  }
89 
90  mIRWidget->load( docElement );
91  mCableWidget->load( docElement );
92 }
93 
94 TQString ConfigGuiIRMC::save() const
95 {
96  TQDomDocument doc;
97  TQDomElement config = doc.createElement( "config" );
98  doc.appendChild( config );
99 
100  TQDomElement element = doc.createElement( "connectmedium" );
101  if ( mConnectionType->currentItem() == 0 )
102  element.appendChild( doc.createTextNode( "bluetooth" ) );
103  if ( mConnectionType->currentItem() == 1 )
104  element.appendChild( doc.createTextNode( "ir" ) );
105  if ( mConnectionType->currentItem() == 2 )
106  element.appendChild( doc.createTextNode( "cable" ) );
107 
108  config.appendChild( element );
109 
110  if ( mConnectionType->currentItem() == 0 ) {
111  TQDomElement btunit = doc.createElement( "btunit" );
112  if ( !mBluetoothWidget->address().isEmpty() )
113  btunit.appendChild( doc.createTextNode( mBluetoothWidget->address() ) );
114 
115  TQDomElement btchannel = doc.createElement( "btchannel" );
116  if ( !mBluetoothWidget->channel().isEmpty() )
117  btchannel.appendChild( doc.createTextNode( mBluetoothWidget->channel() ) );
118 
119  config.appendChild( btunit );
120  config.appendChild( btchannel );
121  }
122 
123  if ( mDontTellSync->isChecked() ) {
124  TQDomElement dontellsync = doc.createElement( "donttellsync" );
125  dontellsync.appendChild( doc.createTextNode( "true" ) );
126  config.appendChild( dontellsync );
127  }
128 
129  mIRWidget->save( doc, config );
130  mCableWidget->save( doc, config );
131 
132  return doc.toString();
133 }
134 
135 void ConfigGuiIRMC::connectionTypeChanged( int type )
136 {
137  mBluetoothWidget->hide();
138  mIRWidget->hide();
139  mCableWidget->hide();
140 
141  if ( type == 0 )
142  mBluetoothWidget->show();
143  else if ( type == 1 )
144  mIRWidget->show();
145  else
146  mCableWidget->show();
147 }
148 
149 void ConfigGuiIRMC::initGUI()
150 {
151  TQTabWidget *tabWidget = new TQTabWidget( this );
152  topLayout()->addWidget( tabWidget );
153 
154  TQVBox *connectionWidget = new TQVBox( tabWidget );
155  connectionWidget->setMargin( KDialog::marginHint() );
156  connectionWidget->setSpacing( 5 );
157 
158  tabWidget->addTab( connectionWidget, i18n( "Connection" ) );
159 
160  mConnectionType = new KComboBox( connectionWidget );
161  TQToolTip::add( mConnectionType, i18n( "Select your connection type." ) );
162 
163  mBluetoothWidget = new BluetoothWidget( connectionWidget );
164  mBluetoothWidget->hide();
165 
166  mIRWidget = new IRWidget( connectionWidget );
167  mIRWidget->hide();
168 
169  mCableWidget = new CableWidget( connectionWidget );
170  mCableWidget->hide();
171 
172  connectionWidget->setStretchFactor( mBluetoothWidget, 1 );
173  connectionWidget->setStretchFactor( mIRWidget, 1 );
174  connectionWidget->setStretchFactor( mCableWidget, 1 );
175 
176  TQVBox *optionsWidget = new TQVBox( tabWidget );
177  optionsWidget->setMargin( KDialog::marginHint() );
178  optionsWidget->setSpacing( 5 );
179 
180  tabWidget->addTab( optionsWidget, i18n( "Options" ) );
181 
182  TQHBox *optionBox = new TQHBox( optionsWidget );
183  optionBox->setSpacing( KDialog::spacingHint() );
184 
185  TQLabel *label = new TQLabel( i18n( "Don't send OBEX UUID (IRMC-SYNC)" ), optionBox );
186  mDontTellSync = new TQCheckBox( optionBox );
187  TQToolTip::add( mDontTellSync, i18n( "Don't send OBEX UUID while connecting. Needed for older IrMC based mobile phones." ) );
188  label->setBuddy( mDontTellSync );
189 
190 }
191 
192 #include "configguiirmc.moc"