kitchensync

configguiopie.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2006 Tobias Koenig <tokoe@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019     USA.
00020 */
00021 
00022 #include "configguiopie.h"
00023 
00024 #include <klocale.h>
00025 
00026 #include <tqcombobox.h>
00027 #include <tqdom.h>
00028 #include <tqlabel.h>
00029 #include <tqlayout.h>
00030 #include <tqlineedit.h>
00031 #include <tqspinbox.h>
00032 
00033 ConfigGuiOpie::ConfigGuiOpie( const QSync::Member &member, TQWidget *parent )
00034   : ConfigGui( member, parent )
00035 {
00036   TQGridLayout *layout = new TQGridLayout( topLayout() );
00037 
00038   TQLabel *label = new TQLabel( i18n("Device IP:"), this );
00039   layout->addWidget( label, 0, 0 );
00040 
00041   mDeviceIP = new TQLineEdit( this );
00042   mDeviceIP->setInputMask( "000.000.000.000" );
00043   label->setBuddy( mDeviceIP );
00044   layout->addWidget( mDeviceIP, 0, 1 );
00045 
00046   label = new TQLabel( i18n("Device Type:"), this );
00047   layout->addWidget( label, 1, 0 );
00048 
00049   mDeviceType = new TQComboBox( this );
00050   label->setBuddy( mDeviceType );
00051   layout->addWidget( mDeviceType, 1, 1 );
00052 
00053   label = new TQLabel( i18n("Username:"), this );
00054   layout->addWidget( label, 2, 0 );
00055 
00056   mUserName = new TQLineEdit( this );
00057   label->setBuddy( mUserName );
00058   layout->addWidget( mUserName, 2, 1 );
00059 
00060   label = new TQLabel( i18n("Password:"), this );
00061   layout->addWidget( label, 3, 0 );
00062 
00063   mPassword = new TQLineEdit( this );
00064   mPassword->setEchoMode( TQLineEdit::Password );
00065   label->setBuddy( mPassword );
00066   layout->addWidget( mPassword, 3, 1 );
00067 
00068   label = new TQLabel( i18n("Protocol:"), this );
00069   layout->addWidget( label, 4, 0 );
00070 
00071   mConnectionType = new TQComboBox( this );
00072   label->setBuddy( mConnectionType );
00073   layout->addWidget( mConnectionType, 4, 1 );
00074 
00075   label = new TQLabel( i18n("Port:"), this );
00076   layout->addWidget( label, 5, 0 );
00077 
00078   mPort = new TQSpinBox( this );
00079   mPort->setRange( 0, 65335 );
00080   label->setBuddy( mPort );
00081   layout->addWidget( mPort, 5, 1 );
00082 
00083   mDeviceType->insertItem( i18n("Opie/OpenZaurus") );
00084   mDeviceType->insertItem( i18n("TQtopia2") );
00085 
00086   mConnectionType->insertItem( i18n("SCP") );
00087   mConnectionType->insertItem( i18n("FTP") );
00088 
00089   topLayout()->addStretch( 1 );
00090 }
00091 
00092 void ConfigGuiOpie::load( const TQString &xml )
00093 {
00094   TQDomDocument doc;
00095   doc.setContent( xml );
00096   TQDomElement docElement = doc.documentElement();
00097   TQDomNode n;
00098   for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) {
00099     TQDomElement e = n.toElement();
00100     if ( e.tagName() == "username" ) {
00101       mUserName->setText( e.text() );
00102     } else if ( e.tagName() == "password" ) {
00103       mPassword->setText( e.text() );
00104     } else if ( e.tagName() == "url" ) {
00105       mDeviceIP->setText( e.text() );
00106     } else if ( e.tagName() == "port" ) {
00107       mPort->setValue( e.text().toInt() );
00108     } else if ( e.tagName() == "device" ) {
00109       if ( e.text() == "opie" )
00110         mDeviceType->setCurrentItem( 0 );
00111       else
00112         mDeviceType->setCurrentItem( 1 );
00113     } else if ( e.tagName() == "conntype" ) {
00114       if ( e.text() == "scp" )
00115         mConnectionType->setCurrentItem( 0 );
00116       else
00117         mConnectionType->setCurrentItem( 1 );
00118     }
00119   }
00120 }
00121 
00122 TQString ConfigGuiOpie::save() const
00123 {
00124   TQString xml;
00125   xml = "<config>";
00126   xml += "<username>" + mUserName->text() + "</username>";
00127   xml += "<password>" + mPassword->text() + "</password>";
00128   xml += "<url>" + mDeviceIP->text() + "</url>";
00129   xml += "<device>" + TQString( mDeviceType->currentItem() == 0 ? "opie" : "qtopia2" ) + "</device>";
00130   xml += "<port>" + TQString::number( mPort->value() ) + "</port>";
00131   xml += "<conntype>" + TQString( mConnectionType->currentItem() == 0 ? "scp" : "ftp" ) + "</conntype>";
00132   xml += "</config>";
00133 
00134   return xml;
00135 }