6 #include <QCoreApplication>
11 #include <QRegularExpression>
12 #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
13 #include <QStringConverter>
15 #include <QStringList>
16 #include <QTextStream>
24 #include "libmythbase/mythversion.h"
53 #define LOC QString("NetworkControl: ")
54 #define LOC_ERR QString("NetworkControl Error: ")
60 (QEvent::Type) QEvent::registerEventType();
62 (QEvent::Type) QEvent::registerEventType();
66 { R
"(^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ?$)" };
76 QString
const& test,
int minchars = 1)
78 if (test.length() < minchars)
79 return command.toLower() == test.toLower();
80 return test.toLower() == command.left(test.length()).toLower();
84 m_commandThread(new
MThread(
"NetworkControl", this))
87 m_jumpMap[
"channelpriorities"] =
"Channel Recording Priorities";
90 m_jumpMap[
"managerecordings"] =
"Manage Recordings / Fix Conflicts";
99 m_jumpMap[
"programfinder"] =
"Program Finder";
100 m_jumpMap[
"programguide"] =
"Program Guide";
102 m_jumpMap[
"musicplaylists"] =
"Select music playlists";
103 m_jumpMap[
"playbackrecordings"] =
"TV Recording Playback";
104 m_jumpMap[
"videobrowser"] =
"Video Browser";
105 m_jumpMap[
"videogallery"] =
"Video Gallery";
106 m_jumpMap[
"videolistings"] =
"Video Listings";
107 m_jumpMap[
"videomanager"] =
"Video Manager";
108 m_jumpMap[
"zoneminderconsole"] =
"ZoneMinder Console";
109 m_jumpMap[
"zoneminderliveview"] =
"ZoneMinder Live View";
110 m_jumpMap[
"zoneminderevents"] =
"ZoneMinder Events";
112 m_jumpMap[
"channelrecpriority"] =
"Channel Recording Priorities";
113 m_jumpMap[
"viewscheduled"] =
"Manage Recordings / Fix Conflicts";
114 m_jumpMap[
"previousbox"] =
"Previously Recorded";
115 m_jumpMap[
"progfinder"] =
"Program Finder";
116 m_jumpMap[
"guidegrid"] =
"Program Guide";
117 m_jumpMap[
"managerecrules"] =
"Manage Recording Rules";
118 m_jumpMap[
"statusbox"] =
"Status Screen";
119 m_jumpMap[
"playbackbox"] =
"TV Recording Playback";
120 m_jumpMap[
"pbb"] =
"TV Recording Playback";
122 m_jumpMap[
"reloadtheme"] =
"Reload Theme";
123 m_jumpMap[
"showborders"] =
"Toggle Show Widget Borders";
124 m_jumpMap[
"shownames"] =
"Toggle Show Widget Names";
133 m_keyMap[
"return"] = Qt::Key_Return;
134 m_keyMap[
"pageup"] = Qt::Key_PageUp;
135 m_keyMap[
"pagedown"] = Qt::Key_PageDown;
136 m_keyMap[
"escape"] = Qt::Key_Escape;
138 m_keyMap[
"backtab"] = Qt::Key_Backtab;
140 m_keyMap[
"backspace"] = Qt::Key_Backspace;
141 m_keyMap[
"insert"] = Qt::Key_Insert;
142 m_keyMap[
"delete"] = Qt::Key_Delete;
149 m_keyMap[
"underscore"] = Qt::Key_Underscore;
151 m_keyMap[
"period"] = Qt::Key_Period;
153 m_keyMap[
"numbersign"] = Qt::Key_NumberSign;
154 m_keyMap[
"poundsign"] = Qt::Key_NumberSign;
155 m_keyMap[
"hash"] = Qt::Key_NumberSign;
157 m_keyMap[
"bracketleft"] = Qt::Key_BracketLeft;
158 m_keyMap[
"["] = Qt::Key_BracketLeft;
159 m_keyMap[
"bracketright"] = Qt::Key_BracketRight;
160 m_keyMap[
"]"] = Qt::Key_BracketRight;
161 m_keyMap[
"backslash"] = Qt::Key_Backslash;
163 m_keyMap[
"dollar"] = Qt::Key_Dollar;
165 m_keyMap[
"percent"] = Qt::Key_Percent;
167 m_keyMap[
"ampersand"] = Qt::Key_Ampersand;
169 m_keyMap[
"parenleft"] = Qt::Key_ParenLeft;
171 m_keyMap[
"parenright"] = Qt::Key_ParenRight;
173 m_keyMap[
"asterisk"] = Qt::Key_Asterisk;
175 m_keyMap[
"question"] = Qt::Key_Question;
181 m_keyMap[
"semicolon"] = Qt::Key_Semicolon;
187 m_keyMap[
"greater"] = Qt::Key_Greater;
263 "mythfrontend shutting down, connection closing...");
328 else if ((nc->
getArg(0).toLower() ==
"exit") || (nc->
getArg(0).toLower() ==
"quit"))
330 QCoreApplication::postEvent(
this,
333 else if (! nc->
getArg(0).isEmpty())
335 result = QString(
"INVALID command '%1', try 'help' for more info")
348 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Client Socket disconnected");
353 for (
auto * ncc : std::as_const(
m_clients))
355 if (ncc->getSocket()->state() == QTcpSocket::UnconnectedState)
374 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"deleteClient(%1), unable to "
375 "locate specified NetworkControlClient").arg((
long long)ncc));
383 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"New connection established."));
394 connect(client, &QAbstractSocket::disconnected,
397 welcomeStr =
"MythFrontend Network Control\r\n";
398 welcomeStr +=
"Type 'help' for usage information\r\n"
399 "---------------------------------";
409 m_textStream(new QTextStream(s))
411 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
429 auto *socket = (QTcpSocket *)sender();
433 while (socket->canReadLine())
435 QString lineIn = socket->readLine();
437 static const QRegularExpression
badChars
438 {
"[^-a-zA-Z0-9\\s\\.:_#/$%&()*+,;<=>?\\[\\]\\|]" };
442 lineIn = lineIn.simplified();
443 if (lineIn.isEmpty())
446 LOG(VB_NETWORK, LOG_INFO,
LOC +
447 QString(
"emit commandReceived(%1)").arg(lineIn));
454 LOG(VB_NETWORK, LOG_INFO,
LOC +
455 QString(
"NetworkControl::receiveCommand(%1)").arg(command));
456 auto *ncc = qobject_cast<NetworkControlClient *>(sender());
468 QString result =
"OK";
471 return QString(
"ERROR: See 'help %1' for usage information")
482 std::this_thread::sleep_for(10ms);
489 QString result =
"OK";
490 QKeyEvent *
event =
nullptr;
493 return QString(
"ERROR: See 'help %1' for usage information")
496 QObject *keyDest =
nullptr;
501 return {
"ERROR: Application has no main window!\n"};
504 while (curToken < nc->getArgCount())
506 int tokenLen = nc->
getArg(curToken).length();
508 if (nc->
getArg(curToken) ==
"sleep")
510 std::this_thread::sleep_for(1s);
522 event =
new QKeyEvent(QEvent::KeyPress, keyCode, Qt::NoModifier,
524 QCoreApplication::postEvent(keyDest, event);
526 event =
new QKeyEvent(QEvent::KeyRelease, keyCode, Qt::NoModifier,
528 QCoreApplication::postEvent(keyDest, event);
530 else if (((tokenLen == 1) &&
531 (nc->
getArg(curToken).at(0).isLetterOrNumber())) ||
533 (nc->
getArg(curToken).contains(
"+"))))
535 QKeySequence a(nc->
getArg(curToken));
536 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
538 Qt::KeyboardModifiers modifiers = Qt::NoModifier;
542 QStringList tokenParts = nc->
getArg(curToken).split(
'+');
545 while (partNum < (tokenParts.size() - 1))
547 if (tokenParts[partNum].toUpper() ==
"CTRL")
548 modifiers |= Qt::ControlModifier;
549 if (tokenParts[partNum].toUpper() ==
"SHIFT")
550 modifiers |= Qt::ShiftModifier;
551 if (tokenParts[partNum].toUpper() ==
"ALT")
552 modifiers |= Qt::AltModifier;
553 if (tokenParts[partNum].toUpper() ==
"META")
554 modifiers |= Qt::MetaModifier;
560 int keyCode = a[0].key();
561 Qt::KeyboardModifiers modifiers = a[0].keyboardModifiers();
565 if (nc->
getArg(curToken) == nc->
getArg(curToken).toUpper())
566 modifiers |= Qt::ShiftModifier;
571 event =
new QKeyEvent(QEvent::KeyPress, keyCode, modifiers,
573 QCoreApplication::postEvent(keyDest, event);
575 event =
new QKeyEvent(QEvent::KeyRelease, keyCode, modifiers,
577 QCoreApplication::postEvent(keyDest, event);
581 return QString(
"ERROR: Invalid syntax at '%1', see 'help %2' for "
594 QString result =
"OK";
598 return QString(
"ERROR: See 'help %1' for usage information")
604 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"mainmenu")
611 (
GetMythUI()->GetCurrentLocation().toLower() !=
"mainmenu"))
612 std::this_thread::sleep_for(10ms);
615 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"mainmenu")
624 return {
"Unable to change to main menu to start playback!"};
632 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback")
634 QString msg = QString(
"NETWORK_CONTROL STOP");
641 (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback"))
642 std::this_thread::sleep_for(10ms);
645 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox")
651 while (!timer.hasExpired(10000) &&
652 (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox"))
653 std::this_thread::sleep_for(10ms);
657 std::this_thread::sleep_for(10ms);
660 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playbackbox")
666 QString msg = QString(
"NETWORK_CONTROL %1 PROGRAM %2 %3 %4")
669 QString::number(clientID));
680 std::this_thread::sleep_for(10ms);
685 result =
"ERROR: Timed out waiting for reply from player";
690 result = QString(
"ERROR: Unable to change to PlaybackBox from "
691 "%1, cannot play requested file.")
698 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playmusic")
700 return QString(
"ERROR: You are in %1 mode and this command is "
701 "only for MythMusic")
711 message = QString(
"MUSIC_COMMAND %1 PLAY").arg(
hostname);
713 message = QString(
"MUSIC_COMMAND %1 PAUSE").arg(
hostname);
715 message = QString(
"MUSIC_COMMAND %1 STOP").arg(
hostname);
727 qApp->processEvents();
728 std::this_thread::sleep_for(10ms);
747 qApp->processEvents();
748 std::this_thread::sleep_for(10ms);
767 qApp->processEvents();
768 std::this_thread::sleep_for(10ms);
778 return {
"ERROR: Invalid 'play music' command"};
785 message = QString(
"MUSIC_COMMAND %1 SET_VOLUME %2")
790 message = QString(
"MUSIC_COMMAND %1 PLAY_TRACK %2")
795 message = QString(
"MUSIC_COMMAND %1 PLAY_URL %2")
800 message = QString(
"MUSIC_COMMAND %1 PLAY_FILE '%2'")
805 return {
"ERROR: Invalid 'play music' command"};
810 return {
"ERROR: Invalid 'play music' command"};
815 else if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playback")
817 return QString(
"ERROR: You are in %1 mode and this command is only "
824 message = QString(
"NETWORK_CONTROL CHANID %1").arg(nc->
getArg(2));
826 return QString(
"ERROR: See 'help %1' for usage information")
831 static const QRegularExpression kChanID2RE {
"^[-\\.\\d_#]+$" };
834 return "ERROR: See 'help play' for usage information";
837 message =
"NETWORK_CONTROL CHANNEL UP";
839 message =
"NETWORK_CONTROL CHANNEL DOWN";
840 else if (nc->
getArg(2).contains(kChanID2RE))
841 message = QString(
"NETWORK_CONTROL CHANNEL %1").arg(nc->
getArg(2));
843 return QString(
"ERROR: See 'help %1' for usage information")
848 static const QRegularExpression kSeekTimeRE { R
"(^\d\d:\d\d:\d\d$)" };
851 return QString(
"ERROR: See 'help %1' for usage information")
855 message =
"NETWORK_CONTROL SEEK BEGINNING";
857 message =
"NETWORK_CONTROL SEEK FORWARD";
860 message =
"NETWORK_CONTROL SEEK BACKWARD";
861 else if (nc->
getArg(2).contains(kSeekTimeRE))
863 int hours = nc->
getArg(2).mid(0, 2).toInt();
864 int minutes = nc->
getArg(2).mid(3, 2).toInt();
865 int seconds = nc->
getArg(2).mid(6, 2).toInt();
866 message = QString(
"NETWORK_CONTROL SEEK POSITION %1")
867 .arg((hours * 3600) + (minutes * 60) + seconds);
871 return QString(
"ERROR: See 'help %1' for usage information")
877 static const QRegularExpression kSpeed1RE { R
"(^\-*\d+x$)" };
878 static const QRegularExpression kSpeed2RE { R
"(^\-*\d+\/\d+x$)" };
879 static const QRegularExpression kSpeed3RE { R
"(^\-*\d*\.\d+x$)" };
882 return QString(
"ERROR: See 'help %1' for usage information")
885 QString token2 = nc->
getArg(2).toLower();
886 if ((token2.contains(kSpeed1RE)) ||
887 (token2.contains(kSpeed2RE)) ||
888 (token2.contains(kSpeed3RE)))
889 message = QString(
"NETWORK_CONTROL SPEED %1").arg(token2);
891 message = QString(
"NETWORK_CONTROL SPEED normal");
893 message = QString(
"NETWORK_CONTROL SPEED 0x");
895 return QString(
"ERROR: See 'help %1' for usage information")
905 message = QString(
"NETWORK_CONTROL STOP");
909 static const QRegularExpression kVolumeRE {
"^\\d+%?$" };
912 (!nc->
getArg(2).toLower().contains(kVolumeRE)))
914 return QString(
"ERROR: See 'help %1' for usage information")
918 message = QString(
"NETWORK_CONTROL VOLUME %1")
919 .arg(nc->
getArg(2).toLower());
923 static const QRegularExpression kNumberRE {
"^\\d+$" };
925 message = QString(
"NETWORK_CONTROL SUBTITLES 0");
926 else if (!nc->
getArg(2).toLower().contains(kNumberRE))
928 return QString(
"ERROR: See 'help %1' for usage information")
933 message = QString(
"NETWORK_CONTROL SUBTITLES %1")
939 return QString(
"ERROR: See 'help %1' for usage information")
943 if (!message.isEmpty())
963 QString result =
"OK";
966 return QString(
"ERROR: See 'help %1' for usage information")
971 bool fullPath =
false;
972 bool mainStackOnly =
true;
975 fullPath = (nc->
getArg(2).toLower() ==
"true" || nc->
getArg(2) ==
"1");
977 mainStackOnly = (nc->
getArg(3).toLower() ==
"true" || nc->
getArg(3) ==
"1");
983 if (location ==
"Playback")
987 QString message = QString(
"NETWORK_CONTROL QUERY POSITION");
994 std::this_thread::sleep_for(10ms);
999 result =
"ERROR: Timed out waiting for reply from player";
1016 return QString(
"VERSION: %1/%2 %3 %4 QT/%5 DBSchema/%6")
1019 MYTH_BINARY_VERSION,
1022 QString::number(dbSchema));
1032 std::chrono::seconds uptime = 0s;
1035 str = QString::number(uptime.count());
1037 str = QString(
"Could not determine uptime.");
1045 str = QString(
"getloadavg() failed");
1047 str = QString(
"%1 %2 %3").arg(loads[0]).arg(loads[1]).arg(loads[2]);
1058 if (
getMemStats(totalMB, freeMB, totalVM, freeVM))
1060 str = QString(
"%1 %2 %3 %4")
1061 .arg(totalMB).arg(freeMB).arg(totalVM).arg(freeVM);
1065 str = QString(
"Could not determine memory stats.");
1075 if (location !=
"Playback")
1079 QString message = QString(
"NETWORK_CONTROL QUERY VOLUME");
1083 QElapsedTimer timer;
1086 std::this_thread::sleep_for(10ms);
1091 str =
"ERROR: Timed out waiting for reply from player";
1112 nc->
getArg(3).toLower().toUInt());
1113 return QString(
"ERROR: See 'help %1' for usage information "
1114 "(parameters mismatch)").arg(nc->
getArg(0));
1118 return QString(
"ERROR: See 'help %1' for usage information")
1128 return QString(
"ERROR: See 'help %1' for usage information")
1131 if (nc->
getArg(1) ==
"verbose")
1134 return {
"ERROR: Missing filter name."};
1138 return QString(
"ERROR: Separate filters with commas with no "
1139 "space: playback,audio\r\n See 'help %1' for usage "
1140 "information").arg(nc->
getArg(0));
1144 QString result =
"OK";
1148 if (pva_result != 0 )
1152 result +=
" Previous filter: " + oldVerboseString +
"\r\n";
1155 LOG(VB_GENERAL, LOG_NOTICE,
1156 QString(
"Verbose mask changed, new level is: %1")
1162 return QString(
"ERROR: See 'help %1' for usage information")
1169 return "MythUIText";
1171 return "MythUITextEdit";
1173 return "MythUIGroup";
1175 return "MythUIButton";
1177 return "MythUICheckBox";
1179 return "MythUIShape";
1181 return "MythUIButtonList";
1183 return "MythUIImage";
1185 return "MythUISpinBox";
1188 return "MythUIWebBrowser";
1191 return "MythUIClock";
1193 return "MythUIStateType";
1195 return "MythUIProgressBar";
1197 return "MythUIButtonTree";
1199 return "MythUIScrollBar";
1201 return "MythUIVideo";
1203 return "MythUIGuideGrid";
1205 return "MythUIEditBar";
1213 return QString(
"ERROR: See 'help %1' for usage information")
1216 if (nc->
getArg(1) ==
"getthemeinfo")
1220 return QString(
"%1 - %2").arg(
themeName, themeDir);
1222 if (nc->
getArg(1) ==
"reload")
1228 if (nc->
getArg(1) ==
"showborders")
1234 if (nc->
getArg(1) ==
"shownames")
1240 if (nc->
getArg(1) ==
"getwidgetnames")
1245 path = nc->
getArg(2).split(
'/');
1257 return {
"ERROR: no top screen found!"};
1261 while (!path.isEmpty())
1263 QString childName = path.takeFirst();
1264 currType = currType->
GetChild(childName);
1266 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1272 for (
int i = 0; i < children->count(); i++)
1275 QString widgetName =
type->objectName();
1277 result += QString(
"%1 - %2\n\r").arg(widgetName, -20).arg(widgetType);
1282 if (nc->
getArg(1) ==
"getarea")
1285 return {
"ERROR: Missing widget name."};
1287 QString widgetName = nc->
getArg(2);
1288 QStringList path = widgetName.split(
'/');
1300 return {
"ERROR: no top screen found!"};
1304 while (path.count() > 1)
1306 QString childName = path.takeFirst();
1307 currType = currType->
GetChild(childName);
1309 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1314 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1316 int x =
type->GetFullArea().x();
1317 int y =
type->GetFullArea().y();
1318 int w =
type->GetFullArea().width();
1319 int h =
type->GetFullArea().height();
1320 return QString(
"The area of '%1' is x:%2, y:%3, w:%4, h:%5")
1321 .arg(widgetName).arg(x).arg(y).arg(w).arg(h);
1323 if (nc->
getArg(1) ==
"setarea")
1326 return {
"ERROR: Missing widget name."};
1329 return {
"ERROR: Missing X, Y, Width or Height."};
1331 QString widgetName = nc->
getArg(2);
1332 QStringList path = widgetName.split(
'/');
1333 QString x = nc->
getArg(3);
1334 QString y = nc->
getArg(4);
1335 QString w = nc->
getArg(5);
1336 QString h = nc->
getArg(6);
1349 return {
"ERROR: no top screen found!"};
1351 while (path.count() > 1)
1353 QString childName = path.takeFirst();
1354 currType = currType->
GetChild(childName);
1356 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1361 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1365 return QString(
"Changed area of '%1' to x:%2, y:%3, w:%4, h:%5")
1366 .arg(widgetName, x, y, w, h);
1369 return QString(
"ERROR: See 'help %1' for usage information")
1395 QMap<QString, QString>::Iterator it;
1397 "Usage: jump JUMPPOINT\r\n"
1399 "Where JUMPPOINT is one of the following:\r\n";
1403 helpText += it.key().leftJustified(20,
' ',
true) +
" - " +
1410 "key LETTER - Send the letter key specified\r\n"
1411 "key NUMBER - Send the number key specified\r\n"
1412 "key CODE - Send one of the following key codes\r\n"
1415 QMap<QString, int>::Iterator it;
1424 helpText += it.key();
1431 "play volume NUMBER% - Change volume to given percentage value\r\n"
1432 "play channel up - Change channel Up\r\n"
1433 "play channel down - Change channel Down\r\n"
1434 "play channel NUMBER - Change to a specific channel number\r\n"
1435 "play chanid NUMBER - Change to a specific channel id (chanid)\r\n"
1436 "play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n"
1437 "play program CHANID yyyy-MM-ddThh:mm:ss\r\n"
1438 " - Play program with chanid & starttime\r\n"
1439 "play program CHANID yyyy-MM-ddThh:mm:ss resume\r\n"
1440 " - Resume program with chanid & starttime\r\n"
1441 "play save preview\r\n"
1442 " - Save preview image from current position\r\n"
1443 "play save preview FILENAME\r\n"
1444 " - Save preview image to FILENAME\r\n"
1445 "play save preview FILENAME WxH\r\n"
1446 " - Save preview image of size WxH\r\n"
1447 "play seek beginning - Seek to the beginning of the recording\r\n"
1448 "play seek forward - Skip forward in the video\r\n"
1449 "play seek backward - Skip backwards in the video\r\n"
1450 "play seek HH:MM:SS - Seek to a specific position\r\n"
1451 "play speed pause - Pause playback\r\n"
1452 "play speed normal - Playback at normal speed\r\n"
1453 "play speed 1x - Playback at normal speed\r\n"
1454 "play speed SPEEDx - Playback where SPEED must be a decimal\r\n"
1455 "play speed 1/8x - Playback at 1/8x speed\r\n"
1456 "play speed 1/4x - Playback at 1/4x speed\r\n"
1457 "play speed 1/3x - Playback at 1/3x speed\r\n"
1458 "play speed 1/2x - Playback at 1/2x speed\r\n"
1459 "play stop - Stop playback\r\n"
1460 "play subtitles [#] - Switch on indicated subtitle tracks\r\n"
1461 "play music play - Resume playback (MythMusic)\r\n"
1462 "play music pause - Pause playback (MythMusic)\r\n"
1463 "play music stop - Stop Playback (MythMusic)\r\n"
1464 "play music setvolume N - Set volume to number (MythMusic)\r\n"
1465 "play music getvolume - Get current volume (MythMusic)\r\n"
1466 "play music getmeta - Get metadata for current track (MythMusic)\r\n"
1467 "play music getstatus - Get music player status playing/paused/stopped (MythMusic)\r\n"
1468 "play music file NAME - Play specified file (MythMusic)\r\n"
1469 "play music track N - Switch to specified track (MythMusic)\r\n"
1470 "play music url URL - Play specified URL (MythMusic)\r\n";
1475 "query location - Query current screen or location\r\n"
1476 "query volume - Query the current playback volume\r\n"
1477 "query recordings - List currently available recordings\r\n"
1478 "query recording CHANID STARTTIME\r\n"
1479 " - List info about the specified program\r\n"
1480 "query liveTV - List current TV schedule\r\n"
1481 "query liveTV CHANID - Query current program for specified channel\r\n"
1482 "query load - List 1/5/15 load averages\r\n"
1483 "query memstats - List free and total, physical and swap memory\r\n"
1484 "query time - Query current time on frontend\r\n"
1485 "query uptime - Query machine uptime\r\n"
1486 "query verbose - Get current VERBOSE mask\r\n"
1487 "query version - Query Frontend version details\r\n"
1488 "query channels - Query available channels\r\n"
1489 "query channels START LIMIT - Query available channels from START and limit results to LIMIT lines\r\n";
1494 "set verbose debug-mask - "
1495 "Change the VERBOSE mask to 'debug-mask'\r\n"
1496 " (i.e. 'set verbose playback,audio')\r\n"
1497 " use 'set verbose default' to revert\r\n"
1498 " back to the default level of\r\n";
1500 else if (
is_abbrev(
"screenshot", command))
1503 "screenshot - Takes a screenshot and saves it as screenshot.png\r\n"
1504 "screenshot WxH - Saves the screenshot as a WxH size image\r\n";
1506 else if (command ==
"exit")
1509 "exit - Terminates session\r\n\r\n";
1511 else if ((
is_abbrev(
"message", command)))
1514 "message - Displays a simple text message popup\r\n";
1516 else if ((
is_abbrev(
"notification", command)))
1519 "notification - Displays a simple text message notification\r\n";
1524 "theme getthemeinfo - Display the name and location of the current theme\r\n"
1525 "theme reload - Reload the theme\r\n"
1526 "theme showborders - Toggle showing widget borders\r\n"
1527 "theme shownames ON/OFF - Toggle showing widget names\r\n"
1528 "theme getwidgetnames PATH - Display the name and type of all the child widgets from PATH\r\n"
1529 "theme getarea WIDGETNAME - Get the area of widget WIDGET on the active screen\r\n"
1530 "theme setarea WIDGETNAME X Y W H - Change the area of widget WIDGET to X Y W H on the active screen\r\n";
1533 if (!helpText.isEmpty())
1536 if (!command.isEmpty())
1537 helpText += QString(
"Unknown command '%1'\r\n\r\n").arg(command);
1540 "Valid Commands:\r\n"
1541 "---------------\r\n"
1542 "jump - Jump to a specified location in Myth\r\n"
1543 "key - Send a keypress to the program\r\n"
1544 "play - Playback related commands\r\n"
1545 "query - Queries\r\n"
1547 "screenshot - Capture screenshot\r\n"
1548 "message - Display a simple text message\r\n"
1549 "notification - Display a simple text notification\r\n"
1550 "theme - Theme related commands\r\n"
1551 "exit - Exit Network Control\r\n"
1553 "Type 'help COMMANDNAME' for help on any specific command.\r\n";
1561 return QString(
"ERROR: See 'help %1' for usage information")
1564 QString message = nc->
getCommand().remove(0, 7).trimmed();
1567 qApp->postEvent(window, me);
1574 return QString(
"ERROR: See 'help %1' for usage information")
1577 QString message = nc->
getCommand().remove(0, 12).trimmed();
1585 QCoreApplication::postEvent(
1590 const QString &reply)
1599 static const QRegularExpression crlfRegEx(
"\r\n$");
1600 static const QRegularExpression crlfcrlfRegEx(
"\r\n.*\r\n");
1605 if (client && clientStream && client->state() == QTcpSocket::ConnectedState)
1607 *clientStream << reply;
1609 if ((!reply.contains(crlfRegEx)) ||
1610 ( reply.contains(crlfcrlfRegEx)))
1611 *clientStream <<
"\r\n" <<
m_prompt;
1613 clientStream->flush();
1622 auto *me =
dynamic_cast<MythEvent *
>(e);
1626 const QString& message = me->
Message();
1628 if (message.startsWith(
"MUSIC_CONTROL"))
1630 QStringList tokens = message.simplified().split(
" ");
1631 if ((tokens.size() >= 4) &&
1632 (tokens[1] ==
"ANSWER") &&
1636 for (
int i = 4; i < tokens.size(); i++)
1637 m_answer += QString(
" ") + tokens[i];
1642 else if (message.startsWith(
"NETWORK_CONTROL"))
1644 QStringList tokens = message.simplified().split(
" ");
1645 if ((tokens.size() >= 3) &&
1646 (tokens[1] ==
"ANSWER"))
1649 for (
int i = 3; i < tokens.size(); i++)
1650 m_answer += QString(
" ") + tokens[i];
1653 else if ((tokens.size() >= 4) &&
1654 (tokens[1] ==
"RESPONSE"))
1658 for (
int i = 4; i < tokens.size(); i++)
1659 m_answer += QString(
" ") + tokens[i];
1685 for (
auto * ncc2 : std::as_const(
m_clients))
1697 if (ncce ==
nullptr)
1709 bool appendCRLF =
true;
1710 QString queryStr(
"SELECT chanid, starttime, endtime, title, subtitle "
1712 "WHERE starttime < :START AND endtime > :END ");
1714 if (!chanID.isEmpty())
1716 queryStr +=
" AND chanid = :CHANID";
1720 queryStr +=
" ORDER BY starttime, endtime, chanid";
1725 if (!chanID.isEmpty())
1732 while (query.
next())
1734 QString title = query.
value(3).toString();
1735 QString subtitle = query.
value(4).toString();
1737 if (!subtitle.isEmpty())
1738 title += QString(
" -\"%1\"").arg(subtitle);
1739 QByteArray atitle = title.toLocal8Bit();
1742 QString(
"%1 %2 %3 %4")
1743 .arg(QString::number(query.
value(0).toInt()).rightJustified(5,
' '),
1754 result =
"ERROR: Unable to retrieve current schedule list.";
1764 bool appendCRLF =
true;
1766 queryStr =
"SELECT chanid, starttime, title, subtitle "
1767 "FROM recorded WHERE deletepending = 0 ";
1769 if ((!chanid.isEmpty()) && (!starttime.isEmpty()))
1771 queryStr +=
"AND chanid = " + chanid +
" "
1772 "AND starttime = '" + starttime +
"' ";
1776 queryStr +=
"ORDER BY starttime, title;";
1784 while (query.
next())
1786 title = query.
value(2).toString();
1787 subtitle = query.
value(3).toString();
1789 if (!subtitle.isEmpty())
1791 episode = QString(
"%1 -\"%2\"").arg(title, subtitle);
1800 .arg(query.
value(0).toString(),
1810 result =
"ERROR: Unable to retrieve recordings list.";
1821 uint sqlStart = start;
1827 queryStr =
"select chanid, callsign, name from channel "
1828 "where deleted IS NULL and visible > 0 "
1829 "ORDER BY callsign";
1833 QString limitStr = QString(
" LIMIT %1,%2").arg(sqlStart).arg(limit);
1834 queryStr += limitStr;
1840 result =
"ERROR: Unable to retrieve channel list.";
1848 result += QString(R
"(0:0 0 "Invalid" "Invalid")");
1852 while (query.
next())
1857 result += QString(
"%1:%2 %3 \"%4\" \"%5\"\r\n")
1858 .arg(cnt).arg(maxcnt)
1859 .arg(query.
value(0).toString(),
1860 query.
value(1).toString(),
1861 query.
value(2).toString());
1874 QStringList size = nc->
getArg(1).split(
'x');
1875 if (size.size() == 2)
1877 width = size[0].toInt();
1878 height = size[1].toInt();
1884 if (width && height)
1886 args << QString::number(width);
1887 args << QString::number(height);
1891 qApp->postEvent(window, me);
1898 for(
int i=0 ; i<arg ; i++) {
1899 QString argstr = c.simplified().split(
" ")[0];
1900 c = c.mid(argstr.length()).trimmed();