#include #include //#include "libmyth/mythdialogs.h" #include "libmyth/mythcontext.h" #include "libmyth/settings.h" #include "libmyth/langsettings.h" #include "libmyth/mythdbcon.h" #include #include "libmythtv/tv.h" #include "mythdialogbox.h" #include #include #include #include "libmyth/dialogbox.h" #include #include #include "installdialog.h" 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) { QString becommand; QApplication a(argc, argv); bool bShow=false; gContext = NULL; gContext = new MythContext(MYTH_BINARY_VERSION); if (!gContext->Init()) { VERBOSE(VB_IMPORTANT, "mythwelcome: Could not initialize myth context. " "Exiting."); return FRONTEND_EXIT_NO_MYTHCONTEXT; } if (!MSqlQuery::testDBConnection()) { VERBOSE(VB_IMPORTANT, "mythwelcome: Could not open the database. " "Exiting."); return -1; } if ( a.argc() == 1 ) { VERBOSE(VB_IMPORTANT, "Not enough argurments"); exit(1); } // Check command line arguments for (int argpos = 1; argpos < a.argc(); ++argpos) { // ++argpos; if (!strcmp(a.argv()[argpos],"-restart")) { becommand="restart"; } else if (!strcmp(a.argv()[argpos],"-start")) { becommand="start"; } else if (!strcmp(a.argv()[argpos],"-stop")) { becommand="stop"; } else if (!strcmp(a.argv()[argpos],"-forceshow")) { bShow=true; } else { cerr << "Invalid argument: " << a.argv()[argpos] << endl << "Valid options are: " << endl << "-restart " << endl << "-start " << endl << "-stop " << endl << "-forceshow" << endl; return FRONTEND_EXIT_INVALID_CMDLINE; } } gContext->LoadQtConfig(); QStringList msg; QString tempip; QString justifyip; QString temphname; QString justifyname; QString tempbetype; QString justifybetype; int listmaxpos = 0 ; typedef QValueVector BEvector; BEvector BElist (20); if (!MSqlQuery::testDBConnection()) { VERBOSE(VB_IMPORTANT, "mythwelcome: Could not open the database. " "Exiting."); } //select the master backend MSqlQuery query(MSqlQuery::InitCon()); query.prepare( "SELECT DISTINCT data,hostname from settings where value='MasterServerIP';"); if (query.exec() && query.isActive() && query.size() > 0) { while (query.next()) { tempip = query.value(0).toString(); justifyip=tempip.rightJustify(15,' ',false); temphname = query.value(1).toString(); justifyname= temphname.rightJustify( 20, ' ',false ); if ( temphname == "" ) tempbetype="MBE: "; else tempbetype="SBE: "; tempbetype.append(justifyname); tempbetype.append(" "); tempbetype.append(justifyip); justifybetype= tempbetype.leftJustify(50,' ' ,true); BElist[listmaxpos] = tempbetype; msg << (justifybetype); listmaxpos++; } } //slave backends query.prepare( "SELECT DISTINCT data,hostname from settings where value='BackendServerIP' and not data=:ip ;"); query.bindValue( ":ip", tempip ); if (query.exec() && query.isActive() && query.size() > 0) { while (query.next()) { tempip = query.value(0).toString(); justifyip=tempip.rightJustify(15,' ',false); temphname = query.value(1).toString(); justifyname= temphname.rightJustify( 20, ' ',false ); if ( temphname == "" ) tempbetype="MBE: "; else tempbetype="SBE: "; tempbetype.append(justifyname); tempbetype.append(" "); tempbetype.append(justifyip); justifybetype= tempbetype.leftJustify(50,' ' ,true); BElist[listmaxpos] = tempbetype; msg << (justifybetype); listmaxpos++; } } if ( query.size () >1) bShow=true; cout << listmaxpos << endl; if ( bShow ) { LanguageSettings::load("mythfrontend"); MythMainWindow *mainWindow = GetMythMainWindow(); mainWindow->Init(); gContext->SetMainWindow(mainWindow); initKeys(); runstuff(msg,BElist,becommand); delete gContext; } else { dorestart( becommand, BElist[0] ); } return 0; }