21 files changed, 222 insertions, 518 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp index 5e4d951..5c2b8b2 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp | |||
@@ -1,94 +1,75 @@ | |||
1 | #include "bluetoothBNEP_NN.h" | 1 | #include "bluetoothBNEP_NN.h" |
2 | #include "bluetoothBNEP_NNI.h" | 2 | #include "bluetoothBNEP_NNI.h" |
3 | #include "bluetoothRFCOMM_NNI.h" | 3 | #include "bluetoothRFCOMM_NNI.h" |
4 | 4 | ||
5 | #ifndef MYPLUGIN | ||
6 | |||
7 | #include "netnodeinterface.h" | 5 | #include "netnodeinterface.h" |
8 | 6 | ||
9 | #endif | ||
10 | |||
11 | // | 7 | // |
12 | // | 8 | // |
13 | // BLUETOOTH PAN/NAP node | 9 | // BLUETOOTH PAN/NAP node |
14 | // | 10 | // |
15 | // | 11 | // |
16 | 12 | ||
17 | static const char * BluetoothBNEPNeeds[] = | 13 | static const char * BluetoothBNEPNeeds[] = |
18 | { 0 | 14 | { 0 |
19 | }; | 15 | }; |
20 | 16 | ||
21 | static const char * BluetoothBNEPProvides[] = | 17 | static const char * BluetoothBNEPProvides[] = |
22 | { "device", | 18 | { "device", |
23 | 0 | 19 | 0 |
24 | }; | 20 | }; |
25 | 21 | ||
26 | /** | 22 | /** |
27 | * Constructor, find all of the possible interfaces | 23 | * Constructor, find all of the possible interfaces |
28 | */ | 24 | */ |
29 | BluetoothBNEPNetNode::BluetoothBNEPNetNode() : | 25 | BluetoothBNEPNetNode::BluetoothBNEPNetNode() : |
30 | ANetNode(tr("Bluetooth PAN/NAP")) { | 26 | ANetNode(tr("Bluetooth PAN/NAP")) { |
31 | InstanceCount = 7; // default | 27 | InstanceCount = 7; // default |
32 | } | 28 | } |
33 | 29 | ||
34 | /** | 30 | /** |
35 | * Delete any interfaces that we own. | 31 | * Delete any interfaces that we own. |
36 | */ | 32 | */ |
37 | BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ | 33 | BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ |
38 | } | 34 | } |
39 | 35 | ||
40 | const QString BluetoothBNEPNetNode::nodeDescription(){ | 36 | const QString BluetoothBNEPNetNode::nodeDescription(){ |
41 | return tr("\ | 37 | return tr("\ |
42 | <p>Sets up a bluetooth link using the bluetooth Network profile.</p>\ | 38 | <p>Sets up a bluetooth link using the bluetooth Network profile.</p>\ |
43 | <p>Use this to connect two computing devices.</p>\ | 39 | <p>Use this to connect two computing devices.</p>\ |
44 | " | 40 | " |
45 | ); | 41 | ); |
46 | } | 42 | } |
47 | 43 | ||
48 | ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { | 44 | ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { |
49 | return new ABluetoothBNEP( this ); | 45 | return new ABluetoothBNEP( this ); |
50 | } | 46 | } |
51 | 47 | ||
52 | const char ** BluetoothBNEPNetNode::needs( void ) { | 48 | const char ** BluetoothBNEPNetNode::needs( void ) { |
53 | return BluetoothBNEPNeeds; | 49 | return BluetoothBNEPNeeds; |
54 | } | 50 | } |
55 | 51 | ||
56 | const char ** BluetoothBNEPNetNode::provides( void ) { | 52 | const char ** BluetoothBNEPNetNode::provides( void ) { |
57 | return BluetoothBNEPProvides; | 53 | return BluetoothBNEPProvides; |
58 | } | 54 | } |
59 | 55 | ||
60 | QString BluetoothBNEPNetNode::genNic( long nr ) { | 56 | QString BluetoothBNEPNetNode::genNic( long nr ) { |
61 | QString S; | 57 | QString S; |
62 | return S.sprintf( "bnep%ld", nr ); | 58 | return S.sprintf( "bnep%ld", nr ); |
63 | } | 59 | } |
64 | 60 | ||
65 | 61 | ||
66 | void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { | 62 | void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { |
67 | if( A == "interfacecount" ) { | 63 | if( A == "interfacecount" ) { |
68 | InstanceCount = V.toLong(); | 64 | InstanceCount = V.toLong(); |
69 | } | 65 | } |
70 | } | 66 | } |
71 | 67 | ||
72 | void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) { | 68 | void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) { |
73 | TS << "interfacecount=" | 69 | TS << "interfacecount=" |
74 | << InstanceCount | 70 | << InstanceCount |
75 | << endl; | 71 | << endl; |
76 | } | 72 | } |
77 | 73 | ||
78 | #ifndef MYPLUGIN | ||
79 | |||
80 | extern "C" { | ||
81 | // create plugin registers both BT functions | ||
82 | void create_plugin( QList<ANetNode> & PNN ) { | ||
83 | PNN.append( new BluetoothBNEPNetNode() ); | ||
84 | PNN.append( new BluetoothRFCOMMNetNode() ); | ||
85 | } | ||
86 | |||
87 | #else | ||
88 | |||
89 | typedef Opie::Core::MakeTypelist<BluetoothBNEPNetNode, BluetoothRFCOMMNetNode>::Result BluetoothTypes; | 74 | typedef Opie::Core::MakeTypelist<BluetoothBNEPNetNode, BluetoothRFCOMMNetNode>::Result BluetoothTypes; |
90 | OPIE_NS2_PLUGIN( NetNodeInterface<BluetoothTypes> ) | 75 | OPIE_NS2_PLUGIN( NetNodeInterface_T<BluetoothTypes> ) |
91 | |||
92 | #endif | ||
93 | |||
94 | } | ||
diff --git a/noncore/settings/networksettings2/cable/cable_NN.cpp b/noncore/settings/networksettings2/cable/cable_NN.cpp index 20299e4..58237a1 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.cpp +++ b/noncore/settings/networksettings2/cable/cable_NN.cpp | |||
@@ -1,69 +1,52 @@ | |||
1 | #include "cable_NN.h" | 1 | #include "cable_NN.h" |
2 | #include "cable_NNI.h" | 2 | #include "cable_NNI.h" |
3 | 3 | ||
4 | #ifndef MYPLUGIN | ||
5 | |||
6 | #include "netnodeinterface.h" | 4 | #include "netnodeinterface.h" |
7 | 5 | ||
8 | #endif | ||
9 | |||
10 | static const char * CableNeeds[] = | 6 | static const char * CableNeeds[] = |
11 | { 0 | 7 | { 0 |
12 | }; | 8 | }; |
13 | 9 | ||
14 | static const char * CableProvides[] = | 10 | static const char * CableProvides[] = |
15 | { "line", | 11 | { "line", |
16 | 0 | 12 | 0 |
17 | }; | 13 | }; |
18 | 14 | ||
19 | /** | 15 | /** |
20 | * Constructor, find all of the possible interfaces | 16 | * Constructor, find all of the possible interfaces |
21 | */ | 17 | */ |
22 | CableNetNode::CableNetNode() : ANetNode(tr("Cable Connection")) { | 18 | CableNetNode::CableNetNode() : ANetNode(tr("Cable Connection")) { |
23 | } | 19 | } |
24 | 20 | ||
25 | /** | 21 | /** |
26 | * Delete any interfaces that we own. | 22 | * Delete any interfaces that we own. |
27 | */ | 23 | */ |
28 | CableNetNode::~CableNetNode(){ | 24 | CableNetNode::~CableNetNode(){ |
29 | } | 25 | } |
30 | 26 | ||
31 | const QString CableNetNode::nodeDescription(){ | 27 | const QString CableNetNode::nodeDescription(){ |
32 | return tr("\ | 28 | return tr("\ |
33 | <p>Sets up a wired serial or parallel.</p>\ | 29 | <p>Sets up a wired serial or parallel.</p>\ |
34 | " | 30 | " |
35 | ); | 31 | ); |
36 | } | 32 | } |
37 | 33 | ||
38 | ANetNodeInstance * CableNetNode::createInstance( void ) { | 34 | ANetNodeInstance * CableNetNode::createInstance( void ) { |
39 | return new ACable( this ); | 35 | return new ACable( this ); |
40 | } | 36 | } |
41 | 37 | ||
42 | const char ** CableNetNode::needs( void ) { | 38 | const char ** CableNetNode::needs( void ) { |
43 | return CableNeeds; | 39 | return CableNeeds; |
44 | } | 40 | } |
45 | 41 | ||
46 | const char ** CableNetNode::provides( void ) { | 42 | const char ** CableNetNode::provides( void ) { |
47 | return CableProvides; | 43 | return CableProvides; |
48 | } | 44 | } |
49 | 45 | ||
50 | void CableNetNode::setSpecificAttribute( QString & , QString & ) { | 46 | void CableNetNode::setSpecificAttribute( QString & , QString & ) { |
51 | } | 47 | } |
52 | 48 | ||
53 | void CableNetNode::saveSpecificAttribute( QTextStream & ) { | 49 | void CableNetNode::saveSpecificAttribute( QTextStream & ) { |
54 | } | 50 | } |
55 | 51 | ||
56 | #ifdef MYPLUGIN | 52 | OPIE_NS2_PLUGIN( NetNodeInterface_T<CableNetNode> ) |
57 | |||
58 | extern "C" { | ||
59 | void create_plugin( QList<ANetNode> & PNN ) { | ||
60 | PNN.append( new CableNetNode() ); | ||
61 | } | ||
62 | |||
63 | #else | ||
64 | |||
65 | OPIE_NS2_PLUGIN( NetNodeInterface<CableNetNode> ) | ||
66 | |||
67 | #endif | ||
68 | |||
69 | } | ||
diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp index 3f8a53f..0c3ead6 100644 --- a/noncore/settings/networksettings2/editconnection.cpp +++ b/noncore/settings/networksettings2/editconnection.cpp | |||
@@ -1,631 +1,630 @@ | |||
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 | ||
25 | class MyQCheckListItem : public QCheckListItem | 25 | class MyQCheckListItem : public QCheckListItem |
26 | { | 26 | { |
27 | public: | 27 | public: |
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 | ||
47 | void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, | 47 | void 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 | ||
58 | class MyQListViewItem : public QListViewItem | 58 | class MyQListViewItem : public QListViewItem |
59 | { | 59 | { |
60 | public: | 60 | public: |
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 | ||
71 | void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, | 71 | void 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 | ||
88 | bool EditConnection::AutoCollapse = 1; | 88 | bool EditConnection::AutoCollapse = 1; |
89 | 89 | ||
90 | EditConnection::EditConnection( QWidget* parent ) : | 90 | EditConnection::EditConnection( QWidget* parent ) : |
91 | EditConnectionGUI( parent, 0, TRUE ), TmpCollection() { | 91 | EditConnectionGUI( 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 | ||
108 | NodeCollection * EditConnection::getTmpCollection( void ) { | 108 | NodeCollection * EditConnection::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 | TmpCollection.clear(); | 122 | TmpCollection.clear(); |
123 | 123 | ||
124 | // update content | 124 | // update content |
125 | QListViewItem * it = Nodes_LV->firstChild(); | 125 | QListViewItem * it = Nodes_LV->firstChild(); |
126 | ANetNode * NN; | 126 | ANetNode * NN; |
127 | 127 | ||
128 | // start iter (if there is a collection) | 128 | // start iter (if there is a collection) |
129 | /* | 129 | /* |
130 | 130 | ||
131 | a node collection is sorted from the toplevel | 131 | a node collection is sorted from the toplevel |
132 | node to the deepest node | 132 | node to the deepest node |
133 | 133 | ||
134 | */ | 134 | */ |
135 | ANetNodeInstance * NNI = | 135 | ANetNodeInstance * NNI = |
136 | (SelectedNodes) ? SelectedNodes->first() : 0 ; | 136 | (SelectedNodes) ? SelectedNodes->first() : 0 ; |
137 | 137 | ||
138 | TmpCollection.setModified( 0 ); | 138 | TmpCollection.setModified( 0 ); |
139 | 139 | ||
140 | // the listview always starts with the toplevel | 140 | // the listview always starts with the toplevel |
141 | // hierarchy. This is always a controller item | 141 | // hierarchy. This is always a controller item |
142 | while ( it ) { | 142 | while ( it ) { |
143 | NN = (*Mapping)[it]; | 143 | NN = (*Mapping)[it]; |
144 | if( NN == 0 ) { | 144 | if( NN == 0 ) { |
145 | // this item is a controller -> | 145 | // this item is a controller -> |
146 | // has radio items as children -> | 146 | // has radio items as children -> |
147 | // find selected one | 147 | // find selected one |
148 | it = it->firstChild(); | 148 | it = it->firstChild(); |
149 | while( it ) { | 149 | while( it ) { |
150 | if( ((QCheckListItem *)it)->isOn() ) { | 150 | if( ((QCheckListItem *)it)->isOn() ) { |
151 | // this radio is selected -> go deeper | 151 | // this radio is selected -> go deeper |
152 | break; | 152 | break; |
153 | } | 153 | } |
154 | it = it->nextSibling(); | 154 | it = it->nextSibling(); |
155 | } | 155 | } |
156 | 156 | ||
157 | if( ! it ) { | 157 | if( ! it ) { |
158 | owarn << "Radio not selected" << oendl; | 158 | owarn << "Radio not selected" << oendl; |
159 | TmpIsValid = 0; | 159 | TmpIsValid = 0; |
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
162 | 162 | ||
163 | // it now contains selected radio | 163 | // it now contains selected radio |
164 | NN = (*Mapping)[it]; | 164 | NN = (*Mapping)[it]; |
165 | } | 165 | } |
166 | 166 | ||
167 | // NN here contains the netnode of the | 167 | // NN here contains the netnode of the |
168 | // current item -> this node needs to | 168 | // current item -> this node needs to |
169 | // be stored in the collection | 169 | // be stored in the collection |
170 | if( NNI == 0 || | 170 | if( NNI == 0 || |
171 | it->text(0) != NNI->nodeClass()->name() ) { | 171 | it->text(0) != NNI->nodeClass()->name() ) { |
172 | // new item not in previous collection | 172 | // new item not in previous collection |
173 | ANetNodeInstance * NNI = NN->createInstance(); | 173 | ANetNodeInstance * NNI = NN->createInstance(); |
174 | NNI->initialize(); | 174 | NNI->initialize(); |
175 | // this node type not in collection | 175 | // this node type not in collection |
176 | TmpCollection.append( NNI ); | 176 | TmpCollection.append( NNI ); |
177 | // master collection changed because new item in it | 177 | // master collection changed because new item in it |
178 | TmpCollection.setModified( 1 ); | 178 | TmpCollection.setModified( 1 ); |
179 | // no more valid items in old list | 179 | // no more valid items in old list |
180 | NNI = 0; | 180 | NNI = 0; |
181 | } else { | 181 | } else { |
182 | // already in list -> copy pointer | 182 | // already in list -> copy pointer |
183 | TmpCollection.append( NNI ); | 183 | TmpCollection.append( NNI ); |
184 | NNI = SelectedNodes->next(); | 184 | NNI = SelectedNodes->next(); |
185 | } | 185 | } |
186 | 186 | ||
187 | // go deeper to next level | 187 | // go deeper to next level |
188 | // this level is can be a new controller | 188 | // this level is can be a new controller |
189 | // or an item | 189 | // or an item |
190 | it = it->firstChild(); | 190 | it = it->firstChild(); |
191 | } | 191 | } |
192 | 192 | ||
193 | TmpIsValid = 1; | 193 | TmpIsValid = 1; |
194 | return &(TmpCollection); | 194 | return &(TmpCollection); |
195 | } | 195 | } |
196 | 196 | ||
197 | // pass a connection NodeCollection to be edited | 197 | // pass a connection NodeCollection to be edited |
198 | void EditConnection::setConnection( NodeCollection * NC ) { | 198 | void EditConnection::setConnection( NodeCollection * NC ) { |
199 | ANetNodeInstance * NNI; | 199 | ANetNodeInstance * NNI; |
200 | ANetNode * NN; | 200 | ANetNode * NN; |
201 | 201 | ||
202 | SelectedNodes = NC; | 202 | SelectedNodes = NC; |
203 | Name_LE->setText( NC->name() ); | 203 | Name_LE->setText( NC->name() ); |
204 | NNI = NC->first(); | 204 | NNI = NC->first(); |
205 | 205 | ||
206 | // show configure tabl | 206 | // show configure tabl |
207 | Tab_TB->setCurrentPage( 1 ); | 207 | Tab_TB->setCurrentPage( 1 ); |
208 | 208 | ||
209 | // valid colledction | 209 | // valid colledction |
210 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); | 210 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); |
211 | Setup_FRM->setEnabled( FALSE ); | 211 | Setup_FRM->setEnabled( FALSE ); |
212 | 212 | ||
213 | // select items in collection | 213 | // select items in collection |
214 | QListViewItem * it = Nodes_LV->firstChild(); | 214 | QListViewItem * it = Nodes_LV->firstChild(); |
215 | bool Found; | 215 | bool Found; |
216 | 216 | ||
217 | TmpIsValid = 0; | 217 | TmpIsValid = 0; |
218 | 218 | ||
219 | while ( it ) { | 219 | while ( it ) { |
220 | NN = (*Mapping)[it]; | 220 | NN = (*Mapping)[it]; |
221 | if( NN == 0 ) { | 221 | if( NN == 0 ) { |
222 | // this item is a controller -> | 222 | // this item is a controller -> |
223 | // has radio items as children -> | 223 | // has radio items as children -> |
224 | // find selected one | 224 | // find selected one |
225 | it = it->firstChild(); | 225 | it = it->firstChild(); |
226 | Found = 0; | 226 | Found = 0; |
227 | while( it ) { | 227 | while( it ) { |
228 | if( NNI && it->text(0) == NNI->nodeClass()->name() ) { | 228 | if( NNI && it->text(0) == NNI->nodeClass()->name() ) { |
229 | // this radio is part of the collection | 229 | // this radio is part of the collection |
230 | ((QCheckListItem *)it)->setOn( 1 ); | 230 | ((QCheckListItem *)it)->setOn( 1 ); |
231 | updateGUI( it, NNI->nodeClass() ); | 231 | updateGUI( it, NNI->nodeClass() ); |
232 | // check its children | 232 | // check its children |
233 | Found = 1; | 233 | Found = 1; |
234 | it = it->firstChild(); | 234 | it = it->firstChild(); |
235 | NNI = SelectedNodes->next(); | 235 | NNI = SelectedNodes->next(); |
236 | // do not bother to check other items | 236 | // do not bother to check other items |
237 | break; | 237 | break; |
238 | } | 238 | } |
239 | it = it->nextSibling(); | 239 | it = it->nextSibling(); |
240 | } | 240 | } |
241 | 241 | ||
242 | if( ! Found ) { | 242 | if( ! Found ) { |
243 | // this means that this level is NOT present in collection | 243 | // this means that this level is NOT present in collection |
244 | // probably INCOMPATIBEL collection OR Missing plugin | 244 | // probably INCOMPATIBEL collection OR Missing plugin |
245 | QMessageBox::warning( | 245 | QMessageBox::warning( |
246 | 0, | 246 | 0, |
247 | tr( "Error presentig Connection" ), | 247 | tr( "Error presentig Connection" ), |
248 | tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). | 248 | tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). |
249 | arg(NNI->nodeClass()->name()) ); | 249 | arg(NNI->nodeClass()->name()) ); |
250 | return; | 250 | return; |
251 | } | 251 | } |
252 | 252 | ||
253 | // it now contains selected radio | 253 | // it now contains selected radio |
254 | NN = (*Mapping)[it]; | 254 | NN = (*Mapping)[it]; |
255 | } else { | 255 | } else { |
256 | // automatic selection | 256 | // automatic selection |
257 | if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { | 257 | if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { |
258 | // should exist and be the same | 258 | // should exist and be the same |
259 | if( NNI ) { | 259 | if( NNI ) { |
260 | QMessageBox::warning( | 260 | QMessageBox::warning( |
261 | 0, | 261 | 0, |
262 | tr( "Error presentig Connection" ), | 262 | tr( "Error presentig Connection" ), |
263 | tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). | 263 | tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). |
264 | arg(NNI->nodeClass()->name()) ); | 264 | arg(NNI->nodeClass()->name()) ); |
265 | } else { | 265 | } else { |
266 | QMessageBox::warning( | 266 | QMessageBox::warning( |
267 | 0, | 267 | 0, |
268 | tr( "Error presentig Connection" ), | 268 | tr( "Error presentig Connection" ), |
269 | tr( "<p>Missing connection\"<i>%1</i>\"</p>" ). | 269 | tr( "<p>Missing connection\"<i>%1</i>\"</p>" ). |
270 | arg(it->text(0)) ); | 270 | arg(it->text(0)) ); |
271 | } | 271 | } |
272 | return; | 272 | return; |
273 | } | 273 | } |
274 | it = it->firstChild(); | 274 | it = it->firstChild(); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | // get result of editing (either new OR updated collection | 279 | // get result of editing (either new OR updated collection |
280 | NodeCollection * EditConnection::connection( void ) { | 280 | NodeCollection * EditConnection::connection( void ) { |
281 | 281 | ||
282 | if( SelectedNodes == 0 ) { | 282 | if( SelectedNodes == 0 ) { |
283 | // new collection | 283 | // new collection |
284 | SelectedNodes = new NodeCollection; | 284 | SelectedNodes = new NodeCollection; |
285 | } | 285 | } |
286 | 286 | ||
287 | // clean out old entries | 287 | // clean out old entries |
288 | SelectedNodes->clear(); | 288 | SelectedNodes->clear(); |
289 | 289 | ||
290 | // transfer | 290 | // transfer |
291 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 291 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
292 | it.current(); | 292 | it.current(); |
293 | ++it ) { | 293 | ++it ) { |
294 | SelectedNodes->append( it.current() ); | 294 | SelectedNodes->append( it.current() ); |
295 | } | 295 | } |
296 | 296 | ||
297 | if( TmpCollection.isModified() ) | 297 | if( TmpCollection.isModified() ) |
298 | SelectedNodes->setModified( 1 ); | 298 | SelectedNodes->setModified( 1 ); |
299 | 299 | ||
300 | if( SelectedNodes->name() != Name_LE->text() ) { | 300 | if( SelectedNodes->name() != Name_LE->text() ) { |
301 | SelectedNodes->setName( Name_LE->text() ); | 301 | SelectedNodes->setName( Name_LE->text() ); |
302 | SelectedNodes->setModified( 1 ); | 302 | SelectedNodes->setModified( 1 ); |
303 | } | 303 | } |
304 | 304 | ||
305 | return SelectedNodes; | 305 | return SelectedNodes; |
306 | } | 306 | } |
307 | 307 | ||
308 | // Build device tree -> start | 308 | // Build device tree -> start |
309 | void EditConnection::buildFullTree( void ) { | 309 | void EditConnection::buildFullTree( void ) { |
310 | ANetNode * NN; | 310 | ANetNode * NN; |
311 | 311 | ||
312 | // toplevel item | 312 | // toplevel item |
313 | MyQCheckListItem * TheTop = new MyQCheckListItem( | 313 | MyQCheckListItem * TheTop = new MyQCheckListItem( |
314 | Nodes_LV, | 314 | Nodes_LV, |
315 | NSResources->netNode2Name("fullsetup"), | 315 | NSResources->netNode2Name("fullsetup"), |
316 | QCheckListItem::Controller ); | 316 | QCheckListItem::Controller ); |
317 | TheTop->setOpen( TRUE ); | 317 | TheTop->setOpen( TRUE ); |
318 | Description_LBL->setText( | 318 | Description_LBL->setText( |
319 | NSResources->netNode2Description( "fullsetup" ) ); | 319 | NSResources->netNode2Description( "fullsetup" ) ); |
320 | Nodes_LV->setSelected( TheTop, TRUE ); | 320 | Nodes_LV->setSelected( TheTop, TRUE ); |
321 | 321 | ||
322 | // find all Nodes that are toplevel nodes -> ie provide | 322 | // find all Nodes that are toplevel nodes -> ie provide |
323 | // TCP/IP Connection | 323 | // TCP/IP Connection |
324 | for( QDictIterator<NetNode_t> Iter(NSResources->netNodes()); | 324 | for( QDictIterator<ANetNode> Iter(NSResources->netNodes()); |
325 | Iter.current(); | 325 | Iter.current(); |
326 | ++Iter ) { | 326 | ++Iter ) { |
327 | 327 | NN = Iter.current(); | |
328 | NN = Iter.current()->NetNode; | ||
329 | 328 | ||
330 | if( ! NN->isToplevel() ) { | 329 | if( ! NN->isToplevel() ) { |
331 | continue; | 330 | continue; |
332 | } | 331 | } |
333 | 332 | ||
334 | MyQCheckListItem * it = new MyQCheckListItem( TheTop, | 333 | MyQCheckListItem * it = new MyQCheckListItem( TheTop, |
335 | NN->name(), | 334 | NN->name(), |
336 | QCheckListItem::RadioButton ); | 335 | QCheckListItem::RadioButton ); |
337 | it->setPixmap( 0, | 336 | it->setPixmap( 0, |
338 | NSResources->getPixmap( NN->pixmapName() ) | 337 | NSResources->getPixmap( NN->pixmapName() ) |
339 | ); | 338 | ); |
340 | // remember that this node maps to this listitem | 339 | // remember that this node maps to this listitem |
341 | Mapping->insert( it, NN ); | 340 | Mapping->insert( it, NN ); |
342 | buildSubTree( it, NN ); | 341 | buildSubTree( it, NN ); |
343 | } | 342 | } |
344 | } | 343 | } |
345 | 344 | ||
346 | // Build device tree -> help function | 345 | // Build device tree -> help function |
347 | void EditConnection::buildSubTree( QListViewItem * it, ANetNode *NN ) { | 346 | void EditConnection::buildSubTree( QListViewItem * it, ANetNode *NN ) { |
348 | ANetNode::NetNodeList & NNL = NN->alternatives(); | 347 | ANetNode::NetNodeList & NNL = NN->alternatives(); |
349 | 348 | ||
350 | if( NNL.size() > 1 ) { | 349 | if( NNL.size() > 1 ) { |
351 | // this node has alternatives -> needs radio buttons | 350 | // this node has alternatives -> needs radio buttons |
352 | it = new MyQCheckListItem( | 351 | it = new MyQCheckListItem( |
353 | it, | 352 | it, |
354 | NSResources->netNode2Name(NN->needs()[0]), | 353 | NSResources->netNode2Name(NN->needs()[0]), |
355 | QCheckListItem::Controller ); | 354 | QCheckListItem::Controller ); |
356 | it->setSelectable( FALSE ); | 355 | it->setSelectable( FALSE ); |
357 | } | 356 | } |
358 | 357 | ||
359 | for ( unsigned int i=0; i < NNL.size(); i++ ) { | 358 | for ( unsigned int i=0; i < NNL.size(); i++ ) { |
360 | QListViewItem * CI; | 359 | QListViewItem * CI; |
361 | if( NNL.size() > 1 ) { | 360 | if( NNL.size() > 1 ) { |
362 | // generate radio buttons | 361 | // generate radio buttons |
363 | CI = new MyQCheckListItem( | 362 | CI = new MyQCheckListItem( |
364 | (QCheckListItem *)it, | 363 | (QCheckListItem *)it, |
365 | NNL[i]->name(), QCheckListItem::RadioButton ); | 364 | NNL[i]->name(), QCheckListItem::RadioButton ); |
366 | // remember that this node maps to this listitem | 365 | // remember that this node maps to this listitem |
367 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); | 366 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); |
368 | Mapping->insert( CI, NNL[i] ); | 367 | Mapping->insert( CI, NNL[i] ); |
369 | CI->setSelectable( FALSE ); | 368 | CI->setSelectable( FALSE ); |
370 | } else { | 369 | } else { |
371 | // Single item | 370 | // Single item |
372 | CI = new MyQListViewItem( it, NNL[i]->name() ); | 371 | CI = new MyQListViewItem( it, NNL[i]->name() ); |
373 | // remember that this node maps to this listitem | 372 | // remember that this node maps to this listitem |
374 | Mapping->insert( CI, NNL[i] ); | 373 | Mapping->insert( CI, NNL[i] ); |
375 | CI->setSelectable( FALSE ); | 374 | CI->setSelectable( FALSE ); |
376 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); | 375 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); |
377 | } | 376 | } |
378 | buildSubTree( CI, NNL[i] ); | 377 | buildSubTree( CI, NNL[i] ); |
379 | } | 378 | } |
380 | } | 379 | } |
381 | 380 | ||
382 | // Clicked ok OK button | 381 | // Clicked ok OK button |
383 | void EditConnection::accept( void ) { | 382 | void EditConnection::accept( void ) { |
384 | if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { | 383 | if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { |
385 | QMessageBox::warning( | 384 | QMessageBox::warning( |
386 | 0, | 385 | 0, |
387 | tr( "Closing Connection Setup" ), | 386 | tr( "Closing Connection Setup" ), |
388 | tr( "Definition not complete or no name" ) ); | 387 | tr( "Definition not complete or no name" ) ); |
389 | return; | 388 | return; |
390 | } | 389 | } |
391 | 390 | ||
392 | // check if all devices have acceptable input | 391 | // check if all devices have acceptable input |
393 | getTmpCollection(); | 392 | getTmpCollection(); |
394 | { ANetNodeInstance * NNI; | 393 | { ANetNodeInstance * NNI; |
395 | QString S; | 394 | QString S; |
396 | 395 | ||
397 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 396 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
398 | it.current(); | 397 | it.current(); |
399 | ++it ) { | 398 | ++it ) { |
400 | NNI = it.current(); | 399 | NNI = it.current(); |
401 | // widget must show its own problems | 400 | // widget must show its own problems |
402 | S = NNI->acceptable(); | 401 | S = NNI->acceptable(); |
403 | if( ! S.isEmpty() ) { | 402 | if( ! S.isEmpty() ) { |
404 | QMessageBox::warning( | 403 | QMessageBox::warning( |
405 | 0, | 404 | 0, |
406 | tr( "Cannot save" ), | 405 | tr( "Cannot save" ), |
407 | S ); | 406 | S ); |
408 | return; | 407 | return; |
409 | } | 408 | } |
410 | NNI->commit(); | 409 | NNI->commit(); |
411 | 410 | ||
412 | if( NNI->isModified() ) { | 411 | if( NNI->isModified() ) { |
413 | TmpCollection.setModified( 1 ); | 412 | TmpCollection.setModified( 1 ); |
414 | // commit the data | 413 | // commit the data |
415 | } | 414 | } |
416 | } | 415 | } |
417 | } | 416 | } |
418 | 417 | ||
419 | QDialog::accept(); | 418 | QDialog::accept(); |
420 | } | 419 | } |
421 | 420 | ||
422 | // triggered by CB | 421 | // triggered by CB |
423 | void EditConnection::SLOT_AutoCollapse( bool b ) { | 422 | void EditConnection::SLOT_AutoCollapse( bool b ) { |
424 | AutoCollapse = b; | 423 | AutoCollapse = b; |
425 | } | 424 | } |
426 | 425 | ||
427 | // clicked on node in tree -> update GUI | 426 | // clicked on node in tree -> update GUI |
428 | void EditConnection::SLOT_SelectNode( QListViewItem * it ) { | 427 | void EditConnection::SLOT_SelectNode( QListViewItem * it ) { |
429 | ANetNode * NN; | 428 | ANetNode * NN; |
430 | if( it == 0 || it->depth() == 0 ) { | 429 | if( it == 0 || it->depth() == 0 ) { |
431 | Description_LBL->setText( | 430 | Description_LBL->setText( |
432 | NSResources->netNode2Description( "fullsetup" ) ); | 431 | NSResources->netNode2Description( "fullsetup" ) ); |
433 | // topevel or no selection | 432 | // topevel or no selection |
434 | return; | 433 | return; |
435 | } | 434 | } |
436 | 435 | ||
437 | // store conversion from lvitem to node | 436 | // store conversion from lvitem to node |
438 | NN = (*Mapping)[ it ]; | 437 | NN = (*Mapping)[ it ]; |
439 | 438 | ||
440 | if( ! NN ) { | 439 | if( ! NN ) { |
441 | // intermediate node | 440 | // intermediate node |
442 | NN = (*Mapping)[ it->parent() ]; | 441 | NN = (*Mapping)[ it->parent() ]; |
443 | if( NN ) { | 442 | if( NN ) { |
444 | // figure out type of this node -> produce mesage | 443 | // figure out type of this node -> produce mesage |
445 | Description_LBL->setText( NSResources->netNode2Description( | 444 | Description_LBL->setText( NSResources->netNode2Description( |
446 | NN->needs()[0]) ); | 445 | NN->needs()[0]) ); |
447 | } else { | 446 | } else { |
448 | Description_LBL->setText( "" ); | 447 | Description_LBL->setText( "" ); |
449 | } | 448 | } |
450 | return; | 449 | return; |
451 | } | 450 | } |
452 | 451 | ||
453 | Description_LBL->setText( NN->nodeDescription() ); | 452 | Description_LBL->setText( NN->nodeDescription() ); |
454 | 453 | ||
455 | if( ! it->isSelectable() ) { | 454 | if( ! it->isSelectable() ) { |
456 | return; | 455 | return; |
457 | } | 456 | } |
458 | 457 | ||
459 | if( ! ((QCheckListItem *)it)->isOn() ) { | 458 | if( ! ((QCheckListItem *)it)->isOn() ) { |
460 | // clicked on line but NOT on Check or Radio item | 459 | // clicked on line but NOT on Check or Radio item |
461 | return; | 460 | return; |
462 | } | 461 | } |
463 | 462 | ||
464 | // item has really changed -> update | 463 | // item has really changed -> update |
465 | TmpIsValid = 0; | 464 | TmpIsValid = 0; |
466 | updateGUI( it, NN ); | 465 | updateGUI( it, NN ); |
467 | } | 466 | } |
468 | 467 | ||
469 | // cliecked on TAB to go to setup | 468 | // cliecked on TAB to go to setup |
470 | void EditConnection::SLOT_AlterTab( const QString & S ) { | 469 | void EditConnection::SLOT_AlterTab( const QString & S ) { |
471 | if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { | 470 | if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { |
472 | // switched to setup -> update CB and populate ws with | 471 | // switched to setup -> update CB and populate ws with |
473 | // forms for devices | 472 | // forms for devices |
474 | 473 | ||
475 | if( ! TmpIsValid ) { | 474 | if( ! TmpIsValid ) { |
476 | getTmpCollection(); | 475 | getTmpCollection(); |
477 | 476 | ||
478 | // clear CB and Ws | 477 | // clear CB and Ws |
479 | { QWidget * W; | 478 | { QWidget * W; |
480 | int i = 0; | 479 | int i = 0; |
481 | 480 | ||
482 | Devices_CB->clear(); | 481 | Devices_CB->clear(); |
483 | while( ( W = Setup_WS->widget( i ) ) ) { | 482 | while( ( W = Setup_WS->widget( i ) ) ) { |
484 | Setup_WS->removeWidget( W ); | 483 | Setup_WS->removeWidget( W ); |
485 | i ++; | 484 | i ++; |
486 | } | 485 | } |
487 | } | 486 | } |
488 | 487 | ||
489 | // update CB | 488 | // update CB |
490 | // and populate WidgetStack | 489 | // and populate WidgetStack |
491 | { ANetNodeInstance * NNI; | 490 | { ANetNodeInstance * NNI; |
492 | QListIterator<ANetNodeInstance> it(TmpCollection); | 491 | QListIterator<ANetNodeInstance> it(TmpCollection); |
493 | int i = 0; | 492 | int i = 0; |
494 | QWidget * W; | 493 | QWidget * W; |
495 | 494 | ||
496 | for ( ; it.current(); ++it ) { | 495 | for ( ; it.current(); ++it ) { |
497 | NNI = it.current(); | 496 | NNI = it.current(); |
498 | Devices_CB->insertItem( | 497 | Devices_CB->insertItem( |
499 | NSResources->getPixmap( NNI->nodeClass()->pixmapName() ), | 498 | NSResources->getPixmap( NNI->nodeClass()->pixmapName() ), |
500 | NNI->nodeClass()->name() | 499 | NNI->nodeClass()->name() |
501 | ); | 500 | ); |
502 | 501 | ||
503 | // add edit widget | 502 | // add edit widget |
504 | W = NNI->edit( Setup_WS ); | 503 | W = NNI->edit( Setup_WS ); |
505 | if( ! W) { | 504 | if( ! W) { |
506 | W = new QLabel( Setup_WS, | 505 | W = new QLabel( Setup_WS, |
507 | tr("No configuration required")); | 506 | tr("No configuration required")); |
508 | } | 507 | } |
509 | Setup_WS->addWidget( W , i ); | 508 | Setup_WS->addWidget( W , i ); |
510 | i ++; | 509 | i ++; |
511 | } | 510 | } |
512 | } | 511 | } |
513 | Setup_WS->raiseWidget( 0 ); | 512 | Setup_WS->raiseWidget( 0 ); |
514 | } // still valid | 513 | } // still valid |
515 | } | 514 | } |
516 | } | 515 | } |
517 | 516 | ||
518 | // update visual feedback of selection state | 517 | // update visual feedback of selection state |
519 | void EditConnection::updateGUI( QListViewItem * it, ANetNode * NN ) { | 518 | void EditConnection::updateGUI( QListViewItem * it, ANetNode * NN ) { |
520 | 519 | ||
521 | bool HCC = haveCompleteConfig( it ); | 520 | bool HCC = haveCompleteConfig( it ); |
522 | Tab_TB->setTabEnabled( Setup_FRM, HCC ); | 521 | Tab_TB->setTabEnabled( Setup_FRM, HCC ); |
523 | Setup_FRM->setEnabled( HCC ); | 522 | Setup_FRM->setEnabled( HCC ); |
524 | 523 | ||
525 | // disable children of all siblings at same level | 524 | // disable children of all siblings at same level |
526 | QListViewItem * Sbl = it->parent()->firstChild(); | 525 | QListViewItem * Sbl = it->parent()->firstChild(); |
527 | while( Sbl ) { | 526 | while( Sbl ) { |
528 | if ( Sbl != it ) { | 527 | if ( Sbl != it ) { |
529 | disableTree( Sbl->firstChild(), FALSE ); | 528 | disableTree( Sbl->firstChild(), FALSE ); |
530 | Sbl->setSelectable( TRUE ); | 529 | Sbl->setSelectable( TRUE ); |
531 | if( AutoCollapse ) | 530 | if( AutoCollapse ) |
532 | Sbl->setOpen( FALSE ); | 531 | Sbl->setOpen( FALSE ); |
533 | } | 532 | } |
534 | Sbl = Sbl->nextSibling(); | 533 | Sbl = Sbl->nextSibling(); |
535 | } | 534 | } |
536 | 535 | ||
537 | // enable selected path (as deep as it goes | 536 | // enable selected path (as deep as it goes |
538 | it->setOpen( TRUE ); | 537 | it->setOpen( TRUE ); |
539 | enablePath( it->firstChild(), | 538 | enablePath( it->firstChild(), |
540 | (it->depth()==1) ? | 539 | (it->depth()==1) ? |
541 | 1 : // toplevel always alternatives | 540 | 1 : // toplevel always alternatives |
542 | (NN->alternatives().size() > 1) ); | 541 | (NN->alternatives().size() > 1) ); |
543 | } | 542 | } |
544 | 543 | ||
545 | void EditConnection::disableTree( QListViewItem * it, bool Mode ) { | 544 | void EditConnection::disableTree( QListViewItem * it, bool Mode ) { |
546 | while( it ) { | 545 | while( it ) { |
547 | // disable sbl's chidren | 546 | // disable sbl's chidren |
548 | it->setSelectable( Mode ); | 547 | it->setSelectable( Mode ); |
549 | if( AutoCollapse ) | 548 | if( AutoCollapse ) |
550 | it->setOpen( Mode ); | 549 | it->setOpen( Mode ); |
551 | disableTree( it->firstChild(), Mode ); | 550 | disableTree( it->firstChild(), Mode ); |
552 | it = it->nextSibling(); | 551 | it = it->nextSibling(); |
553 | } | 552 | } |
554 | } | 553 | } |
555 | 554 | ||
556 | // pah : ParentHasAlternatives | 555 | // pah : ParentHasAlternatives |
557 | void EditConnection::enablePath( QListViewItem * it, bool pha ) { | 556 | void EditConnection::enablePath( QListViewItem * it, bool pha ) { |
558 | while( it ) { | 557 | while( it ) { |
559 | ANetNode * NN; | 558 | ANetNode * NN; |
560 | NN = (*Mapping)[it]; | 559 | NN = (*Mapping)[it]; |
561 | if( NN ) { | 560 | if( NN ) { |
562 | if( pha ) { | 561 | if( pha ) { |
563 | bool doOn = ((QCheckListItem *)it)->isOn(); | 562 | bool doOn = ((QCheckListItem *)it)->isOn(); |
564 | // we are a checklistitem for sure | 563 | // we are a checklistitem for sure |
565 | it->setSelectable( TRUE ); | 564 | it->setSelectable( TRUE ); |
566 | if( AutoCollapse && ! doOn ) | 565 | if( AutoCollapse && ! doOn ) |
567 | it->setOpen( doOn ); | 566 | it->setOpen( doOn ); |
568 | if( doOn ) { | 567 | if( doOn ) { |
569 | // selected alternative | 568 | // selected alternative |
570 | enablePath( it->firstChild(), | 569 | enablePath( it->firstChild(), |
571 | NN->alternatives().size() > 1); | 570 | NN->alternatives().size() > 1); |
572 | } else { | 571 | } else { |
573 | // non-selected alternative | 572 | // non-selected alternative |
574 | disableTree( it->firstChild(), FALSE); | 573 | disableTree( it->firstChild(), FALSE); |
575 | } | 574 | } |
576 | } else { | 575 | } else { |
577 | // we are single subitem | 576 | // we are single subitem |
578 | it->setSelectable( TRUE ); | 577 | it->setSelectable( TRUE ); |
579 | it->setOpen( TRUE ); | 578 | it->setOpen( TRUE ); |
580 | enablePath( it->firstChild(), | 579 | enablePath( it->firstChild(), |
581 | NN->alternatives().size() > 1); | 580 | NN->alternatives().size() > 1); |
582 | } | 581 | } |
583 | } else { | 582 | } else { |
584 | // controller node | 583 | // controller node |
585 | it->setSelectable( TRUE ); | 584 | it->setSelectable( TRUE ); |
586 | it->setOpen( TRUE ); | 585 | it->setOpen( TRUE ); |
587 | enablePath( it->firstChild(), pha ); | 586 | enablePath( it->firstChild(), pha ); |
588 | } | 587 | } |
589 | it = it->nextSibling(); | 588 | it = it->nextSibling(); |
590 | } | 589 | } |
591 | } | 590 | } |
592 | 591 | ||
593 | // do we have a complete configuration (all needs are provided for ?) | 592 | // do we have a complete configuration (all needs are provided for ?) |
594 | bool EditConnection::haveCompleteConfig( QListViewItem * it ) { | 593 | bool EditConnection::haveCompleteConfig( QListViewItem * it ) { |
595 | 594 | ||
596 | // check if all below this level is selected | 595 | // check if all below this level is selected |
597 | it = ( it ) ?it : Nodes_LV->firstChild(); | 596 | it = ( it ) ?it : Nodes_LV->firstChild(); |
598 | ANetNode *NN; | 597 | ANetNode *NN; |
599 | bool Found; | 598 | bool Found; |
600 | 599 | ||
601 | while ( it ) { | 600 | while ( it ) { |
602 | NN = (*Mapping)[it]; | 601 | NN = (*Mapping)[it]; |
603 | if( NN == 0 ) { | 602 | if( NN == 0 ) { |
604 | // this item is a controller -> | 603 | // this item is a controller -> |
605 | // has radio items as children -> | 604 | // has radio items as children -> |
606 | // find selected one | 605 | // find selected one |
607 | it = it->firstChild(); | 606 | it = it->firstChild(); |
608 | Found = 0; | 607 | Found = 0; |
609 | while( it ) { | 608 | while( it ) { |
610 | if( ((QCheckListItem *)it)->isOn() ) { | 609 | if( ((QCheckListItem *)it)->isOn() ) { |
611 | Found = 1; | 610 | Found = 1; |
612 | // go deeper | 611 | // go deeper |
613 | it = it->firstChild(); | 612 | it = it->firstChild(); |
614 | break; | 613 | break; |
615 | } | 614 | } |
616 | it = it->nextSibling(); | 615 | it = it->nextSibling(); |
617 | } | 616 | } |
618 | 617 | ||
619 | if( ! Found ) { | 618 | if( ! Found ) { |
620 | return 0; // no not complete -> a radio should have been chkd | 619 | return 0; // no not complete -> a radio should have been chkd |
621 | } | 620 | } |
622 | 621 | ||
623 | // it now contains selected radio | 622 | // it now contains selected radio |
624 | NN = (*Mapping)[it]; | 623 | NN = (*Mapping)[it]; |
625 | } else { | 624 | } else { |
626 | // automatic selection | 625 | // automatic selection |
627 | it = it->firstChild(); | 626 | it = it->firstChild(); |
628 | } | 627 | } |
629 | } | 628 | } |
630 | return 1; | 629 | return 1; |
631 | } | 630 | } |
diff --git a/noncore/settings/networksettings2/gprs/GPRS_NN.cpp b/noncore/settings/networksettings2/gprs/GPRS_NN.cpp index 4415739..e9553a6 100644 --- a/noncore/settings/networksettings2/gprs/GPRS_NN.cpp +++ b/noncore/settings/networksettings2/gprs/GPRS_NN.cpp | |||
@@ -1,95 +1,78 @@ | |||
1 | #include <resources.h> | 1 | #include <resources.h> |
2 | #include <qpe/qpeapplication.h> | 2 | #include <qpe/qpeapplication.h> |
3 | #include <netnode.h> | 3 | #include <netnode.h> |
4 | #include "GPRS_NN.h" | 4 | #include "GPRS_NN.h" |
5 | #include "GPRS_NNI.h" | 5 | #include "GPRS_NNI.h" |
6 | 6 | ||
7 | #ifndef MYPLUGIN | ||
8 | |||
9 | #include "netnodeinterface.h" | 7 | #include "netnodeinterface.h" |
10 | 8 | ||
11 | #endif | ||
12 | |||
13 | static const char * GPRSNeeds[] = | 9 | static const char * GPRSNeeds[] = |
14 | { "GPRS", | 10 | { "GPRS", |
15 | 0 | 11 | 0 |
16 | }; | 12 | }; |
17 | 13 | ||
18 | static const char * GPRSProvides[] = | 14 | static const char * GPRSProvides[] = |
19 | { "connection", | 15 | { "connection", |
20 | 0 | 16 | 0 |
21 | }; | 17 | }; |
22 | 18 | ||
23 | /** | 19 | /** |
24 | * Constructor, find all of the possible interfaces | 20 | * Constructor, find all of the possible interfaces |
25 | */ | 21 | */ |
26 | GPRSNetNode::GPRSNetNode() : ANetNode(tr("GPRS capable device")) { | 22 | GPRSNetNode::GPRSNetNode() : ANetNode(tr("GPRS capable device")) { |
27 | NSResources->addSystemFile( | 23 | NSResources->addSystemFile( |
28 | "pap-secrets", "/etc/ppp/pap-secrets", 0 ); | 24 | "pap-secrets", "/etc/ppp/pap-secrets", 0 ); |
29 | } | 25 | } |
30 | 26 | ||
31 | /** | 27 | /** |
32 | * Delete any interfaces that we own. | 28 | * Delete any interfaces that we own. |
33 | */ | 29 | */ |
34 | GPRSNetNode::~GPRSNetNode(){ | 30 | GPRSNetNode::~GPRSNetNode(){ |
35 | } | 31 | } |
36 | 32 | ||
37 | const QString GPRSNetNode::nodeDescription(){ | 33 | const QString GPRSNetNode::nodeDescription(){ |
38 | return tr("\ | 34 | return tr("\ |
39 | <p>provides access to a GPRS capable device.</p>\ | 35 | <p>provides access to a GPRS capable device.</p>\ |
40 | " | 36 | " |
41 | ); | 37 | ); |
42 | } | 38 | } |
43 | 39 | ||
44 | ANetNodeInstance * GPRSNetNode::createInstance( void ) { | 40 | ANetNodeInstance * GPRSNetNode::createInstance( void ) { |
45 | return new AGPRSDevice( this ); | 41 | return new AGPRSDevice( this ); |
46 | } | 42 | } |
47 | 43 | ||
48 | bool GPRSNetNode::hasDataForFile( SystemFile & S ) { | 44 | bool GPRSNetNode::hasDataForFile( SystemFile & S ) { |
49 | return S.name() == "pap-secrets"; | 45 | return S.name() == "pap-secrets"; |
50 | } | 46 | } |
51 | 47 | ||
52 | short GPRSNetNode::generateFile( SystemFile & , | 48 | short GPRSNetNode::generateFile( SystemFile & , |
53 | ANetNodeInstance * , | 49 | ANetNodeInstance * , |
54 | long ) { | 50 | long ) { |
55 | 51 | ||
56 | return 0; | 52 | return 0; |
57 | } | 53 | } |
58 | 54 | ||
59 | const char ** GPRSNetNode::needs( void ) { | 55 | const char ** GPRSNetNode::needs( void ) { |
60 | return GPRSNeeds; | 56 | return GPRSNeeds; |
61 | } | 57 | } |
62 | 58 | ||
63 | const char ** GPRSNetNode::provides( void ) { | 59 | const char ** GPRSNetNode::provides( void ) { |
64 | return GPRSProvides; | 60 | return GPRSProvides; |
65 | } | 61 | } |
66 | 62 | ||
67 | void GPRSNetNode::setSpecificAttribute( QString & , QString & ) { | 63 | void GPRSNetNode::setSpecificAttribute( QString & , QString & ) { |
68 | } | 64 | } |
69 | 65 | ||
70 | void GPRSNetNode::saveSpecificAttribute( QTextStream & ) { | 66 | void GPRSNetNode::saveSpecificAttribute( QTextStream & ) { |
71 | } | 67 | } |
72 | 68 | ||
73 | QStringList GPRSNetNode::properFiles( void ) { | 69 | QStringList GPRSNetNode::properFiles( void ) { |
74 | QStringList SL; | 70 | QStringList SL; |
75 | 71 | ||
76 | SL << "peers"; | 72 | SL << "peers"; |
77 | SL << "chatscripts"; | 73 | SL << "chatscripts"; |
78 | SL << "extra"; | 74 | SL << "extra"; |
79 | return SL; | 75 | return SL; |
80 | } | 76 | } |
81 | 77 | ||
82 | #ifdef MYPLUGIN | 78 | OPIE_NS2_PLUGIN( NetNodeInterface_T<GPRSNetNode> ) |
83 | |||
84 | extern "C" { | ||
85 | void create_plugin( QList<ANetNode> & PNN ) { | ||
86 | PNN.append( new GPRSNetNode() ); | ||
87 | } | ||
88 | |||
89 | #else | ||
90 | |||
91 | OPIE_NS2_PLUGIN( NetNodeInterface<GPRSNetNode> ) | ||
92 | |||
93 | #endif | ||
94 | |||
95 | } | ||
diff --git a/noncore/settings/networksettings2/irda/irda_NN.cpp b/noncore/settings/networksettings2/irda/irda_NN.cpp index 6858157..a1ed686 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.cpp +++ b/noncore/settings/networksettings2/irda/irda_NN.cpp | |||
@@ -1,69 +1,52 @@ | |||
1 | #include "irda_NN.h" | 1 | #include "irda_NN.h" |
2 | #include "irda_NNI.h" | 2 | #include "irda_NNI.h" |
3 | 3 | ||
4 | #ifndef MYPLUGIN | ||
5 | |||
6 | #include "netnodeinterface.h" | 4 | #include "netnodeinterface.h" |
7 | 5 | ||
8 | #endif | ||
9 | |||
10 | static const char * IRDANeeds[] = | 6 | static const char * IRDANeeds[] = |
11 | { 0 | 7 | { 0 |
12 | }; | 8 | }; |
13 | 9 | ||
14 | static const char * IRDAProvides[] = | 10 | static const char * IRDAProvides[] = |
15 | { "line", | 11 | { "line", |
16 | 0 | 12 | 0 |
17 | }; | 13 | }; |
18 | 14 | ||
19 | /** | 15 | /** |
20 | * Constructor, find all of the possible interfaces | 16 | * Constructor, find all of the possible interfaces |
21 | */ | 17 | */ |
22 | IRDANetNode::IRDANetNode() : ANetNode(tr("Infrared link")) { | 18 | IRDANetNode::IRDANetNode() : ANetNode(tr("Infrared link")) { |
23 | } | 19 | } |
24 | 20 | ||
25 | /** | 21 | /** |
26 | * Delete any interfaces that we own. | 22 | * Delete any interfaces that we own. |
27 | */ | 23 | */ |
28 | IRDANetNode::~IRDANetNode(){ | 24 | IRDANetNode::~IRDANetNode(){ |
29 | } | 25 | } |
30 | 26 | ||
31 | const QString IRDANetNode::nodeDescription(){ | 27 | const QString IRDANetNode::nodeDescription(){ |
32 | return tr("\ | 28 | return tr("\ |
33 | <p>Sets up a infra red serial link.</p>\ | 29 | <p>Sets up a infra red serial link.</p>\ |
34 | " | 30 | " |
35 | ); | 31 | ); |
36 | } | 32 | } |
37 | 33 | ||
38 | ANetNodeInstance * IRDANetNode::createInstance( void ) { | 34 | ANetNodeInstance * IRDANetNode::createInstance( void ) { |
39 | return new AIRDA( this ); | 35 | return new AIRDA( this ); |
40 | } | 36 | } |
41 | 37 | ||
42 | const char ** IRDANetNode::needs( void ) { | 38 | const char ** IRDANetNode::needs( void ) { |
43 | return IRDANeeds; | 39 | return IRDANeeds; |
44 | } | 40 | } |
45 | 41 | ||
46 | const char ** IRDANetNode::provides( void ) { | 42 | const char ** IRDANetNode::provides( void ) { |
47 | return IRDAProvides; | 43 | return IRDAProvides; |
48 | } | 44 | } |
49 | 45 | ||
50 | void IRDANetNode::setSpecificAttribute( QString & , QString & ) { | 46 | void IRDANetNode::setSpecificAttribute( QString & , QString & ) { |
51 | } | 47 | } |
52 | 48 | ||
53 | void IRDANetNode::saveSpecificAttribute( QTextStream & ) { | 49 | void IRDANetNode::saveSpecificAttribute( QTextStream & ) { |
54 | } | 50 | } |
55 | 51 | ||
56 | #ifdef MYPLUGIN | 52 | OPIE_NS2_PLUGIN( NetNodeInterface_T<IRDANetNode> ) |
57 | |||
58 | extern "C" { | ||
59 | void create_plugin( QList<ANetNode> & PNN ) { | ||
60 | PNN.append( new IRDANetNode() ); | ||
61 | } | ||
62 | |||
63 | #else | ||
64 | |||
65 | OPIE_NS2_PLUGIN( NetNodeInterface<IRDANetNode> ) | ||
66 | |||
67 | #endif | ||
68 | |||
69 | } | ||
diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp index fce3d29..520516c 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp | |||
@@ -1,92 +1,75 @@ | |||
1 | #include "lancard_NN.h" | 1 | #include "lancard_NN.h" |
2 | #include "lancard_NNI.h" | 2 | #include "lancard_NNI.h" |
3 | 3 | ||
4 | #ifndef MYPLUGIN | ||
5 | |||
6 | #include "netnodeinterface.h" | 4 | #include "netnodeinterface.h" |
7 | 5 | ||
8 | #endif | ||
9 | |||
10 | static const char * LanCardNeeds[] = | 6 | static const char * LanCardNeeds[] = |
11 | { 0 | 7 | { 0 |
12 | }; | 8 | }; |
13 | 9 | ||
14 | static const char * LanCardProvides[] = | 10 | static const char * LanCardProvides[] = |
15 | { "device", | 11 | { "device", |
16 | 0 | 12 | 0 |
17 | }; | 13 | }; |
18 | 14 | ||
19 | /** | 15 | /** |
20 | * Constructor, find all of the possible interfaces | 16 | * Constructor, find all of the possible interfaces |
21 | */ | 17 | */ |
22 | LanCardNetNode::LanCardNetNode() : ANetNode(tr("LAN card")), NICMACAddresses() { | 18 | LanCardNetNode::LanCardNetNode() : ANetNode(tr("LAN card")), NICMACAddresses() { |
23 | InstanceCount = 2; | 19 | InstanceCount = 2; |
24 | } | 20 | } |
25 | 21 | ||
26 | /** | 22 | /** |
27 | * Delete any interfaces that we own. | 23 | * Delete any interfaces that we own. |
28 | */ | 24 | */ |
29 | LanCardNetNode::~LanCardNetNode(){ | 25 | LanCardNetNode::~LanCardNetNode(){ |
30 | } | 26 | } |
31 | 27 | ||
32 | const QString LanCardNetNode::nodeDescription(){ | 28 | const QString LanCardNetNode::nodeDescription(){ |
33 | return tr("\ | 29 | return tr("\ |
34 | <p>Sets up a wired regular LAN card.</p>\ | 30 | <p>Sets up a wired regular LAN card.</p>\ |
35 | <p>Use this to set up 10/100/1000 MBit LAN cards.</p>\ | 31 | <p>Use this to set up 10/100/1000 MBit LAN cards.</p>\ |
36 | " | 32 | " |
37 | ); | 33 | ); |
38 | } | 34 | } |
39 | 35 | ||
40 | ANetNodeInstance * LanCardNetNode::createInstance( void ) { | 36 | ANetNodeInstance * LanCardNetNode::createInstance( void ) { |
41 | return new ALanCard( this ); | 37 | return new ALanCard( this ); |
42 | } | 38 | } |
43 | 39 | ||
44 | 40 | ||
45 | const char ** LanCardNetNode::needs( void ) { | 41 | const char ** LanCardNetNode::needs( void ) { |
46 | return LanCardNeeds; | 42 | return LanCardNeeds; |
47 | } | 43 | } |
48 | 44 | ||
49 | const char ** LanCardNetNode::provides( void ) { | 45 | const char ** LanCardNetNode::provides( void ) { |
50 | return LanCardProvides; | 46 | return LanCardProvides; |
51 | } | 47 | } |
52 | 48 | ||
53 | QString LanCardNetNode::genNic( long nr ) { | 49 | QString LanCardNetNode::genNic( long nr ) { |
54 | QString S; | 50 | QString S; |
55 | return S.sprintf( "eth%ld", nr ); | 51 | return S.sprintf( "eth%ld", nr ); |
56 | } | 52 | } |
57 | 53 | ||
58 | void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) { | 54 | void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) { |
59 | if( A == "interfacecount" ) { | 55 | if( A == "interfacecount" ) { |
60 | InstanceCount = V.toLong(); | 56 | InstanceCount = V.toLong(); |
61 | } else if ( A == "macaddress" ) { | 57 | } else if ( A == "macaddress" ) { |
62 | NICMACAddresses.append( V ); | 58 | NICMACAddresses.append( V ); |
63 | } | 59 | } |
64 | } | 60 | } |
65 | 61 | ||
66 | void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) { | 62 | void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) { |
67 | TS << "interfacecount=" | 63 | TS << "interfacecount=" |
68 | << InstanceCount | 64 | << InstanceCount |
69 | << endl; | 65 | << endl; |
70 | for( QStringList::Iterator it = NICMACAddresses.begin(); | 66 | for( QStringList::Iterator it = NICMACAddresses.begin(); |
71 | it != NICMACAddresses.end(); | 67 | it != NICMACAddresses.end(); |
72 | ++it ) { | 68 | ++it ) { |
73 | TS << "macaddress=" | 69 | TS << "macaddress=" |
74 | << (*it) | 70 | << (*it) |
75 | << endl; | 71 | << endl; |
76 | } | 72 | } |
77 | } | 73 | } |
78 | 74 | ||
79 | #ifdef MYPLUGIN | 75 | OPIE_NS2_PLUGIN( NetNodeInterface_T<LanCardNetNode> ) |
80 | |||
81 | extern "C" { | ||
82 | void create_plugin( QList<ANetNode> & PNN ) { | ||
83 | PNN.append( new LanCardNetNode() ); | ||
84 | } | ||
85 | |||
86 | #else | ||
87 | |||
88 | OPIE_NS2_PLUGIN( NetNodeInterface<LanCardNetNode> ) | ||
89 | |||
90 | #endif | ||
91 | |||
92 | } | ||
diff --git a/noncore/settings/networksettings2/modem/modem_NN.cpp b/noncore/settings/networksettings2/modem/modem_NN.cpp index c7f6e78..e91b45a 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.cpp +++ b/noncore/settings/networksettings2/modem/modem_NN.cpp | |||
@@ -1,70 +1,53 @@ | |||
1 | #include "modem_NN.h" | 1 | #include "modem_NN.h" |
2 | #include "modem_NNI.h" | 2 | #include "modem_NNI.h" |
3 | 3 | ||
4 | #ifndef MYPLUGIN | ||
5 | |||
6 | #include "netnodeinterface.h" | 4 | #include "netnodeinterface.h" |
7 | 5 | ||
8 | #endif | ||
9 | |||
10 | static const char * ModemNeeds[] = | 6 | static const char * ModemNeeds[] = |
11 | { "line", | 7 | { "line", |
12 | 0 | 8 | 0 |
13 | }; | 9 | }; |
14 | static const char * ModemProvides[] = | 10 | static const char * ModemProvides[] = |
15 | { "modem", | 11 | { "modem", |
16 | 0 | 12 | 0 |
17 | }; | 13 | }; |
18 | 14 | ||
19 | /** | 15 | /** |
20 | * Constructor, find all of the possible interfaces | 16 | * Constructor, find all of the possible interfaces |
21 | */ | 17 | */ |
22 | ModemNetNode::ModemNetNode() : ANetNode(tr("Dialup modem")) { | 18 | ModemNetNode::ModemNetNode() : ANetNode(tr("Dialup modem")) { |
23 | } | 19 | } |
24 | 20 | ||
25 | /** | 21 | /** |
26 | * Delete any interfaces that we own. | 22 | * Delete any interfaces that we own. |
27 | */ | 23 | */ |
28 | ModemNetNode::~ModemNetNode(){ | 24 | ModemNetNode::~ModemNetNode(){ |
29 | } | 25 | } |
30 | 26 | ||
31 | const QString ModemNetNode::nodeDescription(){ | 27 | const QString ModemNetNode::nodeDescription(){ |
32 | return tr("\ | 28 | return tr("\ |
33 | <p>Sets up a dialing procedures.</p>\ | 29 | <p>Sets up a dialing procedures.</p>\ |
34 | <p>Use this to dial up over modems, ISDN, GSM, ...</p>\ | 30 | <p>Use this to dial up over modems, ISDN, GSM, ...</p>\ |
35 | " | 31 | " |
36 | ); | 32 | ); |
37 | } | 33 | } |
38 | 34 | ||
39 | ANetNodeInstance * ModemNetNode::createInstance( void ) { | 35 | ANetNodeInstance * ModemNetNode::createInstance( void ) { |
40 | return new AModem( this ); | 36 | return new AModem( this ); |
41 | } | 37 | } |
42 | 38 | ||
43 | const char ** ModemNetNode::needs( void ) { | 39 | const char ** ModemNetNode::needs( void ) { |
44 | return ModemNeeds; | 40 | return ModemNeeds; |
45 | } | 41 | } |
46 | 42 | ||
47 | const char ** ModemNetNode::provides( void ) { | 43 | const char ** ModemNetNode::provides( void ) { |
48 | return ModemProvides; | 44 | return ModemProvides; |
49 | } | 45 | } |
50 | 46 | ||
51 | void ModemNetNode::setSpecificAttribute( QString & , QString & ) { | 47 | void ModemNetNode::setSpecificAttribute( QString & , QString & ) { |
52 | } | 48 | } |
53 | 49 | ||
54 | void ModemNetNode::saveSpecificAttribute( QTextStream & ) { | 50 | void ModemNetNode::saveSpecificAttribute( QTextStream & ) { |
55 | } | 51 | } |
56 | 52 | ||
57 | #ifdef MYPLUGIN | 53 | OPIE_NS2_PLUGIN( NetNodeInterface_T<ModemNetNode> ) |
58 | |||
59 | extern "C" { | ||
60 | void create_plugin( QList<ANetNode> & PNN ) { | ||
61 | PNN.append( new ModemNetNode() ); | ||
62 | } | ||
63 | |||
64 | #else | ||
65 | |||
66 | OPIE_NS2_PLUGIN( NetNodeInterface<ModemNetNode> ) | ||
67 | |||
68 | #endif | ||
69 | |||
70 | } | ||
diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp index 82d0c29..2fa31bd 100644 --- a/noncore/settings/networksettings2/network/network_NN.cpp +++ b/noncore/settings/networksettings2/network/network_NN.cpp | |||
@@ -1,112 +1,95 @@ | |||
1 | #include <qpe/qpeapplication.h> | 1 | #include <qpe/qpeapplication.h> |
2 | #include <resources.h> | 2 | #include <resources.h> |
3 | #include <netnode.h> | 3 | #include <netnode.h> |
4 | #include "network_NN.h" | 4 | #include "network_NN.h" |
5 | #include "network_NNI.h" | 5 | #include "network_NNI.h" |
6 | 6 | ||
7 | #ifndef MYPLUGIN | ||
8 | |||
9 | #include "netnodeinterface.h" | 7 | #include "netnodeinterface.h" |
10 | 8 | ||
11 | #endif | ||
12 | |||
13 | static const char * NetworkNeeds[] = | 9 | static const char * NetworkNeeds[] = |
14 | { "device", | 10 | { "device", |
15 | 0 | 11 | 0 |
16 | }; | 12 | }; |
17 | 13 | ||
18 | static const char * NetworkProvides[] = | 14 | static const char * NetworkProvides[] = |
19 | { "connection", | 15 | { "connection", |
20 | 0 | 16 | 0 |
21 | }; | 17 | }; |
22 | 18 | ||
23 | /** | 19 | /** |
24 | * Constructor, find all of the possible interfaces | 20 | * Constructor, find all of the possible interfaces |
25 | */ | 21 | */ |
26 | NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) { | 22 | NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) { |
27 | 23 | ||
28 | NSResources->addSystemFile( | 24 | NSResources->addSystemFile( |
29 | "interfaces", "/etc/network/interfaces", 1 ); | 25 | "interfaces", "/etc/network/interfaces", 1 ); |
30 | } | 26 | } |
31 | 27 | ||
32 | /** | 28 | /** |
33 | * Delete any interfaces that we own. | 29 | * Delete any interfaces that we own. |
34 | */ | 30 | */ |
35 | NetworkNetNode::~NetworkNetNode(){ | 31 | NetworkNetNode::~NetworkNetNode(){ |
36 | } | 32 | } |
37 | 33 | ||
38 | const QString NetworkNetNode::nodeDescription(){ | 34 | const QString NetworkNetNode::nodeDescription(){ |
39 | return tr("\ | 35 | return tr("\ |
40 | <p>Sets up TCP/IP options.</p>\ | 36 | <p>Sets up TCP/IP options.</p>\ |
41 | <p>Use this to configure the TCP/IP protocol</p>\ | 37 | <p>Use this to configure the TCP/IP protocol</p>\ |
42 | " | 38 | " |
43 | ); | 39 | ); |
44 | } | 40 | } |
45 | 41 | ||
46 | ANetNodeInstance * NetworkNetNode::createInstance( void ) { | 42 | ANetNodeInstance * NetworkNetNode::createInstance( void ) { |
47 | return new ANetwork( this ); | 43 | return new ANetwork( this ); |
48 | } | 44 | } |
49 | 45 | ||
50 | bool NetworkNetNode::hasDataForFile( SystemFile & S ) { | 46 | bool NetworkNetNode::hasDataForFile( SystemFile & S ) { |
51 | return S.name() == "interfaces"; | 47 | return S.name() == "interfaces"; |
52 | } | 48 | } |
53 | 49 | ||
54 | short NetworkNetNode::generateFile( SystemFile & SF, | 50 | short NetworkNetNode::generateFile( SystemFile & SF, |
55 | ANetNodeInstance * NNI, | 51 | ANetNodeInstance * NNI, |
56 | long DevNr ) { | 52 | long DevNr ) { |
57 | 53 | ||
58 | if( DevNr < 0 ) { | 54 | if( DevNr < 0 ) { |
59 | // generate device specific but common part | 55 | // generate device specific but common part |
60 | return 1; | 56 | return 1; |
61 | } | 57 | } |
62 | 58 | ||
63 | QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); | 59 | QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); |
64 | 60 | ||
65 | if( SF.name() == "interfaces" ) { | 61 | if( SF.name() == "interfaces" ) { |
66 | Log(("Generate entry for %s in %s\n", NIC.latin1(), SF.name().latin1() )); | 62 | Log(("Generate entry for %s in %s\n", NIC.latin1(), SF.name().latin1() )); |
67 | // generate mapping stanza for this interface | 63 | // generate mapping stanza for this interface |
68 | SF << "# check if " | 64 | SF << "# check if " |
69 | << NIC | 65 | << NIC |
70 | << " can be brought UP" | 66 | << " can be brought UP" |
71 | << endl; | 67 | << endl; |
72 | SF << "mapping " | 68 | SF << "mapping " |
73 | << NIC | 69 | << NIC |
74 | << endl; | 70 | << endl; |
75 | SF << " script " | 71 | SF << " script " |
76 | << QPEApplication::qpeDir() | 72 | << QPEApplication::qpeDir() |
77 | << "bin/networksettings2-request" | 73 | << "bin/networksettings2-request" |
78 | << endl | 74 | << endl |
79 | << endl; | 75 | << endl; |
80 | return 0; | 76 | return 0; |
81 | } | 77 | } |
82 | return 1; | 78 | return 1; |
83 | } | 79 | } |
84 | 80 | ||
85 | const char ** NetworkNetNode::needs( void ) { | 81 | const char ** NetworkNetNode::needs( void ) { |
86 | return NetworkNeeds; | 82 | return NetworkNeeds; |
87 | } | 83 | } |
88 | 84 | ||
89 | const char ** NetworkNetNode::provides( void ) { | 85 | const char ** NetworkNetNode::provides( void ) { |
90 | return NetworkProvides; | 86 | return NetworkProvides; |
91 | } | 87 | } |
92 | 88 | ||
93 | void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { | 89 | void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { |
94 | } | 90 | } |
95 | 91 | ||
96 | void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { | 92 | void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { |
97 | } | 93 | } |
98 | 94 | ||
99 | #ifdef MYPLUGIN | 95 | OPIE_NS2_PLUGIN( NetNodeInterface_T<NetworkNetNode> ) |
100 | |||
101 | extern "C" { | ||
102 | void create_plugin( QList<ANetNode> & PNN ) { | ||
103 | PNN.append( new NetworkNetNode() ); | ||
104 | } | ||
105 | |||
106 | #else | ||
107 | |||
108 | OPIE_NS2_PLUGIN( NetNodeInterface<NetworkNetNode> ) | ||
109 | |||
110 | #endif | ||
111 | |||
112 | } | ||
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index dca6631..9680a96 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp | |||
@@ -1,514 +1,514 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <unistd.h> | 2 | #include <unistd.h> |
3 | #include <errno.h> | 3 | #include <errno.h> |
4 | 4 | ||
5 | #include <opie2/odebug.h> | 5 | #include <opie2/odebug.h> |
6 | #include <opie2/oledbox.h> | 6 | #include <opie2/oledbox.h> |
7 | 7 | ||
8 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
9 | #include <qlistbox.h> | 9 | #include <qlistbox.h> |
10 | #include <qlayout.h> | 10 | #include <qlayout.h> |
11 | #include <qgroupbox.h> | 11 | #include <qgroupbox.h> |
12 | #include <qtimer.h> | 12 | #include <qtimer.h> |
13 | #include <qlistbox.h> | 13 | #include <qlistbox.h> |
14 | #include <qmessagebox.h> | 14 | #include <qmessagebox.h> |
15 | #include <qlabel.h> | 15 | #include <qlabel.h> |
16 | #include <qiconview.h> | 16 | #include <qiconview.h> |
17 | #include <qtimer.h> | 17 | #include <qtimer.h> |
18 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
19 | #include <qtoolbutton.h> | 19 | #include <qtoolbutton.h> |
20 | #include <qevent.h> | 20 | #include <qevent.h> |
21 | 21 | ||
22 | #include "networksettings.h" | 22 | #include "networksettings.h" |
23 | #include "netnode.h" | 23 | #include "netnode.h" |
24 | #include "editconnection.h" | 24 | #include "editconnection.h" |
25 | 25 | ||
26 | NetworkSettings::NetworkSettings( QWidget *parent, | 26 | NetworkSettings::NetworkSettings( QWidget *parent, |
27 | const char *name, | 27 | const char *name, |
28 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), | 28 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), |
29 | NSD() { | 29 | NSD() { |
30 | 30 | ||
31 | UpdateTimer = new QTimer( this ); | 31 | UpdateTimer = new QTimer( this ); |
32 | 32 | ||
33 | // set pixmaps | 33 | // set pixmaps |
34 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); | 34 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); |
35 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); | 35 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); |
36 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); | 36 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); |
37 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); | 37 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); |
38 | 38 | ||
39 | Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); | 39 | Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); |
40 | Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); | 40 | Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); |
41 | Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); | 41 | Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); |
42 | 42 | ||
43 | QVBoxLayout* V = new QVBoxLayout( LED_Frm ); | 43 | QVBoxLayout* V = new QVBoxLayout( LED_Frm ); |
44 | QHBoxLayout * H = new QHBoxLayout( 0 ); | 44 | QHBoxLayout * H = new QHBoxLayout( 0 ); |
45 | V->addStretch(1); | 45 | V->addStretch(1); |
46 | V->addLayout( H ); | 46 | V->addLayout( H ); |
47 | Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm ); | 47 | Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm ); |
48 | H->addWidget( Leds[0], 0, Qt::AlignVCenter ); | 48 | H->addWidget( Leds[0], 0, Qt::AlignVCenter ); |
49 | Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm ); | 49 | Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm ); |
50 | H->addWidget( Leds[1], 0, Qt::AlignVCenter ); | 50 | H->addWidget( Leds[1], 0, Qt::AlignVCenter ); |
51 | Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm ); | 51 | Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm ); |
52 | H->addWidget( Leds[2], 0, Qt::AlignVCenter ); | 52 | H->addWidget( Leds[2], 0, Qt::AlignVCenter ); |
53 | V->addStretch(1); | 53 | V->addStretch(1); |
54 | 54 | ||
55 | 55 | ||
56 | SLOT_ToProfile(); | 56 | SLOT_ToProfile(); |
57 | 57 | ||
58 | // populate main Listbox | 58 | // populate main Listbox |
59 | Profiles_LB->clear(); | 59 | Profiles_LB->clear(); |
60 | QPEApplication::setStylusOperation( | 60 | QPEApplication::setStylusOperation( |
61 | Profiles_LB->viewport(), QPEApplication::RightOnHold ); | 61 | Profiles_LB->viewport(), QPEApplication::RightOnHold ); |
62 | 62 | ||
63 | connect( Profiles_LB, | 63 | connect( Profiles_LB, |
64 | SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), | 64 | SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), |
65 | this, SLOT(SLOT_EditNode(QListBoxItem*)) ); | 65 | this, SLOT(SLOT_EditNode(QListBoxItem*)) ); |
66 | 66 | ||
67 | { Name2Connection_t & M = NSResources->connections(); | 67 | { Name2Connection_t & M = NSResources->connections(); |
68 | NodeCollection * NC; | 68 | NodeCollection * NC; |
69 | // for all connections | 69 | // for all connections |
70 | for( QDictIterator<NodeCollection> it(M); | 70 | for( QDictIterator<NodeCollection> it(M); |
71 | it.current(); | 71 | it.current(); |
72 | ++it ) { | 72 | ++it ) { |
73 | NC = it.current(); | 73 | NC = it.current(); |
74 | Profiles_LB->insertItem( NC->devicePixmap(), | 74 | Profiles_LB->insertItem( NC->devicePixmap(), |
75 | NC->name() ); | 75 | NC->name() ); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | if( Profiles_LB->count() ) { | 79 | if( Profiles_LB->count() ) { |
80 | Profiles_LB->setSelected( 0, TRUE ); | 80 | Profiles_LB->setSelected( 0, TRUE ); |
81 | } | 81 | } |
82 | 82 | ||
83 | // if no profiles -> auto popup editing | 83 | // if no profiles -> auto popup editing |
84 | if( NSResources->connections().count() == 0 ) { | 84 | if( NSResources->connections().count() == 0 ) { |
85 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); | 85 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); |
86 | } | 86 | } |
87 | 87 | ||
88 | connect( &(NSResources->system()), | 88 | connect( &(NSResources->system()), |
89 | SIGNAL( stdoutLine(const QString &) ), | 89 | SIGNAL( stdoutLine(const QString &) ), |
90 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | 90 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); |
91 | 91 | ||
92 | connect( &(NSResources->system()), | 92 | connect( &(NSResources->system()), |
93 | SIGNAL( stderrLine(const QString &) ), | 93 | SIGNAL( stderrLine(const QString &) ), |
94 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | 94 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); |
95 | 95 | ||
96 | connect( &(NSResources->system()), | 96 | connect( &(NSResources->system()), |
97 | SIGNAL( processEvent(const QString &) ), | 97 | SIGNAL( processEvent(const QString &) ), |
98 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | 98 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); |
99 | 99 | ||
100 | UpdateTimer->start( 5000 ); | 100 | UpdateTimer->start( 5000 ); |
101 | connect( UpdateTimer, SIGNAL( timeout() ), | 101 | connect( UpdateTimer, SIGNAL( timeout() ), |
102 | this, SLOT( SLOT_RefreshStates() ) ); | 102 | this, SLOT( SLOT_RefreshStates() ) ); |
103 | 103 | ||
104 | /* Add QCopChannel */ | 104 | /* Add QCopChannel */ |
105 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 105 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
106 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); | 106 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); |
107 | } | 107 | } |
108 | 108 | ||
109 | NetworkSettings::~NetworkSettings() { | 109 | NetworkSettings::~NetworkSettings() { |
110 | QString S; | 110 | QString S; |
111 | 111 | ||
112 | owarn << "Dispose NS" << oendl; | 112 | owarn << "Dispose NS" << oendl; |
113 | if( NSD.isModified() ) { | 113 | if( NSD.isModified() ) { |
114 | owarn << "Modified" << oendl; | 114 | owarn << "Modified" << oendl; |
115 | S = NSD.saveSettings(); | 115 | S = NSD.saveSettings(); |
116 | if( ! S.isEmpty() ) { | 116 | if( ! S.isEmpty() ) { |
117 | S.insert( 0, "<p>" ); | 117 | S.insert( 0, "<p>" ); |
118 | S.append( "</p>" ); | 118 | S.append( "</p>" ); |
119 | // problem saving | 119 | // problem saving |
120 | QMessageBox::warning( | 120 | QMessageBox::warning( |
121 | 0, | 121 | 0, |
122 | tr( "Saving setup" ), S ); | 122 | tr( "Saving setup" ), S ); |
123 | } | 123 | } |
124 | 124 | ||
125 | SLOT_GenerateConfig(); | 125 | SLOT_GenerateConfig(); |
126 | NSD.setModified( 0 ); | 126 | NSD.setModified( 0 ); |
127 | } | 127 | } |
128 | 128 | ||
129 | } | 129 | } |
130 | 130 | ||
131 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { | 131 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { |
132 | Messages_LB->insertItem( S ); | 132 | Messages_LB->insertItem( S ); |
133 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); | 133 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); |
134 | Messages_LB->ensureCurrentVisible(); | 134 | Messages_LB->ensureCurrentVisible(); |
135 | } | 135 | } |
136 | 136 | ||
137 | void NetworkSettings::SLOT_RefreshStates( void ) { | 137 | void NetworkSettings::SLOT_RefreshStates( void ) { |
138 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember | 138 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember |
139 | 139 | ||
140 | if( LBI ) { | 140 | if( LBI ) { |
141 | NodeCollection * NC; | 141 | NodeCollection * NC; |
142 | NSResources->system().probeInterfaces(); | 142 | NSResources->system().probeInterfaces(); |
143 | // update current selection only | 143 | // update current selection only |
144 | NC = NSResources->findConnection( LBI->text() ); | 144 | NC = NSResources->findConnection( LBI->text() ); |
145 | if( NC ) { | 145 | if( NC ) { |
146 | State_t OldS = NC->state(); | 146 | State_t OldS = NC->state(); |
147 | State_t NewS = NC->state(1); | 147 | State_t NewS = NC->state(1); |
148 | if( OldS != NewS ) { | 148 | if( OldS != NewS ) { |
149 | updateProfileState( LBI ); | 149 | updateProfileState( LBI ); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | /* -> LATER !! | 155 | /* -> LATER !! |
156 | bool is; | 156 | bool is; |
157 | NodeCollection * NC; | 157 | NodeCollection * NC; |
158 | 158 | ||
159 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { | 159 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { |
160 | NC = NSResources->findConnection( Profiles_LB->text(i) ); | 160 | NC = NSResources->findConnection( Profiles_LB->text(i) ); |
161 | if( NC ) { | 161 | if( NC ) { |
162 | State_t OldS = NC->state(); | 162 | State_t OldS = NC->state(); |
163 | State_t NewS = NC->state(1); | 163 | State_t NewS = NC->state(1); |
164 | if( OldS != NewS ) { | 164 | if( OldS != NewS ) { |
165 | is = Profiles_LB->isSelected(i); | 165 | is = Profiles_LB->isSelected(i); |
166 | Profiles_LB->changeItem( NC->statePixmap(NewS), | 166 | Profiles_LB->changeItem( NC->statePixmap(NewS), |
167 | NC->name(), | 167 | NC->name(), |
168 | i ); | 168 | i ); |
169 | if( is ) { | 169 | if( is ) { |
170 | Profiles_LB->setSelected( i, TRUE ); | 170 | Profiles_LB->setSelected( i, TRUE ); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } | 173 | } |
174 | } | 174 | } |
175 | if( ci >= 0 ) | 175 | if( ci >= 0 ) |
176 | Profiles_LB->setCurrentItem( ci ); | 176 | Profiles_LB->setCurrentItem( ci ); |
177 | */ | 177 | */ |
178 | } | 178 | } |
179 | 179 | ||
180 | void NetworkSettings::SLOT_AddNode( void ) { | 180 | void NetworkSettings::SLOT_AddNode( void ) { |
181 | SLOT_EditNode( 0 ); | 181 | SLOT_EditNode( 0 ); |
182 | } | 182 | } |
183 | 183 | ||
184 | void NetworkSettings::SLOT_DeleteNode( void ) { | 184 | void NetworkSettings::SLOT_DeleteNode( void ) { |
185 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 185 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
186 | 186 | ||
187 | if ( ! LBI ) | 187 | if ( ! LBI ) |
188 | return; | 188 | return; |
189 | 189 | ||
190 | if( QMessageBox::warning( | 190 | if( QMessageBox::warning( |
191 | 0, | 191 | 0, |
192 | tr( "Removing profile" ), | 192 | tr( "Removing profile" ), |
193 | tr( "Remove selected profile ?" ), | 193 | tr( "Remove selected profile ?" ), |
194 | 1, 0 ) == 1 ) { | 194 | 1, 0 ) == 1 ) { |
195 | NSResources->removeConnection( LBI->text() ); | 195 | NSResources->removeConnection( LBI->text() ); |
196 | delete LBI; | 196 | delete LBI; |
197 | NSD.setModified( 1 ); | 197 | NSD.setModified( 1 ); |
198 | } | 198 | } |
199 | } | 199 | } |
200 | 200 | ||
201 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | 201 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { |
202 | QString OldName = ""; | 202 | QString OldName = ""; |
203 | 203 | ||
204 | EditConnection EC( this ); | 204 | EditConnection EC( this ); |
205 | 205 | ||
206 | if( LBI ) { | 206 | if( LBI ) { |
207 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 207 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
208 | if( ! NC ) { | 208 | if( ! NC ) { |
209 | return; | 209 | return; |
210 | } | 210 | } |
211 | OldName = NC->name(); | 211 | OldName = NC->name(); |
212 | EC.setConnection( NC ); | 212 | EC.setConnection( NC ); |
213 | } | 213 | } |
214 | 214 | ||
215 | EC.showMaximized(); | 215 | EC.showMaximized(); |
216 | // disable refresh timer | 216 | // disable refresh timer |
217 | UpdateTimer->stop(); | 217 | UpdateTimer->stop(); |
218 | 218 | ||
219 | // we need to retry | 219 | // we need to retry |
220 | while( 1 ) { | 220 | while( 1 ) { |
221 | if( EC.exec() == QDialog::Accepted ) { | 221 | if( EC.exec() == QDialog::Accepted ) { |
222 | // toplevel item -> store | 222 | // toplevel item -> store |
223 | NodeCollection * NC = EC.connection(); | 223 | NodeCollection * NC = EC.connection(); |
224 | if( NC->isModified() ) { | 224 | if( NC->isModified() ) { |
225 | if( LBI ) { | 225 | if( LBI ) { |
226 | if( NC->name() != OldName ) { | 226 | if( NC->name() != OldName ) { |
227 | // find if new name is free | 227 | // find if new name is free |
228 | NodeCollection * LCN = NSResources->findConnection( | 228 | NodeCollection * LCN = NSResources->findConnection( |
229 | NC->name() ); | 229 | NC->name() ); |
230 | if( LCN ) { | 230 | if( LCN ) { |
231 | QMessageBox::warning( | 231 | QMessageBox::warning( |
232 | 0, | 232 | 0, |
233 | tr( "In System Config" ), | 233 | tr( "In System Config" ), |
234 | tr( "Name %1 already exists" ).arg(NC->name()) | 234 | tr( "Name %1 already exists" ).arg(NC->name()) |
235 | ); | 235 | ); |
236 | continue; // restart exec | 236 | continue; // restart exec |
237 | } // else new name | 237 | } // else new name |
238 | // new name -> remove item | 238 | // new name -> remove item |
239 | NSResources->removeConnection( OldName ); | 239 | NSResources->removeConnection( OldName ); |
240 | NSResources->addConnection( NC ); | 240 | NSResources->addConnection( NC, 0 ); |
241 | } // else not changed | 241 | } // else not changed |
242 | 242 | ||
243 | // must add it here since change will trigger event | 243 | // must add it here since change will trigger event |
244 | Profiles_LB->changeItem( NC->devicePixmap(), | 244 | Profiles_LB->changeItem( NC->devicePixmap(), |
245 | NC->name(), | 245 | NC->name(), |
246 | Profiles_LB->index( LBI ) | 246 | Profiles_LB->index( LBI ) |
247 | ); | 247 | ); |
248 | } else { | 248 | } else { |
249 | // new item | 249 | // new item |
250 | int ci = Profiles_LB->count(); | 250 | int ci = Profiles_LB->count(); |
251 | NSResources->addConnection( NC ); | 251 | NSResources->addConnection( NC, 0 ); |
252 | NC->setNumber( NSResources->assignConnectionNumber() ); | 252 | NC->setNumber( NSResources->assignConnectionNumber() ); |
253 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); | 253 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); |
254 | Profiles_LB->setSelected( ci, TRUE ); | 254 | Profiles_LB->setSelected( ci, TRUE ); |
255 | } | 255 | } |
256 | updateProfileState( LBI ); | 256 | updateProfileState( LBI ); |
257 | } | 257 | } |
258 | } else { | 258 | } else { |
259 | // cancelled : reset connection | 259 | // cancelled : reset connection |
260 | if( LBI ) { | 260 | if( LBI ) { |
261 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 261 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
262 | NC->reassign(); | 262 | NC->reassign(); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | break; | 265 | break; |
266 | } | 266 | } |
267 | // reenable | 267 | // reenable |
268 | UpdateTimer->start( 5000 ); | 268 | UpdateTimer->start( 5000 ); |
269 | } | 269 | } |
270 | 270 | ||
271 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { | 271 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { |
272 | if( LBI == 0 ) | 272 | if( LBI == 0 ) |
273 | return; | 273 | return; |
274 | 274 | ||
275 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 275 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
276 | 276 | ||
277 | if( NC->description().isEmpty() ) { | 277 | if( NC->description().isEmpty() ) { |
278 | Description_LBL->setText( tr( "<<No description>>" ) ); | 278 | Description_LBL->setText( tr( "<<No description>>" ) ); |
279 | } else { | 279 | } else { |
280 | Description_LBL->setText( NC->description() ); | 280 | Description_LBL->setText( NC->description() ); |
281 | } | 281 | } |
282 | 282 | ||
283 | Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); | 283 | Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); |
284 | 284 | ||
285 | bool FrmActive = 1; | 285 | bool FrmActive = 1; |
286 | bool IsEnabled = 1; | 286 | bool IsEnabled = 1; |
287 | int leds = 0; | 287 | int leds = 0; |
288 | 288 | ||
289 | owarn << "State " << NC->state() << oendl; | 289 | owarn << "State " << NC->state() << oendl; |
290 | switch( NC->state() ) { | 290 | switch( NC->state() ) { |
291 | case Disabled : // no further work | 291 | case Disabled : // no further work |
292 | IsEnabled = 0; | 292 | IsEnabled = 0; |
293 | FrmActive = 0; | 293 | FrmActive = 0; |
294 | owarn << "LEds " << leds << oendl; | 294 | owarn << "LEds " << leds << oendl; |
295 | break; | 295 | break; |
296 | case Unknown : | 296 | case Unknown : |
297 | case Unchecked : | 297 | case Unchecked : |
298 | case Unavailable : | 298 | case Unavailable : |
299 | FrmActive = 0; | 299 | FrmActive = 0; |
300 | break; | 300 | break; |
301 | case Off : | 301 | case Off : |
302 | leds = 1; | 302 | leds = 1; |
303 | break; | 303 | break; |
304 | case Available : | 304 | case Available : |
305 | leds = 2; | 305 | leds = 2; |
306 | break; | 306 | break; |
307 | case IsUp : | 307 | case IsUp : |
308 | leds = 3; | 308 | leds = 3; |
309 | break; | 309 | break; |
310 | } | 310 | } |
311 | 311 | ||
312 | Disable_TB->setOn( ! IsEnabled ); | 312 | Disable_TB->setOn( ! IsEnabled ); |
313 | LED_Frm->setEnabled( FrmActive ); | 313 | LED_Frm->setEnabled( FrmActive ); |
314 | 314 | ||
315 | for( int i = 0 ; i < leds; i ++ ) { | 315 | for( int i = 0 ; i < leds; i ++ ) { |
316 | Leds[i]->setColor( red ); | 316 | Leds[i]->setColor( red ); |
317 | Leds[i]->setOn( true ); | 317 | Leds[i]->setOn( true ); |
318 | } | 318 | } |
319 | for( int i = leds ; i < 3; i ++ ) { | 319 | for( int i = leds ; i < 3; i ++ ) { |
320 | Leds[i]->setColor( red ); | 320 | Leds[i]->setColor( red ); |
321 | Leds[i]->setOn( false ); | 321 | Leds[i]->setOn( false ); |
322 | } | 322 | } |
323 | 323 | ||
324 | Up_TB->setEnabled( leds < 3 && leds != 0 ); | 324 | Up_TB->setEnabled( leds < 3 && leds != 0 ); |
325 | Down_TB->setEnabled( leds > 0 ); | 325 | Down_TB->setEnabled( leds > 0 ); |
326 | } | 326 | } |
327 | 327 | ||
328 | void NetworkSettings::SLOT_CheckState( void ) { | 328 | void NetworkSettings::SLOT_CheckState( void ) { |
329 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 329 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
330 | if ( ! LBI ) | 330 | if ( ! LBI ) |
331 | return; | 331 | return; |
332 | updateProfileState( LBI ); | 332 | updateProfileState( LBI ); |
333 | } | 333 | } |
334 | 334 | ||
335 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { | 335 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { |
336 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { | 336 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { |
337 | SLOT_ShowNode( LBI ); | 337 | SLOT_ShowNode( LBI ); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
341 | void NetworkSettings::SLOT_GenerateConfig( void ) { | 341 | void NetworkSettings::SLOT_GenerateConfig( void ) { |
342 | QString S = NSD.generateSettings(); | 342 | QString S = NSD.generateSettings(); |
343 | if( ! S.isEmpty() ) { | 343 | if( ! S.isEmpty() ) { |
344 | S.insert( 0, "<p>" ); | 344 | S.insert( 0, "<p>" ); |
345 | S.append( "</p>" ); | 345 | S.append( "</p>" ); |
346 | QMessageBox::warning( | 346 | QMessageBox::warning( |
347 | 0, | 347 | 0, |
348 | tr( "Generate config" ), | 348 | tr( "Generate config" ), |
349 | S); | 349 | S); |
350 | } | 350 | } |
351 | } | 351 | } |
352 | 352 | ||
353 | void NetworkSettings::SLOT_Disable( bool T ) { | 353 | void NetworkSettings::SLOT_Disable( bool T ) { |
354 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 354 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
355 | QString Msg; | 355 | QString Msg; |
356 | 356 | ||
357 | if ( ! LBI ) | 357 | if ( ! LBI ) |
358 | return; | 358 | return; |
359 | 359 | ||
360 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 360 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
361 | 361 | ||
362 | owarn << "Prepare to disable" << oendl; | 362 | owarn << "Prepare to disable" << oendl; |
363 | Msg = NC->setState( (T) ? Disable : Enable ); | 363 | Msg = NC->setState( (T) ? Disable : Enable ); |
364 | if( ! Msg.isEmpty() ) { | 364 | if( ! Msg.isEmpty() ) { |
365 | Msg.insert( 0, "<p>" ); | 365 | Msg.insert( 0, "<p>" ); |
366 | Msg.append( "</p>" ); | 366 | Msg.append( "</p>" ); |
367 | QMessageBox::warning( | 367 | QMessageBox::warning( |
368 | 0, | 368 | 0, |
369 | tr( "Activating profile" ), | 369 | tr( "Activating profile" ), |
370 | Msg ); | 370 | Msg ); |
371 | return; | 371 | return; |
372 | } | 372 | } |
373 | 373 | ||
374 | // reload new state | 374 | // reload new state |
375 | NC->state( true ); | 375 | NC->state( true ); |
376 | updateProfileState( LBI ); | 376 | updateProfileState( LBI ); |
377 | } | 377 | } |
378 | 378 | ||
379 | void NetworkSettings::SLOT_Up( void ) { | 379 | void NetworkSettings::SLOT_Up( void ) { |
380 | // bring more up | 380 | // bring more up |
381 | 381 | ||
382 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 382 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
383 | QString Msg; | 383 | QString Msg; |
384 | int led = -1; | 384 | int led = -1; |
385 | 385 | ||
386 | if ( ! LBI ) | 386 | if ( ! LBI ) |
387 | return; | 387 | return; |
388 | 388 | ||
389 | NodeCollection * NC = | 389 | NodeCollection * NC = |
390 | NSResources->findConnection( LBI->text() ); | 390 | NSResources->findConnection( LBI->text() ); |
391 | 391 | ||
392 | switch( NC->state() ) { | 392 | switch( NC->state() ) { |
393 | case Disabled : // cannot modify this state | 393 | case Disabled : // cannot modify this state |
394 | case Unknown : // cannot modify this state | 394 | case Unknown : // cannot modify this state |
395 | case Unchecked : // cannot modify this state | 395 | case Unchecked : // cannot modify this state |
396 | case Unavailable : // cannot modify this state | 396 | case Unavailable : // cannot modify this state |
397 | case IsUp : // highest UP state | 397 | case IsUp : // highest UP state |
398 | return; | 398 | return; |
399 | case Off : // -> activate | 399 | case Off : // -> activate |
400 | led = 1; | 400 | led = 1; |
401 | Down_TB->setEnabled( true ); | 401 | Down_TB->setEnabled( true ); |
402 | Log(( "Activate interface %s\n", NC->name().latin1() )); | 402 | Log(( "Activate interface %s\n", NC->name().latin1() )); |
403 | Msg = NC->setState( Activate ); | 403 | Msg = NC->setState( Activate ); |
404 | break; | 404 | break; |
405 | case Available : // -> up | 405 | case Available : // -> up |
406 | led = 2; | 406 | led = 2; |
407 | Log(( "Bring up interface %s\n", NC->name().latin1() )); | 407 | Log(( "Bring up interface %s\n", NC->name().latin1() )); |
408 | Msg = NC->setState( Up ); | 408 | Msg = NC->setState( Up ); |
409 | if( Msg.isEmpty() ) { | 409 | if( Msg.isEmpty() ) { |
410 | Up_TB->setEnabled( false ); | 410 | Up_TB->setEnabled( false ); |
411 | } | 411 | } |
412 | break; | 412 | break; |
413 | } | 413 | } |
414 | 414 | ||
415 | if( ! Msg.isEmpty() ) { | 415 | if( ! Msg.isEmpty() ) { |
416 | Msg.insert( 0, "<p>" ); | 416 | Msg.insert( 0, "<p>" ); |
417 | Msg.append( "</p>" ); | 417 | Msg.append( "</p>" ); |
418 | QMessageBox::warning( | 418 | QMessageBox::warning( |
419 | 0, | 419 | 0, |
420 | tr( "Increase availability" ), | 420 | tr( "Increase availability" ), |
421 | Msg ); | 421 | Msg ); |
422 | return; | 422 | return; |
423 | } | 423 | } |
424 | 424 | ||
425 | updateProfileState( LBI ); | 425 | updateProfileState( LBI ); |
426 | 426 | ||
427 | // set color of led we should change | 427 | // set color of led we should change |
428 | if( led > 0 ) { | 428 | if( led > 0 ) { |
429 | Leds[led]->setColor( blue ); | 429 | Leds[led]->setColor( blue ); |
430 | Leds[led]->setOn( true ); | 430 | Leds[led]->setOn( true ); |
431 | } | 431 | } |
432 | 432 | ||
433 | } | 433 | } |
434 | 434 | ||
435 | void NetworkSettings::SLOT_Down( void ) { | 435 | void NetworkSettings::SLOT_Down( void ) { |
436 | // bring more down | 436 | // bring more down |
437 | 437 | ||
438 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 438 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
439 | int led = -1; | 439 | int led = -1; |
440 | QString Msg; | 440 | QString Msg; |
441 | 441 | ||
442 | if ( ! LBI ) | 442 | if ( ! LBI ) |
443 | return; | 443 | return; |
444 | 444 | ||
445 | NodeCollection * NC = | 445 | NodeCollection * NC = |
446 | NSResources->findConnection( LBI->text() ); | 446 | NSResources->findConnection( LBI->text() ); |
447 | 447 | ||
448 | switch( NC->state() ) { | 448 | switch( NC->state() ) { |
449 | case Disabled : // cannot modify this state | 449 | case Disabled : // cannot modify this state |
450 | case Unknown : // cannot modify this state | 450 | case Unknown : // cannot modify this state |
451 | case Unchecked : // cannot modify this state | 451 | case Unchecked : // cannot modify this state |
452 | case Unavailable : // cannot modify this state | 452 | case Unavailable : // cannot modify this state |
453 | case Off : // highest DOWN state | 453 | case Off : // highest DOWN state |
454 | break; | 454 | break; |
455 | case Available : // -> down | 455 | case Available : // -> down |
456 | led = 0; | 456 | led = 0; |
457 | Log(( "Deactivate interface %s\n", NC->name().latin1() )); | 457 | Log(( "Deactivate interface %s\n", NC->name().latin1() )); |
458 | Msg = NC->setState( Deactivate ); | 458 | Msg = NC->setState( Deactivate ); |
459 | Down_TB->setEnabled( false ); | 459 | Down_TB->setEnabled( false ); |
460 | break; | 460 | break; |
461 | case IsUp : // highest UP state | 461 | case IsUp : // highest UP state |
462 | led = 1; | 462 | led = 1; |
463 | Up_TB->setEnabled( true ); | 463 | Up_TB->setEnabled( true ); |
464 | Log(( "Bring down interface %s\n", NC->name().latin1() )); | 464 | Log(( "Bring down interface %s\n", NC->name().latin1() )); |
465 | Msg = NC->setState( Down, 1 ); | 465 | Msg = NC->setState( Down, 1 ); |
466 | if( Msg.isEmpty() ) { | 466 | if( Msg.isEmpty() ) { |
467 | // remove 'up' file to make sure | 467 | // remove 'up' file to make sure |
468 | unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; | 468 | unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; |
469 | } | 469 | } |
470 | break; | 470 | break; |
471 | } | 471 | } |
472 | 472 | ||
473 | if( ! Msg.isEmpty() ) { | 473 | if( ! Msg.isEmpty() ) { |
474 | Msg.insert( 0, "<p>" ); | 474 | Msg.insert( 0, "<p>" ); |
475 | Msg.append( "</p>" ); | 475 | Msg.append( "</p>" ); |
476 | QMessageBox::warning( | 476 | QMessageBox::warning( |
477 | 0, | 477 | 0, |
478 | tr( "Decrease availability" ), | 478 | tr( "Decrease availability" ), |
479 | Msg ); | 479 | Msg ); |
480 | return; | 480 | return; |
481 | } | 481 | } |
482 | 482 | ||
483 | updateProfileState( LBI ); | 483 | updateProfileState( LBI ); |
484 | 484 | ||
485 | // set color of led we should change | 485 | // set color of led we should change |
486 | if( led >= 0 ) { | 486 | if( led >= 0 ) { |
487 | Leds[led]->setColor( blue ); | 487 | Leds[led]->setColor( blue ); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
491 | void NetworkSettings::SLOT_ToMessages( void ) { | 491 | void NetworkSettings::SLOT_ToMessages( void ) { |
492 | Profiles_LB->hide(); | 492 | Profiles_LB->hide(); |
493 | Profile_GB->hide(); | 493 | Profile_GB->hide(); |
494 | Messages_GB->show(); | 494 | Messages_GB->show(); |
495 | } | 495 | } |
496 | 496 | ||
497 | void NetworkSettings::SLOT_ToProfile( void ) { | 497 | void NetworkSettings::SLOT_ToProfile( void ) { |
498 | Profiles_LB->show(); | 498 | Profiles_LB->show(); |
499 | Profile_GB->show(); | 499 | Profile_GB->show(); |
500 | Messages_GB->hide(); | 500 | Messages_GB->hide(); |
501 | } | 501 | } |
502 | 502 | ||
503 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { | 503 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { |
504 | QDataStream stream( data, IO_ReadOnly ); | 504 | QDataStream stream( data, IO_ReadOnly ); |
505 | 505 | ||
506 | if( msg == "raise" ) { | 506 | if( msg == "raise" ) { |
507 | raise(); | 507 | raise(); |
508 | return; | 508 | return; |
509 | } /* if ( msg == "someMessage(int,int,int)" ) { | 509 | } /* if ( msg == "someMessage(int,int,int)" ) { |
510 | int a,b,c; | 510 | int a,b,c; |
511 | stream >> a >> b >> c; | 511 | stream >> a >> b >> c; |
512 | ... | 512 | ... |
513 | } */ | 513 | } */ |
514 | } | 514 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index f8f2d1e..f00e0b3 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp | |||
@@ -1,512 +1,519 @@ | |||
1 | #include <time.h> | 1 | #include <time.h> |
2 | #include <qpe/qpeapplication.h> | 2 | #include <qpe/qpeapplication.h> |
3 | #include <qpe/resource.h> | 3 | #include <qpe/resource.h> |
4 | 4 | ||
5 | #include <qpainter.h> | 5 | #include <qpainter.h> |
6 | #include <qbitmap.h> | 6 | #include <qbitmap.h> |
7 | #include <qtextstream.h> | 7 | #include <qtextstream.h> |
8 | #include <qpixmap.h> | 8 | #include <qpixmap.h> |
9 | 9 | ||
10 | #include "resources.h" | 10 | #include "resources.h" |
11 | #include "netnode.h" | 11 | #include "netnode.h" |
12 | 12 | ||
13 | static char * ActionName[] = { | 13 | static char * ActionName[] = { |
14 | "Disable", | 14 | "Disable", |
15 | "Enable", | 15 | "Enable", |
16 | "Activate", | 16 | "Activate", |
17 | "Deactivate", | 17 | "Deactivate", |
18 | "Up", | 18 | "Up", |
19 | "Down" | 19 | "Down" |
20 | }; | 20 | }; |
21 | 21 | ||
22 | static char * StateName[] = { | 22 | static char * StateName[] = { |
23 | "Unchecked", | 23 | "Unchecked", |
24 | "Unknown", | 24 | "Unknown", |
25 | "Unavailable", | 25 | "Unavailable", |
26 | "Disabled", | 26 | "Disabled", |
27 | "Off", | 27 | "Off", |
28 | "Available", | 28 | "Available", |
29 | "IsUp" | 29 | "IsUp" |
30 | }; | 30 | }; |
31 | 31 | ||
32 | QString & deQuote( QString & X ) { | 32 | QString & deQuote( QString & X ) { |
33 | if( X[0] == '"' ) { | 33 | if( X[0] == '"' ) { |
34 | // remove end and trailing "" and \x -> x | 34 | // remove end and trailing "" and \x -> x |
35 | QChar R; | 35 | QChar R; |
36 | long idx; | 36 | long idx; |
37 | idx = X.length()-1; | 37 | idx = X.length()-1; |
38 | X = X.mid( 1, idx ); | 38 | X = X.mid( 1, idx ); |
39 | 39 | ||
40 | idx = 0; | 40 | idx = 0; |
41 | while( ( idx = X.find( '\\', idx ) ) >= 0 ) { | 41 | while( ( idx = X.find( '\\', idx ) ) >= 0 ) { |
42 | R = X.at( idx + 1 ); | 42 | R = X.at( idx + 1 ); |
43 | X.replace( idx, 2, &R, 1 ); | 43 | X.replace( idx, 2, &R, 1 ); |
44 | } | 44 | } |
45 | X = X.left( X.length()-1 ); | 45 | X = X.left( X.length()-1 ); |
46 | } | 46 | } |
47 | return X; | 47 | return X; |
48 | } | 48 | } |
49 | 49 | ||
50 | QString quote( QString X ) { | 50 | QString quote( QString X ) { |
51 | if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { | 51 | if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { |
52 | // need to quote this | 52 | // need to quote this |
53 | QString OutString = "\""; | 53 | QString OutString = "\""; |
54 | 54 | ||
55 | X.replace( QRegExp("\""), "\\\"" ); | 55 | X.replace( QRegExp("\""), "\\\"" ); |
56 | X.replace( QRegExp("\\"), "\\\\" ); | 56 | X.replace( QRegExp("\\"), "\\\\" ); |
57 | X.replace( QRegExp(" "), "\\ " ); | 57 | X.replace( QRegExp(" "), "\\ " ); |
58 | 58 | ||
59 | OutString += X; | 59 | OutString += X; |
60 | OutString += "\""; | 60 | OutString += "\""; |
61 | X = OutString; | 61 | X = OutString; |
62 | } | 62 | } |
63 | return X; | 63 | return X; |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | // | 67 | // |
68 | // | 68 | // |
69 | // ANETNODE | 69 | // ANETNODE |
70 | // | 70 | // |
71 | // | 71 | // |
72 | 72 | ||
73 | void ANetNode::saveAttributes( QTextStream & TS ) { | 73 | void ANetNode::saveAttributes( QTextStream & TS ) { |
74 | saveSpecificAttribute( TS ); | 74 | saveSpecificAttribute( TS ); |
75 | } | 75 | } |
76 | 76 | ||
77 | void ANetNode::setAttribute( QString & Attr, QString & Value ){ | 77 | void ANetNode::setAttribute( QString & Attr, QString & Value ){ |
78 | setSpecificAttribute( Attr, Value ); | 78 | setSpecificAttribute( Attr, Value ); |
79 | } | 79 | } |
80 | 80 | ||
81 | bool ANetNode::isToplevel( void ) { | 81 | bool ANetNode::isToplevel( void ) { |
82 | const char ** P = provides(); | 82 | const char ** P = provides(); |
83 | while( *P ) { | 83 | while( *P ) { |
84 | if( strcmp( *P, "fullsetup") == 0 ) | 84 | if( strcmp( *P, "fullsetup") == 0 ) |
85 | return 1; | 85 | return 1; |
86 | P ++; | 86 | P ++; |
87 | } | 87 | } |
88 | return 0; | 88 | return 0; |
89 | } | 89 | } |
90 | 90 | ||
91 | bool ANetNode::openFile( SystemFile & SF, | 91 | bool ANetNode::openFile( SystemFile & SF, |
92 | ANetNodeInstance * NNI ) { | 92 | ANetNodeInstance * NNI ) { |
93 | return (NNI ) ? NNI->openFile( SF ) : 0 ; | 93 | return (NNI ) ? NNI->openFile( SF ) : 0 ; |
94 | } | 94 | } |
95 | 95 | ||
96 | // | 96 | // |
97 | // | 97 | // |
98 | // ANETNODEINSTANCE | 98 | // ANETNODEINSTANCE |
99 | // | 99 | // |
100 | // | 100 | // |
101 | 101 | ||
102 | long ANetNodeInstance::InstanceCounter = -1; | 102 | long ANetNodeInstance::InstanceCounter = -1; |
103 | 103 | ||
104 | void ANetNodeInstance::initialize( void ) { | 104 | void ANetNodeInstance::initialize( void ) { |
105 | if( InstanceCounter == -1 ) | 105 | if( InstanceCounter == -1 ) |
106 | InstanceCounter = time(0); | 106 | InstanceCounter = time(0); |
107 | // set name | 107 | // set name |
108 | QString N; | 108 | QString N; |
109 | N.sprintf( "-%ld", InstanceCounter++ ); | 109 | N.sprintf( "-%ld", InstanceCounter++ ); |
110 | N.prepend( NodeType->name() ); | 110 | N.prepend( NodeType->name() ); |
111 | setName( N.latin1() ); | 111 | setName( N.latin1() ); |
112 | } | 112 | } |
113 | 113 | ||
114 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ | 114 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ |
115 | if( Attr == "__name" ) { | 115 | if( Attr == "__name" ) { |
116 | setName( Value.latin1() ); | 116 | setName( Value.latin1() ); |
117 | } else { | 117 | } else { |
118 | setSpecificAttribute( Attr, Value ); | 118 | setSpecificAttribute( Attr, Value ); |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { | 122 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { |
123 | TS << "__name=" << name() << endl; | 123 | TS << "__name=" << name() << endl; |
124 | saveSpecificAttribute( TS ); | 124 | saveSpecificAttribute( TS ); |
125 | } | 125 | } |
126 | 126 | ||
127 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { | 127 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { |
128 | return connection()->findNext( this ); | 128 | return connection()->findNext( this ); |
129 | } | 129 | } |
130 | 130 | ||
131 | // | 131 | // |
132 | // | 132 | // |
133 | // NODECOLLECTION | 133 | // NODECOLLECTION |
134 | // | 134 | // |
135 | // | 135 | // |
136 | 136 | ||
137 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { | 137 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { |
138 | IsModified = 0; | 138 | IsModified = 0; |
139 | Index = -1; | 139 | Index = -1; |
140 | Name=""; | 140 | Name=""; |
141 | IsNew = 1; | 141 | IsNew = 1; |
142 | CurrentState = Unchecked; | 142 | CurrentState = Unchecked; |
143 | AssignedInterface = 0; | 143 | AssignedInterface = 0; |
144 | Number = -1; | ||
145 | Done = 0; | ||
144 | } | 146 | } |
145 | 147 | ||
146 | NodeCollection::NodeCollection( QTextStream & TS ) : | 148 | NodeCollection::NodeCollection( QTextStream & TS, bool & Dangling ) : |
147 | QList<ANetNodeInstance>() { | 149 | QList<ANetNodeInstance>() { |
148 | long idx; | 150 | long idx; |
149 | bool InError = 0; | ||
150 | QString S, A, N; | 151 | QString S, A, N; |
152 | |||
153 | Number = -1; | ||
154 | Done = 0; | ||
151 | IsModified = 0; | 155 | IsModified = 0; |
152 | Index = -1; | 156 | Index = -1; |
153 | Name=""; | 157 | Name=""; |
154 | IsNew = 0; | 158 | IsNew = 0; |
155 | AssignedInterface = 0; | 159 | AssignedInterface = 0; |
156 | CurrentState = Unchecked; | 160 | CurrentState = Unchecked; |
157 | 161 | ||
162 | Dangling = 0; // by default node collection is ok | ||
163 | |||
158 | do { | 164 | do { |
159 | S = TS.readLine(); | 165 | S = TS.readLine(); |
160 | if( S.isEmpty() ) { | 166 | if( S.isEmpty() ) { |
161 | if( InError ) { | ||
162 | // remove all nodes | ||
163 | clear(); | ||
164 | } | ||
165 | // empty line | 167 | // empty line |
166 | break; | 168 | break; |
167 | } | 169 | } |
168 | 170 | ||
169 | idx = S.find('='); | 171 | idx = S.find('='); |
170 | S.stripWhiteSpace(); | 172 | S.stripWhiteSpace(); |
171 | A = S.left( idx ); | 173 | A = S.left( idx ); |
172 | A.lower(); | 174 | A.lower(); |
173 | N = S.mid( idx+1, S.length() ); | 175 | N = S.mid( idx+1, S.length() ); |
174 | N.stripWhiteSpace(); | 176 | N.stripWhiteSpace(); |
175 | N = deQuote( N ); | 177 | N = deQuote( N ); |
176 | 178 | ||
177 | if( A == "name" ) { | 179 | if( A == "name" ) { |
178 | Name = N; | 180 | Name = N; |
179 | } else if( A == "number" ) { | 181 | } else if( A == "number" ) { |
180 | setNumber( N.toLong() ); | 182 | setNumber( N.toLong() ); |
181 | } else if( A == "node" ) { | 183 | } else if( A == "node" ) { |
182 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); | 184 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); |
183 | Log(( "Find node %s : %p\n", N.latin1(), NNI )); | 185 | Log(( "Find node %s : %p\n", N.latin1(), NNI )); |
184 | if( NNI && ! InError ) { | 186 | if( NNI ) { |
185 | append( NNI ); | 187 | append( NNI ); |
186 | } else { | 188 | } else { |
187 | // could not find a node type -> collection invalid | 189 | // could not find a node type -> collection invalid |
188 | InError = 1; | 190 | Log(( "Node %s missing -> connection dangling\n", |
191 | N.latin1() )); | ||
192 | // create placeholder for this dangling NNI | ||
193 | NNI = new ErrorNNI( N ); | ||
194 | Dangling = 1; | ||
189 | } | 195 | } |
190 | } | 196 | } |
191 | } while( 1 ); | 197 | } while( 1 ); |
192 | 198 | ||
193 | Log(( "Profile number %s : %d nodes\n", | 199 | Log(( "Profile number %s : %d nodes\n", |
194 | Name.latin1(), count() )); | 200 | Name.latin1(), count() )); |
195 | } | 201 | } |
196 | 202 | ||
197 | |||
198 | NodeCollection::~NodeCollection( void ) { | 203 | NodeCollection::~NodeCollection( void ) { |
199 | } | 204 | } |
200 | 205 | ||
201 | const QString & NodeCollection::description( void ) { | 206 | const QString & NodeCollection::description( void ) { |
202 | ANetNodeInstance * NNI = getToplevel(); | 207 | ANetNodeInstance * NNI = getToplevel(); |
203 | return (NNI) ? NNI->runtime()->description() : Name; | 208 | return (NNI) ? NNI->runtime()->description() : Name; |
204 | } | 209 | } |
205 | 210 | ||
206 | void NodeCollection::append( ANetNodeInstance * NNI ) { | 211 | void NodeCollection::append( ANetNodeInstance * NNI ) { |
207 | NNI->setConnection( this ); | 212 | NNI->setConnection( this ); |
208 | QList<ANetNodeInstance>::append( NNI ); | 213 | QList<ANetNodeInstance>::append( NNI ); |
209 | } | 214 | } |
210 | 215 | ||
211 | void NodeCollection::save( QTextStream & TS ) { | 216 | void NodeCollection::save( QTextStream & TS ) { |
212 | 217 | ||
213 | TS << "name=" << quote( Name ) << endl; | 218 | TS << "name=" << quote( Name ) << endl; |
214 | TS << "number=" << number() << endl; | 219 | TS << "number=" << number() << endl; |
215 | ANetNodeInstance * NNI; | 220 | ANetNodeInstance * NNI; |
216 | for( QListIterator<ANetNodeInstance> it(*this); | 221 | for( QListIterator<ANetNodeInstance> it(*this); |
217 | it.current(); | 222 | it.current(); |
218 | ++it ) { | 223 | ++it ) { |
219 | NNI = it.current(); | 224 | NNI = it.current(); |
220 | TS << "node=" << NNI->name() << endl; | 225 | TS << "node=" << NNI->name() << endl; |
221 | } | 226 | } |
222 | TS << endl; | 227 | TS << endl; |
223 | IsNew = 0; | 228 | IsNew = 0; |
224 | } | 229 | } |
225 | 230 | ||
226 | ANetNodeInstance * NodeCollection::getToplevel( void ) { | 231 | ANetNodeInstance * NodeCollection::getToplevel( void ) { |
227 | ANetNodeInstance * NNI = 0; | 232 | ANetNodeInstance * NNI = 0; |
228 | for( QListIterator<ANetNodeInstance> it(*this); | 233 | for( QListIterator<ANetNodeInstance> it(*this); |
229 | it.current(); | 234 | it.current(); |
230 | ++it ) { | 235 | ++it ) { |
231 | NNI = it.current(); | 236 | NNI = it.current(); |
232 | if( NNI->nodeClass()->isToplevel() ) | 237 | if( NNI->nodeClass()->isToplevel() ) { |
233 | break; | 238 | return NNI; |
239 | } | ||
234 | } | 240 | } |
235 | return NNI; | 241 | return 0; |
236 | } | 242 | } |
237 | 243 | ||
238 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { | 244 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { |
239 | ANetNodeInstance * NNI = 0; | 245 | ANetNodeInstance * NNI = 0; |
240 | for( QListIterator<ANetNodeInstance> it(*this); | 246 | for( QListIterator<ANetNodeInstance> it(*this); |
241 | it.current(); | 247 | it.current(); |
242 | ++it ) { | 248 | ++it ) { |
243 | NNI = it.current(); | 249 | NNI = it.current(); |
244 | if( NNI->name() == S ) | 250 | if( NNI->name() == S ) { |
245 | break; | 251 | return NNI; |
252 | } | ||
246 | } | 253 | } |
247 | return NNI; | 254 | return 0; |
248 | } | 255 | } |
249 | 256 | ||
250 | ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { | 257 | ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { |
251 | ANetNodeInstance * NNNI; | 258 | ANetNodeInstance * NNNI; |
252 | 259 | ||
253 | if( ! NNI ) | 260 | if( ! NNI ) |
254 | getToplevel(); | 261 | getToplevel(); |
255 | 262 | ||
256 | for( QListIterator<ANetNodeInstance> it(*this); | 263 | for( QListIterator<ANetNodeInstance> it(*this); |
257 | it.current(); | 264 | it.current(); |
258 | ++it ) { | 265 | ++it ) { |
259 | NNNI = it.current(); | 266 | NNNI = it.current(); |
260 | if( NNNI == NNI ) { | 267 | if( NNNI == NNI ) { |
261 | ++it; | 268 | ++it; |
262 | return it.current(); | 269 | return it.current(); |
263 | } | 270 | } |
264 | } | 271 | } |
265 | return 0; // no more next | 272 | return 0; // no more next |
266 | } | 273 | } |
267 | 274 | ||
268 | int NodeCollection::compareItems( QCollection::Item I1, | 275 | int NodeCollection::compareItems( QCollection::Item I1, |
269 | QCollection::Item I2 ) { | 276 | QCollection::Item I2 ) { |
270 | ANetNodeInstance * NNI1, * NNI2; | 277 | ANetNodeInstance * NNI1, * NNI2; |
271 | NNI1 = (ANetNodeInstance *)I1; | 278 | NNI1 = (ANetNodeInstance *)I1; |
272 | NNI2 = (ANetNodeInstance *)I2; | 279 | NNI2 = (ANetNodeInstance *)I2; |
273 | return strcmp( NNI1->name(), NNI2->name() ); | 280 | return strcmp( NNI1->name(), NNI2->name() ); |
274 | } | 281 | } |
275 | 282 | ||
276 | static char * State2PixmapTbl[] = { | 283 | static char * State2PixmapTbl[] = { |
277 | "NULL", // Unchecked : no pixmap | 284 | "NULL", // Unchecked : no pixmap |
278 | "check", // Unknown | 285 | "check", // Unknown |
279 | "delete", // unavailable | 286 | "delete", // unavailable |
280 | "disabled", // disabled | 287 | "disabled", // disabled |
281 | "off", // off | 288 | "off", // off |
282 | "disconnected", // available | 289 | "disconnected", // available |
283 | "connected" // up | 290 | "connected" // up |
284 | }; | 291 | }; |
285 | 292 | ||
286 | QPixmap NodeCollection::devicePixmap( void ) { | 293 | QPixmap NodeCollection::devicePixmap( void ) { |
287 | QPixmap pm = NSResources->getPixmap( | 294 | QPixmap pm = NSResources->getPixmap( |
288 | getToplevel()->nextNode()->pixmapName()+"-large"); | 295 | getToplevel()->nextNode()->pixmapName()+"-large"); |
289 | 296 | ||
290 | QPixmap Mini = NSResources->getPixmap( | 297 | QPixmap Mini = NSResources->getPixmap( |
291 | device()->netNode()->pixmapName() ); | 298 | device()->netNode()->pixmapName() ); |
292 | 299 | ||
293 | if( pm.isNull() || Mini.isNull() ) | 300 | if( pm.isNull() || Mini.isNull() ) |
294 | return Resource::loadPixmap("Unknown"); | 301 | return Resource::loadPixmap("Unknown"); |
295 | 302 | ||
296 | QPainter painter( &pm ); | 303 | QPainter painter( &pm ); |
297 | painter.drawPixmap( pm.width()-Mini.width(), | 304 | painter.drawPixmap( pm.width()-Mini.width(), |
298 | pm.height()-Mini.height(), | 305 | pm.height()-Mini.height(), |
299 | Mini ); | 306 | Mini ); |
300 | pm.setMask( pm.createHeuristicMask( TRUE ) ); | 307 | pm.setMask( pm.createHeuristicMask( TRUE ) ); |
301 | return pm; | 308 | return pm; |
302 | } | 309 | } |
303 | 310 | ||
304 | QPixmap NodeCollection::statePixmap( State_t S) { | 311 | QPixmap NodeCollection::statePixmap( State_t S) { |
305 | return NSResources->getPixmap( State2PixmapTbl[S] ); | 312 | return NSResources->getPixmap( State2PixmapTbl[S] ); |
306 | } | 313 | } |
307 | 314 | ||
308 | QString NodeCollection::stateName( State_t S) { | 315 | QString NodeCollection::stateName( State_t S) { |
309 | switch( S ) { | 316 | switch( S ) { |
310 | case Unknown : | 317 | case Unknown : |
311 | return qApp->translate( "networksettings2", "Unknown"); | 318 | return qApp->translate( "networksettings2", "Unknown"); |
312 | case Unavailable : | 319 | case Unavailable : |
313 | return qApp->translate( "networksettings2", "Unavailable"); | 320 | return qApp->translate( "networksettings2", "Unavailable"); |
314 | case Disabled : | 321 | case Disabled : |
315 | return qApp->translate( "networksettings2", "Disabled"); | 322 | return qApp->translate( "networksettings2", "Disabled"); |
316 | case Off : | 323 | case Off : |
317 | return qApp->translate( "networksettings2", "Inactive"); | 324 | return qApp->translate( "networksettings2", "Inactive"); |
318 | case Available : | 325 | case Available : |
319 | return qApp->translate( "networksettings2", "Available"); | 326 | return qApp->translate( "networksettings2", "Available"); |
320 | case IsUp : | 327 | case IsUp : |
321 | return qApp->translate( "networksettings2", "Up"); | 328 | return qApp->translate( "networksettings2", "Up"); |
322 | case Unchecked : /* FT */ | 329 | case Unchecked : /* FT */ |
323 | default : | 330 | default : |
324 | break; | 331 | break; |
325 | } | 332 | } |
326 | return QString(""); | 333 | return QString(""); |
327 | } | 334 | } |
328 | 335 | ||
329 | void NodeCollection::reassign( void ) { | 336 | void NodeCollection::reassign( void ) { |
330 | for( QListIterator<ANetNodeInstance> it(*this); | 337 | for( QListIterator<ANetNodeInstance> it(*this); |
331 | it.current(); | 338 | it.current(); |
332 | ++it ) { | 339 | ++it ) { |
333 | it.current()->setConnection( this ); | 340 | it.current()->setConnection( this ); |
334 | } | 341 | } |
335 | } | 342 | } |
336 | 343 | ||
337 | const QStringList & NodeCollection::triggers() { | 344 | const QStringList & NodeCollection::triggers() { |
338 | return getToplevel()->runtime()->triggers(); | 345 | return getToplevel()->runtime()->triggers(); |
339 | } | 346 | } |
340 | 347 | ||
341 | bool NodeCollection::hasDataForFile( SystemFile & S ) { | 348 | bool NodeCollection::hasDataForFile( SystemFile & S ) { |
342 | return ( firstWithDataForFile( S ) != 0 ); | 349 | return ( firstWithDataForFile( S ) != 0 ); |
343 | } | 350 | } |
344 | 351 | ||
345 | ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) { | 352 | ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) { |
346 | for( QListIterator<ANetNodeInstance> it(*this); | 353 | for( QListIterator<ANetNodeInstance> it(*this); |
347 | it.current(); | 354 | it.current(); |
348 | ++it ) { | 355 | ++it ) { |
349 | if( it.current()->hasDataForFile( S ) ) { | 356 | if( it.current()->hasDataForFile( S ) ) { |
350 | return it.current(); | 357 | return it.current(); |
351 | } | 358 | } |
352 | } | 359 | } |
353 | return 0; | 360 | return 0; |
354 | } | 361 | } |
355 | 362 | ||
356 | State_t NodeCollection::state( bool Update ) { | 363 | State_t NodeCollection::state( bool Update ) { |
357 | State_t NodeState; | 364 | State_t NodeState; |
358 | 365 | ||
359 | if( CurrentState == Unchecked || Update ) { | 366 | if( CurrentState == Unchecked || Update ) { |
360 | // collect states of all nodes until with get the 'higest' | 367 | // collect states of all nodes until with get the 'higest' |
361 | // state possible | 368 | // state possible |
362 | 369 | ||
363 | Log(( "Connection %s state %s\n", | 370 | Log(( "Connection %s state %s\n", |
364 | Name.latin1(), StateName[CurrentState] )); | 371 | Name.latin1(), StateName[CurrentState] )); |
365 | 372 | ||
366 | CurrentState = Unknown; | 373 | CurrentState = Unknown; |
367 | for( QListIterator<ANetNodeInstance> it(*this); | 374 | for( QListIterator<ANetNodeInstance> it(*this); |
368 | it.current(); | 375 | it.current(); |
369 | ++it ) { | 376 | ++it ) { |
370 | Log(( "-> Detect %s\n", it.current()->name() )); | 377 | Log(( "-> Detect %s\n", it.current()->name() )); |
371 | NodeState = it.current()->runtime()->detectState(); | 378 | NodeState = it.current()->runtime()->detectState(); |
372 | Log(( " state %s\n", StateName[NodeState] )); | 379 | Log(( " state %s\n", StateName[NodeState] )); |
373 | 380 | ||
374 | if( NodeState == Disabled || | 381 | if( NodeState == Disabled || |
375 | NodeState == IsUp ) { | 382 | NodeState == IsUp ) { |
376 | // max | 383 | // max |
377 | CurrentState = NodeState; | 384 | CurrentState = NodeState; |
378 | break; | 385 | break; |
379 | } | 386 | } |
380 | 387 | ||
381 | if( NodeState > CurrentState ) { | 388 | if( NodeState > CurrentState ) { |
382 | // higher | 389 | // higher |
383 | CurrentState = NodeState; | 390 | CurrentState = NodeState; |
384 | } | 391 | } |
385 | } | 392 | } |
386 | } | 393 | } |
387 | 394 | ||
388 | return CurrentState; | 395 | return CurrentState; |
389 | } | 396 | } |
390 | 397 | ||
391 | QString NodeCollection::setState( Action_t A, bool Force ) { | 398 | QString NodeCollection::setState( Action_t A, bool Force ) { |
392 | 399 | ||
393 | QString msg; | 400 | QString msg; |
394 | Action_t Actions[10]; | 401 | Action_t Actions[10]; |
395 | int NoOfActions = 0; | 402 | int NoOfActions = 0; |
396 | 403 | ||
397 | // get current state | 404 | // get current state |
398 | state( Force ); | 405 | state( Force ); |
399 | 406 | ||
400 | switch( A ) { | 407 | switch( A ) { |
401 | case Disable : | 408 | case Disable : |
402 | if( CurrentState < Disabled ) { | 409 | if( CurrentState < Disabled ) { |
403 | // disabled | 410 | // disabled |
404 | CurrentState = Disabled; | 411 | CurrentState = Disabled; |
405 | return QString(); | 412 | return QString(); |
406 | } | 413 | } |
407 | 414 | ||
408 | if( CurrentState == IsUp ) { | 415 | if( CurrentState == IsUp ) { |
409 | Actions[NoOfActions++] = Down; | 416 | Actions[NoOfActions++] = Down; |
410 | Actions[NoOfActions++] = Deactivate; | 417 | Actions[NoOfActions++] = Deactivate; |
411 | } else if( CurrentState == Available ) { | 418 | } else if( CurrentState == Available ) { |
412 | Actions[NoOfActions++] = Deactivate; | 419 | Actions[NoOfActions++] = Deactivate; |
413 | } | 420 | } |
414 | Actions[NoOfActions++] = Disable; | 421 | Actions[NoOfActions++] = Disable; |
415 | break; | 422 | break; |
416 | case Enable : | 423 | case Enable : |
417 | // always possible -> detected state is new state | 424 | // always possible -> detected state is new state |
418 | Actions[NoOfActions++] = Enable; | 425 | Actions[NoOfActions++] = Enable; |
419 | break; | 426 | break; |
420 | case Activate : | 427 | case Activate : |
421 | if( ! Force ) { | 428 | if( ! Force ) { |
422 | if( CurrentState >= Available ) { | 429 | if( CurrentState >= Available ) { |
423 | // already available | 430 | // already available |
424 | return QString(); | 431 | return QString(); |
425 | } | 432 | } |
426 | 433 | ||
427 | if( CurrentState != Off ) { | 434 | if( CurrentState != Off ) { |
428 | return qApp->translate( "System", | 435 | return qApp->translate( "System", |
429 | "State should be off" ); | 436 | "State should be off" ); |
430 | } | 437 | } |
431 | } | 438 | } |
432 | 439 | ||
433 | Actions[NoOfActions++] = Activate; | 440 | Actions[NoOfActions++] = Activate; |
434 | break; | 441 | break; |
435 | case Deactivate : | 442 | case Deactivate : |
436 | if( ! Force ) { | 443 | if( ! Force ) { |
437 | if( CurrentState < Off ) { | 444 | if( CurrentState < Off ) { |
438 | // already inactive | 445 | // already inactive |
439 | return QString(); | 446 | return QString(); |
440 | } | 447 | } |
441 | } | 448 | } |
442 | 449 | ||
443 | if( CurrentState == IsUp ) { | 450 | if( CurrentState == IsUp ) { |
444 | Actions[NoOfActions++] = Down; | 451 | Actions[NoOfActions++] = Down; |
445 | } | 452 | } |
446 | Actions[NoOfActions++] = Deactivate; | 453 | Actions[NoOfActions++] = Deactivate; |
447 | break; | 454 | break; |
448 | case Up : | 455 | case Up : |
449 | if( ! Force ) { | 456 | if( ! Force ) { |
450 | if( CurrentState == IsUp ) { | 457 | if( CurrentState == IsUp ) { |
451 | return QString(); | 458 | return QString(); |
452 | } | 459 | } |
453 | if( CurrentState < Off ) { | 460 | if( CurrentState < Off ) { |
454 | return qApp->translate( "System", | 461 | return qApp->translate( "System", |
455 | "State should at least be off" ); | 462 | "State should at least be off" ); |
456 | } | 463 | } |
457 | } | 464 | } |
458 | if( CurrentState == Off ) { | 465 | if( CurrentState == Off ) { |
459 | Actions[NoOfActions++] = Activate; | 466 | Actions[NoOfActions++] = Activate; |
460 | } | 467 | } |
461 | Actions[NoOfActions++] = Up; | 468 | Actions[NoOfActions++] = Up; |
462 | break; | 469 | break; |
463 | case Down : | 470 | case Down : |
464 | if( ! Force ) { | 471 | if( ! Force ) { |
465 | if( CurrentState < Available ) { | 472 | if( CurrentState < Available ) { |
466 | // OK | 473 | // OK |
467 | return QString(); | 474 | return QString(); |
468 | } | 475 | } |
469 | } | 476 | } |
470 | Actions[NoOfActions++] = Down; | 477 | Actions[NoOfActions++] = Down; |
471 | break; | 478 | break; |
472 | } | 479 | } |
473 | 480 | ||
474 | // send actions to all nodes | 481 | // send actions to all nodes |
475 | Log(( "Action %s requires %d steps\n", | 482 | Log(( "Action %s requires %d steps\n", |
476 | ActionName[A], NoOfActions )); | 483 | ActionName[A], NoOfActions )); |
477 | 484 | ||
478 | for( int i = 0 ; i < NoOfActions; i ++ ) { | 485 | for( int i = 0 ; i < NoOfActions; i ++ ) { |
479 | // setState recurses through the tree depth first | 486 | // setState recurses through the tree depth first |
480 | msg = getToplevel()->runtime()->setState( this, Actions[i], Force ); | 487 | msg = getToplevel()->runtime()->setState( this, Actions[i], Force ); |
481 | if( ! msg.isEmpty() ) { | 488 | if( ! msg.isEmpty() ) { |
482 | return msg; | 489 | return msg; |
483 | } | 490 | } |
484 | } | 491 | } |
485 | return QString(); | 492 | return QString(); |
486 | } | 493 | } |
487 | 494 | ||
488 | // | 495 | // |
489 | // | 496 | // |
490 | // RuntimeInfo | 497 | // RuntimeInfo |
491 | // | 498 | // |
492 | // | 499 | // |
493 | 500 | ||
494 | QString RuntimeInfo::setState( NodeCollection * NC, | 501 | QString RuntimeInfo::setState( NodeCollection * NC, |
495 | Action_t A, | 502 | Action_t A, |
496 | bool Force ) { | 503 | bool Force ) { |
497 | QString M; | 504 | QString M; |
498 | RuntimeInfo * Deeper = nextNode(); | 505 | RuntimeInfo * Deeper = nextNode(); |
499 | 506 | ||
500 | if( Deeper ) { | 507 | if( Deeper ) { |
501 | // first go deeper | 508 | // first go deeper |
502 | M = Deeper->setState( NC, A, Force ); | 509 | M = Deeper->setState( NC, A, Force ); |
503 | if( ! M.isEmpty() ) | 510 | if( ! M.isEmpty() ) |
504 | return M; | 511 | return M; |
505 | } | 512 | } |
506 | 513 | ||
507 | // set my own state | 514 | // set my own state |
508 | Log (( "-> Act upon %s\n", netNode()->name() )); | 515 | Log (( "-> Act upon %s\n", netNode()->name() )); |
509 | M = setMyState( NC, A, Force ); | 516 | M = setMyState( NC, A, Force ); |
510 | Log (( " result %s\n", M.latin1() )); | 517 | Log (( " result %s\n", M.latin1() )); |
511 | return M; | 518 | return M; |
512 | } | 519 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 4626381..151d546 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h | |||
@@ -1,596 +1,638 @@ | |||
1 | #ifndef NETNODE_H | 1 | #ifndef NETNODE_H |
2 | #define NETNODE_H | 2 | #define NETNODE_H |
3 | 3 | ||
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | #include <qlist.h> | 5 | #include <qlist.h> |
6 | #include <qdict.h> | 6 | #include <qdict.h> |
7 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
8 | #include <qstringlist.h> | 8 | #include <qstringlist.h> |
9 | #include <qobject.h> | 9 | #include <qobject.h> |
10 | #include <time.h> | 10 | #include <time.h> |
11 | 11 | ||
12 | #include <Utils.h> | 12 | #include <Utils.h> |
13 | #include <system.h> | 13 | #include <system.h> |
14 | 14 | ||
15 | // difference feature interfaces | 15 | // difference feature interfaces |
16 | class AsDevice; | 16 | class AsDevice; |
17 | class AsLine; | 17 | class AsLine; |
18 | class AsConnection; | 18 | class AsConnection; |
19 | class AsFullSetup; | 19 | class AsFullSetup; |
20 | 20 | ||
21 | // needed for plugin creation function | 21 | // needed for plugin creation function |
22 | #include <qlist.h> | 22 | #include <qlist.h> |
23 | 23 | ||
24 | class ANetNode; | 24 | class ANetNode; |
25 | class ANetNodeInstance; | 25 | class ANetNodeInstance; |
26 | class NodeCollection; | 26 | class NodeCollection; |
27 | class QTextStream; | 27 | class QTextStream; |
28 | class RuntimeInfo; | 28 | class RuntimeInfo; |
29 | class InterfaceInfo; | 29 | class InterfaceInfo; |
30 | class NSResources; | 30 | class NSResources; |
31 | 31 | ||
32 | extern QString & deQuote( QString & X ); | 32 | extern QString & deQuote( QString & X ); |
33 | extern QString quote( QString X ); | 33 | extern QString quote( QString X ); |
34 | 34 | ||
35 | #include "systemfile.h" | 35 | #include "systemfile.h" |
36 | 36 | ||
37 | typedef enum State { | 37 | typedef enum State { |
38 | // if we have not yet detected the state of the device | 38 | // if we have not yet detected the state of the device |
39 | Unchecked = 0, | 39 | Unchecked = 0, |
40 | // if we cannot determine the state | 40 | // if we cannot determine the state |
41 | Unknown = 1, | 41 | Unknown = 1, |
42 | // if connection cannot be established e.g. because | 42 | // if connection cannot be established e.g. because |
43 | // the hardware is not available | 43 | // the hardware is not available |
44 | Unavailable = 2, | 44 | Unavailable = 2, |
45 | // if the connection cannot be establishec but NOT | 45 | // if the connection cannot be establishec but NOT |
46 | // because it is physically impossible but because | 46 | // because it is physically impossible but because |
47 | // it has been disabled for FUNCTIONAL reasons | 47 | // it has been disabled for FUNCTIONAL reasons |
48 | Disabled = 3, | 48 | Disabled = 3, |
49 | // if connection is available to is currently down | 49 | // if connection is available to is currently down |
50 | // i.e. the corresponding hardware is not activated | 50 | // i.e. the corresponding hardware is not activated |
51 | Off = 4, | 51 | Off = 4, |
52 | // if connection is available to be used (i.e. the | 52 | // if connection is available to be used (i.e. the |
53 | // devices if fully ready to be used | 53 | // devices if fully ready to be used |
54 | Available = 5, | 54 | Available = 5, |
55 | // if connection is being used | 55 | // if connection is being used |
56 | IsUp = 6 | 56 | IsUp = 6 |
57 | } State_t; | 57 | } State_t; |
58 | 58 | ||
59 | typedef enum Action { | 59 | typedef enum Action { |
60 | // to make the device unavailable functionally -> to disabled | 60 | // to make the device unavailable functionally -> to disabled |
61 | Disable = 0, | 61 | Disable = 0, |
62 | // to make the device available functionally -> to off | 62 | // to make the device available functionally -> to off |
63 | Enable = 1, | 63 | Enable = 1, |
64 | // bring the hardware up -> to Available | 64 | // bring the hardware up -> to Available |
65 | Activate = 2, | 65 | Activate = 2, |
66 | // bring the hardware down -> to off | 66 | // bring the hardware down -> to off |
67 | Deactivate = 3, | 67 | Deactivate = 3, |
68 | // bring the connection up -> to IsUp | 68 | // bring the connection up -> to IsUp |
69 | Up = 4, | 69 | Up = 4, |
70 | // bring the connection down -> to Available | 70 | // bring the connection down -> to Available |
71 | Down = 5 | 71 | Down = 5 |
72 | } Action_t; | 72 | } Action_t; |
73 | 73 | ||
74 | class ANetNode : public QObject { | 74 | class ANetNode : public QObject { |
75 | 75 | ||
76 | public: | 76 | public: |
77 | 77 | ||
78 | typedef QArray<ANetNode *> NetNodeList; | 78 | typedef QArray<ANetNode *> NetNodeList; |
79 | 79 | ||
80 | ANetNode( const char * Name ) : QObject( 0, Name ) {} | 80 | ANetNode( const char * Name ) : QObject( 0, Name ) {} |
81 | virtual ~ANetNode(){}; | 81 | virtual ~ANetNode(){}; |
82 | 82 | ||
83 | // | 83 | // |
84 | // | 84 | // |
85 | // standard methods with sensible default | 85 | // standard methods with sensible default |
86 | // | 86 | // |
87 | // | 87 | // |
88 | 88 | ||
89 | inline int done( void ) | 89 | inline int done( void ) |
90 | { return Done; } | 90 | { return Done; } |
91 | inline void setDone( int D ) | 91 | inline void setDone( int D ) |
92 | { Done = D; } | 92 | { Done = D; } |
93 | 93 | ||
94 | // does this Node provide a Connection | 94 | // does this Node provide a Connection |
95 | bool isToplevel( void ); | 95 | bool isToplevel( void ); |
96 | 96 | ||
97 | // set the value of an attribute | 97 | // set the value of an attribute |
98 | void setAttribute( QString & Attr, QString & Value ) ; | 98 | void setAttribute( QString & Attr, QString & Value ) ; |
99 | void saveAttributes( QTextStream & TS ) ; | 99 | void saveAttributes( QTextStream & TS ) ; |
100 | 100 | ||
101 | // compiled references to 'needed' NetNodes -> needs list | 101 | // compiled references to 'needed' NetNodes -> needs list |
102 | inline void setAlternatives( NetNodeList * Alt ) | 102 | inline void setAlternatives( NetNodeList * Alt ) |
103 | { Alternatives = Alt; } | 103 | { Alternatives = Alt; } |
104 | inline NetNodeList & alternatives( void ) | 104 | inline NetNodeList & alternatives( void ) |
105 | { return *Alternatives; } | 105 | { return *Alternatives; } |
106 | 106 | ||
107 | // | 107 | // |
108 | // | 108 | // |
109 | // Virtual methods with sensible default | 109 | // Virtual methods with sensible default |
110 | // | 110 | // |
111 | // | 111 | // |
112 | 112 | ||
113 | // do instances of this noce class have data for this file | 113 | // do instances of this noce class have data for this file |
114 | virtual bool hasDataForFile( SystemFile & ) | 114 | virtual bool hasDataForFile( SystemFile & ) |
115 | { return 0; } | 115 | { return 0; } |
116 | 116 | ||
117 | // open proper file SF identified by S | 117 | // open proper file SF identified by S |
118 | // this method is called by NS2. | 118 | // this method is called by NS2. |
119 | // | 119 | // |
120 | // overrule this ONLY if this proper file is a common file | 120 | // overrule this ONLY if this proper file is a common file |
121 | // for all NNI of this node class and the data generated | 121 | // for all NNI of this node class and the data generated |
122 | // by each of the NNI needs to be put in one file | 122 | // by each of the NNI needs to be put in one file |
123 | // | 123 | // |
124 | // if this is the case the file should be (re)opened in append | 124 | // if this is the case the file should be (re)opened in append |
125 | // return 0 if file cannot be opened | 125 | // return 0 if file cannot be opened |
126 | virtual bool openFile( SystemFile &SF, | 126 | virtual bool openFile( SystemFile &SF, |
127 | ANetNodeInstance * NNI ); | 127 | ANetNodeInstance * NNI ); |
128 | 128 | ||
129 | // generate instance independent stuff | 129 | // generate instance independent stuff |
130 | // 0 : data output, 1 no data, 2 error | 130 | // 0 : data output, 1 no data, 2 error |
131 | virtual short generatePreamble( SystemFile & ) | 131 | virtual short generatePreamble( SystemFile & ) |
132 | { return 1; } | 132 | { return 1; } |
133 | 133 | ||
134 | // generate instance independent stuff | 134 | // generate instance independent stuff |
135 | // 0 : data output, 1 no data, 2 error | 135 | // 0 : data output, 1 no data, 2 error |
136 | virtual short generatePostamble( SystemFile & ) | 136 | virtual short generatePostamble( SystemFile & ) |
137 | { return 1; } | 137 | { return 1; } |
138 | 138 | ||
139 | // generate instance dependent but instance common stuff | 139 | // generate instance dependent but instance common stuff |
140 | // 0 : data output, 1 no data, 2 error | 140 | // 0 : data output, 1 no data, 2 error |
141 | virtual short generateFile( SystemFile &, | 141 | virtual short generateFile( SystemFile &, |
142 | ANetNodeInstance * , | 142 | ANetNodeInstance * , |
143 | long ) | 143 | long ) |
144 | { return 1; } | 144 | { return 1; } |
145 | 145 | ||
146 | // generate NIC name based on instance nr | 146 | // generate NIC name based on instance nr |
147 | // only relevant if node instances are devices | 147 | // only relevant if node instances are devices |
148 | virtual QString genNic( long ) | 148 | virtual QString genNic( long ) |
149 | { return QString(""); } | 149 | { return QString(""); } |
150 | 150 | ||
151 | // max number of instances for this node type | 151 | // max number of instances for this node type |
152 | // only relevant if node instances are devices | 152 | // only relevant if node instances are devices |
153 | virtual long instanceCount( void ) | 153 | virtual long instanceCount( void ) |
154 | { return 1; } | 154 | { return 1; } |
155 | 155 | ||
156 | // return ID list for each file generated specially for | 156 | // return ID list for each file generated specially for |
157 | // this node type | 157 | // this node type |
158 | virtual QStringList properFiles( void ) | 158 | virtual QStringList properFiles( void ) |
159 | { return QStringList(); } | 159 | { return QStringList(); } |
160 | 160 | ||
161 | // | 161 | // |
162 | // | 162 | // |
163 | // pure virtual methods with sensible default | 163 | // pure virtual methods with sensible default |
164 | // | 164 | // |
165 | // | 165 | // |
166 | 166 | ||
167 | // pixmap needed for this NetNode | 167 | // pixmap needed for this NetNode |
168 | virtual const QString pixmapName() = 0; | 168 | virtual const QString pixmapName() = 0; |
169 | 169 | ||
170 | // description for this NetNode | 170 | // description for this NetNode |
171 | virtual const QString nodeDescription() = 0; | 171 | virtual const QString nodeDescription() = 0; |
172 | 172 | ||
173 | // create a blank instance of a net node | 173 | // create a blank instance of a net node |
174 | virtual ANetNodeInstance * createInstance( void ) = 0; | 174 | virtual ANetNodeInstance * createInstance( void ) = 0; |
175 | 175 | ||
176 | // return features this NetNode provides | 176 | // return features this NetNode provides |
177 | virtual const char ** provides( void ) = 0; | 177 | virtual const char ** provides( void ) = 0; |
178 | 178 | ||
179 | // return features this NetNode needs | 179 | // return features this NetNode needs |
180 | virtual const char ** needs( void ) = 0; | 180 | virtual const char ** needs( void ) = 0; |
181 | 181 | ||
182 | protected : | 182 | protected : |
183 | 183 | ||
184 | NetNodeList * Alternatives; | 184 | NetNodeList * Alternatives; |
185 | 185 | ||
186 | private : | 186 | private : |
187 | 187 | ||
188 | virtual void setSpecificAttribute( QString & , QString & ) = 0; | 188 | virtual void setSpecificAttribute( QString & , QString & ) = 0; |
189 | virtual void saveSpecificAttribute( QTextStream & ) = 0; | 189 | virtual void saveSpecificAttribute( QTextStream & ) = 0; |
190 | int Done; | 190 | int Done; |
191 | 191 | ||
192 | }; | 192 | }; |
193 | 193 | ||
194 | class ANetNodeInstance : public QObject { | 194 | class ANetNodeInstance : public QObject { |
195 | 195 | ||
196 | public: | 196 | public: |
197 | 197 | ||
198 | ANetNodeInstance( ANetNode * NN ) : QObject() | 198 | ANetNodeInstance( ANetNode * NN ) : QObject() |
199 | { IsModified=0; NodeType = NN; IsNew = TRUE; } | 199 | { IsModified=0; NodeType = NN; IsNew = TRUE; } |
200 | virtual ~ANetNodeInstance( void ) { } | 200 | virtual ~ANetNodeInstance( void ) { } |
201 | 201 | ||
202 | inline int done( void ) | 202 | inline int done( void ) |
203 | { return Done; } | 203 | { return Done; } |
204 | inline void setDone( int D ) | 204 | inline void setDone( int D ) |
205 | { Done = D; } | 205 | { Done = D; } |
206 | 206 | ||
207 | // return data was modified | 207 | // return data was modified |
208 | inline void setModified( bool M ) | 208 | inline void setModified( bool M ) |
209 | { IsModified = M; } | 209 | { IsModified = M; } |
210 | inline bool isModified( void ) | 210 | inline bool isModified( void ) |
211 | { return IsModified; } | 211 | { return IsModified; } |
212 | 212 | ||
213 | // get next node | 213 | // get next node |
214 | ANetNodeInstance * nextNode(); | 214 | ANetNodeInstance * nextNode(); |
215 | // return NetNode this is an instance of | 215 | // return NetNode this is an instance of |
216 | ANetNode * nodeClass( void ) | 216 | ANetNode * nodeClass( void ) |
217 | { return NodeType; } | 217 | { return NodeType; } |
218 | 218 | ||
219 | // intialize am instance of a net node | 219 | // intialize am instance of a net node |
220 | void initialize( void ); | 220 | void initialize( void ); |
221 | 221 | ||
222 | // set the value of an attribute | 222 | // set the value of an attribute |
223 | void setAttribute( QString & Attr, QString & Value ) ; | 223 | void setAttribute( QString & Attr, QString & Value ) ; |
224 | void saveAttributes( QTextStream & TS ) ; | 224 | void saveAttributes( QTextStream & TS ) ; |
225 | 225 | ||
226 | // return true if node isntance is NEW and not loaded | 226 | // return true if node isntance is NEW and not loaded |
227 | inline void setNew( bool IsN ) | 227 | inline void setNew( bool IsN ) |
228 | { IsNew = IsN; } | 228 | { IsNew = IsN; } |
229 | inline bool isNew( void ) | 229 | inline bool isNew( void ) |
230 | { return IsNew; } | 230 | { return IsNew; } |
231 | 231 | ||
232 | // return description for this instance | 232 | // return description for this instance |
233 | inline QString & description( void ) | 233 | inline QString & description( void ) |
234 | { return Description; } | 234 | { return Description; } |
235 | inline void setDescription( const QString & S ) | 235 | inline void setDescription( const QString & S ) |
236 | { Description = S; } | 236 | { Description = S; } |
237 | 237 | ||
238 | // pixmap for this instance -> from NetNode | 238 | // pixmap for this instance -> from NetNode |
239 | inline const QString pixmapName( void ) | 239 | inline const QString pixmapName( void ) |
240 | { return NodeType->pixmapName(); } | 240 | { return NodeType->pixmapName(); } |
241 | 241 | ||
242 | inline const char ** provides( void ) | 242 | inline const char ** provides( void ) |
243 | { return NodeType->provides(); } | 243 | { return NodeType->provides(); } |
244 | 244 | ||
245 | inline const char ** needs( void ) | 245 | inline const char ** needs( void ) |
246 | { return NodeType->needs(); } | 246 | { return NodeType->needs(); } |
247 | 247 | ||
248 | inline void setConnection( NodeCollection * NC ) | 248 | inline void setConnection( NodeCollection * NC ) |
249 | { Connection = NC; } | 249 | { Connection = NC; } |
250 | inline NodeCollection * connection( void ) | 250 | inline NodeCollection * connection( void ) |
251 | { return Connection; } | 251 | { return Connection; } |
252 | 252 | ||
253 | // | 253 | // |
254 | // | 254 | // |
255 | // Virtual methods with sensible defaults | 255 | // Virtual methods with sensible defaults |
256 | // | 256 | // |
257 | // | 257 | // |
258 | 258 | ||
259 | 259 | ||
260 | 260 | ||
261 | // open proper file identified by S | 261 | // open proper file identified by S |
262 | virtual bool openFile( SystemFile & ) | 262 | virtual bool openFile( SystemFile & ) |
263 | { return 0; } | 263 | { return 0; } |
264 | 264 | ||
265 | // check if this node (or sub nodes) have data for this file | 265 | // check if this node (or sub nodes) have data for this file |
266 | virtual bool hasDataForFile( SystemFile & S ) | 266 | virtual bool hasDataForFile( SystemFile & S ) |
267 | { return nodeClass()->hasDataForFile( S ); } | 267 | { return nodeClass()->hasDataForFile( S ); } |
268 | 268 | ||
269 | // generate code specific for this node but embedded | 269 | // generate code specific for this node but embedded |
270 | // in the section of the parent | 270 | // in the section of the parent |
271 | // this is called within the code of the parent | 271 | // this is called within the code of the parent |
272 | virtual short generateFileEmbedded( SystemFile & SF, | 272 | virtual short generateFileEmbedded( SystemFile & SF, |
273 | long DevNr ) | 273 | long DevNr ) |
274 | { ANetNodeInstance * NNI = nextNode(); | 274 | { ANetNodeInstance * NNI = nextNode(); |
275 | return (NNI) ? NNI->generateFileEmbedded( SF, DevNr ) : 1; | 275 | return (NNI) ? NNI->generateFileEmbedded( SF, DevNr ) : 1; |
276 | } | 276 | } |
277 | 277 | ||
278 | // generate code specific for this node | 278 | // generate code specific for this node |
279 | // (or find the first node that does) | 279 | // (or find the first node that does) |
280 | virtual short generateFile( SystemFile & SF, | 280 | virtual short generateFile( SystemFile & SF, |
281 | long DevNr ) | 281 | long DevNr ) |
282 | { ANetNodeInstance * NNI = nextNode(); | 282 | { ANetNodeInstance * NNI = nextNode(); |
283 | return (NNI) ? NNI->generateFile( SF, DevNr ) : 1; | 283 | return (NNI) ? NNI->generateFile( SF, DevNr ) : 1; |
284 | } | 284 | } |
285 | 285 | ||
286 | // return true if this node instance is triggered by this trigger | 286 | // return true if this node instance is triggered by this trigger |
287 | // could be delegated to deeper instances | 287 | // could be delegated to deeper instances |
288 | virtual bool triggeredBy( const QString & ) | 288 | virtual bool triggeredBy( const QString & ) |
289 | { return 0; } | 289 | { return 0; } |
290 | 290 | ||
291 | // | 291 | // |
292 | // | 292 | // |
293 | // Pure virtual functions | 293 | // Pure virtual functions |
294 | // | 294 | // |
295 | // | 295 | // |
296 | 296 | ||
297 | // return runtime information for this node | 297 | // return runtime information for this node |
298 | virtual RuntimeInfo * runtime( void ) = 0; | 298 | virtual RuntimeInfo * runtime( void ) = 0; |
299 | 299 | ||
300 | // create edit widget under parent | 300 | // create edit widget under parent |
301 | virtual QWidget * edit( QWidget * parent ) = 0; | 301 | virtual QWidget * edit( QWidget * parent ) = 0; |
302 | 302 | ||
303 | // is given data acceptable | 303 | // is given data acceptable |
304 | virtual QString acceptable( void ) = 0; | 304 | virtual QString acceptable( void ) = 0; |
305 | 305 | ||
306 | // get data from GUI and store in node | 306 | // get data from GUI and store in node |
307 | virtual void commit( void ) = 0; | 307 | virtual void commit( void ) = 0; |
308 | 308 | ||
309 | // returns node specific data -> only useful for 'buddy' | 309 | // returns node specific data -> only useful for 'buddy' |
310 | virtual void * data( void ) = 0; | 310 | virtual void * data( void ) = 0; |
311 | 311 | ||
312 | protected : | 312 | protected : |
313 | 313 | ||
314 | virtual void setSpecificAttribute( QString & , QString & ) = 0; | 314 | virtual void setSpecificAttribute( QString & , QString & ) = 0; |
315 | virtual void saveSpecificAttribute( QTextStream & ) = 0; | 315 | virtual void saveSpecificAttribute( QTextStream & ) = 0; |
316 | 316 | ||
317 | ANetNode * NodeType; | 317 | ANetNode * NodeType; |
318 | // connection to which this node belongs to | 318 | // connection to which this node belongs to |
319 | NodeCollection * Connection; | 319 | NodeCollection * Connection; |
320 | QString Description; | 320 | QString Description; |
321 | bool IsModified; | 321 | bool IsModified; |
322 | // true if this nodeinstance was just created (and not | ||
323 | // loaded from file | ||
322 | bool IsNew; | 324 | bool IsNew; |
323 | int Done; | 325 | int Done; |
324 | 326 | ||
325 | static long InstanceCounter; | 327 | static long InstanceCounter; |
326 | }; | 328 | }; |
327 | 329 | ||
330 | class ErrorNNI: public ANetNodeInstance { | ||
331 | |||
332 | public: | ||
333 | |||
334 | ErrorNNI( const QString & _Name ) : ANetNodeInstance( 0 ) { | ||
335 | setName( _Name.latin1() ); | ||
336 | } | ||
337 | |||
338 | RuntimeInfo * runtime( void ) { | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | // create edit widget under parent | ||
343 | QWidget * edit( QWidget * parent ) { | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | // is given data acceptable | ||
348 | QString acceptable( void ) { | ||
349 | return QString(); | ||
350 | } | ||
351 | |||
352 | // get data from GUI and store in node | ||
353 | void commit( void ) { | ||
354 | } | ||
355 | |||
356 | // returns node specific data -> only useful for 'buddy' | ||
357 | void * data( void ) { | ||
358 | return 0; | ||
359 | } | ||
360 | |||
361 | protected : | ||
362 | |||
363 | void setSpecificAttribute( QString & , QString & ) { | ||
364 | } | ||
365 | |||
366 | void saveSpecificAttribute( QTextStream & ) { | ||
367 | } | ||
368 | }; | ||
369 | |||
328 | class RuntimeInfo : public QObject { | 370 | class RuntimeInfo : public QObject { |
329 | 371 | ||
330 | Q_OBJECT | 372 | Q_OBJECT |
331 | 373 | ||
332 | public : | 374 | public : |
333 | 375 | ||
334 | RuntimeInfo( ANetNodeInstance * TheNNI ) | 376 | RuntimeInfo( ANetNodeInstance * TheNNI ) |
335 | { NNI = TheNNI; } | 377 | { NNI = TheNNI; } |
336 | 378 | ||
337 | // | 379 | // |
338 | // | 380 | // |
339 | // methods to be overloaded by connection capable | 381 | // methods to be overloaded by connection capable |
340 | // runtimes | 382 | // runtimes |
341 | // | 383 | // |
342 | // | 384 | // |
343 | 385 | ||
344 | 386 | ||
345 | // | 387 | // |
346 | // | 388 | // |
347 | // methods to be overloaded by device capable | 389 | // methods to be overloaded by device capable |
348 | // runtimes | 390 | // runtimes |
349 | // | 391 | // |
350 | // | 392 | // |
351 | 393 | ||
352 | // does this node handles this interface e.g.eth0 | 394 | // does this node handles this interface e.g.eth0 |
353 | // recurse deeper if this node cannot answer that question | 395 | // recurse deeper if this node cannot answer that question |
354 | virtual bool handlesInterface( const QString & S ) { | 396 | virtual bool handlesInterface( const QString & S ) { |
355 | RuntimeInfo * RI = device(); | 397 | RuntimeInfo * RI = device(); |
356 | if( RI ) { | 398 | if( RI ) { |
357 | return RI->handlesInterface( S ); | 399 | return RI->handlesInterface( S ); |
358 | } | 400 | } |
359 | return 0; | 401 | return 0; |
360 | } | 402 | } |
361 | bool handlesInterface( const InterfaceInfo & I ) { | 403 | bool handlesInterface( const InterfaceInfo & I ) { |
362 | RuntimeInfo * RI = device(); | 404 | RuntimeInfo * RI = device(); |
363 | if( RI ) { | 405 | if( RI ) { |
364 | return RI->handlesInterface( I ); | 406 | return RI->handlesInterface( I ); |
365 | } | 407 | } |
366 | return 0; | 408 | return 0; |
367 | } | 409 | } |
368 | 410 | ||
369 | // | 411 | // |
370 | // | 412 | // |
371 | // methods to be overloaded by full setup capable | 413 | // methods to be overloaded by full setup capable |
372 | // runtimes | 414 | // runtimes |
373 | // | 415 | // |
374 | // | 416 | // |
375 | 417 | ||
376 | // return description for this full setup | 418 | // return description for this full setup |
377 | virtual const QString & description( void ) { | 419 | virtual const QString & description( void ) { |
378 | return fullSetup()->description( ); | 420 | return fullSetup()->description( ); |
379 | } | 421 | } |
380 | // return triggers that should fire when this | 422 | // return triggers that should fire when this |
381 | // setup is brought up | 423 | // setup is brought up |
382 | virtual const QStringList & triggers( void ) { | 424 | virtual const QStringList & triggers( void ) { |
383 | return fullSetup()->triggers( ); | 425 | return fullSetup()->triggers( ); |
384 | } | 426 | } |
385 | 427 | ||
386 | // | 428 | // |
387 | // | 429 | // |
388 | // methods to be overloaded by line capable | 430 | // methods to be overloaded by line capable |
389 | // runtimes | 431 | // runtimes |
390 | // | 432 | // |
391 | // | 433 | // |
392 | 434 | ||
393 | // return the device file ('/dev/xxx') created | 435 | // return the device file ('/dev/xxx') created |
394 | // by this line capable runtime | 436 | // by this line capable runtime |
395 | virtual QString deviceFile( void ) { | 437 | virtual QString deviceFile( void ) { |
396 | RuntimeInfo * RI = line(); | 438 | RuntimeInfo * RI = line(); |
397 | if( RI ) { | 439 | if( RI ) { |
398 | return RI->deviceFile(); | 440 | return RI->deviceFile(); |
399 | } | 441 | } |
400 | return QString(); | 442 | return QString(); |
401 | } | 443 | } |
402 | 444 | ||
403 | // | 445 | // |
404 | // | 446 | // |
405 | // runtime interface | 447 | // runtime interface |
406 | // | 448 | // |
407 | // | 449 | // |
408 | 450 | ||
409 | // return the node that offers device capability | 451 | // return the node that offers device capability |
410 | virtual RuntimeInfo * device( void ) | 452 | virtual RuntimeInfo * device( void ) |
411 | { RuntimeInfo * RI = nextNode(); | 453 | { RuntimeInfo * RI = nextNode(); |
412 | return (RI) ? RI->device() : 0; | 454 | return (RI) ? RI->device() : 0; |
413 | } | 455 | } |
414 | 456 | ||
415 | // return the node that offers connection capability | 457 | // return the node that offers connection capability |
416 | virtual RuntimeInfo * connection( void ) | 458 | virtual RuntimeInfo * connection( void ) |
417 | { RuntimeInfo * RI = nextNode(); | 459 | { RuntimeInfo * RI = nextNode(); |
418 | return (RI) ? RI->connection() : 0; | 460 | return (RI) ? RI->connection() : 0; |
419 | } | 461 | } |
420 | 462 | ||
421 | // return the node that offers line capability | 463 | // return the node that offers line capability |
422 | virtual RuntimeInfo * line( void ) | 464 | virtual RuntimeInfo * line( void ) |
423 | { RuntimeInfo * RI = nextNode(); | 465 | { RuntimeInfo * RI = nextNode(); |
424 | return (RI) ? RI->line() : 0; | 466 | return (RI) ? RI->line() : 0; |
425 | } | 467 | } |
426 | 468 | ||
427 | // return the node that offers full setup capability | 469 | // return the node that offers full setup capability |
428 | virtual RuntimeInfo * fullSetup( void ) | 470 | virtual RuntimeInfo * fullSetup( void ) |
429 | { RuntimeInfo * RI = nextNode(); | 471 | { RuntimeInfo * RI = nextNode(); |
430 | return (RI) ? RI->fullSetup() : 0; | 472 | return (RI) ? RI->fullSetup() : 0; |
431 | } | 473 | } |
432 | 474 | ||
433 | inline ANetNodeInstance * netNode() | 475 | inline ANetNodeInstance * netNode() |
434 | { return NNI; } | 476 | { return NNI; } |
435 | 477 | ||
436 | inline NodeCollection * nodeCollection() | 478 | inline NodeCollection * nodeCollection() |
437 | { return NNI->connection(); } | 479 | { return NNI->connection(); } |
438 | 480 | ||
439 | virtual State_t detectState( void ) = 0; | 481 | virtual State_t detectState( void ) = 0; |
440 | // public API to set the state | 482 | // public API to set the state |
441 | virtual QString setState( NodeCollection * NC, | 483 | virtual QString setState( NodeCollection * NC, |
442 | Action_t A, | 484 | Action_t A, |
443 | bool Force = 0 ); | 485 | bool Force = 0 ); |
444 | 486 | ||
445 | inline RuntimeInfo * nextNode( void ) { | 487 | inline RuntimeInfo * nextNode( void ) { |
446 | ANetNodeInstance * NNI = netNode()->nextNode(); | 488 | ANetNodeInstance * NNI = netNode()->nextNode(); |
447 | return (NNI) ? NNI->runtime() : 0; | 489 | return (NNI) ? NNI->runtime() : 0; |
448 | } | 490 | } |
449 | 491 | ||
450 | signals : | 492 | signals : |
451 | 493 | ||
452 | // sent by device if state changes | 494 | // sent by device if state changes |
453 | void stateChanged( State_t S, ANetNodeInstance * NNI ); | 495 | void stateChanged( State_t S, ANetNodeInstance * NNI ); |
454 | 496 | ||
455 | protected : | 497 | protected : |
456 | 498 | ||
457 | // set state of this node (private API) | 499 | // set state of this node (private API) |
458 | virtual QString setMyState( NodeCollection * NC, | 500 | virtual QString setMyState( NodeCollection * NC, |
459 | Action_t A, | 501 | Action_t A, |
460 | bool Force = 0 ) = 0; | 502 | bool Force = 0 ) = 0; |
461 | 503 | ||
462 | // connection this runtime info belongs to | 504 | // connection this runtime info belongs to |
463 | ANetNodeInstance * NNI; | 505 | ANetNodeInstance * NNI; |
464 | }; | 506 | }; |
465 | 507 | ||
466 | class NodeCollection : public QList<ANetNodeInstance> { | 508 | class NodeCollection : public QList<ANetNodeInstance> { |
467 | 509 | ||
468 | public : | 510 | public : |
469 | 511 | ||
470 | NodeCollection( void ); | 512 | NodeCollection( void ); |
471 | NodeCollection( QTextStream & TS ); | 513 | NodeCollection( QTextStream & TS, bool & Dangling ); |
472 | ~NodeCollection( void ); | 514 | ~NodeCollection( void ); |
473 | 515 | ||
474 | inline int done( void ) | 516 | inline int done( void ) |
475 | { return Done; } | 517 | { return Done; } |
476 | inline void setDone( int D ) | 518 | inline void setDone( int D ) |
477 | { Done = D; } | 519 | { Done = D; } |
478 | 520 | ||
479 | inline int number( void ) | 521 | inline int number( void ) |
480 | { return Number; } | 522 | { return Number; } |
481 | inline void setNumber( int i ) | 523 | inline void setNumber( int i ) |
482 | { Number = i; } | 524 | { Number = i; } |
483 | inline bool isNew( void ) | 525 | inline bool isNew( void ) |
484 | { return IsNew; } | 526 | { return IsNew; } |
485 | inline void setNew( bool N ) | 527 | inline void setNew( bool N ) |
486 | { IsNew = N ; } | 528 | { IsNew = N ; } |
487 | inline bool isModified( void ) | 529 | inline bool isModified( void ) |
488 | { return IsModified; } | 530 | { return IsModified; } |
489 | inline void setModified( bool N ) | 531 | inline void setModified( bool N ) |
490 | { IsModified = N ; } | 532 | { IsModified = N ; } |
491 | 533 | ||
492 | inline bool handlesInterface( const QString & S ) { | 534 | inline bool handlesInterface( const QString & S ) { |
493 | return getToplevel()->runtime()->handlesInterface( S ); | 535 | return getToplevel()->runtime()->handlesInterface( S ); |
494 | } | 536 | } |
495 | 537 | ||
496 | // return the interface in the OS that is assigned to | 538 | // return the interface in the OS that is assigned to |
497 | // this device | 539 | // this device |
498 | inline InterfaceInfo * assignedInterface( void ) { | 540 | inline InterfaceInfo * assignedInterface( void ) { |
499 | return AssignedInterface; | 541 | return AssignedInterface; |
500 | } | 542 | } |
501 | 543 | ||
502 | // assign the interface to this device | 544 | // assign the interface to this device |
503 | inline void assignInterface( InterfaceInfo * NI ) { | 545 | inline void assignInterface( InterfaceInfo * NI ) { |
504 | if( NI == 0 ) { | 546 | if( NI == 0 ) { |
505 | if( AssignedInterface ) { | 547 | if( AssignedInterface ) { |
506 | AssignedInterface->assignConnection( 0 ); | 548 | AssignedInterface->assignConnection( 0 ); |
507 | } | 549 | } |
508 | } | 550 | } |
509 | AssignedInterface = NI; | 551 | AssignedInterface = NI; |
510 | if( AssignedInterface ) { | 552 | if( AssignedInterface ) { |
511 | AssignedInterface->assignConnection( this ); | 553 | AssignedInterface->assignConnection( this ); |
512 | } | 554 | } |
513 | } | 555 | } |
514 | 556 | ||
515 | inline RuntimeInfo * device() { | 557 | inline RuntimeInfo * device() { |
516 | return getToplevel()->runtime()->device(); | 558 | return getToplevel()->runtime()->device(); |
517 | } | 559 | } |
518 | 560 | ||
519 | const QStringList & triggers(); | 561 | const QStringList & triggers(); |
520 | 562 | ||
521 | State_t state( bool Update = 0 ); | 563 | State_t state( bool Update = 0 ); |
522 | 564 | ||
523 | // get the ixmap for this device | 565 | // get the ixmap for this device |
524 | QPixmap devicePixmap( void ); | 566 | QPixmap devicePixmap( void ); |
525 | QPixmap statePixmap( State_t S ); | 567 | QPixmap statePixmap( State_t S ); |
526 | inline QPixmap statePixmap( bool Update = 0 ) | 568 | inline QPixmap statePixmap( bool Update = 0 ) |
527 | { return statePixmap( state(Update) ); } | 569 | { return statePixmap( state(Update) ); } |
528 | QString stateName( State_t ); | 570 | QString stateName( State_t ); |
529 | inline QString stateName( bool Update = 0 ) | 571 | inline QString stateName( bool Update = 0 ) |
530 | { return stateName( state(Update) ); } | 572 | { return stateName( state(Update) ); } |
531 | 573 | ||
532 | QString setState( Action_t A, bool Force = 0 ); | 574 | QString setState( Action_t A, bool Force = 0 ); |
533 | 575 | ||
534 | void save( QTextStream & TS ); | 576 | void save( QTextStream & TS ); |
535 | 577 | ||
536 | void append( ANetNodeInstance * NNI ); | 578 | void append( ANetNodeInstance * NNI ); |
537 | 579 | ||
538 | // makes sure that all items in the connection point to | 580 | // makes sure that all items in the connection point to |
539 | // that connectoin | 581 | // that connectoin |
540 | void reassign( void ); | 582 | void reassign( void ); |
541 | 583 | ||
542 | ANetNodeInstance * getToplevel( void ); | 584 | ANetNodeInstance * getToplevel( void ); |
543 | ANetNodeInstance * findNext( ANetNodeInstance * NNI ); | 585 | ANetNodeInstance * findNext( ANetNodeInstance * NNI ); |
544 | ANetNodeInstance * findByName( const QString & S ); | 586 | ANetNodeInstance * findByName( const QString & S ); |
545 | 587 | ||
546 | inline const QString & name() | 588 | inline const QString & name() |
547 | { return Name; } | 589 | { return Name; } |
548 | 590 | ||
549 | const QString & description( void ); | 591 | const QString & description( void ); |
550 | 592 | ||
551 | inline void setName( const QString & N) | 593 | inline void setName( const QString & N) |
552 | { Name = N; } | 594 | { Name = N; } |
553 | 595 | ||
554 | inline State_t currentState( void ) | 596 | inline State_t currentState( void ) |
555 | { return CurrentState; } | 597 | { return CurrentState; } |
556 | inline void setCurrentState( State_t S ) | 598 | inline void setCurrentState( State_t S ) |
557 | { CurrentState = S; } | 599 | { CurrentState = S; } |
558 | 600 | ||
559 | // return TRUE if this node can have data to be inserted in | 601 | // return TRUE if this node can have data to be inserted in |
560 | // file identified by S | 602 | // file identified by S |
561 | bool hasDataForFile( SystemFile & S ); | 603 | bool hasDataForFile( SystemFile & S ); |
562 | ANetNodeInstance * firstWithDataForFile( SystemFile & ); | 604 | ANetNodeInstance * firstWithDataForFile( SystemFile & ); |
563 | 605 | ||
564 | // generate items for this file -> toplevel call | 606 | // generate items for this file -> toplevel call |
565 | short generateFile( SystemFile & SF, | 607 | short generateFile( SystemFile & SF, |
566 | long DN // device number | 608 | long DN // device number |
567 | ) | 609 | ) |
568 | { return getToplevel()->generateFile( SF, DN ); } | 610 | { return getToplevel()->generateFile( SF, DN ); } |
569 | 611 | ||
570 | bool triggeredBy( const QString & Trigger ) | 612 | bool triggeredBy( const QString & Trigger ) |
571 | { return getToplevel()->triggeredBy( Trigger ); } | 613 | { return getToplevel()->triggeredBy( Trigger ); } |
572 | 614 | ||
573 | private : | 615 | private : |
574 | 616 | ||
575 | int compareItems ( QCollection::Item item1, | 617 | int compareItems ( QCollection::Item item1, |
576 | QCollection::Item item2 ); | 618 | QCollection::Item item2 ); |
577 | 619 | ||
578 | long Number; | 620 | long Number; |
579 | 621 | ||
580 | // state of this connection | 622 | // state of this connection |
581 | State_t CurrentState; | 623 | State_t CurrentState; |
582 | 624 | ||
583 | QString Name; | 625 | QString Name; |
584 | // true if this collection was just created (and not | 626 | // true if this collection was just created (and not |
585 | // loaded from file | 627 | // loaded from file |
586 | bool IsNew; | 628 | bool IsNew; |
587 | // index in listbox | 629 | // index in listbox |
588 | int Index; | 630 | int Index; |
589 | bool IsModified; | 631 | bool IsModified; |
590 | int Done; | 632 | int Done; |
591 | 633 | ||
592 | InterfaceInfo * AssignedInterface; | 634 | InterfaceInfo * AssignedInterface; |
593 | 635 | ||
594 | }; | 636 | }; |
595 | 637 | ||
596 | #endif | 638 | #endif |
diff --git a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h index 34f3bb5..06d1548 100644 --- a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h +++ b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h | |||
@@ -1,139 +1,149 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (C) 2005 Holger Hans Peter Freyther <freyther@handhelds.org> | 4 | Copyright (C) 2005 Holger Hans Peter Freyther <freyther@handhelds.org> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef ANET_NODE_INTERFACE_H | 32 | #ifndef ANET_NODE_INTERFACE_H |
33 | #define ANET_NODE_INTERFACE_H | 33 | #define ANET_NODE_INTERFACE_H |
34 | 34 | ||
35 | #include <opie2/oapplicationfactory.h> | 35 | #include <opie2/oapplicationfactory.h> |
36 | #include <qpe/qcom.h> | 36 | #include <qpe/qcom.h> |
37 | 37 | ||
38 | // {A215A785-FB73-4F74-84B0-053BCC77DB87} | 38 | // {A215A785-FB73-4F74-84B0-053BCC77DB87} |
39 | #ifndef IID_NetworkSettings2 | 39 | #ifndef IID_NetworkSettings2 |
40 | 40 | ||
41 | #define IID_NetworkSettings2 QUuid( 0xa215a785, 0xfb73, 0x4f74, 0x84, 0xb0, 0x05, 0x3b, 0xcc, 0x77, 0xdb, 0x87) | 41 | #define IID_NetworkSettings2 QUuid( 0xa215a785, 0xfb73, 0x4f74, 0x84, 0xb0, 0x05, 0x3b, 0xcc, 0x77, 0xdb, 0x87) |
42 | 42 | ||
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Multiple Types | 48 | * Multiple Types |
49 | */ | 49 | */ |
50 | template <class Node > | 50 | template <class Node > |
51 | struct NS2PrivateFactory { | 51 | struct NS2PrivateFactory { |
52 | 52 | ||
53 | inline static void createPlugins( QList<ANetNode> & PNN) { | 53 | inline static void createPlugins( QList<ANetNode> & PNN) { |
54 | PNN.append( new Node()); | 54 | PNN.append( new Node()); |
55 | } | 55 | } |
56 | 56 | ||
57 | }; | 57 | }; |
58 | 58 | ||
59 | /* | 59 | /* |
60 | * Stop recursion here | 60 | * Stop recursion here |
61 | */ | 61 | */ |
62 | template <> | 62 | template <> |
63 | struct NS2PrivateFactory<Opie::Core::NullType> { | 63 | struct NS2PrivateFactory<Opie::Core::NullType> { |
64 | 64 | ||
65 | inline static void createPlugins( QList<ANetNode> &) { | 65 | inline static void createPlugins( QList<ANetNode> &) { |
66 | 66 | ||
67 | } | 67 | } |
68 | 68 | ||
69 | }; | 69 | }; |
70 | 70 | ||
71 | template <class Node, class Tail> | 71 | template <class Node, class Tail> |
72 | struct NS2PrivateFactory<Opie::Core::Typelist<Node, Tail> > { | 72 | struct NS2PrivateFactory<Opie::Core::Typelist<Node, Tail> > { |
73 | 73 | ||
74 | inline static void createPlugins( QList<ANetNode> & PNN ) { | 74 | inline static void createPlugins( QList<ANetNode> & PNN ) { |
75 | NS2PrivateFactory<Node>::createPlugins(PNN); | 75 | NS2PrivateFactory<Node>::createPlugins(PNN); |
76 | NS2PrivateFactory<Tail>::createPlugins(PNN); | 76 | NS2PrivateFactory<Tail>::createPlugins(PNN); |
77 | } | 77 | } |
78 | 78 | ||
79 | }; | 79 | }; |
80 | 80 | ||
81 | class NetNodeInterface : public QUnknownInterface { | ||
82 | |||
83 | public : | ||
84 | |||
85 | virtual QRESULT queryInterface( const QUuid& uuid, | ||
86 | QUnknownInterface **iface ) = 0; | ||
87 | |||
88 | virtual void create_plugin( QList<ANetNode> & PNN ) = 0; | ||
89 | }; | ||
90 | |||
81 | template<class Node> | 91 | template<class Node> |
82 | struct NetNodeInterface : public QUnknownInterface { | 92 | struct NetNodeInterface_T : public NetNodeInterface { |
83 | 93 | ||
84 | QRESULT queryInterface(const QUuid& uuid, QUnknownInterface **iface) { | 94 | QRESULT queryInterface(const QUuid& uuid, QUnknownInterface **iface) { |
85 | *iface = 0; | 95 | *iface = 0; |
86 | 96 | ||
87 | if( uuid == IID_QUnknown ) | 97 | if( uuid == IID_QUnknown ) |
88 | *iface = this; | 98 | *iface = this; |
89 | else if( uuid == IID_NetworkSettings2 ) | 99 | else if( uuid == IID_NetworkSettings2 ) |
90 | *iface = this; | 100 | *iface = this; |
91 | else | 101 | else |
92 | return QS_FALSE; | 102 | return QS_FALSE; |
93 | 103 | ||
94 | (*iface)->addRef(); | 104 | (*iface)->addRef(); |
95 | 105 | ||
96 | return QS_OK; | 106 | return QS_OK; |
97 | 107 | ||
98 | } | 108 | } |
99 | 109 | ||
100 | void create_plugin( QList<ANetNode> & PNN ) { | 110 | void create_plugin( QList<ANetNode> & PNN ) { |
101 | 111 | ||
102 | PNN.append( new Node()); | 112 | PNN.append( new Node()); |
103 | 113 | ||
104 | } | 114 | } |
105 | 115 | ||
106 | Q_REFCOUNT | 116 | Q_REFCOUNT |
107 | }; | 117 | }; |
108 | 118 | ||
109 | template<class Node, class Tail> | 119 | template<class Node, class Tail> |
110 | struct NetNodeInterface<Opie::Core::Typelist<Node, Tail> > | 120 | struct NetNodeInterface_T<Opie::Core::Typelist<Node, Tail> > |
111 | : public QUnknownInterface { | 121 | : public NetNodeInterface { |
112 | 122 | ||
113 | QRESULT queryInterface( const QUuid& uuid, | 123 | QRESULT queryInterface( const QUuid& uuid, |
114 | QUnknownInterface **iface) { | 124 | QUnknownInterface **iface) { |
115 | 125 | ||
116 | *iface = 0; | 126 | *iface = 0; |
117 | 127 | ||
118 | if( uuid == IID_QUnknown ) *iface = this; | 128 | if( uuid == IID_QUnknown ) *iface = this; |
119 | else if( uuid == IID_NetworkSettings2 ) *iface = this; | 129 | else if( uuid == IID_NetworkSettings2 ) *iface = this; |
120 | else return QS_FALSE; | 130 | else return QS_FALSE; |
121 | 131 | ||
122 | (*iface)->addRef(); | 132 | (*iface)->addRef(); |
123 | return QS_OK; | 133 | return QS_OK; |
124 | 134 | ||
125 | } | 135 | } |
126 | 136 | ||
127 | void create_plugin( QList<ANetNode> & PNN ) { | 137 | void create_plugin( QList<ANetNode> & PNN ) { |
128 | NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugin( PNN ); | 138 | NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugins( PNN ); |
129 | } | 139 | } |
130 | 140 | ||
131 | Q_REFCOUNT | 141 | Q_REFCOUNT |
132 | 142 | ||
133 | }; | 143 | }; |
134 | 144 | ||
135 | #define OPIE_NS2_PLUGIN( factory ) \ | 145 | #define OPIE_NS2_PLUGIN( factory ) \ |
136 | Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory) } | 146 | Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory) } |
137 | 147 | ||
138 | #endif | 148 | #endif |
139 | 149 | ||
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 79d41ea..3479abb 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp | |||
@@ -1,610 +1,479 @@ | |||
1 | #include <unistd.h> | 1 | #include <unistd.h> |
2 | #include <errno.h> | 2 | #include <errno.h> |
3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
4 | #include <pwd.h> | 4 | #include <pwd.h> |
5 | #include <qpixmap.h> | 5 | #include <qpixmap.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | 8 | ||
9 | #include <qpe/qlibrary.h> | 9 | #include <qpe/qlibrary.h> |
10 | #include <qpe/qpeapplication.h> | 10 | #include <qpe/qpeapplication.h> |
11 | 11 | ||
12 | #include <opie2/odebug.h> | 12 | #include <opie2/odebug.h> |
13 | #include <opie2/opluginloader.h> | 13 | #include <opie2/opluginloader.h> |
14 | 14 | ||
15 | #include <qtopia/resource.h> | 15 | #include <qtopia/resource.h> |
16 | 16 | ||
17 | #include "netnode.h" | 17 | #include "netnode.h" |
18 | #include "resources.h" | 18 | #include "resources.h" |
19 | #include "netnodeinterface.h" | 19 | #include "netnodeinterface.h" |
20 | 20 | ||
21 | #define PLUGINDIR "plugins/networksettings2" | 21 | #define PLUGINDIR "plugins/networksettings2" |
22 | #define ICONDIR "/pics/networksettings2/" | 22 | #define ICONDIR "/pics/networksettings2/" |
23 | 23 | ||
24 | // single resources instance | 24 | // single resources instance |
25 | TheNSResources * _NSResources = 0; | 25 | TheNSResources * _NSResources = 0; |
26 | 26 | ||
27 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), | 27 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), |
28 | ConnectionsMap() { | 28 | ConnectionsMap(), DanglingConnectionsMap() { |
29 | 29 | ||
30 | _NSResources = this; | 30 | _NSResources = this; |
31 | 31 | ||
32 | detectCurrentUser(); | 32 | detectCurrentUser(); |
33 | 33 | ||
34 | // load available netnodes | 34 | // load available netnodes |
35 | 35 | ||
36 | #ifdef MYPLUGIN | ||
37 | |||
38 | findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); | ||
39 | |||
40 | // compile provides and needs lists | ||
41 | { const char ** NeedsRun; | ||
42 | QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); | ||
43 | bool Done; | ||
44 | |||
45 | for ( ; OuterIt.current(); ++OuterIt ) { | ||
46 | // find needs list | ||
47 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; | ||
48 | ANetNode::NetNodeList & NNL = *(NNLP); | ||
49 | |||
50 | // must iterate this way to avoid duplication pointers | ||
51 | for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); | ||
52 | InnerIt.current(); ++InnerIt ) { | ||
53 | if( InnerIt.current() == OuterIt.current() ) | ||
54 | // avoid recursive | ||
55 | continue; | ||
56 | |||
57 | const char ** Provides = InnerIt.current()->NetNode->provides(); | ||
58 | NeedsRun = OuterIt.current()->NetNode->needs(); | ||
59 | |||
60 | for( ; *NeedsRun; NeedsRun ++ ) { | ||
61 | const char ** PRun; | ||
62 | PRun = Provides; | ||
63 | for( ; *PRun; PRun ++ ) { | ||
64 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { | ||
65 | // inner provides what outer needs | ||
66 | NNL.resize( NNL.size() + 1 ); | ||
67 | NNL[NNL.size()-1] = InnerIt.current()->NetNode; | ||
68 | Done = 1; // break from 2 loops | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | OuterIt.current()->NetNode->setAlternatives( NNLP ); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #else | ||
79 | |||
80 | Plugins = 0; | 36 | Plugins = 0; |
81 | findAvailableNetNodes(); | 37 | findAvailableNetNodes(); |
82 | 38 | ||
83 | // compile provides and needs lists | 39 | // compile provides and needs lists |
84 | { const char ** NeedsRun; | 40 | { const char ** NeedsRun; |
85 | QDictIterator<ANetNode> OuterIt( AllNodeTypes ); | 41 | QDictIterator<ANetNode> OuterIt( AllNodeTypes ); |
86 | bool Done; | 42 | bool Done; |
87 | 43 | ||
88 | for ( ; OuterIt.current(); ++OuterIt ) { | 44 | for ( ; OuterIt.current(); ++OuterIt ) { |
89 | // find needs list | 45 | // find needs list |
90 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; | 46 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; |
91 | ANetNode::NetNodeList & NNL = *(NNLP); | 47 | ANetNode::NetNodeList & NNL = *(NNLP); |
92 | 48 | ||
93 | // must iterate this way to avoid duplication pointers | 49 | // must iterate this way to avoid duplication pointers |
94 | for ( QDictIterator<ANetNode> InnerIt( AllNodeTypes ); | 50 | for ( QDictIterator<ANetNode> InnerIt( AllNodeTypes ); |
95 | InnerIt.current(); ++InnerIt ) { | 51 | InnerIt.current(); ++InnerIt ) { |
96 | 52 | ||
97 | if( InnerIt.current() == OuterIt.current() ) | 53 | if( InnerIt.current() == OuterIt.current() ) |
98 | // avoid recursive | 54 | // avoid recursive |
99 | continue; | 55 | continue; |
100 | 56 | ||
101 | const char ** Provides = InnerIt.current()->provides(); | 57 | const char ** Provides = InnerIt.current()->provides(); |
102 | NeedsRun = OuterIt.current()->needs(); | 58 | NeedsRun = OuterIt.current()->needs(); |
103 | 59 | ||
104 | for( ; *NeedsRun; NeedsRun ++ ) { | 60 | for( ; *NeedsRun; NeedsRun ++ ) { |
105 | const char ** PRun; | 61 | const char ** PRun; |
106 | PRun = Provides; | 62 | PRun = Provides; |
107 | for( ; *PRun; PRun ++ ) { | 63 | for( ; *PRun; PRun ++ ) { |
108 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { | 64 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { |
109 | // inner provides what outer needs | 65 | // inner provides what outer needs |
110 | NNL.resize( NNL.size() + 1 ); | 66 | NNL.resize( NNL.size() + 1 ); |
111 | NNL[NNL.size()-1] = InnerIt.current(); | 67 | NNL[NNL.size()-1] = InnerIt.current(); |
112 | Done = 1; // break from 2 loops | 68 | Done = 1; // break from 2 loops |
113 | break; | 69 | break; |
114 | } | 70 | } |
115 | } | 71 | } |
116 | } | 72 | } |
117 | } | 73 | } |
118 | OuterIt.current()->setAlternatives( NNLP ); | 74 | OuterIt.current()->setAlternatives( NNLP ); |
119 | } | 75 | } |
120 | } | 76 | } |
121 | 77 | ||
122 | #endif | ||
123 | |||
124 | // define built in Node types to Description map | 78 | // define built in Node types to Description map |
125 | addNodeType( "device", tr( "Network Device" ), | 79 | addNodeType( "device", tr( "Network Device" ), |
126 | tr( "<p>Devices that can handle IP packets</p>" ) ); | 80 | tr( "<p>Devices that can handle IP packets</p>" ) ); |
127 | addNodeType( "line", tr( "Character device" ), | 81 | addNodeType( "line", tr( "Character device" ), |
128 | tr( "<p>Devices that can handle single bytes</p>" ) ); | 82 | tr( "<p>Devices that can handle single bytes</p>" ) ); |
129 | addNodeType( "connection", tr( "IP Connection" ), | 83 | addNodeType( "connection", tr( "IP Connection" ), |
130 | tr( "<p>Nodes that provide working IP connections</p>" ) ); | 84 | tr( "<p>Nodes that provide working IP connections</p>" ) ); |
131 | addNodeType( "fullsetup", tr( "Connection Profile" ), | 85 | addNodeType( "fullsetup", tr( "Connection Profile" ), |
132 | tr( "<p>Fully configured connection profile</p>" ) ); | 86 | tr( "<p>Fully configured connection profile</p>" ) ); |
133 | addNodeType( "GPRS", tr( "Connection to GPRS device" ), | 87 | addNodeType( "GPRS", tr( "Connection to GPRS device" ), |
134 | tr( "<p>Connection to a GPRS capable device</p>" ) ); | 88 | tr( "<p>Connection to a GPRS capable device</p>" ) ); |
135 | 89 | ||
136 | // get access to the system | 90 | // get access to the system |
137 | TheSystem = new System(); | 91 | TheSystem = new System(); |
138 | 92 | ||
139 | } | 93 | } |
140 | 94 | ||
141 | TheNSResources::~TheNSResources( void ) { | 95 | TheNSResources::~TheNSResources( void ) { |
142 | 96 | ||
143 | #ifndef MYPLUGINS | ||
144 | if( Plugins ) { | 97 | if( Plugins ) { |
145 | delete Plugins; | 98 | delete Plugins; |
146 | delete PluginManager; | 99 | delete PluginManager; |
147 | } | 100 | } |
148 | #endif | ||
149 | delete TheSystem; | 101 | delete TheSystem; |
150 | 102 | ||
151 | } | 103 | } |
152 | 104 | ||
153 | void TheNSResources::addNodeType( const QString & ID, | 105 | void TheNSResources::addNodeType( const QString & ID, |
154 | const QString & Name, | 106 | const QString & Name, |
155 | const QString & Descr ) { | 107 | const QString & Descr ) { |
156 | if( NodeTypeNameMap[ID].isEmpty() ) { | 108 | if( NodeTypeNameMap[ID].isEmpty() ) { |
157 | NodeTypeNameMap.insert( ID, Name ); | 109 | NodeTypeNameMap.insert( ID, Name ); |
158 | NodeTypeDescriptionMap.insert( ID, Descr ); | 110 | NodeTypeDescriptionMap.insert( ID, Descr ); |
159 | } | 111 | } |
160 | } | 112 | } |
161 | 113 | ||
162 | void TheNSResources::addSystemFile( const QString & ID, | 114 | void TheNSResources::addSystemFile( const QString & ID, |
163 | const QString & P, | 115 | const QString & P, |
164 | bool KDI ) { | 116 | bool KDI ) { |
165 | if( ! SystemFiles.find( ID ) ) { | 117 | if( ! SystemFiles.find( ID ) ) { |
166 | // new system file | 118 | // new system file |
167 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); | 119 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); |
168 | } // else existed | 120 | } // else existed |
169 | } | 121 | } |
170 | 122 | ||
171 | void TheNSResources::busy( bool ) { | 123 | void TheNSResources::busy( bool ) { |
172 | /* | 124 | /* |
173 | if( B ) { | 125 | if( B ) { |
174 | ShowWait->show(); | 126 | ShowWait->show(); |
175 | qApp->process | 127 | qApp->process |
176 | } else { | 128 | } else { |
177 | ShowWait->hide(); | 129 | ShowWait->hide(); |
178 | } | 130 | } |
179 | */ | 131 | */ |
180 | } | 132 | } |
181 | 133 | ||
182 | #ifdef MYPLUGIN | ||
183 | /** | ||
184 | * Load all modules that are found in the path | ||
185 | * @param path a directory that is scaned for any plugins that can be loaded | ||
186 | * and attempts to load them | ||
187 | */ | ||
188 | void TheNSResources::findAvailableNetNodes(const QString &path){ | ||
189 | |||
190 | Log(("Locate plugins in %s\n", path.latin1() )); | ||
191 | QDir d(path); | ||
192 | if(!d.exists()) | ||
193 | return; | ||
194 | |||
195 | QString lang = ::getenv("LANG"); | ||
196 | |||
197 | // Don't want sym links | ||
198 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | ||
199 | const QFileInfoList *list = d.entryInfoList(); | ||
200 | QFileInfoListIterator it( *list ); | ||
201 | QFileInfo *fi; | ||
202 | |||
203 | while ( (fi=it.current()) ) { | ||
204 | |||
205 | if( fi->fileName().contains(".so")){ | ||
206 | /* if loaded install translation */ | ||
207 | if( loadNetNode(path + "/" + fi->fileName()) ) { | ||
208 | Log(( "Loading plugin %s\n", fi->fileName().latin1())); | ||
209 | QTranslator *trans = new QTranslator(qApp); | ||
210 | QString fn = QPEApplication::qpeDir()+ | ||
211 | "/i18n/"+lang+"/"+ | ||
212 | fi->fileName().left( fi->fileName().find(".") )+ | ||
213 | ".qm"; | ||
214 | |||
215 | if( trans->load( fn ) ) | ||
216 | qApp->installTranslator( trans ); | ||
217 | else | ||
218 | delete trans; | ||
219 | } else { | ||
220 | Log(( "Error loading plugin %s\n", fi->fileName().latin1())); | ||
221 | } | ||
222 | } | ||
223 | ++it; | ||
224 | } | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * Attempt to load a function and resolve a function. | ||
229 | * @param pluginFileName - the name of the file in which to attempt to load | ||
230 | * @param resolveString - function pointer to resolve | ||
231 | * @return true of loading is successful | ||
232 | */ | ||
233 | bool TheNSResources::loadNetNode( | ||
234 | const QString &pluginFileName, const QString &resolveString){ | ||
235 | |||
236 | QLibrary *lib = new QLibrary(pluginFileName); | ||
237 | void * res = lib->resolve(resolveString); | ||
238 | if( ! res ){ | ||
239 | delete lib; | ||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; | ||
244 | |||
245 | // Try to get an object. | ||
246 | QList<ANetNode> PNN; | ||
247 | |||
248 | getNetNodeList( PNN ); | ||
249 | if( PNN.isEmpty() ) { | ||
250 | delete lib; | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | ANetNode * NNP; | ||
255 | for( QListIterator<ANetNode> it(PNN); | ||
256 | it.current(); | ||
257 | ++it ) { | ||
258 | NetNode_t * NN; | ||
259 | |||
260 | NNP = it.current(); | ||
261 | NN = new NetNode_t; | ||
262 | NN->NetNode = NNP; | ||
263 | NN->TheLibrary = lib; | ||
264 | NN->NodeCountInLib = PNN.count(); | ||
265 | |||
266 | // store mapping | ||
267 | AllNodeTypes.insert( NN->NetNode->name(), NN ); | ||
268 | } | ||
269 | |||
270 | return 1; | ||
271 | } | ||
272 | |||
273 | #else | ||
274 | |||
275 | void TheNSResources::findAvailableNetNodes( void ){ | 134 | void TheNSResources::findAvailableNetNodes( void ){ |
276 | 135 | ||
277 | Plugins = new OPluginLoader( "networksettings2" ); | 136 | Plugins = new OPluginLoader( "networksettings2" ); |
278 | Plugins->setAutoDelete( true ); | 137 | Plugins->setAutoDelete( true ); |
279 | 138 | ||
280 | PluginManager = new OPluginManager( Plugins ); | 139 | PluginManager = new OPluginManager( Plugins ); |
281 | PluginManager->load(); | 140 | PluginManager->load(); |
282 | 141 | ||
283 | if( Plugins->isInSafeMode() ) { | 142 | if( Plugins->isInSafeMode() ) { |
284 | QMessageBox::information( | 143 | QMessageBox::information( |
285 | 0, | 144 | 0, |
286 | tr( "Today Error"), | 145 | tr( "Today Error"), |
287 | tr( "<qt>The plugin '%1' caused Today to crash." | 146 | tr( "<qt>The plugin '%1' caused Today to crash." |
288 | " It could be that the plugin is not properly" | 147 | " It could be that the plugin is not properly" |
289 | " installed.<br>Today tries to continue loading" | 148 | " installed.<br>Today tries to continue loading" |
290 | " plugins.</qt>" ) | 149 | " plugins.</qt>" ) |
291 | .arg( PluginManager->crashedPlugin().name())); | 150 | .arg( PluginManager->crashedPlugin().name())); |
292 | } | 151 | } |
293 | 152 | ||
294 | // Get All Plugins | 153 | // Get All Plugins |
295 | OPluginLoader::List allplugins = Plugins->filtered(); | 154 | OPluginLoader::List allplugins = Plugins->filtered(); |
155 | QString lang = ::getenv("LANG"); | ||
296 | 156 | ||
297 | for( OPluginLoader::List::Iterator it = allplugins.begin(); | 157 | for( OPluginLoader::List::Iterator it = allplugins.begin(); |
298 | it != allplugins.end(); | 158 | it != allplugins.end(); |
299 | ++it ) { | 159 | ++it ) { |
300 | 160 | ||
301 | // check if this plugin supports the proper interface | 161 | // check if this plugin supports the proper interface |
302 | NetNodeInterface * interface = | 162 | NetNodeInterface * interface = |
303 | Plugins->load<NetNodeInterface>( *it, IID_NetworkSettings2 ); | 163 | Plugins->load<NetNodeInterface>( *it, IID_NetworkSettings2 ); |
304 | 164 | ||
305 | if( ! interface ) { | 165 | if( ! interface ) { |
306 | Log(( "Plugin %s from %s does not support proper interface\n", | 166 | Log(( "Plugin %s from %s does not support proper interface\n", |
307 | it->name().latin1(), it->path().latin1() )); | 167 | (*it).name().latin1(), (*it).path().latin1() )); |
308 | continue; | 168 | continue; |
309 | } | 169 | } |
310 | 170 | ||
311 | // add the nodes in this plugin to the dictionary | 171 | // add the nodes in this plugin to the dictionary |
312 | { QList<ANetNode> PNN; | 172 | { QList<ANetNode> PNN; |
313 | 173 | ||
314 | interface->create_plugin( PNN ); | 174 | interface->create_plugin( PNN ); |
315 | 175 | ||
316 | if( PNN.isEmpty() ) { | 176 | if( PNN.isEmpty() ) { |
317 | Log(( "Plugin %s from %s does offer any nodes\n", | 177 | Log(( "Plugin %s from %s does offer any nodes\n", |
318 | it->name().latin1(), it->path().latin1() )); | 178 | (*it).name().latin1(), (*it).path().latin1() )); |
319 | delete interface; | 179 | delete interface; |
320 | continue; | 180 | continue; |
321 | } | 181 | } |
322 | 182 | ||
323 | // merge this node with global node | 183 | // merge this node with global node |
324 | for( QListIterator<ANetNode> it(PNN); | 184 | for( QListIterator<ANetNode> it(PNN); |
325 | it.current(); | 185 | it.current(); |
326 | ++it ) { | 186 | ++it ) { |
327 | AllNodeTypes.insert( it->current()->name(), it->current() ); | 187 | AllNodeTypes.insert( it.current()->name(), it.current() ); |
328 | } | 188 | } |
329 | } | 189 | } |
330 | 190 | ||
331 | // load the translation | 191 | // load the translation |
332 | QTranslator *trans = new QTranslator(qApp); | 192 | QTranslator *trans = new QTranslator(qApp); |
333 | QString fn = QPEApplication::qpeDir()+ | 193 | QString fn = QPEApplication::qpeDir()+ |
334 | "/i18n/"+lang+"/"+ it->name() + ".qm"; | 194 | "/i18n/"+lang+"/"+ (*it).name() + ".qm"; |
335 | 195 | ||
336 | if( trans->load( fn ) ) | 196 | if( trans->load( fn ) ) |
337 | qApp->installTranslator( trans ); | 197 | qApp->installTranslator( trans ); |
338 | else | 198 | else |
339 | delete trans; | 199 | delete trans; |
340 | } | 200 | } |
341 | 201 | ||
342 | } | 202 | } |
343 | 203 | ||
344 | #endif | ||
345 | |||
346 | // used to find unique connection number | 204 | // used to find unique connection number |
347 | int TheNSResources::assignConnectionNumber( void ) { | 205 | int TheNSResources::assignConnectionNumber( void ) { |
348 | bool found = 1; | 206 | bool found = 1; |
349 | for( int trial = 0; ; trial ++ ) { | 207 | for( int trial = 0; ; trial ++ ) { |
350 | found = 1; | 208 | found = 1; |
351 | for( QDictIterator<NodeCollection> it(ConnectionsMap); | 209 | for( QDictIterator<NodeCollection> it(ConnectionsMap); |
352 | it.current(); | 210 | it.current(); |
353 | ++it ) { | 211 | ++it ) { |
354 | if( it.current()->number() == trial ) { | 212 | if( it.current()->number() == trial ) { |
355 | found = 0; | 213 | found = 0; |
356 | break; | 214 | break; |
357 | } | 215 | } |
358 | } | 216 | } |
359 | 217 | ||
360 | if( found ) { | 218 | if( found ) { |
361 | Log(("Assign profile number %d\n", trial )); | 219 | Log(("Assign profile number %d\n", trial )); |
362 | return trial; | 220 | return trial; |
363 | } | 221 | } |
364 | } | 222 | } |
365 | } | 223 | } |
366 | 224 | ||
367 | QPixmap TheNSResources::getPixmap( const QString & QS ) { | 225 | QPixmap TheNSResources::getPixmap( const QString & QS ) { |
368 | QPixmap P; | 226 | QPixmap P; |
369 | QString S("networksettings2/"); | 227 | QString S("networksettings2/"); |
370 | S += QS; | 228 | S += QS; |
371 | P = Resource::loadPixmap( S ); | 229 | P = Resource::loadPixmap( S ); |
372 | if( P.isNull() ) { | 230 | if( P.isNull() ) { |
373 | Log(( "Cannot load %s\n", S.latin1() )); | 231 | Log(( "Cannot load %s\n", S.latin1() )); |
374 | } | 232 | } |
375 | return ( P.isNull() ) ? QPixmap() : P; | 233 | return ( P.isNull() ) ? QPixmap() : P; |
376 | } | 234 | } |
377 | 235 | ||
378 | QString TheNSResources::tr( const char * s ) { | 236 | QString TheNSResources::tr( const char * s ) { |
379 | return qApp->translate( "resource", s ); | 237 | return qApp->translate( "resource", s ); |
380 | } | 238 | } |
381 | 239 | ||
382 | const QString & TheNSResources::netNode2Name( const char * s ) { | 240 | const QString & TheNSResources::netNode2Name( const char * s ) { |
383 | return NodeTypeNameMap[s]; | 241 | return NodeTypeNameMap[s]; |
384 | } | 242 | } |
385 | 243 | ||
386 | const QString & TheNSResources::netNode2Description( const char * s ) { | 244 | const QString & TheNSResources::netNode2Description( const char * s ) { |
387 | return NodeTypeDescriptionMap[s]; | 245 | return NodeTypeDescriptionMap[s]; |
388 | } | 246 | } |
389 | 247 | ||
390 | void TheNSResources::addConnection( NodeCollection * NC ) { | 248 | void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) { |
391 | ANetNodeInstance * NNI; | 249 | ANetNodeInstance * NNI; |
392 | ConnectionsMap.insert( NC->name(), NC ); | 250 | if( Dangling ) { |
251 | DanglingConnectionsMap.insert( NC->name(), NC ); | ||
252 | } else { | ||
253 | ConnectionsMap.insert( NC->name(), NC ); | ||
254 | } | ||
255 | |||
393 | // add (new) nodes to NodeList | 256 | // add (new) nodes to NodeList |
394 | for( QListIterator<ANetNodeInstance> it(*NC); | 257 | for( QListIterator<ANetNodeInstance> it(*NC); |
395 | it.current(); | 258 | it.current(); |
396 | ++it ) { | 259 | ++it ) { |
397 | NNI = it.current(); | 260 | NNI = it.current(); |
398 | if( findNodeInstance( NNI->name() ) == 0 ) { | 261 | if( findNodeInstance( NNI->name() ) == 0 ) { |
399 | // new item | 262 | // new item |
400 | addNodeInstance( NNI ); | 263 | addNodeInstance( NNI ); |
401 | } | 264 | } |
402 | } | 265 | } |
403 | } | 266 | } |
404 | 267 | ||
405 | void TheNSResources::removeConnection( const QString & N ) { | 268 | void TheNSResources::removeConnection( const QString & N ) { |
406 | NodeCollection * NC = findConnection( N ); | 269 | NodeCollection * NC = findConnection( N ); |
407 | if( ! NC ) | 270 | if( ! NC ) |
408 | return; | 271 | return; |
409 | 272 | ||
410 | // delete netnodes in this connection | 273 | // delete netnodes in this connection |
411 | ANetNodeInstance * NNI; | 274 | ANetNodeInstance * NNI; |
412 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { | 275 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { |
413 | removeNodeInstance( NNI->name() ); | 276 | removeNodeInstance( NNI->name() ); |
414 | } | 277 | } |
415 | ConnectionsMap.remove( N ); | 278 | if( ConnectionsMap.find( N ) ) { |
279 | ConnectionsMap.remove( N ); | ||
280 | } else { | ||
281 | DanglingConnectionsMap.remove( N ); | ||
282 | } | ||
283 | |||
416 | } | 284 | } |
417 | 285 | ||
286 | // dangling connections are filtered out | ||
418 | NodeCollection * TheNSResources::findConnection( const QString & S ) { | 287 | NodeCollection * TheNSResources::findConnection( const QString & S ) { |
419 | return ConnectionsMap[ S ]; | 288 | return ConnectionsMap[ S ]; |
420 | } | 289 | } |
421 | 290 | ||
422 | NodeCollection * TheNSResources::getConnection( int nr ) { | 291 | NodeCollection * TheNSResources::getConnection( int nr ) { |
423 | for( QDictIterator<NodeCollection> it(ConnectionsMap); | 292 | for( QDictIterator<NodeCollection> it(ConnectionsMap); |
424 | it.current(); | 293 | it.current(); |
425 | ++it ) { | 294 | ++it ) { |
426 | if( it.current()->number() == nr ) { | 295 | if( it.current()->number() == nr ) { |
427 | return it.current(); | 296 | return it.current(); |
428 | } | 297 | } |
429 | } | 298 | } |
430 | return 0; | 299 | return 0; |
431 | } | 300 | } |
432 | /* | 301 | /* |
433 | void TheNSResources::renumberConnections( void ) { | 302 | void TheNSResources::renumberConnections( void ) { |
434 | Name2Connection_t & M = NSResources->connections(); | 303 | Name2Connection_t & M = NSResources->connections(); |
435 | NodeCollection * NC; | 304 | NodeCollection * NC; |
436 | 305 | ||
437 | // for all connections | 306 | // for all connections |
438 | NodeCollection::resetMaxNr(); | 307 | NodeCollection::resetMaxNr(); |
439 | for( QDictIterator<NodeCollection> it(M); | 308 | for( QDictIterator<NodeCollection> it(M); |
440 | it.current(); | 309 | it.current(); |
441 | ++it ) { | 310 | ++it ) { |
442 | NC = it.current(); | 311 | NC = it.current(); |
443 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 312 | NC->setNumber( NC->maxConnectionNumber()+1 ); |
444 | NC->setModified( 1 ); | 313 | NC->setModified( 1 ); |
445 | } | 314 | } |
446 | } | 315 | } |
447 | */ | 316 | */ |
448 | 317 | ||
449 | typedef struct EnvVars { | 318 | typedef struct EnvVars { |
450 | char * Name; | 319 | char * Name; |
451 | int Len; | 320 | int Len; |
452 | } EnvVar_t; | 321 | } EnvVar_t; |
453 | 322 | ||
454 | #define AnEV(x) x, sizeof(x)-1 | 323 | #define AnEV(x) x, sizeof(x)-1 |
455 | 324 | ||
456 | static EnvVar_t EV[] = { | 325 | static EnvVar_t EV[] = { |
457 | AnEV( "HOME" ), | 326 | AnEV( "HOME" ), |
458 | AnEV( "LOGNAME" ), | 327 | AnEV( "LOGNAME" ), |
459 | AnEV( "USER" ), | 328 | AnEV( "USER" ), |
460 | AnEV( "LD_LIBRARY_PATH" ), | 329 | AnEV( "LD_LIBRARY_PATH" ), |
461 | AnEV( "PATH" ), | 330 | AnEV( "PATH" ), |
462 | AnEV( "QTDIR" ), | 331 | AnEV( "QTDIR" ), |
463 | AnEV( "OPIEDIR" ), | 332 | AnEV( "OPIEDIR" ), |
464 | AnEV( "SHELL" ), | 333 | AnEV( "SHELL" ), |
465 | { NULL, 0 } | 334 | { NULL, 0 } |
466 | }; | 335 | }; |
467 | 336 | ||
468 | void TheNSResources::detectCurrentUser( void ) { | 337 | void TheNSResources::detectCurrentUser( void ) { |
469 | // find current running qpe | 338 | // find current running qpe |
470 | QString QPEEnvFile = ""; | 339 | QString QPEEnvFile = ""; |
471 | 340 | ||
472 | CurrentUser.UserName = ""; | 341 | CurrentUser.UserName = ""; |
473 | CurrentUser.HomeDir = ""; | 342 | CurrentUser.HomeDir = ""; |
474 | 343 | ||
475 | if( getenv( "OPIEDIR" ) == 0 ) { | 344 | if( getenv( "OPIEDIR" ) == 0 ) { |
476 | // nothing known | 345 | // nothing known |
477 | { // open proc dir and find all dirs in it | 346 | { // open proc dir and find all dirs in it |
478 | QRegExp R("[0-9]+"); | 347 | QRegExp R("[0-9]+"); |
479 | QDir ProcDir( "/proc" ); | 348 | QDir ProcDir( "/proc" ); |
480 | QFileInfo FI; | 349 | QFileInfo FI; |
481 | QStringList EL = ProcDir.entryList( QDir::Dirs ); | 350 | QStringList EL = ProcDir.entryList( QDir::Dirs ); |
482 | 351 | ||
483 | // print it out | 352 | // print it out |
484 | for ( QStringList::Iterator it = EL.begin(); | 353 | for ( QStringList::Iterator it = EL.begin(); |
485 | it != EL.end(); | 354 | it != EL.end(); |
486 | ++it ) { | 355 | ++it ) { |
487 | if( R.match( (*it) ) >= 0 ) { | 356 | if( R.match( (*it) ) >= 0 ) { |
488 | QString S = ProcDir.path()+"/"+ (*it); | 357 | QString S = ProcDir.path()+"/"+ (*it); |
489 | S.append( "/exe" ); | 358 | S.append( "/exe" ); |
490 | FI.setFile( S ); | 359 | FI.setFile( S ); |
491 | // get the link | 360 | // get the link |
492 | S = FI.readLink(); | 361 | S = FI.readLink(); |
493 | if( S.right( 8 ) == "/bin/qpe" ) { | 362 | if( S.right( 8 ) == "/bin/qpe" ) { |
494 | // found running qpe | 363 | // found running qpe |
495 | QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); | 364 | QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); |
496 | break; | 365 | break; |
497 | } | 366 | } |
498 | } | 367 | } |
499 | } | 368 | } |
500 | } | 369 | } |
501 | 370 | ||
502 | if( QPEEnvFile.isEmpty() ) { | 371 | if( QPEEnvFile.isEmpty() ) { |
503 | // could not find qpe | 372 | // could not find qpe |
504 | Log(("Could not find qpe\n" )); | 373 | Log(("Could not find qpe\n" )); |
505 | return; | 374 | return; |
506 | } | 375 | } |
507 | 376 | ||
508 | // FI now contains path ProcDir to the cmd dir | 377 | // FI now contains path ProcDir to the cmd dir |
509 | { char * Buf = 0; | 378 | { char * Buf = 0; |
510 | char TB[1024]; | 379 | char TB[1024]; |
511 | long BufSize = 0; | 380 | long BufSize = 0; |
512 | int fd; | 381 | int fd; |
513 | int rd; | 382 | int rd; |
514 | 383 | ||
515 | fd = open( QPEEnvFile.latin1(), O_RDONLY ); | 384 | fd = open( QPEEnvFile.latin1(), O_RDONLY ); |
516 | if( fd < 0 ) { | 385 | if( fd < 0 ) { |
517 | Log(("Could not open %s : %d\n", | 386 | Log(("Could not open %s : %d\n", |
518 | QPEEnvFile.latin1(), errno )); | 387 | QPEEnvFile.latin1(), errno )); |
519 | return; | 388 | return; |
520 | } | 389 | } |
521 | 390 | ||
522 | while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { | 391 | while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { |
523 | Buf = (char *)realloc( Buf, BufSize+rd ); | 392 | Buf = (char *)realloc( Buf, BufSize+rd ); |
524 | memcpy( Buf+BufSize, TB, rd ); | 393 | memcpy( Buf+BufSize, TB, rd ); |
525 | BufSize += rd; | 394 | BufSize += rd; |
526 | } | 395 | } |
527 | 396 | ||
528 | char * Data = Buf; | 397 | char * Data = Buf; |
529 | char * DataEnd = Data+BufSize-1; | 398 | char * DataEnd = Data+BufSize-1; |
530 | 399 | ||
531 | // get env items out of list | 400 | // get env items out of list |
532 | while( Data < DataEnd ) { | 401 | while( Data < DataEnd ) { |
533 | 402 | ||
534 | EnvVar_t * Run = EV; | 403 | EnvVar_t * Run = EV; |
535 | while( Run->Name ) { | 404 | while( Run->Name ) { |
536 | if( strncmp( Data, Run->Name, Run->Len ) == 0 && | 405 | if( strncmp( Data, Run->Name, Run->Len ) == 0 && |
537 | Data[Run->Len] == '=' | 406 | Data[Run->Len] == '=' |
538 | ) { | 407 | ) { |
539 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | 408 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); |
540 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | 409 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = |
541 | strdup( Data ); | 410 | strdup( Data ); |
542 | 411 | ||
543 | if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { | 412 | if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { |
544 | // put OPIEDIR in env | 413 | // put OPIEDIR in env |
545 | putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); | 414 | putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); |
546 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { | 415 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { |
547 | CurrentUser.HomeDir = Data+5; | 416 | CurrentUser.HomeDir = Data+5; |
548 | } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { | 417 | } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { |
549 | CurrentUser.UserName = Data+8; | 418 | CurrentUser.UserName = Data+8; |
550 | } | 419 | } |
551 | break; | 420 | break; |
552 | } | 421 | } |
553 | Run ++; | 422 | Run ++; |
554 | } | 423 | } |
555 | 424 | ||
556 | Data += strlen( Data )+1; | 425 | Data += strlen( Data )+1; |
557 | } | 426 | } |
558 | 427 | ||
559 | free( Buf ); | 428 | free( Buf ); |
560 | 429 | ||
561 | if( ! CurrentUser.UserName.isEmpty() ) { | 430 | if( ! CurrentUser.UserName.isEmpty() ) { |
562 | // find user info | 431 | // find user info |
563 | struct passwd pwd; | 432 | struct passwd pwd; |
564 | struct passwd * pwdres; | 433 | struct passwd * pwdres; |
565 | 434 | ||
566 | if( getpwnam_r( CurrentUser.UserName.latin1(), | 435 | if( getpwnam_r( CurrentUser.UserName.latin1(), |
567 | &pwd, TB, sizeof(TB), &pwdres ) || | 436 | &pwd, TB, sizeof(TB), &pwdres ) || |
568 | pwdres == 0 ) { | 437 | pwdres == 0 ) { |
569 | Log(("Could not determine user %s : %d\n", | 438 | Log(("Could not determine user %s : %d\n", |
570 | CurrentUser.UserName.latin1(), errno )); | 439 | CurrentUser.UserName.latin1(), errno )); |
571 | return; | 440 | return; |
572 | } | 441 | } |
573 | CurrentUser.Uid = pwd.pw_uid; | 442 | CurrentUser.Uid = pwd.pw_uid; |
574 | CurrentUser.Gid = pwd.pw_gid; | 443 | CurrentUser.Gid = pwd.pw_gid; |
575 | } else{ | 444 | } else{ |
576 | CurrentUser.Uid = | 445 | CurrentUser.Uid = |
577 | CurrentUser.Gid = -1; | 446 | CurrentUser.Gid = -1; |
578 | } | 447 | } |
579 | } | 448 | } |
580 | 449 | ||
581 | } else { | 450 | } else { |
582 | char * X; | 451 | char * X; |
583 | QString S; | 452 | QString S; |
584 | 453 | ||
585 | EnvVar_t * Run = EV; | 454 | EnvVar_t * Run = EV; |
586 | while( Run->Name ) { | 455 | while( Run->Name ) { |
587 | 456 | ||
588 | if( ( X = getenv( Run->Name ) ) ) { | 457 | if( ( X = getenv( Run->Name ) ) ) { |
589 | Log(( "Env : %s = %s\n", Run->Name, X )); | 458 | Log(( "Env : %s = %s\n", Run->Name, X )); |
590 | 459 | ||
591 | S.sprintf( "%s=%s", Run->Name, X ); | 460 | S.sprintf( "%s=%s", Run->Name, X ); |
592 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | 461 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); |
593 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | 462 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = |
594 | strdup( S.latin1() ); | 463 | strdup( S.latin1() ); |
595 | 464 | ||
596 | if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { | 465 | if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { |
597 | CurrentUser.UserName = X; | 466 | CurrentUser.UserName = X; |
598 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { | 467 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { |
599 | CurrentUser.HomeDir = X; | 468 | CurrentUser.HomeDir = X; |
600 | } // regulare env var | 469 | } // regulare env var |
601 | } else { | 470 | } else { |
602 | Log(("Could not determine %s\n", Run->Name )); | 471 | Log(("Could not determine %s\n", Run->Name )); |
603 | } | 472 | } |
604 | Run ++; | 473 | Run ++; |
605 | } | 474 | } |
606 | 475 | ||
607 | CurrentUser.Uid = getuid(); | 476 | CurrentUser.Uid = getuid(); |
608 | CurrentUser.Gid = getgid(); | 477 | CurrentUser.Gid = getgid(); |
609 | } | 478 | } |
610 | } | 479 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 421a433..b27cda1 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h | |||
@@ -1,183 +1,153 @@ | |||
1 | #ifndef __RESOURCES__H | 1 | #ifndef __RESOURCES__H |
2 | #define __RESOURCES__H | 2 | #define __RESOURCES__H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qdict.h> | 5 | #include <qdict.h> |
6 | #include <qmap.h> | 6 | #include <qmap.h> |
7 | #include <qlist.h> | 7 | #include <qlist.h> |
8 | #include "netnode.h" | 8 | #include "netnode.h" |
9 | #include "systemfile.h" | 9 | #include "systemfile.h" |
10 | #include "system.h" | 10 | #include "system.h" |
11 | 11 | ||
12 | class QLibrary; | 12 | class QLibrary; |
13 | class QPixmap; | 13 | class QPixmap; |
14 | class ANetNode; | 14 | class ANetNode; |
15 | class ANetNodeInstance; | 15 | class ANetNodeInstance; |
16 | 16 | ||
17 | namespace Opie { | 17 | namespace Opie { |
18 | namespace Core { | 18 | namespace Core { |
19 | class OPluginLoader; | 19 | class OPluginLoader; |
20 | class OPluginManager; | 20 | class OPluginManager; |
21 | } | 21 | } |
22 | } | 22 | } |
23 | 23 | ||
24 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); | 24 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); |
25 | 25 | ||
26 | class CurrentQPEUser { | 26 | class CurrentQPEUser { |
27 | 27 | ||
28 | public : | 28 | public : |
29 | CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} | 29 | CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} |
30 | 30 | ||
31 | inline bool known( void ) | 31 | inline bool known( void ) |
32 | { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } | 32 | { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } |
33 | 33 | ||
34 | QString UserName; | 34 | QString UserName; |
35 | QString HomeDir; | 35 | QString HomeDir; |
36 | int Uid; | 36 | int Uid; |
37 | int Gid; | 37 | int Gid; |
38 | QArray<char *> EnvList; | 38 | QArray<char *> EnvList; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | #ifdef MYPLUGIN | ||
42 | |||
43 | typedef struct NetNode_S { | ||
44 | ANetNode * NetNode; | ||
45 | QLibrary * TheLibrary; | ||
46 | long NodeCountInLib; | ||
47 | } NetNode_t; | ||
48 | typedef QDict<NetNode_t> Name2NetNode_t; | ||
49 | |||
50 | #else | ||
51 | |||
52 | typedef QDict<ANetNode> Name2NetNode_t; | 41 | typedef QDict<ANetNode> Name2NetNode_t; |
53 | |||
54 | #endif | ||
55 | |||
56 | typedef QDict<ANetNodeInstance > Name2Instance_t; | 42 | typedef QDict<ANetNodeInstance > Name2Instance_t; |
57 | typedef QDict<NodeCollection> Name2Connection_t; | 43 | typedef QDict<NodeCollection> Name2Connection_t; |
58 | typedef QDict<SystemFile> Name2SystemFile_t; | 44 | typedef QDict<SystemFile> Name2SystemFile_t; |
59 | 45 | ||
60 | class TheNSResources { | 46 | class TheNSResources { |
61 | 47 | ||
62 | public : | 48 | public : |
63 | 49 | ||
64 | TheNSResources( void ); | 50 | TheNSResources( void ); |
65 | ~TheNSResources( ); | 51 | ~TheNSResources( ); |
66 | 52 | ||
67 | // give busy feedback | 53 | // give busy feedback |
68 | void busy( bool B ); | 54 | void busy( bool B ); |
69 | 55 | ||
70 | System & system() | 56 | System & system() |
71 | { return *TheSystem; } | 57 | { return *TheSystem; } |
72 | 58 | ||
73 | int assignConnectionNumber(void); | 59 | int assignConnectionNumber(void); |
74 | QPixmap getPixmap( const QString & Name ); | 60 | QPixmap getPixmap( const QString & Name ); |
75 | 61 | ||
76 | Name2NetNode_t & netNodes( void ) | 62 | Name2NetNode_t & netNodes( void ) |
77 | { return AllNodeTypes; } | 63 | { return AllNodeTypes; } |
78 | bool netNodeExists( const QString & X ) | 64 | bool netNodeExists( const QString & X ) |
79 | { return AllNodeTypes.find(X)!=0; } | 65 | { return AllNodeTypes.find(X)!=0; } |
80 | #ifdef MYPLUGIN | ||
81 | ANetNode * findNetNode( const QString & N ) | ||
82 | { NetNode_t * NNT = AllNodeTypes.find(N); | ||
83 | return (NNT) ? NNT->NetNode : 0; | ||
84 | } | ||
85 | #else | ||
86 | ANetNode * findNetNode( const QString & N ) | 66 | ANetNode * findNetNode( const QString & N ) |
87 | { return AllNodeTypes.find(N); | 67 | { return AllNodeTypes.find(N); |
88 | } | 68 | } |
89 | #endif | ||
90 | // define new plugin (=node) | 69 | // define new plugin (=node) |
91 | void addNodeType( const QString & ID, | 70 | void addNodeType( const QString & ID, |
92 | const QString & LongName, | 71 | const QString & LongName, |
93 | const QString & Description ); | 72 | const QString & Description ); |
94 | 73 | ||
95 | Name2SystemFile_t & systemFiles( void ) | 74 | Name2SystemFile_t & systemFiles( void ) |
96 | { return SystemFiles; } | 75 | { return SystemFiles; } |
97 | void addSystemFile( const QString & ID, | 76 | void addSystemFile( const QString & ID, |
98 | const QString & P, | 77 | const QString & P, |
99 | bool KDI ); | 78 | bool KDI ); |
100 | 79 | ||
101 | ANetNodeInstance * createNodeInstance( const QString & S ) | 80 | ANetNodeInstance * createNodeInstance( const QString & S ) |
102 | { ANetNodeInstance * NNI = 0; | 81 | { ANetNode * NN = findNetNode( S ); |
103 | printf( "Find node type %s\n", S.latin1() ); | 82 | |
104 | #ifdef MYPLUGIN | 83 | Log(( "Find node type %s : %p\n", S.latin1(), NN )); |
105 | NetNode_t * NNT = AllNodeTypes[S]; | 84 | |
106 | if( ! NNT ) { | 85 | if( NN == 0 ) |
107 | return 0; | 86 | // type of this instance not found |
108 | } | ||
109 | NNI = NNT->NetNode->createInstance(); | ||
110 | #else | ||
111 | ANetNode * NNT = AllNodeTypes[S]; | ||
112 | if( ! NNT ) { | ||
113 | return 0; | 87 | return 0; |
114 | } | 88 | |
115 | NNI = NNT->createInstance(); | 89 | ANetNodeInstance * NNI = NN->createInstance(); |
116 | #endif | ||
117 | NNI->initialize(); | 90 | NNI->initialize(); |
118 | return NNI; | 91 | return NNI; |
119 | } | 92 | } |
120 | 93 | ||
121 | Name2Instance_t & netNodeInstances( void ) | 94 | Name2Instance_t & netNodeInstances( void ) |
122 | { return AllNodes; } | 95 | { return AllNodes; } |
123 | void addNodeInstance( ANetNodeInstance * I ) | 96 | void addNodeInstance( ANetNodeInstance * I ) |
124 | { AllNodes.insert( I->name(), I ); } | 97 | { AllNodes.insert( I->name(), I ); } |
125 | void removeNodeInstance( const QString & N ) | 98 | void removeNodeInstance( const QString & N ) |
126 | { AllNodes.remove( N );} | 99 | { AllNodes.remove( N );} |
127 | ANetNodeInstance * findNodeInstance( const QString & S ) | 100 | ANetNodeInstance * findNodeInstance( const QString & S ) |
128 | { return AllNodes[S]; } | 101 | { return AllNodes[S]; } |
129 | 102 | ||
130 | const QString & netNode2Name( const char * Type ); | 103 | const QString & netNode2Name( const char * Type ); |
131 | const QString & netNode2Description( const char * Type ); | 104 | const QString & netNode2Description( const char * Type ); |
132 | 105 | ||
133 | void addConnection( NodeCollection * NC ); | 106 | void addConnection( NodeCollection * NC, bool Dangling ); |
134 | void removeConnection( const QString & N ); | 107 | void removeConnection( const QString & N ); |
135 | NodeCollection * findConnection( const QString & N ); | 108 | NodeCollection * findConnection( const QString & N ); |
136 | NodeCollection * getConnection( int nr ); | 109 | NodeCollection * getConnection( int nr ); |
137 | Name2Connection_t & connections( void ) | 110 | Name2Connection_t & connections( void ) |
138 | { return ConnectionsMap; } | 111 | { return ConnectionsMap; } |
112 | Name2Connection_t & danglingConnections( void ) | ||
113 | { return ConnectionsMap; } | ||
139 | 114 | ||
140 | inline bool userKnown( void ) | 115 | inline bool userKnown( void ) |
141 | { return CurrentUser.known(); } | 116 | { return CurrentUser.known(); } |
142 | CurrentQPEUser & currentUser( void ) | 117 | CurrentQPEUser & currentUser( void ) |
143 | { return CurrentUser; } | 118 | { return CurrentUser; } |
144 | 119 | ||
145 | private : | 120 | private : |
146 | 121 | ||
147 | void detectCurrentUser( void ); | 122 | void detectCurrentUser( void ); |
148 | QString tr( const char * path ); | 123 | QString tr( const char * path ); |
149 | 124 | ||
150 | #ifdef MYPLUGIN | ||
151 | void findAvailableNetNodes( const QString &path ); | ||
152 | bool loadNetNode( | ||
153 | const QString &pluginFileName, | ||
154 | const QString &resolveString = "create_plugin"); | ||
155 | #else | ||
156 | void findAvailableNetNodes( void ); | 125 | void findAvailableNetNodes( void ); |
157 | #endif | ||
158 | 126 | ||
159 | QMap< QString, QString> NodeTypeNameMap; | 127 | QMap< QString, QString> NodeTypeNameMap; |
160 | QMap< QString, QString> NodeTypeDescriptionMap; | 128 | QMap< QString, QString> NodeTypeDescriptionMap; |
129 | // list of connections that are valid | ||
161 | Name2Connection_t ConnectionsMap; | 130 | Name2Connection_t ConnectionsMap; |
131 | // list of connection configurations that are not valid | ||
132 | // e.g. because plugins are missing | ||
133 | Name2Connection_t DanglingConnectionsMap; | ||
162 | System * TheSystem; | 134 | System * TheSystem; |
163 | Name2SystemFile_t SystemFiles; | 135 | Name2SystemFile_t SystemFiles; |
164 | 136 | ||
165 | // all node type classes | 137 | // all node type classes |
166 | Name2NetNode_t AllNodeTypes; | 138 | Name2NetNode_t AllNodeTypes; |
167 | 139 | ||
168 | // all nodes | 140 | // all nodes |
169 | Name2Instance_t AllNodes; | 141 | Name2Instance_t AllNodes; |
170 | 142 | ||
171 | CurrentQPEUser CurrentUser; | 143 | CurrentQPEUser CurrentUser; |
172 | 144 | ||
173 | #ifndef MYPLUGIN | ||
174 | Opie::Core::OPluginLoader * Plugins; | 145 | Opie::Core::OPluginLoader * Plugins; |
175 | Opie::Core::OPluginManager * PluginManager; | 146 | Opie::Core::OPluginManager * PluginManager; |
176 | #endif | ||
177 | 147 | ||
178 | }; | 148 | }; |
179 | 149 | ||
180 | extern TheNSResources * _NSResources; | 150 | extern TheNSResources * _NSResources; |
181 | #define NSResources _NSResources | 151 | #define NSResources _NSResources |
182 | 152 | ||
183 | #endif | 153 | #endif |
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 698a941..d76353a 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -1,725 +1,743 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <opie2/odebug.h> | 2 | #include <opie2/odebug.h> |
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qfile.h> | 6 | #include <qfile.h> |
7 | #include <qfileinfo.h> | 7 | #include <qfileinfo.h> |
8 | 8 | ||
9 | #include "nsdata.h" | 9 | #include "nsdata.h" |
10 | #include <netnode.h> | 10 | #include <netnode.h> |
11 | #include <resources.h> | 11 | #include <resources.h> |
12 | 12 | ||
13 | static QString CfgFile; | 13 | static QString CfgFile; |
14 | 14 | ||
15 | NetworkSettingsData::NetworkSettingsData( void ) { | 15 | NetworkSettingsData::NetworkSettingsData( void ) { |
16 | // init global resources structure | 16 | // init global resources structure |
17 | new TheNSResources(); | 17 | new TheNSResources(); |
18 | 18 | ||
19 | if( ! NSResources->userKnown() ) { | 19 | if( ! NSResources->userKnown() ) { |
20 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", | 20 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", |
21 | NSResources->currentUser().HomeDir.latin1(), | 21 | NSResources->currentUser().HomeDir.latin1(), |
22 | NSResources->currentUser().UserName.latin1() )); | 22 | NSResources->currentUser().UserName.latin1() )); |
23 | return; | 23 | return; |
24 | } | 24 | } |
25 | 25 | ||
26 | CfgFile.sprintf( "%s/Settings/NS2.conf", | 26 | CfgFile.sprintf( "%s/Settings/NS2.conf", |
27 | NSResources->currentUser().HomeDir.latin1() ); | 27 | NSResources->currentUser().HomeDir.latin1() ); |
28 | Log(( "Cfg from %s\n", CfgFile.latin1() )); | 28 | Log(( "Cfg from %s\n", CfgFile.latin1() )); |
29 | 29 | ||
30 | // load settings | 30 | // load settings |
31 | loadSettings(); | 31 | loadSettings(); |
32 | 32 | ||
33 | // assign interfaces by scanning /tmp/profile-%s.Up files | 33 | // assign interfaces by scanning /tmp/profile-%s.Up files |
34 | { QDir D( "/tmp" ); | 34 | { QDir D( "/tmp" ); |
35 | QFile * F = new QFile; | 35 | QFile * F = new QFile; |
36 | int profilenr; | 36 | int profilenr; |
37 | QString interfacename; | 37 | QString interfacename; |
38 | QTextStream TS ( F ); | 38 | QTextStream TS ( F ); |
39 | 39 | ||
40 | QStringList SL = D.entryList( "profile-*.up"); | 40 | QStringList SL = D.entryList( "profile-*.up"); |
41 | 41 | ||
42 | Log(( "System reports %d interfaces. Found %d up\n", | 42 | Log(( "System reports %d interfaces. Found %d up\n", |
43 | NSResources->system().interfaces().count(), | 43 | NSResources->system().interfaces().count(), |
44 | SL.count() )); | 44 | SL.count() )); |
45 | 45 | ||
46 | for ( QStringList::Iterator it = SL.begin(); | 46 | for ( QStringList::Iterator it = SL.begin(); |
47 | it != SL.end(); | 47 | it != SL.end(); |
48 | ++it ) { | 48 | ++it ) { |
49 | profilenr = atol( (*it).mid( 8 ).latin1() ); | 49 | profilenr = atol( (*it).mid( 8 ).latin1() ); |
50 | // read the interface store int 'up' | 50 | // read the interface store int 'up' |
51 | F->setName( D.path() + "/" + (*it) ); | 51 | F->setName( D.path() + "/" + (*it) ); |
52 | if( F->open( IO_ReadOnly ) ) { | 52 | if( F->open( IO_ReadOnly ) ) { |
53 | NodeCollection * NC; | 53 | NodeCollection * NC; |
54 | interfacename = TS.readLine(); | 54 | interfacename = TS.readLine(); |
55 | F->close(); | 55 | F->close(); |
56 | 56 | ||
57 | Log(( "Assign interface %s to Profile nr %d\n", | 57 | Log(( "Assign interface %s to Profile nr %d\n", |
58 | interfacename.latin1(), profilenr )); | 58 | interfacename.latin1(), profilenr )); |
59 | 59 | ||
60 | NC = NSResources->getConnection( profilenr ); | 60 | NC = NSResources->getConnection( profilenr ); |
61 | if( NC ) { | 61 | if( NC ) { |
62 | NC->assignInterface( | 62 | NC->assignInterface( |
63 | NSResources->system().findInterface( interfacename ) ); | 63 | NSResources->system().findInterface( interfacename ) ); |
64 | } else { | 64 | } else { |
65 | Log(( "Profile nr %d no longer defined\n", | 65 | Log(( "Profile nr %d no longer defined\n", |
66 | profilenr )); | 66 | profilenr )); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | // saving is done by caller | 73 | // saving is done by caller |
74 | NetworkSettingsData::~NetworkSettingsData( void ) { | 74 | NetworkSettingsData::~NetworkSettingsData( void ) { |
75 | delete NSResources; | 75 | delete NSResources; |
76 | } | 76 | } |
77 | 77 | ||
78 | void NetworkSettingsData::loadSettings( void ) { | 78 | void NetworkSettingsData::loadSettings( void ) { |
79 | QString Line, S; | 79 | QString Line, S; |
80 | QString Attr, Value; | 80 | QString Attr, Value; |
81 | long idx; | 81 | long idx; |
82 | 82 | ||
83 | QFile F( CfgFile ); | 83 | QFile F( CfgFile ); |
84 | QTextStream TS( &F ); | 84 | QTextStream TS( &F ); |
85 | 85 | ||
86 | ForceModified = 0; | 86 | ForceModified = 0; |
87 | 87 | ||
88 | do { | 88 | do { |
89 | 89 | ||
90 | if( ! F.open(IO_ReadOnly) ) | 90 | if( ! F.open(IO_ReadOnly) ) |
91 | break; | 91 | break; |
92 | 92 | ||
93 | /* load the file -> | 93 | /* load the file -> |
94 | 94 | ||
95 | FORMAT : | 95 | FORMAT : |
96 | 96 | ||
97 | [NETNODETYPE] | 97 | [NETNODETYPE] |
98 | Entries ... | 98 | Entries ... |
99 | <EMPTYLINE> | 99 | <EMPTYLINE> |
100 | [connection] | 100 | [connection] |
101 | Name=Name | 101 | Name=Name |
102 | Node=Name | 102 | Node=Name |
103 | <EMPTYLINE> | 103 | <EMPTYLINE> |
104 | */ | 104 | */ |
105 | while( ! TS.atEnd() ) { | 105 | while( ! TS.atEnd() ) { |
106 | S = Line = TS.readLine(); | 106 | S = Line = TS.readLine(); |
107 | 107 | ||
108 | if ( S.isEmpty() || S[0] != '[' ) | 108 | if ( S.isEmpty() || S[0] != '[' ) |
109 | continue; | 109 | continue; |
110 | 110 | ||
111 | S = S.mid( 1, S.length()-2 ); | 111 | S = S.mid( 1, S.length()-2 ); |
112 | 112 | ||
113 | if( ! NSResources ) { | 113 | if( ! NSResources ) { |
114 | continue; | 114 | continue; |
115 | } | 115 | } |
116 | 116 | ||
117 | if( S == "connection" ) { | 117 | if( S == "connection" ) { |
118 | // load connections -> collections of nodes | 118 | // load connections -> collections of nodes |
119 | NodeCollection * NC = new NodeCollection( TS ); | 119 | bool Dangling; |
120 | NSResources->addConnection( NC ); | 120 | NodeCollection * NC = new NodeCollection( TS, Dangling ); |
121 | NSResources->addConnection( NC, Dangling ); | ||
121 | } else { | 122 | } else { |
122 | ANetNode * NN = 0; | 123 | ANetNode * NN = 0; |
123 | ANetNodeInstance* NNI = 0; | 124 | ANetNodeInstance* NNI = 0; |
124 | if( S.startsWith( "nodetype " ) ) { | 125 | if( S.startsWith( "nodetype " ) ) { |
125 | S = S.mid( 9, S.length()-9 ); | 126 | S = S.mid( 9, S.length()-9 ); |
126 | S = deQuote(S); | 127 | S = deQuote(S); |
127 | // try to find netnode | 128 | // try to find netnode |
128 | NN = NSResources->findNetNode( S ); | 129 | NN = NSResources->findNetNode( S ); |
129 | } else { | 130 | } else { |
130 | // try to find instance | 131 | // try to find instance |
131 | NNI = NSResources->createNodeInstance( S ); | 132 | NNI = NSResources->createNodeInstance( S ); |
132 | } | 133 | } |
133 | 134 | ||
134 | if( NN == 0 && NNI == 0 ) { | 135 | if( NN == 0 && NNI == 0 ) { |
135 | LeftOvers.append( Line ); | 136 | LeftOvers.append( Line ); |
136 | } | 137 | do { |
138 | Line = TS.readLine(); | ||
139 | // store even delimiter | ||
140 | LeftOvers.append( Line ); | ||
141 | } while ( ! Line.isEmpty() ); | ||
142 | |||
143 | //next section | ||
144 | continue; | ||
145 | } | ||
137 | 146 | ||
147 | // read entries of this section | ||
138 | do { | 148 | do { |
139 | S = Line = TS.readLine(); | 149 | S = Line = TS.readLine(); |
140 | 150 | ||
141 | if( NN || NNI ) { | 151 | if( S.isEmpty() ) { |
142 | if( S.isEmpty() ) { | 152 | // empty line |
143 | // empty line | 153 | break; |
144 | break; | 154 | } |
145 | } | 155 | idx = S.find( '=' ); |
146 | idx = S.find( '=' ); | 156 | if( idx > 0 ) { |
147 | if( idx > 0 ) { | 157 | Attr = S.left( idx ); |
148 | Attr = S.left( idx ); | 158 | Value = S.mid( idx+1, S.length() ); |
149 | Value = S.mid( idx+1, S.length() ); | 159 | } else { |
150 | } else { | 160 | Value=""; |
151 | Value=""; | 161 | Attr = S; |
152 | Attr = S; | 162 | } |
153 | } | ||
154 | 163 | ||
155 | Value.stripWhiteSpace(); | 164 | Value.stripWhiteSpace(); |
156 | Attr.stripWhiteSpace(); | 165 | Attr.stripWhiteSpace(); |
157 | Attr.lower(); | 166 | Attr.lower(); |
158 | // dequote Attr | 167 | // dequote Attr |
159 | Value = deQuote(Value); | 168 | Value = deQuote(Value); |
160 | 169 | ||
161 | if( NN ) { | 170 | if( NN ) { |
162 | // set the attribute | 171 | // set the attribute |
163 | NN->setAttribute( Attr, Value ); | 172 | NN->setAttribute( Attr, Value ); |
164 | } else { | ||
165 | // set the attribute | ||
166 | NNI->setAttribute( Attr, Value ); | ||
167 | } | ||
168 | } else { | 173 | } else { |
169 | LeftOvers.append( Line ); | 174 | // set the attribute |
170 | // add empty line too as delimiter | 175 | NNI->setAttribute( Attr, Value ); |
171 | if( S.isEmpty() ) { | ||
172 | // empty line | ||
173 | break; | ||
174 | } | ||
175 | } | 176 | } |
176 | } while( 1 ); | 177 | } while( 1 ); |
177 | 178 | ||
178 | if( NNI ) { | 179 | if( NNI ) { |
179 | // loading from file -> exists | 180 | // loading from file -> exists |
180 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); | 181 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); |
181 | NNI->setNew( FALSE ); | 182 | NNI->setNew( FALSE ); |
182 | NSResources->addNodeInstance( NNI ); | 183 | NSResources->addNodeInstance( NNI ); |
183 | } | 184 | } |
185 | |||
184 | if( NN ) { | 186 | if( NN ) { |
185 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); | 187 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); |
186 | } | 188 | } |
187 | } | 189 | } |
188 | } | 190 | } |
189 | 191 | ||
190 | } while( 0 ); | 192 | } while( 0 ); |
191 | 193 | ||
192 | } | 194 | } |
193 | 195 | ||
194 | QString NetworkSettingsData::saveSettings( void ) { | 196 | QString NetworkSettingsData::saveSettings( void ) { |
195 | QString ErrS = ""; | 197 | QString ErrS = ""; |
196 | 198 | ||
197 | if( ! isModified() ) | 199 | if( ! isModified() ) |
198 | return ErrS; | 200 | return ErrS; |
199 | 201 | ||
200 | QString S; | 202 | QString S; |
201 | QFile F( CfgFile + ".bup" ); | 203 | QFile F( CfgFile + ".bup" ); |
202 | 204 | ||
203 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); | 205 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); |
204 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { | 206 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { |
205 | ErrS = qApp->translate( "NetworkSettings", | 207 | ErrS = qApp->translate( "NetworkSettings", |
206 | "<p>Could not save setup to \"%1\" !</p>" ). | 208 | "<p>Could not save setup to \"%1\" !</p>" ). |
207 | arg(CfgFile); | 209 | arg(CfgFile); |
208 | // problem | 210 | // problem |
209 | return ErrS; | 211 | return ErrS; |
210 | } | 212 | } |
211 | 213 | ||
212 | QTextStream TS( &F ); | 214 | QTextStream TS( &F ); |
213 | 215 | ||
214 | // save leftovers | ||
215 | for ( QStringList::Iterator it = LeftOvers.begin(); | ||
216 | it != LeftOvers.end(); ++it ) { | ||
217 | TS << (*it) << endl; | ||
218 | } | ||
219 | |||
220 | // save global configs | 216 | // save global configs |
221 | for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); | 217 | for( QDictIterator<ANetNode> it( NSResources->netNodes() ); |
222 | it.current(); | 218 | it.current(); |
223 | ++it ) { | 219 | ++it ) { |
224 | TS << "[nodetype " | 220 | TS << "[nodetype " |
225 | << quote( QString( it.current()->NetNode->name() ) ) | 221 | << quote( QString( it.current()->name() ) ) |
226 | << "]" | 222 | << "]" |
227 | << endl; | 223 | << endl; |
228 | 224 | ||
229 | it.current()->NetNode->saveAttributes( TS ); | 225 | it.current()->saveAttributes( TS ); |
230 | TS << endl; | 226 | TS << endl; |
231 | } | 227 | } |
232 | 228 | ||
229 | // save leftovers | ||
230 | for ( QStringList::Iterator it = LeftOvers.begin(); | ||
231 | it != LeftOvers.end(); ++it ) { | ||
232 | TS << (*it) << endl; | ||
233 | } | ||
234 | |||
235 | // save all netnode instances | ||
236 | { ANetNodeInstance * NNI; | ||
237 | for( QDictIterator<ANetNodeInstance> nit( | ||
238 | NSResources->netNodeInstances()); | ||
239 | nit.current(); | ||
240 | ++nit ) { | ||
241 | // header | ||
242 | NNI = nit.current(); | ||
243 | TS << '[' | ||
244 | << QString(NNI->nodeClass()->name()) | ||
245 | << ']' | ||
246 | << endl; | ||
247 | NNI->saveAttributes( TS ); | ||
248 | TS << endl; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | // good connections | ||
233 | { Name2Connection_t & M = NSResources->connections(); | 253 | { Name2Connection_t & M = NSResources->connections(); |
234 | ANetNodeInstance * NNI; | ||
235 | 254 | ||
236 | // for all connections | 255 | // for all connections |
237 | for( QDictIterator<NodeCollection> it(M); | 256 | for( QDictIterator<NodeCollection> it(M); |
238 | it.current(); | 257 | it.current(); |
239 | ++it ) { | 258 | ++it ) { |
240 | // all nodes in those connections | 259 | TS << "[connection]" << endl; |
241 | for( QListIterator<ANetNodeInstance> nit(*(it.current())); | 260 | it.current()->save(TS); |
242 | nit.current(); | 261 | } |
243 | ++nit ) { | 262 | } |
244 | // header | ||
245 | NNI = nit.current(); | ||
246 | TS << '[' | ||
247 | << QString(NNI->nodeClass()->name()) | ||
248 | << ']' | ||
249 | << endl; | ||
250 | NNI->saveAttributes( TS ); | ||
251 | TS << endl; | ||
252 | } | ||
253 | 263 | ||
264 | // save dangling connections | ||
265 | { Name2Connection_t & M = NSResources->danglingConnections(); | ||
266 | |||
267 | // for all connections | ||
268 | for( QDictIterator<NodeCollection> it(M); | ||
269 | it.current(); | ||
270 | ++it ) { | ||
254 | TS << "[connection]" << endl; | 271 | TS << "[connection]" << endl; |
255 | it.current()->save(TS); | 272 | it.current()->save(TS); |
256 | } | 273 | } |
257 | } | 274 | } |
258 | 275 | ||
259 | QDir D("."); | 276 | QDir D("."); |
260 | D.rename( CfgFile + ".bup", CfgFile ); | 277 | D.rename( CfgFile + ".bup", CfgFile ); |
261 | 278 | ||
262 | // | 279 | // |
263 | // proper files AND system files regenerated | 280 | // proper files AND system files regenerated |
264 | // | 281 | // |
265 | 282 | ||
266 | 283 | ||
267 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | 284 | for( QDictIterator<NodeCollection> it(NSResources->connections()); |
268 | it.current(); | 285 | it.current(); |
269 | ++it ) { | 286 | ++it ) { |
270 | it.current()->setModified( 0 ); | 287 | it.current()->setModified( 0 ); |
271 | } | 288 | } |
272 | 289 | ||
273 | return ErrS; | 290 | return ErrS; |
274 | } | 291 | } |
275 | 292 | ||
276 | QString NetworkSettingsData::generateSettings( void ) { | 293 | QString NetworkSettingsData::generateSettings( void ) { |
277 | QString S = ""; | 294 | QString S = ""; |
278 | Name2SystemFile_t & SFM = NSResources->systemFiles(); | 295 | Name2SystemFile_t & SFM = NSResources->systemFiles(); |
279 | Name2Connection_t & M = NSResources->connections(); | 296 | Name2Connection_t & M = NSResources->connections(); |
280 | NodeCollection * NC; | 297 | NodeCollection * NC; |
281 | ANetNodeInstance * NNI; | 298 | ANetNodeInstance * NNI; |
282 | ANetNodeInstance * FirstWithData; | 299 | ANetNodeInstance * FirstWithData; |
283 | RuntimeInfo * CurDev; | 300 | RuntimeInfo * CurDev; |
284 | ANetNode * NN, * CurDevNN = 0; | 301 | ANetNode * NN, * CurDevNN = 0; |
285 | long NoOfDevs; | 302 | long NoOfDevs; |
286 | long DevCtStart; | 303 | long DevCtStart; |
287 | bool needToGenerate; | 304 | bool needToGenerate; |
288 | 305 | ||
289 | // regenerate system files | 306 | // regenerate system files |
290 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | 307 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
291 | 308 | ||
292 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 309 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
293 | nnit.current(); | 310 | nnit.current(); |
294 | ++nnit ) { | 311 | ++nnit ) { |
295 | { QStringList SL; | 312 | bool FirstItem = 1; |
296 | bool FirstItem = 1; | 313 | bool Generated = 0; |
297 | bool Generated = 0; | ||
298 | 314 | ||
299 | CurDevNN = nnit.current()->NetNode; | 315 | CurDevNN = nnit.current(); |
316 | |||
317 | { QStringList SL; | ||
300 | SL = CurDevNN->properFiles(); | 318 | SL = CurDevNN->properFiles(); |
301 | 319 | ||
302 | for ( QStringList::Iterator it = SL.begin(); | 320 | for ( QStringList::Iterator it = SL.begin(); |
303 | it != SL.end(); | 321 | it != SL.end(); |
304 | ++it ) { | 322 | ++it ) { |
305 | 323 | ||
306 | Generated = 0; | 324 | Generated = 0; |
307 | FirstItem = 1; | 325 | FirstItem = 1; |
308 | // iterate over NNI's of this class | 326 | // iterate over NNI's of this class |
309 | for( QDictIterator<ANetNodeInstance> nniit( | 327 | for( QDictIterator<ANetNodeInstance> nniit( |
310 | NSResources->netNodeInstances() ); | 328 | NSResources->netNodeInstances() ); |
311 | nniit.current(); | 329 | nniit.current(); |
312 | ++nniit ) { | 330 | ++nniit ) { |
313 | if( nniit.current()->nodeClass() != CurDevNN ) | 331 | if( nniit.current()->nodeClass() != CurDevNN ) |
314 | // different class | 332 | // different class |
315 | continue; | 333 | continue; |
316 | 334 | ||
317 | // open proper file | 335 | // open proper file |
318 | { SystemFile SF( (*it) ); | 336 | { SystemFile SF( (*it) ); |
319 | 337 | ||
320 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { | 338 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { |
321 | // cannot open | 339 | // cannot open |
322 | S = qApp->translate( "NetworkSettings", | 340 | S = qApp->translate( "NetworkSettings", |
323 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 341 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
324 | arg( (*it) ).arg( CurDevNN->name() ); | 342 | arg( (*it) ).arg( CurDevNN->name() ); |
325 | return S; | 343 | return S; |
326 | } | 344 | } |
327 | 345 | ||
328 | if( ! SF.open() ) { | 346 | if( ! SF.open() ) { |
329 | S = qApp->translate( "NetworkSettings", | 347 | S = qApp->translate( "NetworkSettings", |
330 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 348 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
331 | arg( (*it) ).arg( CurDevNN->name() ); | 349 | arg( (*it) ).arg( CurDevNN->name() ); |
332 | return S; | 350 | return S; |
333 | } | 351 | } |
334 | 352 | ||
335 | // preamble on first | 353 | // preamble on first |
336 | if( FirstItem ) { | 354 | if( FirstItem ) { |
337 | if( CurDevNN->generatePreamble( SF ) == 2 ) { | 355 | if( CurDevNN->generatePreamble( SF ) == 2 ) { |
338 | S = qApp->translate( "NetworkSettings", | 356 | S = qApp->translate( "NetworkSettings", |
339 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). | 357 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
340 | arg( (*it) ). | 358 | arg( (*it) ). |
341 | arg( CurDevNN->name() ); | 359 | arg( CurDevNN->name() ); |
342 | return S; | 360 | return S; |
343 | } | 361 | } |
344 | } | 362 | } |
345 | FirstItem = 0; | 363 | FirstItem = 0; |
346 | Generated = 1; | 364 | Generated = 1; |
347 | 365 | ||
348 | // item specific | 366 | // item specific |
349 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { | 367 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { |
350 | S = qApp->translate( "NetworkSettings", | 368 | S = qApp->translate( "NetworkSettings", |
351 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). | 369 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). |
352 | arg( nniit.current()->name() ). | 370 | arg( nniit.current()->name() ). |
353 | arg( (*it) ). | 371 | arg( (*it) ). |
354 | arg( CurDevNN->name() ); | 372 | arg( CurDevNN->name() ); |
355 | return S; | 373 | return S; |
356 | } | 374 | } |
357 | } | 375 | } |
358 | } | 376 | } |
359 | 377 | ||
360 | if( Generated ) { | 378 | if( Generated ) { |
361 | SystemFile SF( (*it) ); | 379 | SystemFile SF( (*it) ); |
362 | 380 | ||
363 | if( CurDevNN->openFile( SF, 0 ) && | 381 | if( CurDevNN->openFile( SF, 0 ) && |
364 | ! SF.path().isEmpty() | 382 | ! SF.path().isEmpty() |
365 | ) { | 383 | ) { |
366 | 384 | ||
367 | if( ! SF.open() ) { | 385 | if( ! SF.open() ) { |
368 | S = qApp->translate( "NetworkSettings", | 386 | S = qApp->translate( "NetworkSettings", |
369 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 387 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
370 | arg( (*it) ).arg( CurDevNN->name() ); | 388 | arg( (*it) ).arg( CurDevNN->name() ); |
371 | return S; | 389 | return S; |
372 | } | 390 | } |
373 | 391 | ||
374 | if( CurDevNN->generatePostamble( SF ) == 2 ) { | 392 | if( CurDevNN->generatePostamble( SF ) == 2 ) { |
375 | S = qApp->translate( "NetworkSettings", | 393 | S = qApp->translate( "NetworkSettings", |
376 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). | 394 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
377 | arg( (*it) ). | 395 | arg( (*it) ). |
378 | arg( CurDevNN->name() ); | 396 | arg( CurDevNN->name() ); |
379 | return S; | 397 | return S; |
380 | } | 398 | } |
381 | } // no postamble | 399 | } // no postamble |
382 | } | 400 | } |
383 | } | 401 | } |
384 | } | 402 | } |
385 | } | 403 | } |
386 | 404 | ||
387 | // | 405 | // |
388 | // generate all registered files | 406 | // generate all registered files |
389 | // | 407 | // |
390 | for( QDictIterator<SystemFile> sfit(SFM); | 408 | for( QDictIterator<SystemFile> sfit(SFM); |
391 | sfit.current(); | 409 | sfit.current(); |
392 | ++sfit ) { | 410 | ++sfit ) { |
393 | SystemFile * SF; | 411 | SystemFile * SF; |
394 | 412 | ||
395 | SF = sfit.current(); | 413 | SF = sfit.current(); |
396 | 414 | ||
397 | // reset all | 415 | // reset all |
398 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 416 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
399 | nnit.current(); | 417 | nnit.current(); |
400 | ++nnit ) { | 418 | ++nnit ) { |
401 | nnit.current()->NetNode->setDone(0); | 419 | nnit.current()->setDone(0); |
402 | } | 420 | } |
403 | 421 | ||
404 | for( QDictIterator<ANetNodeInstance> nniit( | 422 | for( QDictIterator<ANetNodeInstance> nniit( |
405 | NSResources->netNodeInstances() ); | 423 | NSResources->netNodeInstances() ); |
406 | nniit.current(); | 424 | nniit.current(); |
407 | ++nniit ) { | 425 | ++nniit ) { |
408 | nniit.current()->setDone(0); | 426 | nniit.current()->setDone(0); |
409 | } | 427 | } |
410 | 428 | ||
411 | for( QDictIterator<NodeCollection> ncit(M); | 429 | for( QDictIterator<NodeCollection> ncit(M); |
412 | ncit.current(); | 430 | ncit.current(); |
413 | ++ncit ) { | 431 | ++ncit ) { |
414 | ncit.current()->setDone(0); | 432 | ncit.current()->setDone(0); |
415 | } | 433 | } |
416 | 434 | ||
417 | Log( ( "Generating system file %s\n", SF->name().latin1() )); | 435 | Log( ( "Generating system file %s\n", SF->name().latin1() )); |
418 | 436 | ||
419 | needToGenerate = 0; | 437 | needToGenerate = 0; |
420 | 438 | ||
421 | // are there netnodes that have instances and need | 439 | // are there netnodes that have instances and need |
422 | // to write data in this system file ? | 440 | // to write data in this system file ? |
423 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 441 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
424 | ! needToGenerate && nnit.current(); | 442 | ! needToGenerate && nnit.current(); |
425 | ++nnit ) { | 443 | ++nnit ) { |
426 | 444 | ||
427 | NN = nnit.current()->NetNode; | 445 | NN = nnit.current(); |
428 | 446 | ||
429 | if( NN->hasDataForFile( *SF ) ) { | 447 | if( NN->hasDataForFile( *SF ) ) { |
430 | // netnode can have data | 448 | // netnode can have data |
431 | 449 | ||
432 | // are there instances of this node ? | 450 | // are there instances of this node ? |
433 | for( QDictIterator<ANetNodeInstance> nniit( | 451 | for( QDictIterator<ANetNodeInstance> nniit( |
434 | NSResources->netNodeInstances() ); | 452 | NSResources->netNodeInstances() ); |
435 | ! needToGenerate && nniit.current(); | 453 | ! needToGenerate && nniit.current(); |
436 | ++nniit ) { | 454 | ++nniit ) { |
437 | if( nniit.current()->nodeClass() == NN ) { | 455 | if( nniit.current()->nodeClass() == NN ) { |
438 | // yes | 456 | // yes |
439 | Log(("Node %s has data\n", | 457 | Log(("Node %s has data\n", |
440 | nniit.current()->name() )); | 458 | nniit.current()->name() )); |
441 | needToGenerate = 1; | 459 | needToGenerate = 1; |
442 | break; | 460 | break; |
443 | } | 461 | } |
444 | } | 462 | } |
445 | } | 463 | } |
446 | } | 464 | } |
447 | 465 | ||
448 | if( ! needToGenerate ) { | 466 | if( ! needToGenerate ) { |
449 | // no instances found that might need to write data | 467 | // no instances found that might need to write data |
450 | // in this systemfile | 468 | // in this systemfile |
451 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); | 469 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); |
452 | continue; | 470 | continue; |
453 | } | 471 | } |
454 | 472 | ||
455 | // ok generate this system file | 473 | // ok generate this system file |
456 | if( ! SF->open() ) { | 474 | if( ! SF->open() ) { |
457 | S = qApp->translate( "NetworkSettings", | 475 | S = qApp->translate( "NetworkSettings", |
458 | "<p>Cannot open system file \"%1\"</p>" ). | 476 | "<p>Cannot open system file \"%1\"</p>" ). |
459 | arg( SF->name() ); | 477 | arg( SF->name() ); |
460 | return S; | 478 | return S; |
461 | } | 479 | } |
462 | 480 | ||
463 | // global presection for this system file | 481 | // global presection for this system file |
464 | if( ! SF->preSection() ) { | 482 | if( ! SF->preSection() ) { |
465 | S = qApp->translate( "NetworkSettings", | 483 | S = qApp->translate( "NetworkSettings", |
466 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). | 484 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). |
467 | arg( SF->name() ); | 485 | arg( SF->name() ); |
468 | return S; | 486 | return S; |
469 | } | 487 | } |
470 | 488 | ||
471 | // find connections that want to write to this file | 489 | // find connections that want to write to this file |
472 | for( QDictIterator<NodeCollection> ncit(M); | 490 | for( QDictIterator<NodeCollection> ncit(M); |
473 | ncit.current(); | 491 | ncit.current(); |
474 | ++ncit ) { | 492 | ++ncit ) { |
475 | 493 | ||
476 | NC = ncit.current(); | 494 | NC = ncit.current(); |
477 | 495 | ||
478 | if( NC->done() ) { | 496 | if( NC->done() ) { |
479 | // already done | 497 | // already done |
480 | continue; | 498 | continue; |
481 | } | 499 | } |
482 | 500 | ||
483 | if( ! NC->hasDataForFile( *SF ) ) { | 501 | if( ! NC->hasDataForFile( *SF ) ) { |
484 | // no data | 502 | // no data |
485 | continue; | 503 | continue; |
486 | } | 504 | } |
487 | 505 | ||
488 | Log(("Generating %s for connection %s\n", | 506 | Log(("Generating %s for connection %s\n", |
489 | SF->name().latin1(), NC->name().latin1() )); | 507 | SF->name().latin1(), NC->name().latin1() )); |
490 | // find highest item that wants to write data to this file | 508 | // find highest item that wants to write data to this file |
491 | FirstWithData = NC->firstWithDataForFile( *SF ); | 509 | FirstWithData = NC->firstWithDataForFile( *SF ); |
492 | 510 | ||
493 | // find device on which this connection works | 511 | // find device on which this connection works |
494 | CurDev = NC->device(); | 512 | CurDev = NC->device(); |
495 | // class of that node | 513 | // class of that node |
496 | CurDevNN = CurDev->netNode()->nodeClass(); | 514 | CurDevNN = CurDev->netNode()->nodeClass(); |
497 | 515 | ||
498 | if( ! FirstWithData->nodeClass()->done() ) { | 516 | if( ! FirstWithData->nodeClass()->done() ) { |
499 | // generate fixed part | 517 | // generate fixed part |
500 | if( ! SF->preDeviceSection( CurDevNN ) ) { | 518 | if( ! SF->preDeviceSection( CurDevNN ) ) { |
501 | S = qApp->translate( "NetworkSettings", | 519 | S = qApp->translate( "NetworkSettings", |
502 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). | 520 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). |
503 | arg( SF->name() ); | 521 | arg( SF->name() ); |
504 | return S; | 522 | return S; |
505 | } | 523 | } |
506 | 524 | ||
507 | if( FirstWithData->nodeClass()->generateFile( | 525 | if( FirstWithData->nodeClass()->generateFile( |
508 | *SF, | 526 | *SF, |
509 | FirstWithData, | 527 | FirstWithData, |
510 | -2 ) == 2 ) { | 528 | -2 ) == 2 ) { |
511 | S = qApp->translate( "NetworkSettings", | 529 | S = qApp->translate( "NetworkSettings", |
512 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). | 530 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). |
513 | arg( SF->name() ). | 531 | arg( SF->name() ). |
514 | arg( CurDevNN->name() ); | 532 | arg( CurDevNN->name() ); |
515 | return S; | 533 | return S; |
516 | } | 534 | } |
517 | FirstWithData->nodeClass()->setDone( 1 ); | 535 | FirstWithData->nodeClass()->setDone( 1 ); |
518 | Log(( "Systemfile %s for node instance %s is done\n", | 536 | Log(( "Systemfile %s for node instance %s is done\n", |
519 | SF->name().latin1(), | 537 | SF->name().latin1(), |
520 | FirstWithData->name() )); | 538 | FirstWithData->name() )); |
521 | } | 539 | } |
522 | 540 | ||
523 | NoOfDevs = 0; | 541 | NoOfDevs = 0; |
524 | DevCtStart = -1; | 542 | DevCtStart = -1; |
525 | 543 | ||
526 | if( SF->knowsDeviceInstances() ) { | 544 | if( SF->knowsDeviceInstances() ) { |
527 | DevCtStart = 0; | 545 | DevCtStart = 0; |
528 | NoOfDevs = CurDevNN->instanceCount(); | 546 | NoOfDevs = CurDevNN->instanceCount(); |
529 | } | 547 | } |
530 | 548 | ||
531 | if( ! CurDev->netNode()->nodeClass()->done() ) { | 549 | if( ! CurDev->netNode()->nodeClass()->done() ) { |
532 | // first time this device is handled | 550 | // first time this device is handled |
533 | // generate common device specific part | 551 | // generate common device specific part |
534 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 552 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
535 | 553 | ||
536 | if( FirstWithData->nodeClass()->generateFile( | 554 | if( FirstWithData->nodeClass()->generateFile( |
537 | *SF, CurDev->netNode(), i ) == 2 ) { | 555 | *SF, CurDev->netNode(), i ) == 2 ) { |
538 | S = qApp->translate( "NetworkSettings", | 556 | S = qApp->translate( "NetworkSettings", |
539 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). | 557 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). |
540 | arg( SF->name() ). | 558 | arg( SF->name() ). |
541 | arg( CurDevNN->name() ); | 559 | arg( CurDevNN->name() ); |
542 | return S; | 560 | return S; |
543 | } | 561 | } |
544 | } | 562 | } |
545 | CurDev->netNode()->nodeClass()->setDone( 1 ); | 563 | CurDev->netNode()->nodeClass()->setDone( 1 ); |
546 | 564 | ||
547 | Log(( "Systemfile %s for Nodeclass %s is done\n", | 565 | Log(( "Systemfile %s for Nodeclass %s is done\n", |
548 | SF->name().latin1(), | 566 | SF->name().latin1(), |
549 | CurDev->netNode()->nodeClass()->name() | 567 | CurDev->netNode()->nodeClass()->name() |
550 | )); | 568 | )); |
551 | } | 569 | } |
552 | 570 | ||
553 | // generate profile specific info | 571 | // generate profile specific info |
554 | // for all nodeconnections that work on the same device | 572 | // for all nodeconnections that work on the same device |
555 | for( QDictIterator<NodeCollection> ncit2(M); | 573 | for( QDictIterator<NodeCollection> ncit2(M); |
556 | ncit2.current(); | 574 | ncit2.current(); |
557 | ++ncit2 ) { | 575 | ++ncit2 ) { |
558 | 576 | ||
559 | if( ncit2.current()->device() != CurDev ) { | 577 | if( ncit2.current()->device() != CurDev ) { |
560 | // different device | 578 | // different device |
561 | continue; | 579 | continue; |
562 | } | 580 | } |
563 | 581 | ||
564 | Log(("Connection %s of family %s\n", | 582 | Log(("Connection %s of family %s\n", |
565 | ncit2.current()->name().latin1(), | 583 | ncit2.current()->name().latin1(), |
566 | CurDev->name() )); | 584 | CurDev->name() )); |
567 | // generate | 585 | // generate |
568 | NNI = ncit2.current()->firstWithDataForFile( *SF ); | 586 | NNI = ncit2.current()->firstWithDataForFile( *SF ); |
569 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 587 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
570 | if( ! SF->preNodeSection( NNI, i ) ) { | 588 | if( ! SF->preNodeSection( NNI, i ) ) { |
571 | S = qApp->translate( "NetworkSettings", | 589 | S = qApp->translate( "NetworkSettings", |
572 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 590 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
573 | arg( SF->name() ). | 591 | arg( SF->name() ). |
574 | arg( CurDevNN->name() ); | 592 | arg( CurDevNN->name() ); |
575 | return S; | 593 | return S; |
576 | } | 594 | } |
577 | 595 | ||
578 | switch( NNI->generateFile( *SF, i ) ) { | 596 | switch( NNI->generateFile( *SF, i ) ) { |
579 | case 0 : | 597 | case 0 : |
580 | (*SF) << endl; | 598 | (*SF) << endl; |
581 | break; | 599 | break; |
582 | case 1 : | 600 | case 1 : |
583 | break; | 601 | break; |
584 | case 2 : | 602 | case 2 : |
585 | S = qApp->translate( "NetworkSettings", | 603 | S = qApp->translate( "NetworkSettings", |
586 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). | 604 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). |
587 | arg( SF->name() ). | 605 | arg( SF->name() ). |
588 | arg( CurDevNN->name() ); | 606 | arg( CurDevNN->name() ); |
589 | return S; | 607 | return S; |
590 | } | 608 | } |
591 | 609 | ||
592 | if( ! SF->postNodeSection( NNI, i ) ) { | 610 | if( ! SF->postNodeSection( NNI, i ) ) { |
593 | S = qApp->translate( "NetworkSettings", | 611 | S = qApp->translate( "NetworkSettings", |
594 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 612 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
595 | arg( SF->name() ). | 613 | arg( SF->name() ). |
596 | arg( CurDevNN->name() ); | 614 | arg( CurDevNN->name() ); |
597 | return S; | 615 | return S; |
598 | } | 616 | } |
599 | } | 617 | } |
600 | 618 | ||
601 | ncit2.current()->setDone( 1 ); | 619 | ncit2.current()->setDone( 1 ); |
602 | 620 | ||
603 | } | 621 | } |
604 | } | 622 | } |
605 | 623 | ||
606 | if( ! SF->postDeviceSection( CurDevNN ) ) { | 624 | if( ! SF->postDeviceSection( CurDevNN ) ) { |
607 | S = qApp->translate( "NetworkSettings", | 625 | S = qApp->translate( "NetworkSettings", |
608 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). | 626 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). |
609 | arg( SF->name() ). | 627 | arg( SF->name() ). |
610 | arg( CurDevNN->name() ); | 628 | arg( CurDevNN->name() ); |
611 | return S; | 629 | return S; |
612 | } | 630 | } |
613 | 631 | ||
614 | 632 | ||
615 | if( ! SF->postSection() ) { | 633 | if( ! SF->postSection() ) { |
616 | S = qApp->translate( "NetworkSettings", | 634 | S = qApp->translate( "NetworkSettings", |
617 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). | 635 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). |
618 | arg( SF->name() ); | 636 | arg( SF->name() ); |
619 | return S; | 637 | return S; |
620 | } | 638 | } |
621 | 639 | ||
622 | // end of file | 640 | // end of file |
623 | SF->close(); | 641 | SF->close(); |
624 | } | 642 | } |
625 | return S; | 643 | return S; |
626 | } | 644 | } |
627 | 645 | ||
628 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { | 646 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { |
629 | // collect connections that can work on top of this interface | 647 | // collect connections that can work on top of this interface |
630 | NodeCollection * NC; | 648 | NodeCollection * NC; |
631 | QList<NodeCollection> PossibleConnections; | 649 | QList<NodeCollection> PossibleConnections; |
632 | Name2Connection_t & M = NSResources->connections(); | 650 | Name2Connection_t & M = NSResources->connections(); |
633 | 651 | ||
634 | // for all connections | 652 | // for all connections |
635 | for( QDictIterator<NodeCollection> it(M); | 653 | for( QDictIterator<NodeCollection> it(M); |
636 | it.current(); | 654 | it.current(); |
637 | ++it ) { | 655 | ++it ) { |
638 | NC = it.current(); | 656 | NC = it.current(); |
639 | // check if this profile handles the requested interface | 657 | // check if this profile handles the requested interface |
640 | if( NC->handlesInterface( Interface ) && // if different Intf. | 658 | if( NC->handlesInterface( Interface ) && // if different Intf. |
641 | NC->state() != Disabled && // if not enabled | 659 | NC->state() != Disabled && // if not enabled |
642 | NC->state() != IsUp // if already used | 660 | NC->state() != IsUp // if already used |
643 | ) { | 661 | ) { |
644 | Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); | 662 | Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); |
645 | PossibleConnections.append( NC ); | 663 | PossibleConnections.append( NC ); |
646 | } | 664 | } |
647 | } | 665 | } |
648 | return PossibleConnections; | 666 | return PossibleConnections; |
649 | } | 667 | } |
650 | 668 | ||
651 | 669 | ||
652 | /* | 670 | /* |
653 | Called by the system to see if interface can be brought UP | 671 | Called by the system to see if interface can be brought UP |
654 | 672 | ||
655 | if allowed, echo Interface-allowed else Interface-disallowed | 673 | if allowed, echo Interface-allowed else Interface-disallowed |
656 | */ | 674 | */ |
657 | 675 | ||
658 | bool NetworkSettingsData::canStart( const char * Interface ) { | 676 | bool NetworkSettingsData::canStart( const char * Interface ) { |
659 | // load situation | 677 | // load situation |
660 | NodeCollection * NC = 0; | 678 | NodeCollection * NC = 0; |
661 | QList<NodeCollection> PossibleConnections; | 679 | QList<NodeCollection> PossibleConnections; |
662 | 680 | ||
663 | PossibleConnections = collectPossible( Interface ); | 681 | PossibleConnections = collectPossible( Interface ); |
664 | 682 | ||
665 | Log( ( "for %s : Possiblilies %d\n", | 683 | Log( ( "for %s : Possiblilies %d\n", |
666 | Interface, PossibleConnections.count() )); | 684 | Interface, PossibleConnections.count() )); |
667 | switch( PossibleConnections.count() ) { | 685 | switch( PossibleConnections.count() ) { |
668 | case 0 : // no connections | 686 | case 0 : // no connections |
669 | break; | 687 | break; |
670 | case 1 : // one connection | 688 | case 1 : // one connection |
671 | NC = PossibleConnections.first(); | 689 | NC = PossibleConnections.first(); |
672 | break; | 690 | break; |
673 | default : // need to ask user ? | 691 | default : // need to ask user ? |
674 | return 1; | 692 | return 1; |
675 | } | 693 | } |
676 | 694 | ||
677 | if( NC ) { | 695 | if( NC ) { |
678 | switch( NC->state() ) { | 696 | switch( NC->state() ) { |
679 | case Unchecked : | 697 | case Unchecked : |
680 | case Unknown : | 698 | case Unknown : |
681 | case Unavailable : | 699 | case Unavailable : |
682 | case Disabled : | 700 | case Disabled : |
683 | // this profile does not allow interface to be UP | 701 | // this profile does not allow interface to be UP |
684 | // -> try others | 702 | // -> try others |
685 | break; | 703 | break; |
686 | case Off : | 704 | case Off : |
687 | // try to UP the device | 705 | // try to UP the device |
688 | { QString S= NC->setState( Activate ); | 706 | { QString S= NC->setState( Activate ); |
689 | if( ! S.isEmpty() ) { | 707 | if( ! S.isEmpty() ) { |
690 | // could not bring device Online -> try other alters | 708 | // could not bring device Online -> try other alters |
691 | Log(( "%s-c%d-disallowed : %s\n", | 709 | Log(( "%s-c%d-disallowed : %s\n", |
692 | Interface, NC->number(), S.latin1() )); | 710 | Interface, NC->number(), S.latin1() )); |
693 | break; | 711 | break; |
694 | } | 712 | } |
695 | // interface assigned | 713 | // interface assigned |
696 | } | 714 | } |
697 | // FT | 715 | // FT |
698 | case Available : | 716 | case Available : |
699 | case IsUp : // also called for 'ifdown' | 717 | case IsUp : // also called for 'ifdown' |
700 | // device is ready -> done | 718 | // device is ready -> done |
701 | Log(( "%s-c%d-allowed\n", Interface, NC->number() )); | 719 | Log(( "%s-c%d-allowed\n", Interface, NC->number() )); |
702 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); | 720 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); |
703 | return 0; | 721 | return 0; |
704 | } | 722 | } |
705 | } | 723 | } |
706 | 724 | ||
707 | // if we come here no alternatives are possible | 725 | // if we come here no alternatives are possible |
708 | Log(( "%s-cnn-disallowed\n", Interface )); | 726 | Log(( "%s-cnn-disallowed\n", Interface )); |
709 | printf( "%s-cnn-disallowed\n", Interface ); | 727 | printf( "%s-cnn-disallowed\n", Interface ); |
710 | return 0; | 728 | return 0; |
711 | } | 729 | } |
712 | 730 | ||
713 | bool NetworkSettingsData::isModified( void ) { | 731 | bool NetworkSettingsData::isModified( void ) { |
714 | if( ForceModified ) | 732 | if( ForceModified ) |
715 | return 1; | 733 | return 1; |
716 | 734 | ||
717 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | 735 | for( QDictIterator<NodeCollection> it(NSResources->connections()); |
718 | it.current(); | 736 | it.current(); |
719 | ++it ) { | 737 | ++it ) { |
720 | if( it.current()->isModified() ) { | 738 | if( it.current()->isModified() ) { |
721 | return 1; | 739 | return 1; |
722 | } | 740 | } |
723 | } | 741 | } |
724 | return 0; | 742 | return 0; |
725 | } | 743 | } |
diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.cpp b/noncore/settings/networksettings2/ppp/ppp_NN.cpp index bd13ab9..8c15e9c 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NN.cpp | |||
@@ -1,100 +1,83 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <resources.h> | 2 | #include <resources.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include "ppp_NN.h" | 4 | #include "ppp_NN.h" |
5 | #include "ppp_NNI.h" | 5 | #include "ppp_NNI.h" |
6 | 6 | ||
7 | #ifndef MYPLUGIN | ||
8 | |||
9 | #include "netnodeinterface.h" | 7 | #include "netnodeinterface.h" |
10 | 8 | ||
11 | #endif | ||
12 | |||
13 | QStringList * PPPNetNode::ProperFiles = 0; | 9 | QStringList * PPPNetNode::ProperFiles = 0; |
14 | 10 | ||
15 | static const char * PPPNeeds[] = | 11 | static const char * PPPNeeds[] = |
16 | { "modem", | 12 | { "modem", |
17 | 0 | 13 | 0 |
18 | }; | 14 | }; |
19 | 15 | ||
20 | static const char * PPPProvides[] = | 16 | static const char * PPPProvides[] = |
21 | { "connection", | 17 | { "connection", |
22 | 0 | 18 | 0 |
23 | }; | 19 | }; |
24 | 20 | ||
25 | /** | 21 | /** |
26 | * Constructor, find all of the possible interfaces | 22 | * Constructor, find all of the possible interfaces |
27 | */ | 23 | */ |
28 | PPPNetNode::PPPNetNode() : ANetNode(tr("PPP Connection")) { | 24 | PPPNetNode::PPPNetNode() : ANetNode(tr("PPP Connection")) { |
29 | 25 | ||
30 | NSResources->addSystemFile( | 26 | NSResources->addSystemFile( |
31 | "pap-secrets", "/etc/ppp/pap-secrets", 0 ); | 27 | "pap-secrets", "/etc/ppp/pap-secrets", 0 ); |
32 | NSResources->addSystemFile( | 28 | NSResources->addSystemFile( |
33 | "chap-secrets", "/etc/ppp/chap-secrets", 0 ); | 29 | "chap-secrets", "/etc/ppp/chap-secrets", 0 ); |
34 | } | 30 | } |
35 | 31 | ||
36 | /** | 32 | /** |
37 | * Delete any interfaces that we own. | 33 | * Delete any interfaces that we own. |
38 | */ | 34 | */ |
39 | PPPNetNode::~PPPNetNode(){ | 35 | PPPNetNode::~PPPNetNode(){ |
40 | } | 36 | } |
41 | 37 | ||
42 | const QString PPPNetNode::nodeDescription(){ | 38 | const QString PPPNetNode::nodeDescription(){ |
43 | return tr("\ | 39 | return tr("\ |
44 | <p>Sets up IP using PPP.</p>\ | 40 | <p>Sets up IP using PPP.</p>\ |
45 | <p>Use this for dialup devices or serial setups</p>\ | 41 | <p>Use this for dialup devices or serial setups</p>\ |
46 | " | 42 | " |
47 | ); | 43 | ); |
48 | } | 44 | } |
49 | 45 | ||
50 | ANetNodeInstance * PPPNetNode::createInstance( void ) { | 46 | ANetNodeInstance * PPPNetNode::createInstance( void ) { |
51 | return new APPP( this ); | 47 | return new APPP( this ); |
52 | } | 48 | } |
53 | 49 | ||
54 | const char ** PPPNetNode::needs( void ) { | 50 | const char ** PPPNetNode::needs( void ) { |
55 | return PPPNeeds; | 51 | return PPPNeeds; |
56 | } | 52 | } |
57 | 53 | ||
58 | const char ** PPPNetNode::provides( void ) { | 54 | const char ** PPPNetNode::provides( void ) { |
59 | return PPPProvides; | 55 | return PPPProvides; |
60 | } | 56 | } |
61 | 57 | ||
62 | QStringList PPPNetNode::properFiles( void ) { | 58 | QStringList PPPNetNode::properFiles( void ) { |
63 | QStringList SL; | 59 | QStringList SL; |
64 | SL << "peers" << "chatscripts"; | 60 | SL << "peers" << "chatscripts"; |
65 | return SL; | 61 | return SL; |
66 | } | 62 | } |
67 | 63 | ||
68 | // need to generate : | 64 | // need to generate : |
69 | // /etc/ppp/pap-secrets | 65 | // /etc/ppp/pap-secrets |
70 | // /etc/ppp/pap-secrets | 66 | // /etc/ppp/pap-secrets |
71 | bool PPPNetNode::hasDataForFile( SystemFile & S ) { | 67 | bool PPPNetNode::hasDataForFile( SystemFile & S ) { |
72 | return S.name() == "pap-secrets" || | 68 | return S.name() == "pap-secrets" || |
73 | S.name() == "chap-secrets" ; | 69 | S.name() == "chap-secrets" ; |
74 | } | 70 | } |
75 | 71 | ||
76 | QString PPPNetNode::genNic( long NicNr ) { | 72 | QString PPPNetNode::genNic( long NicNr ) { |
77 | QString S; | 73 | QString S; |
78 | return S.sprintf( "ppp%ld", NicNr ); | 74 | return S.sprintf( "ppp%ld", NicNr ); |
79 | } | 75 | } |
80 | 76 | ||
81 | void PPPNetNode::setSpecificAttribute( QString & , QString & ) { | 77 | void PPPNetNode::setSpecificAttribute( QString & , QString & ) { |
82 | } | 78 | } |
83 | 79 | ||
84 | void PPPNetNode::saveSpecificAttribute( QTextStream & ) { | 80 | void PPPNetNode::saveSpecificAttribute( QTextStream & ) { |
85 | } | 81 | } |
86 | 82 | ||
87 | #ifdef MYPLUGIN | 83 | OPIE_NS2_PLUGIN( NetNodeInterface_T<PPPNetNode> ) |
88 | |||
89 | extern "C" { | ||
90 | void create_plugin( QList<ANetNode> & PNN ) { | ||
91 | PNN.append( new PPPNetNode() ); | ||
92 | } | ||
93 | |||
94 | #else | ||
95 | |||
96 | OPIE_NS2_PLUGIN( NetNodeInterface<PPPNetNode> ) | ||
97 | |||
98 | #endif | ||
99 | |||
100 | } | ||
diff --git a/noncore/settings/networksettings2/profile/profile_NN.cpp b/noncore/settings/networksettings2/profile/profile_NN.cpp index 6028ea5..1e6912e 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.cpp +++ b/noncore/settings/networksettings2/profile/profile_NN.cpp | |||
@@ -1,75 +1,58 @@ | |||
1 | #include <resources.h> | 1 | #include <resources.h> |
2 | #include "profile_NN.h" | 2 | #include "profile_NN.h" |
3 | #include "profile_NNI.h" | 3 | #include "profile_NNI.h" |
4 | 4 | ||
5 | #ifndef MYPLUGIN | ||
6 | |||
7 | #include "netnodeinterface.h" | 5 | #include "netnodeinterface.h" |
8 | 6 | ||
9 | #endif | ||
10 | |||
11 | static const char * ProfileNeeds[] = | 7 | static const char * ProfileNeeds[] = |
12 | { "connection", | 8 | { "connection", |
13 | 0 | 9 | 0 |
14 | }; | 10 | }; |
15 | static const char * ProfileProvides[] = | 11 | static const char * ProfileProvides[] = |
16 | { "fullsetup", | 12 | { "fullsetup", |
17 | 0 | 13 | 0 |
18 | }; | 14 | }; |
19 | 15 | ||
20 | /** | 16 | /** |
21 | * Constructor, find all of the possible interfaces | 17 | * Constructor, find all of the possible interfaces |
22 | */ | 18 | */ |
23 | ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular connection profile")) { | 19 | ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular connection profile")) { |
24 | 20 | ||
25 | NSResources->addSystemFile( | 21 | NSResources->addSystemFile( |
26 | "interfaces", "/etc/network/interfaces", 1 ); | 22 | "interfaces", "/etc/network/interfaces", 1 ); |
27 | 23 | ||
28 | } | 24 | } |
29 | 25 | ||
30 | /** | 26 | /** |
31 | * Delete any interfaces that we own. | 27 | * Delete any interfaces that we own. |
32 | */ | 28 | */ |
33 | ProfileNetNode::~ProfileNetNode(){ | 29 | ProfileNetNode::~ProfileNetNode(){ |
34 | } | 30 | } |
35 | 31 | ||
36 | const QString ProfileNetNode::nodeDescription(){ | 32 | const QString ProfileNetNode::nodeDescription(){ |
37 | return tr("\ | 33 | return tr("\ |
38 | <p>Define use of an IP connection.</p>\ | 34 | <p>Define use of an IP connection.</p>\ |
39 | <p>Configure if and when this connection needs to be established</p>\ | 35 | <p>Configure if and when this connection needs to be established</p>\ |
40 | " | 36 | " |
41 | ); | 37 | ); |
42 | } | 38 | } |
43 | 39 | ||
44 | ANetNodeInstance * ProfileNetNode::createInstance( void ) { | 40 | ANetNodeInstance * ProfileNetNode::createInstance( void ) { |
45 | return new AProfile( this ); | 41 | return new AProfile( this ); |
46 | } | 42 | } |
47 | 43 | ||
48 | const char ** ProfileNetNode::needs( void ) { | 44 | const char ** ProfileNetNode::needs( void ) { |
49 | return ProfileNeeds; | 45 | return ProfileNeeds; |
50 | } | 46 | } |
51 | 47 | ||
52 | const char ** ProfileNetNode::provides( void ) { | 48 | const char ** ProfileNetNode::provides( void ) { |
53 | return ProfileProvides; | 49 | return ProfileProvides; |
54 | } | 50 | } |
55 | 51 | ||
56 | void ProfileNetNode::setSpecificAttribute( QString & , QString & ) { | 52 | void ProfileNetNode::setSpecificAttribute( QString & , QString & ) { |
57 | } | 53 | } |
58 | 54 | ||
59 | void ProfileNetNode::saveSpecificAttribute( QTextStream & ) { | 55 | void ProfileNetNode::saveSpecificAttribute( QTextStream & ) { |
60 | } | 56 | } |
61 | 57 | ||
62 | #ifdef MYPLUGIN | 58 | OPIE_NS2_PLUGIN( NetNodeInterface_T<ProfileNetNode> ) |
63 | |||
64 | extern "C" { | ||
65 | void create_plugin( QList<ANetNode> & PNN ) { | ||
66 | PNN.append( new ProfileNetNode() ); | ||
67 | } | ||
68 | |||
69 | #else | ||
70 | |||
71 | OPIE_NS2_PLUGIN( NetNodeInterface<ProfileNetNode> ) | ||
72 | |||
73 | #endif | ||
74 | |||
75 | } | ||
diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index 9c07b82..6d90ae0 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp | |||
@@ -1,77 +1,60 @@ | |||
1 | #include <resources.h> | 1 | #include <resources.h> |
2 | #include "usb_NN.h" | 2 | #include "usb_NN.h" |
3 | #include "usb_NNI.h" | 3 | #include "usb_NNI.h" |
4 | 4 | ||
5 | #ifndef MYPLUGIN | ||
6 | |||
7 | #include "netnodeinterface.h" | 5 | #include "netnodeinterface.h" |
8 | 6 | ||
9 | #endif | ||
10 | |||
11 | static const char * USBNeeds[] = | 7 | static const char * USBNeeds[] = |
12 | { 0 | 8 | { 0 |
13 | }; | 9 | }; |
14 | 10 | ||
15 | static const char * USBProvides[] = | 11 | static const char * USBProvides[] = |
16 | { "device", | 12 | { "device", |
17 | 0 | 13 | 0 |
18 | }; | 14 | }; |
19 | 15 | ||
20 | /** | 16 | /** |
21 | * Constructor, find all of the possible interfaces | 17 | * Constructor, find all of the possible interfaces |
22 | */ | 18 | */ |
23 | USBNetNode::USBNetNode() : ANetNode(tr("USB Cable Connect")) { | 19 | USBNetNode::USBNetNode() : ANetNode(tr("USB Cable Connect")) { |
24 | NSResources->addSystemFile( | 20 | NSResources->addSystemFile( |
25 | "interfaces", "/etc/network/interfaces", 1 ); | 21 | "interfaces", "/etc/network/interfaces", 1 ); |
26 | } | 22 | } |
27 | 23 | ||
28 | /** | 24 | /** |
29 | * Delete any interfaces that we own. | 25 | * Delete any interfaces that we own. |
30 | */ | 26 | */ |
31 | USBNetNode::~USBNetNode(){ | 27 | USBNetNode::~USBNetNode(){ |
32 | } | 28 | } |
33 | 29 | ||
34 | const QString USBNetNode::nodeDescription(){ | 30 | const QString USBNetNode::nodeDescription(){ |
35 | return tr("\ | 31 | return tr("\ |
36 | <p>Configure Ethernet over USB.</p>\ | 32 | <p>Configure Ethernet over USB.</p>\ |
37 | <p>Use this for a computer to computer USB cable connection</p>\ | 33 | <p>Use this for a computer to computer USB cable connection</p>\ |
38 | " | 34 | " |
39 | ); | 35 | ); |
40 | } | 36 | } |
41 | 37 | ||
42 | ANetNodeInstance * USBNetNode::createInstance( void ) { | 38 | ANetNodeInstance * USBNetNode::createInstance( void ) { |
43 | return new AUSB( this ); | 39 | return new AUSB( this ); |
44 | } | 40 | } |
45 | 41 | ||
46 | const char ** USBNetNode::needs( void ) { | 42 | const char ** USBNetNode::needs( void ) { |
47 | return USBNeeds; | 43 | return USBNeeds; |
48 | } | 44 | } |
49 | 45 | ||
50 | const char ** USBNetNode::provides( void ) { | 46 | const char ** USBNetNode::provides( void ) { |
51 | return USBProvides; | 47 | return USBProvides; |
52 | } | 48 | } |
53 | 49 | ||
54 | QString USBNetNode::genNic( long ) { | 50 | QString USBNetNode::genNic( long ) { |
55 | return QString( "usbf" ); | 51 | return QString( "usbf" ); |
56 | } | 52 | } |
57 | 53 | ||
58 | void USBNetNode::setSpecificAttribute( QString & , QString & ) { | 54 | void USBNetNode::setSpecificAttribute( QString & , QString & ) { |
59 | } | 55 | } |
60 | 56 | ||
61 | void USBNetNode::saveSpecificAttribute( QTextStream & ) { | 57 | void USBNetNode::saveSpecificAttribute( QTextStream & ) { |
62 | } | 58 | } |
63 | 59 | ||
64 | #ifdef MYPLUGIN | 60 | OPIE_NS2_PLUGIN( NetNodeInterface_T<USBNetNode> ) |
65 | |||
66 | extern "C" { | ||
67 | void create_plugin( QList<ANetNode> & PNN ) { | ||
68 | PNN.append( new USBNetNode() ); | ||
69 | } | ||
70 | |||
71 | #else | ||
72 | |||
73 | OPIE_NS2_PLUGIN( NetNodeInterface<USBNetNode> ) | ||
74 | |||
75 | #endif | ||
76 | |||
77 | } | ||
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index 0a46642..eb439c1 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp | |||
@@ -1,124 +1,119 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qfileinfo.h> | 2 | #include <qfileinfo.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <resources.h> | 4 | #include <resources.h> |
5 | #include "usbrun.h" | 5 | #include "usbrun.h" |
6 | 6 | ||
7 | State_t USBRun::detectState( void ) { | 7 | State_t USBRun::detectState( void ) { |
8 | |||
8 | // unavailable : no card found | 9 | // unavailable : no card found |
9 | // available : card found and assigned to us or free | 10 | // available : card found and assigned to us or free |
10 | // up : card found and assigned to us and up | 11 | // up : card found and assigned to us and up |
12 | |||
11 | NodeCollection * NC = nodeCollection(); | 13 | NodeCollection * NC = nodeCollection(); |
12 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); | 14 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); |
13 | System & Sys = NSResources->system(); | 15 | System & Sys = NSResources->system(); |
14 | InterfaceInfo * Run; | 16 | InterfaceInfo * Run; |
15 | QFile F( S ); | 17 | QFile F( S ); |
16 | Log(("Detecting for %s\n", NC->name().latin1() )); | 18 | Log(("Detecting for %s\n", NC->name().latin1() )); |
17 | 19 | ||
18 | if( F.open( IO_ReadOnly ) ) { | 20 | if( F.open( IO_ReadOnly ) ) { |
19 | // could open file -> read interface and assign | 21 | // could open file -> read interface and assign |
20 | QString X; | 22 | QString X; |
21 | QTextStream TS(&F); | 23 | QTextStream TS(&F); |
22 | X = TS.readLine(); | 24 | X = TS.readLine(); |
23 | Log(("%s exists\n", S.latin1() )); | 25 | Log(("%s exists\n", S.latin1() )); |
24 | // find interface | 26 | // find interface |
25 | if( handlesInterface( X ) ) { | 27 | if( handlesInterface( X ) ) { |
26 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | 28 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); |
27 | It.current(); | 29 | It.current(); |
28 | ++It ) { | 30 | ++It ) { |
29 | Run = It.current(); | 31 | Run = It.current(); |
30 | if( X == Run->Name ) { | 32 | if( X == Run->Name ) { |
31 | NC->assignInterface( Run ); | 33 | NC->assignInterface( Run ); |
32 | return IsUp; | 34 | return IsUp; |
33 | } | 35 | } |
34 | } | 36 | } |
35 | } | 37 | } |
36 | } | 38 | } |
37 | 39 | ||
38 | Log(("Assigned %p\n", NC->assignedInterface() )); | 40 | Log(("Assigned %p\n", NC->assignedInterface() )); |
39 | if( ( Run = NC->assignedInterface() ) ) { | 41 | if( ( Run = NC->assignedInterface() ) ) { |
40 | // we already have an interface assigned -> still present ? | 42 | // we already have an interface assigned -> still present ? |
41 | if( ! Run->IsUp ) { | 43 | if( ! Run->IsUp ) { |
42 | // usb is still free -> keep assignment | 44 | // usb is still free -> keep assignment |
43 | return Available; | 45 | return Available; |
44 | } // else interface is up but NOT us -> some other profile | 46 | } // else interface is up but NOT us -> some other profile |
45 | } | 47 | } |
46 | 48 | ||
47 | // nothing (valid) assigned to us | 49 | // nothing (valid) assigned to us |
48 | NC->assignInterface( 0 ); | 50 | NC->assignInterface( 0 ); |
49 | 51 | ||
50 | // find possible interface | 52 | // find possible interface |
51 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | 53 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); |
52 | It.current(); | 54 | It.current(); |
53 | ++It ) { | 55 | ++It ) { |
54 | Run = It.current(); | 56 | Run = It.current(); |
55 | 57 | ||
56 | Log(("%s %d %d=%d %d\n", | 58 | Log(("%s %d %d=%d %d\n", |
57 | Run->Name.latin1(), | 59 | Run->Name.latin1(), |
58 | handlesInterface( Run->Name ), | 60 | handlesInterface( Run->Name ), |
59 | Run->CardType, ARPHRD_ETHER, | 61 | Run->CardType, ARPHRD_ETHER, |
60 | ! Run->IsUp )); | 62 | ! Run->IsUp )); |
61 | 63 | ||
62 | if( handlesInterface( Run->Name ) && | 64 | if( handlesInterface( Run->Name ) && |
63 | Run->CardType == ARPHRD_ETHER && | 65 | Run->CardType == ARPHRD_ETHER && |
64 | ! Run->IsUp | 66 | ! Run->IsUp |
65 | ) { | 67 | ) { |
66 | // proper type, and Not UP -> free | 68 | // proper type, and Not UP -> free |
67 | return Off; | 69 | // usb cables are currently always available when requested |
70 | // until we can detect if we are plugged in | ||
71 | return Available; | ||
68 | } | 72 | } |
69 | } | 73 | } |
70 | 74 | ||
71 | return Unavailable; | 75 | return Unavailable; |
72 | } | 76 | } |
73 | 77 | ||
74 | QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) { | 78 | QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) { |
75 | 79 | ||
76 | // nothing needs to be done to 'activate' or 'deactivate' | 80 | // nothing needs to be done to 'activate' or 'deactivate' |
77 | // a cable | 81 | // a cable |
78 | |||
79 | // perhaps (later) we can figure out if the device is IN the | ||
80 | // cradle | ||
81 | if( A == Activate ) { | ||
82 | NC->setCurrentState( Available ); | ||
83 | } else if ( A == Deactivate ) { | ||
84 | NC->setCurrentState( Unavailable ); | ||
85 | } | ||
86 | |||
87 | return QString(); | 82 | return QString(); |
88 | } | 83 | } |
89 | 84 | ||
90 | // get interface that is free or assigned to us | 85 | // get interface that is free or assigned to us |
91 | InterfaceInfo * USBRun::getInterface( void ) { | 86 | InterfaceInfo * USBRun::getInterface( void ) { |
92 | 87 | ||
93 | System & S = NSResources->system(); | 88 | System & S = NSResources->system(); |
94 | InterfaceInfo * best = 0, * Run; | 89 | InterfaceInfo * best = 0, * Run; |
95 | QRegExp R( "usb[0-9abcdef]" ); | 90 | QRegExp R( "usb[0-9abcdef]" ); |
96 | 91 | ||
97 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | 92 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); |
98 | It.current(); | 93 | It.current(); |
99 | ++It ) { | 94 | ++It ) { |
100 | Run = It.current(); | 95 | Run = It.current(); |
101 | if( handlesInterface( Run->Name ) && | 96 | if( handlesInterface( Run->Name ) && |
102 | Run->CardType == ARPHRD_ETHER | 97 | Run->CardType == ARPHRD_ETHER |
103 | ) { | 98 | ) { |
104 | // this is a USB card | 99 | // this is a USB card |
105 | if( Run->assignedConnection() == netNode()->connection() ) { | 100 | if( Run->assignedConnection() == netNode()->connection() ) { |
106 | // assigned to us | 101 | // assigned to us |
107 | return Run; | 102 | return Run; |
108 | } else if( Run->assignedConnection() == 0 ) { | 103 | } else if( Run->assignedConnection() == 0 ) { |
109 | // free | 104 | // free |
110 | best = Run; | 105 | best = Run; |
111 | } | 106 | } |
112 | } | 107 | } |
113 | } | 108 | } |
114 | return best; // can be 0 | 109 | return best; // can be 0 |
115 | } | 110 | } |
116 | 111 | ||
117 | bool USBRun::handlesInterface( const QString & S ) { | 112 | bool USBRun::handlesInterface( const QString & S ) { |
118 | return Pat.match( S ) >= 0; | 113 | return Pat.match( S ) >= 0; |
119 | } | 114 | } |
120 | 115 | ||
121 | bool USBRun::handlesInterface( InterfaceInfo * I ) { | 116 | bool USBRun::handlesInterface( InterfaceInfo * I ) { |
122 | return handlesInterface( I->Name ); | 117 | return handlesInterface( I->Name ); |
123 | } | 118 | } |
124 | 119 | ||
diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.cpp b/noncore/settings/networksettings2/vpn/vpn_NN.cpp index 6dd5332..96e9df2 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NN.cpp | |||
@@ -1,69 +1,52 @@ | |||
1 | #include "vpn_NN.h" | 1 | #include "vpn_NN.h" |
2 | #include "vpn_NNI.h" | 2 | #include "vpn_NNI.h" |
3 | 3 | ||
4 | #ifndef MYPLUGIN | ||
5 | |||
6 | #include "netnodeinterface.h" | 4 | #include "netnodeinterface.h" |
7 | 5 | ||
8 | #endif | ||
9 | |||
10 | static const char * VPNNeeds[] = | 6 | static const char * VPNNeeds[] = |
11 | { 0 | 7 | { 0 |
12 | }; | 8 | }; |
13 | 9 | ||
14 | static const char * VPNProvides[] = | 10 | static const char * VPNProvides[] = |
15 | { "connection", | 11 | { "connection", |
16 | 0 | 12 | 0 |
17 | }; | 13 | }; |
18 | /** | 14 | /** |
19 | * Constructor, find all of the possible interfaces | 15 | * Constructor, find all of the possible interfaces |
20 | */ | 16 | */ |
21 | VPNNetNode::VPNNetNode() : ANetNode(tr("VPN Connection")) { | 17 | VPNNetNode::VPNNetNode() : ANetNode(tr("VPN Connection")) { |
22 | } | 18 | } |
23 | 19 | ||
24 | /** | 20 | /** |
25 | * Delete any interfaces that we own. | 21 | * Delete any interfaces that we own. |
26 | */ | 22 | */ |
27 | VPNNetNode::~VPNNetNode(){ | 23 | VPNNetNode::~VPNNetNode(){ |
28 | } | 24 | } |
29 | 25 | ||
30 | const QString VPNNetNode::nodeDescription(){ | 26 | const QString VPNNetNode::nodeDescription(){ |
31 | return tr("\ | 27 | return tr("\ |
32 | <p>Configure private IP connection.</p>\ | 28 | <p>Configure private IP connection.</p>\ |
33 | <p>Defines Secure tunnels over non secure IP sessions</p>\ | 29 | <p>Defines Secure tunnels over non secure IP sessions</p>\ |
34 | " | 30 | " |
35 | ); | 31 | ); |
36 | } | 32 | } |
37 | 33 | ||
38 | ANetNodeInstance * VPNNetNode::createInstance( void ) { | 34 | ANetNodeInstance * VPNNetNode::createInstance( void ) { |
39 | return new AVPN( this ); | 35 | return new AVPN( this ); |
40 | } | 36 | } |
41 | 37 | ||
42 | const char ** VPNNetNode::needs( void ) { | 38 | const char ** VPNNetNode::needs( void ) { |
43 | return VPNNeeds; | 39 | return VPNNeeds; |
44 | } | 40 | } |
45 | 41 | ||
46 | const char ** VPNNetNode::provides( void ) { | 42 | const char ** VPNNetNode::provides( void ) { |
47 | return VPNProvides; | 43 | return VPNProvides; |
48 | } | 44 | } |
49 | 45 | ||
50 | void VPNNetNode::setSpecificAttribute( QString & , QString & ) { | 46 | void VPNNetNode::setSpecificAttribute( QString & , QString & ) { |
51 | } | 47 | } |
52 | 48 | ||
53 | void VPNNetNode::saveSpecificAttribute( QTextStream & ) { | 49 | void VPNNetNode::saveSpecificAttribute( QTextStream & ) { |
54 | } | 50 | } |
55 | 51 | ||
56 | #ifdef MYPLUGIN | 52 | OPIE_NS2_PLUGIN( NetNodeInterface_T<VPNNetNode> ) |
57 | |||
58 | extern "C" { | ||
59 | void create_plugin( QList<ANetNode> & PNN ) { | ||
60 | PNN.append( new VPNNetNode() ); | ||
61 | } | ||
62 | |||
63 | #else | ||
64 | |||
65 | OPIE_NS2_PLUGIN( NetNodeInterface<VPNNetNode> ) | ||
66 | |||
67 | #endif | ||
68 | |||
69 | } | ||
diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.cpp b/noncore/settings/networksettings2/wlan/wlan_NN.cpp index c56da06..f7745be 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NN.cpp | |||
@@ -1,85 +1,68 @@ | |||
1 | #include <resources.h> | 1 | #include <resources.h> |
2 | #include "wlan_NN.h" | 2 | #include "wlan_NN.h" |
3 | #include "wlan_NNI.h" | 3 | #include "wlan_NNI.h" |
4 | 4 | ||
5 | #ifndef MYPLUGIN | ||
6 | |||
7 | #include "netnodeinterface.h" | 5 | #include "netnodeinterface.h" |
8 | 6 | ||
9 | #endif | ||
10 | |||
11 | static const char * WLanNeeds[] = | 7 | static const char * WLanNeeds[] = |
12 | { 0 | 8 | { 0 |
13 | }; | 9 | }; |
14 | 10 | ||
15 | static const char * WLanProvides[] = | 11 | static const char * WLanProvides[] = |
16 | { "device", | 12 | { "device", |
17 | 0 | 13 | 0 |
18 | }; | 14 | }; |
19 | 15 | ||
20 | /** | 16 | /** |
21 | * Constructor, find all of the possible interfaces | 17 | * Constructor, find all of the possible interfaces |
22 | */ | 18 | */ |
23 | WLanNetNode::WLanNetNode() : ANetNode(tr("WLan Device")) { | 19 | WLanNetNode::WLanNetNode() : ANetNode(tr("WLan Device")) { |
24 | NSResources->addSystemFile( | 20 | NSResources->addSystemFile( |
25 | "interfaces", "/etc/network/interfaces", 1 ); | 21 | "interfaces", "/etc/network/interfaces", 1 ); |
26 | InstanceCount = 2; | 22 | InstanceCount = 2; |
27 | } | 23 | } |
28 | 24 | ||
29 | /** | 25 | /** |
30 | * Delete any interfaces that we own. | 26 | * Delete any interfaces that we own. |
31 | */ | 27 | */ |
32 | WLanNetNode::~WLanNetNode(){ | 28 | WLanNetNode::~WLanNetNode(){ |
33 | } | 29 | } |
34 | 30 | ||
35 | const QString WLanNetNode::nodeDescription(){ | 31 | const QString WLanNetNode::nodeDescription(){ |
36 | return tr("\ | 32 | return tr("\ |
37 | <p>Configure Wi/Fi or WLan network cards.</p>\ | 33 | <p>Configure Wi/Fi or WLan network cards.</p>\ |
38 | <p>Defines Wireless options for those cards</p>\ | 34 | <p>Defines Wireless options for those cards</p>\ |
39 | " | 35 | " |
40 | ); | 36 | ); |
41 | } | 37 | } |
42 | 38 | ||
43 | ANetNodeInstance * WLanNetNode::createInstance( void ) { | 39 | ANetNodeInstance * WLanNetNode::createInstance( void ) { |
44 | return new AWLan( this ); | 40 | return new AWLan( this ); |
45 | } | 41 | } |
46 | 42 | ||
47 | const char ** WLanNetNode::needs( void ) { | 43 | const char ** WLanNetNode::needs( void ) { |
48 | return WLanNeeds; | 44 | return WLanNeeds; |
49 | } | 45 | } |
50 | 46 | ||
51 | const char ** WLanNetNode::provides( void ) { | 47 | const char ** WLanNetNode::provides( void ) { |
52 | return WLanProvides; | 48 | return WLanProvides; |
53 | } | 49 | } |
54 | 50 | ||
55 | QString WLanNetNode::genNic( long nr ) { | 51 | QString WLanNetNode::genNic( long nr ) { |
56 | QString S; | 52 | QString S; |
57 | return S.sprintf( "wlan%ld", nr ); | 53 | return S.sprintf( "wlan%ld", nr ); |
58 | } | 54 | } |
59 | 55 | ||
60 | void WLanNetNode::setSpecificAttribute( QString & A, QString & V ) { | 56 | void WLanNetNode::setSpecificAttribute( QString & A, QString & V ) { |
61 | if( A == "interfacecount" ) { | 57 | if( A == "interfacecount" ) { |
62 | InstanceCount = V.toLong(); | 58 | InstanceCount = V.toLong(); |
63 | } | 59 | } |
64 | } | 60 | } |
65 | 61 | ||
66 | void WLanNetNode::saveSpecificAttribute( QTextStream & TS ) { | 62 | void WLanNetNode::saveSpecificAttribute( QTextStream & TS ) { |
67 | TS << "interfacecount=" | 63 | TS << "interfacecount=" |
68 | << InstanceCount | 64 | << InstanceCount |
69 | << endl; | 65 | << endl; |
70 | } | 66 | } |
71 | 67 | ||
72 | #ifdef MYPLUGIN | 68 | OPIE_NS2_PLUGIN( NetNodeInterface_T<WLanNetNode> ) |
73 | |||
74 | extern "C" { | ||
75 | void create_plugin( QList<ANetNode> & PNN ) { | ||
76 | PNN.append( new WLanNetNode() ); | ||
77 | } | ||
78 | |||
79 | #else | ||
80 | |||
81 | OPIE_NS2_PLUGIN( NetNodeInterface<WLanNetNode> ) | ||
82 | |||
83 | #endif | ||
84 | |||
85 | } | ||