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 }
commandlineparser.h
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:304
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
welcomesettings.h
MythShutdownSettings
Definition: welcomesettings.h:15
MythContext
Startup context for MythTV.
Definition: mythcontext.h:43
MythScreenStack
Definition: mythscreenstack.h:16
MythScreenType::Create
virtual bool Create(void)
Definition: mythscreentype.cpp:282
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:45
MYTH_APPNAME_MYTHWELCOME
#define MYTH_APPNAME_MYTHWELCOME
Definition: mythcorecontext.h:27
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:64
mw_sd_notify
#define mw_sd_notify(x)
Definition: mythtv/programs/mythwelcome/main.cpp:30
mythversion.h
welcomedialog.h
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1438
StandardSettingDialog
Definition: standardsettings.h:466
REG_KEY
#define REG_KEY(a, b, c, d)
Definition: mythmainwindow.h:17
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:852
WelcomeDialog
Definition: welcomedialog.h:22
MythWelcomeCommandLineParser
Definition: mythwelcome/commandlineparser.h:7
DestroyMythMainWindow
void DestroyMythMainWindow(void)
Definition: mythmainwindow.cpp:117
SIGHUP
#define SIGHUP
Definition: compat.h:213
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1266
mythtranslation.h
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1282
MythCommandLineParser::ApplySettingsOverride
void ApplySettingsOverride(void)
Apply all overrides to the global context.
Definition: mythcommandlineparser.cpp:2657
MythUIHelper::LoadQtConfig
void LoadQtConfig(void)
Definition: mythuihelper.cpp:319
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:77
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2101
LCD::SetupLCD
static void SetupLCD(void)
Definition: lcddevice.cpp:71
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:1944
MythDisplay::ConfigureQtGUI
static void ConfigureQtGUI(int SwapInterval=1, const QString &Display=QString())
Shared static initialistaion code for all MythTV GUI applications.
Definition: mythdisplay.cpp:1061
MythMainWindow::DisableIdleTimer
void DisableIdleTimer(bool disableIdle=true)
Definition: mythmainwindow.cpp:2417
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:140
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2588
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
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:81
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:62
MythMainWindow::Init
void Init(bool mayReInit=true)
Definition: mythmainwindow.cpp:596
MythContext::Init
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: mythcontext.cpp:1564
MythMainWindow
Definition: mythmainwindow.h:33
LCD
Definition: lcddevice.h:170
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:133
SignalHandler::Init
static void Init(QList< int > &signallist, QObject *parent=nullptr)
Definition: signalhandling.cpp:126