12#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
13#include <QtEnvironmentVariables>
14#include <QtSystemDetection>
16#include <QCoreApplication>
26#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
27#include <QtAndroidExtras>
29#include <QJniEnvironment>
31#define QAndroidJniEnvironment QJniEnvironment
32#define QAndroidJniObject QJniObject
51#include "libmythbase/mythversion.h"
72#define LOC QString("MythContext: ")
82 : m_cachePath(std::move(cache_path))
84 m_cacheFilename = m_cachePath +
'/' + cache_filename;
85 if (m_cachePath.isEmpty() || cache_filename.isEmpty())
87 m_cacheFilename = m_cachePath = QString();
92 void loadOverrides()
const;
93 static void clearOverrides();
96 QString m_cacheFilename {
"cache/contextcache.xml"};
97 QString m_cachePath {
"cache"};
113 bool promptForBackend,
114 bool disableAutoDiscovery,
135 static int UPnPautoconf(std::chrono::milliseconds milliSeconds = 2s);
139 bool checkPort(
const QString &host,
int port, std::chrono::seconds timeLimit)
const;
142 bool event(QEvent* )
override;
185 QStringList tokens = cmd.simplified().split(
" ");
188 bool cardidok =
false;
189 int wantcardid = tokens[0].toInt(&cardidok, 10);
191 if (cardidok && wantcardid > 0)
193 strlist << QString(
"LOCK_TUNER %1").arg(wantcardid);
194 s = s.replace(0, tokens[0].length() + 1,
"");
198 strlist <<
"LOCK_TUNER";
202 int cardid = strlist[0].toInt();
206 s = s.arg(qPrintable(strlist[1]),
207 qPrintable(strlist[2]),
208 qPrintable(strlist[3]));
212 strlist = QStringList(QString(
"FREE_TUNER %1").arg(cardid));
223 label = QObject::tr(
"Could not find specified tuner (%1).")
228 label = QObject::tr(
"Specified tuner (%1) is already in use.")
234 label = QObject::tr(
"All tuners are currently in use. If you want "
235 "to watch TV, you can cancel one of the "
236 "in-progress recordings from the delete menu");
239 LOG(VB_GENERAL, LOG_ALERT, QString(
"exec_program_tv: ") + label);
254 QObject::tr(
"Failed to configure plugin"));
268 QObject::tr(
"%1 failed to run for some reason").arg(cmd));
278 : m_loop(new QEventLoop(this))
326 if (m_guiStartup && !m_guiStartup->m_Exit)
331 mainStack->
PopScreen(m_guiStartup,
false);
332 m_guiStartup =
nullptr;
359 return checker.
checkPort(host, port, timeLimit);
364 const bool promptForBackend,
365 const bool disableAutoDiscovery,
372 m_GUISettingsCache.loadOverrides();
376 m_needsBackend =
true;
384 if (!ignoreDB && !FindDatabase(promptForBackend, disableAutoDiscovery))
407 mainStack->
PopScreen(m_guiStartup,
false);
408 m_guiStartup=
nullptr;
443 if (DefaultUPnP(failure))
444 autoSelect = manualSelect =
false;
446 if (!failure.isEmpty())
447 LOG(VB_GENERAL, LOG_ALERT, failure);
449 failure = TestDBconnection(loaded);
450 if (failure.isEmpty())
452 if (m_guiStartup && m_guiStartup->m_Exit)
454 if (m_guiStartup && m_guiStartup->m_Search)
461 int count = UPnPautoconf();
464 failure = QObject::tr(
"No UPnP backends found",
"Backend Setup");
468 failure = TestDBconnection();
469 if (failure.isEmpty())
471 if (m_guiStartup && m_guiStartup->m_Exit)
476 manualSelect |= (count > 1 || count == -1);
478 if (m_guiStartup && m_guiStartup->m_Search)
482 manualSelect &= m_gui;
485 bool haveDbInfo {
false};
491 switch (ChooseBackend(failure))
496 manualSelect =
false;
500 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - failed");
512 || !PromptForDatabaseParams(failure))
514 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - failed");
518 failure = TestDBconnection();
519 haveDbInfo = failure.isEmpty();
520 if (!failure.isEmpty())
521 LOG(VB_GENERAL, LOG_ALERT, failure);
522 if (m_guiStartup && m_guiStartup->m_Exit)
524 if (m_guiStartup && m_guiStartup->m_Search)
526 if (m_guiStartup && m_guiStartup->m_Setup)
548 bool manualSelect = prompt && !noAutodetect;
551 bool loaded = LoadDatabaseSettings();
558 bool autoSelect = !manualSelect && !loaded && !noAutodetect;
560 if (!FindDatabaseChoose(loaded, manualSelect, autoSelect))
563 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - Success!");
572 GetMythDB()->SaveDatabaseParams(dbParams, !loaded || dbParamsFromFile != dbParams);
574 ResetDatabase(dbParams);
609 GetMythDB()->SetDatabaseParams(dbParams);
616 hostname ==
"my-unique-identifier-goes-here")
618 LOG(VB_GENERAL, LOG_INFO,
"Empty LocalHostName. This is typical.");
619 hostname = QHostInfo::localHostName();
624 LOG(VB_GENERAL, LOG_ALERT,
625 "MCP: Error, could not determine host name." +
ENO);
628#define ANDROID_EXCEPTION_CHECK \
629 if (env->ExceptionCheck()) \
631 env->ExceptionClear(); \
638 bool exception=
false;
641#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
644 QJniObject activity = QNativeInterface::QAndroidApplication::context();
648 (
"getApplicationContext",
"()Landroid/content/Context;");
651 (
"getContentResolver",
"()Landroid/content/ContentResolver;");
654 (
"android/provider/Settings$Secure",
"getString",
655 "(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;",
656 contentR.object<jobject>(),
657 myID.object<jstring>());
660 LOG(VB_GENERAL, LOG_ALERT,
661 "Java exception looking for android id");
663 hostname = QString(
"android-%1").arg(androidId.toString());
669 LOG(VB_GENERAL, LOG_INFO, QString(
"Using a profile name of: '%1' (Usually the "
670 "same as this host's name.)")
680 if (m_loop && m_loop->isRunning())
693 bool accepted =
false;
700 if (!
error.isEmpty())
715 if (!m_loop->isRunning())
730 std::this_thread::sleep_for(1s);
732 std::cout <<
'\n' <<
error.toLocal8Bit().constData() <<
"\n\n";
733 response =
getResponse(
"Would you like to configure the database "
736 if (!response.startsWith(
'y', Qt::CaseInsensitive))
741 response =
getResponse(
"Should I test connectivity to this host "
742 "using the ping command?",
"yes");
743 params.
m_dbHostPing = response.startsWith(
'y', Qt::CaseInsensitive);
755 "(if empty, the local host name "
760 response =
getResponse(
"Would you like to use Wake-On-LAN to retry "
761 "database connections?",
763 params.
m_wolEnabled = response.startsWith(
'y', Qt::CaseInsensitive);
768 std::chrono::seconds(
intResponse(
"Seconds to wait for "
777 accepted =
GetMythDB()->SaveDatabaseParams(params,
false);
801 enum startupStates : std::uint8_t {
809 } startupState = st_start;
811 static const std::array<const QString, 7> kGuiStatuses
812 {
"start",
"dbAwake",
"dbStarted",
"dbConnects",
"beWOL",
"beAwake",
"success"};
815 auto msStartupScreenDelay = std::chrono::duration_cast<std::chrono::milliseconds>(secondsStartupScreenDelay);
817 bool keep_trying =
true;
819 while ((startupState < st_success) && keep_trying)
823 if (dbParams.
m_dbHostName.isNull() && !m_dbHostCp.isEmpty())
830 std::chrono::seconds wakeupTime = 3s;
836 startupState = st_start;
840 startupState = st_dbAwake;
842 attempts = std::max(attempts, 6);
848 std::chrono::seconds progressTotal = wakeupTime * attempts;
850 if (m_guiStartup && !m_guiStartup->m_Exit)
851 m_guiStartup->setTotal(progressTotal);
853 QString beWOLCmd = QString();
854 QString backendIP = QString();
856 QString masterserver;
858 for (
int attempt = 0;
859 attempt < attempts && startupState != st_success;
866 LOG(VB_GENERAL, LOG_INFO,
867 QString(
"Start up testing connections. DB %1, BE %2, attempt %3, status %4, Delay: %5")
868 .arg(host, backendIP, QString::number(attempt),
869 kGuiStatuses[startupState],
870 QString::number(msStartupScreenDelay.count())) );
872 std::chrono::seconds useTimeout = wakeupTime;
876 if (m_gui && !m_guiStartup)
878 if (msStartupScreenDelay==0ms || timer.hasExpired(msStartupScreenDelay.count()))
882 m_guiStartup->setTotal(progressTotal);
885 if (m_guiStartup && !m_guiStartup->m_Exit)
888 m_guiStartup->setStatusState(kGuiStatuses[startupState]);
889 m_guiStartup->setMessageState(
"empty");
892 switch (startupState)
899 if (!checkPort(host, port, useTimeout))
902 startupState = st_dbAwake;
905 if (!checkPort(host, port, useTimeout))
907 startupState = st_dbStarted;
916 GetMythDB()->SetDatabaseParams(dbParams);
919 ResetDatabase(dbParams);
922 for (std::chrono::seconds temp = 0s; temp < useTimeout * 2 ; temp++)
925 std::this_thread::sleep_for(500ms);
929 startupState = st_dbConnects;
935 if (!beWOLCmd.isEmpty())
938 (
"WOLbackendReconnectWaitTime", 0s);
940 (
"WOLbackendConnectRetry", 0);
941 useTimeout = wakeupTime;
942 if (m_gui && !m_guiStartup && attempt == 0)
944 progressTotal = wakeupTime * attempts;
945 if (m_guiStartup && !m_guiStartup->m_Exit)
946 m_guiStartup->setTotal(progressTotal);
947 startupState = st_beWOL;
952 startupState = st_success;
956 (
"MasterServerName");
958 (
"BackendServerAddr", masterserver);
962 if (!beWOLCmd.isEmpty())
966 if (!checkPort(backendIP, backendPort, useTimeout))
969 startupState = st_beAwake;
972 if (!checkPort(backendIP, backendPort, useTimeout))
974 startupState = st_success;
982 if (m_guiStartup->m_Exit)
987 if (m_guiStartup->m_Setup
988 || m_guiStartup->m_Search
989 || m_guiStartup->m_Retry)
994 if (startupState == st_success)
997 QString stateMsg = kGuiStatuses[startupState];
998 stateMsg.append(
"Fail");
999 LOG(VB_GENERAL, LOG_INFO,
1000 QString(
"Start up failure. host %1, status %2")
1001 .arg(host, stateMsg));
1004 keep_trying =
false;
1005 if (m_gui && !m_guiStartup)
1009 m_guiStartup->setTotal(progressTotal);
1013 && !m_guiStartup->m_Exit
1014 && !m_guiStartup->m_Setup
1015 && !m_guiStartup->m_Search
1016 && !m_guiStartup->m_Retry)
1018 m_guiStartup->updateProgress(
true);
1019 m_guiStartup->setStatusState(stateMsg);
1020 m_guiStartup->setMessageState(
"makeselection");
1022 if (!m_guiStartup->m_Retry)
1023 keep_trying =
false;
1027 if (startupState < st_dbAwake)
1029 LOG(VB_GENERAL, LOG_WARNING, QString(
"Pinging to %1 failed, database will be unavailable").arg(host));
1032 "Cannot find (ping) database host %1 on the network",
1034 return err.arg(host);
1037 if (startupState < st_dbConnects)
1040 return QObject::tr(
"Cannot login to database",
"Backend Setup");
1043 if (startupState < st_success)
1045 return QObject::tr(
"Cannot connect to backend",
"Backend Setup");
1050 ResetDatabase(dbParams);
1069 m_guiStartup =
new GUIStartup(mainStack, m_loop);
1070 if (!m_guiStartup->Create())
1072 delete m_guiStartup;
1073 m_guiStartup =
nullptr;
1077 mainStack->
AddScreen(m_guiStartup,
false);
1105 GetMythDB()->SetDatabaseParams(dbParams);
1113 if (dbParams.
m_dbHostName.isNull() && !m_dbHostCp.isEmpty())
1116 GetMythDB()->SetDatabaseParams(dbParams);
1137 db->GetDBManager()->CloseDatabases();
1138 db->SetDatabaseParams(dbParams);
1139 db->ClearSettingsCache();
1151 if (!
error.isEmpty())
1153 LOG(VB_GENERAL, LOG_ERR, QString(
"Error: %1").arg(
error));
1157 LOG(VB_GENERAL, LOG_INFO,
"Putting up the UPnP backend chooser");
1162 GetMythDB()->SetDatabaseParams(dbParams);
1177 auto seconds = duration_cast<std::chrono::seconds>(milliSeconds);
1178 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search %1 secs")
1179 .arg(seconds.count()));
1187 while (totalTime.
elapsed() < milliSeconds)
1189 std::this_thread::sleep_for(25ms);
1190 auto ttl = milliSeconds - totalTime.
elapsed();
1191 if ((searchTime.
elapsed() > 249ms) && (ttl > 1s))
1193 auto ttlSeconds = duration_cast<std::chrono::seconds>(ttl);
1194 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search %1 secs")
1195 .arg(ttlSeconds.count()));
1201 std::this_thread::sleep_for(25ms);
1208 LOG(VB_GENERAL, LOG_INFO,
"No UPnP backends found");
1212 int count = backends->
Count();
1215 LOG(VB_GENERAL, LOG_INFO,
1216 QString(
"Found %1 UPnP backends").arg(count));
1220 LOG(VB_GENERAL, LOG_ERR,
1221 "No UPnP backends found, but SSDPCache::Instance()->Find() not NULL");
1237 int ret = (UPnPconnect(BE, QString())) ? 1 : -1;
1251 static const QString loc =
"DefaultUPnP() - ";
1264 LOG(VB_UPNP, LOG_INFO, loc +
"No default UPnP backend");
1268 LOG(VB_UPNP, LOG_INFO,
1270 QString(
" has default PIN '%1' and host USN: %2").arg(pin, usn));
1274 std::chrono::milliseconds timeout_ms {2s};
1275 auto timeout_s = duration_cast<std::chrono::seconds>(timeout_ms);
1276 LOG(VB_GENERAL, LOG_INFO, loc + QString(
"UPNP Search up to %1 secs")
1277 .arg(timeout_s.count()));
1289 while (totalTime.
elapsed() < timeout_ms)
1295 std::this_thread::sleep_for(25ms);
1297 auto ttl = timeout_ms - totalTime.
elapsed();
1298 if ((searchTime.
elapsed() > 249ms) && (ttl > 1s))
1300 auto ttlSeconds = duration_cast<std::chrono::seconds>(ttl);
1301 LOG(VB_GENERAL, LOG_INFO, loc + QString(
"UPNP Search up to %1 secs")
1302 .arg(ttlSeconds.count()));
1310 if (!devicelocation)
1312 Error =
"Cannot find default UPnP backend";
1316 if (UPnPconnect(devicelocation, pin))
1323 Error =
"Cannot connect to default backend via UPnP. Wrong saved PIN?";
1334 QString loc =
"UPnPconnect() - ";
1340 LOG(VB_UPNP, LOG_INFO, loc + QString(
"Trying host at %1").arg(URL));
1344 GetMythDB()->SetDatabaseParams(dbParams);
1345 LOG(VB_UPNP, LOG_INFO, loc +
1353 LOG(VB_UPNP, LOG_ERR, loc +
"Wrong PIN?");
1357 LOG(VB_UPNP, LOG_ERR, loc +
error);
1364 URL = theURL.host();
1368 LOG(VB_UPNP, LOG_INFO,
"Trying default DB credentials at " + URL);
1370 GetMythDB()->SetDatabaseParams(dbParams);
1379 if (m_disableeventpopup)
1391 if (me->Message() ==
"VERSION_MISMATCH" && (1 == me->ExtraDataCount()))
1392 ShowVersionMismatchPopup(me->ExtraData(0).toUInt());
1393 else if (me->Message() ==
"CONNECTION_FAILURE")
1394 ShowConnectionFailurePopup(
false);
1395 else if (me->Message() ==
"PERSISTENT_CONNECTION_FAILURE")
1396 ShowConnectionFailurePopup(
true);
1397 else if (me->Message() ==
"CONNECTION_RESTABLISHED")
1398 HideConnectionFailurePopup();
1402 return QObject::event(e);
1412 if (m_lastCheck.isValid() && now < m_lastCheck)
1420 m_lastCheck = now.addMSecs(5000);
1422 QString description = persistent ?
1424 "The connection to the master backend "
1425 "server has gone away for some reason. "
1428 "Could not connect to the master backend server. Is "
1429 "it running? Is the IP address set for it in "
1430 "mythtv-setup correct?");
1432 QString message = QObject::tr(
"Could not connect to master backend");
1434 n.
SetId(m_registration);
1444 if (!m_lastCheck.isValid())
1448 n.
SetId(m_registration);
1452 m_lastCheck = QDateTime();
1457 if (m_mbeVersionPopup)
1462 "The server uses network protocol version %1, "
1463 "but this client only understands version %2. "
1464 "Make sure you are running compatible versions of "
1465 "the backend and frontend.")
1466 .arg(remote_version).arg(MYTH_PROTO_VERSION);
1475 LOG(VB_GENERAL, LOG_ERR,
LOC + message);
1487 qApp->processEvents(QEventLoop::AllEvents, 250);
1488 qApp->processEvents(QEventLoop::AllEvents, 250);
1497const std::array<QString, 13> GUISettingsCache::kSettings
1498{
"Theme",
"Language",
"Country",
"GuiHeight",
1499 "GuiOffsetX",
"GuiOffsetY",
"GuiWidth",
"RunFrontendInWindow",
1500 "AlwaysOnTop",
"HideMouseCursor",
"ThemePainter",
"libCECEnabled",
1501 "StartupScreenDelay" };
1504bool GUISettingsCache::save()
1506 QString cacheDirName =
GetConfDir() +
'/' + m_cachePath;
1507 QDir dir(cacheDirName);
1508 dir.mkpath(cacheDirName);
1511 for (
const auto & setting : kSettings)
1513 QString cacheValue = config.
GetValue(
"Settings/" + setting, QString());
1516 if (value != cacheValue)
1518 config.
SetValue(
"Settings/" + setting, value);
1529 return config.
Save();
1534void GUISettingsCache::loadOverrides()
const
1537 for (
const auto & setting : kSettings)
1541 QString value = config.GetValue(
"Settings/" + setting, QString());
1542 if (!value.isEmpty())
1551void GUISettingsCache::clearOverrides()
1554 for (
const auto & setting : kSettings)
1567 m_mbeVersionPopup =
nullptr;
1576 static bool WSAStarted =
false;
1580 int res = WSAStartup(MAKEWORD(2, 0), &wsadata);
1581 LOG(VB_SOCKET, LOG_INFO,
1582 QString(
"WSAStartup returned %1").arg(res));
1593 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Unable to allocate MythCoreContext");
1599 const bool promptForBackend,
1600 const bool disableAutoDiscovery,
1601 const bool ignoreDB)
1605 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Init() Out-of-memory");
1609 qRegisterMetaType<std::chrono::seconds>(
"std::chrono::seconds");
1610 qRegisterMetaType<std::chrono::milliseconds>(
"std::chrono::milliseconds");
1611 qRegisterMetaType<std::chrono::microseconds>(
"std::chrono::microseconds");
1618 QString warning = QObject::tr(
"mythtv-setup is deprecated.\n"
1619 "To set up MythTV, start mythbackend and use:\n"
1620 "http://localhost:6544/setupwizard");
1626 LOG(VB_GENERAL, LOG_EMERG,
1627 QString(
"Application binary version (%1) does not "
1628 "match libraries (%2)")
1631 QString warning = QObject::tr(
1632 "This application is not compatible "
1633 "with the installed MythTV libraries.");
1639 LOG(VB_GENERAL, LOG_WARNING, warning);
1647 QString home = qEnvironmentVariable(
"HOME");
1650 home = qEnvironmentVariable(
"LOCALAPPDATA");
1652 home = qEnvironmentVariable(
"APPDATA");
1654 home = QString(
".");
1656 qputenv(
"HOME", home.toLocal8Bit().constData());
1662 QString homedir = QDir::homePath();
1663 QString
confdir = qEnvironmentVariable(
"MYTHCONFDIR");
1664 if ((homedir.isEmpty() || homedir ==
"/") &&
1667 QString warning =
"Cannot locate your home directory."
1668 " Please set the environment variable HOME";
1674 LOG(VB_GENERAL, LOG_WARNING, warning);
1679 if (!
m_impl->
Init(gui, promptForBackend, disableAutoDiscovery, ignoreDB))
1712 LOG(VB_GENERAL, LOG_INFO,
"Waiting for threads to exit.");
1718 LOG(VB_GENERAL, LOG_INFO,
"Exiting");
1749#include "mythcontext.moc"
#define QAndroidJniEnvironment
#define ANDROID_EXCEPTION_CHECK
#define QAndroidJniObject
static Decision Prompt(DatabaseParams *dbParams, const QString &config_filename)
Structure containing the basic Database parameters.
QString m_dbName
database name
QString m_dbPassword
DB password.
std::chrono::seconds m_wolReconnect
seconds to wait for reconnect
QString m_localHostName
name used for loading/saving settings
bool m_localEnabled
true if localHostName is not default
bool IsValid(const QString &source=QString("Unknown")) const
bool m_dbHostPing
No longer used.
QString m_dbUserName
DB user name.
QString m_wolCommand
command to use for wake-on-lan
bool m_wolEnabled
true if wake-on-lan params are used
int m_dbPort
database port
int m_wolRetry
times to retry to reconnect
QString m_dbHostName
database server
void cancelPortCheck(void)
static bool prompt(bool force=false)
Ask the user for the language to use.
static bool testDBConnection()
Checks DB connection + login (login info via Mythcontext)
static MThreadPool * globalInstance(void)
Dialog asking for user confirmation.
bool event(QEvent *) override
static bool LoadDatabaseSettings()
Load database and host settings from XmlConfiguration::k_default_filename, or set some defaults.
QString m_dbHostCp
dbHostName backup
void OnCloseDialog() const
static void processEvents()
bool checkPort(const QString &host, int port, std::chrono::seconds timeLimit) const
Check if a port is open.
bool m_gui
Should this context use GUI elements?
static void LanguagePrompt()
void ShowVersionMismatchPopup(unsigned remote_version)
QString TestDBconnection(bool prompt=true)
Some quick sanity checks before opening a database connection.
bool PromptForDatabaseParams(const QString &error)
static bool DefaultUPnP(QString &Error)
Get the default backend from XmlConfiguration::kDefaultFilename, use UPnP to find it.
BackendSelection::Decision ChooseBackend(const QString &error)
Search for backends via UPnP, put up a UI for the user to choose one.
bool FindDatabase(bool prompt, bool noAutodetect)
Get database connection settings and test connectivity.
bool Init(bool gui, bool promptForBackend, bool disableAutoDiscovery, bool ignoreDB)
static QString setLocalHostName(QString hostname)
static bool UPnPconnect(const DeviceLocation *backend, const QString &PIN)
Query a backend via UPnP for its database connection parameters.
void EnableDBerrors() const
bool FindDatabaseChoose(bool loaded, bool manualSelect, bool autoSelect)
Helper function for getting database connection settings and test connectivity.
static void ResetDatabase(const DatabaseParams &dbParams)
Called when the user changes the DB connection settings.
void VersionMismatchPopupClosed()
static int UPnPautoconf(std::chrono::milliseconds milliSeconds=2s)
If there is only a single UPnP backend, use it.
GUIStartup * m_guiStartup
void TempMainWindow()
Setup a minimal themed main window, and prompt for user's language.
MythConfirmationDialog * m_mbeVersionPopup
GUISettingsCache m_GUISettingsCache
void ShowConnectionFailurePopup(bool persistent)
void HideConnectionFailurePopup()
void SilenceDBerrors()
Cause MSqlDatabase::OpenDatabase() and MSqlQuery to fail silently.
QString m_masterhostname
master backend hostname
Startup context for MythTV.
CleanupFunction m_cleanup
This is used to destroy global state before main() returns.
QString m_appBinaryVersion
MythContext(QString binversion, bool needsBackend=false)
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
void SetDisableEventPopup(bool check)
Impl * m_impl
PIMPL idiom.
This class contains the runtime context for MythTV.
bool IsFrontend(void) const
is this process a frontend process
void ActivateSettingsCache(bool activate=true)
void ClearOverrideSettingForSession(const QString &key)
void SetLocalHostname(const QString &hostname)
QString GetSetting(const QString &key, const QString &defaultval="")
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
MythPluginManager * GetPluginManager(void)
void OverrideSettingForSession(const QString &key, const QString &value)
QString GetSettingOnHost(const QString &key, const QString &host, const QString &defaultval="")
T GetDurSetting(const QString &key, T defaultval=T::zero())
bool IsBackend(void) const
is this process a backend process
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
bool IsWOLAllowed() const
void SaveLocaleDefaults(void)
int GetNumSetting(const QString &key, int defaultval=0)
void InitPower(bool Create=true)
This class is used as a container for messages.
static const Type kMythEventMessage
MythScreenStack * GetMainStack()
static MythMainWindow * getMainWindow(bool UseDB=true)
Return the existing main window, or create one.
void Init(bool MayReInit=true)
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
bool Queue(const MythNotification ¬ification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
void SetId(int Id)
Contains the application registration id.
void SetParent(void *Parent)
Contains the parent address. Required if id is set Id provided must match the parent address as provi...
void SetDuration(std::chrono::seconds Duration)
Contains a duration during which the notification will be displayed for. The duration is informative ...
bool config_plugin(const QString &plugname)
bool run_plugin(const QString &plugname)
virtual void PopScreen(MythScreenType *screen=nullptr, bool allowFade=true, bool deleteScreen=true)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
A QElapsedTimer based timer to replace use of QTime as a timer.
std::chrono::milliseconds elapsed(void)
Returns milliseconds elapsed since last start() or restart()
void start(void)
starts measuring elapsed time.
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
void Init(MythUIMenuCallbacks &cbs)
UPnPResultCode GetConnectionInfo(const QString &sPin, DatabaseParams *pParams, QString &sMsg)
Small class to handle TCP port checking and finding link-local context.
bool resolveLinkLocal(QString &host, int port, std::chrono::milliseconds timeLimit=30s)
Convenience method to resolve link-local address.
void cancelPortCheck(void)
Cancel the checkPort operation currently in progress.
bool checkPort(const QString &host, int port, std::chrono::milliseconds timeLimit=30s)
Check if a port is open.
static void PrintDebug(void)
Print out any leaks if that level of debugging is enabled.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
DeviceLocation * GetFirst(void)
Returns random entry in cache, returns nullptr when list is empty.
static SSDPCache * Instance()
SSDPCacheEntries * Find(const QString &sURI)
Finds the SSDPCacheEntries in the cache, returns nullptr when absent.
static const QString kBackendURI
void PerformSearch(const QString &sST, std::chrono::seconds timeout=2s)
Send a SSDP discover multicast datagram.
static void Init(QObject *parent=nullptr)
static const QString kDefaultUSN
static const QString kDefaultWOL
static const QString kDefaultDB
QString GetValue(const QString &setting)
static constexpr auto kDefaultFilename
void SetValue(const QString &setting, bool value)
static const QString kDefaultPIN
GUISettingsCache()=default
GUISettingsCache(const QString &cache_filename, QString cache_path)
static const std::array< QString, 13 > kSettings
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
@ GENERIC_EXIT_SOCKET_ERROR
Socket error.
void logStop(void)
Entry point for stopping logging for an application.
static constexpr const char * MYTH_APPNAME_MYTHTV_SETUP
static void plugin_cb(const QString &cmd)
static void exec_program_cb(const QString &cmd)
static void exec_program_tv_cb(const QString &cmd)
static void configplugin_cb(const QString &cmd)
static const QString sLocation
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
bool WaitFor(MythConfirmationDialog *dialog)
Blocks until confirmation dialog exits.
void InitializeMythDirs(void)
#define ENO
This can be appended to the LOG args with "+".
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythNotificationCenter * GetNotificationCenter(void)
bool HasMythMainWindow(void)
MythMainWindow * GetMythMainWindow(void)
void DestroyMythMainWindow(void)
bool MythWakeup(const QString &wakeUpCommand, uint flags, std::chrono::seconds timeout)
int intResponse(const QString &query, int def)
In an interactive shell, prompt the user to input a number.
QString getResponse(const QString &query, const QString &def)
In an interactive shell, prompt the user to input a string.
void ShowNotificationError(const QString &msg, const QString &from, const QString &detail, const VNMask visibility, const MythNotification::Priority priority)
convenience utility to display error message as notification
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
MythUIHelper * GetMythUI()
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
@ UPnPResult_ActionNotAuthorized