int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; QPixmap pixmap(":/app/icons/splash.png"); SplashScreen *s = new SplashScreen(pixmap); s->show(); s->showMessage("Event Music Machine starten..."); QString path = Configuration::getStorageLocation(); if (path == "") { QFileDialog dia(s); dia.setViewMode(QFileDialog::List); dia.setFileMode(QFileDialog::Directory); dia.setAcceptMode(QFileDialog::AcceptOpen); dia.setOptions(QFileDialog::ShowDirsOnly); dia.setWindowTitle(QObject::tr("Bitte selektieren Sie einen Ordner in dem die Konfigurations-Dateien abgelegt werden sollen.")); if (dia.exec() == 1) { path = dia.selectedFiles().at(0); Configuration::setStorageLocation(path); } } s->showMessage("Slotspeicher verbinden..."); if (!QFile(Configuration::getStorageLocation() + "/slotstore.emm").exists()) { QMessageBox::information(s,"Slot-Speicher anlegen",QObject::tr("Es wurde keine gültige Slot-Datenbank gefunden. Sie wurde jetzt angelegt.")); QFile::copy(":/slot-store.sqlite", Configuration::getStorageLocation() + "/slotstore.emm"); QFile::setPermissions(Configuration::getStorageLocation() + "/slotstore.emm",QFile::ReadOther | QFile::WriteOther); } QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(Configuration::getStorageLocation() + "/slotstore.emm"); if (!db.open()) { QMessageBox::warning(s,QObject::tr("Keine Verbindung zum Slot-Speicher"),QObject::tr("Es konnte keine Verbindung zum Slot-Speicher hergestellt werden!")); } s->showMessage("Verbindung zur Tastatur herstellen..."); KeyboardController *keyController = KeyboardController::getInstance(); QObject::connect(keyController, SIGNAL(errorOccured(QString)), s, SLOT(showErrorMessage(QString))); QObject::connect(keyController, SIGNAL(keyPressed(int,int)), &w, SLOT(keyboardSignal(int,int))); keyController->initializeKeyboardController(); s->showMessage("Audiogeräte initialisieren..."); AudioProcessor::getInstance()->initDevices(&w); s->showMessage("Audio-Plugins laden..."); PluginLoader::loadPlugins(); s->showMessage("Slots laden und überprüfen..."); int number = 1; Configuration *config = Configuration::getInstance(); for (int i=0;i<config->getLayer();i++) { for (int j=0;j<config->getVerticalSlots();j++) { for (int k=0;k<config->getHorizontalSlots();k++) { CartSlot *slot = AudioProcessor::getInstance()->getCartSlotWithNumber(number); s->showMessage("Slots laden und überprüfen...\r\n"+slot->getText1()); if (slot->isMissing()) { QMessageBox::information(s,"Datei wurde nicht gefunden","Slot "+QString::number(slot->getNumber())+" ("+slot->getText1()+") konnte nicht geladen werden, weil die Datei nicht gefunden wurde!"); } number++; } } } s->showMessage("Benutzeroberfläche initialisieren..."); w.init(); s->close(); w.show(); return a.exec(); }
int InteractiveApplication::run(int argc, char** argv) { // Generate the XML files if (generateXml() == false) { return -1; } // Set the application to run in interactive mode ApplicationServicesImp* pApp = ApplicationServicesImp::instance(); if (pApp != NULL) { pApp->setInteractive(); } // Initialize the Qt application QApplication& qApplication = dynamic_cast<QApplication&>(getQApp()); #if !defined(LINUX) qApplication.setFont(QFont("Tahoma", 8)); #endif bool configSettingsValid = false; string configSettingsErrorMsg = ""; ConfigurationSettingsImp* pConfigSettings = ConfigurationSettingsImp::instance(); if (pConfigSettings != NULL) { configSettingsValid = pConfigSettings->isInitialized(); if (pConfigSettings->getInitializationErrorMsg() != NULL) { configSettingsErrorMsg = pConfigSettings->getInitializationErrorMsg(); } if (configSettingsValid) { pConfigSettings->validateInitialization(); configSettingsValid = pConfigSettings->isInitialized(); if (pConfigSettings->getInitializationErrorMsg() != NULL) { configSettingsErrorMsg = pConfigSettings->getInitializationErrorMsg(); } } } if (!configSettingsValid) { if (configSettingsErrorMsg.empty()) { configSettingsErrorMsg = "Unable to locate configuration settings"; } reportError(configSettingsErrorMsg); return -1; } else { if (!configSettingsErrorMsg.empty()) { reportWarning(configSettingsErrorMsg); } } { // scope the lifetime of the lock SessionSaveLock lock; // Create a progress object mpProgress = new ProgressAdapter(); // Splash screen Q_INIT_RESOURCE(Application); SplashScreen* pSplash = new SplashScreen(mpProgress); vector<string> splashPaths = Service<InstallerServices>()->getSplashScreenPaths(); pSplash->setSplashImages(list<string>(splashPaths.begin(), splashPaths.end())); pSplash->show(); qApplication.processEvents(); // process pending extension uninstalls InstallerServicesImp::instance()->processPending(mpProgress); string errMsg; if(!ConfigurationSettingsImp::instance()->loadSettings(errMsg)) { if (QMessageBox::warning(pSplash, "Error loading configuration settings", QString("Warning: unable to reload application settings.\n%1\nContinue loading Opticks?").arg(QString::fromStdString(errMsg)), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { pSplash->close(); delete pSplash; return -1; } } // Initialization int iReturn = Application::run(argc, argv); if (iReturn == -1) { pSplash->close(); delete pSplash; return -1; } qApplication.processEvents(); // process auto-installs QDirIterator autos(QString::fromStdString(ConfigurationSettingsImp::instance()->getSettingExtensionFilesPath()->getFullPathAndName()) + "/AutoInstall", QStringList() << "*.aeb", QDir::Files); vector<string> pendingInstall; while (autos.hasNext()) { pendingInstall.push_back(autos.next().toStdString()); } bool autoInstallOccurred = false; InstallerServicesImp::instance()->setPendingInstall(pendingInstall); for (vector<string>::iterator autoIter = pendingInstall.begin(); autoIter != pendingInstall.end(); ++autoIter) { bool success = InstallerServicesImp::instance()->installExtension(*autoIter, mpProgress); if(!success) { QFileInfo autoInfo(QString::fromStdString(*autoIter)); // Attempt to parse the AEB so we can get a better name string extName = autoInfo.fileName().toStdString(); { // scope the AebIo so we don't hold a handle to the aeb file and can delete it below Aeb extension; AebIo io(extension); string errMsg; // ignored if (io.fromFile(autoInfo.filePath().toStdString(), errMsg)) { extName = extension.getName(); } } if(DesktopServicesImp::instance()->showMessageBox("Installation error", "Unable to install " + extName + "\nWould you like to delete the file?", "Yes", "No") == 0) { QFile::remove(QString::fromStdString(*autoIter)); } } else { autoInstallOccurred = true; QFile::remove(QString::fromStdString(*autoIter)); } } InstallerServicesImp::instance()->setPendingInstall(); if (autoInstallOccurred) { // rescan the plug-ins PlugInManagerServicesImp::instance()->buildPlugInList(Service<ConfigurationSettings>()->getPlugInPath()); } // Create the main GUI window mpProgress->updateProgress("Creating the main application window...", 0, NORMAL); ApplicationWindow* pAppWindow = new ApplicationWindow(pSplash); qApplication.processEvents(); // Execute startup plug-ins PlugInManagerServicesImp* pManager = PlugInManagerServicesImp::instance(); if (pManager != NULL) { pManager->executeStartupPlugIns(mpProgress); qApplication.processEvents(); } // Restore the previous position and visibility state of the toolbars and dock windows pAppWindow->restoreConfiguration(); // Keep the splash screen up until all images have been shown to the user. while (!pSplash->canClose()) {} // Display the main application window pAppWindow->show(); // Destroy the splash screen pSplash->close(); delete pSplash; // Create a progress dialog ProgressDlg* pProgressDlg = new ProgressDlg(APP_NAME, pAppWindow); mpProgress->attach(SIGNAL_NAME(Subject, Modified), Slot(pProgressDlg, &ProgressDlg::progressUpdated)); mpProgress->attach(SIGNAL_NAME(Subject, Deleted), Slot(pProgressDlg, &ProgressDlg::progressDeleted)); // Load files specified on the command line ArgumentList* pArgList(ArgumentList::instance()); if (pArgList != NULL) { FileType fileType; vector<string> filenames(pArgList->getOptions("")); for (vector<string>::size_type i = 0; i < filenames.size(); ++i) { FilenameImp filename(filenames[i]); QString strFilename = QString::fromStdString(filename.getFullPathAndName()); if (strFilename.isEmpty() == false) { QFileInfo info(strFilename); if ((info.suffix() == "wiz") || (info.suffix() == "batchwiz")) { if ((fileType.isValid() == true) && (fileType != WIZARD_FILES)) { fileType = EnumWrapper<FileTypeEnum>(); break; } fileType = WIZARD_FILES; } else if (info.suffix() == "session") { if (fileType.isValid() == true) { fileType = EnumWrapper<FileTypeEnum>(); break; } fileType = SESSION_FILE; } else { if ((fileType.isValid() == true) && (fileType != DATASET_FILES)) { fileType = EnumWrapper<FileTypeEnum>(); break; } fileType = DATASET_FILES; } } } if (fileType.isValid() == true) { // Check for valid filenames vector<string> validFilenames; for (vector<string>::size_type i = 0; i < filenames.size(); ++i) { FilenameImp filename(filenames[i]); string normalizedFilename = filename.getFullPathAndName(); if (normalizedFilename.empty() == false) { QString strFilename = QString::fromStdString(normalizedFilename); QFileInfo info(strFilename); if ((info.isFile() == true) && (info.exists() == true)) { validFilenames.push_back(normalizedFilename); } else { reportWarning("The specified file '" + normalizedFilename + "' does not exist and cannot be loaded."); } } } // Load the files switch (fileType) { case WIZARD_FILES: { for (vector<string>::size_type i = 0; i < validFilenames.size(); ++i) { string filename = validFilenames[i]; QString strFilename = QString::fromStdString(filename); QFileInfo info(strFilename); if (info.suffix() == "wiz") { pAppWindow->runWizard(strFilename); } else if (info.suffix() == "batchwiz") { vector<string> batchFiles; batchFiles.push_back(filename); WizardUtilities::runBatchFiles(batchFiles, mpProgress); } } break; } case SESSION_FILE: { if (validFilenames.empty() == false) { VERIFYRV(validFilenames.size() == 1, -1); string filename = validFilenames.front(); string saveKey = SessionManager::getSettingQueryForSaveKey(); SessionSaveType saveType = SESSION_DONT_AUTO_SAVE; DataVariant dvSaveType(saveType); pConfigSettings->adoptTemporarySetting(saveKey, dvSaveType); pAppWindow->openSession(QString::fromStdString(filename)); pConfigSettings->deleteTemporarySetting(saveKey); } break; } case DATASET_FILES: { if (validFilenames.empty() == false) { ImporterResource importer("Auto Importer", validFilenames, mpProgress, false); importer->execute(); } break; } default: break; } } else if (filenames.empty() == false) { string msg = "Unable to import the files specified on the command line. " + string(APP_NAME) + " supports loading one session file, one or more wizard files, or one or more data set files."; mpProgress->updateProgress(msg, 0, ERRORS); } } // If there are any wizards, run them executeStartupBatchWizards(); // Destroy the progress object and progress dialog delete dynamic_cast<ProgressAdapter*>(mpProgress); vector<string> autoExitOptions = pArgList->getOptions("autoExit"); if (autoExitOptions.empty() == false) { SessionSaveType tempSettingQueryForSave = SESSION_DONT_AUTO_SAVE; const string sessionFilename = autoExitOptions.front(); if (sessionFilename.empty() == false) { tempSettingQueryForSave = SESSION_AUTO_SAVE; pAppWindow->setSessionFilename(FilenameImp(sessionFilename).getFullPathAndName()); } DataVariant dvTempSettingQueryForSave(tempSettingQueryForSave); pConfigSettings->adoptTemporarySetting(SessionManager::getSettingQueryForSaveKey(), dvTempSettingQueryForSave); pAppWindow->close(); return iReturn; } // Set the application window to auto-generate textures QTimer textureGenerationTimer; bool generation = RasterLayer::getSettingBackgroundTileGeneration(); if (generation == true) { textureGenerationTimer.setInterval(100); pAppWindow->connect(&textureGenerationTimer, SIGNAL(timeout()), SLOT(pregenerateTexture())); } } // Initiate the GUI event loop, which returns when the user exits the application return qApplication.exec(); }
void SplashScreen::showSplash(QThread *thread) { double opacity = OPACITY_DELTA; const int opacitySteps = qRound(1.0 / OPACITY_DELTA); SplashScreen *splashScreen = new SplashScreen(); bool bTaskBar = false; //Show splash splashScreen->m_canClose = false; splashScreen->setWindowOpacity(opacity); splashScreen->setFixedSize(splashScreen->size()); splashScreen->show(); //Wait for window to show QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); splashScreen->repaint(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); //Setup the event loop QEventLoop *loop = new QEventLoop(splashScreen); connect(thread, SIGNAL(terminated()), loop, SLOT(quit()), Qt::QueuedConnection); connect(thread, SIGNAL(finished()), loop, SLOT(quit()), Qt::QueuedConnection); //Create timer QTimer *timer = new QTimer(); connect(timer, SIGNAL(timeout()), loop, SLOT(quit())); //Start thread QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); thread->start(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); //Init taskbar SET_TASKBAR_STATE(true); //Fade in for(int i = 1; i <= opacitySteps; i++) { opacity = (i < opacitySteps) ? (OPACITY_DELTA * static_cast<double>(i)) : 1.0; splashScreen->setWindowOpacity(opacity); splashScreen->update(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY); SET_TASKBAR_STATE(true); Sleep(FADE_DELAY); } //Start the timer timer->start(30720); //Loop while thread is still running if(bool bIsRunning = THREAD_RUNNING(thread)) { int deadlockCounter = 0; while(bIsRunning) { loop->exec(); if(bIsRunning = THREAD_RUNNING(thread)) { qWarning("Potential deadlock in initialization thread!"); if(++deadlockCounter >= 10) qFatal("Deadlock in initialization thread!"); } } } //Stop the timer timer->stop(); //Fade out for(int i = opacitySteps; i >= 0; i--) { opacity = OPACITY_DELTA * static_cast<double>(i); splashScreen->setWindowOpacity(opacity); splashScreen->update(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY); Sleep(FADE_DELAY); } //Restore taskbar SET_TASKBAR_STATE(false); //Hide splash splashScreen->m_canClose = true; splashScreen->close(); //Free LAMEXP_DELETE(loop); LAMEXP_DELETE(timer); LAMEXP_DELETE(splashScreen); }