summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/main.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/main.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/main.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp
index 973b4b7..2243826 100644
--- a/noncore/settings/networksettings2/main.cpp
+++ b/noncore/settings/networksettings2/main.cpp
@@ -14,28 +14,30 @@ using namespace Opie::Core;
14OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) 14OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> )
15 15
16#else 16#else
17 17
18// just standard GUI 18// just standard GUI
19#define ACT_GUI 0 19#define ACT_GUI 0
20// used by interfaces to request for allow of up/down 20// used by interfaces to request for allow of up/down
21#define ACT_REQUEST 1 21#define ACT_REQUEST 1
22// regenerate config files 22// regenerate config files
23#define ACT_REGEN 2 23#define ACT_REGEN 2
24// used by interfaces to request user prompt 24// used by interfaces to request user prompt
25#define ACT_PROMPT 3 25#define ACT_PROMPT 3
26// used by interfaces to trigger VPN 26// used by interfaces to trigger VPN prompting
27#define ACT_VPN 4 27#define ACT_TRIGGERVPN 4
28// activate opietooth 28// activate opietooth
29#define ACT_OT 5 29#define ACT_OT 5
30// prompt for VPN networks
31#define ACT_PROMPTVPN 6
30 32
31// include Opietooth GUI 33// include Opietooth GUI
32#include <opietooth2/Opietooth.h> 34#include <opietooth2/Opietooth.h>
33using namespace Opietooth2; 35using namespace Opietooth2;
34 36
35#include <qpushbutton.h> 37#include <qpushbutton.h>
36#include <qlayout.h> 38#include <qlayout.h>
37#include <qframe.h> 39#include <qframe.h>
38#include <qlabel.h> 40#include <qlabel.h>
39 41
40int main( int argc, char * argv[] ) { 42int main( int argc, char * argv[] ) {
41 int rv = 0; 43 int rv = 0;
@@ -47,25 +49,29 @@ int main( int argc, char * argv[] ) {
47 49
48 for ( int i = 1; i < argc; i ++ ) { 50 for ( int i = 1; i < argc; i ++ ) {
49 int rmv; 51 int rmv;
50 rmv = 0; 52 rmv = 0;
51 if( strcmp( argv[i], "--regen" ) == 0 ) { 53 if( strcmp( argv[i], "--regen" ) == 0 ) {
52 Action = ACT_REGEN; 54 Action = ACT_REGEN;
53 GuiType = QApplication::Tty; 55 GuiType = QApplication::Tty;
54 rmv = 1; 56 rmv = 1;
55 } else if( strcmp( argv[i], "--prompt" ) == 0 ) { 57 } else if( strcmp( argv[i], "--prompt" ) == 0 ) {
56 Action = ACT_PROMPT; 58 Action = ACT_PROMPT;
57 rmv = 1; 59 rmv = 1;
58 } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { 60 } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) {
59 Action = ACT_VPN; 61 GuiType = QApplication::Tty;
62 Action = ACT_TRIGGERVPN;
63 rmv = 1;
64 } else if( strcmp( argv[i], "--promptvpn" ) == 0 ) {
65 Action = ACT_PROMPTVPN;
60 rmv = 1; 66 rmv = 1;
61 } else if( strcmp( argv[i], "--opietooth" ) == 0 ) { 67 } else if( strcmp( argv[i], "--opietooth" ) == 0 ) {
62 Action = ACT_OT; 68 Action = ACT_OT;
63 rmv = 1; 69 rmv = 1;
64 } 70 }
65 if( rmv ) { 71 if( rmv ) {
66 memmove( argv+i, argv+i+rmv, 72 memmove( argv+i, argv+i+rmv,
67 sizeof( char * ) * (argc-i-rmv) ); 73 sizeof( char * ) * (argc-i-rmv) );
68 i --; 74 i --;
69 argc -= rmv; 75 argc -= rmv;
70 } 76 }
71 } 77 }
@@ -86,57 +92,67 @@ int main( int argc, char * argv[] ) {
86 // TheApp anymore ... 92 // TheApp anymore ...
87 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); 93 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType );
88 } else { 94 } else {
89 TheApp = new QPEApplication( argc, argv, GuiType ); 95 TheApp = new QPEApplication( argc, argv, GuiType );
90 } 96 }
91 97
92 // init qt with app widget 98 // init qt with app widget
93 99
94 switch( Action ) { 100 switch( Action ) {
95 case ACT_REQUEST : 101 case ACT_REQUEST :
96 { NetworkSettingsData NS; 102 { NetworkSettingsData NS;
97 if( NS.canStart( argv[1] ) ) { 103 if( NS.canStart( argv[1] ) ) {
104 QStringList SL;
105 SL << QPEApplication::qpeDir() + "bin/networksettings2"
106 << "--prompt"
107 << argv[1];
108 // exec synchronous -> blocks
109 NSResources->system().execAsUser( SL, 1 );
110 }
111 }
112 break;
113 case ACT_TRIGGERVPN :
114 { NetworkSettingsData NS;
115 if( NS.couldBeTriggered( argv[1] ) ) {
116 // there are VPNS that can be triggered
98 QStringList S; 117 QStringList S;
99 S << QPEApplication::qpeDir() + "/bin/networksettings2"; 118 S << QPEApplication::qpeDir() + "bin/networksettings2";
100 S << "networksettings2"; 119 S << "--promptvpn";
101 S << "--prompt";
102 S << argv[1]; 120 S << argv[1];
103 NSResources->system().execAsUser( S ); 121 NSResources->system().execAsUser( S );
104 Log(("FAILED %s-cNN-allowed\n", argv[1] ));
105 // if we come here , failed
106 printf( "%s-cNN-disallowed", argv[1] );
107 } 122 }
108 } 123 }
109 break; 124 break;
110 case ACT_REGEN : 125 case ACT_REGEN :
111 { NetworkSettingsData NS; 126 { NetworkSettingsData NS;
112 QString S= NS.generateSettings(); 127 QString S= NS.generateSettings();
113 // regen returns 0 if OK 128 // regen returns 0 if OK
114 rv = ( S.isEmpty() ) ? 0 : 1; 129 rv = ( S.isEmpty() ) ? 0 : 1;
115 } 130 }
116 break; 131 break;
117 case ACT_PROMPT : 132 case ACT_PROMPT :
118 { ActivateProfile AP(argv[1]); 133 { ActivateProfile AP(argv[1]);
119 if( AP.exec() == QDialog::Accepted ) { 134 if( AP.exec() == QDialog::Accepted ) {
120 Log(("%s-c%ld-allowed\n", 135 Log(("allow profile %ld for %s\n",
121 argv[1], AP.selectedProfile() )); 136 AP.selectedProfile(), argv[1] ));
122 printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); 137 printf( "A%ld%s\n", AP.selectedProfile(), argv[1] );
123 } else { 138 } else {
124 Log(("%s-c%NN-disallowed\n", argv[1] )); 139 Log(("disallow %s\n", argv[1] ));
125 printf( "%s-cNN-disallowed", argv[1] ); 140 printf( "D-%s\n", argv[1] );
126 } 141 }
127 } 142 }
128 break; 143 break;
129 case ACT_VPN : 144 case ACT_PROMPTVPN :
130 { ActivateVPN AVPN; 145 { ActivateVPN AVPN( argv[1] );
146 Log(("Trigger vpns on interface %s\n", argv[1] ));
131 AVPN.exec(); 147 AVPN.exec();
132 } 148 }
133 break; 149 break;
134 case ACT_GUI : 150 case ACT_GUI :
135 case ACT_OT : 151 case ACT_OT :
136 { QWidget * W; 152 { QWidget * W;
137 153
138 if( Action == ACT_OT ) { 154 if( Action == ACT_OT ) {
139 W = new OTMain( 0 ); 155 W = new OTMain( 0 );
140 } else { 156 } else {
141 W = new NetworkSettings(0); 157 W = new NetworkSettings(0);
142 } 158 }