MythTV master
mythwelcome.cpp
Go to the documentation of this file.
1// Qt
2#include <QtGlobal>
3#include <QApplication>
4
5// MythTV
7#include "libmythbase/mythconfig.h"
14#include "libmythbase/mythversion.h"
18
19// mythwelcome
21#include "welcomedialog.h"
22#include "welcomesettings.h"
23
24#if CONFIG_SYSTEMD_NOTIFY
25#include <systemd/sd-daemon.h>
26static inline void mw_sd_notify(const char *str) { sd_notify(0, str); };
27#else
28static inline void mw_sd_notify(const char */*str*/) {};
29#endif
30
31static void initKeys(void)
32{
33 REG_KEY("Welcome", "STARTXTERM", QT_TRANSLATE_NOOP("MythControls",
34 "Open an Xterm window"), "F12");
35 REG_KEY("Welcome", "SHOWSETTINGS", QT_TRANSLATE_NOOP("MythControls",
36 "Show Mythshutdown settings"), "F11");
37 REG_KEY("Welcome", "STARTSETUP", QT_TRANSLATE_NOOP("MythControls",
38 "Start Mythtv-Setup"), "");
39}
40
41int main(int argc, char **argv)
42{
43 bool bShowSettings = false;
44
46 if (!cmdline.Parse(argc, argv))
47 {
50 }
51
52 if (cmdline.toBool("showhelp"))
53 {
55 return GENERIC_EXIT_OK;
56 }
57
58 if (cmdline.toBool("showversion"))
59 {
61 return GENERIC_EXIT_OK;
62 }
63
65 QApplication a(argc, argv);
66 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHWELCOME);
67
68 int retval = cmdline.ConfigureLogging();
69 if (retval != GENERIC_EXIT_OK)
70 return retval;
71
72 if (!cmdline.toString("geometry").isEmpty())
74
75 if (cmdline.toBool("setup"))
76 bShowSettings = true;
77
78 MythContext context {MYTH_BINARY_VERSION, true};
79
81 if (!context.Init())
82 {
83 LOG(VB_GENERAL, LOG_ERR,
84 "mythwelcome: Could not initialize MythContext. Exiting.");
86 }
87
89
91 {
92 LOG(VB_GENERAL, LOG_ERR,
93 "mythwelcome: Could not open the database. Exiting.");
94 return -1;
95 }
96
98
99 if (LCD *lcd = LCD::Get())
100 lcd->switchToTime();
101
102 MythTranslation::load("mythfrontend");
103
104 MythMainWindow *mainWindow = GetMythMainWindow();
105 mainWindow->Init();
106 mainWindow->DisableIdleTimer();
107
108 initKeys();
109 // Provide systemd ready notification (for type=notify units)
110 mw_sd_notify("READY=1");
111
112 MythScreenStack *mainStack = mainWindow->GetMainStack();
113
114 MythScreenType *screen = nullptr;
115 if (bShowSettings)
116 {
117 screen = new StandardSettingDialog(mainStack, "shutdown",
119 }
120 else
121 {
122 screen = new WelcomeDialog(mainStack, "mythwelcome");
123 }
124
125 bool ok = screen->Create();
126 if (ok)
127 {
128 mainStack->AddScreen(screen, false);
129
130 // Block by running an event loop until last screen is removed
131 QEventLoop block;
132 QObject::connect(mainStack, &MythScreenStack::topScreenChanged,
133 &block, [&](const MythScreenType* _screen)
134 { if (!_screen) block.quit(); });
135 block.exec();
136 }
137
138 mw_sd_notify("STOPPING=1\nSTATUS=Exiting");
139
140 return ok ? 0 : -1;
141}
Definition: lcddevice.h:170
static LCD * Get(void)
Definition: lcddevice.cpp:68
static void SetupLCD(void)
Definition: lcddevice.cpp:75
static bool testDBConnection()
Checks DB connection + login (login info via Mythcontext)
Definition: mythdbcon.cpp:877
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
void ApplySettingsOverride(void)
Apply all overrides to the global context.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
static void PrintVersion(void)
Print application version information.
void PrintHelp(void) const
Print command line option help.
Startup context for MythTV.
Definition: mythcontext.h:20
static void ConfigureQtGUI(int SwapInterval, const MythCommandLineParser &CmdLine)
Shared static initialisation code for all MythTV GUI applications.
MythScreenStack * GetMainStack()
void DisableIdleTimer(bool DisableIdle=true)
Disable the idle timeout timer.
void Init(bool MayReInit=true)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void topScreenChanged(MythScreenType *screen)
Screen in which all other widgets are contained and rendered.
virtual bool Create(void)
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
static void ParseGeometryOverride(const QString &Geometry)
Parse an X11 style command line geometry string.
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
static constexpr const char * MYTH_APPNAME_MYTHWELCOME
Definition: mythappname.h:13
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
static void mw_sd_notify(const char *)
Definition: mythwelcome.cpp:28
int main(int argc, char **argv)
Definition: mythwelcome.cpp:41
static void initKeys(void)
Definition: mythwelcome.cpp:31
MythCommFlagCommandLineParser cmdline