summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/scandialog.cpp
blob: 842466ad1eaf7a983da3deff9d73ea8b2b5d1372 (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
/* main.cpp
 *
 * ---------------------
 *
 * copyright   : (c) 2002 by Maximilian Reiß
 * email       : max.reiss@gmx.de
 *
 */
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#include "scandialog.h"

#include <qframe.h>
#include <qheader.h>
#include <qlabel.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qprogressbar.h>

#include <manager.h>
#include <device.h>
#include <remotedevice.h>


namespace OpieTooth {

/*
 */
    ScanDialog::ScanDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )
        : QDialog( parent, name, modal, fl ) {

        if ( !name )
            setName( "ScanDialog" );
        resize( 240, 320 );
        setCaption( tr( "Scan for devices" ) );

        Frame7 = new QFrame( this, "Frame7" );
        Frame7->setGeometry( QRect( 0, 0, 240, 331 ) );
        Frame7->setFrameShape( QFrame::StyledPanel );
        Frame7->setFrameShadow( QFrame::Raised );


        QWidget* privateLayoutWidget = new QWidget( Frame7, "Layout11" );
        privateLayoutWidget->setGeometry( QRect( 10, 9, 221, 310 ) );
        Layout11 = new QGridLayout( privateLayoutWidget );
        Layout11->setSpacing( 6 );
        Layout11->setMargin( 0 );


        progress = new QProgressBar(privateLayoutWidget,  "progbar");
        progress->setTotalSteps(20);

        //Layout11->addMultiCellWidget( progress, 1, 1, 0, 1 );
        Layout11->addWidget(progress,  2, 2);

        StartButton = new QPushButton( privateLayoutWidget, "StartButton" );
        StartButton->setText( tr( "Start" ) );

        Layout11->addWidget( StartButton, 2, 0 );

        StopButton = new QPushButton( privateLayoutWidget, "StopButton" );
        StopButton->setText( tr( "Cancel" ) );

        Layout11->addWidget( StopButton, 2, 1 );

        ListView1 = new QListView( privateLayoutWidget, "ListView1" );

        ListView1->addColumn( tr( "Add" ) );
        ListView1->addColumn( tr( "Device Name" ) );
        //ListView1->addColumn( tr( "Type" ) );

        Layout11->addMultiCellWidget( ListView1, 0, 0, 0, 1 );

        connect( (QObject*)StartButton, SIGNAL( clicked() ), this, SLOT( startSearch() ) );
        connect( (QObject*)StopButton, SIGNAL( clicked() ),  this,  SLOT( stopSearch() ) );
        connect( (QObject*)localDevice, SIGNAL( foundDevices( const QString& , RemoteDevices::ValueList ) ),
                 this, SLOT(fillList(const QString& , RemoteDevices::ValueList ) ) ) ;
        progressStat = 0;
    }

// hack, make cleaner later
    void ScanDialog::progressTimer(int maxSeconds) {

        progressStat++;
            if (progressStat++ < maxSeconds) {
                QTimer::singleShot( 1000, this, SLOT(progressTimer ) );
            }

    }

    void ScanDialog::startSearch() {
        progress->setProgress(0);
        progressStat = 0;
         // read it from config later
        localDevice = new Manager( "hci0" );
        progressTimer(20);
        // when finished, it emmite foundDevices()
        // checken ob initialisiert , qcop ans applet.
        localDevice->searchDevices();
        progress->setProgress(20);
    }

    void ScanDialog::stopSearch() {

    }

    void ScanDialog::fillList(const QString& device, RemoteDevices::ValueList deviceList) {

        QListViewItem * deviceItem;

        RemoteDevices::ValueList::Iterator it;
        for( it = deviceList.begin(); it != deviceList.end(); ++it ) {

            deviceItem = new QListViewItem( ListView1, (*it).name() );
        }
    }

/*
 * Cleanup
 */
    ScanDialog::~ScanDialog() {
        delete localDevice;
    }

}