3 #include <QApplication>
22 #define LOC QString("SourceManager: ")
23 #define LOC_ERR QString("SourceManager Error: ")
40 "SELECT DISTINCT wss.sourceid, source_name, update_timeout, "
41 "retrieve_timeout, path, author, version, email, types "
42 "FROM weathersourcesettings wss "
43 "LEFT JOIN weatherdatalayout wdl "
44 "ON wss.sourceid = wdl.weathersourcesettings_sourceid "
45 "WHERE hostname = :HOST;";
57 QFileInfo fi(db.
value(4).toString());
59 if (!fi.isExecutable())
67 si->name = db.
value(1).toString();
68 si->updateTimeout = std::chrono::seconds(db.
value(2).toUInt());
69 si->scriptTimeout = std::chrono::seconds(db.
value(3).toUInt());
70 si->path = fi.absolutePath();
71 si->program = fi.absoluteFilePath();
72 si->author = db.
value(5).toString();
73 si->version = db.
value(6).toString();
74 si->email = db.
value(7).toString();
75 si->types = db.
value(8).toString().split(
",");
84 QString path =
GetShareDir() +
"mythweather/scripts/";
86 dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs);
90 LOG(VB_GENERAL, LOG_ERR,
"MythWeather: Scripts directory not found");
93 QString busymessage = tr(
"Searching for scripts");
96 if (popupStack ==
nullptr)
100 "mythweatherbusydialog");
102 if (busyPopup->Create())
112 QCoreApplication::processEvents();
119 db.
prepare(
"SELECT sourceid, path FROM weathersourcesettings "
120 "WHERE hostname = :HOST;");
124 QStringList toRemove;
127 QFileInfo fi(db.
value(1).toString());
128 if (!fi.isExecutable())
130 toRemove << db.
value(0).toString();
131 LOG(VB_GENERAL, LOG_ERR, QString(
"'%1' no longer exists")
132 .arg(fi.absoluteFilePath()));
136 db.
prepare(
"DELETE FROM weathersourcesettings WHERE sourceid = :ID;");
137 for (
int i = 0; i < toRemove.count(); ++i)
171 "SELECT DISTINCT location, weathersourcesettings_sourceid, "
172 " weatherscreens.units, weatherscreens.screen_id "
173 "FROM weatherdatalayout,weatherscreens "
174 "WHERE weatherscreens.screen_id = weatherscreens_screen_id AND "
175 " weatherscreens.hostname = :HOST");
187 QString loc = db.
value(0).toString();
200 for (
auto *script : std::as_const(
m_scripts))
203 if (src->
name == name)
211 LOG(VB_GENERAL, LOG_ERR,
"No Source found for " + name);
223 QStringList locationList(ws->getLocationList(str));
234 for (
auto *src : std::as_const(
m_sources))
236 if (src->getId() ==
id && src->getLocale() == loc &&
237 src->getUnits() == units)
244 auto idmatch = [id](
auto *si){
return si->id == id; };
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()));