configguignokii.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2006 David Förster <david@dfoerster.de> 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 "configguignokii.h" 00023 00024 #include <klocale.h> 00025 #include <kdialog.h> 00026 #include <kcombobox.h> 00027 00028 #include <kdebug.h> 00029 00030 #include <tqlayout.h> 00031 #include <tqlabel.h> 00032 #include <tqlineedit.h> 00033 #include <tqcombobox.h> 00034 #include <tqdom.h> 00035 #include <tqvbox.h> 00036 00037 ConfigGuiGnokii::ConfigGuiGnokii( const QSync::Member &member, TQWidget *parent ) 00038 : ConfigGui( member, parent ) 00039 { 00040 TQGridLayout *layout = new TQGridLayout( topLayout() ); 00041 00042 // Model 00043 TQLabel *label = new TQLabel( i18n("Model:"), this ); 00044 layout->addWidget( label, 0, 0 ); 00045 00046 mModel = new KComboBox( true, this ); 00047 layout->addWidget( mModel, 0, 1 ); 00048 mModel->insertItem( "2110" ); 00049 mModel->insertItem( "3110" ); 00050 mModel->insertItem( "6110" ); 00051 mModel->insertItem( "6110" ); 00052 mModel->insertItem( "6160" ); 00053 mModel->insertItem( "6230" ); 00054 mModel->insertItem( "6230i" ); 00055 mModel->insertItem( "6510" ); 00056 mModel->insertItem( "7110" ); 00057 mModel->insertItem( "AT" ); 00058 // This one requires the gnapplet and rfcomm_channel 00059 mModel->insertItem( "3650" ); 00060 mModel->insertItem( "6600" ); 00061 mModel->insertItem( "gnapplet" ); 00062 mModel->insertItem( "symbian" ); 00063 mModel->insertItem( "sx1" ); 00064 00065 connect( mModel, TQT_SIGNAL (activated( int ) ), 00066 this, TQT_SLOT( slotModelChanged () ) ); 00067 00068 // Connection 00069 label = new TQLabel( i18n("Connection:"), this ); 00070 layout->addWidget( label, 1, 0 ); 00071 00072 mConnection = new TQComboBox( this ); 00073 layout->addWidget( mConnection, 1, 1 ); 00074 00075 connect( mConnection, TQT_SIGNAL (activated( int ) ), 00076 this, TQT_SLOT( slotConnectionChanged ( int ) ) ); 00077 00078 // this is a list of all connection types accepted by the gnokii-sync plugin 00079 mConnectionTypes.append( ConnectionType( "bluetooth", i18n( "Bluetooth" ) ) ); 00080 mConnectionTypes.append( ConnectionType( "irda", i18n( "IrDA" ) ) ); 00081 mConnectionTypes.append( ConnectionType( "serial", i18n( "Serial" ) ) ); 00082 mConnectionTypes.append( ConnectionType( "infrared", i18n( "Infrared" ) ) ); 00083 mConnectionTypes.append( ConnectionType( "tcp", i18n( "TCP" ) ) ); 00084 mConnectionTypes.append( ConnectionType( "dku2", i18n( "USB (nokia_dku2)" ) ) ); 00085 mConnectionTypes.append( ConnectionType( "dku2libusb", i18n( "USB (libusb)" ) ) ); 00086 mConnectionTypes.append( ConnectionType( "dau9p", i18n( "Serial (DAU9P cable)" ) ) ); 00087 mConnectionTypes.append( ConnectionType( "dlr3p", i18n( "Serial (DLR3P cable)" ) ) ); 00088 mConnectionTypes.append( ConnectionType( "tekram", i18n( "Tekram Ir-Dongle" ) ) ); 00089 mConnectionTypes.append( ConnectionType( "m2bus", i18n( "Serial (M2BUS protocol)" ) ) ); 00090 00091 ConnectionTypeList::ConstIterator it; 00092 for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) { 00093 mConnection->insertItem( (*it).second ); 00094 } 00095 00096 TQVBox *connectionWidget = new TQVBox( this ); 00097 connectionWidget->setMargin( KDialog::marginHint() ); 00098 connectionWidget->setSpacing( 5 ); 00099 00100 mBluetooth = new BluetoothWidget( connectionWidget ); 00101 mBluetooth->hide(); 00102 00103 layout->addMultiCellWidget( connectionWidget, 2, 2, 0, 1 ); 00104 00105 // Port 00106 mPortLabel = new TQLabel( i18n("Port:"), this ); 00107 layout->addWidget( mPortLabel, 2, 0 ); 00108 mPortLabel->hide(); 00109 00110 mPort = new KComboBox( true, this ); 00111 layout->addWidget( mPort, 2, 1 ); 00112 mPort->hide(); 00113 00114 mPort->insertItem( "/dev/ircomm0" ); 00115 mPort->insertItem( "/dev/ircomm1" ); 00116 mPort->insertItem( "/dev/ttyS0" ); 00117 mPort->insertItem( "/dev/ttyS1" ); 00118 mPort->insertItem( "/dev/ttyUSB0" ); 00119 mPort->insertItem( "/dev/ttyUSB1" ); 00120 00121 layout->setColStretch( 1, 1 ); 00122 00123 topLayout()->addStretch( 1 ); 00124 } 00125 00126 void ConfigGuiGnokii::slotConnectionChanged( int nth ) 00127 { 00128 mPort->hide(); 00129 mPortLabel->hide(); 00130 mBluetooth->hide(); 00131 00132 // Bluetooth 00133 if ( nth == 0 ) { 00134 mBluetooth->show(); 00135 slotModelChanged(); 00136 00137 if ( !mPort->currentText().isEmpty() ) 00138 mBluetooth->setAddress( mPort->currentText() ); 00139 00140 // dku2libusb 00141 } else if ( nth == 6 ) { 00142 // No widget needed. 00143 } else { 00144 mPort->show(); 00145 mPortLabel->show(); 00146 } 00147 00148 } 00149 00150 void ConfigGuiGnokii::slotModelChanged() 00151 { 00152 mBluetooth->hideChannel(); 00153 00154 if ( mModel->currentText() == "gnapplet" 00155 || mModel->currentText() == "symbian" 00156 || mModel->currentText() == "3650" 00157 || mModel->currentText() == "6600" 00158 || mModel->currentText() == "sx1") 00159 mBluetooth->showChannel(); 00160 else 00161 mBluetooth->setChannel(""); 00162 } 00163 00164 void ConfigGuiGnokii::load( const TQString &xml ) 00165 { 00166 TQDomDocument doc; 00167 doc.setContent( xml ); 00168 TQDomElement docElement = doc.documentElement(); 00169 TQDomNode n; 00170 for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { 00171 TQDomElement e = n.toElement(); 00172 if ( e.tagName() == "connection" ) { 00173 for ( uint i = 0; i < mConnectionTypes.count(); i++ ) { 00174 if ( mConnectionTypes[i].first == e.text()) { 00175 mConnection->setCurrentItem( i ); 00176 slotConnectionChanged( i ); 00177 break; 00178 } 00179 } 00180 } else if ( e.tagName() == "port" ) { 00181 mPort->setCurrentText( e.text() ); 00182 } else if ( e.tagName() == "model" ) { 00183 mModel->setCurrentText( e.text() ); 00184 } else if ( e.tagName() == "rfcomm_channel" ) { 00185 mBluetooth->setChannel( e.text() ); 00186 mBluetooth->showChannel(); 00187 } 00188 } 00189 } 00190 00191 TQString ConfigGuiGnokii::save() const 00192 { 00193 TQString xml; 00194 xml = "<config>"; 00195 00196 ConnectionTypeList::ConstIterator it; 00197 for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) { 00198 if ( mConnection->currentText() == (*it).second ) { 00199 xml += "<connection>" + (*it).first + "</connection>"; 00200 break; 00201 } 00202 } 00203 00204 if ( (*it).first == "bluetooth" ) 00205 xml += "<port>" + mBluetooth->address() + "</port>"; 00206 else if ( (*it).first == "dku2libusb" ) 00207 xml += "<port>" + TQString("FF:FF:FF:FF:FF:FF") + "</port>"; // Only place holder for libgnokii 00208 else 00209 xml += "<port>" + mPort->currentText() + "</port>"; 00210 00211 // model 00212 xml += "<model>" + mModel->currentText() + "</model>"; 00213 00214 // rfcomm_channel 00215 if ( !mBluetooth->channel().isNull() ) 00216 xml += "<rfcomm_channel>" + mBluetooth->channel() + "</rfcomm_channel>"; 00217 00218 xml += "</config>"; 00219 00220 return xml; 00221 } 00222 00223 #include "configguignokii.moc"