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 #include "cleanupguard.h"
40 #include "mythdisplay.h"
41 
42 #define LOC QString("MythScreenWizard: ")
43 #define LOC_WARN QString("MythScreenWizard, Warning: ")
44 #define LOC_ERR QString("MythScreenWizard, Error: ")
45 
46 using namespace std;
47 
48 namespace
49 {
50  void cleanup()
51  {
53 
54  delete gContext;
55  gContext = nullptr;
56 
58 
59  delete qApp;
60 
62  }
63 }
64 
65 // If the theme specified in the DB is somehow broken, try a standard one:
66 //
67 /*
68 static bool resetTheme(QString themedir, const QString badtheme)
69 {
70  QString themename = DEFAULT_UI_THEME;
71 
72  if (badtheme == DEFAULT_UI_THEME)
73  themename = FALLBACK_UI_THEME;
74 
75  LOG(VB_GENERAL, LOG_ERR,
76  QString("Overriding broken theme '%1' with '%2'")
77  .arg(badtheme).arg(themename));
78 
79  gCoreContext->OverrideSettingForSession("Theme", themename);
80  themedir = GetMythUI()->FindThemeDir(themename);
81 
82  MythTranslation::reload();
83  GetMythUI()->LoadQtConfig();
84  GetMythMainWindow()->Init();
85  GetMythMainWindow()->ReinitDone();
86 
87  return RunMenu(themedir, themename);
88 }
89 */
90 static void startAppearWiz(int _x, int _y, int _w, int _h)
91 {
93 
94  auto *screenwizard = new ScreenWizard(mainStack, "screenwizard");
95  screenwizard->SetInitialSettings(_x, _y, _w, _h);
96 
97  if (screenwizard->Create())
98  mainStack->AddScreen(screenwizard);
99  else
100  delete screenwizard;
101 }
102 
103 int main(int argc, char **argv)
104 {
106  if (!cmdline.Parse(argc, argv))
107  {
108  cmdline.PrintHelp();
110  }
111 
112  if (cmdline.toBool("showhelp"))
113  {
114  cmdline.PrintHelp();
115  return GENERIC_EXIT_OK;
116  }
117 
118  if (cmdline.toBool("showversion"))
119  {
121  return GENERIC_EXIT_OK;
122  }
123 
125  new QApplication(argc, argv);
126  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHSCREENWIZARD);
127 
128  QString mask("general");
129  int retval = cmdline.ConfigureLogging(mask, false);
130  if (retval != GENERIC_EXIT_OK)
131  return retval;
132 
133  CleanupGuard callCleanup(cleanup);
134 
135 #ifndef _WIN32
136  QList<int> signallist;
137  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
138  << SIGILL;
139 #if ! CONFIG_DARWIN
140  signallist << SIGRTMIN;
141 #endif
142  SignalHandler::Init(signallist);
143  signal(SIGHUP, SIG_IGN);
144 #endif
145 
146 
147  if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
148  return retval;
149 
150  if (!cmdline.toString("display").isEmpty())
151  {
153  }
154 
156  if (!gContext->Init(true, false, true))
157  {
158  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
160  }
161 
162  if (gCoreContext->GetBoolSetting("RunFrontendInWindow"))
163  {
164  LOG(VB_GENERAL, LOG_WARNING, LOC +
165  "Refusing to run screen setup wizard in windowed mode.");
166  return GENERIC_EXIT_NOT_OK;
167  }
168 
169  int GuiOffsetX = gCoreContext->GetNumSetting("GuiOffsetX", 0);
170  int GuiOffsetY = gCoreContext->GetNumSetting("GuiOffsetY", 0);
171  int GuiWidth = gCoreContext->GetNumSetting("GuiWidth", 0);
172  int GuiHeight = gCoreContext->GetNumSetting("GuiHeight", 0);
173 
174  gCoreContext->OverrideSettingForSession("GuiOffsetX", "0");
175  gCoreContext->OverrideSettingForSession("GuiOffsetY", "0");
176  gCoreContext->OverrideSettingForSession("GuiWidth", "0");
177  gCoreContext->OverrideSettingForSession("GuiHeight", "0");
178 
180 
181  GetMythUI()->LoadQtConfig();
182 
183  QString themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);
184  QString themedir = GetMythUI()->FindThemeDir(themename);
185  if (themedir.isEmpty())
186  {
187  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find theme '%1'")
188  .arg(themename));
189  return GENERIC_EXIT_NO_THEME;
190  }
191 
192  MythMainWindow *mainWindow = GetMythMainWindow();
193  mainWindow->Init();
194  mainWindow->setWindowTitle(QObject::tr("MythTV Screen Setup Wizard"));
195 
196  // We must reload the translation after a language change and this
197  // also means clearing the cached/loaded theme strings, so reload the
198  // theme which also triggers a translation reload
199 /* if (LanguageSelection::prompt())
200  {
201  if (!reloadTheme())
202  return GENERIC_EXIT_NO_THEME;
203  }
204 */
205 
206 /* I don't think we need to connect to the backend
207  if (!gCoreContext->ConnectToMasterServer())
208  {
209  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
210  return GENERIC_EXIT_CONNECT_ERROR;
211  }
212 
213  MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler();
214 */
215 
217  int exitCode = qApp->exec();
218 
219 /*
220  if (sysEventHandler)
221  delete sysEventHandler;
222 */
223 
224  return exitCode ? exitCode : GENERIC_EXIT_OK;
225 }
226 
227 /* vim: set expandtab tabstop=4 shiftwidth=4: */
static void ConfigureQtGUI(int SwapInterval=1)
Shared static initialistaion code for all MythTV GUI applications.
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.
static void PrintVersion(void)
Print application version information.
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:62
static void SetX11Display(const QString &display)
This needs to be set before MythUIHelper is initialized so that the MythUIHelper::Init() can detect X...
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()
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()
#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
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
static QString cleanup(const QString &str)
#define GENERIC_EXIT_NO_THEME
No Theme available.
Definition: exitcodes.h:14
#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
void Init(bool mayReInit=true)
#define GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:11
int main(int argc, char **argv)
int ConfigureLogging(const QString &mask="general", unsigned int progress=0)
Read in logging options and initialize the logging interface.