-rw-r--r-- | noncore/net/opietooth/manager/scandialog.cpp | 21 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/scandialog.h | 4 |
2 files changed, 18 insertions, 7 deletions
diff --git a/noncore/net/opietooth/manager/scandialog.cpp b/noncore/net/opietooth/manager/scandialog.cpp index f8f7b15..ec8df82 100644 --- a/noncore/net/opietooth/manager/scandialog.cpp +++ b/noncore/net/opietooth/manager/scandialog.cpp | |||
@@ -1,171 +1,180 @@ | |||
1 | /* main.cpp | 1 | /* main.cpp |
2 | * | 2 | * |
3 | * --------------------- | 3 | * --------------------- |
4 | * | 4 | * |
5 | * copyright : (c) 2002 by Maximilian Reiß | 5 | * copyright : (c) 2002 by Maximilian Reiß |
6 | * email : max.reiss@gmx.de | 6 | * email : max.reiss@gmx.de |
7 | * | 7 | * |
8 | */ | 8 | */ |
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | 18 | ||
19 | #include "scandialog.h" | 19 | #include "scandialog.h" |
20 | 20 | ||
21 | #include <qframe.h> | 21 | #include <qframe.h> |
22 | #include <qheader.h> | 22 | #include <qheader.h> |
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qlistview.h> | 24 | #include <qlistview.h> |
25 | #include <qpushbutton.h> | 25 | #include <qpushbutton.h> |
26 | #include <qlayout.h> | 26 | #include <qlayout.h> |
27 | #include <qvariant.h> | 27 | #include <qvariant.h> |
28 | #include <qtooltip.h> | 28 | #include <qtooltip.h> |
29 | #include <qwhatsthis.h> | 29 | #include <qwhatsthis.h> |
30 | #include <qprogressbar.h> | 30 | #include <qprogressbar.h> |
31 | #include <qlist.h> | 31 | #include <qlist.h> |
32 | 32 | ||
33 | #include <manager.h> | 33 | #include <manager.h> |
34 | #include <device.h> | 34 | #include <device.h> |
35 | 35 | ||
36 | 36 | ||
37 | 37 | ||
38 | namespace OpieTooth { | 38 | namespace OpieTooth { |
39 | 39 | ||
40 | #include <remotedevice.h> | 40 | #include <remotedevice.h> |
41 | 41 | ||
42 | /* | 42 | /* |
43 | */ | 43 | */ |
44 | ScanDialog::ScanDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) | 44 | ScanDialog::ScanDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) |
45 | : QDialog( parent, name, modal, fl ) { | 45 | : QDialog( parent, name, modal, fl ) { |
46 | 46 | ||
47 | if ( !name ) | 47 | if ( !name ) |
48 | setName( "ScanDialog" ); | 48 | setName( "ScanDialog" ); |
49 | resize( 240, 320 ); | 49 | resize( 240, 320 ); |
50 | setCaption( tr( "Scan for devices" ) ); | 50 | setCaption( tr( "Scan for devices" ) ); |
51 | 51 | ||
52 | Frame7 = new QFrame( this, "Frame7" ); | 52 | Frame7 = new QFrame( this, "Frame7" ); |
53 | Frame7->setGeometry( QRect( 0, 0, 240, 331 ) ); | 53 | Frame7->setGeometry( QRect( 0, 0, 240, 331 ) ); |
54 | Frame7->setFrameShape( QFrame::StyledPanel ); | 54 | Frame7->setFrameShape( QFrame::StyledPanel ); |
55 | Frame7->setFrameShadow( QFrame::Raised ); | 55 | Frame7->setFrameShadow( QFrame::Raised ); |
56 | 56 | ||
57 | QWidget* privateLayoutWidget = new QWidget( Frame7, "Layout11" ); | 57 | QWidget* privateLayoutWidget = new QWidget( Frame7, "Layout11" ); |
58 | privateLayoutWidget->setGeometry( QRect( 10, 9, 221, 280 ) ); | 58 | privateLayoutWidget->setGeometry( QRect( 10, 9, 221, 280 ) ); |
59 | Layout11 = new QVBoxLayout( privateLayoutWidget ); | 59 | Layout11 = new QVBoxLayout( privateLayoutWidget ); |
60 | Layout11->setSpacing( 6 ); | 60 | Layout11->setSpacing( 6 ); |
61 | Layout11->setMargin( 0 ); | 61 | Layout11->setMargin( 0 ); |
62 | 62 | ||
63 | progress = new QProgressBar(privateLayoutWidget, "progbar"); | 63 | progress = new QProgressBar(privateLayoutWidget, "progbar"); |
64 | progress->setTotalSteps(20); | 64 | progress->setTotalSteps(20); |
65 | 65 | ||
66 | QFrame *buttonFrame = new QFrame(Frame7, ""); | 66 | QFrame *buttonFrame = new QFrame(Frame7, ""); |
67 | 67 | ||
68 | StartButton = new QPushButton( buttonFrame, "StartButton" ); | 68 | StartButton = new QPushButton( buttonFrame, "StartButton" ); |
69 | StartButton->setText( tr( "Start scan" ) ); | 69 | StartButton->setText( tr( "Start scan" ) ); |
70 | 70 | ||
71 | StopButton = new QPushButton( buttonFrame, "StopButton" ); | 71 | StopButton = new QPushButton( buttonFrame, "StopButton" ); |
72 | StopButton->setText( tr( "Cancel scan" ) ); | 72 | StopButton->setText( tr( "Cancel scan" ) ); |
73 | 73 | ||
74 | QHBoxLayout *buttonLayout = new QHBoxLayout(buttonFrame); | 74 | QHBoxLayout *buttonLayout = new QHBoxLayout(buttonFrame); |
75 | 75 | ||
76 | buttonLayout->addWidget(StartButton); | 76 | buttonLayout->addWidget(StartButton); |
77 | buttonLayout->addWidget(StopButton); | 77 | buttonLayout->addWidget(StopButton); |
78 | 78 | ||
79 | ListView1 = new QListView( privateLayoutWidget, "ListView1" ); | 79 | ListView1 = new QListView( privateLayoutWidget, "ListView1" ); |
80 | 80 | ||
81 | //ListView1->addColumn( tr( "Add" ) ); | 81 | //ListView1->addColumn( tr( "Add" ) ); |
82 | ListView1->addColumn( tr( "Add Device" ) ); | 82 | ListView1->addColumn( tr( "Add Device" ) ); |
83 | //ListView1->addColumn( tr( "Type" ) ); | 83 | //ListView1->addColumn( tr( "Type" ) ); |
84 | 84 | ||
85 | Layout11->addWidget( ListView1); | 85 | Layout11->addWidget( ListView1); |
86 | Layout11->addWidget(progress); | 86 | Layout11->addWidget(progress); |
87 | Layout11->addWidget( buttonFrame); | 87 | Layout11->addWidget( buttonFrame); |
88 | 88 | ||
89 | localDevice = new Manager( "hci0" ); | 89 | localDevice = new Manager( "hci0" ); |
90 | 90 | ||
91 | connect( (QObject*)StartButton, SIGNAL( clicked() ), this, SLOT( startSearch() ) ); | 91 | connect( StartButton, SIGNAL( clicked() ), this, SLOT( startSearch() ) ); |
92 | connect( (QObject*)StopButton, SIGNAL( clicked() ), this, SLOT( stopSearch() ) ); | 92 | connect( StopButton, SIGNAL( clicked() ), this, SLOT( stopSearch() ) ); |
93 | connect( (QObject*)localDevice, SIGNAL( foundDevices( const QString& , RemoteDevices::ValueList ) ), | 93 | connect( localDevice, SIGNAL( foundDevices( const QString& , RemoteDevice::ValueList ) ), |
94 | this, SLOT(fillList(const QString& , RemoteDevices::ValueList ) ) ) ; | 94 | this, SLOT(fillList(const QString& , RemoteDevice::ValueList ) ) ) ; |
95 | // connect( this, SIGNAL( accept() ), this, SLOT( emitToManager() )); | ||
95 | progressStat = 0; | 96 | progressStat = 0; |
96 | } | 97 | } |
97 | 98 | ||
98 | // hack, make cleaner later | 99 | // hack, make cleaner later |
99 | void ScanDialog::progressTimer() { | 100 | void ScanDialog::progressTimer() { |
100 | 101 | ||
101 | progressStat++; | 102 | progressStat++; |
102 | if (progressStat++ < 20) { | 103 | if (progressStat++ < 20) { |
103 | QTimer::singleShot( 1000, this, SLOT(progressTimer() ) ); | 104 | QTimer::singleShot( 1000, this, SLOT(progressTimer() ) ); |
104 | } | 105 | } |
105 | progress->setProgress(progressStat++); | 106 | progress->setProgress(progressStat++); |
106 | 107 | ||
107 | } | 108 | } |
108 | 109 | ||
110 | void ScanDialog::accept() { | ||
111 | emitToManager(); | ||
112 | QDialog::accept(); | ||
113 | } | ||
114 | |||
115 | |||
109 | void ScanDialog::startSearch() { | 116 | void ScanDialog::startSearch() { |
110 | progress->setProgress(0); | 117 | progress->setProgress(0); |
111 | progressStat = 0; | 118 | progressStat = 0; |
112 | 119 | ||
113 | QCheckListItem *deviceItem2 = new QCheckListItem( ListView1, "Test1", QCheckListItem::CheckBox ); | 120 | QCheckListItem *deviceItem2 = new QCheckListItem( ListView1, "Test1", QCheckListItem::CheckBox ); |
114 | deviceItem2->setText(1, "BLAH" ); | 121 | deviceItem2->setText(1, "BLAH" ); |
115 | 122 | ||
116 | progressTimer(); | 123 | progressTimer(); |
117 | // when finished, it emmite foundDevices() | 124 | // when finished, it emmite foundDevices() |
118 | // checken ob initialisiert , qcop ans applet. | 125 | // checken ob initialisiert , qcop ans applet. |
119 | localDevice->searchDevices(); | 126 | localDevice->searchDevices(); |
120 | 127 | ||
121 | } | 128 | } |
122 | 129 | ||
123 | void ScanDialog::stopSearch() { | 130 | void ScanDialog::stopSearch() { |
124 | 131 | ||
125 | } | 132 | } |
126 | 133 | ||
127 | void ScanDialog::fillList(const QString& device, RemoteDevice::ValueList deviceList) { | 134 | void ScanDialog::fillList(const QString& device, RemoteDevice::ValueList deviceList) { |
128 | 135 | ||
136 | qDebug("fill List"); | ||
129 | QCheckListItem * deviceItem; | 137 | QCheckListItem * deviceItem; |
130 | 138 | ||
131 | RemoteDevice::ValueList::Iterator it; | 139 | RemoteDevice::ValueList::Iterator it; |
132 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { | 140 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) { |
133 | 141 | ||
134 | deviceItem = new QCheckListItem( ListView1, (*it).name() ); | 142 | deviceItem = new QCheckListItem( ListView1, (*it).name(), QCheckListItem::CheckBox ); |
135 | deviceItem->setText(1, (*it).mac() ); | 143 | deviceItem->setText(1, (*it).mac() ); |
136 | } | 144 | } |
137 | } | 145 | } |
138 | 146 | ||
139 | /* | 147 | /* |
140 | * Iterates trough the items, and collects the checked items. | 148 | * Iterates trough the items, and collects the checked items. |
141 | * Then it emits it, so the manager can connect to the signal to fill the listing. | 149 | * Then it emits it, so the manager can connect to the signal to fill the listing. |
142 | */ | 150 | */ |
143 | void ScanDialog::emitToManager() { | 151 | void ScanDialog::emitToManager() { |
152 | qDebug("vor liste durchsuchen"); | ||
144 | 153 | ||
145 | if (!ListView1) { | 154 | if (!ListView1) { |
146 | return; | 155 | return; |
147 | } | 156 | } |
148 | 157 | ||
149 | QList<RemoteDevice> *deviceList = new QList<RemoteDevice>; | 158 | QList<RemoteDevice> *deviceList = new QList<RemoteDevice>; |
150 | deviceList->setAutoDelete(true); | 159 | deviceList->setAutoDelete(true); |
151 | 160 | ||
152 | QListViewItemIterator it( ListView1 ); | 161 | QListViewItemIterator it( ListView1 ); |
153 | for ( ; it.current(); ++it ) { | 162 | for ( ; it.current(); ++it ) { |
154 | if ( ((QCheckListItem*)it.current())->isOn() ) { | 163 | if ( ((QCheckListItem*)it.current())->isOn() ) { |
155 | RemoteDevice * device = new RemoteDevice( it.current()->text(1), it.current()->text(0)); | 164 | RemoteDevice * device = new RemoteDevice( it.current()->text(1), it.current()->text(0)); |
156 | deviceList->append( device ); | 165 | deviceList->append( device ); |
157 | } | 166 | } |
158 | } | 167 | } |
168 | qDebug("vor emit"); | ||
159 | emit selectedDevices( *deviceList ); | 169 | emit selectedDevices( *deviceList ); |
160 | delete deviceList; | 170 | delete deviceList; |
161 | } | 171 | } |
162 | 172 | ||
163 | /* | 173 | /* |
164 | * Cleanup | 174 | * Cleanup |
165 | */ | 175 | */ |
166 | ScanDialog::~ScanDialog() { | 176 | ScanDialog::~ScanDialog() { |
167 | emitToManager(); | ||
168 | delete localDevice; | 177 | delete localDevice; |
169 | } | 178 | } |
170 | 179 | ||
171 | } | 180 | } |
diff --git a/noncore/net/opietooth/manager/scandialog.h b/noncore/net/opietooth/manager/scandialog.h index adc960c..7c84ce2 100644 --- a/noncore/net/opietooth/manager/scandialog.h +++ b/noncore/net/opietooth/manager/scandialog.h | |||
@@ -1,77 +1,79 @@ | |||
1 | /* main.cpp | 1 | /* main.cpp |
2 | * | 2 | * |
3 | * copyright : (c) 2002 by Maximilian Reiß | 3 | * copyright : (c) 2002 by Maximilian Reiß |
4 | * email : max.reiss@gmx.de | 4 | * email : max.reiss@gmx.de |
5 | * | 5 | * |
6 | */ | 6 | */ |
7 | /*************************************************************************** | 7 | /*************************************************************************** |
8 | * * | 8 | * * |
9 | * This program is free software; you can redistribute it and/or modify * | 9 | * This program is free software; you can redistribute it and/or modify * |
10 | * it under the terms of the GNU General Public License as published by * | 10 | * it under the terms of the GNU General Public License as published by * |
11 | * the Free Software Foundation; either version 2 of the License, or * | 11 | * the Free Software Foundation; either version 2 of the License, or * |
12 | * (at your option) any later version. * | 12 | * (at your option) any later version. * |
13 | * * | 13 | * * |
14 | ***************************************************************************/ | 14 | ***************************************************************************/ |
15 | 15 | ||
16 | 16 | ||
17 | #ifndef SCANDIALOG_H | 17 | #ifndef SCANDIALOG_H |
18 | #define SCANDIALOG_H | 18 | #define SCANDIALOG_H |
19 | 19 | ||
20 | #include <qvariant.h> | 20 | #include <qvariant.h> |
21 | #include <qdialog.h> | 21 | #include <qdialog.h> |
22 | #include <qlist.h> | 22 | #include <qlist.h> |
23 | 23 | ||
24 | #include <remotedevice.h> | 24 | #include <remotedevice.h> |
25 | class QVBoxLayout; | 25 | class QVBoxLayout; |
26 | class QHBoxLayout; | 26 | class QHBoxLayout; |
27 | class QGridLayout; | 27 | class QGridLayout; |
28 | class QFrame; | 28 | class QFrame; |
29 | class QLabel; | 29 | class QLabel; |
30 | class QListView; | 30 | class QListView; |
31 | class QListViewItem; | 31 | class QListViewItem; |
32 | class QPushButton; | 32 | class QPushButton; |
33 | class QProgressBar; | 33 | class QProgressBar; |
34 | 34 | ||
35 | 35 | ||
36 | namespace OpieTooth { | 36 | namespace OpieTooth { |
37 | 37 | ||
38 | 38 | ||
39 | class Manager; | 39 | class Manager; |
40 | class Device; | 40 | class Device; |
41 | 41 | ||
42 | class ScanDialog : public QDialog { | 42 | class ScanDialog : public QDialog { |
43 | Q_OBJECT | 43 | Q_OBJECT |
44 | 44 | ||
45 | public: | 45 | public: |
46 | ScanDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); | 46 | ScanDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); |
47 | ~ScanDialog(); | 47 | ~ScanDialog(); |
48 | 48 | ||
49 | QFrame* Frame7; | 49 | QFrame* Frame7; |
50 | QProgressBar* progress; | 50 | QProgressBar* progress; |
51 | QPushButton* StartButton; | 51 | QPushButton* StartButton; |
52 | QPushButton* StopButton; | 52 | QPushButton* StopButton; |
53 | QListView* ListView1; | 53 | QListView* ListView1; |
54 | 54 | ||
55 | public slots: | ||
56 | void accept(); | ||
55 | 57 | ||
56 | protected: | 58 | protected: |
57 | QVBoxLayout* Layout11; | 59 | QVBoxLayout* Layout11; |
58 | 60 | ||
59 | private slots: | 61 | private slots: |
60 | void stopSearch(); | 62 | void stopSearch(); |
61 | void startSearch(); | 63 | void startSearch(); |
62 | void progressTimer(); | 64 | void progressTimer(); |
63 | void fillList(const QString& device, RemoteDevice::ValueList list); | 65 | void fillList(const QString& device, RemoteDevice::ValueList list); |
64 | 66 | ||
65 | private: | 67 | private: |
66 | void emitToManager(); | 68 | void emitToManager(); |
67 | Manager *localDevice; | 69 | Manager *localDevice; |
68 | int progressStat; | 70 | int progressStat; |
69 | 71 | ||
70 | signals: | 72 | signals: |
71 | void selectedDevices(QList<RemoteDevice>&); | 73 | void selectedDevices(QList<RemoteDevice>&); |
72 | }; | 74 | }; |
73 | 75 | ||
74 | 76 | ||
75 | } | 77 | } |
76 | 78 | ||
77 | #endif // SCANDIALOG_H | 79 | #endif // SCANDIALOG_H |