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 <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// Qt
15#include <QtGlobal>
16#include <QApplication>
17#include <QDir>
18#include <QEvent>
19#include <QFileInfo>
20#include <QKeyEvent>
21#include <QString>
22#include <QWidget>
23
24// MythTV
26#include "libmyth/mythcontext.h"
27#include "libmythbase/compat.h"
34#include "libmythbase/mythversion.h"
39
40// MythScreenWizard
42#include "screenwizard.h"
43
44#define LOC QString("MythScreenWizard: ")
45#define LOC_WARN QString("MythScreenWizard, Warning: ")
46#define LOC_ERR QString("MythScreenWizard, Error: ")
47
48// If the theme specified in the DB is somehow broken, try a standard one:
49//
50/*
51static bool resetTheme(QString themedir, const QString badtheme)
52{
53 QString themename = DEFAULT_UI_THEME;
54
55 if (badtheme == DEFAULT_UI_THEME)
56 themename = FALLBACK_UI_THEME;
57
58 LOG(VB_GENERAL, LOG_ERR,
59 QString("Overriding broken theme '%1' with '%2'")
60 .arg(badtheme).arg(themename));
61
62 gCoreContext->OverrideSettingForSession("Theme", themename);
63 themedir = GetMythUI()->FindThemeDir(themename);
64
65 MythTranslation::reload();
66 GetMythUI()->LoadQtConfig();
67 GetMythMainWindow()->Init();
68
69 return RunMenu(themedir, themename);
70}
71*/
72static void startAppearWiz(int _x, int _y, int _w, int _h)
73{
75
76 auto *screenwizard = new ScreenWizard(mainStack, "screenwizard");
77 screenwizard->SetInitialSettings(_x, _y, _w, _h);
78
79 if (screenwizard->Create())
80 mainStack->AddScreen(screenwizard);
81 else
82 delete screenwizard;
83}
84
85int main(int argc, char **argv)
86{
88 if (!cmdline.Parse(argc, argv))
89 {
92 }
93
94 if (cmdline.toBool("showhelp"))
95 {
97 return GENERIC_EXIT_OK;
98 }
99
100 if (cmdline.toBool("showversion"))
101 {
103 return GENERIC_EXIT_OK;
104 }
105
107 QApplication a(argc, argv);
108 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHSCREENWIZARD);
109
110 QString mask("general");
111 int retval = cmdline.ConfigureLogging(mask, false);
112 if (retval != GENERIC_EXIT_OK)
113 return retval;
114
115 retval = cmdline.ConfigureLogging();
116 if (retval != GENERIC_EXIT_OK)
117 return retval;
118
119 MythContext context {MYTH_BINARY_VERSION};
120 if (!context.Init(true, false, true))
121 {
122 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
124 }
125
126 if (gCoreContext->GetBoolSetting("RunFrontendInWindow"))
127 {
128 LOG(VB_GENERAL, LOG_WARNING, LOC +
129 "Refusing to run screen setup wizard in windowed mode.");
130 return GENERIC_EXIT_NOT_OK;
131 }
132
133 int GuiOffsetX = gCoreContext->GetNumSetting("GuiOffsetX", 0);
134 int GuiOffsetY = gCoreContext->GetNumSetting("GuiOffsetY", 0);
135 int GuiWidth = gCoreContext->GetNumSetting("GuiWidth", 0);
136 int GuiHeight = gCoreContext->GetNumSetting("GuiHeight", 0);
137
138 gCoreContext->OverrideSettingForSession("GuiOffsetX", "0");
139 gCoreContext->OverrideSettingForSession("GuiOffsetY", "0");
140 gCoreContext->OverrideSettingForSession("GuiWidth", "0");
141 gCoreContext->OverrideSettingForSession("GuiHeight", "0");
142
144
145 QString themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);
146 QString themedir = GetMythUI()->FindThemeDir(themename);
147 if (themedir.isEmpty())
148 {
149 LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find theme '%1'")
150 .arg(themename));
152 }
153
154 MythMainWindow *mainWindow = GetMythMainWindow();
155 mainWindow->Init();
156 mainWindow->setWindowTitle(QObject::tr("MythTV Screen Setup Wizard"));
157
158 // We must reload the translation after a language change and this
159 // also means clearing the cached/loaded theme strings, so reload the
160 // theme which also triggers a translation reload
161/* if (LanguageSelection::prompt())
162 {
163 if (!reloadTheme())
164 return GENERIC_EXIT_NO_THEME;
165 }
166*/
167
168/* I don't think we need to connect to the backend
169 if (!gCoreContext->ConnectToMasterServer())
170 {
171 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
172 return GENERIC_EXIT_CONNECT_ERROR;
173 }
174
175 MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler();
176*/
177
179 int exitCode = QCoreApplication::exec();
180
181/*
182 if (sysEventHandler)
183 delete sysEventHandler;
184*/
185
186 return exitCode ? exitCode : GENERIC_EXIT_OK;
187}
188
189/* vim: set expandtab tabstop=4 shiftwidth=4: */
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
void ApplySettingsOverride(void)
Apply all overrides to the global context.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
static void PrintVersion(void)
Print application version information.
void PrintHelp(void) const
Print command line option help.
Startup context for MythTV.
Definition: mythcontext.h:20
QString GetSetting(const QString &key, const QString &defaultval="")
void OverrideSettingForSession(const QString &key, const QString &value)
int GetNumSetting(const QString &key, int defaultval=0)
bool GetBoolSetting(const QString &key, bool defaultval=false)
static void ConfigureQtGUI(int SwapInterval, const MythCommandLineParser &CmdLine)
Shared static initialisation code for all MythTV GUI applications.
MythScreenStack * GetMainStack()
void Init(bool MayReInit=true)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString FindThemeDir(const QString &ThemeName, bool Fallback=true)
Returns the full path to the theme denoted by themename.
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_NO_THEME
No Theme available.
Definition: exitcodes.h:17
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:14
static HostSpinBoxSetting * GuiHeight()
static HostSpinBoxSetting * GuiWidth()
static HostSpinBoxSetting * GuiOffsetX()
static HostSpinBoxSetting * GuiOffsetY()
static constexpr const char * MYTH_APPNAME_MYTHSCREENWIZARD
Definition: mythappname.h:20
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static QString themedir
Definition: mythdirs.cpp:23
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
#define LOC
int main(int argc, char **argv)
static void startAppearWiz(int _x, int _y, int _w, int _h)
MythUIHelper * GetMythUI()
static constexpr const char * DEFAULT_UI_THEME
MythCommFlagCommandLineParser cmdline