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 
60  }
61 }
62 
63 // If the theme specified in the DB is somehow broken, try a standard one:
64 //
65 /*
66 static bool resetTheme(QString themedir, const QString badtheme)
67 {
68  QString themename = DEFAULT_UI_THEME;
69 
70  if (badtheme == DEFAULT_UI_THEME)
71  themename = FALLBACK_UI_THEME;
72 
73  LOG(VB_GENERAL, LOG_ERR,
74  QString("Overriding broken theme '%1' with '%2'")
75  .arg(badtheme).arg(themename));
76 
77  gCoreContext->OverrideSettingForSession("Theme", themename);
78  themedir = GetMythUI()->FindThemeDir(themename);
79 
80  MythTranslation::reload();
81  GetMythUI()->LoadQtConfig();
82  GetMythMainWindow()->Init();
83  GetMythMainWindow()->ReinitDone();
84 
85  return RunMenu(themedir, themename);
86 }
87 */
88 static void startAppearWiz(int _x, int _y, int _w, int _h)
89 {
91 
92  auto *screenwizard = new ScreenWizard(mainStack, "screenwizard");
93  screenwizard->SetInitialSettings(_x, _y, _w, _h);
94 
95  if (screenwizard->Create())
96  mainStack->AddScreen(screenwizard);
97  else
98  delete screenwizard;
99 }
100 
101 int main(int argc, char **argv)
102 {
104  if (!cmdline.Parse(argc, argv))
105  {
106  cmdline.PrintHelp();
108  }
109 
110  if (cmdline.toBool("showhelp"))
111  {
112  cmdline.PrintHelp();
113  return GENERIC_EXIT_OK;
114  }
115 
116  if (cmdline.toBool("showversion"))
117  {
119  return GENERIC_EXIT_OK;
120  }
121 
123  QApplication a(argc, argv);
124  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHSCREENWIZARD);
125 
126  QString mask("general");
127  int retval = cmdline.ConfigureLogging(mask, false);
128  if (retval != GENERIC_EXIT_OK)
129  return retval;
130 
131  CleanupGuard callCleanup(cleanup);
132 
133 #ifndef _WIN32
134  QList<int> signallist;
135  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
136  << SIGILL;
137 #if ! CONFIG_DARWIN
138  signallist << SIGRTMIN;
139 #endif
140  SignalHandler::Init(signallist);
141  signal(SIGHUP, SIG_IGN);
142 #endif
143 
144 
145  if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
146  return retval;
147 
148  if (!cmdline.toString("display").isEmpty())
149  {
151  }
152 
154  if (!gContext->Init(true, false, true))
155  {
156  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
158  }
159 
160  if (gCoreContext->GetBoolSetting("RunFrontendInWindow"))
161  {
162  LOG(VB_GENERAL, LOG_WARNING, LOC +
163  "Refusing to run screen setup wizard in windowed mode.");
164  return GENERIC_EXIT_NOT_OK;
165  }
166 
167  int GuiOffsetX = gCoreContext->GetNumSetting("GuiOffsetX", 0);
168  int GuiOffsetY = gCoreContext->GetNumSetting("GuiOffsetY", 0);
169  int GuiWidth = gCoreContext->GetNumSetting("GuiWidth", 0);
170  int GuiHeight = gCoreContext->GetNumSetting("GuiHeight", 0);
171 
172  gCoreContext->OverrideSettingForSession("GuiOffsetX", "0");
173  gCoreContext->OverrideSettingForSession("GuiOffsetY", "0");
174  gCoreContext->OverrideSettingForSession("GuiWidth", "0");
175  gCoreContext->OverrideSettingForSession("GuiHeight", "0");
176 
178 
179  GetMythUI()->LoadQtConfig();
180 
181  QString themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);
182  QString themedir = GetMythUI()->FindThemeDir(themename);
183  if (themedir.isEmpty())
184  {
185  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find theme '%1'")
186  .arg(themename));
187  return GENERIC_EXIT_NO_THEME;
188  }
189 
190  MythMainWindow *mainWindow = GetMythMainWindow();
191  mainWindow->Init();
192  mainWindow->setWindowTitle(QObject::tr("MythTV Screen Setup Wizard"));
193 
194  // We must reload the translation after a language change and this
195  // also means clearing the cached/loaded theme strings, so reload the
196  // theme which also triggers a translation reload
197 /* if (LanguageSelection::prompt())
198  {
199  if (!reloadTheme())
200  return GENERIC_EXIT_NO_THEME;
201  }
202 */
203 
204 /* I don't think we need to connect to the backend
205  if (!gCoreContext->ConnectToMasterServer())
206  {
207  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
208  return GENERIC_EXIT_CONNECT_ERROR;
209  }
210 
211  MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler();
212 */
213 
215  int exitCode = QCoreApplication::exec();
216 
217 /*
218  if (sysEventHandler)
219  delete sysEventHandler;
220 */
221 
222  return exitCode ? exitCode : GENERIC_EXIT_OK;
223 }
224 
225 /* 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 ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
int GetNumSetting(const QString &key, int defaultval=0)
static HostSpinBoxSetting * GuiOffsetX()
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)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23