configguipalm.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2005 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 <kcombobox.h> 00023 #include <kdialog.h> 00024 #include <klineedit.h> 00025 #include <klocale.h> 00026 00027 #include <tqbuttongroup.h> 00028 #include <tqcheckbox.h> 00029 #include <tqdom.h> 00030 #include <tqlabel.h> 00031 #include <tqlayout.h> 00032 #include <tqradiobutton.h> 00033 #include <tqspinbox.h> 00034 #include <tqtabwidget.h> 00035 00036 #include "configguipalm.h" 00037 00038 ConfigGuiPalm::ConfigGuiPalm( const QSync::Member &member, TQWidget *parent ) 00039 : ConfigGui( member, parent ) 00040 { 00041 initGUI(); 00042 00043 mDevice->insertItem( "/dev/pilot" ); 00044 mDevice->insertItem( "/dev/ttyUSB0" ); 00045 mDevice->insertItem( "/dev/ttyUSB1" ); 00046 mDevice->insertItem( "/dev/ttyUSB2" ); 00047 mDevice->insertItem( "/dev/ttyUSB3" ); 00048 00049 mSpeed->insertItem( "9600" ); 00050 mSpeed->insertItem( "19200" ); 00051 mSpeed->insertItem( "38400" ); 00052 mSpeed->insertItem( "57600" ); 00053 mSpeed->insertItem( "115200" ); 00054 } 00055 00056 void ConfigGuiPalm::load( const TQString &xml ) 00057 { 00058 TQDomDocument doc; 00059 doc.setContent( xml ); 00060 TQDomElement docElement = doc.documentElement(); 00061 TQDomNode node; 00062 for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { 00063 TQDomElement element = node.toElement(); 00064 if ( element.tagName() == "sockaddr" ) { 00065 mDevice->setCurrentText( element.text() ); 00066 } else if ( element.tagName() == "speed" ) { 00067 mSpeed->setCurrentText( element.text() ); 00068 } else if ( element.tagName() == "timeout" ) { 00069 mTimeout->setValue( element.text().toInt() ); 00070 } else if ( element.tagName() == "username" ) { 00071 mUserName->setText( element.text() ); 00072 } else if ( element.tagName() == "mismatch" ) { 00073 switch ( element.text().toInt() ) { 00074 case 0: 00075 mSyncAlways->setChecked( true ); 00076 break; 00077 case 2: 00078 mSyncAbort->setChecked( true ); 00079 break; 00080 case 1: 00081 default: 00082 mSyncAsk->setChecked( true ); 00083 break; 00084 } 00085 } else if ( element.tagName() == "popup" ) { 00086 mPopup->setChecked( element.text() == "1" ); 00087 } 00088 } 00089 } 00090 00091 TQString ConfigGuiPalm::save() const 00092 { 00093 TQString config = "<config>"; 00094 00095 config += "<sockaddr>" + mDevice->currentText() + "</sockaddr>"; 00096 config += "<username>" + mUserName->text() + "</username>"; 00097 config += "<timeout>" + TQString::number( mTimeout->value() ) + "</timeout>"; 00098 config += "<type>0</type>"; 00099 config += "<speed>" + mSpeed->currentText() + "</speed>"; 00100 config += "<id>0</id>"; 00101 config += "<codepage>cp1252</codepage>"; 00102 config += "<popup>" + TQString( mPopup->isChecked() ? "1" : "0" ) + "</popup>"; 00103 00104 TQString popup; 00105 if ( mSyncAlways->isChecked() ) 00106 popup = "0"; 00107 else if ( mSyncAsk->isChecked() ) 00108 popup = "1"; 00109 else if ( mSyncAbort->isChecked() ) 00110 popup = "2"; 00111 00112 config += "<mismatch>" + popup + "</mismatch>"; 00113 00114 config += "</config>"; 00115 00116 return config; 00117 } 00118 00119 void ConfigGuiPalm::initGUI() 00120 { 00121 TQFont boldFont = font(); 00122 boldFont.setBold( true ); 00123 00124 TQTabWidget *tabWidget = new TQTabWidget( this ); 00125 00126 TQWidget *connectionWidget = new TQWidget( tabWidget ); 00127 TQVBoxLayout *connectionLayout = new TQVBoxLayout( connectionWidget, 00128 KDialog::marginHint(), KDialog::spacingHint() ); 00129 00130 TQLabel *label = new TQLabel( i18n( "Connection" ), connectionWidget ); 00131 label->setFont( boldFont ); 00132 connectionLayout->addWidget( label ); 00133 00134 TQGridLayout *gridLayout = new TQGridLayout( connectionLayout, 3, 2, KDialog::spacingHint() ); 00135 gridLayout->setMargin( KDialog::marginHint() ); 00136 00137 gridLayout->addWidget( new TQLabel( i18n( "Port:" ), connectionWidget ), 0, 0 ); 00138 gridLayout->addWidget( new TQLabel( i18n( "Speed:" ), connectionWidget ), 1, 0 ); 00139 gridLayout->addWidget( new TQLabel( i18n( "Timeout:" ), connectionWidget ), 2, 0 ); 00140 00141 mDevice = new KComboBox( true, connectionWidget ); 00142 mSpeed = new KComboBox( connectionWidget ); 00143 mTimeout = new TQSpinBox( 1, 60, 1, connectionWidget ); 00144 mTimeout->setSuffix( i18n( " sec" ) ); 00145 00146 gridLayout->addWidget( mDevice, 0, 1 ); 00147 gridLayout->addWidget( mSpeed, 1, 1 ); 00148 gridLayout->addWidget( mTimeout, 2, 1 ); 00149 gridLayout->setColStretch( 1, 1 ); 00150 00151 label = new TQLabel( i18n( "User" ), connectionWidget ); 00152 label->setFont( boldFont ); 00153 connectionLayout->addWidget( label ); 00154 00155 gridLayout = new TQGridLayout( connectionLayout, 1, 2, KDialog::spacingHint() ); 00156 gridLayout->setMargin( KDialog::marginHint() ); 00157 00158 gridLayout->addWidget( new TQLabel( i18n( "Username:" ), connectionWidget ), 0, 0 ); 00159 00160 mUserName = new KLineEdit( connectionWidget ); 00161 gridLayout->addWidget( mUserName, 0, 1 ); 00162 00163 label = new TQLabel( i18n( "What to do if Username does not match" ), connectionWidget ); 00164 label->setFont( boldFont ); 00165 connectionLayout->addWidget( label ); 00166 00167 gridLayout = new TQGridLayout( connectionLayout, 1, 2, KDialog::spacingHint() ); 00168 gridLayout->setMargin( KDialog::marginHint() ); 00169 00170 TQButtonGroup *buttonGroup = new TQButtonGroup( 1, Qt::Horizontal, connectionWidget ); 00171 buttonGroup->setExclusive( true ); 00172 buttonGroup->setFrameStyle( TQFrame::NoFrame ); 00173 mSyncAlways = new TQRadioButton( i18n( "Sync Anyway" ), buttonGroup ); 00174 mSyncAsk = new TQRadioButton( i18n( "Ask What To Do" ), buttonGroup ); 00175 mSyncAbort = new TQRadioButton( i18n( "Abort Sync" ), buttonGroup ); 00176 00177 gridLayout->addMultiCellWidget( buttonGroup, 0, 0, 0, 1 ); 00178 00179 connectionLayout->addStretch( 1 ); 00180 tabWidget->addTab( connectionWidget, i18n( "Connection" ) ); 00181 00182 TQWidget *optionWidget = new TQWidget( tabWidget ); 00183 TQVBoxLayout *optionLayout = new TQVBoxLayout( optionWidget, 00184 KDialog::marginHint(), KDialog::spacingHint() ); 00185 00186 label = new TQLabel( i18n( "Hotsync Notification" ), optionWidget ); 00187 label->setFont( boldFont ); 00188 optionLayout->addWidget( label ); 00189 00190 gridLayout = new TQGridLayout( optionLayout, 1, 2, KDialog::spacingHint() ); 00191 gridLayout->setMargin( KDialog::marginHint() ); 00192 00193 mPopup = new TQCheckBox( i18n( "Popup when interaction is required" ), optionWidget ); 00194 gridLayout->addMultiCellWidget( mPopup, 0, 0, 0, 1 ); 00195 00196 optionLayout->addStretch( 1 ); 00197 tabWidget->addTab( optionWidget, i18n( "Options" ) ); 00198 00199 topLayout()->addWidget( tabWidget ); 00200 }