00001 #include <qlistview.h>
00002 #include <qdialog.h>
00003 #include <qlabel.h>
00004 #include <qlineedit.h>
00005 #include <qtoolbutton.h>
00006 #include <qcheckbox.h>
00007 #include <qspinbox.h>
00008 #include <OTPeer.h>
00009 #include <OTGateway.h>
00010 #include <Opietooth.h>
00011 #include <resources.h>
00012 #include <GUIUtils.h>
00013 #include "bluetoothRFCOMMedit.h"
00014
00015 using namespace Opietooth2;
00016
00017 class PeerLBI : public QListViewItem {
00018
00019 public :
00020
00021 PeerLBI( OTPeer * P, int Ch, QListView * LV ) : QListViewItem( LV ) {
00022 Peer = P;
00023 Channel = Ch;
00024
00025 setText( 0, (P->name().isEmpty()) ?
00026 P->address().toString() :
00027 P->name() );
00028 QString S;
00029 S.setNum( Ch );
00030 setText( 1, S );
00031 setText( 2, P->address().toString() );
00032 }
00033 ~PeerLBI( ) {
00034 }
00035
00036 inline int channel( void ) const
00037 { return Channel; }
00038 inline OTPeer * peer( void ) const
00039 { return Peer; }
00040
00041 int Channel;
00042 OTPeer * Peer;
00043 };
00044
00045 BluetoothRFCOMMEdit::BluetoothRFCOMMEdit( QWidget * Parent ) :
00046 BluetoothRFCOMMGUI( Parent ){
00047 Modified = 0;
00048 OT = OTGateway::getOTGateway();
00049
00050 Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
00051 Remove_TB->setPixmap( NSResources->getPixmap( "remove" ) );
00052 FindDevice_TB->setPixmap( NSResources->getPixmap( "Devices/bluetooth" ) );
00053 Addresses_LV->setColumnAlignment( 1, Qt::AlignRight );
00054 }
00055
00056 BluetoothRFCOMMEdit::~BluetoothRFCOMMEdit( void ) {
00057 OTGateway::releaseOTGateway();
00058 }
00059
00060 QString BluetoothRFCOMMEdit::acceptable( void ) {
00061 return QString();
00062 }
00063
00064 bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) {
00065 int ct = 0;
00066 PeerLBI * I;
00067
00068 if( Modified ) {
00069 QListViewItem * it = Addresses_LV->firstChild();
00070
00071 Data.Devices.resize( 0 );
00072 while( it ) {
00073
00074 ct ++;
00075 Data.Devices.resize( ct );
00076 I = (PeerLBI * )it;
00077
00078 Data.Devices.insert( ct-1, new RFCOMMChannel );
00079
00080 Data.Devices[ct-1]->BDAddress = I->peer()->address().toString();
00081 Data.Devices[ct-1]->Name = I->peer()->name();
00082 Data.Devices[ct-1]->Channel = I->channel();
00083
00084 it = it->nextSibling();
00085 }
00086 }
00087
00088 return Modified;
00089 }
00090
00091 void BluetoothRFCOMMEdit::showData( BluetoothRFCOMMData & Data ) {
00092
00093 OTPeer * P;
00094
00095 for( unsigned int i = 0;
00096 i < Data.Devices.count();
00097 i ++ ) {
00098 P = new OTPeer( OT );
00099 P->setAddress( OTDeviceAddress( Data.Devices[i]->BDAddress ) );
00100 P->setName( Data.Devices[i]->Name );
00101
00102 new PeerLBI( P, Data.Devices[i]->Channel, Addresses_LV );
00103 }
00104 Modified = 0;
00105 }
00106
00107 void BluetoothRFCOMMEdit::SLOT_AddServer( void ) {
00108 QListViewItem * it = Addresses_LV->firstChild();
00109
00110 while( it ) {
00111
00112 if( it->text(2) == Address_LE->text() ) {
00113
00114 return;
00115 }
00116 it = it->nextSibling();
00117 }
00118
00119
00120 Modified = 1;
00121 OTPeer * P = new OTPeer( OT );
00122 P->setAddress( OTDeviceAddress( Address_LE->text() ) );
00123 P->setName( Name_LBL->text() );
00124 new PeerLBI( P, Channel_SB->value(), Addresses_LV );
00125
00126 Address_LE->setText("");
00127 Name_LBL->setText("");
00128 Channel_SB->setValue(1);
00129 }
00130
00131 void BluetoothRFCOMMEdit::SLOT_RemoveServer( void ) {
00132
00133 QListViewItem * it = Addresses_LV->firstChild();
00134
00135 while( it ) {
00136
00137 if( it->isSelected() ) {
00138 delete it;
00139 Modified = 1;
00140 return;
00141 }
00142 it = it->nextSibling();
00143 }
00144 }
00145
00146 void BluetoothRFCOMMEdit::SLOT_FindDevice( void ) {
00147 OTPeer * Peer;
00148 int Channel;
00149
00150
00151 if( OTScan::getDevice( Peer, Channel, OT ) == QDialog::Accepted ) {
00152 Address_LE->setText( Peer->address().toString() );
00153 Name_LBL->setText( Peer->name() );
00154 Channel_SB->setValue( Channel );
00155 }
00156 }