MythTV  master
mythscreenwizard.cpp
Go to the documentation of this file.
1 // C/C++
2 #include <cmath>
3 #include <csignal>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <ctime>
7 #include <fcntl.h>
8 #include <fstream>
9 #include <iostream>
10 #include <string>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13 #include <unistd.h>
14 
15 // Qt
16 #include <QtGlobal>
17 #include <QApplication>
18 #include <QDir>
19 #include <QEvent>
20 #include <QFileInfo>
21 #include <QKeyEvent>
22 #include <QString>
23 #include <QWidget>
24 
25 // MythTV
26 #include "libmyth/langsettings.h"
27 #include "libmyth/mythcontext.h"
29 #include "libmythbase/compat.h"
30 #include "libmythbase/exitcodes.h"
32 #include "libmythbase/mythdbcon.h"
35 #include "libmythbase/mythversion.h"
38 #include "libmythui/mythdisplay.h"
40 #include "libmythui/mythuihelper.h"
41 
42 // MythScreenWizard
44 #include "screenwizard.h"
45 
46 #define LOC QString("MythScreenWizard: ")
47 #define LOC_WARN QString("MythScreenWizard, Warning: ")
48 #define LOC_ERR QString("MythScreenWizard, Error: ")
49 
50 namespace
51 {
52  void cleanup()
53  {
55 
56  delete gContext;
57  gContext = nullptr;
58 
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 
86  return RunMenu(themedir, themename);
87 }
88 */
89 static void startAppearWiz(int _x, int _y, int _w, int _h)
90 {
92 
93  auto *screenwizard = new ScreenWizard(mainStack, "screenwizard");
94  screenwizard->SetInitialSettings(_x, _y, _w, _h);
95 
96  if (screenwizard->Create())
97  mainStack->AddScreen(screenwizard);
98  else
99  delete screenwizard;
100 }
101 
102 int main(int argc, char **argv)
103 {
105  if (!cmdline.Parse(argc, argv))
106  {
107  cmdline.PrintHelp();
109  }
110 
111  if (cmdline.toBool("showhelp"))
112  {
113  cmdline.PrintHelp();
114  return GENERIC_EXIT_OK;
115  }
116 
117  if (cmdline.toBool("showversion"))
118  {
120  return GENERIC_EXIT_OK;
121  }
122 
124  QApplication a(argc, argv);
125  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHSCREENWIZARD);
126 
127  QString mask("general");
128  int retval = cmdline.ConfigureLogging(mask, false);
129  if (retval != GENERIC_EXIT_OK)
130  return retval;
131 
132  CleanupGuard callCleanup(cleanup);
133 
134 #ifndef _WIN32
136 #endif
137 
138 
139  if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
140  return retval;
141 
142  gContext = new MythContext(MYTH_BINARY_VERSION);
143  if (!gContext->Init(true, false, true))
144  {
145  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
147  }
148 
149  if (gCoreContext->GetBoolSetting("RunFrontendInWindow"))
150  {
151  LOG(VB_GENERAL, LOG_WARNING, LOC +
152  "Refusing to run screen setup wizard in windowed mode.");
153  return GENERIC_EXIT_NOT_OK;
154  }
155 
156  int GuiOffsetX = gCoreContext->GetNumSetting("GuiOffsetX", 0);
157  int GuiOffsetY = gCoreContext->GetNumSetting("GuiOffsetY", 0);
158  int GuiWidth = gCoreContext->GetNumSetting("GuiWidth", 0);
159  int GuiHeight = gCoreContext->GetNumSetting("GuiHeight", 0);
160 
161  gCoreContext->OverrideSettingForSession("GuiOffsetX", "0");
162  gCoreContext->OverrideSettingForSession("GuiOffsetY", "0");
163  gCoreContext->OverrideSettingForSession("GuiWidth", "0");
164  gCoreContext->OverrideSettingForSession("GuiHeight", "0");
165 
167 
168  QString themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);
169  QString themedir = GetMythUI()->FindThemeDir(themename);
170  if (themedir.isEmpty())
171  {
172  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find theme '%1'")
173  .arg(themename));
174  return GENERIC_EXIT_NO_THEME;
175  }
176 
177  MythMainWindow *mainWindow = GetMythMainWindow();
178  mainWindow->Init();
179  mainWindow->setWindowTitle(QObject::tr("MythTV Screen Setup Wizard"));
180 
181  // We must reload the translation after a language change and this
182  // also means clearing the cached/loaded theme strings, so reload the
183  // theme which also triggers a translation reload
184 /* if (LanguageSelection::prompt())
185  {
186  if (!reloadTheme())
187  return GENERIC_EXIT_NO_THEME;
188  }
189 */
190 
191 /* I don't think we need to connect to the backend
192  if (!gCoreContext->ConnectToMasterServer())
193  {
194  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
195  return GENERIC_EXIT_CONNECT_ERROR;
196  }
197 
198  MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler();
199 */
200 
202  int exitCode = QCoreApplication::exec();
203 
204 /*
205  if (sysEventHandler)
206  delete sysEventHandler;
207 */
208 
209  return exitCode ? exitCode : GENERIC_EXIT_OK;
210 }
211 
212 /* vim: set expandtab tabstop=4 shiftwidth=4: */
themedir
static QString themedir
Definition: mythdirs.cpp:23
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:318
MythMainWindow::Init
void Init(bool MayReInit=true)
Definition: mythmainwindow.cpp:641
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:72
MythContext
Startup context for MythTV.
Definition: mythcontext.h:43
MythCoreContext::OverrideSettingForSession
void OverrideSettingForSession(const QString &key, const QString &value)
Definition: mythcorecontext.cpp:1336
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
ReferenceCounter::PrintDebug
static void PrintDebug(void)
Print out any leaks if that level of debugging is enabled.
Definition: referencecounter.cpp:72
GuiHeight
static HostSpinBoxSetting * GuiHeight()
Definition: globalsettings.cpp:2260
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
mythsystemevent.h
LOC
#define LOC
Definition: mythscreenwizard.cpp:46
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:11
MythScreenWizardCommandLineParser
Definition: mythscreenwizard_commandlineparser.h:6
langsettings.h
MythDisplay::ConfigureQtGUI
static void ConfigureQtGUI(int SwapInterval, const MythCommandLineParser &CmdLine)
Shared static initialisation code for all MythTV GUI applications.
Definition: mythdisplay.cpp:1158
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1554
mythdisplay.h
mythlogging.h
GENERIC_EXIT_NO_MYTHCONTEXT
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:14
signalhandling.h
CleanupGuard
Definition: cleanupguard.h:6
compat.h
startAppearWiz
static void startAppearWiz(int _x, int _y, int _w, int _h)
Definition: mythscreenwizard.cpp:89
DestroyMythMainWindow
void DestroyMythMainWindow(void)
Definition: mythmainwindow.cpp:114
MythUIThemeHelper::FindThemeDir
QString FindThemeDir(const QString &ThemeName, bool Fallback=true)
Returns the full path to the theme denoted by themename.
Definition: mythuithemehelper.cpp:48
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1382
mythtranslation.h
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1398
GENERIC_EXIT_NO_THEME
@ GENERIC_EXIT_NO_THEME
No Theme available.
Definition: exitcodes.h:15
GENERIC_EXIT_NOT_OK
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:12
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
MythCommandLineParser::ApplySettingsOverride
void ApplySettingsOverride(void)
Apply all overrides to the global context.
Definition: mythcommandlineparser.cpp:2932
GuiOffsetY
static HostSpinBoxSetting * GuiOffsetY()
Definition: globalsettings.cpp:2290
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:911
cleanup
static QString cleanup(const QString &str)
Definition: remoteencoder.cpp:673
GuiOffsetX
static HostSpinBoxSetting * GuiOffsetX()
Definition: globalsettings.cpp:2276
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:905
mythuihelper.h
SignalHandler::Init
static void Init(QObject *parent=nullptr)
Definition: signalhandling.cpp:127
DEFAULT_UI_THEME
static constexpr const char * DEFAULT_UI_THEME
Definition: mythuithemehelper.h:7
mythscreenwizard_commandlineparser.h
mythcorecontext.h
ScreenWizard
Definition: screenwizard.h:18
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2202
cleanupguard.h
MYTH_APPNAME_MYTHSCREENWIZARD
static constexpr const char * MYTH_APPNAME_MYTHSCREENWIZARD
Definition: mythcorecontext.h:36
main
int main(int argc, char **argv)
Definition: mythscreenwizard.cpp:102
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
screenwizard.h
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2864
exitcodes.h
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:66
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:16
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
gContext
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:64
MythContext::Init
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: mythcontext.cpp:1603
MythMainWindow
Definition: mythmainwindow.h:28
GuiWidth
static HostSpinBoxSetting * GuiWidth()
Definition: globalsettings.cpp:2244
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:134
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:897