kitchensync Library API Documentation

qtopiaconfig.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2002,2003 Holger Freyther <freyther@kde.org> 00005 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 Boston, MA 02111-1307, USA. 00021 */ 00022 00023 #include "qtopiaconfig.h" 00024 00025 #include "qtopiakonnector.h" 00026 00027 #include <kapplication.h> 00028 #include <kdebug.h> 00029 #include <klocale.h> 00030 #include <kdialog.h> 00031 00032 #include <qcombobox.h> 00033 #include <qlabel.h> 00034 00035 using namespace OpieHelper; 00036 00037 namespace { 00038 00039 void setCurrent( const QString &str, QComboBox *box, bool insert = true ) 00040 { 00041 if ( str.isEmpty() ) return; 00042 uint b = box->count(); 00043 for ( uint i = 0; i < b; i++ ) { 00044 if ( box->text(i) == str ) { 00045 box->setCurrentItem(i ); 00046 return; 00047 } 00048 } 00049 if ( !insert ) return; 00050 00051 box->insertItem( str ); 00052 box->setCurrentItem( b ); 00053 } 00054 00055 } 00056 00057 00058 QtopiaConfig::QtopiaConfig( QWidget *parent, const char *name ) 00059 : KRES::ConfigWidget( parent, name ) 00060 { 00061 initUI(); 00062 } 00063 00064 QtopiaConfig::~QtopiaConfig() 00065 { 00066 } 00067 00068 void QtopiaConfig::loadSettings( KRES::Resource *resource ) 00069 { 00070 KSync::QtopiaKonnector *k = 00071 dynamic_cast<KSync::QtopiaKonnector *>( resource ); 00072 if ( !k ) { 00073 kdError() << "QtopiConfig::loadSettings(): Wrong Konnector type." << endl; 00074 return; 00075 } 00076 00077 setCurrent( k->userName(), m_cmbUser ); 00078 setCurrent( k->password(), m_cmbPass ); 00079 setCurrent( k->destinationIP(), m_cmbIP ); 00080 setCurrent( k->model(), m_cmbDev, false ); 00081 if ( m_cmbDev->currentText() == QString::fromLatin1("Sharp Zaurus ROM") ) 00082 m_name->setText( k->modelName() ); 00083 00084 slotTextChanged( m_cmbDev->currentText() ); 00085 } 00086 00087 void QtopiaConfig::saveSettings( KRES::Resource *resource ) 00088 { 00089 KSync::QtopiaKonnector *k = 00090 dynamic_cast<KSync::QtopiaKonnector *>( resource ); 00091 if ( !k ) { 00092 kdError() << "QtopiConfig::loadSettings(): Wrong Konnector type." << endl; 00093 return; 00094 } 00095 00096 k->setDestinationIP( m_cmbIP->currentText() ); 00097 k->setUserName( m_cmbUser->currentText() ); 00098 k->setPassword( m_cmbPass->currentText() ); 00099 k->setModel( m_cmbDev->currentText() ); 00100 k->setModelName( name() ); 00101 } 00102 00103 QString QtopiaConfig::name() const 00104 { 00105 return m_name->text().isEmpty() ? "Zaurus" + kapp->randomString( 5 ) : 00106 m_name->text(); 00107 } 00108 00109 void QtopiaConfig::initUI() 00110 { 00111 m_layout = new QGridLayout( this, 4, 5 ); 00112 m_layout->setSpacing( KDialog::spacingHint() ); 00113 00114 m_lblUser = new QLabel( i18n("User:"), this ); 00115 00116 m_cmbUser = new QComboBox(this); 00117 m_cmbUser->setEditable( true ); 00118 m_cmbUser->insertItem( "root"); 00119 00120 m_lblPass = new QLabel( i18n("Password:"), this ); 00121 00122 m_cmbPass = new QComboBox(this); 00123 m_cmbPass->setEditable( true ); 00124 m_cmbPass->insertItem("Qtopia"); 00125 00126 m_lblName = new QLabel( i18n("Name:"), this ); 00127 00128 m_name = new QLineEdit(this); 00129 m_name->setEnabled( false ); 00130 00131 m_lblIP = new QLabel( i18n("Destination address:"), this ); 00132 00133 m_cmbIP = new QComboBox(this); 00134 m_cmbIP->setEditable( true ); 00135 m_cmbIP->insertItem("1.1.1.1", 0); 00136 m_cmbIP->insertItem("192.168.129.201", 1); 00137 00138 m_lblDev = new QLabel( i18n("Distribution:"), this ); 00139 00140 m_cmbDev = new QComboBox(this); 00141 m_cmbDev->insertItem("Sharp Zaurus ROM"); 00142 m_cmbDev->insertItem("Opie and Qtopia1.6", 0 ); 00143 connect( m_cmbDev, SIGNAL( activated( const QString & ) ), 00144 SLOT( slotTextChanged( const QString & ) ) ); 00145 00146 m_layout->addWidget( m_lblDev, 0, 0 ); 00147 m_layout->addWidget( m_cmbDev, 0, 1 ); 00148 00149 m_layout->addWidget( m_lblUser, 1, 0 ); 00150 m_layout->addWidget( m_cmbUser, 1, 1 ); 00151 00152 m_layout->addWidget( m_lblPass, 1, 2 ); 00153 m_layout->addWidget( m_cmbPass, 1, 3 ); 00154 00155 m_layout->addWidget( m_lblIP, 2, 0 ); 00156 m_layout->addWidget( m_cmbIP, 2, 1 ); 00157 00158 m_layout->addWidget( m_lblName, 2, 2 ); 00159 m_layout->addWidget( m_name, 2, 3 ); 00160 } 00161 00162 void QtopiaConfig::slotTextChanged( const QString &str ) 00163 { 00164 bool b = ( str == QString::fromLatin1("Sharp Zaurus ROM") ); 00165 kdDebug(5225) << "Text Changed to " << str << " " << b <<endl; 00166 00167 m_name->setEnabled( b ); 00168 m_lblName->setEnabled( b ); 00169 00170 m_cmbUser->setEnabled( !b ); 00171 m_lblUser->setEnabled( !b ); 00172 00173 m_cmbPass->setEnabled( !b ); 00174 m_lblPass->setEnabled( !b ); 00175 } 00176 00177 #include "qtopiaconfig.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:32 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003