Go to the documentation of this file.
14 #include <QApplication>
19 #define SCREEN_SETUP_SCREEN 1
36 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
79 m_createdSrcMan(srcman == nullptr),
80 m_helpText(nullptr), m_activeList(nullptr),
81 m_inactiveList(nullptr), m_finishButton(nullptr)
126 activeheader->
SetText(tr(
"Active Screens"));
130 inactiveheader->
SetText(tr(
"Inactive Screens"));
134 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
167 for (
int i = 0; i < actions.size() && !handled; i++)
169 QString
action = actions[i];
207 text = tr(
"Add desired screen to the Active Screens list "
208 "by pressing SELECT.") +
"\n";
209 text += si->m_title +
"\n";
210 text += QString(
"%1: %2").arg(tr(
"Sources"))
211 .arg(sources.join(
", "));
226 text += tr(
"Units: ");
228 tr(
"English Units") : tr(
"SI Units");
231 if (!si->m_multiLoc && !si->m_types.empty())
234 text += tr(
"Location: ");
237 text += tr(
"Source: " );
241 text +=
"\n" + tr(
"Press SELECT to ");
243 text += tr(
"change location; ");
245 text += tr(
"change units; ");
246 text += tr(
"move screen up or down; or remove screen.");
259 ScreenListMap::const_iterator i = screenListMap.constBegin();
260 while (i != screenListMap.constEnd())
266 QStringList type_strs;
267 for (
int typei = 0; typei <
types.size(); ++typei)
271 type_strs <<
types[typei];
274 QList<ScriptInfo *> scriptList;
279 for (
const auto *script : qAsConst(scriptList))
288 QMap<long, ScreenListInfo*> active_screens;
291 QString
query =
"SELECT weatherscreens.container, weatherscreens.units, "
292 "weatherdatalayout.dataitem, weatherdatalayout.location, "
293 "weathersourcesettings.source_name, weatherscreens.draworder "
294 "FROM weatherscreens, weatherdatalayout, weathersourcesettings "
295 "WHERE weatherscreens.hostname = :HOST "
296 "AND weatherscreens.screen_id = weatherdatalayout.weatherscreens_screen_id "
297 "AND weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
298 "ORDER BY weatherscreens.draworder;";
310 QString name = db.
value(0).toString();
312 QString dataitem = db.
value(2).toString();
313 QString location = db.
value(3).toString();
314 QString src = db.
value(4).toString();
317 types = screenListMap[name].m_dataTypes;
322 if (active_screens.find(draworder) == active_screens.end())
332 for (
const auto &
type : qAsConst(
types))
334 if (
type == dataitem)
335 si->m_types.insert(dataitem, ti);
338 item->SetData(QVariant::fromValue(si));
339 active_screens.insert(draworder, si);
344 for (
const auto &
type : qAsConst(
types))
346 if (
type == dataitem)
348 si->
m_types.insert(dataitem, ti);
358 QStringList notDefined;
364 for (
const auto &
type : qAsConst(si->m_types))
369 notDefined <<
type.m_name;
370 LOG(VB_GENERAL, LOG_ERR, QString(
"Not defined %1").
arg(
type.m_name));
374 if (!notDefined.empty())
376 LOG(VB_GENERAL, LOG_ERR,
"A Selected screen has data items with no "
383 QString
query =
"DELETE FROM weatherscreens WHERE hostname=:HOST";
389 query =
"INSERT into weatherscreens (draworder, container, units, hostname) "
390 "VALUES (:DRAW, :CONT, :UNITS, :HOST);";
405 QString query2 =
"SELECT screen_id FROM weatherscreens "
406 "WHERE draworder = :DRAW AND hostname = :HOST;";
417 int screen_id = db2.
value(0).toInt();
419 query2 =
"INSERT INTO weatherdatalayout (location, dataitem, "
420 "weatherscreens_screen_id, weathersourcesettings_sourceid) "
421 "VALUES (:LOC, :ITEM, :SCREENID, :SRCID);";
423 for (
const auto &
type : qAsConst(si->m_types))
459 QString label = tr(
"Manipulate Screen");
465 "screensetupmenupopup");
467 if (menuPopup->Create())
471 menuPopup->SetReturnEvent(
this,
"options");
473 menuPopup->AddButtonV(tr(
"Move Up"), QVariant::fromValue(selected));
474 menuPopup->AddButtonV(tr(
"Move Down"), QVariant::fromValue(selected));
475 menuPopup->AddButtonV(tr(
"Remove"), QVariant::fromValue(selected));
476 menuPopup->AddButtonV(tr(
"Change Location"), QVariant::fromValue(selected));
478 menuPopup->AddButtonV(tr(
"Change Units"), QVariant::fromValue(selected));
479 menuPopup->AddButtonV(tr(
"Cancel"), QVariant::fromValue(selected));
490 QStringList type_strs;
494 for (
auto it = si->m_types.begin(); it != si->m_types.end(); ++it)
496 types.insert(it.key(), *it);
497 type_strs << it.key();
499 bool hasUnits = si->m_hasUnits;
501 QList<ScriptInfo *>
tmp;
515 LOG(VB_GENERAL, LOG_ERR,
"Screen cannot be used, not all required "
516 "data is supplied by existing sources");
528 if (locdialog->Create())
539 QString label = QString(
"%1 %2").arg(name).arg(tr(
"Change Units"));
543 auto *menuPopup =
new MythDialogBox(label, popupStack,
"weatherunitspopup");
545 if (menuPopup->Create())
549 menuPopup->SetReturnEvent(
this,
"units");
551 menuPopup->AddButtonV(tr(
"English Units"), QVariant::fromValue(si));
552 menuPopup->AddButtonV(tr(
"SI Units"), QVariant::fromValue(si));
586 QString resultid = dce->
GetId();
587 int buttonnum = dce->GetResult();
589 if (resultid ==
"options")
600 else if (buttonnum == 1)
604 else if (buttonnum == 2)
608 else if (buttonnum == 3)
610 si->m_updating =
true;
613 else if (si->m_hasUnits && buttonnum == 4)
615 si->m_updating =
true;
621 else if (resultid ==
"units")
631 else if (buttonnum == 1)
639 si->m_updating =
false;
644 else if (resultid ==
"location")
648 auto emptyloc = [](
const auto &
type)
649 {
return type.m_location.isEmpty(); };
650 if (std::any_of(si->m_types.cbegin(), si->m_types.cend(), emptyloc))
655 si->m_updating =
false;
658 item->
SetData(QVariant::fromValue(si));
663 item->SetData(QVariant::fromValue(si));
709 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
745 "SELECT DISTINCT sourceid, source_name, update_timeout, retrieve_timeout, "
746 "author, email, version FROM weathersourcesettings, weatherdatalayout "
747 "WHERE weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
748 "AND hostname=:HOST;";
766 si->name = db.
value(1).toString();
767 si->update_timeout = db.
value(2).toUInt() / 60;
768 si->retrieve_timeout = db.
value(3).toUInt();
769 si->author = db.
value(4).toString();
770 si->email = db.
value(5).toString();
771 si->version = db.
value(6).toString();
791 QString
query =
"UPDATE weathersourcesettings "
792 "SET update_timeout = :UPDATE, retrieve_timeout = :RETRIEVE "
793 "WHERE sourceid = :ID;";
801 db.
bindValue(
":UPDATE", si->update_timeout * 60);
802 db.
bindValue(
":RETRIEVE", si->retrieve_timeout);
845 QString txt = tr(
"Author: ");
847 txt +=
"\n" + tr(
"Email: ") + si->email;
848 txt +=
"\n" + tr(
"Version: ") + si->version;
858 m_screenListInfo(new
ScreenListInfo(*si)), m_sourceManager(srcman),
859 m_retScreen(retScreen), m_locationList(nullptr),
860 m_locationEdit(nullptr),m_searchButton(nullptr),
861 m_resultsText(nullptr), m_sourceText(nullptr)
892 LOG(VB_GENERAL, LOG_ERR,
"Theme is missing required elements.");
911 QString busymessage = tr(
"Searching...");
916 "mythweatherbusydialog");
918 if (busyPopup->Create())
929 QHash<ScriptInfo *, QStringList> result_cache;
933 QString searchingresults = tr(
"Searching... Results: %1");
936 QCoreApplication::processEvents();
938 QList<ScriptInfo *> sources;
942 for (
auto *si : qAsConst(sources))
944 if (!result_cache.contains(si))
950 QCoreApplication::processEvents();
954 for (
auto it = result_cache.begin(); it != result_cache.end(); ++it)
957 QStringList
results = it.value();
958 QString name = si->
name;
959 QStringList::iterator rit;
962 QStringList
tmp = (*rit).split(
"::");
965 LOG(VB_GENERAL, LOG_WARNING,
966 QString(
"Invalid line in Location Search reponse "
971 QString resultstring = QString(
"%1 (%2)").arg(
tmp[1]).arg(name);
976 item->SetData(QVariant::fromValue(ri));
977 QCoreApplication::processEvents();
1020 (*it).m_location = ri->
idstr;
1021 (*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
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
arg(title).arg(filename).arg(doDelete))
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
bool Create(void) override
ScreenListMap loadScreens()
MythUISpinBox * m_retrieveSpinbox
void SetValue(int val) override
MythScreenType * m_retScreen
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.
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)
SourceSetup(MythScreenStack *parent, const QString &name)
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
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)
MSqlQuery query(MSqlQuery::InitCon())
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.