MythTV  master
mythwelcome.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QtGlobal>
3 #include <QApplication>
4 
5 // MythTV
6 #include "libmyth/mythcontext.h"
7 #include "libmythbase/compat.h"
12 #include "libmythbase/mythversion.h"
14 #include "libmythui/mythdisplay.h"
16 #include "libmythui/mythuihelper.h"
17 
18 // mythwelcome
20 #include "welcomedialog.h"
21 #include "welcomesettings.h"
22 
23 #if CONFIG_SYSTEMD_NOTIFY
24 #include <systemd/sd-daemon.h>
25 static inline void mw_sd_notify(const char *str) { sd_notify(0, str); };
26 #else
27 static inline void mw_sd_notify(const char */*str*/) {};
28 #endif
29 
30 static 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 
40 int 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 #ifndef _WIN32
79 #endif
80 
81  gContext = new MythContext(MYTH_BINARY_VERSION, true);
82 
84  if (!gContext->Init())
85  {
86  LOG(VB_GENERAL, LOG_ERR,
87  "mythwelcome: Could not initialize MythContext. Exiting.");
90  }
91 
93 
95  {
96  LOG(VB_GENERAL, LOG_ERR,
97  "mythwelcome: Could not open the database. Exiting.");
99  return -1;
100  }
101 
102  LCD::SetupLCD();
103 
104  if (LCD *lcd = LCD::Get())
105  lcd->switchToTime();
106 
107  MythTranslation::load("mythfrontend");
108 
109  MythMainWindow *mainWindow = GetMythMainWindow();
110  mainWindow->Init();
111  mainWindow->DisableIdleTimer();
112 
113  initKeys();
114  // Provide systemd ready notification (for type=notify units)
115  mw_sd_notify("READY=1");
116 
117  MythScreenStack *mainStack = mainWindow->GetMainStack();
118 
119  MythScreenType *screen = nullptr;
120  if (bShowSettings)
121  {
122  screen = new StandardSettingDialog(mainStack, "shutdown",
123  new MythShutdownSettings());
124  }
125  else
126  {
127  screen = new WelcomeDialog(mainStack, "mythwelcome");
128  }
129 
130  bool ok = screen->Create();
131  if (ok)
132  {
133  mainStack->AddScreen(screen, false);
134 
135  // Block by running an event loop until last screen is removed
136  QEventLoop block;
137  QObject::connect(mainStack, &MythScreenStack::topScreenChanged,
138  &block, [&](const MythScreenType* _screen)
139  { if (!_screen) block.quit(); });
140  block.exec();
141  }
142 
143  mw_sd_notify("STOPPING=1\nSTATUS=Exiting");
145 
146  delete gContext;
147 
149 
150  return ok ? 0 : -1;
151 }
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:317
welcomesettings.h
MythShutdownSettings
Definition: welcomesettings.h:14
REG_KEY
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
Definition: mythmainwindow.h:175
MythMainWindow::Init
void Init(bool MayReInit=true)
Definition: mythmainwindow.cpp:641
MythUIScreenBounds::ParseGeometryOverride
static void ParseGeometryOverride(const QString &Geometry)
Parse an X11 style command line geometry string.
Definition: mythuiscreenbounds.cpp:40
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:72
MythContext
Startup context for MythTV.
Definition: mythcontext.h:43
mythwelcome_commandlineparser.h
MythScreenStack
Definition: mythscreenstack.h:16
MythScreenType::Create
virtual bool Create(void)
Definition: mythscreentype.cpp:263
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
main
int main(int argc, char **argv)
Definition: mythwelcome.cpp:40
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:69
MythDisplay::ConfigureQtGUI
static void ConfigureQtGUI(int SwapInterval, const MythCommandLineParser &CmdLine)
Shared static initialisation code for all MythTV GUI applications.
Definition: mythdisplay.cpp:1158
MythMainWindow::DisableIdleTimer
void DisableIdleTimer(bool DisableIdle=true)
Disable the idle timeout timer.
Definition: mythmainwindow.cpp:2125
welcomedialog.h
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1552
StandardSettingDialog
Definition: standardsettings.h:468
mythdisplay.h
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
mythlogging.h
signalhandling.h
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
compat.h
MythScreenStack::topScreenChanged
void topScreenChanged(MythScreenType *screen)
MSqlQuery::testDBConnection
static bool testDBConnection()
Checks DB connection + login (login info via Mythcontext)
Definition: mythdbcon.cpp:876
WelcomeDialog
Definition: welcomedialog.h:17
MythWelcomeCommandLineParser
Definition: mythwelcome_commandlineparser.h:6
DestroyMythMainWindow
void DestroyMythMainWindow(void)
Definition: mythmainwindow.cpp:114
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1380
mythtranslation.h
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1396
MythCommandLineParser::ApplySettingsOverride
void ApplySettingsOverride(void)
Apply all overrides to the global context.
Definition: mythcommandlineparser.cpp:2941
mythuihelper.h
SignalHandler::Init
static void Init(QObject *parent=nullptr)
Definition: signalhandling.cpp:128
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2354
LCD::SetupLCD
static void SetupLCD(void)
Definition: lcddevice.cpp:76
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2197
mw_sd_notify
static void mw_sd_notify(const char *)
Definition: mythwelcome.cpp:27
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2870
lcddevice.h
MythTranslation::load
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
Definition: mythtranslation.cpp:37
exitcodes.h
initKeys
static void initKeys(void)
Definition: mythwelcome.cpp:30
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
MYTH_APPNAME_MYTHWELCOME
static constexpr const char * MYTH_APPNAME_MYTHWELCOME
Definition: mythcorecontext.h:28
gContext
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:64
MythContext::Init
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: mythcontext.cpp:1608
MythMainWindow
Definition: mythmainwindow.h:28
LCD
Definition: lcddevice.h:169
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:135
GENERIC_EXIT_NO_MYTHCONTEXT
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16