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  retval = cmdline.ConfigureLogging();
140  if (retval != GENERIC_EXIT_OK)
141  return retval;
142 
143  gContext = new MythContext(MYTH_BINARY_VERSION);
144  if (!gContext->Init(true, false, true))
145  {
146  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
148  }
149 
150  if (gCoreContext->GetBoolSetting("RunFrontendInWindow"))
151  {
152  LOG(VB_GENERAL, LOG_WARNING, LOC +
153  "Refusing to run screen setup wizard in windowed mode.");
154  return GENERIC_EXIT_NOT_OK;
155  }
156 
157  int GuiOffsetX = gCoreContext->GetNumSetting("GuiOffsetX", 0);
158  int GuiOffsetY = gCoreContext->GetNumSetting("GuiOffsetY", 0);
159  int GuiWidth = gCoreContext->GetNumSetting("GuiWidth", 0);
160  int GuiHeight = gCoreContext->GetNumSetting("GuiHeight", 0);
161 
162  gCoreContext->OverrideSettingForSession("GuiOffsetX", "0");
163  gCoreContext->OverrideSettingForSession("GuiOffsetY", "0");
164  gCoreContext->OverrideSettingForSession("GuiWidth", "0");
165  gCoreContext->OverrideSettingForSession("GuiHeight", "0");
166 
168 
169  QString themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);
170  QString themedir = GetMythUI()->FindThemeDir(themename);
171  if (themedir.isEmpty())
172  {
173  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find theme '%1'")
174  .arg(themename));
175  return GENERIC_EXIT_NO_THEME;
176  }
177 
178  MythMainWindow *mainWindow = GetMythMainWindow();
179  mainWindow->Init();
180  mainWindow->setWindowTitle(QObject::tr("MythTV Screen Setup Wizard"));
181 
182  // We must reload the translation after a language change and this
183  // also means clearing the cached/loaded theme strings, so reload the
184  // theme which also triggers a translation reload
185 /* if (LanguageSelection::prompt())
186  {
187  if (!reloadTheme())
188  return GENERIC_EXIT_NO_THEME;
189  }
190 */
191 
192 /* I don't think we need to connect to the backend
193  if (!gCoreContext->ConnectToMasterServer())
194  {
195  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
196  return GENERIC_EXIT_CONNECT_ERROR;
197  }
198 
199  MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler();
200 */
201 
203  int exitCode = QCoreApplication::exec();
204 
205 /*
206  if (sysEventHandler)
207  delete sysEventHandler;
208 */
209 
210  return exitCode ? exitCode : GENERIC_EXIT_OK;
211 }
212 
213 /* 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:642
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:1337
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:2272
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:1544
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:1372
mythtranslation.h
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1388
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:2916
GuiOffsetY
static HostSpinBoxSetting * GuiOffsetY()
Definition: globalsettings.cpp:2302
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:912
cleanup
static QString cleanup(const QString &str)
Definition: remoteencoder.cpp:673
GuiOffsetX
static HostSpinBoxSetting * GuiOffsetX()
Definition: globalsettings.cpp:2288
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:906
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:2187
cleanupguard.h
MYTH_APPNAME_MYTHSCREENWIZARD
static constexpr const char * MYTH_APPNAME_MYTHSCREENWIZARD
Definition: mythcorecontext.h:35
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:2849
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:2256
SignalHandler::Done
static void Done(void)
Definition: signalhandling.cpp:134
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898