kitchensync

configguignokii.cpp
1/*
2 This file is part of KitchenSync.
3
4 Copyright (c) 2006 David Förster <david@dfoerster.de>
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 "configguignokii.h"
23
24#include <tdelocale.h>
25#include <kdialog.h>
26#include <kcombobox.h>
27
28#include <kdebug.h>
29
30#include <tqlayout.h>
31#include <tqlabel.h>
32#include <tqlineedit.h>
33#include <tqcombobox.h>
34#include <tqdom.h>
35#include <tqvbox.h>
36
37ConfigGuiGnokii::ConfigGuiGnokii( const QSync::Member &member, TQWidget *parent )
38 : ConfigGui( member, parent )
39{
40 TQGridLayout *layout = new TQGridLayout( topLayout() );
41
42 // Model
43 TQLabel *label = new TQLabel( i18n("Model:"), this );
44 layout->addWidget( label, 0, 0 );
45
46 mModel = new KComboBox( true, this );
47 layout->addWidget( mModel, 0, 1 );
48 mModel->insertItem( "2110" );
49 mModel->insertItem( "3110" );
50 mModel->insertItem( "6110" );
51 mModel->insertItem( "6110" );
52 mModel->insertItem( "6160" );
53 mModel->insertItem( "6230" );
54 mModel->insertItem( "6230i" );
55 mModel->insertItem( "6510" );
56 mModel->insertItem( "7110" );
57 mModel->insertItem( "AT" );
58 // This one requires the gnapplet and rfcomm_channel
59 mModel->insertItem( "3650" );
60 mModel->insertItem( "6600" );
61 mModel->insertItem( "gnapplet" );
62 mModel->insertItem( "symbian" );
63 mModel->insertItem( "sx1" );
64
65 connect( mModel, TQT_SIGNAL (activated( int ) ),
66 this, TQT_SLOT( slotModelChanged () ) );
67
68 // Connection
69 label = new TQLabel( i18n("Connection:"), this );
70 layout->addWidget( label, 1, 0 );
71
72 mConnection = new TQComboBox( this );
73 layout->addWidget( mConnection, 1, 1 );
74
75 connect( mConnection, TQT_SIGNAL (activated( int ) ),
76 this, TQT_SLOT( slotConnectionChanged ( int ) ) );
77
78 // this is a list of all connection types accepted by the gnokii-sync plugin
79 mConnectionTypes.append( ConnectionType( "bluetooth", i18n( "Bluetooth" ) ) );
80 mConnectionTypes.append( ConnectionType( "irda", i18n( "IrDA" ) ) );
81 mConnectionTypes.append( ConnectionType( "serial", i18n( "Serial" ) ) );
82 mConnectionTypes.append( ConnectionType( "infrared", i18n( "Infrared" ) ) );
83 mConnectionTypes.append( ConnectionType( "tcp", i18n( "TCP" ) ) );
84 mConnectionTypes.append( ConnectionType( "dku2", i18n( "USB (nokia_dku2)" ) ) );
85 mConnectionTypes.append( ConnectionType( "dku2libusb", i18n( "USB (libusb)" ) ) );
86 mConnectionTypes.append( ConnectionType( "dau9p", i18n( "Serial (DAU9P cable)" ) ) );
87 mConnectionTypes.append( ConnectionType( "dlr3p", i18n( "Serial (DLR3P cable)" ) ) );
88 mConnectionTypes.append( ConnectionType( "tekram", i18n( "Tekram Ir-Dongle" ) ) );
89 mConnectionTypes.append( ConnectionType( "m2bus", i18n( "Serial (M2BUS protocol)" ) ) );
90
91 ConnectionTypeList::ConstIterator it;
92 for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) {
93 mConnection->insertItem( (*it).second );
94 }
95
96 TQVBox *connectionWidget = new TQVBox( this );
97 connectionWidget->setMargin( KDialog::marginHint() );
98 connectionWidget->setSpacing( 5 );
99
100 mBluetooth = new BluetoothWidget( connectionWidget );
101 mBluetooth->hide();
102
103 layout->addMultiCellWidget( connectionWidget, 2, 2, 0, 1 );
104
105 // Port
106 mPortLabel = new TQLabel( i18n("Port:"), this );
107 layout->addWidget( mPortLabel, 2, 0 );
108 mPortLabel->hide();
109
110 mPort = new KComboBox( true, this );
111 layout->addWidget( mPort, 2, 1 );
112 mPort->hide();
113
114 mPort->insertItem( "/dev/ircomm0" );
115 mPort->insertItem( "/dev/ircomm1" );
116 mPort->insertItem( "/dev/ttyS0" );
117 mPort->insertItem( "/dev/ttyS1" );
118 mPort->insertItem( "/dev/ttyUSB0" );
119 mPort->insertItem( "/dev/ttyUSB1" );
120
121 layout->setColStretch( 1, 1 );
122
123 topLayout()->addStretch( 1 );
124}
125
126void ConfigGuiGnokii::slotConnectionChanged( int nth )
127{
128 mPort->hide();
129 mPortLabel->hide();
130 mBluetooth->hide();
131
132 // Bluetooth
133 if ( nth == 0 ) {
134 mBluetooth->show();
135 slotModelChanged();
136
137 if ( !mPort->currentText().isEmpty() )
138 mBluetooth->setAddress( mPort->currentText() );
139
140 // dku2libusb
141 } else if ( nth == 6 ) {
142 // No widget needed.
143 } else {
144 mPort->show();
145 mPortLabel->show();
146 }
147
148}
149
150void ConfigGuiGnokii::slotModelChanged()
151{
152 mBluetooth->hideChannel();
153
154 if ( mModel->currentText() == "gnapplet"
155 || mModel->currentText() == "symbian"
156 || mModel->currentText() == "3650"
157 || mModel->currentText() == "6600"
158 || mModel->currentText() == "sx1")
159 mBluetooth->showChannel();
160 else
161 mBluetooth->setChannel("");
162}
163
164void ConfigGuiGnokii::load( const TQString &xml )
165{
166 TQDomDocument doc;
167 doc.setContent( xml );
168 TQDomElement docElement = doc.documentElement();
169 TQDomNode n;
170 for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) {
171 TQDomElement e = n.toElement();
172 if ( e.tagName() == "connection" ) {
173 for ( uint i = 0; i < mConnectionTypes.count(); i++ ) {
174 if ( mConnectionTypes[i].first == e.text()) {
175 mConnection->setCurrentItem( i );
176 slotConnectionChanged( i );
177 break;
178 }
179 }
180 } else if ( e.tagName() == "port" ) {
181 mPort->setCurrentText( e.text() );
182 } else if ( e.tagName() == "model" ) {
183 mModel->setCurrentText( e.text() );
184 } else if ( e.tagName() == "rfcomm_channel" ) {
185 mBluetooth->setChannel( e.text() );
186 mBluetooth->showChannel();
187 }
188 }
189}
190
191TQString ConfigGuiGnokii::save() const
192{
193 TQString xml;
194 xml = "<config>";
195
196 ConnectionTypeList::ConstIterator it;
197 for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) {
198 if ( mConnection->currentText() == (*it).second ) {
199 xml += "<connection>" + (*it).first + "</connection>";
200 break;
201 }
202 }
203
204 if ( (*it).first == "bluetooth" )
205 xml += "<port>" + mBluetooth->address() + "</port>";
206 else if ( (*it).first == "dku2libusb" )
207 xml += "<port>" + TQString("FF:FF:FF:FF:FF:FF") + "</port>"; // Only place holder for libgnokii
208 else
209 xml += "<port>" + mPort->currentText() + "</port>";
210
211 // model
212 xml += "<model>" + mModel->currentText() + "</model>";
213
214 // rfcomm_channel
215 if ( !mBluetooth->channel().isNull() )
216 xml += "<rfcomm_channel>" + mBluetooth->channel() + "</rfcomm_channel>";
217
218 xml += "</config>";
219
220 return xml;
221}
222
223#include "configguignokii.moc"