kitchensync

configguiopie.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2006 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 "configguiopie.h"
23 
24 #include <tdelocale.h>
25 
26 #include <tqcombobox.h>
27 #include <tqdom.h>
28 #include <tqlabel.h>
29 #include <tqlayout.h>
30 #include <tqlineedit.h>
31 #include <tqspinbox.h>
32 
33 ConfigGuiOpie::ConfigGuiOpie( const QSync::Member &member, TQWidget *parent )
34  : ConfigGui( member, parent )
35 {
36  TQGridLayout *layout = new TQGridLayout( topLayout() );
37 
38  TQLabel *label = new TQLabel( i18n("Device IP:"), this );
39  layout->addWidget( label, 0, 0 );
40 
41  mDeviceIP = new TQLineEdit( this );
42  mDeviceIP->setInputMask( "000.000.000.000" );
43  label->setBuddy( mDeviceIP );
44  layout->addWidget( mDeviceIP, 0, 1 );
45 
46  label = new TQLabel( i18n("Device Type:"), this );
47  layout->addWidget( label, 1, 0 );
48 
49  mDeviceType = new TQComboBox( this );
50  label->setBuddy( mDeviceType );
51  layout->addWidget( mDeviceType, 1, 1 );
52 
53  label = new TQLabel( i18n("Username:"), this );
54  layout->addWidget( label, 2, 0 );
55 
56  mUserName = new TQLineEdit( this );
57  label->setBuddy( mUserName );
58  layout->addWidget( mUserName, 2, 1 );
59 
60  label = new TQLabel( i18n("Password:"), this );
61  layout->addWidget( label, 3, 0 );
62 
63  mPassword = new TQLineEdit( this );
64  mPassword->setEchoMode( TQLineEdit::Password );
65  label->setBuddy( mPassword );
66  layout->addWidget( mPassword, 3, 1 );
67 
68  label = new TQLabel( i18n("Protocol:"), this );
69  layout->addWidget( label, 4, 0 );
70 
71  mConnectionType = new TQComboBox( this );
72  label->setBuddy( mConnectionType );
73  layout->addWidget( mConnectionType, 4, 1 );
74 
75  label = new TQLabel( i18n("Port:"), this );
76  layout->addWidget( label, 5, 0 );
77 
78  mPort = new TQSpinBox( this );
79  mPort->setRange( 0, 65335 );
80  label->setBuddy( mPort );
81  layout->addWidget( mPort, 5, 1 );
82 
83  mDeviceType->insertItem( i18n("Opie/OpenZaurus") );
84  mDeviceType->insertItem( i18n("TQtopia2") );
85 
86  mConnectionType->insertItem( i18n("SCP") );
87  mConnectionType->insertItem( i18n("FTP") );
88 
89  topLayout()->addStretch( 1 );
90 }
91 
92 void ConfigGuiOpie::load( const TQString &xml )
93 {
94  TQDomDocument doc;
95  doc.setContent( xml );
96  TQDomElement docElement = doc.documentElement();
97  TQDomNode n;
98  for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) {
99  TQDomElement e = n.toElement();
100  if ( e.tagName() == "username" ) {
101  mUserName->setText( e.text() );
102  } else if ( e.tagName() == "password" ) {
103  mPassword->setText( e.text() );
104  } else if ( e.tagName() == "url" ) {
105  mDeviceIP->setText( e.text() );
106  } else if ( e.tagName() == "port" ) {
107  mPort->setValue( e.text().toInt() );
108  } else if ( e.tagName() == "device" ) {
109  if ( e.text() == "opie" )
110  mDeviceType->setCurrentItem( 0 );
111  else
112  mDeviceType->setCurrentItem( 1 );
113  } else if ( e.tagName() == "conntype" ) {
114  if ( e.text() == "scp" )
115  mConnectionType->setCurrentItem( 0 );
116  else
117  mConnectionType->setCurrentItem( 1 );
118  }
119  }
120 }
121 
122 TQString ConfigGuiOpie::save() const
123 {
124  TQString xml;
125  xml = "<config>";
126  xml += "<username>" + mUserName->text() + "</username>";
127  xml += "<password>" + mPassword->text() + "</password>";
128  xml += "<url>" + mDeviceIP->text() + "</url>";
129  xml += "<device>" + TQString( mDeviceType->currentItem() == 0 ? "opie" : "qtopia2" ) + "</device>";
130  xml += "<port>" + TQString::number( mPort->value() ) + "</port>";
131  xml += "<conntype>" + TQString( mConnectionType->currentItem() == 0 ? "scp" : "ftp" ) + "</conntype>";
132  xml += "</config>";
133 
134  return xml;
135 }