summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/blue-pin/pindlg.cc
blob: 3db6095c4396ec7d038f6fab5d96d2bf3597e0cb (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

#include "pindlg.h"

/* OPIE */
#include <qpe/config.h>
#include <qpe/qpeapplication.h>

/* QT */
#include <qcheckbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>

/* STD */
#include <stdio.h>

using namespace OpieTooth;

PinDlg::PinDlg(QWidget* parent,
               const char* name, 
               Qt::WFlags f )
        : PinDlgBase( parent, name, f )
{
    m_mac = makeMacFromArgs();

    if(m_mac.isEmpty())
    {
        // can't obtain MAC
        printf("ERR\n"); 
	::exit(0);
    }
    else
    {
        test( m_mac );
        txtStatus->setText(makeTextFromArgs());
        QPEApplication::showDialog( this , false) ; 
    }
}

PinDlg::~PinDlg()
{}

void PinDlg::setMac( const QString& mac )
{
    txtStatus->setText( mac );
}

QString PinDlg::pin() const
{
    return lnePin->text();
}

void PinDlg::test( const QString& mac )
{
    if (!mac.isEmpty() )
    {
        Config cfg("bluepin");
        cfg.setGroup(mac);
        lnePin->setText(cfg.readEntryCrypt("pin", QString::null ) );
    }
}

QString PinDlg::makeTextFromArgs()
{
    if(qApp->argc() > 2)
    {
        QCString dir(qApp->argv()[1]) ;
        QCString bdaddr(qApp->argv()[2]) ;
        
        QCString name;
        if ( qApp->argc() > 3 ) {
            name = qApp->argv()[3];
        }
        QString status;
        if (dir == "out" ) {
            status = QObject::tr("Outgoing connection to ");
        } else
            status = QObject::tr("Incoming connection from ");

        status += name;
        status += "<br>";
        status += "[" + bdaddr + "]";
        
        return status ;
    }
    else
        return QString::null;
}

QString PinDlg::makeMacFromArgs()
{
    if(qApp->argc() < 3)
        return QString::null;
    else
        return qApp->argv()[2] ;
}

void PinDlg::addnum()
{
    if( sender()->inherits( "QPushButton") ) { 
        const QPushButton* btn = static_cast<const QPushButton*> (sender()); 
        lnePin->setText(lnePin->text() + btn->text());
    }
}

void PinDlg::accept()
{
    if ( ckbPin->isChecked() )
    {
        Config cfg("bluepin");
        cfg.setGroup(m_mac );
        cfg.writeEntryCrypt("pin", lnePin->text() );
    }
    printf("PIN:%s\n", lnePin->text().latin1());
    QDialog::accept();
    qApp->quit();
    ::exit(0);
}