23#define LOC QString("SourceManager: ")
24#define LOC_ERR QString("SourceManager Error: ")
41 "SELECT DISTINCT wss.sourceid, source_name, update_timeout, "
42 "retrieve_timeout, path, author, version, email, types "
43 "FROM weathersourcesettings wss "
44 "LEFT JOIN weatherdatalayout wdl "
45 "ON wss.sourceid = wdl.weathersourcesettings_sourceid "
46 "WHERE hostname = :HOST;";
58 QFileInfo fi(db.
value(4).toString());
60 if (!fi.isExecutable())
68 si->name = db.
value(1).toString();
69 si->updateTimeout = std::chrono::seconds(db.
value(2).toUInt());
70 si->scriptTimeout = std::chrono::seconds(db.
value(3).toUInt());
71 si->path = fi.absolutePath();
72 si->program = fi.absoluteFilePath();
73 si->author = db.
value(5).toString();
74 si->version = db.
value(6).toString();
75 si->email = db.
value(7).toString();
76 si->types = db.
value(8).toString().split(
",");
85 QString path =
GetShareDir() +
"mythweather/scripts/";
87 dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs);
91 LOG(VB_GENERAL, LOG_ERR,
"MythWeather: Scripts directory not found");
94 QString busymessage = tr(
"Searching for scripts");
97 if (popupStack ==
nullptr)
101 "mythweatherbusydialog");
103 if (busyPopup->Create())
113 QCoreApplication::processEvents();
120 db.
prepare(
"SELECT sourceid, path FROM weathersourcesettings "
121 "WHERE hostname = :HOST;");
125 QStringList toRemove;
128 QFileInfo fi(db.
value(1).toString());
129 if (!fi.isExecutable())
131 toRemove << db.
value(0).toString();
132 LOG(VB_GENERAL, LOG_ERR, QString(
"'%1' no longer exists")
133 .arg(fi.absoluteFilePath()));
137 db.
prepare(
"DELETE FROM weathersourcesettings WHERE sourceid = :ID;");
138 for (
int i = 0; i < toRemove.count(); ++i)
172 "SELECT DISTINCT location, weathersourcesettings_sourceid, "
173 " weatherscreens.units, weatherscreens.screen_id "
174 "FROM weatherdatalayout,weatherscreens "
175 "WHERE weatherscreens.screen_id = weatherscreens_screen_id AND "
176 " weatherscreens.hostname = :HOST");
188 QString loc = db.
value(0).toString();
201 for (
auto *script : std::as_const(
m_scripts))
204 if (src->
name == name)
212 LOG(VB_GENERAL, LOG_ERR,
"No Source found for " + name);
224 QStringList locationList(ws->getLocationList(str));
235 for (
auto *src : std::as_const(
m_sources))
237 if (src->getId() ==
id && src->getLocale() == loc &&
238 src->getUnits() == units)
255 LOG(VB_GENERAL, LOG_ERR,
LOC +
256 QString(
"NeedSourceFor: Unable to find source for %1, %2, %3")
257 .arg(
id).arg(loc).arg(units));
263 for (
auto *src : std::as_const(
m_sources))
264 src->startUpdateTimer();
269 for (
auto *src : std::as_const(
m_sources))
270 src->stopUpdateTimer();
275 for (
auto *src : std::as_const(
m_sources))
278 src->startUpdate(forceUpdate);
283 QList<ScriptInfo *> &sources)
285 for (
auto *si : std::as_const(
m_scripts))
287 QStringList stypes = si->types;
289 for (
int i = 0; i <
types.count() && handled; ++i)
291 handled = stypes.contains(
types[i]);
297 return sources.count() != 0;
304 LOG(VB_GENERAL, LOG_ERR,
LOC +
305 QString(
"Cannot connect nonexistent screen 0x%1")
306 .arg((uint64_t)screen,0,16));
314 LOG(VB_GENERAL, LOG_ERR,
LOC +
315 QString(
"Cannot connect nonexistent source '%1'").arg(
id));
329 LOG(VB_GENERAL, LOG_ERR,
LOC +
330 QString(
"Cannot disconnect nonexistent screen 0x%1")
331 .arg((uint64_t)screen,0,16));
339 LOG(VB_GENERAL, LOG_ERR,
LOC +
340 QString(
"Cannot disconnect nonexistent source %1")
341 .arg(screen->
getId()));
357 dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs |
358 QDir::NoDotAndDotDot);
359 QFileInfoList files = dir.entryInfoList();
361 for (
const auto &
file : std::as_const(files))
363 QCoreApplication::processEvents();
366 QDir recurseTo(
file.filePath());
370 if (
file.isExecutable() && !(
file.isDir()))
376 LOG(VB_FILE, LOG_INFO, QString(
"Found Script '%1'")
377 .arg(
file.absoluteFilePath()));
QSqlQuery wrapper that fetches a DB connection from the connection pool.
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
QVariant value(int i) const
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
QString GetHostName(void)
static void DBError(const QString &where, const MSqlQuery &query)
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void doUpdate(bool forceUpdate=false)
bool connectScreen(uint id, WeatherScreen *screen)
~SourceManager() override
bool findPossibleSources(QStringList types, QList< ScriptInfo * > &sources)
WeatherSource * needSourceFor(int id, const QString &loc, units_t units)
QStringList getLocationList(ScriptInfo *si, const QString &str)
ScriptInfo * getSourceByName(const QString &name)
bool disconnectScreen(WeatherScreen *screen)
QList< WeatherSource * > m_sources
void recurseDirs(QDir dir)
QList< ScriptInfo * > m_scripts
static ScriptInfo * ProbeScript(const QFileInfo &fi)
static pid_list_t::iterator find(const PIDInfoMap &map, pid_list_t &list, pid_list_t::iterator begin, pid_list_t::iterator end, bool find_open)
static const struct wl_interface * types[]
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
QString GetShareDir(void)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythMainWindow * GetMythMainWindow(void)