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");
355 if (ncc->getSocket()->state() == QTcpSocket::UnconnectedState)
373 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"deleteClient(%1), unable to "
374 "locate specified NetworkControlClient").arg((
long long)ncc));
381 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"New connection established."));
392 connect(client, &QAbstractSocket::disconnected,
395 welcomeStr =
"MythFrontend Network Control\r\n";
396 welcomeStr +=
"Type 'help' for usage information\r\n"
397 "---------------------------------";
409 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
427 auto *socket = (QTcpSocket *)sender();
431 while (socket->canReadLine())
433 QString lineIn = socket->readLine();
435 static const QRegularExpression
badChars
436 {
"[^-a-zA-Z0-9\\s\\.:_#/$%&()*+,;<=>?\\[\\]\\|]" };
440 lineIn = lineIn.simplified();
441 if (lineIn.isEmpty())
444 LOG(VB_NETWORK, LOG_INFO,
LOC +
445 QString(
"emit commandReceived(%1)").arg(lineIn));
452 LOG(VB_NETWORK, LOG_INFO,
LOC +
453 QString(
"NetworkControl::receiveCommand(%1)").arg(command));
454 auto *ncc = qobject_cast<NetworkControlClient *>(sender());
466 QString result =
"OK";
469 return QString(
"ERROR: See 'help %1' for usage information")
480 std::this_thread::sleep_for(10ms);
487 QString result =
"OK";
488 QKeyEvent *
event =
nullptr;
491 return QString(
"ERROR: See 'help %1' for usage information")
494 QObject *keyDest =
nullptr;
499 return {
"ERROR: Application has no main window!\n"};
502 while (curToken < nc->getArgCount())
504 int tokenLen = nc->
getArg(curToken).length();
506 if (nc->
getArg(curToken) ==
"sleep")
508 std::this_thread::sleep_for(1s);
520 event =
new QKeyEvent(QEvent::KeyPress, keyCode, Qt::NoModifier,
522 QCoreApplication::postEvent(keyDest, event);
524 event =
new QKeyEvent(QEvent::KeyRelease, keyCode, Qt::NoModifier,
526 QCoreApplication::postEvent(keyDest, event);
528 else if (((tokenLen == 1) &&
529 (nc->
getArg(curToken).at(0).isLetterOrNumber())) ||
531 (nc->
getArg(curToken).contains(
"+"))))
533 QKeySequence a(nc->
getArg(curToken));
534 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
536 Qt::KeyboardModifiers modifiers = Qt::NoModifier;
540 QStringList tokenParts = nc->
getArg(curToken).split(
'+');
543 while (partNum < (tokenParts.size() - 1))
545 if (tokenParts[partNum].toUpper() ==
"CTRL")
546 modifiers |= Qt::ControlModifier;
547 if (tokenParts[partNum].toUpper() ==
"SHIFT")
548 modifiers |= Qt::ShiftModifier;
549 if (tokenParts[partNum].toUpper() ==
"ALT")
550 modifiers |= Qt::AltModifier;
551 if (tokenParts[partNum].toUpper() ==
"META")
552 modifiers |= Qt::MetaModifier;
558 int keyCode = a[0].key();
559 Qt::KeyboardModifiers modifiers = a[0].keyboardModifiers();
563 if (nc->
getArg(curToken) == nc->
getArg(curToken).toUpper())
564 modifiers |= Qt::ShiftModifier;
569 event =
new QKeyEvent(QEvent::KeyPress, keyCode, modifiers,
571 QCoreApplication::postEvent(keyDest, event);
573 event =
new QKeyEvent(QEvent::KeyRelease, keyCode, modifiers,
575 QCoreApplication::postEvent(keyDest, event);
579 return QString(
"ERROR: Invalid syntax at '%1', see 'help %2' for "
592 QString result =
"OK";
596 return QString(
"ERROR: See 'help %1' for usage information")
602 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"mainmenu")
609 (
GetMythUI()->GetCurrentLocation().toLower() !=
"mainmenu"))
610 std::this_thread::sleep_for(10ms);
613 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"mainmenu")
621 return {
"Unable to change to main menu to start playback!"};
628 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback")
630 QString msg = QString(
"NETWORK_CONTROL STOP");
637 (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback"))
638 std::this_thread::sleep_for(10ms);
641 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox")
647 while (!timer.hasExpired(10000) &&
648 (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox"))
649 std::this_thread::sleep_for(10ms);
653 std::this_thread::sleep_for(10ms);
656 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playbackbox")
662 QString msg = QString(
"NETWORK_CONTROL %1 PROGRAM %2 %3 %4")
665 QString::number(clientID));
676 std::this_thread::sleep_for(10ms);
681 result =
"ERROR: Timed out waiting for reply from player";
686 result = QString(
"ERROR: Unable to change to PlaybackBox from "
687 "%1, cannot play requested file.")
694 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playmusic")
696 return QString(
"ERROR: You are in %1 mode and this command is "
697 "only for MythMusic")
707 message = QString(
"MUSIC_COMMAND %1 PLAY").arg(
hostname);
709 message = QString(
"MUSIC_COMMAND %1 PAUSE").arg(
hostname);
711 message = QString(
"MUSIC_COMMAND %1 STOP").arg(
hostname);
723 qApp->processEvents();
724 std::this_thread::sleep_for(10ms);
743 qApp->processEvents();
744 std::this_thread::sleep_for(10ms);
763 qApp->processEvents();
764 std::this_thread::sleep_for(10ms);
773 return {
"ERROR: Invalid 'play music' command"};
779 message = QString(
"MUSIC_COMMAND %1 SET_VOLUME %2")
784 message = QString(
"MUSIC_COMMAND %1 PLAY_TRACK %2")
789 message = QString(
"MUSIC_COMMAND %1 PLAY_URL %2")
794 message = QString(
"MUSIC_COMMAND %1 PLAY_FILE '%2'")
799 return {
"ERROR: Invalid 'play music' command"};
803 return {
"ERROR: Invalid 'play music' command"};
807 else if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playback")
809 return QString(
"ERROR: You are in %1 mode and this command is only "
816 message = QString(
"NETWORK_CONTROL CHANID %1").arg(nc->
getArg(2));
818 return QString(
"ERROR: See 'help %1' for usage information")
823 static const QRegularExpression kChanID2RE {
"^[-\\.\\d_#]+$" };
826 return "ERROR: See 'help play' for usage information";
829 message =
"NETWORK_CONTROL CHANNEL UP";
831 message =
"NETWORK_CONTROL CHANNEL DOWN";
832 else if (nc->
getArg(2).contains(kChanID2RE))
833 message = QString(
"NETWORK_CONTROL CHANNEL %1").arg(nc->
getArg(2));
835 return QString(
"ERROR: See 'help %1' for usage information")
840 static const QRegularExpression kSeekTimeRE { R
"(^\d\d:\d\d:\d\d$)" };
843 return QString(
"ERROR: See 'help %1' for usage information")
847 message =
"NETWORK_CONTROL SEEK BEGINNING";
849 message =
"NETWORK_CONTROL SEEK FORWARD";
852 message =
"NETWORK_CONTROL SEEK BACKWARD";
853 else if (nc->
getArg(2).contains(kSeekTimeRE))
855 int hours = nc->
getArg(2).mid(0, 2).toInt();
856 int minutes = nc->
getArg(2).mid(3, 2).toInt();
857 int seconds = nc->
getArg(2).mid(6, 2).toInt();
858 message = QString(
"NETWORK_CONTROL SEEK POSITION %1")
859 .arg((hours * 3600) + (minutes * 60) + seconds);
862 return QString(
"ERROR: See 'help %1' for usage information")
867 static const QRegularExpression kSpeed1RE { R
"(^\-*\d+x$)" };
868 static const QRegularExpression kSpeed2RE { R
"(^\-*\d+\/\d+x$)" };
869 static const QRegularExpression kSpeed3RE { R
"(^\-*\d*\.\d+x$)" };
872 return QString(
"ERROR: See 'help %1' for usage information")
875 QString token2 = nc->
getArg(2).toLower();
876 if ((token2.contains(kSpeed1RE)) ||
877 (token2.contains(kSpeed2RE)) ||
878 (token2.contains(kSpeed3RE)))
879 message = QString(
"NETWORK_CONTROL SPEED %1").arg(token2);
881 message = QString(
"NETWORK_CONTROL SPEED normal");
883 message = QString(
"NETWORK_CONTROL SPEED 0x");
885 return QString(
"ERROR: See 'help %1' for usage information")
894 message = QString(
"NETWORK_CONTROL STOP");
897 static const QRegularExpression kVolumeRE {
"^\\d+%?$" };
900 (!nc->
getArg(2).toLower().contains(kVolumeRE)))
902 return QString(
"ERROR: See 'help %1' for usage information")
906 message = QString(
"NETWORK_CONTROL VOLUME %1")
907 .arg(nc->
getArg(2).toLower());
911 static const QRegularExpression kNumberRE {
"^\\d+$" };
913 message = QString(
"NETWORK_CONTROL SUBTITLES 0");
914 else if (!nc->
getArg(2).toLower().contains(kNumberRE))
916 return QString(
"ERROR: See 'help %1' for usage information")
921 message = QString(
"NETWORK_CONTROL SUBTITLES %1")
926 return QString(
"ERROR: See 'help %1' for usage information")
929 if (!message.isEmpty())
949 QString result =
"OK";
952 return QString(
"ERROR: See 'help %1' for usage information")
957 bool fullPath =
false;
958 bool mainStackOnly =
true;
961 fullPath = (nc->
getArg(2).toLower() ==
"true" || nc->
getArg(2) ==
"1");
963 mainStackOnly = (nc->
getArg(3).toLower() ==
"true" || nc->
getArg(3) ==
"1");
969 if (location ==
"Playback")
973 QString message = QString(
"NETWORK_CONTROL QUERY POSITION");
980 std::this_thread::sleep_for(10ms);
985 result =
"ERROR: Timed out waiting for reply from player";
1002 return QString(
"VERSION: %1/%2 %3 %4 QT/%5 DBSchema/%6")
1005 MYTH_BINARY_VERSION,
1008 QString::number(dbSchema));
1016 std::chrono::seconds uptime = 0s;
1019 str = QString::number(uptime.count());
1021 str = QString(
"Could not determine uptime.");
1029 str = QString(
"getloadavg() failed");
1031 str = QString(
"%1 %2 %3").arg(loads[0]).arg(loads[1]).arg(loads[2]);
1042 if (
getMemStats(totalMB, freeMB, totalVM, freeVM))
1044 str = QString(
"%1 %2 %3 %4")
1045 .arg(totalMB).arg(freeMB).arg(totalVM).arg(freeVM);
1049 str = QString(
"Could not determine memory stats.");
1059 if (location !=
"Playback")
1063 QString message = QString(
"NETWORK_CONTROL QUERY VOLUME");
1067 QElapsedTimer timer;
1070 std::this_thread::sleep_for(10ms);
1075 str =
"ERROR: Timed out waiting for reply from player";
1092 nc->
getArg(3).toLower().toUInt());
1093 return QString(
"ERROR: See 'help %1' for usage information "
1094 "(parameters mismatch)").arg(nc->
getArg(0));
1097 return QString(
"ERROR: See 'help %1' for usage information")
1106 return QString(
"ERROR: See 'help %1' for usage information")
1109 if (nc->
getArg(1) ==
"verbose")
1112 return {
"ERROR: Missing filter name."};
1116 return QString(
"ERROR: Separate filters with commas with no "
1117 "space: playback,audio\r\n See 'help %1' for usage "
1118 "information").arg(nc->
getArg(0));
1122 QString result =
"OK";
1126 if (pva_result != 0 )
1130 result +=
" Previous filter: " + oldVerboseString +
"\r\n";
1133 LOG(VB_GENERAL, LOG_NOTICE,
1134 QString(
"Verbose mask changed, new level is: %1")
1140 return QString(
"ERROR: See 'help %1' for usage information")
1147 return "MythUIText";
1149 return "MythUITextEdit";
1151 return "MythUIGroup";
1153 return "MythUIButton";
1155 return "MythUICheckBox";
1157 return "MythUIShape";
1159 return "MythUIButtonList";
1161 return "MythUIImage";
1163 return "MythUISpinBox";
1166 return "MythUIWebBrowser";
1169 return "MythUIClock";
1171 return "MythUIStateType";
1173 return "MythUIProgressBar";
1175 return "MythUIButtonTree";
1177 return "MythUIScrollBar";
1179 return "MythUIVideo";
1181 return "MythUIGuideGrid";
1183 return "MythUIEditBar";
1191 return QString(
"ERROR: See 'help %1' for usage information")
1194 if (nc->
getArg(1) ==
"getthemeinfo")
1198 return QString(
"%1 - %2").arg(
themeName, themeDir);
1200 if (nc->
getArg(1) ==
"reload")
1206 if (nc->
getArg(1) ==
"showborders")
1212 if (nc->
getArg(1) ==
"shownames")
1218 if (nc->
getArg(1) ==
"getwidgetnames")
1223 path = nc->
getArg(2).split(
'/');
1235 return {
"ERROR: no top screen found!"};
1239 while (!path.isEmpty())
1241 QString childName = path.takeFirst();
1242 currType = currType->
GetChild(childName);
1244 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1250 for (
int i = 0; i < children->count(); i++)
1253 QString widgetName =
type->objectName();
1255 result += QString(
"%1 - %2\n\r").arg(widgetName, -20).arg(widgetType);
1260 if (nc->
getArg(1) ==
"getarea")
1263 return {
"ERROR: Missing widget name."};
1265 QString widgetName = nc->
getArg(2);
1266 QStringList path = widgetName.split(
'/');
1278 return {
"ERROR: no top screen found!"};
1282 while (path.count() > 1)
1284 QString childName = path.takeFirst();
1285 currType = currType->
GetChild(childName);
1287 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1292 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1294 int x =
type->GetFullArea().x();
1295 int y =
type->GetFullArea().y();
1296 int w =
type->GetFullArea().width();
1297 int h =
type->GetFullArea().height();
1298 return QString(
"The area of '%1' is x:%2, y:%3, w:%4, h:%5")
1299 .arg(widgetName).arg(x).arg(y).arg(w).arg(h);
1301 if (nc->
getArg(1) ==
"setarea")
1304 return {
"ERROR: Missing widget name."};
1307 return {
"ERROR: Missing X, Y, Width or Height."};
1309 QString widgetName = nc->
getArg(2);
1310 QStringList path = widgetName.split(
'/');
1311 QString x = nc->
getArg(3);
1312 QString y = nc->
getArg(4);
1313 QString w = nc->
getArg(5);
1314 QString h = nc->
getArg(6);
1327 return {
"ERROR: no top screen found!"};
1329 while (path.count() > 1)
1331 QString childName = path.takeFirst();
1332 currType = currType->
GetChild(childName);
1334 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1339 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1343 return QString(
"Changed area of '%1' to x:%2, y:%3, w:%4, h:%5")
1344 .arg(widgetName, x, y, w, h);
1347 return QString(
"ERROR: See 'help %1' for usage information")
1373 QMap<QString, QString>::Iterator it;
1375 "Usage: jump JUMPPOINT\r\n"
1377 "Where JUMPPOINT is one of the following:\r\n";
1381 helpText += it.key().leftJustified(20,
' ',
true) +
" - " +
1388 "key LETTER - Send the letter key specified\r\n"
1389 "key NUMBER - Send the number key specified\r\n"
1390 "key CODE - Send one of the following key codes\r\n"
1393 QMap<QString, int>::Iterator it;
1402 helpText += it.key();
1409 "play volume NUMBER% - Change volume to given percentage value\r\n"
1410 "play channel up - Change channel Up\r\n"
1411 "play channel down - Change channel Down\r\n"
1412 "play channel NUMBER - Change to a specific channel number\r\n"
1413 "play chanid NUMBER - Change to a specific channel id (chanid)\r\n"
1414 "play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n"
1415 "play program CHANID yyyy-MM-ddThh:mm:ss\r\n"
1416 " - Play program with chanid & starttime\r\n"
1417 "play program CHANID yyyy-MM-ddThh:mm:ss resume\r\n"
1418 " - Resume program with chanid & starttime\r\n"
1419 "play save preview\r\n"
1420 " - Save preview image from current position\r\n"
1421 "play save preview FILENAME\r\n"
1422 " - Save preview image to FILENAME\r\n"
1423 "play save preview FILENAME WxH\r\n"
1424 " - Save preview image of size WxH\r\n"
1425 "play seek beginning - Seek to the beginning of the recording\r\n"
1426 "play seek forward - Skip forward in the video\r\n"
1427 "play seek backward - Skip backwards in the video\r\n"
1428 "play seek HH:MM:SS - Seek to a specific position\r\n"
1429 "play speed pause - Pause playback\r\n"
1430 "play speed normal - Playback at normal speed\r\n"
1431 "play speed 1x - Playback at normal speed\r\n"
1432 "play speed SPEEDx - Playback where SPEED must be a decimal\r\n"
1433 "play speed 1/8x - Playback at 1/8x speed\r\n"
1434 "play speed 1/4x - Playback at 1/4x speed\r\n"
1435 "play speed 1/3x - Playback at 1/3x speed\r\n"
1436 "play speed 1/2x - Playback at 1/2x speed\r\n"
1437 "play stop - Stop playback\r\n"
1438 "play subtitles [#] - Switch on indicated subtitle tracks\r\n"
1439 "play music play - Resume playback (MythMusic)\r\n"
1440 "play music pause - Pause playback (MythMusic)\r\n"
1441 "play music stop - Stop Playback (MythMusic)\r\n"
1442 "play music setvolume N - Set volume to number (MythMusic)\r\n"
1443 "play music getvolume - Get current volume (MythMusic)\r\n"
1444 "play music getmeta - Get metadata for current track (MythMusic)\r\n"
1445 "play music getstatus - Get music player status playing/paused/stopped (MythMusic)\r\n"
1446 "play music file NAME - Play specified file (MythMusic)\r\n"
1447 "play music track N - Switch to specified track (MythMusic)\r\n"
1448 "play music url URL - Play specified URL (MythMusic)\r\n";
1453 "query location - Query current screen or location\r\n"
1454 "query volume - Query the current playback volume\r\n"
1455 "query recordings - List currently available recordings\r\n"
1456 "query recording CHANID STARTTIME\r\n"
1457 " - List info about the specified program\r\n"
1458 "query liveTV - List current TV schedule\r\n"
1459 "query liveTV CHANID - Query current program for specified channel\r\n"
1460 "query load - List 1/5/15 load averages\r\n"
1461 "query memstats - List free and total, physical and swap memory\r\n"
1462 "query time - Query current time on frontend\r\n"
1463 "query uptime - Query machine uptime\r\n"
1464 "query verbose - Get current VERBOSE mask\r\n"
1465 "query version - Query Frontend version details\r\n"
1466 "query channels - Query available channels\r\n"
1467 "query channels START LIMIT - Query available channels from START and limit results to LIMIT lines\r\n";
1472 "set verbose debug-mask - "
1473 "Change the VERBOSE mask to 'debug-mask'\r\n"
1474 " (i.e. 'set verbose playback,audio')\r\n"
1475 " use 'set verbose default' to revert\r\n"
1476 " back to the default level of\r\n";
1478 else if (
is_abbrev(
"screenshot", command))
1481 "screenshot - Takes a screenshot and saves it as screenshot.png\r\n"
1482 "screenshot WxH - Saves the screenshot as a WxH size image\r\n";
1484 else if (command ==
"exit")
1487 "exit - Terminates session\r\n\r\n";
1489 else if ((
is_abbrev(
"message", command)))
1492 "message - Displays a simple text message popup\r\n";
1494 else if ((
is_abbrev(
"notification", command)))
1497 "notification - Displays a simple text message notification\r\n";
1502 "theme getthemeinfo - Display the name and location of the current theme\r\n"
1503 "theme reload - Reload the theme\r\n"
1504 "theme showborders - Toggle showing widget borders\r\n"
1505 "theme shownames ON/OFF - Toggle showing widget names\r\n"
1506 "theme getwidgetnames PATH - Display the name and type of all the child widgets from PATH\r\n"
1507 "theme getarea WIDGETNAME - Get the area of widget WIDGET on the active screen\r\n"
1508 "theme setarea WIDGETNAME X Y W H - Change the area of widget WIDGET to X Y W H on the active screen\r\n";
1511 if (!helpText.isEmpty())
1514 if (!command.isEmpty())
1515 helpText += QString(
"Unknown command '%1'\r\n\r\n").arg(command);
1518 "Valid Commands:\r\n"
1519 "---------------\r\n"
1520 "jump - Jump to a specified location in Myth\r\n"
1521 "key - Send a keypress to the program\r\n"
1522 "play - Playback related commands\r\n"
1523 "query - Queries\r\n"
1525 "screenshot - Capture screenshot\r\n"
1526 "message - Display a simple text message\r\n"
1527 "notification - Display a simple text notification\r\n"
1528 "theme - Theme related commands\r\n"
1529 "exit - Exit Network Control\r\n"
1531 "Type 'help COMMANDNAME' for help on any specific command.\r\n";
1539 return QString(
"ERROR: See 'help %1' for usage information")
1542 QString message = nc->
getCommand().remove(0, 7).trimmed();
1545 qApp->postEvent(window, me);
1552 return QString(
"ERROR: See 'help %1' for usage information")
1555 QString message = nc->
getCommand().remove(0, 12).trimmed();
1563 QCoreApplication::postEvent(
1568 const QString &reply)
1577 static const QRegularExpression crlfRegEx(
"\r\n$");
1578 static const QRegularExpression crlfcrlfRegEx(
"\r\n.*\r\n");
1583 if (client && clientStream && client->state() == QTcpSocket::ConnectedState)
1585 *clientStream << reply;
1587 if ((!reply.contains(crlfRegEx)) ||
1588 ( reply.contains(crlfcrlfRegEx)))
1589 *clientStream <<
"\r\n" <<
m_prompt;
1591 clientStream->flush();
1600 auto *me =
dynamic_cast<MythEvent *
>(e);
1604 const QString& message = me->
Message();
1606 if (message.startsWith(
"MUSIC_CONTROL"))
1608 QStringList tokens = message.simplified().split(
" ");
1609 if ((tokens.size() >= 4) &&
1610 (tokens[1] ==
"ANSWER") &&
1614 for (
int i = 4; i < tokens.size(); i++)
1615 m_answer += QString(
" ") + tokens[i];
1620 else if (message.startsWith(
"NETWORK_CONTROL"))
1622 QStringList tokens = message.simplified().split(
" ");
1623 if ((tokens.size() >= 3) &&
1624 (tokens[1] ==
"ANSWER"))
1627 for (
int i = 3; i < tokens.size(); i++)
1628 m_answer += QString(
" ") + tokens[i];
1631 else if ((tokens.size() >= 4) &&
1632 (tokens[1] ==
"RESPONSE"))
1636 for (
int i = 4; i < tokens.size(); i++)
1637 m_answer += QString(
" ") + tokens[i];
1675 if (ncce ==
nullptr)
1687 bool appendCRLF =
true;
1688 QString queryStr(
"SELECT chanid, starttime, endtime, title, subtitle "
1690 "WHERE starttime < :START AND endtime > :END ");
1692 if (!chanID.isEmpty())
1694 queryStr +=
" AND chanid = :CHANID";
1698 queryStr +=
" ORDER BY starttime, endtime, chanid";
1703 if (!chanID.isEmpty())
1710 while (query.
next())
1712 QString title = query.
value(3).toString();
1713 QString subtitle = query.
value(4).toString();
1715 if (!subtitle.isEmpty())
1716 title += QString(
" -\"%1\"").arg(subtitle);
1717 QByteArray atitle = title.toLocal8Bit();
1720 QString(
"%1 %2 %3 %4")
1721 .arg(QString::number(query.
value(0).toInt()).rightJustified(5,
' '),
1732 result =
"ERROR: Unable to retrieve current schedule list.";
1742 bool appendCRLF =
true;
1744 queryStr =
"SELECT chanid, starttime, title, subtitle "
1745 "FROM recorded WHERE deletepending = 0 ";
1747 if ((!chanid.isEmpty()) && (!starttime.isEmpty()))
1749 queryStr +=
"AND chanid = " + chanid +
" "
1750 "AND starttime = '" + starttime +
"' ";
1754 queryStr +=
"ORDER BY starttime, title;";
1762 while (query.
next())
1764 title = query.
value(2).toString();
1765 subtitle = query.
value(3).toString();
1767 if (!subtitle.isEmpty())
1769 episode = QString(
"%1 -\"%2\"").arg(title, subtitle);
1778 .arg(query.
value(0).toString(),
1787 result =
"ERROR: Unable to retrieve recordings list.";
1797 uint sqlStart = start;
1803 queryStr =
"select chanid, callsign, name from channel "
1804 "where deleted IS NULL and visible > 0 "
1805 "ORDER BY callsign";
1809 QString limitStr = QString(
" LIMIT %1,%2").arg(sqlStart).arg(limit);
1810 queryStr += limitStr;
1816 result =
"ERROR: Unable to retrieve channel list.";
1824 result += QString(R
"(0:0 0 "Invalid" "Invalid")");
1828 while (query.
next())
1833 result += QString(
"%1:%2 %3 \"%4\" \"%5\"\r\n")
1834 .arg(cnt).arg(maxcnt)
1835 .arg(query.
value(0).toString(),
1836 query.
value(1).toString(),
1837 query.
value(2).toString());
1850 QStringList size = nc->
getArg(1).split(
'x');
1851 if (size.size() == 2)
1853 width = size[0].toInt();
1854 height = size[1].toInt();
1860 if (width && height)
1862 args << QString::number(width);
1863 args << QString::number(height);
1867 qApp->postEvent(window, me);
1874 for(
int i=0 ; i<arg ; i++) {
1875 QString argstr = c.simplified().split(
" ")[0];
1876 c = c.mid(argstr.length()).trimmed();