int run_backend(MythBackendCommandLineParser &cmdline) { if (!setup_context(cmdline)) return GENERIC_EXIT_NO_MYTHCONTEXT; bool ismaster = gCoreContext->IsMasterHost(); if (!UpgradeTVDatabaseSchema(ismaster, ismaster)) { VERBOSE(VB_IMPORTANT, "Couldn't upgrade database to new schema"); return GENERIC_EXIT_DB_OUTOFDATE; } MythTranslation::load("mythfrontend"); if (!ismaster) { int ret = connect_to_master(); if (ret != GENERIC_EXIT_OK) return ret; } QString myip = gCoreContext->GetSetting("BackendServerIP"); int port = gCoreContext->GetNumSetting("BackendServerPort", 6543); if (myip.isEmpty()) { cerr << "No setting found for this machine's BackendServerIP.\n" << "Please run setup on this machine and modify the first page\n" << "of the general settings.\n"; return GENERIC_EXIT_SETUP_ERROR; } MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler(); if (ismaster) { VERBOSE(VB_GENERAL, LOC + "Starting up as the master server."); } else { VERBOSE(VB_GENERAL, LOC + "Running as a slave backend."); } print_warnings(cmdline); bool fatal_error = false; bool runsched = setupTVs(ismaster, fatal_error); if (fatal_error) { delete sysEventHandler; return GENERIC_EXIT_SETUP_ERROR; } if (ismaster) { if (runsched) { sched = new Scheduler(true, &tvList); int err = sched->GetError(); if (err) return err; if (cmdline.toBool("nosched")) sched->DisableScheduling(); } if (!cmdline.toBool("nohousekeeper")) housekeeping = new HouseKeeper(true, ismaster, sched); if (!cmdline.toBool("noautoexpire")) { expirer = new AutoExpire(&tvList); if (sched) sched->SetExpirer(expirer); } } else if (!cmdline.toBool("nohousekeeper")) { housekeeping = new HouseKeeper(true, ismaster, NULL); } if (!cmdline.toBool("nojobqueue")) jobqueue = new JobQueue(ismaster); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- if (g_pUPnp == NULL) { g_pUPnp = new MediaServer(); g_pUPnp->Init(ismaster, cmdline.toBool("noupnp")); } // ---------------------------------------------------------------------- // Setup status server // ---------------------------------------------------------------------- HttpStatus *httpStatus = NULL; HttpServer *pHS = g_pUPnp->GetHttpServer(); if (pHS) { VERBOSE(VB_IMPORTANT, "Main::Registering HttpStatus Extension"); httpStatus = new HttpStatus( &tvList, sched, expirer, ismaster ); pHS->RegisterExtension( httpStatus ); } VERBOSE(VB_IMPORTANT, QString("Enabled verbose msgs: %1") .arg(verboseString)); MainServer *mainServer = new MainServer( ismaster, port, &tvList, sched, expirer); int exitCode = mainServer->GetExitCode(); if (exitCode != GENERIC_EXIT_OK) { VERBOSE(VB_IMPORTANT, "Backend exiting, MainServer initialization " "error."); delete mainServer; return exitCode; } if (httpStatus && mainServer) httpStatus->SetMainServer(mainServer); StorageGroup::CheckAllStorageGroupDirs(); if (gCoreContext->IsMasterBackend()) SendMythSystemEvent("MASTER_STARTED"); /////////////////////////////// /////////////////////////////// exitCode = qApp->exec(); /////////////////////////////// /////////////////////////////// if (gCoreContext->IsMasterBackend()) { SendMythSystemEvent("MASTER_SHUTDOWN"); qApp->processEvents(); } VERBOSE(VB_GENERAL, "MythBackend exiting"); delete sysEventHandler; delete mainServer; cleanup(); return exitCode; }
void ThemeChooser::customEvent(QEvent *e) { if ((MythEvent::Type)(e->type()) == MythEvent::MythEventMessage) { MythEvent *me = (MythEvent *)e; QStringList tokens = me->Message().split(" ", QString::SkipEmptyParts); if (tokens.isEmpty()) return; if (tokens[0] == "DOWNLOAD_FILE") { QStringList args = me->ExtraDataList(); if ((m_downloadState == dsIdle) || (tokens.size() != 2) || (!m_downloadTheme) || (args[1] != m_downloadFile)) return; if (tokens[1] == "UPDATE") { updateProgressBar(args[2].toInt(), args[3].toInt()); } else if (tokens[1] == "FINISHED") { bool remoteFileIsLocal = false; int fileSize = args[2].toInt(); int errorCode = args[4].toInt(); CloseBusyPopup(); QFileInfo file(m_downloadFile); if ((m_downloadState == dsDownloadingOnBackend) && (m_downloadFile.startsWith("myth://"))) { // The backend download is finished so start the // frontend download if ((errorCode == 0) && (fileSize > 0)) { m_downloadState = dsDownloadingOnFrontend; QString localFile = GetConfDir() + "/tmp/" + file.fileName(); file.setFile(localFile); if (file.exists()) { remoteFileIsLocal = true; } else { GetMythDownloadManager()->queueDownload( m_downloadFile, localFile, this); OpenBusyPopup(tr("Copying %1 Theme Package") .arg(m_downloadTheme->GetName())); } m_downloadFile = localFile; } else { m_downloadState = dsIdle; ShowOkPopup(tr("ERROR downloading theme package on master backend.")); } } if ((m_downloadState == dsDownloadingOnFrontend) && (file.exists())) { // The frontend download is finished if ((errorCode == 0) && (fileSize > 0)) { m_downloadState = dsExtractingTheme; ThemeExtractThread *extractThread = new ThemeExtractThread(this, m_downloadFile, GetConfDir() + "/themes"); QThreadPool::globalInstance()->start(extractThread); if (!remoteFileIsLocal) RemoteFile::DeleteFile(args[0]); OpenBusyPopup(tr("Installing %1 Theme") .arg(m_downloadTheme->GetName())); } else { m_downloadState = dsIdle; ShowOkPopup(tr("ERROR downloading theme package from master backend.")); } } } } else if ((me->Message() == "THEME_INSTALLED") && (m_downloadTheme) && (m_downloadState == dsExtractingTheme)) { m_downloadState = dsIdle; CloseBusyPopup(); QStringList args = me->ExtraDataList(); QFile::remove(args[0]); QString event = QString("THEME_INSTALLED PATH %1") .arg(GetConfDir() + "/themes/" + m_downloadTheme->GetDirectoryName()); SendMythSystemEvent(event); gCoreContext->SaveSetting("Theme", m_downloadTheme->GetDirectoryName()); GetMythMainWindow()->JumpTo("Reload Theme"); } } }