kitchensync

configguipalm.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 <klineedit.h>
25#include <tdelocale.h>
26
27#include <tqbuttongroup.h>
28#include <tqcheckbox.h>
29#include <tqdom.h>
30#include <tqlabel.h>
31#include <tqlayout.h>
32#include <tqradiobutton.h>
33#include <tqspinbox.h>
34#include <tqtabwidget.h>
35
36#include "configguipalm.h"
37
38ConfigGuiPalm::ConfigGuiPalm( const QSync::Member &member, TQWidget *parent )
39 : ConfigGui( member, parent )
40{
41 initGUI();
42
43 mDevice->insertItem( "/dev/pilot" );
44 mDevice->insertItem( "/dev/ttyUSB0" );
45 mDevice->insertItem( "/dev/ttyUSB1" );
46 mDevice->insertItem( "/dev/ttyUSB2" );
47 mDevice->insertItem( "/dev/ttyUSB3" );
48
49 mSpeed->insertItem( "9600" );
50 mSpeed->insertItem( "19200" );
51 mSpeed->insertItem( "38400" );
52 mSpeed->insertItem( "57600" );
53 mSpeed->insertItem( "115200" );
54}
55
56void ConfigGuiPalm::load( const TQString &xml )
57{
58 TQDomDocument doc;
59 doc.setContent( xml );
60 TQDomElement docElement = doc.documentElement();
61 TQDomNode node;
62 for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
63 TQDomElement element = node.toElement();
64 if ( element.tagName() == "sockaddr" ) {
65 mDevice->setCurrentText( element.text() );
66 } else if ( element.tagName() == "speed" ) {
67 mSpeed->setCurrentText( element.text() );
68 } else if ( element.tagName() == "timeout" ) {
69 mTimeout->setValue( element.text().toInt() );
70 } else if ( element.tagName() == "username" ) {
71 mUserName->setText( element.text() );
72 } else if ( element.tagName() == "mismatch" ) {
73 switch ( element.text().toInt() ) {
74 case 0:
75 mSyncAlways->setChecked( true );
76 break;
77 case 2:
78 mSyncAbort->setChecked( true );
79 break;
80 case 1:
81 default:
82 mSyncAsk->setChecked( true );
83 break;
84 }
85 } else if ( element.tagName() == "popup" ) {
86 mPopup->setChecked( element.text() == "1" );
87 }
88 }
89}
90
91TQString ConfigGuiPalm::save() const
92{
93 TQString config = "<config>";
94
95 config += "<sockaddr>" + mDevice->currentText() + "</sockaddr>";
96 config += "<username>" + mUserName->text() + "</username>";
97 config += "<timeout>" + TQString::number( mTimeout->value() ) + "</timeout>";
98 config += "<type>0</type>";
99 config += "<speed>" + mSpeed->currentText() + "</speed>";
100 config += "<id>0</id>";
101 config += "<codepage>cp1252</codepage>";
102 config += "<popup>" + TQString( mPopup->isChecked() ? "1" : "0" ) + "</popup>";
103
104 TQString popup;
105 if ( mSyncAlways->isChecked() )
106 popup = "0";
107 else if ( mSyncAsk->isChecked() )
108 popup = "1";
109 else if ( mSyncAbort->isChecked() )
110 popup = "2";
111
112 config += "<mismatch>" + popup + "</mismatch>";
113
114 config += "</config>";
115
116 return config;
117}
118
119void ConfigGuiPalm::initGUI()
120{
121 TQFont boldFont = font();
122 boldFont.setBold( true );
123
124 TQTabWidget *tabWidget = new TQTabWidget( this );
125
126 TQWidget *connectionWidget = new TQWidget( tabWidget );
127 TQVBoxLayout *connectionLayout = new TQVBoxLayout( connectionWidget,
128 KDialog::marginHint(), KDialog::spacingHint() );
129
130 TQLabel *label = new TQLabel( i18n( "Connection" ), connectionWidget );
131 label->setFont( boldFont );
132 connectionLayout->addWidget( label );
133
134 TQGridLayout *gridLayout = new TQGridLayout( connectionLayout, 3, 2, KDialog::spacingHint() );
135 gridLayout->setMargin( KDialog::marginHint() );
136
137 gridLayout->addWidget( new TQLabel( i18n( "Port:" ), connectionWidget ), 0, 0 );
138 gridLayout->addWidget( new TQLabel( i18n( "Speed:" ), connectionWidget ), 1, 0 );
139 gridLayout->addWidget( new TQLabel( i18n( "Timeout:" ), connectionWidget ), 2, 0 );
140
141 mDevice = new KComboBox( true, connectionWidget );
142 mSpeed = new KComboBox( connectionWidget );
143 mTimeout = new TQSpinBox( 1, 60, 1, connectionWidget );
144 mTimeout->setSuffix( i18n( " sec" ) );
145
146 gridLayout->addWidget( mDevice, 0, 1 );
147 gridLayout->addWidget( mSpeed, 1, 1 );
148 gridLayout->addWidget( mTimeout, 2, 1 );
149 gridLayout->setColStretch( 1, 1 );
150
151 label = new TQLabel( i18n( "User" ), connectionWidget );
152 label->setFont( boldFont );
153 connectionLayout->addWidget( label );
154
155 gridLayout = new TQGridLayout( connectionLayout, 1, 2, KDialog::spacingHint() );
156 gridLayout->setMargin( KDialog::marginHint() );
157
158 gridLayout->addWidget( new TQLabel( i18n( "Username:" ), connectionWidget ), 0, 0 );
159
160 mUserName = new KLineEdit( connectionWidget );
161 gridLayout->addWidget( mUserName, 0, 1 );
162
163 label = new TQLabel( i18n( "What to do if Username does not match" ), connectionWidget );
164 label->setFont( boldFont );
165 connectionLayout->addWidget( label );
166
167 gridLayout = new TQGridLayout( connectionLayout, 1, 2, KDialog::spacingHint() );
168 gridLayout->setMargin( KDialog::marginHint() );
169
170 TQButtonGroup *buttonGroup = new TQButtonGroup( 1, TQt::Horizontal, connectionWidget );
171 buttonGroup->setExclusive( true );
172 buttonGroup->setFrameStyle( TQFrame::NoFrame );
173 mSyncAlways = new TQRadioButton( i18n( "Sync Anyway" ), buttonGroup );
174 mSyncAsk = new TQRadioButton( i18n( "Ask What To Do" ), buttonGroup );
175 mSyncAbort = new TQRadioButton( i18n( "Abort Sync" ), buttonGroup );
176
177 gridLayout->addMultiCellWidget( buttonGroup, 0, 0, 0, 1 );
178
179 connectionLayout->addStretch( 1 );
180 tabWidget->addTab( connectionWidget, i18n( "Connection" ) );
181
182 TQWidget *optionWidget = new TQWidget( tabWidget );
183 TQVBoxLayout *optionLayout = new TQVBoxLayout( optionWidget,
184 KDialog::marginHint(), KDialog::spacingHint() );
185
186 label = new TQLabel( i18n( "Hotsync Notification" ), optionWidget );
187 label->setFont( boldFont );
188 optionLayout->addWidget( label );
189
190 gridLayout = new TQGridLayout( optionLayout, 1, 2, KDialog::spacingHint() );
191 gridLayout->setMargin( KDialog::marginHint() );
192
193 mPopup = new TQCheckBox( i18n( "Popup when interaction is required" ), optionWidget );
194 gridLayout->addMultiCellWidget( mPopup, 0, 0, 0, 1 );
195
196 optionLayout->addStretch( 1 );
197 tabWidget->addTab( optionWidget, i18n( "Options" ) );
198
199 topLayout()->addWidget( tabWidget );
200}