Diffstat (limited to 'noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp | 144 |
1 files changed, 141 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp index d3ddab4..7cac13f 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp | |||
@@ -1,18 +1,156 @@ | |||
1 | #include <qlistview.h> | ||
2 | #include <qdialog.h> | ||
3 | #include <qlabel.h> | ||
4 | #include <qlineedit.h> | ||
5 | #include <qtoolbutton.h> | ||
6 | #include <qcheckbox.h> | ||
7 | #include <qspinbox.h> | ||
8 | #include <OTPeer.h> | ||
9 | #include <OTGateway.h> | ||
10 | #include <Opietooth.h> | ||
11 | #include <resources.h> | ||
1 | #include <GUIUtils.h> | 12 | #include <GUIUtils.h> |
2 | #include "bluetoothRFCOMMedit.h" | 13 | #include "bluetoothRFCOMMedit.h" |
3 | 14 | ||
15 | using namespace Opietooth2; | ||
16 | |||
17 | class PeerLBI : public QListViewItem { | ||
18 | |||
19 | public : | ||
20 | |||
21 | PeerLBI( OTPeer * P, int Ch, QListView * LV ) : QListViewItem( LV ) { | ||
22 | Peer = P; | ||
23 | Channel = Ch; | ||
24 | |||
25 | setText( 0, (P->name().isEmpty()) ? | ||
26 | P->address().toString() : | ||
27 | P->name() ); | ||
28 | QString S; | ||
29 | S.setNum( Ch ); | ||
30 | setText( 1, S ); | ||
31 | setText( 2, P->address().toString() ); | ||
32 | } | ||
33 | ~PeerLBI( ) { | ||
34 | } | ||
35 | |||
36 | inline int channel( void ) const | ||
37 | { return Channel; } | ||
38 | inline OTPeer * peer( void ) const | ||
39 | { return Peer; } | ||
40 | |||
41 | int Channel; | ||
42 | OTPeer * Peer; | ||
43 | }; | ||
44 | |||
4 | BluetoothRFCOMMEdit::BluetoothRFCOMMEdit( QWidget * Parent ) : | 45 | BluetoothRFCOMMEdit::BluetoothRFCOMMEdit( QWidget * Parent ) : |
5 | BluetoothRFCOMMGUI( Parent ){ | 46 | BluetoothRFCOMMGUI( Parent ){ |
47 | Modified = 0; | ||
48 | OT = OTGateway::getOTGateway(); | ||
49 | |||
50 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); | ||
51 | Remove_TB->setPixmap( NSResources->getPixmap( "remove" ) ); | ||
52 | FindDevice_TB->setPixmap( NSResources->getPixmap( "Devices/bluetooth" ) ); | ||
53 | Addresses_LV->setColumnAlignment( 1, Qt::AlignRight ); | ||
54 | } | ||
6 | 55 | ||
56 | BluetoothRFCOMMEdit::~BluetoothRFCOMMEdit( void ) { | ||
57 | OTGateway::releaseOTGateway(); | ||
7 | } | 58 | } |
8 | 59 | ||
9 | QString BluetoothRFCOMMEdit::acceptable( void ) { | 60 | QString BluetoothRFCOMMEdit::acceptable( void ) { |
10 | return QString(); | 61 | return QString(); |
62 | } | ||
63 | |||
64 | bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) { | ||
65 | int ct = 0; | ||
66 | PeerLBI * I; | ||
67 | |||
68 | if( Modified ) { | ||
69 | QListViewItem * it = Addresses_LV->firstChild(); | ||
70 | |||
71 | Data.Devices.resize( 0 ); | ||
72 | while( it ) { | ||
73 | |||
74 | ct ++; | ||
75 | Data.Devices.resize( ct ); | ||
76 | I = (PeerLBI * )it; | ||
77 | |||
78 | Data.Devices.insert( ct-1, new RFCOMMChannel ); | ||
79 | |||
80 | Data.Devices[ct-1]->BDAddress = I->peer()->address().toString(); | ||
81 | Data.Devices[ct-1]->Name = I->peer()->name(); | ||
82 | Data.Devices[ct-1]->Channel = I->channel(); | ||
83 | |||
84 | it = it->nextSibling(); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | return Modified; | ||
11 | } | 89 | } |
12 | 90 | ||
13 | void BluetoothRFCOMMEdit::showData( BluetoothRFCOMMData & Data ) { | 91 | void BluetoothRFCOMMEdit::showData( BluetoothRFCOMMData & Data ) { |
92 | |||
93 | OTPeer * P; | ||
94 | |||
95 | for( unsigned int i = 0; | ||
96 | i < Data.Devices.count(); | ||
97 | i ++ ) { | ||
98 | P = new OTPeer( OT ); | ||
99 | P->setAddress( OTDeviceAddress( Data.Devices[i]->BDAddress ) ); | ||
100 | P->setName( Data.Devices[i]->Name ); | ||
101 | |||
102 | new PeerLBI( P, Data.Devices[i]->Channel, Addresses_LV ); | ||
103 | } | ||
104 | Modified = 0; | ||
14 | } | 105 | } |
15 | 106 | ||
16 | bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) { | 107 | void BluetoothRFCOMMEdit::SLOT_AddServer( void ) { |
17 | return 0; | 108 | QListViewItem * it = Addresses_LV->firstChild(); |
109 | |||
110 | while( it ) { | ||
111 | // check address | ||
112 | if( it->text(2) == Address_LE->text() ) { | ||
113 | // already in table | ||
114 | return; | ||
115 | } | ||
116 | it = it->nextSibling(); | ||
117 | } | ||
118 | |||
119 | // new server | ||
120 | Modified = 1; | ||
121 | OTPeer * P = new OTPeer( OT ); | ||
122 | P->setAddress( OTDeviceAddress( Address_LE->text() ) ); | ||
123 | P->setName( Name_LBL->text() ); | ||
124 | new PeerLBI( P, Channel_SB->value(), Addresses_LV ); | ||
125 | |||
126 | Address_LE->setText(""); | ||
127 | Name_LBL->setText(""); | ||
128 | Channel_SB->setValue(1); | ||
129 | } | ||
130 | |||
131 | void BluetoothRFCOMMEdit::SLOT_RemoveServer( void ) { | ||
132 | |||
133 | QListViewItem * it = Addresses_LV->firstChild(); | ||
134 | |||
135 | while( it ) { | ||
136 | // check address | ||
137 | if( it->isSelected() ) { | ||
138 | delete it; | ||
139 | Modified = 1; | ||
140 | return; | ||
141 | } | ||
142 | it = it->nextSibling(); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | void BluetoothRFCOMMEdit::SLOT_FindDevice( void ) { | ||
147 | OTPeer * Peer; | ||
148 | int Channel; | ||
149 | |||
150 | // find device in Opietooth | ||
151 | if( OTScan::getDevice( Peer, Channel, OT ) == QDialog::Accepted ) { | ||
152 | Address_LE->setText( Peer->address().toString() ); | ||
153 | Name_LBL->setText( Peer->name() ); | ||
154 | Channel_SB->setValue( Channel ); | ||
155 | } | ||
18 | } | 156 | } |