summaryrefslogtreecommitdiff
authorerik <erik>2007-01-31 22:23:27 (UTC)
committer erik <erik>2007-01-31 22:23:27 (UTC)
commit73edac572d9ac9cfd18cc1254fc2019563d55f16 (patch) (unidiff)
treea420b341ce2bcb4a049c76935544b8bce2a0a853
parented5fba8cdb27174427b2e7780508bafa05536ca1 (diff)
downloadopie-73edac572d9ac9cfd18cc1254fc2019563d55f16.zip
opie-73edac572d9ac9cfd18cc1254fc2019563d55f16.tar.gz
opie-73edac572d9ac9cfd18cc1254fc2019563d55f16.tar.bz2
A few files that dereference pointers w/out checking that the pointer is
valid.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistselection.cpp35
-rw-r--r--noncore/settings/networksettings2/editconnection.cpp5
-rw-r--r--noncore/settings/networksettings2/opietooth2/Opietooth.cpp2
3 files changed, 14 insertions, 28 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistselection.cpp b/noncore/multimedia/opieplayer2/playlistselection.cpp
index 678ebdf..780d705 100644
--- a/noncore/multimedia/opieplayer2/playlistselection.cpp
+++ b/noncore/multimedia/opieplayer2/playlistselection.cpp
@@ -1,211 +1,196 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "playlistselection.h" 20#include "playlistselection.h"
21 21
22/* OPIE */ 22/* OPIE */
23#include <opie2/odebug.h> 23#include <opie2/odebug.h>
24using namespace Opie::Core; 24using namespace Opie::Core;
25 25
26/* QT */ 26/* QT */
27#include <qheader.h> 27#include <qheader.h>
28 28
29/* STD */ 29/* STD */
30#include <stdlib.h> 30#include <stdlib.h>
31 31
32class PlayListSelectionItem : public QListViewItem { 32class PlayListSelectionItem : public QListViewItem {
33public: 33public:
34 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { 34 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
35 setText( 0, f->name() ); 35 setText( 0, f->name() );
36 setPixmap( 0, f->pixmap() ); 36 setPixmap( 0, f->pixmap() );
37 } 37 }
38 38
39 ~PlayListSelectionItem() { 39 ~PlayListSelectionItem() {
40 }; 40 };
41 41
42 const DocLnk *file() const { return fl; } 42 const DocLnk *file() const { return fl; }
43 43
44private: 44private:
45 const DocLnk *fl; 45 const DocLnk *fl;
46}; 46};
47 47
48 48
49PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) 49PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
50 : QListView( parent, name ) 50 : QListView( parent, name )
51{ 51{
52// odebug << "starting playlistselector" << oendl; 52// odebug << "starting playlistselector" << oendl;
53// #ifdef USE_PLAYLIST_BACKGROUND
54// setStaticBackground( TRUE );
55// setBackgroundPixmap( Resource::loadPixmap( "opieplayer/background" ) );
56
57// setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) );
58// #endif
59// addColumn("Title",236);
60// setAllColumnsShowFocus( TRUE );
61 addColumn( tr( "Playlist Selection" ) ); 53 addColumn( tr( "Playlist Selection" ) );
62 header()->hide(); 54 header()->hide();
63 setSorting( -1, FALSE ); 55 setSorting( -1, FALSE );
64} 56}
65 57
66 58
67PlayListSelection::~PlayListSelection() { 59PlayListSelection::~PlayListSelection() {
68} 60}
69 61
70 62
71// #ifdef USE_PLAYLIST_BACKGROUND
72void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { 63void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
73// odebug << "drawBackground" << oendl; 64// odebug << "drawBackground" << oendl;
74 p->fillRect( r, QBrush( white ) ); 65 p->fillRect( r, QBrush( white ) );
75// QImage logo = Resource::loadImage( "launcher/opielogo" );
76// if ( !logo.isNull() )
77// p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
78} 66}
79// #endif
80 67
81 68
82void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { 69void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
83 if ( event->state() == QMouseEvent::LeftButton ) { 70 if ( event->state() == QMouseEvent::LeftButton ) {
84 QListViewItem *currentItem = selectedItem(); 71 QListViewItem *currentItem = selectedItem();
85 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); 72 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
86 if ( currentItem && currentItem->itemAbove() == itemUnder ) 73 if ( currentItem && currentItem->itemAbove() == itemUnder )
87 moveSelectedUp(); 74 moveSelectedUp();
88 else if ( currentItem && currentItem->itemBelow() == itemUnder ) 75 else if ( currentItem && currentItem->itemBelow() == itemUnder )
89 moveSelectedDown(); 76 moveSelectedDown();
90 } 77 }
91} 78}
92 79
93 80
94const DocLnk *PlayListSelection::current() { 81const DocLnk *PlayListSelection::current() {
95 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); 82 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
96 if ( item ) 83 if ( item )
97 return item->file(); 84 return item->file();
98 return NULL; 85 return NULL;
99} 86}
100 87
101 88
102void PlayListSelection::addToSelection( const DocLnk &lnk ) { 89void PlayListSelection::addToSelection( const DocLnk &lnk ) {
103 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); 90 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
104 QListViewItem *current = selectedItem(); 91 QListViewItem *current = selectedItem();
105 if ( current ) 92 if ( current )
106 item->moveItem( current ); 93 item->moveItem( current );
107 setSelected( item, TRUE ); 94 setSelected( item, TRUE );
108 ensureItemVisible( selectedItem() ); 95 ensureItemVisible( selectedItem() );
109} 96}
110 97
111 98
112void PlayListSelection::removeSelected() { 99void PlayListSelection::removeSelected() {
113 QListViewItem *item = selectedItem(); 100 QListViewItem *item = selectedItem();
114 delete item; 101 delete item;
115 setSelected( currentItem(), TRUE ); 102 setSelected( currentItem(), TRUE );
116 ensureItemVisible( selectedItem() ); 103 ensureItemVisible( selectedItem() );
117} 104}
118 105
119 106
120void PlayListSelection::moveSelectedUp() { 107void PlayListSelection::moveSelectedUp() {
121 QListViewItem *item = selectedItem(); 108 QListViewItem *item = selectedItem();
122 if ( item && item->itemAbove() ) 109 if ( item && item->itemAbove() )
123 item->itemAbove()->moveItem( item ); 110 item->itemAbove()->moveItem( item );
124 ensureItemVisible( selectedItem() ); 111 ensureItemVisible( selectedItem() );
125} 112}
126 113
127 114
128void PlayListSelection::moveSelectedDown() { 115void PlayListSelection::moveSelectedDown() {
129 QListViewItem *item = selectedItem(); 116 QListViewItem *item = selectedItem();
130 if ( item && item->itemBelow() ) 117 if ( item && item->itemBelow() )
131 item->moveItem( item->itemBelow() ); 118 item->moveItem( item->itemBelow() );
132 ensureItemVisible( selectedItem() ); 119 ensureItemVisible( selectedItem() );
133} 120}
134 121
135 122
136bool PlayListSelection::prev() { 123bool PlayListSelection::prev() {
137 QListViewItem *item = selectedItem(); 124 QListViewItem *item = selectedItem();
138 if ( item && item->itemAbove() ) 125 if ( item && item->itemAbove() )
139 setSelected( item->itemAbove(), TRUE ); 126 setSelected( item->itemAbove(), TRUE );
140 else 127 else
141 return FALSE; 128 return FALSE;
142 ensureItemVisible( selectedItem() ); 129 ensureItemVisible( selectedItem() );
143 return TRUE; 130 return TRUE;
144} 131}
145 132
146bool PlayListSelection::next() { 133bool PlayListSelection::next() {
147 QListViewItem *item = selectedItem(); 134 QListViewItem *item = selectedItem();
148 if ( item && item->itemBelow() ) 135 if ( item && item->itemBelow() )
149 setSelected( item->itemBelow(), TRUE ); 136 setSelected( item->itemBelow(), TRUE );
150 else 137 else
151 return FALSE; 138 return FALSE;
152 ensureItemVisible( selectedItem() ); 139 ensureItemVisible( selectedItem() );
153 return TRUE; 140 return TRUE;
154} 141}
155 142
156 143
157bool PlayListSelection::first() { 144bool PlayListSelection::first() {
158 QListViewItem *item = firstChild(); 145 QListViewItem *item = firstChild();
159 if ( item ) 146 if ( item )
160 setSelected( item, TRUE ); 147 setSelected( item, TRUE );
161 else 148 else
162 return FALSE; 149 return FALSE;
163 ensureItemVisible( selectedItem() ); 150 ensureItemVisible( selectedItem() );
164 return TRUE; 151 return TRUE;
165} 152}
166 153
167 154
168bool PlayListSelection::last() { 155bool PlayListSelection::last() {
169 QListViewItem *prevItem = NULL; 156 QListViewItem *prevItem = NULL;
170 QListViewItem *item = firstChild(); 157 QListViewItem *item = firstChild();
171 while ( ( item = item->nextSibling() ) ) 158 while ( ( item = item->nextSibling() ) )
172 prevItem = item; 159 prevItem = item;
173 if ( prevItem ) 160 if ( prevItem )
174 setSelected( prevItem, TRUE ); 161 setSelected( prevItem, TRUE );
175 else 162 else
176 return FALSE; 163 return FALSE;
177 ensureItemVisible( selectedItem() ); 164 ensureItemVisible( selectedItem() );
178 return TRUE; 165 return TRUE;
179} 166}
180 167
181void PlayListSelection::unSelect() 168void PlayListSelection::unSelect()
182{ 169{
183 //QListViewItem *item = selectedItem();
184 setSelected( currentItem(), FALSE); 170 setSelected( currentItem(), FALSE);
185} 171}
186 172
187void PlayListSelection::writeCurrent( Config& cfg ) { 173void PlayListSelection::writeCurrent( Config& cfg ) {
188 cfg.setGroup("PlayList"); 174 cfg.setGroup("PlayList");
189 QListViewItem *item = selectedItem(); 175 QListViewItem *item = selectedItem();
190 if ( item ) 176 if ( item ) {
191 cfg.writeEntry("current", item->text(0) ); 177 cfg.writeEntry("current", item->text(0) );
192 odebug << item->text(0) << oendl; 178 odebug << item->text(0) << oendl;
179 }
193 180
194} 181}
195 182
196void PlayListSelection::setSelectedItem(const QString &strk ) { 183void PlayListSelection::setSelectedItem(const QString &strk ) {
197 184
198 unSelect(); 185 unSelect();
199 QListViewItemIterator it( this ); 186 QListViewItemIterator it( this );
200 for ( ; it.current(); ++it ) { 187 for ( ; it.current(); ++it ) {
201// odebug << it.current()->text(0) << oendl; 188// odebug << it.current()->text(0) << oendl;
202 if( strk == it.current()->text(0)) { 189 if( strk == it.current()->text(0)) {
203// odebug << "We have a match "+strk << oendl; 190// odebug << "We have a match "+strk << oendl;
204 setSelected( it.current(), TRUE); 191 setSelected( it.current(), TRUE);
205 ensureItemVisible( it.current() ); 192 ensureItemVisible( it.current() );
206 return; 193 return;
207 } 194 }
208 } 195 }
209// setSelected( item, TRUE );
210// ensureItemVisible( selectedItem() );
211} 196}
diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp
index a9bef65..d948fb9 100644
--- a/noncore/settings/networksettings2/editconnection.cpp
+++ b/noncore/settings/networksettings2/editconnection.cpp
@@ -1,646 +1,647 @@
1#include <opie2/odebug.h> 1#include <opie2/odebug.h>
2#include <qlistview.h> 2#include <qlistview.h>
3#include <qwidgetstack.h> 3#include <qwidgetstack.h>
4#include <qframe.h> 4#include <qframe.h>
5#include <qcombobox.h> 5#include <qcombobox.h>
6#include <qtabwidget.h> 6#include <qtabwidget.h>
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <qpushbutton.h> 8#include <qpushbutton.h>
9#include <qlineedit.h> 9#include <qlineedit.h>
10#include <qheader.h> 10#include <qheader.h>
11#include <qpainter.h> 11#include <qpainter.h>
12#include <qcheckbox.h> 12#include <qcheckbox.h>
13#include <qlabel.h> 13#include <qlabel.h>
14 14
15#include "editconnection.h" 15#include "editconnection.h"
16#include "resources.h" 16#include "resources.h"
17#include "netnode.h" 17#include "netnode.h"
18 18
19// 19//
20// 20//
21// THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS 21// THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS
22// 22//
23// 23//
24 24
25class MyQCheckListItem : public QCheckListItem 25class MyQCheckListItem : public QCheckListItem
26{ 26{
27public: 27public:
28 MyQCheckListItem( QListView *parent, const QString & S, Type T ) : 28 MyQCheckListItem( QListView *parent, const QString & S, Type T ) :
29 QCheckListItem( parent, S, T ) { } 29 QCheckListItem( parent, S, T ) { }
30 MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) : 30 MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) :
31 QCheckListItem( parent, S, T ) { } 31 QCheckListItem( parent, S, T ) { }
32 MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) : 32 MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) :
33 QCheckListItem( parent, S, T ) { } 33 QCheckListItem( parent, S, T ) { }
34 34
35 MyQCheckListItem( QListView *parent, const QString & S ) : 35 MyQCheckListItem( QListView *parent, const QString & S ) :
36 QCheckListItem( parent, S, QCheckListItem::Controller ) { } 36 QCheckListItem( parent, S, QCheckListItem::Controller ) { }
37 MyQCheckListItem( QCheckListItem *parent, const QString & S ) : 37 MyQCheckListItem( QCheckListItem *parent, const QString & S ) :
38 QCheckListItem( parent, S, QCheckListItem::Controller ) { } 38 QCheckListItem( parent, S, QCheckListItem::Controller ) { }
39 MyQCheckListItem( QListViewItem *parent, const QString & S ) : 39 MyQCheckListItem( QListViewItem *parent, const QString & S ) :
40 QCheckListItem( parent, S, QCheckListItem::Controller ) { } 40 QCheckListItem( parent, S, QCheckListItem::Controller ) { }
41 41
42 virtual void paintCell( QPainter *p, const QColorGroup &cg, 42 virtual void paintCell( QPainter *p, const QColorGroup &cg,
43 int column, int width, int alignment ); 43 int column, int width, int alignment );
44 44
45}; 45};
46 46
47void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, 47void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg,
48 int column, int width, int alignment ) 48 int column, int width, int alignment )
49{ 49{
50 QColorGroup _cg( cg ); 50 QColorGroup _cg( cg );
51 QColor c = _cg.text(); 51 QColor c = _cg.text();
52 if ( ! isSelectable() ) 52 if ( ! isSelectable() )
53 _cg.setColor( QColorGroup::Text, Qt::lightGray ); 53 _cg.setColor( QColorGroup::Text, Qt::lightGray );
54 QCheckListItem::paintCell( p, _cg, column, width, alignment ); 54 QCheckListItem::paintCell( p, _cg, column, width, alignment );
55 _cg.setColor( QColorGroup::Text, c ); 55 _cg.setColor( QColorGroup::Text, c );
56} 56}
57 57
58class MyQListViewItem : public QListViewItem 58class MyQListViewItem : public QListViewItem
59{ 59{
60public: 60public:
61 MyQListViewItem( QListView *parent, const QString & S ) : 61 MyQListViewItem( QListView *parent, const QString & S ) :
62 QListViewItem( parent, S ) { } 62 QListViewItem( parent, S ) { }
63 MyQListViewItem( QListViewItem *parent, const QString & S ) : 63 MyQListViewItem( QListViewItem *parent, const QString & S ) :
64 QListViewItem( parent, S ) { } 64 QListViewItem( parent, S ) { }
65 65
66 virtual void paintCell( QPainter *p, const QColorGroup &cg, 66 virtual void paintCell( QPainter *p, const QColorGroup &cg,
67 int column, int width, int alignment ); 67 int column, int width, int alignment );
68 68
69}; 69};
70 70
71void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, 71void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
72 int column, int width, int alignment ) 72 int column, int width, int alignment )
73{ 73{
74 QColorGroup _cg( cg ); 74 QColorGroup _cg( cg );
75 QColor c = _cg.text(); 75 QColor c = _cg.text();
76 if ( ! isSelectable() ) 76 if ( ! isSelectable() )
77 _cg.setColor( QColorGroup::Text, Qt::lightGray ); 77 _cg.setColor( QColorGroup::Text, Qt::lightGray );
78 QListViewItem::paintCell( p, _cg, column, width, alignment ); 78 QListViewItem::paintCell( p, _cg, column, width, alignment );
79 _cg.setColor( QColorGroup::Text, c ); 79 _cg.setColor( QColorGroup::Text, c );
80} 80}
81 81
82// 82//
83// 83//
84// REAL GUI 84// REAL GUI
85// 85//
86// 86//
87 87
88bool EditNetworkSetup::AutoCollapse = 1; 88bool EditNetworkSetup::AutoCollapse = 1;
89 89
90EditNetworkSetup::EditNetworkSetup( QWidget* parent ) : 90EditNetworkSetup::EditNetworkSetup( QWidget* parent ) :
91 EditNetworkSetupGUI( parent, 0, TRUE ), TmpCollection() { 91 EditNetworkSetupGUI( parent, 0, TRUE ), TmpCollection() {
92 92
93 Tab_TB->setTabEnabled( Setup_FRM, FALSE ); 93 Tab_TB->setTabEnabled( Setup_FRM, FALSE );
94 Setup_FRM->setEnabled( FALSE ); 94 Setup_FRM->setEnabled( FALSE );
95 95
96 TmpIsValid = 0; 96 TmpIsValid = 0;
97 SelectedNodes = 0; 97 SelectedNodes = 0;
98 98
99 AutoCollapse_CB->setChecked( AutoCollapse ); 99 AutoCollapse_CB->setChecked( AutoCollapse );
100 100
101 Mapping = new QPtrDict<ANetNode>; 101 Mapping = new QPtrDict<ANetNode>;
102 Mapping->setAutoDelete( FALSE ); 102 Mapping->setAutoDelete( FALSE );
103 Nodes_LV->header()->hide(); 103 Nodes_LV->header()->hide();
104 // popluate tree with all NetNodes 104 // popluate tree with all NetNodes
105 buildFullTree(); 105 buildFullTree();
106} 106}
107 107
108NetworkSetup * EditNetworkSetup::getTmpCollection( void ) { 108NetworkSetup * EditNetworkSetup::getTmpCollection( void ) {
109 109
110 if( TmpIsValid ) 110 if( TmpIsValid )
111 // content is stil OK 111 // content is stil OK
112 return &(TmpCollection); 112 return &(TmpCollection);
113 113
114 // reset collection -> delete all NEW NetNodes 114 // reset collection -> delete all NEW NetNodes
115 for( QListIterator<ANetNodeInstance> it(TmpCollection); 115 for( QListIterator<ANetNodeInstance> it(TmpCollection);
116 it.current(); 116 it.current();
117 ++it ) { 117 ++it ) {
118 if( it.current()->isNew() ) { 118 if( it.current()->isNew() ) {
119 delete it.current(); 119 delete it.current();
120 } 120 }
121 } 121 }
122 122
123 TmpCollection.clear(); 123 TmpCollection.clear();
124 if( SelectedNodes ) { 124 if( SelectedNodes ) {
125 // initialize like original 125 // initialize like original
126 TmpCollection.copyFrom( *SelectedNodes ); 126 TmpCollection.copyFrom( *SelectedNodes );
127 } 127 }
128 128
129 // update content 129 // update content
130 QListViewItem * it = Nodes_LV->firstChild(); 130 QListViewItem * it = Nodes_LV->firstChild();
131 ANetNode * NN; 131 ANetNode * NN;
132 132
133 // start iter (if there is a collection) 133 // start iter (if there is a collection)
134 /* 134 /*
135 135
136 a node collection is sorted from the toplevel 136 a node collection is sorted from the toplevel
137 node to the deepest node 137 node to the deepest node
138 138
139 */ 139 */
140 ANetNodeInstance * NNI = 140 ANetNodeInstance * NNI =
141 (SelectedNodes) ? SelectedNodes->first() : 0 ; 141 (SelectedNodes) ? SelectedNodes->first() : 0 ;
142 142
143 TmpCollection.setModified( 0 ); 143 TmpCollection.setModified( 0 );
144 144
145 // the listview always starts with the toplevel 145 // the listview always starts with the toplevel
146 // hierarchy. This is always a controller item 146 // hierarchy. This is always a controller item
147 while ( it ) { 147 while ( it ) {
148 NN = (*Mapping)[it]; 148 NN = (*Mapping)[it];
149 if( NN == 0 ) { 149 if( NN == 0 ) {
150 // this item is a controller -> 150 // this item is a controller ->
151 // has radio items as children -> 151 // has radio items as children ->
152 // find selected one 152 // find selected one
153 it = it->firstChild(); 153 it = it->firstChild();
154 while( it ) { 154 while( it ) {
155 if( ((QCheckListItem *)it)->isOn() ) { 155 if( ((QCheckListItem *)it)->isOn() ) {
156 // this radio is selected -> go deeper 156 // this radio is selected -> go deeper
157 break; 157 break;
158 } 158 }
159 it = it->nextSibling(); 159 it = it->nextSibling();
160 } 160 }
161 161
162 if( ! it ) { 162 if( ! it ) {
163 TmpIsValid = 0; 163 TmpIsValid = 0;
164 return 0; 164 return 0;
165 } 165 }
166 166
167 // it now contains selected radio 167 // it now contains selected radio
168 NN = (*Mapping)[it]; 168 NN = (*Mapping)[it];
169 } 169 }
170 170
171 // NN here contains the netnode of the 171 // NN here contains the netnode of the
172 // current item -> this node needs to 172 // current item -> this node needs to
173 // be stored in the collection 173 // be stored in the collection
174 if( NNI == 0 || 174 if( NNI == 0 ||
175 it->text(0) != NNI->nodeClass()->name() ) { 175 it->text(0) != NNI->nodeClass()->name() ) {
176 // new item not in previous collection 176 // new item not in previous collection
177 ANetNodeInstance * NNI = NN->createInstance(); 177 ANetNodeInstance * NNI = NN->createInstance();
178 NNI->initialize(); 178 NNI->initialize();
179 // this node type not in collection 179 // this node type not in collection
180 TmpCollection.append( NNI ); 180 TmpCollection.append( NNI );
181 // master collection changed because new item in it 181 // master collection changed because new item in it
182 TmpCollection.setModified( 1 ); 182 TmpCollection.setModified( 1 );
183 // no more valid items in old list 183 // no more valid items in old list
184 NNI = 0; 184 NNI = 0;
185 } else { 185 } else {
186 // already in list -> copy pointer 186 // already in list -> copy pointer
187 TmpCollection.append( NNI ); 187 TmpCollection.append( NNI );
188 NNI = SelectedNodes->next(); 188 NNI = SelectedNodes->next();
189 } 189 }
190 190
191 // go deeper to next level 191 // go deeper to next level
192 // this level is can be a new controller 192 // this level is can be a new controller
193 // or an item 193 // or an item
194 it = it->firstChild(); 194 it = it->firstChild();
195 } 195 }
196 196
197 TmpIsValid = 1; 197 TmpIsValid = 1;
198 return &(TmpCollection); 198 return &(TmpCollection);
199} 199}
200 200
201// pass a NetworkSetup NetworkSetup to be edited 201// pass a NetworkSetup NetworkSetup to be edited
202void EditNetworkSetup::setNetworkSetup( NetworkSetup * NC ) { 202void EditNetworkSetup::setNetworkSetup( NetworkSetup * NC ) {
203 ANetNodeInstance * NNI; 203 ANetNodeInstance * NNI;
204 ANetNode * NN; 204 ANetNode * NN;
205 205
206 SelectedNodes = NC; 206 SelectedNodes = NC;
207 Name_LE->setText( NC->name() ); 207 Name_LE->setText( NC->name() );
208 NNI = NC->first(); 208 NNI = NC->first();
209 209
210 // show configure tabl 210 // show configure tabl
211 Tab_TB->setCurrentPage( 1 ); 211 Tab_TB->setCurrentPage( 1 );
212 212
213 // valid colledction 213 // valid colledction
214 Tab_TB->setTabEnabled( Setup_FRM, FALSE ); 214 Tab_TB->setTabEnabled( Setup_FRM, FALSE );
215 Setup_FRM->setEnabled( FALSE ); 215 Setup_FRM->setEnabled( FALSE );
216 216
217 // select items in collection 217 // select items in collection
218 QListViewItem * it = Nodes_LV->firstChild(); 218 QListViewItem * it = Nodes_LV->firstChild();
219 bool Found; 219 bool Found;
220 220
221 TmpIsValid = 0; 221 TmpIsValid = 0;
222 222
223 while ( it ) { 223 while ( it ) {
224 NN = (*Mapping)[it]; 224 NN = (*Mapping)[it];
225 if( NN == 0 ) { 225 if( NN == 0 ) {
226 // this item is a controller -> 226 // this item is a controller ->
227 // has radio items as children -> 227 // has radio items as children ->
228 // find selected one 228 // find selected one
229 it = it->firstChild(); 229 it = it->firstChild();
230 Found = 0; 230 Found = 0;
231 while( it ) { 231 while( it ) {
232 if( NNI && it->text(0) == NNI->nodeClass()->name() ) { 232 if( NNI && it->text(0) == NNI->nodeClass()->name() ) {
233 // this radio is part of the collection 233 // this radio is part of the collection
234 ((QCheckListItem *)it)->setOn( 1 ); 234 ((QCheckListItem *)it)->setOn( 1 );
235 updateGUI( it, NNI->nodeClass() ); 235 updateGUI( it, NNI->nodeClass() );
236 // check its children 236 // check its children
237 Found = 1; 237 Found = 1;
238 it = it->firstChild(); 238 it = it->firstChild();
239 NNI = SelectedNodes->next(); 239 NNI = SelectedNodes->next();
240 // do not bother to check other items 240 // do not bother to check other items
241 break; 241 break;
242 } 242 }
243 it = it->nextSibling(); 243 it = it->nextSibling();
244 } 244 }
245 245
246 if( ! Found ) { 246 if( ! Found ) {
247 // this means that this level is NOT present in collection 247 // this means that this level is NOT present in collection
248 // probably INCOMPATIBEL collection OR Missing plugin 248 // probably INCOMPATIBLE collection OR Missing plugin
249 QString pluginName = NNI ? NNI->nodeClass()->name() : "";
249 QMessageBox::warning( 250 QMessageBox::warning(
250 0, 251 0,
251 tr( "Error presentig NetworkSetup" ), 252 tr( "Error presentig NetworkSetup" ),
252 tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ). 253 tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ).
253 arg(NNI->nodeClass()->name()) ); 254 arg(pluginName) );
254 return; 255 return;
255 } 256 }
256 257
257 // it now contains selected radio 258 // it now contains selected radio
258 NN = (*Mapping)[it]; 259 NN = (*Mapping)[it];
259 } else { 260 } else {
260 // automatic selection 261 // automatic selection
261 if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { 262 if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) {
262 // should exist and be the same 263 // should exist and be the same
263 if( NNI ) { 264 if( NNI ) {
264 QMessageBox::warning( 265 QMessageBox::warning(
265 0, 266 0,
266 tr( "Error presentig NetworkSetup" ), 267 tr( "Error presentig NetworkSetup" ),
267 tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ). 268 tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ).
268 arg(NNI->nodeClass()->name()) ); 269 arg(NNI->nodeClass()->name()) );
269 } else { 270 } else {
270 QMessageBox::warning( 271 QMessageBox::warning(
271 0, 272 0,
272 tr( "Error presentig NetworkSetup" ), 273 tr( "Error presentig NetworkSetup" ),
273 tr( "<p>Missing NetworkSetup\"<i>%1</i>\"</p>" ). 274 tr( "<p>Missing NetworkSetup\"<i>%1</i>\"</p>" ).
274 arg(it->text(0)) ); 275 arg(it->text(0)) );
275 } 276 }
276 return; 277 return;
277 } 278 }
278 it = it->firstChild(); 279 it = it->firstChild();
279 } 280 }
280 } 281 }
281} 282}
282 283
283// get result of editing (either new OR updated collection 284// get result of editing (either new OR updated collection
284NetworkSetup * EditNetworkSetup::networkSetup( void ) { 285NetworkSetup * EditNetworkSetup::networkSetup( void ) {
285 286
286 if( SelectedNodes == 0 ) { 287 if( SelectedNodes == 0 ) {
287 // new collection 288 // new collection
288 SelectedNodes = new NetworkSetup; 289 SelectedNodes = new NetworkSetup;
289 } 290 }
290 291
291 // clean out old entries 292 // clean out old entries
292 SelectedNodes->clear(); 293 SelectedNodes->clear();
293 294
294 // transfer 295 // transfer
295 for( QListIterator<ANetNodeInstance> it(TmpCollection); 296 for( QListIterator<ANetNodeInstance> it(TmpCollection);
296 it.current(); 297 it.current();
297 ++it ) { 298 ++it ) {
298 SelectedNodes->append( it.current() ); 299 SelectedNodes->append( it.current() );
299 } 300 }
300 301
301 if( TmpCollection.isModified() ) 302 if( TmpCollection.isModified() )
302 SelectedNodes->setModified( 1 ); 303 SelectedNodes->setModified( 1 );
303 304
304 if( SelectedNodes->name() != Name_LE->text() ) { 305 if( SelectedNodes->name() != Name_LE->text() ) {
305 SelectedNodes->setName( Name_LE->text() ); 306 SelectedNodes->setName( Name_LE->text() );
306 SelectedNodes->setModified( 1 ); 307 SelectedNodes->setModified( 1 );
307 } 308 }
308 309
309 return SelectedNodes; 310 return SelectedNodes;
310} 311}
311 312
312// Build device tree -> start 313// Build device tree -> start
313void EditNetworkSetup::buildFullTree( void ) { 314void EditNetworkSetup::buildFullTree( void ) {
314 ANetNode * NN; 315 ANetNode * NN;
315 316
316 // toplevel item 317 // toplevel item
317 MyQCheckListItem * TheTop = new MyQCheckListItem( 318 MyQCheckListItem * TheTop = new MyQCheckListItem(
318 Nodes_LV, 319 Nodes_LV,
319 NSResources->netNode2Name("fullsetup"), 320 NSResources->netNode2Name("fullsetup"),
320 QCheckListItem::Controller ); 321 QCheckListItem::Controller );
321 TheTop->setOpen( TRUE ); 322 TheTop->setOpen( TRUE );
322 Description_LBL->setText( 323 Description_LBL->setText(
323 NSResources->netNode2Description( "fullsetup" ) ); 324 NSResources->netNode2Description( "fullsetup" ) );
324 Nodes_LV->setSelected( TheTop, TRUE ); 325 Nodes_LV->setSelected( TheTop, TRUE );
325 326
326 // find all Nodes that are toplevel nodes -> ie provide 327 // find all Nodes that are toplevel nodes -> ie provide
327 // TCP/IP NetworkSetup 328 // TCP/IP NetworkSetup
328 for( QDictIterator<ANetNode> Iter(NSResources->netNodes()); 329 for( QDictIterator<ANetNode> Iter(NSResources->netNodes());
329 Iter.current(); 330 Iter.current();
330 ++Iter ) { 331 ++Iter ) {
331 NN = Iter.current(); 332 NN = Iter.current();
332 333
333 if( ! NN->isToplevel() ) { 334 if( ! NN->isToplevel() ) {
334 continue; 335 continue;
335 } 336 }
336 337
337 MyQCheckListItem * it = new MyQCheckListItem( TheTop, 338 MyQCheckListItem * it = new MyQCheckListItem( TheTop,
338 NN->name(), 339 NN->name(),
339 QCheckListItem::RadioButton ); 340 QCheckListItem::RadioButton );
340 it->setPixmap( 0, 341 it->setPixmap( 0,
341 NSResources->getPixmap( NN->pixmapName() ) 342 NSResources->getPixmap( NN->pixmapName() )
342 ); 343 );
343 // remember that this node maps to this listitem 344 // remember that this node maps to this listitem
344 Mapping->insert( it, NN ); 345 Mapping->insert( it, NN );
345 buildSubTree( it, NN ); 346 buildSubTree( it, NN );
346 } 347 }
347} 348}
348 349
349// Build device tree -> help function 350// Build device tree -> help function
350void EditNetworkSetup::buildSubTree( QListViewItem * it, ANetNode *NN ) { 351void EditNetworkSetup::buildSubTree( QListViewItem * it, ANetNode *NN ) {
351 ANetNode::NetNodeList & NNL = NN->alternatives(); 352 ANetNode::NetNodeList & NNL = NN->alternatives();
352 353
353 if( NNL.size() > 1 ) { 354 if( NNL.size() > 1 ) {
354 // this node has alternatives -> needs radio buttons 355 // this node has alternatives -> needs radio buttons
355 it = new MyQCheckListItem( 356 it = new MyQCheckListItem(
356 it, 357 it,
357 NSResources->netNode2Name(NN->needs()[0]), 358 NSResources->netNode2Name(NN->needs()[0]),
358 QCheckListItem::Controller ); 359 QCheckListItem::Controller );
359 it->setSelectable( FALSE ); 360 it->setSelectable( FALSE );
360 } 361 }
361 362
362 for ( unsigned int i=0; i < NNL.size(); i++ ) { 363 for ( unsigned int i=0; i < NNL.size(); i++ ) {
363 QListViewItem * CI; 364 QListViewItem * CI;
364 if( NNL.size() > 1 ) { 365 if( NNL.size() > 1 ) {
365 // generate radio buttons 366 // generate radio buttons
366 CI = new MyQCheckListItem( 367 CI = new MyQCheckListItem(
367 (QCheckListItem *)it, 368 (QCheckListItem *)it,
368 NNL[i]->name(), QCheckListItem::RadioButton ); 369 NNL[i]->name(), QCheckListItem::RadioButton );
369 // remember that this node maps to this listitem 370 // remember that this node maps to this listitem
370 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); 371 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) );
371 Mapping->insert( CI, NNL[i] ); 372 Mapping->insert( CI, NNL[i] );
372 CI->setSelectable( FALSE ); 373 CI->setSelectable( FALSE );
373 } else { 374 } else {
374 // Single item 375 // Single item
375 CI = new MyQListViewItem( it, NNL[i]->name() ); 376 CI = new MyQListViewItem( it, NNL[i]->name() );
376 // remember that this node maps to this listitem 377 // remember that this node maps to this listitem
377 Mapping->insert( CI, NNL[i] ); 378 Mapping->insert( CI, NNL[i] );
378 CI->setSelectable( FALSE ); 379 CI->setSelectable( FALSE );
379 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); 380 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) );
380 } 381 }
381 buildSubTree( CI, NNL[i] ); 382 buildSubTree( CI, NNL[i] );
382 } 383 }
383} 384}
384 385
385// Clicked ok OK button 386// Clicked ok OK button
386void EditNetworkSetup::accept( void ) { 387void EditNetworkSetup::accept( void ) {
387 if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { 388 if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) {
388 QMessageBox::warning( 389 QMessageBox::warning(
389 0, 390 0,
390 tr( "Closing NetworkSetup Setup" ), 391 tr( "Closing NetworkSetup Setup" ),
391 tr( "Definition not complete or no name" ) ); 392 tr( "Definition not complete or no name" ) );
392 return; 393 return;
393 } 394 }
394 395
395 // check if all devices have acceptable input 396 // check if all devices have acceptable input
396 getTmpCollection(); 397 getTmpCollection();
397 { ANetNodeInstance * NNI; 398 { ANetNodeInstance * NNI;
398 QString S; 399 QString S;
399 400
400 for( QListIterator<ANetNodeInstance> it(TmpCollection); 401 for( QListIterator<ANetNodeInstance> it(TmpCollection);
401 it.current(); 402 it.current();
402 ++it ) { 403 ++it ) {
403 NNI = it.current(); 404 NNI = it.current();
404 // widget must show its own problems 405 // widget must show its own problems
405 S = NNI->acceptable(); 406 S = NNI->acceptable();
406 if( ! S.isEmpty() ) { 407 if( ! S.isEmpty() ) {
407 QMessageBox::warning( 408 QMessageBox::warning(
408 0, 409 0,
409 tr( "Cannot save" ), 410 tr( "Cannot save" ),
410 S ); 411 S );
411 return; 412 return;
412 } 413 }
413 NNI->commit(); 414 NNI->commit();
414 415
415 if( NNI->isModified() ) { 416 if( NNI->isModified() ) {
416 TmpCollection.setModified( 1 ); 417 TmpCollection.setModified( 1 );
417 // commit the data 418 // commit the data
418 } 419 }
419 } 420 }
420 } 421 }
421 422
422 QDialog::accept(); 423 QDialog::accept();
423} 424}
424 425
425// triggered by CB 426// triggered by CB
426void EditNetworkSetup::SLOT_AutoCollapse( bool b ) { 427void EditNetworkSetup::SLOT_AutoCollapse( bool b ) {
427 AutoCollapse = b; 428 AutoCollapse = b;
428} 429}
429 430
430// clicked on node in tree -> update GUI 431// clicked on node in tree -> update GUI
431void EditNetworkSetup::SLOT_SelectNode( QListViewItem * it ) { 432void EditNetworkSetup::SLOT_SelectNode( QListViewItem * it ) {
432 ANetNode * NN; 433 ANetNode * NN;
433 if( it == 0 || it->depth() == 0 ) { 434 if( it == 0 || it->depth() == 0 ) {
434 Description_LBL->setText( 435 Description_LBL->setText(
435 NSResources->netNode2Description( "fullsetup" ) ); 436 NSResources->netNode2Description( "fullsetup" ) );
436 // topevel or no selection 437 // topevel or no selection
437 return; 438 return;
438 } 439 }
439 440
440 // store conversion from lvitem to node 441 // store conversion from lvitem to node
441 NN = (*Mapping)[ it ]; 442 NN = (*Mapping)[ it ];
442 443
443 if( ! NN ) { 444 if( ! NN ) {
444 // intermediate (controller) node 445 // intermediate (controller) node
445 NN = (*Mapping)[ it->parent() ]; 446 NN = (*Mapping)[ it->parent() ];
446 if( NN ) { 447 if( NN ) {
447 // figure out type of this node -> produce message 448 // figure out type of this node -> produce message
448 Description_LBL->setText( NSResources->netNode2Description( 449 Description_LBL->setText( NSResources->netNode2Description(
449 NN->needs()[0]) ); 450 NN->needs()[0]) );
450 } else { 451 } else {
451 Description_LBL->setText( "" ); 452 Description_LBL->setText( "" );
452 } 453 }
453 return; 454 return;
454 } 455 }
455 456
456 // clicked on regular node 457 // clicked on regular node
457 Description_LBL->setText( NN->nodeDescription() ); 458 Description_LBL->setText( NN->nodeDescription() );
458 459
459 if( ! it->isSelectable() ) { 460 if( ! it->isSelectable() ) {
460 return; 461 return;
461 } 462 }
462 463
463 ANetNode::NetNodeList & NNL = NN->alternatives(); 464 ANetNode::NetNodeList & NNL = NN->alternatives();
464 465
465 if( NNL.size() == 0 ) { 466 if( NNL.size() == 0 ) {
466 // this item has no alternatives -> end node 467 // this item has no alternatives -> end node
467 TmpIsValid = 0; 468 TmpIsValid = 0;
468 updateGUI( it, NN ); 469 updateGUI( it, NN );
469 return; 470 return;
470 } 471 }
471 472
472 if( ! ((MyQCheckListItem *)it)->isOn() ) { 473 if( ! ((MyQCheckListItem *)it)->isOn() ) {
473 // not clicked on Check or Radio item 474 // not clicked on Check or Radio item
474 return; 475 return;
475 } 476 }
476 477
477 // item has really changed -> update 478 // item has really changed -> update
478 TmpIsValid = 0; 479 TmpIsValid = 0;
479 updateGUI( it, NN ); 480 updateGUI( it, NN );
480} 481}
481 482
482// cliecked on TAB to go to setup 483// cliecked on TAB to go to setup
483void EditNetworkSetup::SLOT_AlterTab( const QString & S ) { 484void EditNetworkSetup::SLOT_AlterTab( const QString & S ) {
484 if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { 485 if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) {
485 // switched to setup -> update CB and populate ws with 486 // switched to setup -> update CB and populate ws with
486 // forms for devices 487 // forms for devices
487 488
488 if( ! TmpIsValid ) { 489 if( ! TmpIsValid ) {
489 getTmpCollection(); 490 getTmpCollection();
490 491
491 // clear CB and Ws 492 // clear CB and Ws
492 { QWidget * W; 493 { QWidget * W;
493 int i = 0; 494 int i = 0;
494 495
495 Devices_CB->clear(); 496 Devices_CB->clear();
496 while( ( W = Setup_WS->widget( i ) ) ) { 497 while( ( W = Setup_WS->widget( i ) ) ) {
497 Setup_WS->removeWidget( W ); 498 Setup_WS->removeWidget( W );
498 i ++; 499 i ++;
499 } 500 }
500 } 501 }
501 502
502 // update CB 503 // update CB
503 // and populate WidgetStack 504 // and populate WidgetStack
504 { ANetNodeInstance * NNI; 505 { ANetNodeInstance * NNI;
505 QListIterator<ANetNodeInstance> it(TmpCollection); 506 QListIterator<ANetNodeInstance> it(TmpCollection);
506 int i = 0; 507 int i = 0;
507 QWidget * W; 508 QWidget * W;
508 509
509 for ( ; it.current(); ++it ) { 510 for ( ; it.current(); ++it ) {
510 NNI = it.current(); 511 NNI = it.current();
511 Devices_CB->insertItem( 512 Devices_CB->insertItem(
512 NSResources->getPixmap( NNI->nodeClass()->pixmapName() ), 513 NSResources->getPixmap( NNI->nodeClass()->pixmapName() ),
513 NNI->nodeClass()->name() 514 NNI->nodeClass()->name()
514 ); 515 );
515 516
516 // add edit widget 517 // add edit widget
517 W = NNI->edit( Setup_WS ); 518 W = NNI->edit( Setup_WS );
518 if( ! W) { 519 if( ! W) {
519 W = new QLabel( Setup_WS, 520 W = new QLabel( Setup_WS,
520 tr("No configuration required")); 521 tr("No configuration required"));
521 } 522 }
522 Setup_WS->addWidget( W , i ); 523 Setup_WS->addWidget( W , i );
523 i ++; 524 i ++;
524 } 525 }
525 } 526 }
526 Setup_WS->raiseWidget( 0 ); 527 Setup_WS->raiseWidget( 0 );
527 } // still valid 528 } // still valid
528 } 529 }
529} 530}
530 531
531// update visual feedback of selection state 532// update visual feedback of selection state
532void EditNetworkSetup::updateGUI( QListViewItem * it, ANetNode * NN ) { 533void EditNetworkSetup::updateGUI( QListViewItem * it, ANetNode * NN ) {
533 534
534 bool HCC = haveCompleteConfig( it ); 535 bool HCC = haveCompleteConfig( it );
535 Tab_TB->setTabEnabled( Setup_FRM, HCC ); 536 Tab_TB->setTabEnabled( Setup_FRM, HCC );
536 Log(( "COMPLETE CONFIG %d\n", HCC )); 537 Log(( "COMPLETE CONFIG %d\n", HCC ));
537 Setup_FRM->setEnabled( HCC ); 538 Setup_FRM->setEnabled( HCC );
538 539
539 // disable children of all siblings at same level 540 // disable children of all siblings at same level
540 QListViewItem * Sbl = it->parent()->firstChild(); 541 QListViewItem * Sbl = it->parent()->firstChild();
541 while( Sbl ) { 542 while( Sbl ) {
542 if ( Sbl != it ) { 543 if ( Sbl != it ) {
543 disableTree( Sbl->firstChild(), FALSE ); 544 disableTree( Sbl->firstChild(), FALSE );
544 Sbl->setSelectable( TRUE ); 545 Sbl->setSelectable( TRUE );
545 if( AutoCollapse ) 546 if( AutoCollapse )
546 Sbl->setOpen( FALSE ); 547 Sbl->setOpen( FALSE );
547 } 548 }
548 Sbl = Sbl->nextSibling(); 549 Sbl = Sbl->nextSibling();
549 } 550 }
550 551
551 // enable selected path (as deep as it goes 552 // enable selected path (as deep as it goes
552 it->setOpen( TRUE ); 553 it->setOpen( TRUE );
553 enablePath( it->firstChild(), 554 enablePath( it->firstChild(),
554 (it->depth()==1) ? 555 (it->depth()==1) ?
555 1 : // toplevel always alternatives 556 1 : // toplevel always alternatives
556 (NN->alternatives().size() > 1) ); 557 (NN->alternatives().size() > 1) );
557} 558}
558 559
559void EditNetworkSetup::disableTree( QListViewItem * it, bool Mode ) { 560void EditNetworkSetup::disableTree( QListViewItem * it, bool Mode ) {
560 while( it ) { 561 while( it ) {
561 // disable sbl's chidren 562 // disable sbl's chidren
562 it->setSelectable( Mode ); 563 it->setSelectable( Mode );
563 if( AutoCollapse ) 564 if( AutoCollapse )
564 it->setOpen( Mode ); 565 it->setOpen( Mode );
565 disableTree( it->firstChild(), Mode ); 566 disableTree( it->firstChild(), Mode );
566 it = it->nextSibling(); 567 it = it->nextSibling();
567 } 568 }
568} 569}
569 570
570// pah : ParentHasAlternatives 571// pah : ParentHasAlternatives
571void EditNetworkSetup::enablePath( QListViewItem * it, bool pha ) { 572void EditNetworkSetup::enablePath( QListViewItem * it, bool pha ) {
572 while( it ) { 573 while( it ) {
573 ANetNode * NN; 574 ANetNode * NN;
574 NN = (*Mapping)[it]; 575 NN = (*Mapping)[it];
575 if( NN ) { 576 if( NN ) {
576 if( pha ) { 577 if( pha ) {
577 bool doOn = ((QCheckListItem *)it)->isOn(); 578 bool doOn = ((QCheckListItem *)it)->isOn();
578 // we are a checklistitem for sure 579 // we are a checklistitem for sure
579 it->setSelectable( TRUE ); 580 it->setSelectable( TRUE );
580 if( AutoCollapse && ! doOn ) 581 if( AutoCollapse && ! doOn )
581 it->setOpen( doOn ); 582 it->setOpen( doOn );
582 if( doOn ) { 583 if( doOn ) {
583 // selected alternative 584 // selected alternative
584 enablePath( it->firstChild(), 585 enablePath( it->firstChild(),
585 NN->alternatives().size() > 1); 586 NN->alternatives().size() > 1);
586 } else { 587 } else {
587 // non-selected alternative 588 // non-selected alternative
588 disableTree( it->firstChild(), FALSE); 589 disableTree( it->firstChild(), FALSE);
589 } 590 }
590 } else { 591 } else {
591 // we are single subitem 592 // we are single subitem
592 it->setSelectable( TRUE ); 593 it->setSelectable( TRUE );
593 it->setOpen( TRUE ); 594 it->setOpen( TRUE );
594 enablePath( it->firstChild(), 595 enablePath( it->firstChild(),
595 NN->alternatives().size() > 1); 596 NN->alternatives().size() > 1);
596 } 597 }
597 } else { 598 } else {
598 // controller node 599 // controller node
599 it->setSelectable( TRUE ); 600 it->setSelectable( TRUE );
600 it->setOpen( TRUE ); 601 it->setOpen( TRUE );
601 enablePath( it->firstChild(), pha ); 602 enablePath( it->firstChild(), pha );
602 } 603 }
603 it = it->nextSibling(); 604 it = it->nextSibling();
604 } 605 }
605} 606}
606 607
607// do we have a complete configuration (all needs are provided for ?) 608// do we have a complete configuration (all needs are provided for ?)
608bool EditNetworkSetup::haveCompleteConfig( QListViewItem * it ) { 609bool EditNetworkSetup::haveCompleteConfig( QListViewItem * it ) {
609 610
610 // check if all below this level is selected 611 // check if all below this level is selected
611 it = ( it ) ?it : Nodes_LV->firstChild(); 612 it = ( it ) ?it : Nodes_LV->firstChild();
612 ANetNode *NN; 613 ANetNode *NN;
613 bool Found; 614 bool Found;
614 615
615 while ( it ) { 616 while ( it ) {
616 NN = (*Mapping)[it]; 617 NN = (*Mapping)[it];
617 if( NN == 0 ) { 618 if( NN == 0 ) {
618 // this item is a controller -> 619 // this item is a controller ->
619 // has radio items as children -> 620 // has radio items as children ->
620 // find selected one 621 // find selected one
621 it = it->firstChild(); 622 it = it->firstChild();
622 Found = 0; 623 Found = 0;
623 while( it ) { 624 while( it ) {
624 if( ((QCheckListItem *)it)->isOn() ) { 625 if( ((QCheckListItem *)it)->isOn() ) {
625 Found = 1; 626 Found = 1;
626 // go deeper 627 // go deeper
627 it = it->firstChild(); 628 it = it->firstChild();
628 break; 629 break;
629 } 630 }
630 it = it->nextSibling(); 631 it = it->nextSibling();
631 } 632 }
632 633
633 if( ! Found ) { 634 if( ! Found ) {
634 Log(( "Setup not complete\n" )); 635 Log(( "Setup not complete\n" ));
635 return 0; // no not complete -> a radio should have been chkd 636 return 0; // no not complete -> a radio should have been chkd
636 } 637 }
637 638
638 // it now contains selected radio 639 // it now contains selected radio
639 NN = (*Mapping)[it]; 640 NN = (*Mapping)[it];
640 } else { 641 } else {
641 // automatic selection 642 // automatic selection
642 it = it->firstChild(); 643 it = it->firstChild();
643 } 644 }
644 } 645 }
645 return 1; 646 return 1;
646} 647}
diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
index fc30bf8..e23fc9c 100644
--- a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
+++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
@@ -1,1175 +1,1175 @@
1#include <opie2/odebug.h> 1#include <opie2/odebug.h>
2#include <opie2/oledbox.h> 2#include <opie2/oledbox.h>
3#include <opie2/ofiledialog.h> 3#include <opie2/ofiledialog.h>
4 4
5using namespace Opie::Core; 5using namespace Opie::Core;
6using namespace Opie::Ui; 6using namespace Opie::Ui;
7 7
8#include <qpe/resource.h> 8#include <qpe/resource.h>
9#include <qapplication.h> 9#include <qapplication.h>
10#include <qcheckbox.h> 10#include <qcheckbox.h>
11#include <qcombobox.h> 11#include <qcombobox.h>
12#include <qdialog.h> 12#include <qdialog.h>
13#include <qdir.h> 13#include <qdir.h>
14#include <qfile.h> 14#include <qfile.h>
15#include <qgroupbox.h> 15#include <qgroupbox.h>
16#include <qheader.h> 16#include <qheader.h>
17#include <qlabel.h> 17#include <qlabel.h>
18#include <qlayout.h> 18#include <qlayout.h>
19#include <qlistbox.h> 19#include <qlistbox.h>
20#include <qlistview.h> 20#include <qlistview.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include <qprogressbar.h> 22#include <qprogressbar.h>
23#include <qpushbutton.h> 23#include <qpushbutton.h>
24#include <qscrollbar.h> 24#include <qscrollbar.h>
25#include <qtextstream.h> 25#include <qtextstream.h>
26#include <qtextview.h> 26#include <qtextview.h>
27 27
28#include <Opietooth.h> 28#include <Opietooth.h>
29#include <OTDriver.h> 29#include <OTDriver.h>
30#include <OTPeer.h> 30#include <OTPeer.h>
31#include <OTGateway.h> 31#include <OTGateway.h>
32#include <OTSDPAttribute.h> 32#include <OTSDPAttribute.h>
33#include <OTSDPService.h> 33#include <OTSDPService.h>
34#include <OTInquiry.h> 34#include <OTInquiry.h>
35 35
36#include <system.h> 36#include <system.h>
37 37
38using namespace Opietooth2; 38using namespace Opietooth2;
39 39
40namespace Opietooth2 { 40namespace Opietooth2 {
41 41
42class PeerLVI : public QListViewItem { 42class PeerLVI : public QListViewItem {
43 43
44public : 44public :
45 45
46 PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) { 46 PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) {
47 Peer = P; 47 Peer = P;
48 } 48 }
49 ~PeerLVI( void ) { 49 ~PeerLVI( void ) {
50 } 50 }
51 51
52 inline OTPeer * peer( void ) 52 inline OTPeer * peer( void )
53 { return Peer; } 53 { return Peer; }
54 54
55private : 55private :
56 56
57 OTPeer * Peer; 57 OTPeer * Peer;
58}; 58};
59 59
60class ChannelLVI : public QListViewItem { 60class ChannelLVI : public QListViewItem {
61 61
62public : 62public :
63 63
64 ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) { 64 ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) {
65 Channel = Ch; 65 Channel = Ch;
66 } 66 }
67 ~ChannelLVI( void ) { 67 ~ChannelLVI( void ) {
68 } 68 }
69 69
70 inline int channel( void ) 70 inline int channel( void )
71 { return Channel; } 71 { return Channel; }
72 72
73private : 73private :
74 74
75 int Channel; 75 int Channel;
76}; 76};
77 77
78class DriverLVI : public QListViewItem { 78class DriverLVI : public QListViewItem {
79 79
80public : 80public :
81 81
82 DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) { 82 DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) {
83 Driver = P; 83 Driver = P;
84 } 84 }
85 ~DriverLVI( void ) { 85 ~DriverLVI( void ) {
86 } 86 }
87 87
88 inline OTDriver * driver( void ) 88 inline OTDriver * driver( void )
89 { return Driver; } 89 { return Driver; }
90 90
91private : 91private :
92 92
93 OTDriver * Driver; 93 OTDriver * Driver;
94}; 94};
95 95
96class LinkKeyLVI : public QListViewItem { 96class LinkKeyLVI : public QListViewItem {
97 97
98public : 98public :
99 99
100 LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) { 100 LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) {
101 LinkKey = Ch; 101 LinkKey = Ch;
102 } 102 }
103 ~LinkKeyLVI( void ) { 103 ~LinkKeyLVI( void ) {
104 } 104 }
105 105
106 inline int index( void ) 106 inline int index( void )
107 { return LinkKey; } 107 { return LinkKey; }
108 108
109private : 109private :
110 110
111 int LinkKey; 111 int LinkKey;
112}; 112};
113}; 113};
114 114
115// 115//
116// 116//
117// 117//
118// 118//
119// 119//
120 120
121OTSniffing::OTSniffing( QWidget * parent ) : OTSniffGUI( parent ) { 121OTSniffing::OTSniffing( QWidget * parent ) : OTSniffGUI( parent ) {
122 122
123 OT = OTGateway::getOTGateway(); 123 OT = OTGateway::getOTGateway();
124 HciDump = 0; 124 HciDump = 0;
125} 125}
126 126
127OTSniffing::~OTSniffing() { 127OTSniffing::~OTSniffing() {
128 SLOT_Trace( 0 ); 128 SLOT_Trace( 0 );
129} 129}
130 130
131void OTSniffing::SLOT_Trace( bool Run ) { 131void OTSniffing::SLOT_Trace( bool Run ) {
132 132
133 if( ! Run ) { 133 if( ! Run ) {
134 if ( HciDump ) { 134 if ( HciDump ) {
135 HciDump->process().kill(); 135 HciDump->process().kill();
136 delete HciDump; 136 delete HciDump;
137 } 137 }
138 HciDump = 0; 138 HciDump = 0;
139 return; 139 return;
140 } 140 }
141 141
142 HciDump = new MyProcess(); 142 HciDump = new MyProcess();
143 QStringList SL; 143 QStringList SL;
144 144
145 SL << "/usr/sbin/hcidump"; 145 SL << "/usr/sbin/hcidump";
146 switch( DataFormat_CB->currentItem() ) { 146 switch( DataFormat_CB->currentItem() ) {
147 case 0 : // Hex 147 case 0 : // Hex
148 SL << "-x"; 148 SL << "-x";
149 break; 149 break;
150 case 1 : // Ascii 150 case 1 : // Ascii
151 SL << "-a"; 151 SL << "-a";
152 break; 152 break;
153 case 2 : // both 153 case 2 : // both
154 SL << "-X"; 154 SL << "-X";
155 break; 155 break;
156 } 156 }
157 157
158 SL << "-i"; 158 SL << "-i";
159 SL << OT->scanWith()->devname(); 159 SL << OT->scanWith()->devname();
160 160
161 connect( HciDump, 161 connect( HciDump,
162 SIGNAL( stdoutLine( const QString & ) ), 162 SIGNAL( stdoutLine( const QString & ) ),
163 this, 163 this,
164 SLOT( SLOT_Show( const QString & ) ) ); 164 SLOT( SLOT_Show( const QString & ) ) );
165 165
166 connect( HciDump, 166 connect( HciDump,
167 SIGNAL(processExited(MyProcess*) ), 167 SIGNAL(processExited(MyProcess*) ),
168 this, 168 this,
169 SLOT( SLOT_ProcessExited(MyProcess*) ) ); 169 SLOT( SLOT_ProcessExited(MyProcess*) ) );
170 170
171 HciDump->process() << SL; 171 HciDump->process() << SL;
172 172
173 if( ! HciDump->process().start( OProcess::DontCare, 173 if( ! HciDump->process().start( OProcess::DontCare,
174 OProcess::AllOutput ) 174 OProcess::AllOutput )
175 ) { 175 ) {
176 QMessageBox::warning(0, 176 QMessageBox::warning(0,
177 tr("Run hcidump"), 177 tr("Run hcidump"),
178 tr("Cannot start %1").arg(SL.join(" ")) 178 tr("Cannot start %1").arg(SL.join(" "))
179 ); 179 );
180 delete HciDump; 180 delete HciDump;
181 HciDump = 0; 181 HciDump = 0;
182 } 182 }
183 183
184} 184}
185 185
186void OTSniffing::SLOT_Show( const QString & S ) { 186void OTSniffing::SLOT_Show( const QString & S ) {
187 Output_TV->setText( Output_TV->text() + S + "\n" ); 187 Output_TV->setText( Output_TV->text() + S + "\n" );
188 188
189 QScrollBar *scroll = Output_TV->verticalScrollBar(); 189 QScrollBar *scroll = Output_TV->verticalScrollBar();
190 scroll->setValue(scroll->maxValue()); 190 scroll->setValue(scroll->maxValue());
191 //Output_LB->insertItem( S ); 191 //Output_LB->insertItem( S );
192 //Output_LB->setCurrentItem( Output_LB->count()-1 ); 192 //Output_LB->setCurrentItem( Output_LB->count()-1 );
193 //Output_LB->ensureCurrentVisible(); 193 //Output_LB->ensureCurrentVisible();
194} 194}
195 195
196void OTSniffing::SLOT_ProcessExited( MyProcess * ) { 196void OTSniffing::SLOT_ProcessExited( MyProcess * ) {
197 printf( "Exited\n" ); 197 printf( "Exited\n" );
198 delete HciDump; 198 delete HciDump;
199 HciDump = 0; 199 HciDump = 0;
200} 200}
201 201
202void OTSniffing::SLOT_Save( void ) { 202void OTSniffing::SLOT_Save( void ) {
203 QString S = OFileDialog::getSaveFileName( 203 QString S = OFileDialog::getSaveFileName(
204 OFileSelector::Extended, 204 OFileSelector::Extended,
205 QDir::home().path(), 205 QDir::home().path(),
206 QString::null, 206 QString::null,
207 MimeTypes(), 207 MimeTypes(),
208 this ); 208 this );
209 209
210 if( ! S.isEmpty() ) { 210 if( ! S.isEmpty() ) {
211 QFile F( S ); 211 QFile F( S );
212 if( ! F.open( IO_WriteOnly ) ) { 212 if( ! F.open( IO_WriteOnly ) ) {
213 QMessageBox::warning(0, 213 QMessageBox::warning(0,
214 tr("Save log"), 214 tr("Save log"),
215 tr("Cannot open %1").arg(S) 215 tr("Cannot open %1").arg(S)
216 ); 216 );
217 return; 217 return;
218 } 218 }
219 QTextStream TS( &F ); 219 QTextStream TS( &F );
220 TS << S << endl; 220 TS << S << endl;
221 } 221 }
222} 222}
223 223
224void OTSniffing::SLOT_Load( void ) { 224void OTSniffing::SLOT_Load( void ) {
225 QString S = OFileDialog::getOpenFileName( 225 QString S = OFileDialog::getOpenFileName(
226 OFileSelector::Extended, 226 OFileSelector::Extended,
227 QDir::home().path(), 227 QDir::home().path(),
228 QString::null, 228 QString::null,
229 MimeTypes(), 229 MimeTypes(),
230 this ); 230 this );
231 231
232 if( ! S.isEmpty() ) { 232 if( ! S.isEmpty() ) {
233 QFile F( S ); 233 QFile F( S );
234 if( ! F.open( IO_ReadOnly ) ) { 234 if( ! F.open( IO_ReadOnly ) ) {
235 QMessageBox::warning(0, 235 QMessageBox::warning(0,
236 tr("Save log"), 236 tr("Save log"),
237 tr("Cannot open %1").arg(S) 237 tr("Cannot open %1").arg(S)
238 ); 238 );
239 return; 239 return;
240 } 240 }
241 QTextStream TS ( &F ); 241 QTextStream TS ( &F );
242 SLOT_ClearLog(); 242 SLOT_ClearLog();
243 S = TS.read(); 243 S = TS.read();
244 // Output_LB->insertStringList( QStringList::split( "\n", S ) ); 244 // Output_LB->insertStringList( QStringList::split( "\n", S ) );
245 Output_TV->setText( S ); 245 Output_TV->setText( S );
246 } 246 }
247} 247}
248 248
249void OTSniffing::SLOT_ClearLog( void ) { 249void OTSniffing::SLOT_ClearLog( void ) {
250 // Output_LB->clear(); 250 // Output_LB->clear();
251 Output_TV->setText( "" ); 251 Output_TV->setText( "" );
252} 252}
253 253
254// 254//
255// 255//
256// 256//
257// 257//
258// 258//
259 259
260OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) : 260OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) :
261 OTPairingGUI( parent ) { 261 OTPairingGUI( parent ) {
262 262
263 OT = OTGateway::getOTGateway(); 263 OT = OTGateway::getOTGateway();
264 Icons = (_IC ) ? _IC : new OTIcons(); 264 Icons = (_IC ) ? _IC : new OTIcons();
265 MyIcons = (_IC == 0 ); 265 MyIcons = (_IC == 0 );
266 266
267 // unpairing can only be done if bluetooth is disabled 267 // unpairing can only be done if bluetooth is disabled
268 Unpair_But->setEnabled( ! OT->isEnabled() ); 268 Unpair_But->setEnabled( ! OT->isEnabled() );
269 if( ! OT->isEnabled() ) { 269 if( ! OT->isEnabled() ) {
270 Unpair_LBL->hide(); 270 Unpair_LBL->hide();
271 } else { 271 } else {
272 Unpair_LBL->show(); 272 Unpair_LBL->show();
273 } 273 }
274 274
275 // open linkkey file and load pairs 275 // open linkkey file and load pairs
276 LinkKeyArray Keys = OT->getLinkKeys(); 276 LinkKeyArray Keys = OT->getLinkKeys();
277 LinkKeyLVI * it; 277 LinkKeyLVI * it;
278 OTPeer * P; 278 OTPeer * P;
279 OTDriver * D; 279 OTDriver * D;
280 280
281 for( unsigned int i = 0 ; 281 for( unsigned int i = 0 ;
282 i < Keys.count(); 282 i < Keys.count();
283 i ++ ) { 283 i ++ ) {
284 284
285 it = new LinkKeyLVI( i, Pairs_LV ); 285 it = new LinkKeyLVI( i, Pairs_LV );
286 286
287 P = 0; 287 P = 0;
288 D = OT->findDriver( Keys[i].from() ); 288 D = OT->findDriver( Keys[i].from() );
289 289
290 if( D ) { 290 if( D ) {
291 it->setText( 0, D->devname() ); 291 it->setText( 0, D->devname() );
292 292
293 // we are source 293 // we are source
294 P = OT->findPeer( Keys[i].to() ); 294 P = OT->findPeer( Keys[i].to() );
295 295
296 if( P ) { 296 if( P ) {
297 // put name 297 // put name
298 it->setText( 1, P->name() ); 298 it->setText( 1, P->name() );
299 } else { 299 } else {
300 // unknown 300 // unknown
301 it->setText( 1, Keys[i].to().toString() ); 301 it->setText( 1, Keys[i].to().toString() );
302 } 302 }
303 303
304 // and put address as sub 304 // and put address as sub
305 QListViewItem * Sub = new QListViewItem( it ); 305 QListViewItem * Sub = new QListViewItem( it );
306 Sub->setText( 0, D->address().toString() ); 306 Sub->setText( 0, D->address().toString() );
307 Sub->setText( 1, Keys[i].to().toString() ); 307 Sub->setText( 1, Keys[i].to().toString() );
308 } else { 308 } else {
309 // perhaps we are destination 309 // perhaps we are destination
310 D = OT->findDriver( Keys[i].to() ); 310 D = OT->findDriver( Keys[i].to() );
311 311
312 if( D ) { 312 if( D ) {
313 it->setText( 1, D->devname() ); 313 it->setText( 1, D->devname() );
314 314
315 // we are source 315 // we are source
316 P = OT->findPeer( Keys[i].from() ); 316 P = OT->findPeer( Keys[i].from() );
317 317
318 if( P ) { 318 if( P ) {
319 // put name 319 // put name
320 it->setText( 0, P->name() ); 320 it->setText( 0, P->name() );
321 } else { 321 } else {
322 // unknown 322 // unknown
323 it->setText( 0, Keys[i].from().toString() ); 323 it->setText( 0, Keys[i].from().toString() );
324 } 324 }
325 325
326 // and put address as sub 326 // and put address as sub
327 QListViewItem * Sub = new QListViewItem( it ); 327 QListViewItem * Sub = new QListViewItem( it );
328 Sub->setText( 0, Keys[i].from().toString() ); 328 Sub->setText( 0, Keys[i].from().toString() );
329 Sub->setText( 1, D->address().toString() ); 329 Sub->setText( 1, D->address().toString() );
330 } else { 330 } else {
331 // nor source nor destination -> unknown 331 // nor source nor destination -> unknown
332 it->setText( 0, Keys[i].from().toString() ); 332 it->setText( 0, Keys[i].from().toString() );
333 it->setText( 1, Keys[i].to().toString() ); 333 it->setText( 1, Keys[i].to().toString() );
334 } 334 }
335 } 335 }
336 } 336 }
337} 337}
338 338
339 339
340OTPairing::~OTPairing() { 340OTPairing::~OTPairing() {
341 if( MyIcons ) 341 if( MyIcons )
342 delete Icons; 342 delete Icons;
343 OTGateway::releaseOTGateway(); 343 OTGateway::releaseOTGateway();
344} 344}
345 345
346void OTPairing::SLOT_Unpair( ) { 346void OTPairing::SLOT_Unpair( ) {
347 // find selected pair 347 // find selected pair
348 348
349 QListViewItem * it = Pairs_LV->firstChild(); 349 QListViewItem * it = Pairs_LV->firstChild();
350 while( it ) { 350 while( it ) {
351 if( it->isSelected() ) { 351 if( it->isSelected() ) {
352 // confirm ? 352 // confirm ?
353 if( QMessageBox::warning(0, 353 if( QMessageBox::warning(0,
354 tr("Break pairing"), 354 tr("Break pairing"),
355 tr("Sure ?"), 355 tr("Sure ?"),
356 tr("Yes, break"), 356 tr("Yes, break"),
357 tr("No, don't break") ) == 0 ) { 357 tr("No, don't break") ) == 0 ) {
358 LinkKeyLVI * KPIt = (LinkKeyLVI *)it; 358 LinkKeyLVI * KPIt = (LinkKeyLVI *)it;
359 // break 359 // break
360 OT->removeLinkKey( KPIt->index() ); 360 OT->removeLinkKey( KPIt->index() );
361 delete KPIt; 361 delete KPIt;
362 } 362 }
363 return; 363 return;
364 } 364 }
365 it= it->nextSibling(); 365 it= it->nextSibling();
366 } 366 }
367} 367}
368 368
369// 369//
370// 370//
371// 371//
372// 372//
373// 373//
374 374
375OTScan::OTScan( QWidget * parent, OTIcons * _IC ) : 375OTScan::OTScan( QWidget * parent, OTIcons * _IC ) :
376 OTScanGUI( parent ), Filter() { 376 OTScanGUI( parent ), Filter() {
377 377
378 OT = OTGateway::getOTGateway(); 378 OT = OTGateway::getOTGateway();
379 379
380 Icons = (_IC ) ? _IC : new OTIcons(); 380 Icons = (_IC ) ? _IC : new OTIcons();
381 MyIcons = (_IC == 0 ); 381 MyIcons = (_IC == 0 );
382 DetectedPeers_LV->header()->hide(); 382 DetectedPeers_LV->header()->hide();
383 Current = 0; 383 Current = 0;
384 SelectedPeer = 0; 384 SelectedPeer = 0;
385 SelectedChannel = 0; 385 SelectedChannel = 0;
386 386
387 StrengthTimer = new QTimer( this ); 387 StrengthTimer = new QTimer( this );
388 connect( StrengthTimer, 388 connect( StrengthTimer,
389 SIGNAL( timeout()), 389 SIGNAL( timeout()),
390 this, 390 this,
391 SLOT( SLOT_UpdateStrength()) 391 SLOT( SLOT_UpdateStrength())
392 ); 392 );
393 393
394 connect( OT, 394 connect( OT,
395 SIGNAL( detectedPeer( OTPeer *, bool )), 395 SIGNAL( detectedPeer( OTPeer *, bool )),
396 this, 396 this,
397 SLOT( SLOT_NewPeer( OTPeer *, bool )) 397 SLOT( SLOT_NewPeer( OTPeer *, bool ))
398 ); 398 );
399 connect( OT, 399 connect( OT,
400 SIGNAL( finishedDetecting()), 400 SIGNAL( finishedDetecting()),
401 this, 401 this,
402 SLOT( SLOT_FinishedDetecting()) 402 SLOT( SLOT_FinishedDetecting())
403 ); 403 );
404 404
405 // populate with peers we already know about 405 // populate with peers we already know about
406 const PeerVector & P = OT->peers(); 406 const PeerVector & P = OT->peers();
407 for( unsigned int i = 0; 407 for( unsigned int i = 0;
408 i < P.count(); 408 i < P.count();
409 i ++ ) { 409 i ++ ) {
410 SLOT_NewPeer( P[i], TRUE ); 410 SLOT_NewPeer( P[i], TRUE );
411 } 411 }
412 412
413 // populate State fram 413 // populate State fram
414 { QHBoxLayout * H =new QHBoxLayout( State_Frm ); 414 { QHBoxLayout * H =new QHBoxLayout( State_Frm );
415 415
416 Paired_Led = new OLedBox( green, State_Frm ); 416 Paired_Led = new OLedBox( green, State_Frm );
417 QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm ); 417 QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm );
418 418
419 H->addWidget( Paired_Led ); 419 H->addWidget( Paired_Led );
420 H->addWidget( L1 ); 420 H->addWidget( L1 );
421 H->addStretch( 1 ); 421 H->addStretch( 1 );
422 } 422 }
423} 423}
424 424
425OTScan::~OTScan() { 425OTScan::~OTScan() {
426 if( MyIcons ) 426 if( MyIcons )
427 delete Icons; 427 delete Icons;
428 OTGateway::releaseOTGateway(); 428 OTGateway::releaseOTGateway();
429 429
430 // send all peers that we do not care about states 430 // send all peers that we do not care about states
431 QListViewItem * Lit = DetectedPeers_LV->firstChild(); 431 QListViewItem * Lit = DetectedPeers_LV->firstChild();
432 while( Lit ) { 432 while( Lit ) {
433 ((PeerLVI *)Lit)->peer()->stopFindingOutState( ); 433 ((PeerLVI *)Lit)->peer()->stopFindingOutState( );
434 Lit = Lit->nextSibling(); 434 Lit = Lit->nextSibling();
435 } 435 }
436} 436}
437 437
438// static scan dialog function 438// static scan dialog function
439int OTScan::getDevice( OTPeer *& Peer, 439int OTScan::getDevice( OTPeer *& Peer,
440 int & Channel, 440 int & Channel,
441 OTGateway * OT, 441 OTGateway * OT,
442 const UUIDVector & Filter, 442 const UUIDVector & Filter,
443 QWidget* Parent ) { 443 QWidget* Parent ) {
444 bool IsUp = 0; 444 bool IsUp = 0;
445 unsigned int i; 445 unsigned int i;
446 446
447 if( ! OT->isEnabled() ) { 447 if( ! OT || ! OT->isEnabled() ) {
448 QMessageBox::warning( 0, 448 QMessageBox::warning( 0,
449 tr("Scanning problem"), 449 tr("Scanning problem"),
450 tr("Bluetooth not enabled" ) 450 tr("Bluetooth not enabled" )
451 ); 451 );
452 return QDialog::Rejected; 452 return QDialog::Rejected;
453 } 453 }
454 454
455 // check if bluetooth is up 455 // check if bluetooth is up
456 OTDriverList & DL = OT->getDriverList(); 456 OTDriverList & DL = OT->getDriverList();
457 for( i = 0; 457 for( i = 0;
458 i < DL.count(); 458 i < DL.count();
459 i ++ ) { 459 i ++ ) {
460 if( DL[i]->isUp() ) { 460 if( DL[i]->isUp() ) {
461 // one device that is up found 461 // one device that is up found
462 IsUp = 1; 462 IsUp = 1;
463 break; 463 break;
464 } 464 }
465 } 465 }
466 466
467 // use this driver 467 // use this driver
468 OT->setScanWith( OT->driver(i) ); 468 OT->setScanWith( OT->driver(i) );
469 469
470 // create dialog 470 // create dialog
471 QDialog * Dlg = new QDialog( Parent, 0, TRUE ); 471 QDialog * Dlg = new QDialog( Parent, 0, TRUE );
472 QVBoxLayout * V = new QVBoxLayout( Dlg ); 472 QVBoxLayout * V = new QVBoxLayout( Dlg );
473 OTScan * Scn = new OTScan( Dlg ); 473 OTScan * Scn = new OTScan( Dlg );
474 474
475 connect( Scn, 475 connect( Scn,
476 SIGNAL( selected() ), 476 SIGNAL( selected() ),
477 Dlg, 477 Dlg,
478 SLOT( accept() ) 478 SLOT( accept() )
479 ); 479 );
480 480
481 if( Filter ) { 481 if( Filter ) {
482 Scn->setScanFilter( Filter ); 482 Scn->setScanFilter( Filter );
483 } 483 }
484 484
485 V->addWidget( Scn ); 485 V->addWidget( Scn );
486 Dlg->setCaption( tr("Scan Neighbourhood" ) ); 486 Dlg->setCaption( tr("Scan Neighbourhood" ) );
487 Dlg->showMaximized(); 487 Dlg->showMaximized();
488 int rv = Dlg->exec(); 488 int rv = Dlg->exec();
489 489
490 if( rv == QDialog::Accepted ) { 490 if( rv == QDialog::Accepted ) {
491 // get peer 491 // get peer
492 Peer = Scn->selectedPeer(); 492 Peer = Scn->selectedPeer();
493 if( Peer == 0 ) { 493 if( Peer == 0 ) {
494 // no peer selected 494 // no peer selected
495 rv = QDialog::Rejected; 495 rv = QDialog::Rejected;
496 } else { 496 } else {
497 Channel = Scn->selectedChannel(); 497 Channel = Scn->selectedChannel();
498 } 498 }
499 } 499 }
500 500
501 delete Dlg; 501 delete Dlg;
502 502
503 return rv; 503 return rv;
504} 504}
505 505
506void OTScan::setScanFilter( const UUIDVector & V ) { 506void OTScan::setScanFilter( const UUIDVector & V ) {
507 Filter = V; 507 Filter = V;
508} 508}
509 509
510void OTScan::resetScanFilter( void ) { 510void OTScan::resetScanFilter( void ) {
511 Filter.truncate(0); 511 Filter.truncate(0);
512} 512}
513 513
514void OTScan::SLOT_DoScan( bool DoIt ) { 514void OTScan::SLOT_DoScan( bool DoIt ) {
515 if( DoIt ) { 515 if( DoIt ) {
516 OT->scanNeighbourhood(); 516 OT->scanNeighbourhood();
517 } else { 517 } else {
518 OT->stopScanOfNeighbourhood(); 518 OT->stopScanOfNeighbourhood();
519 } 519 }
520 520
521 scanMode( DoIt ); 521 scanMode( DoIt );
522} 522}
523 523
524// double clicked on a device 524// double clicked on a device
525void OTScan::SLOT_Selected( QListViewItem * it ) { 525void OTScan::SLOT_Selected( QListViewItem * it ) {
526 if( ! it ) 526 if( ! it )
527 return; 527 return;
528 528
529 if( Filter.count() > 0 ) { 529 if( Filter.count() > 0 ) {
530 // filter on service 530 // filter on service
531 if( it->depth() == 0 ) { 531 if( it->depth() == 0 ) {
532 // select a service and not a device 532 // select a service and not a device
533 return; 533 return;
534 } 534 }
535 535
536 // store result 536 // store result
537 SelectedPeer = ((PeerLVI *)it->parent())->peer(); 537 SelectedPeer = ((PeerLVI *)it->parent())->peer();
538 SelectedChannel = ((ChannelLVI *)it)->channel(); 538 SelectedChannel = ((ChannelLVI *)it)->channel();
539 } else { 539 } else {
540 // click on device 540 // click on device
541 if( it->depth() != 0 ) { 541 if( it->depth() != 0 ) {
542 return; 542 return;
543 } 543 }
544 544
545 SelectedPeer = ((PeerLVI *)it)->peer(); 545 SelectedPeer = ((PeerLVI *)it)->peer();
546 SelectedChannel = 0; 546 SelectedChannel = 0;
547 } 547 }
548 odebug << "Selected " << SelectedPeer->address().toString() << 548 odebug << "Selected " << SelectedPeer->address().toString() <<
549 " Channel " << SelectedChannel << oendl; 549 " Channel " << SelectedChannel << oendl;
550 emit selected(); 550 emit selected();
551} 551}
552 552
553void OTScan::SLOT_FinishedDetecting( ) { 553void OTScan::SLOT_FinishedDetecting( ) {
554 scanMode( false ); 554 scanMode( false );
555} 555}
556 556
557void OTScan::SLOT_CleanupOld( ) { 557void OTScan::SLOT_CleanupOld( ) {
558 558
559 // iterate over all peers and find those that 559 // iterate over all peers and find those that
560 // are down and have no pairing info 560 // are down and have no pairing info
561 OTPeer * TheP; 561 OTPeer * TheP;
562 const LinkKeyArray & Keys = OT->getLinkKeys(); 562 const LinkKeyArray & Keys = OT->getLinkKeys();
563 563
564 QListViewItem * Lit = DetectedPeers_LV->firstChild(); 564 QListViewItem * Lit = DetectedPeers_LV->firstChild();
565 while( Lit ) { 565 while( Lit ) {
566 TheP = ((PeerLVI *)Lit)->peer(); 566 TheP = ((PeerLVI *)Lit)->peer();
567 if( TheP->state() == OTPeer::Peer_Down ) { 567 if( TheP->state() == OTPeer::Peer_Down ) {
568 unsigned int k; 568 unsigned int k;
569 569
570 // what about linkkeys ? 570 // what about linkkeys ?
571 for( k = 0; k < Keys.count(); k ++ ) { 571 for( k = 0; k < Keys.count(); k ++ ) {
572 if( TheP->address() == Keys[k].to() || 572 if( TheP->address() == Keys[k].to() ||
573 TheP->address() == Keys[k].from() 573 TheP->address() == Keys[k].from()
574 ) { 574 ) {
575 // part of linkkey 575 // part of linkkey
576 odebug << "LINKKEY " << TheP->address().toString() << oendl; 576 odebug << "LINKKEY " << TheP->address().toString() << oendl;
577 break; 577 break;
578 } 578 }
579 } 579 }
580 580
581 if( k == Keys.count() ) { 581 if( k == Keys.count() ) {
582 odebug << "RM LINKKEY " << TheP->address().toString() << oendl; 582 odebug << "RM LINKKEY " << TheP->address().toString() << oendl;
583 // not found -> remember to remove this peer 583 // not found -> remember to remove this peer
584 QListViewItem * Nit; 584 QListViewItem * Nit;
585 OT->removePeer( TheP ); 585 OT->removePeer( TheP );
586 Nit = Lit->nextSibling(); 586 Nit = Lit->nextSibling();
587 delete Lit; 587 delete Lit;
588 Lit = Nit; 588 Lit = Nit;
589 continue; 589 continue;
590 } 590 }
591 } else { 591 } else {
592 odebug << "NODOWN " << TheP->address().toString() << oendl; 592 odebug << "NODOWN " << TheP->address().toString() << oendl;
593 } 593 }
594 594
595 Lit = Lit->nextSibling(); 595 Lit = Lit->nextSibling();
596 } 596 }
597} 597}
598 598
599void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){ 599void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){
600 PeerLVI * it = 0; 600 PeerLVI * it = 0;
601 601
602 if( IsNew ) { 602 if( IsNew ) {
603 it = new PeerLVI( P, DetectedPeers_LV ); 603 it = new PeerLVI( P, DetectedPeers_LV );
604 } else { 604 } else {
605 // find peer in table 605 // find peer in table
606 QListViewItem * Lit = DetectedPeers_LV->firstChild(); 606 QListViewItem * Lit = DetectedPeers_LV->firstChild();
607 while( Lit ) { 607 while( Lit ) {
608 if( ((PeerLVI *)Lit)->peer() == P ) { 608 if( ((PeerLVI *)Lit)->peer() == P ) {
609 // this item 609 // this item
610 it = (PeerLVI *)Lit; 610 it = (PeerLVI *)Lit;
611 break; 611 break;
612 } 612 }
613 Lit = Lit->nextSibling(); 613 Lit = Lit->nextSibling();
614 } 614 }
615 615
616 if( ! it ) { 616 if( ! it ) {
617 odebug << "Should not occur" << oendl; 617 odebug << "Should not occur" << oendl;
618 return; 618 return;
619 } 619 }
620 } 620 }
621 621
622 // update/show info 622 // update/show info
623 it->setText( 0, P->name() ); 623 it->setText( 0, P->name() );
624 it->setPixmap(0, Icons->deviceIcon( 624 it->setPixmap(0, Icons->deviceIcon(
625 OT->deviceTypeToName( P->deviceClass() ) ) ); 625 OT->deviceTypeToName( P->deviceClass() ) ) );
626 626
627 // tell peer to report its state async 627 // tell peer to report its state async
628 connect( P, 628 connect( P,
629 SIGNAL( peerStateReport( OTPeer *)), 629 SIGNAL( peerStateReport( OTPeer *)),
630 this, 630 this,
631 SLOT( SLOT_PeerState( OTPeer *)) 631 SLOT( SLOT_PeerState( OTPeer *))
632 ); 632 );
633 633
634 if( IsNew ) { 634 if( IsNew ) {
635 // find state 635 // find state
636 refreshState( (PeerLVI *)it, 1 ); 636 refreshState( (PeerLVI *)it, 1 );
637 } else { 637 } else {
638 // update staet 638 // update staet
639 SLOT_PeerState( P ); 639 SLOT_PeerState( P );
640 } 640 }
641} 641}
642 642
643void OTScan::SLOT_PeerState( OTPeer * P ) { 643void OTScan::SLOT_PeerState( OTPeer * P ) {
644 PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild(); 644 PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild();
645 while( it ) { 645 while( it ) {
646 if( it->peer() == P ) { 646 if( it->peer() == P ) {
647 break; 647 break;
648 } 648 }
649 it = (PeerLVI * )it->nextSibling(); 649 it = (PeerLVI * )it->nextSibling();
650 } 650 }
651 651
652 if( ! it ) 652 if( ! it )
653 return; 653 return;
654 654
655 switch( P->state() ) { 655 switch( P->state() ) {
656 case OTPeer::Peer_Unknown : 656 case OTPeer::Peer_Unknown :
657 case OTPeer::Peer_Down : 657 case OTPeer::Peer_Down :
658 it->setPixmap( 1, 0 ); 658 it->setPixmap( 1, 0 );
659 break; 659 break;
660 case OTPeer::Peer_Up : 660 case OTPeer::Peer_Up :
661 it->setPixmap( 1, Icons->loadPixmap( 661 it->setPixmap( 1, Icons->loadPixmap(
662 ( P->connectedTo() ) ? "connected" : "notconnected" ) ); 662 ( P->connectedTo() ) ? "connected" : "notconnected" ) );
663 if( it == Current && ! StrengthTimer->isActive() ) { 663 if( it == Current && ! StrengthTimer->isActive() ) {
664 // start showing strength 664 // start showing strength
665 StrengthTimer->start( 1000, FALSE ); 665 StrengthTimer->start( 1000, FALSE );
666 SLOT_UpdateStrength(); 666 SLOT_UpdateStrength();
667 } 667 }
668 break; 668 break;
669 } 669 }
670} 670}
671 671
672void OTScan::SLOT_RefreshState( void ) { 672void OTScan::SLOT_RefreshState( void ) {
673 673
674 QListViewItem * it = DetectedPeers_LV->firstChild(); 674 QListViewItem * it = DetectedPeers_LV->firstChild();
675 while( it ) { 675 while( it ) {
676 if( it->isSelected() ) { 676 if( it->isSelected() ) {
677 break; 677 break;
678 } 678 }
679 it = it->nextSibling(); 679 it = it->nextSibling();
680 } 680 }
681 681
682 if( ! it ) 682 if( ! it )
683 return; 683 return;
684 684
685 refreshState( (PeerLVI *)it, 1 ); 685 refreshState( (PeerLVI *)it, 1 );
686} 686}
687 687
688void OTScan::refreshState( PeerLVI * it, bool Force ) { 688void OTScan::refreshState( PeerLVI * it, bool Force ) {
689 it->setPixmap( 1, Icons->loadPixmap( "find" ) ); 689 it->setPixmap( 1, Icons->loadPixmap( "find" ) );
690 it->peer()->findOutState( 30, Force ); 690 it->peer()->findOutState( 30, Force );
691} 691}
692 692
693void OTScan::SLOT_Show( QListViewItem * it ) { 693void OTScan::SLOT_Show( QListViewItem * it ) {
694 694
695 if( ! it || it->depth() > 0 ) 695 if( ! it || it->depth() > 0 )
696 return; 696 return;
697 697
698 QString S; 698 QString S;
699 699
700 Current = (PeerLVI *)it; 700 Current = (PeerLVI *)it;
701 701
702 Strength_PB->setProgress( 0 ); // reset 702 Strength_PB->setProgress( 0 ); // reset
703 Address_LBL->setText( Current->peer()->address().toString() ); 703 Address_LBL->setText( Current->peer()->address().toString() );
704 Peer_GB->setTitle( Current->peer()->name() ); 704 Peer_GB->setTitle( Current->peer()->name() );
705 705
706 const LinkKeyArray & Keys = OT->getLinkKeys(); 706 const LinkKeyArray & Keys = OT->getLinkKeys();
707 707
708 Paired_Led->setOn( FALSE ); 708 Paired_Led->setOn( FALSE );
709 for( unsigned int i = 0; 709 for( unsigned int i = 0;
710 i < Keys.count(); 710 i < Keys.count();
711 i ++ ) { 711 i ++ ) {
712 if( Current->peer()->address() == Keys[i].to() ) { 712 if( Current->peer()->address() == Keys[i].to() ) {
713 Paired_Led->setOn( TRUE ); 713 Paired_Led->setOn( TRUE );
714 break; 714 break;
715 } 715 }
716 } 716 }
717 717
718 if( Current->peer()->state() == OTPeer::Peer_Up ) { 718 if( Current->peer()->state() == OTPeer::Peer_Up ) {
719 RefreshServices_But->setEnabled( TRUE ); 719 RefreshServices_But->setEnabled( TRUE );
720 StrengthTimer->start( 1000, FALSE ); 720 StrengthTimer->start( 1000, FALSE );
721 SLOT_UpdateStrength(); 721 SLOT_UpdateStrength();
722 } else { 722 } else {
723 RefreshServices_But->setEnabled( FALSE ); 723 RefreshServices_But->setEnabled( FALSE );
724 } 724 }
725 725
726} 726}
727 727
728void OTScan::SLOT_UpdateStrength( void ) { 728void OTScan::SLOT_UpdateStrength( void ) {
729 OTDriver * D = Current->peer()->connectedTo(); 729 OTDriver * D = Current->peer()->connectedTo();
730 730
731 if( D ) { 731 if( D ) {
732 long Q = D->getLinkQuality( Current->peer()->address() ); 732 long Q = D->getLinkQuality( Current->peer()->address() );
733 Strength_PB->setProgress( Q ); 733 Strength_PB->setProgress( Q );
734 if( ! Q ) { 734 if( ! Q ) {
735 // no quality 735 // no quality
736 Strength_PB->setEnabled( TRUE ); 736 Strength_PB->setEnabled( TRUE );
737 StrengthTimer->stop(); 737 StrengthTimer->stop();
738 } 738 }
739 } else { 739 } else {
740 Strength_PB->setEnabled( FALSE ); 740 Strength_PB->setEnabled( FALSE );
741 Strength_PB->setProgress( 0 ); 741 Strength_PB->setProgress( 0 );
742 // no point in continuing 742 // no point in continuing
743 StrengthTimer->stop(); 743 StrengthTimer->stop();
744 } 744 }
745} 745}
746 746
747void OTScan::SLOT_RefreshServices( void ) { 747void OTScan::SLOT_RefreshServices( void ) {
748 748
749 QListViewItem * it = DetectedPeers_LV->firstChild(); 749 QListViewItem * it = DetectedPeers_LV->firstChild();
750 while( it ) { 750 while( it ) {
751 if( it->isSelected() ) { 751 if( it->isSelected() ) {
752 break; 752 break;
753 } 753 }
754 it = it->nextSibling(); 754 it = it->nextSibling();
755 } 755 }
756 756
757 if( ! it ) 757 if( ! it )
758 return; 758 return;
759 759
760 QString S; 760 QString S;
761 PeerLVI * PI = (PeerLVI *)it; 761 PeerLVI * PI = (PeerLVI *)it;
762 762
763 scanMode( true ); 763 scanMode( true );
764 qApp->processEvents(0); 764 qApp->processEvents(0);
765 765
766 ServiceVector & V = PI->peer()->services(); 766 ServiceVector & V = PI->peer()->services();
767 767
768 while( PI->firstChild() ) { 768 while( PI->firstChild() ) {
769 // remove children 769 // remove children
770 delete PI->firstChild(); 770 delete PI->firstChild();
771 } 771 }
772 772
773 for( unsigned int i = 0 ; 773 for( unsigned int i = 0 ;
774 i < V.count(); 774 i < V.count();
775 i ++ ) { 775 i ++ ) {
776 QString S; 776 QString S;
777 S = V[i]->name(); 777 S = V[i]->name();
778 778
779 if( S.isEmpty() ) { 779 if( S.isEmpty() ) {
780 continue; 780 continue;
781 } 781 }
782 782
783 { QListViewItem * SIt; 783 { QListViewItem * SIt;
784 UUIDVector UIDV; 784 UUIDVector UIDV;
785 QPixmap Pm; 785 QPixmap Pm;
786 bool Done = 0; 786 bool Done = 0;
787 bool R; 787 bool R;
788 short ID; 788 short ID;
789 789
790 SIt = 0; 790 SIt = 0;
791 791
792 UIDV = V[i]->classIDList(); 792 UIDV = V[i]->classIDList();
793 // first all UUID ! 1200 12ff (Genericprofiles) 793 // first all UUID ! 1200 12ff (Genericprofiles)
794 for( unsigned int j = 0; 794 for( unsigned int j = 0;
795 j < UIDV.count(); 795 j < UIDV.count();
796 j ++ ) { 796 j ++ ) {
797 797
798 if( Filter.count() ) { 798 if( Filter.count() ) {
799 bool FilterOut = 1; 799 bool FilterOut = 1;
800 // filter out if not in list 800 // filter out if not in list
801 for( unsigned int ff = 0; 801 for( unsigned int ff = 0;
802 ff < Filter.count(); 802 ff < Filter.count();
803 ff ++ ) { 803 ff ++ ) {
804 if( UIDV[j] == Filter[ff] ) { 804 if( UIDV[j] == Filter[ff] ) {
805 FilterOut = 0; 805 FilterOut = 0;
806 break; 806 break;
807 } 807 }
808 } 808 }
809 809
810 if( FilterOut ) { 810 if( FilterOut ) {
811 // not in filter list 811 // not in filter list
812 continue; 812 continue;
813 } 813 }
814 } // else show 814 } // else show
815 815
816 ID = UIDV[j].toShort(); 816 ID = UIDV[j].toShort();
817 if( ID < 0x1200 || ID > 0x12ff ) { 817 if( ID < 0x1200 || ID > 0x12ff ) {
818 // use this profile 818 // use this profile
819 if( R ) { 819 if( R ) {
820 unsigned int ch; 820 unsigned int ch;
821 bool has; 821 bool has;
822 has = V[i]->rfcommChannel( ch ); 822 has = V[i]->rfcommChannel( ch );
823 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); 823 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
824 SIt->setText(0, V[i]->name() ); 824 SIt->setText(0, V[i]->name() );
825 825
826 Pm = Icons->serviceIcon( ID, R ); 826 Pm = Icons->serviceIcon( ID, R );
827 SIt->setPixmap(0, Pm ); 827 SIt->setPixmap(0, Pm );
828 Done = 1; 828 Done = 1;
829 break; 829 break;
830 } 830 }
831 } 831 }
832 } 832 }
833 833
834 if( ! Done ) { 834 if( ! Done ) {
835 // check other range too 835 // check other range too
836 for( unsigned int j = 0; 836 for( unsigned int j = 0;
837 j < UIDV.count(); 837 j < UIDV.count();
838 j ++ ) { 838 j ++ ) {
839 839
840 if( Filter.count() ) { 840 if( Filter.count() ) {
841 bool FilterOut = 1; 841 bool FilterOut = 1;
842 // filter out if not in list 842 // filter out if not in list
843 for( unsigned int ff = 0; 843 for( unsigned int ff = 0;
844 ff < Filter.count(); 844 ff < Filter.count();
845 ff ++ ) { 845 ff ++ ) {
846 if( UIDV[j] == Filter[ff] ) { 846 if( UIDV[j] == Filter[ff] ) {
847 FilterOut = 0; 847 FilterOut = 0;
848 break; 848 break;
849 } 849 }
850 } 850 }
851 851
852 if( FilterOut ) { 852 if( FilterOut ) {
853 // not in filter list 853 // not in filter list
854 continue; 854 continue;
855 } 855 }
856 } // else show 856 } // else show
857 857
858 ID = UIDV[j].toShort(); 858 ID = UIDV[j].toShort();
859 if( ID >= 0x1200 && ID <= 0x12ff ) { 859 if( ID >= 0x1200 && ID <= 0x12ff ) {
860 // use this profile 860 // use this profile
861 unsigned int ch; 861 unsigned int ch;
862 bool has; 862 bool has;
863 has = V[i]->rfcommChannel( ch ); 863 has = V[i]->rfcommChannel( ch );
864 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); 864 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
865 SIt->setText(0, V[i]->name() ); 865 SIt->setText(0, V[i]->name() );
866 866
867 Pm = Icons->serviceIcon( ID, R ); 867 Pm = Icons->serviceIcon( ID, R );
868 SIt->setPixmap(0, Pm ); 868 SIt->setPixmap(0, Pm );
869 869
870 break; 870 break;
871 } 871 }
872 } 872 }
873 } 873 }
874 874
875 } 875 }
876 } 876 }
877 877
878 scanMode( false ); 878 scanMode( false );
879} 879}
880 880
881void OTScan::scanMode( bool M ) { 881void OTScan::scanMode( bool M ) {
882 // avoid infinite loop because it triggers DoScan 882 // avoid infinite loop because it triggers DoScan
883 Detect_But->blockSignals( TRUE ); 883 Detect_But->blockSignals( TRUE );
884 Detect_But->setOn( M ); 884 Detect_But->setOn( M );
885 Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") ); 885 Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") );
886 Detect_But->blockSignals( FALSE ); 886 Detect_But->blockSignals( FALSE );
887} 887}
888 888
889// 889//
890// 890//
891// 891//
892// 892//
893// 893//
894 894
895OTManage::OTManage( QWidget * parent, OTIcons * _IC ) : 895OTManage::OTManage( QWidget * parent, OTIcons * _IC ) :
896 OTManageGUI( parent ) { 896 OTManageGUI( parent ) {
897 897
898 OT = OTGateway::getOTGateway(); 898 OT = OTGateway::getOTGateway();
899 899
900 Icons = (_IC ) ? _IC : new OTIcons(); 900 Icons = (_IC ) ? _IC : new OTIcons();
901 MyIcons = (_IC == 0 ); 901 MyIcons = (_IC == 0 );
902 AllDrivers_LV->setSorting(-1); 902 AllDrivers_LV->setSorting(-1);
903 903
904 connect( OT, 904 connect( OT,
905 SIGNAL( driverListChanged() ), 905 SIGNAL( driverListChanged() ),
906 this, 906 this,
907 SLOT( SLOT_DriverListChanged() ) 907 SLOT( SLOT_DriverListChanged() )
908 ); 908 );
909 connect( OT, 909 connect( OT,
910 SIGNAL( stateChange( OTDriver *, bool ) ), 910 SIGNAL( stateChange( OTDriver *, bool ) ),
911 this, 911 this,
912 SLOT( SLOT_StateChange( OTDriver *, bool ) ) 912 SLOT( SLOT_StateChange( OTDriver *, bool ) )
913 ); 913 );
914 914
915 SLOT_DriverListChanged(); 915 SLOT_DriverListChanged();
916 916
917 AllDrivers_LV->header()->hide(); 917 AllDrivers_LV->header()->hide();
918} 918}
919 919
920OTManage::~OTManage() { 920OTManage::~OTManage() {
921 if( MyIcons ) 921 if( MyIcons )
922 delete Icons; 922 delete Icons;
923 OTGateway::releaseOTGateway(); 923 OTGateway::releaseOTGateway();
924} 924}
925 925
926void OTManage::SLOT_ShowDriver( QListViewItem * It ) { 926void OTManage::SLOT_ShowDriver( QListViewItem * It ) {
927 if( It == 0 || It->depth() > 0 ) 927 if( It == 0 || It->depth() > 0 )
928 // not toplevel 928 // not toplevel
929 return; 929 return;
930 930
931 DriverLVI * it = (DriverLVI *) It; 931 DriverLVI * it = (DriverLVI *) It;
932 DriverIsUp_CB->setChecked( it->driver()->isUp() ); 932 DriverIsUp_CB->setChecked( it->driver()->isUp() );
933} 933}
934 934
935void OTManage::SLOT_UpDriver( bool Up ) { 935void OTManage::SLOT_UpDriver( bool Up ) {
936 QListViewItem * it = AllDrivers_LV->firstChild(); 936 QListViewItem * it = AllDrivers_LV->firstChild();
937 while( it ) { 937 while( it ) {
938 if( it->isSelected() ) { 938 if( it->isSelected() ) {
939 OTDriver * D = ((DriverLVI *)it)->driver(); 939 OTDriver * D = ((DriverLVI *)it)->driver();
940 odebug << "UP driver " << D->devname() << oendl; 940 odebug << "UP driver " << D->devname() << oendl;
941 // this 941 // this
942 D->setUp( Up ); 942 D->setUp( Up );
943 return; 943 return;
944 } 944 }
945 it = it->nextSibling(); 945 it = it->nextSibling();
946 } 946 }
947} 947}
948 948
949void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) { 949void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) {
950 QListViewItem * it = AllDrivers_LV->firstChild(); 950 QListViewItem * it = AllDrivers_LV->firstChild();
951 while( it ) { 951 while( it ) {
952 if( ((DriverLVI *)it)->driver() == D ) { 952 if( ((DriverLVI *)it)->driver() == D ) {
953 it->setPixmap( 0, 953 it->setPixmap( 0,
954 Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) ); 954 Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) );
955 return; 955 return;
956 } 956 }
957 it = it->nextSibling(); 957 it = it->nextSibling();
958 } 958 }
959} 959}
960 960
961void OTManage::SLOT_DriverListChanged( ) { 961void OTManage::SLOT_DriverListChanged( ) {
962 DriverLVI * It; 962 DriverLVI * It;
963 QListViewItem * Sub; 963 QListViewItem * Sub;
964 QListViewItem * First = 0; 964 QListViewItem * First = 0;
965 OTDriver* D; 965 OTDriver* D;
966 OTDriverList & DL = OT->getDriverList(); 966 OTDriverList & DL = OT->getDriverList();
967 967
968 AllDrivers_LV->clear(); 968 AllDrivers_LV->clear();
969 for( unsigned int i = 0; 969 for( unsigned int i = 0;
970 i < DL.count(); 970 i < DL.count();
971 i ++ ) { 971 i ++ ) {
972 D = DL[i]; 972 D = DL[i];
973 It = new DriverLVI( D, AllDrivers_LV ); 973 It = new DriverLVI( D, AllDrivers_LV );
974 974
975 if( ! First ) 975 if( ! First )
976 First = It; 976 First = It;
977 977
978 It->setText( 0, D->devname() ); 978 It->setText( 0, D->devname() );
979 It->setPixmap( 0, 979 It->setPixmap( 0,
980 Icons->loadPixmap( (D->isUp()) ? 980 Icons->loadPixmap( (D->isUp()) ?
981 "bluezon" : "bluezoff" ) ); 981 "bluezon" : "bluezoff" ) );
982 982
983 Sub = new QListViewItem( It ); 983 Sub = new QListViewItem( It );
984 Sub->setText( 0, tr( "Name" ) ); 984 Sub->setText( 0, tr( "Name" ) );
985 Sub->setText( 1, D->name() ); 985 Sub->setText( 1, D->name() );
986 986
987 Sub = new QListViewItem( It ); 987 Sub = new QListViewItem( It );
988 Sub->setText( 0, tr( "Address" ) ); 988 Sub->setText( 0, tr( "Address" ) );
989 Sub->setText( 1, D->address().toString() ); 989 Sub->setText( 1, D->address().toString() );
990 990
991 Sub = new QListViewItem( It ); 991 Sub = new QListViewItem( It );
992 Sub->setText( 0, tr( "Revision" ) ); 992 Sub->setText( 0, tr( "Revision" ) );
993 Sub->setText( 1, D->revision() ); 993 Sub->setText( 1, D->revision() );
994 994
995 Sub = new QListViewItem( It ); 995 Sub = new QListViewItem( It );
996 Sub->setText( 0, tr( "Manufacturer" ) ); 996 Sub->setText( 0, tr( "Manufacturer" ) );
997 Sub->setText( 1, D->manufacturer() ); 997 Sub->setText( 1, D->manufacturer() );
998 998
999 QString Service, Device; 999 QString Service, Device;
1000 D->getClass( Service, Device ); 1000 D->getClass( Service, Device );
1001 1001
1002 Sub = new QListViewItem( It ); 1002 Sub = new QListViewItem( It );
1003 Sub->setText( 0, tr( "Service classes" ) ); 1003 Sub->setText( 0, tr( "Service classes" ) );
1004 Sub->setText( 1, Service ); 1004 Sub->setText( 1, Service );
1005 Sub = new QListViewItem( It ); 1005 Sub = new QListViewItem( It );
1006 Sub->setText( 0, tr( "Device class" ) ); 1006 Sub->setText( 0, tr( "Device class" ) );
1007 Sub->setText( 1, Device ); 1007 Sub->setText( 1, Device );
1008 } 1008 }
1009 1009
1010 if( DL.count() ) { 1010 if( DL.count() ) {
1011 AllDrivers_LV->setCurrentItem( First ); 1011 AllDrivers_LV->setCurrentItem( First );
1012 DriverIsUp_CB->setEnabled( TRUE ); 1012 DriverIsUp_CB->setEnabled( TRUE );
1013 } else { 1013 } else {
1014 DriverIsUp_CB->setChecked( FALSE ); 1014 DriverIsUp_CB->setChecked( FALSE );
1015 DriverIsUp_CB->setEnabled( FALSE ); 1015 DriverIsUp_CB->setEnabled( FALSE );
1016 } 1016 }
1017} 1017}
1018 1018
1019void OTManage::SLOT_SetRefreshTimer( int v ) { 1019void OTManage::SLOT_SetRefreshTimer( int v ) {
1020 OT->setRefreshTimer( v * 1000 ); 1020 OT->setRefreshTimer( v * 1000 );
1021} 1021}
1022 1022
1023// 1023//
1024// 1024//
1025// 1025//
1026// 1026//
1027// 1027//
1028 1028
1029OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) { 1029OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) {
1030 1030
1031 Icons = new OTIcons(); 1031 Icons = new OTIcons();
1032 SnifWindow = 0; 1032 SnifWindow = 0;
1033 OT = OTGateway::getOTGateway(); 1033 OT = OTGateway::getOTGateway();
1034 1034
1035 connect( OT, 1035 connect( OT,
1036 SIGNAL( deviceEnabled( bool ) ), 1036 SIGNAL( deviceEnabled( bool ) ),
1037 this, 1037 this,
1038 SLOT( SLOT_DeviceIsEnabled( bool ) ) 1038 SLOT( SLOT_DeviceIsEnabled( bool ) )
1039 ); 1039 );
1040 connect( OT, 1040 connect( OT,
1041 SIGNAL( driverListChanged() ), 1041 SIGNAL( driverListChanged() ),
1042 this, 1042 this,
1043 SLOT( SLOT_DriverListChanged() ) 1043 SLOT( SLOT_DriverListChanged() )
1044 ); 1044 );
1045 connect( OT, 1045 connect( OT,
1046 SIGNAL( stateChange( OTDriver *, bool ) ), 1046 SIGNAL( stateChange( OTDriver *, bool ) ),
1047 this, 1047 this,
1048 SLOT( SLOT_StateChange( OTDriver *, bool ) ) 1048 SLOT( SLOT_StateChange( OTDriver *, bool ) )
1049 ); 1049 );
1050 1050
1051 if( ! OT->needsEnabling() ) { 1051 if( ! OT->needsEnabling() ) {
1052 MustBeEnabled_CB->hide(); 1052 MustBeEnabled_CB->hide();
1053 } else { 1053 } else {
1054 // detect current state 1054 // detect current state
1055 MustBeEnabled_CB->setChecked( 1055 MustBeEnabled_CB->setChecked(
1056 OT->isEnabled() ); 1056 OT->isEnabled() );
1057 } 1057 }
1058 1058
1059 SLOT_DriverListChanged(); 1059 SLOT_DriverListChanged();
1060} 1060}
1061 1061
1062OTMain::~OTMain() { 1062OTMain::~OTMain() {
1063 OTGateway::releaseOTGateway(); 1063 OTGateway::releaseOTGateway();
1064 delete Icons; 1064 delete Icons;
1065} 1065}
1066 1066
1067void OTMain::SLOT_DriverListChanged() { 1067void OTMain::SLOT_DriverListChanged() {
1068 OTDriver * D; 1068 OTDriver * D;
1069 OTDriverList & DL = OT->getDriverList(); 1069 OTDriverList & DL = OT->getDriverList();
1070 1070
1071 DeviceList_CB->clear(); 1071 DeviceList_CB->clear();
1072 for( unsigned int i = 0; 1072 for( unsigned int i = 0;
1073 i < DL.count(); 1073 i < DL.count();
1074 i ++ ) { 1074 i ++ ) {
1075 D = DL[i]; 1075 D = DL[i];
1076 DeviceList_CB->insertItem( 1076 DeviceList_CB->insertItem(
1077 Icons->loadPixmap( (D->isUp()) ? 1077 Icons->loadPixmap( (D->isUp()) ?
1078 "bluezon" : "bluezoff" ), 1078 "bluezon" : "bluezoff" ),
1079 D->devname() ); 1079 D->devname() );
1080 if( D == OT->scanWith() ) { 1080 if( D == OT->scanWith() ) {
1081 DeviceList_CB->setCurrentItem( i ); 1081 DeviceList_CB->setCurrentItem( i );
1082 } 1082 }
1083 } 1083 }
1084 1084
1085 Scan_But->setEnabled( OT->getDriverList().count() > 0 ); 1085 Scan_But->setEnabled( OT->getDriverList().count() > 0 );
1086 DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 ); 1086 DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 );
1087} 1087}
1088 1088
1089void OTMain::SLOT_EnableBluetooth( bool Up ) { 1089void OTMain::SLOT_EnableBluetooth( bool Up ) {
1090 OT->SLOT_SetEnabled( Up ); 1090 OT->SLOT_SetEnabled( Up );
1091} 1091}
1092 1092
1093void OTMain::SLOT_DeviceIsEnabled( bool Up ) { 1093void OTMain::SLOT_DeviceIsEnabled( bool Up ) {
1094 MustBeEnabled_CB->blockSignals( TRUE ); 1094 MustBeEnabled_CB->blockSignals( TRUE );
1095 MustBeEnabled_CB->setChecked( Up ); 1095 MustBeEnabled_CB->setChecked( Up );
1096 MustBeEnabled_CB->blockSignals( FALSE ); 1096 MustBeEnabled_CB->blockSignals( FALSE );
1097} 1097}
1098 1098
1099void OTMain::SLOT_Manage( void ) { 1099void OTMain::SLOT_Manage( void ) {
1100 QDialog * Dlg = new QDialog( this, 0, TRUE ); 1100 QDialog * Dlg = new QDialog( this, 0, TRUE );
1101 QVBoxLayout * V = new QVBoxLayout( Dlg ); 1101 QVBoxLayout * V = new QVBoxLayout( Dlg );
1102 OTManage * Mng = new OTManage( Dlg, Icons ); 1102 OTManage * Mng = new OTManage( Dlg, Icons );
1103 1103
1104 V->addWidget( Mng ); 1104 V->addWidget( Mng );
1105 1105
1106 Dlg->setCaption( tr("Manage local devices" ) ); 1106 Dlg->setCaption( tr("Manage local devices" ) );
1107 Dlg->showMaximized(); 1107 Dlg->showMaximized();
1108 Dlg->exec(); 1108 Dlg->exec();
1109 delete Dlg; 1109 delete Dlg;
1110} 1110}
1111 1111
1112void OTMain::SLOT_Scan( void ) { 1112void OTMain::SLOT_Scan( void ) {
1113 OTDriverList & DL = OT->getDriverList(); 1113 OTDriverList & DL = OT->getDriverList();
1114 for( unsigned int i = 0; 1114 for( unsigned int i = 0;
1115 i < DL.count(); 1115 i < DL.count();
1116 i ++ ) { 1116 i ++ ) {
1117 if( DL[i]->isUp() && 1117 if( DL[i]->isUp() &&
1118 DL[i]->devname() == DeviceList_CB->currentText() 1118 DL[i]->devname() == DeviceList_CB->currentText()
1119 ) { 1119 ) {
1120 QDialog * Dlg = new QDialog( this, 0, TRUE ); 1120 QDialog * Dlg = new QDialog( this, 0, TRUE );
1121 QVBoxLayout * V = new QVBoxLayout( Dlg ); 1121 QVBoxLayout * V = new QVBoxLayout( Dlg );
1122 OTScan * Scn = new OTScan( Dlg, Icons ); 1122 OTScan * Scn = new OTScan( Dlg, Icons );
1123 1123
1124 OT->setScanWith( OT->driver(i) ); 1124 OT->setScanWith( OT->driver(i) );
1125 V->addWidget( Scn ); 1125 V->addWidget( Scn );
1126 Dlg->setCaption( tr("Scan Neighbourhood" ) ); 1126 Dlg->setCaption( tr("Scan Neighbourhood" ) );
1127 Dlg->showMaximized(); 1127 Dlg->showMaximized();
1128 Dlg->exec(); 1128 Dlg->exec();
1129 1129
1130 delete Dlg; 1130 delete Dlg;
1131 return; 1131 return;
1132 } 1132 }
1133 } 1133 }
1134 1134
1135} 1135}
1136 1136
1137void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) { 1137void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) {
1138 for( int i = 0; 1138 for( int i = 0;
1139 i < DeviceList_CB->count(); 1139 i < DeviceList_CB->count();
1140 i ++ ) { 1140 i ++ ) {
1141 if( DeviceList_CB->text(i) == D->devname() ) { 1141 if( DeviceList_CB->text(i) == D->devname() ) {
1142 DeviceList_CB->changeItem( 1142 DeviceList_CB->changeItem(
1143 Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ), 1143 Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ),
1144 D->devname(), 1144 D->devname(),
1145 i ); 1145 i );
1146 return; 1146 return;
1147 } 1147 }
1148 } 1148 }
1149} 1149}
1150 1150
1151void OTMain::SLOT_Pairing( void ) { 1151void OTMain::SLOT_Pairing( void ) {
1152 QDialog * Dlg = new QDialog( this, 0, TRUE ); 1152 QDialog * Dlg = new QDialog( this, 0, TRUE );
1153 QVBoxLayout * V = new QVBoxLayout( Dlg ); 1153 QVBoxLayout * V = new QVBoxLayout( Dlg );
1154 OTPairing * Pair = new OTPairing( Dlg, Icons ); 1154 OTPairing * Pair = new OTPairing( Dlg, Icons );
1155 1155
1156 V->addWidget( Pair ); 1156 V->addWidget( Pair );
1157 Dlg->showMaximized(); 1157 Dlg->showMaximized();
1158 Dlg->setCaption( tr("Manage pairing" ) ); 1158 Dlg->setCaption( tr("Manage pairing" ) );
1159 Dlg->exec(); 1159 Dlg->exec();
1160 1160
1161 delete Dlg; 1161 delete Dlg;
1162} 1162}
1163 1163
1164void OTMain::SLOT_Sniffing( void ) { 1164void OTMain::SLOT_Sniffing( void ) {
1165 1165
1166 if( SnifWindow == 0 ) { 1166 if( SnifWindow == 0 ) {
1167 SnifWindow = new QDialog( this, 0, FALSE ); 1167 SnifWindow = new QDialog( this, 0, FALSE );
1168 QVBoxLayout * V = new QVBoxLayout( SnifWindow ); 1168 QVBoxLayout * V = new QVBoxLayout( SnifWindow );
1169 OTSniffing * SN = new OTSniffing( SnifWindow ); 1169 OTSniffing * SN = new OTSniffing( SnifWindow );
1170 V->addWidget( SN ); 1170 V->addWidget( SN );
1171 } 1171 }
1172 1172
1173 SnifWindow->showMaximized(); 1173 SnifWindow->showMaximized();
1174 SnifWindow->show(); 1174 SnifWindow->show();
1175} 1175}