Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

main.cpp

Go to the documentation of this file.
00001 #include "nsdata.h"
00002 #include "activateprofile.h"
00003 #include "activatevpn.h"
00004 #include "networksettings.h"
00005 
00006 #include <opie2/odebug.h>
00007 #include <qpe/qpeapplication.h>
00008 
00009 #include <opie2/oapplicationfactory.h>
00010 using namespace Opie::Core;
00011 
00012 #ifdef GONE
00013 
00014 OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> )
00015 
00016 #else
00017 
00018 // just standard GUI
00019 #define ACT_GUI         0
00020 // used by interfaces to request for allow of up/down
00021 #define ACT_REQUEST     1
00022 // regenerate config files
00023 #define ACT_REGEN       2
00024 // used by interfaces to request user prompt 
00025 #define ACT_PROMPT      3
00026 // used by interfaces to trigger VPN prompting
00027 #define ACT_TRIGGERVPN  4
00028 // activate opietooth
00029 #define ACT_OT          5
00030 // prompt for VPN networks
00031 #define ACT_PROMPTVPN   6
00032 
00033 // include Opietooth GUI
00034 #include <opietooth2/Opietooth.h>
00035 using namespace Opietooth2;
00036 
00037 #include <qpushbutton.h>
00038 #include <qlayout.h>
00039 #include <qframe.h>
00040 #include <qlabel.h>
00041 
00042 int main( int argc, char * argv[] ) {
00043         int rv = 0;
00044         int Action = ACT_GUI;
00045         // could be overruled by -qws
00046         QApplication::Type GuiType = QApplication::GuiClient; 
00047 
00048         QPEApplication * TheApp;
00049 
00050         for ( int i = 1; i < argc; i ++ ) {
00051           int rmv;
00052           rmv = 0;
00053           if( strcmp( argv[i], "--regen" ) == 0 ) {
00054             Action = ACT_REGEN;
00055             GuiType = QApplication::Tty;
00056             rmv = 1;
00057           } else if( strcmp( argv[i], "--prompt" ) == 0 ) {
00058             Action = ACT_PROMPT;
00059             rmv = 1;
00060           } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) {
00061             GuiType = QApplication::Tty;
00062             Action = ACT_TRIGGERVPN;
00063             rmv = 1;
00064           } else if( strcmp( argv[i], "--promptvpn" ) == 0 ) {
00065             Action = ACT_PROMPTVPN;
00066             rmv = 1;
00067           } else if( strcmp( argv[i], "--opietooth" ) == 0 ) {
00068             Action = ACT_OT;
00069             rmv = 1;
00070           }
00071           if( rmv ) {
00072             memmove( argv+i, argv+i+rmv, 
00073                 sizeof( char * ) * (argc-i-rmv) );
00074             i --;
00075             argc -= rmv;
00076           }
00077         }
00078 
00079         if( strstr( argv[0], "-request" ) ) {
00080           // called from system to request something
00081           GuiType = QApplication::Tty;
00082           Action = ACT_REQUEST;
00083           Log(("Request : %s\n", argv[1] ));
00084         } else if( strstr( argv[0], "-opietooth" ) ) {
00085           Action = ACT_OT;
00086         }
00087 
00088         // Start Qt
00089         // because QPEApplication does not handle GuiType well
00090         if( GuiType == QApplication::Tty ) {
00091           // this cast is NOT correct but we do not use
00092           // TheApp anymore ...
00093           TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType );
00094         } else {
00095           TheApp = new QPEApplication( argc, argv, GuiType );
00096         }
00097 
00098         // init qt with app widget
00099 
00100         switch( Action ) {
00101           case ACT_REQUEST :
00102             { NetworkSettingsData NS;
00103               if( NS.canStart( argv[1] ) ) {
00104                 QStringList SL;
00105                 SL << QPEApplication::qpeDir() + "bin/networksettings2"
00106                    << "--prompt"
00107                    << argv[1];
00108                 // exec synchronous -> blocks 
00109                 NSResources->system().execAsUser( SL, 1 );
00110               }
00111             }
00112             break;
00113           case ACT_TRIGGERVPN :
00114             { NetworkSettingsData NS;
00115               if( NS.couldBeTriggered( argv[1] ) ) {
00116                 // there are VPNS that can be triggered
00117                 QStringList S;
00118                 S << QPEApplication::qpeDir() + "bin/networksettings2";
00119                 S << "--promptvpn";
00120                 S << argv[1];
00121                 NSResources->system().execAsUser( S );
00122               }
00123             }
00124             break;
00125           case ACT_REGEN :
00126             { NetworkSettingsData NS;
00127               QString S= NS.generateSettings();
00128               // regen returns 0 if OK
00129               rv = ( S.isEmpty() ) ? 0 : 1;
00130             }
00131             break;
00132           case ACT_PROMPT :
00133             { ActivateProfile AP(argv[1]);
00134               if( AP.exec() == QDialog::Accepted ) {
00135                 Log(("allow profile %ld for %s\n", 
00136                     AP.selectedProfile(), argv[1] ));
00137                 printf( "A%ld%s\n", AP.selectedProfile(), argv[1] );
00138               } else {
00139                 Log(("disallow %s\n", argv[1] ));
00140                 printf( "D-%s\n", argv[1] );
00141               }
00142             }
00143             break;
00144           case ACT_PROMPTVPN :
00145             { ActivateVPN AVPN( argv[1] );
00146               Log(("Trigger vpns on interface %s\n", argv[1] ));
00147               AVPN.exec();
00148             }
00149             break;
00150           case ACT_GUI :
00151           case ACT_OT :
00152             { QWidget * W;
00153 
00154               if( Action == ACT_OT ) {
00155                 W = new OTMain( 0 );
00156               } else {
00157                 W = new NetworkSettings(0);
00158               }
00159               TheApp->setMainWidget( W ); 
00160 
00161               W->show();
00162               W->showMaximized();
00163               rv = TheApp->exec();
00164 
00165               delete W;
00166             }
00167             break;
00168         }
00169 
00170         LogClose();
00171 
00172         return rv;
00173 }
00174 
00175 #endif
00176 
00177 
00178 // main.cpp
00179 

Generated on Sat Nov 5 16:15:25 2005 for OPIE by  doxygen 1.4.2