Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 #include <stdlib.h>
00015 #include <stdio.h>
00016 #include <qglobal.h>
00017 #include <locale.h>
00018 #include <QDir>
00019 #include <QStringList>
00020 
00021 #include "TSystem.h"
00022 #include "RVersion.h"
00023 #include "TEnv.h"
00024 #include "TApplication.h"
00025 #include "QRootApplication.h"
00026 
00027 #include "TGo4Log.h"
00028 #include "TGo4Version.h"
00029 #include "TGo4MainWindow.h"
00030 #include "TGo4BrowserProxy.h"
00031 #include "TGo4DabcProxy.h"
00032 #include "TGo4BufferQueue.h"
00033 #include "TGo4QSettings.h"
00034 #include "TGo4AbstractInterface.h"
00035 
00036 #include "TROOT.h"
00037 #include "Riostream.h"
00038 
00039 
00040 #ifndef WIN32
00041 #include "TGX11.h"
00042 
00043 #endif
00044 
00045 int main(int argc, char **argv)
00046 {
00047    setlocale(LC_ALL, "C");
00048 
00049 #ifndef WIN32
00050    gEnv->SetValue("X11.XInitThread", 0);   
00051    
00052    bool iswin32 = false;
00053 #else
00054    bool iswin32 = true;
00055    {
00056       
00057       
00058       
00059       TGo4BufferQueue dummy("dummyQueue");
00060    }   
00061 
00062 #endif
00063 
00064    if (!TGo4Version::CheckVersion(__GO4BUILDVERSION__)) {
00065       std::cerr << "Please configure your system correctly and restart go4 again" << std::endl;
00066       return -1;
00067    }
00068 
00069    int dologin = -1;
00070    const char* loghost = "localhost";
00071    int logport = 5000;
00072    const char* logpass = 0;
00073 
00074    bool prepare_for_client = false;
00075 
00076    bool traceon = false;
00077    QString hotstart = "";
00078    QString dabcnode = "";
00079    QStringList files;
00080 
00081    for(int narg=1;narg<argc;narg++) {
00082       if (strlen(argv[narg])==0) continue;
00083 
00084       if (argv[narg][0]=='-') {
00085          if(!strcmp(argv[narg], "-debug")) {
00086             std::cout << "G-OOOO-> MainGo4GUI switched on debug output" << std::endl;
00087             traceon = true;
00088          } else
00089          if((strcmp(argv[narg], "-observer")==0) ||
00090             (strcmp(argv[narg], "-controller")==0) ||
00091             (strcmp(argv[narg], "-admin")==0)) {
00092 
00093             if(strcmp(argv[narg], "-observer")==0) dologin = 0;
00094             if(strcmp(argv[narg], "-controller")==0) dologin = 1;
00095             if(strcmp(argv[narg], "-admin")==0) dologin = 2;
00096 
00097             if ((narg+1<argc) && (argv[narg+1][0]!='-'))
00098                loghost = argv[++narg];
00099 
00100             if ((narg+1<argc) && (argv[narg+1][0]!='-') && (argv[narg+1][0]>='0') && (argv[narg+1][0]<='9'))
00101                logport = QString(argv[++narg]).toInt();
00102 
00103             if ((narg+1<argc) && (argv[narg+1][0]!='-')) logpass = argv[++narg];
00104          } else
00105          if (strcmp(argv[narg], "-prepare")==0) {
00106             prepare_for_client = true;
00107          }
00108       } else
00109       if (QString(argv[narg]).contains(".root")) {
00110          files.append(argv[narg]);
00111       } else
00112       if (QString(argv[narg]).contains("dabc://")) {
00113          dabcnode = argv[narg];
00114       } else
00115       if (hotstart.length()==0) {
00116          hotstart = argv[narg];
00117          if(!QString(argv[narg]).contains(".hotstart")) hotstart.append(".hotstart");
00118       }
00119    }
00120 
00121    TApplication app("uno", &argc, argv); 
00122 
00123    Q_INIT_RESOURCE(go4icons);
00124 
00125    QRootApplication myapp(argc, argv); 
00126 
00127    
00128    ::setlocale(LC_ALL, "C");
00129 
00130    TGo4AbstractInterface::SetInitSharedLibs();
00131 
00132 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
00133    
00134    QApplication::setColorSpec( QApplication::ManyColor );
00135 #endif
00136 
00137    TGo4Log::LogfileEnable(kFALSE); 
00138    TGo4Log::Instance(); 
00139    TGo4Log::SetIgnoreLevel(1); 
00140    
00141    
00142 
00144    
00145    
00146    
00147    
00148    
00149    
00151    
00152    
00153    
00154 
00155    const char* _env = gSystem->Getenv("GO4SETTINGS");
00156 
00157    QString settfile;
00158    if (_env!=0) settfile = _env;
00159 
00160    if(iswin32 || settfile.isEmpty() || settfile.contains("ACCOUNT")) {
00161       settfile = "";
00162       
00163    } else {
00164       if (settfile.contains("LOCAL")) settfile = QDir::currentPath() + "/go4.conf";
00165       QString subdir = QFileInfo(settfile).absolutePath();
00166       
00167       
00168       if (gSystem->AccessPathName(subdir.toLatin1().constData(),kWritePermission))
00169          settfile = "";
00170    }
00171 
00172    go4sett = new TGo4QSettings(settfile);
00173 
00175    if(traceon) TGo4Log::SetIgnoreLevel(0);
00176           else TGo4Log::SetIgnoreLevel(1);
00177 
00178    const char* dabc_vers = TGo4DabcProxy::GetDabcVersion();
00179 
00180    std::cout << "   Go4 " << __GO4RELEASE__ << ",   build with ROOT " << ROOT_RELEASE;
00181    if (dabc_vers) std::cout << ", DABC " << dabc_vers;
00182    std::cout << " and Qt " << QT_VERSION_STR << std::endl;
00183    
00184 
00185    TGo4MainWindow* Go4MainGUI = new TGo4MainWindow(&myapp);
00186 
00187    myapp.connect(&myapp, SIGNAL(lastWindowClosed()), &myapp, SLOT(quit()));
00188 
00189    Go4MainGUI->ensurePolished();
00190    Go4MainGUI->show();
00191 
00192    myapp.connect( &myapp, SIGNAL( lastWindowClosed() ), &myapp, SLOT( quit() ) );
00193    QApplication::setDoubleClickInterval(400); 
00194    QApplication::setStartDragTime(150); 
00195 
00196    for (int i = 0; i < files.size(); ++i)
00197       Go4MainGUI->Browser()->OpenFile(files.at(i).toLatin1().constData());
00198 
00199    if (dabcnode.length()>0)
00200       Go4MainGUI->Browser()->ConnectDabc(dabcnode.toLatin1().constData());
00201 
00202    if (hotstart.length()>0)
00203       Go4MainGUI->HotStart(hotstart.toLatin1().constData());
00204 
00205    if (dologin>=0) {
00206       go4sett->setClientNode(loghost);
00207       go4sett->setClientPort(logport);
00208       go4sett->setClientDefaultPass(logpass==0);
00209       go4sett->setClientControllerMode(dologin);
00210       Go4MainGUI->ConnectServerSlot(false, logpass);
00211    } else
00212    if (prepare_for_client) {
00213       Go4MainGUI->PrepareForClientConnectionSlot(false);
00214    }
00215 
00216    int res = myapp.exec();
00217    delete go4sett;
00218    return res;
00219 }