00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "qtopiaconfig.h"
00024
00025 #include "qtopiakonnector.h"
00026
00027 #include <kapplication.h>
00028 #include <kdialog.h>
00029 #include <klocale.h>
00030 #include <kmessagebox.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
00073 if ( !k )
00074 return;
00075
00076 setCurrent( k->userName(), m_cmbUser );
00077 m_cmbPass->insertItem( k->password() );
00078 m_cmbPass->setCurrentText( k->password() );
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 return;
00093
00094 k->setDestinationIP( m_cmbIP->currentText() );
00095 k->setUserName( m_cmbUser->currentText() );
00096 if ( m_cmbPass->currentText().isEmpty() )
00097 KMessageBox::information( this, i18n( "You have entered an empty password, this will not work with Qtopia1.7/OPIE" ) );
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
00166 m_name->setEnabled( b );
00167 m_lblName->setEnabled( b );
00168
00169 m_cmbUser->setEnabled( !b );
00170 m_lblUser->setEnabled( !b );
00171
00172 m_cmbPass->setEnabled( !b );
00173 m_lblPass->setEnabled( !b );
00174 }
00175
00176 #include "qtopiaconfig.moc"