summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/main.cpp4
-rw-r--r--noncore/settings/networksettings2/network/network_NN.cpp5
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp109
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.h5
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp12
5 files changed, 77 insertions, 58 deletions
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp
index 200e31b..9004d19 100644
--- a/noncore/settings/networksettings2/main.cpp
+++ b/noncore/settings/networksettings2/main.cpp
@@ -1,147 +1,151 @@
1#include "nsdata.h" 1#include "nsdata.h"
2#include "activateprofile.h" 2#include "activateprofile.h"
3#include "activatevpn.h" 3#include "activatevpn.h"
4#include "networksettings.h" 4#include "networksettings.h"
5 5
6#include <qpe/qpeapplication.h> 6#include <qpe/qpeapplication.h>
7 7
8#include <opie2/oapplicationfactory.h> 8#include <opie2/oapplicationfactory.h>
9using namespace Opie::Core; 9using namespace Opie::Core;
10 10
11#ifdef GONE 11#ifdef GONE
12 12
13OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) 13OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> )
14 14
15#else 15#else
16 16
17// just standard GUI 17// just standard GUI
18#define ACT_GUI 0 18#define ACT_GUI 0
19// used by interfaces to request for allow of up/down 19// used by interfaces to request for allow of up/down
20#define ACT_REQUEST 1 20#define ACT_REQUEST 1
21// regenerate config files 21// regenerate config files
22#define ACT_REGEN 2 22#define ACT_REGEN 2
23// used by interfaces to request user prompt 23// used by interfaces to request user prompt
24#define ACT_PROMPT 3 24#define ACT_PROMPT 3
25// used by interfaces to trigger VPN 25// used by interfaces to trigger VPN
26#define ACT_VPN 4 26#define ACT_VPN 4
27 27
28int main( int argc, char * argv[] ) { 28int main( int argc, char * argv[] ) {
29 int rv = 0; 29 int rv = 0;
30 int Action = ACT_GUI; 30 int Action = ACT_GUI;
31 // could be overruled by -qws 31 // could be overruled by -qws
32 QApplication::Type GuiType = QApplication::GuiClient; 32 QApplication::Type GuiType = QApplication::GuiClient;
33 33
34#ifdef _WS_QWS_ 34#ifdef _WS_QWS_
35 QPEApplication * TheApp; 35 QPEApplication * TheApp;
36#else 36#else
37 QApplication * TheApp; 37 QApplication * TheApp;
38#endif 38#endif
39 39
40 for ( int i = 1; i < argc; i ++ ) { 40 for ( int i = 1; i < argc; i ++ ) {
41 int rmv; 41 int rmv;
42 rmv = 0; 42 rmv = 0;
43 if( strcmp( argv[i], "--regen" ) == 0 ) { 43 if( strcmp( argv[i], "--regen" ) == 0 ) {
44 Action = ACT_REGEN; 44 Action = ACT_REGEN;
45 GuiType = QApplication::Tty; 45 GuiType = QApplication::Tty;
46 rmv = 1; 46 rmv = 1;
47 } else if( strcmp( argv[i], "--prompt" ) == 0 ) { 47 } else if( strcmp( argv[i], "--prompt" ) == 0 ) {
48 Action = ACT_PROMPT; 48 Action = ACT_PROMPT;
49 rmv = 1; 49 rmv = 1;
50 } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { 50 } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) {
51 Action = ACT_VPN; 51 Action = ACT_VPN;
52 rmv = 1; 52 rmv = 1;
53 } 53 }
54 if( rmv ) { 54 if( rmv ) {
55 memmove( argv+i, argv+i+rmv, 55 memmove( argv+i, argv+i+rmv,
56 sizeof( char * ) * (argc-i-rmv) ); 56 sizeof( char * ) * (argc-i-rmv) );
57 i --; 57 i --;
58 argc -= rmv; 58 argc -= rmv;
59 } 59 }
60 } 60 }
61 61
62 if( strstr( argv[0], "-request" ) ) { 62 if( strstr( argv[0], "-request" ) ) {
63 // called from system to request something 63 // called from system to request something
64 GuiType = QApplication::Tty; 64 GuiType = QApplication::Tty;
65 Action = ACT_REQUEST; 65 Action = ACT_REQUEST;
66 Log(("Request : %s\n", argv[1] )); 66 Log(("Request : %s\n", argv[1] ));
67 } 67 }
68 68
69 // Start Qt 69 // Start Qt
70#ifdef _WS_QWS_ 70#ifdef _WS_QWS_
71 // because QPEApplication does not handle GuiType well 71 // because QPEApplication does not handle GuiType well
72 if( GuiType == QApplication::Tty ) { 72 if( GuiType == QApplication::Tty ) {
73 // this cast is NOT correct but we do not use 73 // this cast is NOT correct but we do not use
74 // TheApp anymore ... 74 // TheApp anymore ...
75 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); 75 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType );
76 } else { 76 } else {
77 TheApp = new QPEApplication( argc, argv, GuiType ); 77 TheApp = new QPEApplication( argc, argv, GuiType );
78 } 78 }
79#else 79#else
80 TheApp = new QApplication( argc, argv, GuiType ); 80 TheApp = new QApplication( argc, argv, GuiType );
81#endif 81#endif
82 82
83 // init qt with app widget 83 // init qt with app widget
84 84
85 switch( Action ) { 85 switch( Action ) {
86 case ACT_REQUEST : 86 case ACT_REQUEST :
87 { NetworkSettingsData NS; 87 { NetworkSettingsData NS;
88 if( NS.canStart( argv[1] ) ) { 88 if( NS.canStart( argv[1] ) ) {
89 QString S; 89 QString S;
90 S.sprintf( QPEApplication::qpeDir()+ 90 S.sprintf( QPEApplication::qpeDir()+
91 "/bin/networksettings2" ); 91 "/bin/networksettings2" );
92 char * MyArgv[4]; 92 char * MyArgv[4];
93 MyArgv[0] = "networksettings2"; 93 MyArgv[0] = "networksettings2";
94 MyArgv[1] = "--prompt"; 94 MyArgv[1] = "--prompt";
95 MyArgv[2] = argv[1]; 95 MyArgv[2] = argv[1];
96 MyArgv[3] = NULL; 96 MyArgv[3] = NULL;
97 NSResources->system().execAsUser( S, MyArgv ); 97 NSResources->system().execAsUser( S, MyArgv );
98 Log(("FAILED %s-cNN-allowed\n", argv[1] ));
98 // if we come here , failed 99 // if we come here , failed
99 printf( "%s-cNN-disallowed", argv[1] ); 100 printf( "%s-cNN-disallowed", argv[1] );
100 } 101 }
101 } 102 }
102 break; 103 break;
103 case ACT_REGEN : 104 case ACT_REGEN :
104 { NetworkSettingsData NS; 105 { NetworkSettingsData NS;
105 // regen returns 0 if OK 106 // regen returns 0 if OK
106 rv = (NS.regenerate()) ? 1 : 0; 107 rv = (NS.regenerate()) ? 1 : 0;
107 } 108 }
108 break; 109 break;
109 case ACT_PROMPT : 110 case ACT_PROMPT :
110 { ActivateProfile AP(argv[1]); 111 { ActivateProfile AP(argv[1]);
111 if( AP.exec() == QDialog::Accepted ) { 112 if( AP.exec() == QDialog::Accepted ) {
113 Log(("%s-c%ld-allowed\n",
114 argv[1], AP.selectedProfile() ));
112 printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); 115 printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() );
113 } else { 116 } else {
117 Log(("%s-c%NN-disallowed\n", argv[1] ));
114 printf( "%s-cNN-disallowed", argv[1] ); 118 printf( "%s-cNN-disallowed", argv[1] );
115 } 119 }
116 } 120 }
117 break; 121 break;
118 case ACT_VPN : 122 case ACT_VPN :
119 { ActivateVPN AVPN; 123 { ActivateVPN AVPN;
120 AVPN.exec(); 124 AVPN.exec();
121 } 125 }
122 break; 126 break;
123 case ACT_GUI : 127 case ACT_GUI :
124 { QWidget * W = new NetworkSettings(0); 128 { QWidget * W = new NetworkSettings(0);
125 TheApp->setMainWidget( W ); 129 TheApp->setMainWidget( W );
126 W->show(); 130 W->show();
127#ifdef _WS_QWS_ 131#ifdef _WS_QWS_
128 W->showMaximized(); 132 W->showMaximized();
129#else 133#else
130 W->resize( W->sizeHint() ); 134 W->resize( W->sizeHint() );
131#endif 135#endif
132 rv = TheApp->exec(); 136 rv = TheApp->exec();
133 delete W; 137 delete W;
134 } 138 }
135 break; 139 break;
136 } 140 }
137 141
138 LogClose(); 142 LogClose();
139 143
140 return rv; 144 return rv;
141} 145}
142 146
143#endif 147#endif
144 148
145 149
146// main.cpp 150// main.cpp
147 151
diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp
index 1feffdb..b5c41bf 100644
--- a/noncore/settings/networksettings2/network/network_NN.cpp
+++ b/noncore/settings/networksettings2/network/network_NN.cpp
@@ -1,82 +1,85 @@
1#include <qpe/qpeapplication.h>
1#include <asdevice.h> 2#include <asdevice.h>
2#include "network_NN.h" 3#include "network_NN.h"
3#include "network_NNI.h" 4#include "network_NNI.h"
4 5
5static const char * NetworkNeeds[] = 6static const char * NetworkNeeds[] =
6 { "device", 7 { "device",
7 0 8 0
8 }; 9 };
9 10
10/** 11/**
11 * Constructor, find all of the possible interfaces 12 * Constructor, find all of the possible interfaces
12 */ 13 */
13NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) { 14NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) {
14} 15}
15 16
16/** 17/**
17 * Delete any interfaces that we own. 18 * Delete any interfaces that we own.
18 */ 19 */
19NetworkNetNode::~NetworkNetNode(){ 20NetworkNetNode::~NetworkNetNode(){
20} 21}
21 22
22const QString NetworkNetNode::nodeDescription(){ 23const QString NetworkNetNode::nodeDescription(){
23 return tr("\ 24 return tr("\
24<p>Sets up TCP/IP options.</p>\ 25<p>Sets up TCP/IP options.</p>\
25<p>Use this to configure the TCP/IP protocol</p>\ 26<p>Use this to configure the TCP/IP protocol</p>\
26" 27"
27); 28);
28} 29}
29 30
30ANetNodeInstance * NetworkNetNode::createInstance( void ) { 31ANetNodeInstance * NetworkNetNode::createInstance( void ) {
31 return new ANetwork( this ); 32 return new ANetwork( this );
32} 33}
33 34
34bool NetworkNetNode::hasDataForFile( const QString & S ) { 35bool NetworkNetNode::hasDataForFile( const QString & S ) {
35 return S == "interfaces"; 36 return S == "interfaces";
36} 37}
37 38
38short NetworkNetNode::generateFile( const QString & ID, 39short NetworkNetNode::generateFile( const QString & ID,
39 const QString & , 40 const QString & ,
40 QTextStream & TS, 41 QTextStream & TS,
41 ANetNodeInstance * NNI, 42 ANetNodeInstance * NNI,
42 long DevNr ) { 43 long DevNr ) {
43 44
44 QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); 45 QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr );
45 46
46 if( ID == "interfaces" ) { 47 if( ID == "interfaces" ) {
47 Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() )); 48 Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() ));
48 // generate mapping stanza for this interface 49 // generate mapping stanza for this interface
49 TS << "# check if " 50 TS << "# check if "
50 << NIC 51 << NIC
51 << " can be brought UP" 52 << " can be brought UP"
52 << endl; 53 << endl;
53 TS << "mapping " 54 TS << "mapping "
54 << NIC 55 << NIC
55 << endl; 56 << endl;
56 TS << " script networksettings2-request" 57 TS << " script "
58 << QPEApplication::qpeDir()
59 << "/bin/networksettings2-request"
57 << endl 60 << endl
58 << endl; 61 << endl;
59 return 0; 62 return 0;
60 } 63 }
61 return 1; 64 return 1;
62} 65}
63 66
64const char ** NetworkNetNode::needs( void ) { 67const char ** NetworkNetNode::needs( void ) {
65 return NetworkNeeds; 68 return NetworkNeeds;
66} 69}
67 70
68const char * NetworkNetNode::provides( void ) { 71const char * NetworkNetNode::provides( void ) {
69 return "connection"; 72 return "connection";
70} 73}
71 74
72void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { 75void NetworkNetNode::setSpecificAttribute( QString & , QString & ) {
73} 76}
74 77
75void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { 78void NetworkNetNode::saveSpecificAttribute( QTextStream & ) {
76} 79}
77 80
78extern "C" { 81extern "C" {
79void create_plugin( QList<ANetNode> & PNN ) { 82void create_plugin( QList<ANetNode> & PNN ) {
80 PNN.append( new NetworkNetNode() ); 83 PNN.append( new NetworkNetNode() );
81} 84}
82} 85}
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp
index 7ece817..2f17693 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.cpp
+++ b/noncore/settings/networksettings2/networksettings2/resources.cpp
@@ -1,453 +1,450 @@
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 <qpe/qlibrary.h> 7#include <qpe/qlibrary.h>
8#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
9#include <opie2/odebug.h> 9#include <opie2/odebug.h>
10#include <qtopia/resource.h> 10#include <qtopia/resource.h>
11 11
12#include "netnode.h" 12#include "netnode.h"
13#include "resources.h" 13#include "resources.h"
14 14
15#define PLUGINDIR "plugins/networksettings2" 15#define PLUGINDIR "plugins/networksettings2"
16#define ICONDIR "/pics/networksettings2/" 16#define ICONDIR "/pics/networksettings2/"
17 17
18// single resources instance 18// single resources instance
19TheNSResources * _NSResources = 0; 19TheNSResources * _NSResources = 0;
20 20
21TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), 21TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
22 ConnectionsMap() { 22 ConnectionsMap() {
23 23
24 _NSResources = this; 24 _NSResources = this;
25 25
26 detectCurrentUser(); 26 detectCurrentUser();
27 27
28 // load available netnodes 28 // load available netnodes
29 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); 29 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR );
30 30
31 // compile provides and needs lists 31 // compile provides and needs lists
32 { const char ** NeedsRun; 32 { const char ** NeedsRun;
33 QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); 33 QDictIterator<NetNode_t> OuterIt( AllNodeTypes );
34 bool Done; 34 bool Done;
35 35
36 for ( ; OuterIt.current(); ++OuterIt ) { 36 for ( ; OuterIt.current(); ++OuterIt ) {
37 // find needs list 37 // find needs list
38 ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; 38 ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList;
39 ANetNode::NetNodeList & NNL = *(NNLP); 39 ANetNode::NetNodeList & NNL = *(NNLP);
40 40
41 // must iterate this way to avoid duplication pointers 41 // must iterate this way to avoid duplication pointers
42 for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); 42 for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes );
43 InnerIt.current(); ++InnerIt ) { 43 InnerIt.current(); ++InnerIt ) {
44 if( InnerIt.current() == OuterIt.current() ) 44 if( InnerIt.current() == OuterIt.current() )
45 // avoid recursive 45 // avoid recursive
46 continue; 46 continue;
47 47
48 const char * Provides = InnerIt.current()->NetNode->provides(); 48 const char * Provides = InnerIt.current()->NetNode->provides();
49 NeedsRun = OuterIt.current()->NetNode->needs(); 49 NeedsRun = OuterIt.current()->NetNode->needs();
50 for( ; *NeedsRun; NeedsRun ++ ) { 50 for( ; *NeedsRun; NeedsRun ++ ) {
51 if( strcmp( Provides, *NeedsRun ) == 0 ) { 51 if( strcmp( Provides, *NeedsRun ) == 0 ) {
52 // inner provides what outer needs 52 // inner provides what outer needs
53 NNL.resize( NNL.size() + 1 ); 53 NNL.resize( NNL.size() + 1 );
54 NNL[NNL.size()-1] = InnerIt.current()->NetNode; 54 NNL[NNL.size()-1] = InnerIt.current()->NetNode;
55 Done = 1; // break from 2 loops 55 Done = 1; // break from 2 loops
56 break; 56 break;
57 } 57 }
58 } 58 }
59 } 59 }
60 OuterIt.current()->NetNode->setAlternatives( NNLP ); 60 OuterIt.current()->NetNode->setAlternatives( NNLP );
61 } 61 }
62 } 62 }
63 63
64 // define Node types to Description map 64 // define Node types to Description map
65 NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); 65 NodeTypeNameMap.insert( "device", tr( "Network Device" ) );
66 NodeTypeNameMap.insert( "line", tr( "Character device" ) ); 66 NodeTypeNameMap.insert( "line", tr( "Character device" ) );
67 NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); 67 NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) );
68 NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); 68 NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) );
69 69
70 NodeTypeDescriptionMap.insert( "device", 70 NodeTypeDescriptionMap.insert( "device",
71 tr( "<p>Devices that can handle IP packets</p>" ) ); 71 tr( "<p>Devices that can handle IP packets</p>" ) );
72 NodeTypeDescriptionMap.insert( "line", 72 NodeTypeDescriptionMap.insert( "line",
73 tr( "<p>Devices that can handle single bytes</p>" ) ); 73 tr( "<p>Devices that can handle single bytes</p>" ) );
74 NodeTypeDescriptionMap.insert( "connection", 74 NodeTypeDescriptionMap.insert( "connection",
75 tr( "<p>Nodes that provide working IP connections</p>" ) ); 75 tr( "<p>Nodes that provide working IP connections</p>" ) );
76 NodeTypeDescriptionMap.insert( "fullsetup", 76 NodeTypeDescriptionMap.insert( "fullsetup",
77 tr( "<p>Fully configured connection profile</p>" ) ); 77 tr( "<p>Fully configured connection profile</p>" ) );
78 78
79 // define system files 79 // define system files
80 addSystemFile( "interfaces", "/tmp/interfaces", 1 ); 80 addSystemFile( "interfaces", "/tmp/interfaces", 1 );
81 81
82 // get access to the system 82 // get access to the system
83 TheSystem = new System(); 83 TheSystem = new System();
84 84
85} 85}
86 86
87TheNSResources::~TheNSResources( void ) { 87TheNSResources::~TheNSResources( void ) {
88 delete TheSystem; 88 delete TheSystem;
89} 89}
90 90
91void TheNSResources::addSystemFile( const QString & ID, 91void TheNSResources::addSystemFile( const QString & ID,
92 const QString & P, 92 const QString & P,
93 bool KDI ) { 93 bool KDI ) {
94 if( ! SystemFiles.find( ID ) ) { 94 if( ! SystemFiles.find( ID ) ) {
95 // new system file 95 // new system file
96 SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); 96 SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) );
97 } // else existed 97 } // else existed
98} 98}
99 99
100void TheNSResources::busy( bool ) { 100void TheNSResources::busy( bool ) {
101/* 101/*
102 if( B ) { 102 if( B ) {
103 ShowWait->show(); 103 ShowWait->show();
104 qApp->process 104 qApp->process
105 } else { 105 } else {
106 ShowWait->hide(); 106 ShowWait->hide();
107 } 107 }
108*/ 108*/
109} 109}
110 110
111/** 111/**
112 * Load all modules that are found in the path 112 * Load all modules that are found in the path
113 * @param path a directory that is scaned for any plugins that can be loaded 113 * @param path a directory that is scaned for any plugins that can be loaded
114 * and attempts to load them 114 * and attempts to load them
115 */ 115 */
116void TheNSResources::findAvailableNetNodes(const QString &path){ 116void TheNSResources::findAvailableNetNodes(const QString &path){
117 117
118 Log(("Locate plugins in %s\n", path.latin1() )); 118 Log(("Locate plugins in %s\n", path.latin1() ));
119 QDir d(path); 119 QDir d(path);
120 if(!d.exists()) 120 if(!d.exists())
121 return; 121 return;
122 122
123 QString lang = ::getenv("LANG"); 123 QString lang = ::getenv("LANG");
124 124
125 // Don't want sym links 125 // Don't want sym links
126 d.setFilter( QDir::Files | QDir::NoSymLinks ); 126 d.setFilter( QDir::Files | QDir::NoSymLinks );
127 const QFileInfoList *list = d.entryInfoList(); 127 const QFileInfoList *list = d.entryInfoList();
128 QFileInfoListIterator it( *list ); 128 QFileInfoListIterator it( *list );
129 QFileInfo *fi; 129 QFileInfo *fi;
130 130
131 while ( (fi=it.current()) ) { 131 while ( (fi=it.current()) ) {
132 132
133 if( fi->fileName().contains(".so")){ 133 if( fi->fileName().contains(".so")){
134 /* if loaded install translation */ 134 /* if loaded install translation */
135 if( loadNetNode(path + "/" + fi->fileName()) ) { 135 if( loadNetNode(path + "/" + fi->fileName()) ) {
136 QTranslator *trans = new QTranslator(qApp); 136 QTranslator *trans = new QTranslator(qApp);
137 QString fn = QPEApplication::qpeDir()+ 137 QString fn = QPEApplication::qpeDir()+
138 "/i18n/"+lang+"/"+ 138 "/i18n/"+lang+"/"+
139 fi->fileName().left( fi->fileName().find(".") )+ 139 fi->fileName().left( fi->fileName().find(".") )+
140 ".qm"; 140 ".qm";
141 141
142 if( trans->load( fn ) ) 142 if( trans->load( fn ) )
143 qApp->installTranslator( trans ); 143 qApp->installTranslator( trans );
144 else 144 else
145 delete trans; 145 delete trans;
146 } 146 }
147 } 147 }
148 ++it; 148 ++it;
149 } 149 }
150} 150}
151 151
152// used to find unique connection number 152// used to find unique connection number
153int TheNSResources::assignConnectionNumber( void ) { 153int TheNSResources::assignConnectionNumber( void ) {
154 bool found = 1; 154 bool found = 1;
155 for( int trial = 0; ; trial ++ ) { 155 for( int trial = 0; ; trial ++ ) {
156 found = 1; 156 found = 1;
157 for( QDictIterator<NodeCollection> it(ConnectionsMap); 157 for( QDictIterator<NodeCollection> it(ConnectionsMap);
158 it.current(); 158 it.current();
159 ++it ) { 159 ++it ) {
160 if( it.current()->number() == trial ) { 160 if( it.current()->number() == trial ) {
161 found = 0; 161 found = 0;
162 break; 162 break;
163 } 163 }
164 } 164 }
165 165
166 if( found ) { 166 if( found ) {
167 Log(("Assign profile number %d\n", trial )); 167 Log(("Assign profile number %d\n", trial ));
168 return trial; 168 return trial;
169 } 169 }
170 } 170 }
171} 171}
172 172
173/** 173/**
174 * Attempt to load a function and resolve a function. 174 * Attempt to load a function and resolve a function.
175 * @param pluginFileName - the name of the file in which to attempt to load 175 * @param pluginFileName - the name of the file in which to attempt to load
176 * @param resolveString - function pointer to resolve 176 * @param resolveString - function pointer to resolve
177 * @return true of loading is successful 177 * @return true of loading is successful
178 */ 178 */
179bool TheNSResources::loadNetNode( 179bool TheNSResources::loadNetNode(
180 const QString &pluginFileName, const QString &resolveString){ 180 const QString &pluginFileName, const QString &resolveString){
181 181
182 QLibrary *lib = new QLibrary(pluginFileName); 182 QLibrary *lib = new QLibrary(pluginFileName);
183 void * res = lib->resolve(resolveString); 183 void * res = lib->resolve(resolveString);
184 if( ! res ){ 184 if( ! res ){
185 delete lib; 185 delete lib;
186 return 0; 186 return 0;
187 } 187 }
188 188
189 GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; 189 GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res;
190 190
191 // Try to get an object. 191 // Try to get an object.
192 QList<ANetNode> PNN; 192 QList<ANetNode> PNN;
193 193
194 getNetNodeList( PNN ); 194 getNetNodeList( PNN );
195 if( PNN.isEmpty() ) { 195 if( PNN.isEmpty() ) {
196 delete lib; 196 delete lib;
197 return 0; 197 return 0;
198 } 198 }
199 199
200 ANetNode * NNP; 200 ANetNode * NNP;
201 for( QListIterator<ANetNode> it(PNN); 201 for( QListIterator<ANetNode> it(PNN);
202 it.current(); 202 it.current();
203 ++it ) { 203 ++it ) {
204 NetNode_t * NN; 204 NetNode_t * NN;
205 205
206 NNP = it.current(); 206 NNP = it.current();
207 NN = new NetNode_t; 207 NN = new NetNode_t;
208 NN->NetNode = NNP; 208 NN->NetNode = NNP;
209 NN->TheLibrary = lib; 209 NN->TheLibrary = lib;
210 NN->NodeCountInLib = PNN.count(); 210 NN->NodeCountInLib = PNN.count();
211 211
212 // store mapping 212 // store mapping
213 AllNodeTypes.insert( NN->NetNode->name(), NN ); 213 AllNodeTypes.insert( NN->NetNode->name(), NN );
214 } 214 }
215 215
216 return 1; 216 return 1;
217} 217}
218 218
219QPixmap TheNSResources::getPixmap( const QString & QS ) { 219QPixmap TheNSResources::getPixmap( const QString & QS ) {
220 QPixmap P; 220 QPixmap P;
221 QString S("networksettings2/"); 221 QString S("networksettings2/");
222 S += QS; 222 S += QS;
223 Log(("%s\n", S.latin1() )); 223 Log(("%s\n", S.latin1() ));
224 P = Resource::loadPixmap( S ); 224 P = Resource::loadPixmap( S );
225 return ( P.isNull() ) ? QPixmap() : P; 225 return ( P.isNull() ) ? QPixmap() : P;
226} 226}
227 227
228QString TheNSResources::tr( const char * s ) { 228QString TheNSResources::tr( const char * s ) {
229 return qApp->translate( "resource", s ); 229 return qApp->translate( "resource", s );
230} 230}
231 231
232const QString & TheNSResources::netNode2Name( const char * s ) { 232const QString & TheNSResources::netNode2Name( const char * s ) {
233 return NodeTypeNameMap[s]; 233 return NodeTypeNameMap[s];
234} 234}
235 235
236const QString & TheNSResources::netNode2Description( const char * s ) { 236const QString & TheNSResources::netNode2Description( const char * s ) {
237 return NodeTypeDescriptionMap[s]; 237 return NodeTypeDescriptionMap[s];
238} 238}
239 239
240void TheNSResources::addConnection( NodeCollection * NC ) { 240void TheNSResources::addConnection( NodeCollection * NC ) {
241 ANetNodeInstance * NNI; 241 ANetNodeInstance * NNI;
242 ConnectionsMap.insert( NC->name(), NC ); 242 ConnectionsMap.insert( NC->name(), NC );
243 // add (new) nodes to NodeList 243 // add (new) nodes to NodeList
244 for( QListIterator<ANetNodeInstance> it(*NC); 244 for( QListIterator<ANetNodeInstance> it(*NC);
245 it.current(); 245 it.current();
246 ++it ) { 246 ++it ) {
247 NNI = it.current(); 247 NNI = it.current();
248 if( findNodeInstance( NNI->name() ) == 0 ) { 248 if( findNodeInstance( NNI->name() ) == 0 ) {
249 // new item 249 // new item
250 addNodeInstance( NNI ); 250 addNodeInstance( NNI );
251 } 251 }
252 } 252 }
253} 253}
254 254
255void TheNSResources::removeConnection( const QString & N ) { 255void TheNSResources::removeConnection( const QString & N ) {
256 NodeCollection * NC = findConnection( N ); 256 NodeCollection * NC = findConnection( N );
257 if( ! NC ) 257 if( ! NC )
258 return; 258 return;
259 259
260 // delete netnodes in this connection 260 // delete netnodes in this connection
261 ANetNodeInstance * NNI; 261 ANetNodeInstance * NNI;
262 for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { 262 for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) {
263 removeNodeInstance( NNI->name() ); 263 removeNodeInstance( NNI->name() );
264 } 264 }
265 ConnectionsMap.remove( N ); 265 ConnectionsMap.remove( N );
266} 266}
267 267
268NodeCollection * TheNSResources::findConnection( const QString & S ) { 268NodeCollection * TheNSResources::findConnection( const QString & S ) {
269 return ConnectionsMap[ S ]; 269 return ConnectionsMap[ S ];
270} 270}
271 271
272/* 272/*
273void TheNSResources::renumberConnections( void ) { 273void TheNSResources::renumberConnections( void ) {
274 Name2Connection_t & M = NSResources->connections(); 274 Name2Connection_t & M = NSResources->connections();
275 NodeCollection * NC; 275 NodeCollection * NC;
276 276
277 // for all connections 277 // for all connections
278 NodeCollection::resetMaxNr(); 278 NodeCollection::resetMaxNr();
279 for( QDictIterator<NodeCollection> it(M); 279 for( QDictIterator<NodeCollection> it(M);
280 it.current(); 280 it.current();
281 ++it ) { 281 ++it ) {
282 NC = it.current(); 282 NC = it.current();
283 NC->setNumber( NC->maxConnectionNumber()+1 ); 283 NC->setNumber( NC->maxConnectionNumber()+1 );
284 NC->setModified( 1 ); 284 NC->setModified( 1 );
285 } 285 }
286} 286}
287*/ 287*/
288 288
289typedef struct EnvVars { 289typedef struct EnvVars {
290 char * Name; 290 char * Name;
291 int Len; 291 int Len;
292} EnvVar_t; 292} EnvVar_t;
293 293
294#define AnEV(x) x, sizeof(x)-1 294#define AnEV(x) x, sizeof(x)-1
295 295
296static EnvVar_t EV[] = { 296static EnvVar_t EV[] = {
297 // AnEV( "HOME=" ), -> SPECIAL 297 AnEV( "HOME" ),
298 // AnEV( "LOGNAME=" ), -> SPECIAL 298 AnEV( "LOGNAME" ),
299 AnEV( "USER=" ), 299 AnEV( "USER" ),
300 AnEV( "LD_LIBRARY_PATH=" ), 300 AnEV( "LD_LIBRARY_PATH" ),
301 AnEV( "PATH=" ), 301 AnEV( "PATH" ),
302 AnEV( "QTDIR=" ), 302 AnEV( "QTDIR" ),
303 AnEV( "OPIEDIR=" ), 303 AnEV( "OPIEDIR" ),
304 AnEV( "SHELL=" ), 304 AnEV( "SHELL" ),
305 { NULL, 0 } 305 { NULL, 0 }
306}; 306};
307 307
308void TheNSResources::detectCurrentUser( void ) { 308void TheNSResources::detectCurrentUser( void ) {
309 // find current running qpe 309 // find current running qpe
310 QString QPEEnvFile = ""; 310 QString QPEEnvFile = "";
311 311
312 CurrentUser.UserName = "";
313 CurrentUser.HomeDir = "";
314
312 if( getenv( "OPIEDIR" ) == 0 ) { 315 if( getenv( "OPIEDIR" ) == 0 ) {
313 // nothing known 316 // nothing known
314 { // open proc dir and find all dirs in it 317 { // open proc dir and find all dirs in it
315 QRegExp R("[0-9]+"); 318 QRegExp R("[0-9]+");
316 QDir ProcDir( "/proc" ); 319 QDir ProcDir( "/proc" );
317 QFileInfo FI; 320 QFileInfo FI;
318 QStringList EL = ProcDir.entryList( QDir::Dirs ); 321 QStringList EL = ProcDir.entryList( QDir::Dirs );
319 322
320 // print it out 323 // print it out
321 for ( QStringList::Iterator it = EL.begin(); 324 for ( QStringList::Iterator it = EL.begin();
322 it != EL.end(); 325 it != EL.end();
323 ++it ) { 326 ++it ) {
324 if( R.match( (*it) ) >= 0 ) { 327 if( R.match( (*it) ) >= 0 ) {
325 QString S = ProcDir.path()+"/"+ (*it); 328 QString S = ProcDir.path()+"/"+ (*it);
326 S.append( "/exe" ); 329 S.append( "/exe" );
327 FI.setFile( S ); 330 FI.setFile( S );
328 // get the link 331 // get the link
329 S = FI.readLink(); 332 S = FI.readLink();
330 if( S.right( 8 ) == "/bin/qpe" ) { 333 if( S.right( 8 ) == "/bin/qpe" ) {
331 // found running qpe 334 // found running qpe
332 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); 335 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" );
333 break; 336 break;
334 } 337 }
335 } 338 }
336 } 339 }
337 } 340 }
338 341
339 if( QPEEnvFile.isEmpty() ) { 342 if( QPEEnvFile.isEmpty() ) {
340 // could not find qpe 343 // could not find qpe
341 Log(("Could not find qpe\n" )); 344 Log(("Could not find qpe\n" ));
342 return; 345 return;
343 } 346 }
344 347
345 // FI now contains path ProcDir to the cmd dir 348 // FI now contains path ProcDir to the cmd dir
346 { char * Buf = 0; 349 { char * Buf = 0;
347 char TB[1024]; 350 char TB[1024];
348 long BufSize = 0; 351 long BufSize = 0;
349 int fd; 352 int fd;
350 int rd; 353 int rd;
351 354
352 fd = open( QPEEnvFile.latin1(), O_RDONLY ); 355 fd = open( QPEEnvFile.latin1(), O_RDONLY );
353 if( fd < 0 ) { 356 if( fd < 0 ) {
354 Log(("Could not open %s : %d\n", 357 Log(("Could not open %s : %d\n",
355 QPEEnvFile.latin1(), errno )); 358 QPEEnvFile.latin1(), errno ));
356 return; 359 return;
357 } 360 }
358 361
359 while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { 362 while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) {
360 Buf = (char *)realloc( Buf, BufSize+rd ); 363 Buf = (char *)realloc( Buf, BufSize+rd );
361 memcpy( Buf+BufSize, TB, rd ); 364 memcpy( Buf+BufSize, TB, rd );
362 BufSize += rd; 365 BufSize += rd;
363 } 366 }
364 367
365 char * Data = Buf; 368 char * Data = Buf;
366 char * DataEnd = Data+BufSize-1; 369 char * DataEnd = Data+BufSize-1;
367 370
368 // get env items out of list 371 // get env items out of list
369 while( Data < DataEnd ) { 372 while( Data < DataEnd ) {
370 if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) {
371 CurrentUser.UserName = Data+8;
372 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
373 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
374 strdup( Data );
375 } else if( strncmp( Data, "HOME=", 5 ) == 0 ) {
376 CurrentUser.HomeDir = Data+5;
377 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
378 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
379 strdup( Data );
380 } else {
381 EnvVar_t * Run = EV;
382 while( Run->Name ) {
383 if( strncmp( Data, Run->Name, Run->Len ) == 0 ) {
384 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
385 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
386 strdup( Data );
387 // put OPIEDIR in env
388 if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) {
389 putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] );
390 373
391 } 374 EnvVar_t * Run = EV;
392 break; 375 while( Run->Name ) {
376 if( strncmp( Data, Run->Name, Run->Len ) == 0 &&
377 Data[Run->Len] == '='
378 ) {
379 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
380 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
381 strdup( Data );
382
383 if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) {
384 // put OPIEDIR in env
385 putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] );
386 } else if( strcmp( Run->Name, "HOME" ) == 0 ) {
387 CurrentUser.HomeDir = Data+5;
388 } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) {
389 CurrentUser.UserName = Data+8;
393 } 390 }
394 Run ++; 391 break;
395 } 392 }
393 Run ++;
396 } 394 }
397 395
398 Data += strlen( Data )+1; 396 Data += strlen( Data )+1;
399 } 397 }
400 398
401 free( Buf ); 399 free( Buf );
402 400
403 if( ! CurrentUser.UserName.isEmpty() ) { 401 if( ! CurrentUser.UserName.isEmpty() ) {
404 // find user info 402 // find user info
405 struct passwd pwd; 403 struct passwd pwd;
406 struct passwd * pwdres; 404 struct passwd * pwdres;
407 405
408 if( getpwnam_r( CurrentUser.UserName.latin1(), 406 if( getpwnam_r( CurrentUser.UserName.latin1(),
409 &pwd, TB, sizeof(TB), &pwdres ) || 407 &pwd, TB, sizeof(TB), &pwdres ) ||
410 pwdres == 0 ) { 408 pwdres == 0 ) {
411 Log(("Could not determine user %s : %d\n", 409 Log(("Could not determine user %s : %d\n",
412 CurrentUser.UserName.latin1(), errno )); 410 CurrentUser.UserName.latin1(), errno ));
413 return; 411 return;
414 } 412 }
415 CurrentUser.Uid = pwd.pw_uid; 413 CurrentUser.Uid = pwd.pw_uid;
416 CurrentUser.Gid = pwd.pw_gid; 414 CurrentUser.Gid = pwd.pw_gid;
417 } else{ 415 } else{
418 CurrentUser.Uid = 416 CurrentUser.Uid =
419 CurrentUser.Gid = -1; 417 CurrentUser.Gid = -1;
420 } 418 }
421 } 419 }
422 420
423 } else { 421 } else {
424 CurrentUser.UserName = getenv( "LOGNAME" ); 422 char * X;
425 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 423 QString S;
426 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 424
427 strdup( CurrentUser.UserName ); 425 EnvVar_t * Run = EV;
428 426 while( Run->Name ) {
429 CurrentUser.HomeDir = getenv( "HOME" ); 427
430 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 428 if( ( X = getenv( Run->Name ) ) ) {
431 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 429 Log(( "Env : %s = %s\n", Run->Name, X ));
432 strdup( CurrentUser.HomeDir ); 430
433 431 S.sprintf( "%s=%s", Run->Name, X );
434 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 432 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
435 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER"); 433 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
436 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 434 strdup( S.latin1() );
437 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH"); 435
438 436 if( strcmp( Run->Name, "LOGNAME" ) == 0 ) {
439 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 437 CurrentUser.UserName = X;
440 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH"); 438 } else if( strcmp( Run->Name, "HOME" ) == 0 ) {
441 439 CurrentUser.HomeDir = X;
442 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 440 } // regulare env var
443 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR"); 441 } else {
444 442 Log(("Could not determine %s\n", Run->Name ));
445 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 443 }
446 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR"); 444 Run ++;
447 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 445 }
448 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL");
449 446
450 CurrentUser.Uid = getuid(); 447 CurrentUser.Uid = getuid();
451 CurrentUser.Gid = getgid(); 448 CurrentUser.Gid = getgid();
452 } 449 }
453} 450}
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h
index 16355ba..23b120e 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.h
+++ b/noncore/settings/networksettings2/networksettings2/resources.h
@@ -1,132 +1,137 @@
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
12class QLibrary; 12class QLibrary;
13class QPixmap; 13class QPixmap;
14class ANetNode; 14class ANetNode;
15class ANetNodeInstance; 15class ANetNodeInstance;
16 16
17typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); 17typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN );
18 18
19typedef struct NetNode_S { 19typedef struct NetNode_S {
20 ANetNode * NetNode; 20 ANetNode * NetNode;
21 QLibrary * TheLibrary; 21 QLibrary * TheLibrary;
22 long NodeCountInLib; 22 long NodeCountInLib;
23} NetNode_t; 23} NetNode_t;
24 24
25class CurrentQPEUser { 25class CurrentQPEUser {
26 26
27public : 27public :
28 CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} 28 CurrentQPEUser() : UserName(), HomeDir(), EnvList() {}
29 29
30 inline bool known( void )
31 { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); }
32
30 QString UserName; 33 QString UserName;
31 QString HomeDir; 34 QString HomeDir;
32 int Uid; 35 int Uid;
33 int Gid; 36 int Gid;
34 QArray<char *> EnvList; 37 QArray<char *> EnvList;
35}; 38};
36 39
37typedef QDict<NetNode_t> Name2NetNode_t; 40typedef QDict<NetNode_t> Name2NetNode_t;
38typedef QDict<ANetNodeInstance > Name2Instance_t; 41typedef QDict<ANetNodeInstance > Name2Instance_t;
39typedef QDict<NodeCollection> Name2Connection_t; 42typedef QDict<NodeCollection> Name2Connection_t;
40typedef QDict<SystemFile> Name2SystemFile_t; 43typedef QDict<SystemFile> Name2SystemFile_t;
41 44
42class TheNSResources { 45class TheNSResources {
43 46
44public : 47public :
45 48
46 TheNSResources( void ); 49 TheNSResources( void );
47 ~TheNSResources( ); 50 ~TheNSResources( );
48 51
49 // give busy feedback 52 // give busy feedback
50 void busy( bool B ); 53 void busy( bool B );
51 54
52 System & system() 55 System & system()
53 { return *TheSystem; } 56 { return *TheSystem; }
54 57
55 int assignConnectionNumber(void); 58 int assignConnectionNumber(void);
56 QPixmap getPixmap( const QString & Name ); 59 QPixmap getPixmap( const QString & Name );
57 60
58 Name2NetNode_t & netNodes( void ) 61 Name2NetNode_t & netNodes( void )
59 { return AllNodeTypes; } 62 { return AllNodeTypes; }
60 bool netNodeExists( const QString & X ) 63 bool netNodeExists( const QString & X )
61 { return AllNodeTypes.find(X)!=0; } 64 { return AllNodeTypes.find(X)!=0; }
62 ANetNode * findNetNode( const QString & N ) 65 ANetNode * findNetNode( const QString & N )
63 { NetNode_t * NNT = AllNodeTypes.find(N); 66 { NetNode_t * NNT = AllNodeTypes.find(N);
64 return (NNT) ? NNT->NetNode : 0; 67 return (NNT) ? NNT->NetNode : 0;
65 } 68 }
66 69
67 Name2SystemFile_t & systemFiles( void ) 70 Name2SystemFile_t & systemFiles( void )
68 { return SystemFiles; } 71 { return SystemFiles; }
69 void addSystemFile( const QString & ID, 72 void addSystemFile( const QString & ID,
70 const QString & P, 73 const QString & P,
71 bool KDI ); 74 bool KDI );
72 75
73 ANetNodeInstance * createNodeInstance( const QString & S ) 76 ANetNodeInstance * createNodeInstance( const QString & S )
74 { ANetNodeInstance * NNI = 0; 77 { ANetNodeInstance * NNI = 0;
75 NetNode_t * NNT = AllNodeTypes[S]; 78 NetNode_t * NNT = AllNodeTypes[S];
76 if( ! NNT ) { 79 if( ! NNT ) {
77 return 0; 80 return 0;
78 } 81 }
79 NNI = NNT->NetNode->createInstance(); 82 NNI = NNT->NetNode->createInstance();
80 NNI->initialize(); 83 NNI->initialize();
81 return NNI; 84 return NNI;
82 } 85 }
83 86
84 Name2Instance_t & netNodeInstances( void ) 87 Name2Instance_t & netNodeInstances( void )
85 { return AllNodes; } 88 { return AllNodes; }
86 void addNodeInstance( ANetNodeInstance * I ) 89 void addNodeInstance( ANetNodeInstance * I )
87 { AllNodes.insert( I->name(), I ); } 90 { AllNodes.insert( I->name(), I ); }
88 void removeNodeInstance( const QString & N ) 91 void removeNodeInstance( const QString & N )
89 { AllNodes.remove( N );} 92 { AllNodes.remove( N );}
90 ANetNodeInstance * findNodeInstance( const QString & S ) 93 ANetNodeInstance * findNodeInstance( const QString & S )
91 { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } 94 { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; }
92 95
93 const QString & netNode2Name( const char * Type ); 96 const QString & netNode2Name( const char * Type );
94 const QString & netNode2Description( const char * Type ); 97 const QString & netNode2Description( const char * Type );
95 98
96 void addConnection( NodeCollection * NC ); 99 void addConnection( NodeCollection * NC );
97 void removeConnection( const QString & N ); 100 void removeConnection( const QString & N );
98 NodeCollection * findConnection( const QString & N ); 101 NodeCollection * findConnection( const QString & N );
99 Name2Connection_t & connections( void ) 102 Name2Connection_t & connections( void )
100 { return ConnectionsMap; } 103 { return ConnectionsMap; }
101 104
105 inline bool userKnown( void )
106 { return CurrentUser.known(); }
102 CurrentQPEUser & currentUser( void ) 107 CurrentQPEUser & currentUser( void )
103 { return CurrentUser; } 108 { return CurrentUser; }
104 109
105private : 110private :
106 111
107 void detectCurrentUser( void ); 112 void detectCurrentUser( void );
108 QString tr( const char * path ); 113 QString tr( const char * path );
109 void findAvailableNetNodes( const QString &path ); 114 void findAvailableNetNodes( const QString &path );
110 bool loadNetNode( 115 bool loadNetNode(
111 const QString &pluginFileName, 116 const QString &pluginFileName,
112 const QString &resolveString = "create_plugin"); 117 const QString &resolveString = "create_plugin");
113 118
114 QMap< QString, QString> NodeTypeNameMap; 119 QMap< QString, QString> NodeTypeNameMap;
115 QMap< QString, QString> NodeTypeDescriptionMap; 120 QMap< QString, QString> NodeTypeDescriptionMap;
116 Name2Connection_t ConnectionsMap; 121 Name2Connection_t ConnectionsMap;
117 System * TheSystem; 122 System * TheSystem;
118 Name2SystemFile_t SystemFiles; 123 Name2SystemFile_t SystemFiles;
119 124
120 // all node type classes 125 // all node type classes
121 Name2NetNode_t AllNodeTypes; 126 Name2NetNode_t AllNodeTypes;
122 127
123 // all nodes 128 // all nodes
124 Name2Instance_t AllNodes; 129 Name2Instance_t AllNodes;
125 130
126 CurrentQPEUser CurrentUser; 131 CurrentQPEUser CurrentUser;
127}; 132};
128 133
129extern TheNSResources * _NSResources; 134extern TheNSResources * _NSResources;
130#define NSResources _NSResources 135#define NSResources _NSResources
131 136
132#endif 137#endif
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index d709c0a..e2dd5b5 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -1,593 +1,603 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <qfile.h> 5#include <qfile.h>
6#include <qfileinfo.h> 6#include <qfileinfo.h>
7 7
8#include "nsdata.h" 8#include "nsdata.h"
9#include <asdevice.h> 9#include <asdevice.h>
10#include <resources.h> 10#include <resources.h>
11 11
12static QString CfgFile; 12static QString CfgFile;
13 13
14NetworkSettingsData::NetworkSettingsData( void ) { 14NetworkSettingsData::NetworkSettingsData( void ) {
15 // init global resources structure 15 // init global resources structure
16 new TheNSResources(); 16 new TheNSResources();
17 17
18 if( ! NSResources->userKnown() ) {
19 Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n",
20 NSResources->currentUser().HomeDir.latin1(),
21 NSResources->currentUser().UserName.latin1() ));
22 return;
23 }
24
18 CfgFile.sprintf( "%s/Settings/NS2.conf", 25 CfgFile.sprintf( "%s/Settings/NS2.conf",
19 NSResources->currentUser().HomeDir.latin1() ); 26 NSResources->currentUser().HomeDir.latin1() );
20 Log(( "Cfg from %s\n", CfgFile.latin1() )); 27 Log(( "Cfg from %s\n", CfgFile.latin1() ));
21 28
22 // load settings 29 // load settings
23 IsModified = 0; 30 IsModified = 0;
24 loadSettings(); 31 loadSettings();
25} 32}
26 33
27// saving is done by caller 34// saving is done by caller
28NetworkSettingsData::~NetworkSettingsData( void ) { 35NetworkSettingsData::~NetworkSettingsData( void ) {
29 delete NSResources; 36 delete NSResources;
30} 37}
31 38
32void NetworkSettingsData::loadSettings( void ) { 39void NetworkSettingsData::loadSettings( void ) {
33 QString Line, S; 40 QString Line, S;
34 QString Attr, Value; 41 QString Attr, Value;
35 long idx; 42 long idx;
36 43
37 QFile F( CfgFile ); 44 QFile F( CfgFile );
38 QTextStream TS( &F ); 45 QTextStream TS( &F );
39 46
40 do { 47 do {
41 48
42 if( ! F.open(IO_ReadOnly) ) 49 if( ! F.open(IO_ReadOnly) )
43 break; 50 break;
44 51
45 /* load the file -> 52 /* load the file ->
46 53
47 FORMAT : 54 FORMAT :
48 55
49 [NETNODETYPE] 56 [NETNODETYPE]
50 Entries ... 57 Entries ...
51 <EMPTYLINE> 58 <EMPTYLINE>
52 [connection] 59 [connection]
53 Name=Name 60 Name=Name
54 Node=Name 61 Node=Name
55 <EMPTYLINE> 62 <EMPTYLINE>
56 */ 63 */
57 while( ! TS.atEnd() ) { 64 while( ! TS.atEnd() ) {
58 S = Line = TS.readLine(); 65 S = Line = TS.readLine();
59 66
60 if ( S.isEmpty() || S[0] != '[' ) 67 if ( S.isEmpty() || S[0] != '[' )
61 continue; 68 continue;
62 69
63 S = S.mid( 1, S.length()-2 ); 70 S = S.mid( 1, S.length()-2 );
64 71
65 if( ! NSResources ) { 72 if( ! NSResources ) {
66 continue; 73 continue;
67 } 74 }
68 75
69 if( S == "connection" ) { 76 if( S == "connection" ) {
70 // load connections -> collections of nodes 77 // load connections -> collections of nodes
71 NodeCollection * NC = new NodeCollection( TS ); 78 NodeCollection * NC = new NodeCollection( TS );
72 NSResources->addConnection( NC ); 79 NSResources->addConnection( NC );
73 } else { 80 } else {
74 ANetNode * NN = 0; 81 ANetNode * NN = 0;
75 ANetNodeInstance* NNI = 0; 82 ANetNodeInstance* NNI = 0;
76 if( S.startsWith( "nodetype " ) ) { 83 if( S.startsWith( "nodetype " ) ) {
77 S = S.mid( 9, S.length()-9 ); 84 S = S.mid( 9, S.length()-9 );
78 S = deQuote(S); 85 S = deQuote(S);
79 // try to find netnode 86 // try to find netnode
80 NN = NSResources->findNetNode( S ); 87 NN = NSResources->findNetNode( S );
81 Log( ( "Node %s : %p\n", S.latin1(), NN ) ); 88 Log( ( "Node %s : %p\n", S.latin1(), NN ) );
82 } else { 89 } else {
83 // try to find instance 90 // try to find instance
84 NNI = NSResources->createNodeInstance( S ); 91 NNI = NSResources->createNodeInstance( S );
85 Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); 92 Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI ));
86 } 93 }
87 94
88 if( NN == 0 && NNI == 0 ) { 95 if( NN == 0 && NNI == 0 ) {
89 LeftOvers.append( Line ); 96 LeftOvers.append( Line );
90 } 97 }
91 98
92 do { 99 do {
93 S = Line = TS.readLine(); 100 S = Line = TS.readLine();
94 101
95 if( NN || NNI ) { 102 if( NN || NNI ) {
96 if( S.isEmpty() ) { 103 if( S.isEmpty() ) {
97 // empty line 104 // empty line
98 break; 105 break;
99 } 106 }
100 idx = S.find( '=' ); 107 idx = S.find( '=' );
101 if( idx > 0 ) { 108 if( idx > 0 ) {
102 Attr = S.left( idx ); 109 Attr = S.left( idx );
103 Value = S.mid( idx+1, S.length() ); 110 Value = S.mid( idx+1, S.length() );
104 } else { 111 } else {
105 Value=""; 112 Value="";
106 Attr = S; 113 Attr = S;
107 } 114 }
108 115
109 Value.stripWhiteSpace(); 116 Value.stripWhiteSpace();
110 Attr.stripWhiteSpace(); 117 Attr.stripWhiteSpace();
111 Attr.lower(); 118 Attr.lower();
112 // dequote Attr 119 // dequote Attr
113 Value = deQuote(Value); 120 Value = deQuote(Value);
114 121
115 if( NN ) { 122 if( NN ) {
116 // set the attribute 123 // set the attribute
117 NN->setAttribute( Attr, Value ); 124 NN->setAttribute( Attr, Value );
118 } else { 125 } else {
119 // set the attribute 126 // set the attribute
120 NNI->setAttribute( Attr, Value ); 127 NNI->setAttribute( Attr, Value );
121 } 128 }
122 } else { 129 } else {
123 LeftOvers.append( Line ); 130 LeftOvers.append( Line );
124 // add empty line too as delimiter 131 // add empty line too as delimiter
125 if( S.isEmpty() ) { 132 if( S.isEmpty() ) {
126 // empty line 133 // empty line
127 break; 134 break;
128 } 135 }
129 } 136 }
130 } while( 1 ); 137 } while( 1 );
131 138
132 if( NNI ) { 139 if( NNI ) {
133 // loading from file -> exists 140 // loading from file -> exists
134 NNI->setNew( FALSE ); 141 NNI->setNew( FALSE );
135 NSResources->addNodeInstance( NNI ); 142 NSResources->addNodeInstance( NNI );
136 } 143 }
137 } 144 }
138 } 145 }
139 146
140 } while( 0 ); 147 } while( 0 );
141 148
142} 149}
143 150
144QString NetworkSettingsData::saveSettings( void ) { 151QString NetworkSettingsData::saveSettings( void ) {
145 QString ErrS = ""; 152 QString ErrS = "";
146 153
147 if( ! isModified() ) 154 if( ! isModified() )
148 return ErrS; 155 return ErrS;
149 156
150 QString S; 157 QString S;
151 QFile F( CfgFile + ".bup" ); 158 QFile F( CfgFile + ".bup" );
152 159
153 Log( ( "Saving settings to %s\n", CfgFile.latin1() )); 160 Log( ( "Saving settings to %s\n", CfgFile.latin1() ));
154 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { 161 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
155 ErrS = qApp->translate( "NetworkSettings", 162 ErrS = qApp->translate( "NetworkSettings",
156 "<p>Could not save setup to \"%1\" !</p>" ). 163 "<p>Could not save setup to \"%1\" !</p>" ).
157 arg(CfgFile); 164 arg(CfgFile);
158 // problem 165 // problem
159 return ErrS; 166 return ErrS;
160 } 167 }
161 168
162 QTextStream TS( &F ); 169 QTextStream TS( &F );
163 170
164 // save leftovers 171 // save leftovers
165 for ( QStringList::Iterator it = LeftOvers.begin(); 172 for ( QStringList::Iterator it = LeftOvers.begin();
166 it != LeftOvers.end(); ++it ) { 173 it != LeftOvers.end(); ++it ) {
167 TS << (*it) << endl; 174 TS << (*it) << endl;
168 } 175 }
169 176
170 // save global configs 177 // save global configs
171 for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); 178 for( QDictIterator<NetNode_t> it( NSResources->netNodes() );
172 it.current(); 179 it.current();
173 ++it ) { 180 ++it ) {
174 TS << "[nodetype " 181 TS << "[nodetype "
175 << quote( QString( it.current()->NetNode->name() ) ) 182 << quote( QString( it.current()->NetNode->name() ) )
176 << "]" 183 << "]"
177 << endl; 184 << endl;
178 185
179 it.current()->NetNode->saveAttributes( TS ); 186 it.current()->NetNode->saveAttributes( TS );
180 TS << endl; 187 TS << endl;
181 } 188 }
182 189
183 { Name2Connection_t & M = NSResources->connections(); 190 { Name2Connection_t & M = NSResources->connections();
184 ANetNodeInstance * NNI; 191 ANetNodeInstance * NNI;
185 192
186 // for all connections 193 // for all connections
187 for( QDictIterator<NodeCollection> it(M); 194 for( QDictIterator<NodeCollection> it(M);
188 it.current(); 195 it.current();
189 ++it ) { 196 ++it ) {
190 // all nodes in those connections 197 // all nodes in those connections
191 for( QListIterator<ANetNodeInstance> nit(*(it.current())); 198 for( QListIterator<ANetNodeInstance> nit(*(it.current()));
192 nit.current(); 199 nit.current();
193 ++nit ) { 200 ++nit ) {
194 // header 201 // header
195 NNI = nit.current(); 202 NNI = nit.current();
196 TS << '[' 203 TS << '['
197 << QString(NNI->nodeClass()->name()) 204 << QString(NNI->nodeClass()->name())
198 << ']' 205 << ']'
199 << endl; 206 << endl;
200 NNI->saveAttributes( TS ); 207 NNI->saveAttributes( TS );
201 TS << endl; 208 TS << endl;
202 } 209 }
203 210
204 TS << "[connection]" << endl; 211 TS << "[connection]" << endl;
205 it.current()->save(TS); 212 it.current()->save(TS);
206 } 213 }
207 } 214 }
208 215
209 QDir D("."); 216 QDir D(".");
210 D.rename( CfgFile + ".bup", CfgFile ); 217 D.rename( CfgFile + ".bup", CfgFile );
211 218
212 // 219 //
213 // proper files AND system files regenerated 220 // proper files AND system files regenerated
214 // 221 //
215 222
216 setModified( 0 ); 223 setModified( 0 );
217 return ErrS; 224 return ErrS;
218} 225}
219 226
220QString NetworkSettingsData::generateSettings( void ) { 227QString NetworkSettingsData::generateSettings( void ) {
221 QString S = ""; 228 QString S = "";
222 Name2SystemFile_t & SFM = NSResources->systemFiles(); 229 Name2SystemFile_t & SFM = NSResources->systemFiles();
223 Name2Connection_t & M = NSResources->connections(); 230 Name2Connection_t & M = NSResources->connections();
224 NodeCollection * NC; 231 NodeCollection * NC;
225 ANetNodeInstance * NNI; 232 ANetNodeInstance * NNI;
226 ANetNodeInstance * FirstWithData; 233 ANetNodeInstance * FirstWithData;
227 SystemFile * SF; 234 SystemFile * SF;
228 AsDevice * CurDev; 235 AsDevice * CurDev;
229 ANetNode * NN, * CurDevNN = 0; 236 ANetNode * NN, * CurDevNN = 0;
230 long NoOfDevs; 237 long NoOfDevs;
231 long DevCtStart; 238 long DevCtStart;
232 bool needToGenerate; 239 bool needToGenerate;
233 240
234 // regenerate system files 241 // regenerate system files
235 Log( ( "Generating settings from %s\n", CfgFile.latin1() )); 242 Log( ( "Generating settings from %s\n", CfgFile.latin1() ));
236 243
237 // 244 //
238 // generate files proper to each netnodeinstance 245 // generate files proper to each netnodeinstance
239 // 246 //
240 { Name2Instance_t & NNIs = NSResources->netNodeInstances(); 247 { Name2Instance_t & NNIs = NSResources->netNodeInstances();
241 248
242 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); 249 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs);
243 NNIIt.current(); 250 NNIIt.current();
244 ++NNIIt ) { 251 ++NNIIt ) {
245 // for all nodes find those that are modified 252 // for all nodes find those that are modified
246 NNI = NNIIt.current(); 253 NNI = NNIIt.current();
247 254
248 { // get list of proper files for this nodeclass (if any) 255 { // get list of proper files for this nodeclass (if any)
249 QStringList * PF = NNI->nodeClass()->properFiles(); 256 QStringList * PF = NNI->nodeClass()->properFiles();
250 257
251 if( PF ) { 258 if( PF ) {
252 for ( QStringList::Iterator it = PF->begin(); 259 for ( QStringList::Iterator it = PF->begin();
253 it != PF->end(); 260 it != PF->end();
254 ++it ) { 261 ++it ) {
255 QFile * F = NNI->openFile( (*it) ); 262 QFile * F = NNI->openFile( (*it) );
256 if( F ) { 263 if( F ) {
257 QTextStream TS( F ); 264 QTextStream TS( F );
258 if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { 265 if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) {
259 // problem generating 266 // problem generating
260 S = qApp->translate( "NetworkSettings", 267 S = qApp->translate( "NetworkSettings",
261 "<p>Cannot generate files proper to \"%1\"</p>" ). 268 "<p>Cannot generate files proper to \"%1\"</p>" ).
262 arg(NNI->nodeClass()->name()) ; 269 arg(NNI->nodeClass()->name()) ;
263 delete F; 270 delete F;
264 return S; 271 return S;
265 } 272 }
266 delete F; 273 delete F;
267 } 274 }
268 } 275 }
269 } 276 }
270 } 277 }
271 } 278 }
272 } 279 }
273 280
274 // 281 //
275 // generate all system files 282 // generate all system files
276 // 283 //
277 for( QDictIterator<SystemFile> sfit(SFM); 284 for( QDictIterator<SystemFile> sfit(SFM);
278 sfit.current(); 285 sfit.current();
279 ++sfit ) { 286 ++sfit ) {
280 SF = sfit.current(); 287 SF = sfit.current();
281 288
282 // reset all 289 // reset all
283 for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); 290 for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() );
284 nnit.current(); 291 nnit.current();
285 ++nnit ) { 292 ++nnit ) {
286 nnit.current()->NetNode->setDone(0); 293 nnit.current()->NetNode->setDone(0);
287 } 294 }
288 295
289 for( QDictIterator<ANetNodeInstance> nniit( 296 for( QDictIterator<ANetNodeInstance> nniit(
290 NSResources->netNodeInstances() ); 297 NSResources->netNodeInstances() );
291 nniit.current(); 298 nniit.current();
292 ++nniit ) { 299 ++nniit ) {
293 nniit.current()->setDone(0); 300 nniit.current()->setDone(0);
294 } 301 }
295 302
296 for( QDictIterator<NodeCollection> ncit(M); 303 for( QDictIterator<NodeCollection> ncit(M);
297 ncit.current(); 304 ncit.current();
298 ++ncit ) { 305 ++ncit ) {
299 ncit.current()->setDone(0); 306 ncit.current()->setDone(0);
300 } 307 }
301 308
302 Log( ( "Generating %s\n", SF->name().latin1() )); 309 Log( ( "Generating %s\n", SF->name().latin1() ));
303 310
304 needToGenerate = 0; 311 needToGenerate = 0;
305 312
306 // are there netnodes that have instances and need 313 // are there netnodes that have instances and need
307 // to write data in this system file ? 314 // to write data in this system file ?
308 for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); 315 for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() );
309 ! needToGenerate && nnit.current(); 316 ! needToGenerate && nnit.current();
310 ++nnit ) { 317 ++nnit ) {
311 318
312 NN = nnit.current()->NetNode; 319 NN = nnit.current()->NetNode;
313 320
314 if( NN->hasDataForFile( SF->name() ) ) { 321 if( NN->hasDataForFile( SF->name() ) ) {
315 // netnode can have data 322 // netnode can have data
316 323
317 // are there instances of this node ? 324 // are there instances of this node ?
318 for( QDictIterator<ANetNodeInstance> nniit( 325 for( QDictIterator<ANetNodeInstance> nniit(
319 NSResources->netNodeInstances() ); 326 NSResources->netNodeInstances() );
320 ! needToGenerate && nniit.current(); 327 ! needToGenerate && nniit.current();
321 ++nniit ) { 328 ++nniit ) {
322 if( nniit.current()->nodeClass() == NN ) { 329 if( nniit.current()->nodeClass() == NN ) {
323 // yes 330 // yes
324 Log(("Node %s has data\n", 331 Log(("Node %s has data\n",
325 nniit.current()->name() )); 332 nniit.current()->name() ));
326 needToGenerate = 1; 333 needToGenerate = 1;
327 break; 334 break;
328 } 335 }
329 } 336 }
330 } 337 }
331 } 338 }
332 339
333 if( ! needToGenerate ) { 340 if( ! needToGenerate ) {
334 // no instances found that might need to write data 341 // no instances found that might need to write data
335 // in this systemfile 342 // in this systemfile
336 Log(("No nodes for systemfile %s\n", SF->name().latin1() )); 343 Log(("No nodes for systemfile %s\n", SF->name().latin1() ));
337 continue; 344 continue;
338 } 345 }
339 346
340 // ok generate this system file 347 // ok generate this system file
341 SF->open(); 348 SF->open();
342 349
343 // global presection for this system file 350 // global presection for this system file
344 if( ! SF->preSection() ) { 351 if( ! SF->preSection() ) {
345 S = qApp->translate( "NetworkSettings", 352 S = qApp->translate( "NetworkSettings",
346 "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). 353 "<p>Error in section \"Preamble\" for file \"%1\"</p>" ).
347 arg( SF->name() ); 354 arg( SF->name() );
348 return S; 355 return S;
349 } 356 }
350 357
351 // find connections that want to write to this file 358 // find connections that want to write to this file
352 for( QDictIterator<NodeCollection> ncit(M); 359 for( QDictIterator<NodeCollection> ncit(M);
353 ncit.current(); 360 ncit.current();
354 ++ncit ) { 361 ++ncit ) {
355 362
356 NC = ncit.current(); 363 NC = ncit.current();
357 364
358 if( NC->done() ) { 365 if( NC->done() ) {
359 // already done 366 // already done
360 continue; 367 continue;
361 } 368 }
362 369
363 if( ! NC->hasDataForFile( SF->name() ) ) { 370 if( ! NC->hasDataForFile( SF->name() ) ) {
364 // no data 371 // no data
365 continue; 372 continue;
366 } 373 }
367 374
368 Log(("Generating %s for connection %s\n", 375 Log(("Generating %s for connection %s\n",
369 SF->name().latin1(), NC->name().latin1() )); 376 SF->name().latin1(), NC->name().latin1() ));
370 // find highest item that wants to write data to this file 377 // find highest item that wants to write data to this file
371 FirstWithData = NC->firstWithDataForFile( SF->name() ); 378 FirstWithData = NC->firstWithDataForFile( SF->name() );
372 379
373 // find device on which this connection works 380 // find device on which this connection works
374 CurDev = NC->device(); 381 CurDev = NC->device();
375 // class of that node 382 // class of that node
376 CurDevNN = CurDev->netNode()->nodeClass(); 383 CurDevNN = CurDev->netNode()->nodeClass();
377 384
378 Log(( "%s is done %d\n", 385 Log(( "%s is done %d\n",
379 FirstWithData->nodeClass()->name(), 386 FirstWithData->nodeClass()->name(),
380 FirstWithData->nodeClass()->done() )); 387 FirstWithData->nodeClass()->done() ));
381 388
382 if( ! FirstWithData->nodeClass()->done() ) { 389 if( ! FirstWithData->nodeClass()->done() ) {
383 // generate fixed part 390 // generate fixed part
384 if( ! SF->preDeviceSection( CurDevNN ) ) { 391 if( ! SF->preDeviceSection( CurDevNN ) ) {
385 S = qApp->translate( "NetworkSettings", 392 S = qApp->translate( "NetworkSettings",
386 "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). 393 "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ).
387 arg( SF->name() ); 394 arg( SF->name() );
388 return S; 395 return S;
389 } 396 }
390 397
391 if( FirstWithData->nodeClass()->generateFile( 398 if( FirstWithData->nodeClass()->generateFile(
392 SF->name(), SF->path(), *SF, -1 ) == 2 ) { 399 SF->name(), SF->path(), *SF, -1 ) == 2 ) {
393 S = qApp->translate( "NetworkSettings", 400 S = qApp->translate( "NetworkSettings",
394 "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). 401 "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ).
395 arg( SF->name() ). 402 arg( SF->name() ).
396 arg( CurDevNN->name() ); 403 arg( CurDevNN->name() );
397 return S; 404 return S;
398 } 405 }
399 FirstWithData->nodeClass()->setDone( 1 ); 406 FirstWithData->nodeClass()->setDone( 1 );
400 } 407 }
401 408
402 NoOfDevs = 0; 409 NoOfDevs = 0;
403 DevCtStart = -1; 410 DevCtStart = -1;
404 411
405 if( SF->knowsDeviceInstances() ) { 412 if( SF->knowsDeviceInstances() ) {
406 DevCtStart = 0; 413 DevCtStart = 0;
407 NoOfDevs = CurDevNN->instanceCount(); 414 NoOfDevs = CurDevNN->instanceCount();
408 } 415 }
409 416
410 Log(( "Node %s is done %d\n", 417 Log(( "Node %s is done %d\n",
411 CurDev->netNode()->nodeClass()->name(), 418 CurDev->netNode()->nodeClass()->name(),
412 CurDev->netNode()->nodeClass()->done() )); 419 CurDev->netNode()->nodeClass()->done() ));
413 420
414 if( ! CurDev->netNode()->nodeClass()->done() ) { 421 if( ! CurDev->netNode()->nodeClass()->done() ) {
415 // first time this device is handled 422 // first time this device is handled
416 // generate common device specific part 423 // generate common device specific part
417 for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { 424 for( int i = DevCtStart; i < NoOfDevs ; i ++ ) {
418 425
419 if( FirstWithData->nodeClass()->generateFile( 426 if( FirstWithData->nodeClass()->generateFile(
420 SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { 427 SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) {
421 S = qApp->translate( "NetworkSettings", 428 S = qApp->translate( "NetworkSettings",
422 "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). 429 "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ).
423 arg( SF->name() ). 430 arg( SF->name() ).
424 arg( CurDevNN->name() ); 431 arg( CurDevNN->name() );
425 return S; 432 return S;
426 } 433 }
427 } 434 }
428 CurDev->netNode()->nodeClass()->setDone( 1 ); 435 CurDev->netNode()->nodeClass()->setDone( 1 );
429 } 436 }
430 437
431 // generate profile specific info 438 // generate profile specific info
432 // for all nodeconnections that work on the same device 439 // for all nodeconnections that work on the same device
433 for( QDictIterator<NodeCollection> ncit2(M); 440 for( QDictIterator<NodeCollection> ncit2(M);
434 ncit2.current(); 441 ncit2.current();
435 ++ncit2 ) { 442 ++ncit2 ) {
436 443
437 if( ncit2.current()->device() != CurDev ) { 444 if( ncit2.current()->device() != CurDev ) {
438 // different device 445 // different device
439 continue; 446 continue;
440 } 447 }
441 448
442 Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); 449 Log(("Connection %s of same family\n", ncit2.current()->name().latin1() ));
443 // generate 450 // generate
444 NNI = ncit2.current()->firstWithDataForFile( SF->name() ); 451 NNI = ncit2.current()->firstWithDataForFile( SF->name() );
445 for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { 452 for( int i = DevCtStart; i < NoOfDevs ; i ++ ) {
446 if( ! SF->preNodeSection( NNI, i ) ) { 453 if( ! SF->preNodeSection( NNI, i ) ) {
447 S = qApp->translate( "NetworkSettings", 454 S = qApp->translate( "NetworkSettings",
448 "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). 455 "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ).
449 arg( SF->name() ). 456 arg( SF->name() ).
450 arg( CurDevNN->name() ); 457 arg( CurDevNN->name() );
451 return S; 458 return S;
452 } 459 }
453 460
454 switch( NNI->generateFile( 461 switch( NNI->generateFile(
455 SF->name(), SF->path(), *SF, i ) ) { 462 SF->name(), SF->path(), *SF, i ) ) {
456 case 0 : 463 case 0 :
457 (*SF) << endl; 464 (*SF) << endl;
458 break; 465 break;
459 case 1 : 466 case 1 :
460 break; 467 break;
461 case 2 : 468 case 2 :
462 S = qApp->translate( "NetworkSettings", 469 S = qApp->translate( "NetworkSettings",
463 "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). 470 "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ).
464 arg( SF->name() ). 471 arg( SF->name() ).
465 arg( CurDevNN->name() ); 472 arg( CurDevNN->name() );
466 return S; 473 return S;
467 } 474 }
468 475
469 if( ! SF->postNodeSection( NNI, i ) ) { 476 if( ! SF->postNodeSection( NNI, i ) ) {
470 S = qApp->translate( "NetworkSettings", 477 S = qApp->translate( "NetworkSettings",
471 "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). 478 "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ).
472 arg( SF->name() ). 479 arg( SF->name() ).
473 arg( CurDevNN->name() ); 480 arg( CurDevNN->name() );
474 return S; 481 return S;
475 } 482 }
476 } 483 }
477 484
478 ncit2.current()->setDone( 1 ); 485 ncit2.current()->setDone( 1 );
479 486
480 } 487 }
481 } 488 }
482 489
483 if( ! SF->postDeviceSection( CurDevNN ) ) { 490 if( ! SF->postDeviceSection( CurDevNN ) ) {
484 S = qApp->translate( "NetworkSettings", 491 S = qApp->translate( "NetworkSettings",
485 "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). 492 "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ).
486 arg( SF->name() ). 493 arg( SF->name() ).
487 arg( CurDevNN->name() ); 494 arg( CurDevNN->name() );
488 return S; 495 return S;
489 } 496 }
490 497
491 498
492 if( ! SF->postSection() ) { 499 if( ! SF->postSection() ) {
493 S = qApp->translate( "NetworkSettings", 500 S = qApp->translate( "NetworkSettings",
494 "<p>Error in section \"Closure\" for file \"%1\"</p>" ). 501 "<p>Error in section \"Closure\" for file \"%1\"</p>" ).
495 arg( SF->name() ); 502 arg( SF->name() );
496 return S; 503 return S;
497 } 504 }
498 505
499 // end of file 506 // end of file
500 SF->close(); 507 SF->close();
501 } 508 }
502 return S; 509 return S;
503} 510}
504 511
505QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { 512QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) {
506 // collect connections that can work on top of this interface 513 // collect connections that can work on top of this interface
507 NodeCollection * NC; 514 NodeCollection * NC;
508 QList<NodeCollection> PossibleConnections; 515 QList<NodeCollection> PossibleConnections;
509 Name2Connection_t & M = NSResources->connections(); 516 Name2Connection_t & M = NSResources->connections();
510 517
511 // for all connections 518 // for all connections
512 for( QDictIterator<NodeCollection> it(M); 519 for( QDictIterator<NodeCollection> it(M);
513 it.current(); 520 it.current();
514 ++it ) { 521 ++it ) {
515 NC = it.current(); 522 NC = it.current();
516 // check if this profile handles the requested interface 523 // check if this profile handles the requested interface
517 if( NC->handlesInterface( Interface ) && // if different Intf. 524 if( NC->handlesInterface( Interface ) && // if different Intf.
518 NC->state() != Disabled && // if not enabled 525 NC->state() != Disabled && // if not enabled
519 NC->state() != IsUp // if already used 526 NC->state() != IsUp // if already used
520 ) { 527 ) {
521 Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); 528 Log( ( "Append %s for %s\n", NC->name().latin1(), Interface));
522 PossibleConnections.append( NC ); 529 PossibleConnections.append( NC );
523 } 530 }
524 } 531 }
525 return PossibleConnections; 532 return PossibleConnections;
526} 533}
527 534
528 535
529/* 536/*
530 Called by the system to see if interface can be brought UP 537 Called by the system to see if interface can be brought UP
531 538
532 if allowed, echo Interface-allowed else Interface-disallowed 539 if allowed, echo Interface-allowed else Interface-disallowed
533*/ 540*/
534 541
535bool NetworkSettingsData::canStart( const char * Interface ) { 542bool NetworkSettingsData::canStart( const char * Interface ) {
536 // load situation 543 // load situation
537 NodeCollection * NC = 0; 544 NodeCollection * NC = 0;
538 QList<NodeCollection> PossibleConnections; 545 QList<NodeCollection> PossibleConnections;
539 546
540 PossibleConnections = collectPossible( Interface ); 547 PossibleConnections = collectPossible( Interface );
541 548
542 Log( ( "Possiblilies %d\n", PossibleConnections.count() )); 549 Log( ( "for %s : Possiblilies %d\n",
550 Interface, PossibleConnections.count() ));
543 switch( PossibleConnections.count() ) { 551 switch( PossibleConnections.count() ) {
544 case 0 : // no connections 552 case 0 : // no connections
545 break; 553 break;
546 case 1 : // one connection 554 case 1 : // one connection
547 NC = PossibleConnections.first(); 555 NC = PossibleConnections.first();
548 break; 556 break;
549 default : // need to ask user ? 557 default : // need to ask user ?
550 return 1; 558 return 1;
551 } 559 }
552 560
553 if( NC ) { 561 if( NC ) {
554 switch( NC->state() ) { 562 switch( NC->state() ) {
555 case Unchecked : 563 case Unchecked :
556 case Unknown : 564 case Unknown :
557 case Unavailable : 565 case Unavailable :
558 case Disabled : 566 case Disabled :
559 // this profile does not allow interface to be UP 567 // this profile does not allow interface to be UP
560 // -> try others 568 // -> try others
561 break; 569 break;
562 case Off : 570 case Off :
563 // try to UP the device 571 // try to UP the device
564 if( ! NC->setState( Activate ) ) { 572 if( ! NC->setState( Activate ) ) {
565 // cannot bring device Online -> try other alters 573 // cannot bring device Online -> try other alters
566 break; 574 break;
567 } 575 }
568 // FT 576 // FT
569 case Available : 577 case Available :
570 case IsUp : // also called for 'ifdown' 578 case IsUp : // also called for 'ifdown'
571 // device is ready -> done 579 // device is ready -> done
580 Log(( "%s-c%d-allowed\n", Interface, NC->number() ));
572 printf( "%s-c%d-allowed\n", Interface, NC->number() ); 581 printf( "%s-c%d-allowed\n", Interface, NC->number() );
573 return 0; 582 return 0;
574 } 583 }
575 } 584 }
576 585
577 // if we come here no alternatives are possible 586 // if we come here no alternatives are possible
587 Log(( "%s-cnn-disallowed\n", Interface ));
578 printf( "%s-cnn-disallowed\n", Interface ); 588 printf( "%s-cnn-disallowed\n", Interface );
579 return 0; 589 return 0;
580} 590}
581 591
582/* 592/*
583 Called by the system to regenerate config files 593 Called by the system to regenerate config files
584*/ 594*/
585 595
586bool NetworkSettingsData::regenerate( void ) { 596bool NetworkSettingsData::regenerate( void ) {
587 QString S = generateSettings(); 597 QString S = generateSettings();
588 if( ! S.isEmpty() ) { 598 if( ! S.isEmpty() ) {
589 fprintf( stdout, "%s\n", S.latin1() ); 599 fprintf( stdout, "%s\n", S.latin1() );
590 return 1; 600 return 1;
591 } 601 }
592 return 0; 602 return 0;
593} 603}