summaryrefslogtreecommitdiffstats
path: root/kitchensync/src/configguignokii.cpp
blob: 38f2fbf3a1e18392f4ab19c86e21b9f42896c77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
    This file is part of KitchenSync.

    Copyright (c) 2006 David Förster <[email protected]>

    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 "configguignokii.h"

#include <klocale.h>
#include <kdialog.h>
#include <kcombobox.h>

#include <kdebug.h>

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqcombobox.h>
#include <tqdom.h>
#include <tqvbox.h>

ConfigGuiGnokii::ConfigGuiGnokii( const QSync::Member &member, TQWidget *parent )
  : ConfigGui( member, parent )
{
  TQGridLayout *layout = new TQGridLayout( topLayout() );

  // Model
  TQLabel *label = new TQLabel( i18n("Model:"), this );
  layout->addWidget( label, 0, 0 );

  mModel = new KComboBox( true, this );
  layout->addWidget( mModel, 0, 1 );
  mModel->insertItem( "2110" ); 
  mModel->insertItem( "3110" ); 
  mModel->insertItem( "6110" ); 
  mModel->insertItem( "6110" ); 
  mModel->insertItem( "6160" ); 
  mModel->insertItem( "6230" );
  mModel->insertItem( "6230i" );
  mModel->insertItem( "6510" ); 
  mModel->insertItem( "7110" );
  mModel->insertItem( "AT" );
  // This one requires the gnapplet and rfcomm_channel
  mModel->insertItem( "3650" );
  mModel->insertItem( "6600" );
  mModel->insertItem( "gnapplet" );
  mModel->insertItem( "symbian" );
  mModel->insertItem( "sx1" );

  connect( mModel, TQT_SIGNAL (activated( int ) ),
    this, TQT_SLOT( slotModelChanged () ) );

  // Connection
  label = new TQLabel( i18n("Connection:"), this );
  layout->addWidget( label, 1, 0 );

  mConnection = new TQComboBox( this );
  layout->addWidget( mConnection, 1, 1 );

  connect( mConnection, TQT_SIGNAL (activated( int ) ),
      	    this, TQT_SLOT( slotConnectionChanged ( int ) ) );

  // this is a list of all connection types accepted by the gnokii-sync plugin
  mConnectionTypes.append( ConnectionType( "bluetooth",  i18n( "Bluetooth" ) ) );
  mConnectionTypes.append( ConnectionType( "irda", i18n( "IrDA" ) ) );
  mConnectionTypes.append( ConnectionType( "serial", i18n( "Serial" ) ) );
  mConnectionTypes.append( ConnectionType( "infrared", i18n( "Infrared" ) ) );
  mConnectionTypes.append( ConnectionType( "tcp", i18n( "TCP" ) ) );
  mConnectionTypes.append( ConnectionType( "dku2", i18n( "USB (nokia_dku2)" ) ) );
  mConnectionTypes.append( ConnectionType( "dku2libusb", i18n( "USB (libusb)" ) ) );
  mConnectionTypes.append( ConnectionType( "dau9p", i18n( "Serial (DAU9P cable)" ) ) );
  mConnectionTypes.append( ConnectionType( "dlr3p", i18n( "Serial (DLR3P cable)" ) ) );
  mConnectionTypes.append( ConnectionType( "tekram", i18n( "Tekram Ir-Dongle" ) ) );
  mConnectionTypes.append( ConnectionType( "m2bus", i18n( "Serial (M2BUS protocol)" ) ) );

  ConnectionTypeList::ConstIterator it;
  for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) {
    mConnection->insertItem( (*it).second );
  }

  TQVBox *connectionWidget = new TQVBox( this );
  connectionWidget->setMargin( KDialog::marginHint() );
  connectionWidget->setSpacing( 5 );

  mBluetooth = new BluetoothWidget( connectionWidget ); 
  mBluetooth->hide();

  layout->addMultiCellWidget( connectionWidget, 2, 2, 0, 1 );

  // Port
  mPortLabel = new TQLabel( i18n("Port:"), this );
  layout->addWidget( mPortLabel, 2, 0 );
  mPortLabel->hide();

  mPort = new KComboBox( true, this );
  layout->addWidget( mPort, 2, 1 );
  mPort->hide();

  mPort->insertItem( "/dev/ircomm0" );
  mPort->insertItem( "/dev/ircomm1" );
  mPort->insertItem( "/dev/ttyS0" );
  mPort->insertItem( "/dev/ttyS1" );
  mPort->insertItem( "/dev/ttyUSB0" );
  mPort->insertItem( "/dev/ttyUSB1" );

  layout->setColStretch( 1, 1 );

  topLayout()->addStretch( 1 );
}

void ConfigGuiGnokii::slotConnectionChanged( int nth )
{
  mPort->hide();
  mPortLabel->hide();
  mBluetooth->hide();

  // Bluetooth
  if ( nth == 0 ) {
    mBluetooth->show();
    slotModelChanged();

    if ( !mPort->currentText().isEmpty() )
      mBluetooth->setAddress( mPort->currentText() );

  // dku2libusb
  } else if ( nth == 6 ) {
    // No widget needed.
  } else {
    mPort->show();
    mPortLabel->show();
  }

}

void ConfigGuiGnokii::slotModelChanged()
{
  mBluetooth->hideChannel();

  if ( mModel->currentText() == "gnapplet"
    || mModel->currentText() == "symbian"
    || mModel->currentText() == "3650"
    || mModel->currentText() == "6600"
    || mModel->currentText() == "sx1")
    mBluetooth->showChannel();
  else
    mBluetooth->setChannel("");
}

void ConfigGuiGnokii::load( const TQString &xml )
{
  TQDomDocument doc;
  doc.setContent( xml );
  TQDomElement docElement = doc.documentElement();
  TQDomNode n;
  for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    TQDomElement e = n.toElement();
    if ( e.tagName() == "connection" ) {
      for ( uint i = 0; i < mConnectionTypes.count(); i++ ) {
        if ( mConnectionTypes[i].first == e.text()) {
          mConnection->setCurrentItem( i );
          slotConnectionChanged( i );
          break;
        }
      }
    } else if ( e.tagName() == "port" ) {
      mPort->setCurrentText( e.text() );
    } else if ( e.tagName() == "model" ) {
      mModel->setCurrentText( e.text() );
    } else if ( e.tagName() == "rfcomm_channel" ) {
      mBluetooth->setChannel( e.text() );
      mBluetooth->showChannel();
    }
  }
}

TQString ConfigGuiGnokii::save() const
{
  TQString xml;
  xml = "<config>";

  ConnectionTypeList::ConstIterator it;
  for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) {
    if ( mConnection->currentText() == (*it).second ) {
      xml += "<connection>" + (*it).first + "</connection>";
      break;
    }
  }

  if ( (*it).first == "bluetooth" )
    xml += "<port>" + mBluetooth->address() + "</port>";
  else if ( (*it).first == "dku2libusb" )
    xml += "<port>" + TQString("FF:FF:FF:FF:FF:FF") + "</port>"; // Only place holder for libgnokii
  else
    xml += "<port>" + mPort->currentText() + "</port>";

  // model
  xml += "<model>" + mModel->currentText() + "</model>";

  // rfcomm_channel
  if ( !mBluetooth->channel().isNull() )
    xml += "<rfcomm_channel>" + mBluetooth->channel() + "</rfcomm_channel>";

  xml += "</config>";

  return xml;
}

#include "configguignokii.moc"