MythTV master
mythwelcome.cpp
Go to the documentation of this file.
1// Qt
2#include <QtGlobal>
3#include <QApplication>
4
5// MythTV
13#include "libmythbase/mythversion.h"
17
18// mythwelcome
20#include "welcomedialog.h"
21#include "welcomesettings.h"
22
23#if CONFIG_SYSTEMD_NOTIFY
24#include <systemd/sd-daemon.h>
25static inline void mw_sd_notify(const char *str) { sd_notify(0, str); };
26#else
27static inline void mw_sd_notify(const char */*str*/) {};
28#endif
29
30static void initKeys(void)
31{
32 REG_KEY("Welcome", "STARTXTERM", QT_TRANSLATE_NOOP("MythControls",
33 "Open an Xterm window"), "F12");
34 REG_KEY("Welcome", "SHOWSETTINGS", QT_TRANSLATE_NOOP("MythControls",
35 "Show Mythshutdown settings"), "F11");
36 REG_KEY("Welcome", "STARTSETUP", QT_TRANSLATE_NOOP("MythControls",
37 "Start Mythtv-Setup"), "");
38}
39
40int main(int argc, char **argv)
41{
42 bool bShowSettings = false;
43
45 if (!cmdline.Parse(argc, argv))
46 {
49 }
50
51 if (cmdline.toBool("showhelp"))
52 {
54 return GENERIC_EXIT_OK;
55 }
56
57 if (cmdline.toBool("showversion"))
58 {
60 return GENERIC_EXIT_OK;
61 }
62
64 QApplication a(argc, argv);
65 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHWELCOME);
66
67 int retval = cmdline.ConfigureLogging();
68 if (retval != GENERIC_EXIT_OK)
69 return retval;
70
71 if (!cmdline.toString("geometry").isEmpty())
73
74 if (cmdline.toBool("setup"))
75 bShowSettings = true;
76
77 MythContext context {MYTH_BINARY_VERSION, true};
78
80 if (!context.Init())
81 {
82 LOG(VB_GENERAL, LOG_ERR,
83 "mythwelcome: Could not initialize MythContext. Exiting.");
85 }
86
88
90 {
91 LOG(VB_GENERAL, LOG_ERR,
92 "mythwelcome: Could not open the database. Exiting.");
93 return -1;
94 }
95
97
98 if (LCD *lcd = LCD::Get())
99 lcd->switchToTime();
100
101 MythTranslation::load("mythfrontend");
102
103 MythMainWindow *mainWindow = GetMythMainWindow();
104 mainWindow->Init();
105 mainWindow->DisableIdleTimer();
106
107 initKeys();
108 // Provide systemd ready notification (for type=notify units)
109 mw_sd_notify("READY=1");
110
111 MythScreenStack *mainStack = mainWindow->GetMainStack();
112
113 MythScreenType *screen = nullptr;
114 if (bShowSettings)
115 {
116 screen = new StandardSettingDialog(mainStack, "shutdown",
118 }
119 else
120 {
121 screen = new WelcomeDialog(mainStack, "mythwelcome");
122 }
123
124 bool ok = screen->Create();
125 if (ok)
126 {
127 mainStack->AddScreen(screen, false);
128
129 // Block by running an event loop until last screen is removed
130 QEventLoop block;
131 QObject::connect(mainStack, &MythScreenStack::topScreenChanged,
132 &block, [&](const MythScreenType* _screen)
133 { if (!_screen) block.quit(); });
134 block.exec();
135 }
136
137 mw_sd_notify("STOPPING=1\nSTATUS=Exiting");
138
139 return ok ? 0 : -1;
140}
Definition: lcddevice.h:170
static LCD * Get(void)
Definition: lcddevice.cpp:69
static void SetupLCD(void)
Definition: lcddevice.cpp:76
static bool testDBConnection()
Checks DB connection + login (login info via Mythcontext)
Definition: mythdbcon.cpp:876
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
MythCommFlagCommandLineParser cmdline
#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:27
int main(int argc, char **argv)
Definition: mythwelcome.cpp:40
static void initKeys(void)
Definition: mythwelcome.cpp:30