MythTV  master
mythtv/programs/mythwelcome/main.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QtGlobal>
3 #include <QApplication>
4 
5 // MythTV
6 #include "mythcontext.h"
7 #include "mythversion.h"
8 #include "mythtranslation.h"
9 #include "exitcodes.h"
10 #include "compat.h"
11 #include "lcddevice.h"
12 #include "commandlineparser.h"
13 #include "loggingserver.h"
14 #include "mythlogging.h"
15 #include "signalhandling.h"
16 #include "mythdisplay.h"
17 
18 // libmythui
19 #include "mythmainwindow.h"
20 #include "mythuihelper.h"
21 
22 // mythwelcome
23 #include "welcomedialog.h"
24 #include "welcomesettings.h"
25 
26 #if CONFIG_SYSTEMD_NOTIFY
27 #include <systemd/sd-daemon.h>
28 #define mw_sd_notify(x) \
29  (void)sd_notify(0, x);
30 #else
31 #define mw_sd_notify(x)
32 #endif
33 
34 static void initKeys(void)
35 {
36  REG_KEY("Welcome", "STARTXTERM", QT_TRANSLATE_NOOP("MythControls",
37  "Open an Xterm window"), "F12");
38  REG_KEY("Welcome", "SHOWSETTINGS", QT_TRANSLATE_NOOP("MythControls",
39  "Show Mythshutdown settings"), "F11");
40  REG_KEY("Welcome", "STARTSETUP", QT_TRANSLATE_NOOP("MythControls",
41  "Start Mythtv-Setup"), "");
42 }
43 
44 int main(int argc, char **argv)
45 {
46  bool bShowSettings = false;
47 
49  if (!cmdline.Parse(argc, argv))
50  {
53  }
54 
55  if (cmdline.toBool("showhelp"))
56  {
58  return GENERIC_EXIT_OK;
59  }
60 
61  if (cmdline.toBool("showversion"))
62  {
64  return GENERIC_EXIT_OK;
65  }
66 
68  QApplication a(argc, argv);
69  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHWELCOME);
70 
71  int retval = cmdline.ConfigureLogging();
72  if (retval != GENERIC_EXIT_OK)
73  return retval;
74 
75  if (!cmdline.toString("geometry").isEmpty())
77 
78  if (cmdline.toBool("setup"))
79  bShowSettings = true;
80 
81 #ifndef _WIN32
82  QList<int> signallist;
83  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
84  << SIGILL;
85 #ifndef Q_OS_DARWIN
86  signallist << SIGRTMIN;
87 #endif
88  SignalHandler::Init(signallist);
90 #endif
91 
93 
95  if (!gContext->Init())
96  {
97  LOG(VB_GENERAL, LOG_ERR,
98  "mythwelcome: Could not initialize MythContext. Exiting.");
101  }
102 
104 
106  {
107  LOG(VB_GENERAL, LOG_ERR,
108  "mythwelcome: Could not open the database. Exiting.");
110  return -1;
111  }
112 
113  LCD::SetupLCD();
114 
115  if (LCD *lcd = LCD::Get())
116  lcd->switchToTime();
117 
118  MythTranslation::load("mythfrontend");
119 
120  MythMainWindow *mainWindow = GetMythMainWindow();
121  mainWindow->Init();
122  mainWindow->DisableIdleTimer();
123 
124  initKeys();
125  // Provide systemd ready notification (for type=notify units)
126  mw_sd_notify("READY=1")
127 
128  MythScreenStack *mainStack = mainWindow->GetMainStack();
129 
130  MythScreenType *screen = nullptr;
131  if (bShowSettings)
132  {
133  screen = new StandardSettingDialog(mainStack, "shutdown",
134  new MythShutdownSettings());
135  }
136  else
137  {
138  screen = new WelcomeDialog(mainStack, "mythwelcome");
139  }
140 
141  bool ok = screen->Create();
142  if (ok)
143  {
144  mainStack->AddScreen(screen, false);
145 
146  // Block by running an event loop until last screen is removed
147  QEventLoop block;
148  QObject::connect(mainStack, &MythScreenStack::topScreenChanged,
149  &block, [&](const MythScreenType* _screen)
150  { if (!_screen) block.quit(); });
151  block.exec();
152  }
153 
154  mw_sd_notify("STOPPING=1\nSTATUS=Exiting")
156 
157  delete gContext;
158 
160 
161  return ok ? 0 : -1;
162 }
commandlineparser.h
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:315
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
welcomesettings.h
MythShutdownSettings
Definition: welcomesettings.h:14
MythMainWindow::Init
void Init(bool MayReInit=true)
Definition: mythmainwindow.cpp:638
MythUIScreenBounds::ParseGeometryOverride
static void ParseGeometryOverride(const QString &Geometry)
Parse an X11 style command line geometry string.
Definition: mythuiscreenbounds.cpp:39
MythContext
Startup context for MythTV.
Definition: mythcontext.h:43
MythScreenStack
Definition: mythscreenstack.h:16
MythScreenType::Create
virtual bool Create(void)
Definition: mythscreentype.cpp:266
main
int main(int argc, char **argv)
Definition: mythtv/programs/mythwelcome/main.cpp:44
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
MYTH_APPNAME_MYTHWELCOME
#define MYTH_APPNAME_MYTHWELCOME
Definition: mythcorecontext.h:30
GENERIC_EXIT_INVALID_CMDLINE
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:69
mw_sd_notify
#define mw_sd_notify(x)
Definition: mythtv/programs/mythwelcome/main.cpp:31
mythversion.h
MythDisplay::ConfigureQtGUI
static void ConfigureQtGUI(int SwapInterval, const MythCommandLineParser &CmdLine)
Shared static initialistaion code for all MythTV GUI applications.
Definition: mythdisplay.cpp:1152
MythMainWindow::DisableIdleTimer
void DisableIdleTimer(bool DisableIdle=true)
Disable the idle timeout timer.
Definition: mythmainwindow.cpp:2118
welcomedialog.h
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1553
StandardSettingDialog
Definition: standardsettings.h:468
REG_KEY
#define REG_KEY(a, b, c, d)
Definition: mythmainwindow.h:19
mythdisplay.h
mythlogging.h
signalhandling.h
compat.h
MythScreenStack::topScreenChanged
void topScreenChanged(MythScreenType *screen)
MSqlQuery::testDBConnection
static bool testDBConnection()
Checks DB connection + login (login info via Mythcontext)
Definition: mythdbcon.cpp:870
WelcomeDialog
Definition: welcomedialog.h:21
MythWelcomeCommandLineParser
Definition: mythwelcome/commandlineparser.h:6
DestroyMythMainWindow
void DestroyMythMainWindow(void)
Definition: mythmainwindow.cpp:112
SIGHUP
#define SIGHUP
Definition: compat.h:216
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1381
mythtranslation.h
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1397
MythCommandLineParser::ApplySettingsOverride
void ApplySettingsOverride(void)
Apply all overrides to the global context.
Definition: mythcommandlineparser.cpp:2929
mythuihelper.h
MYTH_BINARY_VERSION
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythtv/programs/mythcommflag/main.cpp:75
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2356
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:2199
mythcontext.h
GENERIC_EXIT_NO_MYTHCONTEXT
#define GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:13
SignalHandler::SetHandler
static void SetHandler(int signum, SigHandlerFunc handler)
Definition: signalhandling.cpp:141
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:102
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2860
initKeys
static void initKeys(void)
Definition: mythtv/programs/mythwelcome/main.cpp:34
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
mythmainwindow.h
loggingserver.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
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:1571
MythMainWindow
Definition: mythmainwindow.h:35
LCD
Definition: lcddevice.h:173
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:134
SignalHandler::Init
static void Init(QList< int > &signallist, QObject *parent=nullptr)
Definition: signalhandling.cpp:127