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.toBool("setup"))
75  bShowSettings = true;
76 
77 #ifndef _WIN32
78  QList<int> signallist;
79  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
80  << SIGILL;
81 #if ! CONFIG_DARWIN
82  signallist << SIGRTMIN;
83 #endif
84  SignalHandler::Init(signallist);
86 #endif
87 
89 
91  if (!gContext->Init())
92  {
93  LOG(VB_GENERAL, LOG_ERR,
94  "mythwelcome: Could not initialize MythContext. Exiting.");
97  }
98 
100 
102  {
103  LOG(VB_GENERAL, LOG_ERR,
104  "mythwelcome: Could not open the database. Exiting.");
106  return -1;
107  }
108 
109  LCD::SetupLCD();
110 
111  if (LCD *lcd = LCD::Get())
112  lcd->switchToTime();
113 
114  MythTranslation::load("mythfrontend");
115 
116  GetMythUI()->LoadQtConfig();
117 
118  MythMainWindow *mainWindow = GetMythMainWindow();
119  mainWindow->Init();
120  mainWindow->DisableIdleTimer();
121 
122  initKeys();
123  // Provide systemd ready notification (for type=notify units)
124  mw_sd_notify("READY=1");
125 
126  MythScreenStack *mainStack = mainWindow->GetMainStack();
127 
128  MythScreenType *screen = nullptr;
129  if (bShowSettings)
130  {
131  screen = new StandardSettingDialog(mainStack, "shutdown",
132  new MythShutdownSettings());
133  }
134  else
135  {
136  screen = new WelcomeDialog(mainStack, "mythwelcome");
137  }
138 
139  bool ok = screen->Create();
140  if (ok)
141  {
142  mainStack->AddScreen(screen, false);
143 
144  // Block by running an event loop until last screen is removed
145  QEventLoop block;
146  QObject::connect(mainStack, &MythScreenStack::topScreenChanged,
147  &block, [&](MythScreenType* _screen)
148  { if (!_screen) block.quit(); });
149  block.exec();
150  }
151 
152  mw_sd_notify("STOPPING=1\nSTATUS=Exiting");
154 
155  delete gContext;
156 
158 
159  return ok ? 0 : -1;
160 }
static void ConfigureQtGUI(int SwapInterval=1)
Shared static initialistaion code for all MythTV GUI applications.
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.
static void PrintVersion(void)
Print application version information.
#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:62
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:852
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
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: lcddevice.h:169
#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 Init(bool mayReInit=true)
void topScreenChanged(MythScreenType *screen)
int ConfigureLogging(const QString &mask="general", unsigned int progress=0)
Read in logging options and initialize the logging interface.