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 const QString&
action = actions[i];
201 text = tr(
"Add desired screen to the Active Screens list "
202 "by pressing SELECT.") +
"\n";
203 text += si->m_title +
"\n";
204 text += QString(
"%1: %2").arg(tr(
"Sources"), sources.join(
", "));
219 text += tr(
"Units: ");
221 tr(
"English Units") : tr(
"SI Units");
224 if (!si->m_multiLoc && !si->m_types.empty())
227 text += tr(
"Location: ");
230 text += tr(
"Source: " );
234 text +=
"\n" + tr(
"Press SELECT to ");
236 text += tr(
"change location; ");
238 text += tr(
"change units; ");
239 text += tr(
"move screen up or down; or remove screen.");
252 ScreenListMap::const_iterator i = screenListMap.constBegin();
253 while (i != screenListMap.constEnd())
259 QStringList type_strs;
260 for (
const QString&
type : std::as_const(
types))
267 QList<ScriptInfo *> scriptList;
272 for (
const auto *script : std::as_const(scriptList))
281 QMap<long, ScreenListInfo*> active_screens;
284 QString query =
"SELECT weatherscreens.container, weatherscreens.units, "
285 "weatherdatalayout.dataitem, weatherdatalayout.location, "
286 "weathersourcesettings.source_name, weatherscreens.draworder "
287 "FROM weatherscreens, weatherdatalayout, weathersourcesettings "
288 "WHERE weatherscreens.hostname = :HOST "
289 "AND weatherscreens.screen_id = weatherdatalayout.weatherscreens_screen_id "
290 "AND weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
291 "ORDER BY weatherscreens.draworder;";
303 QString name = db.
value(0).toString();
305 QString dataitem = db.
value(2).toString();
306 QString location = db.
value(3).toString();
307 QString src = db.
value(4).toString();
310 types = screenListMap[name].m_dataTypes;
315 if (active_screens.find(draworder) == active_screens.end())
325 for (
const auto &
type : std::as_const(
types))
327 if (
type == dataitem)
328 si->m_types.insert(dataitem, ti);
331 item->SetData(QVariant::fromValue(si));
332 active_screens.insert(draworder, si);
337 for (
const auto &
type : std::as_const(
types))
339 if (
type == dataitem)
341 si->
m_types.insert(dataitem, ti);
351 QStringList notDefined;
357 for (
const auto &
type : std::as_const(si->m_types))
362 notDefined <<
type.m_name;
363 LOG(VB_GENERAL, LOG_ERR, QString(
"Not defined %1").arg(
type.m_name));
367 if (!notDefined.empty())
369 LOG(VB_GENERAL, LOG_ERR,
"A Selected screen has data items with no "
376 QString query =
"DELETE FROM weatherscreens WHERE hostname=:HOST";
382 query =
"INSERT into weatherscreens (draworder, container, units, hostname) "
383 "VALUES (:DRAW, :CONT, :UNITS, :HOST);";
398 QString query2 =
"SELECT screen_id FROM weatherscreens "
399 "WHERE draworder = :DRAW AND hostname = :HOST;";
410 int screen_id = db2.
value(0).toInt();
412 query2 =
"INSERT INTO weatherdatalayout (location, dataitem, "
413 "weatherscreens_screen_id, weathersourcesettings_sourceid) "
414 "VALUES (:LOC, :ITEM, :SCREENID, :SRCID);";
416 for (
const auto &
type : std::as_const(si->m_types))
452 QString label = tr(
"Manipulate Screen");
458 "screensetupmenupopup");
460 if (menuPopup->Create())
464 menuPopup->SetReturnEvent(
this,
"options");
466 menuPopup->AddButtonV(tr(
"Move Up"), QVariant::fromValue(selected));
467 menuPopup->AddButtonV(tr(
"Move Down"), QVariant::fromValue(selected));
468 menuPopup->AddButtonV(tr(
"Remove"), QVariant::fromValue(selected));
469 menuPopup->AddButtonV(tr(
"Change Location"), QVariant::fromValue(selected));
471 menuPopup->AddButtonV(tr(
"Change Units"), QVariant::fromValue(selected));
472 menuPopup->AddButtonV(tr(
"Cancel"), QVariant::fromValue(selected));
483 QStringList type_strs;
487 for (
auto it = si->m_types.begin(); it != si->m_types.end(); ++it)
489 types.insert(it.key(), *it);
490 type_strs << it.key();
492 bool hasUnits = si->m_hasUnits;
494 QList<ScriptInfo *>
tmp;
509 LOG(VB_GENERAL, LOG_ERR,
"Screen cannot be used, not all required "
510 "data is supplied by existing sources");
523 if (locdialog->Create())
534 QString label = QString(
"%1 %2").arg(name, tr(
"Change Units"));
538 auto *menuPopup =
new MythDialogBox(label, popupStack,
"weatherunitspopup");
540 if (menuPopup->Create())
544 menuPopup->SetReturnEvent(
this,
"units");
546 menuPopup->AddButtonV(tr(
"English Units"), QVariant::fromValue(si));
547 menuPopup->AddButtonV(tr(
"SI Units"), QVariant::fromValue(si));
581 QString resultid = dce->
GetId();
582 int buttonnum = dce->GetResult();
584 if (resultid ==
"options")
595 else if (buttonnum == 1)
599 else if (buttonnum == 2)
603 else if (buttonnum == 3)
605 si->m_updating =
true;
608 else if (si->m_hasUnits && buttonnum == 4)
610 si->m_updating =
true;
616 else if (resultid ==
"units")
626 else if (buttonnum == 1)
634 si->m_updating =
false;
639 else if (resultid ==
"location")
643 auto emptyloc = [](
const auto &
type)
644 {
return type.m_location.isEmpty(); };
645 if (std::any_of(si->m_types.cbegin(), si->m_types.cend(), emptyloc))
650 si->m_updating =
false;
653 item->
SetData(QVariant::fromValue(si));
658 item->SetData(QVariant::fromValue(si));
695 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
731 "SELECT DISTINCT sourceid, source_name, update_timeout, retrieve_timeout, "
732 "author, email, version FROM weathersourcesettings, weatherdatalayout "
733 "WHERE weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
734 "AND hostname=:HOST;";
752 si->name = db.
value(1).toString();
753 si->update_timeout = std::chrono::minutes(db.
value(2).toUInt() / 60);
754 si->retrieve_timeout = std::chrono::seconds(db.
value(3).toUInt());
755 si->author = db.
value(4).toString();
756 si->email = db.
value(5).toString();
757 si->version = db.
value(6).toString();
777 QString query =
"UPDATE weathersourcesettings "
778 "SET update_timeout = :UPDATE, retrieve_timeout = :RETRIEVE "
779 "WHERE sourceid = :ID;";
787 db.
bindValue(
":UPDATE", (
int)duration_cast<std::chrono::seconds>(si->update_timeout).count());
788 db.
bindValue(
":RETRIEVE", (
int)si->retrieve_timeout.count());
831 QString txt = tr(
"Author: ");
833 txt +=
"\n" + tr(
"Email: ") + si->email;
834 txt +=
"\n" + tr(
"Version: ") + si->version;
844 m_screenListInfo(new
ScreenListInfo(*si)), m_sourceManager(srcman),
845 m_retScreen(retScreen)
847 for (
const auto &
type : std::as_const(si->
m_types))
876 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
895 QString busymessage = tr(
"Searching...");
900 "mythweatherbusydialog");
902 if (busyPopup->Create())
913 QHash<ScriptInfo *, QStringList> result_cache;
917 QString searchingresults = tr(
"Searching... Results: %1");
920 QCoreApplication::processEvents();
922 QList<ScriptInfo *> sources;
926 for (
auto *si : std::as_const(sources))
928 if (!result_cache.contains(si))
934 QCoreApplication::processEvents();
938 for (
auto it = result_cache.begin(); it != result_cache.end(); ++it)
941 QStringList
results = it.value();
942 QString name = si->
name;
943 QStringList::iterator rit;
946 QStringList
tmp = (*rit).split(
"::");
949 LOG(VB_GENERAL, LOG_WARNING,
950 QString(
"Invalid line in Location Search reponse "
951 "from %1: %2").arg(name, *rit));
954 QString resultstring = QString(
"%1 (%2)").arg(
tmp[1], name);
959 item->SetData(QVariant::fromValue(ri));
960 QCoreApplication::processEvents();
1003 (*it).m_location = ri->
idstr;
1004 (*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)
std::enable_if_t< std::chrono::__is_duration< T >::value, void > SetDuration(T val)
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
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.
std::enable_if_t< std::chrono::__is_duration< T >::value, T > GetDuration()
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)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.