Go to the documentation of this file.
5 #include <QCoreApplication>
8 #include <QDomDocument>
11 #include <QTextStream>
23 #include "libmythbase/mythversion.h"
46 LOG(VB_GENERAL, LOG_ERR,
"Missing 'menu' buttonlist.");
60 LOG(VB_GENERAL, LOG_INFO,
"ERROR, bad parsing");
199 if (
type &&
type->keyPressEvent(event))
206 bool handled =
false;
211 for (
int i = 0; i < actions.size() && !handled; i++)
213 QString
action = actions[i];
224 QString menuaction =
"UPMENU";
225 QString selExit =
"EXITING_APP_PROMPT";
228 selExit =
"EXITING_APP";
229 else if (
action ==
"STANDBYMODE")
230 selExit =
"STANDBY_MODE";
239 QString sel =
"EXITING_MENU";
247 QCoreApplication::exit();
251 action ==
"STANDBYMODE" ||
253 (QCoreApplication::applicationName() ==
260 QCoreApplication::exit();
265 else if (
action ==
"HELP")
269 else if (
action ==
"EJECT")
299 int override_menu =
GetMythDB()->GetNumSetting(
"OverrideExitMenu");
300 QString label = tr(
"System Menu");
314 if (override_menu != 7)
317 switch (override_menu)
347 QFile
file(
"/etc/os_myth_release");
348 if (
file.open(QFile::ReadOnly))
350 QTextStream
t( &
file );
351 distro_line =
t.readLine();
355 QString label = tr(
"Revision: %1\n Branch: %2\n %3")
376 QString resultid = dce->GetId();
378 QString halt_cmd =
GetMythDB()->GetSetting(
"HaltCommand");
379 QString reboot_cmd =
GetMythDB()->GetSetting(
"RebootCommand");
381 if (resultid ==
"popmenu")
383 QString
action = dce->GetData().toString();
386 if (!halt_cmd.isEmpty())
389 else if (
action ==
"reboot")
391 if (!reboot_cmd.isEmpty())
394 else if (
action ==
"about")
398 else if (
action ==
"standby")
400 QString arg(
"standby_mode");
403 else if (
action ==
"exit")
405 QString arg(
"exiting_app");
409 else if (resultid ==
"password")
411 QString text = dce->GetResultText();
414 QString password =
GetMythDB()->GetSetting(button.password);
415 if (text == password)
417 QString timestamp_setting = QString(
"%1Time").arg(button.password);
419 QString last_time_stamp =
421 GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp);
446 for (QDomNode child = element.firstChild(); !child.isNull();
447 child = child.nextSibling())
449 QDomElement info = child.toElement();
452 if (info.tagName() ==
"type")
456 else if (info.tagName() ==
"text")
458 if (text.isEmpty() &&
459 info.attribute(
"lang",
"").isEmpty())
461 text = QCoreApplication::translate(
"ThemeUI",
464 else if ((info.attribute(
"lang",
"").toLower() ==
466 (info.attribute(
"lang",
"").toLower() ==
472 else if (info.tagName() ==
"alttext")
474 if (alttext.isEmpty() &&
475 info.attribute(
"lang",
"").isEmpty())
477 alttext = QCoreApplication::translate(
"ThemeUI",
480 else if ((info.attribute(
"lang",
"").toLower() ==
482 (info.attribute(
"lang",
"").toLower() ==
488 else if (info.tagName() ==
"action")
492 else if (info.tagName() ==
"depends")
496 else if (info.tagName() ==
"dependsexec")
500 else if (info.tagName() ==
"dependssetting")
504 else if (info.tagName() ==
"dependjumppoint")
509 else if (info.tagName() ==
"dependswindow")
511 QString xmlFile = info.attribute(
"xmlfile",
"");
513 if (xmlFile.isEmpty() || windowName.isEmpty())
518 else if (info.tagName() ==
"description")
520 if (description.isEmpty() &&
521 info.attribute(
"lang",
"").isEmpty())
523 description = QCoreApplication::translate(
"ThemeUI",
526 else if ((info.attribute(
"lang",
"").toLower() ==
528 (info.attribute(
"lang",
"").toLower() ==
534 else if (info.tagName() ==
"password")
540 LOG(VB_GENERAL, LOG_ERR,
541 QString(
"MythThemedMenu: Unknown tag %1 in button")
542 .arg(info.tagName()));
549 LOG(VB_GENERAL, LOG_ERR,
"MythThemedMenu: Missing 'text' in button");
555 LOG(VB_GENERAL, LOG_ERR,
"MythThemedMenu: Missing 'action' in button");
583 if (!f.exists() || !f.open(QIODevice::ReadOnly))
585 LOG(VB_GENERAL, LOG_ERR, QString(
"MythThemedMenu: Couldn't read "
586 "menu file %1").arg(menuname));
588 if (menuname !=
"mainmenu.xml")
589 ShowOkPopup(tr(
"MythTV could not locate the menu file %1")
598 if (!doc.setContent(&f,
false, &errorMsg, &errorLine, &errorColumn))
600 LOG(VB_GENERAL, LOG_ERR,
601 QString(
"Error parsing: %1\nat line: %2 column: %3 msg: %4").
602 arg(
filename).arg(errorLine).arg(errorColumn).arg(errorMsg));
605 if (menuname !=
"mainmenu.xml")
613 LOG(VB_GUI, LOG_INFO, QString(
"Loading menu theme from %1").arg(
filename));
615 QDomElement docElem = doc.documentElement();
617 m_menumode = docElem.attribute(
"name",
"MAIN");
619 QDomNode n = docElem.firstChild();
622 QDomElement e = n.toElement();
625 if (e.tagName() ==
"button")
631 LOG(VB_GENERAL, LOG_ERR,
632 QString(
"MythThemedMenu: Unknown element %1")
642 LOG(VB_GENERAL, LOG_ERR,
643 QString(
"MythThemedMenu: No buttons for menu %1").arg(menuname));
676 const QString &alttext,
677 const QStringList &
action,
678 const QString &description,
679 const QString &password)
684 newbutton.
text = text;
693 QVariant::fromValue(newbutton));
695 listbuttonitem->DisplayState(
type,
"icon");
696 listbuttonitem->SetText(description,
"description");
707 for (
const auto & act : qAsConst(button.action))
726 QString testdir =
GetConfDir() +
'/' + menuname;
730 LOG(VB_FILE, LOG_DEBUG,
"No menu file " + testdir);
733 file.setFileName(testdir);
736 LOG(VB_FILE, LOG_DEBUG,
"No menu file " + testdir);
739 file.setFileName(testdir);
742 LOG(VB_FILE, LOG_DEBUG,
"No menu file " + testdir);
745 file.setFileName(testdir);
748 LOG(VB_FILE, LOG_DEBUG,
"No menu file " + testdir);
750 testdir =
"../mythfrontend/" + menuname;
751 file.setFileName(testdir);
754 LOG(VB_FILE, LOG_DEBUG,
"No menu file " + testdir);
756 testdir =
GetShareDir() +
"themes/defaultmenu/" + menuname;
757 file.setFileName(testdir);
760 LOG(VB_FILE, LOG_DEBUG,
"No menu file " + testdir);
778 if (
action.startsWith(
"EXEC "))
786 if (
action.startsWith(
"EXECTV "))
788 QString rest =
action.right(
action.length() - 7).trimmed();
792 else if (
action.startsWith(
"MENU "))
799 if (newmenu->foundTheme())
804 else if (
action.startsWith(
"UPMENU"))
808 else if (
action.startsWith(
"CONFIGPLUGIN"))
814 else if (
action.startsWith(
"PLUGIN"))
820 else if (
action.startsWith(
"SHUTDOWN"))
827 else if (
action.startsWith(
"EJECT"))
829 if (cbs && cbs->
eject)
832 else if (
action.startsWith(
"JUMP "))
837 else if (
action.startsWith(
"MEDIA "))
841 QStringList list =
action.simplified().split(
' ');
842 if (list.size() >= 3)
851 LOG(VB_GENERAL, LOG_ERR,
"Unknown menu action: " +
action);
859 QStringList files = fileList.split(
" ");
862 for (
const auto &
file : qAsConst(files))
881 return filename_info.exists() && filename_info.isFile() && filename_info.isExecutable();
892 QString timestamp_setting = QString(
"%1Time").arg(password_setting);
894 QString last_time_stamp =
GetMythDB()->GetSetting(timestamp_setting);
895 QString password =
GetMythDB()->GetSetting(password_setting);
898 if (password.isEmpty())
901 if (last_time_stamp.length() < 1)
903 LOG(VB_GENERAL, LOG_ERR,
904 "MythThemedMenu: Could not read password/pin time stamp.\n"
905 "This is only an issue if it happens repeatedly.");
910 if (!last_time.isValid() || last_time.secsTo(curr_time) < 120)
914 GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp);
919 LOG(VB_GENERAL, LOG_INFO, QString(
"Using Password: %1")
920 .arg(password_setting));
922 QString text = tr(
"Enter password:");
926 if (dialog->Create())
928 dialog->SetReturnEvent(
this,
"password");
MythScreenStack * GetMainStack()
void SetReturnEvent(QObject *retobject, const QString &resultid)
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
void EnsureStateLoaded(const QString &name)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
void JumpTo(const QString &Destination, bool Pop=true)
const char * GetMythSourceVersion()
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
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="", std::chrono::minutes LenMins=2h, const QString &Year="1895", const QString &Id="", bool UseBookmarks=false)
static QString parseText(QDomElement &element)
MythUIType * GetFocusWidget(void) const
static constexpr const char * MYTH_APPNAME_MYTHTV_SETUP
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
void AddButton(const QString &title)
Basic menu dialog, message and a list of options.
static MythThemedMenu * menu
bool Create(void) override
QString GetShareDir(void)
bool DestinationExists(const QString &Destination) const
static QString getFirstText(QDomElement &element)
MythUIMenuCallbacks * GetMenuCBs()
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static bool WindowExists(const QString &xmlfile, const QString &windowname)
QString GetLanguage(void)
Returns two character ISO-639 language descriptor for UI language.
MythScreenStack * GetScreenStack() const
A C++ ripoff of the stroke library for MythTV.
The base class on which all widgets and screens are based.
const char * GetMythSourcePath()
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
void AddButtonV(const QString &title, QVariant data=0, bool newMenu=false, bool setCurrent=false)
static constexpr const char * MYTH_APPNAME_MYTHFRONTEND
All purpose text widget, displays a text string.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
QString GetLanguageAndVariant(void)
Returns the user-set language and variant.
MythPlugin * GetPlugin(const QString &plugname)
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
virtual void SetText(const QString &text)
virtual void PopScreen(MythScreenType *screen=nullptr, bool allowFade=true, bool deleteScreen=true)
MythMainWindow * GetMythMainWindow(void)
@ kDatabase
Default UTC, database format.
MythScreenStack * GetStack(const QString &Stackname)
MythScreenStack * m_screenStack
QString GetMenuThemeDir()
Dialog prompting the user to enter a text string.
virtual void aboutToShow(void)
MythUIHelper * GetMythUI()
MythPluginManager * GetPluginManager(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
This widget is used for grouping other widgets for display when a particular named state is called....
bool DisplayState(const QString &name)