void FAckley::initialize(){ setOriginalGlobalOpt(); if(IS_PROBLEM_NAME(m_id,"FUN_Ackley")||IS_PROBLEM_NAME(m_id,"FUN_Ackley_Noisy")){ } else if(IS_PROBLEM_NAME(m_id,"FUN_S_Ackley")){ loadTranslation(); }else if(IS_PROBLEM_NAME(m_id,"FUN_R_Ackley")){ setConditionNumber(2); loadRotation(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RS_Ackley")){ setConditionNumber(100); loadTranslation(); loadRotation(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RS_Ackley_Bound_CEC05")){ setConditionNumber(100); loadTranslation(); loadRotation(); setBias(-140); }else if(IS_PROBLEM_NAME(m_id,"FUN_S_Ackley_CEC08")){ setBias(-140); loadTranslation(); }else{ throw myException("Error: please check the problem ID@FAckley::initialize()"); } setGlobalOpt(); }
void loadTranslator(void) { char *lang=NULL; bool autoSelect=true; if(prefs->get(DEFAULT_LANGUAGE,&lang)) { if(lang && strlen(lang)>0 && strcmp(lang,"auto")) autoSelect=false; } if(autoSelect) { ADM_info("Using system language\n"); lang=ADM_strdup(QLocale::system().name().toUtf8().constData()); }else { ADM_info("Language forced \n"); } ADM_info("Initializing language %s\n",lang); #ifdef __APPLE__ QString appdir = QCoreApplication::applicationDirPath() + "/../share/avidemux6/i18n/"; #elif defined(_WIN32) QString appdir = QCoreApplication::applicationDirPath() + "/i18n/"; #else QString appdir = ADM_getInstallRelativePath("share","avidemux6","i18n"); #endif QString languageFile=QString(lang); int nbLoaded=0; nbLoaded+=loadTranslation(&qtTranslator, appdir + "qt_" + languageFile); nbLoaded+=loadTranslation(&avidemuxTranslator, appdir + "avidemux_" + languageFile); translatorLoaded = true; if(!nbLoaded) // Nothing to translate.. return; ADM_info("Updating translations...\n"); // Re-translate existing map (to take care of global strings already allocated) if(!map) map = new QMap<QString, char*>; QMapIterator<QString, char*> mapIterator(*map); while (mapIterator.hasNext()) { mapIterator.next(); QByteArray translatedMessage = QApplication::translate("", mapIterator.key().toAscii().constData()).toUtf8(); char *buffer = mapIterator.value(); int copyLength = translatedMessage.length() + 1; if (copyLength > MAX_UNLOADED_MSG_LENGTH + 1) { copyLength = MAX_UNLOADED_MSG_LENGTH; buffer[MAX_UNLOADED_MSG_LENGTH] = '\0'; } memcpy(buffer, translatedMessage.constData(), copyLength); } ADM_info("[Locale] Test: &Edit -> %s\n\n", HIDE_STRING_FROM_QT("MainWindow", "&Edit").toUtf8().data()); }
void FWeierstrass::initialize(){ setOriginalGlobalOpt(); if(IS_PROBLEM_NAME(m_id,"FUN_Weierstrass")){ }else if(IS_PROBLEM_NAME(m_id,"FUN_R_Weierstrass")){ setConditionNumber(2); loadRotation(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RS_Weierstrass")){ setConditionNumber(5); loadTranslation(); loadRotation(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RS_Weierstrass_CEC05")){ setConditionNumber(5); loadTranslation(); loadRotation(); setBias(90); }else { throw myException("Error: please check the problem ID@FWeierstrass::initialize"); } setGlobalOpt(); setAccuracy(1.0e-2); }
static void load() { // The way Qt translation system handles plural forms makes it necessary to // have a translation file which contains only plural forms for `en`. That's // why we load the `en` translation unconditionally, then load the // translation for the current locale to overload it. loadTranslation(QStringLiteral("en")); QLocale locale = QLocale::system(); if (locale.name() != QStringLiteral("en")) { if (!loadTranslation(locale.name())) { loadTranslation(locale.bcp47Name()); } } }
/** * THE entry point for the application * * @param argc Number of arguments in array argv * @param argv Arguments array */ int main(int argc, char** argv) { /* Create the Qt core application object */ QApplication qapp(argc, argv); #if defined(__APPLE__) || defined(Q_OS_MAC) /* Load plugins from within the bundle ONLY */ QDir dir(QApplication::applicationDirPath()); dir.cdUp(); dir.cd("plugins"); QApplication::setLibraryPaths(QStringList(dir.absolutePath())); #endif /* Let te world know... */ printVersion(); /* Parse command-line arguments */ if (parseArgs(argc, argv) == false) return 0; /* Load translation for current locale */ loadTranslation(QLocale::system().name(), qapp); /* Create and initialize the Fixture Editor application object */ App app; if (FXEDArgs::fixture.isEmpty() == false) app.loadFixtureDefinition(FXEDArgs::fixture); /* Show and execute the application */ app.show(); return qapp.exec(); }
const std::string& get(const std::string& _instance) { loadTranslation(); auto it = m_translate.find(_instance); if (it == m_translate.end()) { EWOL_DEBUG("Can not find tranlation : '" << _instance << "'"); return _instance; } return it->second; };
void FSchwefel_2_22::initialize() { setOriginalGlobalOpt(); if(IS_PROBLEM_NAME(m_id,"FUN_Schwefel_2_22")||IS_PROBLEM_NAME(m_id,"FUN_Schwefel_2_22_Noisy")) { } else if(IS_PROBLEM_NAME(m_id,"FUN_S_Schwefel_2_22")) { loadTranslation(); } else if(IS_PROBLEM_NAME(m_id,"FUN_R_Schwefel_2_22")) { setConditionNumber(2); loadRotation(); } else if(IS_PROBLEM_NAME(m_id,"FUN_RS_Schwefel_2_22")) { setConditionNumber(2); loadTranslation(); loadRotation(); } else { throw myException("Error: please check the problem ID@FSchwefel_2_22::initialize"); } setGlobalOpt(); }
void FSchwefel::initialize() { vector<double> v(m_numDim,420.9687); setOriginalGlobalOpt(0,&v); if(IS_PROBLEM_NAME(m_id,"FUN_Schwefel")||IS_PROBLEM_NAME(m_id,"FUN_Schwefel_Noisy")){ }else if(IS_PROBLEM_NAME(m_id,"FUN_S_Schwefel")){ loadTranslation(); }else if(IS_PROBLEM_NAME(m_id,"FUN_R_Schwefel")){ setConditionNumber(2); loadRotation(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RS_Schwefel")){ setConditionNumber(2); loadTranslation(); loadRotation(); }else{ throw myException("Error: please check the problem ID@FSchwefel::initialize"); } setGlobalOpt(0,&v); setAccuracy(1.0e-2); }
void installTranslator(){ QString language = config->language(); if (language=="auto") language = QLocale::system().name(); if (language.isEmpty() || language=="en_US"){ deactivateTranslators(); return; } if (loadTranslation(translator,"keepassx-",language,QStringList() << HomeDir << DataDir+"/i18n/")) { if (!translatorActive){ QApplication::installTranslator(translator); translatorActive = true; } } else{ deactivateTranslators(); return; } if (loadTranslation(qtTranslator,"qt_",language,QStringList() << HomeDir << DataDir+"/i18n/" << QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { if (!qtTranslatorActive){ QApplication::installTranslator(qtTranslator); qtTranslatorActive = true; } } else{ deactivateTranslators(true); } }
layer_interface * qtvplugin_grid::load_initial_plugin(QString strSLibPath,viewer_interface * ptrviewer) { //!In this instance, we will see how to create a new instance for each ptrviewer qtvplugin_grid * instance = 0; //!1.Check whether there is already a instance for ptrviewer( viewer_interface) mutex_instances.lock(); if (map_instances.empty()==true) { map_instances[ptrviewer] = this; instance = this; } else if (map_instances.contains(ptrviewer)==false) { //Create a new instance for ptrviewer instance = new qtvplugin_grid; map_instances[ptrviewer] = instance; } else instance = map_instances[ptrviewer]; mutex_instances.unlock(); //!2.if the instance correspones to this, do init operations. if (instance==this) { QFileInfo info(strSLibPath); m_SLLibName = info.completeBaseName(); m_SLLibPath = strSLibPath; m_pVi = ptrviewer; mutex_instances.lock(); m_nInstance = ++count_instances[m_SLLibName]; mutex_instances.unlock(); loadTranslation(); load_ini(); } //!3.if the instance not correspones to this, call the instances' load_initial_plugin instead. else { layer_interface * ret = instance->load_initial_plugin(strSLibPath,ptrviewer); assert(ret==instance); } return instance; }
int main(int argc, char *argv[]) { qInstallMessageHandler(emptyMessageHandler); QApplication app{argc, argv}; QTranslator qtTranslator; QTranslator chewingTranslator; loadTranslation(app, qtTranslator, chewingTranslator); readArgument(app); ChewingEditor w; w.show(); return app.exec(); }
void HybridComp::initialize(){ m_originalGlobalOpt.flagGloObj()=false; m_originalGlobalOpt.flagLoc()=false; if(IS_PROBLEM_NAME(m_id,"FUN_Com")||IS_PROBLEM_NAME(m_id,"FUN_R_Com")){ setUpFCom(); }else if(IS_PROBLEM_NAME(m_id,"FUN_Com_CEC05")||IS_PROBLEM_NAME(m_id,"FUN_H_Com_CEC05")||IS_PROBLEM_NAME(m_id,"FUN_H_Com_Noisy_CEC05")){ SetUpFCom_CEC05(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RH_Com_CEC05")||IS_PROBLEM_NAME(m_id,"FUN_RH_Com_NarrowBasin_CEC05")||\ IS_PROBLEM_NAME(m_id,"FUN_RH_Com_Bound_CEC05")){ SetUpFRH_Com_CEC05(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RH_Com_F21_CEC05")||IS_PROBLEM_NAME(m_id,"FUN_RH_Com_HighConNumMatrix_F22_CEC05")||\ IS_PROBLEM_NAME(m_id,"FUN_Noncont_RH_Com_F23_CEC05")){ SetUpFRH001_Com_CEC05(); }else if(IS_PROBLEM_NAME(m_id,"FUN_RH_Com_F24_CEC05")||IS_PROBLEM_NAME(m_id,"FUN_RH_Com_noBounds_F25_CEC05")){ SetUpFRH002_Com_CEC05(); }else { throw myException("Error: please check the problem ID@HybridComp::initialize"); } loadTranslation(); loadRotation(); CodeVReal x(m_numDim,m_numObj); for(int i=0;i<m_numFuncs;i++){ for(int j=0;j<m_numDim;j++){ // calculate the estimate max value of funciton i x[j]=m_searchRange[j].m_upper; x[j]/=mp_stretchSeverity[i]; } mpp_f[i]->BenchmarkFunction::evaluate_(x,false); mp_fmax[i]=x.m_obj[0]; } vector<double> v(m_numDim,0); m_globalOpt.setNumOpts(1); setGlobalOpt(0,&v,mpp_f[0]->getTranslation()); setAccuracy(1.0e-3); setDisAccuracy(0.1); }
int main(int argc, char *argv[]) { // Disable it because we already support HDPI display natively qunsetenv("QT_DEVICE_PIXEL_RATIO"); QGuiApplication app(argc, argv); app.setOrganizationName("KDE"); app.setApplicationName(GCOMPRIS_APPLICATION_NAME); app.setOrganizationDomain("kde.org"); app.setApplicationVersion(ApplicationInfo::GCVersion()); // Local scope for config QSettings config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/gcompris/" + GCOMPRIS_APPLICATION_NAME + ".conf", QSettings::IniFormat); // Load translations QTranslator translator; QString locale = loadTranslation(config, translator); // Apply translation app.installTranslator(&translator); QCommandLineParser parser; parser.setApplicationDescription("GCompris is an educational software for children 2 to 10"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption exportActivitiesAsSQL("export-activities-as-sql", "Export activities as SQL"); parser.addOption(exportActivitiesAsSQL); QCommandLineOption clDefaultCursor(QStringList() << "c" << "cursor", QObject::tr("Run GCompris with the default system cursor.")); parser.addOption(clDefaultCursor); QCommandLineOption clNoCursor(QStringList() << "C" << "nocursor", QObject::tr("Run GCompris without cursor (touch screen mode).")); parser.addOption(clNoCursor); QCommandLineOption clFullscreen(QStringList() << "f" << "fullscreen", QObject::tr("Run GCompris in fullscreen mode.")); parser.addOption(clFullscreen); QCommandLineOption clWindow(QStringList() << "w" << "window", QObject::tr("Run GCompris in window mode.")); parser.addOption(clWindow); QCommandLineOption clSound(QStringList() << "s" << "sound", QObject::tr("Run GCompris with sound enabled.")); parser.addOption(clSound); QCommandLineOption clMute(QStringList() << "m" << "mute", QObject::tr("Run GCompris without sound.")); parser.addOption(clMute); QCommandLineOption clWithoutConfig(QStringList() << "disable-config", QObject::tr("Disable the configuration button.")); parser.addOption(clWithoutConfig); QCommandLineOption clWithConfig(QStringList() << "enable-config", QObject::tr("Enable the configuration button (default).")); parser.addOption(clWithConfig); parser.process(app); ApplicationInfo::init(); ActivityInfoTree::init(); ApplicationSettings::init(); File::init(); DownloadManager::init(); // Tell media players to stop playing, it's GCompris time ApplicationInfo::getInstance()->requestAudioFocus(); // Must be done after ApplicationSettings is constructed because we get an // async callback from the payment system ApplicationSettings::getInstance()->checkPayment(); // Getting fullscreen mode from config if exist, else true is default value bool isFullscreen = true; { if(config.contains("General/fullscreen")) { isFullscreen = config.value("General/fullscreen").toBool(); } // Set the cursor image bool defaultCursor = false; if(config.contains("General/defaultCursor")) { defaultCursor = config.value("General/defaultCursor").toBool(); } if(!defaultCursor && !parser.isSet(clDefaultCursor)) QGuiApplication::setOverrideCursor( QCursor(QPixmap(":/gcompris/src/core/resource/cursor.svg"), 0, 0)); // Hide the cursor bool noCursor = false; if(config.contains("General/noCursor")) { noCursor = config.value("General/noCursor").toBool(); } if(noCursor || parser.isSet(clNoCursor)) QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); } // Update execution counter ApplicationSettings::getInstance()->setExeCount(ApplicationSettings::getInstance()->exeCount() + 1); // Register voices-resources for current locale, updates/downloads only if // not prohibited by the settings if(!DownloadManager::getInstance()->areVoicesRegistered()) DownloadManager::getInstance()->updateResource(DownloadManager::getInstance() ->getVoicesResourceForLocale(locale)); if(parser.isSet(clFullscreen)) { isFullscreen = true; } if(parser.isSet(clWindow)) { isFullscreen = false; } if(parser.isSet(clMute)) { ApplicationSettings::getInstance()->setIsAudioEffectsEnabled(false); ApplicationSettings::getInstance()->setIsAudioVoicesEnabled(false); } if(parser.isSet(clSound)) { ApplicationSettings::getInstance()->setIsAudioEffectsEnabled(true); ApplicationSettings::getInstance()->setIsAudioVoicesEnabled(true); } if(parser.isSet(clWithConfig)) { ApplicationSettings::getInstance()->setKioskMode(false); } if(parser.isSet(clWithoutConfig)) { ApplicationSettings::getInstance()->setKioskMode(true); } QQmlApplicationEngine engine(QUrl("qrc:/gcompris/src/core/main.qml")); QObject::connect(&engine, SIGNAL(quit()), DownloadManager::getInstance(), SLOT(shutdown())); // add import path for shipped qml modules: #ifdef SAILFISHOS engine.addImportPath(QStringLiteral("%1/../share/%2/lib/qml") .arg(QCoreApplication::applicationDirPath()).arg(GCOMPRIS_APPLICATION_NAME)); #else engine.addImportPath(QStringLiteral("%1/../lib/qml") .arg(QCoreApplication::applicationDirPath())); #endif if(parser.isSet(exportActivitiesAsSQL)) { ActivityInfoTree *menuTree(qobject_cast<ActivityInfoTree*>(ActivityInfoTree::menuTreeProvider(&engine, NULL))); menuTree->exportAsSQL(); exit(0); } QObject *topLevel = engine.rootObjects().value(0); QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); if (!window) { qWarning("Error: Your root item has to be a Window."); return -1; } ApplicationInfo::setWindow(window); window->setIcon(QIcon(QPixmap(QString::fromUtf8(":/gcompris/src/core/resource/gcompris-icon.png")))); if(isFullscreen) { window->showFullScreen(); } else { window->show(); } return app.exec(); }
int main( int argc, char * * argv ) { // initialize memory managers MemoryManager::init(); NotePlayHandleManager::init(); // intialize RNG srand( getpid() + time( 0 ) ); disable_denormals(); bool coreOnly = false; bool fullscreen = true; bool exitAfterImport = false; bool allowRoot = false; bool renderLoop = false; bool renderTracks = false; QString fileToLoad, fileToImport, renderOut, profilerOutputFile, configFile; // first of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--help" || arg == "-h" || arg == "--version" || arg == "-v" || arg == "--render" || arg == "-r" ) { coreOnly = true; } else if( arg == "--rendertracks" ) { coreOnly = true; renderTracks = true; } else if( arg == "--allowroot" ) { allowRoot = true; } else if( arg == "--geometry" || arg == "-geometry") { if( arg == "--geometry" ) { // Delete the first "-" so Qt recognize the option strcpy(argv[i], "-geometry"); } // option -geometry is filtered by Qt later, // so we need to check its presence now to // determine, if the application should run in // fullscreen mode (default, no -geometry given). fullscreen = false; } } #if !defined(LMMS_BUILD_WIN32) && !defined(LMMS_BUILD_HAIKU) if ( ( getuid() == 0 || geteuid() == 0 ) && !allowRoot ) { printf( "LMMS cannot be run as root.\nUse \"--allowroot\" to override.\n\n" ); return EXIT_FAILURE; } #endif QCoreApplication * app = coreOnly ? new QCoreApplication( argc, argv ) : new MainApplication( argc, argv ); Mixer::qualitySettings qs( Mixer::qualitySettings::Mode_HighQuality ); OutputSettings os( 44100, OutputSettings::BitRateSettings(160, false), OutputSettings::Depth_16Bit ); ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile; // second of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--version" || arg == "-v" ) { printVersion( argv[0] ); return EXIT_SUCCESS; } else if( arg == "--help" || arg == "-h" ) { printHelp(); return EXIT_SUCCESS; } else if( arg == "--upgrade" || arg == "-u" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } DataFile dataFile( QString::fromLocal8Bit( argv[i] ) ); if( argc > i+1 ) // output file specified { dataFile.writeFile( QString::fromLocal8Bit( argv[i+1] ) ); } else // no output file specified; use stdout { QTextStream ts( stdout ); dataFile.write( ts ); fflush( stdout ); } return EXIT_SUCCESS; } else if( arg == "--allowroot" ) { // Ignore, processed earlier #ifdef LMMS_BUILD_WIN32 if( allowRoot ) { printf( "\nOption \"--allowroot\" will be ignored on this platform.\n\n" ); } #endif } else if( arg == "--dump" || arg == "-d" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } QFile f( QString::fromLocal8Bit( argv[i] ) ); f.open( QIODevice::ReadOnly ); QString d = qUncompress( f.readAll() ); printf( "%s\n", d.toUtf8().constData() ); return EXIT_SUCCESS; } else if( arg == "--render" || arg == "-r" || arg == "--rendertracks" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); renderOut = fileToLoad; } else if( arg == "--loop" || arg == "-l" ) { renderLoop = true; } else if( arg == "--output" || arg == "-o" ) { ++i; if( i == argc ) { printf( "\nNo output file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } renderOut = QString::fromLocal8Bit( argv[i] ); } else if( arg == "--format" || arg == "-f" ) { ++i; if( i == argc ) { printf( "\nNo output format specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ext = QString( argv[i] ); if( ext == "wav" ) { eff = ProjectRenderer::WaveFile; } #ifdef LMMS_HAVE_OGGVORBIS else if( ext == "ogg" ) { eff = ProjectRenderer::OggFile; } #endif else { printf( "\nInvalid output format %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--samplerate" || arg == "-s" ) { ++i; if( i == argc ) { printf( "\nNo samplerate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } sample_rate_t sr = QString( argv[i] ).toUInt(); if( sr >= 44100 && sr <= 192000 ) { os.setSampleRate(sr); } else { printf( "\nInvalid samplerate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--bitrate" || arg == "-b" ) { ++i; if( i == argc ) { printf( "\nNo bitrate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int br = QString( argv[i] ).toUInt(); if( br >= 64 && br <= 384 ) { OutputSettings::BitRateSettings bitRateSettings = os.getBitRateSettings(); bitRateSettings.setBitRate(br); os.setBitRateSettings(bitRateSettings); } else { printf( "\nInvalid bitrate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg =="--float" || arg == "-a" ) { os.setBitDepth(OutputSettings::Depth_32Bit); } else if( arg == "--interpolation" || arg == "-i" ) { ++i; if( i == argc ) { printf( "\nNo interpolation method specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ip = QString( argv[i] ); if( ip == "linear" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_Linear; } else if( ip == "sincfastest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincFastest; } else if( ip == "sincmedium" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincMedium; } else if( ip == "sincbest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincBest; } else { printf( "\nInvalid interpolation method %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--oversampling" || arg == "-x" ) { ++i; if( i == argc ) { printf( "\nNo oversampling specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int o = QString( argv[i] ).toUInt(); switch( o ) { case 1: qs.oversampling = Mixer::qualitySettings::Oversampling_None; break; case 2: qs.oversampling = Mixer::qualitySettings::Oversampling_2x; break; case 4: qs.oversampling = Mixer::qualitySettings::Oversampling_4x; break; case 8: qs.oversampling = Mixer::qualitySettings::Oversampling_8x; break; default: printf( "\nInvalid oversampling %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--import" ) { ++i; if( i == argc ) { printf( "\nNo file specified for importing.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToImport = QString::fromLocal8Bit( argv[i] ); // exit after import? (only for debugging) if( QString( argv[i + 1] ) == "-e" ) { exitAfterImport = true; ++i; } } else if( arg == "--profile" || arg == "-p" ) { ++i; if( i == argc ) { printf( "\nNo profile specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } profilerOutputFile = QString::fromLocal8Bit( argv[i] ); } else if( arg == "--config" || arg == "-c" ) { ++i; if( i == argc ) { printf( "\nNo configuration file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } configFile = QString::fromLocal8Bit( argv[i] ); } else { if( argv[i][0] == '-' ) { printf( "\nInvalid option %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); } } // Test file argument before continuing if( !fileToLoad.isEmpty() ) { fileCheck( fileToLoad ); } else if( !fileToImport.isEmpty() ) { fileCheck( fileToImport ); } ConfigManager::inst()->loadConfigFile(configFile); // set language QString pos = ConfigManager::inst()->value( "app", "language" ); if( pos.isEmpty() ) { pos = QLocale::system().name().left( 2 ); } #ifdef LMMS_BUILD_WIN32 #undef QT_TRANSLATIONS_DIR #define QT_TRANSLATIONS_DIR ConfigManager::inst()->localeDir() #endif #ifdef QT_TRANSLATIONS_DIR // load translation for Qt-widgets/-dialogs loadTranslation( QString( "qt_" ) + pos, QString( QT_TRANSLATIONS_DIR ) ); #endif // load actual translation for LMMS loadTranslation( pos ); // try to set realtime priority #ifdef LMMS_BUILD_LINUX #ifdef LMMS_HAVE_SCHED_H #ifndef __OpenBSD__ struct sched_param sparam; sparam.sched_priority = ( sched_get_priority_max( SCHED_FIFO ) + sched_get_priority_min( SCHED_FIFO ) ) / 2; if( sched_setscheduler( 0, SCHED_FIFO, &sparam ) == -1 ) { printf( "Notice: could not set realtime priority.\n" ); } #endif #endif #endif #ifdef LMMS_BUILD_WIN32 if( !SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS ) ) { printf( "Notice: could not set high priority.\n" ); } #endif #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = SA_SIGINFO; if ( sigemptyset( &sa.sa_mask ) ) { fprintf( stderr, "Signal initialization failed.\n" ); } if ( sigaction( SIGPIPE, &sa, NULL ) ) { fprintf( stderr, "Signal initialization failed.\n" ); } #endif bool destroyEngine = false; // if we have an output file for rendering, just render the song // without starting the GUI if( !renderOut.isEmpty() ) { Engine::init( true ); destroyEngine = true; printf( "Loading project...\n" ); Engine::getSong()->loadProject( fileToLoad ); if( Engine::getSong()->isEmpty() ) { printf("The project %s is empty, aborting!\n", fileToLoad.toUtf8().constData() ); exit( EXIT_FAILURE ); } printf( "Done\n" ); Engine::getSong()->setExportLoop( renderLoop ); // when rendering multiple tracks, renderOut is a directory // otherwise, it is a file, so we need to append the file extension if ( !renderTracks ) { renderOut = baseName( renderOut ) + ProjectRenderer::getFileExtensionFromFormat(eff); } // create renderer RenderManager * r = new RenderManager( qs, os, eff, renderOut ); QCoreApplication::instance()->connect( r, SIGNAL( finished() ), SLOT( quit() ) ); // timer for progress-updates QTimer * t = new QTimer( r ); r->connect( t, SIGNAL( timeout() ), SLOT( updateConsoleProgress() ) ); t->start( 200 ); if( profilerOutputFile.isEmpty() == false ) { Engine::mixer()->profiler().setOutputFile( profilerOutputFile ); } // start now! if ( renderTracks ) { r->renderTracks(); } else { r->renderProject(); } } else // otherwise, start the GUI { new GuiApplication(); // re-intialize RNG - shared libraries might have srand() or // srandom() calls in their init procedure srand( getpid() + time( 0 ) ); // recover a file? QString recoveryFile = ConfigManager::inst()->recoveryFile(); bool recoveryFilePresent = QFileInfo( recoveryFile ).exists() && QFileInfo( recoveryFile ).isFile(); bool autoSaveEnabled = ConfigManager::inst()->value( "ui", "enableautosave" ).toInt(); if( recoveryFilePresent ) { QMessageBox mb; mb.setWindowTitle( MainWindow::tr( "Project recovery" ) ); mb.setText( QString( "<html>" "<p style=\"margin-left:6\">%1</p>" "<table cellpadding=\"3\">" " <tr>" " <td><b>%2</b></td>" " <td>%3</td>" " </tr>" " <tr>" " <td><b>%4</b></td>" " <td>%5</td>" " </tr>" " <tr>" " <td><b>%6</b></td>" " <td>%7</td>" " </tr>" "</table>" "</html>" ).arg( MainWindow::tr( "There is a recovery file present. " "It looks like the last session did not end " "properly or another instance of LMMS is " "already running. Do you want to recover the " "project of this session?" ), MainWindow::tr( "Recover" ), MainWindow::tr( "Recover the file. Please don't run " "multiple instances of LMMS when you do this." ), MainWindow::tr( "Ignore" ), MainWindow::tr( "Launch LMMS as usual but with " "automatic backup disabled to prevent the " "present recover file from being overwritten." ), MainWindow::tr( "Discard" ), MainWindow::tr( "Launch a default session and delete " "the restored files. This is not reversible." ) ) ); mb.setIcon( QMessageBox::Warning ); mb.setWindowIcon( embed::getIconPixmap( "icon" ) ); mb.setWindowFlags( Qt::WindowCloseButtonHint ); QPushButton * recover; QPushButton * discard; QPushButton * ignore; QPushButton * exit; #if QT_VERSION >= 0x050000 // setting all buttons to the same roles allows us // to have a custom layout discard = mb.addButton( MainWindow::tr( "Discard" ), QMessageBox::AcceptRole ); ignore = mb.addButton( MainWindow::tr( "Ignore" ), QMessageBox::AcceptRole ); recover = mb.addButton( MainWindow::tr( "Recover" ), QMessageBox::AcceptRole ); # else // in qt4 the button order is reversed recover = mb.addButton( MainWindow::tr( "Recover" ), QMessageBox::AcceptRole ); ignore = mb.addButton( MainWindow::tr( "Ignore" ), QMessageBox::AcceptRole ); discard = mb.addButton( MainWindow::tr( "Discard" ), QMessageBox::AcceptRole ); #endif // have a hidden exit button exit = mb.addButton( "", QMessageBox::RejectRole); exit->setVisible(false); // set icons recover->setIcon( embed::getIconPixmap( "recover" ) ); discard->setIcon( embed::getIconPixmap( "discard" ) ); ignore->setIcon( embed::getIconPixmap( "ignore" ) ); mb.setDefaultButton( recover ); mb.setEscapeButton( exit ); mb.exec(); if( mb.clickedButton() == discard ) { gui->mainWindow()->sessionCleanup(); } else if( mb.clickedButton() == recover ) // Recover { fileToLoad = recoveryFile; gui->mainWindow()->setSession( MainWindow::SessionState::Recover ); } else if( mb.clickedButton() == ignore ) { if( autoSaveEnabled ) { gui->mainWindow()->setSession( MainWindow::SessionState::Limited ); } } else // Exit { return 0; } } // first show the Main Window and then try to load given file // [Settel] workaround: showMaximized() doesn't work with // FVWM2 unless the window is already visible -> show() first gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } // Handle macOS-style FileOpen QEvents QString queuedFile = static_cast<MainApplication *>( app )->queuedFile(); if ( !queuedFile.isEmpty() ) { fileToLoad = queuedFile; } if( !fileToLoad.isEmpty() ) { if( fileToLoad == recoveryFile ) { Engine::getSong()->createNewProjectFromTemplate( fileToLoad ); } else { Engine::getSong()->loadProject( fileToLoad ); } } else if( !fileToImport.isEmpty() ) { ImportFilter::import( fileToImport, Engine::getSong() ); if( exitAfterImport ) { return EXIT_SUCCESS; } } // If enabled, open last project if there is one. Else, create // a new one. Also skip recently opened file if limited session to // lower the chance of opening an already opened file. else if( ConfigManager::inst()-> value( "app", "openlastproject" ).toInt() && !ConfigManager::inst()-> recentlyOpenedProjects().isEmpty() && gui->mainWindow()->getSession() != MainWindow::SessionState::Limited ) { QString f = ConfigManager::inst()-> recentlyOpenedProjects().first(); QFileInfo recentFile( f ); if ( recentFile.exists() ) { Engine::getSong()->loadProject( f ); } else { Engine::getSong()->createNewProject(); } } else { Engine::getSong()->createNewProject(); } // Finally we start the auto save timer and also trigger the // autosave one time as recover.mmp is a signal to possible other // instances of LMMS. if( autoSaveEnabled && gui->mainWindow()->getSession() != MainWindow::SessionState::Limited ) { gui->mainWindow()->autoSaveTimerReset(); gui->mainWindow()->autoSave(); } } const int ret = app->exec(); delete app; if( destroyEngine ) { Engine::destroy(); } // cleanup memory managers MemoryManager::cleanup(); // ProjectRenderer::updateConsoleProgress() doesn't return line after render if( coreOnly ) { printf( "\n" ); } return ret; }
void Mat4::loadTranslation(Vec3 pos) { loadTranslation(pos.x, pos.y, pos.z); }
Application::Application( int &argc, char **argv ) : Common( argc, argv ) , d( new ApplicationPrivate ) { QStringList args = arguments(); args.removeFirst(); #ifndef Q_OS_MAC if( isRunning() ) { sendMessage( args.join( "\", \"" ) ); return; } connect( this, SIGNAL(messageReceived(QString)), SLOT(parseArgs(QString)) ); #endif setApplicationName( APP ); setApplicationVersion( QString( "%1.%2.%3.%4" ) .arg( MAJOR_VER ).arg( MINOR_VER ).arg( RELEASE_VER ).arg( BUILD_VER ) ); setOrganizationDomain( DOMAINURL ); setOrganizationName( ORG ); setWindowIcon( QIcon( ":/images/crypto_128x128.png" ) ); // Actions d->closeAction = new QAction( this ); d->closeAction->setShortcut( Qt::CTRL + Qt::Key_W ); connect( d->closeAction, SIGNAL(triggered()), SLOT(closeWindow()) ); d->newAction = new QAction( this ); d->newAction->setShortcut( Qt::CTRL + Qt::Key_N ); connect( d->newAction, SIGNAL(triggered()), SLOT(parseArgs()) ); #if defined(Q_OS_MAC) setQuitOnLastWindowClosed( false ); d->bar = new MacMenuBar; d->bar->addAction( MacMenuBar::AboutAction, this, SLOT(showAbout()) ); d->bar->addAction( MacMenuBar::PreferencesAction, this, SLOT(showSettings()) ); d->bar->fileMenu()->addAction( d->newAction ); d->bar->fileMenu()->addAction( d->closeAction ); d->bar->dockMenu()->addAction( d->newAction ); #endif installTranslator( d->appTranslator = new QTranslator( this ) ); installTranslator( d->commonTranslator = new QTranslator( this ) ); installTranslator( d->qtTranslator = new QTranslator( this ) ); loadTranslation( Settings::language() ); initDigiDocLib(); QString ini = QString( "%1/digidoc.ini" ).arg( applicationDirPath() ); if( QFileInfo( ini ).isFile() ) initConfigStore( ini.toUtf8() ); else initConfigStore( NULL ); Poller::ApiType api = Poller::PKCS11; #ifdef Q_OS_WIN QString provider; QSettings reg( "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography\\Calais\\SmartCards", QSettings::NativeFormat ); Q_FOREACH( const QString &group, reg.childGroups() ) { if( group.contains( "esteid", Qt::CaseInsensitive ) ) { provider = reg.value( group + "/" + "Crypto Provider" ).toString(); break; } } if( QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA && provider != "EstEID Card CSP" ) api = Poller::CNG; if( args.contains("-capi") && QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA ) showWarning( tr("CAPI parameter is not supported on Windows Vista and newer") ); else if( args.contains("-capi") ) api = Poller::CAPI; if( args.contains("-cng") ) api = Poller::CNG; #endif if( args.contains("-pkcs11") ) api = Poller::PKCS11; d->poller = new Poller( api, this ); parseArgs( args ); }
int saisieAppuisInitQT_main(QApplication &app, int argc, char *argv[]) { app.setApplicationName("SaisieAppuisInitQT"); app.setOrganizationName("Culture3D"); QStringList cmdline_args = QCoreApplication::arguments(); if (cmdline_args.back().contains("help")) { QString help = "Mandatory unnamed args :\n" "* string :: {Full name (Dir+Pattern)}\n" "* string :: {Orientation ; NONE if not used}\n" "* string :: {Point name, or point file name}\n" "* string :: {Output}\n\n" "Named args :\n" "* [Name=SzW] Pt2di :: {Sz of window}\n" "* [Name=NbF] Pt2di :: {Nb of sub window}\n" "* [Name=NameAuto] string :: {Prefix for automatic point creation}\n" //"* [Name=Pref2Add] string :: {Prefix to add during import (for bug correction ?)}\n" "* [Name=ForceGray] bool :: {Force gray image, def=false}\n" "* [Name=OriMode] string :: {Orientation type (GRID) (Def=Std)}\n" "* [Name=ZMoy] REAL :: {Average Z, Mandatory in PB}\n" "* [Name=ZInc] REAL :: {Incertitude on Z, Mandatory in PB}\n\n" "Example:\nmm3d " + app.applicationName() + " IMG_558{0-9}[1].tif RadialBasic 100 measures.xml\n\n" "NB: visual interface for argument edition available with command:\n\n mm3d v" + app.applicationName() + "\n\n"; return helpMessage(app, help); } loadTranslation(app); QSettings settings(QApplication::organizationName(), QApplication::applicationName()); if ((argc>0)&&(string(argv[0]).find("SaisieQT")!= string::npos)) { argv++; argc--; } Pt2di aSzWin(800,800); Pt2di aNbFen(-1,-1); string aFullName, aDir, aName, aNamePt, aNameOut; //mandatory arguments string aNameOri, aModeOri, aNameAuto, aPrefix2Add; //named args aPrefix2Add = ""; bool aForceGray = false; settings.beginGroup("Misc"); aNameAuto = settings.value("defPtName", QString("100")).toString().toStdString(); settings.endGroup(); settings.beginGroup("Drawing settings"); aForceGray = settings.value("forceGray", false ).toBool(); settings.endGroup(); double aZInc, aZMoy; if (argv[0][0] == 'v') { MMVisualMode = true; argv[0] = (char*) "SaisieAppuisInitQT"; } std::string aInputSec; SaisieAppuisInit(argc, argv, aSzWin, aNbFen, aFullName, aDir, aName, aNamePt, aNameOri, aModeOri, aNameOut, aNameAuto, aPrefix2Add, aForceGray, aZMoy, aZInc,aInputSec); if (!MMVisualMode) { if (!checkNamePt( QString (aNamePt.c_str()))) return -1; QStringList filenames = getFilenames(aDir, aName); int aNbW = aNbFen.x * aNbFen.y; if (filenames.size() < aNbW) { aNbW = filenames.size(); cVirtualInterface::ComputeNbFen(aNbFen, aNbW); } updateSettings(settings, aSzWin,aNbFen, aForceGray); settings.beginGroup("Misc"); settings.setValue("defPtName", QString(aNameAuto.c_str())); settings.endGroup(); QStringList input; input << QString(MMDir().c_str()) + QString("bin/SaisiePts") << QString(MMDir().c_str()) + QString("include/XML_MicMac/SaisieInitiale.xml") << QString("DirectoryChantier=") + QString(aDir.c_str()) << QString("+Image=") + QString(aName.c_str()) << QString("+Ori=") + QString(aNameOri.c_str()) << QString("+NamePt=") + QString(aNamePt.c_str()) << QString("+NameAuto=") + QString(aNameAuto.c_str()) << QString("+Sauv=") + QString(aNameOut.c_str()) << QString("+SzWx=") + QString::number(aSzWin.x) << QString("+SzWy=") + QString::number(aSzWin.y) << QString("+NbFx=") + QString::number(aNbFen.x) << QString("+NbFy=") + QString::number(aNbFen.y); if (aModeOri == "GRID") { input << QString("+ModeOriIm=eGeomImageGrille") << QString("+Conik=false") << QString("+ZIncIsProp=false") //<< QString(+PostFixOri=GRIBin") << QString("+Px1Inc=") + QString::number(aZInc) << QString("+Px1Moy=") + QString::number(aZMoy); //<< QString("+Geom=eGeomMNTFaisceauIm1ZTerrain_Px1D"); } if (EAMIsInit(&aForceGray)) input << QString("+ForceGray=") + QString(((string)(ToString(aForceGray))).c_str()); if (EAMIsInit(&aPrefix2Add)) input << QString("+Pref2Add=") + QString(aPrefix2Add.c_str()); char **output; // Copy input to output output = new char*[input.size() + 1]; for (int i = 0; i < input.size(); i++) { output[i] = new char[strlen(input.at(i).toStdString().c_str())+1]; memcpy(output[i], input.at(i).toStdString().c_str(), strlen(input.at(i).toStdString().c_str())+1); } output[input.size()] = ((char*)NULL); cResultSubstAndStdGetFile<cParamSaisiePts> aP2( input.size()-2,output+2, output[1], StdGetFileXMLSpec("ParamSaisiePts.xml"), "ParamSaisiePts", "ParamSaisiePts", "DirectoryChantier", "FileChantierNameDescripteur" ); cAppli_SaisiePts anAppli (aP2,false); SaisieQtWindow w(POINT2D_INIT); new cQT_Interface(anAppli,&w); w.show(); w.addFiles(filenames, false); return app.exec(); } else return EXIT_SUCCESS; }
int main( int argc, char * * argv ) { // intialize RNG srand( getpid() + time( 0 ) ); bool core_only = false; bool fullscreen = true; bool exit_after_import = false; QString file_to_load, file_to_save, file_to_import, render_out; for( int i = 1; i < argc; ++i ) { if( argc > i && ( ( QString( argv[i] ) == "--render" || QString( argv[i] ) == "-r" ) || ( QString( argv[i] ) == "--help" || QString( argv[i] ) == "-h" ) ) ) { core_only = true; } else if( argc > i && QString( argv[i] ) == "-geometry" ) { // option -geometry is filtered by Qt later, // so we need to check its presence now to // determine, if the application should run in // fullscreen mode (default, no -geometry given). fullscreen = false; } } QCoreApplication * app = core_only ? new QCoreApplication( argc, argv ) : new QApplication( argc, argv ) ; Mixer::qualitySettings qs( Mixer::qualitySettings::Mode_HighQuality ); ProjectRenderer::OutputSettings os( 44100, false, 160, ProjectRenderer::Depth_16Bit ); ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile; for( int i = 1; i < argc; ++i ) { if( QString( argv[i] ) == "--version" || QString( argv[i] ) == "-v" ) { printf( "\nLinux MultiMedia Studio %s\n(%s %s, Qt %s, %s)\n\n" "Copyright (c) 2004-2014 LMMS developers.\n\n" "This program is free software; you can redistribute it and/or\n" "modify it under the terms of the GNU General Public\n" "License as published by the Free Software Foundation; either\n" "version 2 of the License, or (at your option) any later version.\n\n" "Try \"%s --help\" for more information.\n\n", LMMS_VERSION, PLATFORM, MACHINE, QT_VERSION_STR, GCC_VERSION, argv[0] ); return( EXIT_SUCCESS ); } else if( argc > i && ( QString( argv[i] ) == "--help" || QString( argv[i] ) == "-h" ) ) { printf( "\nLinux MultiMedia Studio %s\n" "Copyright (c) 2004-2014 LMMS developers.\n\n" "usage: lmms [ -r <project file> ] [ options ]\n" " [ -u <in> <out> ]\n" " [ -d <in> ]\n" " [ -h ]\n" " [ <file to load> ]\n\n" "-r, --render <project file> render given project file\n" "-o, --output <file> render into <file>\n" "-f, --output-format <format> specify format of render-output where\n" " format is either 'wav' or 'ogg'.\n" "-s, --samplerate <samplerate> specify output samplerate in Hz\n" " range: 44100 (default) to 192000\n" "-b, --bitrate <bitrate> specify output bitrate in kHz\n" " default: 160.\n" "-i, --interpolation <method> specify interpolation method\n" " possible values:\n" " - linear\n" " - sincfastest (default)\n" " - sincmedium\n" " - sincbest\n" "-x, --oversampling <value> specify oversampling\n" " possible values: 1, 2, 4, 8\n" " default: 2\n" "-u, --upgrade <in> [out] upgrade file <in> and save as <out>\n" " standard out is used if no output file is specifed\n" "-d, --dump <in> dump XML of compressed file <in>\n" "-v, --version show version information and exit.\n" "-h, --help show this usage information and exit.\n\n", LMMS_VERSION ); return( EXIT_SUCCESS ); } else if( argc > i+1 && ( QString( argv[i] ) == "--upgrade" || QString( argv[i] ) == "-u" ) ) { QString inFile( argv[i + 1] ); DataFile dataFile( inFile ); if (argc > i+2) { const QString outFile = argv[i + 2]; dataFile.writeFile( outFile ); } else { QTextStream ts( stdout ); dataFile.write( ts ); fflush( stdout ); } return( EXIT_SUCCESS ); } else if( argc > i && ( QString( argv[i] ) == "--dump" || QString( argv[i] ) == "-d" ) ) { QFile f( argv[i + 1] ); f.open( QIODevice::ReadOnly ); QString d = qUncompress( f.readAll() ); printf( "%s\n", d.toUtf8().constData() ); return( EXIT_SUCCESS ); } else if( argc > i && ( QString( argv[i] ) == "--render" || QString( argv[i] ) == "-r" ) ) { file_to_load = QString( argv[i + 1] ); render_out = baseName( file_to_load ) + "."; ++i; } else if( argc > i && ( QString( argv[i] ) == "--output" || QString( argv[i] ) == "-o" ) ) { render_out = baseName( QString( argv[i + 1] ) ) + "."; ++i; } else if( argc > i && ( QString( argv[i] ) == "--format" || QString( argv[i] ) == "-f" ) ) { const QString ext = QString( argv[i + 1] ); if( ext == "wav" ) { eff = ProjectRenderer::WaveFile; } #ifdef LMMS_HAVE_OGGVORBIS else if( ext == "ogg" ) { eff = ProjectRenderer::OggFile; } #endif else { printf( "\nInvalid output format %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] ); return( EXIT_FAILURE ); } ++i; } else if( argc > i && ( QString( argv[i] ) == "--samplerate" || QString( argv[i] ) == "-s" ) ) { sample_rate_t sr = QString( argv[i + 1] ).toUInt(); if( sr >= 44100 && sr <= 192000 ) { os.samplerate = sr; } else { printf( "\nInvalid samplerate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] ); return( EXIT_FAILURE ); } ++i; } else if( argc > i && ( QString( argv[i] ) == "--bitrate" || QString( argv[i] ) == "-b" ) ) { int br = QString( argv[i + 1] ).toUInt(); if( br >= 64 && br <= 384 ) { os.bitrate = br; } else { printf( "\nInvalid bitrate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] ); return( EXIT_FAILURE ); } ++i; } else if( argc > i && ( QString( argv[i] ) == "--interpolation" || QString( argv[i] ) == "-i" ) ) { const QString ip = QString( argv[i + 1] ); if( ip == "linear" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_Linear; } else if( ip == "sincfastest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincFastest; } else if( ip == "sincmedium" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincMedium; } else if( ip == "sincbest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincBest; } else { printf( "\nInvalid interpolation method %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] ); return( EXIT_FAILURE ); } ++i; } else if( argc > i && ( QString( argv[i] ) == "--oversampling" || QString( argv[i] ) == "-x" ) ) { int o = QString( argv[i + 1] ).toUInt(); switch( o ) { case 1: qs.oversampling = Mixer::qualitySettings::Oversampling_None; break; case 2: qs.oversampling = Mixer::qualitySettings::Oversampling_2x; break; case 4: qs.oversampling = Mixer::qualitySettings::Oversampling_4x; break; case 8: qs.oversampling = Mixer::qualitySettings::Oversampling_8x; break; default: printf( "\nInvalid oversampling %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] ); return( EXIT_FAILURE ); } ++i; } else if( argc > i && ( QString( argv[i] ) == "--import" ) ) { file_to_import = argv[i+1]; ++i; // exit after import? (only for debugging) if( argc > i && QString( argv[i+1] ) == "-e" ) { exit_after_import = true; } } else { if( argv[i][0] == '-' ) { printf( "\nInvalid option %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return( EXIT_FAILURE ); } file_to_load = argv[i]; } } QString pos = QLocale::system().name().left( 2 ); #ifdef LMMS_BUILD_WIN32 #undef QT_TRANSLATIONS_DIR #define QT_TRANSLATIONS_DIR configManager::inst()->localeDir() #endif #ifdef QT_TRANSLATIONS_DIR // load translation for Qt-widgets/-dialogs loadTranslation( QString( "qt_" ) + pos, QString( QT_TRANSLATIONS_DIR ) ); #endif // load actual translation for LMMS loadTranslation( pos ); // try to set realtime priority #ifdef LMMS_BUILD_LINUX #ifdef LMMS_HAVE_SCHED_H #ifndef __OpenBSD__ struct sched_param sparam; sparam.sched_priority = ( sched_get_priority_max( SCHED_FIFO ) + sched_get_priority_min( SCHED_FIFO ) ) / 2; if( sched_setscheduler( 0, SCHED_FIFO, &sparam ) == -1 ) { printf( "Notice: could not set realtime priority.\n" ); } #endif #endif #endif configManager::inst()->loadConfigFile(); if( render_out.isEmpty() ) { // init style and palette QApplication::setStyle( new LmmsStyle() ); // show splash screen QSplashScreen splashScreen( embed::getIconPixmap( "splash" ) ); splashScreen.show(); splashScreen.showMessage( MainWindow::tr( "Version %1" ).arg( LMMS_VERSION ), Qt::AlignRight | Qt::AlignBottom, Qt::white ); qApp->processEvents(); // init central engine which handles all components of LMMS engine::init(); splashScreen.hide(); // re-intialize RNG - shared libraries might have srand() or // srandom() calls in their init procedure srand( getpid() + time( 0 ) ); // recover a file? QString recoveryFile = QDir(configManager::inst()->workingDir()).absoluteFilePath("recover.dataFile"); if( QFileInfo(recoveryFile).exists() && QMessageBox::question( engine::mainWindow(), MainWindow::tr( "Project recovery" ), MainWindow::tr( "It looks like the last session did not end properly. " "Do you want to recover the project of this session?" ), QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes ) { file_to_load = recoveryFile; } // we try to load given file if( !file_to_load.isEmpty() ) { engine::mainWindow()->show(); if( fullscreen ) { engine::mainWindow()->showMaximized(); } if( file_to_load == recoveryFile ) { engine::getSong()->createNewProjectFromTemplate( file_to_load ); } else { engine::getSong()->loadProject( file_to_load ); } } else if( !file_to_import.isEmpty() ) { ImportFilter::import( file_to_import, engine::getSong() ); if( exit_after_import ) { return 0; } engine::mainWindow()->show(); if( fullscreen ) { engine::mainWindow()->showMaximized(); } } else { engine::getSong()->createNewProject(); // [Settel] workaround: showMaximized() doesn't work with // FVWM2 unless the window is already visible -> show() first engine::mainWindow()->show(); if( fullscreen ) { engine::mainWindow()->showMaximized(); } } } else { // we're going to render our song engine::init( false ); printf( "loading project...\n" ); engine::getSong()->loadProject( file_to_load ); printf( "done\n" ); // create renderer ProjectRenderer * r = new ProjectRenderer( qs, os, eff, render_out + QString( ( eff == ProjectRenderer::WaveFile ) ? "wav" : "ogg" ) ); QCoreApplication::instance()->connect( r, SIGNAL( finished() ), SLOT( quit() ) ); // timer for progress-updates QTimer * t = new QTimer( r ); r->connect( t, SIGNAL( timeout() ), SLOT( updateConsoleProgress() ) ); t->start( 200 ); // start now! r->startProcessing(); } const int ret = app->exec(); delete app; return( ret ); }
int main(int argc, char *argv[]) { // Disable it because we already support HDPI display natively qunsetenv("QT_DEVICE_PIXEL_RATIO"); QApplication app(argc, argv); app.setOrganizationName("KDE"); app.setApplicationName(GCOMPRIS_APPLICATION_NAME); app.setOrganizationDomain("kde.org"); app.setApplicationVersion(ApplicationInfo::GCVersion()); //add a variable to disable default fullscreen on Mac, see below.. #if defined(Q_OS_MAC) // Sandboxing on MacOSX as documented in: // http://doc.qt.io/qt-5/osx-deployment.html QDir dir(QGuiApplication::applicationDirPath()); dir.cdUp(); dir.cd("Plugins"); QGuiApplication::setLibraryPaths(QStringList(dir.absolutePath())); #endif // Local scope for config QSettings config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/gcompris/" + GCOMPRIS_APPLICATION_NAME + ".conf", QSettings::IniFormat); // Load translations QTranslator translator; loadTranslation(config, translator); // Apply translation app.installTranslator(&translator); QCommandLineParser parser; parser.setApplicationDescription("GCompris is an educational software for children 2 to 10"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption exportActivitiesAsSQL("export-activities-as-sql", "Export activities as SQL"); parser.addOption(exportActivitiesAsSQL); QCommandLineOption clDefaultCursor(QStringList() << "c" << "cursor", QObject::tr("Run GCompris with the default system cursor.")); parser.addOption(clDefaultCursor); QCommandLineOption clNoCursor(QStringList() << "C" << "nocursor", QObject::tr("Run GCompris without cursor (touch screen mode).")); parser.addOption(clNoCursor); QCommandLineOption clFullscreen(QStringList() << "f" << "fullscreen", QObject::tr("Run GCompris in fullscreen mode.")); parser.addOption(clFullscreen); QCommandLineOption clWindow(QStringList() << "w" << "window", QObject::tr("Run GCompris in window mode.")); parser.addOption(clWindow); QCommandLineOption clSound(QStringList() << "s" << "sound", QObject::tr("Run GCompris with sound enabled.")); parser.addOption(clSound); QCommandLineOption clMute(QStringList() << "m" << "mute", QObject::tr("Run GCompris without sound.")); parser.addOption(clMute); QCommandLineOption clWithoutKioskMode(QStringList() << "disable-kioskmode", QObject::tr("Disable the kiosk mode (default).")); parser.addOption(clWithoutKioskMode); QCommandLineOption clWithKioskMode(QStringList() << "enable-kioskmode", QObject::tr("Enable the kiosk mode.")); parser.addOption(clWithKioskMode); QCommandLineOption clSoftwareRenderer(QStringList() << "software-renderer", QObject::tr("Use software renderer instead of openGL (slower but should run with any graphical card, needs Qt 5.8 minimum).")); parser.addOption(clSoftwareRenderer); QCommandLineOption clOpenGLRenderer(QStringList() << "opengl-renderer", QObject::tr("Use openGL renderer instead of software (faster but crash potentially depending on your graphical card).")); parser.addOption(clOpenGLRenderer); parser.process(app); GComprisPlugin plugin; plugin.registerTypes("GCompris"); ActivityInfoTree::registerResources(); // Tell media players to stop playing, it's GCompris time ApplicationInfo::getInstance()->requestAudioFocus(); // Must be done after ApplicationSettings is constructed because we get an // async callback from the payment system ApplicationSettings::getInstance()->checkPayment(); // Disable default fullscreen launch on Mac as it's a bit broken, window is behind desktop bars #if defined(Q_OS_MAC) bool isFullscreen = false; #else // for other platforms, fullscreen is the default value bool isFullscreen = true; #endif { isFullscreen = config.value("General/fullscreen", isFullscreen).toBool(); // Set the cursor image bool defaultCursor = config.value("General/defaultCursor", false).toBool(); if(!defaultCursor && !parser.isSet(clDefaultCursor)) QGuiApplication::setOverrideCursor( QCursor(QPixmap(":/gcompris/src/core/resource/cursor.svg"), 0, 0)); // Hide the cursor bool noCursor = config.value("General/noCursor", false).toBool(); if(noCursor || parser.isSet(clNoCursor)) QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); } // Update execution counter ApplicationSettings::getInstance()->setExeCount(ApplicationSettings::getInstance()->exeCount() + 1); if(parser.isSet(clFullscreen)) { isFullscreen = true; } if(parser.isSet(clWindow)) { isFullscreen = false; } if(parser.isSet(clMute)) { ApplicationSettings::getInstance()->setIsAudioEffectsEnabled(false); ApplicationSettings::getInstance()->setIsAudioVoicesEnabled(false); } if(parser.isSet(clSound)) { ApplicationSettings::getInstance()->setIsAudioEffectsEnabled(true); ApplicationSettings::getInstance()->setIsAudioVoicesEnabled(true); } if(parser.isSet(clWithoutKioskMode)) { ApplicationSettings::getInstance()->setKioskMode(false); } if(parser.isSet(clWithKioskMode)) { ApplicationSettings::getInstance()->setKioskMode(true); } if(parser.isSet(clSoftwareRenderer)) { ApplicationSettings::getInstance()->setRenderer(QStringLiteral("software")); } if(parser.isSet(clOpenGLRenderer)) { ApplicationSettings::getInstance()->setRenderer(QStringLiteral("opengl")); } // Set the renderer used const QString &renderer = ApplicationSettings::getInstance()->renderer(); ApplicationInfo::getInstance()->setUseOpenGL(renderer != QLatin1String("software")); #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) if(renderer == QLatin1String("software")) QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software); else if(renderer == QLatin1String("opengl")) QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGL); #endif QQmlApplicationEngine engine(QUrl("qrc:/gcompris/src/core/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::quit, DownloadManager::getInstance(), &DownloadManager::shutdown); // add import path for shipped qml modules: #ifdef SAILFISHOS engine.addImportPath(QStringLiteral("%1/../share/%2/lib/qml") .arg(QCoreApplication::applicationDirPath()).arg(GCOMPRIS_APPLICATION_NAME)); #else engine.addImportPath(QStringLiteral("%1/../lib/qml") .arg(QCoreApplication::applicationDirPath())); #endif ApplicationInfo::getInstance()->setBox2DInstalled(engine); if(parser.isSet(exportActivitiesAsSQL)) { ActivityInfoTree *menuTree(qobject_cast<ActivityInfoTree*>(ActivityInfoTree::menuTreeProvider(&engine, nullptr))); menuTree->exportAsSQL(); exit(0); } QObject *topLevel = engine.rootObjects().value(0); QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); if (window == nullptr) { qWarning("Error: Your root item has to be a Window."); return -1; } ApplicationInfo::setWindow(window); window->setIcon(QIcon(QPixmap(QString::fromUtf8(":/gcompris/src/core/resource/gcompris-icon.png")))); if(isFullscreen) { window->showFullScreen(); } else { window->show(); } return app.exec(); }
int main( int argc, char * * argv ) { // initialize memory managers MemoryManager::init(); NotePlayHandleManager::init(); // intialize RNG srand( getpid() + time( 0 ) ); disable_denormals(); bool coreOnly = false; bool fullscreen = true; bool exitAfterImport = false; bool allowRoot = false; bool renderLoop = false; bool renderTracks = false; QString fileToLoad, fileToImport, renderOut, profilerOutputFile; // first of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--help" || arg == "-h" || arg == "--version" || arg == "-v" || arg == "--render" || arg == "-r" ) { coreOnly = true; } else if( arg == "--rendertracks" ) { coreOnly = true; renderTracks = true; } else if( arg == "--allowroot" ) { allowRoot = true; } else if( arg == "-geometry" ) { // option -geometry is filtered by Qt later, // so we need to check its presence now to // determine, if the application should run in // fullscreen mode (default, no -geometry given). fullscreen = false; } } #ifndef LMMS_BUILD_WIN32 if ( ( getuid() == 0 || geteuid() == 0 ) && !allowRoot ) { printf( "LMMS cannot be run as root.\nUse \"--allowroot\" to override.\n\n" ); return EXIT_FAILURE; } #endif QCoreApplication * app = coreOnly ? new QCoreApplication( argc, argv ) : new QApplication( argc, argv ) ; Mixer::qualitySettings qs( Mixer::qualitySettings::Mode_HighQuality ); ProjectRenderer::OutputSettings os( 44100, false, 160, ProjectRenderer::Depth_16Bit ); ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile; // second of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--version" || arg == "-v" ) { printVersion( argv[0] ); return EXIT_SUCCESS; } else if( arg == "--help" || arg == "-h" ) { printHelp(); return EXIT_SUCCESS; } else if( arg == "--upgrade" || arg == "-u" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } DataFile dataFile( QString::fromLocal8Bit( argv[i] ) ); if( argc > i+1 ) // output file specified { dataFile.writeFile( QString::fromLocal8Bit( argv[i+1] ) ); } else // no output file specified; use stdout { QTextStream ts( stdout ); dataFile.write( ts ); fflush( stdout ); } return EXIT_SUCCESS; } else if( arg == "--allowroot" ) { // Ignore, processed earlier #ifdef LMMS_BUILD_WIN32 if( allowRoot ) { printf( "\nOption \"--allowroot\" will be ignored on this platform.\n\n" ); } #endif } else if( arg == "--dump" || arg == "-d" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } QFile f( QString::fromLocal8Bit( argv[i] ) ); f.open( QIODevice::ReadOnly ); QString d = qUncompress( f.readAll() ); printf( "%s\n", d.toUtf8().constData() ); return EXIT_SUCCESS; } else if( arg == "--render" || arg == "-r" || arg == "--rendertracks" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); renderOut = fileToLoad; } else if( arg == "--loop" || arg == "-l" ) { renderLoop = true; } else if( arg == "--output" || arg == "-o" ) { ++i; if( i == argc ) { printf( "\nNo output file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } renderOut = QString::fromLocal8Bit( argv[i] ); } else if( arg == "--format" || arg == "-f" ) { ++i; if( i == argc ) { printf( "\nNo output format specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ext = QString( argv[i] ); if( ext == "wav" ) { eff = ProjectRenderer::WaveFile; } #ifdef LMMS_HAVE_OGGVORBIS else if( ext == "ogg" ) { eff = ProjectRenderer::OggFile; } #endif else { printf( "\nInvalid output format %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--samplerate" || arg == "-s" ) { ++i; if( i == argc ) { printf( "\nNo samplerate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } sample_rate_t sr = QString( argv[i] ).toUInt(); if( sr >= 44100 && sr <= 192000 ) { os.samplerate = sr; } else { printf( "\nInvalid samplerate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--bitrate" || arg == "-b" ) { ++i; if( i == argc ) { printf( "\nNo bitrate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int br = QString( argv[i] ).toUInt(); if( br >= 64 && br <= 384 ) { os.bitrate = br; } else { printf( "\nInvalid bitrate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg =="--float" || arg == "-a" ) { os.depth = ProjectRenderer::Depth_32Bit; } else if( arg == "--interpolation" || arg == "-i" ) { ++i; if( i == argc ) { printf( "\nNo interpolation method specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ip = QString( argv[i] ); if( ip == "linear" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_Linear; } else if( ip == "sincfastest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincFastest; } else if( ip == "sincmedium" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincMedium; } else if( ip == "sincbest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincBest; } else { printf( "\nInvalid interpolation method %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--oversampling" || arg == "-x" ) { ++i; if( i == argc ) { printf( "\nNo oversampling specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int o = QString( argv[i] ).toUInt(); switch( o ) { case 1: qs.oversampling = Mixer::qualitySettings::Oversampling_None; break; case 2: qs.oversampling = Mixer::qualitySettings::Oversampling_2x; break; case 4: qs.oversampling = Mixer::qualitySettings::Oversampling_4x; break; case 8: qs.oversampling = Mixer::qualitySettings::Oversampling_8x; break; default: printf( "\nInvalid oversampling %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--import" ) { ++i; if( i == argc ) { printf( "\nNo file specified for importing.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToImport = QString::fromLocal8Bit( argv[i] ); // exit after import? (only for debugging) if( QString( argv[i + 1] ) == "-e" ) { exitAfterImport = true; ++i; } } else if( arg == "--profile" || arg == "-p" ) { ++i; if( i == argc ) { printf( "\nNo profile specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } profilerOutputFile = QString::fromLocal8Bit( argv[1] ); } else { if( argv[i][0] == '-' ) { printf( "\nInvalid option %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); } } ConfigManager::inst()->loadConfigFile(); // set language QString pos = ConfigManager::inst()->value( "app", "language" ); if( pos.isEmpty() ) { pos = QLocale::system().name().left( 2 ); } #ifdef LMMS_BUILD_WIN32 #undef QT_TRANSLATIONS_DIR #define QT_TRANSLATIONS_DIR ConfigManager::inst()->localeDir() #endif #ifdef QT_TRANSLATIONS_DIR // load translation for Qt-widgets/-dialogs loadTranslation( QString( "qt_" ) + pos, QString( QT_TRANSLATIONS_DIR ) ); #endif // load actual translation for LMMS loadTranslation( pos ); // try to set realtime priority #ifdef LMMS_BUILD_LINUX #ifdef LMMS_HAVE_SCHED_H #ifndef __OpenBSD__ struct sched_param sparam; sparam.sched_priority = ( sched_get_priority_max( SCHED_FIFO ) + sched_get_priority_min( SCHED_FIFO ) ) / 2; if( sched_setscheduler( 0, SCHED_FIFO, &sparam ) == -1 ) { printf( "Notice: could not set realtime priority.\n" ); } #endif #endif #endif #ifdef LMMS_BUILD_WIN32 if( !SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS ) ) { printf( "Notice: could not set high priority.\n" ); } #endif // if we have an output file for rendering, just render the song // without starting the GUI if( !renderOut.isEmpty() ) { Engine::init( true ); QFileInfo fileInfo( fileToLoad ); if ( !fileInfo.exists() ) { printf("The file %s does not exist!\n", fileToLoad.toStdString().c_str()); exit( 1 ); } printf( "Loading project...\n" ); Engine::getSong()->loadProject( fileToLoad ); printf( "Done\n" ); Engine::getSong()->setExportLoop( renderLoop ); // when rendering multiple tracks, renderOut is a directory // otherwise, it is a file, so we need to append the file extension if ( !renderTracks ) { renderOut = baseName( renderOut ) + ProjectRenderer::getFileExtensionFromFormat(eff); } // create renderer RenderManager * r = new RenderManager( qs, os, eff, renderOut ); QCoreApplication::instance()->connect( r, SIGNAL( finished() ), SLOT( quit() ) ); // timer for progress-updates QTimer * t = new QTimer( r ); r->connect( t, SIGNAL( timeout() ), SLOT( updateConsoleProgress() ) ); t->start( 200 ); if( profilerOutputFile.isEmpty() == false ) { Engine::mixer()->profiler().setOutputFile( profilerOutputFile ); } // start now! if ( renderTracks ) { r->renderTracks(); } else { r->renderProject(); } } else // otherwise, start the GUI { new GuiApplication(); // re-intialize RNG - shared libraries might have srand() or // srandom() calls in their init procedure srand( getpid() + time( 0 ) ); // recover a file? QString recoveryFile = ConfigManager::inst()->recoveryFile(); if( QFileInfo(recoveryFile).exists() && QMessageBox::question( gui->mainWindow(), MainWindow::tr( "Project recovery" ), MainWindow::tr( "It looks like the last session did not end properly. " "Do you want to recover the project of this session?" ), QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes ) { fileToLoad = recoveryFile; } // we try to load given file if( !fileToLoad.isEmpty() ) { gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } if( fileToLoad == recoveryFile ) { Engine::getSong()->createNewProjectFromTemplate( fileToLoad ); } else { Engine::getSong()->loadProject( fileToLoad ); } } else if( !fileToImport.isEmpty() ) { ImportFilter::import( fileToImport, Engine::getSong() ); if( exitAfterImport ) { return EXIT_SUCCESS; } gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } } else { // If enabled, open last project if there is one. Else, create // a new one. if( ConfigManager::inst()-> value( "app", "openlastproject" ).toInt() && !ConfigManager::inst()->recentlyOpenedProjects().isEmpty() ) { QString f = ConfigManager::inst()-> recentlyOpenedProjects().first(); QFileInfo recentFile( f ); if ( recentFile.exists() ) { Engine::getSong()->loadProject( f ); } else { Engine::getSong()->createNewProject(); } } else { Engine::getSong()->createNewProject(); } // [Settel] workaround: showMaximized() doesn't work with // FVWM2 unless the window is already visible -> show() first gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } } } const int ret = app->exec(); delete app; // cleanup memory managers MemoryManager::cleanup(); return ret; }
/*! * Конструктор класса DaemonUi. */ DaemonUi::DaemonUi(QWidget *parent) : QDialog(parent, Qt::Tool) , m_core(0) , m_feeds(0) , m_plugins(0) , m_pool(0) , m_storage(0) { Path::init(LS("schatd2")); m_settings = new Settings(Path::data() + LS("/schatd2.conf"), this); loadTranslation(); m_toolBar = new QToolBar(this); m_toolBar->setIconSize(QSize(22, 22)); m_toolBar->setStyleSheet(LS("QToolBar{margin:0px;border:0px;}")); m_menu = new QMenu(); createActions(); createButtons(); m_controlGroup = new QGroupBox(this); QHBoxLayout *controlGroupLay = new QHBoxLayout(m_controlGroup); controlGroupLay->addWidget(m_toolBar); controlGroupLay->setMargin(2); controlGroupLay->setSpacing(0); // Отображение статуса m_statusLabel = new QLabel(this); m_ledLabel = new QLabel(this); m_statusGroup = new QGroupBox(this); QHBoxLayout *statusGroupLay = new QHBoxLayout(m_statusGroup); statusGroupLay->setMargin(2); statusGroupLay->setSpacing(0); statusGroupLay->addWidget(m_statusLabel); statusGroupLay->addStretch(); statusGroupLay->addWidget(m_ledLabel); QHBoxLayout *controlLay = new QHBoxLayout; controlLay->addWidget(m_controlGroup); controlLay->addWidget(m_statusGroup); m_siteBtn = new QToolButton(this); m_siteBtn->setStyleSheet(LS("QToolButton{color:#0066cc;background:none;border:none} QToolButton:hover{text-decoration:underline}")); m_siteBtn->setText("schat.me"); m_siteBtn->setFocusPolicy(Qt::NoFocus); m_siteBtn->setCursor(Qt::PointingHandCursor); m_siteBtn->setIcon(QIcon(":/images/globe-blue.png")); m_siteBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); // Кнопки внизу окна QHBoxLayout *bottomLay = new QHBoxLayout; bottomLay->addWidget(m_siteBtn); bottomLay->addStretch(); bottomLay->addWidget(m_hideButton); bottomLay->addWidget(m_quitButton); // Все основные виджеты QVBoxLayout *bodyLay = new QVBoxLayout; bodyLay->setMargin(6); bodyLay->setSpacing(6); bodyLay->addLayout(controlLay); bodyLay->addLayout(bottomLay); // Надпись вверху окна m_aboutLabel = new QLabel(QString( "<html><body style='color:#333;margin:6px;'>" "<h4 style='margin-bottom:0px;'>Simple Chat Daemon %1</h4>" "<p style='margin-left:16px;margin-top:5px;'>Copyright © 2008-%2 Alexander Sedov <<a href='mailto:[email protected]' style='color:#0066cc;'>[email protected]</a>></p>" "</body></html>").arg(SCHAT_VERSION).arg(QDateTime::currentDateTime().toString("yyyy")), this); m_aboutLabel->setStyleSheet("background:#fff; border:4px solid #fff;"); m_aboutLabel->setOpenExternalLinks(true); QFrame *line2 = new QFrame(this); line2->setFrameShape(QFrame::HLine); line2->setFrameShadow(QFrame::Sunken); // End QVBoxLayout *mainLay = new QVBoxLayout(this); mainLay->setMargin(0); mainLay->setSpacing(0); mainLay->addWidget(m_aboutLabel); mainLay->addWidget(line2); mainLay->addLayout(bodyLay); createTray(); setState(Unknown); setWindowIcon(QIcon(":/images/schat16-green.png")); retranslateUi(); QTimer::singleShot(0, this, SLOT(init())); connect(m_siteBtn, SIGNAL(clicked()), SLOT(openSite())); }