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

MainGo4GUI.cpp

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "Riostream.h"
00017 #include <stdlib.h>
00018 
00019 #include "qdir.h"
00020 
00021 #include "TSystem.h"
00022 
00023 #include "tqapplication.h"
00024 #include "qrootapplication.h"
00025 
00026 #include "TGo4Log.h"
00027 #include "TGo4Version.h"
00028 #include "TGo4MainWindow.h"
00029 #include "TGo4QSettings.h"
00030 
00031 int main(int argc, char **argv) {
00032 
00033     bool traceon = false;
00034     bool servermode = true;
00035     QString hotstart = "";
00036 
00037     for(int narg=1;narg<argc;narg++) {
00038        if (strlen(argv[narg])==0) continue;
00039 
00040        if (argv[narg][0]=='-') {
00041           if(!strcmp(argv[narg], "-debug")) {
00042              cout << "G-OOOO-> MainGo4GUI switched on debug output" << endl;
00043              traceon = true;
00044           } else
00045           if(strstr(argv[narg], "-client")) {
00046              cout << "G-OOOO-> MainGo4GUI is starting as client." << endl;
00047              servermode = false;
00048              if(strstr(argv[narg], "-debug")) traceon = true;
00049           }
00050 
00051        } else
00052          if (hotstart.length()==0) {
00053             hotstart = argv[narg];
00054             if(!strstr(argv[narg], ".hotstart")) hotstart.append(".hotstart");
00055             exit;
00056          }
00057     }
00058 
00059     TQApplication app("uno",&argc,argv); // init ROOT before Qt because of XInitThreads JA
00060 
00061     QRootApplication myapp( argc, argv, 0 );
00062 
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     if(traceon) TGo4Log::SetIgnoreLevel(0);
00127            else TGo4Log::SetIgnoreLevel(1);
00128 
00129     if (argc<2)
00130        cout << "G-OOOO->  Started go4gui. "  << endl;
00131 
00132     cout << "   Go4 " << __GO4RELEASE__ << endl;
00133 
00134     // create instance, which should be used everywhere
00135     go4sett = new TGo4QSettings();
00136 
00137     TGo4MainWindow* Go4MainGUI = new TGo4MainWindow(&myapp, servermode);
00138 
00139 
00140     myapp.setMainWidget(Go4MainGUI);
00141     Go4MainGUI->polish();
00142     Go4MainGUI->show();
00143     myapp.connect( &myapp, SIGNAL( lastWindowClosed() ), &myapp, SLOT( quit() ) );
00144     QApplication::setDoubleClickInterval(400); //ms, for Qt>=3.3 avoid very fast defaults!
00145     QApplication::setStartDragTime(150); // ms
00146 
00147     if (hotstart.length()>0)
00148       Go4MainGUI->HotStart(hotstart.latin1());
00149     int res = myapp.exec();
00150 
00151     delete go4sett;
00152 
00153     return res;
00154 }
00155 
00156 
00157 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:20 2008 for Go4-v3.04-1 by  doxygen 1.4.2