MythTV  master
mythtv/programs/mythwelcome/main.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QApplication>
3 
4 // MythTV
5 #include "mythcontext.h"
6 #include "mythversion.h"
7 #include "mythtranslation.h"
8 #include "exitcodes.h"
9 #include "compat.h"
10 #include "lcddevice.h"
11 #include "commandlineparser.h"
12 #include "loggingserver.h"
13 #include "mythlogging.h"
14 #include "signalhandling.h"
15 #include "mythdisplay.h"
16 
17 // libmythui
18 #include "mythmainwindow.h"
19 #include "mythuihelper.h"
20 
21 // mythwelcome
22 #include "welcomedialog.h"
23 #include "welcomesettings.h"
24 
25 #if CONFIG_SYSTEMD_NOTIFY
26 #include <systemd/sd-daemon.h>
27 #define mw_sd_notify(x) \
28  (void)sd_notify(0, x);
29 #else
30 #define mw_sd_notify(x)
31 #endif
32 
33 static void initKeys(void)
34 {
35  REG_KEY("Welcome", "STARTXTERM", QT_TRANSLATE_NOOP("MythControls",
36  "Open an Xterm window"), "F12");
37  REG_KEY("Welcome", "SHOWSETTINGS", QT_TRANSLATE_NOOP("MythControls",
38  "Show Mythshutdown settings"), "F11");
39  REG_KEY("Welcome", "STARTSETUP", QT_TRANSLATE_NOOP("MythControls",
40  "Start Mythtv-Setup"), "");
41 }
42 
43 int main(int argc, char **argv)
44 {
45  bool bShowSettings = false;
46 
48  if (!cmdline.Parse(argc, argv))
49  {
52  }
53 
54  if (cmdline.toBool("showhelp"))
55  {
57  return GENERIC_EXIT_OK;
58  }
59 
60  if (cmdline.toBool("showversion"))
61  {
63  return GENERIC_EXIT_OK;
64  }
65 
67  QApplication a(argc, argv);
68  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHWELCOME);
69 
70  int retval = cmdline.ConfigureLogging();
71  if (retval != GENERIC_EXIT_OK)
72  return retval;
73 
74  if (!cmdline.toString("geometry").isEmpty())
76 
77  if (cmdline.toBool("setup"))
78  bShowSettings = true;
79 
80 #ifndef _WIN32
81  QList<int> signallist;
82  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
83  << SIGILL;
84 #if ! CONFIG_DARWIN
85  signallist << SIGRTMIN;
86 #endif
87  SignalHandler::Init(signallist);
89 #endif
90 
92 
94  if (!gContext->Init())
95  {
96  LOG(VB_GENERAL, LOG_ERR,
97  "mythwelcome: Could not initialize MythContext. Exiting.");
100  }
101 
103 
105  {
106  LOG(VB_GENERAL, LOG_ERR,
107  "mythwelcome: Could not open the database. Exiting.");
109  return -1;
110  }
111 
112  LCD::SetupLCD();
113 
114  if (LCD *lcd = LCD::Get())
115  lcd->switchToTime();
116 
117  MythTranslation::load("mythfrontend");
118 
119  MythMainWindow *mainWindow = GetMythMainWindow();
120  mainWindow->Init();
121  mainWindow->DisableIdleTimer();
122 
123  initKeys();
124  // Provide systemd ready notification (for type=notify units)
125  mw_sd_notify("READY=1")
126 
127  MythScreenStack *mainStack = mainWindow->GetMainStack();
128 
129  MythScreenType *screen = nullptr;
130  if (bShowSettings)
131  {
132  screen = new StandardSettingDialog(mainStack, "shutdown",
133  new MythShutdownSettings());
134  }
135  else
136  {
137  screen = new WelcomeDialog(mainStack, "mythwelcome");
138  }
139 
140  bool ok = screen->Create();
141  if (ok)
142  {
143  mainStack->AddScreen(screen, false);
144 
145  // Block by running an event loop until last screen is removed
146  QEventLoop block;
147  QObject::connect(mainStack, &MythScreenStack::topScreenChanged,
148  &block, [&](MythScreenType* _screen)
149  { if (!_screen) block.quit(); });
150  block.exec();
151  }
152 
153  mw_sd_notify("STOPPING=1\nSTATUS=Exiting")
155 
156  delete gContext;
157 
159 
160  return ok ? 0 : -1;
161 }
commandlineparser.h
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:314
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:637
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:265
main
int main(int argc, char **argv)
Definition: mythtv/programs/mythwelcome/main.cpp:43
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:44
MYTH_APPNAME_MYTHWELCOME
#define MYTH_APPNAME_MYTHWELCOME
Definition: mythcorecontext.h:28
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:30
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:2096
welcomedialog.h
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1449
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:866
WelcomeDialog
Definition: welcomedialog.h:21
MythWelcomeCommandLineParser
Definition: mythwelcome/commandlineparser.h:6
DestroyMythMainWindow
void DestroyMythMainWindow(void)
Definition: mythmainwindow.cpp:111
SIGHUP
#define SIGHUP
Definition: compat.h:216
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1277
mythtranslation.h
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1293
MythCommandLineParser::ApplySettingsOverride
void ApplySettingsOverride(void)
Apply all overrides to the global context.
Definition: mythcommandlineparser.cpp:2825
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:74
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2252
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:2095
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:138
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:101
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2756
initKeys
static void initKeys(void)
Definition: mythtv/programs/mythwelcome/main.cpp:33
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:50
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:1570
MythMainWindow
Definition: mythmainwindow.h:35
LCD
Definition: lcddevice.h:173
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:131
SignalHandler::Init
static void Init(QList< int > &signallist, QObject *parent=nullptr)
Definition: signalhandling.cpp:124