Go to the documentation of this file.
2 #include <QApplication>
30 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
73 m_createdSrcMan(srcman == nullptr)
118 activeheader->
SetText(tr(
"Active Screens"));
122 inactiveheader->
SetText(tr(
"Inactive Screens"));
126 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
159 for (
int i = 0; i < actions.size() && !handled; i++)
161 QString
action = actions[i];
199 text = tr(
"Add desired screen to the Active Screens list "
200 "by pressing SELECT.") +
"\n";
201 text += si->m_title +
"\n";
202 text += QString(
"%1: %2").arg(tr(
"Sources"), sources.join(
", "));
217 text += tr(
"Units: ");
219 tr(
"English Units") : tr(
"SI Units");
222 if (!si->m_multiLoc && !si->m_types.empty())
225 text += tr(
"Location: ");
228 text += tr(
"Source: " );
232 text +=
"\n" + tr(
"Press SELECT to ");
234 text += tr(
"change location; ");
236 text += tr(
"change units; ");
237 text += tr(
"move screen up or down; or remove screen.");
250 ScreenListMap::const_iterator i = screenListMap.constBegin();
251 while (i != screenListMap.constEnd())
257 QStringList type_strs;
258 for (
const QString&
type : qAsConst(
types))
265 QList<ScriptInfo *> scriptList;
270 for (
const auto *script : qAsConst(scriptList))
279 QMap<long, ScreenListInfo*> active_screens;
282 QString query =
"SELECT weatherscreens.container, weatherscreens.units, "
283 "weatherdatalayout.dataitem, weatherdatalayout.location, "
284 "weathersourcesettings.source_name, weatherscreens.draworder "
285 "FROM weatherscreens, weatherdatalayout, weathersourcesettings "
286 "WHERE weatherscreens.hostname = :HOST "
287 "AND weatherscreens.screen_id = weatherdatalayout.weatherscreens_screen_id "
288 "AND weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
289 "ORDER BY weatherscreens.draworder;";
301 QString name = db.
value(0).toString();
303 QString dataitem = db.
value(2).toString();
304 QString location = db.
value(3).toString();
305 QString src = db.
value(4).toString();
308 types = screenListMap[name].m_dataTypes;
313 if (active_screens.find(draworder) == active_screens.end())
323 for (
const auto &
type : qAsConst(
types))
325 if (
type == dataitem)
326 si->m_types.insert(dataitem, ti);
329 item->SetData(QVariant::fromValue(si));
330 active_screens.insert(draworder, si);
335 for (
const auto &
type : qAsConst(
types))
337 if (
type == dataitem)
339 si->
m_types.insert(dataitem, ti);
349 QStringList notDefined;
355 for (
const auto &
type : qAsConst(si->m_types))
360 notDefined <<
type.m_name;
361 LOG(VB_GENERAL, LOG_ERR, QString(
"Not defined %1").arg(
type.m_name));
365 if (!notDefined.empty())
367 LOG(VB_GENERAL, LOG_ERR,
"A Selected screen has data items with no "
374 QString query =
"DELETE FROM weatherscreens WHERE hostname=:HOST";
380 query =
"INSERT into weatherscreens (draworder, container, units, hostname) "
381 "VALUES (:DRAW, :CONT, :UNITS, :HOST);";
396 QString query2 =
"SELECT screen_id FROM weatherscreens "
397 "WHERE draworder = :DRAW AND hostname = :HOST;";
408 int screen_id = db2.
value(0).toInt();
410 query2 =
"INSERT INTO weatherdatalayout (location, dataitem, "
411 "weatherscreens_screen_id, weathersourcesettings_sourceid) "
412 "VALUES (:LOC, :ITEM, :SCREENID, :SRCID);";
414 for (
const auto &
type : qAsConst(si->m_types))
450 QString label = tr(
"Manipulate Screen");
456 "screensetupmenupopup");
458 if (menuPopup->Create())
462 menuPopup->SetReturnEvent(
this,
"options");
464 menuPopup->AddButtonV(tr(
"Move Up"), QVariant::fromValue(selected));
465 menuPopup->AddButtonV(tr(
"Move Down"), QVariant::fromValue(selected));
466 menuPopup->AddButtonV(tr(
"Remove"), QVariant::fromValue(selected));
467 menuPopup->AddButtonV(tr(
"Change Location"), QVariant::fromValue(selected));
469 menuPopup->AddButtonV(tr(
"Change Units"), QVariant::fromValue(selected));
470 menuPopup->AddButtonV(tr(
"Cancel"), QVariant::fromValue(selected));
481 QStringList type_strs;
485 for (
auto it = si->m_types.begin(); it != si->m_types.end(); ++it)
487 types.insert(it.key(), *it);
488 type_strs << it.key();
490 bool hasUnits = si->m_hasUnits;
492 QList<ScriptInfo *>
tmp;
506 LOG(VB_GENERAL, LOG_ERR,
"Screen cannot be used, not all required "
507 "data is supplied by existing sources");
519 if (locdialog->Create())
530 QString label = QString(
"%1 %2").arg(name, tr(
"Change Units"));
534 auto *menuPopup =
new MythDialogBox(label, popupStack,
"weatherunitspopup");
536 if (menuPopup->Create())
540 menuPopup->SetReturnEvent(
this,
"units");
542 menuPopup->AddButtonV(tr(
"English Units"), QVariant::fromValue(si));
543 menuPopup->AddButtonV(tr(
"SI Units"), QVariant::fromValue(si));
577 QString resultid = dce->
GetId();
578 int buttonnum = dce->GetResult();
580 if (resultid ==
"options")
591 else if (buttonnum == 1)
595 else if (buttonnum == 2)
599 else if (buttonnum == 3)
601 si->m_updating =
true;
604 else if (si->m_hasUnits && buttonnum == 4)
606 si->m_updating =
true;
612 else if (resultid ==
"units")
622 else if (buttonnum == 1)
630 si->m_updating =
false;
635 else if (resultid ==
"location")
639 auto emptyloc = [](
const auto &
type)
640 {
return type.m_location.isEmpty(); };
641 if (std::any_of(si->m_types.cbegin(), si->m_types.cend(), emptyloc))
646 si->m_updating =
false;
649 item->
SetData(QVariant::fromValue(si));
654 item->SetData(QVariant::fromValue(si));
691 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
727 "SELECT DISTINCT sourceid, source_name, update_timeout, retrieve_timeout, "
728 "author, email, version FROM weathersourcesettings, weatherdatalayout "
729 "WHERE weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
730 "AND hostname=:HOST;";
748 si->name = db.
value(1).toString();
749 si->update_timeout = std::chrono::minutes(db.
value(2).toUInt() / 60);
750 si->retrieve_timeout = std::chrono::seconds(db.
value(3).toUInt());
751 si->author = db.
value(4).toString();
752 si->email = db.
value(5).toString();
753 si->version = db.
value(6).toString();
773 QString query =
"UPDATE weathersourcesettings "
774 "SET update_timeout = :UPDATE, retrieve_timeout = :RETRIEVE "
775 "WHERE sourceid = :ID;";
783 db.
bindValue(
":UPDATE", (
int)duration_cast<std::chrono::seconds>(si->update_timeout).count());
784 db.
bindValue(
":RETRIEVE", (
int)si->retrieve_timeout.count());
827 QString txt = tr(
"Author: ");
829 txt +=
"\n" + tr(
"Email: ") + si->email;
830 txt +=
"\n" + tr(
"Version: ") + si->version;
840 m_screenListInfo(new
ScreenListInfo(*si)), m_sourceManager(srcman),
841 m_retScreen(retScreen)
872 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
891 QString busymessage = tr(
"Searching...");
896 "mythweatherbusydialog");
898 if (busyPopup->Create())
909 QHash<ScriptInfo *, QStringList> result_cache;
913 QString searchingresults = tr(
"Searching... Results: %1");
916 QCoreApplication::processEvents();
918 QList<ScriptInfo *> sources;
922 for (
auto *si : qAsConst(sources))
924 if (!result_cache.contains(si))
930 QCoreApplication::processEvents();
934 for (
auto it = result_cache.begin(); it != result_cache.end(); ++it)
937 QStringList
results = it.value();
938 QString name = si->
name;
939 QStringList::iterator rit;
942 QStringList
tmp = (*rit).split(
"::");
945 LOG(VB_GENERAL, LOG_WARNING,
946 QString(
"Invalid line in Location Search reponse "
947 "from %1: %2").arg(name, *rit));
950 QString resultstring = QString(
"%1 (%2)").arg(
tmp[1], name);
955 item->SetData(QVariant::fromValue(ri));
956 QCoreApplication::processEvents();
999 (*it).m_location = ri->
idstr;
1000 (*it).m_src = ri->src;
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
MythScreenStack * GetMainStack()
MythUIButtonList * m_sourceList
std::chrono::minutes update_timeout
ScreenListInfo * m_screenListInfo
MythUIButtonList * m_activeList
MythUIButton * m_finishButton
virtual bool NextPrevWidgetFocus(bool up_or_down)
void doListSelect(MythUIButtonListItem *selected)
void sourceListItemSelected(MythUIButtonListItem *item)
MythUIButton * m_finishButton
void updateHelpText(void)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
bool Create(void) override
QVariant value(int i) const
void customEvent(QEvent *event) override
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
A text entry and edit widget.
static const struct wl_interface * types[]
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Screen in which all other widgets are contained and rendered.
void showUnitsPopup(const QString &name, ScreenListInfo *si)
QString GetText(void) const
void SetRange(int low, int high, int step, uint pageMultiple=5)
Set the lower and upper bounds of the spinbox, the interval and page amount.
SourceManager * m_sourceManager
QMultiHash< QString, TypeListInfo > TypeListMap
MythUIButton * m_finishButton
void updateSpinboxUpdate(void)
MythUIType * GetFocusWidget(void) const
MythUICheckBox * m_backgroundCheckbox
static constexpr uint8_t ENG_UNITS
bool Create(void) override
ScreenListMap loadScreens()
MythUISpinBox * m_retrieveSpinbox
void SetValue(int val) override
MythScreenType * m_retScreen
static constexpr uint8_t SI_UNITS
MythUIText * m_resultsText
MythUISpinBox * m_updateSpinbox
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
MythUITextEdit * m_locationEdit
bool Create(void) override
bool SetFocusWidget(MythUIType *widget=nullptr)
Basic menu dialog, message and a list of options.
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
std::chrono::seconds retrieve_timeout
std::enable_if< std::chrono::__is_duration< T >::value, T >::type GetDuration()
int GetIntValue(void) const override
static void DBError(const QString &where, const MSqlQuery &query)
bool Create(void) override
void BuildFocusList(void)
void doLocationDialog(ScreenListInfo *si)
ScreenSetup(MythScreenStack *parent, const QString &name, SourceManager *srcman)
void itemClicked(MythUIButtonListItem *item)
void SetEnabled(bool enable)
QMap< QString, ScreenListInfo > ScreenListMap
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
LocationDialog(MythScreenStack *parent, const QString &name, MythScreenType *retScreen, ScreenListInfo *si, SourceManager *srcman)
int GetNumSetting(const QString &key, int defaultval=0)
The base class on which all widgets and screens are based.
ScriptInfo * getSourceByName(const QString &name)
QSqlError lastError(void) const
MythUIButton * m_searchButton
All purpose text widget, displays a text string.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
QStringList getLocationList(ScriptInfo *si, const QString &str)
void itemSelected(MythUIButtonListItem *item)
void retrieveSpinboxUpdate(void)
QString executedQuery(void) const
void SetCheckState(MythUIStateType::StateType state)
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
MythUIText * m_sourceText
virtual void SetText(const QString &text)
MythUIButtonList * m_locationList
static const Type kEventType
MythMainWindow * GetMythMainWindow(void)
A widget for offering a range of numerical values where only the the bounding values and interval are...
MythUIText * m_sourceText
bool findPossibleSources(QStringList types, QList< ScriptInfo * > &sources)
MythScreenStack * GetStack(const QString &Stackname)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUIButtonList * m_inactiveList
QString GetHostName(void)
~LocationDialog() override
SourceManager * m_sourceManager
void SaveSetting(const QString &key, int newValue)
MythUIStateType::StateType GetCheckState() const
MythUISpinBox * m_timeoutSpinbox
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
std::enable_if< std::chrono::__is_duration< T >::value, void >::type SetDuration(T val)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.