Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4GUI/MainGo4GUI.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include <iostream.h>
00017 
00018 #include "qdir.h"
00019 
00020 #include "qtroot/interface/tqapplication.h"
00021 #include "qtroot/interface/qrootapplication.h"
00022 
00023 #include "Go4Log/TGo4Log.h"
00024 #include "Go4Display/TGo4Display.h"
00025 #include "Go4Analysis/TGo4Version.h"
00026 #include "TGo4MainWindow.h"
00027 #include "TGo4QSettings.h"
00028 
00029 int main(int argc, char **argv) {
00030 
00031     bool localmode = false;
00032     bool traceon = false;
00033     bool servermode = true;
00034     QString hotstart = "";
00035 
00036     for(int narg=1;narg<argc;narg++) {
00037        if (strlen(argv[narg])==0) continue;
00038        
00039        if (argv[narg][0]=='-') {
00040           if(!strcmp(argv[narg], "-local")) {
00041              cout << "G-OOOO-> MainGo4GUI is starting in local mode only " << endl;
00042              localmode = true;
00043           } else
00044           if(!strcmp(argv[narg], "-debug")) {
00045              cout << "G-OOOO-> MainGo4GUI switched on debug output" << endl;
00046              traceon = true;
00047           } else
00048           if(strstr(argv[narg], "-client")) {
00049              cout << "G-OOOO-> MainGo4GUI is starting as client." << endl;
00050              servermode = false;
00051              if(strstr(argv[narg], "-debug")) traceon = true;
00052           }
00053 
00054        } else
00055          if (hotstart.length()==0) hotstart = argv[narg];
00056     }
00057 
00058     TQApplication app("uno",&argc,argv); // init ROOT before Qt because of XInitThreads JA
00059 
00060     QRootApplication myapp( argc, argv, 0 );
00061 
00062     Int_t negport=0;
00063     TGo4Log::Instance(); // init logger object
00064     TGo4Log::SetIgnoreLevel(1); // set this to 1 to suppress detailed debug output
00065     // set this to 2 to get warnings and errors only
00066     // set this to 3 to get errors only
00067     TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages
00068     
00070     // has to be done here, since mainwindow components have local
00071     // settings access before mainwindow init is executed!
00072     // Default is to use current directory. Environment variable
00073     // GO4SETTINGS can be set to a certain go4 setup location
00074     // if GO4SETTINGS contains the "ACCOUNT" keyword, we use the
00075     // qt default to have the settings in $HOME/.qt/    
00076     // NOTE: if $HOME/.qt/go4rc exists,
00077     // Qt would use these settings even if the TGo4QSettings use the 
00078     // current dir option or userpath for saving the settings; 
00079     // Therefore, the local settings will have different names go4localrc
00080     TGo4QSettings::SetHomeSettingsFile("/go4"); // might change the default filename in .qt here  
00081     bool accountsettings=false;
00082     QString settingsenv=getenv("GO4SETTINGS");
00083     if(settingsenv.isEmpty()) {
00084        // use Qt settings in $PWD/.qt. if false, use $HOME/.qt, or the user path if set
00085        if (gSystem->AccessPathName(QDir::currentDirPath(),kWritePermission)) {
00086          TGo4QSettings::SetToCurrentDir(false);
00087          accountsettings=true;  
00088        } else {
00089          TGo4QSettings::SetToCurrentDir(true);
00090        }   
00091     } else 
00092     if(settingsenv.contains("ACCOUNT")) {
00093        TGo4QSettings::SetToCurrentDir(false);
00094        accountsettings=true;
00095     } else {
00096        TGo4QSettings::SetUserPath(settingsenv);  
00097     }
00099     QString homesettings = QDir::homeDirPath()+ "/.qt/go4rc";   
00100     QString usersettings = TGo4QSettings::GetUserPath()+TGo4QSettings::GetSettingsName()+"rc";
00101     QString hometools = QDir::homeDirPath()+ "/.qt/go4toolsrc";   
00102     QString usertools = TGo4QSettings::GetUserPath()+"/go4toolsrc";
00103    
00104    if(!accountsettings && gSystem->AccessPathName(usersettings)) // file not there
00105       {
00106          // first create subfolder .qt if not there, otherwise copy fails!
00107          QString qsubdir=TGo4QSettings::GetUserPath();
00108          if(gSystem->AccessPathName(qsubdir))
00109             {
00110                cout <<"Creating settings subdirectory "<<qsubdir<<" ..."<< endl;
00111                if(gSystem->mkdir(qsubdir,true)!=0)
00112                   cout <<"Could not create "<<qsubdir<<" !"<< endl;
00113             
00114             }
00115          
00116          if(gSystem->CopyFile(homesettings,usersettings,kTRUE)==0)
00117             cout <<"Copied account settings "<<homesettings<<" to "<<usersettings << endl;
00118          else
00119             cout<<"Could not copy "<<homesettings<<" to "<<usersettings << endl;
00120          if(gSystem->CopyFile(hometools,usertools,kTRUE)==0)
00121             cout <<"Copied account settings "<<hometools<<" to "<<usertools << endl;
00122          else
00123             cout<<"Could not copy "<<hometools<<" to "<<usertools << endl;
00124       }   
00126     TGo4Display *exserver=0;
00127     
00128     if(traceon) TGo4Log::SetIgnoreLevel(0);
00129            else TGo4Log::SetIgnoreLevel(1);
00130 
00131     if (argc<2)
00132        cout << "G-OOOO->  Started go4gui. "  << endl;
00133 
00134     cout << "   Go4 " << __GO4RELEASE__ << endl;
00135 
00136     TGo4MainWindow *Go4MainGUI;
00137     if(!localmode) {
00138        exserver = new TGo4Display(negport,"dummy",servermode);
00139        Go4MainGUI = new TGo4MainWindow();
00140     } else
00141        Go4MainGUI = new TGo4MainWindow(0, 0, Qt::WType_TopLevel, true);
00142 
00143     myapp.setMainWidget(Go4MainGUI);
00144     Go4MainGUI->polish();
00145     Go4MainGUI->show();
00146     myapp.connect( &myapp, SIGNAL( lastWindowClosed() ), &myapp, SLOT( quit() ) );
00147     QApplication::setDoubleClickInterval(400); //ms, for Qt>=3.3 avoid very fast defaults!
00148     QApplication::setStartDragTime(150); // ms
00149     if (hotstart.length()>0)
00150       Go4MainGUI->HotStart(hotstart.data());
00151     int res = myapp.exec();
00152     return res;
00153 }
00154 
00155 
00156 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:59 2005 for Go4-v2.10-5 by doxygen1.2.15