kitchensync

configguigpe.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2007 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 "configguigpe.h"
23 
24 #include <tqcheckbox.h>
25 #include <tqdom.h>
26 #include <tqlabel.h>
27 #include <tqlayout.h>
28 #include <tqspinbox.h>
29 
30 #include <kcombobox.h>
31 #include <kdialog.h>
32 #include <klineedit.h>
33 #include <tdelocale.h>
34 
35 ConfigGuiGpe::ConfigGuiGpe( const QSync::Member &member, TQWidget *parent )
36  : ConfigGui( member, parent )
37 {
38  initGUI();
39 
40  mConnectionMode->insertItem( i18n( "Local" ) );
41  mConnectionMode->insertItem( i18n( "Ssh" ) );
42 }
43 
44 void ConfigGuiGpe::load( const TQString &xml )
45 {
46  TQDomDocument doc;
47  doc.setContent( xml );
48  TQDomElement docElement = doc.documentElement();
49  TQDomNode node;
50  for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
51  TQDomElement element = node.toElement();
52  if ( element.tagName() == "use_local" ) {
53  if ( element.text().toInt() == 1 )
54  mConnectionMode->setCurrentItem( 0 );
55  else
56  mConnectionMode->setCurrentItem( 1 );
57  } else if ( element.tagName() == "handheld_ip" ) {
58  mIP->setText( element.text() );
59  } else if ( element.tagName() == "handheld_port" ) {
60  mPort->setValue( element.text().toInt() );
61  } else if ( element.tagName() == "handheld_user" ) {
62  mUser->setText( element.text() );
63  }
64  }
65 }
66 
67 TQString ConfigGuiGpe::save() const
68 {
69  TQString config = "<config>";
70 
71  config += TQString( "<use_local>%1</use_local>" ).arg( mConnectionMode->currentItem() == 0 );
72  config += TQString( "<use_ssh>%1</use_ssh>" ).arg( mConnectionMode->currentItem() == 1 );
73  config += TQString( "<handheld_ip>%1</handheld_ip>" ).arg( mIP->text() );
74  config += TQString( "<handheld_port>%1</handheld_port>" ).arg( mPort->value() );
75  config += TQString( "<handheld_user>%1</handheld_user>" ).arg( mUser->text() );
76 
77  config += "</config>";
78 
79  return config;
80 }
81 
82 void ConfigGuiGpe::initGUI()
83 {
84  TQGridLayout *layout = new TQGridLayout( topLayout(), 12, 4, KDialog::spacingHint() );
85  layout->setMargin( KDialog::marginHint() );
86 
87  layout->addWidget( new TQLabel( i18n( "Connection Mode:" ), this ), 0, 0 );
88  mConnectionMode = new KComboBox( this );
89  layout->addMultiCellWidget( mConnectionMode, 0, 0, 0, 3 );
90 
91  layout->addWidget( new TQLabel( i18n( "IP Address:" ), this ), 1, 0 );
92  mIP = new KLineEdit( this );
93  mIP->setInputMask( "000.000.000.000" );
94  layout->addWidget( mIP, 1, 1 );
95 
96  layout->addWidget( new TQLabel( i18n( "Port:" ), this ), 1, 2, TQt::AlignRight );
97  mPort = new TQSpinBox( 1, 65536, 1, this );
98  layout->addWidget( mPort, 1, 3 );
99 
100  layout->addWidget( new TQLabel( i18n( "User:" ), this ), 2, 0 );
101  mUser = new KLineEdit( this );
102  layout->addMultiCellWidget( mUser, 2, 2, 1, 3 );
103 }