int main(int argc, char *argv[]) { Q_INIT_RESOURCE(caQtDM); #ifdef MOBILE Q_INIT_RESOURCE(qtcontrols); #endif QApplication app(argc, argv); QApplication::setOrganizationName("Paul Scherrer Institut"); QApplication::setApplicationName("caQtDM"); #ifdef MOBILE_ANDROID app.setStyle(QStyleFactory::create("fusion")); #endif // we do not want numbers with a group separators QLocale loc = QLocale::system(); loc.setNumberOptions(QLocale::OmitGroupSeparator); loc.setDefault(loc); QString fileName = ""; QString macroString = ""; QString geometry = ""; QString macroFile = ""; QMap<QString, QString> options; options.clear(); searchFile *s = new searchFile("caQtDM_stylesheet.qss"); QString fileNameFound = s->findFile(); if(fileNameFound.isNull()) { printf("caQtDM -- file <caQtDM_stylesheet.qss> could not be loaded, is 'CAQTDM_DISPLAY_PATH' <%s> defined?\n", qasc(s->displayPath())); } else { QFile file(fileNameFound); file.open(QFile::ReadOnly); QString StyleSheet = QLatin1String(file.readAll()); printf("caQtDM -- file <caQtDM_stylesheet.qss> loaded as the default application stylesheet\n"); app.setStyleSheet(StyleSheet); file.close(); } int in, numargs; bool attach = false; bool minimize= false; bool nostyles = false; bool printscreen = false; bool resizing = true; for (numargs = argc, in = 1; in < numargs; in++) { //qDebug() << argv[in]; if ( strcmp (argv[in], "-display" ) == 0 ) { in++; printf("caQtDM -- display <%s>\n", argv[in]); } else if ( strcmp (argv[in], "-macro" ) == 0 ) { in++; printf("caQtDM -- macro <%s>\n", argv[in]); macroString = QString(argv[in]); } else if ( strcmp (argv[in], "-attach" ) == 0 ) { printf("caQtDM -- will attach to another caQtDM if running\n"); attach = true; } else if ( strcmp (argv[in], "-noMsg" ) == 0 ) { printf("caQtDM -- will minimize its main windows\n"); minimize = true; } else if( strcmp (argv[in], "-macrodefs" ) == 0) { in++; printf("caQtDM -- will load macro string from file <%s>\n", argv[in]); macroFile = QString(argv[in]); } else if ( strcmp (argv[in], "-noStyles" ) == 0 ) { printf("caQtDM -- will not replace the default application stylesheet caQtDM_stylesheet.qss\n"); nostyles = true; } else if ( strcmp (argv[in], "-x" ) == 0 ) { } else if ( strcmp (argv[in], "-displayFont" ) == 0 ) { in++; } else if(!strcmp(argv[in],"-help") || !strcmp(argv[in],"-h") || !strcmp(argv[in],"-?")) { in++; printf("Usage:\n" " caQtDM[X options]\n" " [-help | -h | -?]\n" " [-x]\n" " [-attach]\n" " [-noMsg]\n" " [-noStyles] works only when not attaching\n" " [-macro \"xxx=aaa,yyy=bbb, ...\"]\n" " [-macrodefs filename] will load macro definitions from file\n" " [-dg [<width>x<height>][+<xoffset>-<yoffset>]\n" " [-httpconfig] will display a network configuration screen at startup\n" " [-print] will print file and exit\n" " [-noResize] will prevent resizing\n" " [-cs defaultcontrolsystempluginname]\n" " [-option \"xxx=aaa,yyy=bbb, ...\"] options for cs plugins\n" " [file]\n" " [&]\n" "\n" " -x -displayFont -display are ignored !\n\n"); exit(1); } else if((!strcmp(argv[in],"-displayGeometry")) || (!strcmp(argv[in],"-dg"))) { // [-dg [xpos[xypos]][+xoffset[+yoffset]] in++; geometry = QString(argv[in]); } else if(!strcmp(argv[in], "-print")) { printscreen = true; minimize = true; resizing = false; } else if(!strcmp(argv[in], "-noResize")) { resizing = false; } else if(!strcmp(argv[in], "-httpconfig")) { HTTPCONFIGURATOR = true; } else if(!strcmp(argv[in], "-cs")) { in++; options.insert("defaultPlugin", QString(argv[in])); } else if ( strcmp (argv[in], "-option" ) == 0 ) { in++; printf("caQtDM -- option <%s>\n", argv[in]); createMap(options, QString(argv[in])); } else if (strncmp (argv[in], "-" , 1) == 0) { /* unknown application argument */ printf("caQtDM -- Argument %d = [%s] is unknown!, possible -attach -macro -noMsg -noStyles -dg -x -print -httpconfig -noResize\n",in,argv[in]); } else { printf("caQtDM -- file = <%s>\n", argv[in]); fileName = QString(argv[in]); break; } } // must be always true for mobile plattforms #ifdef MOBILE HTTPCONFIGURATOR = true; #endif if(!nostyles) { s = new searchFile("stylesheet.qss"); fileNameFound = s->findFile(); if(fileNameFound.isNull()) { printf("caQtDM -- file <stylesheet.qss> could not be loaded, is 'CAQTDM_DISPLAY_PATH' <%s> defined?\n", qasc(s->displayPath())); } else { QFile file(fileNameFound); file.open(QFile::ReadOnly); QString StyleSheet = QLatin1String(file.readAll()); printf("caQtDM -- file <stylesheet.qss> replaced the default stylesheet\n"); app.setStyleSheet(StyleSheet); file.close(); } } // load macro definitions from file (located in this directory or in the caQTDM_DISPLAY_PATH) if(macroFile.length() > 0) { s = new searchFile(macroFile); fileNameFound = s->findFile(); if(fileNameFound.isNull()) { printf("caQtDM -- file <stylesheet.qss> could not be loaded, is 'CAQTDM_DISPLAY_PATH' <%s> defined?\n", qasc(s->displayPath())); } else { QFile file(fileNameFound); file.open(QFile::ReadOnly); macroString = QLatin1String(file.readAll()); file.close(); } } #ifdef IO_OPTIMIZED_FOR_TABWIDGETS printf("caQtDM -- viewer will disable monitors for hidden pages of QTabWidgets, in case of problems\n"); printf(" you may disable this by not defining IO_OPTIMIZED_FOR_TABWIDGETS in qtdefs.pri\n"); #else printf("caQtDM -- viewer will not disable monitors for hidden pages of QTabWidgets\n"); printf(" you may enable this by defining IO_OPTIMIZED_FOR_TABWIDGETS in qtdefs.pri\n"); #endif #ifndef CONFIGURATOR QString displayPath = (QString) qgetenv("CAQTDM_URL_DISPLAY_PATH"); if(displayPath.length() > 0) { printf("caQtDM -- files will be downloaded from <%s> when not locally found\n", qasc(displayPath)); } else { printf("caQtDM -- files will not be downloaded from an url when not locally found, while CAQTDM_URL_DISPLAY_PATH is not defined\n"); } #endif FileOpenWindow window (0, fileName, macroString, attach, minimize, geometry, printscreen, resizing, options); window.setWindowIcon (QIcon(":/caQtDM.ico")); window.show(); window.move(0,0); if (signal(SIGINT, unixSignalHandler) == SIG_ERR) { qFatal("ERR - %s(%d): An error occurred while setting a signal handler.\n", __FILE__,__LINE__); } if (signal(SIGTERM, unixSignalHandler) == SIG_ERR) { qFatal("ERR - %s(%d): An error occurred while setting a signal handler.\n", __FILE__,__LINE__); } QObject::connect(&app, SIGNAL(aboutToQuit()), &window, SLOT(doSomething())); return app.exec(); }