3 #include <QApplication>
21 #define LOC QString("SourceManager: ")
22 #define LOC_ERR QString("SourceManager Error: ")
39 "SELECT DISTINCT wss.sourceid, source_name, update_timeout, "
40 "retrieve_timeout, path, author, version, email, types "
41 "FROM weathersourcesettings wss "
42 "LEFT JOIN weatherdatalayout wdl "
43 "ON wss.sourceid = wdl.weathersourcesettings_sourceid "
44 "WHERE hostname = :HOST;";
56 QFileInfo fi(db.
value(4).toString());
58 if (!fi.isExecutable())
66 si->name = db.
value(1).toString();
67 si->updateTimeout = std::chrono::seconds(db.
value(2).toUInt());
68 si->scriptTimeout = std::chrono::seconds(db.
value(3).toUInt());
69 si->path = fi.absolutePath();
70 si->program = fi.absoluteFilePath();
71 si->author = db.
value(5).toString();
72 si->version = db.
value(6).toString();
73 si->email = db.
value(7).toString();
74 si->types = db.
value(8).toString().split(
",");
83 QString path =
GetShareDir() +
"mythweather/scripts/";
85 dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs);
89 LOG(VB_GENERAL, LOG_ERR,
"MythWeather: Scripts directory not found");
92 QString busymessage = tr(
"Searching for scripts");
95 if (popupStack ==
nullptr)
99 "mythweatherbusydialog");
101 if (busyPopup->Create())
111 QCoreApplication::processEvents();
118 db.
prepare(
"SELECT sourceid, path FROM weathersourcesettings "
119 "WHERE hostname = :HOST;");
123 QStringList toRemove;
126 QFileInfo fi(db.
value(1).toString());
127 if (!fi.isExecutable())
129 toRemove << db.
value(0).toString();
130 LOG(VB_GENERAL, LOG_ERR, QString(
"'%1' no longer exists")
131 .arg(fi.absoluteFilePath()));
135 db.
prepare(
"DELETE FROM weathersourcesettings WHERE sourceid = :ID;");
136 for (
int i = 0; i < toRemove.count(); ++i)
170 "SELECT DISTINCT location, weathersourcesettings_sourceid, "
171 " weatherscreens.units, weatherscreens.screen_id "
172 "FROM weatherdatalayout,weatherscreens "
173 "WHERE weatherscreens.screen_id = weatherscreens_screen_id AND "
174 " weatherscreens.hostname = :HOST");
186 QString loc = db.
value(0).toString();
199 for (
auto *script : std::as_const(
m_scripts))
202 if (src->
name == name)
210 LOG(VB_GENERAL, LOG_ERR,
"No Source found for " + name);
222 QStringList locationList(ws->getLocationList(str));
233 for (
auto *src : std::as_const(
m_sources))
235 if (src->getId() ==
id && src->getLocale() == loc &&
236 src->getUnits() == units)
243 auto idmatch = [id](
auto *si){
return si->id == id; };
254 LOG(VB_GENERAL, LOG_ERR,
LOC +
255 QString(
"NeedSourceFor: Unable to find source for %1, %2, %3")
256 .arg(
id).arg(loc).arg(units));
262 for (
auto *src : std::as_const(
m_sources))
263 src->startUpdateTimer();
268 for (
auto *src : std::as_const(
m_sources))
269 src->stopUpdateTimer();
274 for (
auto *src : std::as_const(
m_sources))
277 src->startUpdate(forceUpdate);
282 QList<ScriptInfo *> &sources)
284 for (
auto *si : std::as_const(
m_scripts))
286 QStringList stypes = si->types;
288 for (
int i = 0; i <
types.count() && handled; ++i)
290 handled = stypes.contains(
types[i]);
296 return sources.count() != 0;
303 LOG(VB_GENERAL, LOG_ERR,
LOC +
304 QString(
"Cannot connect nonexistent screen 0x%1")
305 .arg((uint64_t)screen,0,16));
313 LOG(VB_GENERAL, LOG_ERR,
LOC +
314 QString(
"Cannot connect nonexistent source '%1'").arg(
id));
328 LOG(VB_GENERAL, LOG_ERR,
LOC +
329 QString(
"Cannot disconnect nonexistent screen 0x%1")
330 .arg((uint64_t)screen,0,16));
338 LOG(VB_GENERAL, LOG_ERR,
LOC +
339 QString(
"Cannot disconnect nonexistent source %1")
340 .arg(screen->
getId()));
356 dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs |
357 QDir::NoDotAndDotDot);
358 QFileInfoList files = dir.entryInfoList();
360 for (
const auto &
file : std::as_const(files))
362 QCoreApplication::processEvents();
365 QDir recurseTo(
file.filePath());
369 if (
file.isExecutable() && !(
file.isDir()))
375 LOG(VB_FILE, LOG_INFO, QString(
"Found Script '%1'")
376 .arg(
file.absoluteFilePath()));