MythTV  master
mythtv/programs/mythscreenwizard/main.cpp
Go to the documentation of this file.
1 #include <cmath>
2 #include <csignal>
3 #include <cstdio>
4 #include <cstdlib>
5 #include <ctime>
6 #include <fcntl.h>
7 #include <fstream>
8 #include <iostream>
9 #include <string>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <unistd.h>
13 
14 #include <QKeyEvent>
15 #include <QEvent>
16 #include <QTextCodec>
17 #include <QWidget>
18 #include <QApplication>
19 #include <QString>
20 #include <QRegExp>
21 #include <QFileInfo>
22 #include <QDir>
23 
24 #include "exitcodes.h"
25 #include "mythcontext.h"
26 #include "mythdbcon.h"
27 #include "mythversion.h"
28 #include "commandlineparser.h"
29 #include "compat.h"
30 #include "mythsystemevent.h"
31 #include "mythlogging.h"
32 #include "signalhandling.h"
33 #include "screenwizard.h"
34 #include "langsettings.h"
35 #include "mythtranslation.h"
36 #include "mythmainwindow.h"
37 #include "mythuihelper.h"
38 #include "mythcorecontext.h"
39 #if CONFIG_DARWIN
40 #include "mythuidefines.h"
41 #endif
42 #include "cleanupguard.h"
43 
44 #define LOC QString("MythScreenWizard: ")
45 #define LOC_WARN QString("MythScreenWizard, Warning: ")
46 #define LOC_ERR QString("MythScreenWizard, Error: ")
47 
48 using namespace std;
49 
50 namespace
51 {
52  void cleanup()
53  {
55 
56  delete gContext;
57  gContext = nullptr;
58 
60 
61  delete qApp;
62 
64  }
65 }
66 
67 // If the theme specified in the DB is somehow broken, try a standard one:
68 //
69 /*
70 static bool resetTheme(QString themedir, const QString badtheme)
71 {
72  QString themename = DEFAULT_UI_THEME;
73 
74  if (badtheme == DEFAULT_UI_THEME)
75  themename = FALLBACK_UI_THEME;
76 
77  LOG(VB_GENERAL, LOG_ERR,
78  QString("Overriding broken theme '%1' with '%2'")
79  .arg(badtheme).arg(themename));
80 
81  gCoreContext->OverrideSettingForSession("Theme", themename);
82  themedir = GetMythUI()->FindThemeDir(themename);
83 
84  MythTranslation::reload();
85  GetMythUI()->LoadQtConfig();
86 #if CONFIG_DARWIN
87  GetMythMainWindow()->Init(QT_PAINTER);
88 #else
89  GetMythMainWindow()->Init();
90 #endif
91  GetMythMainWindow()->ReinitDone();
92 
93  return RunMenu(themedir, themename);
94 }
95 */
96 static void startAppearWiz(int _x, int _y, int _w, int _h)
97 {
99 
100  ScreenWizard *screenwizard = new ScreenWizard(mainStack,
101  "screenwizard");
102  screenwizard->SetInitialSettings(_x, _y, _w, _h);
103 
104  if (screenwizard->Create())
105  mainStack->AddScreen(screenwizard);
106  else
107  delete screenwizard;
108 }
109 
110 int main(int argc, char **argv)
111 {
112 
113 #if CONFIG_OMX_RPI
114  setenv("QT_XCB_GL_INTEGRATION","none",0);
115 #endif
116 
118  if (!cmdline.Parse(argc, argv))
119  {
120  cmdline.PrintHelp();
122  }
123 
124  if (cmdline.toBool("showhelp"))
125  {
126  cmdline.PrintHelp();
127  return GENERIC_EXIT_OK;
128  }
129 
130  if (cmdline.toBool("showversion"))
131  {
133  return GENERIC_EXIT_OK;
134  }
135 
136 
137 #ifdef Q_OS_MAC
138  // Without this, we can't set focus to any of the CheckBoxSetting, and most
139  // of the MythPushButton widgets, and they don't use the themed background.
140  QApplication::setDesktopSettingsAware(false);
141 #endif
142  new QApplication(argc, argv);
143  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHSCREENWIZARD);
144 
145  int retval;
146  QString mask("general");
147  if ((retval = cmdline.ConfigureLogging(mask, false)) != GENERIC_EXIT_OK)
148  return retval;
149 
150  CleanupGuard callCleanup(cleanup);
151 
152 #ifndef _WIN32
153  QList<int> signallist;
154  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
155  << SIGILL;
156 #if ! CONFIG_DARWIN
157  signallist << SIGRTMIN;
158 #endif
159  SignalHandler::Init(signallist);
160  signal(SIGHUP, SIG_IGN);
161 #endif
162 
163 
164  if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
165  return retval;
166 
167  if (!cmdline.toString("display").isEmpty())
168  {
170  }
171 
173  if (!gContext->Init(true, false, true))
174  {
175  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
177  }
178 
179  if (gCoreContext->GetBoolSetting("RunFrontendInWindow"))
180  {
181  LOG(VB_GENERAL, LOG_WARNING, LOC +
182  "Refusing to run screen setup wizard in windowed mode.");
183  return GENERIC_EXIT_NOT_OK;
184  }
185 
186  int GuiOffsetX = gCoreContext->GetNumSetting("GuiOffsetX", 0);
187  int GuiOffsetY = gCoreContext->GetNumSetting("GuiOffsetY", 0);
188  int GuiWidth = gCoreContext->GetNumSetting("GuiWidth", 0);
189  int GuiHeight = gCoreContext->GetNumSetting("GuiHeight", 0);
190 
191  gCoreContext->OverrideSettingForSession("GuiOffsetX", "0");
192  gCoreContext->OverrideSettingForSession("GuiOffsetY", "0");
193  gCoreContext->OverrideSettingForSession("GuiWidth", "0");
194  gCoreContext->OverrideSettingForSession("GuiHeight", "0");
195 
197 
198  GetMythUI()->LoadQtConfig();
199 
200  QString themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);
201  QString themedir = GetMythUI()->FindThemeDir(themename);
202  if (themedir.isEmpty())
203  {
204  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find theme '%1'")
205  .arg(themename));
206  return GENERIC_EXIT_NO_THEME;
207  }
208 
209  MythMainWindow *mainWindow = GetMythMainWindow();
210 #if CONFIG_DARWIN
211  mainWindow->Init(OPENGL2_PAINTER);
212 #else
213  mainWindow->Init();
214 #endif
215  mainWindow->setWindowTitle(QObject::tr("MythTV Screen Setup Wizard"));
216 
217  // We must reload the translation after a language change and this
218  // also means clearing the cached/loaded theme strings, so reload the
219  // theme which also triggers a translation reload
220 /* if (LanguageSelection::prompt())
221  {
222  if (!reloadTheme())
223  return GENERIC_EXIT_NO_THEME;
224  }
225 */
226 
227 /* I don't think we need to connect to the backend
228  if (!gCoreContext->ConnectToMasterServer())
229  {
230  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
231  return GENERIC_EXIT_CONNECT_ERROR;
232  }
233 
234  MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler();
235 */
236 
238  int exitCode = qApp->exec();
239 
240 /*
241  if (sysEventHandler)
242  delete sysEventHandler;
243 */
244 
245  return exitCode ? exitCode : GENERIC_EXIT_OK;
246 }
247 
248 /* vim: set expandtab tabstop=4 shiftwidth=4: */
bool Create(void) override
Startup context for MythTV.
Definition: mythcontext.h:42
QString FindThemeDir(const QString &themename, bool doFallback=true)
Returns the full path to the theme denoted by themename.
static QString themedir
Definition: mythdirs.cpp:21
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.
void PrintHelp(void) const
Print command line option help.
static void Init(QList< int > &signallist, QObject *parent=nullptr)
void DestroyMythMainWindow(void)
#define DEFAULT_UI_THEME
Definition: mythuihelper.h:12
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define MYTH_APPNAME_MYTHSCREENWIZARD
MythScreenStack * GetMainStack()
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 void SetX11Display(const QString &display)
This needs to be set before MythUIHelper is initialized so that the MythUIHelper::Init() can detect X...
#define OPENGL2_PAINTER
Definition: mythuidefines.h:4
void ApplySettingsOverride(void)
Apply all overrides to the global context.
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
static HostSpinBoxSetting * GuiWidth()
void OverrideSettingForSession(const QString &key, const QString &value)
QString GetSetting(const QString &key, const QString &defaultval="")
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
static void Done(void)
MythCommFlagCommandLineParser cmdline
static void startAppearWiz(int _x, int _y, int _w, int _h)
MythUIHelper * GetMythUI()
void SetInitialSettings(int _x, int _y, int _w, int _h)
static void PrintDebug(void)
Print out any leaks if that level of debugging is enabled.
MythMainWindow * GetMythMainWindow(void)
int GetNumSetting(const QString &key, int defaultval=0)
static HostSpinBoxSetting * GuiOffsetX()
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool GetBoolSetting(const QString &key, bool defaultval=false)
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
static HostSpinBoxSetting * GuiOffsetY()
static void cleanup(VideoFilter *filter)
#define SIGHUP
Definition: compat.h:213
static HostSpinBoxSetting * GuiHeight()
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
#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)
#define GENERIC_EXIT_NO_THEME
No Theme available.
Definition: exitcodes.h:14
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
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
#define GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:11
int main(int argc, char **argv)
void PrintVersion(void) const
Print application version information.