MythTV  master
setupwizard_general.cpp
Go to the documentation of this file.
1 // qt
2 #include <QString>
3 #include <QVariant>
4 
5 // myth
6 #include "mythcontext.h"
7 #include "mythsystemlegacy.h"
8 #include "mythdbcon.h"
9 #include "mythdirs.h"
10 
11 #include "hardwareprofile.h"
12 
13 #include "audiogeneralsettings.h"
14 #include "setupwizard_general.h"
15 #include "setupwizard_audio.h"
16 
17 // ---------------------------------------------------
18 
20  : MythScreenType(parent, name)
21 {
22  m_popupStack = GetMythMainWindow()->GetStack("popup stack");
24 }
25 
27 {
28  // Load the theme for this screen
29  bool foundtheme = LoadWindowFromXML("config-ui.xml", "generalwizard", this);
30  if (!foundtheme)
31  return false;
32 
33  m_submitButton = dynamic_cast<MythUIButton *> (GetChild("submit"));
34  m_viewButton = dynamic_cast<MythUIButton *> (GetChild("view"));
35  m_deleteButton = dynamic_cast<MythUIButton *> (GetChild("delete"));
36 
37  m_nextButton = dynamic_cast<MythUIButton *> (GetChild("next"));
38  m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));
39 
40  m_profileLocation = dynamic_cast<MythUIText *> (GetChild("profiletext"));
41  m_adminPassword = dynamic_cast<MythUIText *> (GetChild("profilepassword"));
42 
45  {
46  LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
47  return false;
48  }
49 
50  m_submitButton->SetHelpText( tr("Anonymously submit a profile of your hardware. "
51  "This helps the developers to determine where "
52  "to focus their efforts.") );
53  m_viewButton->SetHelpText( tr("Visit your online hardware profile. (This requires "
54  "that you have the MythBrowser plugin installed)") );
55  m_deleteButton->SetHelpText( tr("Delete your online hardware profile.") );
56 
57  m_nextButton->SetHelpText( tr("Save these changes and move on to the "
58  "next configuration step.") );
59  m_cancelButton->SetHelpText( tr("Exit this wizard, save no changes.") );
60 
61  connect(m_submitButton, SIGNAL(Clicked()), this, SLOT(slotSubmit()));
62  connect(m_viewButton, SIGNAL(Clicked()), this, SLOT(slotView()));
63  connect(m_deleteButton, SIGNAL(Clicked()), this, SLOT(slotDelete()));
64 
65  connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(slotNext()));
66  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
67 
69  loadData();
70 
71 #ifndef __linux__
72 #ifndef CONFIG_BINDINGS_PYTHON
73  // The hardware profiler only works on linux.
74  // Make the widgets invisible on other platforms.
75 
77  m_viewButton->Hide();
79 
82 
83  if (m_adminPassword)
85 #endif
86 #endif
87 
88  return true;
89 }
90 
92 {
93  if (!m_hardwareProfile)
94  return;
95 
97 
100 
101  if (m_adminPassword)
103 }
104 
106 {
107  save();
108 
110  auto *sw = new AudioSetupWizard(mainStack, this, "audiosetupwizard");
111 
112  if (sw->Create())
113  {
114  mainStack->AddScreen(sw);
115  }
116  else
117  delete sw;
118 }
119 
121 {
122  QString message = tr("Would you like to share your "
123  "hardware profile with the MythTV developers? "
124  "Profiles are anonymous and are a great way to "
125  "help with future development.");
126  auto *confirmdialog = new MythConfirmationDialog(m_popupStack,message);
127 
128  if (confirmdialog->Create())
129  m_popupStack->AddScreen(confirmdialog);
130 
131  connect(confirmdialog, SIGNAL(haveResult(bool)),
132  SLOT(OnSubmitPromptReturn(bool)));
133 }
134 
136 {
137  if (submit)
138  {
139  CreateBusyDialog(tr("Submitting your hardware profile..."));
141  {
142  if (m_busyPopup)
143  {
144  m_busyPopup->Close();
145  m_busyPopup = nullptr;
146  }
147  ShowOkPopup(tr("Hardware profile submitted. Thank you for supporting "
148  "MythTV!"));
149  if (m_profileLocation)
151  if (m_adminPassword)
153  }
154  else
155  {
156  if (m_busyPopup)
157  {
158  m_busyPopup->Close();
159  m_busyPopup = nullptr;
160  }
161  ShowOkPopup(tr("Encountered a problem while submitting your profile."));
162  }
163  }
164 }
165 
167 {
168  if (gCoreContext->GetSetting("HardwareProfilePublicUUID").isEmpty())
169  {
170  ShowOkPopup(tr("You haven't submitted your hardware profile yet! "
171  "Please submit your profile to visit it online."));
172  return;
173  }
174 
175  QString url = m_hardwareProfile->GetProfileURL();
176 
177  LOG(VB_GENERAL, LOG_DEBUG, QString("Profile URL = %1").arg(url));
178 
179  if (url.isEmpty())
180  return;
181 
182  QString browser = gCoreContext->GetSetting("WebBrowserCommand", "");
183  QString zoom = gCoreContext->GetSetting("WebBrowserZoomLevel", "1.0");
184 
185  if (browser.isEmpty())
186  {
187  ShowOkPopup(tr("No browser command set! MythTV needs a browser "
188  "installed and configure to display your hardware "
189  "profile."));
190  return;
191  }
192 
193  if (browser.toLower() == "internal")
194  {
195  GetMythMainWindow()->HandleMedia("WebBrowser", url);
196  return;
197  }
198 
199  QString cmd = browser;
200  cmd.replace("%ZOOM%", zoom);
201  cmd.replace("%URL%", url);
202  cmd.replace('\'', "%27");
203  cmd.replace("&","\\&");
204  cmd.replace(";","\\;");
205 
206  GetMythMainWindow()->AllowInput(false);
208  GetMythMainWindow()->AllowInput(true);
209 }
210 
212 {
213  if (gCoreContext->GetSetting("HardwareProfileUUID").isEmpty())
214  {
215  ShowOkPopup(tr("You haven't submitted your hardware profile yet!"));
216  return;
217  }
218 
219  QString message = tr("Are you sure you want to delete "
220  "your online profile? Your information "
221  "is anonymous and helps the developers "
222  "to know what hardware the majority of users "
223  "prefer.");
224  auto *confirmdialog = new MythConfirmationDialog(m_popupStack,message);
225 
226  if (confirmdialog->Create())
227  m_popupStack->AddScreen(confirmdialog);
228 
229  connect(confirmdialog, SIGNAL(haveResult(bool)),
230  SLOT(OnDeletePromptReturn(bool)));
231 }
232 
234 {
235  if (submit)
236  {
237  CreateBusyDialog(tr("Deleting your hardware profile..."));
239  {
240  if (m_busyPopup)
241  {
242  m_busyPopup->Close();
243  m_busyPopup = nullptr;
244  }
245  ShowOkPopup(tr("Hardware profile deleted."));
246  if (m_profileLocation)
248  if (m_adminPassword)
250  }
251  else
252  {
253  if (m_busyPopup)
254  {
255  m_busyPopup->Close();
256  m_busyPopup = nullptr;
257  }
258  ShowOkPopup(tr("Encountered a problem while deleting your profile."));
259  }
260  }
261 }
262 
264 {
265 }
266 
267 bool GeneralSetupWizard::keyPressEvent(QKeyEvent *event)
268 {
269  if (GetFocusWidget()->keyPressEvent(event))
270  return true;
271 
272  bool handled = false;
273 
275  handled = true;
276 
277  return handled;
278 }
279 
280 void GeneralSetupWizard::CreateBusyDialog(const QString& message)
281 {
282  if (m_busyPopup)
283  return;
284 
286  "setupwizardbusydialog");
287 
288  if (m_busyPopup->Create())
290 }
MythUIButton * m_cancelButton
Dialog asking for user confirmation.
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
MythUIText * m_profileLocation
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
void AllowInput(bool allow)
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
MythUIButton * m_viewButton
void BuildFocusList(void)
MythUIButton * m_nextButton
void CreateBusyDialog(const QString &message)
void Hide(void)
virtual void Close()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void SetHelpText(const QString &text)
Definition: mythuitype.h:150
bool Create(void) override
HardwareProfile * m_hardwareProfile
QString GetSetting(const QString &key, const QString &defaultval="")
MythUIButton * m_deleteButton
bool Create(void) override
MythUIButton * m_submitButton
uint myth_system(const QString &command, uint flags, uint timeout)
void GenerateUUIDs(void)
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
QString GetProfileURL(void) const
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool SubmitProfile(bool updateTime=true)
MythUIBusyDialog * m_busyPopup
avoid disabling UI drawing
Definition: mythsystem.h:35
void OnSubmitPromptReturn(bool submit)
void OnDeletePromptReturn(bool submit)
MythUIText * m_adminPassword
static QString GetAdminPasswordFromFile(void)
bool HandleMedia(const QString &handler, const QString &mrl, const QString &plot="", const QString &title="", const QString &subtitle="", const QString &director="", int season=0, int episode=0, const QString &inetref="", int lenMins=120, const QString &year="1895", const QString &id="", bool useBookmarks=false)
Screen in which all other widgets are contained and rendered.
MythScreenStack * m_popupStack
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
GeneralSetupWizard(MythScreenStack *parent, const char *name=nullptr)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
bool DeleteProfile(void)