summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/rfcommassigndialogimpl.cpp
blob: be720b8b8e768fd5aa58a198c8ed1ce0b33b7cb8 (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

#include "rfcommassigndialogimpl.h"
#include "rfcommassigndialogitem.h"
#include "rfcommconfhandler.h"

/* OPIE */
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
#include <opie2/odebug.h>
using namespace Opie::Core;

/* QT */
#include <qlayout.h>

using namespace OpieTooth;

// TODO: write only the file in bluebase?
// muss rfcommd dann neu gestartet werden
// sollte rfcomm bind all nicht eh default config sein ( polled das? - d.h. sobald nen gerät in der nähe ist bindet es?


RfcommAssignDialog::RfcommAssignDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )
        : RfcommAssignDialogBase( parent, name, modal, fl )
{

    m_range = 5;

    m_scrollView = new QScrollView( this );
    m_scrollView->setResizePolicy( QScrollView::AutoOneFit );
    m_scrollView->setHScrollBarMode( QScrollView::AlwaysOff );

    RfcommAssignDialogBaseLayout->addWidget( m_scrollView );

    m_box = new QVBox( m_scrollView->viewport() );
    m_scrollView->addChild( m_box );

    confHandler = new RfCommConfHandler( "/etc/bluetooth/rfcomm.conf" );

    loadConfig();
}

RfcommAssignDialog::~RfcommAssignDialog()
{
    if ( confHandler )
    {
        delete confHandler;
    }
}


void RfcommAssignDialog::newDevice( const QString & mac )
{

    for ( int i = 0 ; i < m_range; i++ )
    {

        QMap<QString, RfCommConfObject*>::Iterator it;
        it = confHandler->foundEntries().find( QString("%1").arg( i ) );
        // make sure that rfcommX is not assigned yet
        if (  it == confHandler->foundEntries().end() )
        {
            QDialog dialog( this,  "newdevice", true, WStyle_ContextHelp );
            dialog.setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, 
                (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth()));

            RfcommDialogItem *newDev = new RfcommDialogItem( &dialog );
            newDev->setIdent( i );
            newDev->setMac( mac );

            if ( QPEApplication::execDialog( &dialog ) == QDialog::Accepted )
            {
                RfcommDialogItem *rfcomm = new RfcommDialogItem( m_box );
                m_itemList.insert( i , rfcomm );
                rfcomm->setIdent( i );
                rfcomm->setMac( mac );
                rfcomm->setChannel( newDev->channel() );
                rfcomm->setComment( newDev->comment() );
                odebug << "New device set up" << oendl; 
            }
        }
    }
}

void RfcommAssignDialog::loadConfig()
{

    //Config cfg( "bluetoothmanager-rfcommbind" );

    for ( int i = 0 ; i < m_range; i++ )
    {
        // cfg.setGroup( QString("%1").arg( i ) );
        RfcommDialogItem *rfcomm = new RfcommDialogItem( m_box );
        m_itemList.insert( i , rfcomm );
        rfcomm->setIdent( i );
        QMap<QString, RfCommConfObject*>::Iterator it;
        it = confHandler->foundEntries().find( QString("%1").arg( i ) );
        if ( it != confHandler->foundEntries().end() )
        {
            odebug << "Found key in foundEntries() " << oendl; 
            rfcomm->setMac( it.data()->mac() );
            rfcomm->setChannel( it.data()->channel() );
            rfcomm->setComment( it.data()->comment() );
        }
        /* Use rfcomm.conf directly for now
         * rfcomm->setMac( cfg.readEntry( "mac",  "" ) );
         * rfcomm->setChannel( cfg.readNumEntry( "channel", 1 ) );
         * rfcomm->setComment( cfg.readEntry( "comment", "" ) );
         */
    }
}


void RfcommAssignDialog::saveConfig()
{

    //Config cfg( "bluetoothmanager-rfcommbind" );

    QMap< int, RfcommDialogItem*>::Iterator it;

    QMap< QString, RfCommConfObject*> outMap;

    for( it = m_itemList.begin(); it != m_itemList.end(); ++it )
    {

        //cfg.setGroup( QString("%1").arg( it.key() ) );
        RfcommDialogItem *rfcomm = it.data();


        outMap.insert( QString( "%1").arg( it.key() ), new RfCommConfObject( it.key(), rfcomm->mac(), rfcomm->channel(),  rfcomm->comment() ) );


        //cfg.writeEntry( "mac",  rfcomm->mac() );
        //cfg.writeEntry( "channel", rfcomm->channel() );
        //cfg.writeEntry( "comment", rfcomm->comment() );
    }

    confHandler->save( outMap );

}