00001
00002 #include <QString>
00003 #include <QVariant>
00004
00005
00006 #include "mythcontext.h"
00007 #include "mythdbcon.h"
00008 #include "mythdirs.h"
00009
00010 #include "hardwareprofile.h"
00011
00012 #include "audiogeneralsettings.h"
00013 #include "setupwizard_general.h"
00014 #include "setupwizard_audio.h"
00015
00016
00017
00018 GeneralSetupWizard::GeneralSetupWizard(MythScreenStack *parent, const char *name)
00019 : MythScreenType(parent, name),
00020 m_submitButton(NULL), m_viewButton(NULL),
00021 m_deleteButton(NULL), m_nextButton(NULL),
00022 m_cancelButton(NULL), m_profileLocation(NULL),
00023 m_adminPassword(NULL), m_busyPopup(NULL)
00024 {
00025 m_popupStack = GetMythMainWindow()->GetStack("popup stack");
00026 m_hardwareProfile = new HardwareProfile();
00027 }
00028
00029 bool GeneralSetupWizard::Create()
00030 {
00031 bool foundtheme = false;
00032
00033
00034 foundtheme = LoadWindowFromXML("config-ui.xml", "generalwizard", this);
00035
00036 if (!foundtheme)
00037 return false;
00038
00039 m_submitButton = dynamic_cast<MythUIButton *> (GetChild("submit"));
00040 m_viewButton = dynamic_cast<MythUIButton *> (GetChild("view"));
00041 m_deleteButton = dynamic_cast<MythUIButton *> (GetChild("delete"));
00042
00043 m_nextButton = dynamic_cast<MythUIButton *> (GetChild("next"));
00044 m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));
00045
00046 m_profileLocation = dynamic_cast<MythUIText *> (GetChild("profiletext"));
00047 m_adminPassword = dynamic_cast<MythUIText *> (GetChild("profilepassword"));
00048
00049 if (!m_submitButton || !m_viewButton || !m_deleteButton ||
00050 !m_nextButton || !m_cancelButton)
00051 {
00052 LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
00053 return false;
00054 }
00055
00056 m_submitButton->SetHelpText( tr("Anonymously submit a profile of your hardware. "
00057 "This helps the developers to determine where "
00058 "to focus their efforts.") );
00059 m_viewButton->SetHelpText( tr("Visit your online hardware profile. (This requires "
00060 "that you have the MythBrowser plugin installed)") );
00061 m_deleteButton->SetHelpText( tr("Delete your online hardware profile.") );
00062
00063 m_nextButton->SetHelpText( tr("Save these changes and move on to the "
00064 "next configuration step.") );
00065 m_cancelButton->SetHelpText( tr("Exit this wizard, save no changes.") );
00066
00067 connect(m_submitButton, SIGNAL(Clicked()), this, SLOT(slotSubmit()));
00068 connect(m_viewButton, SIGNAL(Clicked()), this, SLOT(slotView()));
00069 connect(m_deleteButton, SIGNAL(Clicked()), this, SLOT(slotDelete()));
00070
00071 connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(slotNext()));
00072 connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
00073
00074 BuildFocusList();
00075 loadData();
00076
00077 #ifndef __linux__
00078 #ifndef CONFIG_BINDINGS_PYTHON
00079
00080
00081
00082 m_submitButton->Hide();
00083 m_viewButton->Hide();
00084 m_deleteButton->Hide();
00085
00086 if (m_profileLocation)
00087 m_profileLocation->Hide();
00088
00089 if (m_adminPassword)
00090 m_adminPassword->Hide();
00091 #endif
00092 #endif
00093
00094 return true;
00095 }
00096
00097 GeneralSetupWizard::~GeneralSetupWizard()
00098 {
00099 }
00100
00101 void GeneralSetupWizard::loadData()
00102 {
00103 if (!m_hardwareProfile)
00104 return;
00105
00106 m_hardwareProfile->GenerateUUIDs();
00107
00108 if (m_profileLocation)
00109 m_profileLocation->SetText(m_hardwareProfile->GetProfileURL());
00110
00111 if (m_adminPassword)
00112 m_adminPassword->SetText(m_hardwareProfile->GetAdminPasswordFromFile());
00113 }
00114
00115 void GeneralSetupWizard::slotNext(void)
00116 {
00117 save();
00118
00119 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00120 AudioSetupWizard *sw = new AudioSetupWizard(mainStack, this, "audiosetupwizard");
00121
00122 if (sw->Create())
00123 {
00124 mainStack->AddScreen(sw);
00125 }
00126 else
00127 delete sw;
00128 }
00129
00130 void GeneralSetupWizard::slotSubmit(void)
00131 {
00132 QString message = QObject::tr("Would you like to share your "
00133 "hardware profile with the MythTV developers? "
00134 "Profiles are anonymous and are a great way to "
00135 "help with future development.");
00136 MythConfirmationDialog *confirmdialog =
00137 new MythConfirmationDialog(m_popupStack,message);
00138
00139 if (confirmdialog->Create())
00140 m_popupStack->AddScreen(confirmdialog);
00141
00142 connect(confirmdialog, SIGNAL(haveResult(bool)),
00143 SLOT(OnSubmitPromptReturn(bool)));
00144 }
00145
00146 void GeneralSetupWizard::OnSubmitPromptReturn(bool submit)
00147 {
00148 if (submit)
00149 {
00150 CreateBusyDialog(tr("Submitting your hardware profile..."));
00151 if (m_hardwareProfile->SubmitProfile())
00152 {
00153 if (m_busyPopup)
00154 {
00155 m_busyPopup->Close();
00156 m_busyPopup = NULL;
00157 }
00158 ShowOkPopup(tr("Hardware profile submitted. Thank you for supporting "
00159 "MythTV!"));
00160 if (m_profileLocation)
00161 m_profileLocation->SetText(m_hardwareProfile->GetProfileURL());
00162 if (m_adminPassword)
00163 m_adminPassword->SetText(m_hardwareProfile->GetAdminPasswordFromFile());
00164 }
00165 else
00166 {
00167 if (m_busyPopup)
00168 {
00169 m_busyPopup->Close();
00170 m_busyPopup = NULL;
00171 }
00172 ShowOkPopup(tr("Encountered a problem while submitting your profile."));
00173 }
00174 }
00175 }
00176
00177 void GeneralSetupWizard::slotView(void)
00178 {
00179 if (gCoreContext->GetSetting("HardwareProfilePublicUUID").isEmpty())
00180 {
00181 ShowOkPopup(tr("You haven't submitted your hardware profile yet! "
00182 "Please submit your profile to visit it online."));
00183 return;
00184 }
00185
00186 QString url = m_hardwareProfile->GetProfileURL();
00187
00188 LOG(VB_GENERAL, LOG_DEBUG, QString("Profile URL = %1").arg(url));
00189
00190 if (url.isEmpty())
00191 return;
00192
00193 QString browser = gCoreContext->GetSetting("WebBrowserCommand", "");
00194 QString zoom = gCoreContext->GetSetting("WebBrowserZoomLevel", "1.0");
00195
00196 if (browser.isEmpty())
00197 {
00198 ShowOkPopup(tr("No browser command set! MythTV needs a browser "
00199 "installed and configure to display your hardware "
00200 "profile."));
00201 return;
00202 }
00203
00204 if (browser.toLower() == "internal")
00205 {
00206 GetMythMainWindow()->HandleMedia("WebBrowser", url);
00207 return;
00208 }
00209 else
00210 {
00211 QString cmd = browser;
00212 cmd.replace("%ZOOM%", zoom);
00213 cmd.replace("%URL%", url);
00214 cmd.replace('\'', "%27");
00215 cmd.replace("&","\\&");
00216 cmd.replace(";","\\;");
00217
00218 GetMythMainWindow()->AllowInput(false);
00219 myth_system(cmd, kMSDontDisableDrawing);
00220 GetMythMainWindow()->AllowInput(true);
00221 return;
00222 }
00223 }
00224
00225 void GeneralSetupWizard::slotDelete(void)
00226 {
00227 if (gCoreContext->GetSetting("HardwareProfileUUID").isEmpty())
00228 {
00229 ShowOkPopup(tr("You haven't submitted your hardware profile yet!"));
00230 return;
00231 }
00232
00233 QString message = QObject::tr("Are you sure you want to delete "
00234 "your online profile? Your information "
00235 "is anonymous and helps the developers "
00236 "to know what hardware the majority of users "
00237 "prefer.");
00238 MythConfirmationDialog *confirmdialog =
00239 new MythConfirmationDialog(m_popupStack,message);
00240
00241 if (confirmdialog->Create())
00242 m_popupStack->AddScreen(confirmdialog);
00243
00244 connect(confirmdialog, SIGNAL(haveResult(bool)),
00245 SLOT(OnDeletePromptReturn(bool)));
00246 }
00247
00248 void GeneralSetupWizard::OnDeletePromptReturn(bool submit)
00249 {
00250 if (submit)
00251 {
00252 CreateBusyDialog(tr("Deleting your hardware profile..."));
00253 if (m_hardwareProfile->DeleteProfile())
00254 {
00255 if (m_busyPopup)
00256 {
00257 m_busyPopup->Close();
00258 m_busyPopup = NULL;
00259 }
00260 ShowOkPopup(tr("Hardware profile deleted."));
00261 if (m_profileLocation)
00262 m_profileLocation->SetText("");
00263 if (m_adminPassword)
00264 m_adminPassword->SetText("");
00265 }
00266 else
00267 {
00268 if (m_busyPopup)
00269 {
00270 m_busyPopup->Close();
00271 m_busyPopup = NULL;
00272 }
00273 ShowOkPopup(tr("Encountered a problem while deleting your profile."));
00274 }
00275 }
00276 }
00277
00278 void GeneralSetupWizard::save(void)
00279 {
00280 }
00281
00282 bool GeneralSetupWizard::keyPressEvent(QKeyEvent *event)
00283 {
00284 if (GetFocusWidget()->keyPressEvent(event))
00285 return true;
00286
00287 bool handled = false;
00288
00289 if (!handled && MythScreenType::keyPressEvent(event))
00290 handled = true;
00291
00292 return handled;
00293 }
00294
00295 void GeneralSetupWizard::CreateBusyDialog(QString message)
00296 {
00297 if (m_busyPopup)
00298 return;
00299
00300 m_busyPopup = new MythUIBusyDialog(message, m_popupStack,
00301 "setupwizardbusydialog");
00302
00303 if (m_busyPopup->Create())
00304 m_popupStack->AddScreen(m_busyPopup);
00305 }
00306