//#include #include "installdialog.h" #include "installsettings.h" #include "password_manage.h" #include "autocard.h" #include "settemplate.h" // Qt #include #include #include #include #include #include #include #include #include #include //MythTV #include "langsettings.h" #include "mythcontext.h" #include "mythversion.h" #include "mythtranslation.h" #include "mythdbcon.h" #include "exitcodes.h" #include "compat.h" #include "lcddevice.h" #include "commandlineparser.h" #include "mythlogging.h" #include "dialogbox.h" // libmythui #include "mythmainwindow.h" #include "mythuihelper.h" //?? #include "myththemebase.h" HostParms hostparm; DDCinfo ddcinfo; void initKeys(void) { REG_KEY("Welcome", "STARTXTERM", "Open an Xterm window", "F12"); REG_KEY("Welcome", "SHOWSETTINGS", "Show Mythshutdown settings", "F11"); } int main(int argc, char **argv) { bool showLang = false; bool bShowSettings = false; bool bShowNetwork = false; bool bShowHostype = false; bool bShowMisc = false; bool bShowshutdown = false; bool bShowadvanced = false; bool bShowsound = false; bool bShowadvancedX = false; bool bShowAccesscontrol = false; bool bShowplugins = false; bool bShowsoftware = false; bool bShowTemplate = false; bool bShowuser = false; bool bShowwebuser = false; bool bRunSetup = false; bool bShowHelp = false; bool bShowReadme = false; bool bShowddns = false; bool bShowinfrared = false; bool bShowscreensaver = false; bool bShowquestion = false; bool bShowsupplemental = false; bool bShowremotes_only = false; bool bShowvnc = false; bool bShowFileshare = false; QStringList template_c_line ; QString modulelist = "" ; QString templateop=""; QString templatename=""; QString templatehostname=""; QString question; // int FRONTEND_EXIT_NO_MYTHCONTEXT = 1; // int FRONTEND_EXIT_INVALID_CMDLINE =1 ; QApplication a(argc, argv); QCoreApplication::setApplicationName("mythinstall"); // Check command line arguments MythInstallCommandLineParser cmdline; int retval; if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK) return retval; if (!cmdline.Parse(argc, argv)) { cmdline.PrintHelp(); return 4; return GENERIC_EXIT_INVALID_CMDLINE; } if (cmdline.toBool("showhelp")) { cmdline.PrintHelp(); return GENERIC_EXIT_OK; } if (cmdline.toBool("showversion")) { cmdline.PrintVersion(); return GENERIC_EXIT_OK; } //--------------------Start of real stuff--------------------- gContext = new MythContext(MYTH_BINARY_VERSION); if (!gContext->Init()) { LOG(VB_GENERAL, LOG_ERR, "mythinstall: Could not initialize MythContext. Exiting."); return GENERIC_EXIT_NO_MYTHCONTEXT; } if (!MSqlQuery::testDBConnection()) { LOG(VB_GENERAL, LOG_ERR, "mythinstall: Could not open the database. Exiting."); return -1; } if (cmdline.toBool("screen")) { bShowSettings = true; LOG(VB_GENERAL, LOG_INFO, QString("mythinstall: Screen stuff")); QString tmpArg = (cmdline.toString("screen")) ; // QStringList pairs = QStringList::split(",", tmpArg); QStringList pairs = tmpArg.split(","); for (int index = 0; index < pairs.size(); ++index) { if ( pairs[index] == "network" ) { bShowNetwork = true; modulelist.append("network,"); } else if ( pairs[index] == "misc" ) { bShowMisc = true; modulelist.append("misc,"); } else if ( pairs[index] == "sleep" ) { bShowshutdown = true; modulelist.append("sleep,"); } else if ( pairs[index] == "hostype" ) { bShowHostype = true; modulelist.append("hostype,"); } else if ( pairs[index] == "advanced" ) { bShowadvanced = true; modulelist.append("advanced,"); } else if ( pairs[index] == "sound" ) { bShowsound = true; modulelist.append("audio,"); } else if ( pairs[index] == "advancedX" ) { bShowadvancedX = true; modulelist.append("advancedX,"); } else if ( pairs[index] == "accesscontrol" ) { bShowAccesscontrol = true; modulelist.append("accesscontrol,"); } else if ( pairs[index] == "plugins" ) { bShowplugins = true; modulelist.append("plugins,"); } else if ( pairs[index] == "software" ) { bShowsoftware = true; modulelist.append("software,"); } else if ( pairs[index] == "user" ) { bShowuser = true; modulelist.append("user,"); } else if ( pairs[index] == "webuser" ) { bShowwebuser = true; modulelist.append("webuser,"); } else if ( pairs[index] == "ddns" ) { bShowddns = true; modulelist.append("ddns,"); } else if ( pairs[index] == "ir" ) { bShowinfrared = true; modulelist.append("ir,"); } else if ( pairs[index] == "screensaver" ) { bShowscreensaver = true; modulelist.append("screensaver,"); } else if ( pairs[index] == "supplemental" ) { bShowsupplemental = true; modulelist.append("supplemental,"); } else if ( pairs[index] == "remotes_only" ) { bShowremotes_only = true; modulelist.append("remotes_only,"); } else if ( pairs[index] == "vnc" ) { bShowvnc = true; modulelist.append("vnc,"); } else if ( pairs[index] == "fileshare" ) { bShowFileshare = true; modulelist.append("fileshare,"); } } //for loop } if (cmdline.toBool("help")) bShowHelp = true; if (cmdline.toBool("readme")) { bShowReadme = true; } if (cmdline.toBool("question")) { bShowquestion = true; question = (cmdline.toString("question")) ; } if (cmdline.toBool("run_mythsetup")) bRunSetup = true; if (cmdline.toBool("show_lang")) showLang = true; LCD::SetupLCD(); if (class LCD *lcd = LCD::Get()) lcd->switchToTime(); MythTranslation::load("mythfrontend"); GetMythUI()->LoadQtConfig(); MythMainWindow *mainWindow = GetMythMainWindow(); mainWindow->Init(); // if parms were passed to -t then doen't init the screen. // if ( template_c_line.size() == 0 ) // { // gCoreContext->SaveSetting("HOSTtemplatetype","Do Nothing" ); // mainWindow->Init(); // findme // gContext->SetMainWindow(mainWindow); // // MythThemeBase *themeBase = new MythThemeBase(); // initKeys(); // }; gCoreContext->ActivateSettingsCache(false); gCoreContext->ClearSettingsCache(); gCoreContext->ActivateSettingsCache(false); if (bShowSettings) { gCoreContext->ActivateSettingsCache(false); gCoreContext->ClearSettingsCache(); bool runconfig = false; system("cp -f /etc/systemconfig /tmp/systemconfig.bak"); QString olddb = gCoreContext->GetSetting("HostMysqlserver"); QString oldhostype = gCoreContext->GetSetting("HostSystemType"); //sync db with pacman if (bShowplugins || bShowsoftware) { system("pacman -Q > /tmp/pacman_installed"); QString progPacmanNamesArray[] = { "mythappletrailers", "mytharchive", "mythbrowser", "mythgallery", "mythgame", "dolphin-emu", "fceux", "sdlmame", "mednafen", "mupen64plus", "romdb", "snes9x", "xe", "mythmusic", "mythnetvision", "mythnews", "libdvdcss", "mythweather", "mythzoneminder", "huludesktop", "openpht", "plex-media-server", "kodi", "webmin", "web-on-linhes", "foldingathome"}; QString progDBNamesArray[] = { "Hostpluginmythappletrailers", "Hostpluginmytharchive", "Hostpluginmythbrowser", "Hostpluginmythgallery", "Hostpluginmythgame", "HostpluginmythgameDolphin", "Hostpluginmythgamefceux", "HostpluginmythgameMame", "HostpluginmythgameMednafen", "Hostpluginmythgamemupen64", "HostpluginmythgameROMDB", "Hostpluginmythgamesnes9x", "HostpluginmythgameXe", "Hostpluginmythmusic", "Hostpluginmythnetvision", "Hostpluginmythnews", "Hostpluginmythvideo_dvdcss", "Hostpluginmythweather", "Hostpluginmythzoneminder", "HostHuluDesktop", "HostPLEXHT", "HostPLEXMS", "HostXBMC", "Hostwebmin", "Hostwebonlinhes", "Hostfoldingathome"}; char cmd[200]; int grepstatus; int pacmanNamesArraySize = sizeof(progPacmanNamesArray) / sizeof(progPacmanNamesArray[0]); //for loop to run though progPacmanNamesArray for(int i = 0; i < pacmanNamesArraySize; i++) { QByteArray PacName = progPacmanNamesArray[i].toLocal8Bit(); const char *PacNameChar = PacName.data(); sprintf(cmd, "grep -q '%s ' /tmp/pacman_installed", PacNameChar); //LOG(VB_GENERAL, LOG_INFO, QString(progPacmanNamesArray[i])); //LOG(VB_GENERAL, LOG_INFO, QString(progDBNamesArray[i])); QString currDBValue = gCoreContext->GetSetting(progDBNamesArray[i]); //LOG(VB_GENERAL, LOG_INFO, QString(currDBValue)); grepstatus = system(cmd); if ( grepstatus != 0 && currDBValue == "1" ) { //LOG(VB_GENERAL, LOG_INFO, QString("pkg NOT found and db 1")); gCoreContext->SaveSetting(progDBNamesArray[i],"0" ); runconfig = true; } else if ( grepstatus == 0 && currDBValue == "0" ) { //LOG(VB_GENERAL, LOG_INFO, QString("pkg found and db 0")); gCoreContext->SaveSetting(progDBNamesArray[i],"1" ); runconfig = true; } } system("rm -f /tmp/pacman_installed"); } //DONE sync db with pacman runsettings(false,bShowNetwork,bShowHostype,bShowMisc,bShowshutdown,bShowadvanced,bShowsound,bShowadvancedX,bShowAccesscontrol,bShowplugins,bShowsoftware,bShowuser,bShowwebuser,bShowddns,bShowinfrared,bShowscreensaver,bShowsupplemental,bShowremotes_only,bShowvnc,bShowFileshare); QString newdb = gCoreContext->GetSetting("HostMysqlserver"); QString newhostype = gCoreContext->GetSetting("HostSystemType"); int status = system("diff /tmp/systemconfig.bak /etc/systemconfig"); bool restart = false; //save my settings in case db switches QString cmdtxt=MV_ROOT; cmdtxt.append("bin/myth_settings_wrapper.sh -c save -t syssettings -d " + olddb); system(qPrintable(cmdtxt)); if ( status != 0 ) { runconfig = true; } if ( newdb != olddb ) { runconfig = true; restart = true; //db changed save setting from olddb QString cmdtxt; cmdtxt=MV_ROOT; cmdtxt.append("bin/myth_settings_wrapper.sh -c save -t syssettings -d " + olddb ) ; system(qPrintable(cmdtxt)); } if ( runconfig ) { //LOG(VB_GENERAL, LOG_ERR, // "mythinstall: this is where i stalled"); if ( newhostype != oldhostype ) modulelist.append("hostypec,"); // trim off last , modulelist.truncate(modulelist.length()-1); QString cmdtxt; cmdtxt=MV_ROOT ; cmdtxt.append("bin/myth_settings_wrapper.sh -c restore -t syssettings -d "); QString dbcommand = cmdtxt; dbcommand.append(newdb); run_systemconfig(modulelist,restart,dbcommand); } system("rm -f /tmp/systemconfig.bak"); gCoreContext->ActivateSettingsCache(false); gCoreContext->ClearSettingsCache(); if ( restart ) { DialogBox *dia = NULL; QString prompt; QString *problems = new QString("The network address of the database has changed."); problems->append("\n"); problems->append("The frontend will need to restart to connect to the new database."); problems->append("\n"); dia = new DialogBox(mainWindow, problems->append("\n" )); dia->AddButton(QObject::tr("OK")); int returncode = 0; returncode = dia->exec(); dia->deleteLater(); //cout << "restarting" << endl; QString cmdtxt; cmdtxt=MV_ROOT ; cmdtxt.append("bin/systemconfig.sh reloadfe" ); system(qPrintable(cmdtxt)); } gCoreContext->ActivateSettingsCache(false); gCoreContext->ClearSettingsCache(); gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE"); }//run settings else if (bShowTemplate) { // if ( template_c_line.size() == 2) // { // templateop=template_c_line[0]; // templatename=template_c_line[1]; // } // else if ( template_c_line.size() == 3) // { // templateop=template_c_line[0]; // templatename=template_c_line[1]; // templatehostname=template_c_line[2]; // }; // choosetemplate(templateop,templatename,templatehostname); } else if (bRunSetup) { DialogBox *dia = NULL; QString prompt; QString *problems = new QString("To configure the TV cards and program guide the setup program needs to be run."); problems->append("\n"); problems->append("\n"); problems->append("For those in North America, guide data is provided by Schedules Direct."); problems->append("\n"); problems->append("Visit http://www.schedulesdirect.org/ to signup for your account today"); problems->append("\n"); problems->append("\n"); problems->append("\n"); problems->append("If you choose to not run mythtv-setup now, the program can be run at any time by typing mythtv-setup or hitting ALT+s"); problems->append("\n"); problems->append("\n"); prompt = QObject::tr("Do you wish to run mythtv-setup ?"); dia = new DialogBox(mainWindow, problems->append("\n" + prompt)); dia->AddButton(QObject::tr("Yes")); dia->AddButton(QObject::tr("Yes and try to autodetect cards")); dia->AddButton(QObject::tr("No")); int returncode = 0; returncode = dia->exec(); DialogCode dcode = dia->exec(); dia->deleteLater(); if (kDialogCodeButton0 == dcode ) returncode = 0; if (kDialogCodeButton1 == dcode ) returncode = 1; if (kDialogCodeButton2 == dcode ) returncode = 2; /* if (returncode == 1) { AutoCard listcards; listcards.exec(); }*/ return returncode; } else if (bShowHelp) { DialogBox *dia = NULL; QString prompt; QString *problems = new QString("LinHES Help"); problems->append("\n"); problems->append("Visit http://linhes.org for additional help."); problems->append("\n"); problems->append("\n"); problems->append("------Keyboard Shortcuts---------------------------------"); problems->append("\n"); problems->append("Alt + h: This Screen"); problems->append("\n"); #ifdef __MVAPP__ problems->append("F2: Open/Close Terminal"); problems->append("\n"); problems->append("Shift + Return: Open New Terminal (xterm)"); problems->append("\n"); problems->append("Alt + F2: Show 2nd desktop Alt + F1 To Go Back"); problems->append("\n"); problems->append("Alt + c: Capture Myth Screenshot"); problems->append("\n"); #else problems->append("Alt + x: Open New Terminal (xterm)"); problems->append("\n"); problems->append("Alt + m: Open mythfrontend"); problems->append("\n"); problems->append("m in mythfrontend: Display Power/About Menu"); problems->append("\n"); #endif problems->append("Alt + 1: Start Master mythbackend"); problems->append("\n"); problems->append("Alt + 2: Stop Master mythbackend"); problems->append("\n"); problems->append("Alt + 3: Restart Master mythbackend"); problems->append("\n"); problems->append("Alt + s: Open mythtv-setup"); problems->append("\n"); problems->append("Alt + u: Unhide/Hide Mouse Pointer"); problems->append("\n"); problems->append("Alt + w: Open Web Browser (Chrome if installed)"); problems->append("\n"); problems->append("Alt + f: Restart Window Manager"); problems->append("\n"); dia = new DialogBox(mainWindow, problems->append("\n" )); dia->AddButton(QObject::tr("OK")); int returncode = 0; returncode = dia->exec(); dia->deleteLater(); DestroyMythMainWindow(); delete gContext; return returncode; } else if (bShowReadme) { DialogBox *dia = NULL; QString prompt; QString line; QString *problems = new QString(""); problems->append("\n"); QFile file("/usr/MythVantage/README"); if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) { QTextStream t( &file ); // use a text stream while ( !t.atEnd() ) { line = t.readLine(); problems->append(line); problems->append("\n"); } file.close(); } else problems->append("Couldn't open file"); dia = new DialogBox(mainWindow, problems->append("\n" )); dia->AddButton(QObject::tr("OK")); int returncode = 0; returncode = dia->exec(); dia->deleteLater(); DestroyMythMainWindow(); delete gContext; return returncode; } else if (bShowquestion) { //LOG(VB_GENERAL, LOG_INFO, QString(question)); DialogBox *dia = NULL; QString prompt; QString *problems = new QString(""); problems->append("\n"); problems->append("\n"); problems->append(question); dia = new DialogBox(mainWindow, problems->append("\n" )); dia->AddButton(QObject::tr("Yes")); dia->AddButton(QObject::tr("No")); int returncode = 0; returncode = dia->exec(); dia->deleteLater(); DestroyMythMainWindow(); delete gContext; return returncode; } else { if (LanguageSelection::prompt(showLang)){ //taken from reloadTheme mythtv-setup MythTranslation::reload(); GetMythMainWindow()->ReinitDone(); } MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); WelcomeDialog *welcome = new WelcomeDialog(mainStack, "Welcome"); if (welcome->Create()) { mainStack->AddScreen(welcome, true); } else return -1; do { qApp->processEvents(); usleep(5000); } while (mainStack->TotalScreens() > 0); // DestroyMythMainWindow(); // delete gContext; // gContext = NULL; // delete qApp; } DestroyMythMainWindow(); //gCoreContext->GetSetting("MasterServerIP"); //gCoreContext->GetSetting("BackendServerIP"); delete gContext; gContext = NULL ; //delete qApp; return 0; }