12#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
13#include <QtSystemDetection>
15#include <QCoreApplication>
25#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
26#include <QtAndroidExtras>
28#include <QJniEnvironment>
30#define QAndroidJniEnvironment QJniEnvironment
31#define QAndroidJniObject QJniObject
54#include "libmythbase/mythversion.h"
75#define LOC QString("MythContext: ")
85 : m_cachePath(std::move(cache_path))
87 m_cacheFilename = m_cachePath +
'/' + cache_filename;
88 if (m_cachePath.isEmpty() || cache_filename.isEmpty())
90 m_cacheFilename = m_cachePath = QString();
95 void loadOverrides()
const;
96 static void clearOverrides();
99 QString m_cacheFilename {
"cache/contextcache.xml"};
100 QString m_cachePath {
"cache"};
116 bool promptForBackend,
117 bool disableAutoDiscovery,
138 static int UPnPautoconf(std::chrono::milliseconds milliSeconds = 2s);
142 bool checkPort(
const QString &host,
int port, std::chrono::seconds timeLimit)
const;
145 bool event(QEvent* )
override;
188 QStringList tokens = cmd.simplified().split(
" ");
191 bool cardidok =
false;
192 int wantcardid = tokens[0].toInt(&cardidok, 10);
194 if (cardidok && wantcardid > 0)
196 strlist << QString(
"LOCK_TUNER %1").arg(wantcardid);
197 s = s.replace(0, tokens[0].length() + 1,
"");
201 strlist <<
"LOCK_TUNER";
205 int cardid = strlist[0].toInt();
209 s = s.arg(qPrintable(strlist[1]),
210 qPrintable(strlist[2]),
211 qPrintable(strlist[3]));
215 strlist = QStringList(QString(
"FREE_TUNER %1").arg(cardid));
226 label = QObject::tr(
"Could not find specified tuner (%1).")
231 label = QObject::tr(
"Specified tuner (%1) is already in use.")
237 label = QObject::tr(
"All tuners are currently in use. If you want "
238 "to watch TV, you can cancel one of the "
239 "in-progress recordings from the delete menu");
242 LOG(VB_GENERAL, LOG_ALERT, QString(
"exec_program_tv: ") + label);
257 QObject::tr(
"Failed to configure plugin"));
271 QObject::tr(
"%1 failed to run for some reason").arg(cmd));
281 : m_loop(new QEventLoop(this))
329 if (m_guiStartup && !m_guiStartup->m_Exit)
334 mainStack->
PopScreen(m_guiStartup,
false);
335 m_guiStartup =
nullptr;
362 return checker.
checkPort(host, port, timeLimit);
367 const bool promptForBackend,
368 const bool disableAutoDiscovery,
375 m_GUISettingsCache.loadOverrides();
379 m_needsBackend =
true;
387 if (!ignoreDB && !FindDatabase(promptForBackend, disableAutoDiscovery))
410 mainStack->
PopScreen(m_guiStartup,
false);
411 m_guiStartup=
nullptr;
446 if (DefaultUPnP(failure))
447 autoSelect = manualSelect =
false;
449 if (!failure.isEmpty())
450 LOG(VB_GENERAL, LOG_ALERT, failure);
452 failure = TestDBconnection(loaded);
453 if (failure.isEmpty())
455 if (m_guiStartup && m_guiStartup->m_Exit)
457 if (m_guiStartup && m_guiStartup->m_Search)
464 int count = UPnPautoconf();
467 failure = QObject::tr(
"No UPnP backends found",
"Backend Setup");
471 failure = TestDBconnection();
472 if (failure.isEmpty())
474 if (m_guiStartup && m_guiStartup->m_Exit)
479 manualSelect |= (count > 1 || count == -1);
481 if (m_guiStartup && m_guiStartup->m_Search)
485 manualSelect &= m_gui;
488 bool haveDbInfo {
false};
494 switch (ChooseBackend(failure))
499 manualSelect =
false;
503 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - failed");
515 || !PromptForDatabaseParams(failure))
517 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - failed");
521 failure = TestDBconnection();
522 haveDbInfo = failure.isEmpty();
523 if (!failure.isEmpty())
524 LOG(VB_GENERAL, LOG_ALERT, failure);
525 if (m_guiStartup && m_guiStartup->m_Exit)
527 if (m_guiStartup && m_guiStartup->m_Search)
529 if (m_guiStartup && m_guiStartup->m_Setup)
551 bool manualSelect = prompt && !noAutodetect;
554 bool loaded = LoadDatabaseSettings();
561 bool autoSelect = !manualSelect && !loaded && !noAutodetect;
563 if (!FindDatabaseChoose(loaded, manualSelect, autoSelect))
566 LOG(VB_GENERAL, LOG_DEBUG,
"FindDatabase() - Success!");
575 GetMythDB()->SaveDatabaseParams(dbParams, !loaded || dbParamsFromFile != dbParams);
577 ResetDatabase(dbParams);
612 GetMythDB()->SetDatabaseParams(dbParams);
619 hostname ==
"my-unique-identifier-goes-here")
621 LOG(VB_GENERAL, LOG_INFO,
"Empty LocalHostName. This is typical.");
622 hostname = QHostInfo::localHostName();
627 LOG(VB_GENERAL, LOG_ALERT,
628 "MCP: Error, could not determine host name." +
ENO);
631#define ANDROID_EXCEPTION_CHECK \
632 if (env->ExceptionCheck()) \
634 env->ExceptionClear(); \
641 bool exception=
false;
644#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
647 QJniObject activity = QNativeInterface::QAndroidApplication::context();
651 (
"getApplicationContext",
"()Landroid/content/Context;");
654 (
"getContentResolver",
"()Landroid/content/ContentResolver;");
657 (
"android/provider/Settings$Secure",
"getString",
658 "(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;",
659 contentR.object<jobject>(),
660 myID.object<jstring>());
663 LOG(VB_GENERAL, LOG_ALERT,
664 "Java exception looking for android id");
666 hostname = QString(
"android-%1").arg(androidId.toString());
672 LOG(VB_GENERAL, LOG_INFO, QString(
"Using a profile name of: '%1' (Usually the "
673 "same as this host's name.)")
683 if (m_loop && m_loop->isRunning())
696 bool accepted =
false;
703 if (!
error.isEmpty())
718 if (!m_loop->isRunning())
733 std::this_thread::sleep_for(1s);
735 std::cout <<
'\n' <<
error.toLocal8Bit().constData() <<
"\n\n";
736 response =
getResponse(
"Would you like to configure the database "
739 if (!response.startsWith(
'y', Qt::CaseInsensitive))
744 response =
getResponse(
"Should I test connectivity to this host "
745 "using the ping command?",
"yes");
746 params.
m_dbHostPing = response.startsWith(
'y', Qt::CaseInsensitive);
758 "(if empty, the local host name "
763 response =
getResponse(
"Would you like to use Wake-On-LAN to retry "
764 "database connections?",
766 params.
m_wolEnabled = response.startsWith(
'y', Qt::CaseInsensitive);
771 std::chrono::seconds(
intResponse(
"Seconds to wait for "
780 accepted =
GetMythDB()->SaveDatabaseParams(params,
false);
804 enum startupStates : std::uint8_t {
812 } startupState = st_start;
814 static const std::array<const QString, 7> kGuiStatuses
815 {
"start",
"dbAwake",
"dbStarted",
"dbConnects",
"beWOL",
"beAwake",
"success"};
818 auto msStartupScreenDelay = std::chrono::duration_cast<std::chrono::milliseconds>(secondsStartupScreenDelay);
820 bool keep_trying =
true;
822 while ((startupState < st_success) && keep_trying)
826 if (dbParams.
m_dbHostName.isNull() && !m_dbHostCp.isEmpty())
833 std::chrono::seconds wakeupTime = 3s;
839 startupState = st_start;
843 startupState = st_dbAwake;
845 attempts = std::max(attempts, 6);
851 std::chrono::seconds progressTotal = wakeupTime * attempts;
853 if (m_guiStartup && !m_guiStartup->m_Exit)
854 m_guiStartup->setTotal(progressTotal);
856 QString beWOLCmd = QString();
857 QString backendIP = QString();
859 QString masterserver;
861 for (
int attempt = 0;
862 attempt < attempts && startupState != st_success;
869 LOG(VB_GENERAL, LOG_INFO,
870 QString(
"Start up testing connections. DB %1, BE %2, attempt %3, status %4, Delay: %5")
871 .arg(host, backendIP, QString::number(attempt),
872 kGuiStatuses[startupState],
873 QString::number(msStartupScreenDelay.count())) );
875 std::chrono::seconds useTimeout = wakeupTime;
879 if (m_gui && !m_guiStartup)
881 if (msStartupScreenDelay==0ms || timer.hasExpired(msStartupScreenDelay.count()))
885 m_guiStartup->setTotal(progressTotal);
888 if (m_guiStartup && !m_guiStartup->m_Exit)
891 m_guiStartup->setStatusState(kGuiStatuses[startupState]);
892 m_guiStartup->setMessageState(
"empty");
895 switch (startupState)
902 if (!checkPort(host, port, useTimeout))
905 startupState = st_dbAwake;
908 if (!checkPort(host, port, useTimeout))
910 startupState = st_dbStarted;
919 GetMythDB()->SetDatabaseParams(dbParams);
922 ResetDatabase(dbParams);
925 for (std::chrono::seconds temp = 0s; temp < useTimeout * 2 ; temp++)
928 std::this_thread::sleep_for(500ms);
932 startupState = st_dbConnects;
938 if (!beWOLCmd.isEmpty())
941 (
"WOLbackendReconnectWaitTime", 0s);
943 (
"WOLbackendConnectRetry", 0);
944 useTimeout = wakeupTime;
945 if (m_gui && !m_guiStartup && attempt == 0)
947 progressTotal = wakeupTime * attempts;
948 if (m_guiStartup && !m_guiStartup->m_Exit)
949 m_guiStartup->setTotal(progressTotal);
950 startupState = st_beWOL;
955 startupState = st_success;
959 (
"MasterServerName");
961 (
"BackendServerAddr", masterserver);
965 if (!beWOLCmd.isEmpty())
969 if (!checkPort(backendIP, backendPort, useTimeout))
972 startupState = st_beAwake;
975 if (!checkPort(backendIP, backendPort, useTimeout))
977 startupState = st_success;
985 if (m_guiStartup->m_Exit)
990 if (m_guiStartup->m_Setup
991 || m_guiStartup->m_Search
992 || m_guiStartup->m_Retry)
997 if (startupState == st_success)
1000 QString stateMsg = kGuiStatuses[startupState];
1001 stateMsg.append(
"Fail");
1002 LOG(VB_GENERAL, LOG_INFO,
1003 QString(
"Start up failure. host %1, status %2")
1004 .arg(host, stateMsg));
1007 keep_trying =
false;
1008 if (m_gui && !m_guiStartup)
1012 m_guiStartup->setTotal(progressTotal);
1016 && !m_guiStartup->m_Exit
1017 && !m_guiStartup->m_Setup
1018 && !m_guiStartup->m_Search
1019 && !m_guiStartup->m_Retry)
1021 m_guiStartup->updateProgress(
true);
1022 m_guiStartup->setStatusState(stateMsg);
1023 m_guiStartup->setMessageState(
"makeselection");
1025 if (!m_guiStartup->m_Retry)
1026 keep_trying =
false;
1030 if (startupState < st_dbAwake)
1032 LOG(VB_GENERAL, LOG_WARNING, QString(
"Pinging to %1 failed, database will be unavailable").arg(host));
1035 "Cannot find (ping) database host %1 on the network",
1037 return err.arg(host);
1040 if (startupState < st_dbConnects)
1043 return QObject::tr(
"Cannot login to database",
"Backend Setup");
1046 if (startupState < st_success)
1048 return QObject::tr(
"Cannot connect to backend",
"Backend Setup");
1053 ResetDatabase(dbParams);
1072 m_guiStartup =
new GUIStartup(mainStack, m_loop);
1073 if (!m_guiStartup->Create())
1075 delete m_guiStartup;
1076 m_guiStartup =
nullptr;
1080 mainStack->
AddScreen(m_guiStartup,
false);
1108 GetMythDB()->SetDatabaseParams(dbParams);
1116 if (dbParams.
m_dbHostName.isNull() && !m_dbHostCp.isEmpty())
1119 GetMythDB()->SetDatabaseParams(dbParams);
1140 db->GetDBManager()->CloseDatabases();
1141 db->SetDatabaseParams(dbParams);
1142 db->ClearSettingsCache();
1154 if (!
error.isEmpty())
1156 LOG(VB_GENERAL, LOG_ERR, QString(
"Error: %1").arg(
error));
1160 LOG(VB_GENERAL, LOG_INFO,
"Putting up the UPnP backend chooser");
1165 GetMythDB()->SetDatabaseParams(dbParams);
1180 auto seconds = duration_cast<std::chrono::seconds>(milliSeconds);
1181 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search %1 secs")
1182 .arg(seconds.count()));
1190 while (totalTime.
elapsed() < milliSeconds)
1192 std::this_thread::sleep_for(25ms);
1193 auto ttl = milliSeconds - totalTime.
elapsed();
1194 if ((searchTime.
elapsed() > 249ms) && (ttl > 1s))
1196 auto ttlSeconds = duration_cast<std::chrono::seconds>(ttl);
1197 LOG(VB_GENERAL, LOG_INFO, QString(
"UPNP Search %1 secs")
1198 .arg(ttlSeconds.count()));
1204 std::this_thread::sleep_for(25ms);
1211 LOG(VB_GENERAL, LOG_INFO,
"No UPnP backends found");
1215 int count = backends->
Count();
1218 LOG(VB_GENERAL, LOG_INFO,
1219 QString(
"Found %1 UPnP backends").arg(count));
1223 LOG(VB_GENERAL, LOG_ERR,
1224 "No UPnP backends found, but SSDPCache::Instance()->Find() not NULL");
1240 int ret = (UPnPconnect(BE, QString())) ? 1 : -1;
1254 static const QString loc =
"DefaultUPnP() - ";
1267 LOG(VB_UPNP, LOG_INFO, loc +
"No default UPnP backend");
1271 LOG(VB_UPNP, LOG_INFO,
1273 QString(
" has default PIN '%1' and host USN: %2").arg(pin, usn));
1277 std::chrono::milliseconds timeout_ms {2s};
1278 auto timeout_s = duration_cast<std::chrono::seconds>(timeout_ms);
1279 LOG(VB_GENERAL, LOG_INFO, loc + QString(
"UPNP Search up to %1 secs")
1280 .arg(timeout_s.count()));
1292 while (totalTime.
elapsed() < timeout_ms)
1298 std::this_thread::sleep_for(25ms);
1300 auto ttl = timeout_ms - totalTime.
elapsed();
1301 if ((searchTime.
elapsed() > 249ms) && (ttl > 1s))
1303 auto ttlSeconds = duration_cast<std::chrono::seconds>(ttl);
1304 LOG(VB_GENERAL, LOG_INFO, loc + QString(
"UPNP Search up to %1 secs")
1305 .arg(ttlSeconds.count()));
1313 if (!devicelocation)
1315 Error =
"Cannot find default UPnP backend";
1319 if (UPnPconnect(devicelocation, pin))
1326 Error =
"Cannot connect to default backend via UPnP. Wrong saved PIN?";
1337 QString loc =
"UPnPconnect() - ";
1343 LOG(VB_UPNP, LOG_INFO, loc + QString(
"Trying host at %1").arg(URL));
1347 GetMythDB()->SetDatabaseParams(dbParams);
1348 LOG(VB_UPNP, LOG_INFO, loc +
1356 LOG(VB_UPNP, LOG_ERR, loc +
"Wrong PIN?");
1360 LOG(VB_UPNP, LOG_ERR, loc +
error);
1367 URL = theURL.host();
1371 LOG(VB_UPNP, LOG_INFO,
"Trying default DB credentials at " + URL);
1373 GetMythDB()->SetDatabaseParams(dbParams);
1382 if (m_disableeventpopup)
1394 if (me->Message() ==
"VERSION_MISMATCH" && (1 == me->ExtraDataCount()))
1395 ShowVersionMismatchPopup(me->ExtraData(0).toUInt());
1396 else if (me->Message() ==
"CONNECTION_FAILURE")
1397 ShowConnectionFailurePopup(
false);
1398 else if (me->Message() ==
"PERSISTENT_CONNECTION_FAILURE")
1399 ShowConnectionFailurePopup(
true);
1400 else if (me->Message() ==
"CONNECTION_RESTABLISHED")
1401 HideConnectionFailurePopup();
1405 return QObject::event(e);
1415 if (m_lastCheck.isValid() && now < m_lastCheck)
1423 m_lastCheck = now.addMSecs(5000);
1425 QString description = persistent ?
1427 "The connection to the master backend "
1428 "server has gone away for some reason. "
1431 "Could not connect to the master backend server. Is "
1432 "it running? Is the IP address set for it in "
1433 "mythtv-setup correct?");
1435 QString message = QObject::tr(
"Could not connect to master backend");
1437 n.
SetId(m_registration);
1447 if (!m_lastCheck.isValid())
1451 n.
SetId(m_registration);
1455 m_lastCheck = QDateTime();
1460 if (m_mbeVersionPopup)
1465 "The server uses network protocol version %1, "
1466 "but this client only understands version %2. "
1467 "Make sure you are running compatible versions of "
1468 "the backend and frontend.")
1469 .arg(remote_version).arg(MYTH_PROTO_VERSION);
1478 LOG(VB_GENERAL, LOG_ERR,
LOC + message);
1490 qApp->processEvents(QEventLoop::AllEvents, 250);
1491 qApp->processEvents(QEventLoop::AllEvents, 250);
1500const std::array<QString, 13> GUISettingsCache::kSettings
1501{
"Theme",
"Language",
"Country",
"GuiHeight",
1502 "GuiOffsetX",
"GuiOffsetY",
"GuiWidth",
"RunFrontendInWindow",
1503 "AlwaysOnTop",
"HideMouseCursor",
"ThemePainter",
"libCECEnabled",
1504 "StartupScreenDelay" };
1507bool GUISettingsCache::save()
1509 QString cacheDirName =
GetConfDir() +
'/' + m_cachePath;
1510 QDir dir(cacheDirName);
1511 dir.mkpath(cacheDirName);
1514 for (
const auto & setting : kSettings)
1516 QString cacheValue = config.
GetValue(
"Settings/" + setting, QString());
1519 if (value != cacheValue)
1521 config.
SetValue(
"Settings/" + setting, value);
1532 return config.
Save();
1537void GUISettingsCache::loadOverrides()
const
1540 for (
const auto & setting : kSettings)
1544 QString value = config.GetValue(
"Settings/" + setting, QString());
1545 if (!value.isEmpty())
1554void GUISettingsCache::clearOverrides()
1557 for (
const auto & setting : kSettings)
1570 m_mbeVersionPopup =
nullptr;
1579 static bool WSAStarted =
false;
1583 int res = WSAStartup(MAKEWORD(2, 0), &wsadata);
1584 LOG(VB_SOCKET, LOG_INFO,
1585 QString(
"WSAStartup returned %1").arg(res));
1596 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Unable to allocate MythCoreContext");
1602 const bool promptForBackend,
1603 const bool disableAutoDiscovery,
1604 const bool ignoreDB)
1608 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Init() Out-of-memory");
1612 qRegisterMetaType<std::chrono::seconds>(
"std::chrono::seconds");
1613 qRegisterMetaType<std::chrono::milliseconds>(
"std::chrono::milliseconds");
1614 qRegisterMetaType<std::chrono::microseconds>(
"std::chrono::microseconds");
1621 QString warning = QObject::tr(
"mythtv-setup is deprecated.\n"
1622 "To set up MythTV, start mythbackend and use:\n"
1623 "http://localhost:6544/setupwizard");
1629 LOG(VB_GENERAL, LOG_EMERG,
1630 QString(
"Application binary version (%1) does not "
1631 "match libraries (%2)")
1634 QString warning = QObject::tr(
1635 "This application is not compatible "
1636 "with the installed MythTV libraries.");
1642 LOG(VB_GENERAL, LOG_WARNING, warning);
1650 QString home = getenv(
"HOME");
1653 home = getenv(
"LOCALAPPDATA");
1655 home = getenv(
"APPDATA");
1657 home = QString(
".");
1659 _putenv(QString(
"HOME=%1").arg(home).toLocal8Bit().constData());
1665 QString homedir = QDir::homePath();
1666 QString
confdir = qEnvironmentVariable(
"MYTHCONFDIR");
1667 if ((homedir.isEmpty() || homedir ==
"/") &&
1670 QString warning =
"Cannot locate your home directory."
1671 " Please set the environment variable HOME";
1677 LOG(VB_GENERAL, LOG_WARNING, warning);
1682 if (!
m_impl->
Init(gui, promptForBackend, disableAutoDiscovery, ignoreDB))
1715 LOG(VB_GENERAL, LOG_INFO,
"Waiting for threads to exit.");
1721 LOG(VB_GENERAL, LOG_INFO,
"Exiting");
1752#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()
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.
void ShowVersionMismatchPopup(uint remote_version)
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