6#include <QCoreApplication>
11#include <QRegularExpression>
12#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
13#include <QStringConverter>
25#include "libmythbase/mythversion.h"
54#define LOC QString("NetworkControl: ")
55#define LOC_ERR QString("NetworkControl Error: ")
61 (QEvent::Type) QEvent::registerEventType();
63 (QEvent::Type) QEvent::registerEventType();
67 { R
"(^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ?$)" };
77 QString
const& test,
int minchars = 1)
79 if (test.length() < minchars)
80 return command.toLower() == test.toLower();
81 return test.toLower() == command.left(test.length()).toLower();
85 m_commandThread(new
MThread(
"NetworkControl", this))
88 m_jumpMap[
"channelpriorities"] =
"Channel Recording Priorities";
91 m_jumpMap[
"managerecordings"] =
"Manage Recordings / Fix Conflicts";
100 m_jumpMap[
"programfinder"] =
"Program Finder";
101 m_jumpMap[
"programguide"] =
"Program Guide";
103 m_jumpMap[
"musicplaylists"] =
"Select music playlists";
104 m_jumpMap[
"playbackrecordings"] =
"TV Recording Playback";
105 m_jumpMap[
"videobrowser"] =
"Video Browser";
106 m_jumpMap[
"videogallery"] =
"Video Gallery";
107 m_jumpMap[
"videolistings"] =
"Video Listings";
108 m_jumpMap[
"videomanager"] =
"Video Manager";
109 m_jumpMap[
"zoneminderconsole"] =
"ZoneMinder Console";
110 m_jumpMap[
"zoneminderliveview"] =
"ZoneMinder Live View";
111 m_jumpMap[
"zoneminderevents"] =
"ZoneMinder Events";
113 m_jumpMap[
"channelrecpriority"] =
"Channel Recording Priorities";
114 m_jumpMap[
"viewscheduled"] =
"Manage Recordings / Fix Conflicts";
115 m_jumpMap[
"previousbox"] =
"Previously Recorded";
116 m_jumpMap[
"progfinder"] =
"Program Finder";
117 m_jumpMap[
"guidegrid"] =
"Program Guide";
118 m_jumpMap[
"managerecrules"] =
"Manage Recording Rules";
119 m_jumpMap[
"statusbox"] =
"Status Screen";
120 m_jumpMap[
"playbackbox"] =
"TV Recording Playback";
121 m_jumpMap[
"pbb"] =
"TV Recording Playback";
123 m_jumpMap[
"reloadtheme"] =
"Reload Theme";
124 m_jumpMap[
"showborders"] =
"Toggle Show Widget Borders";
125 m_jumpMap[
"shownames"] =
"Toggle Show Widget Names";
134 m_keyMap[
"return"] = Qt::Key_Return;
135 m_keyMap[
"pageup"] = Qt::Key_PageUp;
136 m_keyMap[
"pagedown"] = Qt::Key_PageDown;
137 m_keyMap[
"escape"] = Qt::Key_Escape;
139 m_keyMap[
"backtab"] = Qt::Key_Backtab;
141 m_keyMap[
"backspace"] = Qt::Key_Backspace;
142 m_keyMap[
"insert"] = Qt::Key_Insert;
143 m_keyMap[
"delete"] = Qt::Key_Delete;
150 m_keyMap[
"underscore"] = Qt::Key_Underscore;
152 m_keyMap[
"period"] = Qt::Key_Period;
154 m_keyMap[
"numbersign"] = Qt::Key_NumberSign;
155 m_keyMap[
"poundsign"] = Qt::Key_NumberSign;
156 m_keyMap[
"hash"] = Qt::Key_NumberSign;
158 m_keyMap[
"bracketleft"] = Qt::Key_BracketLeft;
159 m_keyMap[
"["] = Qt::Key_BracketLeft;
160 m_keyMap[
"bracketright"] = Qt::Key_BracketRight;
161 m_keyMap[
"]"] = Qt::Key_BracketRight;
162 m_keyMap[
"backslash"] = Qt::Key_Backslash;
164 m_keyMap[
"dollar"] = Qt::Key_Dollar;
166 m_keyMap[
"percent"] = Qt::Key_Percent;
168 m_keyMap[
"ampersand"] = Qt::Key_Ampersand;
170 m_keyMap[
"parenleft"] = Qt::Key_ParenLeft;
172 m_keyMap[
"parenright"] = Qt::Key_ParenRight;
174 m_keyMap[
"asterisk"] = Qt::Key_Asterisk;
176 m_keyMap[
"question"] = Qt::Key_Question;
182 m_keyMap[
"semicolon"] = Qt::Key_Semicolon;
188 m_keyMap[
"greater"] = Qt::Key_Greater;
264 "mythfrontend shutting down, connection closing...");
329 else if ((nc->
getArg(0).toLower() ==
"exit") || (nc->
getArg(0).toLower() ==
"quit"))
331 QCoreApplication::postEvent(
this,
334 else if (! nc->
getArg(0).isEmpty())
336 result = QString(
"INVALID command '%1', try 'help' for more info")
349 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Client Socket disconnected");
354 for (
auto * ncc : std::as_const(
m_clients))
356 if (ncc->getSocket()->state() == QTcpSocket::UnconnectedState)
375 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"deleteClient(%1), unable to "
376 "locate specified NetworkControlClient").arg((
long long)ncc));
384 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"New connection established."));
395 connect(client, &QAbstractSocket::disconnected,
398 welcomeStr =
"MythFrontend Network Control\r\n";
399 welcomeStr +=
"Type 'help' for usage information\r\n"
400 "---------------------------------";
410 m_textStream(new QTextStream(s))
412#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
430 auto *socket = (QTcpSocket *)sender();
434 while (socket->canReadLine())
436 QString lineIn = socket->readLine();
438 static const QRegularExpression
badChars
439 {
"[^-a-zA-Z0-9\\s\\.:_#/$%&()*+,;<=>?\\[\\]\\|]" };
443 lineIn = lineIn.simplified();
444 if (lineIn.isEmpty())
447 LOG(VB_NETWORK, LOG_INFO,
LOC +
448 QString(
"emit commandReceived(%1)").arg(lineIn));
455 LOG(VB_NETWORK, LOG_INFO,
LOC +
456 QString(
"NetworkControl::receiveCommand(%1)").arg(command));
457 auto *ncc = qobject_cast<NetworkControlClient *>(sender());
469 QString result =
"OK";
472 return QString(
"ERROR: See 'help %1' for usage information")
483 std::this_thread::sleep_for(10ms);
490 QString result =
"OK";
491 QKeyEvent *
event =
nullptr;
494 return QString(
"ERROR: See 'help %1' for usage information")
497 QObject *keyDest =
nullptr;
502 return {
"ERROR: Application has no main window!\n"};
505 while (curToken < nc->getArgCount())
507 int tokenLen = nc->
getArg(curToken).length();
509 if (nc->
getArg(curToken) ==
"sleep")
511 std::this_thread::sleep_for(1s);
523 event =
new QKeyEvent(QEvent::KeyPress, keyCode, Qt::NoModifier,
525 QCoreApplication::postEvent(keyDest, event);
527 event =
new QKeyEvent(QEvent::KeyRelease, keyCode, Qt::NoModifier,
529 QCoreApplication::postEvent(keyDest, event);
531 else if (((tokenLen == 1) &&
532 (nc->
getArg(curToken).at(0).isLetterOrNumber())) ||
534 (nc->
getArg(curToken).contains(
"+"))))
536 QKeySequence a(nc->
getArg(curToken));
537#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
539 Qt::KeyboardModifiers modifiers = Qt::NoModifier;
543 QStringList tokenParts = nc->
getArg(curToken).split(
'+');
546 while (partNum < (tokenParts.size() - 1))
548 if (tokenParts[partNum].toUpper() ==
"CTRL")
549 modifiers |= Qt::ControlModifier;
550 if (tokenParts[partNum].toUpper() ==
"SHIFT")
551 modifiers |= Qt::ShiftModifier;
552 if (tokenParts[partNum].toUpper() ==
"ALT")
553 modifiers |= Qt::AltModifier;
554 if (tokenParts[partNum].toUpper() ==
"META")
555 modifiers |= Qt::MetaModifier;
561 int keyCode = a[0].key();
562 Qt::KeyboardModifiers modifiers = a[0].keyboardModifiers();
566 if (nc->
getArg(curToken) == nc->
getArg(curToken).toUpper())
567 modifiers |= Qt::ShiftModifier;
572 event =
new QKeyEvent(QEvent::KeyPress, keyCode, modifiers,
574 QCoreApplication::postEvent(keyDest, event);
576 event =
new QKeyEvent(QEvent::KeyRelease, keyCode, modifiers,
578 QCoreApplication::postEvent(keyDest, event);
582 return QString(
"ERROR: Invalid syntax at '%1', see 'help %2' for "
595 QString result =
"OK";
599 return QString(
"ERROR: See 'help %1' for usage information")
605 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"mainmenu")
612 (
GetMythUI()->GetCurrentLocation().toLower() !=
"mainmenu"))
613 std::this_thread::sleep_for(10ms);
616 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"mainmenu")
625 return {
"Unable to change to main menu to start playback!"};
633 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback")
635 QString msg = QString(
"NETWORK_CONTROL STOP");
642 (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback"))
643 std::this_thread::sleep_for(10ms);
646 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox")
652 while (!timer.hasExpired(10000) &&
653 (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox"))
654 std::this_thread::sleep_for(10ms);
658 std::this_thread::sleep_for(10ms);
661 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playbackbox")
667 QString msg = QString(
"NETWORK_CONTROL %1 PROGRAM %2 %3 %4")
670 QString::number(clientID));
681 std::this_thread::sleep_for(10ms);
686 result =
"ERROR: Timed out waiting for reply from player";
691 result = QString(
"ERROR: Unable to change to PlaybackBox from "
692 "%1, cannot play requested file.")
699 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playmusic")
701 return QString(
"ERROR: You are in %1 mode and this command is "
702 "only for MythMusic")
712 message = QString(
"MUSIC_COMMAND %1 PLAY").arg(
hostname);
714 message = QString(
"MUSIC_COMMAND %1 PAUSE").arg(
hostname);
716 message = QString(
"MUSIC_COMMAND %1 STOP").arg(
hostname);
728 qApp->processEvents();
729 std::this_thread::sleep_for(10ms);
748 qApp->processEvents();
749 std::this_thread::sleep_for(10ms);
768 qApp->processEvents();
769 std::this_thread::sleep_for(10ms);
779 return {
"ERROR: Invalid 'play music' command"};
786 message = QString(
"MUSIC_COMMAND %1 SET_VOLUME %2")
791 message = QString(
"MUSIC_COMMAND %1 PLAY_TRACK %2")
796 message = QString(
"MUSIC_COMMAND %1 PLAY_URL %2")
801 message = QString(
"MUSIC_COMMAND %1 PLAY_FILE '%2'")
806 return {
"ERROR: Invalid 'play music' command"};
811 return {
"ERROR: Invalid 'play music' command"};
816 else if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playback")
818 return QString(
"ERROR: You are in %1 mode and this command is only "
825 message = QString(
"NETWORK_CONTROL CHANID %1").arg(nc->
getArg(2));
827 return QString(
"ERROR: See 'help %1' for usage information")
832 static const QRegularExpression kChanID2RE {
"^[-\\.\\d_#]+$" };
835 return "ERROR: See 'help play' for usage information";
838 message =
"NETWORK_CONTROL CHANNEL UP";
840 message =
"NETWORK_CONTROL CHANNEL DOWN";
841 else if (nc->
getArg(2).contains(kChanID2RE))
842 message = QString(
"NETWORK_CONTROL CHANNEL %1").arg(nc->
getArg(2));
844 return QString(
"ERROR: See 'help %1' for usage information")
849 static const QRegularExpression kSeekTimeRE { R
"(^\d\d:\d\d:\d\d$)" };
852 return QString(
"ERROR: See 'help %1' for usage information")
856 message =
"NETWORK_CONTROL SEEK BEGINNING";
858 message =
"NETWORK_CONTROL SEEK FORWARD";
861 message =
"NETWORK_CONTROL SEEK BACKWARD";
862 else if (nc->
getArg(2).contains(kSeekTimeRE))
864 int hours = nc->
getArg(2).mid(0, 2).toInt();
865 int minutes = nc->
getArg(2).mid(3, 2).toInt();
866 int seconds = nc->
getArg(2).mid(6, 2).toInt();
867 message = QString(
"NETWORK_CONTROL SEEK POSITION %1")
868 .arg((hours * 3600) + (minutes * 60) + seconds);
872 return QString(
"ERROR: See 'help %1' for usage information")
878 static const QRegularExpression kSpeed1RE { R
"(^\-*\d+x$)" };
879 static const QRegularExpression kSpeed2RE { R
"(^\-*\d+\/\d+x$)" };
880 static const QRegularExpression kSpeed3RE { R
"(^\-*\d*\.\d+x$)" };
883 return QString(
"ERROR: See 'help %1' for usage information")
886 QString token2 = nc->
getArg(2).toLower();
887 if ((token2.contains(kSpeed1RE)) ||
888 (token2.contains(kSpeed2RE)) ||
889 (token2.contains(kSpeed3RE)))
890 message = QString(
"NETWORK_CONTROL SPEED %1").arg(token2);
892 message = QString(
"NETWORK_CONTROL SPEED normal");
894 message = QString(
"NETWORK_CONTROL SPEED 0x");
896 return QString(
"ERROR: See 'help %1' for usage information")
906 message = QString(
"NETWORK_CONTROL STOP");
910 static const QRegularExpression kVolumeRE {
"^\\d+%?$" };
913 (!nc->
getArg(2).toLower().contains(kVolumeRE)))
915 return QString(
"ERROR: See 'help %1' for usage information")
919 message = QString(
"NETWORK_CONTROL VOLUME %1")
920 .arg(nc->
getArg(2).toLower());
924 static const QRegularExpression kNumberRE {
"^\\d+$" };
926 message = QString(
"NETWORK_CONTROL SUBTITLES 0");
927 else if (!nc->
getArg(2).toLower().contains(kNumberRE))
929 return QString(
"ERROR: See 'help %1' for usage information")
934 message = QString(
"NETWORK_CONTROL SUBTITLES %1")
940 return QString(
"ERROR: See 'help %1' for usage information")
944 if (!message.isEmpty())
964 QString result =
"OK";
967 return QString(
"ERROR: See 'help %1' for usage information")
972 bool fullPath =
false;
973 bool mainStackOnly =
true;
976 fullPath = (nc->
getArg(2).toLower() ==
"true" || nc->
getArg(2) ==
"1");
978 mainStackOnly = (nc->
getArg(3).toLower() ==
"true" || nc->
getArg(3) ==
"1");
984 if (location ==
"Playback")
988 QString message = QString(
"NETWORK_CONTROL QUERY POSITION");
995 std::this_thread::sleep_for(10ms);
1000 result =
"ERROR: Timed out waiting for reply from player";
1017 return QString(
"VERSION: %1/%2 %3 %4 QT/%5 DBSchema/%6")
1020 MYTH_BINARY_VERSION,
1023 QString::number(dbSchema));
1033 std::chrono::seconds uptime = 0s;
1036 str = QString::number(uptime.count());
1038 str = QString(
"Could not determine uptime.");
1046 str = QString(
"getloadavg() failed");
1048 str = QString(
"%1 %2 %3").arg(loads[0]).arg(loads[1]).arg(loads[2]);
1059 if (
getMemStats(totalMB, freeMB, totalVM, freeVM))
1061 str = QString(
"%1 %2 %3 %4")
1062 .arg(totalMB).arg(freeMB).arg(totalVM).arg(freeVM);
1066 str = QString(
"Could not determine memory stats.");
1076 if (location !=
"Playback")
1080 QString message = QString(
"NETWORK_CONTROL QUERY VOLUME");
1084 QElapsedTimer timer;
1087 std::this_thread::sleep_for(10ms);
1092 str =
"ERROR: Timed out waiting for reply from player";
1113 nc->
getArg(3).toLower().toUInt());
1114 return QString(
"ERROR: See 'help %1' for usage information "
1115 "(parameters mismatch)").arg(nc->
getArg(0));
1119 return QString(
"ERROR: See 'help %1' for usage information")
1129 return QString(
"ERROR: See 'help %1' for usage information")
1132 if (nc->
getArg(1) ==
"verbose")
1135 return {
"ERROR: Missing filter name."};
1139 return QString(
"ERROR: Separate filters with commas with no "
1140 "space: playback,audio\r\n See 'help %1' for usage "
1141 "information").arg(nc->
getArg(0));
1145 QString result =
"OK";
1149 if (pva_result != 0 )
1153 result +=
" Previous filter: " + oldVerboseString +
"\r\n";
1156 LOG(VB_GENERAL, LOG_NOTICE,
1157 QString(
"Verbose mask changed, new level is: %1")
1163 return QString(
"ERROR: See 'help %1' for usage information")
1170 return "MythUIText";
1172 return "MythUITextEdit";
1174 return "MythUIGroup";
1176 return "MythUIButton";
1178 return "MythUICheckBox";
1180 return "MythUIShape";
1182 return "MythUIButtonList";
1184 return "MythUIImage";
1186 return "MythUISpinBox";
1187#if CONFIG_QTWEBENGINE
1189 return "MythUIWebBrowser";
1192 return "MythUIClock";
1194 return "MythUIStateType";
1196 return "MythUIProgressBar";
1198 return "MythUIButtonTree";
1200 return "MythUIScrollBar";
1202 return "MythUIVideo";
1204 return "MythUIGuideGrid";
1206 return "MythUIEditBar";
1214 return QString(
"ERROR: See 'help %1' for usage information")
1217 if (nc->
getArg(1) ==
"getthemeinfo")
1221 return QString(
"%1 - %2").arg(
themeName, themeDir);
1223 if (nc->
getArg(1) ==
"reload")
1229 if (nc->
getArg(1) ==
"showborders")
1235 if (nc->
getArg(1) ==
"shownames")
1241 if (nc->
getArg(1) ==
"getwidgetnames")
1246 path = nc->
getArg(2).split(
'/');
1258 return {
"ERROR: no top screen found!"};
1262 while (!path.isEmpty())
1264 QString childName = path.takeFirst();
1265 currType = currType->
GetChild(childName);
1267 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1273 for (
int i = 0; i < children->count(); i++)
1276 QString widgetName =
type->objectName();
1278 result += QString(
"%1 - %2\n\r").arg(widgetName, -20).arg(widgetType);
1283 if (nc->
getArg(1) ==
"getarea")
1286 return {
"ERROR: Missing widget name."};
1288 QString widgetName = nc->
getArg(2);
1289 QStringList path = widgetName.split(
'/');
1301 return {
"ERROR: no top screen found!"};
1305 while (path.count() > 1)
1307 QString childName = path.takeFirst();
1308 currType = currType->
GetChild(childName);
1310 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1315 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1317 int x =
type->GetFullArea().x();
1318 int y =
type->GetFullArea().y();
1319 int w =
type->GetFullArea().width();
1320 int h =
type->GetFullArea().height();
1321 return QString(
"The area of '%1' is x:%2, y:%3, w:%4, h:%5")
1322 .arg(widgetName).arg(x).arg(y).arg(w).arg(h);
1324 if (nc->
getArg(1) ==
"setarea")
1327 return {
"ERROR: Missing widget name."};
1330 return {
"ERROR: Missing X, Y, Width or Height."};
1332 QString widgetName = nc->
getArg(2);
1333 QStringList path = widgetName.split(
'/');
1334 QString x = nc->
getArg(3);
1335 QString y = nc->
getArg(4);
1336 QString w = nc->
getArg(5);
1337 QString h = nc->
getArg(6);
1350 return {
"ERROR: no top screen found!"};
1352 while (path.count() > 1)
1354 QString childName = path.takeFirst();
1355 currType = currType->
GetChild(childName);
1357 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1362 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1366 return QString(
"Changed area of '%1' to x:%2, y:%3, w:%4, h:%5")
1367 .arg(widgetName, x, y, w, h);
1370 return QString(
"ERROR: See 'help %1' for usage information")
1396 QMap<QString, QString>::Iterator it;
1398 "Usage: jump JUMPPOINT\r\n"
1400 "Where JUMPPOINT is one of the following:\r\n";
1404 helpText += it.key().leftJustified(20,
' ',
true) +
" - " +
1411 "key LETTER - Send the letter key specified\r\n"
1412 "key NUMBER - Send the number key specified\r\n"
1413 "key CODE - Send one of the following key codes\r\n"
1416 QMap<QString, int>::Iterator it;
1425 helpText += it.key();
1432 "play volume NUMBER% - Change volume to given percentage value\r\n"
1433 "play channel up - Change channel Up\r\n"
1434 "play channel down - Change channel Down\r\n"
1435 "play channel NUMBER - Change to a specific channel number\r\n"
1436 "play chanid NUMBER - Change to a specific channel id (chanid)\r\n"
1437 "play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n"
1438 "play program CHANID yyyy-MM-ddThh:mm:ss\r\n"
1439 " - Play program with chanid & starttime\r\n"
1440 "play program CHANID yyyy-MM-ddThh:mm:ss resume\r\n"
1441 " - Resume program with chanid & starttime\r\n"
1442 "play save preview\r\n"
1443 " - Save preview image from current position\r\n"
1444 "play save preview FILENAME\r\n"
1445 " - Save preview image to FILENAME\r\n"
1446 "play save preview FILENAME WxH\r\n"
1447 " - Save preview image of size WxH\r\n"
1448 "play seek beginning - Seek to the beginning of the recording\r\n"
1449 "play seek forward - Skip forward in the video\r\n"
1450 "play seek backward - Skip backwards in the video\r\n"
1451 "play seek HH:MM:SS - Seek to a specific position\r\n"
1452 "play speed pause - Pause playback\r\n"
1453 "play speed normal - Playback at normal speed\r\n"
1454 "play speed 1x - Playback at normal speed\r\n"
1455 "play speed SPEEDx - Playback where SPEED must be a decimal\r\n"
1456 "play speed 1/8x - Playback at 1/8x speed\r\n"
1457 "play speed 1/4x - Playback at 1/4x speed\r\n"
1458 "play speed 1/3x - Playback at 1/3x speed\r\n"
1459 "play speed 1/2x - Playback at 1/2x speed\r\n"
1460 "play stop - Stop playback\r\n"
1461 "play subtitles [#] - Switch on indicated subtitle tracks\r\n"
1462 "play music play - Resume playback (MythMusic)\r\n"
1463 "play music pause - Pause playback (MythMusic)\r\n"
1464 "play music stop - Stop Playback (MythMusic)\r\n"
1465 "play music setvolume N - Set volume to number (MythMusic)\r\n"
1466 "play music getvolume - Get current volume (MythMusic)\r\n"
1467 "play music getmeta - Get metadata for current track (MythMusic)\r\n"
1468 "play music getstatus - Get music player status playing/paused/stopped (MythMusic)\r\n"
1469 "play music file NAME - Play specified file (MythMusic)\r\n"
1470 "play music track N - Switch to specified track (MythMusic)\r\n"
1471 "play music url URL - Play specified URL (MythMusic)\r\n";
1476 "query location - Query current screen or location\r\n"
1477 "query volume - Query the current playback volume\r\n"
1478 "query recordings - List currently available recordings\r\n"
1479 "query recording CHANID STARTTIME\r\n"
1480 " - List info about the specified program\r\n"
1481 "query liveTV - List current TV schedule\r\n"
1482 "query liveTV CHANID - Query current program for specified channel\r\n"
1483 "query load - List 1/5/15 load averages\r\n"
1484 "query memstats - List free and total, physical and swap memory\r\n"
1485 "query time - Query current time on frontend\r\n"
1486 "query uptime - Query machine uptime\r\n"
1487 "query verbose - Get current VERBOSE mask\r\n"
1488 "query version - Query Frontend version details\r\n"
1489 "query channels - Query available channels\r\n"
1490 "query channels START LIMIT - Query available channels from START and limit results to LIMIT lines\r\n";
1495 "set verbose debug-mask - "
1496 "Change the VERBOSE mask to 'debug-mask'\r\n"
1497 " (i.e. 'set verbose playback,audio')\r\n"
1498 " use 'set verbose default' to revert\r\n"
1499 " back to the default level of\r\n";
1501 else if (
is_abbrev(
"screenshot", command))
1504 "screenshot - Takes a screenshot and saves it as screenshot.png\r\n"
1505 "screenshot WxH - Saves the screenshot as a WxH size image\r\n";
1507 else if (command ==
"exit")
1510 "exit - Terminates session\r\n\r\n";
1512 else if ((
is_abbrev(
"message", command)))
1515 "message - Displays a simple text message popup\r\n";
1517 else if ((
is_abbrev(
"notification", command)))
1520 "notification - Displays a simple text message notification\r\n";
1525 "theme getthemeinfo - Display the name and location of the current theme\r\n"
1526 "theme reload - Reload the theme\r\n"
1527 "theme showborders - Toggle showing widget borders\r\n"
1528 "theme shownames ON/OFF - Toggle showing widget names\r\n"
1529 "theme getwidgetnames PATH - Display the name and type of all the child widgets from PATH\r\n"
1530 "theme getarea WIDGETNAME - Get the area of widget WIDGET on the active screen\r\n"
1531 "theme setarea WIDGETNAME X Y W H - Change the area of widget WIDGET to X Y W H on the active screen\r\n";
1534 if (!helpText.isEmpty())
1537 if (!command.isEmpty())
1538 helpText += QString(
"Unknown command '%1'\r\n\r\n").arg(command);
1541 "Valid Commands:\r\n"
1542 "---------------\r\n"
1543 "jump - Jump to a specified location in Myth\r\n"
1544 "key - Send a keypress to the program\r\n"
1545 "play - Playback related commands\r\n"
1546 "query - Queries\r\n"
1548 "screenshot - Capture screenshot\r\n"
1549 "message - Display a simple text message\r\n"
1550 "notification - Display a simple text notification\r\n"
1551 "theme - Theme related commands\r\n"
1552 "exit - Exit Network Control\r\n"
1554 "Type 'help COMMANDNAME' for help on any specific command.\r\n";
1562 return QString(
"ERROR: See 'help %1' for usage information")
1565 QString message = nc->
getCommand().remove(0, 7).trimmed();
1568 qApp->postEvent(window, me);
1575 return QString(
"ERROR: See 'help %1' for usage information")
1578 QString message = nc->
getCommand().remove(0, 12).trimmed();
1586 QCoreApplication::postEvent(
1591 const QString &reply)
1600 static const QRegularExpression crlfRegEx(
"\r\n$");
1601 static const QRegularExpression crlfcrlfRegEx(
"\r\n.*\r\n");
1606 if (client && clientStream && client->state() == QTcpSocket::ConnectedState)
1608 *clientStream << reply;
1610 if ((!reply.contains(crlfRegEx)) ||
1611 ( reply.contains(crlfcrlfRegEx)))
1612 *clientStream <<
"\r\n" <<
m_prompt;
1614 clientStream->flush();
1623 auto *me =
dynamic_cast<MythEvent *
>(e);
1627 const QString& message = me->
Message();
1629 if (message.startsWith(
"MUSIC_CONTROL"))
1631 QStringList tokens = message.simplified().split(
" ");
1632 if ((tokens.size() >= 4) &&
1633 (tokens[1] ==
"ANSWER") &&
1637 for (
int i = 4; i < tokens.size(); i++)
1638 m_answer += QString(
" ") + tokens[i];
1643 else if (message.startsWith(
"NETWORK_CONTROL"))
1645 QStringList tokens = message.simplified().split(
" ");
1646 if ((tokens.size() >= 3) &&
1647 (tokens[1] ==
"ANSWER"))
1650 for (
int i = 3; i < tokens.size(); i++)
1651 m_answer += QString(
" ") + tokens[i];
1654 else if ((tokens.size() >= 4) &&
1655 (tokens[1] ==
"RESPONSE"))
1659 for (
int i = 4; i < tokens.size(); i++)
1660 m_answer += QString(
" ") + tokens[i];
1686 for (
auto * ncc2 : std::as_const(
m_clients))
1698 if (ncce ==
nullptr)
1710 bool appendCRLF =
true;
1711 QString queryStr(
"SELECT chanid, starttime, endtime, title, subtitle "
1713 "WHERE starttime < :START AND endtime > :END ");
1715 if (!chanID.isEmpty())
1717 queryStr +=
" AND chanid = :CHANID";
1721 queryStr +=
" ORDER BY starttime, endtime, chanid";
1726 if (!chanID.isEmpty())
1733 while (query.
next())
1735 QString title = query.
value(3).toString();
1736 QString subtitle = query.
value(4).toString();
1738 if (!subtitle.isEmpty())
1739 title += QString(
" -\"%1\"").arg(subtitle);
1740 QByteArray atitle = title.toLocal8Bit();
1743 QString(
"%1 %2 %3 %4")
1744 .arg(QString::number(query.
value(0).toInt()).rightJustified(5,
' '),
1755 result =
"ERROR: Unable to retrieve current schedule list.";
1765 bool appendCRLF =
true;
1767 queryStr =
"SELECT chanid, starttime, title, subtitle "
1768 "FROM recorded WHERE deletepending = 0 ";
1770 if ((!chanid.isEmpty()) && (!starttime.isEmpty()))
1772 queryStr +=
"AND chanid = " + chanid +
" "
1773 "AND starttime = '" + starttime +
"' ";
1777 queryStr +=
"ORDER BY starttime, title;";
1785 while (query.
next())
1787 title = query.
value(2).toString();
1788 subtitle = query.
value(3).toString();
1790 if (!subtitle.isEmpty())
1792 episode = QString(
"%1 -\"%2\"").arg(title, subtitle);
1801 .arg(query.
value(0).toString(),
1811 result =
"ERROR: Unable to retrieve recordings list.";
1822 uint sqlStart = start;
1828 queryStr =
"select chanid, callsign, name from channel "
1829 "where deleted IS NULL and visible > 0 "
1830 "ORDER BY callsign";
1834 QString limitStr = QString(
" LIMIT %1,%2").arg(sqlStart).arg(limit);
1835 queryStr += limitStr;
1841 result =
"ERROR: Unable to retrieve channel list.";
1849 result += QString(R
"(0:0 0 "Invalid" "Invalid")");
1853 while (query.
next())
1858 result += QString(
"%1:%2 %3 \"%4\" \"%5\"\r\n")
1859 .arg(cnt).arg(maxcnt)
1860 .arg(query.
value(0).toString(),
1861 query.
value(1).toString(),
1862 query.
value(2).toString());
1875 QStringList size = nc->
getArg(1).split(
'x');
1876 if (size.size() == 2)
1878 width = size[0].toInt();
1879 height = size[1].toInt();
1885 if (width && height)
1887 args << QString::number(width);
1888 args << QString::number(height);
1892 qApp->postEvent(window, me);
1899 for(
int i=0 ; i<arg ; i++) {
1900 QString argstr = c.simplified().split(
" ")[0];
1901 c = c.mid(argstr.length()).trimmed();
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.
This is a wrapper around QThread that does several additional things.
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
QString GetHostName(void)
void SendSystemEvent(const QString &msg)
void dispatch(const MythEvent &event)
int GetNumSetting(const QString &key, int defaultval=0)
This class is used as a container for messages.
const QString & Message() const
static const Type kMythEventMessage
static const Type kMythUserMessage
static void ResetScreensaver()
MythScreenStack * GetMainStack()
void JumpTo(const QString &Destination, bool Pop=true)
static bool IsTopScreenInitialized()
MythScreenStack * GetStack(const QString &Stackname)
bool Queue(const MythNotification ¬ification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
void addListener(QObject *listener)
Add a listener to the observable.
void removeListener(QObject *listener)
Remove a listener to the observable.
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
virtual MythScreenType * GetTopScreen(void) const
Screen in which all other widgets are contained and rendered.
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
A simple text clock widget.
A narrow purpose widget used to represent cut positions and regions when editing a video.
Create a group of widgets.
A narrow purpose widget used to show television programs and the timeslots they occupy on channels.
Image widget, displays a single image or multiple images in sequence.
QString GetCurrentLocation(bool FullPath=false, bool MainStackOnly=true)
A widget for rendering primitive shapes and lines.
A widget for offering a range of numerical values where only the the bounding values and interval are...
This widget is used for grouping other widgets for display when a particular named state is called.
A text entry and edit widget.
All purpose text widget, displays a text string.
The base class on which all widgets and screens are based.
QList< MythUIType * > * GetAllChildren(void)
Return a list of all child widgets.
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Video widget, displays raw image data.
NetworkControlClient * getClient()
NetworkControlClient(QTcpSocket *s)
void commandReceived(QString &)
~NetworkControlClient() override
QTextStream * m_textStream
QTextStream * getTextStream()
static const Type kEventType
void processNetworkControlCommand(NetworkCommand *nc)
QList< NetworkCommand * > m_networkControlReplies
static QString processSet(NetworkCommand *nc)
static QString getWidgetType(MythUIType *type)
QRecursiveMutex m_clientLock
static QString processNotification(NetworkCommand *nc)
QString processJump(NetworkCommand *nc)
void receiveCommand(QString &command)
QList< NetworkControlClient * > m_clients
QString processQuery(NetworkCommand *nc)
QMap< int, QString > m_keyTextMap
static QString processMessage(NetworkCommand *nc)
void customEvent(QEvent *e) override
QString processTheme(NetworkCommand *nc)
static QString listChannels(uint start, uint limit)
QMap< QString, int > m_keyMap
QString processPlay(NetworkCommand *nc, int clientID)
static QString listSchedule(const QString &chanID="")
void newControlConnection(QTcpSocket *client)
QList< NetworkCommand * > m_networkControlCommands
MThread * m_commandThread
QString processKey(NetworkCommand *nc)
void notifyDataAvailable(void)
static QString listRecordings(const QString &chanid="", const QString &starttime="")
QString processHelp(NetworkCommand *nc)
void sendReplyToClient(NetworkControlClient *ncc, const QString &reply)
QMap< QString, QString > m_jumpMap
~NetworkControl() override
static QString saveScreenshot(NetworkCommand *nc)
void newConnection(QTcpSocket *)
int verboseArgParse(const QString &arg)
Parse the –verbose commandline argument and set the verbose level.
static const QRegularExpression badChars
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythNotificationCenter * GetNotificationCenter(void)
MythMainWindow * GetMythMainWindow(void)
bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM)
Returns memory statistics in megabytes.
loadArray getLoadAvgs(void)
Returns the system load averages.
bool getUptime(std::chrono::seconds &uptime)
Returns uptime statistics.
std::array< double, 3 > loadArray
static constexpr const char * ACTION_SCREENSHOT
static constexpr const char * ACTION_HANDLEMEDIA
MythUIHelper * GetMythUI()
const char * GetMythSourceVersion()
const char * GetMythSourcePath()
QString current_iso_string(bool stripped)
Returns current Date and Time in UTC as a string.
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
static constexpr qint64 FE_LONG_TO
static const QRegularExpression kStartTimeRE
static bool is_abbrev(QString const &command, QString const &test, int minchars=1)
Is test an abbreviation of command ? The test substring must be at least minchars long.
static const QRegularExpression kChanID1RE
static const QEvent::Type kNetworkControlDataReadyEvent
static constexpr qint64 FE_SHORT_TO