summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp
blob: 7cac13f09b779fb159abca6e98f65e5df179c1fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <qlistview.h>
#include <qdialog.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qtoolbutton.h>
#include <qcheckbox.h>
#include <qspinbox.h>
#include <OTPeer.h>
#include <OTGateway.h>
#include <Opietooth.h>
#include <resources.h>
#include <GUIUtils.h>
#include "bluetoothRFCOMMedit.h"

using namespace Opietooth2;

class PeerLBI : public QListViewItem {

public :

      PeerLBI( OTPeer * P, int Ch, QListView * LV ) : QListViewItem( LV ) {
        Peer = P;
        Channel = Ch;

        setText( 0, (P->name().isEmpty()) ? 
                      P->address().toString() :
                      P->name() );
        QString S;
        S.setNum( Ch );
        setText( 1, S );
        setText( 2, P->address().toString() );
      }
      ~PeerLBI( ) {
      }

      inline int channel( void ) const
        { return Channel; }
      inline OTPeer * peer( void ) const
        { return Peer; }

      int Channel;
      OTPeer * Peer;
};

BluetoothRFCOMMEdit::BluetoothRFCOMMEdit( QWidget * Parent ) : 
      BluetoothRFCOMMGUI( Parent ){
      Modified = 0;
      OT = OTGateway::getOTGateway();

      Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
      Remove_TB->setPixmap( NSResources->getPixmap( "remove" ) );
      FindDevice_TB->setPixmap( NSResources->getPixmap( "Devices/bluetooth" ) );
      Addresses_LV->setColumnAlignment( 1, Qt::AlignRight );
}

BluetoothRFCOMMEdit::~BluetoothRFCOMMEdit( void ) {
      OTGateway::releaseOTGateway();
}

QString BluetoothRFCOMMEdit::acceptable( void ) {
      return QString();
}

bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) {
    int ct = 0;
    PeerLBI * I;

    if( Modified ) {
      QListViewItem * it = Addresses_LV->firstChild();

      Data.Devices.resize( 0 );
      while( it ) {

        ct ++;
        Data.Devices.resize( ct ); 
        I = (PeerLBI * )it;

        Data.Devices.insert( ct-1, new RFCOMMChannel );

        Data.Devices[ct-1]->BDAddress = I->peer()->address().toString();
        Data.Devices[ct-1]->Name = I->peer()->name();
        Data.Devices[ct-1]->Channel = I->channel();

        it = it->nextSibling();
      }
    }

    return Modified;
}

void BluetoothRFCOMMEdit::showData( BluetoothRFCOMMData & Data ) {

    OTPeer * P;

    for( unsigned int i = 0;
         i < Data.Devices.count();
         i ++ ) {
      P = new OTPeer( OT );
      P->setAddress( OTDeviceAddress( Data.Devices[i]->BDAddress ) );
      P->setName( Data.Devices[i]->Name );

      new PeerLBI( P, Data.Devices[i]->Channel, Addresses_LV );
    }
    Modified = 0;
}

void BluetoothRFCOMMEdit::SLOT_AddServer( void ) {
    QListViewItem * it = Addresses_LV->firstChild();

    while( it ) {
      // check address
      if( it->text(2) == Address_LE->text() ) {
        // already in table
        return;
      }
      it = it->nextSibling();
    }

    // new server
    Modified = 1;
    OTPeer * P = new OTPeer( OT );
    P->setAddress( OTDeviceAddress( Address_LE->text() ) );
    P->setName( Name_LBL->text() );
    new PeerLBI( P, Channel_SB->value(), Addresses_LV );

    Address_LE->setText("");
    Name_LBL->setText("");
    Channel_SB->setValue(1);
}

void BluetoothRFCOMMEdit::SLOT_RemoveServer( void ) {

    QListViewItem * it = Addresses_LV->firstChild();

    while( it ) {
      // check address
      if( it->isSelected() ) {
        delete it;
        Modified = 1;
        return;
      }
      it = it->nextSibling();
    }
}

void BluetoothRFCOMMEdit::SLOT_FindDevice( void ) {
    OTPeer * Peer;
    int Channel;

    // find device in Opietooth
    if( OTScan::getDevice( Peer, Channel, OT ) == QDialog::Accepted ) {
      Address_LE->setText( Peer->address().toString() );
      Name_LBL->setText( Peer->name() );
      Channel_SB->setValue( Channel );
    }
}