1 #include <QCoreApplication>
49 #define LOC QString("MythContext: ")
61 bool Init (
const bool gui,
62 const bool prompt,
const bool noPrompt,
64 bool FindDatabase(
const bool prompt,
const bool noPrompt);
66 void TempMainWindow(
bool languagePrompt =
true);
67 void EndTempWindow(
void);
69 bool LoadDatabaseSettings(
void);
72 bool PromptForDatabaseParams(
const QString &
error);
73 QString TestDBconnection(
void);
74 void SilenceDBerrors(
void);
75 void EnableDBerrors(
void);
76 void ResetDatabase(
void);
78 int ChooseBackend(
const QString &
error);
79 int UPnPautoconf(
const int milliSeconds = 2000);
80 bool DefaultUPnP(QString &
error);
81 bool UPnPconnect(
const DeviceLocation *device,
const QString &PIN);
86 void ShowConnectionFailurePopup(
bool persistent);
87 void HideConnectionFailurePopup(
void);
89 void ShowVersionMismatchPopup(
uint remoteVersion);
121 QStringList tokens = cmd.simplified().split(
" ");
125 int wantcardid = tokens[0].toInt(&cardidok, 10);
127 if (cardidok && wantcardid > 0)
129 strlist << QString(
"LOCK_TUNER %1").arg(wantcardid);
130 s = s.replace(0, tokens[0].length() + 1,
"");
133 strlist <<
"LOCK_TUNER";
136 int cardid = strlist[0].toInt();
140 s = s.sprintf(qPrintable(s),
141 qPrintable(strlist[1]),
142 qPrintable(strlist[2]),
143 qPrintable(strlist[3]));
147 strlist = QStringList(QString(
"FREE_TUNER %1").arg(cardid));
149 QString ret = strlist[0];
158 label = QObject::tr(
"Could not find specified tuner (%1).")
161 label = QObject::tr(
"Specified tuner (%1) is already in use.")
166 label = QObject::tr(
"All tuners are currently in use. If you want "
167 "to watch TV, you can cancel one of the "
168 "in-progress recordings from the delete menu");
171 LOG(VB_GENERAL, LOG_ALERT, QString(
"exec_program_tv: ") + label);
182 ShowOkPopup(QObject::tr(
"Failed to configure plugin %1").arg(cmd));
190 ShowOkPopup(QObject::tr(
"The plugin %1 has failed "
191 "to run for some reason...").arg(cmd));
203 disableeventpopup(
false),
206 MBEconnectPopup(NULL),
207 MBEversionPopup(NULL)
265 const bool promptForBackend,
281 if (!ignoreDB && !
FindDatabase(promptForBackend, noPrompt))
328 bool manualSelect = prompt && !noAutodetect;
339 bool autoSelect = !manualSelect && !loaded && !noAutodetect;
349 autoSelect = manualSelect =
false;
351 if (failure.length())
352 LOG(VB_GENERAL, LOG_ALERT, failure);
355 if (failure.isEmpty())
366 failure = QObject::tr(
"No UPnP backends found",
"Backend Setup");
371 if (failure.isEmpty())
376 manualSelect |= (count > 1 || count == -1);
379 manualSelect &=
m_gui;
394 manualSelect =
false;
408 if (!failure.isEmpty())
409 LOG(VB_GENERAL, LOG_ALERT, failure);
411 while (!failure.isEmpty());
414 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - Success!");
423 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - failed");
475 if (hostname.isEmpty() ||
476 hostname ==
"my-unique-identifier-goes-here")
478 char localhostname[1024];
479 if (gethostname(localhostname, 1024))
481 LOG(VB_GENERAL, LOG_ALERT,
482 "MCP: Error, could not determine host name." + ENO);
483 localhostname[0] =
'\0';
485 hostname = localhostname;
486 LOG(VB_GENERAL, LOG_NOTICE,
"Empty LocalHostName.");
493 LOG(VB_GENERAL, LOG_INFO, QString(
"Using localhost value of %1")
556 bool accepted =
false;
567 accepted = (settings.
exec() == QDialog::Accepted);
569 LOG(VB_GENERAL, LOG_ALERT,
570 "User cancelled database configuration");
580 cout << endl << error.toLocal8Bit().constData() << endl << endl;
581 response =
getResponse(
"Would you like to configure the database "
584 if (!response.startsWith(
'y', Qt::CaseInsensitive))
589 response =
getResponse(
"Should I test connectivity to this host "
590 "using the ping command?",
"yes");
591 params.
dbHostPing = response.startsWith(
'y', Qt::CaseInsensitive);
603 "(if empty, the local host name "
608 response =
getResponse(
"Would you like to use Wake-On-LAN to retry "
609 "database connections?",
611 params.
wolEnabled = response.startsWith(
'y', Qt::CaseInsensitive);
637 QString err = QString::null;
645 if ((host ==
"localhost") ||
646 (host ==
"127.0.0.1") ||
656 if (
ping(host, wakeupTime))
662 LOG(VB_GENERAL, LOG_INFO,
663 QString(
"Trying to wake up host %1, attempt %2")
664 .arg(host).arg(attempt));
667 LOG(VB_GENERAL, LOG_INFO,
668 QString(
"Waiting for %1 seconds").arg(wakeupTime));
674 LOG(VB_GENERAL, LOG_INFO,
675 QString(
"Testing network connectivity to '%1'").arg(host));
678 if (doPing && !
ping(host, 3))
682 "Cannot find (ping) database host %1 on the network",
684 return err.arg(host);
696 return QObject::tr(
"Cannot login to database",
"Backend Setup");
700 return QString::null;
765 if (!error.isEmpty())
767 LOG(VB_GENERAL, LOG_ERR, QString(
"Error: %1").arg(error));
771 LOG(VB_GENERAL, LOG_INFO,
"Putting up the UPnP backend chooser");
789 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search %1 secs")
790 .arg(milliSeconds / 1000));
798 while (totalTime.
elapsed() < milliSeconds)
801 int ttl = milliSeconds - totalTime.
elapsed();
802 if ((searchTime.
elapsed() > 249) && (ttl > 1000))
804 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search %1 secs")
815 LOG(VB_GENERAL, LOG_INFO,
"No UPnP backends found");
819 int count = backends->
Count();
822 LOG(VB_GENERAL, LOG_INFO,
823 QString(
"Found %1 UPnP backends").arg(count));
827 LOG(VB_GENERAL, LOG_ERR,
828 "No UPnP backends found, but SSDP::Find() not NULL");
844 int ret = (
UPnPconnect(BE, QString::null)) ? 1 : -1;
858 QString loc =
"DefaultUPnP() - ";
864 LOG(VB_UPNP, LOG_INFO, loc +
"No default UPnP backend");
868 LOG(VB_UPNP, LOG_INFO, loc +
"config.xml has default " +
869 QString(
"PIN '%1' and host USN: %2") .arg(PIN).arg(USN));
873 int timeout_ms = 2000;
874 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search up to %1 secs")
875 .arg(timeout_ms / 1000));
885 while (totalTime.
elapsed() < timeout_ms)
894 int ttl = timeout_ms - totalTime.
elapsed();
895 if ((searchTime.
elapsed() > 249) && (ttl > 1000))
897 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search up to %1 secs")
908 error =
"Cannot find default UPnP backend";
920 error =
"Cannot connect to default backend via UPnP. Wrong saved PIN?";
931 QString loc =
"UPnPconnect() - ";
935 LOG(VB_UPNP, LOG_INFO, loc + QString(
"Trying host at %1").arg(URL));
940 LOG(VB_UPNP, LOG_INFO, loc +
948 LOG(VB_UPNP, LOG_ERR, loc +
"Wrong PIN?");
952 LOG(VB_UPNP, LOG_ERR, loc + error);
959 URL.remove(
"http://");
960 URL.remove(QRegExp(
"[:/].*"));
964 LOG(VB_UPNP, LOG_INFO,
"Trying default DB credentials at " + URL);
980 else if (me->
Message() ==
"CONNECTION_FAILURE")
982 else if (me->
Message() ==
"PERSISTENT_CONNECTION_FAILURE")
984 else if (me->
Message() ==
"CONNECTION_RESTABLISHED")
997 QString message = (persistent) ?
999 "The connection to the master backend "
1000 "server has gone away for some reason. "
1003 "Could not connect to the master backend server. Is "
1004 "it running? Is the IP address set for it in "
1005 "mythtv-setup correct?");
1029 "The server uses network protocol version %1, "
1030 "but this client only understands version %2. "
1031 "Make sure you are running compatible versions of "
1032 "the backend and frontend.")
1033 .arg(remote_version).arg(MYTH_PROTO_VERSION);
1042 LOG(VB_GENERAL, LOG_ERR,
LOC + message);
1043 qApp->exit(GENERIC_EXIT_SOCKET_ERROR);
1055 qApp->exit(GENERIC_EXIT_SOCKET_ERROR);
1059 :
d(NULL), app_binary_version(binversion)
1062 static bool WSAStarted =
false;
1065 int res = WSAStartup(MAKEWORD(2, 0), &wsadata);
1066 LOG(VB_SOCKET, LOG_INFO,
1067 QString(
"WSAStartup returned %1").arg(res));
1077 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Unable to allocate MythCoreContext");
1078 qApp->exit(GENERIC_EXIT_NO_MYTHCONTEXT);
1083 const bool promptForBackend,
1084 const bool disableAutoDiscovery,
1085 const bool ignoreDB)
1089 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Init() Out-of-memory");
1095 LOG(VB_GENERAL, LOG_EMERG,
1096 QString(
"Application binary version (%1) does not "
1097 "match libraries (%2)")
1100 QString warning = QObject::tr(
1101 "This application is not compatible "
1102 "with the installed MythTV libraries.");
1108 LOG(VB_GENERAL, LOG_WARNING, warning);
1116 QString home = getenv(
"HOME");
1119 home = getenv(
"LOCALAPPDATA");
1121 home = getenv(
"APPDATA");
1123 home = QString(
".");
1125 _putenv(QString(
"HOME=%1").arg(home).toLocal8Bit().constData());
1131 QString homedir = QDir::homePath();
1132 QString
confdir = getenv(
"MYTHCONFDIR");
1133 if ((homedir.isEmpty() || homedir ==
"/") &&
1134 (confdir.isEmpty() || confdir.contains(
"$HOME")))
1136 QString warning =
"Cannot locate your home directory."
1137 " Please set the environment variable HOME";
1143 LOG(VB_GENERAL, LOG_WARNING, warning);
1148 if (!
d->
Init(gui, promptForBackend, disableAutoDiscovery, ignoreDB))
1161 LOG(VB_GENERAL, LOG_INFO,
"Waiting for threads to exit.");