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 
16 // libmythui
17 #include "mythmainwindow.h"
18 #include "mythuihelper.h"
19 
20 // mythwelcome
21 #include "welcomedialog.h"
22 #include "welcomesettings.h"
23 
24 #if CONFIG_SYSTEMD_NOTIFY
25 #include <systemd/sd-daemon.h>
26 #define mw_sd_notify(x) \
27  (void)sd_notify(0, x);
28 #else
29 #define mw_sd_notify(x)
30 #endif
31 
32 static void initKeys(void)
33 {
34  REG_KEY("Welcome", "STARTXTERM", QT_TRANSLATE_NOOP("MythControls",
35  "Open an Xterm window"), "F12");
36  REG_KEY("Welcome", "SHOWSETTINGS", QT_TRANSLATE_NOOP("MythControls",
37  "Show Mythshutdown settings"), "F11");
38  REG_KEY("Welcome", "STARTSETUP", QT_TRANSLATE_NOOP("MythControls",
39  "Start Mythtv-Setup"), "");
40 }
41 
42 int main(int argc, char **argv)
43 {
44  bool bShowSettings = false;
45 
46 #if CONFIG_OMX_RPI
47  setenv("QT_XCB_GL_INTEGRATION","none",0);
48 #endif
49 
51  if (!cmdline.Parse(argc, argv))
52  {
55  }
56 
57  if (cmdline.toBool("showhelp"))
58  {
60  return GENERIC_EXIT_OK;
61  }
62 
63  if (cmdline.toBool("showversion"))
64  {
66  return GENERIC_EXIT_OK;
67  }
68 
69  QApplication a(argc, argv);
70  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHWELCOME);
71 
72  int retval;
73  if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
74  return retval;
75 
76  if (cmdline.toBool("setup"))
77  bShowSettings = true;
78 
79 #ifndef _WIN32
80  QList<int> signallist;
81  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
82  << SIGILL;
83 #if ! CONFIG_DARWIN
84  signallist << SIGRTMIN;
85 #endif
86  SignalHandler::Init(signallist);
88 #endif
89 
91 
93  if (!gContext->Init())
94  {
95  LOG(VB_GENERAL, LOG_ERR,
96  "mythwelcome: Could not initialize MythContext. Exiting.");
99  }
100 
102 
104  {
105  LOG(VB_GENERAL, LOG_ERR,
106  "mythwelcome: Could not open the database. Exiting.");
108  return -1;
109  }
110 
111  LCD::SetupLCD();
112 
113  if (LCD *lcd = LCD::Get())
114  lcd->switchToTime();
115 
116  MythTranslation::load("mythfrontend");
117 
118  GetMythUI()->LoadQtConfig();
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;
131  if (bShowSettings)
132  screen = new StandardSettingDialog(mainStack, "shutdown",
133  new MythShutdownSettings());
134  else
135  screen = new WelcomeDialog(mainStack, "mythwelcome");
136 
137  bool ok = screen->Create();
138  if (ok)
139  {
140  mainStack->AddScreen(screen, false);
141 
142  // Block by running an event loop until last screen is removed
143  QEventLoop block;
144  QObject::connect(mainStack, &MythScreenStack::topScreenChanged,
145  &block, [&](MythScreenType* _screen)
146  { if (!_screen) block.quit(); });
147  block.exec();
148  }
149 
150  mw_sd_notify("STOPPING=1\nSTATUS=Exiting");
152 
153  delete gContext;
154 
156 
157  return ok ? 0 : -1;
158 }
Startup context for MythTV.
Definition: mythcontext.h:42
#define mw_sd_notify(x)
void LoadQtConfig(void)
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
#define MYTH_APPNAME_MYTHWELCOME
virtual bool Create(void)
void PrintHelp(void) const
Print command line option help.
int main(int argc, char **argv)
static void SetupLCD(void)
Definition: lcddevice.cpp:72
static void Init(QList< int > &signallist, QObject *parent=nullptr)
void DestroyMythMainWindow(void)
MythScreenStack * GetMainStack()
#define REG_KEY(a, b, c, d)
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:63
void Init(const QString &forcedpainter=QString(), bool mayReInit=true)
static LCD * Get(void)
Definition: lcddevice.cpp:65
void ApplySettingsOverride(void)
Apply all overrides to the global context.
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
static bool testDBConnection()
Checks DB connection + login (login info via Mythcontext)
Definition: mythdbcon.cpp:851
static void Done(void)
static void SetHandler(int signum, SigHandlerFunc handler)
void DisableIdleTimer(bool disableIdle=true)
MythCommFlagCommandLineParser cmdline
MythUIHelper * GetMythUI()
MythMainWindow * GetMythMainWindow(void)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
static void initKeys(void)
#define SIGHUP
Definition: compat.h:213
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
Definition: lcddevice.h:165
#define setenv(x, y, z)
Definition: compat.h:156
bool Init(const bool gui=true, const bool promptForBackend=false, const bool disableAutoDiscovery=false, const bool ignoreDB=false)
int ConfigureLogging(QString mask="general", unsigned int progress=0)
Read in logging options and initialize the logging interface.
#define GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:13
Screen in which all other widgets are contained and rendered.
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
void PrintVersion(void) const
Print application version information.
void topScreenChanged(MythScreenType *screen)